Commit 6ee88d71 authored by Daniel Mack's avatar Daniel Mack Committed by Dmitry Torokhov

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: default avatarDaniel Mack <daniel@caiaq.de>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent 21cea58e
...@@ -37,10 +37,8 @@ struct gpio_keys_drvdata { ...@@ -37,10 +37,8 @@ struct gpio_keys_drvdata {
struct gpio_button_data data[0]; struct gpio_button_data data[0];
}; };
static void gpio_keys_report_event(struct work_struct *work) static void gpio_keys_report_event(struct gpio_button_data *bdata)
{ {
struct gpio_button_data *bdata =
container_of(work, struct gpio_button_data, work);
struct gpio_keys_button *button = bdata->button; struct gpio_keys_button *button = bdata->button;
struct input_dev *input = bdata->input; struct input_dev *input = bdata->input;
unsigned int type = button->type ?: EV_KEY; unsigned int type = button->type ?: EV_KEY;
...@@ -50,6 +48,14 @@ static void gpio_keys_report_event(struct work_struct *work) ...@@ -50,6 +48,14 @@ static void gpio_keys_report_event(struct work_struct *work)
input_sync(input); input_sync(input);
} }
static void gpio_keys_work_func(struct work_struct *work)
{
struct gpio_button_data *bdata =
container_of(work, struct gpio_button_data, work);
gpio_keys_report_event(bdata);
}
static void gpio_keys_timer(unsigned long _data) static void gpio_keys_timer(unsigned long _data)
{ {
struct gpio_button_data *data = (struct gpio_button_data *)_data; 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,7 +87,7 @@ static int __devinit gpio_keys_setup_key(struct device *dev,
int irq, error; int irq, error;
setup_timer(&bdata->timer, gpio_keys_timer, (unsigned long)bdata); setup_timer(&bdata->timer, gpio_keys_timer, (unsigned long)bdata);
INIT_WORK(&bdata->work, gpio_keys_report_event); INIT_WORK(&bdata->work, gpio_keys_work_func);
error = gpio_request(button->gpio, desc); error = gpio_request(button->gpio, desc);
if (error < 0) { if (error < 0) {
...@@ -185,6 +191,11 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev) ...@@ -185,6 +191,11 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
goto fail2; goto fail2;
} }
/* get current state of buttons */
for (i = 0; i < pdata->nbuttons; i++)
gpio_keys_report_event(&ddata->data[i]);
input_sync(input);
device_init_wakeup(&pdev->dev, wakeup); device_init_wakeup(&pdev->dev, wakeup);
return 0; return 0;
...@@ -253,18 +264,21 @@ static int gpio_keys_suspend(struct device *dev) ...@@ -253,18 +264,21 @@ static int gpio_keys_suspend(struct device *dev)
static int gpio_keys_resume(struct device *dev) static int gpio_keys_resume(struct device *dev)
{ {
struct platform_device *pdev = to_platform_device(dev); struct platform_device *pdev = to_platform_device(dev);
struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
int i; int i;
if (device_may_wakeup(&pdev->dev)) {
for (i = 0; i < pdata->nbuttons; i++) { for (i = 0; i < pdata->nbuttons; i++) {
struct gpio_keys_button *button = &pdata->buttons[i]; struct gpio_keys_button *button = &pdata->buttons[i];
if (button->wakeup) { if (button->wakeup && device_may_wakeup(&pdev->dev)) {
int irq = gpio_to_irq(button->gpio); int irq = gpio_to_irq(button->gpio);
disable_irq_wake(irq); disable_irq_wake(irq);
} }
gpio_keys_report_event(&ddata->data[i]);
} }
} input_sync(ddata->input);
return 0; return 0;
} }
......
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