Lines Matching +full:scan +full:- +full:interval

1 // SPDX-License-Identifier: GPL-2.0-only
29 #include <linux/platform_data/keypad-pxa27x.h>
37 #define KPAS 0x0020 /* Keypad Automatic Scan register */
39 /* Keypad Automatic Scan Multiple Key Presser register 0-3 */
47 #define KPC_MKRN(n) ((((n) - 1) & 0x7) << 26) /* matrix key row number */
48 #define KPC_MKCN(n) ((((n) - 1) & 0x7) << 23) /* matrix key column number */
49 #define KPC_DKN(n) ((((n) - 1) & 0x7) << 6) /* direct key number */
51 #define KPC_AS (0x1 << 30) /* Automatic Scan bit */
52 #define KPC_ASACT (0x1 << 29) /* Automatic Scan on Activity */
56 #define KPC_MS(n) (0x1 << (13 + (n))) /* Matrix scan line 'n' */
90 #define keypad_readl(off) __raw_readl(keypad->mmio_base + (off))
91 #define keypad_writel(off, v) __raw_writel((v), keypad->mmio_base + (off))
110 /* state row bits of each column scan */
121 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_matrix_key_parse_dt()
122 struct device *dev = input_dev->dev.parent; in pxa27x_keypad_matrix_key_parse_dt()
132 return -EINVAL; in pxa27x_keypad_matrix_key_parse_dt()
135 pdata->matrix_key_rows = rows; in pxa27x_keypad_matrix_key_parse_dt()
136 pdata->matrix_key_cols = cols; in pxa27x_keypad_matrix_key_parse_dt()
139 pdata->matrix_key_rows, in pxa27x_keypad_matrix_key_parse_dt()
140 pdata->matrix_key_cols, in pxa27x_keypad_matrix_key_parse_dt()
141 keypad->keycodes, input_dev); in pxa27x_keypad_matrix_key_parse_dt()
151 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_direct_key_parse_dt()
152 struct device *dev = input_dev->dev.parent; in pxa27x_keypad_direct_key_parse_dt()
153 struct device_node *np = dev->of_node; in pxa27x_keypad_direct_key_parse_dt()
160 error = of_property_read_u32(np, "marvell,direct-key-count", in pxa27x_keypad_direct_key_parse_dt()
161 &pdata->direct_key_num); in pxa27x_keypad_direct_key_parse_dt()
164 * If do not have marvel,direct-key-count defined, in pxa27x_keypad_direct_key_parse_dt()
167 return error == -EINVAL ? 0 : error; in pxa27x_keypad_direct_key_parse_dt()
170 error = of_property_read_u32(np, "marvell,direct-key-mask", in pxa27x_keypad_direct_key_parse_dt()
171 &pdata->direct_key_mask); in pxa27x_keypad_direct_key_parse_dt()
173 if (error != -EINVAL) in pxa27x_keypad_direct_key_parse_dt()
177 * If marvell,direct-key-mask is not defined, driver will use in pxa27x_keypad_direct_key_parse_dt()
180 pdata->direct_key_mask = 0; in pxa27x_keypad_direct_key_parse_dt()
183 pdata->direct_key_low_active = of_property_read_bool(np, in pxa27x_keypad_direct_key_parse_dt()
184 "marvell,direct-key-low-active"); in pxa27x_keypad_direct_key_parse_dt()
186 prop = of_get_property(np, "marvell,direct-key-map", &proplen); in pxa27x_keypad_direct_key_parse_dt()
188 return -EINVAL; in pxa27x_keypad_direct_key_parse_dt()
191 return -EINVAL; in pxa27x_keypad_direct_key_parse_dt()
197 return -EINVAL; in pxa27x_keypad_direct_key_parse_dt()
201 keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = code; in pxa27x_keypad_direct_key_parse_dt()
202 __set_bit(code, input_dev->keybit); in pxa27x_keypad_direct_key_parse_dt()
216 const char relkeyname[] = {"marvell,rotary-rel-key"}; in pxa27x_keypad_rotary_parse_dt()
217 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_rotary_parse_dt()
218 struct device *dev = input_dev->dev.parent; in pxa27x_keypad_rotary_parse_dt()
219 struct device_node *np = dev->of_node; in pxa27x_keypad_rotary_parse_dt()
222 /* if can read correct rotary key-code, we do not need this. */ in pxa27x_keypad_rotary_parse_dt()
228 pdata->rotary0_rel_code = (code & 0xffff); in pxa27x_keypad_rotary_parse_dt()
229 __set_bit(relcode, input_dev->relbit); in pxa27x_keypad_rotary_parse_dt()
232 pdata->rotary1_rel_code = relcode; in pxa27x_keypad_rotary_parse_dt()
233 __set_bit(relcode, input_dev->relbit); in pxa27x_keypad_rotary_parse_dt()
248 * Now we depends on direct-rel-code. in pxa27x_keypad_rotary_parse_dt()
257 keypad->keycodes[n] = keycode; in pxa27x_keypad_rotary_parse_dt()
258 __set_bit(keycode, input_dev->keybit); in pxa27x_keypad_rotary_parse_dt()
261 keypad->keycodes[n + 1] = keycode; in pxa27x_keypad_rotary_parse_dt()
262 __set_bit(keycode, input_dev->keybit); in pxa27x_keypad_rotary_parse_dt()
265 pdata->rotary0_rel_code = -1; in pxa27x_keypad_rotary_parse_dt()
267 pdata->rotary1_rel_code = -1; in pxa27x_keypad_rotary_parse_dt()
270 pdata->enable_rotary0 = 1; in pxa27x_keypad_rotary_parse_dt()
272 pdata->enable_rotary1 = 1; 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()
283 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_build_keycode_from_dt()
284 struct device *dev = input_dev->dev.parent; in pxa27x_keypad_build_keycode_from_dt()
285 struct device_node *np = dev->of_node; in pxa27x_keypad_build_keycode_from_dt()
292 return -ENOMEM; in pxa27x_keypad_build_keycode_from_dt()
313 error = of_property_read_u32(np, "marvell,debounce-interval", in pxa27x_keypad_build_keycode_from_dt()
314 &pdata->debounce_interval); in pxa27x_keypad_build_keycode_from_dt()
316 dev_err(dev, "failed to parse debounce-interval\n"); 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()
334 dev_info(keypad->input_dev->dev.parent, "missing platform data\n"); in pxa27x_keypad_build_keycode_from_dt()
336 return -EINVAL; in pxa27x_keypad_build_keycode_from_dt()
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()
349 error = matrix_keypad_build_keymap(pdata->matrix_keymap_data, NULL, in pxa27x_keypad_build_keycode()
350 pdata->matrix_key_rows, in pxa27x_keypad_build_keycode()
351 pdata->matrix_key_cols, 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()
363 for (i = 0; i < pdata->direct_key_num; i++) { in pxa27x_keypad_build_keycode()
364 keycode = pdata->direct_key_map[i]; in pxa27x_keypad_build_keycode()
365 keypad->keycodes[MAX_MATRIX_KEY_NUM + i] = keycode; in pxa27x_keypad_build_keycode()
366 __set_bit(keycode, input_dev->keybit); in pxa27x_keypad_build_keycode()
369 if (pdata->enable_rotary0) { in pxa27x_keypad_build_keycode()
370 if (pdata->rotary0_up_key && pdata->rotary0_down_key) { in pxa27x_keypad_build_keycode()
371 keycode = pdata->rotary0_up_key; in pxa27x_keypad_build_keycode()
372 keypad->keycodes[MAX_MATRIX_KEY_NUM + 0] = keycode; in pxa27x_keypad_build_keycode()
373 __set_bit(keycode, input_dev->keybit); in pxa27x_keypad_build_keycode()
375 keycode = pdata->rotary0_down_key; in pxa27x_keypad_build_keycode()
376 keypad->keycodes[MAX_MATRIX_KEY_NUM + 1] = keycode; in pxa27x_keypad_build_keycode()
377 __set_bit(keycode, input_dev->keybit); 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()
382 __set_bit(pdata->rotary0_rel_code, input_dev->relbit); in pxa27x_keypad_build_keycode()
386 if (pdata->enable_rotary1) { in pxa27x_keypad_build_keycode()
387 if (pdata->rotary1_up_key && pdata->rotary1_down_key) { in pxa27x_keypad_build_keycode()
388 keycode = pdata->rotary1_up_key; in pxa27x_keypad_build_keycode()
389 keypad->keycodes[MAX_MATRIX_KEY_NUM + 2] = keycode; in pxa27x_keypad_build_keycode()
390 __set_bit(keycode, input_dev->keybit); in pxa27x_keypad_build_keycode()
392 keycode = pdata->rotary1_down_key; in pxa27x_keypad_build_keycode()
393 keypad->keycodes[MAX_MATRIX_KEY_NUM + 3] = keycode; in pxa27x_keypad_build_keycode()
394 __set_bit(keycode, input_dev->keybit); 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()
399 __set_bit(pdata->rotary1_rel_code, input_dev->relbit); in pxa27x_keypad_build_keycode()
403 __clear_bit(KEY_RESERVED, input_dev->keybit); in pxa27x_keypad_build_keycode()
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()
421 goto scan; in pxa27x_keypad_scan_matrix()
428 if (col >= pdata->matrix_key_cols || in pxa27x_keypad_scan_matrix()
429 row >= pdata->matrix_key_rows) in pxa27x_keypad_scan_matrix()
430 goto scan; in pxa27x_keypad_scan_matrix()
433 goto scan; in pxa27x_keypad_scan_matrix()
451 scan: in pxa27x_keypad_scan_matrix()
452 for (col = 0; col < pdata->matrix_key_cols; col++) { in pxa27x_keypad_scan_matrix()
456 bits_changed = keypad->matrix_key_state[col] ^ new_state[col]; in pxa27x_keypad_scan_matrix()
460 for (row = 0; row < pdata->matrix_key_rows; row++) { 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()
482 return (kprec & 0xff) - 0x7f - 0xff; in rotary_delta()
484 return (kprec & 0xff) - 0x7f; in rotary_delta()
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()
498 /* simulate a press-n-release */ in report_rotary_event()
506 input_report_rel(dev, keypad->rotary_rel_code[r], delta); in report_rotary_event()
513 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; in pxa27x_keypad_scan_rotary()
520 if (pdata->enable_rotary0) in pxa27x_keypad_scan_rotary()
523 if (pdata->enable_rotary1) in pxa27x_keypad_scan_rotary()
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()
537 if (pdata->enable_rotary0 || pdata->enable_rotary1) in pxa27x_keypad_scan_direct()
544 if (pdata->direct_key_low_active) 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()
554 for (i = 0; i < pdata->direct_key_num; i++) { 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()
569 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; in clear_wakeup_event()
571 if (pdata->clear_wakeup_event) in clear_wakeup_event()
572 (pdata->clear_wakeup_event)(); in clear_wakeup_event()
593 const struct pxa27x_keypad_platform_data *pdata = keypad->pdata; in pxa27x_keypad_config()
600 /* enable matrix keys with automatic scan */ in pxa27x_keypad_config()
601 if (pdata->matrix_key_rows && pdata->matrix_key_cols) { in pxa27x_keypad_config()
603 kpc |= KPC_MKRN(pdata->matrix_key_rows) | in pxa27x_keypad_config()
604 KPC_MKCN(pdata->matrix_key_cols); in pxa27x_keypad_config()
607 /* enable rotary key, debounce interval same as direct keys */ in pxa27x_keypad_config()
608 if (pdata->enable_rotary0) { in pxa27x_keypad_config()
614 if (pdata->enable_rotary1) { in pxa27x_keypad_config()
620 if (pdata->direct_key_num > direct_key_num) in pxa27x_keypad_config()
621 direct_key_num = pdata->direct_key_num; in pxa27x_keypad_config()
627 if (pdata->direct_key_mask) 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()
638 keypad_writel(KPKDI, pdata->debounce_interval); in pxa27x_keypad_config()
646 ret = clk_prepare_enable(keypad->clk); in pxa27x_keypad_open()
660 clk_disable_unprepare(keypad->clk); in pxa27x_keypad_close()
672 if (device_may_wakeup(&pdev->dev)) in pxa27x_keypad_suspend()
673 enable_irq_wake(keypad->irq); in pxa27x_keypad_suspend()
675 clk_disable_unprepare(keypad->clk); in pxa27x_keypad_suspend()
684 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_resume()
691 if (device_may_wakeup(&pdev->dev)) { in pxa27x_keypad_resume()
692 disable_irq_wake(keypad->irq); in pxa27x_keypad_resume()
694 mutex_lock(&input_dev->mutex); in pxa27x_keypad_resume()
698 ret = clk_prepare_enable(keypad->clk); in pxa27x_keypad_resume()
703 mutex_unlock(&input_dev->mutex); in pxa27x_keypad_resume()
716 dev_get_platdata(&pdev->dev); in pxa27x_keypad_probe()
717 struct device_node *np = pdev->dev.of_node; in pxa27x_keypad_probe()
724 return -EINVAL; in pxa27x_keypad_probe()
728 return -ENXIO; in pxa27x_keypad_probe()
730 keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), in pxa27x_keypad_probe()
733 return -ENOMEM; in pxa27x_keypad_probe()
735 input_dev = devm_input_allocate_device(&pdev->dev); in pxa27x_keypad_probe()
737 return -ENOMEM; in pxa27x_keypad_probe()
739 keypad->pdata = pdata; in pxa27x_keypad_probe()
740 keypad->input_dev = input_dev; in pxa27x_keypad_probe()
741 keypad->irq = irq; in pxa27x_keypad_probe()
743 keypad->mmio_base = devm_platform_ioremap_resource(pdev, 0); in pxa27x_keypad_probe()
744 if (IS_ERR(keypad->mmio_base)) in pxa27x_keypad_probe()
745 return PTR_ERR(keypad->mmio_base); in pxa27x_keypad_probe()
747 keypad->clk = devm_clk_get(&pdev->dev, NULL); in pxa27x_keypad_probe()
748 if (IS_ERR(keypad->clk)) { in pxa27x_keypad_probe()
749 dev_err(&pdev->dev, "failed to get keypad clock\n"); in pxa27x_keypad_probe()
750 return PTR_ERR(keypad->clk); in pxa27x_keypad_probe()
753 input_dev->name = pdev->name; in pxa27x_keypad_probe()
754 input_dev->id.bustype = BUS_HOST; in pxa27x_keypad_probe()
755 input_dev->open = pxa27x_keypad_open; in pxa27x_keypad_probe()
756 input_dev->close = pxa27x_keypad_close; in pxa27x_keypad_probe()
757 input_dev->dev.parent = &pdev->dev; in pxa27x_keypad_probe()
759 input_dev->keycode = keypad->keycodes; in pxa27x_keypad_probe()
760 input_dev->keycodesize = sizeof(keypad->keycodes[0]); in pxa27x_keypad_probe()
761 input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); in pxa27x_keypad_probe()
765 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); in pxa27x_keypad_probe()
777 pdata = keypad->pdata; in pxa27x_keypad_probe()
780 dev_err(&pdev->dev, "failed to build keycode\n"); in pxa27x_keypad_probe()
784 keypad->row_shift = get_count_order(pdata->matrix_key_cols); in pxa27x_keypad_probe()
786 if ((pdata->enable_rotary0 && keypad->rotary_rel_code[0] != -1) || in pxa27x_keypad_probe()
787 (pdata->enable_rotary1 && keypad->rotary_rel_code[1] != -1)) { in pxa27x_keypad_probe()
788 input_dev->evbit[0] |= BIT_MASK(EV_REL); in pxa27x_keypad_probe()
791 error = devm_request_irq(&pdev->dev, irq, pxa27x_keypad_irq_handler, in pxa27x_keypad_probe()
792 0, pdev->name, keypad); in pxa27x_keypad_probe()
794 dev_err(&pdev->dev, "failed to request IRQ\n"); in pxa27x_keypad_probe()
801 dev_err(&pdev->dev, "failed to register input device\n"); in pxa27x_keypad_probe()
806 device_init_wakeup(&pdev->dev, 1); in pxa27x_keypad_probe()
813 { .compatible = "marvell,pxa27x-keypad" },
822 .name = "pxa27x-keypad",
832 MODULE_ALIAS("platform:pxa27x-keypad");