From: Loic Poulain <loic.poulain@oss.qualcomm.com>
To: Robert Foss <rfoss@kernel.org>,
Andi Shyti <andi.shyti@kernel.org>,
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Cc: linux-i2c@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org,
Loic Poulain <loic.poulain@oss.qualcomm.com>
Subject: [PATCH 4/5] i2c: qcom-cci: Add burst write support
Date: Sun, 04 Oct 2026 21:09:50 +0200 [thread overview]
Message-ID: <20261004-cci-imp-v1-4-227d12cb4829@oss.qualcomm.com> (raw)
In-Reply-To: <20261004-cci-imp-v1-0-227d12cb4829@oss.qualcomm.com>
A single CCI_I2C_WRITE command can only carry up to 11 bytes,
so every i2c write was capped at that size via i2c max_write
quirk.
CCI v1.2 introduces burst mode support, where consecutive
write commands (marked as burst) run back-to-back as a single
transfer.
Use this in cci_i2c_write() to allow longer writes across the
whole queue instead of a single command's payload, and raise
max_write_len accordingly for every CCI revision that supports
burst mode.
unlock/lock commands are required to ensure the commands for
a given transfer are executed atomically.
Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
---
drivers/i2c/busses/i2c-qcom-cci.c | 44 +++++++++++++++++++++++++++++++--------
1 file changed, 35 insertions(+), 9 deletions(-)
diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
index c0b39d419e296454a083d38ce302940875b8ad2b..9554d42e6b976ef33f6421a98209c2fb837e9698 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -85,14 +85,24 @@
#define NUM_QUEUES 2
#define CCI_I2C_SET_PARAM 1
+#define CCI_I2C_LOCK 6
+#define CCI_I2C_UNLOCK 7
#define CCI_I2C_REPORT 8
#define CCI_I2C_WRITE 9
#define CCI_I2C_READ 10
+#define CCI_I2C_REPORT_IRQ_EN BIT(8)
+
#define CCI_I2C_WRITE_WC 3
+#define CCI_I2C_WRITE_MAX_LEN (CCI_I2C_WRITE_WC * sizeof(u32) - 1)
#define CCI_I2C_WRITE_NWORDS(len) DIV_ROUND_UP((len) + 1, sizeof(u32))
+#define CCI_I2C_WRITE_BURST 0xf
+#define CCI_I2C_BURST_OVERHEAD 4 /* LOCK + SET_PARAM + UNLOCK + REPORT */
-#define CCI_I2C_REPORT_IRQ_EN BIT(8)
+/* Largest write that can be bursted through a queue of @qsize words */
+#define CCI_I2C_BURST_MAX_LEN(qsize) \
+ (((qsize) - CCI_I2C_BURST_OVERHEAD) / CCI_I2C_WRITE_WC * \
+ CCI_I2C_WRITE_MAX_LEN)
enum {
I2C_MODE_STANDARD,
@@ -520,14 +530,15 @@ static int cci_i2c_read(struct cci *cci, u16 master,
return 0;
}
-static void cci_i2c_load_write(u8 *buf, u16 len, void __iomem *loadq)
+static void cci_i2c_load_write(void __iomem *loadq, u8 *buf, u16 len, bool burst)
{
u32 cmd[CCI_I2C_WRITE_WC] = { };
- if (WARN_ON(len >= CCI_I2C_WRITE_WC * sizeof(u32)))
+ if (WARN_ON(len > CCI_I2C_WRITE_MAX_LEN ||
+ (burst && len != CCI_I2C_WRITE_MAX_LEN)))
return;
- cmd[0] = CCI_I2C_WRITE | len << 4;
+ cmd[0] = CCI_I2C_WRITE | (burst ? CCI_I2C_WRITE_BURST : len) << 4;
memcpy((u8 *)cmd + 1, buf, len);
iowrite32_rep(loadq, cmd, CCI_I2C_WRITE_NWORDS(len));
}
@@ -536,9 +547,12 @@ static int cci_i2c_write(struct cci *cci, u16 master,
u16 addr, u8 *buf, u16 len)
{
void __iomem *loadq = cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, QUEUE_0);
+ bool burst = len > CCI_I2C_WRITE_MAX_LEN;
int ret;
u32 val;
+ dev_dbg(cci->dev, "master %d write: len=%u\n", master, len);
+
/*
* Call validate queue to make sure queue is empty before starting.
* This is to avoid overflow / underflow of queue.
@@ -547,10 +561,22 @@ static int cci_i2c_write(struct cci *cci, u16 master,
if (ret < 0)
return ret;
+ if (burst)
+ writel(CCI_I2C_LOCK, loadq);
+
val = CCI_I2C_SET_PARAM | (addr & 0x7f) << 4;
writel(val, loadq);
- cci_i2c_load_write(buf, len, loadq);
+ do {
+ u16 to_write = min_t(u16, len, CCI_I2C_WRITE_MAX_LEN);
+
+ len -= to_write;
+ cci_i2c_load_write(loadq, buf, to_write, len > 0);
+ buf += to_write;
+ } while (len);
+
+ if (burst)
+ writel(CCI_I2C_UNLOCK, loadq);
val = CCI_I2C_REPORT | CCI_I2C_REPORT_IRQ_EN;
writel(val, loadq);
@@ -712,7 +738,7 @@ static const struct cci_data cci_hw_catalog[] = {
.max_mode = I2C_MODE_FAST_PLUS,
.queue_size = { 64, 16 },
.quirks = {
- .max_write_len = 11,
+ .max_write_len = CCI_I2C_BURST_MAX_LEN(64),
.max_read_len = 12,
},
},
@@ -721,7 +747,7 @@ static const struct cci_data cci_hw_catalog[] = {
.max_mode = I2C_MODE_FAST_PLUS,
.queue_size = { 128, 32 },
.quirks = {
- .max_write_len = 11,
+ .max_write_len = CCI_I2C_BURST_MAX_LEN(128),
.max_read_len = 12,
},
},
@@ -730,7 +756,7 @@ static const struct cci_data cci_hw_catalog[] = {
.max_mode = I2C_MODE_FAST_PLUS,
.queue_size = { 128, 32 },
.quirks = {
- .max_write_len = 11,
+ .max_write_len = CCI_I2C_BURST_MAX_LEN(128),
.max_read_len = 12,
},
},
@@ -739,7 +765,7 @@ static const struct cci_data cci_hw_catalog[] = {
.max_mode = I2C_MODE_FAST_PLUS,
.queue_size = { 1024, 32 },
.quirks = {
- .max_write_len = 11,
+ .max_write_len = CCI_I2C_BURST_MAX_LEN(1024),
.max_read_len = 12,
},
},
--
2.34.1
next prev parent reply other threads:[~2026-10-04 19:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-04 19:09 [PATCH 0/5] i2c: qcom-cci: Runtime capability detection and improved read/write Loic Poulain
2026-10-04 19:09 ` [PATCH 1/5] i2c: qcom-cci: Factor out write command queue programming Loic Poulain
2026-10-04 19:09 ` [PATCH 2/5] i2c: qcom-cci: Handle and report queue overflow/underflow interrupts Loic Poulain
2026-10-04 19:09 ` [PATCH 3/5] i2c: qcom-cci: Detect capabilities from CCI_HW_VERSION at runtime Loic Poulain
2026-10-04 19:09 ` Loic Poulain [this message]
2026-10-04 19:09 ` [PATCH 5/5] i2c: qcom-cci: Extend i2c read limits based on CCI revision Loic Poulain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261004-cci-imp-v1-4-227d12cb4829@oss.qualcomm.com \
--to=loic.poulain@oss.qualcomm.com \
--cc=andi.shyti@kernel.org \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rfoss@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®