Lines Matching +full:codec +full:- +full:irq
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * wm97xx-core.c -- Touch screen driver core for Wolfson WM9705, WM9712
15 * - supports WM9705, WM9712, WM9713
16 * - polling mode
17 * - continuous mode (arch-dependent)
18 * - adjustable rpu/dpp settings
19 * - adjustable pressure current
20 * - adjustable sample settle delay
21 * - 4 and 5 wire touchscreens (5 wire is WM9712 only)
22 * - pen down detection
23 * - battery monitor
24 * - sample AUX adcs
25 * - power management
26 * - codec GPIO
27 * - codec event notification
29 * - Support for async sampling control for noisy LCDs.
60 * o min, max:- indicate the min and max values your touch screen returns
61 * o fuzz:- use a higher number to reduce jitter
66 * Documentation/input/input-programming.rst for more details.
86 if (wm->ac97) in wm97xx_reg_read()
87 return wm->ac97->bus->ops->read(wm->ac97, reg); in wm97xx_reg_read()
89 return -1; in wm97xx_reg_read()
97 wm->dig[(reg - AC97_WM9713_DIG1) >> 1] = val; in wm97xx_reg_write()
101 wm->gpio[(reg - AC97_GPIO_CFG) >> 1] = val; in wm97xx_reg_write()
103 /* wm9713 irq reg */ in wm97xx_reg_write()
105 wm->misc = val; in wm97xx_reg_write()
107 if (wm->ac97) in wm97xx_reg_write()
108 wm->ac97->bus->ops->write(wm->ac97, reg, val); in wm97xx_reg_write()
113 * wm97xx_read_aux_adc - Read the aux adc.
115 * @adcsel: codec ADC to be read
127 /* get codec */ in wm97xx_read_aux_adc()
128 mutex_lock(&wm->codec_mutex); in wm97xx_read_aux_adc()
131 * the AUX ADC before we can use sample the AUX inputs-> in wm97xx_read_aux_adc()
133 if (wm->id == WM9713_ID2 && in wm97xx_read_aux_adc()
139 /* Prepare the codec for AUX reading */ in wm97xx_read_aux_adc()
140 wm->codec->aux_prepare(wm); in wm97xx_read_aux_adc()
143 wm->pen_probably_down = 1; in wm97xx_read_aux_adc()
146 rc = wm->codec->poll_sample(wm, adcsel, &auxval); in wm97xx_read_aux_adc()
151 wm->codec->dig_restore(wm); in wm97xx_read_aux_adc()
153 wm->pen_probably_down = 0; in wm97xx_read_aux_adc()
156 dev_err(wm->dev, in wm97xx_read_aux_adc()
159 wm->codec->dig_enable(wm, false); in wm97xx_read_aux_adc()
162 mutex_unlock(&wm->codec_mutex); in wm97xx_read_aux_adc()
163 return (rc == RC_VALID ? auxval & 0xfff : -EBUSY); in wm97xx_read_aux_adc()
168 * wm97xx_get_gpio - Get the status of a codec GPIO.
172 * Get the status of a codec GPIO pin
180 mutex_lock(&wm->codec_mutex); in wm97xx_get_gpio()
188 mutex_unlock(&wm->codec_mutex); in wm97xx_get_gpio()
194 * wm97xx_set_gpio - Set the status of a codec GPIO.
199 * Set the status of a codec GPIO pin
207 mutex_lock(&wm->codec_mutex); in wm97xx_set_gpio()
215 if (wm->id == WM9712_ID2 && wm->variant != WM97xx_WM1613) in wm97xx_set_gpio()
219 mutex_unlock(&wm->codec_mutex); in wm97xx_set_gpio()
224 * Codec GPIO pin configuration, this sets pin direction, polarity,
233 mutex_lock(&wm->codec_mutex); in wm97xx_config_gpio()
266 mutex_unlock(&wm->codec_mutex); in wm97xx_config_gpio()
282 wm->suspend_mode = mode; in wm97xx_set_suspend_mode()
283 device_init_wakeup(&wm->input_dev->dev, mode != 0); in wm97xx_set_suspend_mode()
288 * Codec PENDOWN irq handler
291 static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id) in wm97xx_pen_interrupt() argument
294 int pen_was_down = wm->pen_is_down; in wm97xx_pen_interrupt()
297 if (wm->id == WM9705_ID2) { in wm97xx_pen_interrupt()
300 wm->pen_is_down = 1; in wm97xx_pen_interrupt()
302 wm->pen_is_down = 0; in wm97xx_pen_interrupt()
305 mutex_lock(&wm->codec_mutex); in wm97xx_pen_interrupt()
310 wm->pen_is_down = 1; in wm97xx_pen_interrupt()
314 wm->pen_is_down = 0; in wm97xx_pen_interrupt()
319 if (wm->id == WM9712_ID2 && wm->variant != WM97xx_WM1613) in wm97xx_pen_interrupt()
325 mutex_unlock(&wm->codec_mutex); in wm97xx_pen_interrupt()
333 if (!wm->mach_ops->acc_enabled || wm->mach_ops->acc_pen_down) { in wm97xx_pen_interrupt()
334 if (wm->pen_is_down && !pen_was_down) { in wm97xx_pen_interrupt()
336 queue_delayed_work(wm->ts_workq, &wm->ts_reader, 1); in wm97xx_pen_interrupt()
340 if (!wm->pen_is_down && pen_was_down) in wm97xx_pen_interrupt()
341 wm->pen_is_down = 1; in wm97xx_pen_interrupt()
344 if (!wm->pen_is_down && wm->mach_ops->acc_enabled) in wm97xx_pen_interrupt()
345 wm->mach_ops->acc_pen_up(wm); in wm97xx_pen_interrupt()
351 * initialise pen IRQ handler and workqueue
357 if (request_threaded_irq(wm->pen_irq, NULL, wm97xx_pen_interrupt, in wm97xx_init_pen_irq()
359 "wm97xx-pen", wm)) { in wm97xx_init_pen_irq()
360 dev_err(wm->dev, in wm97xx_init_pen_irq()
362 wm->pen_irq = 0; in wm97xx_init_pen_irq()
363 return -EINVAL; in wm97xx_init_pen_irq()
367 if (wm->id != WM9705_ID2) { in wm97xx_init_pen_irq()
368 BUG_ON(!wm->mach_ops->irq_gpio); in wm97xx_init_pen_irq()
371 reg & ~(wm->mach_ops->irq_gpio)); in wm97xx_init_pen_irq()
384 mutex_lock(&wm->codec_mutex); in wm97xx_read_samples()
386 if (wm->mach_ops && wm->mach_ops->acc_enabled) in wm97xx_read_samples()
387 rc = wm->mach_ops->acc_pen_down(wm); in wm97xx_read_samples()
389 rc = wm->codec->poll_touch(wm, &data); in wm97xx_read_samples()
392 if (wm->pen_is_down) { in wm97xx_read_samples()
393 wm->pen_is_down = 0; in wm97xx_read_samples()
394 dev_dbg(wm->dev, "pen up\n"); in wm97xx_read_samples()
395 input_report_abs(wm->input_dev, ABS_PRESSURE, 0); in wm97xx_read_samples()
396 input_report_key(wm->input_dev, BTN_TOUCH, 0); in wm97xx_read_samples()
397 input_sync(wm->input_dev); in wm97xx_read_samples()
409 if (wm->ts_reader_interval < HZ / 10) in wm97xx_read_samples()
410 wm->ts_reader_interval++; in wm97xx_read_samples()
414 dev_dbg(wm->dev, in wm97xx_read_samples()
423 dev_dbg(wm->dev, "Measurement out of range, dropping it\n"); in wm97xx_read_samples()
428 input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff); in wm97xx_read_samples()
429 input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff); in wm97xx_read_samples()
430 input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff); in wm97xx_read_samples()
431 input_report_key(wm->input_dev, BTN_TOUCH, 1); in wm97xx_read_samples()
432 input_sync(wm->input_dev); in wm97xx_read_samples()
433 wm->pen_is_down = 1; in wm97xx_read_samples()
434 wm->ts_reader_interval = wm->ts_reader_min_interval; in wm97xx_read_samples()
436 dev_dbg(wm->dev, "pen down\n"); in wm97xx_read_samples()
437 wm->pen_is_down = 1; in wm97xx_read_samples()
438 wm->ts_reader_interval = wm->ts_reader_min_interval; in wm97xx_read_samples()
442 mutex_unlock(&wm->codec_mutex); in wm97xx_read_samples()
454 BUG_ON(!wm->codec); in wm97xx_ts_reader()
460 if (wm->pen_is_down || !wm->pen_irq) in wm97xx_ts_reader()
461 queue_delayed_work(wm->ts_workq, &wm->ts_reader, in wm97xx_ts_reader()
462 wm->ts_reader_interval); in wm97xx_ts_reader()
466 * wm97xx_ts_input_open - Open the touch screen input device.
476 wm->ts_workq = alloc_ordered_workqueue("kwm97xx", 0); in wm97xx_ts_input_open()
477 if (wm->ts_workq == NULL) { in wm97xx_ts_input_open()
478 dev_err(wm->dev, in wm97xx_ts_input_open()
480 return -EINVAL; in wm97xx_ts_input_open()
484 if (wm->mach_ops && wm->mach_ops->acc_enabled) in wm97xx_ts_input_open()
485 wm->codec->acc_enable(wm, 1); in wm97xx_ts_input_open()
486 wm->codec->dig_enable(wm, 1); in wm97xx_ts_input_open()
488 INIT_DELAYED_WORK(&wm->ts_reader, wm97xx_ts_reader); in wm97xx_ts_input_open()
490 wm->ts_reader_min_interval = HZ >= 100 ? HZ / 100 : 1; in wm97xx_ts_input_open()
491 if (wm->ts_reader_min_interval < 1) in wm97xx_ts_input_open()
492 wm->ts_reader_min_interval = 1; in wm97xx_ts_input_open()
493 wm->ts_reader_interval = wm->ts_reader_min_interval; in wm97xx_ts_input_open()
495 wm->pen_is_down = 0; in wm97xx_ts_input_open()
496 if (wm->pen_irq) in wm97xx_ts_input_open()
499 dev_err(wm->dev, "No IRQ specified\n"); in wm97xx_ts_input_open()
504 if (wm->pen_irq == 0) in wm97xx_ts_input_open()
505 queue_delayed_work(wm->ts_workq, &wm->ts_reader, in wm97xx_ts_input_open()
506 wm->ts_reader_interval); in wm97xx_ts_input_open()
512 * wm97xx_ts_input_close - Close the touch screen input device.
525 if (wm->pen_irq) { in wm97xx_ts_input_close()
527 if (wm->id != WM9705_ID2) { in wm97xx_ts_input_close()
528 BUG_ON(!wm->mach_ops->irq_gpio); in wm97xx_ts_input_close()
531 reg | wm->mach_ops->irq_gpio); in wm97xx_ts_input_close()
534 free_irq(wm->pen_irq, wm); in wm97xx_ts_input_close()
537 wm->pen_is_down = 0; in wm97xx_ts_input_close()
542 cancel_delayed_work_sync(&wm->ts_reader); in wm97xx_ts_input_close()
544 destroy_workqueue(wm->ts_workq); in wm97xx_ts_input_close()
547 wm->codec->dig_enable(wm, 0); in wm97xx_ts_input_close()
548 if (wm->mach_ops && wm->mach_ops->acc_enabled) in wm97xx_ts_input_close()
549 wm->codec->acc_enable(wm, 0); in wm97xx_ts_input_close()
554 struct wm97xx_pdata *pdata = dev_get_platdata(wm->dev); in wm97xx_register_touch()
557 wm->input_dev = devm_input_allocate_device(wm->dev); in wm97xx_register_touch()
558 if (wm->input_dev == NULL) in wm97xx_register_touch()
559 return -ENOMEM; in wm97xx_register_touch()
562 wm->input_dev->name = "wm97xx touchscreen"; in wm97xx_register_touch()
563 wm->input_dev->phys = "wm97xx"; in wm97xx_register_touch()
564 wm->input_dev->open = wm97xx_ts_input_open; in wm97xx_register_touch()
565 wm->input_dev->close = wm97xx_ts_input_close; in wm97xx_register_touch()
567 __set_bit(EV_ABS, wm->input_dev->evbit); in wm97xx_register_touch()
568 __set_bit(EV_KEY, wm->input_dev->evbit); in wm97xx_register_touch()
569 __set_bit(BTN_TOUCH, wm->input_dev->keybit); in wm97xx_register_touch()
571 input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1], in wm97xx_register_touch()
573 input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1], in wm97xx_register_touch()
575 input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1], in wm97xx_register_touch()
578 input_set_drvdata(wm->input_dev, wm); in wm97xx_register_touch()
579 wm->input_dev->dev.parent = wm->dev; in wm97xx_register_touch()
581 ret = input_register_device(wm->input_dev); in wm97xx_register_touch()
589 wm->touch_dev = platform_device_alloc("wm97xx-touch", -1); in wm97xx_register_touch()
590 if (!wm->touch_dev) in wm97xx_register_touch()
591 return -ENOMEM; in wm97xx_register_touch()
593 platform_set_drvdata(wm->touch_dev, wm); in wm97xx_register_touch()
594 wm->touch_dev->dev.parent = wm->dev; in wm97xx_register_touch()
595 wm->touch_dev->dev.platform_data = pdata; in wm97xx_register_touch()
596 ret = platform_device_add(wm->touch_dev); in wm97xx_register_touch()
602 platform_device_put(wm->touch_dev); in wm97xx_register_touch()
609 platform_device_unregister(wm->touch_dev); in wm97xx_unregister_touch()
616 mutex_init(&wm->codec_mutex); in _wm97xx_probe()
617 dev_set_drvdata(wm->dev, wm); in _wm97xx_probe()
619 /* check that we have a supported codec */ in _wm97xx_probe()
622 dev_err(wm->dev, in _wm97xx_probe()
624 return -ENODEV; in _wm97xx_probe()
627 wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2); in _wm97xx_probe()
629 wm->variant = WM97xx_GENERIC; in _wm97xx_probe()
631 dev_info(wm->dev, "detected a wm97%02x codec\n", wm->id & 0xff); in _wm97xx_probe()
633 switch (wm->id & 0xff) { in _wm97xx_probe()
636 wm->codec = &wm9705_codec; in _wm97xx_probe()
641 wm->codec = &wm9712_codec; in _wm97xx_probe()
646 wm->codec = &wm9713_codec; in _wm97xx_probe()
650 dev_err(wm->dev, "Support for wm97%02x not compiled in.\n", in _wm97xx_probe()
651 wm->id & 0xff); in _wm97xx_probe()
652 return -ENODEV; in _wm97xx_probe()
656 wm->codec->phy_init(wm); in _wm97xx_probe()
659 wm->gpio[0] = wm97xx_reg_read(wm, AC97_GPIO_CFG); in _wm97xx_probe()
660 wm->gpio[1] = wm97xx_reg_read(wm, AC97_GPIO_POLARITY); in _wm97xx_probe()
661 wm->gpio[2] = wm97xx_reg_read(wm, AC97_GPIO_STICKY); in _wm97xx_probe()
662 wm->gpio[3] = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP); in _wm97xx_probe()
663 wm->gpio[4] = wm97xx_reg_read(wm, AC97_GPIO_STATUS); in _wm97xx_probe()
664 wm->gpio[5] = wm97xx_reg_read(wm, AC97_MISC_AFE); in _wm97xx_probe()
671 platform_device_unregister(wm->battery_dev); in wm97xx_remove_battery()
679 wm->battery_dev = platform_device_alloc("wm97xx-battery", -1); in wm97xx_add_battery()
680 if (!wm->battery_dev) in wm97xx_add_battery()
681 return -ENOMEM; in wm97xx_add_battery()
683 platform_set_drvdata(wm->battery_dev, wm); in wm97xx_add_battery()
684 wm->battery_dev->dev.parent = wm->dev; in wm97xx_add_battery()
685 wm->battery_dev->dev.platform_data = pdata; in wm97xx_add_battery()
686 ret = platform_device_add(wm->battery_dev); in wm97xx_add_battery()
688 platform_device_put(wm->battery_dev); in wm97xx_add_battery()
701 return -ENOMEM; in wm97xx_probe()
703 wm->dev = dev; in wm97xx_probe()
704 wm->ac97 = to_ac97_t(dev); in wm97xx_probe()
710 ret = wm97xx_add_battery(wm, pdata ? pdata->batt_pdata : NULL); in wm97xx_probe()
734 struct wm97xx_platform_data *mfd_pdata = dev_get_platdata(&pdev->dev); in wm97xx_mfd_probe()
737 wm = devm_kzalloc(&pdev->dev, sizeof(struct wm97xx), GFP_KERNEL); in wm97xx_mfd_probe()
739 return -ENOMEM; in wm97xx_mfd_probe()
741 wm->dev = &pdev->dev; in wm97xx_mfd_probe()
742 wm->ac97 = mfd_pdata->ac97; in wm97xx_mfd_probe()
748 ret = wm97xx_add_battery(wm, mfd_pdata->batt_pdata); in wm97xx_mfd_probe()
761 wm97xx_remove(&pdev->dev); in wm97xx_mfd_remove()
770 if (device_may_wakeup(&wm->input_dev->dev)) in wm97xx_suspend()
771 suspend_mode = wm->suspend_mode; in wm97xx_suspend()
775 mutex_lock(&wm->input_dev->mutex); in wm97xx_suspend()
776 if (input_device_enabled(wm->input_dev)) in wm97xx_suspend()
777 cancel_delayed_work_sync(&wm->ts_reader); in wm97xx_suspend()
782 if (input_device_enabled(wm->input_dev)) in wm97xx_suspend()
784 wm->ac97->bus->ops->write(wm->ac97, AC97_WM97XX_DIGITISER2, reg); in wm97xx_suspend()
786 /* WM9713 has an additional power bit - turn it off if there in wm97xx_suspend()
788 if (wm->id == WM9713_ID2 && in wm97xx_suspend()
789 (!input_device_enabled(wm->input_dev) || !suspend_mode)) { in wm97xx_suspend()
793 mutex_unlock(&wm->input_dev->mutex); in wm97xx_suspend()
802 mutex_lock(&wm->input_dev->mutex); in wm97xx_resume()
804 if (wm->id == WM9713_ID2) { in wm97xx_resume()
805 wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig[0]); in wm97xx_resume()
806 wm97xx_reg_write(wm, 0x5a, wm->misc); in wm97xx_resume()
807 if (input_device_enabled(wm->input_dev)) { in wm97xx_resume()
814 wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig[1]); in wm97xx_resume()
815 wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2]); in wm97xx_resume()
817 wm97xx_reg_write(wm, AC97_GPIO_CFG, wm->gpio[0]); in wm97xx_resume()
818 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, wm->gpio[1]); in wm97xx_resume()
819 wm97xx_reg_write(wm, AC97_GPIO_STICKY, wm->gpio[2]); in wm97xx_resume()
820 wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, wm->gpio[3]); in wm97xx_resume()
821 wm97xx_reg_write(wm, AC97_GPIO_STATUS, wm->gpio[4]); in wm97xx_resume()
822 wm97xx_reg_write(wm, AC97_MISC_AFE, wm->gpio[5]); in wm97xx_resume()
824 if (input_device_enabled(wm->input_dev) && !wm->pen_irq) { in wm97xx_resume()
825 wm->ts_reader_interval = wm->ts_reader_min_interval; in wm97xx_resume()
826 queue_delayed_work(wm->ts_workq, &wm->ts_reader, in wm97xx_resume()
827 wm->ts_reader_interval); in wm97xx_resume()
829 mutex_unlock(&wm->input_dev->mutex); in wm97xx_resume()
842 mutex_lock(&wm->codec_mutex); in wm97xx_register_mach_ops()
843 if (wm->mach_ops) { in wm97xx_register_mach_ops()
844 mutex_unlock(&wm->codec_mutex); in wm97xx_register_mach_ops()
845 return -EINVAL; in wm97xx_register_mach_ops()
847 wm->mach_ops = mach_ops; in wm97xx_register_mach_ops()
848 mutex_unlock(&wm->codec_mutex); in wm97xx_register_mach_ops()
856 mutex_lock(&wm->codec_mutex); in wm97xx_unregister_mach_ops()
857 wm->mach_ops = NULL; in wm97xx_unregister_mach_ops()
858 mutex_unlock(&wm->codec_mutex); in wm97xx_unregister_mach_ops()
863 .name = "wm97xx-ts",
875 .name = "wm97xx-ts",
907 MODULE_DESCRIPTION("WM97xx Core - Touch Screen / AUX ADC / GPIO Driver");