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