gpiolib: add gpio_request_{in,out}put support
Subsystems (3)
v2 cover gpiolib: add gpio_request_{in,out}put support
v2:
- add error messages to comply with requirements of Jean-Christophe
[PATCH v2 1/5] gpiolib: fix whitespaces
[PATCH v2 2/5] gpiolib: add gpio_request_{in,out}put support [PATCH v2 3/5] gpiolib: gpio_request(): add error message [PATCH v2 4/5] at91sam9*: use gpio_request_output() [PATCH v2 5/5] animeo_ip: use gpio_request_input()
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 1/5 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 v2 2/5 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 | 34 ++++++++++++++++++++++++++++++++++ include/gpio.h | 13 +++++++++++++ 2 files changed, 47 insertions(+)
drivers/gpio/gpio.c +34 -0
@@ -47,6 +47,40 @@ 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) +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) +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
PATCH v2 3/5 gpiolib: gpio_request(): add error message
In reply to Antony Pavlov--- drivers/gpio/gpio.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/gpio/gpio.c +22 -7
@@ -29,22 +29,37 @@ int gpio_request(unsigned gpio, const char *label)struct gpio_chip *chip = gi->chip;int ret; -if (!gpio_is_valid (gpio)) -return -EINVAL ; -if (!chip) -return -EINVAL ; -if (gi->requested) -return -EBUSY ; +if (!gpio_is_valid (gpio)) { + ret = -EINVAL ; + goto err; + } + +if (!chip) { + ret = -EINVAL ; + goto err; + } + +if (gi->requested) { + ret = -EBUSY ; + goto err; + } +if (chip->ops->request) { ret = chip->ops->request (chip, gpio - chip->base);if (ret) -return ret; + goto err; } gi->requested = true; gi->label =xstrdup (label);return 0 ; + +err: +pr_err ("can't request gpio %d as %s (%d)\n" , + gpio, label, ret); + +return ret; }int gpio_request_input (unsigned gpio,const char *label)
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v2 3/5] gpiolib: gpio_request(): add error message
Nack the is need to handle by the caller not here
Best Regards,
J.
Quoted 58 lines
Signed-off-by Antony Pavlov <[email protected]>--- drivers/gpio/gpio.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)drivers/gpio/gpio.c +22
-7@@ -29,22 +29,37 @@ int gpio_request(unsigned gpio, const char *label)struct gpio_chip *chip = gi->chip;int ret; -if (!gpio_is_valid (gpio)) -return -EINVAL ; -if (!chip) -return -EINVAL ; -if (gi->requested) -return -EBUSY ; +if (!gpio_is_valid (gpio)) { + ret = -EINVAL ; + goto err; + } + +if (!chip) { + ret = -EINVAL ; + goto err; + } + +if (gi->requested) { + ret = -EBUSY ; + goto err; + } +if (chip->ops->request) { ret = chip->ops->request (chip, gpio - chip->base);if (ret) -return ret; + goto err; } gi->requested = true; gi->label =xstrdup (label);return 0 ; + +err: +pr_err ("can't request gpio %d as %s (%d)\n" , + gpio, label, ret); + +return ret; }int gpio_request_input (unsigned gpio,const char *label)Signature · 1 line
1.7.10.4
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v2 3/5] gpiolib: gpio_request(): add error message
Quoted 1 line · Jean-Christophe PLAGNIOL-VILLARD
Nack the is need to handle by the caller not here
You want to get duplicated code? Ok, you will get in the "patch v3" series! :)))
Quoted 61 lines
Best Regards,
J.Quoted 58 lines
Signed-off-by Antony Pavlov <[email protected]>--- drivers/gpio/gpio.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)drivers/gpio/gpio.c +22
-8@@ -29,22 +29,37 @@ int gpio_request(unsigned gpio, const char *label)struct gpio_chip *chip = gi->chip;int ret; -if (!gpio_is_valid (gpio)) -return -EINVAL ; -if (!chip) -return -EINVAL ; -if (gi->requested) -return -EBUSY ; +if (!gpio_is_valid (gpio)) { + ret = -EINVAL ; + goto err; + } + +if (!chip) { + ret = -EINVAL ; + goto err; + } + +if (gi->requested) { + ret = -EBUSY ; + goto err; + } +if (chip->ops->request) { ret = chip->ops->request (chip, gpio - chip->base);if (ret) -return ret; + goto err; } gi->requested = true; gi->label =xstrdup (label);return 0 ; + +err: +pr_err ("can't request gpio %d as %s (%d)\n" , + gpio, label, ret); + +return ret; }int gpio_request_input (unsigned gpio,const char *label) --1.7.10.4
Signature · 7 lines
Best regards, Antony Pavlov _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v2 3/5] gpiolib: gpio_request(): add error message
Quoted 5 lines · Antony Pavlov
Quoted 1 line · Jean-Christophe PLAGNIOL-VILLARD
Nack the is need to handle by the caller not here
You want to get duplicated code? Ok, you will get in the "patch v3" series! :)))
this is not duplicated code the caller known the dev or the part of the code that fault
and we do auto request which is silent or other par of the code report the erroor at higher level to yet I do not want the generic API to print something
Best Regards,
J.
Quoted 58 lines
Quoted 58 lines
Best Regards,
J.Quoted 54 lines
Signed-off-by Antony Pavlov <[email protected]>--- drivers/gpio/gpio.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)drivers/gpio/gpio.c +22
-7@@ -29,22 +29,37 @@ int gpio_request(unsigned gpio, const char *label)struct gpio_chip *chip = gi->chip;int ret; -if (!gpio_is_valid (gpio)) -return -EINVAL ; -if (!chip) -return -EINVAL ; -if (gi->requested) -return -EBUSY ; +if (!gpio_is_valid (gpio)) { + ret = -EINVAL ; + goto err; + } + +if (!chip) { + ret = -EINVAL ; + goto err; + } + +if (gi->requested) { + ret = -EBUSY ; + goto err; + } +if (chip->ops->request) { ret = chip->ops->request (chip, gpio - chip->base);if (ret) -return ret; + goto err; } gi->requested = true; gi->label =xstrdup (label);return 0 ; + +err: +pr_err ("can't request gpio %d as %s (%d)\n" , + gpio, label, ret); + +return ret; }
Quoted 10 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpio/gpio.c +0
-1int gpio_request_input (unsigned gpio,const char *label) --1.7.10.4
Signature · 2 lines
Best regards, Antony Pavlov
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 4/5 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 v2 5/5 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