[PATCH 5/5] i2c: qcom-cci: Extend i2c read limits based on CCI revision
From: Loic Poulain
Date: Sun Oct 04 2026 - 15:11:37 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.
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 9554d42e6b976ef33f6421a98209c2fb837e9698..586283b2cb5f4d54a13e54da70812c1fc033b242 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -104,6 +104,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,
@@ -483,7 +486,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.
@@ -511,21 +513,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;
}
@@ -730,7 +727,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),
},
},
{
@@ -739,7 +736,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),
},
},
{
@@ -748,7 +745,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),
},
},
{
@@ -757,7 +754,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),
},
},
{
@@ -766,7 +763,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