Lines Matching refs:kp
108 static u8 pmic8xxx_col_state(struct pmic8xxx_kp *kp, u8 col) in pmic8xxx_col_state() argument
112 return 1 << kp->num_cols; in pmic8xxx_col_state()
114 return col & ((1 << kp->num_cols) - 1); in pmic8xxx_col_state()
129 static int pmic8xxx_chk_sync_read(struct pmic8xxx_kp *kp) in pmic8xxx_chk_sync_read() argument
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()
154 static int pmic8xxx_kp_read_data(struct pmic8xxx_kp *kp, u16 *state, in pmic8xxx_kp_read_data() argument
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()
171 static int pmic8xxx_kp_read_matrix(struct pmic8xxx_kp *kp, u16 *new_state, in pmic8xxx_kp_read_matrix() argument
177 if (kp->num_rows < PM8XXX_MIN_ROWS) in pmic8xxx_kp_read_matrix()
180 read_rows = kp->num_rows; in pmic8xxx_kp_read_matrix()
182 pmic8xxx_chk_sync_read(kp); in pmic8xxx_kp_read_matrix()
185 rc = pmic8xxx_kp_read_data(kp, old_state, KEYP_OLD_DATA, in pmic8xxx_kp_read_matrix()
188 dev_err(kp->dev, in pmic8xxx_kp_read_matrix()
194 rc = pmic8xxx_kp_read_data(kp, new_state, KEYP_RECENT_DATA, 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()
219 static void __pmic8xxx_kp_scan_matrix(struct pmic8xxx_kp *kp, u16 *new_state, in __pmic8xxx_kp_scan_matrix() argument
224 for (row = 0; row < kp->num_rows; 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()
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()
245 input_sync(kp->input); in __pmic8xxx_kp_scan_matrix()
250 static bool pmic8xxx_detect_ghost_keys(struct pmic8xxx_kp *kp, u16 *new_state) in pmic8xxx_detect_ghost_keys() argument
256 for (row = 0; row < kp->num_rows; row++) { in pmic8xxx_detect_ghost_keys()
258 ((1 << kp->num_cols) - 1); in pmic8xxx_detect_ghost_keys()
264 dev_dbg(kp->dev, "detected ghost key on row[%d]" in pmic8xxx_detect_ghost_keys()
274 static int pmic8xxx_kp_scan_matrix(struct pmic8xxx_kp *kp, unsigned int events) in pmic8xxx_kp_scan_matrix() argument
282 rc = pmic8xxx_kp_read_matrix(kp, new_state, NULL); in pmic8xxx_kp_scan_matrix()
287 if (pmic8xxx_detect_ghost_keys(kp, new_state)) in pmic8xxx_kp_scan_matrix()
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()
293 rc = pmic8xxx_kp_read_matrix(kp, new_state, old_state); in pmic8xxx_kp_scan_matrix()
297 __pmic8xxx_kp_scan_matrix(kp, old_state, kp->keystate); in pmic8xxx_kp_scan_matrix()
298 __pmic8xxx_kp_scan_matrix(kp, new_state, old_state); 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()
303 rc = pmic8xxx_kp_read_matrix(kp, new_state, old_state); in pmic8xxx_kp_scan_matrix()
306 __pmic8xxx_kp_scan_matrix(kp, old_state, kp->keystate); in pmic8xxx_kp_scan_matrix()
307 __pmic8xxx_kp_scan_matrix(kp, new_state, old_state); in pmic8xxx_kp_scan_matrix()
308 memcpy(kp->keystate, new_state, sizeof(new_state)); in pmic8xxx_kp_scan_matrix()
332 struct pmic8xxx_kp *kp = data; in pmic8xxx_kp_stuck_irq() local
334 rc = pmic8xxx_kp_read_matrix(kp, new_state, old_state); in pmic8xxx_kp_stuck_irq()
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()
347 struct pmic8xxx_kp *kp = data; in pmic8xxx_kp_irq() local
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()
359 rc = pmic8xxx_kp_scan_matrix(kp, events); in pmic8xxx_kp_irq()
361 dev_err(kp->dev, "failed to scan matrix\n"); in pmic8xxx_kp_irq()
366 static int pmic8xxx_kpd_init(struct pmic8xxx_kp *kp, in pmic8xxx_kpd_init() argument
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()
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()
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()
450 static int pmic8xxx_kp_enable(struct pmic8xxx_kp *kp) in pmic8xxx_kp_enable() argument
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()
463 static int pmic8xxx_kp_disable(struct pmic8xxx_kp *kp) in pmic8xxx_kp_disable() argument
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()
478 struct pmic8xxx_kp *kp = input_get_drvdata(dev); in pmic8xxx_kp_open() local
480 return pmic8xxx_kp_enable(kp); in pmic8xxx_kp_open()
485 struct pmic8xxx_kp *kp = input_get_drvdata(dev); in pmic8xxx_kp_close() local
487 pmic8xxx_kp_disable(kp); in pmic8xxx_kp_close()
506 struct pmic8xxx_kp *kp; in pmic8xxx_kp_probe() local
526 kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL); in pmic8xxx_kp_probe()
527 if (!kp) 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()
534 platform_set_drvdata(pdev, kp); 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()
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()
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()
583 rc = pmic8xxx_kpd_init(kp, pdev); in pmic8xxx_kp_probe()
589 rc = devm_request_any_context_irq(&pdev->dev, kp->key_sense_irq, in pmic8xxx_kp_probe()
591 kp); 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()
605 rc = regmap_read(kp->regmap, KEYP_CTRL, &ctrl_val); 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()
628 struct pmic8xxx_kp *kp = platform_get_drvdata(pdev); in pmic8xxx_kp_suspend() local
629 struct input_dev *input_dev = kp->input; in pmic8xxx_kp_suspend()
632 enable_irq_wake(kp->key_sense_irq); in pmic8xxx_kp_suspend()
637 pmic8xxx_kp_disable(kp); in pmic8xxx_kp_suspend()
648 struct pmic8xxx_kp *kp = platform_get_drvdata(pdev); in pmic8xxx_kp_resume() local
649 struct input_dev *input_dev = kp->input; in pmic8xxx_kp_resume()
652 disable_irq_wake(kp->key_sense_irq); in pmic8xxx_kp_resume()
657 pmic8xxx_kp_enable(kp); in pmic8xxx_kp_resume()