Skip to contentSkip to conversation

i2c: i2c-bcm2708: fixes cdiv uneven number

PATCH In review Silvan Wicki 3 participants 4 messages May 1, 2015 – May 12, 2015 2 messages not in the archive I2C subsystem host drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 i2c: i2c-bcm2708: fixes cdiv uneven number

Prevents that cdiv can be an uneven number as per datasheet cdiv is always rounded down to an even number.

Datasheet at page 34 on
http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

---
 drivers/i2c/busses/i2c-bcm2708.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-bcm2708.c +11 -2
index 81e9374..dd7094a 100644
@@ -67,6 +67,9 @@
 #define BSC_S_DONE		0x00000002
 #define BSC_S_TA		0x00000001
 
+#define BSC_CDIV_MAX		0xFFFE
+#define BSC_CDIV_BITMASK	0xFFFE
+
 #define I2C_TIMEOUT_MS	150
 #define I2C_WAIT_LOOP_COUNT 40
 
@@ -441,9 +444,15 @@ static int bcm2708_i2c_probe(struct platform_device *pdev)
 
 	bus_hz = clk_get_rate(bi->clk);
 	cdiv = bus_hz / baudrate;
-	if (cdiv > 0xffff) {
-		cdiv = 0xffff;
+	/* as per datasheet cdiv is always rounded down to an even number */
+	if (cdiv > BSC_CDIV_MAX) {
+		cdiv = BSC_CDIV_MAX;
 		baudrate = bus_hz / cdiv;
+	} else {
+		if ((cdiv & BSC_CDIV_BITMASK) != cdiv) {
+			cdiv &= BSC_CDIV_BITMASK;
+			baudrate = bus_hz / cdiv;
+		}
 	}
 	bi->cdiv = cdiv;
 
Signature · 1 line
2.1.4
Reviewed-by
#2 lore raw
In reply to a message not in the archive
Quoted 8 lines · Silvan Wicki

Prevents that cdiv can be an uneven number as per datasheet cdiv is always rounded down to an even number.

Datasheet at page 34 on
http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

---

Quoted 42 lines
 drivers/i2c/busses/i2c-bcm2708.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-bcm2708.c +11 -3
index 81e9374..dd7094a 100644
@@ -67,6 +67,9 @@
 #define BSC_S_DONE             0x00000002
 #define BSC_S_TA               0x00000001
 
+#define BSC_CDIV_MAX           0xFFFE
+#define BSC_CDIV_BITMASK       0xEFFF
+
 #define I2C_TIMEOUT_MS 150
 #define I2C_WAIT_LOOP_COUNT 40
 
@@ -441,9 +444,15 @@ static int bcm2708_i2c_probe(struct platform_device *pdev)
 
        bus_hz = clk_get_rate(bi->clk);
        cdiv = bus_hz / baudrate;
-       if (cdiv > 0xffff) {
-               cdiv = 0xffff;
+       /* as per datasheet cdiv is always rounded down to an even number */
+       if (cdiv > BSC_CDIV_MAX) {
+               cdiv = BSC_CDIV_MAX;
                baudrate = bus_hz / cdiv;
+       } else {
+               if ((cdiv & BSC_CDIV_BITMASK) != cdiv) {
+                       cdiv &= BSC_CDIV_BITMASK;
+                       baudrate = bus_hz / cdiv;
+               }
        }
        bi->cdiv = cdiv;
 
--

2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to a message not in the archive
Quoted 22 lines · rajeev kumar
Quoted 8 lines · Silvan Wicki

Prevents that cdiv can be an uneven number as per datasheet cdiv is always rounded down to an even number.

Datasheet at page 34 on
http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

---

Quoted 11 lines
 drivers/i2c/busses/i2c-bcm2708.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-bcm2708.c +0 -0
index 81e9374..dd7094a 100644
@@ -67,6 +67,9 @@
 #define BSC_S_DONE             0x00000002
 #define BSC_S_TA               0x00000001
 
Quoted 2 lines

drivers/i2c/busses/i2c-bcm2708.c line 71

Quoted 2 lines
drivers/i2c/busses/i2c-bcm2708.c +2 -0
+#define BSC_CDIV_MAX           0xFFFE
+#define BSC_CDIV_BITMASK       0xEFFF

BSC_CDIV_BITMASK needs to be 0xFFFE; please don't change

Quoted 29 lines
Quoted 29 lines
drivers/i2c/busses/i2c-bcm2708.c +9 -3
+
 #define I2C_TIMEOUT_MS 150
 #define I2C_WAIT_LOOP_COUNT 40
 
@@ -441,9 +444,15 @@ static int bcm2708_i2c_probe(struct platform_device *pdev)
 
        bus_hz = clk_get_rate(bi->clk);
        cdiv = bus_hz / baudrate;
-       if (cdiv > 0xffff) {
-               cdiv = 0xffff;
+       /* as per datasheet cdiv is always rounded down to an even number */
+       if (cdiv > BSC_CDIV_MAX) {
+               cdiv = BSC_CDIV_MAX;
                baudrate = bus_hz / cdiv;
+       } else {
+               if ((cdiv & BSC_CDIV_BITMASK) != cdiv) {
+                       cdiv &= BSC_CDIV_BITMASK;
+                       baudrate = bus_hz / cdiv;
+               }
        }
        bi->cdiv = cdiv;
 
--

2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
In reply to a message not in the archive
Quoted 9 lines · Silvan Wicki

Prevents that cdiv can be an uneven number as per datasheet cdiv is always rounded down to an even number.

Datasheet at page 34 on
http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

---
 drivers/i2c/busses/i2c-bcm2708.c | 13 +++++++++++--

Which kernel are you using? We don't have such a driver in upstream.