linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] input: gpio_keys: Polling mode support.
@ 2008-10-21  8:38 Paul Mundt
  2008-10-28 10:18 ` Paul Mundt
  0 siblings, 1 reply; 17+ messages in thread
From: Paul Mundt @ 2008-10-21  8:38 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-sh

This implements an optional polling mode for the gpio_keys driver,
necessary for GPIOs that are not able to generate IRQs.

Polling mode is done device granular, and can not be toggled for
individual GPIOs in order to maintain simplicity. Platforms with both
IRQ capable and incapable GPIOs are required to register multiple
times, once for each case.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>

---

 drivers/input/keyboard/Kconfig     |    1 
 drivers/input/keyboard/gpio_keys.c |   91 ++++++++++++++++++++++++++++---------
 include/linux/gpio_keys.h          |    1 
 3 files changed, 72 insertions(+), 21 deletions(-)

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index efd70a9..a8cefe9 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -283,6 +283,7 @@ config KEYBOARD_AAED2000
 config KEYBOARD_GPIO
 	tristate "GPIO Buttons"
 	depends on GENERIC_GPIO
+	select INPUT_POLLDEV
 	help
 	  This driver implements support for buttons connected
 	  to GPIO pins of various CPUs (and some other chips).
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 05f3f43..412a10d 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -1,7 +1,8 @@
 /*
- * Driver for keys on GPIO lines capable of generating interrupts.
+ * Driver for keys on GPIO lines, either IRQ-driven or polled.
  *
  * Copyright 2005 Phil Blundell
+ * Copyright 2008 Paul Mundt
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -9,7 +10,6 @@
  */
 
 #include <linux/module.h>
-
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <linux/interrupt.h>
@@ -22,7 +22,7 @@
 #include <linux/platform_device.h>
 #include <linux/input.h>
 #include <linux/gpio_keys.h>
-
+#include <linux/input-polldev.h>
 #include <asm/gpio.h>
 
 struct gpio_button_data {
@@ -32,7 +32,8 @@ struct gpio_button_data {
 };
 
 struct gpio_keys_drvdata {
-	struct input_dev *input;
+	struct gpio_keys_platform_data *pdata;
+	struct input_polled_dev *poll_dev;
 	struct gpio_button_data data[0];
 };
 
@@ -54,6 +55,33 @@ static void gpio_check_button(unsigned long _data)
 	gpio_keys_report_event(data);
 }
 
+static void gpio_handle_button_event(struct gpio_keys_button *button,
+				     struct gpio_button_data *bdata)
+{
+	if (button->debounce_interval)
+		mod_timer(&bdata->timer,
+			jiffies + msecs_to_jiffies(button->debounce_interval));
+	else
+		gpio_keys_report_event(bdata);
+}
+
+static void gpio_keys_poll(struct input_polled_dev *dev)
+{
+	struct gpio_keys_drvdata *ddata = dev->private;
+	struct gpio_keys_platform_data *pdata = ddata->pdata;
+	int i;
+
+	for (i = 0; i < pdata->nbuttons; i++) {
+		struct gpio_keys_button *button = &pdata->buttons[i];
+		struct gpio_button_data *bdata = &ddata->data[i];
+
+		bdata->input = dev->input;
+		bdata->button = button;
+
+		gpio_handle_button_event(button, bdata);
+	}
+}
+
 static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
 {
 	struct gpio_button_data *bdata = dev_id;
@@ -61,11 +89,7 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
 
 	BUG_ON(irq != gpio_to_irq(button->gpio));
 
-	if (button->debounce_interval)
-		mod_timer(&bdata->timer,
-			jiffies + msecs_to_jiffies(button->debounce_interval));
-	else
-		gpio_keys_report_event(bdata);
+	gpio_handle_button_event(button, bdata);
 
 	return IRQ_HANDLED;
 }
@@ -74,6 +98,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 {
 	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
 	struct gpio_keys_drvdata *ddata;
+	struct input_polled_dev *poll_dev;
 	struct input_dev *input;
 	int i, error;
 	int wakeup = 0;
@@ -81,14 +106,19 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
 			pdata->nbuttons * sizeof(struct gpio_button_data),
 			GFP_KERNEL);
-	input = input_allocate_device();
-	if (!ddata || !input) {
+	poll_dev = input_allocate_polled_device();
+	if (!ddata || !poll_dev) {
 		error = -ENOMEM;
 		goto fail1;
 	}
 
 	platform_set_drvdata(pdev, ddata);
 
+	poll_dev->private = ddata;
+	poll_dev->poll = gpio_keys_poll;
+	poll_dev->poll_interval = 50; /* msec */
+
+	input = poll_dev->input;
 	input->name = pdev->name;
 	input->phys = "gpio-keys/input0";
 	input->dev.parent = &pdev->dev;
@@ -98,7 +128,8 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 	input->id.product = 0x0001;
 	input->id.version = 0x0100;
 
-	ddata->input = input;
+	ddata->poll_dev = poll_dev;
+	ddata->pdata = pdata;
 
 	for (i = 0; i < pdata->nbuttons; i++) {
 		struct gpio_keys_button *button = &pdata->buttons[i];
@@ -127,6 +158,15 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 			goto fail2;
 		}
 
+		input_set_capability(input, type, button->code);
+
+		/*
+		 * Skip the IRQ setup and wakeup source initialization if
+		 * we are going to be polled.
+		 */
+		if (pdata->polling)
+			continue;
+
 		irq = gpio_to_irq(button->gpio);
 		if (irq < 0) {
 			error = irq;
@@ -151,11 +191,12 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 
 		if (button->wakeup)
 			wakeup = 1;
-
-		input_set_capability(input, type, button->code);
 	}
 
-	error = input_register_device(input);
+	if (pdata->polling)
+		error = input_register_polled_device(poll_dev);
+	else
+		error = input_register_device(input);
 	if (error) {
 		pr_err("gpio-keys: Unable to register input device, "
 			"error: %d\n", error);
@@ -168,7 +209,9 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 
  fail2:
 	while (--i >= 0) {
-		free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
+		if (!pdata->polling)
+			free_irq(gpio_to_irq(pdata->buttons[i].gpio),
+				 &ddata->data[i]);
 		if (pdata->buttons[i].debounce_interval)
 			del_timer_sync(&ddata->data[i].timer);
 		gpio_free(pdata->buttons[i].gpio);
@@ -176,7 +219,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, NULL);
  fail1:
-	input_free_device(input);
+	input_free_polled_device(poll_dev);
 	kfree(ddata);
 
 	return error;
@@ -186,20 +229,26 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
 {
 	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
 	struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
-	struct input_dev *input = ddata->input;
+	struct input_polled_dev *poll_dev = ddata->poll_dev;
 	int i;
 
 	device_init_wakeup(&pdev->dev, 0);
 
 	for (i = 0; i < pdata->nbuttons; i++) {
-		int irq = gpio_to_irq(pdata->buttons[i].gpio);
-		free_irq(irq, &ddata->data[i]);
+		if (!pdata->polling) {
+			int irq = gpio_to_irq(pdata->buttons[i].gpio);
+			free_irq(irq, &ddata->data[i]);
+		}
+
 		if (pdata->buttons[i].debounce_interval)
 			del_timer_sync(&ddata->data[i].timer);
 		gpio_free(pdata->buttons[i].gpio);
 	}
 
-	input_unregister_device(input);
+	if (pdata->polling)
+		input_unregister_polled_device(poll_dev);
+	else
+		input_unregister_device(poll_dev->input);
 
 	return 0;
 }
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
index ec6ecd7..e869752 100644
--- a/include/linux/gpio_keys.h
+++ b/include/linux/gpio_keys.h
@@ -15,6 +15,7 @@ struct gpio_keys_button {
 struct gpio_keys_platform_data {
 	struct gpio_keys_button *buttons;
 	int nbuttons;
+	int polling;		/* force polling mode */
 };
 
 #endif

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

* Re: [PATCH] input: gpio_keys: Polling mode support.
  2008-10-21  8:38 [PATCH] input: gpio_keys: Polling " Paul Mundt
@ 2008-10-28 10:18 ` Paul Mundt
  2008-10-29  3:51   ` Dmitry Torokhov
  0 siblings, 1 reply; 17+ messages in thread
From: Paul Mundt @ 2008-10-28 10:18 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, linux-sh

Ping.

On Tue, Oct 21, 2008 at 05:38:16PM +0900, Paul Mundt wrote:
> This implements an optional polling mode for the gpio_keys driver,
> necessary for GPIOs that are not able to generate IRQs.
> 
> Polling mode is done device granular, and can not be toggled for
> individual GPIOs in order to maintain simplicity. Platforms with both
> IRQ capable and incapable GPIOs are required to register multiple
> times, once for each case.
> 
> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
> 
> ---
> 
>  drivers/input/keyboard/Kconfig     |    1 
>  drivers/input/keyboard/gpio_keys.c |   91 ++++++++++++++++++++++++++++---------
>  include/linux/gpio_keys.h          |    1 
>  3 files changed, 72 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index efd70a9..a8cefe9 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -283,6 +283,7 @@ config KEYBOARD_AAED2000
>  config KEYBOARD_GPIO
>  	tristate "GPIO Buttons"
>  	depends on GENERIC_GPIO
> +	select INPUT_POLLDEV
>  	help
>  	  This driver implements support for buttons connected
>  	  to GPIO pins of various CPUs (and some other chips).
> diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
> index 05f3f43..412a10d 100644
> --- a/drivers/input/keyboard/gpio_keys.c
> +++ b/drivers/input/keyboard/gpio_keys.c
> @@ -1,7 +1,8 @@
>  /*
> - * Driver for keys on GPIO lines capable of generating interrupts.
> + * Driver for keys on GPIO lines, either IRQ-driven or polled.
>   *
>   * Copyright 2005 Phil Blundell
> + * Copyright 2008 Paul Mundt
>   *
>   * This program is free software; you can redistribute it and/or modify
>   * it under the terms of the GNU General Public License version 2 as
> @@ -9,7 +10,6 @@
>   */
>  
>  #include <linux/module.h>
> -
>  #include <linux/init.h>
>  #include <linux/fs.h>
>  #include <linux/interrupt.h>
> @@ -22,7 +22,7 @@
>  #include <linux/platform_device.h>
>  #include <linux/input.h>
>  #include <linux/gpio_keys.h>
> -
> +#include <linux/input-polldev.h>
>  #include <asm/gpio.h>
>  
>  struct gpio_button_data {
> @@ -32,7 +32,8 @@ struct gpio_button_data {
>  };
>  
>  struct gpio_keys_drvdata {
> -	struct input_dev *input;
> +	struct gpio_keys_platform_data *pdata;
> +	struct input_polled_dev *poll_dev;
>  	struct gpio_button_data data[0];
>  };
>  
> @@ -54,6 +55,33 @@ static void gpio_check_button(unsigned long _data)
>  	gpio_keys_report_event(data);
>  }
>  
> +static void gpio_handle_button_event(struct gpio_keys_button *button,
> +				     struct gpio_button_data *bdata)
> +{
> +	if (button->debounce_interval)
> +		mod_timer(&bdata->timer,
> +			jiffies + msecs_to_jiffies(button->debounce_interval));
> +	else
> +		gpio_keys_report_event(bdata);
> +}
> +
> +static void gpio_keys_poll(struct input_polled_dev *dev)
> +{
> +	struct gpio_keys_drvdata *ddata = dev->private;
> +	struct gpio_keys_platform_data *pdata = ddata->pdata;
> +	int i;
> +
> +	for (i = 0; i < pdata->nbuttons; i++) {
> +		struct gpio_keys_button *button = &pdata->buttons[i];
> +		struct gpio_button_data *bdata = &ddata->data[i];
> +
> +		bdata->input = dev->input;
> +		bdata->button = button;
> +
> +		gpio_handle_button_event(button, bdata);
> +	}
> +}
> +
>  static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
>  {
>  	struct gpio_button_data *bdata = dev_id;
> @@ -61,11 +89,7 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
>  
>  	BUG_ON(irq != gpio_to_irq(button->gpio));
>  
> -	if (button->debounce_interval)
> -		mod_timer(&bdata->timer,
> -			jiffies + msecs_to_jiffies(button->debounce_interval));
> -	else
> -		gpio_keys_report_event(bdata);
> +	gpio_handle_button_event(button, bdata);
>  
>  	return IRQ_HANDLED;
>  }
> @@ -74,6 +98,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  {
>  	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
>  	struct gpio_keys_drvdata *ddata;
> +	struct input_polled_dev *poll_dev;
>  	struct input_dev *input;
>  	int i, error;
>  	int wakeup = 0;
> @@ -81,14 +106,19 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
>  			pdata->nbuttons * sizeof(struct gpio_button_data),
>  			GFP_KERNEL);
> -	input = input_allocate_device();
> -	if (!ddata || !input) {
> +	poll_dev = input_allocate_polled_device();
> +	if (!ddata || !poll_dev) {
>  		error = -ENOMEM;
>  		goto fail1;
>  	}
>  
>  	platform_set_drvdata(pdev, ddata);
>  
> +	poll_dev->private = ddata;
> +	poll_dev->poll = gpio_keys_poll;
> +	poll_dev->poll_interval = 50; /* msec */
> +
> +	input = poll_dev->input;
>  	input->name = pdev->name;
>  	input->phys = "gpio-keys/input0";
>  	input->dev.parent = &pdev->dev;
> @@ -98,7 +128,8 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  	input->id.product = 0x0001;
>  	input->id.version = 0x0100;
>  
> -	ddata->input = input;
> +	ddata->poll_dev = poll_dev;
> +	ddata->pdata = pdata;
>  
>  	for (i = 0; i < pdata->nbuttons; i++) {
>  		struct gpio_keys_button *button = &pdata->buttons[i];
> @@ -127,6 +158,15 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  			goto fail2;
>  		}
>  
> +		input_set_capability(input, type, button->code);
> +
> +		/*
> +		 * Skip the IRQ setup and wakeup source initialization if
> +		 * we are going to be polled.
> +		 */
> +		if (pdata->polling)
> +			continue;
> +
>  		irq = gpio_to_irq(button->gpio);
>  		if (irq < 0) {
>  			error = irq;
> @@ -151,11 +191,12 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  
>  		if (button->wakeup)
>  			wakeup = 1;
> -
> -		input_set_capability(input, type, button->code);
>  	}
>  
> -	error = input_register_device(input);
> +	if (pdata->polling)
> +		error = input_register_polled_device(poll_dev);
> +	else
> +		error = input_register_device(input);
>  	if (error) {
>  		pr_err("gpio-keys: Unable to register input device, "
>  			"error: %d\n", error);
> @@ -168,7 +209,9 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  
>   fail2:
>  	while (--i >= 0) {
> -		free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
> +		if (!pdata->polling)
> +			free_irq(gpio_to_irq(pdata->buttons[i].gpio),
> +				 &ddata->data[i]);
>  		if (pdata->buttons[i].debounce_interval)
>  			del_timer_sync(&ddata->data[i].timer);
>  		gpio_free(pdata->buttons[i].gpio);
> @@ -176,7 +219,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  
>  	platform_set_drvdata(pdev, NULL);
>   fail1:
> -	input_free_device(input);
> +	input_free_polled_device(poll_dev);
>  	kfree(ddata);
>  
>  	return error;
> @@ -186,20 +229,26 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
>  {
>  	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
>  	struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
> -	struct input_dev *input = ddata->input;
> +	struct input_polled_dev *poll_dev = ddata->poll_dev;
>  	int i;
>  
>  	device_init_wakeup(&pdev->dev, 0);
>  
>  	for (i = 0; i < pdata->nbuttons; i++) {
> -		int irq = gpio_to_irq(pdata->buttons[i].gpio);
> -		free_irq(irq, &ddata->data[i]);
> +		if (!pdata->polling) {
> +			int irq = gpio_to_irq(pdata->buttons[i].gpio);
> +			free_irq(irq, &ddata->data[i]);
> +		}
> +
>  		if (pdata->buttons[i].debounce_interval)
>  			del_timer_sync(&ddata->data[i].timer);
>  		gpio_free(pdata->buttons[i].gpio);
>  	}
>  
> -	input_unregister_device(input);
> +	if (pdata->polling)
> +		input_unregister_polled_device(poll_dev);
> +	else
> +		input_unregister_device(poll_dev->input);
>  
>  	return 0;
>  }
> diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
> index ec6ecd7..e869752 100644
> --- a/include/linux/gpio_keys.h
> +++ b/include/linux/gpio_keys.h
> @@ -15,6 +15,7 @@ struct gpio_keys_button {
>  struct gpio_keys_platform_data {
>  	struct gpio_keys_button *buttons;
>  	int nbuttons;
> +	int polling;		/* force polling mode */
>  };
>  
>  #endif

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

* Re: [PATCH] input: gpio_keys: Polling mode support.
  2008-10-28 10:18 ` Paul Mundt
@ 2008-10-29  3:51   ` Dmitry Torokhov
  2008-11-25 20:43     ` Paul Mundt
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry Torokhov @ 2008-10-29  3:51 UTC (permalink / raw)
  To: Paul Mundt, linux-input, linux-sh

Hi Paul,

On Tue, Oct 28, 2008 at 07:18:57PM +0900, Paul Mundt wrote:
> Ping.
> 
> On Tue, Oct 21, 2008 at 05:38:16PM +0900, Paul Mundt wrote:
> > This implements an optional polling mode for the gpio_keys driver,
> > necessary for GPIOs that are not able to generate IRQs.
> > 
> > Polling mode is done device granular, and can not be toggled for
> > individual GPIOs in order to maintain simplicity. Platforms with both
> > IRQ capable and incapable GPIOs are required to register multiple
> > times, once for each case.
> > 
> >  
> > -	input_unregister_device(input);
> > +	if (pdata->polling)
> > +		input_unregister_polled_device(poll_dev);

You also need to do input_free_polled_device (but not input_free_device
 - yeah, I know, its confusing... The reason is that input_dev is
   refcounted while input_polled_dev is not).
> > +	else
> > +		input_unregister_device(poll_dev->input);
> >  

I also concerned with unconditionally polling INPUT_POLLDEV for all
users of gpio-keys. Maybe we could make polling support optional?

-- 
Dmitry

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

* Re: [PATCH] input: gpio_keys: Polling mode support.
  2008-10-29  3:51   ` Dmitry Torokhov
@ 2008-11-25 20:43     ` Paul Mundt
  2008-12-08  3:32       ` Paul Mundt
  0 siblings, 1 reply; 17+ messages in thread
From: Paul Mundt @ 2008-11-25 20:43 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-sh

On Tue, Oct 28, 2008 at 11:51:23PM -0400, Dmitry Torokhov wrote:
> On Tue, Oct 28, 2008 at 07:18:57PM +0900, Paul Mundt wrote:
> > On Tue, Oct 21, 2008 at 05:38:16PM +0900, Paul Mundt wrote:
> > > This implements an optional polling mode for the gpio_keys driver,
> > > necessary for GPIOs that are not able to generate IRQs.
> > > 
> > > Polling mode is done device granular, and can not be toggled for
> > > individual GPIOs in order to maintain simplicity. Platforms with both
> > > IRQ capable and incapable GPIOs are required to register multiple
> > > times, once for each case.
> > > 
> > >  
> > > -	input_unregister_device(input);
> > > +	if (pdata->polling)
> > > +		input_unregister_polled_device(poll_dev);
> 
> You also need to do input_free_polled_device (but not input_free_device
>  - yeah, I know, its confusing... The reason is that input_dev is
>    refcounted while input_polled_dev is not).

Thanks, fixed.

> > > +	else
> > > +		input_unregister_device(poll_dev->input);
> > >  
> 
> I also concerned with unconditionally polling INPUT_POLLDEV for all
> users of gpio-keys. Maybe we could make polling support optional?
> 
I thought that was what my patch was doing? I couldn't think of a clean
way to do it on a per-gpio basis, so the cleanest way seemed to be to
regster in polled and non-polled blocks. ie, polled devices will set
pdata->polling and register those for gpio_keys to set up a polled dev.
Devices that do not set pdata->polling will remain unaffected.

If you have some suggestions on how to toggle this on a per-gpio basis,
I am quite happy to change the code. If your concern is the select of
INPUT_POLLDEV, I can just select it from my platform code if you prefer.
This does mean that we would need nopped definitions in
linux/input-polldev.h though, or litter gpio_keys with ifdefs, which is
what I was trying to avoid in the first place. Let me know what you
prefer here, and I'll update accordingly.

For now, here is an updated version..

Signed-off-by: Paul Mundt <lethal@linux-sh.org>

---

 drivers/input/keyboard/Kconfig     |    1 
 drivers/input/keyboard/gpio_keys.c |   92 ++++++++++++++++++++++++++++---------
 include/linux/gpio_keys.h          |    1 
 3 files changed, 73 insertions(+), 21 deletions(-)

diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index efd70a9..a8cefe9 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -283,6 +283,7 @@ config KEYBOARD_AAED2000
 config KEYBOARD_GPIO
 	tristate "GPIO Buttons"
 	depends on GENERIC_GPIO
+	select INPUT_POLLDEV
 	help
 	  This driver implements support for buttons connected
 	  to GPIO pins of various CPUs (and some other chips).
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 05f3f43..e7a46f8 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -1,7 +1,8 @@
 /*
- * Driver for keys on GPIO lines capable of generating interrupts.
+ * Driver for keys on GPIO lines, either IRQ-driven or polled.
  *
  * Copyright 2005 Phil Blundell
+ * Copyright 2008 Paul Mundt
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -9,7 +10,6 @@
  */
 
 #include <linux/module.h>
-
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <linux/interrupt.h>
@@ -22,7 +22,7 @@
 #include <linux/platform_device.h>
 #include <linux/input.h>
 #include <linux/gpio_keys.h>
-
+#include <linux/input-polldev.h>
 #include <asm/gpio.h>
 
 struct gpio_button_data {
@@ -32,7 +32,8 @@ struct gpio_button_data {
 };
 
 struct gpio_keys_drvdata {
-	struct input_dev *input;
+	struct gpio_keys_platform_data *pdata;
+	struct input_polled_dev *poll_dev;
 	struct gpio_button_data data[0];
 };
 
@@ -54,6 +55,33 @@ static void gpio_check_button(unsigned long _data)
 	gpio_keys_report_event(data);
 }
 
+static void gpio_handle_button_event(struct gpio_keys_button *button,
+				     struct gpio_button_data *bdata)
+{
+	if (button->debounce_interval)
+		mod_timer(&bdata->timer,
+			jiffies + msecs_to_jiffies(button->debounce_interval));
+	else
+		gpio_keys_report_event(bdata);
+}
+
+static void gpio_keys_poll(struct input_polled_dev *dev)
+{
+	struct gpio_keys_drvdata *ddata = dev->private;
+	struct gpio_keys_platform_data *pdata = ddata->pdata;
+	int i;
+
+	for (i = 0; i < pdata->nbuttons; i++) {
+		struct gpio_keys_button *button = &pdata->buttons[i];
+		struct gpio_button_data *bdata = &ddata->data[i];
+
+		bdata->input = dev->input;
+		bdata->button = button;
+
+		gpio_handle_button_event(button, bdata);
+	}
+}
+
 static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
 {
 	struct gpio_button_data *bdata = dev_id;
@@ -61,11 +89,7 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
 
 	BUG_ON(irq != gpio_to_irq(button->gpio));
 
-	if (button->debounce_interval)
-		mod_timer(&bdata->timer,
-			jiffies + msecs_to_jiffies(button->debounce_interval));
-	else
-		gpio_keys_report_event(bdata);
+	gpio_handle_button_event(button, bdata);
 
 	return IRQ_HANDLED;
 }
@@ -74,6 +98,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 {
 	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
 	struct gpio_keys_drvdata *ddata;
+	struct input_polled_dev *poll_dev;
 	struct input_dev *input;
 	int i, error;
 	int wakeup = 0;
@@ -81,14 +106,19 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
 			pdata->nbuttons * sizeof(struct gpio_button_data),
 			GFP_KERNEL);
-	input = input_allocate_device();
-	if (!ddata || !input) {
+	poll_dev = input_allocate_polled_device();
+	if (!ddata || !poll_dev) {
 		error = -ENOMEM;
 		goto fail1;
 	}
 
 	platform_set_drvdata(pdev, ddata);
 
+	poll_dev->private = ddata;
+	poll_dev->poll = gpio_keys_poll;
+	poll_dev->poll_interval = 50; /* msec */
+
+	input = poll_dev->input;
 	input->name = pdev->name;
 	input->phys = "gpio-keys/input0";
 	input->dev.parent = &pdev->dev;
@@ -98,7 +128,8 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 	input->id.product = 0x0001;
 	input->id.version = 0x0100;
 
-	ddata->input = input;
+	ddata->poll_dev = poll_dev;
+	ddata->pdata = pdata;
 
 	for (i = 0; i < pdata->nbuttons; i++) {
 		struct gpio_keys_button *button = &pdata->buttons[i];
@@ -127,6 +158,15 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 			goto fail2;
 		}
 
+		input_set_capability(input, type, button->code);
+
+		/*
+		 * Skip the IRQ setup and wakeup source initialization if
+		 * we are going to be polled.
+		 */
+		if (pdata->polling)
+			continue;
+
 		irq = gpio_to_irq(button->gpio);
 		if (irq < 0) {
 			error = irq;
@@ -151,11 +191,12 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 
 		if (button->wakeup)
 			wakeup = 1;
-
-		input_set_capability(input, type, button->code);
 	}
 
-	error = input_register_device(input);
+	if (pdata->polling)
+		error = input_register_polled_device(poll_dev);
+	else
+		error = input_register_device(input);
 	if (error) {
 		pr_err("gpio-keys: Unable to register input device, "
 			"error: %d\n", error);
@@ -168,7 +209,9 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 
  fail2:
 	while (--i >= 0) {
-		free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
+		if (!pdata->polling)
+			free_irq(gpio_to_irq(pdata->buttons[i].gpio),
+				 &ddata->data[i]);
 		if (pdata->buttons[i].debounce_interval)
 			del_timer_sync(&ddata->data[i].timer);
 		gpio_free(pdata->buttons[i].gpio);
@@ -176,7 +219,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, NULL);
  fail1:
-	input_free_device(input);
+	input_free_polled_device(poll_dev);
 	kfree(ddata);
 
 	return error;
@@ -186,20 +229,27 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
 {
 	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
 	struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
-	struct input_dev *input = ddata->input;
+	struct input_polled_dev *poll_dev = ddata->poll_dev;
 	int i;
 
 	device_init_wakeup(&pdev->dev, 0);
 
 	for (i = 0; i < pdata->nbuttons; i++) {
-		int irq = gpio_to_irq(pdata->buttons[i].gpio);
-		free_irq(irq, &ddata->data[i]);
+		if (!pdata->polling) {
+			int irq = gpio_to_irq(pdata->buttons[i].gpio);
+			free_irq(irq, &ddata->data[i]);
+		}
+
 		if (pdata->buttons[i].debounce_interval)
 			del_timer_sync(&ddata->data[i].timer);
 		gpio_free(pdata->buttons[i].gpio);
 	}
 
-	input_unregister_device(input);
+	if (pdata->polling) {
+		input_unregister_polled_device(poll_dev);
+		input_free_polled_device(poll_dev);
+	} else
+		input_unregister_device(poll_dev->input);
 
 	return 0;
 }
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
index ec6ecd7..e869752 100644
--- a/include/linux/gpio_keys.h
+++ b/include/linux/gpio_keys.h
@@ -15,6 +15,7 @@ struct gpio_keys_button {
 struct gpio_keys_platform_data {
 	struct gpio_keys_button *buttons;
 	int nbuttons;
+	int polling;		/* force polling mode */
 };
 
 #endif

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

* Re: [PATCH] input: gpio_keys: Polling mode support.
  2008-11-25 20:43     ` Paul Mundt
@ 2008-12-08  3:32       ` Paul Mundt
  2008-12-24  1:47         ` Paul Mundt
  0 siblings, 1 reply; 17+ messages in thread
From: Paul Mundt @ 2008-12-08  3:32 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, linux-sh

Ping.

On Wed, Nov 26, 2008 at 05:43:58AM +0900, Paul Mundt wrote:
> On Tue, Oct 28, 2008 at 11:51:23PM -0400, Dmitry Torokhov wrote:
> > On Tue, Oct 28, 2008 at 07:18:57PM +0900, Paul Mundt wrote:
> > > On Tue, Oct 21, 2008 at 05:38:16PM +0900, Paul Mundt wrote:
> > > > This implements an optional polling mode for the gpio_keys driver,
> > > > necessary for GPIOs that are not able to generate IRQs.
> > > > 
> > > > Polling mode is done device granular, and can not be toggled for
> > > > individual GPIOs in order to maintain simplicity. Platforms with both
> > > > IRQ capable and incapable GPIOs are required to register multiple
> > > > times, once for each case.
> > > > 
> > > >  
> > > > -	input_unregister_device(input);
> > > > +	if (pdata->polling)
> > > > +		input_unregister_polled_device(poll_dev);
> > 
> > You also need to do input_free_polled_device (but not input_free_device
> >  - yeah, I know, its confusing... The reason is that input_dev is
> >    refcounted while input_polled_dev is not).
> 
> Thanks, fixed.
> 
> > > > +	else
> > > > +		input_unregister_device(poll_dev->input);
> > > >  
> > 
> > I also concerned with unconditionally polling INPUT_POLLDEV for all
> > users of gpio-keys. Maybe we could make polling support optional?
> > 
> I thought that was what my patch was doing? I couldn't think of a clean
> way to do it on a per-gpio basis, so the cleanest way seemed to be to
> regster in polled and non-polled blocks. ie, polled devices will set
> pdata->polling and register those for gpio_keys to set up a polled dev.
> Devices that do not set pdata->polling will remain unaffected.
> 
> If you have some suggestions on how to toggle this on a per-gpio basis,
> I am quite happy to change the code. If your concern is the select of
> INPUT_POLLDEV, I can just select it from my platform code if you prefer.
> This does mean that we would need nopped definitions in
> linux/input-polldev.h though, or litter gpio_keys with ifdefs, which is
> what I was trying to avoid in the first place. Let me know what you
> prefer here, and I'll update accordingly.
> 
> For now, here is an updated version..
> 
> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
> 
> ---
> 
>  drivers/input/keyboard/Kconfig     |    1 
>  drivers/input/keyboard/gpio_keys.c |   92 ++++++++++++++++++++++++++++---------
>  include/linux/gpio_keys.h          |    1 
>  3 files changed, 73 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> index efd70a9..a8cefe9 100644
> --- a/drivers/input/keyboard/Kconfig
> +++ b/drivers/input/keyboard/Kconfig
> @@ -283,6 +283,7 @@ config KEYBOARD_AAED2000
>  config KEYBOARD_GPIO
>  	tristate "GPIO Buttons"
>  	depends on GENERIC_GPIO
> +	select INPUT_POLLDEV
>  	help
>  	  This driver implements support for buttons connected
>  	  to GPIO pins of various CPUs (and some other chips).
> diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
> index 05f3f43..e7a46f8 100644
> --- a/drivers/input/keyboard/gpio_keys.c
> +++ b/drivers/input/keyboard/gpio_keys.c
> @@ -1,7 +1,8 @@
>  /*
> - * Driver for keys on GPIO lines capable of generating interrupts.
> + * Driver for keys on GPIO lines, either IRQ-driven or polled.
>   *
>   * Copyright 2005 Phil Blundell
> + * Copyright 2008 Paul Mundt
>   *
>   * This program is free software; you can redistribute it and/or modify
>   * it under the terms of the GNU General Public License version 2 as
> @@ -9,7 +10,6 @@
>   */
>  
>  #include <linux/module.h>
> -
>  #include <linux/init.h>
>  #include <linux/fs.h>
>  #include <linux/interrupt.h>
> @@ -22,7 +22,7 @@
>  #include <linux/platform_device.h>
>  #include <linux/input.h>
>  #include <linux/gpio_keys.h>
> -
> +#include <linux/input-polldev.h>
>  #include <asm/gpio.h>
>  
>  struct gpio_button_data {
> @@ -32,7 +32,8 @@ struct gpio_button_data {
>  };
>  
>  struct gpio_keys_drvdata {
> -	struct input_dev *input;
> +	struct gpio_keys_platform_data *pdata;
> +	struct input_polled_dev *poll_dev;
>  	struct gpio_button_data data[0];
>  };
>  
> @@ -54,6 +55,33 @@ static void gpio_check_button(unsigned long _data)
>  	gpio_keys_report_event(data);
>  }
>  
> +static void gpio_handle_button_event(struct gpio_keys_button *button,
> +				     struct gpio_button_data *bdata)
> +{
> +	if (button->debounce_interval)
> +		mod_timer(&bdata->timer,
> +			jiffies + msecs_to_jiffies(button->debounce_interval));
> +	else
> +		gpio_keys_report_event(bdata);
> +}
> +
> +static void gpio_keys_poll(struct input_polled_dev *dev)
> +{
> +	struct gpio_keys_drvdata *ddata = dev->private;
> +	struct gpio_keys_platform_data *pdata = ddata->pdata;
> +	int i;
> +
> +	for (i = 0; i < pdata->nbuttons; i++) {
> +		struct gpio_keys_button *button = &pdata->buttons[i];
> +		struct gpio_button_data *bdata = &ddata->data[i];
> +
> +		bdata->input = dev->input;
> +		bdata->button = button;
> +
> +		gpio_handle_button_event(button, bdata);
> +	}
> +}
> +
>  static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
>  {
>  	struct gpio_button_data *bdata = dev_id;
> @@ -61,11 +89,7 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
>  
>  	BUG_ON(irq != gpio_to_irq(button->gpio));
>  
> -	if (button->debounce_interval)
> -		mod_timer(&bdata->timer,
> -			jiffies + msecs_to_jiffies(button->debounce_interval));
> -	else
> -		gpio_keys_report_event(bdata);
> +	gpio_handle_button_event(button, bdata);
>  
>  	return IRQ_HANDLED;
>  }
> @@ -74,6 +98,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  {
>  	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
>  	struct gpio_keys_drvdata *ddata;
> +	struct input_polled_dev *poll_dev;
>  	struct input_dev *input;
>  	int i, error;
>  	int wakeup = 0;
> @@ -81,14 +106,19 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
>  			pdata->nbuttons * sizeof(struct gpio_button_data),
>  			GFP_KERNEL);
> -	input = input_allocate_device();
> -	if (!ddata || !input) {
> +	poll_dev = input_allocate_polled_device();
> +	if (!ddata || !poll_dev) {
>  		error = -ENOMEM;
>  		goto fail1;
>  	}
>  
>  	platform_set_drvdata(pdev, ddata);
>  
> +	poll_dev->private = ddata;
> +	poll_dev->poll = gpio_keys_poll;
> +	poll_dev->poll_interval = 50; /* msec */
> +
> +	input = poll_dev->input;
>  	input->name = pdev->name;
>  	input->phys = "gpio-keys/input0";
>  	input->dev.parent = &pdev->dev;
> @@ -98,7 +128,8 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  	input->id.product = 0x0001;
>  	input->id.version = 0x0100;
>  
> -	ddata->input = input;
> +	ddata->poll_dev = poll_dev;
> +	ddata->pdata = pdata;
>  
>  	for (i = 0; i < pdata->nbuttons; i++) {
>  		struct gpio_keys_button *button = &pdata->buttons[i];
> @@ -127,6 +158,15 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  			goto fail2;
>  		}
>  
> +		input_set_capability(input, type, button->code);
> +
> +		/*
> +		 * Skip the IRQ setup and wakeup source initialization if
> +		 * we are going to be polled.
> +		 */
> +		if (pdata->polling)
> +			continue;
> +
>  		irq = gpio_to_irq(button->gpio);
>  		if (irq < 0) {
>  			error = irq;
> @@ -151,11 +191,12 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  
>  		if (button->wakeup)
>  			wakeup = 1;
> -
> -		input_set_capability(input, type, button->code);
>  	}
>  
> -	error = input_register_device(input);
> +	if (pdata->polling)
> +		error = input_register_polled_device(poll_dev);
> +	else
> +		error = input_register_device(input);
>  	if (error) {
>  		pr_err("gpio-keys: Unable to register input device, "
>  			"error: %d\n", error);
> @@ -168,7 +209,9 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  
>   fail2:
>  	while (--i >= 0) {
> -		free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
> +		if (!pdata->polling)
> +			free_irq(gpio_to_irq(pdata->buttons[i].gpio),
> +				 &ddata->data[i]);
>  		if (pdata->buttons[i].debounce_interval)
>  			del_timer_sync(&ddata->data[i].timer);
>  		gpio_free(pdata->buttons[i].gpio);
> @@ -176,7 +219,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  
>  	platform_set_drvdata(pdev, NULL);
>   fail1:
> -	input_free_device(input);
> +	input_free_polled_device(poll_dev);
>  	kfree(ddata);
>  
>  	return error;
> @@ -186,20 +229,27 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
>  {
>  	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
>  	struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
> -	struct input_dev *input = ddata->input;
> +	struct input_polled_dev *poll_dev = ddata->poll_dev;
>  	int i;
>  
>  	device_init_wakeup(&pdev->dev, 0);
>  
>  	for (i = 0; i < pdata->nbuttons; i++) {
> -		int irq = gpio_to_irq(pdata->buttons[i].gpio);
> -		free_irq(irq, &ddata->data[i]);
> +		if (!pdata->polling) {
> +			int irq = gpio_to_irq(pdata->buttons[i].gpio);
> +			free_irq(irq, &ddata->data[i]);
> +		}
> +
>  		if (pdata->buttons[i].debounce_interval)
>  			del_timer_sync(&ddata->data[i].timer);
>  		gpio_free(pdata->buttons[i].gpio);
>  	}
>  
> -	input_unregister_device(input);
> +	if (pdata->polling) {
> +		input_unregister_polled_device(poll_dev);
> +		input_free_polled_device(poll_dev);
> +	} else
> +		input_unregister_device(poll_dev->input);
>  
>  	return 0;
>  }
> diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
> index ec6ecd7..e869752 100644
> --- a/include/linux/gpio_keys.h
> +++ b/include/linux/gpio_keys.h
> @@ -15,6 +15,7 @@ struct gpio_keys_button {
>  struct gpio_keys_platform_data {
>  	struct gpio_keys_button *buttons;
>  	int nbuttons;
> +	int polling;		/* force polling mode */
>  };
>  
>  #endif

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

* Re: [PATCH] input: gpio_keys: Polling mode support.
  2008-12-08  3:32       ` Paul Mundt
@ 2008-12-24  1:47         ` Paul Mundt
  0 siblings, 0 replies; 17+ messages in thread
From: Paul Mundt @ 2008-12-24  1:47 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input, linux-sh

Re-ping.

On Mon, Dec 08, 2008 at 12:32:22PM +0900, Paul Mundt wrote:
> Ping.
> 
> On Wed, Nov 26, 2008 at 05:43:58AM +0900, Paul Mundt wrote:
> > On Tue, Oct 28, 2008 at 11:51:23PM -0400, Dmitry Torokhov wrote:
> > > On Tue, Oct 28, 2008 at 07:18:57PM +0900, Paul Mundt wrote:
> > > > On Tue, Oct 21, 2008 at 05:38:16PM +0900, Paul Mundt wrote:
> > > > > This implements an optional polling mode for the gpio_keys driver,
> > > > > necessary for GPIOs that are not able to generate IRQs.
> > > > > 
> > > > > Polling mode is done device granular, and can not be toggled for
> > > > > individual GPIOs in order to maintain simplicity. Platforms with both
> > > > > IRQ capable and incapable GPIOs are required to register multiple
> > > > > times, once for each case.
> > > > > 
> > > > >  
> > > > > -	input_unregister_device(input);
> > > > > +	if (pdata->polling)
> > > > > +		input_unregister_polled_device(poll_dev);
> > > 
> > > You also need to do input_free_polled_device (but not input_free_device
> > >  - yeah, I know, its confusing... The reason is that input_dev is
> > >    refcounted while input_polled_dev is not).
> > 
> > Thanks, fixed.
> > 
> > > > > +	else
> > > > > +		input_unregister_device(poll_dev->input);
> > > > >  
> > > 
> > > I also concerned with unconditionally polling INPUT_POLLDEV for all
> > > users of gpio-keys. Maybe we could make polling support optional?
> > > 
> > I thought that was what my patch was doing? I couldn't think of a clean
> > way to do it on a per-gpio basis, so the cleanest way seemed to be to
> > regster in polled and non-polled blocks. ie, polled devices will set
> > pdata->polling and register those for gpio_keys to set up a polled dev.
> > Devices that do not set pdata->polling will remain unaffected.
> > 
> > If you have some suggestions on how to toggle this on a per-gpio basis,
> > I am quite happy to change the code. If your concern is the select of
> > INPUT_POLLDEV, I can just select it from my platform code if you prefer.
> > This does mean that we would need nopped definitions in
> > linux/input-polldev.h though, or litter gpio_keys with ifdefs, which is
> > what I was trying to avoid in the first place. Let me know what you
> > prefer here, and I'll update accordingly.
> > 
> > For now, here is an updated version..
> > 
> > Signed-off-by: Paul Mundt <lethal@linux-sh.org>
> > 
> > ---
> > 
> >  drivers/input/keyboard/Kconfig     |    1 
> >  drivers/input/keyboard/gpio_keys.c |   92 ++++++++++++++++++++++++++++---------
> >  include/linux/gpio_keys.h          |    1 
> >  3 files changed, 73 insertions(+), 21 deletions(-)
> > 
> > diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
> > index efd70a9..a8cefe9 100644
> > --- a/drivers/input/keyboard/Kconfig
> > +++ b/drivers/input/keyboard/Kconfig
> > @@ -283,6 +283,7 @@ config KEYBOARD_AAED2000
> >  config KEYBOARD_GPIO
> >  	tristate "GPIO Buttons"
> >  	depends on GENERIC_GPIO
> > +	select INPUT_POLLDEV
> >  	help
> >  	  This driver implements support for buttons connected
> >  	  to GPIO pins of various CPUs (and some other chips).
> > diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
> > index 05f3f43..e7a46f8 100644
> > --- a/drivers/input/keyboard/gpio_keys.c
> > +++ b/drivers/input/keyboard/gpio_keys.c
> > @@ -1,7 +1,8 @@
> >  /*
> > - * Driver for keys on GPIO lines capable of generating interrupts.
> > + * Driver for keys on GPIO lines, either IRQ-driven or polled.
> >   *
> >   * Copyright 2005 Phil Blundell
> > + * Copyright 2008 Paul Mundt
> >   *
> >   * This program is free software; you can redistribute it and/or modify
> >   * it under the terms of the GNU General Public License version 2 as
> > @@ -9,7 +10,6 @@
> >   */
> >  
> >  #include <linux/module.h>
> > -
> >  #include <linux/init.h>
> >  #include <linux/fs.h>
> >  #include <linux/interrupt.h>
> > @@ -22,7 +22,7 @@
> >  #include <linux/platform_device.h>
> >  #include <linux/input.h>
> >  #include <linux/gpio_keys.h>
> > -
> > +#include <linux/input-polldev.h>
> >  #include <asm/gpio.h>
> >  
> >  struct gpio_button_data {
> > @@ -32,7 +32,8 @@ struct gpio_button_data {
> >  };
> >  
> >  struct gpio_keys_drvdata {
> > -	struct input_dev *input;
> > +	struct gpio_keys_platform_data *pdata;
> > +	struct input_polled_dev *poll_dev;
> >  	struct gpio_button_data data[0];
> >  };
> >  
> > @@ -54,6 +55,33 @@ static void gpio_check_button(unsigned long _data)
> >  	gpio_keys_report_event(data);
> >  }
> >  
> > +static void gpio_handle_button_event(struct gpio_keys_button *button,
> > +				     struct gpio_button_data *bdata)
> > +{
> > +	if (button->debounce_interval)
> > +		mod_timer(&bdata->timer,
> > +			jiffies + msecs_to_jiffies(button->debounce_interval));
> > +	else
> > +		gpio_keys_report_event(bdata);
> > +}
> > +
> > +static void gpio_keys_poll(struct input_polled_dev *dev)
> > +{
> > +	struct gpio_keys_drvdata *ddata = dev->private;
> > +	struct gpio_keys_platform_data *pdata = ddata->pdata;
> > +	int i;
> > +
> > +	for (i = 0; i < pdata->nbuttons; i++) {
> > +		struct gpio_keys_button *button = &pdata->buttons[i];
> > +		struct gpio_button_data *bdata = &ddata->data[i];
> > +
> > +		bdata->input = dev->input;
> > +		bdata->button = button;
> > +
> > +		gpio_handle_button_event(button, bdata);
> > +	}
> > +}
> > +
> >  static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
> >  {
> >  	struct gpio_button_data *bdata = dev_id;
> > @@ -61,11 +89,7 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
> >  
> >  	BUG_ON(irq != gpio_to_irq(button->gpio));
> >  
> > -	if (button->debounce_interval)
> > -		mod_timer(&bdata->timer,
> > -			jiffies + msecs_to_jiffies(button->debounce_interval));
> > -	else
> > -		gpio_keys_report_event(bdata);
> > +	gpio_handle_button_event(button, bdata);
> >  
> >  	return IRQ_HANDLED;
> >  }
> > @@ -74,6 +98,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
> >  {
> >  	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
> >  	struct gpio_keys_drvdata *ddata;
> > +	struct input_polled_dev *poll_dev;
> >  	struct input_dev *input;
> >  	int i, error;
> >  	int wakeup = 0;
> > @@ -81,14 +106,19 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
> >  	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
> >  			pdata->nbuttons * sizeof(struct gpio_button_data),
> >  			GFP_KERNEL);
> > -	input = input_allocate_device();
> > -	if (!ddata || !input) {
> > +	poll_dev = input_allocate_polled_device();
> > +	if (!ddata || !poll_dev) {
> >  		error = -ENOMEM;
> >  		goto fail1;
> >  	}
> >  
> >  	platform_set_drvdata(pdev, ddata);
> >  
> > +	poll_dev->private = ddata;
> > +	poll_dev->poll = gpio_keys_poll;
> > +	poll_dev->poll_interval = 50; /* msec */
> > +
> > +	input = poll_dev->input;
> >  	input->name = pdev->name;
> >  	input->phys = "gpio-keys/input0";
> >  	input->dev.parent = &pdev->dev;
> > @@ -98,7 +128,8 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
> >  	input->id.product = 0x0001;
> >  	input->id.version = 0x0100;
> >  
> > -	ddata->input = input;
> > +	ddata->poll_dev = poll_dev;
> > +	ddata->pdata = pdata;
> >  
> >  	for (i = 0; i < pdata->nbuttons; i++) {
> >  		struct gpio_keys_button *button = &pdata->buttons[i];
> > @@ -127,6 +158,15 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
> >  			goto fail2;
> >  		}
> >  
> > +		input_set_capability(input, type, button->code);
> > +
> > +		/*
> > +		 * Skip the IRQ setup and wakeup source initialization if
> > +		 * we are going to be polled.
> > +		 */
> > +		if (pdata->polling)
> > +			continue;
> > +
> >  		irq = gpio_to_irq(button->gpio);
> >  		if (irq < 0) {
> >  			error = irq;
> > @@ -151,11 +191,12 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
> >  
> >  		if (button->wakeup)
> >  			wakeup = 1;
> > -
> > -		input_set_capability(input, type, button->code);
> >  	}
> >  
> > -	error = input_register_device(input);
> > +	if (pdata->polling)
> > +		error = input_register_polled_device(poll_dev);
> > +	else
> > +		error = input_register_device(input);
> >  	if (error) {
> >  		pr_err("gpio-keys: Unable to register input device, "
> >  			"error: %d\n", error);
> > @@ -168,7 +209,9 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
> >  
> >   fail2:
> >  	while (--i >= 0) {
> > -		free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
> > +		if (!pdata->polling)
> > +			free_irq(gpio_to_irq(pdata->buttons[i].gpio),
> > +				 &ddata->data[i]);
> >  		if (pdata->buttons[i].debounce_interval)
> >  			del_timer_sync(&ddata->data[i].timer);
> >  		gpio_free(pdata->buttons[i].gpio);
> > @@ -176,7 +219,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
> >  
> >  	platform_set_drvdata(pdev, NULL);
> >   fail1:
> > -	input_free_device(input);
> > +	input_free_polled_device(poll_dev);
> >  	kfree(ddata);
> >  
> >  	return error;
> > @@ -186,20 +229,27 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
> >  {
> >  	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
> >  	struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
> > -	struct input_dev *input = ddata->input;
> > +	struct input_polled_dev *poll_dev = ddata->poll_dev;
> >  	int i;
> >  
> >  	device_init_wakeup(&pdev->dev, 0);
> >  
> >  	for (i = 0; i < pdata->nbuttons; i++) {
> > -		int irq = gpio_to_irq(pdata->buttons[i].gpio);
> > -		free_irq(irq, &ddata->data[i]);
> > +		if (!pdata->polling) {
> > +			int irq = gpio_to_irq(pdata->buttons[i].gpio);
> > +			free_irq(irq, &ddata->data[i]);
> > +		}
> > +
> >  		if (pdata->buttons[i].debounce_interval)
> >  			del_timer_sync(&ddata->data[i].timer);
> >  		gpio_free(pdata->buttons[i].gpio);
> >  	}
> >  
> > -	input_unregister_device(input);
> > +	if (pdata->polling) {
> > +		input_unregister_polled_device(poll_dev);
> > +		input_free_polled_device(poll_dev);
> > +	} else
> > +		input_unregister_device(poll_dev->input);
> >  
> >  	return 0;
> >  }
> > diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
> > index ec6ecd7..e869752 100644
> > --- a/include/linux/gpio_keys.h
> > +++ b/include/linux/gpio_keys.h
> > @@ -15,6 +15,7 @@ struct gpio_keys_button {
> >  struct gpio_keys_platform_data {
> >  	struct gpio_keys_button *buttons;
> >  	int nbuttons;
> > +	int polling;		/* force polling mode */
> >  };
> >  
> >  #endif
> --
> To unsubscribe from this list: send the line "unsubscribe linux-sh" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH] input: gpio_keys: polling mode support
@ 2010-07-06 19:01 Alexander Clouter
  2010-07-08 16:26 ` Alexander Clouter
  2010-07-12 19:29 ` Alexander Clouter
  0 siblings, 2 replies; 17+ messages in thread
From: Alexander Clouter @ 2010-07-06 19:01 UTC (permalink / raw)
  To: linux-input; +Cc: Paul Mundt

This implements an optional polling mode for the gpio_keys driver,
necessary for GPIOs that are not able to generate IRQs.

gpio_keys_platform_data has been extended with poll_interval
which specifies the polling interval in ms, this is passed onto
input-polldev.

This work was based on the patch[1] originally conceived by Paul
Mundt but now the absolute dependency on INPUT_POLLDEV has been
removed (so existing users of gpio_keys can compile out polldev)
plus some un-necessary code has been removed.

N.B. untested on an IRQ driven gpio_keys using platform as I have
	none available to me, but looks like it should still work

[1] http://article.gmane.org/gmane.linux.kernel.input/5814

Signed-off-by: Alexander Clouter <alex@digriz.org.uk>
---
 drivers/input/keyboard/gpio_keys.c |  122 +++++++++++++++++++++++++++++++-----
 include/linux/gpio_keys.h          |    1 +
 2 files changed, 106 insertions(+), 17 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index b8213fd..c790b45 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -1,7 +1,9 @@
 /*
- * Driver for keys on GPIO lines capable of generating interrupts.
+ * Driver for keys on GPIO lines, either IRQ-driven or polled.
  *
  * Copyright 2005 Phil Blundell
+ * Copyright 2008 Paul Mundt
+ * Copyright 2010 Alexander Clouter <alex@digriz.org.uk>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -25,6 +27,7 @@
 #include <linux/gpio_keys.h>
 #include <linux/workqueue.h>
 #include <linux/gpio.h>
+#include <linux/input-polldev.h>
 
 struct gpio_button_data {
 	struct gpio_keys_button *button;
@@ -36,6 +39,9 @@ struct gpio_button_data {
 
 struct gpio_keys_drvdata {
 	struct input_dev *input;
+#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
+	struct input_polled_dev *poll_dev;
+#endif
 	struct mutex disable_lock;
 	unsigned int n_buttons;
 	struct gpio_button_data data[0];
@@ -340,6 +346,16 @@ static void gpio_keys_timer(unsigned long _data)
 	schedule_work(&data->work);
 }
 
+static void gpio_handle_button_event(struct gpio_keys_button *button,
+				     struct gpio_button_data *bdata)
+{
+	if (button->debounce_interval)
+		mod_timer(&bdata->timer,
+			jiffies + msecs_to_jiffies(button->debounce_interval));
+	else
+		gpio_keys_report_event(bdata);
+}
+
 static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
 {
 	struct gpio_button_data *bdata = dev_id;
@@ -347,15 +363,26 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
 
 	BUG_ON(irq != gpio_to_irq(button->gpio));
 
-	if (button->debounce_interval)
-		mod_timer(&bdata->timer,
-			jiffies + msecs_to_jiffies(button->debounce_interval));
-	else
-		schedule_work(&bdata->work);
+	gpio_handle_button_event(button, bdata);
 
 	return IRQ_HANDLED;
 }
 
+#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
+static void gpio_keys_poll(struct input_polled_dev *dev)
+{
+	struct gpio_keys_drvdata *ddata = dev->private;
+	int i;
+
+	for (i = 0; i < ddata->n_buttons; i++) {
+		struct gpio_button_data *bdata = &ddata->data[i];
+		struct gpio_keys_button *button = bdata->button;
+
+		gpio_handle_button_event(button, bdata);
+	}
+}
+#endif
+
 static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
 					 struct gpio_button_data *bdata,
 					 struct gpio_keys_button *button)
@@ -422,23 +449,52 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 	struct input_dev *input;
 	int i, error;
 	int wakeup = 0;
+#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
+	struct input_polled_dev *poll_dev;
+#else
+
+	if (pdata->poll_interval) {
+		dev_err(dev, "device needs polling (enable INPUT_POLLDEV)\n");
+		return -EINVAL;
+	}
+#endif
 
 	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
 			pdata->nbuttons * sizeof(struct gpio_button_data),
 			GFP_KERNEL);
-	input = input_allocate_device();
+#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
+	if (pdata->poll_interval) {
+		poll_dev = input_allocate_polled_device();
+		if (poll_dev)
+			input = poll_dev->input;
+	} else
+#endif
+		input = input_allocate_device();
 	if (!ddata || !input) {
 		dev_err(dev, "failed to allocate state\n");
 		error = -ENOMEM;
 		goto fail1;
 	}
 
-	ddata->input = input;
+#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
+	if (pdata->poll_interval) {
+		ddata->poll_dev = poll_dev;
+	} else
+#endif
+		ddata->input = input;
 	ddata->n_buttons = pdata->nbuttons;
 	mutex_init(&ddata->disable_lock);
 
 	platform_set_drvdata(pdev, ddata);
 
+#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
+	if (pdata->poll_interval) {
+		poll_dev->private = ddata;
+		poll_dev->poll = gpio_keys_poll;
+		poll_dev->poll_interval = pdata->poll_interval;
+	}
+#endif
+
 	input->name = pdev->name;
 	input->phys = "gpio-keys/input0";
 	input->dev.parent = &pdev->dev;
@@ -460,14 +516,17 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 		bdata->input = input;
 		bdata->button = button;
 
+		input_set_capability(input, type, button->code);
+
+		if (pdata->poll_interval)
+			continue;
+
 		error = gpio_keys_setup_key(pdev, bdata, button);
 		if (error)
 			goto fail2;
 
 		if (button->wakeup)
 			wakeup = 1;
-
-		input_set_capability(input, type, button->code);
 	}
 
 	error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group);
@@ -477,7 +536,12 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 		goto fail2;
 	}
 
-	error = input_register_device(input);
+#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
+	if (pdata->poll_interval)
+		error = input_register_polled_device(poll_dev);
+	else
+#endif
+		error = input_register_device(input);
 	if (error) {
 		dev_err(dev, "Unable to register input device, error: %d\n",
 			error);
@@ -497,7 +561,9 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 	sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
  fail2:
 	while (--i >= 0) {
-		free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
+		if (!pdata->poll_interval)
+			free_irq(gpio_to_irq(pdata->buttons[i].gpio),
+				&ddata->data[i]);
 		if (pdata->buttons[i].debounce_interval)
 			del_timer_sync(&ddata->data[i].timer);
 		cancel_work_sync(&ddata->data[i].work);
@@ -506,7 +572,12 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, NULL);
  fail1:
-	input_free_device(input);
+#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
+	if (pdata->poll_interval)
+		input_free_polled_device(poll_dev);
+	else
+#endif
+		input_free_device(input);
 	kfree(ddata);
 
 	return error;
@@ -516,23 +587,40 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
 {
 	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
 	struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
-	struct input_dev *input = ddata->input;
+	struct input_dev *input;
 	int i;
+#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
+	struct input_polled_dev *poll_dev;
+#endif
 
 	sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
 
 	device_init_wakeup(&pdev->dev, 0);
 
 	for (i = 0; i < pdata->nbuttons; i++) {
-		int irq = gpio_to_irq(pdata->buttons[i].gpio);
-		free_irq(irq, &ddata->data[i]);
+		if (!pdata->poll_interval) {
+			int irq = gpio_to_irq(pdata->buttons[i].gpio);
+			free_irq(irq, &ddata->data[i]);
+		}
 		if (pdata->buttons[i].debounce_interval)
 			del_timer_sync(&ddata->data[i].timer);
 		cancel_work_sync(&ddata->data[i].work);
 		gpio_free(pdata->buttons[i].gpio);
 	}
 
-	input_unregister_device(input);
+#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
+	if (pdata->poll_interval) {
+		poll_dev = ddata->poll_dev;
+		input_unregister_polled_device(poll_dev);
+		input_free_polled_device(poll_dev);
+	} else {
+#endif
+		input = ddata->input;
+		input_unregister_device(input);
+		input_free_device(input);
+#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
+	}
+#endif
 
 	return 0;
 }
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
index cd0b3f3..7dd075b 100644
--- a/include/linux/gpio_keys.h
+++ b/include/linux/gpio_keys.h
@@ -17,6 +17,7 @@ struct gpio_keys_platform_data {
 	struct gpio_keys_button *buttons;
 	int nbuttons;
 	unsigned int rep:1;		/* enable input subsystem auto repeat */
+	unsigned int poll_interval;	/* polling interval in ms */
 };
 
 #endif
-- 
1.7.1

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

* Re: [PATCH] input: gpio_keys: polling mode support
  2010-07-06 19:01 [PATCH] input: gpio_keys: polling mode support Alexander Clouter
@ 2010-07-08 16:26 ` Alexander Clouter
  2010-07-12 19:29 ` Alexander Clouter
  1 sibling, 0 replies; 17+ messages in thread
From: Alexander Clouter @ 2010-07-08 16:26 UTC (permalink / raw)
  To: linux-input

ping...?

Alexander Clouter <alex@digriz.org.uk> wrote:
>
> This implements an optional polling mode for the gpio_keys driver,
> necessary for GPIOs that are not able to generate IRQs.
> 
> gpio_keys_platform_data has been extended with poll_interval
> which specifies the polling interval in ms, this is passed onto
> input-polldev.
> 
> This work was based on the patch[1] originally conceived by Paul
> Mundt but now the absolute dependency on INPUT_POLLDEV has been
> removed (so existing users of gpio_keys can compile out polldev)
> plus some un-necessary code has been removed.
> 
> N.B. untested on an IRQ driven gpio_keys using platform as I have
>        none available to me, but looks like it should still work
> 
> [1] http://article.gmane.org/gmane.linux.kernel.input/5814
> 
> Signed-off-by: Alexander Clouter <alex@digriz.org.uk>
> ---
> drivers/input/keyboard/gpio_keys.c |  122 +++++++++++++++++++++++++++++++-----
> include/linux/gpio_keys.h          |    1 +
> 2 files changed, 106 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
> index b8213fd..c790b45 100644
> --- a/drivers/input/keyboard/gpio_keys.c
> +++ b/drivers/input/keyboard/gpio_keys.c
> @@ -1,7 +1,9 @@
> /*
> - * Driver for keys on GPIO lines capable of generating interrupts.
> + * Driver for keys on GPIO lines, either IRQ-driven or polled.
>  *
>  * Copyright 2005 Phil Blundell
> + * Copyright 2008 Paul Mundt
> + * Copyright 2010 Alexander Clouter <alex@digriz.org.uk>
>  *
>  * This program is free software; you can redistribute it and/or modify
>  * it under the terms of the GNU General Public License version 2 as
> @@ -25,6 +27,7 @@
> #include <linux/gpio_keys.h>
> #include <linux/workqueue.h>
> #include <linux/gpio.h>
> +#include <linux/input-polldev.h>
> 
> struct gpio_button_data {
>        struct gpio_keys_button *button;
> @@ -36,6 +39,9 @@ struct gpio_button_data {
> 
> struct gpio_keys_drvdata {
>        struct input_dev *input;
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +       struct input_polled_dev *poll_dev;
> +#endif
>        struct mutex disable_lock;
>        unsigned int n_buttons;
>        struct gpio_button_data data[0];
> @@ -340,6 +346,16 @@ static void gpio_keys_timer(unsigned long _data)
>        schedule_work(&data->work);
> }
> 
> +static void gpio_handle_button_event(struct gpio_keys_button *button,
> +                                    struct gpio_button_data *bdata)
> +{
> +       if (button->debounce_interval)
> +               mod_timer(&bdata->timer,
> +                       jiffies + msecs_to_jiffies(button->debounce_interval));
> +       else
> +               gpio_keys_report_event(bdata);
> +}
> +
> static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
> {
>        struct gpio_button_data *bdata = dev_id;
> @@ -347,15 +363,26 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
> 
>        BUG_ON(irq != gpio_to_irq(button->gpio));
> 
> -       if (button->debounce_interval)
> -               mod_timer(&bdata->timer,
> -                       jiffies + msecs_to_jiffies(button->debounce_interval));
> -       else
> -               schedule_work(&bdata->work);
> +       gpio_handle_button_event(button, bdata);
> 
>        return IRQ_HANDLED;
> }
> 
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +static void gpio_keys_poll(struct input_polled_dev *dev)
> +{
> +       struct gpio_keys_drvdata *ddata = dev->private;
> +       int i;
> +
> +       for (i = 0; i < ddata->n_buttons; i++) {
> +               struct gpio_button_data *bdata = &ddata->data[i];
> +               struct gpio_keys_button *button = bdata->button;
> +
> +               gpio_handle_button_event(button, bdata);
> +       }
> +}
> +#endif
> +
> static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
>                                         struct gpio_button_data *bdata,
>                                         struct gpio_keys_button *button)
> @@ -422,23 +449,52 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>        struct input_dev *input;
>        int i, error;
>        int wakeup = 0;
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +       struct input_polled_dev *poll_dev;
> +#else
> +
> +       if (pdata->poll_interval) {
> +               dev_err(dev, "device needs polling (enable INPUT_POLLDEV)\n");
> +               return -EINVAL;
> +       }
> +#endif
> 
>        ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
>                        pdata->nbuttons * sizeof(struct gpio_button_data),
>                        GFP_KERNEL);
> -       input = input_allocate_device();
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +       if (pdata->poll_interval) {
> +               poll_dev = input_allocate_polled_device();
> +               if (poll_dev)
> +                       input = poll_dev->input;
> +       } else
> +#endif
> +               input = input_allocate_device();
>        if (!ddata || !input) {
>                dev_err(dev, "failed to allocate state\n");
>                error = -ENOMEM;
>                goto fail1;
>        }
> 
> -       ddata->input = input;
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +       if (pdata->poll_interval) {
> +               ddata->poll_dev = poll_dev;
> +       } else
> +#endif
> +               ddata->input = input;
>        ddata->n_buttons = pdata->nbuttons;
>        mutex_init(&ddata->disable_lock);
> 
>        platform_set_drvdata(pdev, ddata);
> 
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +       if (pdata->poll_interval) {
> +               poll_dev->private = ddata;
> +               poll_dev->poll = gpio_keys_poll;
> +               poll_dev->poll_interval = pdata->poll_interval;
> +       }
> +#endif
> +
>        input->name = pdev->name;
>        input->phys = "gpio-keys/input0";
>        input->dev.parent = &pdev->dev;
> @@ -460,14 +516,17 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>                bdata->input = input;
>                bdata->button = button;
> 
> +               input_set_capability(input, type, button->code);
> +
> +               if (pdata->poll_interval)
> +                       continue;
> +
>                error = gpio_keys_setup_key(pdev, bdata, button);
>                if (error)
>                        goto fail2;
> 
>                if (button->wakeup)
>                        wakeup = 1;
> -
> -               input_set_capability(input, type, button->code);
>        }
> 
>        error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group);
> @@ -477,7 +536,12 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>                goto fail2;
>        }
> 
> -       error = input_register_device(input);
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +       if (pdata->poll_interval)
> +               error = input_register_polled_device(poll_dev);
> +       else
> +#endif
> +               error = input_register_device(input);
>        if (error) {
>                dev_err(dev, "Unable to register input device, error: %d\n",
>                        error);
> @@ -497,7 +561,9 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>        sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
>  fail2:
>        while (--i >= 0) {
> -               free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
> +               if (!pdata->poll_interval)
> +                       free_irq(gpio_to_irq(pdata->buttons[i].gpio),
> +                               &ddata->data[i]);
>                if (pdata->buttons[i].debounce_interval)
>                        del_timer_sync(&ddata->data[i].timer);
>                cancel_work_sync(&ddata->data[i].work);
> @@ -506,7 +572,12 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
> 
>        platform_set_drvdata(pdev, NULL);
>  fail1:
> -       input_free_device(input);
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +       if (pdata->poll_interval)
> +               input_free_polled_device(poll_dev);
> +       else
> +#endif
> +               input_free_device(input);
>        kfree(ddata);
> 
>        return error;
> @@ -516,23 +587,40 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
> {
>        struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
>        struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
> -       struct input_dev *input = ddata->input;
> +       struct input_dev *input;
>        int i;
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +       struct input_polled_dev *poll_dev;
> +#endif
> 
>        sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
> 
>        device_init_wakeup(&pdev->dev, 0);
> 
>        for (i = 0; i < pdata->nbuttons; i++) {
> -               int irq = gpio_to_irq(pdata->buttons[i].gpio);
> -               free_irq(irq, &ddata->data[i]);
> +               if (!pdata->poll_interval) {
> +                       int irq = gpio_to_irq(pdata->buttons[i].gpio);
> +                       free_irq(irq, &ddata->data[i]);
> +               }
>                if (pdata->buttons[i].debounce_interval)
>                        del_timer_sync(&ddata->data[i].timer);
>                cancel_work_sync(&ddata->data[i].work);
>                gpio_free(pdata->buttons[i].gpio);
>        }
> 
> -       input_unregister_device(input);
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +       if (pdata->poll_interval) {
> +               poll_dev = ddata->poll_dev;
> +               input_unregister_polled_device(poll_dev);
> +               input_free_polled_device(poll_dev);
> +       } else {
> +#endif
> +               input = ddata->input;
> +               input_unregister_device(input);
> +               input_free_device(input);
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +       }
> +#endif
> 
>        return 0;
> }
> diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
> index cd0b3f3..7dd075b 100644
> --- a/include/linux/gpio_keys.h
> +++ b/include/linux/gpio_keys.h
> @@ -17,6 +17,7 @@ struct gpio_keys_platform_data {
>        struct gpio_keys_button *buttons;
>        int nbuttons;
>        unsigned int rep:1;             /* enable input subsystem auto repeat */
> +       unsigned int poll_interval;     /* polling interval in ms */
> };
> 
> #endif
> -- 
> 1.7.1
> --
> To unsubscribe from this list: send the line "unsubscribe linux-input" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

-- 
Alexander Clouter
.sigmonster says: Men seldom show dimples to girls who have pimples.


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

* Re: [PATCH] input: gpio_keys: polling mode support
  2010-07-06 19:01 [PATCH] input: gpio_keys: polling mode support Alexander Clouter
  2010-07-08 16:26 ` Alexander Clouter
@ 2010-07-12 19:29 ` Alexander Clouter
  2010-07-13  1:17   ` Paul Mundt
  1 sibling, 1 reply; 17+ messages in thread
From: Alexander Clouter @ 2010-07-12 19:29 UTC (permalink / raw)
  To: linux-input; +Cc: Paul Mundt, dmitry.torokhov

Hi,

-EDONTCARE? :(

Cheers

* Alexander Clouter <alex@digriz.org.uk> [2010-07-06 20:01:28+0100]:
>
> This implements an optional polling mode for the gpio_keys driver,
> necessary for GPIOs that are not able to generate IRQs.
> 
> gpio_keys_platform_data has been extended with poll_interval
> which specifies the polling interval in ms, this is passed onto
> input-polldev.
> 
> This work was based on the patch[1] originally conceived by Paul
> Mundt but now the absolute dependency on INPUT_POLLDEV has been
> removed (so existing users of gpio_keys can compile out polldev)
> plus some un-necessary code has been removed.
> 
> N.B. untested on an IRQ driven gpio_keys using platform as I have
> 	none available to me, but looks like it should still work
> 
> [1] http://article.gmane.org/gmane.linux.kernel.input/5814
> 
> Signed-off-by: Alexander Clouter <alex@digriz.org.uk>
> ---
>  drivers/input/keyboard/gpio_keys.c |  122 +++++++++++++++++++++++++++++++-----
>  include/linux/gpio_keys.h          |    1 +
>  2 files changed, 106 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
> index b8213fd..c790b45 100644
> --- a/drivers/input/keyboard/gpio_keys.c
> +++ b/drivers/input/keyboard/gpio_keys.c
> @@ -1,7 +1,9 @@
>  /*
> - * Driver for keys on GPIO lines capable of generating interrupts.
> + * Driver for keys on GPIO lines, either IRQ-driven or polled.
>   *
>   * Copyright 2005 Phil Blundell
> + * Copyright 2008 Paul Mundt
> + * Copyright 2010 Alexander Clouter <alex@digriz.org.uk>
>   *
>   * This program is free software; you can redistribute it and/or modify
>   * it under the terms of the GNU General Public License version 2 as
> @@ -25,6 +27,7 @@
>  #include <linux/gpio_keys.h>
>  #include <linux/workqueue.h>
>  #include <linux/gpio.h>
> +#include <linux/input-polldev.h>
>  
>  struct gpio_button_data {
>  	struct gpio_keys_button *button;
> @@ -36,6 +39,9 @@ struct gpio_button_data {
>  
>  struct gpio_keys_drvdata {
>  	struct input_dev *input;
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +	struct input_polled_dev *poll_dev;
> +#endif
>  	struct mutex disable_lock;
>  	unsigned int n_buttons;
>  	struct gpio_button_data data[0];
> @@ -340,6 +346,16 @@ static void gpio_keys_timer(unsigned long _data)
>  	schedule_work(&data->work);
>  }
>  
> +static void gpio_handle_button_event(struct gpio_keys_button *button,
> +				     struct gpio_button_data *bdata)
> +{
> +	if (button->debounce_interval)
> +		mod_timer(&bdata->timer,
> +			jiffies + msecs_to_jiffies(button->debounce_interval));
> +	else
> +		gpio_keys_report_event(bdata);
> +}
> +
>  static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
>  {
>  	struct gpio_button_data *bdata = dev_id;
> @@ -347,15 +363,26 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
>  
>  	BUG_ON(irq != gpio_to_irq(button->gpio));
>  
> -	if (button->debounce_interval)
> -		mod_timer(&bdata->timer,
> -			jiffies + msecs_to_jiffies(button->debounce_interval));
> -	else
> -		schedule_work(&bdata->work);
> +	gpio_handle_button_event(button, bdata);
>  
>  	return IRQ_HANDLED;
>  }
>  
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +static void gpio_keys_poll(struct input_polled_dev *dev)
> +{
> +	struct gpio_keys_drvdata *ddata = dev->private;
> +	int i;
> +
> +	for (i = 0; i < ddata->n_buttons; i++) {
> +		struct gpio_button_data *bdata = &ddata->data[i];
> +		struct gpio_keys_button *button = bdata->button;
> +
> +		gpio_handle_button_event(button, bdata);
> +	}
> +}
> +#endif
> +
>  static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
>  					 struct gpio_button_data *bdata,
>  					 struct gpio_keys_button *button)
> @@ -422,23 +449,52 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  	struct input_dev *input;
>  	int i, error;
>  	int wakeup = 0;
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +	struct input_polled_dev *poll_dev;
> +#else
> +
> +	if (pdata->poll_interval) {
> +		dev_err(dev, "device needs polling (enable INPUT_POLLDEV)\n");
> +		return -EINVAL;
> +	}
> +#endif
>  
>  	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
>  			pdata->nbuttons * sizeof(struct gpio_button_data),
>  			GFP_KERNEL);
> -	input = input_allocate_device();
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +	if (pdata->poll_interval) {
> +		poll_dev = input_allocate_polled_device();
> +		if (poll_dev)
> +			input = poll_dev->input;
> +	} else
> +#endif
> +		input = input_allocate_device();
>  	if (!ddata || !input) {
>  		dev_err(dev, "failed to allocate state\n");
>  		error = -ENOMEM;
>  		goto fail1;
>  	}
>  
> -	ddata->input = input;
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +	if (pdata->poll_interval) {
> +		ddata->poll_dev = poll_dev;
> +	} else
> +#endif
> +		ddata->input = input;
>  	ddata->n_buttons = pdata->nbuttons;
>  	mutex_init(&ddata->disable_lock);
>  
>  	platform_set_drvdata(pdev, ddata);
>  
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +	if (pdata->poll_interval) {
> +		poll_dev->private = ddata;
> +		poll_dev->poll = gpio_keys_poll;
> +		poll_dev->poll_interval = pdata->poll_interval;
> +	}
> +#endif
> +
>  	input->name = pdev->name;
>  	input->phys = "gpio-keys/input0";
>  	input->dev.parent = &pdev->dev;
> @@ -460,14 +516,17 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  		bdata->input = input;
>  		bdata->button = button;
>  
> +		input_set_capability(input, type, button->code);
> +
> +		if (pdata->poll_interval)
> +			continue;
> +
>  		error = gpio_keys_setup_key(pdev, bdata, button);
>  		if (error)
>  			goto fail2;
>  
>  		if (button->wakeup)
>  			wakeup = 1;
> -
> -		input_set_capability(input, type, button->code);
>  	}
>  
>  	error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group);
> @@ -477,7 +536,12 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  		goto fail2;
>  	}
>  
> -	error = input_register_device(input);
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +	if (pdata->poll_interval)
> +		error = input_register_polled_device(poll_dev);
> +	else
> +#endif
> +		error = input_register_device(input);
>  	if (error) {
>  		dev_err(dev, "Unable to register input device, error: %d\n",
>  			error);
> @@ -497,7 +561,9 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  	sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
>   fail2:
>  	while (--i >= 0) {
> -		free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
> +		if (!pdata->poll_interval)
> +			free_irq(gpio_to_irq(pdata->buttons[i].gpio),
> +				&ddata->data[i]);
>  		if (pdata->buttons[i].debounce_interval)
>  			del_timer_sync(&ddata->data[i].timer);
>  		cancel_work_sync(&ddata->data[i].work);
> @@ -506,7 +572,12 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
>  
>  	platform_set_drvdata(pdev, NULL);
>   fail1:
> -	input_free_device(input);
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +	if (pdata->poll_interval)
> +		input_free_polled_device(poll_dev);
> +	else
> +#endif
> +		input_free_device(input);
>  	kfree(ddata);
>  
>  	return error;
> @@ -516,23 +587,40 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
>  {
>  	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
>  	struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
> -	struct input_dev *input = ddata->input;
> +	struct input_dev *input;
>  	int i;
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +	struct input_polled_dev *poll_dev;
> +#endif
>  
>  	sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
>  
>  	device_init_wakeup(&pdev->dev, 0);
>  
>  	for (i = 0; i < pdata->nbuttons; i++) {
> -		int irq = gpio_to_irq(pdata->buttons[i].gpio);
> -		free_irq(irq, &ddata->data[i]);
> +		if (!pdata->poll_interval) {
> +			int irq = gpio_to_irq(pdata->buttons[i].gpio);
> +			free_irq(irq, &ddata->data[i]);
> +		}
>  		if (pdata->buttons[i].debounce_interval)
>  			del_timer_sync(&ddata->data[i].timer);
>  		cancel_work_sync(&ddata->data[i].work);
>  		gpio_free(pdata->buttons[i].gpio);
>  	}
>  
> -	input_unregister_device(input);
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +	if (pdata->poll_interval) {
> +		poll_dev = ddata->poll_dev;
> +		input_unregister_polled_device(poll_dev);
> +		input_free_polled_device(poll_dev);
> +	} else {
> +#endif
> +		input = ddata->input;
> +		input_unregister_device(input);
> +		input_free_device(input);
> +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> +	}
> +#endif
>  
>  	return 0;
>  }
> diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
> index cd0b3f3..7dd075b 100644
> --- a/include/linux/gpio_keys.h
> +++ b/include/linux/gpio_keys.h
> @@ -17,6 +17,7 @@ struct gpio_keys_platform_data {
>  	struct gpio_keys_button *buttons;
>  	int nbuttons;
>  	unsigned int rep:1;		/* enable input subsystem auto repeat */
> +	unsigned int poll_interval;	/* polling interval in ms */
>  };
>  
>  #endif
> -- 
> 1.7.1

-- 
Alexander Clouter
.sigmonster says: One picture is worth 128K words.

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

* Re: [PATCH] input: gpio_keys: polling mode support
  2010-07-12 19:29 ` Alexander Clouter
@ 2010-07-13  1:17   ` Paul Mundt
  2010-07-13  1:28     ` Dmitry Torokhov
  0 siblings, 1 reply; 17+ messages in thread
From: Paul Mundt @ 2010-07-13  1:17 UTC (permalink / raw)
  To: Alexander Clouter; +Cc: linux-input, dmitry.torokhov

On Mon, Jul 12, 2010 at 08:29:51PM +0100, Alexander Clouter wrote:
> Hi,
> 
> -EDONTCARE? :(
> 
You could try Cc-ing akpm on the next version, so it at least doesn't get
lost.

> >  
> > +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> > +static void gpio_keys_poll(struct input_polled_dev *dev)
> > +{
> > +	struct gpio_keys_drvdata *ddata = dev->private;
> > +	int i;
> > +
> > +	for (i = 0; i < ddata->n_buttons; i++) {
> > +		struct gpio_button_data *bdata = &ddata->data[i];
> > +		struct gpio_keys_button *button = bdata->button;
> > +
> > +		gpio_handle_button_event(button, bdata);
> > +	}
> > +}
> > +#endif
> > +
This gets back to why I opted to select the polldev stuff in the first
place, to avoid the total mess that all of the ifdeffery causes without
it. It's also inconsistent, as you have the poll interval tested openly
in some places and always defined, while the poll dev itself is always
under ifdef due to the input layer definitions.

Personally I've never found the argument that the polling stuff should be
optional very convincing. It's a reasonable mode of operation for devices
that don't have IRQs bound to GPIOs, and having to depend on the platform
to select random bits of input subsystem infrastructure to support a
driver that may or may not be enabled at all is ugly at best.

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

* Re: [PATCH] input: gpio_keys: polling mode support
  2010-07-13  1:17   ` Paul Mundt
@ 2010-07-13  1:28     ` Dmitry Torokhov
  2010-07-13  7:26       ` Alexander Clouter
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry Torokhov @ 2010-07-13  1:28 UTC (permalink / raw)
  To: Paul Mundt; +Cc: Alexander Clouter, linux-input

On Tue, Jul 13, 2010 at 10:17:07AM +0900, Paul Mundt wrote:
> On Mon, Jul 12, 2010 at 08:29:51PM +0100, Alexander Clouter wrote:
> > Hi,
> > 
> > -EDONTCARE? :(
> > 
> You could try Cc-ing akpm on the next version, so it at least doesn't get
> lost.
> 
> > >  
> > > +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> > > +static void gpio_keys_poll(struct input_polled_dev *dev)
> > > +{
> > > +	struct gpio_keys_drvdata *ddata = dev->private;
> > > +	int i;
> > > +
> > > +	for (i = 0; i < ddata->n_buttons; i++) {
> > > +		struct gpio_button_data *bdata = &ddata->data[i];
> > > +		struct gpio_keys_button *button = bdata->button;
> > > +
> > > +		gpio_handle_button_event(button, bdata);
> > > +	}
> > > +}
> > > +#endif
> > > +
> This gets back to why I opted to select the polldev stuff in the first
> place, to avoid the total mess that all of the ifdeffery causes without
> it. It's also inconsistent, as you have the poll interval tested openly
> in some places and always defined, while the poll dev itself is always
> under ifdef due to the input layer definitions.
> 
> Personally I've never found the argument that the polling stuff should be
> optional very convincing. It's a reasonable mode of operation for devices
> that don't have IRQs bound to GPIOs, and having to depend on the platform
> to select random bits of input subsystem infrastructure to support a
> driver that may or may not be enabled at all is ugly at best.

Let me play a tad with it and if I can't untangle it reasonably I'll
just dig up old Paul's patch.

-- 
Dmitry

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

* Re: [PATCH] input: gpio_keys: polling mode support
  2010-07-13  1:28     ` Dmitry Torokhov
@ 2010-07-13  7:26       ` Alexander Clouter
  2010-07-13 19:57         ` [PATCHv2] " Alexander Clouter
  0 siblings, 1 reply; 17+ messages in thread
From: Alexander Clouter @ 2010-07-13  7:26 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Paul Mundt, linux-input

Hi,

* Dmitry Torokhov <dmitry.torokhov@gmail.com> [2010-07-12 18:28:19-0700]:
>
> > > > +#if defined(CONFIG_INPUT_POLLDEV) || defined(CONFIG_INPUT_POLLDEV_MODULE)
> > > > +static void gpio_keys_poll(struct input_polled_dev *dev)
> > > > +{
> > > > +	struct gpio_keys_drvdata *ddata = dev->private;
> > > > +	int i;
> > > > +
> > > > +	for (i = 0; i < ddata->n_buttons; i++) {
> > > > +		struct gpio_button_data *bdata = &ddata->data[i];
> > > > +		struct gpio_keys_button *button = bdata->button;
> > > > +
> > > > +		gpio_handle_button_event(button, bdata);
> > > > +	}
> > > > +}
> > > > +#endif
> >
> > This gets back to why I opted to select the polldev stuff in the first
> > place, to avoid the total mess that all of the ifdeffery causes without
> > it.
>
Well, for me the ifdef madness really only looks bad as (took me a while 
to work out) as when configuring polldev to be a module things do not 
set CONFIG_INPUT_POLLDEV.  Is this normal?

grep'ing /usr/src/linux/{arch,drivers/input} for 
CONFIG_INPUT_POLLDEV_MODULE comes up with no matchs at all (except for 
gpio_keys.c after my patch is applied).

To clean up the ifdef madness, the only approach I can think of is to 
define some dummy noop input_allocate_polled_device(), 
input_free_polled_device() and input_unregister_polled_device() 
functions defined in gpio_keys.c when CONFIG_INPUT_POLLDEV is not 
compiled in.

I am happy to do this if preferred?

I can see the argument against forcing gpio_key users having to use 
polldev (it adds 10kB to the kernel for me), especially on my platform I 
have a 4MB Flash and my kernel can only be 768kB...

> > It's also inconsistent, as you have the poll interval tested openly
> > in some places and always defined, while the poll dev itself is always
> > under ifdef due to the input layer definitions.
>
It was meant to me, you will notice the non-ifdef sections do not do 
anything other than check if poll_interval is non-zero.  As this is not 
an expensive check for the CPU but it is argubly expensive on 
readability throwing in some more ifdef's...I felt it a good compromise.
 
> > Personally I've never found the argument that the polling stuff should be
> > optional very convincing. It's a reasonable mode of operation for devices
> > that don't have IRQs bound to GPIOs, and having to depend on the platform
> > to select random bits of input subsystem infrastructure to support a
> > driver that may or may not be enabled at all is ugly at best.
> 
> Let me play a tad with it and if I can't untangle it reasonably I'll
> just dig up old Paul's patch.
> 
Paul's patch unneccessarily extends gpio_keys_drvdata with 
gpio_keys_platform_data.

Cheers

-- 
Alexander Clouter
.sigmonster says: Never argue with a woman when she's tired -- or rested.

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

* [PATCHv2] input: gpio_keys: polling mode support
  2010-07-13  7:26       ` Alexander Clouter
@ 2010-07-13 19:57         ` Alexander Clouter
  2010-07-13 20:04           ` [PATCHv3] " Alexander Clouter
  0 siblings, 1 reply; 17+ messages in thread
From: Alexander Clouter @ 2010-07-13 19:57 UTC (permalink / raw)
  To: linux-input; +Cc: Paul Mundt, Dmitry Torokhov

This implements an optional polling mode for the gpio_keys driver,
necessary for GPIOs that are not able to generate IRQs.

gpio_keys_platform_data has been extended with poll_interval
which specifies the polling interval in ms, this is passed onto
input-polldev.

This work was based on the patch[1] originally conceived by Paul
Mundt but now the absolute dependency on INPUT_POLLDEV has been
removed (so existing users of gpio_keys can compile out polldev)
plus some un-necessary code has been removed.

Changes since v1:
 * remove #ifdef madness

[1] http://article.gmane.org/gmane.linux.kernel.input/5814

Signed-off-by: Alexander Clouter <alex@digriz.org.uk>
---
 drivers/input/keyboard/gpio_keys.c |  121 +++++++++++++++++++++++++++++++-----
 include/linux/gpio_keys.h          |    1 +
 2 files changed, 105 insertions(+), 17 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index b8213fd..285638d 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -1,7 +1,9 @@
 /*
- * Driver for keys on GPIO lines capable of generating interrupts.
+ * Driver for keys on GPIO lines, either IRQ-driven or polled.
  *
  * Copyright 2005 Phil Blundell
+ * Copyright 2008 Paul Mundt
+ * Copyright 2010 Alexander Clouter <alex@digriz.org.uk>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -25,6 +27,7 @@
 #include <linux/gpio_keys.h>
 #include <linux/workqueue.h>
 #include <linux/gpio.h>
+#include <linux/input-polldev.h>
 
 struct gpio_button_data {
 	struct gpio_keys_button *button;
@@ -36,11 +39,32 @@ struct gpio_button_data {
 
 struct gpio_keys_drvdata {
 	struct input_dev *input;
+	struct input_polled_dev *poll_dev;
 	struct mutex disable_lock;
 	unsigned int n_buttons;
 	struct gpio_button_data data[0];
 };
 
+#if !defined(CONFIG_INPUT_POLLDEV) && !defined(CONFIG_INPUT_POLLDEV_MODULE)
+inline struct input_polled_dev *input_allocate_polled_device(void)
+{
+	return NULL;
+}
+
+inline void input_free_polled_device(struct input_polled_dev *poll_dev)
+{
+}
+
+inline int input_register_polled_device(struct input_polled_dev *dev)
+{
+	return -ENXIO;
+}
+
+inline void input_unregister_polled_device(struct input_polled_dev *poll_dev)
+{
+}
+#endif
+
 /*
  * SYSFS interface for enabling/disabling keys and switches:
  *
@@ -340,6 +364,16 @@ static void gpio_keys_timer(unsigned long _data)
 	schedule_work(&data->work);
 }
 
+static void gpio_handle_button_event(struct gpio_keys_button *button,
+				     struct gpio_button_data *bdata)
+{
+	if (button->debounce_interval)
+		mod_timer(&bdata->timer,
+			jiffies + msecs_to_jiffies(button->debounce_interval));
+	else
+		gpio_keys_report_event(bdata);
+}
+
 static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
 {
 	struct gpio_button_data *bdata = dev_id;
@@ -347,15 +381,24 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
 
 	BUG_ON(irq != gpio_to_irq(button->gpio));
 
-	if (button->debounce_interval)
-		mod_timer(&bdata->timer,
-			jiffies + msecs_to_jiffies(button->debounce_interval));
-	else
-		schedule_work(&bdata->work);
+	gpio_handle_button_event(button, bdata);
 
 	return IRQ_HANDLED;
 }
 
+static void gpio_keys_poll(struct input_polled_dev *dev)
+{
+	struct gpio_keys_drvdata *ddata = dev->private;
+	int i;
+
+	for (i = 0; i < ddata->n_buttons; i++) {
+		struct gpio_button_data *bdata = &ddata->data[i];
+		struct gpio_keys_button *button = bdata->button;
+
+		gpio_handle_button_event(button, bdata);
+	}
+}
+
 static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
 					 struct gpio_button_data *bdata,
 					 struct gpio_keys_button *button)
@@ -420,25 +463,47 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 	struct gpio_keys_drvdata *ddata;
 	struct device *dev = &pdev->dev;
 	struct input_dev *input;
+	struct input_polled_dev *poll_dev;
 	int i, error;
 	int wakeup = 0;
 
+#if !defined(CONFIG_INPUT_POLLDEV) && !defined(CONFIG_INPUT_POLLDEV_MODULE)
+	if (pdata->poll_interval) {
+		dev_err(dev, "device needs polling (enable INPUT_POLLDEV)\n");
+		return -EINVAL;
+	}
+#endif
+
 	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
 			pdata->nbuttons * sizeof(struct gpio_button_data),
 			GFP_KERNEL);
-	input = input_allocate_device();
+	if (pdata->poll_interval) {
+		poll_dev = input_allocate_polled_device();
+		if (poll_dev)
+			input = poll_dev->input;
+	} else
+		input = input_allocate_device();
 	if (!ddata || !input) {
 		dev_err(dev, "failed to allocate state\n");
 		error = -ENOMEM;
 		goto fail1;
 	}
 
-	ddata->input = input;
+	if (pdata->poll_interval) {
+		ddata->poll_dev = poll_dev;
+	} else
+		ddata->input = input;
 	ddata->n_buttons = pdata->nbuttons;
 	mutex_init(&ddata->disable_lock);
 
 	platform_set_drvdata(pdev, ddata);
 
+	if (pdata->poll_interval) {
+		poll_dev->private = ddata;
+		poll_dev->poll = gpio_keys_poll;
+		poll_dev->poll_interval = pdata->poll_interval;
+	}
+
 	input->name = pdev->name;
 	input->phys = "gpio-keys/input0";
 	input->dev.parent = &pdev->dev;
@@ -460,14 +525,17 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 		bdata->input = input;
 		bdata->button = button;
 
+		input_set_capability(input, type, button->code);
+
+		if (pdata->poll_interval)
+			continue;
+
 		error = gpio_keys_setup_key(pdev, bdata, button);
 		if (error)
 			goto fail2;
 
 		if (button->wakeup)
 			wakeup = 1;
-
-		input_set_capability(input, type, button->code);
 	}
 
 	error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group);
@@ -477,7 +545,10 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 		goto fail2;
 	}
 
-	error = input_register_device(input);
+	if (pdata->poll_interval)
+		error = input_register_polled_device(poll_dev);
+	else
+		error = input_register_device(input);
 	if (error) {
 		dev_err(dev, "Unable to register input device, error: %d\n",
 			error);
@@ -497,7 +568,9 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 	sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
  fail2:
 	while (--i >= 0) {
-		free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
+		if (!pdata->poll_interval)
+			free_irq(gpio_to_irq(pdata->buttons[i].gpio),
+				&ddata->data[i]);
 		if (pdata->buttons[i].debounce_interval)
 			del_timer_sync(&ddata->data[i].timer);
 		cancel_work_sync(&ddata->data[i].work);
@@ -506,7 +579,10 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, NULL);
  fail1:
-	input_free_device(input);
+	if (pdata->poll_interval)
+		input_free_polled_device(poll_dev);
+	else
+		input_free_device(input);
 	kfree(ddata);
 
 	return error;
@@ -516,7 +592,8 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
 {
 	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
 	struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
-	struct input_dev *input = ddata->input;
+	struct input_dev *input;
+	struct input_polled_dev *poll_dev;
 	int i;
 
 	sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
@@ -524,15 +601,25 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
 	device_init_wakeup(&pdev->dev, 0);
 
 	for (i = 0; i < pdata->nbuttons; i++) {
-		int irq = gpio_to_irq(pdata->buttons[i].gpio);
-		free_irq(irq, &ddata->data[i]);
+		if (!pdata->poll_interval) {
+			int irq = gpio_to_irq(pdata->buttons[i].gpio);
+			free_irq(irq, &ddata->data[i]);
+		}
 		if (pdata->buttons[i].debounce_interval)
 			del_timer_sync(&ddata->data[i].timer);
 		cancel_work_sync(&ddata->data[i].work);
 		gpio_free(pdata->buttons[i].gpio);
 	}
 
-	input_unregister_device(input);
+	if (pdata->poll_interval) {
+		poll_dev = ddata->poll_dev;
+		input_unregister_polled_device(poll_dev);
+		input_free_polled_device(poll_dev);
+	} else {
+		input = ddata->input;
+		input_unregister_device(input);
+		input_free_device(input);
+	}
 
 	return 0;
 }
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
index cd0b3f3..7dd075b 100644
--- a/include/linux/gpio_keys.h
+++ b/include/linux/gpio_keys.h
@@ -17,6 +17,7 @@ struct gpio_keys_platform_data {
 	struct gpio_keys_button *buttons;
 	int nbuttons;
 	unsigned int rep:1;		/* enable input subsystem auto repeat */
+	unsigned int poll_interval;	/* polling interval in ms */
 };
 
 #endif
-- 
1.7.1

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

* [PATCHv3] input: gpio_keys: polling mode support
  2010-07-13 19:57         ` [PATCHv2] " Alexander Clouter
@ 2010-07-13 20:04           ` Alexander Clouter
  2010-07-19 21:26             ` Ferenc Wagner
  0 siblings, 1 reply; 17+ messages in thread
From: Alexander Clouter @ 2010-07-13 20:04 UTC (permalink / raw)
  To: linux-input; +Cc: Paul Mundt, Dmitry Torokhov

This implements an optional polling mode for the gpio_keys driver,
necessary for GPIOs that are not able to generate IRQs.

gpio_keys_platform_data has been extended with poll_interval
which specifies the polling interval in ms, this is passed onto
input-polldev.

This work was based on the patch[1] originally conceived by Paul
Mundt but now the absolute dependency on INPUT_POLLDEV has been
removed (so existing users of gpio_keys can compile out polldev)
plus some un-necessary code has been removed.

[1] http://article.gmane.org/gmane.linux.kernel.input/5814

Changes since v2:
 * fix minor coding style glitch
Changes since v1:
 * remove #ifdef madness

Signed-off-by: Alexander Clouter <alex@digriz.org.uk>
---
 drivers/input/keyboard/gpio_keys.c |  121 +++++++++++++++++++++++++++++++-----
 include/linux/gpio_keys.h          |    1 +
 2 files changed, 105 insertions(+), 17 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index b8213fd..b88a308 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -1,7 +1,9 @@
 /*
- * Driver for keys on GPIO lines capable of generating interrupts.
+ * Driver for keys on GPIO lines, either IRQ-driven or polled.
  *
  * Copyright 2005 Phil Blundell
+ * Copyright 2008 Paul Mundt
+ * Copyright 2010 Alexander Clouter <alex@digriz.org.uk>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -25,6 +27,7 @@
 #include <linux/gpio_keys.h>
 #include <linux/workqueue.h>
 #include <linux/gpio.h>
+#include <linux/input-polldev.h>
 
 struct gpio_button_data {
 	struct gpio_keys_button *button;
@@ -36,11 +39,32 @@ struct gpio_button_data {
 
 struct gpio_keys_drvdata {
 	struct input_dev *input;
+	struct input_polled_dev *poll_dev;
 	struct mutex disable_lock;
 	unsigned int n_buttons;
 	struct gpio_button_data data[0];
 };
 
+#if !defined(CONFIG_INPUT_POLLDEV) && !defined(CONFIG_INPUT_POLLDEV_MODULE)
+inline struct input_polled_dev *input_allocate_polled_device(void)
+{
+	return NULL;
+}
+
+inline void input_free_polled_device(struct input_polled_dev *poll_dev)
+{
+}
+
+inline int input_register_polled_device(struct input_polled_dev *dev)
+{
+	return -ENXIO;
+}
+
+inline void input_unregister_polled_device(struct input_polled_dev *poll_dev)
+{
+}
+#endif
+
 /*
  * SYSFS interface for enabling/disabling keys and switches:
  *
@@ -340,6 +364,16 @@ static void gpio_keys_timer(unsigned long _data)
 	schedule_work(&data->work);
 }
 
+static void gpio_handle_button_event(struct gpio_keys_button *button,
+				     struct gpio_button_data *bdata)
+{
+	if (button->debounce_interval)
+		mod_timer(&bdata->timer,
+			jiffies + msecs_to_jiffies(button->debounce_interval));
+	else
+		gpio_keys_report_event(bdata);
+}
+
 static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
 {
 	struct gpio_button_data *bdata = dev_id;
@@ -347,15 +381,24 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
 
 	BUG_ON(irq != gpio_to_irq(button->gpio));
 
-	if (button->debounce_interval)
-		mod_timer(&bdata->timer,
-			jiffies + msecs_to_jiffies(button->debounce_interval));
-	else
-		schedule_work(&bdata->work);
+	gpio_handle_button_event(button, bdata);
 
 	return IRQ_HANDLED;
 }
 
+static void gpio_keys_poll(struct input_polled_dev *dev)
+{
+	struct gpio_keys_drvdata *ddata = dev->private;
+	int i;
+
+	for (i = 0; i < ddata->n_buttons; i++) {
+		struct gpio_button_data *bdata = &ddata->data[i];
+		struct gpio_keys_button *button = bdata->button;
+
+		gpio_handle_button_event(button, bdata);
+	}
+}
+
 static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
 					 struct gpio_button_data *bdata,
 					 struct gpio_keys_button *button)
@@ -420,25 +463,47 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 	struct gpio_keys_drvdata *ddata;
 	struct device *dev = &pdev->dev;
 	struct input_dev *input;
+	struct input_polled_dev *poll_dev;
 	int i, error;
 	int wakeup = 0;
 
+#if !defined(CONFIG_INPUT_POLLDEV) && !defined(CONFIG_INPUT_POLLDEV_MODULE)
+	if (pdata->poll_interval) {
+		dev_err(dev, "device needs polling (enable INPUT_POLLDEV)\n");
+		return -EINVAL;
+	}
+#endif
+
 	ddata = kzalloc(sizeof(struct gpio_keys_drvdata) +
 			pdata->nbuttons * sizeof(struct gpio_button_data),
 			GFP_KERNEL);
-	input = input_allocate_device();
+	if (pdata->poll_interval) {
+		poll_dev = input_allocate_polled_device();
+		if (poll_dev)
+			input = poll_dev->input;
+	} else
+		input = input_allocate_device();
 	if (!ddata || !input) {
 		dev_err(dev, "failed to allocate state\n");
 		error = -ENOMEM;
 		goto fail1;
 	}
 
-	ddata->input = input;
+	if (pdata->poll_interval)
+		ddata->poll_dev = poll_dev;
+	else
+		ddata->input = input;
 	ddata->n_buttons = pdata->nbuttons;
 	mutex_init(&ddata->disable_lock);
 
 	platform_set_drvdata(pdev, ddata);
 
+	if (pdata->poll_interval) {
+		poll_dev->private = ddata;
+		poll_dev->poll = gpio_keys_poll;
+		poll_dev->poll_interval = pdata->poll_interval;
+	}
+
 	input->name = pdev->name;
 	input->phys = "gpio-keys/input0";
 	input->dev.parent = &pdev->dev;
@@ -460,14 +525,17 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 		bdata->input = input;
 		bdata->button = button;
 
+		input_set_capability(input, type, button->code);
+
+		if (pdata->poll_interval)
+			continue;
+
 		error = gpio_keys_setup_key(pdev, bdata, button);
 		if (error)
 			goto fail2;
 
 		if (button->wakeup)
 			wakeup = 1;
-
-		input_set_capability(input, type, button->code);
 	}
 
 	error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group);
@@ -477,7 +545,10 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 		goto fail2;
 	}
 
-	error = input_register_device(input);
+	if (pdata->poll_interval)
+		error = input_register_polled_device(poll_dev);
+	else
+		error = input_register_device(input);
 	if (error) {
 		dev_err(dev, "Unable to register input device, error: %d\n",
 			error);
@@ -497,7 +568,9 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 	sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
  fail2:
 	while (--i >= 0) {
-		free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
+		if (!pdata->poll_interval)
+			free_irq(gpio_to_irq(pdata->buttons[i].gpio),
+				&ddata->data[i]);
 		if (pdata->buttons[i].debounce_interval)
 			del_timer_sync(&ddata->data[i].timer);
 		cancel_work_sync(&ddata->data[i].work);
@@ -506,7 +579,10 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, NULL);
  fail1:
-	input_free_device(input);
+	if (pdata->poll_interval)
+		input_free_polled_device(poll_dev);
+	else
+		input_free_device(input);
 	kfree(ddata);
 
 	return error;
@@ -516,7 +592,8 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
 {
 	struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
 	struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
-	struct input_dev *input = ddata->input;
+	struct input_dev *input;
+	struct input_polled_dev *poll_dev;
 	int i;
 
 	sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
@@ -524,15 +601,25 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
 	device_init_wakeup(&pdev->dev, 0);
 
 	for (i = 0; i < pdata->nbuttons; i++) {
-		int irq = gpio_to_irq(pdata->buttons[i].gpio);
-		free_irq(irq, &ddata->data[i]);
+		if (!pdata->poll_interval) {
+			int irq = gpio_to_irq(pdata->buttons[i].gpio);
+			free_irq(irq, &ddata->data[i]);
+		}
 		if (pdata->buttons[i].debounce_interval)
 			del_timer_sync(&ddata->data[i].timer);
 		cancel_work_sync(&ddata->data[i].work);
 		gpio_free(pdata->buttons[i].gpio);
 	}
 
-	input_unregister_device(input);
+	if (pdata->poll_interval) {
+		poll_dev = ddata->poll_dev;
+		input_unregister_polled_device(poll_dev);
+		input_free_polled_device(poll_dev);
+	} else {
+		input = ddata->input;
+		input_unregister_device(input);
+		input_free_device(input);
+	}
 
 	return 0;
 }
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
index cd0b3f3..7dd075b 100644
--- a/include/linux/gpio_keys.h
+++ b/include/linux/gpio_keys.h
@@ -17,6 +17,7 @@ struct gpio_keys_platform_data {
 	struct gpio_keys_button *buttons;
 	int nbuttons;
 	unsigned int rep:1;		/* enable input subsystem auto repeat */
+	unsigned int poll_interval;	/* polling interval in ms */
 };
 
 #endif
-- 
1.7.1

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

* Re: [PATCHv3] input: gpio_keys: polling mode support
  2010-07-13 20:04           ` [PATCHv3] " Alexander Clouter
@ 2010-07-19 21:26             ` Ferenc Wagner
  2010-07-24  7:46               ` Dmitry Torokhov
  0 siblings, 1 reply; 17+ messages in thread
From: Ferenc Wagner @ 2010-07-19 21:26 UTC (permalink / raw)
  To: Alexander Clouter; +Cc: linux-input, Paul Mundt, Dmitry Torokhov

Hi,

Just in case you didn't know: there's an alternate implementation at
https://dev.openwrt.org/browser/trunk/target/linux/generic-2.6/files/drivers/input/misc/gpio_buttons.c?rev=21436
-- 
Regards,
Feri.

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

* Re: [PATCHv3] input: gpio_keys: polling mode support
  2010-07-19 21:26             ` Ferenc Wagner
@ 2010-07-24  7:46               ` Dmitry Torokhov
  2010-07-24 19:17                 ` Ferenc Wagner
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry Torokhov @ 2010-07-24  7:46 UTC (permalink / raw)
  To: Ferenc Wagner; +Cc: Alexander Clouter, linux-input, Paul Mundt

On Mon, Jul 19, 2010 at 11:26:55PM +0200, Ferenc Wagner wrote:
> Hi,
> 
> Just in case you didn't know: there's an alternate implementation at
> https://dev.openwrt.org/browser/trunk/target/linux/generic-2.6/files/drivers/input/misc/gpio_buttons.c?rev=21436

Hmm, I might like this option best of all. We just need to rename the
driver so that we can have both polled and interrupt driven compiled,
Then we'd bind based on device name creatd for us.

Can you submit it officially?

Thanks.

-- 
Dmitry

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

* Re: [PATCHv3] input: gpio_keys: polling mode support
  2010-07-24  7:46               ` Dmitry Torokhov
@ 2010-07-24 19:17                 ` Ferenc Wagner
  0 siblings, 0 replies; 17+ messages in thread
From: Ferenc Wagner @ 2010-07-24 19:17 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Alexander Clouter, linux-input, Paul Mundt, Gabor Juhos,
	Nuno Goncalves

Dmitry Torokhov <dmitry.torokhov@gmail.com> writes:

> On Mon, Jul 19, 2010 at 11:26:55PM +0200, Ferenc Wagner wrote:
> 
>> Just in case you didn't know: there's an alternate implementation at
>> https://dev.openwrt.org/browser/trunk/target/linux/generic-2.6/files/drivers/input/misc/gpio_buttons.c?rev=21436
>
> Hmm, I might like this option best of all. We just need to rename the
> driver so that we can have both polled and interrupt driven compiled,
> Then we'd bind based on device name creatd for us.
>
> Can you submit it officially?

Hi,

Actually, I'm not affiliated with that code, I just happened to run into
it some time ago.  I put its authors on Cc, they sure can help you
better.  I'd expect them to very gladly submit it, thus reducing the
delta between OpenWRT and upstream Linux. :)
-- 
Regards,
Feri.

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

end of thread, other threads:[~2010-07-24 19:17 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-06 19:01 [PATCH] input: gpio_keys: polling mode support Alexander Clouter
2010-07-08 16:26 ` Alexander Clouter
2010-07-12 19:29 ` Alexander Clouter
2010-07-13  1:17   ` Paul Mundt
2010-07-13  1:28     ` Dmitry Torokhov
2010-07-13  7:26       ` Alexander Clouter
2010-07-13 19:57         ` [PATCHv2] " Alexander Clouter
2010-07-13 20:04           ` [PATCHv3] " Alexander Clouter
2010-07-19 21:26             ` Ferenc Wagner
2010-07-24  7:46               ` Dmitry Torokhov
2010-07-24 19:17                 ` Ferenc Wagner
  -- strict thread matches above, loose matches on Subject: below --
2008-10-21  8:38 [PATCH] input: gpio_keys: Polling " Paul Mundt
2008-10-28 10:18 ` Paul Mundt
2008-10-29  3:51   ` Dmitry Torokhov
2008-11-25 20:43     ` Paul Mundt
2008-12-08  3:32       ` Paul Mundt
2008-12-24  1:47         ` Paul Mundt

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).