brcm2708: update linux 4.4 patches to latest version
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0121-Extend-clock-timeout-fix-modprobe-baudrate-parameter.patch
1 From 29171b2e2b69a4edb84bd228e1d9ea0451e7dcd2 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.
5
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.
7 ---
8 drivers/i2c/busses/i2c-bcm2708.c | 45 ++++++++++++++++++++++++++--------------
9 1 file changed, 29 insertions(+), 16 deletions(-)
10
11 --- a/drivers/i2c/busses/i2c-bcm2708.c
12 +++ b/drivers/i2c/busses/i2c-bcm2708.c
13 @@ -71,7 +71,8 @@
14
15 #define DRV_NAME "bcm2708_i2c"
16
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");
22
23 @@ -87,6 +88,7 @@ struct bcm2708_i2c {
24 int irq;
25 struct clk *clk;
26 u32 cdiv;
27 + u32 clk_tout;
28
29 struct completion done;
30
31 @@ -126,7 +128,7 @@ static inline void bcm2708_bsc_fifo_fill
32
33 static inline int bcm2708_bsc_setup(struct bcm2708_i2c *bi)
34 {
35 - u32 cdiv, s;
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;
39
40 @@ -134,12 +136,14 @@ static inline int bcm2708_bsc_setup(stru
41 * Use the value that we cached in the probe.
42 */
43 cdiv = bi->cdiv;
44 + clk_tout = bi->clk_tout;
45
46 if (bi->msg->flags & I2C_M_RD)
47 c |= BSC_C_INTR | BSC_C_READ;
48 else
49 c |= BSC_C_INTT;
50
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;
58 unsigned long bus_hz;
59 - u32 cdiv;
60 -
61 - if (pdev->dev.of_node) {
62 - u32 bus_clk_rate;
63 - pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
64 - if (pdev->id < 0) {
65 - dev_err(&pdev->dev, "alias is missing\n");
66 - return -EINVAL;
67 + u32 cdiv, clk_tout;
68 +
69 + if (!baudrate) {
70 + baudrate = baudrate_default;
71 + if (pdev->dev.of_node) {
72 + u32 bus_clk_rate;
73 + pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
74 + if (pdev->id < 0) {
75 + dev_err(&pdev->dev, "alias is missing\n");
76 + return -EINVAL;
77 + }
78 + if (!of_property_read_u32(pdev->dev.of_node,
79 + "clock-frequency", &bus_clk_rate))
80 + baudrate = bus_clk_rate;
81 + else
82 + dev_warn(&pdev->dev,
83 + "Could not read clock-frequency property\n");
84 }
85 - if (!of_property_read_u32(pdev->dev.of_node,
86 - "clock-frequency", &bus_clk_rate))
87 - baudrate = bus_clk_rate;
88 - else
89 - dev_warn(&pdev->dev,
90 - "Could not read clock-frequency property\n");
91 }
92
93 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
94 @@ -417,7 +424,13 @@ static int bcm2708_i2c_probe(struct plat
95 cdiv = 0xffff;
96 baudrate = bus_hz / cdiv;
97 }
98 +
99 + clk_tout = 35/1000*baudrate; //35ms timeout as per SMBus specs.
100 + if (clk_tout > 0xffff)
101 + clk_tout = 0xffff;
102 +
103 bi->cdiv = cdiv;
104 + bi->clk_tout = clk_tout;
105
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);