linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: rtc-v3020: use gpio_request_one()
@ 2013-02-21  8:31 Jingoo Han
  2013-02-21  8:48 ` Igor Grinberg
  2013-02-22  2:19 ` [PATCH V2] rtc: rtc-v3020: use gpio_request_array() Jingoo Han
  0 siblings, 2 replies; 6+ messages in thread
From: Jingoo Han @ 2013-02-21  8:31 UTC (permalink / raw)
  To: 'Andrew Morton'
  Cc: linux-kernel, 'Alessandro Zummo',
	rtc-linux, 'Jingoo Han'

Using gpio_request_one() can make the code simpler because it can
set the direction and initial value in one shot.

Signed-off-by: Jingoo Han <jg1.han@samsung.com>
---
 drivers/rtc/rtc-v3020.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
index bca5d67..d59cd24 100644
--- a/drivers/rtc/rtc-v3020.c
+++ b/drivers/rtc/rtc-v3020.c
@@ -125,11 +125,10 @@ static int v3020_gpio_map(struct v3020 *chip, struct platform_device *pdev,
 	v3020_gpio[V3020_IO].gpio = pdata->gpio_io;
 
 	for (i = 0; i < ARRAY_SIZE(v3020_gpio); i++) {
-		err = gpio_request(v3020_gpio[i].gpio, v3020_gpio[i].name);
+		err = gpio_request_one(v3020_gpio[i].gpio, GPIOF_OUT_INIT_HIGH,
+					v3020_gpio[i].name);
 		if (err)
 			goto err_request;
-
-		gpio_direction_output(v3020_gpio[i].gpio, 1);
 	}
 
 	chip->gpio = v3020_gpio;
-- 
1.7.2.5



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

* Re: [PATCH] rtc: rtc-v3020: use gpio_request_one()
  2013-02-21  8:31 [PATCH] rtc: rtc-v3020: use gpio_request_one() Jingoo Han
@ 2013-02-21  8:48 ` Igor Grinberg
  2013-02-22  2:13   ` Jingoo Han
  2013-02-22  2:19 ` [PATCH V2] rtc: rtc-v3020: use gpio_request_array() Jingoo Han
  1 sibling, 1 reply; 6+ messages in thread
From: Igor Grinberg @ 2013-02-21  8:48 UTC (permalink / raw)
  To: Jingoo Han
  Cc: 'Andrew Morton', linux-kernel, 'Alessandro Zummo',
	rtc-linux

On 02/21/13 10:31, Jingoo Han wrote:
> Using gpio_request_one() can make the code simpler because it can
> set the direction and initial value in one shot.

If you are on this, then I think converting to gpio_request_array()
would be even better.

> 
> Signed-off-by: Jingoo Han <jg1.han@samsung.com>
> ---
>  drivers/rtc/rtc-v3020.c |    5 ++---
>  1 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
> index bca5d67..d59cd24 100644
> --- a/drivers/rtc/rtc-v3020.c
> +++ b/drivers/rtc/rtc-v3020.c
> @@ -125,11 +125,10 @@ static int v3020_gpio_map(struct v3020 *chip, struct platform_device *pdev,
>  	v3020_gpio[V3020_IO].gpio = pdata->gpio_io;
>  
>  	for (i = 0; i < ARRAY_SIZE(v3020_gpio); i++) {
> -		err = gpio_request(v3020_gpio[i].gpio, v3020_gpio[i].name);
> +		err = gpio_request_one(v3020_gpio[i].gpio, GPIOF_OUT_INIT_HIGH,
> +					v3020_gpio[i].name);
>  		if (err)
>  			goto err_request;
> -
> -		gpio_direction_output(v3020_gpio[i].gpio, 1);
>  	}

If you convert to gpio_request_array(), you can also drop the for loop.

>  
>  	chip->gpio = v3020_gpio;
> 

-- 
Regards,
Igor.

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

* Re: [PATCH] rtc: rtc-v3020: use gpio_request_one()
  2013-02-21  8:48 ` Igor Grinberg
@ 2013-02-22  2:13   ` Jingoo Han
  0 siblings, 0 replies; 6+ messages in thread
From: Jingoo Han @ 2013-02-22  2:13 UTC (permalink / raw)
  To: 'Igor Grinberg'
  Cc: 'Andrew Morton', linux-kernel, 'Alessandro Zummo',
	rtc-linux, 'Jingoo Han'

On Thursday, February 21, 2013 5:48 PM, Igor Grinberg wrote:
> 
> On 02/21/13 10:31, Jingoo Han wrote:
> > Using gpio_request_one() can make the code simpler because it can
> > set the direction and initial value in one shot.
> 
> If you are on this, then I think converting to gpio_request_array()
> would be even better.

Hi Igor Grinberg,

OK, I see.
I will use gpio_request_array() and send v2 patch soon.
Thank you for your comment.


Best regards,
Jingoo Han

> 
> >
> > Signed-off-by: Jingoo Han <jg1.han@samsung.com>
> > ---
> >  drivers/rtc/rtc-v3020.c |    5 ++---
> >  1 files changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
> > index bca5d67..d59cd24 100644
> > --- a/drivers/rtc/rtc-v3020.c
> > +++ b/drivers/rtc/rtc-v3020.c
> > @@ -125,11 +125,10 @@ static int v3020_gpio_map(struct v3020 *chip, struct platform_device *pdev,
> >  	v3020_gpio[V3020_IO].gpio = pdata->gpio_io;
> >
> >  	for (i = 0; i < ARRAY_SIZE(v3020_gpio); i++) {
> > -		err = gpio_request(v3020_gpio[i].gpio, v3020_gpio[i].name);
> > +		err = gpio_request_one(v3020_gpio[i].gpio, GPIOF_OUT_INIT_HIGH,
> > +					v3020_gpio[i].name);
> >  		if (err)
> >  			goto err_request;
> > -
> > -		gpio_direction_output(v3020_gpio[i].gpio, 1);
> >  	}
> 
> If you convert to gpio_request_array(), you can also drop the for loop.
> 
> >
> >  	chip->gpio = v3020_gpio;
> >
> 
> --
> Regards,
> Igor.


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

* [PATCH V2] rtc: rtc-v3020: use gpio_request_array()
  2013-02-21  8:31 [PATCH] rtc: rtc-v3020: use gpio_request_one() Jingoo Han
  2013-02-21  8:48 ` Igor Grinberg
@ 2013-02-22  2:19 ` Jingoo Han
  2013-02-24  8:48   ` Igor Grinberg
  2015-05-19 22:11   ` [V2] " Alexandre Belloni
  1 sibling, 2 replies; 6+ messages in thread
From: Jingoo Han @ 2013-02-22  2:19 UTC (permalink / raw)
  To: 'Andrew Morton'
  Cc: linux-kernel, 'Alessandro Zummo',
	rtc-linux, 'Igor Grinberg', 'Jingoo Han'

Using gpio_request_array()/gpio_free_array() can make the code
simpler because it can set the direction and initial value
in one shot and the for loop is unnecessary.

Also, struct v3020_gpio is removed, because the struct v3020_gpio
is replaced with struct gpio.

Signed-off-by: Jingoo Han <jg1.han@samsung.com>
---
Changes since v1:
- Replace gpio_request_one() with gpio_request_array()

 drivers/rtc/rtc-v3020.c |   37 ++++++++++++-------------------------
 1 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
index bca5d67..600798c 100644
--- a/drivers/rtc/rtc-v3020.c
+++ b/drivers/rtc/rtc-v3020.c
@@ -49,18 +49,13 @@ struct v3020_chip_ops {
 #define V3020_RD	2
 #define V3020_IO	3
 
-struct v3020_gpio {
-	const char *name;
-	unsigned int gpio;
-};
-
 struct v3020 {
 	/* MMIO access */
 	void __iomem *ioaddress;
 	int leftshift;
 
 	/* GPIO access */
-	struct v3020_gpio *gpio;
+	struct gpio *gpio;
 
 	struct v3020_chip_ops *ops;
 
@@ -107,48 +102,40 @@ static struct v3020_chip_ops v3020_mmio_ops = {
 	.write_bit	= v3020_mmio_write_bit,
 };
 
-static struct v3020_gpio v3020_gpio[] = {
-	{ "RTC CS", 0 },
-	{ "RTC WR", 0 },
-	{ "RTC RD", 0 },
-	{ "RTC IO", 0 },
+static struct gpio v3020_gpio[] = {
+	{ 0, GPIOF_OUT_INIT_HIGH, "RTC CS"},
+	{ 0, GPIOF_OUT_INIT_HIGH, "RTC WR"},
+	{ 0, GPIOF_OUT_INIT_HIGH, "RTC RD"},
+	{ 0, GPIOF_OUT_INIT_HIGH, "RTC IO"},
 };
 
 static int v3020_gpio_map(struct v3020 *chip, struct platform_device *pdev,
 			  struct v3020_platform_data *pdata)
 {
-	int i, err;
+	int err;
 
 	v3020_gpio[V3020_CS].gpio = pdata->gpio_cs;
 	v3020_gpio[V3020_WR].gpio = pdata->gpio_wr;
 	v3020_gpio[V3020_RD].gpio = pdata->gpio_rd;
 	v3020_gpio[V3020_IO].gpio = pdata->gpio_io;
 
-	for (i = 0; i < ARRAY_SIZE(v3020_gpio); i++) {
-		err = gpio_request(v3020_gpio[i].gpio, v3020_gpio[i].name);
-		if (err)
-			goto err_request;
-
-		gpio_direction_output(v3020_gpio[i].gpio, 1);
-	}
+	err = gpio_request_array(v3020_gpio, ARRAY_SIZE(v3020_gpio));
+	if (err)
+		goto err_request;
 
 	chip->gpio = v3020_gpio;
 
 	return 0;
 
 err_request:
-	while (--i >= 0)
-		gpio_free(v3020_gpio[i].gpio);
+	gpio_free_array(v3020_gpio, ARRAY_SIZE(v3020_gpio));
 
 	return err;
 }
 
 static void v3020_gpio_unmap(struct v3020 *chip)
 {
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(v3020_gpio); i++)
-		gpio_free(v3020_gpio[i].gpio);
+	gpio_free_array(v3020_gpio, ARRAY_SIZE(v3020_gpio));
 }
 
 static void v3020_gpio_write_bit(struct v3020 *chip, unsigned char bit)
-- 
1.7.2.5



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

* Re: [PATCH V2] rtc: rtc-v3020: use gpio_request_array()
  2013-02-22  2:19 ` [PATCH V2] rtc: rtc-v3020: use gpio_request_array() Jingoo Han
@ 2013-02-24  8:48   ` Igor Grinberg
  2015-05-19 22:11   ` [V2] " Alexandre Belloni
  1 sibling, 0 replies; 6+ messages in thread
From: Igor Grinberg @ 2013-02-24  8:48 UTC (permalink / raw)
  To: Jingoo Han
  Cc: 'Andrew Morton', linux-kernel, 'Alessandro Zummo',
	rtc-linux



On 02/22/13 04:19, Jingoo Han wrote:
> Using gpio_request_array()/gpio_free_array() can make the code
> simpler because it can set the direction and initial value
> in one shot and the for loop is unnecessary.
> 
> Also, struct v3020_gpio is removed, because the struct v3020_gpio
> is replaced with struct gpio.
> 
> Signed-off-by: Jingoo Han <jg1.han@samsung.com>
> ---
> Changes since v1:
> - Replace gpio_request_one() with gpio_request_array()

Thanks for addressing this!
It looks much better now, although one comment below.

> 
>  drivers/rtc/rtc-v3020.c |   37 ++++++++++++-------------------------
>  1 files changed, 12 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
> index bca5d67..600798c 100644
> --- a/drivers/rtc/rtc-v3020.c
> +++ b/drivers/rtc/rtc-v3020.c

[...]

> @@ -107,48 +102,40 @@ static struct v3020_chip_ops v3020_mmio_ops = {
>  	.write_bit	= v3020_mmio_write_bit,
>  };
>  
> -static struct v3020_gpio v3020_gpio[] = {
> -	{ "RTC CS", 0 },
> -	{ "RTC WR", 0 },
> -	{ "RTC RD", 0 },
> -	{ "RTC IO", 0 },
> +static struct gpio v3020_gpio[] = {
> +	{ 0, GPIOF_OUT_INIT_HIGH, "RTC CS"},
> +	{ 0, GPIOF_OUT_INIT_HIGH, "RTC WR"},
> +	{ 0, GPIOF_OUT_INIT_HIGH, "RTC RD"},
> +	{ 0, GPIOF_OUT_INIT_HIGH, "RTC IO"},
>  };
>  
>  static int v3020_gpio_map(struct v3020 *chip, struct platform_device *pdev,
>  			  struct v3020_platform_data *pdata)
>  {
> -	int i, err;
> +	int err;
>  
>  	v3020_gpio[V3020_CS].gpio = pdata->gpio_cs;
>  	v3020_gpio[V3020_WR].gpio = pdata->gpio_wr;
>  	v3020_gpio[V3020_RD].gpio = pdata->gpio_rd;
>  	v3020_gpio[V3020_IO].gpio = pdata->gpio_io;
>  
> -	for (i = 0; i < ARRAY_SIZE(v3020_gpio); i++) {
> -		err = gpio_request(v3020_gpio[i].gpio, v3020_gpio[i].name);
> -		if (err)
> -			goto err_request;
> -
> -		gpio_direction_output(v3020_gpio[i].gpio, 1);
> -	}
> +	err = gpio_request_array(v3020_gpio, ARRAY_SIZE(v3020_gpio));
> +	if (err)
> +		goto err_request;
>  
>  	chip->gpio = v3020_gpio;
>  
>  	return 0;
>  
>  err_request:
> -	while (--i >= 0)
> -		gpio_free(v3020_gpio[i].gpio);
> +	gpio_free_array(v3020_gpio, ARRAY_SIZE(v3020_gpio));

Once you use the gpio_request_array(), you don't need to care
about the error.
If gpio_request_array() fails, it does the roll back for you.
So, you just need to return err and remove the whole err_request label.

>  
>  	return err;
>  }
>  
>  static void v3020_gpio_unmap(struct v3020 *chip)
>  {
> -	int i;
> -
> -	for (i = 0; i < ARRAY_SIZE(v3020_gpio); i++)
> -		gpio_free(v3020_gpio[i].gpio);
> +	gpio_free_array(v3020_gpio, ARRAY_SIZE(v3020_gpio));
>  }
>  
>  static void v3020_gpio_write_bit(struct v3020 *chip, unsigned char bit)
> 

-- 
Regards,
Igor.

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

* Re: [V2] rtc: rtc-v3020: use gpio_request_array()
  2013-02-22  2:19 ` [PATCH V2] rtc: rtc-v3020: use gpio_request_array() Jingoo Han
  2013-02-24  8:48   ` Igor Grinberg
@ 2015-05-19 22:11   ` Alexandre Belloni
  1 sibling, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2015-05-19 22:11 UTC (permalink / raw)
  To: Jingoo Han
  Cc: linux-kernel, 'Alessandro Zummo',
	rtc-linux, 'Igor Grinberg'

On 22/02/2013 at 11:19:15 +0900, Jingoo Han wrote :
> Using gpio_request_array()/gpio_free_array() can make the code
> simpler because it can set the direction and initial value
> in one shot and the for loop is unnecessary.
> 
> Also, struct v3020_gpio is removed, because the struct v3020_gpio
> is replaced with struct gpio.
> 
> Signed-off-by: Jingoo Han <jg1.han@samsung.com>
> ---
> Changes since v1:
> - Replace gpio_request_one() with gpio_request_array()
> 
>  drivers/rtc/rtc-v3020.c |   37 ++++++++++++-------------------------
>  1 files changed, 12 insertions(+), 25 deletions(-)
> 
Applied with the change suggested by Igor, thanks.

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

end of thread, other threads:[~2015-05-19 22:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-21  8:31 [PATCH] rtc: rtc-v3020: use gpio_request_one() Jingoo Han
2013-02-21  8:48 ` Igor Grinberg
2013-02-22  2:13   ` Jingoo Han
2013-02-22  2:19 ` [PATCH V2] rtc: rtc-v3020: use gpio_request_array() Jingoo Han
2013-02-24  8:48   ` Igor Grinberg
2015-05-19 22:11   ` [V2] " Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).