* [PATCH v2 1/6] i2c: qcom-cci: Factor out write command queue programming
2026-10-13 10:30 [PATCH v2 0/6] i2c: qcom-cci: Runtime capability detection and improved read/write Loic Poulain
@ 2026-10-13 10:30 ` Loic Poulain
2026-10-14 12:53 ` Bryan O'Donoghue
2026-10-13 10:30 ` [PATCH v2 2/6] i2c: qcom-cci: Handle and report queue overflow/underflow interrupts Loic Poulain
` (4 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Loic Poulain @ 2026-10-13 10:30 UTC (permalink / raw)
To: Robert Foss, Andi Shyti, Konrad Dybcio
Cc: linux-i2c, linux-arm-msm, linux-kernel, Loic Poulain
Factor out write-command queueing into a dedicated helper and replace
the manual byte-to-word packing code with iowrite32_rep().
The resulting code is easier to follow and will be reused by
upcoming burst-write support.
Also add a sanity check on the write buffer length, which should
already be validated by the caller/I2C-core.
Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
---
drivers/i2c/busses/i2c-qcom-cci.c | 41 +++++++++++++++++++++------------------
1 file changed, 22 insertions(+), 19 deletions(-)
diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
index d509dc1c14700d9c199d67df19082bae4f1ae470..3304760411082b72e10e529a2bd66361e100fa06 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -77,6 +77,9 @@
#define CCI_I2C_WRITE 9
#define CCI_I2C_READ 10
+#define CCI_I2C_WRITE_WC 3
+#define CCI_I2C_WRITE_NWORDS(len) DIV_ROUND_UP((len) + 1, sizeof(u32))
+
#define CCI_I2C_REPORT_IRQ_EN BIT(8)
enum {
@@ -485,42 +488,42 @@ 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)
+{
+ u32 cmd[CCI_I2C_WRITE_WC] = { };
+
+ if (WARN_ON(len >= CCI_I2C_WRITE_WC * sizeof(u32)))
+ return;
+
+ cmd[0] = CCI_I2C_WRITE | len << 4;
+ memcpy((u8 *)cmd + 1, buf, len);
+ iowrite32_rep(loadq, cmd, CCI_I2C_WRITE_NWORDS(len));
+}
+
static int cci_i2c_write(struct cci *cci, u16 master,
u16 addr, u8 *buf, u16 len)
{
- u8 queue = QUEUE_0;
- u8 load[12] = { 0 };
- int i = 0, j, ret;
+ void __iomem *loadq = cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, QUEUE_0);
+ int ret;
u32 val;
/*
* Call validate queue to make sure queue is empty before starting.
* This is to avoid overflow / underflow of queue.
*/
- ret = cci_validate_queue(cci, master, queue);
+ ret = cci_validate_queue(cci, master, QUEUE_0);
if (ret < 0)
return ret;
val = CCI_I2C_SET_PARAM | (addr & 0x7f) << 4;
- writel(val, cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, queue));
+ writel(val, loadq);
- load[i++] = CCI_I2C_WRITE | len << 4;
-
- for (j = 0; j < len; j++)
- load[i++] = buf[j];
-
- for (j = 0; j < i; j += 4) {
- val = load[j];
- val |= load[j + 1] << 8;
- val |= load[j + 2] << 16;
- val |= load[j + 3] << 24;
- writel(val, cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, queue));
- }
+ cci_i2c_load_write(buf, len, loadq);
val = CCI_I2C_REPORT | CCI_I2C_REPORT_IRQ_EN;
- writel(val, cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, queue));
+ writel(val, loadq);
- return cci_run_queue(cci, master, queue);
+ return cci_run_queue(cci, master, QUEUE_0);
}
static int cci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
--
2.34.1
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2 1/6] i2c: qcom-cci: Factor out write command queue programming
2026-10-13 10:30 ` [PATCH v2 1/6] i2c: qcom-cci: Factor out write command queue programming Loic Poulain
@ 2026-10-14 12:53 ` Bryan O'Donoghue
2026-10-14 13:18 ` Loic Poulain
0 siblings, 1 reply; 11+ messages in thread
From: Bryan O'Donoghue @ 2026-10-14 12:53 UTC (permalink / raw)
To: Loic Poulain, Robert Foss, Andi Shyti, Konrad Dybcio
Cc: linux-i2c, linux-arm-msm, linux-kernel
On 13/10/2026 11:30, Loic Poulain wrote:
> Factor out write-command queueing into a dedicated helper and replace
> the manual byte-to-word packing code with iowrite32_rep().
>
> The resulting code is easier to follow and will be reused by
> upcoming burst-write support.
>
> Also add a sanity check on the write buffer length, which should
> already be validated by the caller/I2C-core.
>
> Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
> ---
> drivers/i2c/busses/i2c-qcom-cci.c | 41 +++++++++++++++++++++------------------
> 1 file changed, 22 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
> index d509dc1c14700d9c199d67df19082bae4f1ae470..3304760411082b72e10e529a2bd66361e100fa06 100644
> --- a/drivers/i2c/busses/i2c-qcom-cci.c
> +++ b/drivers/i2c/busses/i2c-qcom-cci.c
> @@ -77,6 +77,9 @@
> #define CCI_I2C_WRITE 9
> #define CCI_I2C_READ 10
>
> +#define CCI_I2C_WRITE_WC 3
> +#define CCI_I2C_WRITE_NWORDS(len) DIV_ROUND_UP((len) + 1, sizeof(u32))
> +
> #define CCI_I2C_REPORT_IRQ_EN BIT(8)
>
> enum {
> @@ -485,42 +488,42 @@ 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)
> +{
> + u32 cmd[CCI_I2C_WRITE_WC] = { };
> +
> + if (WARN_ON(len >= CCI_I2C_WRITE_WC * sizeof(u32)))
> + return;
Why not trap this and return the error - cci_i2c_write() has a result code.
> +
> + cmd[0] = CCI_I2C_WRITE | len << 4;
> + memcpy((u8 *)cmd + 1, buf, len);
> + iowrite32_rep(loadq, cmd, CCI_I2C_WRITE_NWORDS(len));
> +}
> +
> static int cci_i2c_write(struct cci *cci, u16 master,
> u16 addr, u8 *buf, u16 len)
> {
> - u8 queue = QUEUE_0;
> - u8 load[12] = { 0 };
> - int i = 0, j, ret;
> + void __iomem *loadq = cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, QUEUE_0);
> + int ret;
> u32 val;
>
> /*
> * Call validate queue to make sure queue is empty before starting.
> * This is to avoid overflow / underflow of queue.
> */
> - ret = cci_validate_queue(cci, master, queue);
> + ret = cci_validate_queue(cci, master, QUEUE_0);
> if (ret < 0)
> return ret;
>
> val = CCI_I2C_SET_PARAM | (addr & 0x7f) << 4;
> - writel(val, cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, queue));
> + writel(val, loadq);
>
> - load[i++] = CCI_I2C_WRITE | len << 4;
> -
> - for (j = 0; j < len; j++)
> - load[i++] = buf[j];
> -
> - for (j = 0; j < i; j += 4) {
> - val = load[j];
> - val |= load[j + 1] << 8;
> - val |= load[j + 2] << 16;
> - val |= load[j + 3] << 24;
> - writel(val, cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, queue));
> - }
> + cci_i2c_load_write(buf, len, loadq);
>
> val = CCI_I2C_REPORT | CCI_I2C_REPORT_IRQ_EN;
> - writel(val, cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, queue));
> + writel(val, loadq);
>
> - return cci_run_queue(cci, master, queue);
> + return cci_run_queue(cci, master, QUEUE_0);
> }
>
> static int cci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
>
> --
> 2.34.1
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2 1/6] i2c: qcom-cci: Factor out write command queue programming
2026-10-14 12:53 ` Bryan O'Donoghue
@ 2026-10-14 13:18 ` Loic Poulain
0 siblings, 0 replies; 11+ messages in thread
From: Loic Poulain @ 2026-10-14 13:18 UTC (permalink / raw)
To: Bryan O'Donoghue
Cc: Robert Foss, Andi Shyti, Konrad Dybcio, linux-i2c, linux-arm-msm,
linux-kernel
On Wed, Oct 14, 2026 at 2:53 PM Bryan O'Donoghue <bod.linux@nxsw.ie> wrote:
>
> On 13/10/2026 11:30, Loic Poulain wrote:
> > Factor out write-command queueing into a dedicated helper and replace
> > the manual byte-to-word packing code with iowrite32_rep().
> >
> > The resulting code is easier to follow and will be reused by
> > upcoming burst-write support.
> >
> > Also add a sanity check on the write buffer length, which should
> > already be validated by the caller/I2C-core.
> >
> > Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
> > ---
> > drivers/i2c/busses/i2c-qcom-cci.c | 41 +++++++++++++++++++++------------------
> > 1 file changed, 22 insertions(+), 19 deletions(-)
> >
> > diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
> > index d509dc1c14700d9c199d67df19082bae4f1ae470..3304760411082b72e10e529a2bd66361e100fa06 100644
> > --- a/drivers/i2c/busses/i2c-qcom-cci.c
> > +++ b/drivers/i2c/busses/i2c-qcom-cci.c
> > @@ -77,6 +77,9 @@
> > #define CCI_I2C_WRITE 9
> > #define CCI_I2C_READ 10
> >
> > +#define CCI_I2C_WRITE_WC 3
> > +#define CCI_I2C_WRITE_NWORDS(len) DIV_ROUND_UP((len) + 1, sizeof(u32))
> > +
> > #define CCI_I2C_REPORT_IRQ_EN BIT(8)
> >
> > enum {
> > @@ -485,42 +488,42 @@ 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)
> > +{
> > + u32 cmd[CCI_I2C_WRITE_WC] = { };
> > +
> > + if (WARN_ON(len >= CCI_I2C_WRITE_WC * sizeof(u32)))
> > + return;
>
> Why not trap this and return the error - cci_i2c_write() has a result code.
Because this condition should never occur, the I2C core is expected to
enforce the transfer length limit through our max_write_len quirk
before the request reaches the driver. This check is purely paranoid
and is not expected to trigger even in normal error-handling paths.
Not returning errors keeps the behavior aligned with the previous
version, though we could have catched this issue earlier in i2c_write
and return from there...
>
> > +
> > + cmd[0] = CCI_I2C_WRITE | len << 4;
> > + memcpy((u8 *)cmd + 1, buf, len);
> > + iowrite32_rep(loadq, cmd, CCI_I2C_WRITE_NWORDS(len));
> > +}
> > +
> > static int cci_i2c_write(struct cci *cci, u16 master,
> > u16 addr, u8 *buf, u16 len)
> > {
> > - u8 queue = QUEUE_0;
> > - u8 load[12] = { 0 };
> > - int i = 0, j, ret;
> > + void __iomem *loadq = cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, QUEUE_0);
> > + int ret;
> > u32 val;
> >
> > /*
> > * Call validate queue to make sure queue is empty before starting.
> > * This is to avoid overflow / underflow of queue.
> > */
> > - ret = cci_validate_queue(cci, master, queue);
> > + ret = cci_validate_queue(cci, master, QUEUE_0);
> > if (ret < 0)
> > return ret;
> >
> > val = CCI_I2C_SET_PARAM | (addr & 0x7f) << 4;
> > - writel(val, cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, queue));
> > + writel(val, loadq);
> >
> > - load[i++] = CCI_I2C_WRITE | len << 4;
> > -
> > - for (j = 0; j < len; j++)
> > - load[i++] = buf[j];
> > -
> > - for (j = 0; j < i; j += 4) {
> > - val = load[j];
> > - val |= load[j + 1] << 8;
> > - val |= load[j + 2] << 16;
> > - val |= load[j + 3] << 24;
> > - writel(val, cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, queue));
> > - }
> > + cci_i2c_load_write(buf, len, loadq);
> >
> > val = CCI_I2C_REPORT | CCI_I2C_REPORT_IRQ_EN;
> > - writel(val, cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, queue));
> > + writel(val, loadq);
> >
> > - return cci_run_queue(cci, master, queue);
> > + return cci_run_queue(cci, master, QUEUE_0);
> > }
> >
> > static int cci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
> >
> > --
> > 2.34.1
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 2/6] i2c: qcom-cci: Handle and report queue overflow/underflow interrupts
2026-10-13 10:30 [PATCH v2 0/6] i2c: qcom-cci: Runtime capability detection and improved read/write Loic Poulain
2026-10-13 10:30 ` [PATCH v2 1/6] i2c: qcom-cci: Factor out write command queue programming Loic Poulain
@ 2026-10-13 10:30 ` Loic Poulain
2026-10-14 12:55 ` Bryan O'Donoghue
2026-10-13 10:30 ` [PATCH v2 3/6] i2c: qcom-cci: Detect capabilities from CCI_HW_VERSION at runtime Loic Poulain
` (3 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Loic Poulain @ 2026-10-13 10:30 UTC (permalink / raw)
To: Robert Foss, Andi Shyti, Konrad Dybcio
Cc: linux-i2c, linux-arm-msm, linux-kernel, Loic Poulain
CCI_IRQ_STATUS_0_I2C_Mx_ERROR aggregates the per-queue overflow and
underflow bits together with NACK_ERR, and all of them were
handled the same way: report -EIO and halt the queue. There was no
way to tell a NACK apart from a FIFO overflow/underflow in the logs.
Decode the individual overflow/underflow bits for each queue and
report them with dev_warn_ratelimited() as such errors are not
expected in normal operation.
Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
---
drivers/i2c/busses/i2c-qcom-cci.c | 34 ++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
index 3304760411082b72e10e529a2bd66361e100fa06..099da0069251681cc52e351fb656bd73e78a96c9 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -54,10 +54,18 @@
#define CCI_IRQ_STATUS_0 0xc0c
#define CCI_IRQ_STATUS_0_I2C_M0_RD_DONE BIT(0)
#define CCI_IRQ_STATUS_0_I2C_M0_Q0_REPORT BIT(4)
+#define CCI_IRQ_STATUS_0_I2C_M0_Q0_UNDERFLOW BIT(5)
+#define CCI_IRQ_STATUS_0_I2C_M0_Q0_OVERFLOW BIT(6)
#define CCI_IRQ_STATUS_0_I2C_M0_Q1_REPORT BIT(8)
+#define CCI_IRQ_STATUS_0_I2C_M0_Q1_UNDERFLOW BIT(9)
+#define CCI_IRQ_STATUS_0_I2C_M0_Q1_OVERFLOW BIT(10)
#define CCI_IRQ_STATUS_0_I2C_M1_RD_DONE BIT(12)
#define CCI_IRQ_STATUS_0_I2C_M1_Q0_REPORT BIT(16)
+#define CCI_IRQ_STATUS_0_I2C_M1_Q0_UNDERFLOW BIT(17)
+#define CCI_IRQ_STATUS_0_I2C_M1_Q0_OVERFLOW BIT(18)
#define CCI_IRQ_STATUS_0_I2C_M1_Q1_REPORT BIT(20)
+#define CCI_IRQ_STATUS_0_I2C_M1_Q1_UNDERFLOW BIT(21)
+#define CCI_IRQ_STATUS_0_I2C_M1_Q1_OVERFLOW BIT(22)
#define CCI_IRQ_STATUS_0_RST_DONE_ACK BIT(24)
#define CCI_IRQ_STATUS_0_I2C_M0_Q0Q1_HALT_ACK BIT(25)
#define CCI_IRQ_STATUS_0_I2C_M1_Q0Q1_HALT_ACK BIT(26)
@@ -190,22 +198,40 @@ static irqreturn_t cci_isr(int irq, void *dev)
writel(reset, cci->base + CCI_RESET_CMD);
if (unlikely(val & CCI_IRQ_STATUS_0_I2C_M0_ERROR)) {
+ cci->master[0].status = -EIO;
+
if (val & CCI_IRQ_STATUS_0_I2C_M0_Q0_NACK_ERR ||
val & CCI_IRQ_STATUS_0_I2C_M0_Q1_NACK_ERR)
cci->master[0].status = -ENXIO;
- else
- cci->master[0].status = -EIO;
+
+ if (val & CCI_IRQ_STATUS_0_I2C_M0_Q0_OVERFLOW)
+ dev_warn_ratelimited(cci->dev, "master 0 queue 0 overflow\n");
+ if (val & CCI_IRQ_STATUS_0_I2C_M0_Q0_UNDERFLOW)
+ dev_warn_ratelimited(cci->dev, "master 0 queue 0 underflow\n");
+ if (val & CCI_IRQ_STATUS_0_I2C_M0_Q1_OVERFLOW)
+ dev_warn_ratelimited(cci->dev, "master 0 queue 1 overflow\n");
+ if (val & CCI_IRQ_STATUS_0_I2C_M0_Q1_UNDERFLOW)
+ dev_warn_ratelimited(cci->dev, "master 0 queue 1 underflow\n");
writel(CCI_HALT_REQ_I2C_M0_Q0Q1, cci->base + CCI_HALT_REQ);
ret = IRQ_HANDLED;
}
if (unlikely(val & CCI_IRQ_STATUS_0_I2C_M1_ERROR)) {
+ cci->master[1].status = -EIO;
+
if (val & CCI_IRQ_STATUS_0_I2C_M1_Q0_NACK_ERR ||
val & CCI_IRQ_STATUS_0_I2C_M1_Q1_NACK_ERR)
cci->master[1].status = -ENXIO;
- else
- cci->master[1].status = -EIO;
+
+ if (val & CCI_IRQ_STATUS_0_I2C_M1_Q0_OVERFLOW)
+ dev_warn_ratelimited(cci->dev, "master 1 queue 0 overflow\n");
+ if (val & CCI_IRQ_STATUS_0_I2C_M1_Q0_UNDERFLOW)
+ dev_warn_ratelimited(cci->dev, "master 1 queue 0 underflow\n");
+ if (val & CCI_IRQ_STATUS_0_I2C_M1_Q1_OVERFLOW)
+ dev_warn_ratelimited(cci->dev, "master 1 queue 1 overflow\n");
+ if (val & CCI_IRQ_STATUS_0_I2C_M1_Q1_UNDERFLOW)
+ dev_warn_ratelimited(cci->dev, "master 1 queue 1 underflow\n");
writel(CCI_HALT_REQ_I2C_M1_Q0Q1, cci->base + CCI_HALT_REQ);
ret = IRQ_HANDLED;
--
2.34.1
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2 2/6] i2c: qcom-cci: Handle and report queue overflow/underflow interrupts
2026-10-13 10:30 ` [PATCH v2 2/6] i2c: qcom-cci: Handle and report queue overflow/underflow interrupts Loic Poulain
@ 2026-10-14 12:55 ` Bryan O'Donoghue
0 siblings, 0 replies; 11+ messages in thread
From: Bryan O'Donoghue @ 2026-10-14 12:55 UTC (permalink / raw)
To: Loic Poulain, Robert Foss, Andi Shyti, Konrad Dybcio
Cc: linux-i2c, linux-arm-msm, linux-kernel
On 13/10/2026 11:30, Loic Poulain wrote:
> CCI_IRQ_STATUS_0_I2C_Mx_ERROR aggregates the per-queue overflow and
> underflow bits together with NACK_ERR, and all of them were
> handled the same way: report -EIO and halt the queue. There was no
> way to tell a NACK apart from a FIFO overflow/underflow in the logs.
>
> Decode the individual overflow/underflow bits for each queue and
> report them with dev_warn_ratelimited() as such errors are not
> expected in normal operation.
>
> Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 3/6] i2c: qcom-cci: Detect capabilities from CCI_HW_VERSION at runtime
2026-10-13 10:30 [PATCH v2 0/6] i2c: qcom-cci: Runtime capability detection and improved read/write Loic Poulain
2026-10-13 10:30 ` [PATCH v2 1/6] i2c: qcom-cci: Factor out write command queue programming Loic Poulain
2026-10-13 10:30 ` [PATCH v2 2/6] i2c: qcom-cci: Handle and report queue overflow/underflow interrupts Loic Poulain
@ 2026-10-13 10:30 ` Loic Poulain
2026-10-13 10:30 ` [PATCH v2 4/6] i2c: qcom-cci: Add burst write support Loic Poulain
` (2 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Loic Poulain @ 2026-10-13 10:30 UTC (permalink / raw)
To: Robert Foss, Andi Shyti, Konrad Dybcio
Cc: linux-i2c, linux-arm-msm, linux-kernel, Loic Poulain
In theory, every SoC integrating a CCI revision that differs from
an existing one should introduce a dedicated compatible string.
In practice, most CCI instances still fall back to the msm8996
compat (v1.4.0), one of the oldest supported versions. In order
to take advantage of capabilities introduced in later versions,
such as larger queues (v1.6.0) or threshold IRQ support (v1.7.0),
we need to properly distinguish the different variants.
Replace the static per-compatible cci_data definitions with a
version-sorted capability table keyed by (hw_major, hw_minor).
During probe, read CCI hardware revision register and select
the newest capability entry whose version is less than or equal
to the detected hardware revision. This allows revisions to
automatically inherit the closest supported capability set
without requiring additional compatible strings.
Several compatibles that currently fall back to the msm8996
configuration (e.g. sdm845, sm8250 and sm8450) will now resolve
to the corresponding capability tier, gaining access to their
larger queue sizes instead of the conservative msm8996 defaults.
- v1.2.x CCI increase I2C write payload + burst write support
- v1.6.x CCI has increased queue sizes (64,16) -> (128,32)
- v1.7.x CCI introduces threshold IRQs (leveraged later)
- v1.10.x CCI increase queue 0 size (128) -> (1024)
Suggested-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
---
drivers/i2c/busses/i2c-qcom-cci.c | 162 +++++++++++++++++++++++++-------------
1 file changed, 106 insertions(+), 56 deletions(-)
diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
index 099da0069251681cc52e351fb656bd73e78a96c9..3bca29f1d2699375a0348b18a5a2e646a59fd94c 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -2,6 +2,7 @@
// Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
// Copyright (c) 2017-2022 Linaro Limited.
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/completion.h>
#include <linux/i2c.h>
@@ -14,6 +15,10 @@
#include <linux/pm_opp.h>
#define CCI_HW_VERSION 0x0
+#define CCI_HW_VERSION_MAJOR_MASK GENMASK(31, 28)
+#define CCI_HW_VERSION_MINOR_MASK GENMASK(27, 16)
+#define CCI_HW_VERSION_STEP_MASK GENMASK(15, 0)
+#define QCOM_CCI_VERSION(major, minor) .hw_major = (major), .hw_minor = (minor)
#define CCI_RESET_CMD 0x004
#define CCI_RESET_CMD_MASK 0x0f73f3f7
#define CCI_RESET_CMD_M0_MASK 0x000003f1
@@ -133,7 +138,8 @@ struct cci_master {
};
struct cci_data {
- unsigned int num_masters;
+ u16 hw_major;
+ u16 hw_minor;
struct i2c_adapter_quirks quirks;
u16 queue_size[NUM_QUEUES];
/* Highest I2C mode supported by this variant. */
@@ -144,6 +150,7 @@ struct cci {
struct device *dev;
void __iomem *base;
unsigned int irq;
+ unsigned int num_masters;
const struct cci_data *data;
struct clk_bulk_data *clocks;
int nclocks;
@@ -245,7 +252,7 @@ static int cci_halt(struct cci *cci, u8 master_num)
struct cci_master *master;
u32 val;
- if (master_num >= cci->data->num_masters) {
+ if (master_num >= cci->num_masters) {
dev_err(cci->dev, "Unsupported master idx (%u)\n", master_num);
return -EINVAL;
}
@@ -371,7 +378,7 @@ static int cci_init(struct cci *cci)
writel(val, cci->base + CCI_IRQ_MASK_0);
- for (i = 0; i < cci->data->num_masters; i++) {
+ for (i = 0; i < cci->num_masters; i++) {
int mode = cci->master[i].mode;
const struct hw_params *hw;
@@ -615,7 +622,7 @@ static int cci_get_required_rate(struct cci *cci, unsigned long *rate)
for (int ri = 0; ri < NUM_CCI_CLK_RATES; ri++) {
bool supported = true;
- for (int i = 0; i < cci->data->num_masters; i++) {
+ for (int i = 0; i < cci->num_masters; i++) {
int mode = cci->master[i].mode;
if (!cci->master[i].cci)
@@ -690,6 +697,81 @@ static const struct dev_pm_ops qcom_cci_pm = {
SET_RUNTIME_PM_OPS(cci_suspend_runtime, cci_resume_runtime, NULL)
};
+/* Hardware capabilities, ascending by version major,minor */
+static const struct cci_data cci_hw_catalog[] = {
+ {
+ QCOM_CCI_VERSION(1, 0),
+ .max_mode = I2C_MODE_FAST,
+ .queue_size = { 64, 16 },
+ .quirks = {
+ .max_write_len = 10,
+ .max_read_len = 12,
+ },
+ },
+ {
+ QCOM_CCI_VERSION(1, 2),
+ .max_mode = I2C_MODE_FAST_PLUS,
+ .queue_size = { 64, 16 },
+ .quirks = {
+ .max_write_len = 11,
+ .max_read_len = 12,
+ },
+ },
+ {
+ QCOM_CCI_VERSION(1, 6),
+ .max_mode = I2C_MODE_FAST_PLUS,
+ .queue_size = { 128, 32 },
+ .quirks = {
+ .max_write_len = 11,
+ .max_read_len = 12,
+ },
+ },
+ {
+ QCOM_CCI_VERSION(1, 7),
+ .max_mode = I2C_MODE_FAST_PLUS,
+ .queue_size = { 128, 32 },
+ .quirks = {
+ .max_write_len = 11,
+ .max_read_len = 12,
+ },
+ },
+ {
+ QCOM_CCI_VERSION(1, 10),
+ .max_mode = I2C_MODE_FAST_PLUS,
+ .queue_size = { 1024, 32 },
+ .quirks = {
+ .max_write_len = 11,
+ .max_read_len = 12,
+ },
+ },
+};
+
+static void cci_detect_hw_caps(struct cci *cci, u32 hw_version)
+{
+ u8 major = FIELD_GET(CCI_HW_VERSION_MAJOR_MASK, hw_version);
+ u16 minor = FIELD_GET(CCI_HW_VERSION_MINOR_MASK, hw_version);
+ u16 step = FIELD_GET(CCI_HW_VERSION_STEP_MASK, hw_version);
+ const struct cci_data *data = &cci_hw_catalog[0];
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(cci_hw_catalog); i++) {
+ if (cci_hw_catalog[i].hw_major > major ||
+ (cci_hw_catalog[i].hw_major == major && cci_hw_catalog[i].hw_minor > minor))
+ break;
+ data = &cci_hw_catalog[i];
+ }
+
+ dev_dbg(cci->dev, "CCI HW version %u.%u.%u, using caps tier %u.%u\n",
+ major, minor, step, data->hw_major, data->hw_minor);
+
+ cci->data = data;
+
+ for (i = 0; i < cci->num_masters; i++) {
+ if (cci->master[i].cci)
+ cci->master[i].adap.quirks = &cci->data->quirks;
+ }
+}
+
static int cci_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -705,9 +787,6 @@ static int cci_probe(struct platform_device *pdev)
cci->dev = dev;
platform_set_drvdata(pdev, cci);
- cci->data = device_get_match_data(dev);
- if (!cci->data)
- return -ENOENT;
for_each_available_child_of_node(dev->of_node, child) {
struct cci_master *master;
@@ -719,14 +798,16 @@ static int cci_probe(struct platform_device *pdev)
continue;
}
- if (idx >= cci->data->num_masters) {
+ if (idx >= NUM_MASTERS) {
dev_err(dev, "%pOF invalid 'reg' value: %u (max is %u)",
- child, idx, cci->data->num_masters - 1);
+ child, idx, NUM_MASTERS - 1);
continue;
}
+ if (idx >= cci->num_masters)
+ cci->num_masters = idx + 1;
+
master = &cci->master[idx];
- master->adap.quirks = &cci->data->quirks;
master->adap.algo = &cci_algo;
master->adap.dev.parent = dev;
master->adap.dev.of_node = of_node_get(child);
@@ -777,10 +858,6 @@ static int cci_probe(struct platform_device *pdev)
if (ret && ret != -ENODEV)
return dev_err_probe(dev, ret, "failed to add OPP table\n");
- ret = cci_set_core_rate(cci);
- if (ret)
- return ret;
-
ret = cci_enable_clocks(cci);
if (ret < 0)
return ret;
@@ -799,7 +876,11 @@ static int cci_probe(struct platform_device *pdev)
}
val = readl(cci->base + CCI_HW_VERSION);
- dev_dbg(dev, "CCI HW version = 0x%08x", val);
+ cci_detect_hw_caps(cci, val);
+
+ ret = cci_set_core_rate(cci);
+ if (ret)
+ goto disable_clocks;
ret = cci_reset(cci);
if (ret < 0)
@@ -810,7 +891,7 @@ static int cci_probe(struct platform_device *pdev)
pm_runtime_set_active(dev);
pm_runtime_enable(dev);
- for (i = 0; i < cci->data->num_masters; i++) {
+ for (i = 0; i < cci->num_masters; i++) {
if (!cci->master[i].cci)
continue;
@@ -844,7 +925,7 @@ static void cci_remove(struct platform_device *pdev)
struct cci *cci = platform_get_drvdata(pdev);
int i;
- for (i = 0; i < cci->data->num_masters; i++) {
+ for (i = 0; i < cci->num_masters; i++) {
if (cci->master[i].cci) {
i2c_del_adapter(&cci->master[i].adap);
of_node_put(cci->master[i].adap.dev.of_node);
@@ -856,51 +937,20 @@ static void cci_remove(struct platform_device *pdev)
pm_runtime_set_suspended(&pdev->dev);
}
-static const struct cci_data cci_v1_data = {
- .num_masters = 1,
- .queue_size = { 64, 16 },
- .quirks = {
- .max_write_len = 10,
- .max_read_len = 12,
- },
- .max_mode = I2C_MODE_FAST,
-};
-
-static const struct cci_data cci_v1_5_data = {
- .num_masters = 2,
- .queue_size = { 64, 16 },
- .quirks = {
- .max_write_len = 10,
- .max_read_len = 12,
- },
- .max_mode = I2C_MODE_FAST,
-};
-
-static const struct cci_data cci_v2_data = {
- .num_masters = 2,
- .queue_size = { 64, 16 },
- .quirks = {
- .max_write_len = 11,
- .max_read_len = 12,
- },
- .max_mode = I2C_MODE_FAST_PLUS,
-};
-
static const struct of_device_id cci_dt_match[] = {
- { .compatible = "qcom,msm8226-cci", .data = &cci_v1_data},
- { .compatible = "qcom,msm8953-cci", .data = &cci_v2_data},
- { .compatible = "qcom,msm8974-cci", .data = &cci_v1_5_data},
- { .compatible = "qcom,msm8996-cci", .data = &cci_v2_data},
-
+ { .compatible = "qcom,msm8226-cci" },
+ { .compatible = "qcom,msm8953-cci" },
+ { .compatible = "qcom,msm8974-cci" },
+ { .compatible = "qcom,msm8996-cci" },
/*
* Legacy compatibles kept for backwards compatibility.
* Do not add any new ones unless they introduce a new config
*/
- { .compatible = "qcom,msm8916-cci", .data = &cci_v1_data},
- { .compatible = "qcom,sdm845-cci", .data = &cci_v2_data},
- { .compatible = "qcom,sm8250-cci", .data = &cci_v2_data},
- { .compatible = "qcom,sm8450-cci", .data = &cci_v2_data},
+ { .compatible = "qcom,msm8916-cci" },
+ { .compatible = "qcom,sdm845-cci" },
+ { .compatible = "qcom,sm8250-cci" },
+ { .compatible = "qcom,sm8450-cci" },
{}
};
MODULE_DEVICE_TABLE(of, cci_dt_match);
--
2.34.1
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v2 4/6] i2c: qcom-cci: Add burst write support
2026-10-13 10:30 [PATCH v2 0/6] i2c: qcom-cci: Runtime capability detection and improved read/write Loic Poulain
` (2 preceding siblings ...)
2026-10-13 10:30 ` [PATCH v2 3/6] i2c: qcom-cci: Detect capabilities from CCI_HW_VERSION at runtime Loic Poulain
@ 2026-10-13 10:30 ` Loic Poulain
2026-10-14 11:22 ` Konrad Dybcio
2026-10-13 10:30 ` [PATCH v2 5/6] i2c: qcom-cci: Extend i2c read limits based on CCI revision Loic Poulain
2026-10-13 10:30 ` [PATCH v2 6/6] i2c: qcom-cci: Add burst read support Loic Poulain
5 siblings, 1 reply; 11+ messages in thread
From: Loic Poulain @ 2026-10-13 10:30 UTC (permalink / raw)
To: Robert Foss, Andi Shyti, Konrad Dybcio
Cc: linux-i2c, linux-arm-msm, linux-kernel, Loic Poulain
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 3bca29f1d2699375a0348b18a5a2e646a59fd94c..27bbd1e196f9c55c1af14168b83eb6e6d51c75ed 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -86,14 +86,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,
@@ -521,14 +531,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));
}
@@ -537,9 +548,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.
@@ -548,10 +562,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);
@@ -713,7 +739,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,
},
},
@@ -722,7 +748,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,
},
},
@@ -731,7 +757,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,
},
},
@@ -740,7 +766,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
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2 4/6] i2c: qcom-cci: Add burst write support
2026-10-13 10:30 ` [PATCH v2 4/6] i2c: qcom-cci: Add burst write support Loic Poulain
@ 2026-10-14 11:22 ` Konrad Dybcio
0 siblings, 0 replies; 11+ messages in thread
From: Konrad Dybcio @ 2026-10-14 11:22 UTC (permalink / raw)
To: Loic Poulain, Robert Foss, Andi Shyti
Cc: linux-i2c, linux-arm-msm, linux-kernel
On 10/13/26 12:30 PM, Loic Poulain wrote:
> 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.
[...]
> -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;
I think this calls for FIELD_PREP(), but we can do that as follow-up
cleanup at the end of the series
Konrad
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 5/6] i2c: qcom-cci: Extend i2c read limits based on CCI revision
2026-10-13 10:30 [PATCH v2 0/6] i2c: qcom-cci: Runtime capability detection and improved read/write Loic Poulain
` (3 preceding siblings ...)
2026-10-13 10:30 ` [PATCH v2 4/6] i2c: qcom-cci: Add burst write support Loic Poulain
@ 2026-10-13 10:30 ` Loic Poulain
2026-10-13 10:30 ` [PATCH v2 6/6] i2c: qcom-cci: Add burst read support Loic Poulain
5 siblings, 0 replies; 11+ messages in thread
From: Loic Poulain @ 2026-10-13 10:30 UTC (permalink / raw)
To: Robert Foss, Andi Shyti, Konrad Dybcio
Cc: linux-i2c, linux-arm-msm, linux-kernel, Loic Poulain
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 27bbd1e196f9c55c1af14168b83eb6e6d51c75ed..9a8d201c890622d6c1f7b6b7aa2e0d7c075008ac 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -105,6 +105,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,
@@ -484,7 +487,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.
@@ -512,21 +514,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;
}
@@ -731,7 +728,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),
},
},
{
@@ -740,7 +737,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),
},
},
{
@@ -749,7 +746,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),
},
},
{
@@ -758,7 +755,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),
},
},
{
@@ -767,7 +764,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
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH v2 6/6] i2c: qcom-cci: Add burst read support
2026-10-13 10:30 [PATCH v2 0/6] i2c: qcom-cci: Runtime capability detection and improved read/write Loic Poulain
` (4 preceding siblings ...)
2026-10-13 10:30 ` [PATCH v2 5/6] i2c: qcom-cci: Extend i2c read limits based on CCI revision Loic Poulain
@ 2026-10-13 10:30 ` Loic Poulain
5 siblings, 0 replies; 11+ messages in thread
From: Loic Poulain @ 2026-10-13 10:30 UTC (permalink / raw)
To: Robert Foss, Andi Shyti, Konrad Dybcio
Cc: linux-i2c, linux-arm-msm, linux-kernel, Loic Poulain
CCI_I2C_READ transfers are currently limited by max_read_len to the
amount of data that fits in the read FIFO, as the driver only drains
the FIFO once after receiving RD_DONE. On current hardware this limits
reads to at most 254 bytes.
CCI v1.7 and later support reads larger than the FIFO depth by
generating RD_THRESHOLD interrupts as the FIFO fills, allowing software
to drain data while the transfer is still in progress. When the FIFO
becomes full, the hardware can also apply backpressure by stretching
SCL and reports this condition through RD_PAUSE_IRQ.
Program CCI_I2C_Mm_RD_THRESHOLD to half the FIFO depth on hardware that
supports RD_THRESHOLD and update the read path to drain the FIFO on
each threshold interrupt until the final RD_DONE event is received.
Older hardware revisions do not support RD_THRESHOLD, keep their read
size limited to the FIFO depth and continue relying solely on RD_DONE
for completion.
Also emit a warning when RD_PAUSE_IRQ is observed, as FIFO backpressure
is unexpected under normal conditions and may indicate that software is
not draining the FIFO quickly enough.
Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
---
drivers/i2c/busses/i2c-qcom-cci.c | 163 +++++++++++++++++++++++++++++++++-----
1 file changed, 141 insertions(+), 22 deletions(-)
diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
index 9a8d201c890622d6c1f7b6b7aa2e0d7c075008ac..2ef4af603aa2b80614c6bff3a56424da6e4b0b5f 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -13,6 +13,7 @@
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/pm_opp.h>
+#include <linux/spinlock.h>
#define CCI_HW_VERSION 0x0
#define CCI_HW_VERSION_MAJOR_MASK GENMASK(31, 28)
@@ -36,6 +37,7 @@
#define CCI_I2C_Mm_READ_DATA(m) (0x118 + 0x100 * (m))
#define CCI_I2C_Mm_READ_BUF_LEVEL(m) (0x11c + 0x100 * (m))
+#define CCI_I2C_Mm_RD_THRESHOLD(m) (0x120 + 0x100 * (m))
#define CCI_I2C_Mm_Qn_EXEC_WORD_CNT(m, n) (0x300 + 0x200 * (m) + 0x100 * (n))
#define CCI_I2C_Mm_Qn_CUR_WORD_CNT(m, n) (0x304 + 0x200 * (m) + 0x100 * (n))
#define CCI_I2C_Mm_Qn_CUR_CMD(m, n) (0x308 + 0x200 * (m) + 0x100 * (n))
@@ -58,6 +60,7 @@
#define CCI_IRQ_CLEAR_0 0xc08
#define CCI_IRQ_STATUS_0 0xc0c
#define CCI_IRQ_STATUS_0_I2C_M0_RD_DONE BIT(0)
+#define CCI_IRQ_STATUS_0_I2C_M0_RD_UNDERFLOW BIT(1)
#define CCI_IRQ_STATUS_0_I2C_M0_Q0_REPORT BIT(4)
#define CCI_IRQ_STATUS_0_I2C_M0_Q0_UNDERFLOW BIT(5)
#define CCI_IRQ_STATUS_0_I2C_M0_Q0_OVERFLOW BIT(6)
@@ -65,6 +68,7 @@
#define CCI_IRQ_STATUS_0_I2C_M0_Q1_UNDERFLOW BIT(9)
#define CCI_IRQ_STATUS_0_I2C_M0_Q1_OVERFLOW BIT(10)
#define CCI_IRQ_STATUS_0_I2C_M1_RD_DONE BIT(12)
+#define CCI_IRQ_STATUS_0_I2C_M1_RD_UNDERFLOW BIT(13)
#define CCI_IRQ_STATUS_0_I2C_M1_Q0_REPORT BIT(16)
#define CCI_IRQ_STATUS_0_I2C_M1_Q0_UNDERFLOW BIT(17)
#define CCI_IRQ_STATUS_0_I2C_M1_Q0_OVERFLOW BIT(18)
@@ -81,6 +85,18 @@
#define CCI_IRQ_STATUS_0_I2C_M0_ERROR 0x18000ee6
#define CCI_IRQ_STATUS_0_I2C_M1_ERROR 0x60ee6000
+#define CCI_IRQ_MASK_1 0xc10
+#define CCI_IRQ_MASK_1_I2C_M0_RD_THRESHOLD BIT(16)
+#define CCI_IRQ_MASK_1_I2C_M0_RD_PAUSE BIT(17)
+#define CCI_IRQ_MASK_1_I2C_M1_RD_THRESHOLD BIT(20)
+#define CCI_IRQ_MASK_1_I2C_M1_RD_PAUSE BIT(21)
+#define CCI_IRQ_CLEAR_1 0xc14
+#define CCI_IRQ_STATUS_1 0xc18
+#define CCI_IRQ_STATUS_1_I2C_M0_RD_THRESHOLD BIT(16)
+#define CCI_IRQ_STATUS_1_I2C_M0_RD_PAUSE BIT(17)
+#define CCI_IRQ_STATUS_1_I2C_M1_RD_THRESHOLD BIT(20)
+#define CCI_IRQ_STATUS_1_I2C_M1_RD_PAUSE BIT(21)
+
#define CCI_TIMEOUT (msecs_to_jiffies(100))
#define NUM_MASTERS 2
#define NUM_QUEUES 2
@@ -108,6 +124,9 @@
/* The first and last bytes are reserved - not payload */
#define CCI_I2C_READ_MAX_LEN(fsize) ((fsize) - 2)
+/* Unlimited read via threshold-irq support */
+#define CCI_I2C_READ_BURST_NOLIMIT 0
+
enum {
I2C_MODE_STANDARD,
I2C_MODE_FAST,
@@ -169,16 +188,52 @@ struct cci {
int nclocks;
struct clk *cci_clk;
struct cci_master master[NUM_MASTERS];
+ /* Protects read-modify-write access to CCI_IRQ_MASK_1 */
+ spinlock_t threshold_lock;
};
+static bool cci_has_threshold_irq(const struct cci *cci)
+{
+ return cci->data->quirks.max_read_len == CCI_I2C_READ_BURST_NOLIMIT;
+}
+
+static void cci_set_rd_threshold_irq(struct cci *cci, u16 master, bool enable)
+{
+ u32 bits, val;
+
+ if (!cci_has_threshold_irq(cci))
+ return;
+
+ guard(spinlock_irqsave)(&cci->threshold_lock);
+
+ bits = master ? CCI_IRQ_MASK_1_I2C_M1_RD_THRESHOLD :
+ CCI_IRQ_MASK_1_I2C_M0_RD_THRESHOLD;
+
+ writel(bits, cci->base + CCI_IRQ_CLEAR_1);
+
+ val = readl(cci->base + CCI_IRQ_MASK_1);
+ if (enable)
+ val |= bits;
+ else
+ val &= ~bits;
+
+ writel(val, cci->base + CCI_IRQ_MASK_1);
+}
+
static irqreturn_t cci_isr(int irq, void *dev)
{
struct cci *cci = dev;
- u32 val, reset = 0;
+ u32 val, val1 = 0, reset = 0;
int ret = IRQ_NONE;
val = readl(cci->base + CCI_IRQ_STATUS_0);
writel(val, cci->base + CCI_IRQ_CLEAR_0);
+
+ if (cci_has_threshold_irq(cci)) {
+ val1 = readl(cci->base + CCI_IRQ_STATUS_1);
+ writel(val1, cci->base + CCI_IRQ_CLEAR_1);
+ }
+
writel(0x1, cci->base + CCI_IRQ_GLOBAL_CLEAR_CMD);
if (val & CCI_IRQ_STATUS_0_RST_DONE_ACK) {
@@ -204,6 +259,28 @@ static irqreturn_t cci_isr(int irq, void *dev)
ret = IRQ_HANDLED;
}
+ if (val1 & CCI_IRQ_STATUS_1_I2C_M0_RD_THRESHOLD) {
+ cci_set_rd_threshold_irq(cci, 0, false);
+ complete(&cci->master[0].irq_complete);
+ ret = IRQ_HANDLED;
+ }
+
+ if (val1 & CCI_IRQ_STATUS_1_I2C_M1_RD_THRESHOLD) {
+ cci_set_rd_threshold_irq(cci, 1, false);
+ complete(&cci->master[1].irq_complete);
+ ret = IRQ_HANDLED;
+ }
+
+ if (val1 & CCI_IRQ_STATUS_1_I2C_M0_RD_PAUSE) {
+ dev_warn_ratelimited(cci->dev, "master 0 read paused (fifo full)\n");
+ ret = IRQ_HANDLED;
+ }
+
+ if (val1 & CCI_IRQ_STATUS_1_I2C_M1_RD_PAUSE) {
+ dev_warn_ratelimited(cci->dev, "master 1 read paused (fifo full)\n");
+ ret = IRQ_HANDLED;
+ }
+
if (unlikely(val & CCI_IRQ_STATUS_0_I2C_M0_Q0Q1_HALT_ACK)) {
reset |= CCI_RESET_CMD_M0_MASK;
ret = IRQ_HANDLED;
@@ -232,6 +309,8 @@ static irqreturn_t cci_isr(int irq, void *dev)
dev_warn_ratelimited(cci->dev, "master 0 queue 1 overflow\n");
if (val & CCI_IRQ_STATUS_0_I2C_M0_Q1_UNDERFLOW)
dev_warn_ratelimited(cci->dev, "master 0 queue 1 underflow\n");
+ if (val & CCI_IRQ_STATUS_0_I2C_M0_RD_UNDERFLOW)
+ dev_warn_ratelimited(cci->dev, "master 0 FIFO read underflow\n");
writel(CCI_HALT_REQ_I2C_M0_Q0Q1, cci->base + CCI_HALT_REQ);
ret = IRQ_HANDLED;
@@ -252,6 +331,8 @@ static irqreturn_t cci_isr(int irq, void *dev)
dev_warn_ratelimited(cci->dev, "master 1 queue 1 overflow\n");
if (val & CCI_IRQ_STATUS_0_I2C_M1_Q1_UNDERFLOW)
dev_warn_ratelimited(cci->dev, "master 1 queue 1 underflow\n");
+ if (val & CCI_IRQ_STATUS_0_I2C_M1_RD_UNDERFLOW)
+ dev_warn_ratelimited(cci->dev, "master 1 FIFO read underflow\n");
writel(CCI_HALT_REQ_I2C_M1_Q0Q1, cci->base + CCI_HALT_REQ);
ret = IRQ_HANDLED;
@@ -389,6 +470,9 @@ static int cci_init(struct cci *cci)
CCI_IRQ_MASK_0_I2C_M1_ERROR;
int i;
+ if (cci_has_threshold_irq(cci))
+ val |= CCI_IRQ_MASK_1_I2C_M0_RD_PAUSE | CCI_IRQ_MASK_1_I2C_M1_RD_PAUSE;
+
writel(val, cci->base + CCI_IRQ_MASK_0);
for (i = 0; i < cci->num_masters; i++) {
@@ -419,6 +503,18 @@ static int cci_init(struct cci *cci)
val = hw->scl_stretch_en << 8 | hw->trdhld << 4 | hw->tsp;
writel(val, cci->base + CCI_I2C_Mm_MISC_CTL(i));
+
+ if (cci_has_threshold_irq(cci)) {
+ /* Hardware supporting the RD_THRESHOLD interrupt provides a minimum FIFO
+ * depth of 64 words, with the threshold reset to the full FIFO size by
+ * default. Configure the threshold to half the FIFO depth to allow burst
+ * reads while maintaining sufficient headroom to drain the FIFO before it
+ * fills up.
+ */
+ val = readl(cci->base + CCI_I2C_Mm_RD_THRESHOLD(i));
+ val = max_t(u32, val, 64);
+ writel(val / 2, cci->base + CCI_I2C_Mm_RD_THRESHOLD(i));
+ }
}
return 0;
@@ -484,7 +580,7 @@ static int cci_validate_queue(struct cci *cci, u8 master, u8 queue)
static int cci_i2c_read(struct cci *cci, u16 master,
u16 addr, u8 *buf, u16 len)
{
- u32 val, words_read, words_exp;
+ u32 val, words_read;
u8 queue = QUEUE_1;
int i, index = 0, ret;
@@ -502,27 +598,48 @@ static int cci_i2c_read(struct cci *cci, u16 master,
val = CCI_I2C_READ | len << 4;
writel(val, cci->base + CCI_I2C_Mm_Qn_LOAD_DATA(master, queue));
- ret = cci_run_queue(cci, master, queue);
- if (ret < 0)
- return ret;
+ val = readl(cci->base + CCI_I2C_Mm_Qn_CUR_WORD_CNT(master, queue));
+ writel(val, cci->base + CCI_I2C_Mm_Qn_EXEC_WORD_CNT(master, queue));
- words_read = readl(cci->base + CCI_I2C_Mm_READ_BUF_LEVEL(master));
- words_exp = len / 4 + 1;
- if (words_read != words_exp) {
- dev_err(cci->dev, "words read = %d, words expected = %d\n",
- words_read, words_exp);
- return -EIO;
- }
+ reinit_completion(&cci->master[master].irq_complete);
- /* 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;
+ cci_set_rd_threshold_irq(cci, master, true);
- 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;
+ val = BIT(master * 2 + queue);
+ writel(val, cci->base + CCI_QUEUE_START);
+
+ /*
+ * Hardware supporting RD_THRESHOLD can handle reads larger than the FIFO size.
+ * The FIFO is drained each time an RD_THRESHOLD interrupt is received, until
+ * the final RD_DONE interrupt completes the transfer.
+ * On hardware lacking RD_THRESHOLD support, reads are limited to the FIFO
+ * size and only one completion (RD_DONE interrupt) is expected.
+ */
+ while (index < len) {
+ if (!wait_for_completion_timeout(&cci->master[master].irq_complete,
+ CCI_TIMEOUT)) {
+ dev_err(cci->dev, "master %d queue %d read timeout\n",
+ master, queue);
+ cci_reset(cci);
+ return -ETIMEDOUT;
+ }
+
+ if (cci->master[master].status)
+ return cci->master[master].status;
+
+ words_read = readl(cci->base + CCI_I2C_Mm_READ_BUF_LEVEL(master));
+
+ while (words_read--) {
+ val = readl_relaxed(cci->base + CCI_I2C_Mm_READ_DATA(master));
+ /* The first byte of the read is the slave ID echo, not payload */
+ for (i = (index == 0) ? 1 : 0; i < 4 && index < len; i++)
+ buf[index++] = (val >> (i * 8)) & 0xff;
+ }
+
+ if (index < len) {
+ reinit_completion(&cci->master[master].irq_complete);
+ cci_set_rd_threshold_irq(cci, master, true);
+ }
}
return 0;
@@ -755,7 +872,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 = CCI_I2C_READ_MAX_LEN(256),
+ .max_read_len = CCI_I2C_READ_BURST_NOLIMIT,
},
},
{
@@ -764,7 +881,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 = CCI_I2C_READ_MAX_LEN(256),
+ .max_read_len = CCI_I2C_READ_BURST_NOLIMIT,
},
},
};
@@ -811,6 +928,8 @@ static int cci_probe(struct platform_device *pdev)
cci->dev = dev;
platform_set_drvdata(pdev, cci);
+ spin_lock_init(&cci->threshold_lock);
+
for_each_available_child_of_node(dev->of_node, child) {
struct cci_master *master;
u32 idx;
--
2.34.1
^ permalink raw reply [flat|nested] 11+ messages in thread