// SPDX-License-Identifier: GPL-2.0-only /* * Driver for buttons on GPIO lines not capable of generating interrupts * * Copyright (C) 2007-2010 Gabor Juhos <juhosg@openwrt.org> * Copyright (C) 2010 Nuno Goncalves <nunojpg@gmail.com> * * This file was based on: /drivers/input/misc/cobalt_btns.c * Copyright (C) 2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> * * also was based on: /drivers/input/keyboard/gpio_keys.c * Copyright 2005 Phil Blundell
*/
if (fwnode_property_read_u32(child, "debounce-interval",
&button->debounce_interval))
button->debounce_interval = 5;
button++;
}
return pdata;
}
staticvoid gpio_keys_polled_set_abs_params(struct input_dev *input, conststruct gpio_keys_platform_data *pdata, unsignedint code)
{ int i, min = 0, max = 0;
for (i = 0; i < pdata->nbuttons; i++) { conststruct gpio_keys_button *button = &pdata->buttons[i];
if (button->type != EV_ABS || button->code != code) continue;
if (button->value < min)
min = button->value; if (button->value > max)
max = button->value;
}
__set_bit(EV_KEY, input->evbit); if (pdata->rep)
__set_bit(EV_REP, input->evbit);
for (i = 0; i < pdata->nbuttons; i++) { conststruct gpio_keys_button *button = &pdata->buttons[i]; struct gpio_keys_button_data *bdata = &bdev->data[i]; unsignedint type = button->type ?: EV_KEY;
if (button->wakeup) {
dev_err(dev, DRV_NAME " does not support wakeup\n");
fwnode_handle_put(child); return -EINVAL;
}
if (!dev_get_platdata(dev)) { /* No legacy static platform data */
child = device_get_next_child_node(dev, child); if (!child) {
dev_err(dev, "missing child device node\n"); return -EINVAL;
}
bdata->gpiod = devm_fwnode_gpiod_get(dev, child,
NULL, GPIOD_IN,
button->desc); if (IS_ERR(bdata->gpiod)) {
fwnode_handle_put(child); return dev_err_probe(dev, PTR_ERR(bdata->gpiod), "failed to get gpio\n");
}
} elseif (gpio_is_valid(button->gpio)) { /* * Legacy GPIO number so request the GPIO here and * convert it to descriptor.
*/
error = devm_gpio_request_one(dev, button->gpio, GPIOF_IN,
button->desc ? : DRV_NAME); if (error) return dev_err_probe(dev, error, "unable to claim gpio %u\n",
button->gpio);
bdata->gpiod = gpio_to_desc(button->gpio); if (!bdata->gpiod) {
dev_err(dev, "unable to convert gpio %u to descriptor\n",
button->gpio); return -EINVAL;
}
if (button->active_low ^ gpiod_is_active_low(bdata->gpiod))
gpiod_toggle_active_low(bdata->gpiod);
}
error = input_register_device(input); if (error) {
dev_err(dev, "unable to register polled device, err=%d\n",
error); return error;
}
/* report initial state of the buttons */ for (i = 0; i < pdata->nbuttons; i++)
gpio_keys_polled_check_state(input, &pdata->buttons[i],
&bdev->data[i]);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.