Lines Matching +full:key +full:- +full:code
1 // SPDX-License-Identifier: GPL-2.0-only
29 #include <linux/platform_data/keypad-pxa27x.h>
34 #define KPDK 0x0008 /* Keypad Direct Key register */
36 #define KPMK 0x0018 /* Keypad Matrix Key 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 */
54 #define KPC_IMKP (0x1 << 21) /* Ignore Multiple Key Press */
62 #define KPC_DI (0x1 << 5) /* Direct key interrupt bit */
90 #define keypad_readl(off) __raw_readl(keypad->mmio_base + (off))
91 #define keypad_writel(off, v) __raw_writel((v), keypad->mmio_base + (off))
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()
155 unsigned short code; in pxa27x_keypad_direct_key_parse_dt() local
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()
165 * it means direct key is not supported. 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()
200 code = be16_to_cpup(prop + i); 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()
213 unsigned int code, proplen; in pxa27x_keypad_rotary_parse_dt() local
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()
221 relkey_ret = of_property_read_u32(np, relkeyname, &code); 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()
227 relcode = code & 0xffff; 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()
231 relcode = code >> 16; 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()
245 code = be32_to_cpup(prop); in pxa27x_keypad_rotary_parse_dt()
247 * Not all up/down key code are valid. in pxa27x_keypad_rotary_parse_dt()
248 * Now we depends on direct-rel-code. in pxa27x_keypad_rotary_parse_dt()
250 if ((!(code & 0xffff) || !(code >> 16)) && relkey_ret) { in pxa27x_keypad_rotary_parse_dt()
256 keycode = code & 0xffff; 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()
260 keycode = code >> 16; 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()
297 dev_err(dev, "failed to parse matrix key\n"); in pxa27x_keypad_build_keycode_from_dt()
303 dev_err(dev, "failed to parse direct key\n"); in pxa27x_keypad_build_keycode_from_dt()
309 dev_err(dev, "failed to parse rotary key\n"); 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()
321 * The keycodes may not only includes matrix key but also the direct in pxa27x_keypad_build_keycode_from_dt()
322 * key or rotary key. 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()
427 /* if invalid row/col, treat as no key pressed */ 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()
452 for (col = 0; col < pdata->matrix_key_cols; col++) { in pxa27x_keypad_scan_matrix()
454 int code; in pxa27x_keypad_scan_matrix() local
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()
466 input_event(input_dev, EV_MSC, MSC_SCAN, code); 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()
495 int code = MAX_MATRIX_KEY_NUM + 2 * r + (delta > 0 ? 0 : 1); in report_rotary_event() local
496 unsigned char keycode = keypad->keycodes[code]; in report_rotary_event()
498 /* simulate a press-n-release */ in report_rotary_event()
499 input_event(dev, EV_MSC, MSC_SCAN, code); in report_rotary_event()
502 input_event(dev, EV_MSC, MSC_SCAN, code); 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()
541 * The KPDR_DK only output the key pin level, so it relates to board, 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()
556 int code = MAX_MATRIX_KEY_NUM + i; in pxa27x_keypad_scan_direct() local
558 input_event(input_dev, EV_MSC, MSC_SCAN, code); 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()
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()
632 /* enable direct key */ 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()
671 * Or it can not detect the key pressing. in pxa27x_keypad_suspend()
673 if (device_may_wakeup(&pdev->dev)) in pxa27x_keypad_suspend()
674 enable_irq_wake(keypad->irq); in pxa27x_keypad_suspend()
676 clk_disable_unprepare(keypad->clk); in pxa27x_keypad_suspend()
685 struct input_dev *input_dev = keypad->input_dev; in pxa27x_keypad_resume()
692 if (device_may_wakeup(&pdev->dev)) { in pxa27x_keypad_resume()
693 disable_irq_wake(keypad->irq); in pxa27x_keypad_resume()
695 mutex_lock(&input_dev->mutex); in pxa27x_keypad_resume()
699 ret = clk_prepare_enable(keypad->clk); in pxa27x_keypad_resume()
704 mutex_unlock(&input_dev->mutex); in pxa27x_keypad_resume()
718 dev_get_platdata(&pdev->dev); in pxa27x_keypad_probe()
719 struct device_node *np = pdev->dev.of_node; in pxa27x_keypad_probe()
727 return -EINVAL; in pxa27x_keypad_probe()
731 return -ENXIO; in pxa27x_keypad_probe()
735 dev_err(&pdev->dev, "failed to get I/O memory\n"); in pxa27x_keypad_probe()
736 return -ENXIO; in pxa27x_keypad_probe()
739 keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), in pxa27x_keypad_probe()
742 return -ENOMEM; in pxa27x_keypad_probe()
744 input_dev = devm_input_allocate_device(&pdev->dev); in pxa27x_keypad_probe()
746 return -ENOMEM; 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()
762 input_dev->name = pdev->name; in pxa27x_keypad_probe()
763 input_dev->id.bustype = BUS_HOST; in pxa27x_keypad_probe()
764 input_dev->open = pxa27x_keypad_open; in pxa27x_keypad_probe()
765 input_dev->close = pxa27x_keypad_close; in pxa27x_keypad_probe()
766 input_dev->dev.parent = &pdev->dev; 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()
774 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); in pxa27x_keypad_probe()
786 pdata = keypad->pdata; in pxa27x_keypad_probe()
789 dev_err(&pdev->dev, "failed to build keycode\n"); 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()
797 input_dev->evbit[0] |= BIT_MASK(EV_REL); in pxa27x_keypad_probe()
800 error = devm_request_irq(&pdev->dev, irq, pxa27x_keypad_irq_handler, in pxa27x_keypad_probe()
801 0, pdev->name, keypad); in pxa27x_keypad_probe()
803 dev_err(&pdev->dev, "failed to request IRQ\n"); in pxa27x_keypad_probe()
810 dev_err(&pdev->dev, "failed to register input device\n"); in pxa27x_keypad_probe()
815 device_init_wakeup(&pdev->dev, 1); in pxa27x_keypad_probe()
822 { .compatible = "marvell,pxa27x-keypad" },
831 .name = "pxa27x-keypad",
841 MODULE_ALIAS("platform:pxa27x-keypad");