[U-Boot] [PATCH 1/2 v4] i2c:gpio:s5p: I2C GPIO Software implementation (via soft_i2c)
Lukasz Majewski
l.majewski at samsung.com
Fri Aug 12 10:32:10 CEST 2011
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)
Changes for v4:
- i2x_init_board() removed
- s5pc210 support added
- GPIO code and I2C enable code split to separate patches
---
arch/arm/include/asm/arch-s5pc1xx/gpio.h | 38 +++++++++++++++++++++++++++++
arch/arm/include/asm/arch-s5pc2xx/gpio.h | 39 ++++++++++++++++++++++++++++++
board/samsung/goni/goni.c | 2 +
board/samsung/universal_c210/universal.c | 2 +
drivers/gpio/s5p_gpio.c | 21 ++++++++++++++++
5 files changed, 102 insertions(+), 0 deletions(-)
diff --git a/arch/arm/include/asm/arch-s5pc1xx/gpio.h b/arch/arm/include/asm/arch-s5pc1xx/gpio.h
index 903de9c..4a5ca87 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 void *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/arch/arm/include/asm/arch-s5pc2xx/gpio.h b/arch/arm/include/asm/arch-s5pc2xx/gpio.h
index 8db5895..82aaab5 100644
--- a/arch/arm/include/asm/arch-s5pc2xx/gpio.h
+++ b/arch/arm/include/asm/arch-s5pc2xx/gpio.h
@@ -88,6 +88,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 void *s5p_gpio;
#endif
/* Pin configurations */
@@ -108,4 +143,8 @@ void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode);
#define GPIO_DRV_4X 0x3
#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..adc1e0e 100644
--- a/board/samsung/goni/goni.c
+++ b/board/samsung/goni/goni.c
@@ -29,11 +29,13 @@
DECLARE_GLOBAL_DATA_PTR;
static struct s5pc110_gpio *s5pc110_gpio;
+void *s5p_gpio;
int board_init(void)
{
/* Set Initial global variables */
s5pc110_gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
+ s5p_gpio = (void *) s5pc110_gpio;
gd->bd->bi_arch_number = MACH_TYPE_GONI;
gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
diff --git a/board/samsung/universal_c210/universal.c b/board/samsung/universal_c210/universal.c
index 1b27e8b..b4a7f86 100644
--- a/board/samsung/universal_c210/universal.c
+++ b/board/samsung/universal_c210/universal.c
@@ -32,6 +32,7 @@ DECLARE_GLOBAL_DATA_PTR;
struct s5pc210_gpio_part1 *gpio1;
struct s5pc210_gpio_part2 *gpio2;
+void *s5p_gpio;
unsigned int board_rev;
u32 get_board_rev(void)
@@ -50,6 +51,7 @@ int board_init(void)
{
gpio1 = (struct s5pc210_gpio_part1 *) S5PC210_GPIO_PART1_BASE;
gpio2 = (struct s5pc210_gpio_part2 *) S5PC210_GPIO_PART2_BASE;
+ s5p_gpio = (void *) gpio1; /* ptr used with I2C SW implementation */
gd->bd->bi_arch_number = MACH_TYPE_UNIVERSAL_C210;
gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
diff --git a/drivers/gpio/s5p_gpio.c b/drivers/gpio/s5p_gpio.c
index 2043859..49c43c7 100644
--- a/drivers/gpio/s5p_gpio.c
+++ b/drivers/gpio/s5p_gpio.c
@@ -141,3 +141,24 @@ void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode)
writel(value, &bank->drv);
}
+
+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;
+}
--
1.7.2.3
More information about the U-Boot
mailing list