Lines Matching full:keypad
29 #include <linux/platform_data/keypad-pxa27x.h>
31 * Keypad Controller registers
33 #define KPC 0x0000 /* Keypad Control register */
34 #define KPDK 0x0008 /* Keypad Direct Key register */
35 #define KPREC 0x0010 /* Keypad Rotary Encoder register */
36 #define KPMK 0x0018 /* Keypad Matrix Key register */
37 #define KPAS 0x0020 /* Keypad Automatic Scan register */
39 /* Keypad Automatic Scan Multiple Key Presser register 0-3 */
59 #define KPC_ME (0x1 << 12) /* Matrix Keypad Enable */
61 #define KPC_DK_DEB_SEL (0x1 << 9) /* Direct Keypad Debounce Select */
66 #define KPC_DE (0x1 << 1) /* Direct Keypad Enable */
67 #define KPC_DIE (0x1 << 0) /* Direct Keypad interrupt Enable */
90 #define keypad_readl(off) __raw_readl(keypad->mmio_base + (off))
91 #define keypad_writel(off, v) __raw_writel((v), keypad->mmio_base + (off))
118 static int pxa27x_keypad_matrix_key_parse_dt(struct pxa27x_keypad *keypad, in pxa27x_keypad_matrix_key_parse_dt() argument
121 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_matrix_key_parse_dt()
141 keypad->keycodes, input_dev); in pxa27x_keypad_matrix_key_parse_dt()
148 static int pxa27x_keypad_direct_key_parse_dt(struct pxa27x_keypad *keypad, in pxa27x_keypad_direct_key_parse_dt() argument
151 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_direct_key_parse_dt()
178 * default value. Default value is set when configure the keypad. in pxa27x_keypad_direct_key_parse_dt()
201 keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = code; in pxa27x_keypad_direct_key_parse_dt()
208 static int pxa27x_keypad_rotary_parse_dt(struct pxa27x_keypad *keypad, in pxa27x_keypad_rotary_parse_dt() argument
217 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_rotary_parse_dt()
239 * If the prop is not set, it means keypad does not need in pxa27x_keypad_rotary_parse_dt()
257 keypad->keycodes[n] = keycode; in pxa27x_keypad_rotary_parse_dt()
261 keypad->keycodes[n + 1] = keycode; in pxa27x_keypad_rotary_parse_dt()
275 keypad->rotary_rel_code[0] = pdata->rotary0_rel_code; in pxa27x_keypad_rotary_parse_dt()
276 keypad->rotary_rel_code[1] = pdata->rotary1_rel_code; in pxa27x_keypad_rotary_parse_dt()
281 static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad) in pxa27x_keypad_build_keycode_from_dt() argument
283 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_build_keycode_from_dt()
295 error = pxa27x_keypad_matrix_key_parse_dt(keypad, pdata); in pxa27x_keypad_build_keycode_from_dt()
301 error = pxa27x_keypad_direct_key_parse_dt(keypad, pdata); in pxa27x_keypad_build_keycode_from_dt()
307 error = pxa27x_keypad_rotary_parse_dt(keypad, pdata); in pxa27x_keypad_build_keycode_from_dt()
324 input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); in pxa27x_keypad_build_keycode_from_dt()
326 keypad->pdata = pdata; in pxa27x_keypad_build_keycode_from_dt()
332 static int pxa27x_keypad_build_keycode_from_dt(struct pxa27x_keypad *keypad) in pxa27x_keypad_build_keycode_from_dt() argument
334 dev_info(keypad->input_dev->dev.parent, "missing platform data\n"); in pxa27x_keypad_build_keycode_from_dt()
341 static int pxa27x_keypad_build_keycode(struct pxa27x_keypad *keypad) in pxa27x_keypad_build_keycode() argument
343 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; in pxa27x_keypad_build_keycode()
344 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_build_keycode()
352 keypad->keycodes, input_dev); in pxa27x_keypad_build_keycode()
360 input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); in pxa27x_keypad_build_keycode()
365 keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = keycode; in pxa27x_keypad_build_keycode()
372 keypad->keycodes[MAX_MATRIX_KEY_NUM + 0] = keycode; in pxa27x_keypad_build_keycode()
376 keypad->keycodes[MAX_MATRIX_KEY_NUM + 1] = keycode; in pxa27x_keypad_build_keycode()
379 keypad->rotary_rel_code[0] = -1; in pxa27x_keypad_build_keycode()
381 keypad->rotary_rel_code[0] = pdata->rotary0_rel_code; in pxa27x_keypad_build_keycode()
389 keypad->keycodes[MAX_MATRIX_KEY_NUM + 2] = keycode; in pxa27x_keypad_build_keycode()
393 keypad->keycodes[MAX_MATRIX_KEY_NUM + 3] = keycode; in pxa27x_keypad_build_keycode()
396 keypad->rotary_rel_code[1] = -1; in pxa27x_keypad_build_keycode()
398 keypad->rotary_rel_code[1] = pdata->rotary1_rel_code; in pxa27x_keypad_build_keycode()
408 static void pxa27x_keypad_scan_matrix(struct pxa27x_keypad *keypad) in pxa27x_keypad_scan_matrix() argument
410 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; in pxa27x_keypad_scan_matrix()
411 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_scan_matrix()
456 bits_changed = keypad->matrix_key_state[col] ^ new_state[col]; in pxa27x_keypad_scan_matrix()
464 code = MATRIX_SCAN_CODE(row, col, keypad->row_shift); in pxa27x_keypad_scan_matrix()
467 input_report_key(input_dev, keypad->keycodes[code], in pxa27x_keypad_scan_matrix()
472 memcpy(keypad->matrix_key_state, new_state, sizeof(new_state)); in pxa27x_keypad_scan_matrix()
487 static void report_rotary_event(struct pxa27x_keypad *keypad, int r, int delta) in report_rotary_event() argument
489 struct input_dev *dev = keypad->input_dev; in report_rotary_event()
494 if (keypad->rotary_rel_code[r] == -1) { in report_rotary_event()
496 unsigned char keycode = keypad->keycodes[code]; in report_rotary_event()
506 input_report_rel(dev, keypad->rotary_rel_code[r], delta); in report_rotary_event()
511 static void pxa27x_keypad_scan_rotary(struct pxa27x_keypad *keypad) in pxa27x_keypad_scan_rotary() argument
513 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; in pxa27x_keypad_scan_rotary()
521 report_rotary_event(keypad, 0, rotary_delta(kprec)); in pxa27x_keypad_scan_rotary()
524 report_rotary_event(keypad, 1, rotary_delta(kprec >> 16)); in pxa27x_keypad_scan_rotary()
527 static void pxa27x_keypad_scan_direct(struct pxa27x_keypad *keypad) in pxa27x_keypad_scan_direct() argument
529 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; in pxa27x_keypad_scan_direct()
530 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_scan_direct()
538 pxa27x_keypad_scan_rotary(keypad); in pxa27x_keypad_scan_direct()
545 new_state = ~KPDK_DK(kpdk) & keypad->direct_key_mask; in pxa27x_keypad_scan_direct()
547 new_state = KPDK_DK(kpdk) & keypad->direct_key_mask; in pxa27x_keypad_scan_direct()
549 bits_changed = keypad->direct_key_state ^ new_state; in pxa27x_keypad_scan_direct()
559 input_report_key(input_dev, keypad->keycodes[code], in pxa27x_keypad_scan_direct()
564 keypad->direct_key_state = new_state; in pxa27x_keypad_scan_direct()
567 static void clear_wakeup_event(struct pxa27x_keypad *keypad) in clear_wakeup_event() argument
569 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; in clear_wakeup_event()
577 struct pxa27x_keypad *keypad = dev_id; in pxa27x_keypad_irq_handler() local
580 clear_wakeup_event(keypad); in pxa27x_keypad_irq_handler()
583 pxa27x_keypad_scan_direct(keypad); in pxa27x_keypad_irq_handler()
586 pxa27x_keypad_scan_matrix(keypad); in pxa27x_keypad_irq_handler()
591 static void pxa27x_keypad_config(struct pxa27x_keypad *keypad) in pxa27x_keypad_config() argument
593 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; in pxa27x_keypad_config()
628 keypad->direct_key_mask = pdata->direct_key_mask; in pxa27x_keypad_config()
630 keypad->direct_key_mask = ((1 << direct_key_num) - 1) & ~mask; in pxa27x_keypad_config()
643 struct pxa27x_keypad *keypad = input_get_drvdata(dev); in pxa27x_keypad_open() local
646 ret = clk_prepare_enable(keypad->clk); in pxa27x_keypad_open()
650 pxa27x_keypad_config(keypad); in pxa27x_keypad_open()
657 struct pxa27x_keypad *keypad = input_get_drvdata(dev); in pxa27x_keypad_close() local
660 clk_disable_unprepare(keypad->clk); in pxa27x_keypad_close()
667 struct pxa27x_keypad *keypad = platform_get_drvdata(pdev); in pxa27x_keypad_suspend() local
670 * If the keypad is used a wake up source, clock can not be disabled. in pxa27x_keypad_suspend()
674 enable_irq_wake(keypad->irq); in pxa27x_keypad_suspend()
676 clk_disable_unprepare(keypad->clk); in pxa27x_keypad_suspend()
684 struct pxa27x_keypad *keypad = platform_get_drvdata(pdev); in pxa27x_keypad_resume() local
685 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_resume()
689 * If the keypad is used as wake up source, the clock is not turned in pxa27x_keypad_resume()
693 disable_irq_wake(keypad->irq); in pxa27x_keypad_resume()
699 ret = clk_prepare_enable(keypad->clk); in pxa27x_keypad_resume()
701 pxa27x_keypad_config(keypad); in pxa27x_keypad_resume()
720 struct pxa27x_keypad *keypad; in pxa27x_keypad_probe() local
739 keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), in pxa27x_keypad_probe()
741 if (!keypad) in pxa27x_keypad_probe()
748 keypad->pdata = pdata; in pxa27x_keypad_probe()
749 keypad->input_dev = input_dev; in pxa27x_keypad_probe()
750 keypad->irq = irq; in pxa27x_keypad_probe()
752 keypad->mmio_base = devm_ioremap_resource(&pdev->dev, res); in pxa27x_keypad_probe()
753 if (IS_ERR(keypad->mmio_base)) in pxa27x_keypad_probe()
754 return PTR_ERR(keypad->mmio_base); in pxa27x_keypad_probe()
756 keypad->clk = devm_clk_get(&pdev->dev, NULL); in pxa27x_keypad_probe()
757 if (IS_ERR(keypad->clk)) { in pxa27x_keypad_probe()
758 dev_err(&pdev->dev, "failed to get keypad clock\n"); in pxa27x_keypad_probe()
759 return PTR_ERR(keypad->clk); in pxa27x_keypad_probe()
768 input_dev->keycode = keypad->keycodes; in pxa27x_keypad_probe()
769 input_dev->keycodesize = sizeof(keypad->keycodes[0]); in pxa27x_keypad_probe()
770 input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); in pxa27x_keypad_probe()
772 input_set_drvdata(input_dev, keypad); in pxa27x_keypad_probe()
778 error = pxa27x_keypad_build_keycode(keypad); in pxa27x_keypad_probe()
780 error = pxa27x_keypad_build_keycode_from_dt(keypad); in pxa27x_keypad_probe()
786 pdata = keypad->pdata; in pxa27x_keypad_probe()
793 keypad->row_shift = get_count_order(pdata->matrix_key_cols); in pxa27x_keypad_probe()
795 if ((pdata->enable_rotary0 && keypad->rotary_rel_code[0] != -1) || in pxa27x_keypad_probe()
796 (pdata->enable_rotary1 && keypad->rotary_rel_code[1] != -1)) { in pxa27x_keypad_probe()
801 0, pdev->name, keypad); in pxa27x_keypad_probe()
814 platform_set_drvdata(pdev, keypad); in pxa27x_keypad_probe()
822 { .compatible = "marvell,pxa27x-keypad" },
831 .name = "pxa27x-keypad",
838 MODULE_DESCRIPTION("PXA27x Keypad Controller Driver");
841 MODULE_ALIAS("platform:pxa27x-keypad");