Skip to content

Commit d89bb12

Browse files
committed
i2c-bcm2708: fixed baudrate
Fixed issue where the wrong CDIV value was set for baudrates below 3815 Hz (for 250MHz bus clock). In that case the computed CDIV value was more than 0xffff. However the CDIV register width is only 16 bits. This resulted in incorrect setting of CDIV and higher baudrate than intended. Example: 3500Hz -> CDIV=0x11704 -> CDIV(16bit)=0x1704 -> 42430Hz After correction: 3500Hz -> CDIV=0x11704 -> CDIV(16bit)=0xffff -> 3815Hz The correct baudrate is shown in the log after the cdiv > 0xffff correction.
1 parent ff9f6d8 commit d89bb12

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

drivers/i2c/busses/i2c-bcm2708.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ static inline void bcm2708_bsc_setup(struct bcm2708_i2c *bi)
155155

156156
bus_hz = clk_get_rate(bi->clk);
157157
cdiv = bus_hz / baudrate;
158+
if (cdiv > 0xffff)
159+
cdiv = 0xffff;
158160

159161
if (bi->msg->flags & I2C_M_RD)
160162
c |= BSC_C_INTR | BSC_C_READ;
@@ -268,6 +270,8 @@ static int bcm2708_i2c_probe(struct platform_device *pdev)
268270
struct clk *clk;
269271
struct bcm2708_i2c *bi;
270272
struct i2c_adapter *adap;
273+
unsigned long bus_hz;
274+
u32 cdiv;
271275

272276
regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
273277
if (!regs) {
@@ -343,8 +347,15 @@ static int bcm2708_i2c_probe(struct platform_device *pdev)
343347
goto out_free_irq;
344348
}
345349

346-
dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %dk)\n",
347-
pdev->id, (unsigned long)regs->start, irq, baudrate/1000);
350+
bus_hz = clk_get_rate(bi->clk);
351+
cdiv = bus_hz / baudrate;
352+
if (cdiv > 0xffff) {
353+
cdiv = 0xffff;
354+
baudrate = bus_hz / cdiv;
355+
}
356+
357+
dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
358+
pdev->id, (unsigned long)regs->start, irq, baudrate);
348359

349360
return 0;
350361

0 commit comments

Comments
 (0)