* [PATCH] i2c: imx: acknowledge the count byte of an atomic block read
@ 2026-11-16 12:27 Mehmet Fide
2026-11-16 12:44 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Mehmet Fide @ 2026-11-16 12:27 UTC (permalink / raw)
To: Andi Shyti, Oleksij Rempel
Cc: Pengutronix Kernel Team, Frank Li, Sascha Hauer, Fabio Estevam,
Stefan Eichenberger, Stefan Eichenberger, linux-i2c, imx,
linux-arm-kernel, linux-kernel, stable, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
i2c_smbus_xfer_emulated() sends the read message of an SMBus block read
with a length of 1 and I2C_M_RECV_LEN. i2c_imx_prepare_read() clears
I2CR_TXAK only for a message longer than one byte, so the atomic read
does not acknowledge the count byte. The target stops sending, the rest
of the block is read as 0xff and the transfer reports success.
The test for I2C_M_RECV_LEN was dropped when the read was split into
i2c_imx_prepare_read() and its callers. Commit a5d0b9e32745 ("i2c: imx:
fix emulated smbus block read") added it back to the interrupt driven
read only. The DMA read never gets an I2C_M_RECV_LEN message.
Fixes: b460b15b3cc2 ("i2c: imx: separate atomic, dma and non-dma use case")
Cc: stable@vger.kernel.org # v6.13+
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
Notes:
Reported by the Sashiko review of "i2c: imx: test the block read flag of
the message that is read":
https://sashiko.dev/#/bug/linux-09e3015b-fc03-4410-809b-82964cdfac9c
Tested on a Colibri VF50 on the Iris carrier, kernel at this base, with
the M41T0 RTC at 0x68. The core takes the atomic path only after
SYSTEM_RUNNING, so a test-only hook called xfer_atomic() with interrupts
disabled, with the two messages that i2c_smbus_xfer_emulated() builds
for a block read. Register 0x04 (0x13) as count byte: without the patch
0x13 and then 0xff (50 of 50, return 2); with it the next registers,
the same bytes as the interrupt driven read (50 of 50). With a count
byte of 1 (register 0x05): 01 ff before, 01 01 after (50 of 50 each).
drivers/i2c/busses/i2c-imx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index ccf08cd63151..1a3fc245d6ba 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1283,7 +1283,7 @@ static int i2c_imx_prepare_read(struct imx_i2c_struct *i2c_imx,
* Reset the I2CR_TXAK flag initially for SMBus block read since the
* length is unknown
*/
- if (msgs->len - 1)
+ if ((msgs->len - 1) || (msgs->flags & I2C_M_RECV_LEN))
temp &= ~I2CR_TXAK;
if (use_dma)
temp |= I2CR_DMAEN;
base-commit: 25e7ab89f4774b0f842cee0e8a20c11f755924d5
--
2.56.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] i2c: imx: acknowledge the count byte of an atomic block read
2026-11-16 12:27 [PATCH] i2c: imx: acknowledge the count byte of an atomic block read Mehmet Fide
@ 2026-11-16 12:44 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-16 12:44 UTC (permalink / raw)
To: Mehmet Fide; +Cc: imx, Frank.Li
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Medium] i2c: imx: missing TXAK for 1-byte block read in
i2c_imx_isr_read_block_data_len() [1]
--
commit 0b842b7d356553521b725411a4e465612a28658b
Author: Mehmet Fide <mehmet.fide@screeningeagle.com>
i2c: imx: acknowledge the count byte of an atomic block read
This commit clears I2CR_TXAK in i2c_imx_prepare_read() when I2C_M_RECV_LEN
is set so that atomic SMBus block reads acknowledge the initial count byte.
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index ccf08cd63151f..1a3fc245d6ba7 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1283,7 +1283,7 @@ static int i2c_imx_prepare_read(struct imx_i2c_struct *i2c_imx,
> * Reset the I2CR_TXAK flag initially for SMBus block read since the
> * length is unknown
> */
> - if (msgs->len - 1)
> + if ((msgs->len - 1) || (msgs->flags & I2C_M_RECV_LEN))
> temp &= ~I2CR_TXAK;
> if (use_dma)
> temp |= I2CR_DMAEN;
[Severity: Medium]
This problem wasn't introduced by this patch, but on the interrupt-driven
path, does i2c_imx_isr_read_block_data_len() fail to set I2CR_TXAK
[1] when an SMBus block read without PEC returns a block length of
1 byte?
Reading the count byte from IMX_I2C_I2DR immediately starts clocking in the
single payload byte. When len is 1 and the initial msg->len is 1,
i2c_imx_isr_read_block_data_len() updates msg->len to 2 and msg_buf_idx to
1 without setting I2CR_TXAK:
drivers/i2c/busses/i2c-imx.c:i2c_imx_isr_read_block_data_len() {
...
i2c_imx->msg->len += len;
i2c_imx->msg->buf[i2c_imx->msg_buf_idx++] = len;
}
On the next interrupt, i2c_imx_isr_read_continue() sees
msg_buf_idx == msg->len - 1 and misses the msg->len - 2 branch that sets
I2CR_TXAK. The controller then acknowledges the final byte before
generating a stop condition, which can cause the target device to hold SDA
low and wedge the bus.
[1] https://sashiko.dev/#/bug/linux-8e52fb9c-78a7-426b-ad34-b729995ff1c3
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116122707.1349139-1-mehmet.fide@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 12:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 12:27 [PATCH] i2c: imx: acknowledge the count byte of an atomic block read Mehmet Fide
2026-11-16 12:44 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox