gpio_keys driver updates
Subsystems (2)
cover gpio_keys driver updates
Some updates for the gpio_keys drivers.
PATCH 1/3 gpio_keys: use dev_ macros to report information
The gpio_keys driver is binding to a platform device but using pr_err() to report errors. Change to using dev_err() so that all messages are prefixed by the device name.
--- drivers/input/keyboard/gpio_keys.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/input/keyboard/gpio_keys.c +9 -7
@@ -78,6 +78,7 @@ static int __devinit gpio_keys_probe(str {struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;struct gpio_keys_drvdata *ddata; +struct device *dev = &pdev->dev;struct input_dev *input;int i, error;int wakeup =0 ;
@@ -87,6 +88,7 @@ static int __devinit gpio_keys_probe(str GFP_KERNEL); input =input_allocate_device ();if (!ddata || !input) { +dev_err (dev,"failed to allocate state\n" ); error = -ENOMEM ; goto fail1; }
@@ -122,14 +124,14 @@ static int __devinit gpio_keys_probe(str error =gpio_request (button->gpio, button->desc ?:"gpio_keys" );if (error <0 ) { -pr_err ("gpio-keys: failed to request GPIO %d," -" error %d\n" , button->gpio, error); +dev_err (dev,"failed to request GPIO %d, error %d\n" , + button->gpio, error); goto fail2; } error =gpio_direction_input (button->gpio);if (error <0 ) { -pr_err ("gpio-keys: failed to configure input" +dev_err (dev,"failed to configure" " direction for GPIO %d, error %d\n" , button->gpio, error);gpio_free (button->gpio);
@@ -139,8 +141,8 @@ static int __devinit gpio_keys_probe(str irq =gpio_to_irq (button->gpio);if (irq <0 ) { error = irq; -pr_err ("gpio-keys: Unable to get irq number" -" for GPIO %d, error %d\n" , +dev_err (dev,"Unable to get irq number " +"for GPIO %d, error %d\n" , button->gpio, error);gpio_free (button->gpio); goto fail2;
@@ -152,7 +154,7 @@ static int __devinit gpio_keys_probe(str button->desc ? button->desc :"gpio_keys" , bdata);if (error) { -pr_err ("gpio-keys: Unable to claim irq %d; error %d\n" , +dev_err (dev,"Unable to claim irq %d; error %d\n" , irq, error);gpio_free (button->gpio); goto fail2;
@@ -166,7 +168,7 @@ static int __devinit gpio_keys_probe(str error =input_register_device (input);if (error) { -pr_err ("gpio-keys: Unable to register input device, " +dev_err (dev,"Unable to register input device, " "error: %d\n" , error); goto fail2; }
PATCH 2/3 gpio_keys: use <linux/gpio.h> instead of <asm/gpio.h>
In reply to Ben DooksThe gpio keys driver should be using <linux/gpio.h> instead of <asm/gpio.h>
--- drivers/input/keyboard/gpio_keys.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/input/keyboard/gpio_keys.c +1 -2
@@ -23,8 +23,7 @@#include <linux/input.h> #include <linux/gpio_keys.h> #include <linux/workqueue.h> - -#include <asm/gpio.h> +#include <linux/gpio.h> struct gpio_button_data {struct gpio_keys_button *button;
PATCH 3/3 gpio_keys: seperate individual button setup to make code neater
In reply to Ben DooksMove the code that deals with setting up each individual button out into a new function to reduce the indentation and allow us to common up some of the error recovery code.
--- drivers/input/keyboard/gpio_keys.c | 93 +++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 40 deletions(-)
drivers/input/keyboard/gpio_keys.c +53 -40
@@ -73,6 +73,57 @@ static irqreturn_t gpio_keys_isr(int irqreturn IRQ_HANDLED ; } +static int __devinit gpio_keys_setup_key (struct device *dev, +struct gpio_button_data *bdata, +struct gpio_keys_button *button) +{ +char *desc = button->desc ? button->desc :"gpio_keys" ; +int irq, error; + +setup_timer (&bdata->timer, gpio_keys_timer, (unsigned long )bdata); +INIT_WORK (&bdata->work, gpio_keys_report_event); + + error =gpio_request (button->gpio, desc); +if (error <0 ) { +dev_err (dev,"failed to request GPIO %d, error %d\n" , + button->gpio, error); + goto fail2; + } + + error =gpio_direction_input (button->gpio); +if (error <0 ) { +dev_err (dev,"failed to configure" +" direction for GPIO %d, error %d\n" , + button->gpio, error); + goto fail3; + } + + irq =gpio_to_irq (button->gpio); +if (irq <0 ) { + error = irq; +dev_err (dev,"Unable to get irq number for GPIO %d, error %d\n" , + button->gpio, error); + goto fail3; + } + + error =request_irq (irq, gpio_keys_isr, +IRQF_SHARED | +IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING , + desc, bdata); +if (error) { +dev_err (dev,"Unable to claim irq %d; error %d\n" , + irq, error); + goto fail3; + } + +return 0 ; + +fail3: +gpio_free (button->gpio); +fail2: +return error; +} +static int __devinit gpio_keys_probe (struct platform_device *pdev) {struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
@@ -112,52 +163,14 @@ static int __devinit gpio_keys_probe(strfor (i =0 ; i < pdata->nbuttons; i++) {struct gpio_keys_button *button = &pdata->buttons[i];struct gpio_button_data *bdata = &ddata->data[i]; -int irq;unsigned int type = button->type ?:EV_KEY ; bdata->input = input; bdata->button = button; -setup_timer (&bdata->timer, - gpio_keys_timer, (unsigned long )bdata); -INIT_WORK (&bdata->work, gpio_keys_report_event); - - error =gpio_request (button->gpio, button->desc ?:"gpio_keys" ); -if (error <0 ) { -dev_err (dev,"failed to request GPIO %d, error %d\n" , - button->gpio, error); - goto fail2; - } - - error =gpio_direction_input (button->gpio); -if (error <0 ) { -dev_err (dev,"failed to configure" -" direction for GPIO %d, error %d\n" , - button->gpio, error); -gpio_free (button->gpio); - goto fail2; - } - irq =gpio_to_irq (button->gpio); -if (irq <0 ) { - error = irq; -dev_err (dev,"Unable to get irq number " -"for GPIO %d, error %d\n" , - button->gpio, error); -gpio_free (button->gpio); + error =gpio_keys_setup_key (dev, bdata, button); +if (error) goto fail2; - } - - error =request_irq (irq, gpio_keys_isr, -IRQF_SHARED | -IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING , - button->desc ? button->desc :"gpio_keys" , - bdata); -if (error) { -dev_err (dev,"Unable to claim irq %d; error %d\n" , - irq, error); -gpio_free (button->gpio); - goto fail2; - }if (button->wakeup) wakeup =1 ;
Quoted 1 line · Ben Dooks
Some updates for the
gpio_keysdrivers.
Applied all three to 'next', thank you Ben.
Signature · 1 line
Dmitry