[PATCH 4/5] i2c: qcom-cci: Add burst write support

From: Loic Poulain

Date: Sun Oct 04 2026 - 15:11:12 EST


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@xxxxxxxxxxxxxxxx>
---
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