1 From ceee7776c010c5f09d30985c9e5223b363a6172a Mon Sep 17 00:00:00 2001
2 From: Sven Eckelmann <sven@narfation.org>
3 Date: Sun, 10 Aug 2025 20:05:15 +0200
4 Subject: [PATCH] i2c: rtl9300: Increase timeout for transfer polling
6 The timeout for transfers was only set to 2ms. Because of this relatively
7 low limit, 12-byte read operations to the frontend MCU of a RTL8239 POE PSE
8 chip cluster was consistently resulting in a timeout.
10 The original OpenWrt downstream driver [1] was not using any timeout limit
11 at all. This is also possible by setting the timeout_us parameter of
12 regmap_read_poll_timeout() to 0. But since the driver currently implements
13 the ETIMEDOUT error, it is more sensible to increase the timeout in such a
14 way that communication with the (quite common) Realtek I2C-connected POE
15 management solution is possible.
17 [1] https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=target/linux/realtek/files-6.12/drivers/i2c/busses/i2c-rtl9300.c;h=c4d973195ef39dc56d6207e665d279745525fcac#l202
19 Fixes: c366be720235 ("i2c: Add driver for the RTL9300 I2C controller")
20 Signed-off-by: Sven Eckelmann <sven@narfation.org>
21 Cc: <stable@vger.kernel.org> # v6.13+
22 Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
23 Tested-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
24 Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
25 Link: https://lore.kernel.org/r/20250810-i2c-rtl9300-multi-byte-v5-3-cd9dca0db722@narfation.org
27 diff --git a/drivers/i2c/busses/i2c-rtl9300.c b/drivers/i2c/busses/i2c-rtl9300.c
28 index 4a538b266080..4a282d57e2c1 100644
29 --- a/drivers/i2c/busses/i2c-rtl9300.c
30 +++ b/drivers/i2c/busses/i2c-rtl9300.c
31 @@ -175,7 +175,7 @@ static int rtl9300_i2c_execute_xfer(struct rtl9300_i2c *i2c, char read_write,
34 ret = regmap_read_poll_timeout(i2c->regmap, i2c->reg_base + RTL9300_I2C_MST_CTRL1,
35 - val, !(val & RTL9300_I2C_MST_CTRL1_I2C_TRIG), 100, 2000);
36 + val, !(val & RTL9300_I2C_MST_CTRL1_I2C_TRIG), 100, 100000);