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 v2 6/6] i2c: qcom-cci: Add burst read support
Date: Tue, 13 Oct 2026 12:30:30 +0200 [thread overview]
Message-ID: <20261013-cci-imp-v2-6-6873326b44a3@oss.qualcomm.com> (raw)
In-Reply-To: <20261013-cci-imp-v2-0-6873326b44a3@oss.qualcomm.com>
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
prev parent reply other threads:[~2026-10-13 10:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
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-14 12:53 ` Bryan O'Donoghue
2026-10-14 13:18 ` 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-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
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
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 [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=20261013-cci-imp-v2-6-6873326b44a3@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®