Lines Matching +full:gpio +full:- +full:keymap
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2007-2009 Nokia Corporation
30 #define LM8323_CMD_WRITE_PORT_SEL 0x85 /* Set GPIO in/out. */
31 #define LM8323_CMD_WRITE_PORT_STATE 0x86 /* Set GPIO pullup. */
32 #define LM8323_CMD_READ_PORT_SEL 0x87 /* Get GPIO in/out. */
33 #define LM8323_CMD_READ_PORT_STATE 0x88 /* Get GPIO pullup. */
88 /* Load ramp counter from duty cycle field (range 0 - 0xff). */
142 unsigned short keymap[LM8323_KEYMAP_SIZE]; member
151 #define dev_to_lm8323(d) container_of(d, struct lm8323_chip, client->dev)
171 dev_err(&lm->client->dev, "tried to send %d bytes\n", len); in lm8323_write()
185 ret = i2c_master_send(lm->client, data, len); in lm8323_write()
186 if (unlikely(ret == -EREMOTEIO)) in lm8323_write()
187 ret = i2c_master_send(lm->client, data, len); in lm8323_write()
189 dev_err(&lm->client->dev, "sent %d bytes of %d total\n", in lm8323_write()
207 ret = i2c_master_send(lm->client, &cmd, 1); in lm8323_read()
208 if (unlikely(ret == -EREMOTEIO)) in lm8323_read()
209 ret = i2c_master_send(lm->client, &cmd, 1); in lm8323_read()
211 dev_err(&lm->client->dev, "sending read cmd 0x%02x failed\n", in lm8323_read()
216 ret = i2c_master_recv(lm->client, buf, len); in lm8323_read()
218 dev_err(&lm->client->dev, "wanted %d bytes, got %d\n", in lm8323_read()
233 * The signals are AT-style: the low 7 bits are the keycode, and the top
250 int old_keys_down = lm->keys_down; in process_keys()
261 dev_err(&lm->client->dev, "Failed reading fifo \n"); in process_keys()
269 unsigned short keycode = lm->keymap[key]; in process_keys()
271 dev_vdbg(&lm->client->dev, "key 0x%02x %s\n", in process_keys()
274 if (lm->kp_enabled) { in process_keys()
275 input_event(lm->idev, EV_MSC, MSC_SCAN, key); in process_keys()
276 input_report_key(lm->idev, keycode, isdown); in process_keys()
277 input_sync(lm->idev); in process_keys()
281 lm->keys_down++; in process_keys()
283 lm->keys_down--; in process_keys()
291 if (!old_keys_down && lm->keys_down) in process_keys()
293 if (old_keys_down && !lm->keys_down) in process_keys()
294 lm8323_set_active_time(lm, lm->active_time); in process_keys()
303 dev_vdbg(&lm->client->dev, "fifo overflow!\n"); in lm8323_process_error()
305 dev_vdbg(&lm->client->dev, in lm8323_process_error()
308 dev_vdbg(&lm->client->dev, in lm8323_process_error()
311 dev_vdbg(&lm->client->dev, "bad command parameter\n"); in lm8323_process_error()
323 int keysize = (lm->size_x << 4) | lm->size_y; in lm8323_configure()
325 int debounce = lm->debounce_time >> 2; in lm8323_configure()
326 int active = lm->active_time >> 2; in lm8323_configure()
330 * a close-run thing, give ourselves a 12ms buffer. in lm8323_configure()
338 lm8323_set_active_time(lm, lm->active_time); in lm8323_configure()
353 mutex_lock(&pwm->lock); in pwm_done()
354 pwm->running = false; in pwm_done()
355 if (pwm->desired_brightness != pwm->brightness) in pwm_done()
356 schedule_work(&pwm->work); in pwm_done()
357 mutex_unlock(&pwm->lock); in pwm_done()
370 mutex_lock(&lm->lock); in lm8323_irq()
377 dev_vdbg(&lm->client->dev, "rotator fired\n"); in lm8323_irq()
380 dev_vdbg(&lm->client->dev, "error!\n"); in lm8323_irq()
384 dev_err(&lm->client->dev, "chip lost config; " in lm8323_irq()
390 dev_vdbg(&lm->client->dev, in lm8323_irq()
392 pwm_done(&lm->pwm[i]); in lm8323_irq()
397 mutex_unlock(&lm->lock); in lm8323_irq()
411 return -EIO; in lm8323_read_id()
418 lm8323_write(pwm->chip, 4, LM8323_CMD_PWM_WRITE, (pos << 2) | pwm->id, in lm8323_write_pwm_one()
437 lm8323_write(pwm->chip, 2, LM8323_CMD_START_PWM, pwm->id); in lm8323_write_pwm()
438 pwm->running = true; in lm8323_write_pwm()
448 mutex_lock(&pwm->lock); in lm8323_pwm_work()
456 if (pwm->running || pwm->desired_brightness == pwm->brightness) in lm8323_pwm_work()
459 kill = (pwm->desired_brightness == 0); in lm8323_pwm_work()
460 up = (pwm->desired_brightness > pwm->brightness); in lm8323_pwm_work()
461 steps = abs(pwm->desired_brightness - pwm->brightness); in lm8323_pwm_work()
467 if ((pwm->fade_time / steps) > (32768 / 512)) { in lm8323_pwm_work()
475 perstep = (hz * pwm->fade_time) / (steps * 1000); in lm8323_pwm_work()
487 steps -= s; in lm8323_pwm_work()
491 pwm->brightness = pwm->desired_brightness; in lm8323_pwm_work()
494 mutex_unlock(&pwm->lock); in lm8323_pwm_work()
501 struct lm8323_chip *lm = pwm->chip; in lm8323_pwm_set_brightness()
503 mutex_lock(&pwm->lock); in lm8323_pwm_set_brightness()
504 pwm->desired_brightness = brightness; in lm8323_pwm_set_brightness()
505 mutex_unlock(&pwm->lock); in lm8323_pwm_set_brightness()
508 schedule_work(&pwm->work); in lm8323_pwm_set_brightness()
513 mutex_lock(&lm->lock); in lm8323_pwm_set_brightness()
514 if (likely(!lm->pm_suspend)) in lm8323_pwm_set_brightness()
515 schedule_work(&pwm->work); in lm8323_pwm_set_brightness()
517 lm8323_pwm_work(&pwm->work); in lm8323_pwm_set_brightness()
518 mutex_unlock(&lm->lock); in lm8323_pwm_set_brightness()
528 return sprintf(buf, "%d\n", pwm->fade_time); in lm8323_pwm_show_time()
543 pwm->fade_time = time; in lm8323_pwm_store_time()
563 pwm = &lm->pwm[id - 1]; in init_pwm()
565 pwm->id = id; in init_pwm()
566 pwm->fade_time = 0; in init_pwm()
567 pwm->brightness = 0; in init_pwm()
568 pwm->desired_brightness = 0; in init_pwm()
569 pwm->running = false; in init_pwm()
570 pwm->enabled = false; in init_pwm()
571 INIT_WORK(&pwm->work, lm8323_pwm_work); in init_pwm()
572 mutex_init(&pwm->lock); in init_pwm()
573 pwm->chip = lm; in init_pwm()
576 pwm->cdev.name = name; in init_pwm()
577 pwm->cdev.brightness_set = lm8323_pwm_set_brightness; in init_pwm()
578 pwm->cdev.groups = lm8323_pwm_groups; in init_pwm()
580 err = devm_led_classdev_register(dev, &pwm->cdev); in init_pwm()
585 pwm->enabled = true; in init_pwm()
596 return sprintf(buf, "%u\n", !lm->kp_enabled); in lm8323_show_disable()
611 mutex_lock(&lm->lock); in lm8323_set_disable()
612 lm->kp_enabled = !i; in lm8323_set_disable()
613 mutex_unlock(&lm->lock); in lm8323_set_disable()
627 struct lm8323_platform_data *pdata = dev_get_platdata(&client->dev); in lm8323_probe()
635 if (!pdata || !pdata->size_x || !pdata->size_y) { in lm8323_probe()
636 dev_err(&client->dev, "missing platform_data\n"); in lm8323_probe()
637 return -EINVAL; in lm8323_probe()
640 if (pdata->size_x > 8) { in lm8323_probe()
641 dev_err(&client->dev, "invalid x size %d specified\n", in lm8323_probe()
642 pdata->size_x); in lm8323_probe()
643 return -EINVAL; in lm8323_probe()
646 if (pdata->size_y > 12) { in lm8323_probe()
647 dev_err(&client->dev, "invalid y size %d specified\n", in lm8323_probe()
648 pdata->size_y); in lm8323_probe()
649 return -EINVAL; in lm8323_probe()
652 lm = devm_kzalloc(&client->dev, sizeof(*lm), GFP_KERNEL); in lm8323_probe()
654 return -ENOMEM; in lm8323_probe()
656 idev = devm_input_allocate_device(&client->dev); in lm8323_probe()
658 return -ENOMEM; in lm8323_probe()
660 lm->client = client; in lm8323_probe()
661 lm->idev = idev; in lm8323_probe()
662 mutex_init(&lm->lock); in lm8323_probe()
664 lm->size_x = pdata->size_x; in lm8323_probe()
665 lm->size_y = pdata->size_y; in lm8323_probe()
666 dev_vdbg(&client->dev, "Keypad size: %d x %d\n", in lm8323_probe()
667 lm->size_x, lm->size_y); in lm8323_probe()
669 lm->debounce_time = pdata->debounce_time; in lm8323_probe()
670 lm->active_time = pdata->active_time; in lm8323_probe()
684 dev_err(&client->dev, in lm8323_probe()
696 dev_err(&client->dev, "device not found\n"); in lm8323_probe()
697 return -ENODEV; in lm8323_probe()
701 err = init_pwm(lm, pwm + 1, &client->dev, in lm8323_probe()
702 pdata->pwm_names[pwm]); in lm8323_probe()
707 lm->kp_enabled = true; in lm8323_probe()
709 idev->name = pdata->name ? : "LM8323 keypad"; in lm8323_probe()
710 snprintf(lm->phys, sizeof(lm->phys), in lm8323_probe()
711 "%s/input-kp", dev_name(&client->dev)); in lm8323_probe()
712 idev->phys = lm->phys; in lm8323_probe()
714 idev->evbit[0] = BIT(EV_KEY) | BIT(EV_MSC); in lm8323_probe()
715 __set_bit(MSC_SCAN, idev->mscbit); in lm8323_probe()
717 __set_bit(pdata->keymap[i], idev->keybit); in lm8323_probe()
718 lm->keymap[i] = pdata->keymap[i]; in lm8323_probe()
720 __clear_bit(KEY_RESERVED, idev->keybit); in lm8323_probe()
722 if (pdata->repeat) in lm8323_probe()
723 __set_bit(EV_REP, idev->evbit); in lm8323_probe()
727 dev_dbg(&client->dev, "error registering input device\n"); in lm8323_probe()
731 err = devm_request_threaded_irq(&client->dev, client->irq, in lm8323_probe()
736 dev_err(&client->dev, "could not get IRQ %d\n", client->irq); in lm8323_probe()
742 device_init_wakeup(&client->dev, 1); in lm8323_probe()
743 enable_irq_wake(client->irq); in lm8323_probe()
758 irq_set_irq_wake(client->irq, 0); in lm8323_suspend()
759 disable_irq(client->irq); in lm8323_suspend()
761 mutex_lock(&lm->lock); in lm8323_suspend()
762 lm->pm_suspend = true; in lm8323_suspend()
763 mutex_unlock(&lm->lock); in lm8323_suspend()
766 if (lm->pwm[i].enabled) in lm8323_suspend()
767 led_classdev_suspend(&lm->pwm[i].cdev); in lm8323_suspend()
778 mutex_lock(&lm->lock); in lm8323_resume()
779 lm->pm_suspend = false; in lm8323_resume()
780 mutex_unlock(&lm->lock); in lm8323_resume()
783 if (lm->pwm[i].enabled) in lm8323_resume()
784 led_classdev_resume(&lm->pwm[i].cdev); in lm8323_resume()
786 enable_irq(client->irq); in lm8323_resume()
787 irq_set_irq_wake(client->irq, 1); in lm8323_resume()