misc: ixp4-beeper: use gpiolib strictly
Subsystems (2)
PATCH 3/7 misc: ixp4-beeper: use gpiolib strictly
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.
---
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(-)
drivers/input/misc/ixp4xx-beeper.c +11 -2
@@ -76,11 +76,13 @@ static int ixp4xx_spkr_event(struct input_dev *dev, unsigned int type, unsignedstatic 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 ; }
Signature · 1 line
1.8.3.1
PATCH 3/7 misc: ixp4-beeper: use gpiolib strictly
Quoted 10 lines · Linus Walleij
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 <[email protected]>Cc Krzysztof Halasa <[email protected]>Cc Alexandre Courbot <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Linus Walleij <[email protected]>
Quoted 3 lines
---
Arnd/Greg: seeking your ACK to take this through the GPIO tree as part of the attempt at cleaning out custom GPIO implementations.
PATCH 3/7 misc: ixp4-beeper: use gpiolib strictly
In reply to Linus WalleijQuoted 23 lines · Linus Walleij
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 <[email protected]>Cc Krzysztof Halasa <[email protected]>Cc Alexandre Courbot <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Linus Walleij <[email protected]>---
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(-)drivers/input/misc/ixp4xx-beeper.c +0
-0@@ -76,11 +76,13 @@ static int ixp4xx_spkr_event(struct input_dev *dev, unsigned int type, unsigned
drivers/input/misc/ixp4xx-beeper.c static int ixp4xx_spkr_event(struct input_dev *dev, unsigned int type, unsigned · line 85
Quoted 10 lines
drivers/input/misc/ixp4xx-beeper.c +3
-1static 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.
Quoted 30 lines
drivers/input/misc/ixp4xx-beeper.c +7
-1return 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);
drivers/input/misc/ixp4xx-beeper.c static int ixp4xx_spkr_remove(struct platform_device *dev) · line 153
Quoted 4 lines
drivers/input/misc/ixp4xx-beeper.c +1
-0@@ -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?
Quoted 4 lines
drivers/input/misc/ixp4xx-beeper.c +0
-0return 0 ; }
PATCH 3/7 misc: ixp4-beeper: use gpiolib strictly
Quoted 8 lines · Alex Courbot
drivers/input/misc/ixp4xx-beeper.c static int ixp4xx_spkr_event(struct input_dev *dev, unsigned int type, unsigned · line 85
Quoted 3 lines · Linus Walleij
/* flip the beeper output */drivers/input/misc/ixp4xx-beeper.c +1
-1- *IXP4XX_GPIO_GPOUTR ^= (1 << (unsigned int ) dev_id); +gpio_set_value (pin, ~gpio_get_value (pin));Don't you want
Quoted 7 lines
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 callinggpio_set_value(-2). In practice your gpio is very unlikely to ever be set to 0.
You're right, fixed this.
Quoted 6 lines
Quoted 2 lines
free_irq(IRQ_IXP4XX_TIMER2, (void *)dev->id);+
gpio_free(dev->id);Just wondering, is there a reason for not using the
devm_gpiofunctions 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
PATCH 3/7 misc: ixp4-beeper: use gpiolib strictly
In reply to Linus WalleijQuoted 10 lines · Linus Walleij
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 <[email protected]>Cc Krzysztof Halasa <[email protected]>Cc Alexandre Courbot <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Linus Walleij <[email protected]>
Quoted 3 lines
---
Arnd/Greg: seeking your ACK to take this through the GPIO tree as part of the attempt at cleaning out custom GPIO implementations.