Lines Matching +full:num +full:- +full:rows
1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright (c) 2009-2011, NVIDIA Corporation.
80 unsigned char num; 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()
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()
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 if (of_find_property(np, "nvidia,needs-ghost-filter", NULL)) in tegra_kbc_parse_dt()
508 kbc->use_ghost_filter = true; in tegra_kbc_parse_dt()
510 if (of_property_read_bool(np, "wakeup-source") || in tegra_kbc_parse_dt()
511 of_property_read_bool(np, "nvidia,wakeup-source")) /* legacy */ in tegra_kbc_parse_dt()
512 kbc->wakeup = true; in tegra_kbc_parse_dt()
514 if (!of_get_property(np, "nvidia,kbc-row-pins", &proplen)) { in tegra_kbc_parse_dt()
515 dev_err(kbc->dev, "property nvidia,kbc-row-pins not found\n"); in tegra_kbc_parse_dt()
516 return -ENOENT; in tegra_kbc_parse_dt()
520 if (!of_get_property(np, "nvidia,kbc-col-pins", &proplen)) { in tegra_kbc_parse_dt()
521 dev_err(kbc->dev, "property nvidia,kbc-col-pins not found\n"); in tegra_kbc_parse_dt()
522 return -ENOENT; in tegra_kbc_parse_dt()
526 if (num_rows > kbc->hw_support->max_rows) { in tegra_kbc_parse_dt()
527 dev_err(kbc->dev, in tegra_kbc_parse_dt()
528 "Number of rows is more than supported by hardware\n"); in tegra_kbc_parse_dt()
529 return -EINVAL; in tegra_kbc_parse_dt()
532 if (num_cols > kbc->hw_support->max_columns) { in tegra_kbc_parse_dt()
533 dev_err(kbc->dev, in tegra_kbc_parse_dt()
535 return -EINVAL; in tegra_kbc_parse_dt()
539 dev_err(kbc->dev, "property linux,keymap not found\n"); in tegra_kbc_parse_dt()
540 return -ENOENT; in tegra_kbc_parse_dt()
544 dev_err(kbc->dev, in tegra_kbc_parse_dt()
545 "keypad rows/columns not properly specified\n"); in tegra_kbc_parse_dt()
546 return -EINVAL; in tegra_kbc_parse_dt()
549 /* Set all pins as non-configured */ in tegra_kbc_parse_dt()
550 for (i = 0; i < kbc->num_rows_and_columns; i++) in tegra_kbc_parse_dt()
551 kbc->pin_cfg[i].type = PIN_CFG_IGNORE; in tegra_kbc_parse_dt()
553 ret = of_property_read_u32_array(np, "nvidia,kbc-row-pins", in tegra_kbc_parse_dt()
556 dev_err(kbc->dev, "Rows configurations are not proper\n"); in tegra_kbc_parse_dt()
557 return -EINVAL; in tegra_kbc_parse_dt()
560 ret = of_property_read_u32_array(np, "nvidia,kbc-col-pins", in tegra_kbc_parse_dt()
563 dev_err(kbc->dev, "Cols configurations are not proper\n"); in tegra_kbc_parse_dt()
564 return -EINVAL; in tegra_kbc_parse_dt()
568 kbc->pin_cfg[rows_cfg[i]].type = PIN_CFG_ROW; in tegra_kbc_parse_dt()
569 kbc->pin_cfg[rows_cfg[i]].num = i; in tegra_kbc_parse_dt()
573 kbc->pin_cfg[cols_cfg[i]].type = PIN_CFG_COL; in tegra_kbc_parse_dt()
574 kbc->pin_cfg[cols_cfg[i]].num = i; in tegra_kbc_parse_dt()
591 { .compatible = "nvidia,tegra114-kbc", .data = &tegra11_kbc_hw_support},
592 { .compatible = "nvidia,tegra30-kbc", .data = &tegra20_kbc_hw_support},
593 { .compatible = "nvidia,tegra20-kbc", .data = &tegra20_kbc_hw_support},
609 match = of_match_device(tegra_kbc_of_match, &pdev->dev); in tegra_kbc_probe()
611 kbc = devm_kzalloc(&pdev->dev, sizeof(*kbc), GFP_KERNEL); in tegra_kbc_probe()
613 dev_err(&pdev->dev, "failed to alloc memory for kbc\n"); in tegra_kbc_probe()
614 return -ENOMEM; in tegra_kbc_probe()
617 kbc->dev = &pdev->dev; in tegra_kbc_probe()
618 kbc->hw_support = match->data; in tegra_kbc_probe()
619 kbc->max_keys = kbc->hw_support->max_rows * in tegra_kbc_probe()
620 kbc->hw_support->max_columns; in tegra_kbc_probe()
621 kbc->num_rows_and_columns = kbc->hw_support->max_rows + in tegra_kbc_probe()
622 kbc->hw_support->max_columns; in tegra_kbc_probe()
623 keymap_rows = kbc->max_keys; in tegra_kbc_probe()
624 spin_lock_init(&kbc->lock); in tegra_kbc_probe()
631 return -EINVAL; in tegra_kbc_probe()
633 kbc->irq = platform_get_irq(pdev, 0); in tegra_kbc_probe()
634 if (kbc->irq < 0) in tegra_kbc_probe()
635 return -ENXIO; in tegra_kbc_probe()
637 kbc->idev = devm_input_allocate_device(&pdev->dev); in tegra_kbc_probe()
638 if (!kbc->idev) { in tegra_kbc_probe()
639 dev_err(&pdev->dev, "failed to allocate input device\n"); in tegra_kbc_probe()
640 return -ENOMEM; in tegra_kbc_probe()
643 timer_setup(&kbc->timer, tegra_kbc_keypress_timer, 0); in tegra_kbc_probe()
646 kbc->mmio = devm_ioremap_resource(&pdev->dev, res); in tegra_kbc_probe()
647 if (IS_ERR(kbc->mmio)) in tegra_kbc_probe()
648 return PTR_ERR(kbc->mmio); in tegra_kbc_probe()
650 kbc->clk = devm_clk_get(&pdev->dev, NULL); in tegra_kbc_probe()
651 if (IS_ERR(kbc->clk)) { in tegra_kbc_probe()
652 dev_err(&pdev->dev, "failed to get keyboard clock\n"); in tegra_kbc_probe()
653 return PTR_ERR(kbc->clk); in tegra_kbc_probe()
656 kbc->rst = devm_reset_control_get(&pdev->dev, "kbc"); in tegra_kbc_probe()
657 if (IS_ERR(kbc->rst)) { in tegra_kbc_probe()
658 dev_err(&pdev->dev, "failed to get keyboard reset\n"); in tegra_kbc_probe()
659 return PTR_ERR(kbc->rst); in tegra_kbc_probe()
665 * the rows. There is an additional delay before the row scanning in tegra_kbc_probe()
668 debounce_cnt = min(kbc->debounce_cnt, KBC_MAX_DEBOUNCE_CNT); in tegra_kbc_probe()
670 kbc->repoll_dly = KBC_ROW_SCAN_DLY + scan_time_rows + kbc->repeat_cnt; in tegra_kbc_probe()
671 kbc->repoll_dly = DIV_ROUND_UP(kbc->repoll_dly, KBC_CYCLE_MS); in tegra_kbc_probe()
673 kbc->idev->name = pdev->name; in tegra_kbc_probe()
674 kbc->idev->id.bustype = BUS_HOST; in tegra_kbc_probe()
675 kbc->idev->dev.parent = &pdev->dev; in tegra_kbc_probe()
676 kbc->idev->open = tegra_kbc_open; in tegra_kbc_probe()
677 kbc->idev->close = tegra_kbc_close; in tegra_kbc_probe()
679 if (kbc->keymap_data && kbc->use_fn_map) in tegra_kbc_probe()
682 err = matrix_keypad_build_keymap(kbc->keymap_data, NULL, in tegra_kbc_probe()
684 kbc->hw_support->max_columns, in tegra_kbc_probe()
685 kbc->keycode, kbc->idev); in tegra_kbc_probe()
687 dev_err(&pdev->dev, "failed to setup keymap\n"); in tegra_kbc_probe()
691 __set_bit(EV_REP, kbc->idev->evbit); in tegra_kbc_probe()
692 input_set_capability(kbc->idev, EV_MSC, MSC_SCAN); in tegra_kbc_probe()
694 input_set_drvdata(kbc->idev, kbc); in tegra_kbc_probe()
696 err = devm_request_irq(&pdev->dev, kbc->irq, tegra_kbc_isr, in tegra_kbc_probe()
698 pdev->name, kbc); in tegra_kbc_probe()
700 dev_err(&pdev->dev, "failed to request keyboard IRQ\n"); in tegra_kbc_probe()
704 err = input_register_device(kbc->idev); in tegra_kbc_probe()
706 dev_err(&pdev->dev, "failed to register input device\n"); in tegra_kbc_probe()
711 device_init_wakeup(&pdev->dev, kbc->wakeup); in tegra_kbc_probe()
721 val = readl(kbc->mmio + KBC_CONTROL_0); in tegra_kbc_set_keypress_interrupt()
726 writel(val, kbc->mmio + KBC_CONTROL_0); in tegra_kbc_set_keypress_interrupt()
734 mutex_lock(&kbc->idev->mutex); in tegra_kbc_suspend()
735 if (device_may_wakeup(&pdev->dev)) { in tegra_kbc_suspend()
736 disable_irq(kbc->irq); in tegra_kbc_suspend()
737 del_timer_sync(&kbc->timer); in tegra_kbc_suspend()
741 writel(0x7, kbc->mmio + KBC_INT_0); in tegra_kbc_suspend()
746 kbc->cp_to_wkup_dly = readl(kbc->mmio + KBC_TO_CNT_0); in tegra_kbc_suspend()
747 writel(0, kbc->mmio + KBC_TO_CNT_0); in tegra_kbc_suspend()
752 kbc->keypress_caused_wake = false; in tegra_kbc_suspend()
755 enable_irq(kbc->irq); in tegra_kbc_suspend()
756 enable_irq_wake(kbc->irq); in tegra_kbc_suspend()
758 if (input_device_enabled(kbc->idev)) in tegra_kbc_suspend()
761 mutex_unlock(&kbc->idev->mutex); in tegra_kbc_suspend()
772 mutex_lock(&kbc->idev->mutex); in tegra_kbc_resume()
773 if (device_may_wakeup(&pdev->dev)) { in tegra_kbc_resume()
774 disable_irq_wake(kbc->irq); in tegra_kbc_resume()
780 writel(kbc->cp_to_wkup_dly, kbc->mmio + KBC_TO_CNT_0); in tegra_kbc_resume()
784 if (kbc->keypress_caused_wake && kbc->wakeup_key) { in tegra_kbc_resume()
792 input_report_key(kbc->idev, kbc->wakeup_key, 1); in tegra_kbc_resume()
793 input_sync(kbc->idev); in tegra_kbc_resume()
794 input_report_key(kbc->idev, kbc->wakeup_key, 0); in tegra_kbc_resume()
795 input_sync(kbc->idev); in tegra_kbc_resume()
798 if (input_device_enabled(kbc->idev)) in tegra_kbc_resume()
801 mutex_unlock(&kbc->idev->mutex); in tegra_kbc_resume()
812 .name = "tegra-kbc",
822 MODULE_ALIAS("platform:tegra-kbc");