linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/7] misc: ixp4-beeper: use gpiolib strictly
@ 2013-09-10 12:30 Linus Walleij
  2013-09-10 21:47 ` Arnd Bergmann
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Linus Walleij @ 2013-09-10 12:30 UTC (permalink / raw)
  To: linux-gpio, Imre Kaloz, Krzysztof Halasa
  Cc: Alexandre Courbot, linux-arm-kernel, Linus Walleij, Arnd Bergmann,
	Greg Kroah-Hartman

Request and free the GPIO line used for the beeper properly.
Then use the gpiolib API to flip the output of the GPIO pin
instead of relying on hacks to poke the register bits.

Cc: Imre Kaloz <kaloz@openwrt.org>
Cc: Krzysztof Halasa <khc@pm.waw.pl>
Cc: Alexandre Courbot <acourbot@nvidia.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
Arnd/Greg: seeking your ACK to take this through the GPIO tree
as part of the attempt at cleaning out custom GPIO implementations.
---
 drivers/input/misc/ixp4xx-beeper.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/input/misc/ixp4xx-beeper.c b/drivers/input/misc/ixp4xx-beeper.c
index f14afd0..fb3bec5 100644
--- a/drivers/input/misc/ixp4xx-beeper.c
+++ b/drivers/input/misc/ixp4xx-beeper.c
@@ -76,11 +76,13 @@ static int ixp4xx_spkr_event(struct input_dev *dev, unsigned int type, unsigned
 
 static irqreturn_t ixp4xx_spkr_interrupt(int irq, void *dev_id)
 {
+	unsigned int pin = (unsigned int) dev_id;
+
 	/* clear interrupt */
 	*IXP4XX_OSST = IXP4XX_OSST_TIMER_2_PEND;
 
 	/* flip the beeper output */
-	*IXP4XX_GPIO_GPOUTR ^= (1 << (unsigned int) dev_id);
+	gpio_set_value(pin, ~gpio_get_value(pin));
 
 	return IRQ_HANDLED;
 }
@@ -108,11 +110,15 @@ static int ixp4xx_spkr_probe(struct platform_device *dev)
 	input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
 	input_dev->event = ixp4xx_spkr_event;
 
+	err = gpio_request(dev->id, "ixp4-beeper");
+	if (err)
+		goto err_free_device;
+
 	err = request_irq(IRQ_IXP4XX_TIMER2, &ixp4xx_spkr_interrupt,
 			  IRQF_NO_SUSPEND, "ixp4xx-beeper",
 			  (void *) dev->id);
 	if (err)
-		goto err_free_device;
+		goto err_free_gpio;
 
 	err = input_register_device(input_dev);
 	if (err)
@@ -124,6 +130,8 @@ static int ixp4xx_spkr_probe(struct platform_device *dev)
 
  err_free_irq:
 	free_irq(IRQ_IXP4XX_TIMER2, (void *)dev->id);
+ err_free_gpio:
+	gpio_free(dev->id);
  err_free_device:
 	input_free_device(input_dev);
 
@@ -142,6 +150,7 @@ static int ixp4xx_spkr_remove(struct platform_device *dev)
 	ixp4xx_spkr_control(pin, 0);
 
 	free_irq(IRQ_IXP4XX_TIMER2, (void *)dev->id);
+	gpio_free(dev->id);
 
 	return 0;
 }
-- 
1.8.3.1


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

* Re: [PATCH 3/7] misc: ixp4-beeper: use gpiolib strictly
  2013-09-10 12:30 [PATCH 3/7] misc: ixp4-beeper: use gpiolib strictly Linus Walleij
@ 2013-09-10 21:47 ` Arnd Bergmann
  2013-09-11  1:58 ` Alex Courbot
  2013-09-26 15:51 ` Greg Kroah-Hartman
  2 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2013-09-10 21:47 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-gpio, Imre Kaloz, Krzysztof Halasa, Alexandre Courbot,
	linux-arm-kernel, Greg Kroah-Hartman

On Tuesday 10 September 2013, Linus Walleij wrote:
> Request and free the GPIO line used for the beeper properly.
> Then use the gpiolib API to flip the output of the GPIO pin
> instead of relying on hacks to poke the register bits.
> 
> Cc: Imre Kaloz <kaloz@openwrt.org>
> Cc: Krzysztof Halasa <khc@pm.waw.pl>
> Cc: Alexandre Courbot <acourbot@nvidia.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> Arnd/Greg: seeking your ACK to take this through the GPIO tree
> as part of the attempt at cleaning out custom GPIO implementations.


Acked-by: Arnd Bergmann <arnd@arndb.de>

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

* Re: [PATCH 3/7] misc: ixp4-beeper: use gpiolib strictly
  2013-09-10 12:30 [PATCH 3/7] misc: ixp4-beeper: use gpiolib strictly Linus Walleij
  2013-09-10 21:47 ` Arnd Bergmann
@ 2013-09-11  1:58 ` Alex Courbot
  2013-09-13  8:35   ` Linus Walleij
  2013-09-26 15:51 ` Greg Kroah-Hartman
  2 siblings, 1 reply; 5+ messages in thread
From: Alex Courbot @ 2013-09-11  1:58 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-gpio@vger.kernel.org, Imre Kaloz, Krzysztof Halasa,
	linux-arm-kernel@lists.infradead.org, Arnd Bergmann,
	Greg Kroah-Hartman

On 09/10/2013 09:30 PM, Linus Walleij wrote:
> Request and free the GPIO line used for the beeper properly.
> Then use the gpiolib API to flip the output of the GPIO pin
> instead of relying on hacks to poke the register bits.
>
> Cc: Imre Kaloz <kaloz@openwrt.org>
> Cc: Krzysztof Halasa <khc@pm.waw.pl>
> Cc: Alexandre Courbot <acourbot@nvidia.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> Arnd/Greg: seeking your ACK to take this through the GPIO tree
> as part of the attempt at cleaning out custom GPIO implementations.
> ---
>   drivers/input/misc/ixp4xx-beeper.c | 13 +++++++++++--
>   1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/misc/ixp4xx-beeper.c b/drivers/input/misc/ixp4xx-beeper.c
> index f14afd0..fb3bec5 100644
> --- a/drivers/input/misc/ixp4xx-beeper.c
> +++ b/drivers/input/misc/ixp4xx-beeper.c
> @@ -76,11 +76,13 @@ static int ixp4xx_spkr_event(struct input_dev *dev, unsigned int type, unsigned
>
>   static irqreturn_t ixp4xx_spkr_interrupt(int irq, void *dev_id)
>   {
> +	unsigned int pin = (unsigned int) dev_id;
> +
>   	/* clear interrupt */
>   	*IXP4XX_OSST = IXP4XX_OSST_TIMER_2_PEND;
>
>   	/* flip the beeper output */
> -	*IXP4XX_GPIO_GPOUTR ^= (1 << (unsigned int) dev_id);
> +	gpio_set_value(pin, ~gpio_get_value(pin));

Don't you want

	gpio_set_value(pin, !gpio_get_value(pin));

instead? From the deleted line I suppose you guess to invert the GPIO 
value, but using ~ will invert all the bits of the integer returned by 
gpio_get_value(), meaning that if it returns 1 you will end up calling 
gpio_set_value(-2). In practice your gpio is very unlikely to ever be 
set to 0.

>
>   	return IRQ_HANDLED;
>   }
> @@ -108,11 +110,15 @@ static int ixp4xx_spkr_probe(struct platform_device *dev)
>   	input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
>   	input_dev->event = ixp4xx_spkr_event;
>
> +	err = gpio_request(dev->id, "ixp4-beeper");
> +	if (err)
> +		goto err_free_device;
> +
>   	err = request_irq(IRQ_IXP4XX_TIMER2, &ixp4xx_spkr_interrupt,
>   			  IRQF_NO_SUSPEND, "ixp4xx-beeper",
>   			  (void *) dev->id);
>   	if (err)
> -		goto err_free_device;
> +		goto err_free_gpio;
>
>   	err = input_register_device(input_dev);
>   	if (err)
> @@ -124,6 +130,8 @@ static int ixp4xx_spkr_probe(struct platform_device *dev)
>
>    err_free_irq:
>   	free_irq(IRQ_IXP4XX_TIMER2, (void *)dev->id);
> + err_free_gpio:
> +	gpio_free(dev->id);
>    err_free_device:
>   	input_free_device(input_dev);
>
> @@ -142,6 +150,7 @@ static int ixp4xx_spkr_remove(struct platform_device *dev)
>   	ixp4xx_spkr_control(pin, 0);
>
>   	free_irq(IRQ_IXP4XX_TIMER2, (void *)dev->id);
> +	gpio_free(dev->id);

Just wondering, is there a reason for not using the devm_gpio functions 
here?

>
>   	return 0;
>   }
>


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

* Re: [PATCH 3/7] misc: ixp4-beeper: use gpiolib strictly
  2013-09-11  1:58 ` Alex Courbot
@ 2013-09-13  8:35   ` Linus Walleij
  0 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2013-09-13  8:35 UTC (permalink / raw)
  To: Alex Courbot
  Cc: linux-gpio@vger.kernel.org, Imre Kaloz, Krzysztof Halasa,
	linux-arm-kernel@lists.infradead.org, Arnd Bergmann,
	Greg Kroah-Hartman

On Wed, Sep 11, 2013 at 3:58 AM, Alex Courbot <acourbot@nvidia.com> wrote:
> On 09/10/2013 09:30 PM, Linus Walleij wrote:
>>         /* flip the beeper output */
>> -       *IXP4XX_GPIO_GPOUTR ^= (1 << (unsigned int) dev_id);
>> +       gpio_set_value(pin, ~gpio_get_value(pin));
>
>
> Don't you want
>
>         gpio_set_value(pin, !gpio_get_value(pin));
>
> instead? From the deleted line I suppose you guess to invert the GPIO value,
> but using ~ will invert all the bits of the integer returned by
> gpio_get_value(), meaning that if it returns 1 you will end up calling
> gpio_set_value(-2). In practice your gpio is very unlikely to ever be set to
> 0.

You're right, fixed this.

>>         free_irq(IRQ_IXP4XX_TIMER2, (void *)dev->id);
>> +       gpio_free(dev->id);
>
>
> Just wondering, is there a reason for not using the devm_gpio functions
> here?

I didn't want to change the style of the whole driver, but I can make
a separate patch switching the whole driver to use managed
resources at some later point.

Yours,
Linus Walleij

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

* Re: [PATCH 3/7] misc: ixp4-beeper: use gpiolib strictly
  2013-09-10 12:30 [PATCH 3/7] misc: ixp4-beeper: use gpiolib strictly Linus Walleij
  2013-09-10 21:47 ` Arnd Bergmann
  2013-09-11  1:58 ` Alex Courbot
@ 2013-09-26 15:51 ` Greg Kroah-Hartman
  2 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2013-09-26 15:51 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-gpio, Imre Kaloz, Krzysztof Halasa, Alexandre Courbot,
	linux-arm-kernel, Arnd Bergmann

On Tue, Sep 10, 2013 at 02:30:26PM +0200, Linus Walleij wrote:
> Request and free the GPIO line used for the beeper properly.
> Then use the gpiolib API to flip the output of the GPIO pin
> instead of relying on hacks to poke the register bits.
> 
> Cc: Imre Kaloz <kaloz@openwrt.org>
> Cc: Krzysztof Halasa <khc@pm.waw.pl>
> Cc: Alexandre Courbot <acourbot@nvidia.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> Arnd/Greg: seeking your ACK to take this through the GPIO tree
> as part of the attempt at cleaning out custom GPIO implementations.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

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

end of thread, other threads:[~2013-09-26 15:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-10 12:30 [PATCH 3/7] misc: ixp4-beeper: use gpiolib strictly Linus Walleij
2013-09-10 21:47 ` Arnd Bergmann
2013-09-11  1:58 ` Alex Courbot
2013-09-13  8:35   ` Linus Walleij
2013-09-26 15:51 ` Greg Kroah-Hartman

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