From: sashiko-bot@kernel.org
To: "Xianwei Zhao" <xianwei.zhao@amlogic.com>
Cc: linux-amlogic@lists.infradead.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org, neil.armstrong@linaro.org
Subject: Re: [PATCH v9 2/2] i2c: amlogic: Add Amlogic A9 I2C controller driver
Date: Tue, 17 Nov 2026 06:07:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-218238@kernel.org> (raw)
In-Reply-To: <20261117-a9-i2c-v9-2-7b303c894fea@amlogic.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] i2c: amlogic-a9: transfer started before IRQ setup in
aml_i2c_do_start()
- [Medium] i2c: amlogic-a9: stale irq_state and edge IRQ miss in
aml_i2c_irq()
--
commit 03c13e6537d771dbf45284639a6d6d31511b9ee4
Author: Junyi Zhao <junyi.zhao@amlogic.com>
i2c: amlogic: Add Amlogic A9 I2C controller driver
This commit adds an I2C controller driver for Amlogic A9 SoCs, along with
Kconfig, Makefile, and MAINTAINERS entries.
> diff --git a/drivers/i2c/busses/i2c-amlogic-a9.c b/drivers/i2c/busses/i2c-amlogic-a9.c
> new file mode 100644
> index 0000000000000..8492c13680aab
> --- /dev/null
> +++ b/drivers/i2c/busses/i2c-amlogic-a9.c
[ ... ]
> +static irqreturn_t aml_i2c_irq(int irqno, void *dev_id)
> +{
> + struct aml_i2c *i2c = dev_id;
> + u8 *buf = NULL;
> + u32 rd_len, i;
> + u32 rd_val;
> + u32 irq_state;
> +
> + guard(spinlock)(&i2c->lock);
> + irq_state = readl(i2c->regs + REG_CFG_IRQ_STATE);
> + if (i2c->state == A9_STATE_IDLE) {
> + dev_warn(i2c->dev, "i2c irq triggered abnormally, irq_state:0x%x,irq_en:0x%x\n",
> + irq_state, readl(i2c->regs + REG_CFG_IRQ_ENABLE));
> + goto irq_trans_out;
> + }
> +
> + if (irq_state & A9_TRANS_ERROR) {
> + i2c->error = -ENXIO;
> + goto complete_irq_out;
> + }
> +
> + switch (i2c->state) {
> + case A9_STATE_READ:
> + buf = i2c->msg->buf;
> + rd_len = min(i2c->msg->len - i2c->pos, A9_I2C_FIFO_DEPTH);
> + for (i = 0; i < rd_len; i++) {
> + rd_val = readl(i2c->regs + REG_CFG_RX);
> + buf[i2c->pos++] = rd_val & TX_RX_DATA;
> + }
> + /* Rx must clear thresh after read fifo */
> + clear_irq_status(i2c, A9_RX_THRESH_READ);
> + break;
> + case A9_STATE_WRITE:
> + aml_i2c_prepare_xfer(i2c, A9_FIFO_FILL_HALF);
> + if (i2c->pos == i2c->msg->len)
> + aml_i2c_set_mask(i2c, REG_CFG_IRQ_ENABLE, A9_TX_THRESH_WRITE, 0);
> + /* Tx must clear thresh after write fifo */
> + clear_irq_status(i2c, A9_TX_THRESH_WRITE);
> + break;
> + default:
> + break;
> + }
> +
> + if (!(irq_state & A9_TRANS_DONE) ||
> + (i2c->state == A9_STATE_READ && i2c->pos < i2c->msg->len)) {
> + return IRQ_HANDLED;
> + }
[Severity: Medium]
Can multi-chunk read transfers miss the A9_PHY_DONE interrupt and time out in
aml_i2c_xfer_msg()?
Documentation/devicetree/bindings/i2c/amlogic,a9-i2c.yaml specifies a
rising-edge interrupt (interrupts = <0 164 1>), which requires a 0-to-1
transition on the interrupt line to latch a new pending interrupt in the GIC.
Unlike A9_STATE_WRITE, A9_STATE_READ never disables A9_RX_THRESH_READ when
the remaining bytes fit in the 32-byte FIFO, and irq_state is sampled only
once before reading up to 32 bytes from REG_CFG_RX.
On a 64-byte read, the 32nd byte of the second chunk asserts A9_RX_THRESH_READ
as soon as it enters the FIFO, before the bus NACK and STOP finish:
aml_i2c_irq()
irq_state = readl(REG_CFG_IRQ_STATE) /* A9_RX_THRESH_READ */
readl(REG_CFG_RX) x 32
/* hardware finishes STOP and sets A9_PHY_DONE in REG_CFG_IRQ_STATE */
clear_irq_status(A9_RX_THRESH_READ)
/* A9_PHY_DONE stays high; no 0->1 edge on the IRQ line */
if (!(irq_state & A9_TRANS_DONE) || ...)
return IRQ_HANDLED; <-- never completes i2c->done
Likewise, if both A9_RX_THRESH_READ and A9_PHY_DONE are already set in
irq_state when more than 32 bytes remain, aml_i2c_irq() drains 32 bytes,
clears only A9_RX_THRESH_READ, and returns early because i2c->pos <
i2c->msg->len. Because A9_PHY_DONE remains asserted without a new rising
edge and fewer than 32 tail bytes remain in the FIFO, no further interrupt
fires and wait_for_completion_timeout() hangs for 500 ms before returning
-ETIMEDOUT.
> +
> +complete_irq_out:
> + i2c->state = A9_STATE_IDLE;
> + reset_fifo_pos(i2c);
> + aml_i2c_set_mask(i2c, REG_CFG_IRQ_ENABLE, A9_RX_THRESH_READ | A9_TX_THRESH_WRITE, 0);
> + complete(&i2c->done);
> +irq_trans_out:
> + clear_irq_status(i2c, IRQ_ALL_MASK);
> +
> + return IRQ_HANDLED;
> +}
> +
> +static void aml_i2c_do_start(struct aml_i2c *i2c, struct i2c_msg *msg)
> +{
> + unsigned int reg_val;
> + unsigned int trans_len;
> +
> + trans_len = msg->len;
> + reg_val = (unsigned int)(((msg->addr & 0x7f) << START_SADDR_SHIFT) |
> + ((msg->flags & I2C_M_RD) ? START_READ : 0) |
> + ((trans_len & 0xfff) << START_LEN_SHIFT) | START_START);
> + aml_i2c_set_mask(i2c, REG_CFG_START,
> + START_START | START_SLAVE_ADDR | START_READ | START_LEN, reg_val);
> + clear_irq_status(i2c, IRQ_ALL_MASK);
> + /* enable thresh mode */
> + if (trans_len > A9_I2C_FIFO_DEPTH) {
> + reg_val = (msg->flags & I2C_M_RD) ? A9_RX_THRESH_READ : A9_TX_THRESH_WRITE;
> + aml_i2c_set_mask(i2c, REG_CFG_IRQ_ENABLE,
> + A9_RX_THRESH_READ | A9_TX_THRESH_WRITE, reg_val);
> + }
> +}
[Severity: Medium]
Should clear_irq_status() and the REG_CFG_IRQ_ENABLE update happen before
setting START_START in REG_CFG_START?
A9_ENABLE_IRQ_BIT (A9_NCK_ERROR | A9_PHY_DONE) is already enabled in
REG_CFG_IRQ_ENABLE from aml_i2c_probe(). If execution is delayed after
writing START_START (for example under CONFIG_PREEMPT_RT or a hypervisor) and
the transfer immediately NACKs the address or finishes, clear_irq_status(i2c,
IRQ_ALL_MASK) wipes out A9_NCK_ERROR or A9_PHY_DONE before aml_i2c_irq()
reads REG_CFG_IRQ_STATE. aml_i2c_irq() then sees irq_state == 0, misses
A9_TRANS_ERROR, reads unpopulated bytes from REG_CFG_RX on a read message,
and returns early without completing i2c->done, causing aml_i2c_xfer_msg() to
time out after 500 ms.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-a9-i2c-v9-0-7b303c894fea@amlogic.com?part=2
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
next prev parent reply other threads:[~2026-11-17 6:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 5:44 [PATCH v9 0/2] i2c: Add driver support Amlogic A9 I2C Xianwei Zhao via B4 Relay
2026-11-17 5:44 ` [PATCH v9 1/2] dt-bindings: i2c: add Amlogic A9 I2C controller Xianwei Zhao via B4 Relay
2026-11-17 9:05 ` Markus Elfring
2026-11-17 9:32 ` Xianwei Zhao
2026-11-17 5:44 ` [PATCH v9 2/2] i2c: amlogic: Add Amlogic A9 I2C controller driver Xianwei Zhao via B4 Relay
2026-11-17 6:07 ` sashiko-bot [this message]
2026-11-17 9:36 ` Markus Elfring
2026-11-17 10:01 ` Xianwei Zhao
2026-11-17 10:06 ` [v9 " Markus Elfring
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=sashiko-outbox-218238@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-amlogic@lists.infradead.org \
--cc=neil.armstrong@linaro.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xianwei.zhao@amlogic.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