Lines Matching refs:kbc
143 static void tegra_kbc_report_keys(struct tegra_kbc *kbc) in tegra_kbc_report_keys() argument
156 val = readl(kbc->mmio + KBC_KP_ENT0_0 + i); in tegra_kbc_report_keys()
165 keycodes[num_down] = kbc->keycode[scancode]; in tegra_kbc_report_keys()
167 if ((keycodes[num_down] == KEY_FN) && kbc->use_fn_map) in tegra_kbc_report_keys()
182 if (kbc->use_ghost_filter && num_down >= 3) { in tegra_kbc_report_keys()
210 scancodes[i] += kbc->max_keys; in tegra_kbc_report_keys()
211 keycodes[i] = kbc->keycode[scancodes[i]]; in tegra_kbc_report_keys()
219 tegra_kbc_report_released_keys(kbc->idev, in tegra_kbc_report_keys()
220 kbc->current_keys, kbc->num_pressed_keys, in tegra_kbc_report_keys()
222 tegra_kbc_report_pressed_keys(kbc->idev, scancodes, keycodes, num_down); in tegra_kbc_report_keys()
223 input_sync(kbc->idev); in tegra_kbc_report_keys()
225 memcpy(kbc->current_keys, keycodes, sizeof(kbc->current_keys)); in tegra_kbc_report_keys()
226 kbc->num_pressed_keys = num_down; in tegra_kbc_report_keys()
229 static void tegra_kbc_set_fifo_interrupt(struct tegra_kbc *kbc, bool enable) in tegra_kbc_set_fifo_interrupt() argument
233 val = readl(kbc->mmio + KBC_CONTROL_0); in tegra_kbc_set_fifo_interrupt()
238 writel(val, kbc->mmio + KBC_CONTROL_0); in tegra_kbc_set_fifo_interrupt()
243 struct tegra_kbc *kbc = from_timer(kbc, t, timer); in tegra_kbc_keypress_timer() local
248 spin_lock_irqsave(&kbc->lock, flags); in tegra_kbc_keypress_timer()
250 val = (readl(kbc->mmio + KBC_INT_0) >> 4) & 0xf; in tegra_kbc_keypress_timer()
254 tegra_kbc_report_keys(kbc); in tegra_kbc_keypress_timer()
260 dly = (val == 1) ? kbc->repoll_dly : 1; in tegra_kbc_keypress_timer()
261 mod_timer(&kbc->timer, jiffies + msecs_to_jiffies(dly)); in tegra_kbc_keypress_timer()
264 for (i = 0; i < kbc->num_pressed_keys; i++) in tegra_kbc_keypress_timer()
265 input_report_key(kbc->idev, kbc->current_keys[i], 0); in tegra_kbc_keypress_timer()
266 input_sync(kbc->idev); in tegra_kbc_keypress_timer()
268 kbc->num_pressed_keys = 0; in tegra_kbc_keypress_timer()
271 tegra_kbc_set_fifo_interrupt(kbc, true); in tegra_kbc_keypress_timer()
274 spin_unlock_irqrestore(&kbc->lock, flags); in tegra_kbc_keypress_timer()
279 struct tegra_kbc *kbc = args; in tegra_kbc_isr() local
283 spin_lock_irqsave(&kbc->lock, flags); in tegra_kbc_isr()
289 val = readl(kbc->mmio + KBC_INT_0); in tegra_kbc_isr()
290 writel(val, kbc->mmio + KBC_INT_0); in tegra_kbc_isr()
297 tegra_kbc_set_fifo_interrupt(kbc, false); in tegra_kbc_isr()
298 mod_timer(&kbc->timer, jiffies + kbc->cp_dly_jiffies); in tegra_kbc_isr()
301 kbc->keypress_caused_wake = true; in tegra_kbc_isr()
304 spin_unlock_irqrestore(&kbc->lock, flags); in tegra_kbc_isr()
309 static void tegra_kbc_setup_wakekeys(struct tegra_kbc *kbc, bool filter) in tegra_kbc_setup_wakekeys() argument
315 rst_val = (filter && !kbc->wakeup) ? ~0 : 0; in tegra_kbc_setup_wakekeys()
317 for (i = 0; i < kbc->hw_support->max_rows; i++) in tegra_kbc_setup_wakekeys()
318 writel(rst_val, kbc->mmio + KBC_ROW0_MASK_0 + i * 4); in tegra_kbc_setup_wakekeys()
321 static void tegra_kbc_config_pins(struct tegra_kbc *kbc) in tegra_kbc_config_pins() argument
332 u32 row_cfg = readl(kbc->mmio + r_offs); in tegra_kbc_config_pins()
333 u32 col_cfg = readl(kbc->mmio + c_offs); in tegra_kbc_config_pins()
338 switch (kbc->pin_cfg[i].type) { in tegra_kbc_config_pins()
340 row_cfg |= ((kbc->pin_cfg[i].num << 1) | 1) << r_shft; in tegra_kbc_config_pins()
344 col_cfg |= ((kbc->pin_cfg[i].num << 1) | 1) << c_shft; in tegra_kbc_config_pins()
351 writel(row_cfg, kbc->mmio + r_offs); in tegra_kbc_config_pins()
352 writel(col_cfg, kbc->mmio + c_offs); in tegra_kbc_config_pins()
356 static int tegra_kbc_start(struct tegra_kbc *kbc) in tegra_kbc_start() argument
362 ret = clk_prepare_enable(kbc->clk); in tegra_kbc_start()
367 reset_control_assert(kbc->rst); in tegra_kbc_start()
369 reset_control_deassert(kbc->rst); in tegra_kbc_start()
372 tegra_kbc_config_pins(kbc); in tegra_kbc_start()
373 tegra_kbc_setup_wakekeys(kbc, false); in tegra_kbc_start()
375 writel(kbc->repeat_cnt, kbc->mmio + KBC_RPT_DLY_0); in tegra_kbc_start()
378 debounce_cnt = min(kbc->debounce_cnt, KBC_MAX_DEBOUNCE_CNT); in tegra_kbc_start()
383 writel(val, kbc->mmio + KBC_CONTROL_0); in tegra_kbc_start()
389 val = readl(kbc->mmio + KBC_INIT_DLY_0); in tegra_kbc_start()
390 kbc->cp_dly_jiffies = usecs_to_jiffies((val & 0xfffff) * 32); in tegra_kbc_start()
392 kbc->num_pressed_keys = 0; in tegra_kbc_start()
399 val = readl(kbc->mmio + KBC_INT_0); in tegra_kbc_start()
404 val = readl(kbc->mmio + KBC_KP_ENT0_0); in tegra_kbc_start()
405 val = readl(kbc->mmio + KBC_KP_ENT1_0); in tegra_kbc_start()
407 writel(0x7, kbc->mmio + KBC_INT_0); in tegra_kbc_start()
409 enable_irq(kbc->irq); in tegra_kbc_start()
414 static void tegra_kbc_stop(struct tegra_kbc *kbc) in tegra_kbc_stop() argument
419 spin_lock_irqsave(&kbc->lock, flags); in tegra_kbc_stop()
420 val = readl(kbc->mmio + KBC_CONTROL_0); in tegra_kbc_stop()
422 writel(val, kbc->mmio + KBC_CONTROL_0); in tegra_kbc_stop()
423 spin_unlock_irqrestore(&kbc->lock, flags); in tegra_kbc_stop()
425 disable_irq(kbc->irq); in tegra_kbc_stop()
426 del_timer_sync(&kbc->timer); in tegra_kbc_stop()
428 clk_disable_unprepare(kbc->clk); in tegra_kbc_stop()
433 struct tegra_kbc *kbc = input_get_drvdata(dev); in tegra_kbc_open() local
435 return tegra_kbc_start(kbc); in tegra_kbc_open()
440 struct tegra_kbc *kbc = input_get_drvdata(dev); in tegra_kbc_close() local
442 return tegra_kbc_stop(kbc); in tegra_kbc_close()
445 static bool tegra_kbc_check_pin_cfg(const struct tegra_kbc *kbc, in tegra_kbc_check_pin_cfg() argument
453 const struct tegra_kbc_pin_cfg *pin_cfg = &kbc->pin_cfg[i]; in tegra_kbc_check_pin_cfg()
457 if (pin_cfg->num >= kbc->hw_support->max_rows) { in tegra_kbc_check_pin_cfg()
458 dev_err(kbc->dev, in tegra_kbc_check_pin_cfg()
467 if (pin_cfg->num >= kbc->hw_support->max_columns) { in tegra_kbc_check_pin_cfg()
468 dev_err(kbc->dev, in tegra_kbc_check_pin_cfg()
479 dev_err(kbc->dev, in tegra_kbc_check_pin_cfg()
489 static int tegra_kbc_parse_dt(struct tegra_kbc *kbc) in tegra_kbc_parse_dt() argument
491 struct device_node *np = kbc->dev->of_node; in tegra_kbc_parse_dt()
502 kbc->debounce_cnt = prop; in tegra_kbc_parse_dt()
505 kbc->repeat_cnt = prop; in tegra_kbc_parse_dt()
507 kbc->use_ghost_filter = of_property_present(np, "nvidia,needs-ghost-filter"); in tegra_kbc_parse_dt()
511 kbc->wakeup = true; in tegra_kbc_parse_dt()
514 dev_err(kbc->dev, "property nvidia,kbc-row-pins not found\n"); in tegra_kbc_parse_dt()
520 dev_err(kbc->dev, "property nvidia,kbc-col-pins not found\n"); in tegra_kbc_parse_dt()
525 if (num_rows > kbc->hw_support->max_rows) { in tegra_kbc_parse_dt()
526 dev_err(kbc->dev, in tegra_kbc_parse_dt()
531 if (num_cols > kbc->hw_support->max_columns) { in tegra_kbc_parse_dt()
532 dev_err(kbc->dev, in tegra_kbc_parse_dt()
538 dev_err(kbc->dev, "property linux,keymap not found\n"); in tegra_kbc_parse_dt()
543 dev_err(kbc->dev, in tegra_kbc_parse_dt()
549 for (i = 0; i < kbc->num_rows_and_columns; i++) in tegra_kbc_parse_dt()
550 kbc->pin_cfg[i].type = PIN_CFG_IGNORE; in tegra_kbc_parse_dt()
555 dev_err(kbc->dev, "Rows configurations are not proper\n"); in tegra_kbc_parse_dt()
562 dev_err(kbc->dev, "Cols configurations are not proper\n"); in tegra_kbc_parse_dt()
567 kbc->pin_cfg[rows_cfg[i]].type = PIN_CFG_ROW; in tegra_kbc_parse_dt()
568 kbc->pin_cfg[rows_cfg[i]].num = i; in tegra_kbc_parse_dt()
572 kbc->pin_cfg[cols_cfg[i]].type = PIN_CFG_COL; in tegra_kbc_parse_dt()
573 kbc->pin_cfg[cols_cfg[i]].num = i; in tegra_kbc_parse_dt()
599 struct tegra_kbc *kbc; in tegra_kbc_probe() local
609 kbc = devm_kzalloc(&pdev->dev, sizeof(*kbc), GFP_KERNEL); in tegra_kbc_probe()
610 if (!kbc) { in tegra_kbc_probe()
615 kbc->dev = &pdev->dev; in tegra_kbc_probe()
616 kbc->hw_support = match->data; in tegra_kbc_probe()
617 kbc->max_keys = kbc->hw_support->max_rows * in tegra_kbc_probe()
618 kbc->hw_support->max_columns; in tegra_kbc_probe()
619 kbc->num_rows_and_columns = kbc->hw_support->max_rows + in tegra_kbc_probe()
620 kbc->hw_support->max_columns; in tegra_kbc_probe()
621 keymap_rows = kbc->max_keys; in tegra_kbc_probe()
622 spin_lock_init(&kbc->lock); in tegra_kbc_probe()
624 err = tegra_kbc_parse_dt(kbc); in tegra_kbc_probe()
628 if (!tegra_kbc_check_pin_cfg(kbc, &num_rows)) in tegra_kbc_probe()
631 kbc->irq = platform_get_irq(pdev, 0); in tegra_kbc_probe()
632 if (kbc->irq < 0) in tegra_kbc_probe()
635 kbc->idev = devm_input_allocate_device(&pdev->dev); in tegra_kbc_probe()
636 if (!kbc->idev) { in tegra_kbc_probe()
641 timer_setup(&kbc->timer, tegra_kbc_keypress_timer, 0); in tegra_kbc_probe()
643 kbc->mmio = devm_platform_ioremap_resource(pdev, 0); in tegra_kbc_probe()
644 if (IS_ERR(kbc->mmio)) in tegra_kbc_probe()
645 return PTR_ERR(kbc->mmio); in tegra_kbc_probe()
647 kbc->clk = devm_clk_get(&pdev->dev, NULL); in tegra_kbc_probe()
648 if (IS_ERR(kbc->clk)) { in tegra_kbc_probe()
650 return PTR_ERR(kbc->clk); in tegra_kbc_probe()
653 kbc->rst = devm_reset_control_get(&pdev->dev, "kbc"); in tegra_kbc_probe()
654 if (IS_ERR(kbc->rst)) { in tegra_kbc_probe()
656 return PTR_ERR(kbc->rst); in tegra_kbc_probe()
665 debounce_cnt = min(kbc->debounce_cnt, KBC_MAX_DEBOUNCE_CNT); in tegra_kbc_probe()
667 kbc->repoll_dly = KBC_ROW_SCAN_DLY + scan_time_rows + kbc->repeat_cnt; in tegra_kbc_probe()
668 kbc->repoll_dly = DIV_ROUND_UP(kbc->repoll_dly, KBC_CYCLE_MS); in tegra_kbc_probe()
670 kbc->idev->name = pdev->name; in tegra_kbc_probe()
671 kbc->idev->id.bustype = BUS_HOST; in tegra_kbc_probe()
672 kbc->idev->dev.parent = &pdev->dev; in tegra_kbc_probe()
673 kbc->idev->open = tegra_kbc_open; in tegra_kbc_probe()
674 kbc->idev->close = tegra_kbc_close; in tegra_kbc_probe()
676 if (kbc->keymap_data && kbc->use_fn_map) in tegra_kbc_probe()
679 err = matrix_keypad_build_keymap(kbc->keymap_data, NULL, in tegra_kbc_probe()
681 kbc->hw_support->max_columns, in tegra_kbc_probe()
682 kbc->keycode, kbc->idev); in tegra_kbc_probe()
688 __set_bit(EV_REP, kbc->idev->evbit); in tegra_kbc_probe()
689 input_set_capability(kbc->idev, EV_MSC, MSC_SCAN); in tegra_kbc_probe()
691 input_set_drvdata(kbc->idev, kbc); in tegra_kbc_probe()
693 err = devm_request_irq(&pdev->dev, kbc->irq, tegra_kbc_isr, in tegra_kbc_probe()
695 pdev->name, kbc); in tegra_kbc_probe()
701 err = input_register_device(kbc->idev); in tegra_kbc_probe()
707 platform_set_drvdata(pdev, kbc); in tegra_kbc_probe()
708 device_init_wakeup(&pdev->dev, kbc->wakeup); in tegra_kbc_probe()
713 static void tegra_kbc_set_keypress_interrupt(struct tegra_kbc *kbc, bool enable) in tegra_kbc_set_keypress_interrupt() argument
717 val = readl(kbc->mmio + KBC_CONTROL_0); in tegra_kbc_set_keypress_interrupt()
722 writel(val, kbc->mmio + KBC_CONTROL_0); in tegra_kbc_set_keypress_interrupt()
728 struct tegra_kbc *kbc = platform_get_drvdata(pdev); in tegra_kbc_suspend() local
730 mutex_lock(&kbc->idev->mutex); in tegra_kbc_suspend()
732 disable_irq(kbc->irq); in tegra_kbc_suspend()
733 del_timer_sync(&kbc->timer); in tegra_kbc_suspend()
734 tegra_kbc_set_fifo_interrupt(kbc, false); in tegra_kbc_suspend()
737 writel(0x7, kbc->mmio + KBC_INT_0); in tegra_kbc_suspend()
742 kbc->cp_to_wkup_dly = readl(kbc->mmio + KBC_TO_CNT_0); in tegra_kbc_suspend()
743 writel(0, kbc->mmio + KBC_TO_CNT_0); in tegra_kbc_suspend()
745 tegra_kbc_setup_wakekeys(kbc, true); in tegra_kbc_suspend()
748 kbc->keypress_caused_wake = false; in tegra_kbc_suspend()
750 tegra_kbc_set_keypress_interrupt(kbc, true); in tegra_kbc_suspend()
751 enable_irq(kbc->irq); in tegra_kbc_suspend()
752 enable_irq_wake(kbc->irq); in tegra_kbc_suspend()
754 if (input_device_enabled(kbc->idev)) in tegra_kbc_suspend()
755 tegra_kbc_stop(kbc); in tegra_kbc_suspend()
757 mutex_unlock(&kbc->idev->mutex); in tegra_kbc_suspend()
765 struct tegra_kbc *kbc = platform_get_drvdata(pdev); in tegra_kbc_resume() local
768 mutex_lock(&kbc->idev->mutex); in tegra_kbc_resume()
770 disable_irq_wake(kbc->irq); in tegra_kbc_resume()
771 tegra_kbc_setup_wakekeys(kbc, false); in tegra_kbc_resume()
773 tegra_kbc_set_keypress_interrupt(kbc, false); in tegra_kbc_resume()
776 writel(kbc->cp_to_wkup_dly, kbc->mmio + KBC_TO_CNT_0); in tegra_kbc_resume()
778 tegra_kbc_set_fifo_interrupt(kbc, true); in tegra_kbc_resume()
780 if (kbc->keypress_caused_wake && kbc->wakeup_key) { in tegra_kbc_resume()
788 input_report_key(kbc->idev, kbc->wakeup_key, 1); in tegra_kbc_resume()
789 input_sync(kbc->idev); in tegra_kbc_resume()
790 input_report_key(kbc->idev, kbc->wakeup_key, 0); in tegra_kbc_resume()
791 input_sync(kbc->idev); in tegra_kbc_resume()
794 if (input_device_enabled(kbc->idev)) in tegra_kbc_resume()
795 err = tegra_kbc_start(kbc); in tegra_kbc_resume()
797 mutex_unlock(&kbc->idev->mutex); in tegra_kbc_resume()