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 1/5] i2c: qcom-cci: Factor out write command queue programming
Date: Sun, 04 Oct 2026 21:09:47 +0200 [thread overview]
Message-ID: <20261004-cci-imp-v1-1-227d12cb4829@oss.qualcomm.com> (raw)
In-Reply-To: <20261004-cci-imp-v1-0-227d12cb4829@oss.qualcomm.com>
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
next prev parent reply other threads:[~2026-10-04 19:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-04 19:09 [PATCH 0/5] i2c: qcom-cci: Runtime capability detection and improved read/write Loic Poulain
2026-10-04 19:09 ` Loic Poulain [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261004-cci-imp-v1-1-227d12cb4829@oss.qualcomm.com \
--to=loic.poulain@oss.qualcomm.com \
--cc=andi.shyti@kernel.org \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rfoss@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®