brcm2708: update against latest rpi-3.10.y branch
[openwrt.git] / target / linux / brcm2708 / patches-3.10 / 0036-set-i2c-speed-via-module-parameter-or-menuconfig.-Th.patch
1 From 17bb1be5d09fe58cd14084c5eac0052f03d6d71f Mon Sep 17 00:00:00 2001
2 From: popcornmix <popcornmix@gmail.com>
3 Date: Wed, 3 Oct 2012 20:08:19 +0100
4 Subject: [PATCH 036/174] set i2c speed via module-parameter or menuconfig.
5  Thanks FrankBoesing
6
7 ---
8  drivers/i2c/busses/Kconfig       | 11 +++++++++++
9  drivers/i2c/busses/i2c-bcm2708.c | 12 ++++++++----
10  2 files changed, 19 insertions(+), 4 deletions(-)
11
12 --- a/drivers/i2c/busses/Kconfig
13 +++ b/drivers/i2c/busses/Kconfig
14 @@ -353,6 +353,17 @@ config I2C_BCM2708
15           support for the BCM2708. BSC is a Broadcom proprietary bus compatible
16           with I2C/TWI/SMBus.
17  
18 +config I2C_BCM2708_BAUDRATE
19 +    prompt "BCM2708 I2C baudrate"
20 +       depends on I2C_BCM2708
21 +    int
22 +    default 100000
23 +    help
24 +      Set the I2C baudrate. This will alter the default value. A
25 +      different baudrate can be set by using a module parameter as well. If
26 +      no parameter is provided when loading, this is the value that will be
27 +      used.
28 +
29  config I2C_BLACKFIN_TWI
30         tristate "Blackfin TWI I2C support"
31         depends on BLACKFIN
32 --- a/drivers/i2c/busses/i2c-bcm2708.c
33 +++ b/drivers/i2c/busses/i2c-bcm2708.c
34 @@ -66,11 +66,15 @@
35  #define BSC_S_DONE             0x00000002
36  #define BSC_S_TA               0x00000001
37  
38 -#define I2C_CLOCK_HZ   100000 /* FIXME: get from DT */
39  #define I2C_TIMEOUT_MS 150
40  
41  #define DRV_NAME       "bcm2708_i2c"
42  
43 +static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
44 +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
45 +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
46 +
47 +
48  struct bcm2708_i2c {
49         struct i2c_adapter adapter;
50  
51 @@ -148,7 +152,7 @@ static inline void bcm2708_bsc_setup(str
52         u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
53  
54         bus_hz = clk_get_rate(bi->clk);
55 -       cdiv = bus_hz / I2C_CLOCK_HZ;
56 +       cdiv = bus_hz / baudrate;
57  
58         if (bi->msg->flags & I2C_M_RD)
59                 c |= BSC_C_INTR | BSC_C_READ;
60 @@ -331,8 +335,8 @@ static int bcm2708_i2c_probe(struct plat
61                 goto out_free_irq;
62         }
63  
64 -       dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d)\n",
65 -               pdev->id, (unsigned long)regs->start, irq);
66 +       dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %dk)\n",
67 +               pdev->id, (unsigned long)regs->start, irq, baudrate/1000);
68  
69         return 0;
70