aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/brcm2708/patches-4.4/0142-FIXUP-i2c_bcm2708-Don-t-change-module-baudrate-param.patch
blob: e2f4ba46ac25aeb34e089010b34ca9fbbe028c79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
From 3b0e6758d12a326405c257fe074dab570b1de92e Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.org>
Date: Tue, 19 Jan 2016 16:28:05 +0000
Subject: [PATCH 142/156] FIXUP i2c_bcm2708: Don't change module baudrate
 parameter

Overwriting the baudrate module parameter creates an apparent
forced baudrate for i2c busses after the first. Not only does this
override the baudrate from DT it also prevents the bus ID from
being initialised.

Also fix whitespace errors.
---
 drivers/i2c/busses/i2c-bcm2708.c | 48 +++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 23 deletions(-)

--- a/drivers/i2c/busses/i2c-bcm2708.c
+++ b/drivers/i2c/busses/i2c-bcm2708.c
@@ -71,7 +71,6 @@
 
 #define DRV_NAME		"bcm2708_i2c"
 
-static unsigned int baudrate_default = CONFIG_I2C_BCM2708_BAUDRATE;
 static unsigned int baudrate;
 module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
 MODULE_PARM_DESC(baudrate, "The I2C baudrate");
@@ -317,25 +316,28 @@ static int bcm2708_i2c_probe(struct plat
 	struct i2c_adapter *adap;
 	unsigned long bus_hz;
 	u32 cdiv, clk_tout;
-	
-	if (!baudrate) {
-		baudrate = baudrate_default;
-		if (pdev->dev.of_node) {
-			u32 bus_clk_rate;
-			pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
-			if (pdev->id < 0) {
-				dev_err(&pdev->dev, "alias is missing\n");
-				return -EINVAL;
-			}
-			if (!of_property_read_u32(pdev->dev.of_node,
-						"clock-frequency", &bus_clk_rate))
-				baudrate = bus_clk_rate;
-			else
-				dev_warn(&pdev->dev,
-					"Could not read clock-frequency property\n");
+	u32 baud;
+
+	baud = CONFIG_I2C_BCM2708_BAUDRATE;
+
+	if (pdev->dev.of_node) {
+		u32 bus_clk_rate;
+		pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
+		if (pdev->id < 0) {
+			dev_err(&pdev->dev, "alias is missing\n");
+			return -EINVAL;
 		}
+		if (!of_property_read_u32(pdev->dev.of_node,
+					"clock-frequency", &bus_clk_rate))
+			baud = bus_clk_rate;
+		else
+			dev_warn(&pdev->dev,
+				"Could not read clock-frequency property\n");
 	}
 
+	if (baudrate)
+		baud = baudrate;
+
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!regs) {
 		dev_err(&pdev->dev, "could not get IO memory\n");
@@ -419,21 +421,21 @@ static int bcm2708_i2c_probe(struct plat
 	}
 
 	bus_hz = clk_get_rate(bi->clk);
-	cdiv = bus_hz / baudrate;
+	cdiv = bus_hz / baud;
 	if (cdiv > 0xffff) {
 		cdiv = 0xffff;
-		baudrate = bus_hz / cdiv;
+		baud = bus_hz / cdiv;
 	}
-	
- 	clk_tout = 35/1000*baudrate; //35ms timeout as per SMBus specs.
- 	if (clk_tout > 0xffff)
+
+	clk_tout = 35/1000*baud; //35ms timeout as per SMBus specs.
+	if (clk_tout > 0xffff)
 		clk_tout = 0xffff;
 	
 	bi->cdiv = cdiv;
 	bi->clk_tout = clk_tout;
 
 	dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
-		pdev->id, (unsigned long)regs->start, irq, baudrate);
+		pdev->id, (unsigned long)regs->start, irq, baud);
 
 	return 0;