Lines Matching +full:tegra30 +full:- +full:timer

1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright (c) 2009-2011, NVIDIA Corporation.
104 struct timer_list timer; member
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()
178 * Ghosting occurs if there are 3 keys such that - in tegra_kbc_report_keys()
182 if (kbc->use_ghost_filter && num_down >= 3) { in tegra_kbc_report_keys()
190 * and the other is in the same column as the i-th key. 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()
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()
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()
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()
274 spin_unlock_irqrestore(&kbc->lock, flags); in tegra_kbc_keypress_timer()
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()
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()
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()
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()
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()
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()
387 * mode so the timer routine is scheduled appropriately. 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()
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()
453 const struct tegra_kbc_pin_cfg *pin_cfg = &kbc->pin_cfg[i]; in tegra_kbc_check_pin_cfg()
455 switch (pin_cfg->type) { 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()
460 i, pin_cfg->num); 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()
470 i, pin_cfg->num); in tegra_kbc_check_pin_cfg()
479 dev_err(kbc->dev, in tegra_kbc_check_pin_cfg()
481 pin_cfg->type, pin_cfg->num); in tegra_kbc_check_pin_cfg()
491 struct device_node *np = kbc->dev->of_node; in tegra_kbc_parse_dt()
501 if (!of_property_read_u32(np, "nvidia,debounce-delay-ms", &prop)) in tegra_kbc_parse_dt()
502 kbc->debounce_cnt = prop; in tegra_kbc_parse_dt()
504 if (!of_property_read_u32(np, "nvidia,repeat-delay-ms", &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()
509 if (of_property_read_bool(np, "wakeup-source") || in tegra_kbc_parse_dt()
510 of_property_read_bool(np, "nvidia,wakeup-source")) /* legacy */ in tegra_kbc_parse_dt()
511 kbc->wakeup = true; in tegra_kbc_parse_dt()
513 if (!of_get_property(np, "nvidia,kbc-row-pins", &proplen)) { in tegra_kbc_parse_dt()
514 dev_err(kbc->dev, "property nvidia,kbc-row-pins not found\n"); in tegra_kbc_parse_dt()
515 return -ENOENT; in tegra_kbc_parse_dt()
519 if (!of_get_property(np, "nvidia,kbc-col-pins", &proplen)) { in tegra_kbc_parse_dt()
520 dev_err(kbc->dev, "property nvidia,kbc-col-pins not found\n"); in tegra_kbc_parse_dt()
521 return -ENOENT; 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()
528 return -EINVAL; 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()
534 return -EINVAL; in tegra_kbc_parse_dt()
538 dev_err(kbc->dev, "property linux,keymap not found\n"); in tegra_kbc_parse_dt()
539 return -ENOENT; in tegra_kbc_parse_dt()
543 dev_err(kbc->dev, in tegra_kbc_parse_dt()
545 return -EINVAL; in tegra_kbc_parse_dt()
548 /* Set all pins as non-configured */ 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()
552 ret = of_property_read_u32_array(np, "nvidia,kbc-row-pins", in tegra_kbc_parse_dt()
555 dev_err(kbc->dev, "Rows configurations are not proper\n"); in tegra_kbc_parse_dt()
556 return -EINVAL; in tegra_kbc_parse_dt()
559 ret = of_property_read_u32_array(np, "nvidia,kbc-col-pins", in tegra_kbc_parse_dt()
562 dev_err(kbc->dev, "Cols configurations are not proper\n"); in tegra_kbc_parse_dt()
563 return -EINVAL; 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()
590 { .compatible = "nvidia,tegra114-kbc", .data = &tegra11_kbc_hw_support},
591 { .compatible = "nvidia,tegra30-kbc", .data = &tegra20_kbc_hw_support},
592 { .compatible = "nvidia,tegra20-kbc", .data = &tegra20_kbc_hw_support},
607 match = of_match_device(tegra_kbc_of_match, &pdev->dev); in tegra_kbc_probe()
609 kbc = devm_kzalloc(&pdev->dev, sizeof(*kbc), GFP_KERNEL); in tegra_kbc_probe()
611 dev_err(&pdev->dev, "failed to alloc memory for kbc\n"); in tegra_kbc_probe()
612 return -ENOMEM; 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()
629 return -EINVAL; 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()
633 return -ENXIO; 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()
637 dev_err(&pdev->dev, "failed to allocate input device\n"); in tegra_kbc_probe()
638 return -ENOMEM; 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()
649 dev_err(&pdev->dev, "failed to get keyboard clock\n"); 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()
655 dev_err(&pdev->dev, "failed to get keyboard reset\n"); 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()
684 dev_err(&pdev->dev, "failed to setup keymap\n"); 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()
697 dev_err(&pdev->dev, "failed to request keyboard IRQ\n"); in tegra_kbc_probe()
701 err = input_register_device(kbc->idev); in tegra_kbc_probe()
703 dev_err(&pdev->dev, "failed to register input device\n"); in tegra_kbc_probe()
708 device_init_wakeup(&pdev->dev, kbc->wakeup); in tegra_kbc_probe()
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()
730 mutex_lock(&kbc->idev->mutex); in tegra_kbc_suspend()
731 if (device_may_wakeup(&pdev->dev)) { in tegra_kbc_suspend()
732 disable_irq(kbc->irq); in tegra_kbc_suspend()
733 del_timer_sync(&kbc->timer); 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()
748 kbc->keypress_caused_wake = false; 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()
757 mutex_unlock(&kbc->idev->mutex); in tegra_kbc_suspend()
768 mutex_lock(&kbc->idev->mutex); in tegra_kbc_resume()
769 if (device_may_wakeup(&pdev->dev)) { in tegra_kbc_resume()
770 disable_irq_wake(kbc->irq); in tegra_kbc_resume()
776 writel(kbc->cp_to_wkup_dly, kbc->mmio + KBC_TO_CNT_0); 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()
797 mutex_unlock(&kbc->idev->mutex); in tegra_kbc_resume()
808 .name = "tegra-kbc",
818 MODULE_ALIAS("platform:tegra-kbc");