Commit b26d4e22 authored by Aaron Lu's avatar Aaron Lu Committed by Rafael J. Wysocki

input: gpio_keys_polled: Make use of device property API

Make use of device property API in this driver so that both OF based
system and ACPI based system can use this driver.
Signed-off-by: default avatarAaron Lu <aaron.lu@intel.com>
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: default avatarGrant Likely <grant.likely@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent a43f2cbb
...@@ -25,9 +25,7 @@ ...@@ -25,9 +25,7 @@
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/gpio_keys.h> #include <linux/gpio_keys.h>
#include <linux/of.h> #include <linux/property.h>
#include <linux/of_platform.h>
#include <linux/of_gpio.h>
#define DRV_NAME "gpio-keys-polled" #define DRV_NAME "gpio-keys-polled"
...@@ -102,21 +100,15 @@ static void gpio_keys_polled_close(struct input_polled_dev *dev) ...@@ -102,21 +100,15 @@ static void gpio_keys_polled_close(struct input_polled_dev *dev)
pdata->disable(bdev->dev); pdata->disable(bdev->dev);
} }
#ifdef CONFIG_OF
static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct device *dev) static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct device *dev)
{ {
struct device_node *node, *pp;
struct gpio_keys_platform_data *pdata; struct gpio_keys_platform_data *pdata;
struct gpio_keys_button *button; struct gpio_keys_button *button;
struct fwnode_handle *child;
int error; int error;
int nbuttons; int nbuttons;
int i;
node = dev->of_node;
if (!node)
return NULL;
nbuttons = of_get_child_count(node); nbuttons = device_get_child_node_count(dev);
if (nbuttons == 0) if (nbuttons == 0)
return NULL; return NULL;
...@@ -126,51 +118,43 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct ...@@ -126,51 +118,43 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
pdata->buttons = (struct gpio_keys_button *)(pdata + 1); pdata->buttons = (struct gpio_keys_button *)(pdata + 1);
pdata->nbuttons = nbuttons;
pdata->rep = !!of_get_property(node, "autorepeat", NULL); pdata->rep = device_property_present(dev, "autorepeat");
of_property_read_u32(node, "poll-interval", &pdata->poll_interval); device_property_read_u32(dev, "poll-interval", &pdata->poll_interval);
i = 0; device_for_each_child_node(dev, child) {
for_each_child_of_node(node, pp) { struct gpio_desc *desc;
int gpio;
enum of_gpio_flags flags;
if (!of_find_property(pp, "gpios", NULL)) { desc = devm_get_gpiod_from_child(dev, child);
pdata->nbuttons--; if (IS_ERR(desc)) {
dev_warn(dev, "Found button without gpios\n"); error = PTR_ERR(desc);
continue;
}
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);
fwnode_handle_put(child);
return ERR_PTR(error); return ERR_PTR(error);
} }
button = &pdata->buttons[i++]; button = &pdata->buttons[pdata->nbuttons++];
button->gpiod = desc;
button->gpio = gpio;
button->active_low = flags & OF_GPIO_ACTIVE_LOW;
if (of_property_read_u32(pp, "linux,code", &button->code)) { if (fwnode_property_read_u32(child, "linux,code", &button->code)) {
dev_err(dev, "Button without keycode: 0x%x\n", dev_err(dev, "Button without keycode: %d\n",
button->gpio); pdata->nbuttons - 1);
fwnode_handle_put(child);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
button->desc = of_get_property(pp, "label", NULL); fwnode_property_read_string(child, "label", &button->desc);
if (of_property_read_u32(pp, "linux,input-type", &button->type)) if (fwnode_property_read_u32(child, "linux,input-type",
&button->type))
button->type = EV_KEY; button->type = EV_KEY;
button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL); button->wakeup = fwnode_property_present(child, "gpio-key,wakeup");
if (of_property_read_u32(pp, "debounce-interval", if (fwnode_property_read_u32(child, "debounce-interval",
&button->debounce_interval)) &button->debounce_interval))
button->debounce_interval = 5; button->debounce_interval = 5;
} }
...@@ -187,15 +171,6 @@ static const struct of_device_id gpio_keys_polled_of_match[] = { ...@@ -187,15 +171,6 @@ static const struct of_device_id gpio_keys_polled_of_match[] = {
}; };
MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match); MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match);
#else
static inline struct gpio_keys_platform_data *
gpio_keys_polled_get_devtree_pdata(struct device *dev)
{
return NULL;
}
#endif
static int gpio_keys_polled_probe(struct platform_device *pdev) static int gpio_keys_polled_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
...@@ -323,7 +298,7 @@ static struct platform_driver gpio_keys_polled_driver = { ...@@ -323,7 +298,7 @@ static struct platform_driver gpio_keys_polled_driver = {
.driver = { .driver = {
.name = DRV_NAME, .name = DRV_NAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,
.of_match_table = of_match_ptr(gpio_keys_polled_of_match), .of_match_table = gpio_keys_polled_of_match,
}, },
}; };
module_platform_driver(gpio_keys_polled_driver); module_platform_driver(gpio_keys_polled_driver);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment