[U-Boot] [PATCH v5 10/11] exynos: gpio: Convert to driver model
Convert the exynos GPIO driver to driver model. This implements the generic GPIO interface but not the extra Exynos-specific functions. Signed-off-by: Simon Glass s...@chromium.org --- Changes in v5: - Avoid reordering functions Changes in v4: None Changes in v3: None Changes in v2: None drivers/gpio/s5p_gpio.c | 422 +++- include/configs/exynos-common.h | 4 + 2 files changed, 290 insertions(+), 136 deletions(-) diff --git a/drivers/gpio/s5p_gpio.c b/drivers/gpio/s5p_gpio.c index 99f2dd8..38ef14d 100644 --- a/drivers/gpio/s5p_gpio.c +++ b/drivers/gpio/s5p_gpio.c @@ -6,8 +6,15 @@ */ #include common.h +#include dm.h +#include errno.h +#include fdtdec.h +#include malloc.h #include asm/io.h #include asm/gpio.h +#include dm/device-internal.h + +DECLARE_GLOBAL_DATA_PTR; #define S5P_GPIO_GET_PIN(x)(x % GPIO_PER_BANK) @@ -26,100 +33,45 @@ #define RATE_MASK(gpio)(0x1 (gpio + 16)) #define RATE_SET(gpio) (0x1 (gpio + 16)) -#define name_to_gpio(n) s5p_name_to_gpio(n) -static inline int s5p_name_to_gpio(const char *name) +#define GPIO_NAME_SIZE 20 + +/* Platform data for each bank */ +struct exynos_gpio_platdata { + struct s5p_gpio_bank *bank; + const char *bank_name; /* Name of port, e.g. 'gpa0 */ +}; + +/* Information about each bank at run-time */ +struct exynos_bank_info { + char label[GPIO_PER_BANK][GPIO_NAME_SIZE]; + struct s5p_gpio_bank *bank; +}; + +static struct s5p_gpio_bank *s5p_gpio_get_bank(unsigned int gpio) { - unsigned num, irregular_set_number, irregular_bank_base; - const struct gpio_name_num_table *tabp; - char this_bank, bank_name, irregular_bank_name; - char *endp; - - /* -* The gpio name starts with either 'g' or 'gp' followed by the bank -* name character. Skip one or two characters depending on the prefix. -*/ - if (name[0] == 'g' name[1] == 'p') - name += 2; - else if (name[0] == 'g') - name++; - else - return -1; /* Name must start with 'g' */ - - bank_name = *name++; - if (!*name) - return -1; /* At least one digit is required/expected. */ - - /* -* On both exynos5 and exynos5420 architectures there is a bank of -* GPIOs which does not fall into the regular address pattern. Those -* banks are c4 on Exynos5 and y7 on Exynos5420. The rest of the below -* assignments help to handle these irregularities. -*/ -#if defined(CONFIG_EXYNOS4) || defined(CONFIG_EXYNOS5) - if (cpu_is_exynos5()) { - if (proid_is_exynos5420()) { - tabp = exynos5420_gpio_table; - irregular_bank_name = 'y'; - irregular_set_number = '7'; - irregular_bank_base = EXYNOS5420_GPIO_Y70; - } else { - tabp = exynos5_gpio_table; - irregular_bank_name = 'c'; - irregular_set_number = '4'; - irregular_bank_base = EXYNOS5_GPIO_C40; - } - } else { - if (proid_is_exynos4412()) - tabp = exynos4x12_gpio_table; - else - tabp = exynos4_gpio_table; - irregular_bank_name = 0; - irregular_set_number = 0; - irregular_bank_base = 0; - } -#else - if (cpu_is_s5pc110()) - tabp = s5pc110_gpio_table; - else - tabp = s5pc100_gpio_table; - irregular_bank_name = 0; - irregular_set_number = 0; - irregular_bank_base = 0; -#endif + const struct gpio_info *data; + unsigned int upto; + int i, count; - this_bank = tabp-bank; - do { - if (bank_name == this_bank) { - unsigned pin_index; /* pin number within the bank */ - if ((bank_name == irregular_bank_name) - (name[0] == irregular_set_number)) { - pin_index = name[1] - '0'; - /* Irregular sets have 8 pins. */ - if (pin_index = GPIO_PER_BANK) - return -1; - num = irregular_bank_base + pin_index; - } else { - pin_index = simple_strtoul(name, endp, 8); - pin_index -= tabp-bank_offset; - /* -* Sanity check: bunk 'z' has no set number, -* for all other banks there must be exactly -* two octal digits, and the resulting number -* should not exceed the number of pins in the -
[U-Boot] [PATCH v5 10/11] exynos: gpio: Convert to driver model
Convert the exynos GPIO driver to driver model. This implements the generic GPIO interface but not the extra Exynos-specific functions. Signed-off-by: Simon Glass s...@chromium.org --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/gpio/s5p_gpio.c | 419 +++- include/configs/exynos-common.h | 4 + 2 files changed, 287 insertions(+), 136 deletions(-) diff --git a/drivers/gpio/s5p_gpio.c b/drivers/gpio/s5p_gpio.c index 99f2dd8..7fd97e2 100644 --- a/drivers/gpio/s5p_gpio.c +++ b/drivers/gpio/s5p_gpio.c @@ -6,8 +6,15 @@ */ #include common.h +#include dm.h +#include errno.h +#include fdtdec.h +#include malloc.h #include asm/io.h #include asm/gpio.h +#include dm/device-internal.h + +DECLARE_GLOBAL_DATA_PTR; #define S5P_GPIO_GET_PIN(x)(x % GPIO_PER_BANK) @@ -26,101 +33,19 @@ #define RATE_MASK(gpio)(0x1 (gpio + 16)) #define RATE_SET(gpio) (0x1 (gpio + 16)) -#define name_to_gpio(n) s5p_name_to_gpio(n) -static inline int s5p_name_to_gpio(const char *name) -{ - unsigned num, irregular_set_number, irregular_bank_base; - const struct gpio_name_num_table *tabp; - char this_bank, bank_name, irregular_bank_name; - char *endp; - - /* -* The gpio name starts with either 'g' or 'gp' followed by the bank -* name character. Skip one or two characters depending on the prefix. -*/ - if (name[0] == 'g' name[1] == 'p') - name += 2; - else if (name[0] == 'g') - name++; - else - return -1; /* Name must start with 'g' */ - - bank_name = *name++; - if (!*name) - return -1; /* At least one digit is required/expected. */ - - /* -* On both exynos5 and exynos5420 architectures there is a bank of -* GPIOs which does not fall into the regular address pattern. Those -* banks are c4 on Exynos5 and y7 on Exynos5420. The rest of the below -* assignments help to handle these irregularities. -*/ -#if defined(CONFIG_EXYNOS4) || defined(CONFIG_EXYNOS5) - if (cpu_is_exynos5()) { - if (proid_is_exynos5420()) { - tabp = exynos5420_gpio_table; - irregular_bank_name = 'y'; - irregular_set_number = '7'; - irregular_bank_base = EXYNOS5420_GPIO_Y70; - } else { - tabp = exynos5_gpio_table; - irregular_bank_name = 'c'; - irregular_set_number = '4'; - irregular_bank_base = EXYNOS5_GPIO_C40; - } - } else { - if (proid_is_exynos4412()) - tabp = exynos4x12_gpio_table; - else - tabp = exynos4_gpio_table; - irregular_bank_name = 0; - irregular_set_number = 0; - irregular_bank_base = 0; - } -#else - if (cpu_is_s5pc110()) - tabp = s5pc110_gpio_table; - else - tabp = s5pc100_gpio_table; - irregular_bank_name = 0; - irregular_set_number = 0; - irregular_bank_base = 0; -#endif +#define GPIO_NAME_SIZE 20 - this_bank = tabp-bank; - do { - if (bank_name == this_bank) { - unsigned pin_index; /* pin number within the bank */ - if ((bank_name == irregular_bank_name) - (name[0] == irregular_set_number)) { - pin_index = name[1] - '0'; - /* Irregular sets have 8 pins. */ - if (pin_index = GPIO_PER_BANK) - return -1; - num = irregular_bank_base + pin_index; - } else { - pin_index = simple_strtoul(name, endp, 8); - pin_index -= tabp-bank_offset; - /* -* Sanity check: bunk 'z' has no set number, -* for all other banks there must be exactly -* two octal digits, and the resulting number -* should not exceed the number of pins in the -* bank. -*/ - if (((bank_name != 'z') !name[1]) || - *endp || - (pin_index = tabp-bank_size)) - return -1; - num = tabp-base + pin_index; - } - return num; - } - this_bank = (++tabp)-bank; - } while (this_bank); +/*
Re: [U-Boot] [PATCH v5 10/11] exynos: gpio: Convert to driver model
On Mon, Jul 28, 2014 at 06:11:37AM -0600, Simon Glass wrote: Convert the exynos GPIO driver to driver model. This implements the generic GPIO interface but not the extra Exynos-specific functions. OK, so same comment as about the serial conversion. And, I hear you about there being big changes, but I think this illustrates best why we need to keep function ordering the same: [snip] @@ -132,35 +57,34 @@ static void s5p_gpio_cfg_pin(struct s5p_gpio_bank *bank, int gpio, int cfg) writel(value, bank-con); } -static void s5p_gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en) +#ifndef CONFIG_SPL_BUILD +static int s5p_gpio_get_cfg_pin(struct s5p_gpio_bank *bank, int gpio) { unsigned int value; - value = readl(bank-dat); - value = ~DAT_MASK(gpio); - if (en) - value |= DAT_SET(gpio); - writel(value, bank-dat); + value = readl(bank-con); + value = CON_MASK(gpio); + return CON_SFR_UNSHIFT(value, gpio); } [snip] -static unsigned int s5p_gpio_get_value(struct s5p_gpio_bank *bank, int gpio) +static void s5p_gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en) { unsigned int value; value = readl(bank-dat); - return !!(value DAT_MASK(gpio)); + value = ~DAT_MASK(gpio); + if (en) + value |= DAT_SET(gpio); + writel(value, bank-dat); } We've moved the function around, the signature changed but the guts didn't at all? -- Tom signature.asc Description: Digital signature ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Re: [U-Boot] [PATCH v5 10/11] exynos: gpio: Convert to driver model
Hi Tom, On 28 July 2014 21:36, Tom Rini tr...@ti.com wrote: On Mon, Jul 28, 2014 at 06:11:37AM -0600, Simon Glass wrote: Convert the exynos GPIO driver to driver model. This implements the generic GPIO interface but not the extra Exynos-specific functions. OK, so same comment as about the serial conversion. And, I hear you about there being big changes, but I think this illustrates best why we need to keep function ordering the same: [snip] @@ -132,35 +57,34 @@ static void s5p_gpio_cfg_pin(struct s5p_gpio_bank *bank, int gpio, int cfg) writel(value, bank-con); } -static void s5p_gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en) +#ifndef CONFIG_SPL_BUILD +static int s5p_gpio_get_cfg_pin(struct s5p_gpio_bank *bank, int gpio) { unsigned int value; - value = readl(bank-dat); - value = ~DAT_MASK(gpio); - if (en) - value |= DAT_SET(gpio); - writel(value, bank-dat); + value = readl(bank-con); + value = CON_MASK(gpio); + return CON_SFR_UNSHIFT(value, gpio); } [snip] -static unsigned int s5p_gpio_get_value(struct s5p_gpio_bank *bank, int gpio) +static void s5p_gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en) { unsigned int value; value = readl(bank-dat); - return !!(value DAT_MASK(gpio)); + value = ~DAT_MASK(gpio); + if (en) + value |= DAT_SET(gpio); + writel(value, bank-dat); } We've moved the function around, the signature changed but the guts didn't at all? Yes that's just wrong, I will fix it. Regards, Simon ___ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot