[U-Boot] [PATCH v3] i2c:gpio:s5p: I2C GPIO Software implementation (via soft_i2c)

Minkyu Kang promsoft at gmail.com
Thu Aug 11 11:43:25 CEST 2011


Dear Lukasz Majewski,

On 10 August 2011 18:21, Lukasz Majewski <l.majewski at samsung.com> wrote:
> This patch adds support for software I2C for GONI reference target.
> It adds support for access to GPIOs by number, not as it is present,
> by bank and offset.
>
> Signed-off-by: Lukasz Majewski <l.majewski at samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park at samsung.com>
> Cc: Minkyu Kang <mk7.kang at samsung.com>
> Cc: Heiko Schocher <hs at denx.de>
>
> ---
> Changes for v2:
>        - Generic GPIO code added to arch/arm/gpio.h
>        - Platform dependent GPIO code added to board/samsung/goni.c
>        - Code cleanup
> Changes for v3:
>        - I2C GPIO common code added to drivers/gpio/s5p_gpio.c
>        - i2c_init_board() function added(required by soft_i2c)
> ---
>  arch/arm/include/asm/arch-s5pc1xx/gpio.h |   38 ++++++++++++++++++++++++++++++

Please adds s5pc2xx also.

>  board/samsung/goni/goni.c                |   16 ++++++++----
>  drivers/gpio/s5p_gpio.c                  |   24 +++++++++++++++++++
>  include/configs/s5p_goni.h               |   14 +++++++++++
>  4 files changed, 86 insertions(+), 6 deletions(-)
>
> diff --git a/arch/arm/include/asm/arch-s5pc1xx/gpio.h b/arch/arm/include/asm/arch-s5pc1xx/gpio.h
> index 903de9c..619ba6f 100644
> --- a/arch/arm/include/asm/arch-s5pc1xx/gpio.h
> +++ b/arch/arm/include/asm/arch-s5pc1xx/gpio.h
> @@ -134,6 +134,41 @@ unsigned int s5p_gpio_get_value(struct s5p_gpio_bank *bank, int gpio);
>  void s5p_gpio_set_pull(struct s5p_gpio_bank *bank, int gpio, int mode);
>  void s5p_gpio_set_drv(struct s5p_gpio_bank *bank, int gpio, int mode);
>  void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode);
> +struct s5p_gpio_bank *s5p_gpio_get_bank(int nr);
> +int s5p_gpio_get_pin(int nr);
> +
> +static inline int gpio_request(int gpio, const char *label)
> +{
> +       return 0;
> +}
> +
> +static inline int gpio_direction_input(int nr)
> +{
> +       s5p_gpio_direction_input(s5p_gpio_get_bank(nr),
> +                               s5p_gpio_get_pin(nr));
> +       return 0;
> +}
> +
> +static inline int gpio_direction_output(int nr, int value)
> +{
> +       s5p_gpio_direction_output(s5p_gpio_get_bank(nr),
> +                                s5p_gpio_get_pin(nr), value);
> +       return 0;
> +}
> +
> +static inline int gpio_get_value(int nr)
> +{
> +       return (int) s5p_gpio_get_value(s5p_gpio_get_bank(nr),
> +                                      s5p_gpio_get_pin(nr));
> +}
> +
> +static inline void gpio_set_value(int nr, int value)
> +{
> +       s5p_gpio_set_value(s5p_gpio_get_bank(nr),
> +                         s5p_gpio_get_pin(nr), value);
> +}
> +
> +extern struct s5pc110_gpio *s5p_gpio;
>  #endif
>
>  /* Pin configurations */
> @@ -155,4 +190,7 @@ void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode);
>  #define GPIO_DRV_FAST  0x0
>  #define GPIO_DRV_SLOW  0x1
>
> +/* GPIO pins per bank  */
> +#define GPIO_PER_BANK 8
> +
>  #endif
> diff --git a/board/samsung/goni/goni.c b/board/samsung/goni/goni.c
> index e24cd29..354f5ad 100644
> --- a/board/samsung/goni/goni.c
> +++ b/board/samsung/goni/goni.c
> @@ -28,12 +28,12 @@
>
>  DECLARE_GLOBAL_DATA_PTR;
>
> -static struct s5pc110_gpio *s5pc110_gpio;
> +struct s5pc110_gpio *s5p_gpio;

Why you removed the "static"?
And.. why you change s5pc110_gpio to s5p_gpio?
It is unrelated changes with this patch.

>
>  int board_init(void)
>  {
>        /* Set Initial global variables */
> -       s5pc110_gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
> +       s5p_gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
>
>        gd->bd->bi_arch_number = MACH_TYPE_GONI;
>        gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
> @@ -67,13 +67,17 @@ int checkboard(void)
>  }
>  #endif
>
> +#ifdef CONFIG_SOFT_I2C
> +void i2c_init_board(void) {}
> +#endif

Empty function?
then please undef CONFIG_SYS_I2C_INIT_BOARD.

> +
>  #ifdef CONFIG_GENERIC_MMC
>  int board_mmc_init(bd_t *bis)
>  {
>        int i;
>
>        /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
> -       s5p_gpio_direction_output(&s5pc110_gpio->j2, 7, 1);
> +       s5p_gpio_direction_output(&s5p_gpio->j2, 7, 1);

unrelated change.

>
>        /*
>         * MMC0 GPIO
> @@ -86,11 +90,11 @@ int board_mmc_init(bd_t *bis)
>                if (i == 2)
>                        continue;
>                /* GPG0[0:6] special function 2 */
> -               s5p_gpio_cfg_pin(&s5pc110_gpio->g0, i, 0x2);
> +               s5p_gpio_cfg_pin(&s5p_gpio->g0, i, 0x2);

ditto.

>                /* GPG0[0:6] pull disable */
> -               s5p_gpio_set_pull(&s5pc110_gpio->g0, i, GPIO_PULL_NONE);
> +               s5p_gpio_set_pull(&s5p_gpio->g0, i, GPIO_PULL_NONE);

ditto.


>                /* GPG0[0:6] drv 4x */
> -               s5p_gpio_set_drv(&s5pc110_gpio->g0, i, GPIO_DRV_4X);
> +               s5p_gpio_set_drv(&s5p_gpio->g0, i, GPIO_DRV_4X);

ditto.


>        }
>
>        return s5p_mmc_init(0, 4);
> diff --git a/drivers/gpio/s5p_gpio.c b/drivers/gpio/s5p_gpio.c
> index 2043859..e247b6f 100644
> --- a/drivers/gpio/s5p_gpio.c
> +++ b/drivers/gpio/s5p_gpio.c
> @@ -141,3 +141,27 @@ void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode)
>
>        writel(value, &bank->drv);
>  }
> +
> +#ifdef CONFIG_SOFT_I2C

I think, we don't have to use ifdef here.
These are looks common functions of GPIO.

> +/* Platform dependent functions for extracting GPIO number */
> +int s5p_gpio_get_nr(void *gp_ptr, int gpio)
> +{
> +       unsigned int offset = gp_ptr - (void *) s5p_gpio;
> +       offset /= sizeof(struct s5p_gpio_bank);
> +
> +       return (offset * GPIO_PER_BANK) + gpio;
> +}
> +
> +struct s5p_gpio_bank *s5p_gpio_get_bank(int nr)
> +{
> +       int bank = nr / GPIO_PER_BANK;
> +       bank *= sizeof(struct s5p_gpio_bank);
> +
> +       return (struct s5p_gpio_bank *) ((void *) s5p_gpio + bank);
> +}
> +
> +int s5p_gpio_get_pin(int nr)
> +{
> +       return nr % GPIO_PER_BANK;
> +}
> +#endif
> diff --git a/include/configs/s5p_goni.h b/include/configs/s5p_goni.h
> index 381bb39..620dca7 100644
> --- a/include/configs/s5p_goni.h
> +++ b/include/configs/s5p_goni.h
> @@ -223,4 +223,18 @@
>
>  #define CONFIG_SYS_INIT_SP_ADDR        (CONFIG_SYS_LOAD_ADDR - 0x1000000)
>
> +#include <asm/arch/gpio.h>
> +/*
> + * I2C Settings
> + */
> +#define S5PC110_GPIO_J3          (S5PC110_GPIO_BASE + 0x2C0)
> +#define CONFIG_SOFT_I2C_GPIO_SCL s5p_gpio_get_nr(S5PC110_GPIO_J3, 3)
> +#define CONFIG_SOFT_I2C_GPIO_SDA s5p_gpio_get_nr(S5PC110_GPIO_J3, 0)
> +
> +#define CONFIG_SOFT_I2C        1
> +#define CONFIG_SYS_I2C_SPEED   50000
> +#define CONFIG_SYS_I2C_INIT_BOARD
> +#define CONFIG_I2C_MULTI_BUS
> +#define CONFIG_SYS_MAX_I2C_BUS 7
> +
>  #endif /* __CONFIG_H */

I think, you can divide into 2 patches.
One is for GPIO.
Another is for enabling soft i2c.

Thanks
Minkyu Kang
-- 
from. prom.
www.promsoft.net


More information about the U-Boot mailing list