Input: gpio_keys - allow separating gpio and irq in device tree

This change allows specify interrupt for buttons separately form gpio,
potentially allowing to form several "clusters" of buttons on
different interrupts.

Button defined without both gpio and irq in device tree is a hared error
instead of a warning now.

Tested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This commit is contained in:
Dmitry Torokhov 2014-11-14 15:57:09 -08:00
parent 1d6a01365f
commit 97d86e07b7
2 changed files with 33 additions and 26 deletions

View file

@ -10,12 +10,13 @@ Optional properties:
Each button (key) is represented as a sub-node of "gpio-keys": Each button (key) is represented as a sub-node of "gpio-keys":
Subnode properties: Subnode properties:
- gpios: OF device-tree gpio specification.
- interrupts: the interrupt line for that input.
- label: Descriptive name of the key. - label: Descriptive name of the key.
- linux,code: Keycode to emit. - linux,code: Keycode to emit.
Required mutual exclusive subnode-properties: Note that either "interrupts" or "gpios" properties can be omitted, but not
- gpios: OF device-tree gpio specification. both at the same time. Specifying both properties is allowed.
- interrupts: the interrupt line for that input
Optional subnode-properties: Optional subnode-properties:
- linux,input-type: Specify event type this button/key generates. - linux,input-type: Specify event type this button/key generates.
@ -23,6 +24,9 @@ Optional subnode-properties:
- debounce-interval: Debouncing interval time in milliseconds. - debounce-interval: Debouncing interval time in milliseconds.
If not specified defaults to 5. If not specified defaults to 5.
- gpio-key,wakeup: Boolean, button can wake-up the system. - gpio-key,wakeup: Boolean, button can wake-up the system.
- linux,can-disable: Boolean, indicates that button is connected
to dedicated (not shared) interrupt which can be disabled to
suppress events from the button.
Example nodes: Example nodes:

View file

@ -470,6 +470,9 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
button->debounce_interval; button->debounce_interval;
} }
if (button->irq) {
bdata->irq = button->irq;
} else {
irq = gpio_to_irq(button->gpio); irq = gpio_to_irq(button->gpio);
if (irq < 0) { if (irq < 0) {
error = irq; error = irq;
@ -479,6 +482,7 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
return error; return error;
} }
bdata->irq = irq; bdata->irq = irq;
}
INIT_WORK(&bdata->work, gpio_keys_gpio_work_func); INIT_WORK(&bdata->work, gpio_keys_gpio_work_func);
setup_timer(&bdata->timer, setup_timer(&bdata->timer,
@ -618,33 +622,30 @@ gpio_keys_get_devtree_pdata(struct device *dev)
i = 0; i = 0;
for_each_child_of_node(node, pp) { for_each_child_of_node(node, pp) {
int gpio = -1;
enum of_gpio_flags flags; enum of_gpio_flags flags;
button = &pdata->buttons[i++]; button = &pdata->buttons[i++];
if (!of_find_property(pp, "gpios", NULL)) { button->gpio = of_get_gpio_flags(pp, 0, &flags);
button->irq = irq_of_parse_and_map(pp, 0); if (button->gpio < 0) {
if (button->irq == 0) { error = button->gpio;
i--; if (error != -ENOENT) {
pdata->nbuttons--;
dev_warn(dev, "Found button without gpios or irqs\n");
continue;
}
} else {
gpio = of_get_gpio_flags(pp, 0, &flags);
if (gpio < 0) {
error = gpio;
if (error != -EPROBE_DEFER) if (error != -EPROBE_DEFER)
dev_err(dev, dev_err(dev,
"Failed to get gpio flags, error: %d\n", "Failed to get gpio flags, error: %d\n",
error); error);
return ERR_PTR(error); return ERR_PTR(error);
} }
} else {
button->active_low = flags & OF_GPIO_ACTIVE_LOW;
} }
button->gpio = gpio; button->irq = irq_of_parse_and_map(pp, 0);
button->active_low = flags & OF_GPIO_ACTIVE_LOW;
if (!gpio_is_valid(button->gpio) && !button->irq) {
dev_err(dev, "Found button without gpios or irqs\n");
return ERR_PTR(-EINVAL);
}
if (of_property_read_u32(pp, "linux,code", &button->code)) { if (of_property_read_u32(pp, "linux,code", &button->code)) {
dev_err(dev, "Button without keycode: 0x%x\n", dev_err(dev, "Button without keycode: 0x%x\n",
@ -659,6 +660,8 @@ gpio_keys_get_devtree_pdata(struct device *dev)
button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL); button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL);
button->can_disable = !!of_get_property(pp, "linux,can-disable", NULL);
if (of_property_read_u32(pp, "debounce-interval", if (of_property_read_u32(pp, "debounce-interval",
&button->debounce_interval)) &button->debounce_interval))
button->debounce_interval = 5; button->debounce_interval = 5;