]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
i2c: lpc32xx: correct sanity check for requested bus speed
authorVladimir Zapolskiy <vz@mleia.com>
Wed, 12 Aug 2015 17:22:13 +0000 (20:22 +0300)
committerLothar Waßmann <LW@KARO-electronics.de>
Thu, 10 Sep 2015 08:24:16 +0000 (10:24 +0200)
LPC32xx has 3 I2C bus controllers, 2 of them are used as generic ones
and their parent clock is HCLK and CLK_HI/CLK_LO registers are 10 bit
wide. This means that if HCLK is 104MHz, then minimal configurable I2C
clock speed is about 51KHz.

Only USB OTG I2C bus controller CLK registers are 8 bit wide, thus in
assumption that peripheral clock is 13MHz it allows to set the minimal
bus speed about 25.5KHz.

Check for negative half clock value is removed since it is always false.

The change fixes the following problem for I2C busses 0 and 1:

  => i2c dev 0
  Setting bus to 0
  => i2c speed 100000
  Setting bus speed to 100000 Hz
  Failure changing bus speed (-22)

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
Tested-by: Sylvain Lemieux <slemieux@tycoint.com>
drivers/i2c/lpc32xx_i2c.c

index e63260cc9b06c15ed530ff927efd385aeb33e318..47163cc65a923dc36e8b5a8e2d07a73f8851f278 100644 (file)
@@ -69,20 +69,20 @@ static unsigned int lpc32xx_i2c_set_bus_speed(struct i2c_adapter *adap,
                        unsigned int speed)
 {
        int half_period;
-       int clk_rate;
 
        if (speed == 0)
                return -EINVAL;
 
-       if (adap->hwadapnr == 2)
-               /* OTG I2C clock source is different. */
-               clk_rate = get_periph_clk_rate();
-       else
-               clk_rate = get_hclk_clk_rate();
-       half_period = (clk_rate / speed) / 2;
-
-       if ((half_period > 255) || (half_period < 0))
-               return -EINVAL;
+       /* OTG I2C clock source and CLK registers are different */
+       if (adap->hwadapnr == 2) {
+               half_period = (get_periph_clk_rate() / speed) / 2;
+               if (half_period > 0xFF)
+                       return -EINVAL;
+       } else {
+               half_period = (get_hclk_clk_rate() / speed) / 2;
+               if (half_period > 0x3FF)
+                       return -EINVAL;
+       }
 
        writel(half_period, &lpc32xx_i2c[adap->hwadapnr]->clk_hi);
        writel(half_period, &lpc32xx_i2c[adap->hwadapnr]->clk_lo);
@@ -97,7 +97,7 @@ static void _i2c_init(struct i2c_adapter *adap,
 
        /* soft reset (auto-clears) */
        writel(LPC32XX_I2C_SOFT_RESET, &i2c->ctrl);
-       /* set HI and LO periods for about 350 kHz */
+       /* set HI and LO periods for half of the default speed */
        lpc32xx_i2c_set_bus_speed(adap, requested_speed);
 }