linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] matrix_keypad: add support for clustered irq
@ 2010-05-26 13:57 Luotao Fu
  2010-05-26 14:29 ` Eric Miao
  2010-05-27  6:43 ` [PATCH V2] " Luotao Fu
  0 siblings, 2 replies; 6+ messages in thread
From: Luotao Fu @ 2010-05-26 13:57 UTC (permalink / raw)
  To: Dmitry Torokhov, Marek Vasut
  Cc: Eric Miao, linux-kernel, linux-input, Luotao Fu

This one adds support of a combined irq source for the whole matrix keypad.
This can be useful all rows and columns of the keypad is e.g. connected to
a GPIO expander, which only has one interrupt line for all events on every
single GPIO.

Signed-off-by: Luotao Fu <l.fu@pengutronix.de>
---
 drivers/input/keyboard/matrix_keypad.c |   80 ++++++++++++++++++++++++++------
 include/linux/input/matrix_keypad.h    |    5 ++
 2 files changed, 70 insertions(+), 15 deletions(-)

diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
index b443e08..260dcb0 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -87,8 +87,12 @@ static void enable_row_irqs(struct matrix_keypad *keypad)
 	const struct matrix_keypad_platform_data *pdata = keypad->pdata;
 	int i;
 
-	for (i = 0; i < pdata->num_row_gpios; i++)
-		enable_irq(gpio_to_irq(pdata->row_gpios[i]));
+	if (pdata->clustered_irq > 0)
+		enable_irq(pdata->clustered_irq);
+	else {
+		for (i = 0; i < pdata->num_row_gpios; i++)
+			enable_irq(gpio_to_irq(pdata->row_gpios[i]));
+	}
 }
 
 static void disable_row_irqs(struct matrix_keypad *keypad)
@@ -96,8 +100,12 @@ static void disable_row_irqs(struct matrix_keypad *keypad)
 	const struct matrix_keypad_platform_data *pdata = keypad->pdata;
 	int i;
 
-	for (i = 0; i < pdata->num_row_gpios; i++)
-		disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i]));
+	if (pdata->clustered_irq > 0)
+		disable_irq_nosync(pdata->clustered_irq);
+	else {
+		for (i = 0; i < pdata->num_row_gpios; i++)
+			disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i]));
+	}
 }
 
 /*
@@ -226,6 +234,17 @@ static int matrix_keypad_suspend(struct device *dev)
 	matrix_keypad_stop(keypad->input_dev);
 
 	if (device_may_wakeup(&pdev->dev)) {
+		if (pdata->clustered_irq > 0) {
+			unsigned int cirq = pdata->clustered_irq;
+
+			if (enable_irq_wake(cirq) == 0) {
+				for (i = 0; i < pdata->num_row_gpios; i++)
+					__set_bit(i, keypad->disabled_gpios);
+			}
+
+			goto out;
+		}
+
 		for (i = 0; i < pdata->num_row_gpios; i++) {
 			if (!test_bit(i, keypad->disabled_gpios)) {
 				unsigned int gpio = pdata->row_gpios[i];
@@ -235,7 +254,7 @@ static int matrix_keypad_suspend(struct device *dev)
 			}
 		}
 	}
-
+out:
 	return 0;
 }
 
@@ -247,6 +266,17 @@ static int matrix_keypad_resume(struct device *dev)
 	int i;
 
 	if (device_may_wakeup(&pdev->dev)) {
+		if (pdata->clustered_irq > 0) {
+			unsigned int cirq = pdata->clustered_irq;
+
+			if (disable_irq_wake(cirq) == 0) {
+				for (i = 0; i < pdata->num_row_gpios; i++)
+					clear_bit(i, keypad->disabled_gpios);
+			}
+
+			goto out;
+		}
+
 		for (i = 0; i < pdata->num_row_gpios; i++) {
 			if (test_and_clear_bit(i, keypad->disabled_gpios)) {
 				unsigned int gpio = pdata->row_gpios[i];
@@ -256,6 +286,7 @@ static int matrix_keypad_resume(struct device *dev)
 		}
 	}
 
+out:
 	matrix_keypad_start(keypad->input_dev);
 
 	return 0;
@@ -296,17 +327,31 @@ static int __devinit init_matrix_gpio(struct platform_device *pdev,
 		gpio_direction_input(pdata->row_gpios[i]);
 	}
 
-	for (i = 0; i < pdata->num_row_gpios; i++) {
-		err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
+	if (pdata->clustered_irq > 0) {
+		err = request_irq(pdata->clustered_irq,
 				matrix_keypad_interrupt,
-				IRQF_DISABLED |
-				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+				pdata->clustered_irq_flags,
 				"matrix-keypad", keypad);
 		if (err) {
 			dev_err(&pdev->dev,
-				"Unable to acquire interrupt for GPIO line %i\n",
-				pdata->row_gpios[i]);
-			goto err_free_irqs;
+				"Unable to acquire clustered interrupt\n");
+			goto err_free_rows;
+		}
+	} else {
+		for (i = 0; i < pdata->num_row_gpios; i++) {
+			err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
+					matrix_keypad_interrupt,
+					IRQF_DISABLED |
+					IRQF_TRIGGER_RISING |
+					IRQF_TRIGGER_FALLING,
+					"matrix-keypad", keypad);
+			if (err) {
+				dev_err(&pdev->dev,
+					"Unable to acquire interrupt "
+					"for GPIO line %i\n",
+					pdata->row_gpios[i]);
+				goto err_free_irqs;
+			}
 		}
 	}
 
@@ -418,11 +463,16 @@ static int __devexit matrix_keypad_remove(struct platform_device *pdev)
 
 	device_init_wakeup(&pdev->dev, 0);
 
-	for (i = 0; i < pdata->num_row_gpios; i++) {
-		free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
-		gpio_free(pdata->row_gpios[i]);
+	if (pdata->clustered_irq > 0) {
+		free_irq(pdata->clustered_irq, keypad);
+	} else {
+		for (i = 0; i < pdata->num_row_gpios; i++)
+			free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
 	}
 
+	for (i = 0; i < pdata->num_row_gpios; i++)
+		gpio_free(pdata->row_gpios[i]);
+
 	for (i = 0; i < pdata->num_col_gpios; i++)
 		gpio_free(pdata->col_gpios[i]);
 
diff --git a/include/linux/input/matrix_keypad.h b/include/linux/input/matrix_keypad.h
index c964cd7..8e8dc2e 100644
--- a/include/linux/input/matrix_keypad.h
+++ b/include/linux/input/matrix_keypad.h
@@ -63,6 +63,11 @@ struct matrix_keypad_platform_data {
 	/* key debounce interval in milli-second */
 	unsigned int	debounce_ms;
 
+	/* used if interrupts of all row/column GPIOs are bundled to one single
+	 * irq */
+	unsigned int	clustered_irq;
+	unsigned int	clustered_irq_flags;
+
 	bool		active_low;
 	bool		wakeup;
 	bool		no_autorepeat;
-- 
1.7.0

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

* Re: [PATCH] matrix_keypad: add support for clustered irq
  2010-05-26 13:57 [PATCH] matrix_keypad: add support for clustered irq Luotao Fu
@ 2010-05-26 14:29 ` Eric Miao
  2010-05-26 14:38   ` Luotao Fu
  2010-05-27  6:43 ` [PATCH V2] " Luotao Fu
  1 sibling, 1 reply; 6+ messages in thread
From: Eric Miao @ 2010-05-26 14:29 UTC (permalink / raw)
  To: Luotao Fu; +Cc: Dmitry Torokhov, Marek Vasut, linux-kernel, linux-input

On Wed, May 26, 2010 at 9:57 PM, Luotao Fu <l.fu@pengutronix.de> wrote:
> This one adds support of a combined irq source for the whole matrix keypad.
> This can be useful all rows and columns of the keypad is e.g. connected to
> a GPIO expander, which only has one interrupt line for all events on every
> single GPIO.
>
> Signed-off-by: Luotao Fu <l.fu@pengutronix.de>
> ---
>  drivers/input/keyboard/matrix_keypad.c |   80 ++++++++++++++++++++++++++------
>  include/linux/input/matrix_keypad.h    |    5 ++
>  2 files changed, 70 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
> index b443e08..260dcb0 100644
> --- a/drivers/input/keyboard/matrix_keypad.c
> +++ b/drivers/input/keyboard/matrix_keypad.c
> @@ -87,8 +87,12 @@ static void enable_row_irqs(struct matrix_keypad *keypad)
>        const struct matrix_keypad_platform_data *pdata = keypad->pdata;
>        int i;
>
> -       for (i = 0; i < pdata->num_row_gpios; i++)
> -               enable_irq(gpio_to_irq(pdata->row_gpios[i]));
> +       if (pdata->clustered_irq > 0)
> +               enable_irq(pdata->clustered_irq);
> +       else {
> +               for (i = 0; i < pdata->num_row_gpios; i++)
> +                       enable_irq(gpio_to_irq(pdata->row_gpios[i]));
> +       }
>  }
>
>  static void disable_row_irqs(struct matrix_keypad *keypad)
> @@ -96,8 +100,12 @@ static void disable_row_irqs(struct matrix_keypad *keypad)
>        const struct matrix_keypad_platform_data *pdata = keypad->pdata;
>        int i;
>
> -       for (i = 0; i < pdata->num_row_gpios; i++)
> -               disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i]));
> +       if (pdata->clustered_irq > 0)
> +               disable_irq_nosync(pdata->clustered_irq);
> +       else {
> +               for (i = 0; i < pdata->num_row_gpios; i++)
> +                       disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i]));
> +       }
>  }
>
>  /*
> @@ -226,6 +234,17 @@ static int matrix_keypad_suspend(struct device *dev)
>        matrix_keypad_stop(keypad->input_dev);
>
>        if (device_may_wakeup(&pdev->dev)) {
> +               if (pdata->clustered_irq > 0) {
> +                       unsigned int cirq = pdata->clustered_irq;
> +
> +                       if (enable_irq_wake(cirq) == 0) {
> +                               for (i = 0; i < pdata->num_row_gpios; i++)
> +                                       __set_bit(i, keypad->disabled_gpios);
> +                       }
> +
> +                       goto out;
> +               }
> +

This might deserve a separate function, and what is the usage of disabled_gpios,
I seem to find nowhere (except in the resume routine).

>                for (i = 0; i < pdata->num_row_gpios; i++) {
>                        if (!test_bit(i, keypad->disabled_gpios)) {
>                                unsigned int gpio = pdata->row_gpios[i];
> @@ -235,7 +254,7 @@ static int matrix_keypad_suspend(struct device *dev)
>                        }
>                }
>        }
> -
> +out:
>        return 0;
>  }
>
> @@ -247,6 +266,17 @@ static int matrix_keypad_resume(struct device *dev)
>        int i;
>
>        if (device_may_wakeup(&pdev->dev)) {
> +               if (pdata->clustered_irq > 0) {
> +                       unsigned int cirq = pdata->clustered_irq;
> +
> +                       if (disable_irq_wake(cirq) == 0) {
> +                               for (i = 0; i < pdata->num_row_gpios; i++)
> +                                       clear_bit(i, keypad->disabled_gpios);
> +                       }
> +
> +                       goto out;
> +               }
> +

Better a separate routine.

>                for (i = 0; i < pdata->num_row_gpios; i++) {
>                        if (test_and_clear_bit(i, keypad->disabled_gpios)) {
>                                unsigned int gpio = pdata->row_gpios[i];
> @@ -256,6 +286,7 @@ static int matrix_keypad_resume(struct device *dev)
>                }
>        }
>
> +out:
>        matrix_keypad_start(keypad->input_dev);
>
>        return 0;
> @@ -296,17 +327,31 @@ static int __devinit init_matrix_gpio(struct platform_device *pdev,
>                gpio_direction_input(pdata->row_gpios[i]);
>        }
>
> -       for (i = 0; i < pdata->num_row_gpios; i++) {
> -               err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
> +       if (pdata->clustered_irq > 0) {
> +               err = request_irq(pdata->clustered_irq,
>                                matrix_keypad_interrupt,
> -                               IRQF_DISABLED |
> -                               IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
> +                               pdata->clustered_irq_flags,
>                                "matrix-keypad", keypad);
>                if (err) {
>                        dev_err(&pdev->dev,
> -                               "Unable to acquire interrupt for GPIO line %i\n",
> -                               pdata->row_gpios[i]);
> -                       goto err_free_irqs;
> +                               "Unable to acquire clustered interrupt\n");
> +                       goto err_free_rows;
> +               }
> +       } else {
> +               for (i = 0; i < pdata->num_row_gpios; i++) {
> +                       err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
> +                                       matrix_keypad_interrupt,
> +                                       IRQF_DISABLED |
> +                                       IRQF_TRIGGER_RISING |
> +                                       IRQF_TRIGGER_FALLING,
> +                                       "matrix-keypad", keypad);
> +                       if (err) {
> +                               dev_err(&pdev->dev,
> +                                       "Unable to acquire interrupt "
> +                                       "for GPIO line %i\n",
> +                                       pdata->row_gpios[i]);
> +                               goto err_free_irqs;
> +                       }

Ditto.

>                }
>        }
>
> @@ -418,11 +463,16 @@ static int __devexit matrix_keypad_remove(struct platform_device *pdev)
>
>        device_init_wakeup(&pdev->dev, 0);
>
> -       for (i = 0; i < pdata->num_row_gpios; i++) {
> -               free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
> -               gpio_free(pdata->row_gpios[i]);
> +       if (pdata->clustered_irq > 0) {
> +               free_irq(pdata->clustered_irq, keypad);
> +       } else {
> +               for (i = 0; i < pdata->num_row_gpios; i++)
> +                       free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
>        }
>
> +       for (i = 0; i < pdata->num_row_gpios; i++)
> +               gpio_free(pdata->row_gpios[i]);
> +
>        for (i = 0; i < pdata->num_col_gpios; i++)
>                gpio_free(pdata->col_gpios[i]);
>
> diff --git a/include/linux/input/matrix_keypad.h b/include/linux/input/matrix_keypad.h
> index c964cd7..8e8dc2e 100644
> --- a/include/linux/input/matrix_keypad.h
> +++ b/include/linux/input/matrix_keypad.h
> @@ -63,6 +63,11 @@ struct matrix_keypad_platform_data {
>        /* key debounce interval in milli-second */
>        unsigned int    debounce_ms;
>
> +       /* used if interrupts of all row/column GPIOs are bundled to one single
> +        * irq */
> +       unsigned int    clustered_irq;
> +       unsigned int    clustered_irq_flags;
> +
>        bool            active_low;
>        bool            wakeup;
>        bool            no_autorepeat;
> --
> 1.7.0
>
>

Otherwise looks OK to me.

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

* Re: [PATCH] matrix_keypad: add support for clustered irq
  2010-05-26 14:29 ` Eric Miao
@ 2010-05-26 14:38   ` Luotao Fu
  0 siblings, 0 replies; 6+ messages in thread
From: Luotao Fu @ 2010-05-26 14:38 UTC (permalink / raw)
  To: Eric Miao
  Cc: Luotao Fu, Dmitry Torokhov, Marek Vasut, linux-kernel,
	linux-input

[-- Attachment #1: Type: text/plain, Size: 8918 bytes --]

Hi Eric,

thankf for the review.

On Wed, May 26, 2010 at 10:29:53PM +0800, Eric Miao wrote:
> On Wed, May 26, 2010 at 9:57 PM, Luotao Fu <l.fu@pengutronix.de> wrote:
> > This one adds support of a combined irq source for the whole matrix keypad.
> > This can be useful all rows and columns of the keypad is e.g. connected to
> > a GPIO expander, which only has one interrupt line for all events on every
> > single GPIO.
> >
> > Signed-off-by: Luotao Fu <l.fu@pengutronix.de>
> > ---
> >  drivers/input/keyboard/matrix_keypad.c |   80 ++++++++++++++++++++++++++------
> >  include/linux/input/matrix_keypad.h    |    5 ++
> >  2 files changed, 70 insertions(+), 15 deletions(-)
> >
> > diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
> > index b443e08..260dcb0 100644
> > --- a/drivers/input/keyboard/matrix_keypad.c
> > +++ b/drivers/input/keyboard/matrix_keypad.c
> > @@ -87,8 +87,12 @@ static void enable_row_irqs(struct matrix_keypad *keypad)
> >        const struct matrix_keypad_platform_data *pdata = keypad->pdata;
> >        int i;
> >
> > -       for (i = 0; i < pdata->num_row_gpios; i++)
> > -               enable_irq(gpio_to_irq(pdata->row_gpios[i]));
> > +       if (pdata->clustered_irq > 0)
> > +               enable_irq(pdata->clustered_irq);
> > +       else {
> > +               for (i = 0; i < pdata->num_row_gpios; i++)
> > +                       enable_irq(gpio_to_irq(pdata->row_gpios[i]));
> > +       }
> >  }
> >
> >  static void disable_row_irqs(struct matrix_keypad *keypad)
> > @@ -96,8 +100,12 @@ static void disable_row_irqs(struct matrix_keypad *keypad)
> >        const struct matrix_keypad_platform_data *pdata = keypad->pdata;
> >        int i;
> >
> > -       for (i = 0; i < pdata->num_row_gpios; i++)
> > -               disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i]));
> > +       if (pdata->clustered_irq > 0)
> > +               disable_irq_nosync(pdata->clustered_irq);
> > +       else {
> > +               for (i = 0; i < pdata->num_row_gpios; i++)
> > +                       disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i]));
> > +       }
> >  }
> >
> >  /*
> > @@ -226,6 +234,17 @@ static int matrix_keypad_suspend(struct device *dev)
> >        matrix_keypad_stop(keypad->input_dev);
> >
> >        if (device_may_wakeup(&pdev->dev)) {
> > +               if (pdata->clustered_irq > 0) {
> > +                       unsigned int cirq = pdata->clustered_irq;
> > +
> > +                       if (enable_irq_wake(cirq) == 0) {
> > +                               for (i = 0; i < pdata->num_row_gpios; i++)
> > +                                       __set_bit(i, keypad->disabled_gpios);
> > +                       }
> > +
> > +                       goto out;
> > +               }
> > +
> 
> This might deserve a separate function, and what is the usage of disabled_gpios,
> I seem to find nowhere (except in the resume routine).

indeed, will fix. The disable_gpios flag seems to be used to flag an
asleep/awake row/column. It's introduced by the original code. I think
that for the case with single irq I might better use another flag
instead since we have the situaiton "all or none" here and don't have to
mark every single lines.

> 
> >                for (i = 0; i < pdata->num_row_gpios; i++) {
> >                        if (!test_bit(i, keypad->disabled_gpios)) {
> >                                unsigned int gpio = pdata->row_gpios[i];
> > @@ -235,7 +254,7 @@ static int matrix_keypad_suspend(struct device *dev)
> >                        }
> >                }
> >        }
> > -
> > +out:
> >        return 0;
> >  }
> >
> > @@ -247,6 +266,17 @@ static int matrix_keypad_resume(struct device *dev)
> >        int i;
> >
> >        if (device_may_wakeup(&pdev->dev)) {
> > +               if (pdata->clustered_irq > 0) {
> > +                       unsigned int cirq = pdata->clustered_irq;
> > +
> > +                       if (disable_irq_wake(cirq) == 0) {
> > +                               for (i = 0; i < pdata->num_row_gpios; i++)
> > +                                       clear_bit(i, keypad->disabled_gpios);
> > +                       }
> > +
> > +                       goto out;
> > +               }
> > +
> 
> Better a separate routine.
> 
> >                for (i = 0; i < pdata->num_row_gpios; i++) {
> >                        if (test_and_clear_bit(i, keypad->disabled_gpios)) {
> >                                unsigned int gpio = pdata->row_gpios[i];
> > @@ -256,6 +286,7 @@ static int matrix_keypad_resume(struct device *dev)
> >                }
> >        }
> >
> > +out:
> >        matrix_keypad_start(keypad->input_dev);
> >
> >        return 0;
> > @@ -296,17 +327,31 @@ static int __devinit init_matrix_gpio(struct platform_device *pdev,
> >                gpio_direction_input(pdata->row_gpios[i]);
> >        }
> >
> > -       for (i = 0; i < pdata->num_row_gpios; i++) {
> > -               err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
> > +       if (pdata->clustered_irq > 0) {
> > +               err = request_irq(pdata->clustered_irq,
> >                                matrix_keypad_interrupt,
> > -                               IRQF_DISABLED |
> > -                               IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
> > +                               pdata->clustered_irq_flags,
> >                                "matrix-keypad", keypad);
> >                if (err) {
> >                        dev_err(&pdev->dev,
> > -                               "Unable to acquire interrupt for GPIO line %i\n",
> > -                               pdata->row_gpios[i]);
> > -                       goto err_free_irqs;
> > +                               "Unable to acquire clustered interrupt\n");
> > +                       goto err_free_rows;
> > +               }
> > +       } else {
> > +               for (i = 0; i < pdata->num_row_gpios; i++) {
> > +                       err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
> > +                                       matrix_keypad_interrupt,
> > +                                       IRQF_DISABLED |
> > +                                       IRQF_TRIGGER_RISING |
> > +                                       IRQF_TRIGGER_FALLING,
> > +                                       "matrix-keypad", keypad);
> > +                       if (err) {
> > +                               dev_err(&pdev->dev,
> > +                                       "Unable to acquire interrupt "
> > +                                       "for GPIO line %i\n",
> > +                                       pdata->row_gpios[i]);
> > +                               goto err_free_irqs;
> > +                       }
> 
> Ditto.
> 
> >                }
> >        }
> >
> > @@ -418,11 +463,16 @@ static int __devexit matrix_keypad_remove(struct platform_device *pdev)
> >
> >        device_init_wakeup(&pdev->dev, 0);
> >
> > -       for (i = 0; i < pdata->num_row_gpios; i++) {
> > -               free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
> > -               gpio_free(pdata->row_gpios[i]);
> > +       if (pdata->clustered_irq > 0) {
> > +               free_irq(pdata->clustered_irq, keypad);
> > +       } else {
> > +               for (i = 0; i < pdata->num_row_gpios; i++)
> > +                       free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
> >        }
> >
> > +       for (i = 0; i < pdata->num_row_gpios; i++)
> > +               gpio_free(pdata->row_gpios[i]);
> > +
> >        for (i = 0; i < pdata->num_col_gpios; i++)
> >                gpio_free(pdata->col_gpios[i]);
> >
> > diff --git a/include/linux/input/matrix_keypad.h b/include/linux/input/matrix_keypad.h
> > index c964cd7..8e8dc2e 100644
> > --- a/include/linux/input/matrix_keypad.h
> > +++ b/include/linux/input/matrix_keypad.h
> > @@ -63,6 +63,11 @@ struct matrix_keypad_platform_data {
> >        /* key debounce interval in milli-second */
> >        unsigned int    debounce_ms;
> >
> > +       /* used if interrupts of all row/column GPIOs are bundled to one single
> > +        * irq */
> > +       unsigned int    clustered_irq;
> > +       unsigned int    clustered_irq_flags;
> > +
> >        bool            active_low;
> >        bool            wakeup;
> >        bool            no_autorepeat;
> > --
> > 1.7.0
> >
> >
> 
> Otherwise looks OK to me.

Thanks

cheers
Luotao Fu
-- 
Pengutronix e.K.                           | Dipl.-Ing. Luotao Fu        |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

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

* [PATCH V2] matrix_keypad: add support for clustered irq
  2010-05-26 13:57 [PATCH] matrix_keypad: add support for clustered irq Luotao Fu
  2010-05-26 14:29 ` Eric Miao
@ 2010-05-27  6:43 ` Luotao Fu
  2010-05-27 15:14   ` Eric Miao
  1 sibling, 1 reply; 6+ messages in thread
From: Luotao Fu @ 2010-05-27  6:43 UTC (permalink / raw)
  To: Dmitry Torokhov, Marek Vasut
  Cc: Eric Miao, linux-kernel, linux-input, Luotao Fu

This one adds support of a combined irq source for the whole matrix keypad.
This can be useful if all rows and columns of the keypad are e.g. connected
to a GPIO expander, which only has one interrupt line for all events on
every single GPIO.

Signed-off-by: Luotao Fu <l.fu@pengutronix.de>
---
V2 Changes:
* create separate functions for suspend/resume calls.
* add bool flag to signal enable/disable state of all gpios.
* add spinlock to suspend and resume callbacks.

 drivers/input/keyboard/matrix_keypad.c |  138 ++++++++++++++++++++++++--------
 include/linux/input/matrix_keypad.h    |    5 +
 2 files changed, 109 insertions(+), 34 deletions(-)

diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
index b443e08..99b7204 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -37,6 +37,7 @@ struct matrix_keypad {
 	spinlock_t lock;
 	bool scan_pending;
 	bool stopped;
+	bool gpio_all_disabled;
 };
 
 /*
@@ -87,8 +88,12 @@ static void enable_row_irqs(struct matrix_keypad *keypad)
 	const struct matrix_keypad_platform_data *pdata = keypad->pdata;
 	int i;
 
-	for (i = 0; i < pdata->num_row_gpios; i++)
-		enable_irq(gpio_to_irq(pdata->row_gpios[i]));
+	if (pdata->clustered_irq > 0)
+		enable_irq(pdata->clustered_irq);
+	else {
+		for (i = 0; i < pdata->num_row_gpios; i++)
+			enable_irq(gpio_to_irq(pdata->row_gpios[i]));
+	}
 }
 
 static void disable_row_irqs(struct matrix_keypad *keypad)
@@ -96,8 +101,12 @@ static void disable_row_irqs(struct matrix_keypad *keypad)
 	const struct matrix_keypad_platform_data *pdata = keypad->pdata;
 	int i;
 
-	for (i = 0; i < pdata->num_row_gpios; i++)
-		disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i]));
+	if (pdata->clustered_irq > 0)
+		disable_irq_nosync(pdata->clustered_irq);
+	else {
+		for (i = 0; i < pdata->num_row_gpios; i++)
+			disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i]));
+	}
 }
 
 /*
@@ -216,25 +225,74 @@ static void matrix_keypad_stop(struct input_dev *dev)
 }
 
 #ifdef CONFIG_PM
-static int matrix_keypad_suspend(struct device *dev)
+static inline void __suspend_keypad(struct matrix_keypad *keypad)
 {
-	struct platform_device *pdev = to_platform_device(dev);
-	struct matrix_keypad *keypad = platform_get_drvdata(pdev);
 	const struct matrix_keypad_platform_data *pdata = keypad->pdata;
+	unsigned int cirq = pdata->clustered_irq;
+	unsigned int gpio;
+	unsigned long flags;
 	int i;
 
-	matrix_keypad_stop(keypad->input_dev);
+	spin_lock_irqsave(&keypad->lock, flags);
 
-	if (device_may_wakeup(&pdev->dev)) {
-		for (i = 0; i < pdata->num_row_gpios; i++) {
-			if (!test_bit(i, keypad->disabled_gpios)) {
-				unsigned int gpio = pdata->row_gpios[i];
+	if (pdata->clustered_irq > 0) {
+		if (enable_irq_wake(cirq) == 0)
+			keypad->gpio_all_disabled = true;
 
-				if (enable_irq_wake(gpio_to_irq(gpio)) == 0)
-					__set_bit(i, keypad->disabled_gpios);
-			}
+		goto out;
+	}
+
+	for (i = 0; i < pdata->num_row_gpios; i++) {
+		if (!test_bit(i, keypad->disabled_gpios)) {
+			gpio = pdata->row_gpios[i];
+
+			if (enable_irq_wake(gpio_to_irq(gpio)) == 0)
+				__set_bit(i, keypad->disabled_gpios);
+		}
+	}
+out:
+	spin_unlock_irqrestore(&keypad->lock, flags);
+}
+
+static inline void __resume_keypad(struct matrix_keypad *keypad)
+{
+	const struct matrix_keypad_platform_data *pdata = keypad->pdata;
+	unsigned int cirq = pdata->clustered_irq;
+	unsigned int gpio;
+	unsigned long flags;
+	int i;
+
+	spin_lock_irqsave(&keypad->lock, flags);
+
+	if (pdata->clustered_irq > 0) {
+		if (keypad->gpio_all_disabled) {
+			disable_irq_wake(cirq);
+			keypad->gpio_all_disabled = false;
+		}
+
+		goto out;
+	}
+
+	for (i = 0; i < pdata->num_row_gpios; i++) {
+		if (test_and_clear_bit(i, keypad->disabled_gpios)) {
+			gpio = pdata->row_gpios[i];
+			disable_irq_wake(gpio_to_irq(gpio));
 		}
 	}
+out:
+	spin_unlock_irqrestore(&keypad->lock, flags);
+
+}
+
+static int matrix_keypad_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct matrix_keypad *keypad = platform_get_drvdata(pdev);
+
+	matrix_keypad_stop(keypad->input_dev);
+
+	if (device_may_wakeup(&pdev->dev))
+		__suspend_keypad(keypad);
 
 	return 0;
 }
@@ -246,15 +304,8 @@ static int matrix_keypad_resume(struct device *dev)
 	const struct matrix_keypad_platform_data *pdata = keypad->pdata;
 	int i;
 
-	if (device_may_wakeup(&pdev->dev)) {
-		for (i = 0; i < pdata->num_row_gpios; i++) {
-			if (test_and_clear_bit(i, keypad->disabled_gpios)) {
-				unsigned int gpio = pdata->row_gpios[i];
-
-				disable_irq_wake(gpio_to_irq(gpio));
-			}
-		}
-	}
+	if (device_may_wakeup(&pdev->dev))
+		__resume_keypad(keypad);
 
 	matrix_keypad_start(keypad->input_dev);
 
@@ -296,17 +347,31 @@ static int __devinit init_matrix_gpio(struct platform_device *pdev,
 		gpio_direction_input(pdata->row_gpios[i]);
 	}
 
-	for (i = 0; i < pdata->num_row_gpios; i++) {
-		err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
+	if (pdata->clustered_irq > 0) {
+		err = request_irq(pdata->clustered_irq,
 				matrix_keypad_interrupt,
-				IRQF_DISABLED |
-				IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+				pdata->clustered_irq_flags,
 				"matrix-keypad", keypad);
 		if (err) {
 			dev_err(&pdev->dev,
-				"Unable to acquire interrupt for GPIO line %i\n",
-				pdata->row_gpios[i]);
-			goto err_free_irqs;
+				"Unable to acquire clustered interrupt\n");
+			goto err_free_rows;
+		}
+	} else {
+		for (i = 0; i < pdata->num_row_gpios; i++) {
+			err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
+					matrix_keypad_interrupt,
+					IRQF_DISABLED |
+					IRQF_TRIGGER_RISING |
+					IRQF_TRIGGER_FALLING,
+					"matrix-keypad", keypad);
+			if (err) {
+				dev_err(&pdev->dev,
+					"Unable to acquire interrupt "
+					"for GPIO line %i\n",
+					pdata->row_gpios[i]);
+				goto err_free_irqs;
+			}
 		}
 	}
 
@@ -418,11 +483,16 @@ static int __devexit matrix_keypad_remove(struct platform_device *pdev)
 
 	device_init_wakeup(&pdev->dev, 0);
 
-	for (i = 0; i < pdata->num_row_gpios; i++) {
-		free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
-		gpio_free(pdata->row_gpios[i]);
+	if (pdata->clustered_irq > 0) {
+		free_irq(pdata->clustered_irq, keypad);
+	} else {
+		for (i = 0; i < pdata->num_row_gpios; i++)
+			free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
 	}
 
+	for (i = 0; i < pdata->num_row_gpios; i++)
+		gpio_free(pdata->row_gpios[i]);
+
 	for (i = 0; i < pdata->num_col_gpios; i++)
 		gpio_free(pdata->col_gpios[i]);
 
diff --git a/include/linux/input/matrix_keypad.h b/include/linux/input/matrix_keypad.h
index c964cd7..8e8dc2e 100644
--- a/include/linux/input/matrix_keypad.h
+++ b/include/linux/input/matrix_keypad.h
@@ -63,6 +63,11 @@ struct matrix_keypad_platform_data {
 	/* key debounce interval in milli-second */
 	unsigned int	debounce_ms;
 
+	/* used if interrupts of all row/column GPIOs are bundled to one single
+	 * irq */
+	unsigned int	clustered_irq;
+	unsigned int	clustered_irq_flags;
+
 	bool		active_low;
 	bool		wakeup;
 	bool		no_autorepeat;
-- 
1.7.0

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

* Re: [PATCH V2] matrix_keypad: add support for clustered irq
  2010-05-27  6:43 ` [PATCH V2] " Luotao Fu
@ 2010-05-27 15:14   ` Eric Miao
  2010-06-10 19:32     ` Dmitry Torokhov
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Miao @ 2010-05-27 15:14 UTC (permalink / raw)
  To: Luotao Fu; +Cc: Dmitry Torokhov, Marek Vasut, linux-kernel, linux-input

On Thu, May 27, 2010 at 2:43 PM, Luotao Fu <l.fu@pengutronix.de> wrote:
> This one adds support of a combined irq source for the whole matrix keypad.
> This can be useful if all rows and columns of the keypad are e.g. connected
> to a GPIO expander, which only has one interrupt line for all events on
> every single GPIO.
>
> Signed-off-by: Luotao Fu <l.fu@pengutronix.de>

I feel OK. Acked-by: Eric Miao <eric.y.miao@gmail.com>

> ---
> V2 Changes:
> * create separate functions for suspend/resume calls.
> * add bool flag to signal enable/disable state of all gpios.
> * add spinlock to suspend and resume callbacks.
>
>  drivers/input/keyboard/matrix_keypad.c |  138 ++++++++++++++++++++++++--------
>  include/linux/input/matrix_keypad.h    |    5 +
>  2 files changed, 109 insertions(+), 34 deletions(-)
>
> diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
> index b443e08..99b7204 100644
> --- a/drivers/input/keyboard/matrix_keypad.c
> +++ b/drivers/input/keyboard/matrix_keypad.c
> @@ -37,6 +37,7 @@ struct matrix_keypad {
>        spinlock_t lock;
>        bool scan_pending;
>        bool stopped;
> +       bool gpio_all_disabled;
>  };
>
>  /*
> @@ -87,8 +88,12 @@ static void enable_row_irqs(struct matrix_keypad *keypad)
>        const struct matrix_keypad_platform_data *pdata = keypad->pdata;
>        int i;
>
> -       for (i = 0; i < pdata->num_row_gpios; i++)
> -               enable_irq(gpio_to_irq(pdata->row_gpios[i]));
> +       if (pdata->clustered_irq > 0)
> +               enable_irq(pdata->clustered_irq);
> +       else {
> +               for (i = 0; i < pdata->num_row_gpios; i++)
> +                       enable_irq(gpio_to_irq(pdata->row_gpios[i]));
> +       }
>  }
>
>  static void disable_row_irqs(struct matrix_keypad *keypad)
> @@ -96,8 +101,12 @@ static void disable_row_irqs(struct matrix_keypad *keypad)
>        const struct matrix_keypad_platform_data *pdata = keypad->pdata;
>        int i;
>
> -       for (i = 0; i < pdata->num_row_gpios; i++)
> -               disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i]));
> +       if (pdata->clustered_irq > 0)
> +               disable_irq_nosync(pdata->clustered_irq);
> +       else {
> +               for (i = 0; i < pdata->num_row_gpios; i++)
> +                       disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i]));
> +       }
>  }
>
>  /*
> @@ -216,25 +225,74 @@ static void matrix_keypad_stop(struct input_dev *dev)
>  }
>
>  #ifdef CONFIG_PM
> -static int matrix_keypad_suspend(struct device *dev)
> +static inline void __suspend_keypad(struct matrix_keypad *keypad)
>  {
> -       struct platform_device *pdev = to_platform_device(dev);
> -       struct matrix_keypad *keypad = platform_get_drvdata(pdev);
>        const struct matrix_keypad_platform_data *pdata = keypad->pdata;
> +       unsigned int cirq = pdata->clustered_irq;
> +       unsigned int gpio;
> +       unsigned long flags;
>        int i;
>
> -       matrix_keypad_stop(keypad->input_dev);
> +       spin_lock_irqsave(&keypad->lock, flags);
>
> -       if (device_may_wakeup(&pdev->dev)) {
> -               for (i = 0; i < pdata->num_row_gpios; i++) {
> -                       if (!test_bit(i, keypad->disabled_gpios)) {
> -                               unsigned int gpio = pdata->row_gpios[i];
> +       if (pdata->clustered_irq > 0) {
> +               if (enable_irq_wake(cirq) == 0)
> +                       keypad->gpio_all_disabled = true;
>
> -                               if (enable_irq_wake(gpio_to_irq(gpio)) == 0)
> -                                       __set_bit(i, keypad->disabled_gpios);
> -                       }
> +               goto out;
> +       }
> +
> +       for (i = 0; i < pdata->num_row_gpios; i++) {
> +               if (!test_bit(i, keypad->disabled_gpios)) {
> +                       gpio = pdata->row_gpios[i];
> +
> +                       if (enable_irq_wake(gpio_to_irq(gpio)) == 0)
> +                               __set_bit(i, keypad->disabled_gpios);
> +               }
> +       }
> +out:
> +       spin_unlock_irqrestore(&keypad->lock, flags);
> +}
> +
> +static inline void __resume_keypad(struct matrix_keypad *keypad)
> +{
> +       const struct matrix_keypad_platform_data *pdata = keypad->pdata;
> +       unsigned int cirq = pdata->clustered_irq;
> +       unsigned int gpio;
> +       unsigned long flags;
> +       int i;
> +
> +       spin_lock_irqsave(&keypad->lock, flags);
> +
> +       if (pdata->clustered_irq > 0) {
> +               if (keypad->gpio_all_disabled) {
> +                       disable_irq_wake(cirq);
> +                       keypad->gpio_all_disabled = false;
> +               }
> +
> +               goto out;
> +       }
> +
> +       for (i = 0; i < pdata->num_row_gpios; i++) {
> +               if (test_and_clear_bit(i, keypad->disabled_gpios)) {
> +                       gpio = pdata->row_gpios[i];
> +                       disable_irq_wake(gpio_to_irq(gpio));
>                }
>        }
> +out:
> +       spin_unlock_irqrestore(&keypad->lock, flags);
> +
> +}
> +
> +static int matrix_keypad_suspend(struct device *dev)
> +{
> +       struct platform_device *pdev = to_platform_device(dev);
> +       struct matrix_keypad *keypad = platform_get_drvdata(pdev);
> +
> +       matrix_keypad_stop(keypad->input_dev);
> +
> +       if (device_may_wakeup(&pdev->dev))
> +               __suspend_keypad(keypad);
>
>        return 0;
>  }
> @@ -246,15 +304,8 @@ static int matrix_keypad_resume(struct device *dev)
>        const struct matrix_keypad_platform_data *pdata = keypad->pdata;
>        int i;
>
> -       if (device_may_wakeup(&pdev->dev)) {
> -               for (i = 0; i < pdata->num_row_gpios; i++) {
> -                       if (test_and_clear_bit(i, keypad->disabled_gpios)) {
> -                               unsigned int gpio = pdata->row_gpios[i];
> -
> -                               disable_irq_wake(gpio_to_irq(gpio));
> -                       }
> -               }
> -       }
> +       if (device_may_wakeup(&pdev->dev))
> +               __resume_keypad(keypad);
>
>        matrix_keypad_start(keypad->input_dev);
>
> @@ -296,17 +347,31 @@ static int __devinit init_matrix_gpio(struct platform_device *pdev,
>                gpio_direction_input(pdata->row_gpios[i]);
>        }
>
> -       for (i = 0; i < pdata->num_row_gpios; i++) {
> -               err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
> +       if (pdata->clustered_irq > 0) {
> +               err = request_irq(pdata->clustered_irq,
>                                matrix_keypad_interrupt,
> -                               IRQF_DISABLED |
> -                               IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
> +                               pdata->clustered_irq_flags,
>                                "matrix-keypad", keypad);
>                if (err) {
>                        dev_err(&pdev->dev,
> -                               "Unable to acquire interrupt for GPIO line %i\n",
> -                               pdata->row_gpios[i]);
> -                       goto err_free_irqs;
> +                               "Unable to acquire clustered interrupt\n");
> +                       goto err_free_rows;
> +               }
> +       } else {
> +               for (i = 0; i < pdata->num_row_gpios; i++) {
> +                       err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
> +                                       matrix_keypad_interrupt,
> +                                       IRQF_DISABLED |
> +                                       IRQF_TRIGGER_RISING |
> +                                       IRQF_TRIGGER_FALLING,
> +                                       "matrix-keypad", keypad);
> +                       if (err) {
> +                               dev_err(&pdev->dev,
> +                                       "Unable to acquire interrupt "
> +                                       "for GPIO line %i\n",
> +                                       pdata->row_gpios[i]);
> +                               goto err_free_irqs;
> +                       }
>                }
>        }
>
> @@ -418,11 +483,16 @@ static int __devexit matrix_keypad_remove(struct platform_device *pdev)
>
>        device_init_wakeup(&pdev->dev, 0);
>
> -       for (i = 0; i < pdata->num_row_gpios; i++) {
> -               free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
> -               gpio_free(pdata->row_gpios[i]);
> +       if (pdata->clustered_irq > 0) {
> +               free_irq(pdata->clustered_irq, keypad);
> +       } else {
> +               for (i = 0; i < pdata->num_row_gpios; i++)
> +                       free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
>        }
>
> +       for (i = 0; i < pdata->num_row_gpios; i++)
> +               gpio_free(pdata->row_gpios[i]);
> +
>        for (i = 0; i < pdata->num_col_gpios; i++)
>                gpio_free(pdata->col_gpios[i]);
>
> diff --git a/include/linux/input/matrix_keypad.h b/include/linux/input/matrix_keypad.h
> index c964cd7..8e8dc2e 100644
> --- a/include/linux/input/matrix_keypad.h
> +++ b/include/linux/input/matrix_keypad.h
> @@ -63,6 +63,11 @@ struct matrix_keypad_platform_data {
>        /* key debounce interval in milli-second */
>        unsigned int    debounce_ms;
>
> +       /* used if interrupts of all row/column GPIOs are bundled to one single
> +        * irq */
> +       unsigned int    clustered_irq;
> +       unsigned int    clustered_irq_flags;
> +
>        bool            active_low;
>        bool            wakeup;
>        bool            no_autorepeat;
> --
> 1.7.0
>
>

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

* Re: [PATCH V2] matrix_keypad: add support for clustered irq
  2010-05-27 15:14   ` Eric Miao
@ 2010-06-10 19:32     ` Dmitry Torokhov
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2010-06-10 19:32 UTC (permalink / raw)
  To: Eric Miao; +Cc: Luotao Fu, Marek Vasut, linux-kernel, linux-input

On Thursday, May 27, 2010 08:14:50 am Eric Miao wrote:
> On Thu, May 27, 2010 at 2:43 PM, Luotao Fu <l.fu@pengutronix.de> wrote:
> > This one adds support of a combined irq source for the whole matrix keypad.
> > This can be useful if all rows and columns of the keypad are e.g. connected
> > to a GPIO expander, which only has one interrupt line for all events on
> > every single GPIO.
> >
> > Signed-off-by: Luotao Fu <l.fu@pengutronix.de>
> 
> I feel OK. Acked-by: Eric Miao <eric.y.miao@gmail.com>
> 
> > ---
> > V2 Changes:
> > * create separate functions for suspend/resume calls.
> > * add bool flag to signal enable/disable state of all gpios.
> > * add spinlock to suspend and resume callbacks.

The spinlock is not needed, it should be OK to get interrupted in the middle
of setting up wakeup sources. The enable/disable irq is different as if we
get interrupted in the middle of the process our counters will get messed
up.

Fixed a few compile warnings and applied for .36.

Thanks.

-- 
Dmitry

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

end of thread, other threads:[~2010-06-10 19:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-26 13:57 [PATCH] matrix_keypad: add support for clustered irq Luotao Fu
2010-05-26 14:29 ` Eric Miao
2010-05-26 14:38   ` Luotao Fu
2010-05-27  6:43 ` [PATCH V2] " Luotao Fu
2010-05-27 15:14   ` Eric Miao
2010-06-10 19:32     ` Dmitry Torokhov

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