i2c: Update drivers to use enum for speed
authorSimon Glass <sjg@chromium.org>
Thu, 23 Jan 2020 18:48:22 +0000 (11:48 -0700)
committerHeiko Schocher <hs@denx.de>
Mon, 27 Jan 2020 06:24:02 +0000 (07:24 +0100)
Convert the obvious uses of i2c bus speeds to use the enum.

Use livetree access for code changes.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heiko Schocher <hs@denx.de>
14 files changed:
drivers/i2c/exynos_hs_i2c.c
drivers/i2c/fsl_i2c.c
drivers/i2c/i2c-cdns.c
drivers/i2c/i2c-uclass.c
drivers/i2c/i2c-uniphier-f.c
drivers/i2c/i2c-uniphier.c
drivers/i2c/imx_lpi2c.c
drivers/i2c/mv_i2c.c
drivers/i2c/mvtwsi.c
drivers/i2c/omap24xx_i2c.c
drivers/i2c/rcar_i2c.c
drivers/i2c/rcar_iic.c
drivers/i2c/s3c24x0_i2c.c
drivers/i2c/sandbox_i2c.c

index a0821c92578f579cdd89ca71da38e3ec9f3934e4..9f201c66d05b6903ac0de3617d37da6be1fa404c 100644 (file)
@@ -527,8 +527,9 @@ static int s3c_i2c_ofdata_to_platdata(struct udevice *dev)
 
        i2c_bus->id = pinmux_decode_periph_id(blob, node);
 
-       i2c_bus->clock_frequency = fdtdec_get_int(blob, node,
-                                                 "clock-frequency", 100000);
+       i2c_bus->clock_frequency =
+               dev_read_u32_default(dev, "clock-frequency",
+                                    I2C_SPEED_STANDARD_RATE);
        i2c_bus->node = node;
        i2c_bus->bus_num = dev->seq;
 
index bbbd6ef5bfdc6e5534f9293a90bd8f51ccd90729..097c54388f83416bceed19d8b996f606b2b7ab1a 100644 (file)
@@ -584,7 +584,8 @@ static int fsl_i2c_ofdata_to_platdata(struct udevice *bus)
        dev->index = dev_read_u32_default(bus, "cell-index", -1);
        dev->slaveadd = dev_read_u32_default(bus, "u-boot,i2c-slave-addr",
                                             0x7f);
-       dev->speed = dev_read_u32_default(bus, "clock-frequency", 400000);
+       dev->speed = dev_read_u32_default(bus, "clock-frequency",
+                                         I2C_SPEED_FAST_RATE);
 
        if (!clk_get_by_index(bus, 0, &clock))
                dev->i2c_clk = clk_get_rate(&clock);
index ff3956d8c23d7e7f1f0d82467c888b5c305ee66c..ac15da2c67ffea715dc5b3ece1c4b032dcd9f44b 100644 (file)
@@ -213,7 +213,7 @@ static int cdns_i2c_set_bus_speed(struct udevice *dev, unsigned int speed)
        unsigned long speed_p = speed;
        int ret = 0;
 
-       if (speed > 400000) {
+       if (speed > I2C_SPEED_FAST_RATE) {
                debug("%s, failed to set clock speed to %u\n", __func__,
                      speed);
                return -EINVAL;
index fe77e646193c57449d70cf5a5acb6e163c4ae8ff..2aa3efe8aaa01e7fa8f1b86109e917fd32056535 100644 (file)
@@ -641,7 +641,8 @@ static int i2c_post_probe(struct udevice *dev)
 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
        struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev);
 
-       i2c->speed_hz = dev_read_u32_default(dev, "clock-frequency", 100000);
+       i2c->speed_hz = dev_read_u32_default(dev, "clock-frequency",
+                                            I2C_SPEED_STANDARD_RATE);
 
        return dm_i2c_set_bus_speed(dev, i2c->speed_hz);
 #else
@@ -699,11 +700,10 @@ int i2c_uclass_init(struct uclass *class)
                return -ENOMEM;
 
        /* Get the last allocated alias. */
-#if CONFIG_IS_ENABLED(OF_CONTROL)
-       priv->max_id = dev_read_alias_highest_id("i2c");
-#else
-       priv->max_id = -1;
-#endif
+       if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA))
+               priv->max_id = dev_read_alias_highest_id("i2c");
+       else
+               priv->max_id = -1;
 
        debug("%s: highest alias id is %d\n", __func__, priv->max_id);
 
index ced606bf36fd179bd6f1352b3bf2fea0855a909f..62acd28e1bc0c2db4cb6bc86cf89b16e04d0fcd3 100644 (file)
@@ -281,7 +281,7 @@ static int uniphier_fi2c_set_bus_speed(struct udevice *bus, unsigned int speed)
        struct uniphier_fi2c_regs __iomem *regs = priv->regs;
 
        /* max supported frequency is 400 kHz */
-       if (speed > 400000)
+       if (speed > I2C_SPEED_FAST_RATE)
                return -EINVAL;
 
        ret = uniphier_fi2c_check_bus_busy(priv);
index e427415e7ed72b18bb2bc479982269b797909240..07a7e03033d9cbe5432c61cd2ab554716154f99a 100644 (file)
@@ -177,7 +177,7 @@ static int uniphier_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
        struct uniphier_i2c_priv *priv = dev_get_priv(bus);
 
        /* max supported frequency is 400 kHz */
-       if (speed > 400000)
+       if (speed > I2C_SPEED_FAST_RATE)
                return -EINVAL;
 
        /* bus reset: make sure the bus is idle when change the frequency */
index 2de99d019e0869e4f7ec1d6d49c460ac40550664..c9d3faa9119f30fad2cf5b65dfa6183eb188deb3 100644 (file)
@@ -169,7 +169,7 @@ static int bus_i2c_start(struct udevice *bus, u8 addr, u8 dir)
                debug("i2c: start check busy bus: 0x%x\n", result);
 
                /* Try to init the lpi2c then check the bus busy again */
-               bus_i2c_init(bus, 100000);
+               bus_i2c_init(bus, I2C_SPEED_STANDARD_RATE);
                result = imx_lpci2c_check_busy_bus(regs);
                if (result) {
                        printf("i2c: Error check busy bus: 0x%x\n", result);
@@ -388,13 +388,13 @@ static int imx_lpi2c_probe_chip(struct udevice *bus, u32 chip,
        result = bus_i2c_start(bus, chip, 0);
        if (result) {
                bus_i2c_stop(bus);
-               bus_i2c_init(bus, 100000);
+               bus_i2c_init(bus, I2C_SPEED_STANDARD_RATE);
                return result;
        }
 
        result = bus_i2c_stop(bus);
        if (result)
-               bus_i2c_init(bus, 100000);
+               bus_i2c_init(bus, I2C_SPEED_STANDARD_RATE);
 
        return result;
 }
@@ -489,7 +489,7 @@ static int imx_lpi2c_probe(struct udevice *bus)
                        return ret;
        }
 
-       ret = bus_i2c_init(bus, 100000);
+       ret = bus_i2c_init(bus, I2C_SPEED_STANDARD_RATE);
        if (ret < 0)
                return ret;
 
index 8a56ef9a245977d788ca4c29934774bcd6cd5a82..63665f0952759a40e8ff98b4d2443bacc7d22599 100644 (file)
@@ -434,7 +434,7 @@ void i2c_init(int speed, int slaveaddr)
        base_glob = (struct mv_i2c *)CONFIG_MV_I2C_REG;
 #endif
 
-       if (speed > 100000)
+       if (speed > I2C_SPEED_STANDARD_RATE)
                val = ICR_FM;
        else
                val = ICR_SM;
@@ -565,7 +565,7 @@ static int mv_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
        struct mv_i2c_priv *priv = dev_get_priv(bus);
        u32 val;
 
-       if (speed > 100000)
+       if (speed > I2C_SPEED_STANDARD_RATE)
                val = ICR_FM;
        else
                val = ICR_SM;
index 0a2dafcec6caceb1b0b25f1417112ae8da7657af..382cf4b30413a3379e454c83c71bc47d94560d3c 100644 (file)
@@ -805,8 +805,9 @@ static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus)
                                    "cell-index", -1);
        dev->slaveadd = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus),
                                       "u-boot,i2c-slave-addr", 0x0);
-       dev->speed = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus),
-                                   "clock-frequency", 100000);
+       dev->speed = dev_read_u32_default(bus, "clock-frequency",
+                                         I2C_SPEED_STANDARD_RATE);
+
        return 0;
 }
 
index 7e6e3c4f8134c8c0547746d840f7ca4b70ec1121..6e7d24d727b354684a9e2b9a028d2e57d38a22d3 100644 (file)
@@ -1066,7 +1066,8 @@ static int omap_i2c_ofdata_to_platdata(struct udevice *bus)
        struct omap_i2c_platdata *plat = dev_get_platdata(bus);
 
        plat->base = devfdt_get_addr(bus);
-       plat->speed = dev_read_u32_default(bus, "clock-frequency", 100000);
+       plat->speed = dev_read_u32_default(bus, "clock-frequency",
+                                          I2C_SPEED_STANDARD_RATE);
        plat->ip_rev = dev_get_driver_data(bus);
 
        return 0;
index 2ebae349ed3c2123db58e539598e517ae468b3d7..05d0dc601210ebf788569f701db9a9f82443cbb5 100644 (file)
@@ -344,7 +344,7 @@ static int rcar_i2c_probe(struct udevice *dev)
        writel(0, priv->base + RCAR_I2C_ICMSR);
        writel(0, priv->base + RCAR_I2C_ICMAR);
 
-       ret = rcar_i2c_set_speed(dev, 100000);
+       ret = rcar_i2c_set_speed(dev, I2C_SPEED_STANDARD_RATE);
        if (ret)
                clk_disable(&priv->clk);
 
index 9d45f547d15313d24645df1ebf1800f68c8eb344..2a82eb0b764a081499042e9266a07d9f06c435ca 100644 (file)
@@ -248,7 +248,7 @@ static int rcar_iic_probe(struct udevice *dev)
 
        rcar_iic_finish(dev);
 
-       return rcar_iic_set_speed(dev, 100000);
+       return rcar_iic_set_speed(dev, I2C_SPEED_STANDARD_RATE);
 }
 
 static const struct dm_i2c_ops rcar_iic_ops = {
index ad0bc69fa383e7d64e10ea72131ac9548a96b0e6..68bf93b324aaed9b6c7443a552cbbabd1751f7aa 100644 (file)
@@ -313,8 +313,9 @@ static int s3c_i2c_ofdata_to_platdata(struct udevice *dev)
 
        i2c_bus->id = pinmux_decode_periph_id(blob, node);
 
-       i2c_bus->clock_frequency = fdtdec_get_int(blob, node,
-                                                 "clock-frequency", 100000);
+       i2c_bus->clock_frequency =
+               dev_read_u32_default(dev, "clock-frequency",
+                                    I2C_SPEED_STANDARD_RATE);
        i2c_bus->node = node;
        i2c_bus->bus_num = dev->seq;
 
index 0dbbaa0c44730b86370b928bd67efc71dfae9ea3..1a4521d5b8e57644cd0f85fef64cc72785bc1344 100644 (file)
@@ -72,7 +72,8 @@ static int sandbox_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
                * 400KHz for reads.
                */
                is_read = nmsgs > 1;
-               if (i2c->speed_hz > (is_read ? 400000 : 100000)) {
+               if (i2c->speed_hz > (is_read ? I2C_SPEED_FAST_RATE :
+                               I2C_SPEED_STANDARD_RATE)) {
                        debug("%s: Max speed exceeded\n", __func__);
                        return -EINVAL;
                }