From: Troy Mitchell <troy.mitchell@linux.spacemit.com>
To: Alex Elder <elder@riscstar.com>,
Troy Mitchell <troy.mitchell@linux.spacemit.com>,
Andi Shyti <andi.shyti@kernel.org>, Yixun Lan <dlan@gentoo.org>,
Aurelien Jarno <aurelien@aurel32.net>,
Michael Opdenacker <michael.opdenacker@rootcommit.com>,
Troy Mitchell <troymitchell988@gmail.com>
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-riscv@lists.infradead.org, spacemit@lists.linux.dev
Subject: Re: [PATCH v5 2/2] i2c: spacemit: introduce pio for k1
Date: Mon, 29 Dec 2025 10:03:51 +0800 [thread overview]
Message-ID: <68BEF1A67DD3F4D0+aVHhhzvaM49Mm-0d@kernel.org> (raw)
In-Reply-To: <86c5e338-e630-4933-a123-cfa1201495ed@riscstar.com>
On Sun, Dec 28, 2025 at 05:24:26PM -0600, Alex Elder wrote:
> On 12/25/25 9:31 PM, Troy Mitchell wrote:
> > This patch introduces I2C PIO functionality for the Spacemit K1 SoC,
> > enabling the use of I2C in atomic context.
> >
> > When i2c xfer_atomic is invoked, use_pio is set accordingly.
> >
> > Since an atomic context is required, all interrupts are disabled when
> > operating in PIO mode. Even with interrupts disabled, the bits in the
> > ISR (Interrupt Status Register) will still be set, so error handling can
> > be performed by polling the relevant status bits in the ISR.
> >
> > Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
>
> This generally looks good and what I say below doesn't
> really ask for functional changes.
>
> I have some suggestions on comments to improve readability
> of the code. I still have a few questions related to delays
> and timeouts, and when you enable TX and RX interrupts.
> These are more about explaining/justifying what's going on,
> though in some cases they might imply an improvement that
> could be made.
>
[...]
> > + *
> > + * For the tx empty interrupt, it will be enabled in the
> > + * i2c_start function.
> > + * Otherwise, it will cause an erroneous empty interrupt before i2c_start.
>
> I don't think the TX FIFO empty interrupt is "erroneous" in
NO FIFO NOW. Data Byte Register(DBR).
But the comments below still suitable.
> > +static int spacemit_i2c_wait_pio_xfer(struct spacemit_i2c_dev *i2c)
> > +{
> > + u32 mask, msec = jiffies_to_msecs(i2c->adapt.timeout);
> > + ktime_t timeout = ktime_add_ms(ktime_get(), msec);
> > + int ret;
> > +
> > + mask = SPACEMIT_SR_IRF | SPACEMIT_SR_ITE;
> > +
> > + do {
> > + i2c->status = readl(i2c->base + SPACEMIT_ISR);
> > +
> > + spacemit_i2c_clear_int_status(i2c, i2c->status);
> > +
> > + if (!(i2c->status & mask)) {
> > + udelay(10);
>
> You are looking only for TX FIFO empty and RX FIFO full
> interrupts. In this situation I *think* you have several
> possible interrupt conditions occurring. Some questions:
> - Would observing one of the other possibly conditions
> at this point be an error?
> - If so, is it OK to simply ignore (and acknowledge) these?
actualy, we can.
but I think it's better to check error here.
> - Why is the 10 microsecond delay required?
To ensure hardware stability, even in interrupt mode, the bit is set
first before the interrupt occurs.
> - Is it reasonable to delay if you see the RXHF condition?
The delay is only taken when none of the expected bits are observed.
>
> > + continue;
> > + }
> > +
> > + spacemit_i2c_handle_state(i2c);
> > +
> > +
>
> Delete the extra blank lines here.
>
> > + } while (i2c->unprocessed && ktime_compare(ktime_get(), timeout) < 0);
> > +
> > + if (i2c->unprocessed)
> > + return 0;
> > +
> > + if (i2c->read)
> > + return 1;
> > +
> > + /*
> > + * If this is the last byte to write of the current message,
> > + * we have to wait here. Otherwise, control will proceed directly
> > + * to start(), which would overwrite the current data.
> > + */
> > + ret = readl_poll_timeout_atomic(i2c->base + SPACEMIT_ISR,
> > + i2c->status, i2c->status & SPACEMIT_SR_ITE,
> > + 30, 1000);
>
> Why is 1000 microseconds the correct timeout period here?
1000us is sufficient for the hardware to respond; if it still doesn't
work by then, it's considered a hardware timeout.
>
> > + if (ret)
> > + return 0;
> > +
> > + /*
> > + * For writes: in interrupt mode, an ITE (write-empty) interrupt is triggered
> > + * after the last byte, and the MSD-related handling takes place there.
> > + * In PIO mode, however, we need to explicitly call err_check() to emulate this
> > + * step, otherwise the next transfer will fail.
> > + */
> > + if (i2c->msg_idx == i2c->msg_num - 1) {
> > + mask = SPACEMIT_SR_MSD | SPACEMIT_SR_ERR;
> > + /*
> > + * In some cases, MSD may not arrive immediately;
> > + * wait here to handle that.
> > + */
> > + ret = readl_poll_timeout_atomic(i2c->base + SPACEMIT_ISR,
> > + i2c->status, i2c->status & mask,
> > + 30, 1000);
>
> Same question in this case. Also, symbolic constants for
> timeouts are often better.
See above. Thanks. I'll define it.
- Troy
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-12-29 2:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-26 3:31 [PATCH v5 0/2] i2c: spacemit: introduce pio for k1 Troy Mitchell
2025-12-26 3:31 ` [PATCH v5 1/2] i2c: spacemit: replace i2c_xfer_msg() Troy Mitchell
2025-12-27 19:45 ` Andi Shyti
2025-12-28 10:31 ` Troy Mitchell
2025-12-28 23:24 ` Alex Elder
2025-12-29 14:39 ` Aurelien Jarno
2025-12-26 3:31 ` [PATCH v5 2/2] i2c: spacemit: introduce pio for k1 Troy Mitchell
2025-12-28 23:24 ` Alex Elder
2025-12-29 2:03 ` Troy Mitchell [this message]
2025-12-29 2:07 ` Troy Mitchell
2025-12-29 13:54 ` Aurelien Jarno
2025-12-29 15:07 ` Aurelien Jarno
2026-01-08 7:43 ` Troy Mitchell
2025-12-27 19:38 ` [PATCH v5 0/2] " Andi Shyti
2025-12-28 10:33 ` Troy Mitchell
2025-12-29 14:38 ` Aurelien Jarno
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=68BEF1A67DD3F4D0+aVHhhzvaM49Mm-0d@kernel.org \
--to=troy.mitchell@linux.spacemit.com \
--cc=andi.shyti@kernel.org \
--cc=aurelien@aurel32.net \
--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=michael.opdenacker@rootcommit.com \
--cc=spacemit@lists.linux.dev \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox