1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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>
39#include <linux/pm.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>
46#include <linux/io.h>
47#include <linux/slab.h>
48
49#define TS_NAME "wm97xx"
50#define WM_CORE_VERSION "1.00"
51#define DEFAULT_PRESSURE 0xb0c0
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69static int abs_x[3] = {150, 4000, 5};
70module_param_array(abs_x, int, NULL, 0);
71MODULE_PARM_DESC(abs_x, "Touchscreen absolute X min, max, fuzz");
72
73static int abs_y[3] = {200, 4000, 40};
74module_param_array(abs_y, int, NULL, 0);
75MODULE_PARM_DESC(abs_y, "Touchscreen absolute Y min, max, fuzz");
76
77static int abs_p[3] = {0, 150, 4};
78module_param_array(abs_p, int, NULL, 0);
79MODULE_PARM_DESC(abs_p, "Touchscreen absolute Pressure min, max, fuzz");
80
81
82
83
84int wm97xx_reg_read(struct wm97xx *wm, u16 reg)
85{
86 if (wm->ac97)
87 return wm->ac97->bus->ops->read(wm->ac97, reg);
88 else
89 return -1;
90}
91EXPORT_SYMBOL_GPL(wm97xx_reg_read);
92
93void wm97xx_reg_write(struct wm97xx *wm, u16 reg, u16 val)
94{
95
96 if (reg >= AC97_WM9713_DIG1 && reg <= AC97_WM9713_DIG3)
97 wm->dig[(reg - AC97_WM9713_DIG1) >> 1] = val;
98
99
100 if (reg >= AC97_GPIO_CFG && reg <= AC97_MISC_AFE)
101 wm->gpio[(reg - AC97_GPIO_CFG) >> 1] = val;
102
103
104 if (reg == 0x5a)
105 wm->misc = val;
106
107 if (wm->ac97)
108 wm->ac97->bus->ops->write(wm->ac97, reg, val);
109}
110EXPORT_SYMBOL_GPL(wm97xx_reg_write);
111
112
113
114
115
116
117
118
119
120int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel)
121{
122 int power_adc = 0, auxval;
123 u16 power = 0;
124 int rc = 0;
125 int timeout = 0;
126
127
128 mutex_lock(&wm->codec_mutex);
129
130
131
132
133 if (wm->id == WM9713_ID2 &&
134 (power = wm97xx_reg_read(wm, AC97_EXTENDED_MID)) & 0x8000) {
135 power_adc = 1;
136 wm97xx_reg_write(wm, AC97_EXTENDED_MID, power & 0x7fff);
137 }
138
139
140 wm->codec->aux_prepare(wm);
141
142
143 wm->pen_probably_down = 1;
144
145 while (rc != RC_VALID && timeout++ < 5)
146 rc = wm->codec->poll_sample(wm, adcsel, &auxval);
147
148 if (power_adc)
149 wm97xx_reg_write(wm, AC97_EXTENDED_MID, power | 0x8000);
150
151 wm->codec->dig_restore(wm);
152
153 wm->pen_probably_down = 0;
154
155 if (timeout >= 5) {
156 dev_err(wm->dev,
157 "timeout reading auxadc %d, disabling digitiser\n",
158 adcsel);
159 wm->codec->dig_enable(wm, false);
160 }
161
162 mutex_unlock(&wm->codec_mutex);
163 return (rc == RC_VALID ? auxval & 0xfff : -EBUSY);
164}
165EXPORT_SYMBOL_GPL(wm97xx_read_aux_adc);
166
167
168
169
170
171
172
173
174
175enum wm97xx_gpio_status wm97xx_get_gpio(struct wm97xx *wm, u32 gpio)
176{
177 u16 status;
178 enum wm97xx_gpio_status ret;
179
180 mutex_lock(&wm->codec_mutex);
181 status = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
182
183 if (status & gpio)
184 ret = WM97XX_GPIO_HIGH;
185 else
186 ret = WM97XX_GPIO_LOW;
187
188 mutex_unlock(&wm->codec_mutex);
189 return ret;
190}
191EXPORT_SYMBOL_GPL(wm97xx_get_gpio);
192
193
194
195
196
197
198
199
200
201
202void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio,
203 enum wm97xx_gpio_status status)
204{
205 u16 reg;
206
207 mutex_lock(&wm->codec_mutex);
208 reg = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
209
210 if (status == WM97XX_GPIO_HIGH)
211 reg |= gpio;
212 else
213 reg &= ~gpio;
214
215 if (wm->id == WM9712_ID2 && wm->variant != WM97xx_WM1613)
216 wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg << 1);
217 else
218 wm97xx_reg_write(wm, AC97_GPIO_STATUS, reg);
219 mutex_unlock(&wm->codec_mutex);
220}
221EXPORT_SYMBOL_GPL(wm97xx_set_gpio);
222
223
224
225
226
227void 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)
230{
231 u16 reg;
232
233 mutex_lock(&wm->codec_mutex);
234 reg = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
235
236 if (pol == WM97XX_GPIO_POL_HIGH)
237 reg |= gpio;
238 else
239 reg &= ~gpio;
240
241 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, reg);
242 reg = wm97xx_reg_read(wm, AC97_GPIO_STICKY);
243
244 if (sticky == WM97XX_GPIO_STICKY)
245 reg |= gpio;
246 else
247 reg &= ~gpio;
248
249 wm97xx_reg_write(wm, AC97_GPIO_STICKY, reg);
250 reg = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP);
251
252 if (wake == WM97XX_GPIO_WAKE)
253 reg |= gpio;
254 else
255 reg &= ~gpio;
256
257 wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, reg);
258 reg = wm97xx_reg_read(wm, AC97_GPIO_CFG);
259
260 if (dir == WM97XX_GPIO_IN)
261 reg |= gpio;
262 else
263 reg &= ~gpio;
264
265 wm97xx_reg_write(wm, AC97_GPIO_CFG, reg);
266 mutex_unlock(&wm->codec_mutex);
267}
268EXPORT_SYMBOL_GPL(wm97xx_config_gpio);
269
270
271
272
273
274
275
276
277
278
279
280void wm97xx_set_suspend_mode(struct wm97xx *wm, u16 mode)
281{
282 wm->suspend_mode = mode;
283 device_init_wakeup(&wm->input_dev->dev, mode != 0);
284}
285EXPORT_SYMBOL_GPL(wm97xx_set_suspend_mode);
286
287
288
289
290static void wm97xx_pen_irq_worker(struct work_struct *work)
291{
292 struct wm97xx *wm = container_of(work, struct wm97xx, pen_event_work);
293 int pen_was_down = wm->pen_is_down;
294
295
296 if (wm->id == WM9705_ID2) {
297 if (wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER_RD) &
298 WM97XX_PEN_DOWN)
299 wm->pen_is_down = 1;
300 else
301 wm->pen_is_down = 0;
302 } else {
303 u16 status, pol;
304 mutex_lock(&wm->codec_mutex);
305 status = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
306 pol = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
307
308 if (WM97XX_GPIO_13 & pol & status) {
309 wm->pen_is_down = 1;
310 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol &
311 ~WM97XX_GPIO_13);
312 } else {
313 wm->pen_is_down = 0;
314 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, pol |
315 WM97XX_GPIO_13);
316 }
317
318 if (wm->id == WM9712_ID2 && wm->variant != WM97xx_WM1613)
319 wm97xx_reg_write(wm, AC97_GPIO_STATUS, (status &
320 ~WM97XX_GPIO_13) << 1);
321 else
322 wm97xx_reg_write(wm, AC97_GPIO_STATUS, status &
323 ~WM97XX_GPIO_13);
324 mutex_unlock(&wm->codec_mutex);
325 }
326
327
328
329
330
331
332 if (!wm->mach_ops->acc_enabled || wm->mach_ops->acc_pen_down) {
333 if (wm->pen_is_down && !pen_was_down) {
334
335 queue_delayed_work(wm->ts_workq, &wm->ts_reader, 1);
336 }
337
338
339 if (!wm->pen_is_down && pen_was_down)
340 wm->pen_is_down = 1;
341 }
342
343 if (!wm->pen_is_down && wm->mach_ops->acc_enabled)
344 wm->mach_ops->acc_pen_up(wm);
345
346 wm->mach_ops->irq_enable(wm, 1);
347}
348
349
350
351
352
353
354
355
356
357
358static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id)
359{
360 struct wm97xx *wm = dev_id;
361
362 if (!work_pending(&wm->pen_event_work)) {
363 wm->mach_ops->irq_enable(wm, 0);
364 queue_work(wm->ts_workq, &wm->pen_event_work);
365 }
366
367 return IRQ_HANDLED;
368}
369
370
371
372
373static int wm97xx_init_pen_irq(struct wm97xx *wm)
374{
375 u16 reg;
376
377
378
379 BUG_ON(!wm->mach_ops->irq_enable);
380
381 if (request_irq(wm->pen_irq, wm97xx_pen_interrupt, IRQF_SHARED,
382 "wm97xx-pen", wm)) {
383 dev_err(wm->dev,
384 "Failed to register pen down interrupt, polling");
385 wm->pen_irq = 0;
386 return -EINVAL;
387 }
388
389
390 if (wm->id != WM9705_ID2) {
391 BUG_ON(!wm->mach_ops->irq_gpio);
392 reg = wm97xx_reg_read(wm, AC97_MISC_AFE);
393 wm97xx_reg_write(wm, AC97_MISC_AFE,
394 reg & ~(wm->mach_ops->irq_gpio));
395 reg = wm97xx_reg_read(wm, 0x5a);
396 wm97xx_reg_write(wm, 0x5a, reg & ~0x0001);
397 }
398
399 return 0;
400}
401
402static int wm97xx_read_samples(struct wm97xx *wm)
403{
404 struct wm97xx_data data;
405 int rc;
406
407 mutex_lock(&wm->codec_mutex);
408
409 if (wm->mach_ops && wm->mach_ops->acc_enabled)
410 rc = wm->mach_ops->acc_pen_down(wm);
411 else
412 rc = wm->codec->poll_touch(wm, &data);
413
414 if (rc & RC_PENUP) {
415 if (wm->pen_is_down) {
416 wm->pen_is_down = 0;
417 dev_dbg(wm->dev, "pen up\n");
418 input_report_abs(wm->input_dev, ABS_PRESSURE, 0);
419 input_report_key(wm->input_dev, BTN_TOUCH, 0);
420 input_sync(wm->input_dev);
421 } else if (!(rc & RC_AGAIN)) {
422
423
424
425
426
427
428
429
430
431
432 if (wm->ts_reader_interval < HZ / 10)
433 wm->ts_reader_interval++;
434 }
435
436 } else if (rc & RC_VALID) {
437 dev_dbg(wm->dev,
438 "pen down: x=%x:%d, y=%x:%d, pressure=%x:%d\n",
439 data.x >> 12, data.x & 0xfff, data.y >> 12,
440 data.y & 0xfff, data.p >> 12, data.p & 0xfff);
441
442 if (abs_x[0] > (data.x & 0xfff) ||
443 abs_x[1] < (data.x & 0xfff) ||
444 abs_y[0] > (data.y & 0xfff) ||
445 abs_y[1] < (data.y & 0xfff)) {
446 dev_dbg(wm->dev, "Measurement out of range, dropping it\n");
447 rc = RC_AGAIN;
448 goto out;
449 }
450
451 input_report_abs(wm->input_dev, ABS_X, data.x & 0xfff);
452 input_report_abs(wm->input_dev, ABS_Y, data.y & 0xfff);
453 input_report_abs(wm->input_dev, ABS_PRESSURE, data.p & 0xfff);
454 input_report_key(wm->input_dev, BTN_TOUCH, 1);
455 input_sync(wm->input_dev);
456 wm->pen_is_down = 1;
457 wm->ts_reader_interval = wm->ts_reader_min_interval;
458 } else if (rc & RC_PENDOWN) {
459 dev_dbg(wm->dev, "pen down\n");
460 wm->pen_is_down = 1;
461 wm->ts_reader_interval = wm->ts_reader_min_interval;
462 }
463
464out:
465 mutex_unlock(&wm->codec_mutex);
466 return rc;
467}
468
469
470
471
472static void wm97xx_ts_reader(struct work_struct *work)
473{
474 int rc;
475 struct wm97xx *wm = container_of(work, struct wm97xx, ts_reader.work);
476
477 BUG_ON(!wm->codec);
478
479 do {
480 rc = wm97xx_read_samples(wm);
481 } while (rc & RC_AGAIN);
482
483 if (wm->pen_is_down || !wm->pen_irq)
484 queue_delayed_work(wm->ts_workq, &wm->ts_reader,
485 wm->ts_reader_interval);
486}
487
488
489
490
491
492
493
494
495static int wm97xx_ts_input_open(struct input_dev *idev)
496{
497 struct wm97xx *wm = input_get_drvdata(idev);
498
499 wm->ts_workq = alloc_ordered_workqueue("kwm97xx", 0);
500 if (wm->ts_workq == NULL) {
501 dev_err(wm->dev,
502 "Failed to create workqueue\n");
503 return -EINVAL;
504 }
505
506
507 if (wm->mach_ops && wm->mach_ops->acc_enabled)
508 wm->codec->acc_enable(wm, 1);
509 wm->codec->dig_enable(wm, 1);
510
511 INIT_DELAYED_WORK(&wm->ts_reader, wm97xx_ts_reader);
512 INIT_WORK(&wm->pen_event_work, wm97xx_pen_irq_worker);
513
514 wm->ts_reader_min_interval = HZ >= 100 ? HZ / 100 : 1;
515 if (wm->ts_reader_min_interval < 1)
516 wm->ts_reader_min_interval = 1;
517 wm->ts_reader_interval = wm->ts_reader_min_interval;
518
519 wm->pen_is_down = 0;
520 if (wm->pen_irq)
521 wm97xx_init_pen_irq(wm);
522 else
523 dev_err(wm->dev, "No IRQ specified\n");
524
525
526
527
528 if (wm->pen_irq == 0)
529 queue_delayed_work(wm->ts_workq, &wm->ts_reader,
530 wm->ts_reader_interval);
531
532 return 0;
533}
534
535
536
537
538
539
540
541
542
543
544static void wm97xx_ts_input_close(struct input_dev *idev)
545{
546 struct wm97xx *wm = input_get_drvdata(idev);
547 u16 reg;
548
549 if (wm->pen_irq) {
550
551 if (wm->id != WM9705_ID2) {
552 BUG_ON(!wm->mach_ops->irq_gpio);
553 reg = wm97xx_reg_read(wm, AC97_MISC_AFE);
554 wm97xx_reg_write(wm, AC97_MISC_AFE,
555 reg | wm->mach_ops->irq_gpio);
556 }
557
558 free_irq(wm->pen_irq, wm);
559 }
560
561 wm->pen_is_down = 0;
562
563
564 if (cancel_work_sync(&wm->pen_event_work))
565 wm->mach_ops->irq_enable(wm, 1);
566
567
568
569
570 cancel_delayed_work_sync(&wm->ts_reader);
571
572 destroy_workqueue(wm->ts_workq);
573
574
575 wm->codec->dig_enable(wm, 0);
576 if (wm->mach_ops && wm->mach_ops->acc_enabled)
577 wm->codec->acc_enable(wm, 0);
578}
579
580static int wm97xx_register_touch(struct wm97xx *wm)
581{
582 struct wm97xx_pdata *pdata = dev_get_platdata(wm->dev);
583 int ret;
584
585 wm->input_dev = devm_input_allocate_device(wm->dev);
586 if (wm->input_dev == NULL)
587 return -ENOMEM;
588
589
590 wm->input_dev->name = "wm97xx touchscreen";
591 wm->input_dev->phys = "wm97xx";
592 wm->input_dev->open = wm97xx_ts_input_open;
593 wm->input_dev->close = wm97xx_ts_input_close;
594
595 __set_bit(EV_ABS, wm->input_dev->evbit);
596 __set_bit(EV_KEY, wm->input_dev->evbit);
597 __set_bit(BTN_TOUCH, wm->input_dev->keybit);
598
599 input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1],
600 abs_x[2], 0);
601 input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1],
602 abs_y[2], 0);
603 input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1],
604 abs_p[2], 0);
605
606 input_set_drvdata(wm->input_dev, wm);
607 wm->input_dev->dev.parent = wm->dev;
608
609 ret = input_register_device(wm->input_dev);
610 if (ret)
611 return ret;
612
613
614
615
616
617 wm->touch_dev = platform_device_alloc("wm97xx-touch", -1);
618 if (!wm->touch_dev)
619 return -ENOMEM;
620
621 platform_set_drvdata(wm->touch_dev, wm);
622 wm->touch_dev->dev.parent = wm->dev;
623 wm->touch_dev->dev.platform_data = pdata;
624 ret = platform_device_add(wm->touch_dev);
625 if (ret < 0)
626 goto touch_reg_err;
627
628 return 0;
629touch_reg_err:
630 platform_device_put(wm->touch_dev);
631
632 return ret;
633}
634
635static void wm97xx_unregister_touch(struct wm97xx *wm)
636{
637 platform_device_unregister(wm->touch_dev);
638}
639
640static int _wm97xx_probe(struct wm97xx *wm)
641{
642 int id = 0;
643
644 mutex_init(&wm->codec_mutex);
645 dev_set_drvdata(wm->dev, wm);
646
647
648 id = wm97xx_reg_read(wm, AC97_VENDOR_ID1);
649 if (id != WM97XX_ID1) {
650 dev_err(wm->dev,
651 "Device with vendor %04x is not a wm97xx\n", id);
652 return -ENODEV;
653 }
654
655 wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2);
656
657 wm->variant = WM97xx_GENERIC;
658
659 dev_info(wm->dev, "detected a wm97%02x codec\n", wm->id & 0xff);
660
661 switch (wm->id & 0xff) {
662#ifdef CONFIG_TOUCHSCREEN_WM9705
663 case 0x05:
664 wm->codec = &wm9705_codec;
665 break;
666#endif
667#ifdef CONFIG_TOUCHSCREEN_WM9712
668 case 0x12:
669 wm->codec = &wm9712_codec;
670 break;
671#endif
672#ifdef CONFIG_TOUCHSCREEN_WM9713
673 case 0x13:
674 wm->codec = &wm9713_codec;
675 break;
676#endif
677 default:
678 dev_err(wm->dev, "Support for wm97%02x not compiled in.\n",
679 wm->id & 0xff);
680 return -ENODEV;
681 }
682
683
684 wm->codec->phy_init(wm);
685
686
687 wm->gpio[0] = wm97xx_reg_read(wm, AC97_GPIO_CFG);
688 wm->gpio[1] = wm97xx_reg_read(wm, AC97_GPIO_POLARITY);
689 wm->gpio[2] = wm97xx_reg_read(wm, AC97_GPIO_STICKY);
690 wm->gpio[3] = wm97xx_reg_read(wm, AC97_GPIO_WAKEUP);
691 wm->gpio[4] = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
692 wm->gpio[5] = wm97xx_reg_read(wm, AC97_MISC_AFE);
693
694 return wm97xx_register_touch(wm);
695}
696
697static void wm97xx_remove_battery(struct wm97xx *wm)
698{
699 platform_device_unregister(wm->battery_dev);
700}
701
702static int wm97xx_add_battery(struct wm97xx *wm,
703 struct wm97xx_batt_pdata *pdata)
704{
705 int ret;
706
707 wm->battery_dev = platform_device_alloc("wm97xx-battery", -1);
708 if (!wm->battery_dev)
709 return -ENOMEM;
710
711 platform_set_drvdata(wm->battery_dev, wm);
712 wm->battery_dev->dev.parent = wm->dev;
713 wm->battery_dev->dev.platform_data = pdata;
714 ret = platform_device_add(wm->battery_dev);
715 if (ret)
716 platform_device_put(wm->battery_dev);
717
718 return ret;
719}
720
721static int wm97xx_probe(struct device *dev)
722{
723 struct wm97xx *wm;
724 int ret;
725 struct wm97xx_pdata *pdata = dev_get_platdata(dev);
726
727 wm = devm_kzalloc(dev, sizeof(struct wm97xx), GFP_KERNEL);
728 if (!wm)
729 return -ENOMEM;
730
731 wm->dev = dev;
732 wm->ac97 = to_ac97_t(dev);
733
734 ret = _wm97xx_probe(wm);
735 if (ret)
736 return ret;
737
738 ret = wm97xx_add_battery(wm, pdata ? pdata->batt_pdata : NULL);
739 if (ret < 0)
740 goto batt_err;
741
742 return ret;
743
744batt_err:
745 wm97xx_unregister_touch(wm);
746 return ret;
747}
748
749static int wm97xx_remove(struct device *dev)
750{
751 struct wm97xx *wm = dev_get_drvdata(dev);
752
753 wm97xx_remove_battery(wm);
754 wm97xx_unregister_touch(wm);
755
756 return 0;
757}
758
759static int wm97xx_mfd_probe(struct platform_device *pdev)
760{
761 struct wm97xx *wm;
762 struct wm97xx_platform_data *mfd_pdata = dev_get_platdata(&pdev->dev);
763 int ret;
764
765 wm = devm_kzalloc(&pdev->dev, sizeof(struct wm97xx), GFP_KERNEL);
766 if (!wm)
767 return -ENOMEM;
768
769 wm->dev = &pdev->dev;
770 wm->ac97 = mfd_pdata->ac97;
771
772 ret = _wm97xx_probe(wm);
773 if (ret)
774 return ret;
775
776 ret = wm97xx_add_battery(wm, mfd_pdata->batt_pdata);
777 if (ret < 0)
778 goto batt_err;
779
780 return ret;
781
782batt_err:
783 wm97xx_unregister_touch(wm);
784 return ret;
785}
786
787static int wm97xx_mfd_remove(struct platform_device *pdev)
788{
789 return wm97xx_remove(&pdev->dev);
790}
791
792static int __maybe_unused wm97xx_suspend(struct device *dev)
793{
794 struct wm97xx *wm = dev_get_drvdata(dev);
795 u16 reg;
796 int suspend_mode;
797
798 if (device_may_wakeup(&wm->input_dev->dev))
799 suspend_mode = wm->suspend_mode;
800 else
801 suspend_mode = 0;
802
803 mutex_lock(&wm->input_dev->mutex);
804 if (input_device_enabled(wm->input_dev))
805 cancel_delayed_work_sync(&wm->ts_reader);
806
807
808 reg = wm97xx_reg_read(wm, AC97_WM97XX_DIGITISER2);
809 reg &= ~WM97XX_PRP_DET_DIG;
810 if (input_device_enabled(wm->input_dev))
811 reg |= suspend_mode;
812 wm->ac97->bus->ops->write(wm->ac97, AC97_WM97XX_DIGITISER2, reg);
813
814
815
816 if (wm->id == WM9713_ID2 &&
817 (!input_device_enabled(wm->input_dev) || !suspend_mode)) {
818 reg = wm97xx_reg_read(wm, AC97_EXTENDED_MID) | 0x8000;
819 wm97xx_reg_write(wm, AC97_EXTENDED_MID, reg);
820 }
821 mutex_unlock(&wm->input_dev->mutex);
822
823 return 0;
824}
825
826static int __maybe_unused wm97xx_resume(struct device *dev)
827{
828 struct wm97xx *wm = dev_get_drvdata(dev);
829
830 mutex_lock(&wm->input_dev->mutex);
831
832 if (wm->id == WM9713_ID2) {
833 wm97xx_reg_write(wm, AC97_WM9713_DIG1, wm->dig[0]);
834 wm97xx_reg_write(wm, 0x5a, wm->misc);
835 if (input_device_enabled(wm->input_dev)) {
836 u16 reg;
837 reg = wm97xx_reg_read(wm, AC97_EXTENDED_MID) & 0x7fff;
838 wm97xx_reg_write(wm, AC97_EXTENDED_MID, reg);
839 }
840 }
841
842 wm97xx_reg_write(wm, AC97_WM9713_DIG2, wm->dig[1]);
843 wm97xx_reg_write(wm, AC97_WM9713_DIG3, wm->dig[2]);
844
845 wm97xx_reg_write(wm, AC97_GPIO_CFG, wm->gpio[0]);
846 wm97xx_reg_write(wm, AC97_GPIO_POLARITY, wm->gpio[1]);
847 wm97xx_reg_write(wm, AC97_GPIO_STICKY, wm->gpio[2]);
848 wm97xx_reg_write(wm, AC97_GPIO_WAKEUP, wm->gpio[3]);
849 wm97xx_reg_write(wm, AC97_GPIO_STATUS, wm->gpio[4]);
850 wm97xx_reg_write(wm, AC97_MISC_AFE, wm->gpio[5]);
851
852 if (input_device_enabled(wm->input_dev) && !wm->pen_irq) {
853 wm->ts_reader_interval = wm->ts_reader_min_interval;
854 queue_delayed_work(wm->ts_workq, &wm->ts_reader,
855 wm->ts_reader_interval);
856 }
857 mutex_unlock(&wm->input_dev->mutex);
858
859 return 0;
860}
861
862static SIMPLE_DEV_PM_OPS(wm97xx_pm_ops, wm97xx_suspend, wm97xx_resume);
863
864
865
866
867int wm97xx_register_mach_ops(struct wm97xx *wm,
868 struct wm97xx_mach_ops *mach_ops)
869{
870 mutex_lock(&wm->codec_mutex);
871 if (wm->mach_ops) {
872 mutex_unlock(&wm->codec_mutex);
873 return -EINVAL;
874 }
875 wm->mach_ops = mach_ops;
876 mutex_unlock(&wm->codec_mutex);
877
878 return 0;
879}
880EXPORT_SYMBOL_GPL(wm97xx_register_mach_ops);
881
882void wm97xx_unregister_mach_ops(struct wm97xx *wm)
883{
884 mutex_lock(&wm->codec_mutex);
885 wm->mach_ops = NULL;
886 mutex_unlock(&wm->codec_mutex);
887}
888EXPORT_SYMBOL_GPL(wm97xx_unregister_mach_ops);
889
890static struct device_driver wm97xx_driver = {
891 .name = "wm97xx-ts",
892#ifdef CONFIG_AC97_BUS
893 .bus = &ac97_bus_type,
894#endif
895 .owner = THIS_MODULE,
896 .probe = wm97xx_probe,
897 .remove = wm97xx_remove,
898 .pm = &wm97xx_pm_ops,
899};
900
901static struct platform_driver wm97xx_mfd_driver = {
902 .driver = {
903 .name = "wm97xx-ts",
904 .pm = &wm97xx_pm_ops,
905 },
906 .probe = wm97xx_mfd_probe,
907 .remove = wm97xx_mfd_remove,
908};
909
910static int __init wm97xx_init(void)
911{
912 int ret;
913
914 ret = platform_driver_register(&wm97xx_mfd_driver);
915 if (ret)
916 return ret;
917
918 if (IS_BUILTIN(CONFIG_AC97_BUS))
919 ret = driver_register(&wm97xx_driver);
920 return ret;
921}
922
923static void __exit wm97xx_exit(void)
924{
925 if (IS_BUILTIN(CONFIG_AC97_BUS))
926 driver_unregister(&wm97xx_driver);
927 platform_driver_unregister(&wm97xx_mfd_driver);
928}
929
930module_init(wm97xx_init);
931module_exit(wm97xx_exit);
932
933
934MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
935MODULE_DESCRIPTION("WM97xx Core - Touch Screen / AUX ADC / GPIO Driver");
936MODULE_LICENSE("GPL");
937