1 From 3239987e97227ed6dcad81498b98f6e40c2a81a8 Mon Sep 17 00:00:00 2001
2 From: Devon Fyson <devonfyson@gmail.com>
3 Date: Wed, 30 Dec 2015 16:40:47 -0500
4 Subject: [PATCH] Extend clock timeout, fix modprobe baudrate parameter.
6 Set the BSC_CLKT clock streching timeout to 35ms as per SMBus specs.\n- Increase priority of baudrate parameter passed to modprobe (in /etc/modprobe.d/*.conf or command line). Currently custom baudrates don't work because they are overridden by clock-frequency in the platform_device passed to the function.
8 drivers/i2c/busses/i2c-bcm2708.c | 45 ++++++++++++++++++++++++++--------------
9 1 file changed, 29 insertions(+), 16 deletions(-)
11 --- a/drivers/i2c/busses/i2c-bcm2708.c
12 +++ b/drivers/i2c/busses/i2c-bcm2708.c
15 #define DRV_NAME "bcm2708_i2c"
17 -static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
18 +static unsigned int baudrate_default = CONFIG_I2C_BCM2708_BAUDRATE;
19 +static unsigned int baudrate;
20 module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
21 MODULE_PARM_DESC(baudrate, "The I2C baudrate");
23 @@ -87,6 +88,7 @@ struct bcm2708_i2c {
29 struct completion done;
31 @@ -126,7 +128,7 @@ static inline void bcm2708_bsc_fifo_fill
33 static inline int bcm2708_bsc_setup(struct bcm2708_i2c *bi)
36 + u32 cdiv, s, clk_tout;
37 u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
38 int wait_loops = I2C_WAIT_LOOP_COUNT;
40 @@ -134,12 +136,14 @@ static inline int bcm2708_bsc_setup(stru
41 * Use the value that we cached in the probe.
44 + clk_tout = bi->clk_tout;
46 if (bi->msg->flags & I2C_M_RD)
47 c |= BSC_C_INTR | BSC_C_READ;
51 + bcm2708_wr(bi, BSC_CLKT, clk_tout);
52 bcm2708_wr(bi, BSC_DIV, cdiv);
53 bcm2708_wr(bi, BSC_A, bi->msg->addr);
54 bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
55 @@ -312,21 +316,24 @@ static int bcm2708_i2c_probe(struct plat
56 struct bcm2708_i2c *bi;
57 struct i2c_adapter *adap;
61 - if (pdev->dev.of_node) {
63 - pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
65 - dev_err(&pdev->dev, "alias is missing\n");
70 + baudrate = baudrate_default;
71 + if (pdev->dev.of_node) {
73 + pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
75 + dev_err(&pdev->dev, "alias is missing\n");
78 + if (!of_property_read_u32(pdev->dev.of_node,
79 + "clock-frequency", &bus_clk_rate))
80 + baudrate = bus_clk_rate;
82 + dev_warn(&pdev->dev,
83 + "Could not read clock-frequency property\n");
85 - if (!of_property_read_u32(pdev->dev.of_node,
86 - "clock-frequency", &bus_clk_rate))
87 - baudrate = bus_clk_rate;
89 - dev_warn(&pdev->dev,
90 - "Could not read clock-frequency property\n");
93 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
94 @@ -417,7 +424,13 @@ static int bcm2708_i2c_probe(struct plat
96 baudrate = bus_hz / cdiv;
99 + clk_tout = 35/1000*baudrate; //35ms timeout as per SMBus specs.
100 + if (clk_tout > 0xffff)
104 + bi->clk_tout = clk_tout;
106 dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
107 pdev->id, (unsigned long)regs->start, irq, baudrate);