Patchwork [U-Boot,v2] i2c:gpio:s5p: I2C GPIO Software implementation (via soft_i2c)

login
register
mail settings
Submitter Łukasz Majewski
Date July 20, 2011, 8:35 a.m.
Message ID <1311150914-9667-1-git-send-email-l.majewski@samsung.com>
Download mbox | patch
Permalink /patch/105600/
State Changes Requested
Delegated to: Minkyu Kang
Headers show

Comments

Łukasz Majewski - July 20, 2011, 8:35 a.m.
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@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Cc: Heiko Schocher <hs@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
---
 arch/arm/include/asm/arch-s5pc1xx/gpio.h |   36 ++++++++++++++++++++++++++++++
 board/samsung/goni/goni.c                |   30 +++++++++++++++++++++++-
 include/configs/s5p_goni.h               |   13 ++++++++++
 3 files changed, 77 insertions(+), 2 deletions(-)
Minkyu Kang - Aug. 9, 2011, 2:19 a.m.
Dear Lukasz Majewski,

On 20 July 2011 17:35, Lukasz Majewski <l.majewski@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@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Minkyu Kang <mk7.kang@samsung.com>
> Cc: Heiko Schocher <hs@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
> ---
>  arch/arm/include/asm/arch-s5pc1xx/gpio.h |   36 ++++++++++++++++++++++++++++++
>  board/samsung/goni/goni.c                |   30 +++++++++++++++++++++++-
>  include/configs/s5p_goni.h               |   13 ++++++++++
>  3 files changed, 77 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/include/asm/arch-s5pc1xx/gpio.h b/arch/arm/include/asm/arch-s5pc1xx/gpio.h
> index 903de9c..8d2e2e9 100644
> --- a/arch/arm/include/asm/arch-s5pc1xx/gpio.h
> +++ b/arch/arm/include/asm/arch-s5pc1xx/gpio.h

please add s5pc2xx also.

> diff --git a/board/samsung/goni/goni.c b/board/samsung/goni/goni.c
> index e24cd29..d1ff956 100644
> --- a/board/samsung/goni/goni.c
> +++ b/board/samsung/goni/goni.c
> @@ -1,7 +1,8 @@
>  /*
> - *  Copyright (C) 2008-2009 Samsung Electronics
> + *  Copyright (C) 2008-2011 Samsung Electronics
>  *  Minkyu Kang <mk7.kang@samsung.com>
>  *  Kyungmin Park <kyungmin.park@samsung.com>
> + *  Lukasz Majewski <l.majewski@samsung.com>
>  *
>  * See file CREDITS for list of people who contributed to this
>  * project.
> @@ -28,7 +29,7 @@
>
>  DECLARE_GLOBAL_DATA_PTR;
>
> -static struct s5pc110_gpio *s5pc110_gpio;
> +struct s5pc110_gpio *s5pc110_gpio;

Why?

>
>  int board_init(void)
>  {
> @@ -96,3 +97,28 @@ int board_mmc_init(bd_t *bis)
>        return s5p_mmc_init(0, 4);
>  }
>  #endif
> +
> +#ifdef CONFIG_SOFT_I2C
> +void i2c_init_board(void) {}
> +/* Platform dependent functions for extracting GPIO number */
> +int s5p_gpio_get_nr(void *gp_ptr, int gpio)
> +{
> +       unsigned int offset = gp_ptr - (void *) s5pc110_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 *) s5pc110_gpio + bank);
> +}
> +
> +int s5p_gpio_get_pin(int nr)
> +{
> +       return nr % GPIO_PER_BANK;
> +}
> +#endif

I think these codes are not board specific.
Please make common file for I2C gpio for s5p.

Thanks
Minkyu Kang

Patch

diff --git a/arch/arm/include/asm/arch-s5pc1xx/gpio.h b/arch/arm/include/asm/arch-s5pc1xx/gpio.h
index 903de9c..8d2e2e9 100644
--- a/arch/arm/include/asm/arch-s5pc1xx/gpio.h
+++ b/arch/arm/include/asm/arch-s5pc1xx/gpio.h
@@ -134,6 +134,40 @@  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);
+}
+
 #endif
 
 /* Pin configurations */
@@ -155,4 +189,6 @@  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..d1ff956 100644
--- a/board/samsung/goni/goni.c
+++ b/board/samsung/goni/goni.c
@@ -1,7 +1,8 @@ 
 /*
- *  Copyright (C) 2008-2009 Samsung Electronics
+ *  Copyright (C) 2008-2011 Samsung Electronics
  *  Minkyu Kang <mk7.kang@samsung.com>
  *  Kyungmin Park <kyungmin.park@samsung.com>
+ *  Lukasz Majewski <l.majewski@samsung.com>
  *
  * See file CREDITS for list of people who contributed to this
  * project.
@@ -28,7 +29,7 @@ 
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static struct s5pc110_gpio *s5pc110_gpio;
+struct s5pc110_gpio *s5pc110_gpio;
 
 int board_init(void)
 {
@@ -96,3 +97,28 @@  int board_mmc_init(bd_t *bis)
 	return s5p_mmc_init(0, 4);
 }
 #endif
+
+#ifdef CONFIG_SOFT_I2C
+void i2c_init_board(void) {}
+/* Platform dependent functions for extracting GPIO number */
+int s5p_gpio_get_nr(void *gp_ptr, int gpio)
+{
+	unsigned int offset = gp_ptr - (void *) s5pc110_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 *) s5pc110_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 010428b..7af1b5f 100644
--- a/include/configs/s5p_goni.h
+++ b/include/configs/s5p_goni.h
@@ -224,4 +224,17 @@ 
 
 #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_I2C_MULTI_BUS
+#define CONFIG_SYS_MAX_I2C_BUS	7
+
 #endif	/* __CONFIG_H */