Skip to content

Commit 8cf4b36

Browse files
committed
Input: matrix_keypad - consolidate handling of clustered interrupt
Now that the driver stores interrupt numbers corresponding to individual GPIOs in non-clustered mode, it is possible to unify handling of both modes by storing clustered interrupt at position 0 and setting the number of interrupts in this case to 1. Link: https://lore.kernel.org/r/20240121053232.276968-2-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent a96fb71 commit 8cf4b36

File tree

1 file changed

+20
-43
lines changed

1 file changed

+20
-43
lines changed

drivers/input/keyboard/matrix_keypad.c

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ struct matrix_keypad {
2727
const struct matrix_keypad_platform_data *pdata;
2828
struct input_dev *input_dev;
2929
unsigned int row_shift;
30-
unsigned int row_irqs[MATRIX_MAX_ROWS];
3130

32-
DECLARE_BITMAP(disabled_gpios, MATRIX_MAX_ROWS);
31+
unsigned int row_irqs[MATRIX_MAX_ROWS];
32+
unsigned int num_row_irqs;
33+
DECLARE_BITMAP(wakeup_enabled_irqs, MATRIX_MAX_ROWS);
3334

3435
uint32_t last_key_state[MATRIX_MAX_COLS];
3536
struct delayed_work work;
@@ -86,28 +87,18 @@ static bool row_asserted(const struct matrix_keypad_platform_data *pdata,
8687

8788
static void enable_row_irqs(struct matrix_keypad *keypad)
8889
{
89-
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
9090
int i;
9191

92-
if (pdata->clustered_irq > 0)
93-
enable_irq(pdata->clustered_irq);
94-
else {
95-
for (i = 0; i < pdata->num_row_gpios; i++)
96-
enable_irq(keypad->row_irqs[i]);
97-
}
92+
for (i = 0; i < keypad->num_row_irqs; i++)
93+
enable_irq(keypad->row_irqs[i]);
9894
}
9995

10096
static void disable_row_irqs(struct matrix_keypad *keypad)
10197
{
102-
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
10398
int i;
10499

105-
if (pdata->clustered_irq > 0)
106-
disable_irq_nosync(pdata->clustered_irq);
107-
else {
108-
for (i = 0; i < pdata->num_row_gpios; i++)
109-
disable_irq_nosync(keypad->row_irqs[i]);
110-
}
100+
for (i = 0; i < keypad->num_row_irqs; i++)
101+
disable_irq_nosync(keypad->row_irqs[i]);
111102
}
112103

113104
/*
@@ -233,35 +224,20 @@ static void matrix_keypad_stop(struct input_dev *dev)
233224

234225
static void matrix_keypad_enable_wakeup(struct matrix_keypad *keypad)
235226
{
236-
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
237227
int i;
238228

239-
if (pdata->clustered_irq > 0) {
240-
if (enable_irq_wake(pdata->clustered_irq) == 0)
241-
keypad->gpio_all_disabled = true;
242-
} else {
243-
244-
for (i = 0; i < pdata->num_row_gpios; i++)
245-
if (!test_bit(i, keypad->disabled_gpios))
246-
if (enable_irq_wake(keypad->row_irqs[i]) == 0)
247-
__set_bit(i, keypad->disabled_gpios);
248-
}
229+
for_each_clear_bit(i, keypad->wakeup_enabled_irqs, keypad->num_row_irqs)
230+
if (enable_irq_wake(keypad->row_irqs[i]) == 0)
231+
__set_bit(i, keypad->wakeup_enabled_irqs);
249232
}
250233

251234
static void matrix_keypad_disable_wakeup(struct matrix_keypad *keypad)
252235
{
253-
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
254236
int i;
255237

256-
if (pdata->clustered_irq > 0) {
257-
if (keypad->gpio_all_disabled) {
258-
disable_irq_wake(pdata->clustered_irq);
259-
keypad->gpio_all_disabled = false;
260-
}
261-
} else {
262-
for (i = 0; i < pdata->num_row_gpios; i++)
263-
if (test_and_clear_bit(i, keypad->disabled_gpios))
264-
disable_irq_wake(keypad->row_irqs[i]);
238+
for_each_set_bit(i, keypad->wakeup_enabled_irqs, keypad->num_row_irqs) {
239+
disable_irq_wake(keypad->row_irqs[i]);
240+
__clear_bit(i, keypad->wakeup_enabled_irqs);
265241
}
266242
}
267243

@@ -335,6 +311,9 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,
335311
"Unable to acquire clustered interrupt\n");
336312
goto err_free_rows;
337313
}
314+
315+
keypad->row_irqs[0] = pdata->clustered_irq;
316+
keypad->num_row_irqs = 1;
338317
} else {
339318
for (i = 0; i < pdata->num_row_gpios; i++) {
340319
irq = gpio_to_irq(pdata->row_gpios[i]);
@@ -360,6 +339,8 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,
360339

361340
keypad->row_irqs[i] = irq;
362341
}
342+
343+
keypad->num_row_irqs = pdata->num_row_gpios;
363344
}
364345

365346
/* initialized as disabled - enabled by input->open */
@@ -386,12 +367,8 @@ static void matrix_keypad_free_gpio(struct matrix_keypad *keypad)
386367
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
387368
int i;
388369

389-
if (pdata->clustered_irq > 0) {
390-
free_irq(pdata->clustered_irq, keypad);
391-
} else {
392-
for (i = 0; i < pdata->num_row_gpios; i++)
393-
free_irq(keypad->row_irqs[i], keypad);
394-
}
370+
for (i = 0; i < keypad->num_row_irqs; i++)
371+
free_irq(keypad->row_irqs[i], keypad);
395372

396373
for (i = 0; i < pdata->num_row_gpios; i++)
397374
gpio_free(pdata->row_gpios[i]);

0 commit comments

Comments
 (0)