From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.6.y 2/6] Input: matrix_keypad - avoid repeatedly converting GPIO to IRQ
Date: Tue, 10 Nov 2026 21:03:37 -0500 [thread overview]
Message-ID: <20261111020056.444668-2-sashal@kernel.org> (raw)
In-Reply-To: <20261111020056.444668-1-sashal@kernel.org>
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
[ Upstream commit a96fb711c6be76bcfbcf594a865002fa7c0eb525 ]
There is no need to do conversion from GPIOs to interrupt numbers.
Convert row GPIOs to interrupt numbers once in probe() and use
this information when the driver needs to enable or disable given
interrupt line.
Link: https://lore.kernel.org/r/20240121053232.276968-1-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Stable-dep-of: 1527451f87df ("Revert "Input: matrix_keypad - force switch rows to input mode"")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/input/keyboard/matrix_keypad.c | 48 ++++++++++++++------------
1 file changed, 25 insertions(+), 23 deletions(-)
diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
index 50fa764c82d2b..1cd1ffb80401a 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -27,6 +27,7 @@ struct matrix_keypad {
const struct matrix_keypad_platform_data *pdata;
struct input_dev *input_dev;
unsigned int row_shift;
+ unsigned int row_irqs[MATRIX_MAX_ROWS];
DECLARE_BITMAP(disabled_gpios, MATRIX_MAX_ROWS);
@@ -92,7 +93,7 @@ static void enable_row_irqs(struct matrix_keypad *keypad)
enable_irq(pdata->clustered_irq);
else {
for (i = 0; i < pdata->num_row_gpios; i++)
- enable_irq(gpio_to_irq(pdata->row_gpios[i]));
+ enable_irq(keypad->row_irqs[i]);
}
}
@@ -105,7 +106,7 @@ static void disable_row_irqs(struct matrix_keypad *keypad)
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]));
+ disable_irq_nosync(keypad->row_irqs[i]);
}
}
@@ -233,7 +234,6 @@ static void matrix_keypad_stop(struct input_dev *dev)
static void matrix_keypad_enable_wakeup(struct matrix_keypad *keypad)
{
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
- unsigned int gpio;
int i;
if (pdata->clustered_irq > 0) {
@@ -241,21 +241,16 @@ static void matrix_keypad_enable_wakeup(struct matrix_keypad *keypad)
keypad->gpio_all_disabled = true;
} else {
- 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)
+ for (i = 0; i < pdata->num_row_gpios; i++)
+ if (!test_bit(i, keypad->disabled_gpios))
+ if (enable_irq_wake(keypad->row_irqs[i]) == 0)
__set_bit(i, keypad->disabled_gpios);
- }
- }
}
}
static void matrix_keypad_disable_wakeup(struct matrix_keypad *keypad)
{
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
- unsigned int gpio;
int i;
if (pdata->clustered_irq > 0) {
@@ -264,12 +259,9 @@ static void matrix_keypad_disable_wakeup(struct matrix_keypad *keypad)
keypad->gpio_all_disabled = false;
}
} else {
- 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));
- }
- }
+ for (i = 0; i < pdata->num_row_gpios; i++)
+ if (test_and_clear_bit(i, keypad->disabled_gpios))
+ disable_irq_wake(keypad->row_irqs[i]);
}
}
@@ -306,7 +298,7 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,
struct matrix_keypad *keypad)
{
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
- int i, err;
+ int i, irq, err;
/* initialized strobe lines as outputs, activated */
for (i = 0; i < pdata->num_col_gpios; i++) {
@@ -345,11 +337,19 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,
}
} else {
for (i = 0; i < pdata->num_row_gpios; i++) {
- err = request_any_context_irq(
- gpio_to_irq(pdata->row_gpios[i]),
+ irq = gpio_to_irq(pdata->row_gpios[i]);
+ if (irq < 0) {
+ err = irq;
+ dev_err(&pdev->dev,
+ "Unable to convert GPIO line %i to irq: %d\n",
+ pdata->row_gpios[i], err);
+ goto err_free_irqs;
+ }
+
+ err = request_any_context_irq(irq,
matrix_keypad_interrupt,
IRQF_TRIGGER_RISING |
- IRQF_TRIGGER_FALLING,
+ IRQF_TRIGGER_FALLING,
"matrix-keypad", keypad);
if (err < 0) {
dev_err(&pdev->dev,
@@ -357,6 +357,8 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,
pdata->row_gpios[i]);
goto err_free_irqs;
}
+
+ keypad->row_irqs[i] = irq;
}
}
@@ -366,7 +368,7 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,
err_free_irqs:
while (--i >= 0)
- free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
+ free_irq(keypad->row_irqs[i], keypad);
i = pdata->num_row_gpios;
err_free_rows:
while (--i >= 0)
@@ -388,7 +390,7 @@ static void matrix_keypad_free_gpio(struct matrix_keypad *keypad)
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);
+ free_irq(keypad->row_irqs[i], keypad);
}
for (i = 0; i < pdata->num_row_gpios; i++)
--
2.53.0
next prev parent reply other threads:[~2026-11-11 2:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 10:36 FAILED: patch "[PATCH] Revert "Input: matrix_keypad - force switch rows to input mode"" failed to apply to 6.6-stable tree Sasha Levin
2026-11-11 2:03 ` [PATCH 6.6.y 1/6] Input: matrix_keypad - convert to platform remove callback returning void Sasha Levin
2026-11-11 2:03 ` Sasha Levin [this message]
2026-11-11 2:03 ` [PATCH 6.6.y 3/6] Input: matrix_keypad - consolidate handling of clustered interrupt Sasha Levin
2026-11-11 2:03 ` [PATCH 6.6.y 4/6] Input: matrix_keypad - switch to using managed resources Sasha Levin
2026-11-11 2:03 ` [PATCH 6.6.y 5/6] Input: matrix_keypad - remove support for clustered interrupt Sasha Levin
2026-11-11 2:03 ` [PATCH 6.6.y 6/6] Revert "Input: matrix_keypad - force switch rows to input mode" Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261111020056.444668-2-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox