[U-Boot] [PATCH v1] i2c: sunxi: add device-model support for i2c

Simon Glass sjg at chromium.org
Sun Apr 16 19:34:52 UTC 2017


Hi,

On 1 March 2017 at 14:34, Philipp Tomsich
<philipp.tomsich at theobroma-systems.com> wrote:
> The I2C block in sunxi (Allwinner SoCs) is based on Designware and uses
> the same driver as the Marvell Orion 5x and Kirkwood families.
>
> This change adds a compatible id matching the binding for sunxi
> devices, supports configuring the clocks and to release the module
> reset on sunxi platforms as directed by the device tree.
>
> As we enable DT control of this driver, we need to make sure the
> common config header (sunxi-common.h) does try to turn on support for
> the legacy I2C support.
>
> Signed-off-by: Philipp Tomsich <philipp.tomsich at theobroma-systems.com>
> ---
>  drivers/i2c/mvtwsi.c           | 42 ++++++++++++++++++++++++++++++++++++++++++
>  include/configs/sunxi-common.h |  9 ++++++---
>  2 files changed, 48 insertions(+), 3 deletions(-)

Instead of the #ifdefs can you just rely on the header files doing the
right thing?

>
> diff --git a/drivers/i2c/mvtwsi.c b/drivers/i2c/mvtwsi.c
> index 648a96e..475131b 100644
> --- a/drivers/i2c/mvtwsi.c
> +++ b/drivers/i2c/mvtwsi.c
> @@ -16,6 +16,12 @@
>  #ifdef CONFIG_DM_I2C
>  #include <dm.h>
>  #endif

Please don't put #ifdefs around header file inclusions.

> +#if defined(CONFIG_CLK)
> +#include <clk.h>
> +#endif
> +#if defined(CONFIG_DM_RESET)
> +#include <reset.h>
> +#endif
>
>  DECLARE_GLOBAL_DATA_PTR;
>
> @@ -36,6 +42,12 @@ DECLARE_GLOBAL_DATA_PTR;
>  #endif
>  #endif /* CONFIG_DM_I2C */
>
> +/* On SUNXI, we get CONFIG_SYS_TCLK from this include, so we want to
> +   always have it. */
> +#if defined(CONFIG_DM_I2C) && defined(CONFIG_ARCH_SUNXI)
> +#include <asm/arch/i2c.h>
> +#endif
> +
>  /*
>   * TWSI register structure
>   */
> @@ -81,6 +93,14 @@ struct mvtwsi_i2c_dev {
>         uint speed;
>         /* The current length of a clock period (depending on speed) */
>         uint tick;
> +#if defined(CONFIG_DM_RESET)
> +       bool reset_valid;
> +       struct reset_ctl reset;
> +#endif
> +#if defined(CONFIG_CLK)
> +       bool clk_gate_valid;
> +       struct clk clk_gate;
> +#endif
>  };
>  #endif /* CONFIG_DM_I2C */
>
> @@ -781,6 +801,14 @@ static int mvtwsi_i2c_ofdata_to_platdata(struct udevice *bus)
>                                        "u-boot,i2c-slave-addr", 0x0);
>         dev->speed = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus),
>                                     "clock-frequency", 100000);
> +#if defined(CONFIG_DM_RESET)
> +       if (reset_get_by_index(bus, 0, &dev->reset) == 0)
> +               dev->reset_valid = true;
> +#endif
> +#if defined(CONFIG_CLK)
> +       if (clk_get_by_index(bus, 0, &dev->clk_gate) == 0)
> +               dev->clk_gate_valid = true;
> +#endif
>         return 0;
>  }
>
> @@ -789,6 +817,17 @@ static int mvtwsi_i2c_probe(struct udevice *bus)
>         struct mvtwsi_i2c_dev *dev = dev_get_priv(bus);
>         uint actual_speed;
>
> +#if defined(CONFIG_DM_RESET)
> +       /* Enable the controller */
> +       if (dev->reset_valid)
> +               reset_deassert(&dev->reset);
> +#endif
> +#if defined(CONFIG_CLK)
> +       /* Open the clock-gate */
> +       if (dev->clk_gate_valid)
> +               clk_enable(&dev->clk_gate);
> +#endif
> +
>         __twsi_i2c_init(dev->base, dev->speed, dev->slaveadd, &actual_speed);
>         dev->speed = actual_speed;
>         dev->tick = calc_tick(dev->speed);
> @@ -831,6 +870,9 @@ static const struct dm_i2c_ops mvtwsi_i2c_ops = {
>  static const struct udevice_id mvtwsi_i2c_ids[] = {
>         { .compatible = "marvell,mv64xxx-i2c", },
>         { .compatible = "marvell,mv78230-i2c", },
> +#if defined(CONFIG_ARCH_SUNXI)
> +       { .compatible = "allwinner,sun6i-a31-i2c", },
> +#endif
>         { /* sentinel */ }
>  };
>
> diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
> index 4f566fa..aaab809 100644
> --- a/include/configs/sunxi-common.h
> +++ b/include/configs/sunxi-common.h
> @@ -262,11 +262,14 @@
>      defined CONFIG_SY8106A_POWER
>  #endif
>
> -#if defined CONFIG_I2C0_ENABLE || defined CONFIG_I2C1_ENABLE || \
> -    defined CONFIG_I2C2_ENABLE || defined CONFIG_I2C3_ENABLE || \
> -    defined CONFIG_I2C4_ENABLE || defined CONFIG_R_I2C_ENABLE
> +#if !defined(CONFIG_DM_I2C) && \
> +       (defined CONFIG_I2C0_ENABLE || defined CONFIG_I2C1_ENABLE ||    \
> +        defined CONFIG_I2C2_ENABLE || defined CONFIG_I2C3_ENABLE ||    \
> +        defined CONFIG_I2C4_ENABLE || defined CONFIG_R_I2C_ENABLE)
>  #define CONFIG_SYS_I2C
> +#if !defined(CONFIG_SYS_I2C_MVTWSI)
>  #define CONFIG_SYS_I2C_MVTWSI
> +#endif
>  #define CONFIG_SYS_I2C_SPEED           400000
>  #define CONFIG_SYS_I2C_SLAVE           0x7f
>  #endif
> --
> 1.9.1
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/listinfo/u-boot


More information about the U-Boot mailing list