[PATCH v2 19/19] i2c: Update drivers to use enum for speed

pt ptchentw at gmail.com
Mon Jan 6 11:10:23 CET 2020


Hi Simon,
     I found this commit has style problems reported by checkpatch.pl,
is it better to fix it?

Simon Glass <sjg at chromium.org> 於 2020年1月4日 週六 上午6:27寫道:

> Convert the obvious uses of i2c bus speeds to use the enum.
>
> Use livetree access for code changes.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> Changes in v2: None
>
>  drivers/i2c/exynos_hs_i2c.c  |  4 ++--
>  drivers/i2c/fsl_i2c.c        |  3 ++-
>  drivers/i2c/i2c-cdns.c       |  2 +-
>  drivers/i2c/i2c-uclass.c     | 12 ++++++------
>  drivers/i2c/i2c-uniphier-f.c |  2 +-
>  drivers/i2c/i2c-uniphier.c   |  2 +-
>  drivers/i2c/imx_lpi2c.c      |  8 ++++----
>  drivers/i2c/mv_i2c.c         |  4 ++--
>  drivers/i2c/mvtwsi.c         |  5 +++--
>  drivers/i2c/omap24xx_i2c.c   |  3 ++-
>  drivers/i2c/rcar_i2c.c       |  2 +-
>  drivers/i2c/rcar_iic.c       |  2 +-
>  drivers/i2c/s3c24x0_i2c.c    |  4 ++--
>  drivers/i2c/sandbox_i2c.c    |  3 ++-
>  14 files changed, 30 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/i2c/exynos_hs_i2c.c b/drivers/i2c/exynos_hs_i2c.c
> index a0821c9257..048272c6b5 100644
> --- a/drivers/i2c/exynos_hs_i2c.c
> +++ b/drivers/i2c/exynos_hs_i2c.c
> @@ -527,8 +527,8 @@ 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);
>
 CHECK: Alignment should match open parenthesis

>         i2c_bus->node = node;
>         i2c_bus->bus_num = dev->seq;
>
> diff --git a/drivers/i2c/fsl_i2c.c b/drivers/i2c/fsl_i2c.c
> index bbbd6ef5bf..097c54388f 100644
> --- a/drivers/i2c/fsl_i2c.c
> +++ b/drivers/i2c/fsl_i2c.c
> @@ -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);
> diff --git a/drivers/i2c/i2c-cdns.c b/drivers/i2c/i2c-cdns.c
> index ff3956d8c2..ac15da2c67 100644
> --- a/drivers/i2c/i2c-cdns.c
> +++ b/drivers/i2c/i2c-cdns.c
> @@ -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;
> diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
> index fe77e64619..2aa3efe8aa 100644
> --- a/drivers/i2c/i2c-uclass.c
> +++ b/drivers/i2c/i2c-uclass.c
> @@ -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);
>
> diff --git a/drivers/i2c/i2c-uniphier-f.c b/drivers/i2c/i2c-uniphier-f.c
> index ced606bf36..62acd28e1b 100644
> --- a/drivers/i2c/i2c-uniphier-f.c
> +++ b/drivers/i2c/i2c-uniphier-f.c
> @@ -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);
> diff --git a/drivers/i2c/i2c-uniphier.c b/drivers/i2c/i2c-uniphier.c
> index e427415e7e..07a7e03033 100644
> --- a/drivers/i2c/i2c-uniphier.c
> +++ b/drivers/i2c/i2c-uniphier.c
> @@ -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
> */
> diff --git a/drivers/i2c/imx_lpi2c.c b/drivers/i2c/imx_lpi2c.c
> index 2de99d019e..c9d3faa911 100644
> --- a/drivers/i2c/imx_lpi2c.c
> +++ b/drivers/i2c/imx_lpi2c.c
> @@ -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;
>
> diff --git a/drivers/i2c/mv_i2c.c b/drivers/i2c/mv_i2c.c
> index 8a56ef9a24..63665f0952 100644
> --- a/drivers/i2c/mv_i2c.c
> +++ b/drivers/i2c/mv_i2c.c
> @@ -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;
> diff --git a/drivers/i2c/mvtwsi.c b/drivers/i2c/mvtwsi.c
> index 0a2dafcec6..382cf4b304 100644
> --- a/drivers/i2c/mvtwsi.c
> +++ b/drivers/i2c/mvtwsi.c
> @@ -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;
>  }
>
> diff --git a/drivers/i2c/omap24xx_i2c.c b/drivers/i2c/omap24xx_i2c.c
> index 7e6e3c4f81..6e7d24d727 100644
> --- a/drivers/i2c/omap24xx_i2c.c
> +++ b/drivers/i2c/omap24xx_i2c.c
> @@ -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;
> diff --git a/drivers/i2c/rcar_i2c.c b/drivers/i2c/rcar_i2c.c
> index 2ebae349ed..05d0dc6012 100644
> --- a/drivers/i2c/rcar_i2c.c
> +++ b/drivers/i2c/rcar_i2c.c
> @@ -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);
>
> diff --git a/drivers/i2c/rcar_iic.c b/drivers/i2c/rcar_iic.c
> index 9d45f547d1..2a82eb0b76 100644
> --- a/drivers/i2c/rcar_iic.c
> +++ b/drivers/i2c/rcar_iic.c
> @@ -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 = {
> diff --git a/drivers/i2c/s3c24x0_i2c.c b/drivers/i2c/s3c24x0_i2c.c
> index ad0bc69fa3..612f5af168 100644
> --- a/drivers/i2c/s3c24x0_i2c.c
> +++ b/drivers/i2c/s3c24x0_i2c.c
> @@ -313,8 +313,8 @@ 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);
>
 CHECK: Alignment should match open parenthesis

>         i2c_bus->node = node;
>         i2c_bus->bus_num = dev->seq;
>
> diff --git a/drivers/i2c/sandbox_i2c.c b/drivers/i2c/sandbox_i2c.c
> index 0dbbaa0c44..1a4521d5b8 100644
> --- a/drivers/i2c/sandbox_i2c.c
> +++ b/drivers/i2c/sandbox_i2c.c
> @@ -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;
>                 }
> --
> 2.24.1.735.g03f4e72817-goog
>
> Best regards,
Jun Chen


More information about the U-Boot mailing list