brcm2708: update against latest rpi-3.10.y branch
[openwrt/svn-archive/archive.git] / target / linux / brcm2708 / patches-3.10 / 0143-i2c-bcm2708-fixed-baudrate.patch
1 From fdd5f63fca69c692eaaac24b3a3d23e2cdf2fb4d 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/174] 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 --- a/drivers/i2c/busses/i2c-bcm2708.c
15 +++ b/drivers/i2c/busses/i2c-bcm2708.c
16 @@ -155,6 +155,8 @@ static inline void bcm2708_bsc_setup(str
17
18 bus_hz = clk_get_rate(bi->clk);
19 cdiv = bus_hz / baudrate;
20 + if (cdiv > 0xffff)
21 + cdiv = 0xffff;
22
23 if (bi->msg->flags & I2C_M_RD)
24 c |= BSC_C_INTR | BSC_C_READ;
25 @@ -268,6 +270,8 @@ static int bcm2708_i2c_probe(struct plat
26 struct clk *clk;
27 struct bcm2708_i2c *bi;
28 struct i2c_adapter *adap;
29 + unsigned long bus_hz;
30 + u32 cdiv;
31
32 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
33 if (!regs) {
34 @@ -343,8 +347,15 @@ static int bcm2708_i2c_probe(struct plat
35 goto out_free_irq;
36 }
37
38 - dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %dk)\n",
39 - pdev->id, (unsigned long)regs->start, irq, baudrate/1000);
40 + bus_hz = clk_get_rate(bi->clk);
41 + cdiv = bus_hz / baudrate;
42 + if (cdiv > 0xffff) {
43 + cdiv = 0xffff;
44 + baudrate = bus_hz / cdiv;
45 + }
46 +
47 + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
48 + pdev->id, (unsigned long)regs->start, irq, baudrate);
49
50 return 0;
51