brcm2708: update linux 4.4 patches to latest version
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0139-FIXUP-i2c_bcm2708-Don-t-change-module-baudrate-param.patch
1 From 68f3ff91c01ecdd6be1738429f586095427cecd7 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Tue, 19 Jan 2016 16:28:05 +0000
4 Subject: [PATCH] FIXUP i2c_bcm2708: Don't change module baudrate parameter
5
6 Overwriting the baudrate module parameter creates an apparent
7 forced baudrate for i2c busses after the first. Not only does this
8 override the baudrate from DT it also prevents the bus ID from
9 being initialised.
10
11 Also fix whitespace errors.
12 ---
13 drivers/i2c/busses/i2c-bcm2708.c | 48 +++++++++++++++++++++-------------------
14 1 file changed, 25 insertions(+), 23 deletions(-)
15
16 --- a/drivers/i2c/busses/i2c-bcm2708.c
17 +++ b/drivers/i2c/busses/i2c-bcm2708.c
18 @@ -71,7 +71,6 @@
19
20 #define DRV_NAME "bcm2708_i2c"
21
22 -static unsigned int baudrate_default = CONFIG_I2C_BCM2708_BAUDRATE;
23 static unsigned int baudrate;
24 module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
25 MODULE_PARM_DESC(baudrate, "The I2C baudrate");
26 @@ -317,25 +316,28 @@ static int bcm2708_i2c_probe(struct plat
27 struct i2c_adapter *adap;
28 unsigned long bus_hz;
29 u32 cdiv, clk_tout;
30 -
31 - if (!baudrate) {
32 - baudrate = baudrate_default;
33 - if (pdev->dev.of_node) {
34 - u32 bus_clk_rate;
35 - pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
36 - if (pdev->id < 0) {
37 - dev_err(&pdev->dev, "alias is missing\n");
38 - return -EINVAL;
39 - }
40 - if (!of_property_read_u32(pdev->dev.of_node,
41 - "clock-frequency", &bus_clk_rate))
42 - baudrate = bus_clk_rate;
43 - else
44 - dev_warn(&pdev->dev,
45 - "Could not read clock-frequency property\n");
46 + u32 baud;
47 +
48 + baud = CONFIG_I2C_BCM2708_BAUDRATE;
49 +
50 + if (pdev->dev.of_node) {
51 + u32 bus_clk_rate;
52 + pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
53 + if (pdev->id < 0) {
54 + dev_err(&pdev->dev, "alias is missing\n");
55 + return -EINVAL;
56 }
57 + if (!of_property_read_u32(pdev->dev.of_node,
58 + "clock-frequency", &bus_clk_rate))
59 + baud = bus_clk_rate;
60 + else
61 + dev_warn(&pdev->dev,
62 + "Could not read clock-frequency property\n");
63 }
64
65 + if (baudrate)
66 + baud = baudrate;
67 +
68 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
69 if (!regs) {
70 dev_err(&pdev->dev, "could not get IO memory\n");
71 @@ -419,21 +421,21 @@ static int bcm2708_i2c_probe(struct plat
72 }
73
74 bus_hz = clk_get_rate(bi->clk);
75 - cdiv = bus_hz / baudrate;
76 + cdiv = bus_hz / baud;
77 if (cdiv > 0xffff) {
78 cdiv = 0xffff;
79 - baudrate = bus_hz / cdiv;
80 + baud = bus_hz / cdiv;
81 }
82 -
83 - clk_tout = 35/1000*baudrate; //35ms timeout as per SMBus specs.
84 - if (clk_tout > 0xffff)
85 +
86 + clk_tout = 35/1000*baud; //35ms timeout as per SMBus specs.
87 + if (clk_tout > 0xffff)
88 clk_tout = 0xffff;
89
90 bi->cdiv = cdiv;
91 bi->clk_tout = clk_tout;
92
93 dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
94 - pdev->id, (unsigned long)regs->start, irq, baudrate);
95 + pdev->id, (unsigned long)regs->start, irq, baud);
96
97 return 0;
98