brcm2708: update 3.10 patches with raspberrypi/rpi-3.10.y of 27 Apr. 2014
[openwrt/svn-archive/archive.git] / target / linux / brcm2708 / patches-3.10 / 0143-i2c-bcm2708-fixed-baudrate.patch
1 From bfece5de53315bba13fd253745d12d63a8803b11 Mon Sep 17 00:00:00 2001
2 From: brabl2 <pavelvrbka@seznam.cz>
3 Date: Sat, 21 Dec 2013 21:25:36 +0100
4 Subject: [PATCH 143/196] i2c-bcm2708: fixed baudrate
5
6 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.
7 Example: 3500Hz -> CDIV=0x11704 -> CDIV(16bit)=0x1704 -> 42430Hz
8 After correction: 3500Hz -> CDIV=0x11704 -> CDIV(16bit)=0xffff -> 3815Hz
9 The correct baudrate is shown in the log after the cdiv > 0xffff correction.
10 ---
11 drivers/i2c/busses/i2c-bcm2708.c | 15 +++++++++++++--
12 1 file changed, 13 insertions(+), 2 deletions(-)
13
14 diff --git a/drivers/i2c/busses/i2c-bcm2708.c b/drivers/i2c/busses/i2c-bcm2708.c
15 index 33f4e7d..dd7a5c8 100644
16 --- a/drivers/i2c/busses/i2c-bcm2708.c
17 +++ b/drivers/i2c/busses/i2c-bcm2708.c
18 @@ -155,6 +155,8 @@ static inline void bcm2708_bsc_setup(struct bcm2708_i2c *bi)
19
20 bus_hz = clk_get_rate(bi->clk);
21 cdiv = bus_hz / baudrate;
22 + if (cdiv > 0xffff)
23 + cdiv = 0xffff;
24
25 if (bi->msg->flags & I2C_M_RD)
26 c |= BSC_C_INTR | BSC_C_READ;
27 @@ -268,6 +270,8 @@ static int bcm2708_i2c_probe(struct platform_device *pdev)
28 struct clk *clk;
29 struct bcm2708_i2c *bi;
30 struct i2c_adapter *adap;
31 + unsigned long bus_hz;
32 + u32 cdiv;
33
34 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
35 if (!regs) {
36 @@ -343,8 +347,15 @@ static int bcm2708_i2c_probe(struct platform_device *pdev)
37 goto out_free_irq;
38 }
39
40 - dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %dk)\n",
41 - pdev->id, (unsigned long)regs->start, irq, baudrate/1000);
42 + bus_hz = clk_get_rate(bi->clk);
43 + cdiv = bus_hz / baudrate;
44 + if (cdiv > 0xffff) {
45 + cdiv = 0xffff;
46 + baudrate = bus_hz / cdiv;
47 + }
48 +
49 + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
50 + pdev->id, (unsigned long)regs->start, irq, baudrate);
51
52 return 0;
53
54 --
55 1.9.1
56