Lines Matching +full:short +full:- +full:key +full:- +full:debounce

1 // SPDX-License-Identifier: GPL-2.0-or-later
8 * Copyright (C) 2008-2010 Analog Devices Inc.
24 #include <linux/pinctrl/pinconf-generic.h>
34 #define KEY_LCK_EC_STAT 0x03 /* Key Lock and Event Counter Register */
35 #define KEY_EVENTA 0x04 /* Key Event Register A */
36 #define KEY_EVENTB 0x05 /* Key Event Register B */
37 #define KEY_EVENTC 0x06 /* Key Event Register C */
38 #define KEY_EVENTD 0x07 /* Key Event Register D */
39 #define KEY_EVENTE 0x08 /* Key Event Register E */
40 #define KEY_EVENTF 0x09 /* Key Event Register F */
41 #define KEY_EVENTG 0x0A /* Key Event Register G */
42 #define KEY_EVENTH 0x0B /* Key Event Register H */
43 #define KEY_EVENTI 0x0C /* Key Event Register I */
44 #define KEY_EVENTJ 0x0D /* Key Event Register J */
72 #define DEBOUNCE_DIS1 0x29 /* Debounce Disable */
73 #define DEBOUNCE_DIS2 0x2A /* Debounce Disable */
74 #define DEBOUNCE_DIS3 0x2B /* Debounce Disable */
114 /* Key Lock and Event Counter Register */
126 * 128 so it fits matrix-keymap maximum number of keys when the full
158 #define ADP5588_ROWS_MAX (GPI_PIN_ROW7 - GPI_PIN_ROW0 + 1)
159 #define ADP5588_COLS_MAX (GPI_PIN_COL9 - GPI_PIN_COL0 + 1)
161 #define ADP5588_GPIMAPSIZE_MAX (GPI_PIN_END - GPI_PIN_BASE + 1)
163 /* Key Event Register xy */
167 #define KP_SEL(x) (BIT(x) - 1) /* 2^x-1 */
192 unsigned short keycode[ADP5588_KEYMAPSIZE];
208 dev_err(&client->dev, "Read Error\n"); in adp5588_read()
221 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); in adp5588_gpio_get_value()
222 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); in adp5588_gpio_get_value()
225 guard(mutex)(&kpad->gpio_lock); in adp5588_gpio_get_value()
227 if (kpad->dir[bank] & bit) in adp5588_gpio_get_value()
228 val = kpad->dat_out[bank]; in adp5588_gpio_get_value()
230 val = adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank); in adp5588_gpio_get_value()
239 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); in adp5588_gpio_set_value()
240 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); in adp5588_gpio_set_value()
242 guard(mutex)(&kpad->gpio_lock); in adp5588_gpio_set_value()
245 kpad->dat_out[bank] |= bit; in adp5588_gpio_set_value()
247 kpad->dat_out[bank] &= ~bit; in adp5588_gpio_set_value()
249 adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank, kpad->dat_out[bank]); in adp5588_gpio_set_value()
256 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); in adp5588_gpio_set_config()
257 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); in adp5588_gpio_set_config()
268 return -ENOTSUPP; in adp5588_gpio_set_config()
271 guard(mutex)(&kpad->gpio_lock); in adp5588_gpio_set_config()
274 kpad->pull_dis[bank] |= bit; in adp5588_gpio_set_config()
276 kpad->pull_dis[bank] &= bit; in adp5588_gpio_set_config()
278 return adp5588_write(kpad->client, GPIO_PULL1 + bank, in adp5588_gpio_set_config()
279 kpad->pull_dis[bank]); in adp5588_gpio_set_config()
285 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); in adp5588_gpio_direction_input()
286 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); in adp5588_gpio_direction_input()
288 guard(mutex)(&kpad->gpio_lock); in adp5588_gpio_direction_input()
290 kpad->dir[bank] &= ~bit; in adp5588_gpio_direction_input()
291 return adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]); in adp5588_gpio_direction_input()
298 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); in adp5588_gpio_direction_output()
299 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); in adp5588_gpio_direction_output()
302 guard(mutex)(&kpad->gpio_lock); in adp5588_gpio_direction_output()
304 kpad->dir[bank] |= bit; in adp5588_gpio_direction_output()
307 kpad->dat_out[bank] |= bit; in adp5588_gpio_direction_output()
309 kpad->dat_out[bank] &= ~bit; in adp5588_gpio_direction_output()
311 error = adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank, in adp5588_gpio_direction_output()
312 kpad->dat_out[bank]); in adp5588_gpio_direction_output()
316 error = adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]); in adp5588_gpio_direction_output()
331 for (i = 0; i < kpad->rows; i++) in adp5588_build_gpiomap()
334 for (i = 0; i < kpad->cols; i++) in adp5588_build_gpiomap()
335 pin_used[i + GPI_PIN_COL_BASE - GPI_PIN_BASE] = true; in adp5588_build_gpiomap()
339 kpad->gpiomap[n_unused++] = i; in adp5588_build_gpiomap()
349 mutex_lock(&kpad->gpio_lock); in adp5588_irq_bus_lock()
359 if (kpad->int_en[i] ^ kpad->irq_mask[i]) { in adp5588_irq_bus_sync_unlock()
360 kpad->int_en[i] = kpad->irq_mask[i]; in adp5588_irq_bus_sync_unlock()
361 adp5588_write(kpad->client, GPI_EM1 + i, kpad->int_en[i]); in adp5588_irq_bus_sync_unlock()
365 mutex_unlock(&kpad->gpio_lock); in adp5588_irq_bus_sync_unlock()
373 unsigned long real_irq = kpad->gpiomap[hwirq]; in adp5588_irq_mask()
375 kpad->irq_mask[ADP5588_BANK(real_irq)] &= ~ADP5588_BIT(real_irq); in adp5588_irq_mask()
384 unsigned long real_irq = kpad->gpiomap[hwirq]; in adp5588_irq_unmask()
387 kpad->irq_mask[ADP5588_BANK(real_irq)] |= ADP5588_BIT(real_irq); in adp5588_irq_unmask()
393 return -EINVAL; in adp5588_irq_set_type()
413 struct device *dev = &kpad->client->dev; in adp5588_gpio_add()
417 kpad->gc.ngpio = adp5588_build_gpiomap(kpad); in adp5588_gpio_add()
418 if (kpad->gc.ngpio == 0) { in adp5588_gpio_add()
423 kpad->gc.parent = &kpad->client->dev; in adp5588_gpio_add()
424 kpad->gc.direction_input = adp5588_gpio_direction_input; in adp5588_gpio_add()
425 kpad->gc.direction_output = adp5588_gpio_direction_output; in adp5588_gpio_add()
426 kpad->gc.get = adp5588_gpio_get_value; in adp5588_gpio_add()
427 kpad->gc.set = adp5588_gpio_set_value; in adp5588_gpio_add()
428 kpad->gc.set_config = adp5588_gpio_set_config; in adp5588_gpio_add()
429 kpad->gc.can_sleep = 1; in adp5588_gpio_add()
431 kpad->gc.base = -1; in adp5588_gpio_add()
432 kpad->gc.label = kpad->client->name; in adp5588_gpio_add()
433 kpad->gc.owner = THIS_MODULE; in adp5588_gpio_add()
435 if (device_property_present(dev, "interrupt-controller")) { in adp5588_gpio_add()
436 if (!kpad->client->irq) { in adp5588_gpio_add()
438 return -EINVAL; in adp5588_gpio_add()
441 girq = &kpad->gc.irq; in adp5588_gpio_add()
443 girq->handler = handle_bad_irq; in adp5588_gpio_add()
444 girq->threaded = true; in adp5588_gpio_add()
447 mutex_init(&kpad->gpio_lock); in adp5588_gpio_add()
449 error = devm_gpiochip_add_data(dev, &kpad->gc, kpad); in adp5588_gpio_add()
456 kpad->dat_out[i] = adp5588_read(kpad->client, in adp5588_gpio_add()
458 kpad->dir[i] = adp5588_read(kpad->client, GPIO_DIR1 + i); in adp5588_gpio_add()
459 kpad->pull_dis[i] = adp5588_read(kpad->client, GPIO_PULL1 + i); in adp5588_gpio_add()
484 unsigned int irq, gpio = key_val - GPI_PIN_BASE, irq_type; in adp5588_gpio_irq_handle()
485 struct i2c_client *client = kpad->client; in adp5588_gpio_irq_handle()
489 hwirq = adp5588_gpiomap_get_hwirq(&client->dev, kpad->gpiomap, in adp5588_gpio_irq_handle()
490 gpio, kpad->gc.ngpio); in adp5588_gpio_irq_handle()
492 dev_err(&client->dev, "Could not get hwirq for key(%u)\n", key_val); in adp5588_gpio_irq_handle()
496 irq = irq_find_mapping(kpad->gc.irq.domain, hwirq); in adp5588_gpio_irq_handle()
502 dev_err(&client->dev, "Could not get irq(%u) data\n", irq); in adp5588_gpio_irq_handle()
522 int key = adp5588_read(kpad->client, KEY_EVENTA + i); in adp5588_report_events() local
523 int key_val = key & KEY_EV_MASK; in adp5588_report_events()
524 int key_press = key & KEY_EV_PRESSED; in adp5588_report_events()
530 int row = (key_val - 1) / ADP5588_COLS_MAX; in adp5588_report_events()
531 int col = (key_val - 1) % ADP5588_COLS_MAX; in adp5588_report_events()
532 int code = MATRIX_SCAN_CODE(row, col, kpad->row_shift); in adp5588_report_events()
534 dev_dbg_ratelimited(&kpad->client->dev, in adp5588_report_events()
535 "report key(%d) r(%d) c(%d) code(%d)\n", in adp5588_report_events()
536 key_val, row, col, kpad->keycode[code]); in adp5588_report_events()
538 input_report_key(kpad->input, in adp5588_report_events()
539 kpad->keycode[code], key_press); in adp5588_report_events()
548 kpad->irq_time = ktime_get(); in adp5588_hard_irq()
556 struct i2c_client *client = kpad->client; in adp5588_thread_irq()
565 if (kpad->delay) { in adp5588_thread_irq()
566 target_time = ktime_add_ms(kpad->irq_time, kpad->delay); in adp5588_thread_irq()
577 dev_err(&client->dev, "Event Overflow Error\n"); in adp5588_thread_irq()
583 input_sync(kpad->input); in adp5588_thread_irq()
594 struct i2c_client *client = kpad->client; in adp5588_setup()
597 ret = adp5588_write(client, KP_GPIO1, KP_SEL(kpad->rows)); in adp5588_setup()
601 ret = adp5588_write(client, KP_GPIO2, KP_SEL(kpad->cols) & 0xFF); in adp5588_setup()
605 ret = adp5588_write(client, KP_GPIO3, KP_SEL(kpad->cols) >> 8); in adp5588_setup()
609 for (i = 0; i < kpad->nkeys_unlock; i++) { in adp5588_setup()
610 ret = adp5588_write(client, UNLOCK1 + i, kpad->unlock_keys[i]); in adp5588_setup()
615 if (kpad->nkeys_unlock) { in adp5588_setup()
640 struct i2c_client *client = kpad->client; in adp5588_fw_parse()
648 if (!device_property_present(&client->dev, "keypad,num-rows") && in adp5588_fw_parse()
649 !device_property_present(&client->dev, "keypad,num-columns")) { in adp5588_fw_parse()
651 kpad->gpio_only = true; in adp5588_fw_parse()
655 ret = matrix_keypad_parse_properties(&client->dev, &kpad->rows, in adp5588_fw_parse()
656 &kpad->cols); in adp5588_fw_parse()
660 if (kpad->rows > ADP5588_ROWS_MAX || kpad->cols > ADP5588_COLS_MAX) { in adp5588_fw_parse()
661 dev_err(&client->dev, "Invalid nr of rows(%u) or cols(%u)\n", in adp5588_fw_parse()
662 kpad->rows, kpad->cols); in adp5588_fw_parse()
663 return -EINVAL; in adp5588_fw_parse()
666 ret = matrix_keypad_build_keymap(NULL, NULL, kpad->rows, kpad->cols, in adp5588_fw_parse()
667 kpad->keycode, kpad->input); in adp5588_fw_parse()
671 kpad->row_shift = get_count_order(kpad->cols); in adp5588_fw_parse()
673 if (device_property_read_bool(&client->dev, "autorepeat")) in adp5588_fw_parse()
674 __set_bit(EV_REP, kpad->input->evbit); in adp5588_fw_parse()
676 kpad->nkeys_unlock = device_property_count_u32(&client->dev, in adp5588_fw_parse()
677 "adi,unlock-keys"); in adp5588_fw_parse()
678 if (kpad->nkeys_unlock <= 0) { in adp5588_fw_parse()
679 /* so that we don't end up enabling key lock */ in adp5588_fw_parse()
680 kpad->nkeys_unlock = 0; in adp5588_fw_parse()
684 if (kpad->nkeys_unlock > ARRAY_SIZE(kpad->unlock_keys)) { in adp5588_fw_parse()
685 dev_err(&client->dev, "number of unlock keys(%d) > (%zu)\n", in adp5588_fw_parse()
686 kpad->nkeys_unlock, ARRAY_SIZE(kpad->unlock_keys)); in adp5588_fw_parse()
687 return -EINVAL; in adp5588_fw_parse()
690 ret = device_property_read_u32_array(&client->dev, "adi,unlock-keys", in adp5588_fw_parse()
691 kpad->unlock_keys, in adp5588_fw_parse()
692 kpad->nkeys_unlock); in adp5588_fw_parse()
696 for (i = 0; i < kpad->nkeys_unlock; i++) { in adp5588_fw_parse()
705 if (kpad->unlock_keys[i] >= kpad->cols * kpad->rows) { in adp5588_fw_parse()
706 dev_err(&client->dev, "Invalid unlock key(%d)\n", in adp5588_fw_parse()
707 kpad->unlock_keys[i]); in adp5588_fw_parse()
708 return -EINVAL; in adp5588_fw_parse()
715 kpad->unlock_keys[i] += 1; in adp5588_fw_parse()
730 if (!i2c_check_functionality(client->adapter, in adp5588_probe()
732 dev_err(&client->dev, "SMBUS Byte Data not Supported\n"); in adp5588_probe()
733 return -EIO; in adp5588_probe()
736 kpad = devm_kzalloc(&client->dev, sizeof(*kpad), GFP_KERNEL); in adp5588_probe()
738 return -ENOMEM; in adp5588_probe()
740 input = devm_input_allocate_device(&client->dev); in adp5588_probe()
742 return -ENOMEM; in adp5588_probe()
744 kpad->client = client; in adp5588_probe()
745 kpad->input = input; in adp5588_probe()
751 error = devm_regulator_get_enable(&client->dev, "vcc"); in adp5588_probe()
755 gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH); in adp5588_probe()
771 kpad->delay = msecs_to_jiffies(WA_DELAYED_READOUT_TIME); in adp5588_probe()
773 input->name = client->name; in adp5588_probe()
774 input->phys = "adp5588-keys/input0"; in adp5588_probe()
778 input->id.bustype = BUS_I2C; in adp5588_probe()
779 input->id.vendor = 0x0001; in adp5588_probe()
780 input->id.product = 0x0001; in adp5588_probe()
781 input->id.version = revid; in adp5588_probe()
785 dev_err(&client->dev, "unable to register input device: %d\n", in adp5588_probe()
798 if (client->irq) { in adp5588_probe()
799 error = devm_request_threaded_irq(&client->dev, client->irq, in adp5588_probe()
802 client->dev.driver->name, kpad); in adp5588_probe()
804 dev_err(&client->dev, "failed to request irq %d: %d\n", in adp5588_probe()
805 client->irq, error); in adp5588_probe()
810 dev_info(&client->dev, "Rev.%d controller\n", revid); in adp5588_probe()
825 if (client->irq) in adp5588_suspend()
826 disable_irq(client->irq); in adp5588_suspend()
835 if (client->irq) in adp5588_resume()
836 enable_irq(client->irq); in adp5588_resume()
844 { "adp5588-keys" },
845 { "adp5587-keys" },