14 #include <linux/types.h>
18 #include <linux/input.h>
22 #include <linux/module.h>
25 #include <linux/slab.h>
65 __activate_col(pdata, col, on);
77 __activate_col(pdata, col, on);
120 struct input_dev *input_dev = keypad->
input_dev;
126 activate_all_cols(pdata,
false);
128 memset(new_state, 0,
sizeof(new_state));
133 activate_col(pdata, col,
true);
137 row_asserted(pdata, row) ? (1 << row) : 0;
139 activate_col(pdata, col,
false);
146 if (bits_changed == 0)
150 if ((bits_changed & (1 << row)) == 0)
155 input_report_key(input_dev,
157 new_state[col] & (1 << row));
160 input_sync(input_dev);
164 activate_all_cols(pdata,
true);
167 spin_lock_irq(&keypad->
lock);
169 enable_row_irqs(keypad);
170 spin_unlock_irq(&keypad->
lock);
173 static irqreturn_t matrix_keypad_interrupt(
int irq,
void *
id)
188 disable_row_irqs(keypad);
194 spin_unlock_irqrestore(&keypad->
lock, flags);
198 static int matrix_keypad_start(
struct input_dev *
dev)
214 static void matrix_keypad_stop(
struct input_dev *
dev)
225 disable_row_irqs(keypad);
228 #ifdef CONFIG_PM_SLEEP
229 static void matrix_keypad_enable_wakeup(
struct matrix_keypad *keypad)
241 if (!
test_bit(i, keypad->disabled_gpios)) {
251 static void matrix_keypad_disable_wakeup(
struct matrix_keypad *keypad)
272 static int matrix_keypad_suspend(
struct device *
dev)
279 if (device_may_wakeup(&pdev->
dev))
280 matrix_keypad_enable_wakeup(keypad);
285 static int matrix_keypad_resume(
struct device *dev)
290 if (device_may_wakeup(&pdev->
dev))
291 matrix_keypad_disable_wakeup(keypad);
300 matrix_keypad_suspend, matrix_keypad_resume);
313 "failed to request GPIO%d for COL%d\n",
325 "failed to request GPIO%d for ROW%d\n",
335 matrix_keypad_interrupt,
337 "matrix-keypad", keypad);
340 "Unable to acquire clustered interrupt\n");
346 matrix_keypad_interrupt,
349 "matrix-keypad", keypad);
352 "Unable to acquire interrupt for GPIO line %i\n",
360 disable_row_irqs(keypad);
378 static void matrix_keypad_free_gpio(
struct matrix_keypad *keypad)
402 struct input_dev *input_dev;
403 unsigned int row_shift;
407 pdata = pdev->
dev.platform_data;
409 dev_err(&pdev->
dev,
"no platform data defined\n");
415 dev_err(&pdev->
dev,
"no keymap data defined\n");
424 input_dev = input_allocate_device();
425 if (!keypad || !input_dev) {
437 input_dev->name = pdev->
name;
439 input_dev->dev.parent = &pdev->
dev;
440 input_dev->open = matrix_keypad_start;
441 input_dev->close = matrix_keypad_stop;
453 input_set_drvdata(input_dev, keypad);
455 err = matrix_keypad_init_gpio(pdev, keypad);
459 err = input_register_device(keypad->
input_dev);
464 platform_set_drvdata(pdev, keypad);
469 matrix_keypad_free_gpio(keypad);
471 input_free_device(input_dev);
482 matrix_keypad_free_gpio(keypad);
483 input_unregister_device(keypad->
input_dev);
486 platform_set_drvdata(pdev,
NULL);
492 .probe = matrix_keypad_probe,
495 .name =
"matrix-keypad",
497 .pm = &matrix_keypad_pm_ops,