gpiolib: add gpio_request_{in,out}put support
Subsystems (3)
v3 cover gpiolib: add gpio_request_{in,out}put support
v3:
- gpio_request() error message is <<handled by the caller>>
v2:
- add error messages to comply with requirements of Jean-Christophe
[PATCH v3 1/4] gpiolib: fix whitespaces
[PATCH v3 2/4] gpiolib: add gpio_request_{in,out}put support [PATCH v3 3/4] at91sam9*: use gpio_request_output() [PATCH v3 4/4] animeo_ip: use gpio_request_input()
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 1/4 gpiolib: fix whitespaces
--- include/gpio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/gpio.h +1 -1
@@ -6,7 +6,7 @@#ifndef CONFIG_GPIOLIB static inline int gpio_request (unsigned gpio,const char *label) { -return 0 ; +return 0 ; }static inline void gpio_free (unsigned gpio)
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 2/4 gpiolib: add gpio_request_{in,out}put support
In reply to Antony Pavlovgpio_request() followed by gpio_direction_{in,out}put is a gpio usage pattern (e.g. the similar functions are used in a ARM boards code).
--- drivers/gpio/gpio.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/gpio.h | 13 +++++++++++++ 2 files changed, 53 insertions(+)
drivers/gpio/gpio.c +40 -0
@@ -47,6 +47,46 @@ int gpio_request(unsigned gpio, const char *label)return 0 ; } +int gpio_request_input (unsigned gpio,const char *label) +{ +int ret; + + ret =gpio_request (gpio, label); +if (ret) { +pr_err ("can't request gpio %d as %s (%d)\n" , + gpio, label, ret); +return ret; + } + + ret =gpio_direction_input (gpio); +if (ret) { +pr_err ("can't configure gpio %d (%s) as input (%d)\n" , + gpio, label, ret); + } + +return ret; +} + +int gpio_request_output (unsigned gpio,const char *label,int value) +{ +int ret; + + ret =gpio_request (gpio, label); +if (ret) { +pr_err ("can't request gpio %d as %s (%d)\n" , + gpio, label, ret); +return ret; + } + + ret =gpio_direction_output (gpio, value); +if (ret) { +pr_err ("can't configure gpio %d (%s) as output (%d)\n" , + gpio, label, ret); + } + +return ret; +} +void gpio_free (unsigned gpio) {struct gpio_info *gi = &gpio_desc[gpio];
include/gpio.h +13 -0
@@ -9,11 +9,24 @@ static inline int gpio_request(unsigned gpio, const char *label) return 0; } +static inline int gpio_request_input (unsigned gpio,const char *label) +{ +return 0 ; +} + +static inline int gpio_request_output (unsigned gpio,const char *label, +int value) +{ +return 0 ; +} +static inline void gpio_free (unsigned gpio) { }#else int gpio_request (unsigned gpio,const char *label); +int gpio_request_input (unsigned gpio,const char *label); +int gpio_request_output (unsigned gpio,const char *label,int value);void gpio_free (unsigned gpio);#endif
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 3 lines · Antony Pavlov
gpio_request()followed by gpio_direction_{in,out}put is a gpio usage pattern (e.g. the similar functions are used in a ARM boards code).
NACK again
NO PRINT ERROR in generic code
this MUST be handled by the board code
I DO wand duplicated code
Quoted 90 lines
Signed-off-by Antony Pavlov <[email protected]>--- drivers/gpio/gpio.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/gpio.h | 13 +++++++++++++ 2 files changed, 53 insertions(+)drivers/gpio/gpio.c +40
-0@@ -47,6 +47,46 @@ int gpio_request(unsigned gpio, const char *label)return 0 ; } +int gpio_request_input (unsigned gpio,const char *label) +{ +int ret; + + ret =gpio_request (gpio, label); +if (ret) { +pr_err ("can't request gpio %d as %s (%d)\n" , + gpio, label, ret); +return ret; + } + + ret =gpio_direction_input (gpio); +if (ret) { +pr_err ("can't configure gpio %d (%s) as input (%d)\n" , + gpio, label, ret); + } + +return ret; +} + +int gpio_request_output (unsigned gpio,const char *label,int value) +{ +int ret; + + ret =gpio_request (gpio, label); +if (ret) { +pr_err ("can't request gpio %d as %s (%d)\n" , + gpio, label, ret); +return ret; + } + + ret =gpio_direction_output (gpio, value); +if (ret) { +pr_err ("can't configure gpio %d (%s) as output (%d)\n" , + gpio, label, ret); + } + +return ret; +} +void gpio_free (unsigned gpio) {struct gpio_info *gi = &gpio_desc[gpio];include/gpio.h +13
-0@@ -9,11 +9,24 @@ static inline int gpio_request(unsigned gpio, const char *label) return 0; } +static inline int gpio_request_input (unsigned gpio,const char *label) +{ +return 0 ; +} + +static inline int gpio_request_output (unsigned gpio,const char *label, +int value) +{ +return 0 ; +} +static inline void gpio_free (unsigned gpio) { }#else int gpio_request (unsigned gpio,const char *label); +int gpio_request_input (unsigned gpio,const char *label); +int gpio_request_output (unsigned gpio,const char *label,int value);void gpio_free (unsigned gpio);#endif Signature · 1 line
1.7.10.4
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
I just examined http://www.kernel.org/doc/Documentation/gpio.txt
I think, that I can drop my "homegrown" gpio_direction_{in,out}put functions in favour of gpio_request_one() and int gpio_request_array() functions.
Quoted 101 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 3 lines · Antony Pavlov
gpio_request()followed by gpio_direction_{in,out}put is a gpio usage pattern (e.g. the similar functions are used in a ARM boards code).NACK again
NO PRINT ERROR in generic code
this MUST be handled by the board code
I DO wand duplicated code
Quoted 90 lines
Signed-off-by Antony Pavlov <[email protected]>--- drivers/gpio/gpio.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/gpio.h | 13 +++++++++++++ 2 files changed, 53 insertions(+)drivers/gpio/gpio.c +40
-0@@ -47,6 +47,46 @@ int gpio_request(unsigned gpio, const char *label)return 0 ; } +int gpio_request_input (unsigned gpio,const char *label) +{ +int ret; + + ret =gpio_request (gpio, label); +if (ret) { +pr_err ("can't request gpio %d as %s (%d)\n" , + gpio, label, ret); +return ret; + } + + ret =gpio_direction_input (gpio); +if (ret) { +pr_err ("can't configure gpio %d (%s) as input (%d)\n" , + gpio, label, ret); + } + +return ret; +} + +int gpio_request_output (unsigned gpio,const char *label,int value) +{ +int ret; + + ret =gpio_request (gpio, label); +if (ret) { +pr_err ("can't request gpio %d as %s (%d)\n" , + gpio, label, ret); +return ret; + } + + ret =gpio_direction_output (gpio, value); +if (ret) { +pr_err ("can't configure gpio %d (%s) as output (%d)\n" , + gpio, label, ret); + } + +return ret; +} +void gpio_free (unsigned gpio) {struct gpio_info *gi = &gpio_desc[gpio];include/gpio.h +13
-1@@ -9,11 +9,24 @@ static inline int gpio_request(unsigned gpio, const char *label) return 0; } +static inline int gpio_request_input (unsigned gpio,const char *label) +{ +return 0 ; +} + +static inline int gpio_request_output (unsigned gpio,const char *label, +int value) +{ +return 0 ; +} +static inline void gpio_free (unsigned gpio) { }#else int gpio_request (unsigned gpio,const char *label); +int gpio_request_input (unsigned gpio,const char *label); +int gpio_request_output (unsigned gpio,const char *label,int value);void gpio_free (unsigned gpio);#endif --1.7.10.4
Signature · 7 lines
Best regards, Antony Pavlov _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 3/4 at91sam9*: use gpio_request_output()
In reply to Antony Pavlov--- arch/arm/boards/at91sam9261ek/init.c | 18 +----------------- arch/arm/boards/at91sam9263ek/init.c | 18 +----------------- arch/arm/boards/at91sam9m10ihd/init.c | 18 +----------------- 3 files changed, 3 insertions(+), 51 deletions(-)
arch/arm/boards/at91sam9261ek/init.c +1 -17
@@ -153,22 +153,6 @@ static void ek_add_device_udc(void) {}* LCD Controller */ #if defined(CONFIG_DRIVER_VIDEO_ATMEL) -static int ek_gpio_request_output(int gpio, const char *name) -{ - int ret; - - ret = gpio_request(gpio, name); - if (ret) { - pr_err("%s: can not request gpio %d (%d)\n", name, gpio, ret); - return ret; - } - - ret = gpio_direction_output(gpio, 1); - if (ret) - pr_err("%s: can not configure gpio %d as output (%d)\n", name, gpio, ret); - return ret; -} - /* TFT */ static struct fb_videomode at91_tft_vga_modes[] = { {
@@ -211,7 +195,7 @@ static struct atmel_lcdfb_platform_data ek_lcdc_data = {static int at91_lcdc_gpio (void ) { -return ek_gpio_request_output (AT91_PIN_PA12 ,"lcdc_tft_power" ); +return gpio_request_output (AT91_PIN_PA12 ,"lcdc_tft_power" ,1 ); }static void ek_add_device_lcdc (void )
arch/arm/boards/at91sam9263ek/init.c +1 -17
@@ -153,22 +153,6 @@ static void ek_add_device_udc(void) {}* LCD Controller */ #if defined(CONFIG_DRIVER_VIDEO_ATMEL) -static int ek_gpio_request_output(int gpio, const char *name) -{ - int ret; - - ret = gpio_request(gpio, name); - if (ret) { - pr_err("%s: can not request gpio %d (%d)\n", name, gpio, ret); - return ret; - } - - ret = gpio_direction_output(gpio, 1); - if (ret) - pr_err("%s: can not configure gpio %d as output (%d)\n", name, gpio, ret); - return ret; -} - static struct fb_videomode at91_tft_vga_modes[] = { { .name = "TX09D50VM1CCA @ 60",
@@ -208,7 +192,7 @@ static struct atmel_lcdfb_platform_data ek_lcdc_data = {static void ek_add_device_lcdc (void ) { -if (ek_gpio_request_output (AT91_PIN_PA30 ,"lcdc_power" )) +if (gpio_request_output (AT91_PIN_PA30 ,"lcdc_power" ,1 ))return ;at91_add_device_lcdc (&ek_lcdc_data);
arch/arm/boards/at91sam9m10ihd/init.c +1 -17
@@ -174,22 +174,6 @@ static int at91sam9m10g45ek_mem_init(void)mem_initcall (at91sam9m10g45ek_mem_init); #if defined(CONFIG_DRIVER_VIDEO_ATMEL) -static int ek_gpio_request_output(int gpio, const char *name) -{ - int ret; - - ret = gpio_request(gpio, name); - if (ret) { - pr_err("%s: can not request gpio %d (%d)\n", name, gpio, ret); - return ret; - } - - ret = gpio_direction_output(gpio, 1); - if (ret) - pr_err("%s: can not configure gpio %d as output (%d)\n", name, gpio, ret); - return ret; -} - static struct fb_videomode at91fb_default_monspecs[] = { { .name = "MULTEK",
@@ -230,7 +214,7 @@ static struct atmel_lcdfb_platform_data ek_lcdc_data = {static void ek_add_device_lcd (void ) { -if (ek_gpio_request_output (AT91_PIN_PE6 ,"lcdc_power" )) +if (gpio_request_output (AT91_PIN_PE6 ,"lcdc_power" ,1 ))return ;at91_add_device_lcdc (&ek_lcdc_data);
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 4/4 animeo_ip: use gpio_request_input()
In reply to Antony Pavlov--- arch/arm/boards/animeo_ip/init.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
arch/arm/boards/animeo_ip/init.c +2 -13
@@ -33,20 +33,9 @@ static int animeo_ip_get_pio_revision(int gpio, char *name) {int ret; - ret =gpio_request (gpio, name); -if (ret) { -pr_err ("animeo_ip: can not request gpio %d as %s (%d)\n" , - gpio, name, ret); + ret =gpio_request_input (gpio, name); +if (ret)return ret; - } - - ret =gpio_direction_input (gpio); - -if (ret) { -pr_err ("animeo_ip: can configure gpio %d (%s) as input (%d)\n" , - gpio, name, ret); -return ret; - }return gpio_get_value (gpio); }
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox