linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] input_ gpio_keys: scan gpio state at probe time
@ 2009-11-25 10:53 Daniel Mack
  2009-11-26  3:46 ` Dmitry Torokhov
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Mack @ 2009-11-25 10:53 UTC (permalink / raw)
  To: linux-input; +Cc: Daniel Mack, Dmitry Torokhov, Jani Nikula, Mike Rapoport

gpio_keys.c registers interrupts at both edges of all given gpio lines
and updates the input device when they change. However, the driver fails
to check the current line state at probe time.

Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Jani Nikula <ext-jani.1.nikula@nokia.com>
Cc: Mike Rapoport <mike@compulab.co.il>
---
 drivers/input/keyboard/gpio_keys.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 77d1309..cb5f862 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -171,6 +171,18 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 		goto fail2;
 	}
 
+	/* get current state of buttons */
+	for (i = 0; i < pdata->nbuttons; i++) {
+		struct gpio_keys_button *button = &pdata->buttons[i];
+		int state = !!gpio_get_value(button->gpio) ^ button->active_low;
+
+		if (state) {
+			unsigned int type = button->type ?: EV_KEY;
+			input_event(input, type, button->code, !!state);
+			input_sync(input);
+		}
+	}
+
 	device_init_wakeup(&pdev->dev, wakeup);
 
 	return 0;
-- 
1.6.5.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] input_ gpio_keys: scan gpio state at probe time
  2009-11-25 10:53 [PATCH] input_ gpio_keys: scan gpio state at probe time Daniel Mack
@ 2009-11-26  3:46 ` Dmitry Torokhov
  2009-12-14  3:10   ` Daniel Mack
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2009-11-26  3:46 UTC (permalink / raw)
  To: Daniel Mack; +Cc: linux-input, Jani Nikula, Mike Rapoport

On Wed, Nov 25, 2009 at 11:53:36AM +0100, Daniel Mack wrote:
> gpio_keys.c registers interrupts at both edges of all given gpio lines
> and updates the input device when they change. However, the driver fails
> to check the current line state at probe time.
> 

Should not matter for keys really, but is important for swicthes. I
guess we need to also do this at resume. Does the following still work?

Thanks.

-- 
Dmitry


Input: gpio_keys - scan gpio state at probe time

From: Daniel Mack <daniel@caiaq.de>

Signed-off-by: Daniel Mack <daniel@caiaq.de>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

 drivers/input/keyboard/gpio_keys.c |   36 +++++++++++++++++++++++++-----------
 1 files changed, 25 insertions(+), 11 deletions(-)


diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 8941a8b..1aff3b7 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -37,10 +37,8 @@ struct gpio_keys_drvdata {
 	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 input_dev *input = bdata->input;
 	unsigned int type = button->type ?: EV_KEY;
@@ -50,6 +48,14 @@ static void gpio_keys_report_event(struct work_struct *work)
 	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)
 {
 	struct gpio_button_data *data = (struct gpio_button_data *)_data;
@@ -81,7 +87,7 @@ static int __devinit gpio_keys_setup_key(struct device *dev,
 	int irq, error;
 
 	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);
 	if (error < 0) {
@@ -185,6 +191,11 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 		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);
 
 	return 0;
@@ -253,18 +264,21 @@ static int gpio_keys_suspend(struct device *dev)
 static int gpio_keys_resume(struct 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;
 	int i;
 
-	if (device_may_wakeup(&pdev->dev)) {
-		for (i = 0; i < pdata->nbuttons; i++) {
-			struct gpio_keys_button *button = &pdata->buttons[i];
-			if (button->wakeup) {
-				int irq = gpio_to_irq(button->gpio);
-				disable_irq_wake(irq);
-			}
+	for (i = 0; i < pdata->nbuttons; i++) {
+
+		struct gpio_keys_button *button = &pdata->buttons[i];
+		if (button->wakeup && device_may_wakeup(&pdev->dev)) {
+			int irq = gpio_to_irq(button->gpio);
+			disable_irq_wake(irq);
 		}
+
+		gpio_keys_report_event(&ddata->data[i]);
 	}
+	input_sync(ddata->input);
 
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] input_ gpio_keys: scan gpio state at probe time
  2009-11-26  3:46 ` Dmitry Torokhov
@ 2009-12-14  3:10   ` Daniel Mack
  2009-12-14  4:31     ` Dmitry Torokhov
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Mack @ 2009-12-14  3:10 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, Jani Nikula, Mike Rapoport

On Wed, Nov 25, 2009 at 07:46:13PM -0800, Dmitry Torokhov wrote:
> On Wed, Nov 25, 2009 at 11:53:36AM +0100, Daniel Mack wrote:
> > gpio_keys.c registers interrupts at both edges of all given gpio lines
> > and updates the input device when they change. However, the driver fails
> > to check the current line state at probe time.
> > 
> 
> Should not matter for keys really, but is important for swicthes. I
> guess we need to also do this at resume. Does the following still work?

Sorry for the long delay on this. I could finally test this patch and it
works fine, key states are reported correctly after resume.

Thanks,
Daniel

> Input: gpio_keys - scan gpio state at probe time
> 
> From: Daniel Mack <daniel@caiaq.de>
> 
> Signed-off-by: Daniel Mack <daniel@caiaq.de>
> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
> ---
> 
>  drivers/input/keyboard/gpio_keys.c |   36 +++++++++++++++++++++++++-----------
>  1 files changed, 25 insertions(+), 11 deletions(-)
> 
> 
> diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
> index 8941a8b..1aff3b7 100644
> --- a/drivers/input/keyboard/gpio_keys.c
> +++ b/drivers/input/keyboard/gpio_keys.c
> @@ -37,10 +37,8 @@ struct gpio_keys_drvdata {
>  	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 input_dev *input = bdata->input;
>  	unsigned int type = button->type ?: EV_KEY;
> @@ -50,6 +48,14 @@ static void gpio_keys_report_event(struct work_struct *work)
>  	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)
>  {
>  	struct gpio_button_data *data = (struct gpio_button_data *)_data;
> @@ -81,7 +87,7 @@ static int __devinit gpio_keys_setup_key(struct device *dev,
>  	int irq, error;
>  
>  	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);
>  	if (error < 0) {
> @@ -185,6 +191,11 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  		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);
>  
>  	return 0;
> @@ -253,18 +264,21 @@ static int gpio_keys_suspend(struct device *dev)
>  static int gpio_keys_resume(struct 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;
>  	int i;
>  
> -	if (device_may_wakeup(&pdev->dev)) {
> -		for (i = 0; i < pdata->nbuttons; i++) {
> -			struct gpio_keys_button *button = &pdata->buttons[i];
> -			if (button->wakeup) {
> -				int irq = gpio_to_irq(button->gpio);
> -				disable_irq_wake(irq);
> -			}
> +	for (i = 0; i < pdata->nbuttons; i++) {
> +
> +		struct gpio_keys_button *button = &pdata->buttons[i];
> +		if (button->wakeup && device_may_wakeup(&pdev->dev)) {
> +			int irq = gpio_to_irq(button->gpio);
> +			disable_irq_wake(irq);
>  		}
> +
> +		gpio_keys_report_event(&ddata->data[i]);
>  	}
> +	input_sync(ddata->input);
>  
>  	return 0;
>  }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] input_ gpio_keys: scan gpio state at probe time
  2009-12-14  3:10   ` Daniel Mack
@ 2009-12-14  4:31     ` Dmitry Torokhov
  2009-12-17  1:05       ` Daniel Mack
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2009-12-14  4:31 UTC (permalink / raw)
  To: Daniel Mack; +Cc: linux-input, Jani Nikula, Mike Rapoport

On Mon, Dec 14, 2009 at 11:10:55AM +0800, Daniel Mack wrote:
> On Wed, Nov 25, 2009 at 07:46:13PM -0800, Dmitry Torokhov wrote:
> > On Wed, Nov 25, 2009 at 11:53:36AM +0100, Daniel Mack wrote:
> > > gpio_keys.c registers interrupts at both edges of all given gpio lines
> > > and updates the input device when they change. However, the driver fails
> > > to check the current line state at probe time.
> > > 
> > 
> > Should not matter for keys really, but is important for swicthes. I
> > guess we need to also do this at resume. Does the following still work?
> 
> Sorry for the long delay on this. I could finally test this patch and it
> works fine, key states are reported correctly after resume.
> 

Thanks Daniel.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] input_ gpio_keys: scan gpio state at probe time
  2009-12-14  4:31     ` Dmitry Torokhov
@ 2009-12-17  1:05       ` Daniel Mack
  2009-12-17  1:16         ` Dmitry Torokhov
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Mack @ 2009-12-17  1:05 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, Jani Nikula, Mike Rapoport

On Sun, Dec 13, 2009 at 08:31:17PM -0800, Dmitry Torokhov wrote:
> On Mon, Dec 14, 2009 at 11:10:55AM +0800, Daniel Mack wrote:
> > On Wed, Nov 25, 2009 at 07:46:13PM -0800, Dmitry Torokhov wrote:
> > > On Wed, Nov 25, 2009 at 11:53:36AM +0100, Daniel Mack wrote:
> > > > gpio_keys.c registers interrupts at both edges of all given gpio lines
> > > > and updates the input device when they change. However, the driver fails
> > > > to check the current line state at probe time.
> > > > 
> > > 
> > > Should not matter for keys really, but is important for swicthes. I
> > > guess we need to also do this at resume. Does the following still work?
> > 
> > Sorry for the long delay on this. I could finally test this patch and it
> > works fine, key states are reported correctly after resume.
> > 
> 
> Thanks Daniel.

Will this still make it to 2.6.33?

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] input_ gpio_keys: scan gpio state at probe time
  2009-12-17  1:05       ` Daniel Mack
@ 2009-12-17  1:16         ` Dmitry Torokhov
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2009-12-17  1:16 UTC (permalink / raw)
  To: Daniel Mack; +Cc: linux-input, Jani Nikula, Mike Rapoport

On Thu, Dec 17, 2009 at 09:05:49AM +0800, Daniel Mack wrote:
> On Sun, Dec 13, 2009 at 08:31:17PM -0800, Dmitry Torokhov wrote:
> > On Mon, Dec 14, 2009 at 11:10:55AM +0800, Daniel Mack wrote:
> > > On Wed, Nov 25, 2009 at 07:46:13PM -0800, Dmitry Torokhov wrote:
> > > > On Wed, Nov 25, 2009 at 11:53:36AM +0100, Daniel Mack wrote:
> > > > > gpio_keys.c registers interrupts at both edges of all given gpio lines
> > > > > and updates the input device when they change. However, the driver fails
> > > > > to check the current line state at probe time.
> > > > > 
> > > > 
> > > > Should not matter for keys really, but is important for swicthes. I
> > > > guess we need to also do this at resume. Does the following still work?
> > > 
> > > Sorry for the long delay on this. I could finally test this patch and it
> > > works fine, key states are reported correctly after resume.
> > > 
> > 
> > Thanks Daniel.
> 
> Will this still make it to 2.6.33?
> 

It is already there.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-12-17  1:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-25 10:53 [PATCH] input_ gpio_keys: scan gpio state at probe time Daniel Mack
2009-11-26  3:46 ` Dmitry Torokhov
2009-12-14  3:10   ` Daniel Mack
2009-12-14  4:31     ` Dmitry Torokhov
2009-12-17  1:05       ` Daniel Mack
2009-12-17  1:16         ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).