aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorDaniel Mack <daniel@caiaq.de>2009-11-30 03:04:02 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2009-11-30 03:05:20 -0500
commit6ee88d713fb75ab191515f66edffa4e866386565 (patch)
treee1d5230d0d6ce85f4194e2744c5318e63fa2f190 /drivers/input
parent21cea58e49cf59e7c77ce2a01be432458e9f99a9 (diff)
Input: gpio_keys - scan gpio state at probe and resume time
We need to read and report gpio state when we bind the driver to the device and upon resume so that userspace has correct state of the switches (and keys but they are less important since, even if they are happened to be pressed, we'd expect them to be released fairly soon). Signed-off-by: Daniel Mack <daniel@caiaq.de> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/keyboard/gpio_keys.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 8941a8ba89bf..1aff3b76effd 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -37,10 +37,8 @@ struct gpio_keys_drvdata {
37 struct gpio_button_data data[0]; 37 struct gpio_button_data data[0];
38}; 38};
39 39
40static void gpio_keys_report_event(struct work_struct *work) 40static void gpio_keys_report_event(struct gpio_button_data *bdata)
41{ 41{
42 struct gpio_button_data *bdata =
43 container_of(work, struct gpio_button_data, work);
44 struct gpio_keys_button *button = bdata->button; 42 struct gpio_keys_button *button = bdata->button;
45 struct input_dev *input = bdata->input; 43 struct input_dev *input = bdata->input;
46 unsigned int type = button->type ?: EV_KEY; 44 unsigned int type = button->type ?: EV_KEY;
@@ -50,6 +48,14 @@ static void gpio_keys_report_event(struct work_struct *work)
50 input_sync(input); 48 input_sync(input);
51} 49}
52 50
51static void gpio_keys_work_func(struct work_struct *work)
52{
53 struct gpio_button_data *bdata =
54 container_of(work, struct gpio_button_data, work);
55
56 gpio_keys_report_event(bdata);
57}
58
53static void gpio_keys_timer(unsigned long _data) 59static void gpio_keys_timer(unsigned long _data)
54{ 60{
55 struct gpio_button_data *data = (struct gpio_button_data *)_data; 61 struct gpio_button_data *data = (struct gpio_button_data *)_data;
@@ -81,7 +87,7 @@ static int __devinit gpio_keys_setup_key(struct device *dev,
81 int irq, error; 87 int irq, error;
82 88
83 setup_timer(&bdata->timer, gpio_keys_timer, (unsigned long)bdata); 89 setup_timer(&bdata->timer, gpio_keys_timer, (unsigned long)bdata);
84 INIT_WORK(&bdata->work, gpio_keys_report_event); 90 INIT_WORK(&bdata->work, gpio_keys_work_func);
85 91
86 error = gpio_request(button->gpio, desc); 92 error = gpio_request(button->gpio, desc);
87 if (error < 0) { 93 if (error < 0) {
@@ -185,6 +191,11 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
185 goto fail2; 191 goto fail2;
186 } 192 }
187 193
194 /* get current state of buttons */
195 for (i = 0; i < pdata->nbuttons; i++)
196 gpio_keys_report_event(&ddata->data[i]);
197 input_sync(input);
198
188 device_init_wakeup(&pdev->dev, wakeup); 199 device_init_wakeup(&pdev->dev, wakeup);
189 200
190 return 0; 201 return 0;
@@ -253,18 +264,21 @@ static int gpio_keys_suspend(struct device *dev)
253static int gpio_keys_resume(struct device *dev) 264static int gpio_keys_resume(struct device *dev)
254{ 265{
255 struct platform_device *pdev = to_platform_device(dev); 266 struct platform_device *pdev = to_platform_device(dev);
267 struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
256 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; 268 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
257 int i; 269 int i;
258 270
259 if (device_may_wakeup(&pdev->dev)) { 271 for (i = 0; i < pdata->nbuttons; i++) {
260 for (i = 0; i < pdata->nbuttons; i++) { 272
261 struct gpio_keys_button *button = &pdata->buttons[i]; 273 struct gpio_keys_button *button = &pdata->buttons[i];
262 if (button->wakeup) { 274 if (button->wakeup && device_may_wakeup(&pdev->dev)) {
263 int irq = gpio_to_irq(button->gpio); 275 int irq = gpio_to_irq(button->gpio);
264 disable_irq_wake(irq); 276 disable_irq_wake(irq);
265 }
266 } 277 }
278
279 gpio_keys_report_event(&ddata->data[i]);
267 } 280 }
281 input_sync(ddata->input);
268 282
269 return 0; 283 return 0;
270} 284}