1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * wm97xx-core.c -- Touch screen driver core for Wolfson WM9705, WM9712
4 * and WM9713 AC97 Codecs.
6 * Copyright 2003, 2004, 2005, 2006, 2007, 2008 Wolfson Microelectronics PLC.
7 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
8 * Parts Copyright : Ian Molton <spyro@f2s.com>
9 * Andrew Zabolotny <zap@homelink.ru>
10 * Russell King <rmk@arm.linux.org.uk>
15 * - supports WM9705, WM9712, WM9713
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
27 * - codec event notification
29 * - Support for async sampling control for noisy LCDs.
32 #include <linux/module.h>
33 #include <linux/moduleparam.h>
34 #include <linux/kernel.h>
35 #include <linux/init.h>
36 #include <linux/delay.h>
37 #include <linux/string.h>
38 #include <linux/proc_fs.h>
40 #include <linux/interrupt.h>
41 #include <linux/bitops.h>
42 #include <linux/mfd/wm97xx.h>
43 #include <linux/workqueue.h>
44 #include <linux/wm97xx.h>
45 #include <linux/uaccess.h>
47 #include <linux/slab.h>
49 #define TS_NAME "wm97xx"
50 #define WM_CORE_VERSION "1.00"
51 #define DEFAULT_PRESSURE 0xb0c0
55 * Touchscreen absolute values
57 * These parameters are used to help the input layer discard out of
58 * range readings and reduce jitter etc.
60 * o min, max:- indicate the min and max values your touch screen returns
61 * o fuzz:- use a higher number to reduce jitter
63 * The default values correspond to Mainstone II in QVGA mode
66 * Documentation/input/input-programming.rst for more details.
69 static int abs_x
[3] = {150, 4000, 5};
70 module_param_array(abs_x
, int, NULL
, 0);
71 MODULE_PARM_DESC(abs_x
, "Touchscreen absolute X min, max, fuzz");
73 static int abs_y
[3] = {200, 4000, 40};
74 module_param_array(abs_y
, int, NULL
, 0);
75 MODULE_PARM_DESC(abs_y
, "Touchscreen absolute Y min, max, fuzz");
77 static int abs_p
[3] = {0, 150, 4};
78 module_param_array(abs_p
, int, NULL
, 0);
79 MODULE_PARM_DESC(abs_p
, "Touchscreen absolute Pressure min, max, fuzz");
82 * wm97xx IO access, all IO locking done by AC97 layer
84 int wm97xx_reg_read(struct wm97xx
*wm
, u16 reg
)
87 return wm
->ac97
->bus
->ops
->read(wm
->ac97
, reg
);
91 EXPORT_SYMBOL_GPL(wm97xx_reg_read
);
93 void wm97xx_reg_write(struct wm97xx
*wm
, u16 reg
, u16 val
)
95 /* cache digitiser registers */
96 if (reg
>= AC97_WM9713_DIG1
&& reg
<= AC97_WM9713_DIG3
)
97 wm
->dig
[(reg
- AC97_WM9713_DIG1
) >> 1] = val
;
100 if (reg
>= AC97_GPIO_CFG
&& reg
<= AC97_MISC_AFE
)
101 wm
->gpio
[(reg
- AC97_GPIO_CFG
) >> 1] = val
;
108 wm
->ac97
->bus
->ops
->write(wm
->ac97
, reg
, val
);
110 EXPORT_SYMBOL_GPL(wm97xx_reg_write
);
113 * wm97xx_read_aux_adc - Read the aux adc.
114 * @wm: wm97xx device.
115 * @adcsel: codec ADC to be read
117 * Reads the selected AUX ADC.
120 int wm97xx_read_aux_adc(struct wm97xx
*wm
, u16 adcsel
)
122 int power_adc
= 0, auxval
;
128 mutex_lock(&wm
->codec_mutex
);
130 /* When the touchscreen is not in use, we may have to power up
131 * the AUX ADC before we can use sample the AUX inputs->
133 if (wm
->id
== WM9713_ID2
&&
134 (power
= wm97xx_reg_read(wm
, AC97_EXTENDED_MID
)) & 0x8000) {
136 wm97xx_reg_write(wm
, AC97_EXTENDED_MID
, power
& 0x7fff);
139 /* Prepare the codec for AUX reading */
140 wm
->codec
->aux_prepare(wm
);
142 /* Turn polling mode on to read AUX ADC */
143 wm
->pen_probably_down
= 1;
145 while (rc
!= RC_VALID
&& timeout
++ < 5)
146 rc
= wm
->codec
->poll_sample(wm
, adcsel
, &auxval
);
149 wm97xx_reg_write(wm
, AC97_EXTENDED_MID
, power
| 0x8000);
151 wm
->codec
->dig_restore(wm
);
153 wm
->pen_probably_down
= 0;
157 "timeout reading auxadc %d, disabling digitiser\n",
159 wm
->codec
->dig_enable(wm
, false);
162 mutex_unlock(&wm
->codec_mutex
);
163 return (rc
== RC_VALID
? auxval
& 0xfff : -EBUSY
);
165 EXPORT_SYMBOL_GPL(wm97xx_read_aux_adc
);
168 * wm97xx_get_gpio - Get the status of a codec GPIO.
169 * @wm: wm97xx device.
172 * Get the status of a codec GPIO pin
175 enum wm97xx_gpio_status
wm97xx_get_gpio(struct wm97xx
*wm
, u32 gpio
)
178 enum wm97xx_gpio_status ret
;
180 mutex_lock(&wm
->codec_mutex
);
181 status
= wm97xx_reg_read(wm
, AC97_GPIO_STATUS
);
184 ret
= WM97XX_GPIO_HIGH
;
186 ret
= WM97XX_GPIO_LOW
;
188 mutex_unlock(&wm
->codec_mutex
);
191 EXPORT_SYMBOL_GPL(wm97xx_get_gpio
);
194 * wm97xx_set_gpio - Set the status of a codec GPIO.
195 * @wm: wm97xx device.
199 * Set the status of a codec GPIO pin
202 void wm97xx_set_gpio(struct wm97xx
*wm
, u32 gpio
,
203 enum wm97xx_gpio_status status
)
207 mutex_lock(&wm
->codec_mutex
);
208 reg
= wm97xx_reg_read(wm
, AC97_GPIO_STATUS
);
210 if (status
== WM97XX_GPIO_HIGH
)
215 if (wm
->id
== WM9712_ID2
&& wm
->variant
!= WM97xx_WM1613
)
216 wm97xx_reg_write(wm
, AC97_GPIO_STATUS
, reg
<< 1);
218 wm97xx_reg_write(wm
, AC97_GPIO_STATUS
, reg
);
219 mutex_unlock(&wm
->codec_mutex
);
221 EXPORT_SYMBOL_GPL(wm97xx_set_gpio
);
224 * Codec GPIO pin configuration, this sets pin direction, polarity,
225 * stickyness and wake up.
227 void wm97xx_config_gpio(struct wm97xx
*wm
, u32 gpio
, enum wm97xx_gpio_dir dir
,
228 enum wm97xx_gpio_pol pol
, enum wm97xx_gpio_sticky sticky
,
229 enum wm97xx_gpio_wake wake
)
233 mutex_lock(&wm
->codec_mutex
);
234 reg
= wm97xx_reg_read(wm
, AC97_GPIO_POLARITY
);
236 if (pol
== WM97XX_GPIO_POL_HIGH
)
241 wm97xx_reg_write(wm
, AC97_GPIO_POLARITY
, reg
);
242 reg
= wm97xx_reg_read(wm
, AC97_GPIO_STICKY
);
244 if (sticky
== WM97XX_GPIO_STICKY
)
249 wm97xx_reg_write(wm
, AC97_GPIO_STICKY
, reg
);
250 reg
= wm97xx_reg_read(wm
, AC97_GPIO_WAKEUP
);
252 if (wake
== WM97XX_GPIO_WAKE
)
257 wm97xx_reg_write(wm
, AC97_GPIO_WAKEUP
, reg
);
258 reg
= wm97xx_reg_read(wm
, AC97_GPIO_CFG
);
260 if (dir
== WM97XX_GPIO_IN
)
265 wm97xx_reg_write(wm
, AC97_GPIO_CFG
, reg
);
266 mutex_unlock(&wm
->codec_mutex
);
268 EXPORT_SYMBOL_GPL(wm97xx_config_gpio
);
271 * Configure the WM97XX_PRP value to use while system is suspended.
272 * If a value other than 0 is set then WM97xx pen detection will be
273 * left enabled in the configured mode while the system is in suspend,
274 * the device has users and suspend has not been disabled via the
275 * wakeup sysfs entries.
277 * @wm: WM97xx device to configure
278 * @mode: WM97XX_PRP value to configure while suspended
280 void wm97xx_set_suspend_mode(struct wm97xx
*wm
, u16 mode
)
282 wm
->suspend_mode
= mode
;
283 device_init_wakeup(&wm
->input_dev
->dev
, mode
!= 0);
285 EXPORT_SYMBOL_GPL(wm97xx_set_suspend_mode
);
288 * Codec PENDOWN irq handler
291 static irqreturn_t
wm97xx_pen_interrupt(int irq
, void *dev_id
)
293 struct wm97xx
*wm
= dev_id
;
294 int pen_was_down
= wm
->pen_is_down
;
296 /* do we need to enable the touch panel reader */
297 if (wm
->id
== WM9705_ID2
) {
298 if (wm97xx_reg_read(wm
, AC97_WM97XX_DIGITISER_RD
) &
305 mutex_lock(&wm
->codec_mutex
);
306 status
= wm97xx_reg_read(wm
, AC97_GPIO_STATUS
);
307 pol
= wm97xx_reg_read(wm
, AC97_GPIO_POLARITY
);
309 if (WM97XX_GPIO_13
& pol
& status
) {
311 wm97xx_reg_write(wm
, AC97_GPIO_POLARITY
, pol
&
315 wm97xx_reg_write(wm
, AC97_GPIO_POLARITY
, pol
|
319 if (wm
->id
== WM9712_ID2
&& wm
->variant
!= WM97xx_WM1613
)
320 wm97xx_reg_write(wm
, AC97_GPIO_STATUS
, (status
&
321 ~WM97XX_GPIO_13
) << 1);
323 wm97xx_reg_write(wm
, AC97_GPIO_STATUS
, status
&
325 mutex_unlock(&wm
->codec_mutex
);
328 /* If the system is not using continuous mode or it provides a
329 * pen down operation then we need to schedule polls while the
330 * pen is down. Otherwise the machine driver is responsible
331 * for scheduling reads.
333 if (!wm
->mach_ops
->acc_enabled
|| wm
->mach_ops
->acc_pen_down
) {
334 if (wm
->pen_is_down
&& !pen_was_down
) {
335 /* Data is not available immediately on pen down */
336 queue_delayed_work(wm
->ts_workq
, &wm
->ts_reader
, 1);
339 /* Let ts_reader report the pen up for debounce. */
340 if (!wm
->pen_is_down
&& pen_was_down
)
344 if (!wm
->pen_is_down
&& wm
->mach_ops
->acc_enabled
)
345 wm
->mach_ops
->acc_pen_up(wm
);
351 * initialise pen IRQ handler and workqueue
353 static int wm97xx_init_pen_irq(struct wm97xx
*wm
)
357 if (request_threaded_irq(wm
->pen_irq
, NULL
, wm97xx_pen_interrupt
,
358 IRQF_SHARED
| IRQF_ONESHOT
,
361 "Failed to register pen down interrupt, polling");
366 /* Configure GPIO as interrupt source on WM971x */
367 if (wm
->id
!= WM9705_ID2
) {
368 BUG_ON(!wm
->mach_ops
->irq_gpio
);
369 reg
= wm97xx_reg_read(wm
, AC97_MISC_AFE
);
370 wm97xx_reg_write(wm
, AC97_MISC_AFE
,
371 reg
& ~(wm
->mach_ops
->irq_gpio
));
372 reg
= wm97xx_reg_read(wm
, 0x5a);
373 wm97xx_reg_write(wm
, 0x5a, reg
& ~0x0001);
379 static int wm97xx_read_samples(struct wm97xx
*wm
)
381 struct wm97xx_data data
;
384 mutex_lock(&wm
->codec_mutex
);
386 if (wm
->mach_ops
&& wm
->mach_ops
->acc_enabled
)
387 rc
= wm
->mach_ops
->acc_pen_down(wm
);
389 rc
= wm
->codec
->poll_touch(wm
, &data
);
392 if (wm
->pen_is_down
) {
394 dev_dbg(wm
->dev
, "pen up\n");
395 input_report_abs(wm
->input_dev
, ABS_PRESSURE
, 0);
396 input_report_key(wm
->input_dev
, BTN_TOUCH
, 0);
397 input_sync(wm
->input_dev
);
398 } else if (!(rc
& RC_AGAIN
)) {
399 /* We need high frequency updates only while
400 * pen is down, the user never will be able to
401 * touch screen faster than a few times per
402 * second... On the other hand, when the user
403 * is actively working with the touchscreen we
404 * don't want to lose the quick response. So we
405 * will slowly increase sleep time after the
406 * pen is up and quicky restore it to ~one task
407 * switch when pen is down again.
409 if (wm
->ts_reader_interval
< HZ
/ 10)
410 wm
->ts_reader_interval
++;
413 } else if (rc
& RC_VALID
) {
415 "pen down: x=%x:%d, y=%x:%d, pressure=%x:%d\n",
416 data
.x
>> 12, data
.x
& 0xfff, data
.y
>> 12,
417 data
.y
& 0xfff, data
.p
>> 12, data
.p
& 0xfff);
419 if (abs_x
[0] > (data
.x
& 0xfff) ||
420 abs_x
[1] < (data
.x
& 0xfff) ||
421 abs_y
[0] > (data
.y
& 0xfff) ||
422 abs_y
[1] < (data
.y
& 0xfff)) {
423 dev_dbg(wm
->dev
, "Measurement out of range, dropping it\n");
428 input_report_abs(wm
->input_dev
, ABS_X
, data
.x
& 0xfff);
429 input_report_abs(wm
->input_dev
, ABS_Y
, data
.y
& 0xfff);
430 input_report_abs(wm
->input_dev
, ABS_PRESSURE
, data
.p
& 0xfff);
431 input_report_key(wm
->input_dev
, BTN_TOUCH
, 1);
432 input_sync(wm
->input_dev
);
434 wm
->ts_reader_interval
= wm
->ts_reader_min_interval
;
435 } else if (rc
& RC_PENDOWN
) {
436 dev_dbg(wm
->dev
, "pen down\n");
438 wm
->ts_reader_interval
= wm
->ts_reader_min_interval
;
442 mutex_unlock(&wm
->codec_mutex
);
447 * The touchscreen sample reader.
449 static void wm97xx_ts_reader(struct work_struct
*work
)
452 struct wm97xx
*wm
= container_of(work
, struct wm97xx
, ts_reader
.work
);
457 rc
= wm97xx_read_samples(wm
);
458 } while (rc
& RC_AGAIN
);
460 if (wm
->pen_is_down
|| !wm
->pen_irq
)
461 queue_delayed_work(wm
->ts_workq
, &wm
->ts_reader
,
462 wm
->ts_reader_interval
);
466 * wm97xx_ts_input_open - Open the touch screen input device.
467 * @idev: Input device to be opened.
469 * Called by the input sub system to open a wm97xx touchscreen device.
470 * Starts the touchscreen thread and touch digitiser.
472 static int wm97xx_ts_input_open(struct input_dev
*idev
)
474 struct wm97xx
*wm
= input_get_drvdata(idev
);
476 wm
->ts_workq
= alloc_ordered_workqueue("kwm97xx", 0);
477 if (wm
->ts_workq
== NULL
) {
479 "Failed to create workqueue\n");
483 /* start digitiser */
484 if (wm
->mach_ops
&& wm
->mach_ops
->acc_enabled
)
485 wm
->codec
->acc_enable(wm
, 1);
486 wm
->codec
->dig_enable(wm
, 1);
488 INIT_DELAYED_WORK(&wm
->ts_reader
, wm97xx_ts_reader
);
490 wm
->ts_reader_min_interval
= HZ
>= 100 ? HZ
/ 100 : 1;
491 if (wm
->ts_reader_min_interval
< 1)
492 wm
->ts_reader_min_interval
= 1;
493 wm
->ts_reader_interval
= wm
->ts_reader_min_interval
;
497 wm97xx_init_pen_irq(wm
);
499 dev_err(wm
->dev
, "No IRQ specified\n");
501 /* If we either don't have an interrupt for pen down events or
502 * failed to acquire it then we need to poll.
504 if (wm
->pen_irq
== 0)
505 queue_delayed_work(wm
->ts_workq
, &wm
->ts_reader
,
506 wm
->ts_reader_interval
);
512 * wm97xx_ts_input_close - Close the touch screen input device.
513 * @idev: Input device to be closed.
515 * Called by the input sub system to close a wm97xx touchscreen
516 * device. Kills the touchscreen thread and stops the touch
520 static void wm97xx_ts_input_close(struct input_dev
*idev
)
522 struct wm97xx
*wm
= input_get_drvdata(idev
);
526 /* Return the interrupt to GPIO usage (disabling it) */
527 if (wm
->id
!= WM9705_ID2
) {
528 BUG_ON(!wm
->mach_ops
->irq_gpio
);
529 reg
= wm97xx_reg_read(wm
, AC97_MISC_AFE
);
530 wm97xx_reg_write(wm
, AC97_MISC_AFE
,
531 reg
| wm
->mach_ops
->irq_gpio
);
534 free_irq(wm
->pen_irq
, wm
);
539 /* ts_reader rearms itself so we need to explicitly stop it
540 * before we destroy the workqueue.
542 cancel_delayed_work_sync(&wm
->ts_reader
);
544 destroy_workqueue(wm
->ts_workq
);
547 wm
->codec
->dig_enable(wm
, 0);
548 if (wm
->mach_ops
&& wm
->mach_ops
->acc_enabled
)
549 wm
->codec
->acc_enable(wm
, 0);
552 static int wm97xx_register_touch(struct wm97xx
*wm
)
554 struct wm97xx_pdata
*pdata
= dev_get_platdata(wm
->dev
);
557 wm
->input_dev
= devm_input_allocate_device(wm
->dev
);
558 if (wm
->input_dev
== NULL
)
561 /* set up touch configuration */
562 wm
->input_dev
->name
= "wm97xx touchscreen";
563 wm
->input_dev
->phys
= "wm97xx";
564 wm
->input_dev
->open
= wm97xx_ts_input_open
;
565 wm
->input_dev
->close
= wm97xx_ts_input_close
;
567 __set_bit(EV_ABS
, wm
->input_dev
->evbit
);
568 __set_bit(EV_KEY
, wm
->input_dev
->evbit
);
569 __set_bit(BTN_TOUCH
, wm
->input_dev
->keybit
);
571 input_set_abs_params(wm
->input_dev
, ABS_X
, abs_x
[0], abs_x
[1],
573 input_set_abs_params(wm
->input_dev
, ABS_Y
, abs_y
[0], abs_y
[1],
575 input_set_abs_params(wm
->input_dev
, ABS_PRESSURE
, abs_p
[0], abs_p
[1],
578 input_set_drvdata(wm
->input_dev
, wm
);
579 wm
->input_dev
->dev
.parent
= wm
->dev
;
581 ret
= input_register_device(wm
->input_dev
);
586 * register our extended touch device (for machine specific
589 wm
->touch_dev
= platform_device_alloc("wm97xx-touch", -1);
593 platform_set_drvdata(wm
->touch_dev
, wm
);
594 wm
->touch_dev
->dev
.parent
= wm
->dev
;
595 wm
->touch_dev
->dev
.platform_data
= pdata
;
596 ret
= platform_device_add(wm
->touch_dev
);
602 platform_device_put(wm
->touch_dev
);
607 static void wm97xx_unregister_touch(struct wm97xx
*wm
)
609 platform_device_unregister(wm
->touch_dev
);
612 static int _wm97xx_probe(struct wm97xx
*wm
)
616 mutex_init(&wm
->codec_mutex
);
617 dev_set_drvdata(wm
->dev
, wm
);
619 /* check that we have a supported codec */
620 id
= wm97xx_reg_read(wm
, AC97_VENDOR_ID1
);
621 if (id
!= WM97XX_ID1
) {
623 "Device with vendor %04x is not a wm97xx\n", id
);
627 wm
->id
= wm97xx_reg_read(wm
, AC97_VENDOR_ID2
);
629 wm
->variant
= WM97xx_GENERIC
;
631 dev_info(wm
->dev
, "detected a wm97%02x codec\n", wm
->id
& 0xff);
633 switch (wm
->id
& 0xff) {
634 #ifdef CONFIG_TOUCHSCREEN_WM9705
636 wm
->codec
= &wm9705_codec
;
639 #ifdef CONFIG_TOUCHSCREEN_WM9712
641 wm
->codec
= &wm9712_codec
;
644 #ifdef CONFIG_TOUCHSCREEN_WM9713
646 wm
->codec
= &wm9713_codec
;
650 dev_err(wm
->dev
, "Support for wm97%02x not compiled in.\n",
655 /* set up physical characteristics */
656 wm
->codec
->phy_init(wm
);
658 /* load gpio cache */
659 wm
->gpio
[0] = wm97xx_reg_read(wm
, AC97_GPIO_CFG
);
660 wm
->gpio
[1] = wm97xx_reg_read(wm
, AC97_GPIO_POLARITY
);
661 wm
->gpio
[2] = wm97xx_reg_read(wm
, AC97_GPIO_STICKY
);
662 wm
->gpio
[3] = wm97xx_reg_read(wm
, AC97_GPIO_WAKEUP
);
663 wm
->gpio
[4] = wm97xx_reg_read(wm
, AC97_GPIO_STATUS
);
664 wm
->gpio
[5] = wm97xx_reg_read(wm
, AC97_MISC_AFE
);
666 return wm97xx_register_touch(wm
);
669 static void wm97xx_remove_battery(struct wm97xx
*wm
)
671 platform_device_unregister(wm
->battery_dev
);
674 static int wm97xx_add_battery(struct wm97xx
*wm
,
675 struct wm97xx_batt_pdata
*pdata
)
679 wm
->battery_dev
= platform_device_alloc("wm97xx-battery", -1);
680 if (!wm
->battery_dev
)
683 platform_set_drvdata(wm
->battery_dev
, wm
);
684 wm
->battery_dev
->dev
.parent
= wm
->dev
;
685 wm
->battery_dev
->dev
.platform_data
= pdata
;
686 ret
= platform_device_add(wm
->battery_dev
);
688 platform_device_put(wm
->battery_dev
);
693 static int wm97xx_probe(struct device
*dev
)
697 struct wm97xx_pdata
*pdata
= dev_get_platdata(dev
);
699 wm
= devm_kzalloc(dev
, sizeof(struct wm97xx
), GFP_KERNEL
);
704 wm
->ac97
= to_ac97_t(dev
);
706 ret
= _wm97xx_probe(wm
);
710 ret
= wm97xx_add_battery(wm
, pdata
? pdata
->batt_pdata
: NULL
);
717 wm97xx_unregister_touch(wm
);
721 static int wm97xx_remove(struct device
*dev
)
723 struct wm97xx
*wm
= dev_get_drvdata(dev
);
725 wm97xx_remove_battery(wm
);
726 wm97xx_unregister_touch(wm
);
731 static int wm97xx_mfd_probe(struct platform_device
*pdev
)
734 struct wm97xx_platform_data
*mfd_pdata
= dev_get_platdata(&pdev
->dev
);
737 wm
= devm_kzalloc(&pdev
->dev
, sizeof(struct wm97xx
), GFP_KERNEL
);
741 wm
->dev
= &pdev
->dev
;
742 wm
->ac97
= mfd_pdata
->ac97
;
744 ret
= _wm97xx_probe(wm
);
748 ret
= wm97xx_add_battery(wm
, mfd_pdata
->batt_pdata
);
755 wm97xx_unregister_touch(wm
);
759 static void wm97xx_mfd_remove(struct platform_device
*pdev
)
761 wm97xx_remove(&pdev
->dev
);
764 static int wm97xx_suspend(struct device
*dev
)
766 struct wm97xx
*wm
= dev_get_drvdata(dev
);
770 if (device_may_wakeup(&wm
->input_dev
->dev
))
771 suspend_mode
= wm
->suspend_mode
;
775 mutex_lock(&wm
->input_dev
->mutex
);
776 if (input_device_enabled(wm
->input_dev
))
777 cancel_delayed_work_sync(&wm
->ts_reader
);
779 /* Power down the digitiser (bypassing the cache for resume) */
780 reg
= wm97xx_reg_read(wm
, AC97_WM97XX_DIGITISER2
);
781 reg
&= ~WM97XX_PRP_DET_DIG
;
782 if (input_device_enabled(wm
->input_dev
))
784 wm
->ac97
->bus
->ops
->write(wm
->ac97
, AC97_WM97XX_DIGITISER2
, reg
);
786 /* WM9713 has an additional power bit - turn it off if there
787 * are no users or if suspend mode is zero. */
788 if (wm
->id
== WM9713_ID2
&&
789 (!input_device_enabled(wm
->input_dev
) || !suspend_mode
)) {
790 reg
= wm97xx_reg_read(wm
, AC97_EXTENDED_MID
) | 0x8000;
791 wm97xx_reg_write(wm
, AC97_EXTENDED_MID
, reg
);
793 mutex_unlock(&wm
->input_dev
->mutex
);
798 static int wm97xx_resume(struct device
*dev
)
800 struct wm97xx
*wm
= dev_get_drvdata(dev
);
802 mutex_lock(&wm
->input_dev
->mutex
);
803 /* restore digitiser and gpios */
804 if (wm
->id
== WM9713_ID2
) {
805 wm97xx_reg_write(wm
, AC97_WM9713_DIG1
, wm
->dig
[0]);
806 wm97xx_reg_write(wm
, 0x5a, wm
->misc
);
807 if (input_device_enabled(wm
->input_dev
)) {
809 reg
= wm97xx_reg_read(wm
, AC97_EXTENDED_MID
) & 0x7fff;
810 wm97xx_reg_write(wm
, AC97_EXTENDED_MID
, reg
);
814 wm97xx_reg_write(wm
, AC97_WM9713_DIG2
, wm
->dig
[1]);
815 wm97xx_reg_write(wm
, AC97_WM9713_DIG3
, wm
->dig
[2]);
817 wm97xx_reg_write(wm
, AC97_GPIO_CFG
, wm
->gpio
[0]);
818 wm97xx_reg_write(wm
, AC97_GPIO_POLARITY
, wm
->gpio
[1]);
819 wm97xx_reg_write(wm
, AC97_GPIO_STICKY
, wm
->gpio
[2]);
820 wm97xx_reg_write(wm
, AC97_GPIO_WAKEUP
, wm
->gpio
[3]);
821 wm97xx_reg_write(wm
, AC97_GPIO_STATUS
, wm
->gpio
[4]);
822 wm97xx_reg_write(wm
, AC97_MISC_AFE
, wm
->gpio
[5]);
824 if (input_device_enabled(wm
->input_dev
) && !wm
->pen_irq
) {
825 wm
->ts_reader_interval
= wm
->ts_reader_min_interval
;
826 queue_delayed_work(wm
->ts_workq
, &wm
->ts_reader
,
827 wm
->ts_reader_interval
);
829 mutex_unlock(&wm
->input_dev
->mutex
);
834 static DEFINE_SIMPLE_DEV_PM_OPS(wm97xx_pm_ops
, wm97xx_suspend
, wm97xx_resume
);
837 * Machine specific operations
839 int wm97xx_register_mach_ops(struct wm97xx
*wm
,
840 struct wm97xx_mach_ops
*mach_ops
)
842 mutex_lock(&wm
->codec_mutex
);
844 mutex_unlock(&wm
->codec_mutex
);
847 wm
->mach_ops
= mach_ops
;
848 mutex_unlock(&wm
->codec_mutex
);
852 EXPORT_SYMBOL_GPL(wm97xx_register_mach_ops
);
854 void wm97xx_unregister_mach_ops(struct wm97xx
*wm
)
856 mutex_lock(&wm
->codec_mutex
);
858 mutex_unlock(&wm
->codec_mutex
);
860 EXPORT_SYMBOL_GPL(wm97xx_unregister_mach_ops
);
862 static struct device_driver wm97xx_driver
= {
864 #ifdef CONFIG_AC97_BUS
865 .bus
= &ac97_bus_type
,
867 .owner
= THIS_MODULE
,
868 .probe
= wm97xx_probe
,
869 .remove
= wm97xx_remove
,
870 .pm
= pm_sleep_ptr(&wm97xx_pm_ops
),
873 static struct platform_driver wm97xx_mfd_driver
= {
876 .pm
= pm_sleep_ptr(&wm97xx_pm_ops
),
878 .probe
= wm97xx_mfd_probe
,
879 .remove_new
= wm97xx_mfd_remove
,
882 static int __init
wm97xx_init(void)
886 ret
= platform_driver_register(&wm97xx_mfd_driver
);
890 if (IS_BUILTIN(CONFIG_AC97_BUS
))
891 ret
= driver_register(&wm97xx_driver
);
895 static void __exit
wm97xx_exit(void)
897 if (IS_BUILTIN(CONFIG_AC97_BUS
))
898 driver_unregister(&wm97xx_driver
);
899 platform_driver_unregister(&wm97xx_mfd_driver
);
902 module_init(wm97xx_init
);
903 module_exit(wm97xx_exit
);
905 /* Module information */
906 MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
907 MODULE_DESCRIPTION("WM97xx Core - Touch Screen / AUX ADC / GPIO Driver");
908 MODULE_LICENSE("GPL");