Lines Matching +full:row +full:- +full:delay

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
12 #include <linux/delay.h>
78 * struct pmic8xxx_kp - internal keypad data structure
80 * @num_rows: number of row of keypad
110 /* all keys pressed on that particular row? */ in pmic8xxx_col_state()
112 return 1 << kp->num_cols; in pmic8xxx_col_state()
114 return col & ((1 << kp->num_cols) - 1); in pmic8xxx_col_state()
134 rc = regmap_read(kp->regmap, KEYP_SCAN, &scan_val); in pmic8xxx_chk_sync_read()
136 dev_err(kp->dev, "Error reading KEYP_SCAN reg, rc=%d\n", rc); in pmic8xxx_chk_sync_read()
142 rc = regmap_write(kp->regmap, KEYP_SCAN, scan_val); in pmic8xxx_chk_sync_read()
144 dev_err(kp->dev, "Error writing KEYP_SCAN reg, rc=%d\n", rc); in pmic8xxx_chk_sync_read()
157 int rc, row; in pmic8xxx_kp_read_data() local
160 for (row = 0; row < read_rows; row++) { in pmic8xxx_kp_read_data()
161 rc = regmap_read(kp->regmap, data_reg, &val); in pmic8xxx_kp_read_data()
164 dev_dbg(kp->dev, "%d = %d\n", row, val); in pmic8xxx_kp_read_data()
165 state[row] = pmic8xxx_col_state(kp, val); in pmic8xxx_kp_read_data()
177 if (kp->num_rows < PM8XXX_MIN_ROWS) in pmic8xxx_kp_read_matrix()
180 read_rows = kp->num_rows; in pmic8xxx_kp_read_matrix()
188 dev_err(kp->dev, in pmic8xxx_kp_read_matrix()
197 dev_err(kp->dev, in pmic8xxx_kp_read_matrix()
205 rc = regmap_read(kp->regmap, KEYP_SCAN, &scan_val); in pmic8xxx_kp_read_matrix()
207 dev_err(kp->dev, "Error reading KEYP_SCAN reg, rc=%d\n", rc); in pmic8xxx_kp_read_matrix()
212 rc = regmap_write(kp->regmap, KEYP_SCAN, scan_val); in pmic8xxx_kp_read_matrix()
214 dev_err(kp->dev, "Error writing KEYP_SCAN reg, rc=%d\n", rc); in pmic8xxx_kp_read_matrix()
222 int row, col, code; in __pmic8xxx_kp_scan_matrix() local
224 for (row = 0; row < kp->num_rows; row++) { in __pmic8xxx_kp_scan_matrix()
225 int bits_changed = new_state[row] ^ old_state[row]; in __pmic8xxx_kp_scan_matrix()
230 for (col = 0; col < kp->num_cols; col++) { in __pmic8xxx_kp_scan_matrix()
234 dev_dbg(kp->dev, "key [%d:%d] %s\n", row, col, in __pmic8xxx_kp_scan_matrix()
235 !(new_state[row] & (1 << col)) ? in __pmic8xxx_kp_scan_matrix()
238 code = MATRIX_SCAN_CODE(row, col, PM8XXX_ROW_SHIFT); in __pmic8xxx_kp_scan_matrix()
240 input_event(kp->input, EV_MSC, MSC_SCAN, code); in __pmic8xxx_kp_scan_matrix()
241 input_report_key(kp->input, in __pmic8xxx_kp_scan_matrix()
242 kp->keycodes[code], in __pmic8xxx_kp_scan_matrix()
243 !(new_state[row] & (1 << col))); in __pmic8xxx_kp_scan_matrix()
245 input_sync(kp->input); in __pmic8xxx_kp_scan_matrix()
252 int row, found_first = -1; in pmic8xxx_detect_ghost_keys() local
256 for (row = 0; row < kp->num_rows; row++) { in pmic8xxx_detect_ghost_keys()
257 row_state = (~new_state[row]) & in pmic8xxx_detect_ghost_keys()
258 ((1 << kp->num_cols) - 1); in pmic8xxx_detect_ghost_keys()
261 if (found_first == -1) in pmic8xxx_detect_ghost_keys()
262 found_first = row; in pmic8xxx_detect_ghost_keys()
264 dev_dbg(kp->dev, "detected ghost key on row[%d]" in pmic8xxx_detect_ghost_keys()
265 " and row[%d]\n", found_first, row); in pmic8xxx_detect_ghost_keys()
289 __pmic8xxx_kp_scan_matrix(kp, new_state, kp->keystate); in pmic8xxx_kp_scan_matrix()
290 memcpy(kp->keystate, new_state, sizeof(new_state)); in pmic8xxx_kp_scan_matrix()
292 case 0x3: /* two events - eventcounter is gray-coded */ in pmic8xxx_kp_scan_matrix()
297 __pmic8xxx_kp_scan_matrix(kp, old_state, kp->keystate); in pmic8xxx_kp_scan_matrix()
299 memcpy(kp->keystate, new_state, sizeof(new_state)); in pmic8xxx_kp_scan_matrix()
302 dev_dbg(kp->dev, "Some key events were lost\n"); in pmic8xxx_kp_scan_matrix()
306 __pmic8xxx_kp_scan_matrix(kp, old_state, kp->keystate); in pmic8xxx_kp_scan_matrix()
308 memcpy(kp->keystate, new_state, sizeof(new_state)); in pmic8xxx_kp_scan_matrix()
311 rc = -EINVAL; in pmic8xxx_kp_scan_matrix()
318 * whenever key-stuck interrupt happens, because events counter doesn't
336 dev_err(kp->dev, "failed to read keypad matrix\n"); in pmic8xxx_kp_stuck_irq()
340 __pmic8xxx_kp_scan_matrix(kp, new_state, kp->stuckstate); in pmic8xxx_kp_stuck_irq()
351 rc = regmap_read(kp->regmap, KEYP_CTRL, &ctrl_val); in pmic8xxx_kp_irq()
353 dev_err(kp->dev, "failed to read keyp_ctrl register\n"); in pmic8xxx_kp_irq()
361 dev_err(kp->dev, "failed to scan matrix\n"); in pmic8xxx_kp_irq()
369 const struct device_node *of_node = pdev->dev.of_node; in pmic8xxx_kpd_init()
380 if (kp->num_cols < KEYP_CTRL_SCAN_COLS_MIN) in pmic8xxx_kpd_init()
383 bits = kp->num_cols - KEYP_CTRL_SCAN_COLS_MIN; in pmic8xxx_kpd_init()
387 /* Find row bits */ in pmic8xxx_kpd_init()
388 if (kp->num_rows < KEYP_CTRL_SCAN_ROWS_MIN) in pmic8xxx_kpd_init()
391 bits = row_bits[kp->num_rows - KEYP_CTRL_SCAN_ROWS_MIN]; in pmic8xxx_kpd_init()
395 rc = regmap_write(kp->regmap, KEYP_CTRL, ctrl_val); in pmic8xxx_kpd_init()
397 dev_err(kp->dev, "Error writing KEYP_CTRL reg, rc=%d\n", rc); in pmic8xxx_kpd_init()
401 if (of_property_read_u32(of_node, "scan-delay", &scan_delay_ms)) in pmic8xxx_kpd_init()
406 dev_err(&pdev->dev, "invalid keypad scan time supplied\n"); in pmic8xxx_kpd_init()
407 return -EINVAL; in pmic8xxx_kpd_init()
410 if (of_property_read_u32(of_node, "row-hold", &row_hold_ns)) in pmic8xxx_kpd_init()
416 dev_err(&pdev->dev, "invalid keypad row hold time supplied\n"); in pmic8xxx_kpd_init()
417 return -EINVAL; in pmic8xxx_kpd_init()
426 dev_err(&pdev->dev, "invalid debounce time supplied\n"); in pmic8xxx_kpd_init()
427 return -EINVAL; in pmic8xxx_kpd_init()
430 bits = (debounce_ms / 5) - 1; in pmic8xxx_kpd_init()
434 bits = fls(scan_delay_ms) - 1; in pmic8xxx_kpd_init()
437 /* Row hold time is a multiple of 32KHz cycles. */ in pmic8xxx_kpd_init()
442 rc = regmap_write(kp->regmap, KEYP_SCAN, scan_val); in pmic8xxx_kpd_init()
444 dev_err(kp->dev, "Error writing KEYP_SCAN reg, rc=%d\n", rc); in pmic8xxx_kpd_init()
454 kp->ctrl_reg |= KEYP_CTRL_KEYP_EN; in pmic8xxx_kp_enable()
456 rc = regmap_write(kp->regmap, KEYP_CTRL, kp->ctrl_reg); in pmic8xxx_kp_enable()
458 dev_err(kp->dev, "Error writing KEYP_CTRL reg, rc=%d\n", rc); in pmic8xxx_kp_enable()
467 kp->ctrl_reg &= ~KEYP_CTRL_KEYP_EN; in pmic8xxx_kp_disable()
469 rc = regmap_write(kp->regmap, KEYP_CTRL, kp->ctrl_reg); in pmic8xxx_kp_disable()
494 * - Initialize keypad control parameters, like no. of rows, columns,
496 * - configure rows and column gpios pull up/down.
497 * - set irq edge type.
498 * - enable the keypad controller.
502 struct device_node *np = pdev->dev.of_node; in pmic8xxx_kp_probe()
510 rc = matrix_keypad_parse_properties(&pdev->dev, &rows, &cols); in pmic8xxx_kp_probe()
516 dev_err(&pdev->dev, "invalid platform data\n"); in pmic8xxx_kp_probe()
517 return -EINVAL; in pmic8xxx_kp_probe()
520 repeat = !of_property_read_bool(np, "linux,input-no-autorepeat"); in pmic8xxx_kp_probe()
522 wakeup = of_property_read_bool(np, "wakeup-source") || in pmic8xxx_kp_probe()
524 of_property_read_bool(np, "linux,keypad-wakeup"); in pmic8xxx_kp_probe()
526 kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL); in pmic8xxx_kp_probe()
528 return -ENOMEM; in pmic8xxx_kp_probe()
530 kp->regmap = dev_get_regmap(pdev->dev.parent, NULL); in pmic8xxx_kp_probe()
531 if (!kp->regmap) in pmic8xxx_kp_probe()
532 return -ENODEV; in pmic8xxx_kp_probe()
536 kp->num_rows = rows; in pmic8xxx_kp_probe()
537 kp->num_cols = cols; in pmic8xxx_kp_probe()
538 kp->dev = &pdev->dev; in pmic8xxx_kp_probe()
540 kp->input = devm_input_allocate_device(&pdev->dev); in pmic8xxx_kp_probe()
541 if (!kp->input) { in pmic8xxx_kp_probe()
542 dev_err(&pdev->dev, "unable to allocate input device\n"); in pmic8xxx_kp_probe()
543 return -ENOMEM; in pmic8xxx_kp_probe()
546 kp->key_sense_irq = platform_get_irq(pdev, 0); in pmic8xxx_kp_probe()
547 if (kp->key_sense_irq < 0) in pmic8xxx_kp_probe()
548 return kp->key_sense_irq; in pmic8xxx_kp_probe()
550 kp->key_stuck_irq = platform_get_irq(pdev, 1); in pmic8xxx_kp_probe()
551 if (kp->key_stuck_irq < 0) in pmic8xxx_kp_probe()
552 return kp->key_stuck_irq; in pmic8xxx_kp_probe()
554 kp->input->name = "PMIC8XXX keypad"; in pmic8xxx_kp_probe()
555 kp->input->phys = "pmic8xxx_keypad/input0"; in pmic8xxx_kp_probe()
557 kp->input->id.bustype = BUS_I2C; in pmic8xxx_kp_probe()
558 kp->input->id.version = 0x0001; in pmic8xxx_kp_probe()
559 kp->input->id.product = 0x0001; in pmic8xxx_kp_probe()
560 kp->input->id.vendor = 0x0001; in pmic8xxx_kp_probe()
562 kp->input->open = pmic8xxx_kp_open; in pmic8xxx_kp_probe()
563 kp->input->close = pmic8xxx_kp_close; in pmic8xxx_kp_probe()
567 kp->keycodes, kp->input); in pmic8xxx_kp_probe()
569 dev_err(&pdev->dev, "failed to build keymap\n"); in pmic8xxx_kp_probe()
574 __set_bit(EV_REP, kp->input->evbit); in pmic8xxx_kp_probe()
575 input_set_capability(kp->input, EV_MSC, MSC_SCAN); in pmic8xxx_kp_probe()
577 input_set_drvdata(kp->input, kp); in pmic8xxx_kp_probe()
580 memset(kp->keystate, 0xff, sizeof(kp->keystate)); in pmic8xxx_kp_probe()
581 memset(kp->stuckstate, 0xff, sizeof(kp->stuckstate)); in pmic8xxx_kp_probe()
585 dev_err(&pdev->dev, "unable to initialize keypad controller\n"); in pmic8xxx_kp_probe()
589 rc = devm_request_any_context_irq(&pdev->dev, kp->key_sense_irq, in pmic8xxx_kp_probe()
590 pmic8xxx_kp_irq, IRQF_TRIGGER_RISING, "pmic-keypad", in pmic8xxx_kp_probe()
593 dev_err(&pdev->dev, "failed to request keypad sense irq\n"); in pmic8xxx_kp_probe()
597 rc = devm_request_any_context_irq(&pdev->dev, kp->key_stuck_irq, in pmic8xxx_kp_probe()
599 "pmic-keypad-stuck", kp); in pmic8xxx_kp_probe()
601 dev_err(&pdev->dev, "failed to request keypad stuck irq\n"); in pmic8xxx_kp_probe()
605 rc = regmap_read(kp->regmap, KEYP_CTRL, &ctrl_val); in pmic8xxx_kp_probe()
607 dev_err(&pdev->dev, "failed to read KEYP_CTRL register\n"); in pmic8xxx_kp_probe()
611 kp->ctrl_reg = ctrl_val; in pmic8xxx_kp_probe()
613 rc = input_register_device(kp->input); in pmic8xxx_kp_probe()
615 dev_err(&pdev->dev, "unable to register keypad input device\n"); in pmic8xxx_kp_probe()
619 device_init_wakeup(&pdev->dev, wakeup); in pmic8xxx_kp_probe()
628 struct input_dev *input_dev = kp->input; in pmic8xxx_kp_suspend()
631 enable_irq_wake(kp->key_sense_irq); in pmic8xxx_kp_suspend()
633 mutex_lock(&input_dev->mutex); in pmic8xxx_kp_suspend()
638 mutex_unlock(&input_dev->mutex); in pmic8xxx_kp_suspend()
648 struct input_dev *input_dev = kp->input; in pmic8xxx_kp_resume()
651 disable_irq_wake(kp->key_sense_irq); in pmic8xxx_kp_resume()
653 mutex_lock(&input_dev->mutex); in pmic8xxx_kp_resume()
658 mutex_unlock(&input_dev->mutex); in pmic8xxx_kp_resume()
668 { .compatible = "qcom,pm8058-keypad" },
669 { .compatible = "qcom,pm8921-keypad" },
677 .name = "pm8xxx-keypad",