Skip to contentSkip to conversation

i2c: i2c-bcm2708: fixes cdiv uneven number

PATCH Superseded Silvan Wicki 2 participants 2 messages Apr 30, 2015 – May 1, 2015 1 message not in the archive I2C subsystem host drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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 | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-bcm2708.c +8 -2
index 81e9374..454ab48 100644
@@ -441,9 +441,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 > 0xfffe) {
+		cdiv = 0xfffe;
 		baudrate = bus_hz / cdiv;
+	} else {
+		if ((cdiv & 0xfffe) != cdiv) {
+			cdiv &= 0xfffe;
+			baudrate = bus_hz / cdiv;
+		}
 	}
 	bi->cdiv = cdiv;
 
Signature · 1 line
2.1.4

A message that is not in the archive (sent off-list or not yet received): 1430417266-14900-1-git-send-email-linux_wi-ADq4ffItWIY@public.gmane.org

#2 lore raw
Quoted 16 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 | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-bcm2708.c +0 -0
index 81e9374..454ab48 100644

drivers/i2c/busses/i2c-bcm2708.c static int bcm2708_i2c_probe(struct platform_device *pdev) · line 446

Quoted 8 lines
drivers/i2c/busses/i2c-bcm2708.c +3 -2
@@ -441,9 +441,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 > 0xfffe) {
+               cdiv = 0xfffe;

Use #define

~Rajeev

Quoted 16 lines
drivers/i2c/busses/i2c-bcm2708.c +5 -1
                baudrate = bus_hz / cdiv;
+       } else {
+               if ((cdiv & 0xfffe) != cdiv) {
+                       cdiv &= 0xfffe;
+                       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