Lines Matching +full:scan +full:- +full:interval +full:- +full:ms

1 // SPDX-License-Identifier: GPL-2.0-only
30 /* key debounce interval in milli-second */
52 * HiZ when de-activated to cause minmal side effect when scanning other
59 gpiod_direction_output(keypad->col_gpios[col], 1); in __activate_col()
61 gpiod_set_value_cansleep(keypad->col_gpios[col], 0); in __activate_col()
62 if (!keypad->drive_inactive_cols) in __activate_col()
63 gpiod_direction_input(keypad->col_gpios[col]); in __activate_col()
71 if (on && keypad->col_scan_delay_us) in activate_col()
72 udelay(keypad->col_scan_delay_us); in activate_col()
79 for (col = 0; col < keypad->num_col_gpios; col++) in activate_all_cols()
85 return gpiod_get_value_cansleep(keypad->row_gpios[row]); in row_asserted()
92 for (i = 0; i < keypad->num_row_gpios; i++) in enable_row_irqs()
93 enable_irq(keypad->row_irqs[i]); in enable_row_irqs()
100 for (i = 0; i < keypad->num_row_gpios; i++) in disable_row_irqs()
101 disable_irq_nosync(keypad->row_irqs[i]); in disable_row_irqs()
111 struct input_dev *input_dev = keypad->input_dev; in matrix_keypad_scan()
112 const unsigned short *keycodes = input_dev->keycode; in matrix_keypad_scan()
116 /* de-activate all columns for scanning */ in matrix_keypad_scan()
121 for (row = 0; row < keypad->num_row_gpios; row++) in matrix_keypad_scan()
122 gpiod_direction_input(keypad->row_gpios[row]); in matrix_keypad_scan()
125 for (col = 0; col < keypad->num_col_gpios; col++) { in matrix_keypad_scan()
129 for (row = 0; row < keypad->num_row_gpios; row++) in matrix_keypad_scan()
136 for (col = 0; col < keypad->num_col_gpios; col++) { in matrix_keypad_scan()
139 bits_changed = keypad->last_key_state[col] ^ new_state[col]; in matrix_keypad_scan()
143 for (row = 0; row < keypad->num_row_gpios; row++) { in matrix_keypad_scan()
147 code = MATRIX_SCAN_CODE(row, col, keypad->row_shift); in matrix_keypad_scan()
156 memcpy(keypad->last_key_state, new_state, sizeof(new_state)); in matrix_keypad_scan()
161 spin_lock_irq(&keypad->lock); in matrix_keypad_scan()
162 keypad->scan_pending = false; in matrix_keypad_scan()
164 spin_unlock_irq(&keypad->lock); in matrix_keypad_scan()
172 spin_lock_irqsave(&keypad->lock, flags); in matrix_keypad_interrupt()
176 * scan already. In that case we should not try to in matrix_keypad_interrupt()
179 if (unlikely(keypad->scan_pending || keypad->stopped)) in matrix_keypad_interrupt()
183 keypad->scan_pending = true; in matrix_keypad_interrupt()
184 schedule_delayed_work(&keypad->work, in matrix_keypad_interrupt()
185 msecs_to_jiffies(keypad->debounce_ms)); in matrix_keypad_interrupt()
188 spin_unlock_irqrestore(&keypad->lock, flags); in matrix_keypad_interrupt()
196 keypad->stopped = false; in matrix_keypad_start()
200 * Schedule an immediate key scan to capture current key state; in matrix_keypad_start()
201 * columns will be activated and IRQs be enabled after the scan. in matrix_keypad_start()
203 schedule_delayed_work(&keypad->work, 0); in matrix_keypad_start()
212 spin_lock_irq(&keypad->lock); in matrix_keypad_stop()
213 keypad->stopped = true; in matrix_keypad_stop()
214 spin_unlock_irq(&keypad->lock); in matrix_keypad_stop()
216 flush_delayed_work(&keypad->work); in matrix_keypad_stop()
228 for_each_clear_bit(i, keypad->wakeup_enabled_irqs, in matrix_keypad_enable_wakeup()
229 keypad->num_row_gpios) in matrix_keypad_enable_wakeup()
230 if (enable_irq_wake(keypad->row_irqs[i]) == 0) in matrix_keypad_enable_wakeup()
231 __set_bit(i, keypad->wakeup_enabled_irqs); in matrix_keypad_enable_wakeup()
238 for_each_set_bit(i, keypad->wakeup_enabled_irqs, in matrix_keypad_disable_wakeup()
239 keypad->num_row_gpios) { in matrix_keypad_disable_wakeup()
240 disable_irq_wake(keypad->row_irqs[i]); in matrix_keypad_disable_wakeup()
241 __clear_bit(i, keypad->wakeup_enabled_irqs); in matrix_keypad_disable_wakeup()
250 matrix_keypad_stop(keypad->input_dev); in matrix_keypad_suspend()
252 if (device_may_wakeup(&pdev->dev)) in matrix_keypad_suspend()
263 if (device_may_wakeup(&pdev->dev)) in matrix_keypad_resume()
266 matrix_keypad_start(keypad->input_dev); in matrix_keypad_resume()
282 nrow = gpiod_count(&pdev->dev, "row"); in matrix_keypad_init_gpio()
283 ncol = gpiod_count(&pdev->dev, "col"); in matrix_keypad_init_gpio()
285 dev_err(&pdev->dev, "missing row or column GPIOs\n"); in matrix_keypad_init_gpio()
286 return -EINVAL; in matrix_keypad_init_gpio()
289 keypad->num_row_gpios = nrow; in matrix_keypad_init_gpio()
290 keypad->num_col_gpios = ncol; in matrix_keypad_init_gpio()
292 active_low = device_property_read_bool(&pdev->dev, "gpio-activelow"); in matrix_keypad_init_gpio()
295 for (i = 0; i < keypad->num_col_gpios; i++) { in matrix_keypad_init_gpio()
296 keypad->col_gpios[i] = devm_gpiod_get_index(&pdev->dev, "col", in matrix_keypad_init_gpio()
298 err = PTR_ERR_OR_ZERO(keypad->col_gpios[i]); in matrix_keypad_init_gpio()
300 dev_err(&pdev->dev, in matrix_keypad_init_gpio()
306 gpiod_set_consumer_name(keypad->col_gpios[i], "matrix_kbd_col"); in matrix_keypad_init_gpio()
308 if (active_low ^ gpiod_is_active_low(keypad->col_gpios[i])) in matrix_keypad_init_gpio()
309 gpiod_toggle_active_low(keypad->col_gpios[i]); in matrix_keypad_init_gpio()
311 gpiod_direction_output(keypad->col_gpios[i], 1); in matrix_keypad_init_gpio()
314 for (i = 0; i < keypad->num_row_gpios; i++) { in matrix_keypad_init_gpio()
315 keypad->row_gpios[i] = devm_gpiod_get_index(&pdev->dev, "row", in matrix_keypad_init_gpio()
317 err = PTR_ERR_OR_ZERO(keypad->row_gpios[i]); in matrix_keypad_init_gpio()
319 dev_err(&pdev->dev, in matrix_keypad_init_gpio()
325 gpiod_set_consumer_name(keypad->row_gpios[i], "matrix_kbd_row"); in matrix_keypad_init_gpio()
327 if (active_low ^ gpiod_is_active_low(keypad->row_gpios[i])) in matrix_keypad_init_gpio()
328 gpiod_toggle_active_low(keypad->row_gpios[i]); in matrix_keypad_init_gpio()
341 for (i = 0; i < keypad->num_row_gpios; i++) { in matrix_keypad_setup_interrupts()
342 irq = gpiod_to_irq(keypad->row_gpios[i]); in matrix_keypad_setup_interrupts()
345 dev_err(&pdev->dev, in matrix_keypad_setup_interrupts()
351 err = devm_request_any_context_irq(&pdev->dev, irq, in matrix_keypad_setup_interrupts()
355 "matrix-keypad", keypad); in matrix_keypad_setup_interrupts()
357 dev_err(&pdev->dev, in matrix_keypad_setup_interrupts()
363 keypad->row_irqs[i] = irq; in matrix_keypad_setup_interrupts()
366 /* initialized as disabled - enabled by input->open */ in matrix_keypad_setup_interrupts()
379 keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); in matrix_keypad_probe()
381 return -ENOMEM; in matrix_keypad_probe()
383 input_dev = devm_input_allocate_device(&pdev->dev); in matrix_keypad_probe()
385 return -ENOMEM; in matrix_keypad_probe()
387 keypad->input_dev = input_dev; in matrix_keypad_probe()
388 keypad->stopped = true; in matrix_keypad_probe()
389 INIT_DELAYED_WORK(&keypad->work, matrix_keypad_scan); in matrix_keypad_probe()
390 spin_lock_init(&keypad->lock); in matrix_keypad_probe()
392 keypad->drive_inactive_cols = in matrix_keypad_probe()
393 device_property_read_bool(&pdev->dev, "drive-inactive-cols"); in matrix_keypad_probe()
394 device_property_read_u32(&pdev->dev, "debounce-delay-ms", in matrix_keypad_probe()
395 &keypad->debounce_ms); in matrix_keypad_probe()
396 device_property_read_u32(&pdev->dev, "col-scan-delay-us", in matrix_keypad_probe()
397 &keypad->col_scan_delay_us); in matrix_keypad_probe()
403 keypad->row_shift = get_count_order(keypad->num_col_gpios); in matrix_keypad_probe()
409 input_dev->name = pdev->name; in matrix_keypad_probe()
410 input_dev->id.bustype = BUS_HOST; in matrix_keypad_probe()
411 input_dev->open = matrix_keypad_start; in matrix_keypad_probe()
412 input_dev->close = matrix_keypad_stop; in matrix_keypad_probe()
415 keypad->num_row_gpios, in matrix_keypad_probe()
416 keypad->num_col_gpios, in matrix_keypad_probe()
419 dev_err(&pdev->dev, "failed to build keymap\n"); in matrix_keypad_probe()
420 return -ENOMEM; in matrix_keypad_probe()
423 if (!device_property_read_bool(&pdev->dev, "linux,no-autorepeat")) in matrix_keypad_probe()
424 __set_bit(EV_REP, input_dev->evbit); in matrix_keypad_probe()
429 err = input_register_device(keypad->input_dev); in matrix_keypad_probe()
433 wakeup = device_property_read_bool(&pdev->dev, "wakeup-source") || in matrix_keypad_probe()
435 device_property_read_bool(&pdev->dev, "linux,wakeup"); in matrix_keypad_probe()
436 device_init_wakeup(&pdev->dev, wakeup); in matrix_keypad_probe()
445 { .compatible = "gpio-matrix-keypad" },
454 .name = "matrix-keypad",
464 MODULE_ALIAS("platform:matrix-keypad");