Input: wm97xx-core - use IRQF_SAMPLE_RANDOM
[linux-2.6/kmemtrace.git] / drivers / input / touchscreen / wm97xx-core.c
blobfec07c28281a72789fdc4b6aa68e785449b51760
1 /*
2 * wm97xx-core.c -- Touch screen driver core for Wolfson WM9705, WM9712
3 * and WM9713 AC97 Codecs.
5 * Copyright 2003, 2004, 2005, 2006, 2007, 2008 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood
7 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
8 * Parts Copyright : Ian Molton <spyro@f2s.com>
9 * Andrew Zabolotny <zap@homelink.ru>
10 * Russell King <rmk@arm.linux.org.uk>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
17 * Notes:
19 * Features:
20 * - supports WM9705, WM9712, WM9713
21 * - polling mode
22 * - continuous mode (arch-dependent)
23 * - adjustable rpu/dpp settings
24 * - adjustable pressure current
25 * - adjustable sample settle delay
26 * - 4 and 5 wire touchscreens (5 wire is WM9712 only)
27 * - pen down detection
28 * - battery monitor
29 * - sample AUX adcs
30 * - power management
31 * - codec GPIO
32 * - codec event notification
33 * Todo
34 * - Support for async sampling control for noisy LCDs.
38 #include <linux/module.h>
39 #include <linux/moduleparam.h>
40 #include <linux/version.h>
41 #include <linux/kernel.h>
42 #include <linux/init.h>
43 #include <linux/delay.h>
44 #include <linux/string.h>
45 #include <linux/proc_fs.h>
46 #include <linux/pm.h>
47 #include <linux/interrupt.h>
48 #include <linux/bitops.h>
49 #include <linux/workqueue.h>
50 #include <linux/wm97xx.h>
51 #include <linux/uaccess.h>
52 #include <linux/io.h>
54 #define TS_NAME "wm97xx"
55 #define WM_CORE_VERSION "1.00"
56 #define DEFAULT_PRESSURE 0xb0c0
60 * Touchscreen absolute values
62 * These parameters are used to help the input layer discard out of
63 * range readings and reduce jitter etc.
65 * o min, max:- indicate the min and max values your touch screen returns
66 * o fuzz:- use a higher number to reduce jitter
68 * The default values correspond to Mainstone II in QVGA mode
70 * Please read
71 * Documentation/input/input-programming.txt for more details.
74 static int abs_x[3] = {350, 3900, 5};
75 module_param_array(abs_x, int, NULL, 0);
76 MODULE_PARM_DESC(abs_x, "Touchscreen absolute X min, max, fuzz");
78 static int abs_y[3] = {320, 3750, 40};
79 module_param_array(abs_y, int, NULL, 0);
80 MODULE_PARM_DESC(abs_y, "Touchscreen absolute Y min, max, fuzz");
82 static int abs_p[3] = {0, 150, 4};
83 module_param_array(abs_p, int, NULL, 0);
84 MODULE_PARM_DESC(abs_p, "Touchscreen absolute Pressure min, max, fuzz");
87 * wm97xx IO access, all IO locking done by AC97 layer
89 int wm97xx_reg_read(struct wm97xx *wm, u16 reg)
91 if (wm->ac97)
92 return wm->ac97->bus->ops->read(wm->ac97, reg);
93 else
94 return -1;
96 EXPORT_SYMBOL_GPL(wm97xx_reg_read);
98 void wm97xx_reg_write(struct wm97xx *wm, u16 reg, u16 val)
100 /* cache digitiser registers */
101 if (reg >= AC97_WM9713_DIG1 && reg <= AC97_WM9713_DIG3)
102 wm->dig[(reg - AC97_WM9713_DIG1) >> 1] = val;
104 /* cache gpio regs */
105 if (reg >= AC97_GPIO_CFG && reg <= AC97_MISC_AFE)
106 wm->gpio[(reg - AC97_GPIO_CFG) >> 1] = val;
108 /* wm9713 irq reg */
109 if (reg == 0x5a)
110 wm->misc = val;
112 if (wm->ac97)
113 wm->ac97->bus->ops->write(wm->ac97, reg, val);
115 EXPORT_SYMBOL_GPL(wm97xx_reg_write);
118 * wm97xx_read_aux_adc - Read the aux adc.
119 * @wm: wm97xx device.
120 * @adcsel: codec ADC to be read
122 * Reads the selected AUX ADC.
125 int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel)
127 int power_adc = 0, auxval;
128 u16 power = 0;
130 /* get codec */
131 mutex_lock(&wm->codec_mutex);
133 /* When the touchscreen is not in use, we may have to power up
134 * the AUX ADC before we can use sample the AUX inputs->
136 if (wm->id == WM9713_ID2 &&
137 (power = wm97xx_reg_read(wm, AC97_EXTENDED_MID)) & 0x8000) {
138 power_adc = 1;
139 wm97xx_reg_write(wm, AC97_EXTENDED_MID, power & 0x7fff);
142 /* Prepare the codec for AUX reading */
143 wm->codec->aux_prepare(wm);
145 /* Turn polling mode on to read AUX ADC */
146 wm->pen_probably_down = 1;
147 wm->codec->poll_sample(wm, adcsel, &auxval);
149 if (power_adc)
150 wm97xx_reg_write(wm, AC97_EXTENDED_MID, power | 0x8000);
152 wm->codec->dig_restore(wm);
154 wm->pen_probably_down = 0;
156 mutex_unlock(&wm->codec_mutex);
157 return auxval & 0xfff;
159 EXPORT_SYMBOL_GPL(wm97xx_read_aux_adc);
162 * wm97xx_get_gpio - Get the status of a codec GPIO.
163 * @wm: wm97xx device.
164 * @gpio: gpio
166 * Get the status of a codec GPIO pin
169 enum wm97xx_gpio_status wm97xx_get_gpio(struct wm97xx *wm, u32 gpio)
171 u16 status;
172 enum wm97xx_gpio_status ret;
174 mutex_lock(&wm->codec_mutex);
175 status = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
177 if (status & gpio)
178 ret = WM97XX_GPIO_HIGH;
179 else
180 ret = WM97XX_GPIO_LOW;
182 mutex_unlock(&wm->codec_mutex);
183 return ret;
185 EXPORT_SYMBOL_GPL(wm97xx_get_gpio);
188 * wm97xx_set_gpio - Set the status of a codec GPIO.
189 * @wm: wm97xx device.
190 * @gpio: gpio
193 * Set the status of a codec GPIO pin
196 void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio,
197 enum wm97xx_gpio_status status)
199 u16 reg;
201 mutex_lock(&wm->codec_mutex);
202 reg = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
204 if (status & WM97XX_GPIO_HIGH)
205 reg |= gpio;
206 else
207 reg &= ~gpio;
209 if (wm->id == WM9712_ID2)
210 wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg << 1);
211 else
212 wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg);
213 mutex_unlock(&wm->codec_mutex);
215 EXPORT_SYMBOL_GPL(wm97xx_set_gpio);
218 * Codec GPIO pin configuration, this sets pin direction, polarity,
219 * stickyness and wake up.
221 void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio, enum wm97xx_gpio_dir dir,
222 enum wm97xx_gpio_pol pol, enum wm97xx_gpio_sticky sticky,
223 enum wm97xx_gpio_wake wake)
225 u16 reg;
227 mutex_lock(&wm->codec_mutex);
228 reg = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
230 if (pol == WM97XX_GPIO_POL_HIGH)
231 reg |= gpio;
232 else
233 reg &= ~gpio;
235 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, reg);
236 reg = wm97xx_reg_read(wm, AC97_GPIO_STICKY);
238 if (sticky == WM97XX_GPIO_STICKY)
239 reg |= gpio;
240 else
241 reg &= ~gpio;
243 wm97xx_reg_write(wm, AC97_GPIO_STICKY, reg);
244 reg = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP);
246 if (wake == WM97XX_GPIO_WAKE)
247 reg |= gpio;
248 else
249 reg &= ~gpio;
251 wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, reg);
252 reg = wm97xx_reg_read(wm, AC97_GPIO_CFG);
254 if (dir == WM97XX_GPIO_IN)
255 reg |= gpio;
256 else
257 reg &= ~gpio;
259 wm97xx_reg_write(wm, AC97_GPIO_CFG, reg);
260 mutex_unlock(&wm->codec_mutex);
262 EXPORT_SYMBOL_GPL(wm97xx_config_gpio);
265 * Handle a pen down interrupt.
267 static void wm97xx_pen_irq_worker(struct work_struct *work)
269 struct wm97xx *wm = container_of(work, struct wm97xx, pen_event_work);
270 int pen_was_down = wm->pen_is_down;
272 /* do we need to enable the touch panel reader */
273 if (wm->id == WM9705_ID2) {
274 if (wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD) &
275 WM97XX_PEN_DOWN)
276 wm->pen_is_down = 1;
277 else
278 wm->pen_is_down = 0;
279 } else {
280 u16 status, pol;
281 mutex_lock(&wm->codec_mutex);
282 status = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
283 pol = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
285 if (WM97XX_GPIO_13 & pol & status) {
286 wm->pen_is_down = 1;
287 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol &
288 ~WM97XX_GPIO_13);
289 } else {
290 wm->pen_is_down = 0;
291 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol |
292 WM97XX_GPIO_13);
295 if (wm->id == WM9712_ID2)
296 wm97xx_reg_write(wm, AC97_GPIO_STATUS, (status &
297 ~WM97XX_GPIO_13) << 1);
298 else
299 wm97xx_reg_write(wm, AC97_GPIO_STATUS, status &
300 ~WM97XX_GPIO_13);
301 mutex_unlock(&wm->codec_mutex);
304 /* If the system is not using continuous mode or it provides a
305 * pen down operation then we need to schedule polls while the
306 * pen is down. Otherwise the machine driver is responsible
307 * for scheduling reads.
309 if (!wm->mach_ops->acc_enabled || wm->mach_ops->acc_pen_down) {
310 if (wm->pen_is_down && !pen_was_down) {
311 /* Data is not availiable immediately on pen down */
312 queue_delayed_work(wm->ts_workq, &wm->ts_reader, 1);
315 /* Let ts_reader report the pen up for debounce. */
316 if (!wm->pen_is_down && pen_was_down)
317 wm->pen_is_down = 1;
320 if (!wm->pen_is_down && wm->mach_ops->acc_enabled)
321 wm->mach_ops->acc_pen_up(wm);
323 wm->mach_ops->irq_enable(wm, 1);
327 * Codec PENDOWN irq handler
329 * We have to disable the codec interrupt in the handler because it
330 * can take upto 1ms to clear the interrupt source. We schedule a task
331 * in a work queue to do the actual interaction with the chip. The
332 * interrupt is then enabled again in the slow handler when the source
333 * has been cleared.
335 static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id)
337 struct wm97xx *wm = dev_id;
339 if (!work_pending(&wm->pen_event_work)) {
340 wm->mach_ops->irq_enable(wm, 0);
341 queue_work(wm->ts_workq, &wm->pen_event_work);
344 return IRQ_HANDLED;
348 * initialise pen IRQ handler and workqueue
350 static int wm97xx_init_pen_irq(struct wm97xx *wm)
352 u16 reg;
354 /* If an interrupt is supplied an IRQ enable operation must also be
355 * provided. */
356 BUG_ON(!wm->mach_ops->irq_enable);
358 if (request_irq(wm->pen_irq, wm97xx_pen_interrupt,
359 IRQF_SHARED | IRQF_SAMPLE_RANDOM,
360 "wm97xx-pen", wm)) {
361 dev_err(wm->dev,
362 "Failed to register pen down interrupt, polling");
363 wm->pen_irq = 0;
364 return -EINVAL;
367 /* Configure GPIO as interrupt source on WM971x */
368 if (wm->id != WM9705_ID2) {
369 BUG_ON(!wm->mach_ops->irq_gpio);
370 reg = wm97xx_reg_read(wm, AC97_MISC_AFE);
371 wm97xx_reg_write(wm, AC97_MISC_AFE,
372 reg & ~(wm->mach_ops->irq_gpio));
373 reg = wm97xx_reg_read(wm, 0x5a);
374 wm97xx_reg_write(wm, 0x5a, reg & ~0x0001);
377 return 0;
380 static int wm97xx_read_samples(struct wm97xx *wm)
382 struct wm97xx_data data;
383 int rc;
385 mutex_lock(&wm->codec_mutex);
387 if (wm->mach_ops && wm->mach_ops->acc_enabled)
388 rc = wm->mach_ops->acc_pen_down(wm);
389 else
390 rc = wm->codec->poll_touch(wm, &data);
392 if (rc & RC_PENUP) {
393 if (wm->pen_is_down) {
394 wm->pen_is_down = 0;
395 dev_dbg(wm->dev, "pen up\n");
396 input_report_abs(wm->input_dev, ABS_PRESSURE, 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) {
414 dev_dbg(wm->dev,
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);
418 input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff);
419 input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff);
420 input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff);
421 input_sync(wm->input_dev);
422 wm->pen_is_down = 1;
423 wm->ts_reader_interval = wm->ts_reader_min_interval;
424 } else if (rc & RC_PENDOWN) {
425 dev_dbg(wm->dev, "pen down\n");
426 wm->pen_is_down = 1;
427 wm->ts_reader_interval = wm->ts_reader_min_interval;
430 mutex_unlock(&wm->codec_mutex);
431 return rc;
435 * The touchscreen sample reader.
437 static void wm97xx_ts_reader(struct work_struct *work)
439 int rc;
440 struct wm97xx *wm = container_of(work, struct wm97xx, ts_reader.work);
442 BUG_ON(!wm->codec);
444 do {
445 rc = wm97xx_read_samples(wm);
446 } while (rc & RC_AGAIN);
448 if (wm->pen_is_down || !wm->pen_irq)
449 queue_delayed_work(wm->ts_workq, &wm->ts_reader,
450 wm->ts_reader_interval);
454 * wm97xx_ts_input_open - Open the touch screen input device.
455 * @idev: Input device to be opened.
457 * Called by the input sub system to open a wm97xx touchscreen device.
458 * Starts the touchscreen thread and touch digitiser.
460 static int wm97xx_ts_input_open(struct input_dev *idev)
462 struct wm97xx *wm = input_get_drvdata(idev);
464 wm->ts_workq = create_singlethread_workqueue("kwm97xx");
465 if (wm->ts_workq == NULL) {
466 dev_err(wm->dev,
467 "Failed to create workqueue\n");
468 return -EINVAL;
471 /* start digitiser */
472 if (wm->mach_ops && wm->mach_ops->acc_enabled)
473 wm->codec->acc_enable(wm, 1);
474 wm->codec->dig_enable(wm, 1);
476 INIT_DELAYED_WORK(&wm->ts_reader, wm97xx_ts_reader);
477 INIT_WORK(&wm->pen_event_work, wm97xx_pen_irq_worker);
479 wm->ts_reader_min_interval = HZ >= 100 ? HZ / 100 : 1;
480 if (wm->ts_reader_min_interval < 1)
481 wm->ts_reader_min_interval = 1;
482 wm->ts_reader_interval = wm->ts_reader_min_interval;
484 wm->pen_is_down = 0;
485 if (wm->pen_irq)
486 wm97xx_init_pen_irq(wm);
487 else
488 dev_err(wm->dev, "No IRQ specified\n");
490 /* If we either don't have an interrupt for pen down events or
491 * failed to acquire it then we need to poll.
493 if (wm->pen_irq == 0)
494 queue_delayed_work(wm->ts_workq, &wm->ts_reader,
495 wm->ts_reader_interval);
497 return 0;
501 * wm97xx_ts_input_close - Close the touch screen input device.
502 * @idev: Input device to be closed.
504 * Called by the input sub system to close a wm97xx touchscreen
505 * device. Kills the touchscreen thread and stops the touch
506 * digitiser.
509 static void wm97xx_ts_input_close(struct input_dev *idev)
511 struct wm97xx *wm = input_get_drvdata(idev);
512 u16 reg;
514 if (wm->pen_irq) {
515 /* Return the interrupt to GPIO usage (disabling it) */
516 if (wm->id != WM9705_ID2) {
517 BUG_ON(!wm->mach_ops->irq_gpio);
518 reg = wm97xx_reg_read(wm, AC97_MISC_AFE);
519 wm97xx_reg_write(wm, AC97_MISC_AFE,
520 reg | wm->mach_ops->irq_gpio);
523 free_irq(wm->pen_irq, wm);
526 wm->pen_is_down = 0;
528 /* Balance out interrupt disables/enables */
529 if (cancel_work_sync(&wm->pen_event_work))
530 wm->mach_ops->irq_enable(wm, 1);
532 /* ts_reader rearms itself so we need to explicitly stop it
533 * before we destroy the workqueue.
535 cancel_delayed_work_sync(&wm->ts_reader);
537 destroy_workqueue(wm->ts_workq);
539 /* stop digitiser */
540 wm->codec->dig_enable(wm, 0);
541 if (wm->mach_ops && wm->mach_ops->acc_enabled)
542 wm->codec->acc_enable(wm, 0);
545 static int wm97xx_probe(struct device *dev)
547 struct wm97xx *wm;
548 int ret = 0, id = 0;
550 wm = kzalloc(sizeof(struct wm97xx), GFP_KERNEL);
551 if (!wm)
552 return -ENOMEM;
553 mutex_init(&wm->codec_mutex);
555 wm->dev = dev;
556 dev->driver_data = wm;
557 wm->ac97 = to_ac97_t(dev);
559 /* check that we have a supported codec */
560 id = wm97xx_reg_read(wm, AC97_VENDOR_ID1);
561 if (id != WM97XX_ID1) {
562 dev_err(dev, "Device with vendor %04x is not a wm97xx\n", id);
563 ret = -ENODEV;
564 goto alloc_err;
567 wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2);
569 dev_info(wm->dev, "detected a wm97%02x codec\n", wm->id & 0xff);
571 switch (wm->id & 0xff) {
572 #ifdef CONFIG_TOUCHSCREEN_WM9705
573 case 0x05:
574 wm->codec = &wm9705_codec;
575 break;
576 #endif
577 #ifdef CONFIG_TOUCHSCREEN_WM9712
578 case 0x12:
579 wm->codec = &wm9712_codec;
580 break;
581 #endif
582 #ifdef CONFIG_TOUCHSCREEN_WM9713
583 case 0x13:
584 wm->codec = &wm9713_codec;
585 break;
586 #endif
587 default:
588 dev_err(wm->dev, "Support for wm97%02x not compiled in.\n",
589 wm->id & 0xff);
590 ret = -ENODEV;
591 goto alloc_err;
594 wm->input_dev = input_allocate_device();
595 if (wm->input_dev == NULL) {
596 ret = -ENOMEM;
597 goto alloc_err;
600 /* set up touch configuration */
601 wm->input_dev->name = "wm97xx touchscreen";
602 wm->input_dev->open = wm97xx_ts_input_open;
603 wm->input_dev->close = wm97xx_ts_input_close;
604 set_bit(EV_ABS, wm->input_dev->evbit);
605 set_bit(ABS_X, wm->input_dev->absbit);
606 set_bit(ABS_Y, wm->input_dev->absbit);
607 set_bit(ABS_PRESSURE, wm->input_dev->absbit);
608 input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1],
609 abs_x[2], 0);
610 input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1],
611 abs_y[2], 0);
612 input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1],
613 abs_p[2], 0);
614 input_set_drvdata(wm->input_dev, wm);
615 wm->input_dev->dev.parent = dev;
616 ret = input_register_device(wm->input_dev);
617 if (ret < 0)
618 goto dev_alloc_err;
620 /* set up physical characteristics */
621 wm->codec->phy_init(wm);
623 /* load gpio cache */
624 wm->gpio[0] = wm97xx_reg_read(wm, AC97_GPIO_CFG);
625 wm->gpio[1] = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
626 wm->gpio[2] = wm97xx_reg_read(wm, AC97_GPIO_STICKY);
627 wm->gpio[3] = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP);
628 wm->gpio[4] = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
629 wm->gpio[5] = wm97xx_reg_read(wm, AC97_MISC_AFE);
631 /* register our battery device */
632 wm->battery_dev = platform_device_alloc("wm97xx-battery", -1);
633 if (!wm->battery_dev) {
634 ret = -ENOMEM;
635 goto batt_err;
637 platform_set_drvdata(wm->battery_dev, wm);
638 wm->battery_dev->dev.parent = dev;
639 ret = platform_device_add(wm->battery_dev);
640 if (ret < 0)
641 goto batt_reg_err;
643 /* register our extended touch device (for machine specific
644 * extensions) */
645 wm->touch_dev = platform_device_alloc("wm97xx-touch", -1);
646 if (!wm->touch_dev) {
647 ret = -ENOMEM;
648 goto touch_err;
650 platform_set_drvdata(wm->touch_dev, wm);
651 wm->touch_dev->dev.parent = dev;
652 ret = platform_device_add(wm->touch_dev);
653 if (ret < 0)
654 goto touch_reg_err;
656 return ret;
658 touch_reg_err:
659 platform_device_put(wm->touch_dev);
660 touch_err:
661 platform_device_unregister(wm->battery_dev);
662 wm->battery_dev = NULL;
663 batt_reg_err:
664 platform_device_put(wm->battery_dev);
665 batt_err:
666 input_unregister_device(wm->input_dev);
667 wm->input_dev = NULL;
668 dev_alloc_err:
669 input_free_device(wm->input_dev);
670 alloc_err:
671 kfree(wm);
673 return ret;
676 static int wm97xx_remove(struct device *dev)
678 struct wm97xx *wm = dev_get_drvdata(dev);
680 platform_device_unregister(wm->battery_dev);
681 platform_device_unregister(wm->touch_dev);
682 input_unregister_device(wm->input_dev);
683 kfree(wm);
685 return 0;
688 #ifdef CONFIG_PM
689 static int wm97xx_suspend(struct device *dev, pm_message_t state)
691 struct wm97xx *wm = dev_get_drvdata(dev);
693 if (wm->input_dev->users)
694 cancel_delayed_work_sync(&wm->ts_reader);
696 return 0;
699 static int wm97xx_resume(struct device *dev)
701 struct wm97xx *wm = dev_get_drvdata(dev);
703 /* restore digitiser and gpios */
704 if (wm->id == WM9713_ID2) {
705 wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig[0]);
706 wm97xx_reg_write(wm, 0x5a, wm->misc);
707 if (wm->input_dev->users) {
708 u16 reg;
709 reg = wm97xx_reg_read(wm, AC97_EXTENDED_MID) & 0x7fff;
710 wm97xx_reg_write(wm, AC97_EXTENDED_MID, reg);
714 wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig[1]);
715 wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2]);
717 wm97xx_reg_write(wm, AC97_GPIO_CFG, wm->gpio[0]);
718 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, wm->gpio[1]);
719 wm97xx_reg_write(wm, AC97_GPIO_STICKY, wm->gpio[2]);
720 wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, wm->gpio[3]);
721 wm97xx_reg_write(wm, AC97_GPIO_STATUS, wm->gpio[4]);
722 wm97xx_reg_write(wm, AC97_MISC_AFE, wm->gpio[5]);
724 if (wm->input_dev->users && !wm->pen_irq) {
725 wm->ts_reader_interval = wm->ts_reader_min_interval;
726 queue_delayed_work(wm->ts_workq, &wm->ts_reader,
727 wm->ts_reader_interval);
730 return 0;
733 #else
734 #define wm97xx_suspend NULL
735 #define wm97xx_resume NULL
736 #endif
739 * Machine specific operations
741 int wm97xx_register_mach_ops(struct wm97xx *wm,
742 struct wm97xx_mach_ops *mach_ops)
744 mutex_lock(&wm->codec_mutex);
745 if (wm->mach_ops) {
746 mutex_unlock(&wm->codec_mutex);
747 return -EINVAL;
749 wm->mach_ops = mach_ops;
750 mutex_unlock(&wm->codec_mutex);
752 return 0;
754 EXPORT_SYMBOL_GPL(wm97xx_register_mach_ops);
756 void wm97xx_unregister_mach_ops(struct wm97xx *wm)
758 mutex_lock(&wm->codec_mutex);
759 wm->mach_ops = NULL;
760 mutex_unlock(&wm->codec_mutex);
762 EXPORT_SYMBOL_GPL(wm97xx_unregister_mach_ops);
764 static struct device_driver wm97xx_driver = {
765 .name = "ac97",
766 .bus = &ac97_bus_type,
767 .owner = THIS_MODULE,
768 .probe = wm97xx_probe,
769 .remove = wm97xx_remove,
770 .suspend = wm97xx_suspend,
771 .resume = wm97xx_resume,
774 static int __init wm97xx_init(void)
776 return driver_register(&wm97xx_driver);
779 static void __exit wm97xx_exit(void)
781 driver_unregister(&wm97xx_driver);
784 module_init(wm97xx_init);
785 module_exit(wm97xx_exit);
787 /* Module information */
788 MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>");
789 MODULE_DESCRIPTION("WM97xx Core - Touch Screen / AUX ADC / GPIO Driver");
790 MODULE_LICENSE("GPL");