24 #include <linux/module.h>
28 #include <linux/errno.h>
31 #include <linux/input.h>
32 #include <linux/slab.h>
38 #define OMAP4_KBD_REVISION 0x00
39 #define OMAP4_KBD_SYSCONFIG 0x10
40 #define OMAP4_KBD_SYSSTATUS 0x14
41 #define OMAP4_KBD_IRQSTATUS 0x18
42 #define OMAP4_KBD_IRQENABLE 0x1C
43 #define OMAP4_KBD_WAKEUPENABLE 0x20
44 #define OMAP4_KBD_PENDING 0x24
45 #define OMAP4_KBD_CTRL 0x28
46 #define OMAP4_KBD_DEBOUNCINGTIME 0x2C
47 #define OMAP4_KBD_LONGKEYTIME 0x30
48 #define OMAP4_KBD_TIMEOUT 0x34
49 #define OMAP4_KBD_STATEMACHINE 0x38
50 #define OMAP4_KBD_ROWINPUTS 0x3C
51 #define OMAP4_KBD_COLUMNOUTPUTS 0x40
52 #define OMAP4_KBD_FULLCODE31_0 0x44
53 #define OMAP4_KBD_FULLCODE63_32 0x48
56 #define OMAP4_DEF_IRQENABLE_EVENTEN (1 << 0)
57 #define OMAP4_DEF_IRQENABLE_LONGKEY (1 << 1)
58 #define OMAP4_DEF_IRQENABLE_TIMEOUTEN (1 << 2)
59 #define OMAP4_DEF_WUP_EVENT_ENA (1 << 0)
60 #define OMAP4_DEF_WUP_LONG_KEY_ENA (1 << 1)
61 #define OMAP4_DEF_CTRL_NOSOFTMODE (1 << 1)
62 #define OMAP4_DEF_CTRLPTVVALUE (1 << 2)
63 #define OMAP4_DEF_CTRLPTV (1 << 1)
66 #define OMAP4_VAL_IRQDISABLE 0x00
67 #define OMAP4_VAL_DEBOUNCINGTIME 0x07
68 #define OMAP4_VAL_FUNCTIONALCFG 0x1E
70 #define OMAP4_MASK_IRQSTATUSDISABLE 0xFFFF
123 struct input_dev *input_dev = keypad_data->
input;
135 for (row = 0; row < keypad_data->
rows; row++) {
136 changed = key_state[row] ^ keypad_data->
key_state[row];
140 for (col = 0; col < keypad_data->
cols; col++) {
141 if (changed & (1 << col)) {
145 input_report_key(input_dev,
146 keypad_data->
keymap[code],
147 key_state[row] & (1 << col));
152 input_sync(input_dev);
169 static int omap4_keypad_open(
struct input_dev *
input)
171 struct omap4_keypad *keypad_data = input_get_drvdata(input);
173 pm_runtime_get_sync(input->dev.parent);
194 static void omap4_keypad_close(
struct input_dev *
input)
196 struct omap4_keypad *keypad_data = input_get_drvdata(input);
210 pm_runtime_put_sync(input->dev.parent);
220 dev_err(dev,
"missing DT data");
224 of_property_read_u32(np,
"keypad,num-rows", &keypad_data->
rows);
225 of_property_read_u32(np,
"keypad,num-columns", &keypad_data->
cols);
226 if (!keypad_data->
rows || !keypad_data->
cols) {
227 dev_err(dev,
"number of keypad rows/columns not specified\n");
237 static inline int omap4_keypad_parse_dt(
struct device *dev,
247 dev_get_platdata(&pdev->
dev);
251 struct input_dev *input_dev;
253 unsigned int max_keys;
260 dev_err(&pdev->
dev,
"no base address specified\n");
266 dev_err(&pdev->
dev,
"no keyboard irq assigned\n");
272 dev_err(&pdev->
dev,
"keypad_data memory allocation failed\n");
276 keypad_data->
irq = irq;
282 error = omap4_keypad_parse_dt(&pdev->
dev, keypad_data);
289 dev_err(&pdev->
dev,
"can't request mem region\n");
291 goto err_free_keypad;
295 if (!keypad_data->
base) {
296 dev_err(&pdev->
dev,
"can't ioremap mem resource\n");
298 goto err_release_mem;
307 error = pm_runtime_get_sync(&pdev->
dev);
309 dev_err(&pdev->
dev,
"pm_runtime_get_sync() failed\n");
326 "Keypad reports unsupported revision %d", rev);
328 goto err_pm_put_sync;
332 keypad_data->
input = input_dev = input_allocate_device();
335 goto err_pm_put_sync;
338 input_dev->name = pdev->
name;
339 input_dev->dev.parent = &pdev->
dev;
341 input_dev->id.vendor = 0x0001;
342 input_dev->id.product = 0x0001;
343 input_dev->id.version = 0x0001;
345 input_dev->open = omap4_keypad_open;
346 input_dev->close = omap4_keypad_close;
352 input_set_drvdata(input_dev, keypad_data);
356 keypad_data->
keymap = kzalloc(max_keys *
sizeof(keypad_data->
keymap[0]),
358 if (!keypad_data->
keymap) {
359 dev_err(&pdev->
dev,
"Not enough memory for keymap\n");
365 keypad_data->
rows, keypad_data->
cols,
366 keypad_data->
keymap, input_dev);
368 dev_err(&pdev->
dev,
"failed to build keymap\n");
369 goto err_free_keymap;
374 "omap4-keypad", keypad_data);
376 dev_err(&pdev->
dev,
"failed to register interrupt\n");
380 pm_runtime_put_sync(&pdev->
dev);
382 error = input_register_device(keypad_data->
input);
384 dev_err(&pdev->
dev,
"failed to register input device\n");
388 platform_set_drvdata(pdev, keypad_data);
392 pm_runtime_disable(&pdev->
dev);
397 input_free_device(input_dev);
399 pm_runtime_put_sync(&pdev->
dev);
411 struct omap4_keypad *keypad_data = platform_get_drvdata(pdev);
416 pm_runtime_disable(&pdev->
dev);
418 input_unregister_device(keypad_data->
input);
428 platform_set_drvdata(pdev,
NULL);
434 static const struct of_device_id omap_keypad_dt_match[] = {
442 .probe = omap4_keypad_probe,
445 .name =
"omap4-keypad",