Skip to contentSkip to conversation

gpiolib: add gpio_request_{in,out}put support

PATCH Superseded Antony Pavlov 2 participants 9 messages Jan 31, 2013 – Feb 1, 2013

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

PATCH v2 1/5 gpiolib: fix whitespaces

---
 include/gpio.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/gpio.h +1 -1
index eedb980..794d959 100644
@@ -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
#2 lore raw

PATCH v2 2/5 gpiolib: add gpio_request_{in,out}put support

In reply to 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).

---
 drivers/gpio/gpio.c |   34 ++++++++++++++++++++++++++++++++++
 include/gpio.h      |   13 +++++++++++++
 2 files changed, 47 insertions(+)
drivers/gpio/gpio.c +34 -0
index d37f5a0..5876454 100644
@@ -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
index 794d959..309c1c5 100644
@@ -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
#3 lore raw

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
index 5876454..179fc7b 100644
@@ -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
#4 lore raw

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
---
 drivers/gpio/gpio.c |   29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/gpio/gpio.c +22 -7
index 5876454..179fc7b 100644
@@ -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

#5 lore raw

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
---
 drivers/gpio/gpio.c |   29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/gpio/gpio.c +22 -8
index 5876454..179fc7b 100644
@@ -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
#6 lore raw

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
---
 drivers/gpio/gpio.c |   29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/gpio/gpio.c +22 -7
index 5876454..179fc7b 100644
@@ -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 -1
 int 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

#7 lore raw

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
index 2597ff8..220dd2f 100644
@@ -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
index 90fdbec..ed133b9 100644
@@ -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
index f258caf..6159bfc 100644
@@ -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
#8 lore raw

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
index ada3bb0..a5062f1 100644
@@ -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