f1404f4a9209c76ca88b0412b22b0f4a45ef0b3d
[openwrt/staging/hauke.git] /
1 From 8387866a1d91c78d9aa75052821b1dafa25fff0f Mon Sep 17 00:00:00 2001
2 From: Alex Crawford <raspberrypi/linux@code.acrawford.com>
3 Date: Fri, 28 Jan 2022 13:36:51 -0800
4 Subject: [PATCH] i2c: bcm2835: Make clock-stretch timeout configurable
5
6 The default clock-stretch timeout is 35 mS, which works well for
7 SMBus, but there are some I2C devices which can stretch the clock even
8 longer. Rather than trying to prescribe a safe default for everyone,
9 allow the timeout to be configured.
10
11 Signed-off-by: Alex Crawford <raspberrypi/linux@code.acrawford.com>
12 ---
13 drivers/i2c/busses/i2c-bcm2835.c | 10 +++++++---
14 1 file changed, 7 insertions(+), 3 deletions(-)
15
16 --- a/drivers/i2c/busses/i2c-bcm2835.c
17 +++ b/drivers/i2c/busses/i2c-bcm2835.c
18 @@ -60,6 +60,10 @@ static unsigned int debug;
19 module_param(debug, uint, 0644);
20 MODULE_PARM_DESC(debug, "1=err, 2=isr, 3=xfer");
21
22 +static unsigned int clk_tout_ms = 35; /* SMBUs-recommended 35ms */
23 +module_param(clk_tout_ms, uint, 0644);
24 +MODULE_PARM_DESC(clk_tout_ms, "clock-stretch timeout (mS)");
25 +
26 #define BCM2835_DEBUG_MAX 512
27 struct bcm2835_debug {
28 struct i2c_msg *msg;
29 @@ -219,12 +223,12 @@ static int clk_bcm2835_i2c_set_rate(stru
30 (redl << BCM2835_I2C_REDL_SHIFT));
31
32 /*
33 - * Set the clock stretch timeout to the SMBUs-recommended 35ms.
34 + * Set the clock stretch timeout.
35 */
36 - if (rate > 0xffff*1000/35)
37 + if (rate > 0xffff*1000/clk_tout_ms)
38 clk_tout = 0xffff;
39 else
40 - clk_tout = 35*rate/1000;
41 + clk_tout = clk_tout_ms*rate/1000;
42
43 bcm2835_i2c_writel(div->i2c_dev, BCM2835_I2C_CLKT, clk_tout);
44