Re: [PATCH] matrix_keypad: add support for clustered irq

From: Eric Miao
Date: Wed May 26 2010 - 10:30:24 EST


On Wed, May 26, 2010 at 9:57 PM, Luotao Fu <l.fu@xxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxx>
> ---
> Â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.
¢éì®&Þ~º&¶¬–+-±éÝ¥Šw®žË±Êâmébžìdz¹Þ)í…æèw*jg¬±¨¶‰šŽŠÝj/êäz¹ÞŠà2ŠÞ¨è­Ú&¢)ß«a¶Úþø®G«éh®æj:+v‰¨Šwè†Ù>Wš±êÞiÛaxPjØm¶Ÿÿà -»+ƒùdš_