[PATCH v4 5/7] i2c: qcom-cci: Extend i2c read limits based on CCI revision

From: Loic Poulain

Date: Mon Nov 09 2026 - 09:10:19 EST


max_read_len was hardcoded to 12 bytes for all CCI revisions, but
this does not reflect the actual hardware limits. Depending on the
CCI version, the maximum read size is either 14 bytes (16 - 2) or
254 bytes (256 - 2), corresponding to FIFO_SIZE - 2. Two FIFO
bytes are reserved by the hardware, with the first and last bytes
used for metadata such as slave ID/address reporting.

Add CCI_I2C_READ_MAX_LEN macro to derive max_read_len from each
revision's FIFO size instead of hardcoding it and adjust the
values according the hardware revisions.

Improve the FIFO read procedure, read the first word, discard
its ID-echo byte, then drain the remaining words in a plain loop.
Switch to readl_relaxed() for the FIFO reads, since the preceding
wait_for_completion_timeout() already orders them against the
hardware's completion interrupt.

Reviewed-by: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
Signed-off-by: Loic Poulain <loic.poulain@xxxxxxxxxxxxxxxx>
---
drivers/i2c/busses/i2c-qcom-cci.c | 37 +++++++++++++++++--------------------
1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
index a698130f4712492847336e401c0789b1a64dd02e..2e10e9775cffe57f291c48176ceda4ec14411db3 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -106,6 +106,9 @@
(((qsize) - CCI_I2C_BURST_OVERHEAD) / CCI_I2C_WRITE_WC * \
CCI_I2C_WRITE_MAX_LEN)

+/* The first and last bytes are reserved - not payload */
+#define CCI_I2C_READ_MAX_LEN(fsize) ((fsize) - 2)
+
enum {
I2C_MODE_STANDARD,
I2C_MODE_FAST,
@@ -479,7 +482,6 @@ static int cci_i2c_read(struct cci *cci, u16 master,
u32 val, words_read, words_exp;
u8 queue = QUEUE_1;
int i, index = 0, ret;
- bool first = true;

/*
* Call validate queue to make sure queue is empty before starting.
@@ -507,21 +509,16 @@ static int cci_i2c_read(struct cci *cci, u16 master,
return -EIO;
}

- do {
- val = readl(cci->base + CCI_I2C_Mm_READ_DATA(master));
-
- for (i = 0; i < 4 && index < len; i++) {
- if (first) {
- /* The LS byte of this register represents the
- * first byte read from the slave during a read
- * access.
- */
- first = false;
- continue;
- }
+ /* The first byte of the read is the slave ID echo, not payload */
+ val = readl_relaxed(cci->base + CCI_I2C_Mm_READ_DATA(master));
+ for (i = 1; i < 4 && index < len; i++)
+ buf[index++] = (val >> (i * 8)) & 0xff;
+
+ while (--words_read) {
+ val = readl_relaxed(cci->base + CCI_I2C_Mm_READ_DATA(master));
+ for (i = 0; i < 4 && index < len; i++)
buf[index++] = (val >> (i * 8)) & 0xff;
- }
- } while (--words_read);
+ }

return 0;
}
@@ -734,7 +731,7 @@ static const struct cci_data cci_hw_catalog[] = {
.queue_size = { 64, 16 },
.quirks = {
.max_write_len = 10,
- .max_read_len = 12,
+ .max_read_len = CCI_I2C_READ_MAX_LEN(16),
},
},
{
@@ -743,7 +740,7 @@ static const struct cci_data cci_hw_catalog[] = {
.queue_size = { 64, 16 },
.quirks = {
.max_write_len = CCI_I2C_BURST_MAX_LEN(64),
- .max_read_len = 12,
+ .max_read_len = CCI_I2C_READ_MAX_LEN(16),
},
},
{
@@ -752,7 +749,7 @@ static const struct cci_data cci_hw_catalog[] = {
.queue_size = { 128, 32 },
.quirks = {
.max_write_len = CCI_I2C_BURST_MAX_LEN(128),
- .max_read_len = 12,
+ .max_read_len = CCI_I2C_READ_MAX_LEN(16),
},
},
{
@@ -761,7 +758,7 @@ static const struct cci_data cci_hw_catalog[] = {
.queue_size = { 128, 32 },
.quirks = {
.max_write_len = CCI_I2C_BURST_MAX_LEN(128),
- .max_read_len = 12,
+ .max_read_len = CCI_I2C_READ_MAX_LEN(256),
},
},
{
@@ -770,7 +767,7 @@ static const struct cci_data cci_hw_catalog[] = {
.queue_size = { 1024, 32 },
.quirks = {
.max_write_len = CCI_I2C_BURST_MAX_LEN(1024),
- .max_read_len = 12,
+ .max_read_len = CCI_I2C_READ_MAX_LEN(256),
},
},
};

--
2.34.1