From: Aurelien Jarno <aurelien@aurel32.net>
To: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Cc: Andi Shyti <andi.shyti@kernel.org>, Yixun Lan <dlan@gentoo.org>,
Alex Elder <elder@riscstar.com>,
Troy Mitchell <troymitchell988@gmail.com>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-riscv@lists.infradead.org, spacemit@lists.linux.dev
Subject: Re: [PATCH v2 6/6] i2c: spacemit: introduce pio for k1
Date: Fri, 26 Sep 2025 18:47:14 +0200 [thread overview]
Message-ID: <aNbDkn9AC4FFx-Zc@aurel32.net> (raw)
In-Reply-To: <20250925-k1-i2c-atomic-v2-6-46dc13311cda@linux.spacemit.com>
Hi Troy,
On 2025-09-25 10:02, Troy Mitchell wrote:
> This patch introduces I2C PIO functionality for the Spacemit K1 SoC,
> enabling the use of I2C with interrupts disabled.
>
> Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
> ---
> drivers/i2c/busses/i2c-k1.c | 164 +++++++++++++++++++++++++++++++++++++-------
> 1 file changed, 140 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-k1.c b/drivers/i2c/busses/i2c-k1.c
> index 6b918770e612e098b8ad17418f420d87c94df166..e403eb7d6f329f4fe5c5242f94cc21094dff105c 100644
> --- a/drivers/i2c/busses/i2c-k1.c
> +++ b/drivers/i2c/busses/i2c-k1.c
[snip]
> @@ -293,10 +307,54 @@ static void spacemit_i2c_start(struct spacemit_i2c_dev *i2c)
> /* send start pulse */
> val = readl(i2c->base + SPACEMIT_ICR);
> val &= ~SPACEMIT_CR_STOP;
> - val |= SPACEMIT_CR_START | SPACEMIT_CR_TB | SPACEMIT_CR_DTEIE;
> + val |= SPACEMIT_CR_START | SPACEMIT_CR_TB;
> +
> + if (!i2c->is_pio)
> + val |= SPACEMIT_CR_DTEIE;
> +
> writel(val, i2c->base + SPACEMIT_ICR);
> }
>
> +static irqreturn_t spacemit_i2c_irq_handler(int irq, void *devid);
> +static int spacemit_i2c_wait_pio_xfer(struct spacemit_i2c_dev *i2c)
> +{
> + u32 msec = jiffies_to_msecs(i2c->adapt.timeout);
> + ktime_t timeout = ktime_add_ms(ktime_get(), msec);
> + int ret;
> +
> + while (i2c->unprocessed && ktime_compare(ktime_get(), timeout) < 0) {
> + udelay(10);
> + i2c->status = readl(i2c->base + SPACEMIT_ISR);
> +
> + spacemit_i2c_clear_int_status(i2c, i2c->status);
> +
> + if (!(i2c->status & SPACEMIT_SR_IRF) && !(i2c->status & SPACEMIT_SR_ITE))
> + continue;
> +
> + spacemit_i2c_irq_handler(0, i2c);
> +
> + i2c->status = readl(i2c->base + SPACEMIT_ISR);
> +
> + /*
> + * This is the last byte to write of the current message.
> + * If we do not wait here, control will proceed directly to start(),
> + * which would overwrite the current data.
> + */
> + if (!i2c->read && !i2c->unprocessed) {
> + ret = readl_poll_timeout(i2c->base + SPACEMIT_ISR,
> + i2c->status, i2c->status & SPACEMIT_SR_ITE,
> + 30, 1000);
This needs to be readl_poll_timeout_atomic(), like you changed in
spacemit_i2c_wait_bus_idle().
> + if (ret)
> + return 0;
> + }
> + }
> +
> + if (i2c->unprocessed)
> + return 0;
> +
> + return 1;
> +}
> +
> static int spacemit_i2c_xfer_msg(struct spacemit_i2c_dev *i2c)
> {
> unsigned long time_left;
[snip]
> @@ -479,15 +578,21 @@ static void spacemit_i2c_calc_timeout(struct spacemit_i2c_dev *i2c)
> i2c->adapt.timeout = usecs_to_jiffies(timeout + USEC_PER_SEC / 10) / i2c->msg_num;
> }
>
> -static int spacemit_i2c_xfer(struct i2c_adapter *adapt, struct i2c_msg *msgs, int num)
> +static inline int
> +spacemit_i2c_xfer(struct i2c_adapter *adapt, struct i2c_msg *msgs, int num, bool is_pio)
> {
> struct spacemit_i2c_dev *i2c = i2c_get_adapdata(adapt);
> int ret;
>
> + i2c->is_pio = is_pio;
> +
> i2c->msgs = msgs;
> i2c->msg_num = num;
>
> - spacemit_i2c_calc_timeout(i2c);
> + if (!i2c->is_pio)
> + spacemit_i2c_calc_timeout(i2c);
> + else
> + i2c->adapt.timeout = SPACEMIT_WAIT_TIMEOUT;
Thanks for fixing that, however i2c->adapt.timeout needs to be in
jiffies, so you want to use msecs_to_jiffies(SPACEMIT_WAIT_TIMEOUT).
> spacemit_i2c_init(i2c);
>
Regards
Aurelien
--
Aurelien Jarno GPG: 4096R/1DDD8C9B
aurelien@aurel32.net http://aurel32.net
WARNING: multiple messages have this Message-ID (diff)
From: Aurelien Jarno <aurelien@aurel32.net>
To: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Cc: Andi Shyti <andi.shyti@kernel.org>, Yixun Lan <dlan@gentoo.org>,
Alex Elder <elder@riscstar.com>,
Troy Mitchell <troymitchell988@gmail.com>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-riscv@lists.infradead.org, spacemit@lists.linux.dev
Subject: Re: [PATCH v2 6/6] i2c: spacemit: introduce pio for k1
Date: Fri, 26 Sep 2025 18:47:14 +0200 [thread overview]
Message-ID: <aNbDkn9AC4FFx-Zc@aurel32.net> (raw)
In-Reply-To: <20250925-k1-i2c-atomic-v2-6-46dc13311cda@linux.spacemit.com>
Hi Troy,
On 2025-09-25 10:02, Troy Mitchell wrote:
> This patch introduces I2C PIO functionality for the Spacemit K1 SoC,
> enabling the use of I2C with interrupts disabled.
>
> Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
> ---
> drivers/i2c/busses/i2c-k1.c | 164 +++++++++++++++++++++++++++++++++++++-------
> 1 file changed, 140 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-k1.c b/drivers/i2c/busses/i2c-k1.c
> index 6b918770e612e098b8ad17418f420d87c94df166..e403eb7d6f329f4fe5c5242f94cc21094dff105c 100644
> --- a/drivers/i2c/busses/i2c-k1.c
> +++ b/drivers/i2c/busses/i2c-k1.c
[snip]
> @@ -293,10 +307,54 @@ static void spacemit_i2c_start(struct spacemit_i2c_dev *i2c)
> /* send start pulse */
> val = readl(i2c->base + SPACEMIT_ICR);
> val &= ~SPACEMIT_CR_STOP;
> - val |= SPACEMIT_CR_START | SPACEMIT_CR_TB | SPACEMIT_CR_DTEIE;
> + val |= SPACEMIT_CR_START | SPACEMIT_CR_TB;
> +
> + if (!i2c->is_pio)
> + val |= SPACEMIT_CR_DTEIE;
> +
> writel(val, i2c->base + SPACEMIT_ICR);
> }
>
> +static irqreturn_t spacemit_i2c_irq_handler(int irq, void *devid);
> +static int spacemit_i2c_wait_pio_xfer(struct spacemit_i2c_dev *i2c)
> +{
> + u32 msec = jiffies_to_msecs(i2c->adapt.timeout);
> + ktime_t timeout = ktime_add_ms(ktime_get(), msec);
> + int ret;
> +
> + while (i2c->unprocessed && ktime_compare(ktime_get(), timeout) < 0) {
> + udelay(10);
> + i2c->status = readl(i2c->base + SPACEMIT_ISR);
> +
> + spacemit_i2c_clear_int_status(i2c, i2c->status);
> +
> + if (!(i2c->status & SPACEMIT_SR_IRF) && !(i2c->status & SPACEMIT_SR_ITE))
> + continue;
> +
> + spacemit_i2c_irq_handler(0, i2c);
> +
> + i2c->status = readl(i2c->base + SPACEMIT_ISR);
> +
> + /*
> + * This is the last byte to write of the current message.
> + * If we do not wait here, control will proceed directly to start(),
> + * which would overwrite the current data.
> + */
> + if (!i2c->read && !i2c->unprocessed) {
> + ret = readl_poll_timeout(i2c->base + SPACEMIT_ISR,
> + i2c->status, i2c->status & SPACEMIT_SR_ITE,
> + 30, 1000);
This needs to be readl_poll_timeout_atomic(), like you changed in
spacemit_i2c_wait_bus_idle().
> + if (ret)
> + return 0;
> + }
> + }
> +
> + if (i2c->unprocessed)
> + return 0;
> +
> + return 1;
> +}
> +
> static int spacemit_i2c_xfer_msg(struct spacemit_i2c_dev *i2c)
> {
> unsigned long time_left;
[snip]
> @@ -479,15 +578,21 @@ static void spacemit_i2c_calc_timeout(struct spacemit_i2c_dev *i2c)
> i2c->adapt.timeout = usecs_to_jiffies(timeout + USEC_PER_SEC / 10) / i2c->msg_num;
> }
>
> -static int spacemit_i2c_xfer(struct i2c_adapter *adapt, struct i2c_msg *msgs, int num)
> +static inline int
> +spacemit_i2c_xfer(struct i2c_adapter *adapt, struct i2c_msg *msgs, int num, bool is_pio)
> {
> struct spacemit_i2c_dev *i2c = i2c_get_adapdata(adapt);
> int ret;
>
> + i2c->is_pio = is_pio;
> +
> i2c->msgs = msgs;
> i2c->msg_num = num;
>
> - spacemit_i2c_calc_timeout(i2c);
> + if (!i2c->is_pio)
> + spacemit_i2c_calc_timeout(i2c);
> + else
> + i2c->adapt.timeout = SPACEMIT_WAIT_TIMEOUT;
Thanks for fixing that, however i2c->adapt.timeout needs to be in
jiffies, so you want to use msecs_to_jiffies(SPACEMIT_WAIT_TIMEOUT).
> spacemit_i2c_init(i2c);
>
Regards
Aurelien
--
Aurelien Jarno GPG: 4096R/1DDD8C9B
aurelien@aurel32.net http://aurel32.net
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-09-26 16:47 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-25 2:02 [PATCH v2 0/6] i2c: spacemit: fix and introduce pio Troy Mitchell
2025-09-25 2:02 ` Troy Mitchell
2025-09-25 2:02 ` [PATCH v2 1/6] i2c: spacemit: ensure bus release check runs when wait_bus_idle() fails Troy Mitchell
2025-09-25 2:02 ` Troy Mitchell
2025-09-25 2:02 ` [PATCH v2 2/6] i2c: spacemit: remove stop function to avoid bus error Troy Mitchell
2025-09-25 2:02 ` Troy Mitchell
2025-09-25 20:11 ` Aurelien Jarno
2025-09-25 20:11 ` Aurelien Jarno
2025-09-25 2:02 ` [PATCH v2 3/6] i2c: spacemit: disable SDA glitch fix to avoid restart delay Troy Mitchell
2025-09-25 2:02 ` Troy Mitchell
2025-09-25 2:02 ` [PATCH v2 4/6] i2c: spacemit: check SDA instead of SCL after bus reset Troy Mitchell
2025-09-25 2:02 ` Troy Mitchell
2025-09-25 2:02 ` [PATCH v2 5/6] i2c: spacemit: ensure SDA is released " Troy Mitchell
2025-09-25 2:02 ` Troy Mitchell
2025-09-25 20:43 ` Aurelien Jarno
2025-09-25 20:43 ` Aurelien Jarno
2025-09-25 2:02 ` [PATCH v2 6/6] i2c: spacemit: introduce pio for k1 Troy Mitchell
2025-09-25 2:02 ` Troy Mitchell
2025-09-26 11:10 ` Yixun Lan
2025-09-26 11:10 ` Yixun Lan
2025-09-26 13:13 ` Troy Mitchell
2025-09-26 13:13 ` Troy Mitchell
2025-09-26 14:28 ` Wolfram Sang
2025-09-26 14:28 ` Wolfram Sang
2025-09-27 1:24 ` Yixun Lan
2025-09-27 1:24 ` Yixun Lan
2025-09-27 3:57 ` Troy Mitchell
2025-09-27 3:57 ` Troy Mitchell
2025-09-28 6:06 ` Troy Mitchell
2025-09-28 6:06 ` Troy Mitchell
2025-09-26 16:47 ` Aurelien Jarno [this message]
2025-09-26 16:47 ` Aurelien Jarno
2025-09-27 4:05 ` Troy Mitchell
2025-09-27 4:05 ` Troy Mitchell
2025-09-27 1:45 ` Yixun Lan
2025-09-27 1:45 ` Yixun Lan
2025-09-27 4:04 ` Troy Mitchell
2025-09-27 4:04 ` Troy Mitchell
2025-09-27 10:16 ` Yixun Lan
2025-09-27 10:16 ` Yixun Lan
2025-09-27 10:24 ` Troy Mitchell
2025-09-27 10:24 ` Troy Mitchell
2025-09-27 10:56 ` Yixun Lan
2025-09-27 10:56 ` Yixun Lan
2025-09-28 1:17 ` Troy Mitchell
2025-09-28 1:17 ` Troy Mitchell
2025-09-28 2:54 ` Yixun Lan
2025-09-28 2:54 ` Yixun Lan
2025-09-28 8:09 ` Troy Mitchell
2025-09-28 8:09 ` Troy Mitchell
2025-09-28 11:22 ` Yixun Lan
2025-09-28 11:22 ` Yixun Lan
2025-09-25 21:50 ` [PATCH v2 0/6] i2c: spacemit: fix and introduce pio Wolfram Sang
2025-09-25 21:50 ` Wolfram Sang
2025-09-26 1:47 ` Troy Mitchell
2025-09-26 1:47 ` Troy Mitchell
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=aNbDkn9AC4FFx-Zc@aurel32.net \
--to=aurelien@aurel32.net \
--cc=andi.shyti@kernel.org \
--cc=dlan@gentoo.org \
--cc=elder@riscstar.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=spacemit@lists.linux.dev \
--cc=troy.mitchell@linux.spacemit.com \
--cc=troymitchell988@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.