* [PATCH 0/5] i2c: qcom-cci: Runtime capability detection and improved read/write
@ 2026-10-04 19:09 Loic Poulain
2026-10-04 19:09 ` [PATCH 1/5] i2c: qcom-cci: Factor out write command queue programming Loic Poulain
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Loic Poulain @ 2026-10-04 19:09 UTC (permalink / raw)
To: Robert Foss, Andi Shyti, Konrad Dybcio
Cc: linux-i2c, linux-arm-msm, linux-kernel, Loic Poulain
Improves the Qualcomm CCI I2C driver in three related ways:
- Capabilities (queue sizes, max transfer lengths, supported I2C mode)
are currently hardcoded per DT compatible string in a handful of
cci_data instances. Patch 3 replaces the static per-compatible
structs with a single version-sorted capability catalog resolved
at runtime from CCI_HW_VERSION.
- The driver only supported single-command writes, capped at 11 bytes
regardless of how much space the command queue actually has. Patches
1 and 4 factor out the write-command queueing into a reusable helper
and then add burst-write support, chunking longer writes
across the whole queue instead of a single command's payload.
- The FIFO read path hardcoded a fixed 12-byte limit unrelated to the
actual per-revision FIFO size, with a special-cased drain loop.
Patch 5 simplify the FIFO read/drain-loop and derive the read-side
limits from each revision's FIFO size
Also add overflow and underflow IRQ reporting, as queue limits are
now derived from the hardware capabilities and exercised more
aggressively.
Support for unbounded read and write transfers using the threshold
IRQ mechanism is planned as a follow-up. Such functionality is not
part of this series.
Depends on: https://lore.kernel.org/all/20260929-cci-clk-fix-v6-0-62a268cccb0f@oss.qualcomm.com/
Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
---
Loic Poulain (5):
i2c: qcom-cci: Factor out write command queue programming
i2c: qcom-cci: Handle and report queue overflow/underflow interrupts
i2c: qcom-cci: Detect capabilities from CCI_HW_VERSION at runtime
i2c: qcom-cci: Add burst write support
i2c: qcom-cci: Extend i2c read limits based on CCI revision
drivers/i2c/busses/i2c-qcom-cci.c | 286 ++++++++++++++++++++++++++------------
1 file changed, 194 insertions(+), 92 deletions(-)
---
base-commit: eb271d18cdcee558095324dffaa53d9e6fe78882
change-id: 20260929-cci-imp-8ba384309942
Best regards,
--
Loic Poulain <loic.poulain@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/5] i2c: qcom-cci: Factor out write command queue programming
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 ` Loic Poulain
2026-10-04 19:09 ` [PATCH 2/5] i2c: qcom-cci: Handle and report queue overflow/underflow interrupts Loic Poulain
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Loic Poulain @ 2026-10-04 19:09 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 526a699eee147996b2756b47c0e6982678990be0..c4bb97868c54de636be756328ca7ee4e46e6b400 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] 6+ messages in thread
* [PATCH 2/5] i2c: qcom-cci: Handle and report queue overflow/underflow interrupts
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 ` Loic Poulain
2026-10-04 19:09 ` [PATCH 3/5] i2c: qcom-cci: Detect capabilities from CCI_HW_VERSION at runtime Loic Poulain
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Loic Poulain @ 2026-10-04 19:09 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.
While at it, change the HALT_ACK branches to OR into 'reset' instead
of overwriting it, so a halt request for one master isn't dropped
when the other master's HALT_ACK is handled in the same interrupt.
Signed-off-by: Loic Poulain <loic.poulain@oss.qualcomm.com>
---
drivers/i2c/busses/i2c-qcom-cci.c | 38 ++++++++++++++++++++++++++++++++------
1 file changed, 32 insertions(+), 6 deletions(-)
diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
index c4bb97868c54de636be756328ca7ee4e46e6b400..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)
@@ -177,12 +185,12 @@ static irqreturn_t cci_isr(int irq, void *dev)
}
if (unlikely(val & CCI_IRQ_STATUS_0_I2C_M0_Q0Q1_HALT_ACK)) {
- reset = CCI_RESET_CMD_M0_MASK;
+ reset |= CCI_RESET_CMD_M0_MASK;
ret = IRQ_HANDLED;
}
if (unlikely(val & CCI_IRQ_STATUS_0_I2C_M1_Q0Q1_HALT_ACK)) {
- reset = CCI_RESET_CMD_M1_MASK;
+ reset |= CCI_RESET_CMD_M1_MASK;
ret = IRQ_HANDLED;
}
@@ -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] 6+ messages in thread
* [PATCH 3/5] i2c: qcom-cci: Detect capabilities from CCI_HW_VERSION at runtime
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 ` Loic Poulain
2026-10-04 19:09 ` [PATCH 4/5] i2c: qcom-cci: Add burst write support Loic Poulain
2026-10-04 19:09 ` [PATCH 5/5] i2c: qcom-cci: Extend i2c read limits based on CCI revision Loic Poulain
4 siblings, 0 replies; 6+ messages in thread
From: Loic Poulain @ 2026-10-04 19:09 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 dinstinquish 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 | 158 +++++++++++++++++++++++++-------------
1 file changed, 104 insertions(+), 54 deletions(-)
diff --git a/drivers/i2c/busses/i2c-qcom-cci.c b/drivers/i2c/busses/i2c-qcom-cci.c
index 099da0069251681cc52e351fb656bd73e78a96c9..c0b39d419e296454a083d38ce302940875b8ad2b 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -14,6 +14,10 @@
#include <linux/pm_opp.h>
#define CCI_HW_VERSION 0x0
+#define CCI_HW_VERSION_MAJOR(val) (((val) >> 28) & 0xf)
+#define CCI_HW_VERSION_MINOR(val) (((val) >> 16) & 0xfff)
+#define CCI_HW_VERSION_STEP(val) ((val) & 0xffff)
+#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 +137,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 +149,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 +251,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 +377,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 +621,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 +696,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 = CCI_HW_VERSION_MAJOR(hw_version);
+ u16 minor = CCI_HW_VERSION_MINOR(hw_version);
+ u16 step = CCI_HW_VERSION_STEP(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 < 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,8 +786,8 @@ 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)
+ cci->num_masters = (uintptr_t)device_get_match_data(dev);
+ if (!cci->num_masters)
return -ENOENT;
for_each_available_child_of_node(dev->of_node, child) {
@@ -719,14 +800,13 @@ static int cci_probe(struct platform_device *pdev)
continue;
}
- if (idx >= cci->data->num_masters) {
+ if (idx >= cci->num_masters) {
dev_err(dev, "%pOF invalid 'reg' value: %u (max is %u)",
- child, idx, cci->data->num_masters - 1);
+ child, idx, cci->num_masters - 1);
continue;
}
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 +857,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 +875,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 +890,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 +924,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 +936,21 @@ 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", .data = (void *)1 },
+ { .compatible = "qcom,msm8953-cci", .data = (void *)NUM_MASTERS },
+ { .compatible = "qcom,msm8974-cci", .data = (void *)NUM_MASTERS },
+ { .compatible = "qcom,msm8996-cci", .data = (void *)NUM_MASTERS },
/*
* 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", .data = (void *)1 },
+ { .compatible = "qcom,sdm845-cci", .data = (void *)NUM_MASTERS },
+ { .compatible = "qcom,sm8250-cci", .data = (void *)NUM_MASTERS },
+ { .compatible = "qcom,sm8450-cci", .data = (void *)NUM_MASTERS },
{}
};
MODULE_DEVICE_TABLE(of, cci_dt_match);
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/5] i2c: qcom-cci: Add burst write support
2026-10-04 19:09 [PATCH 0/5] i2c: qcom-cci: Runtime capability detection and improved read/write Loic Poulain
` (2 preceding siblings ...)
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 ` Loic Poulain
2026-10-04 19:09 ` [PATCH 5/5] i2c: qcom-cci: Extend i2c read limits based on CCI revision Loic Poulain
4 siblings, 0 replies; 6+ messages in thread
From: Loic Poulain @ 2026-10-04 19:09 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 c0b39d419e296454a083d38ce302940875b8ad2b..9554d42e6b976ef33f6421a98209c2fb837e9698 100644
--- a/drivers/i2c/busses/i2c-qcom-cci.c
+++ b/drivers/i2c/busses/i2c-qcom-cci.c
@@ -85,14 +85,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,
@@ -520,14 +530,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));
}
@@ -536,9 +547,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.
@@ -547,10 +561,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);
@@ -712,7 +738,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,
},
},
@@ -721,7 +747,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,
},
},
@@ -730,7 +756,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,
},
},
@@ -739,7 +765,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] 6+ messages in thread
* [PATCH 5/5] i2c: qcom-cci: Extend i2c read limits based on CCI revision
2026-10-04 19:09 [PATCH 0/5] i2c: qcom-cci: Runtime capability detection and improved read/write Loic Poulain
` (3 preceding siblings ...)
2026-10-04 19:09 ` [PATCH 4/5] i2c: qcom-cci: Add burst write support Loic Poulain
@ 2026-10-04 19:09 ` Loic Poulain
4 siblings, 0 replies; 6+ messages in thread
From: Loic Poulain @ 2026-10-04 19:09 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 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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-10-04 19:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 5/5] i2c: qcom-cci: Extend i2c read limits based on CCI revision Loic Poulain
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®