mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v3 0/4] gpiolib: add gpio_request_{in,out}put support
@ 2013-02-01 18:22 Antony Pavlov
  2013-02-01 18:22 ` [PATCH v3 1/4] gpiolib: fix whitespaces Antony Pavlov
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Antony Pavlov @ 2013-02-01 18:22 UTC (permalink / raw)
  To: barebox

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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 1/4] gpiolib: fix whitespaces
  2013-02-01 18:22 [PATCH v3 0/4] gpiolib: add gpio_request_{in,out}put support Antony Pavlov
@ 2013-02-01 18:22 ` Antony Pavlov
  2013-02-01 18:22 ` [PATCH v3 2/4] gpiolib: add gpio_request_{in,out}put support Antony Pavlov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2013-02-01 18:22 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 include/gpio.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/gpio.h b/include/gpio.h
index eedb980..794d959 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -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)
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 2/4] gpiolib: add gpio_request_{in,out}put support
  2013-02-01 18:22 [PATCH v3 0/4] gpiolib: add gpio_request_{in,out}put support Antony Pavlov
  2013-02-01 18:22 ` [PATCH v3 1/4] gpiolib: fix whitespaces Antony Pavlov
@ 2013-02-01 18:22 ` Antony Pavlov
  2013-02-01 18:26   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-02-01 18:22 ` [PATCH v3 3/4] at91sam9*: use gpio_request_output() Antony Pavlov
  2013-02-01 18:22 ` [PATCH v3 4/4] animeo_ip: use gpio_request_input() Antony Pavlov
  3 siblings, 1 reply; 7+ messages in thread
From: Antony Pavlov @ 2013-02-01 18:22 UTC (permalink / raw)
  To: barebox

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).

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 drivers/gpio/gpio.c |   40 ++++++++++++++++++++++++++++++++++++++++
 include/gpio.h      |   13 +++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/drivers/gpio/gpio.c b/drivers/gpio/gpio.c
index d37f5a0..c0c66ae 100644
--- a/drivers/gpio/gpio.c
+++ b/drivers/gpio/gpio.c
@@ -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];
diff --git a/include/gpio.h b/include/gpio.h
index 794d959..309c1c5 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 3/4] at91sam9*: use gpio_request_output()
  2013-02-01 18:22 [PATCH v3 0/4] gpiolib: add gpio_request_{in,out}put support Antony Pavlov
  2013-02-01 18:22 ` [PATCH v3 1/4] gpiolib: fix whitespaces Antony Pavlov
  2013-02-01 18:22 ` [PATCH v3 2/4] gpiolib: add gpio_request_{in,out}put support Antony Pavlov
@ 2013-02-01 18:22 ` Antony Pavlov
  2013-02-01 18:22 ` [PATCH v3 4/4] animeo_ip: use gpio_request_input() Antony Pavlov
  3 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2013-02-01 18:22 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 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(-)

diff --git a/arch/arm/boards/at91sam9261ek/init.c b/arch/arm/boards/at91sam9261ek/init.c
index 2597ff8..220dd2f 100644
--- a/arch/arm/boards/at91sam9261ek/init.c
+++ b/arch/arm/boards/at91sam9261ek/init.c
@@ -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)
diff --git a/arch/arm/boards/at91sam9263ek/init.c b/arch/arm/boards/at91sam9263ek/init.c
index 90fdbec..ed133b9 100644
--- a/arch/arm/boards/at91sam9263ek/init.c
+++ b/arch/arm/boards/at91sam9263ek/init.c
@@ -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);
diff --git a/arch/arm/boards/at91sam9m10ihd/init.c b/arch/arm/boards/at91sam9m10ihd/init.c
index f258caf..6159bfc 100644
--- a/arch/arm/boards/at91sam9m10ihd/init.c
+++ b/arch/arm/boards/at91sam9m10ihd/init.c
@@ -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);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 4/4] animeo_ip: use gpio_request_input()
  2013-02-01 18:22 [PATCH v3 0/4] gpiolib: add gpio_request_{in,out}put support Antony Pavlov
                   ` (2 preceding siblings ...)
  2013-02-01 18:22 ` [PATCH v3 3/4] at91sam9*: use gpio_request_output() Antony Pavlov
@ 2013-02-01 18:22 ` Antony Pavlov
  3 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2013-02-01 18:22 UTC (permalink / raw)
  To: barebox

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 arch/arm/boards/animeo_ip/init.c |   15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/arch/arm/boards/animeo_ip/init.c b/arch/arm/boards/animeo_ip/init.c
index ada3bb0..a5062f1 100644
--- a/arch/arm/boards/animeo_ip/init.c
+++ b/arch/arm/boards/animeo_ip/init.c
@@ -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);
 }
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 2/4] gpiolib: add gpio_request_{in,out}put support
  2013-02-01 18:22 ` [PATCH v3 2/4] gpiolib: add gpio_request_{in,out}put support Antony Pavlov
@ 2013-02-01 18:26   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-02-01 19:23     ` Antony Pavlov
  0 siblings, 1 reply; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-02-01 18:26 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

On 22:22 Fri 01 Feb     , Antony Pavlov wrote:
> 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
> 
> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> ---
>  drivers/gpio/gpio.c |   40 ++++++++++++++++++++++++++++++++++++++++
>  include/gpio.h      |   13 +++++++++++++
>  2 files changed, 53 insertions(+)
> 
> diff --git a/drivers/gpio/gpio.c b/drivers/gpio/gpio.c
> index d37f5a0..c0c66ae 100644
> --- a/drivers/gpio/gpio.c
> +++ b/drivers/gpio/gpio.c
> @@ -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];
> diff --git a/include/gpio.h b/include/gpio.h
> index 794d959..309c1c5 100644
> --- a/include/gpio.h
> +++ b/include/gpio.h
> @@ -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
> 

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 2/4] gpiolib: add gpio_request_{in,out}put support
  2013-02-01 18:26   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-02-01 19:23     ` Antony Pavlov
  0 siblings, 0 replies; 7+ messages in thread
From: Antony Pavlov @ 2013-02-01 19:23 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: 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.

On 1 February 2013 22:26, Jean-Christophe PLAGNIOL-VILLARD
<plagnioj@jcrosoft.com> wrote:
> On 22:22 Fri 01 Feb     , Antony Pavlov wrote:
>> 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
>>
>> Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
>> ---
>>  drivers/gpio/gpio.c |   40 ++++++++++++++++++++++++++++++++++++++++
>>  include/gpio.h      |   13 +++++++++++++
>>  2 files changed, 53 insertions(+)
>>
>> diff --git a/drivers/gpio/gpio.c b/drivers/gpio/gpio.c
>> index d37f5a0..c0c66ae 100644
>> --- a/drivers/gpio/gpio.c
>> +++ b/drivers/gpio/gpio.c
>> @@ -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];
>> diff --git a/include/gpio.h b/include/gpio.h
>> index 794d959..309c1c5 100644
>> --- a/include/gpio.h
>> +++ b/include/gpio.h
>> @@ -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
>>



-- 
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-02-01 19:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-01 18:22 [PATCH v3 0/4] gpiolib: add gpio_request_{in,out}put support Antony Pavlov
2013-02-01 18:22 ` [PATCH v3 1/4] gpiolib: fix whitespaces Antony Pavlov
2013-02-01 18:22 ` [PATCH v3 2/4] gpiolib: add gpio_request_{in,out}put support Antony Pavlov
2013-02-01 18:26   ` Jean-Christophe PLAGNIOL-VILLARD
2013-02-01 19:23     ` Antony Pavlov
2013-02-01 18:22 ` [PATCH v3 3/4] at91sam9*: use gpio_request_output() Antony Pavlov
2013-02-01 18:22 ` [PATCH v3 4/4] animeo_ip: use gpio_request_input() Antony Pavlov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox