Lines Matching +full:unlock +full:- +full:keys

1 // SPDX-License-Identifier: GPL-2.0-or-later
8 * Copyright (C) 2008-2010 Analog Devices Inc.
24 #include <linux/pinctrl/pinconf-generic.h>
46 #define UNLOCK1 0x0F /* Unlock Key1 */
47 #define UNLOCK2 0x10 /* Unlock Key2 */
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)
167 #define KP_SEL(x) (BIT(x) - 1) /* 2^x-1 */
207 dev_err(&client->dev, "Read Error\n"); in adp5588_read()
220 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); in adp5588_gpio_get_value()
221 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); in adp5588_gpio_get_value()
224 mutex_lock(&kpad->gpio_lock); in adp5588_gpio_get_value()
226 if (kpad->dir[bank] & bit) in adp5588_gpio_get_value()
227 val = kpad->dat_out[bank]; in adp5588_gpio_get_value()
229 val = adp5588_read(kpad->client, GPIO_DAT_STAT1 + bank); in adp5588_gpio_get_value()
231 mutex_unlock(&kpad->gpio_lock); in adp5588_gpio_get_value()
240 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); in adp5588_gpio_set_value()
241 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); in adp5588_gpio_set_value()
243 mutex_lock(&kpad->gpio_lock); in adp5588_gpio_set_value()
246 kpad->dat_out[bank] |= bit; in adp5588_gpio_set_value()
248 kpad->dat_out[bank] &= ~bit; in adp5588_gpio_set_value()
250 adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank, kpad->dat_out[bank]); in adp5588_gpio_set_value()
252 mutex_unlock(&kpad->gpio_lock); in adp5588_gpio_set_value()
259 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); in adp5588_gpio_set_config()
260 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); in adp5588_gpio_set_config()
272 return -ENOTSUPP; in adp5588_gpio_set_config()
275 mutex_lock(&kpad->gpio_lock); in adp5588_gpio_set_config()
278 kpad->pull_dis[bank] |= bit; in adp5588_gpio_set_config()
280 kpad->pull_dis[bank] &= bit; in adp5588_gpio_set_config()
282 ret = adp5588_write(kpad->client, GPIO_PULL1 + bank, in adp5588_gpio_set_config()
283 kpad->pull_dis[bank]); in adp5588_gpio_set_config()
285 mutex_unlock(&kpad->gpio_lock); in adp5588_gpio_set_config()
293 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); in adp5588_gpio_direction_input()
294 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); in adp5588_gpio_direction_input()
297 mutex_lock(&kpad->gpio_lock); in adp5588_gpio_direction_input()
299 kpad->dir[bank] &= ~bit; in adp5588_gpio_direction_input()
300 ret = adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]); in adp5588_gpio_direction_input()
302 mutex_unlock(&kpad->gpio_lock); in adp5588_gpio_direction_input()
311 unsigned int bank = ADP5588_BANK(kpad->gpiomap[off]); in adp5588_gpio_direction_output()
312 unsigned int bit = ADP5588_BIT(kpad->gpiomap[off]); in adp5588_gpio_direction_output()
315 mutex_lock(&kpad->gpio_lock); in adp5588_gpio_direction_output()
317 kpad->dir[bank] |= bit; in adp5588_gpio_direction_output()
320 kpad->dat_out[bank] |= bit; in adp5588_gpio_direction_output()
322 kpad->dat_out[bank] &= ~bit; in adp5588_gpio_direction_output()
324 ret = adp5588_write(kpad->client, GPIO_DAT_OUT1 + bank, in adp5588_gpio_direction_output()
325 kpad->dat_out[bank]); in adp5588_gpio_direction_output()
329 ret = adp5588_write(kpad->client, GPIO_DIR1 + bank, kpad->dir[bank]); in adp5588_gpio_direction_output()
332 mutex_unlock(&kpad->gpio_lock); in adp5588_gpio_direction_output()
345 for (i = 0; i < kpad->rows; i++) in adp5588_build_gpiomap()
348 for (i = 0; i < kpad->cols; i++) in adp5588_build_gpiomap()
349 pin_used[i + GPI_PIN_COL_BASE - GPI_PIN_BASE] = true; in adp5588_build_gpiomap()
353 kpad->gpiomap[n_unused++] = i; in adp5588_build_gpiomap()
363 mutex_lock(&kpad->gpio_lock); in adp5588_irq_bus_lock()
373 if (kpad->int_en[i] ^ kpad->irq_mask[i]) { in adp5588_irq_bus_sync_unlock()
374 kpad->int_en[i] = kpad->irq_mask[i]; in adp5588_irq_bus_sync_unlock()
375 adp5588_write(kpad->client, GPI_EM1 + i, kpad->int_en[i]); in adp5588_irq_bus_sync_unlock()
379 mutex_unlock(&kpad->gpio_lock); in adp5588_irq_bus_sync_unlock()
387 unsigned long real_irq = kpad->gpiomap[hwirq]; in adp5588_irq_mask()
389 kpad->irq_mask[ADP5588_BANK(real_irq)] &= ~ADP5588_BIT(real_irq); in adp5588_irq_mask()
398 unsigned long real_irq = kpad->gpiomap[hwirq]; in adp5588_irq_unmask()
401 kpad->irq_mask[ADP5588_BANK(real_irq)] |= ADP5588_BIT(real_irq); in adp5588_irq_unmask()
407 return -EINVAL; in adp5588_irq_set_type()
427 struct device *dev = &kpad->client->dev; in adp5588_gpio_add()
431 kpad->gc.ngpio = adp5588_build_gpiomap(kpad); in adp5588_gpio_add()
432 if (kpad->gc.ngpio == 0) { in adp5588_gpio_add()
437 kpad->gc.parent = &kpad->client->dev; in adp5588_gpio_add()
438 kpad->gc.direction_input = adp5588_gpio_direction_input; in adp5588_gpio_add()
439 kpad->gc.direction_output = adp5588_gpio_direction_output; in adp5588_gpio_add()
440 kpad->gc.get = adp5588_gpio_get_value; in adp5588_gpio_add()
441 kpad->gc.set = adp5588_gpio_set_value; in adp5588_gpio_add()
442 kpad->gc.set_config = adp5588_gpio_set_config; in adp5588_gpio_add()
443 kpad->gc.can_sleep = 1; in adp5588_gpio_add()
445 kpad->gc.base = -1; in adp5588_gpio_add()
446 kpad->gc.label = kpad->client->name; in adp5588_gpio_add()
447 kpad->gc.owner = THIS_MODULE; in adp5588_gpio_add()
449 girq = &kpad->gc.irq; in adp5588_gpio_add()
451 girq->handler = handle_bad_irq; in adp5588_gpio_add()
452 girq->threaded = true; in adp5588_gpio_add()
454 mutex_init(&kpad->gpio_lock); in adp5588_gpio_add()
456 error = devm_gpiochip_add_data(dev, &kpad->gc, kpad); in adp5588_gpio_add()
463 kpad->dat_out[i] = adp5588_read(kpad->client, in adp5588_gpio_add()
465 kpad->dir[i] = adp5588_read(kpad->client, GPIO_DIR1 + i); in adp5588_gpio_add()
466 kpad->pull_dis[i] = adp5588_read(kpad->client, GPIO_PULL1 + i); in adp5588_gpio_add()
491 unsigned int irq, gpio = key_val - GPI_PIN_BASE, irq_type; in adp5588_gpio_irq_handle()
492 struct i2c_client *client = kpad->client; in adp5588_gpio_irq_handle()
496 hwirq = adp5588_gpiomap_get_hwirq(&client->dev, kpad->gpiomap, in adp5588_gpio_irq_handle()
497 gpio, kpad->gc.ngpio); in adp5588_gpio_irq_handle()
499 dev_err(&client->dev, "Could not get hwirq for key(%u)\n", key_val); in adp5588_gpio_irq_handle()
503 irq = irq_find_mapping(kpad->gc.irq.domain, hwirq); in adp5588_gpio_irq_handle()
509 dev_err(&client->dev, "Could not get irq(%u) data\n", irq); in adp5588_gpio_irq_handle()
529 int key = adp5588_read(kpad->client, KEY_EVENTA + i); in adp5588_report_events()
537 int row = (key_val - 1) / ADP5588_COLS_MAX; in adp5588_report_events()
538 int col = (key_val - 1) % ADP5588_COLS_MAX; in adp5588_report_events()
539 int code = MATRIX_SCAN_CODE(row, col, kpad->row_shift); in adp5588_report_events()
541 dev_dbg_ratelimited(&kpad->client->dev, in adp5588_report_events()
543 key_val, row, col, kpad->keycode[code]); in adp5588_report_events()
545 input_report_key(kpad->input, in adp5588_report_events()
546 kpad->keycode[code], key_press); in adp5588_report_events()
555 kpad->irq_time = ktime_get(); in adp5588_hard_irq()
563 struct i2c_client *client = kpad->client; in adp5588_thread_irq()
572 if (kpad->delay) { in adp5588_thread_irq()
573 target_time = ktime_add_ms(kpad->irq_time, kpad->delay); in adp5588_thread_irq()
584 dev_err(&client->dev, "Event Overflow Error\n"); in adp5588_thread_irq()
590 input_sync(kpad->input); in adp5588_thread_irq()
601 struct i2c_client *client = kpad->client; in adp5588_setup()
604 ret = adp5588_write(client, KP_GPIO1, KP_SEL(kpad->rows)); in adp5588_setup()
608 ret = adp5588_write(client, KP_GPIO2, KP_SEL(kpad->cols) & 0xFF); in adp5588_setup()
612 ret = adp5588_write(client, KP_GPIO3, KP_SEL(kpad->cols) >> 8); in adp5588_setup()
616 for (i = 0; i < kpad->nkeys_unlock; i++) { in adp5588_setup()
617 ret = adp5588_write(client, UNLOCK1 + i, kpad->unlock_keys[i]); in adp5588_setup()
622 if (kpad->nkeys_unlock) { in adp5588_setup()
647 struct i2c_client *client = kpad->client; in adp5588_fw_parse()
650 ret = matrix_keypad_parse_properties(&client->dev, &kpad->rows, in adp5588_fw_parse()
651 &kpad->cols); in adp5588_fw_parse()
655 if (kpad->rows > ADP5588_ROWS_MAX || kpad->cols > ADP5588_COLS_MAX) { in adp5588_fw_parse()
656 dev_err(&client->dev, "Invalid nr of rows(%u) or cols(%u)\n", in adp5588_fw_parse()
657 kpad->rows, kpad->cols); in adp5588_fw_parse()
658 return -EINVAL; in adp5588_fw_parse()
661 ret = matrix_keypad_build_keymap(NULL, NULL, kpad->rows, kpad->cols, in adp5588_fw_parse()
662 kpad->keycode, kpad->input); in adp5588_fw_parse()
666 kpad->row_shift = get_count_order(kpad->cols); in adp5588_fw_parse()
668 if (device_property_read_bool(&client->dev, "autorepeat")) in adp5588_fw_parse()
669 __set_bit(EV_REP, kpad->input->evbit); in adp5588_fw_parse()
671 kpad->nkeys_unlock = device_property_count_u32(&client->dev, in adp5588_fw_parse()
672 "adi,unlock-keys"); in adp5588_fw_parse()
673 if (kpad->nkeys_unlock <= 0) { in adp5588_fw_parse()
675 kpad->nkeys_unlock = 0; in adp5588_fw_parse()
679 if (kpad->nkeys_unlock > ARRAY_SIZE(kpad->unlock_keys)) { in adp5588_fw_parse()
680 dev_err(&client->dev, "number of unlock keys(%d) > (%zu)\n", in adp5588_fw_parse()
681 kpad->nkeys_unlock, ARRAY_SIZE(kpad->unlock_keys)); in adp5588_fw_parse()
682 return -EINVAL; in adp5588_fw_parse()
685 ret = device_property_read_u32_array(&client->dev, "adi,unlock-keys", in adp5588_fw_parse()
686 kpad->unlock_keys, in adp5588_fw_parse()
687 kpad->nkeys_unlock); in adp5588_fw_parse()
691 for (i = 0; i < kpad->nkeys_unlock; i++) { in adp5588_fw_parse()
694 * to use GPIs (which are part of the keys event) as unlock keys, in adp5588_fw_parse()
696 * at some point. Hence, for now, let's just allow keys which are in adp5588_fw_parse()
700 if (kpad->unlock_keys[i] >= kpad->cols * kpad->rows) { in adp5588_fw_parse()
701 dev_err(&client->dev, "Invalid unlock key(%d)\n", in adp5588_fw_parse()
702 kpad->unlock_keys[i]); in adp5588_fw_parse()
703 return -EINVAL; in adp5588_fw_parse()
707 * Firmware properties keys start from 0 but on the device they in adp5588_fw_parse()
710 kpad->unlock_keys[i] += 1; in adp5588_fw_parse()
732 if (!i2c_check_functionality(client->adapter, in adp5588_probe()
734 dev_err(&client->dev, "SMBUS Byte Data not Supported\n"); in adp5588_probe()
735 return -EIO; in adp5588_probe()
738 kpad = devm_kzalloc(&client->dev, sizeof(*kpad), GFP_KERNEL); in adp5588_probe()
740 return -ENOMEM; in adp5588_probe()
742 input = devm_input_allocate_device(&client->dev); in adp5588_probe()
744 return -ENOMEM; in adp5588_probe()
746 kpad->client = client; in adp5588_probe()
747 kpad->input = input; in adp5588_probe()
753 vcc = devm_regulator_get(&client->dev, "vcc"); in adp5588_probe()
761 error = devm_add_action_or_reset(&client->dev, in adp5588_probe()
766 gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH); in adp5588_probe()
782 kpad->delay = msecs_to_jiffies(WA_DELAYED_READOUT_TIME); in adp5588_probe()
784 input->name = client->name; in adp5588_probe()
785 input->phys = "adp5588-keys/input0"; in adp5588_probe()
789 input->id.bustype = BUS_I2C; in adp5588_probe()
790 input->id.vendor = 0x0001; in adp5588_probe()
791 input->id.product = 0x0001; in adp5588_probe()
792 input->id.version = revid; in adp5588_probe()
796 dev_err(&client->dev, "unable to register input device: %d\n", in adp5588_probe()
809 error = devm_request_threaded_irq(&client->dev, client->irq, in adp5588_probe()
812 client->dev.driver->name, kpad); in adp5588_probe()
814 dev_err(&client->dev, "failed to request irq %d: %d\n", in adp5588_probe()
815 client->irq, error); in adp5588_probe()
819 dev_info(&client->dev, "Rev.%d keypad, irq %d\n", revid, client->irq); in adp5588_probe()
834 disable_irq(client->irq); in adp5588_suspend()
843 enable_irq(client->irq); in adp5588_resume()
851 { "adp5588-keys", 0 },
852 { "adp5587-keys", 0 },