mirror of
https://github.com/FEX-Emu/linux.git
synced 2025-02-21 21:02:24 +00:00
Input: gpio-keys - request and configure GPIOs
Currently, gpio_keys.c assumes the GPIOs to be already properly configured; this patch changes gpio-keys to perform explicit calls to gpio_request() and gpio_configure_input(). This matches the behaviour of leds-gpio. Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
This commit is contained in:
parent
8bf4215e8a
commit
6a2e391190
@ -75,16 +75,32 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
for (i = 0; i < pdata->nbuttons; i++) {
|
for (i = 0; i < pdata->nbuttons; i++) {
|
||||||
struct gpio_keys_button *button = &pdata->buttons[i];
|
struct gpio_keys_button *button = &pdata->buttons[i];
|
||||||
int irq = gpio_to_irq(button->gpio);
|
int irq;
|
||||||
unsigned int type = button->type ?: EV_KEY;
|
unsigned int type = button->type ?: EV_KEY;
|
||||||
|
|
||||||
|
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);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = gpio_direction_input(button->gpio);
|
||||||
|
if (error < 0) {
|
||||||
|
pr_err("gpio-keys: failed to configure input"
|
||||||
|
" direction for GPIO %d, error %d\n",
|
||||||
|
button->gpio, error);
|
||||||
|
gpio_free(button->gpio);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
irq = gpio_to_irq(button->gpio);
|
||||||
if (irq < 0) {
|
if (irq < 0) {
|
||||||
error = irq;
|
error = irq;
|
||||||
printk(KERN_ERR
|
pr_err("gpio-keys: Unable to get irq number"
|
||||||
"gpio-keys: "
|
" for GPIO %d, error %d\n",
|
||||||
"Unable to get irq number for GPIO %d,"
|
|
||||||
"error %d\n",
|
|
||||||
button->gpio, error);
|
button->gpio, error);
|
||||||
|
gpio_free(button->gpio);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,9 +110,9 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
|
|||||||
button->desc ? button->desc : "gpio_keys",
|
button->desc ? button->desc : "gpio_keys",
|
||||||
pdev);
|
pdev);
|
||||||
if (error) {
|
if (error) {
|
||||||
printk(KERN_ERR
|
pr_err("gpio-keys: Unable to claim irq %d; error %d\n",
|
||||||
"gpio-keys: Unable to claim irq %d; error %d\n",
|
|
||||||
irq, error);
|
irq, error);
|
||||||
|
gpio_free(button->gpio);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,8 +124,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
error = input_register_device(input);
|
error = input_register_device(input);
|
||||||
if (error) {
|
if (error) {
|
||||||
printk(KERN_ERR
|
pr_err("gpio-keys: Unable to register input device, "
|
||||||
"gpio-keys: Unable to register input device, "
|
|
||||||
"error: %d\n", error);
|
"error: %d\n", error);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@ -119,8 +134,10 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
while (--i >= 0)
|
while (--i >= 0) {
|
||||||
free_irq(gpio_to_irq(pdata->buttons[i].gpio), pdev);
|
free_irq(gpio_to_irq(pdata->buttons[i].gpio), pdev);
|
||||||
|
gpio_free(pdata->buttons[i].gpio);
|
||||||
|
}
|
||||||
|
|
||||||
platform_set_drvdata(pdev, NULL);
|
platform_set_drvdata(pdev, NULL);
|
||||||
input_free_device(input);
|
input_free_device(input);
|
||||||
@ -139,6 +156,7 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
|
|||||||
for (i = 0; i < pdata->nbuttons; i++) {
|
for (i = 0; i < pdata->nbuttons; i++) {
|
||||||
int irq = gpio_to_irq(pdata->buttons[i].gpio);
|
int irq = gpio_to_irq(pdata->buttons[i].gpio);
|
||||||
free_irq(irq, pdev);
|
free_irq(irq, pdev);
|
||||||
|
gpio_free(pdata->buttons[i].gpio);
|
||||||
}
|
}
|
||||||
|
|
||||||
input_unregister_device(input);
|
input_unregister_device(input);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user