input: gpio-keys: Add devicetree probe support
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
2c194e5822
commit
7a037a952d
|
@ -11,6 +11,8 @@
|
||||||
#include <gpio_keys.h>
|
#include <gpio_keys.h>
|
||||||
#include <poller.h>
|
#include <poller.h>
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
|
#include <of_gpio.h>
|
||||||
|
#include <input/keyboard.h>
|
||||||
|
|
||||||
struct gpio_key {
|
struct gpio_key {
|
||||||
int code;
|
int code;
|
||||||
|
@ -31,6 +33,8 @@ struct gpio_keys {
|
||||||
struct kfifo *recv_fifo;
|
struct kfifo *recv_fifo;
|
||||||
struct poller_struct poller;
|
struct poller_struct poller;
|
||||||
struct console_device cdev;
|
struct console_device cdev;
|
||||||
|
|
||||||
|
int use_keycodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline struct gpio_keys *
|
static inline struct gpio_keys *
|
||||||
|
@ -77,33 +81,29 @@ static int gpio_keys_getc(struct console_device *cdev)
|
||||||
struct gpio_keys *gk = cdev_to_gk_pdata(cdev);
|
struct gpio_keys *gk = cdev_to_gk_pdata(cdev);
|
||||||
|
|
||||||
kfifo_get(gk->recv_fifo, (u_char*)&code, sizeof(int));
|
kfifo_get(gk->recv_fifo, (u_char*)&code, sizeof(int));
|
||||||
return code;
|
|
||||||
|
if (IS_ENABLED(CONFIG_OFDEVICE) && gk->use_keycodes)
|
||||||
|
return keycode_bb_keys[code];
|
||||||
|
else
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __init gpio_keys_probe(struct device_d *dev)
|
static int gpio_keys_probe_pdata(struct gpio_keys *gk, struct device_d *dev)
|
||||||
{
|
{
|
||||||
int ret, i, gpio;
|
|
||||||
struct gpio_keys_platform_data *pdata;
|
struct gpio_keys_platform_data *pdata;
|
||||||
struct console_device *cdev;
|
int i;
|
||||||
struct gpio_keys *gk;
|
|
||||||
|
|
||||||
pdata = dev->platform_data;
|
pdata = dev->platform_data;
|
||||||
|
|
||||||
if (!pdata) {
|
if (!pdata) {
|
||||||
/* small (so we copy it) but critical! */
|
/* small (so we copy it) but critical! */
|
||||||
pr_err("missing platform_data\n");
|
dev_err(dev, "missing platform_data\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
gk = xzalloc(sizeof(*gk));
|
|
||||||
|
|
||||||
gk->fifo_size = 50;
|
|
||||||
|
|
||||||
if (pdata->fifo_size)
|
if (pdata->fifo_size)
|
||||||
gk->fifo_size = pdata->fifo_size;
|
gk->fifo_size = pdata->fifo_size;
|
||||||
|
|
||||||
gk->recv_fifo = kfifo_alloc(pdata->fifo_size);
|
|
||||||
|
|
||||||
gk->buttons = xzalloc(pdata->nbuttons * sizeof(*gk->buttons));
|
gk->buttons = xzalloc(pdata->nbuttons * sizeof(*gk->buttons));
|
||||||
gk->nbuttons = pdata->nbuttons;
|
gk->nbuttons = pdata->nbuttons;
|
||||||
|
|
||||||
|
@ -113,7 +113,65 @@ static int __init gpio_keys_probe(struct device_d *dev)
|
||||||
gk->buttons[i].active_low = pdata->buttons[i].active_low;
|
gk->buttons[i].active_low = pdata->buttons[i].active_low;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < pdata->nbuttons; i++) {
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int gpio_keys_probe_dt(struct gpio_keys *gk, struct device_d *dev)
|
||||||
|
{
|
||||||
|
struct device_node *npkey, *np = dev->device_node;
|
||||||
|
int i = 0, ret;
|
||||||
|
|
||||||
|
if (!IS_ENABLED(CONFIG_OFDEVICE))
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
|
gk->nbuttons = of_get_child_count(np);
|
||||||
|
gk->buttons = xzalloc(gk->nbuttons * sizeof(*gk->buttons));
|
||||||
|
|
||||||
|
for_each_child_of_node(np, npkey) {
|
||||||
|
enum of_gpio_flags gpioflags;
|
||||||
|
uint32_t keycode;
|
||||||
|
|
||||||
|
gk->buttons[i].gpio = of_get_named_gpio_flags(npkey, "gpios", 0, &gpioflags);
|
||||||
|
if (gk->buttons[i].gpio < 0)
|
||||||
|
return gk->buttons[i].gpio;
|
||||||
|
|
||||||
|
if (gpioflags & OF_GPIO_ACTIVE_LOW)
|
||||||
|
gk->buttons[i].active_low = 1;
|
||||||
|
|
||||||
|
ret = of_property_read_u32(npkey, "linux,code", &keycode);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
gk->buttons[i].code = keycode;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
gk->use_keycodes = 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __init gpio_keys_probe(struct device_d *dev)
|
||||||
|
{
|
||||||
|
int ret, i, gpio;
|
||||||
|
struct console_device *cdev;
|
||||||
|
struct gpio_keys *gk;
|
||||||
|
|
||||||
|
gk = xzalloc(sizeof(*gk));
|
||||||
|
gk->fifo_size = 50;
|
||||||
|
|
||||||
|
if (dev->device_node)
|
||||||
|
ret = gpio_keys_probe_dt(gk, dev);
|
||||||
|
else
|
||||||
|
ret = gpio_keys_probe_pdata(gk, dev);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
gk->recv_fifo = kfifo_alloc(gk->fifo_size);
|
||||||
|
|
||||||
|
for (i = 0; i < gk->nbuttons; i++) {
|
||||||
gpio = gk->buttons[i].gpio;
|
gpio = gk->buttons[i].gpio;
|
||||||
ret = gpio_request(gpio, "gpio_keys");
|
ret = gpio_request(gpio, "gpio_keys");
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
@ -137,8 +195,14 @@ static int __init gpio_keys_probe(struct device_d *dev)
|
||||||
return poller_register(&gk->poller);
|
return poller_register(&gk->poller);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct of_device_id key_gpio_of_ids[] = {
|
||||||
|
{ .compatible = "gpio-keys", },
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
static struct driver_d gpio_keys_driver = {
|
static struct driver_d gpio_keys_driver = {
|
||||||
.name = "gpio_keys",
|
.name = "gpio_keys",
|
||||||
.probe = gpio_keys_probe,
|
.probe = gpio_keys_probe,
|
||||||
|
.of_compatible = DRV_OF_COMPAT(key_gpio_of_ids),
|
||||||
};
|
};
|
||||||
device_platform_driver(gpio_keys_driver);
|
device_platform_driver(gpio_keys_driver);
|
||||||
|
|
Loading…
Reference in New Issue