diff options
author | Aaron Lu <aaron.lu@intel.com> | 2014-10-21 07:34:00 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-11-04 15:58:24 -0500 |
commit | b26d4e2283b6d9b65bfe14b99c9c3a560e390a00 (patch) | |
tree | ea88d6d17c9cca3e7a36f01bc9aebe0f7b86a75f | |
parent | a43f2cbbb009f96231bbbe24ad4f824215dedb81 (diff) |
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: Aaron Lu <aaron.lu@intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: Grant Likely <grant.likely@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r-- | drivers/input/keyboard/gpio_keys_polled.c | 73 |
1 files changed, 24 insertions, 49 deletions
diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index b7a514ced509..c9c1c8ca7267 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c | |||
@@ -25,9 +25,7 @@ | |||
25 | #include <linux/gpio.h> | 25 | #include <linux/gpio.h> |
26 | #include <linux/gpio/consumer.h> | 26 | #include <linux/gpio/consumer.h> |
27 | #include <linux/gpio_keys.h> | 27 | #include <linux/gpio_keys.h> |
28 | #include <linux/of.h> | 28 | #include <linux/property.h> |
29 | #include <linux/of_platform.h> | ||
30 | #include <linux/of_gpio.h> | ||
31 | 29 | ||
32 | #define DRV_NAME "gpio-keys-polled" | 30 | #define DRV_NAME "gpio-keys-polled" |
33 | 31 | ||
@@ -102,21 +100,15 @@ static void gpio_keys_polled_close(struct input_polled_dev *dev) | |||
102 | pdata->disable(bdev->dev); | 100 | pdata->disable(bdev->dev); |
103 | } | 101 | } |
104 | 102 | ||
105 | #ifdef CONFIG_OF | ||
106 | static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct device *dev) | 103 | static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct device *dev) |
107 | { | 104 | { |
108 | struct device_node *node, *pp; | ||
109 | struct gpio_keys_platform_data *pdata; | 105 | struct gpio_keys_platform_data *pdata; |
110 | struct gpio_keys_button *button; | 106 | struct gpio_keys_button *button; |
107 | struct fwnode_handle *child; | ||
111 | int error; | 108 | int error; |
112 | int nbuttons; | 109 | int nbuttons; |
113 | int i; | ||
114 | |||
115 | node = dev->of_node; | ||
116 | if (!node) | ||
117 | return NULL; | ||
118 | 110 | ||
119 | nbuttons = of_get_child_count(node); | 111 | nbuttons = device_get_child_node_count(dev); |
120 | if (nbuttons == 0) | 112 | if (nbuttons == 0) |
121 | return NULL; | 113 | return NULL; |
122 | 114 | ||
@@ -126,52 +118,44 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct | |||
126 | return ERR_PTR(-ENOMEM); | 118 | return ERR_PTR(-ENOMEM); |
127 | 119 | ||
128 | pdata->buttons = (struct gpio_keys_button *)(pdata + 1); | 120 | pdata->buttons = (struct gpio_keys_button *)(pdata + 1); |
129 | pdata->nbuttons = nbuttons; | ||
130 | 121 | ||
131 | pdata->rep = !!of_get_property(node, "autorepeat", NULL); | 122 | pdata->rep = device_property_present(dev, "autorepeat"); |
132 | of_property_read_u32(node, "poll-interval", &pdata->poll_interval); | 123 | device_property_read_u32(dev, "poll-interval", &pdata->poll_interval); |
133 | 124 | ||
134 | i = 0; | 125 | device_for_each_child_node(dev, child) { |
135 | for_each_child_of_node(node, pp) { | 126 | struct gpio_desc *desc; |
136 | int gpio; | ||
137 | enum of_gpio_flags flags; | ||
138 | |||
139 | if (!of_find_property(pp, "gpios", NULL)) { | ||
140 | pdata->nbuttons--; | ||
141 | dev_warn(dev, "Found button without gpios\n"); | ||
142 | continue; | ||
143 | } | ||
144 | 127 | ||
145 | gpio = of_get_gpio_flags(pp, 0, &flags); | 128 | desc = devm_get_gpiod_from_child(dev, child); |
146 | if (gpio < 0) { | 129 | if (IS_ERR(desc)) { |
147 | error = gpio; | 130 | error = PTR_ERR(desc); |
148 | if (error != -EPROBE_DEFER) | 131 | if (error != -EPROBE_DEFER) |
149 | dev_err(dev, | 132 | dev_err(dev, |
150 | "Failed to get gpio flags, error: %d\n", | 133 | "Failed to get gpio flags, error: %d\n", |
151 | error); | 134 | error); |
135 | fwnode_handle_put(child); | ||
152 | return ERR_PTR(error); | 136 | return ERR_PTR(error); |
153 | } | 137 | } |
154 | 138 | ||
155 | button = &pdata->buttons[i++]; | 139 | button = &pdata->buttons[pdata->nbuttons++]; |
140 | button->gpiod = desc; | ||
156 | 141 | ||
157 | button->gpio = gpio; | 142 | if (fwnode_property_read_u32(child, "linux,code", &button->code)) { |
158 | button->active_low = flags & OF_GPIO_ACTIVE_LOW; | 143 | dev_err(dev, "Button without keycode: %d\n", |
159 | 144 | pdata->nbuttons - 1); | |
160 | if (of_property_read_u32(pp, "linux,code", &button->code)) { | 145 | fwnode_handle_put(child); |
161 | dev_err(dev, "Button without keycode: 0x%x\n", | ||
162 | button->gpio); | ||
163 | return ERR_PTR(-EINVAL); | 146 | return ERR_PTR(-EINVAL); |
164 | } | 147 | } |
165 | 148 | ||
166 | button->desc = of_get_property(pp, "label", NULL); | 149 | fwnode_property_read_string(child, "label", &button->desc); |
167 | 150 | ||
168 | if (of_property_read_u32(pp, "linux,input-type", &button->type)) | 151 | if (fwnode_property_read_u32(child, "linux,input-type", |
152 | &button->type)) | ||
169 | button->type = EV_KEY; | 153 | button->type = EV_KEY; |
170 | 154 | ||
171 | button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL); | 155 | button->wakeup = fwnode_property_present(child, "gpio-key,wakeup"); |
172 | 156 | ||
173 | if (of_property_read_u32(pp, "debounce-interval", | 157 | if (fwnode_property_read_u32(child, "debounce-interval", |
174 | &button->debounce_interval)) | 158 | &button->debounce_interval)) |
175 | button->debounce_interval = 5; | 159 | button->debounce_interval = 5; |
176 | } | 160 | } |
177 | 161 | ||
@@ -187,15 +171,6 @@ static const struct of_device_id gpio_keys_polled_of_match[] = { | |||
187 | }; | 171 | }; |
188 | MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match); | 172 | MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match); |
189 | 173 | ||
190 | #else | ||
191 | |||
192 | static inline struct gpio_keys_platform_data * | ||
193 | gpio_keys_polled_get_devtree_pdata(struct device *dev) | ||
194 | { | ||
195 | return NULL; | ||
196 | } | ||
197 | #endif | ||
198 | |||
199 | static int gpio_keys_polled_probe(struct platform_device *pdev) | 174 | static int gpio_keys_polled_probe(struct platform_device *pdev) |
200 | { | 175 | { |
201 | struct device *dev = &pdev->dev; | 176 | struct device *dev = &pdev->dev; |
@@ -323,7 +298,7 @@ static struct platform_driver gpio_keys_polled_driver = { | |||
323 | .driver = { | 298 | .driver = { |
324 | .name = DRV_NAME, | 299 | .name = DRV_NAME, |
325 | .owner = THIS_MODULE, | 300 | .owner = THIS_MODULE, |
326 | .of_match_table = of_match_ptr(gpio_keys_polled_of_match), | 301 | .of_match_table = gpio_keys_polled_of_match, |
327 | }, | 302 | }, |
328 | }; | 303 | }; |
329 | module_platform_driver(gpio_keys_polled_driver); | 304 | module_platform_driver(gpio_keys_polled_driver); |