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 5/5] i2c: qcom-cci: Extend i2c read limits based on CCI revision
Date: Sun, 04 Oct 2026 21:09:51 +0200 [thread overview]
Message-ID: <20261004-cci-imp-v1-5-227d12cb4829@oss.qualcomm.com> (raw)
In-Reply-To: <20261004-cci-imp-v1-0-227d12cb4829@oss.qualcomm.com>
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@oss.qualcomm.com>
---
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
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 ` [PATCH 4/5] i2c: qcom-cci: Add burst write support Loic Poulain
2026-10-04 19:09 ` Loic Poulain [this message]
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-5-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®