zylonite-wm97xx.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * zylonite-wm97xx.c -- Zylonite Continuous Touch screen driver
  3. *
  4. * Copyright 2004, 2007, 2008 Wolfson Microelectronics PLC.
  5. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  6. * Parts Copyright : Ian Molton <spyro@f2s.com>
  7. * Andrew Zabolotny <zap@homelink.ru>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. * Notes:
  15. * This is a wm97xx extended touch driver supporting interrupt driven
  16. * and continuous operation on Marvell Zylonite development systems
  17. * (which have a WM9713 on board).
  18. */
  19. #include <linux/module.h>
  20. #include <linux/moduleparam.h>
  21. #include <linux/kernel.h>
  22. #include <linux/delay.h>
  23. #include <linux/gpio.h>
  24. #include <linux/irq.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/io.h>
  27. #include <linux/wm97xx.h>
  28. #include <mach/hardware.h>
  29. #include <mach/mfp.h>
  30. #include <mach/regs-ac97.h>
  31. struct continuous {
  32. u16 id; /* codec id */
  33. u8 code; /* continuous code */
  34. u8 reads; /* number of coord reads per read cycle */
  35. u32 speed; /* number of coords per second */
  36. };
  37. #define WM_READS(sp) ((sp / HZ) + 1)
  38. static const struct continuous cinfo[] = {
  39. { WM9713_ID2, 0, WM_READS(94), 94 },
  40. { WM9713_ID2, 1, WM_READS(120), 120 },
  41. { WM9713_ID2, 2, WM_READS(154), 154 },
  42. { WM9713_ID2, 3, WM_READS(188), 188 },
  43. };
  44. /* continuous speed index */
  45. static int sp_idx;
  46. /*
  47. * Pen sampling frequency (Hz) in continuous mode.
  48. */
  49. static int cont_rate = 200;
  50. module_param(cont_rate, int, 0);
  51. MODULE_PARM_DESC(cont_rate, "Sampling rate in continuous mode (Hz)");
  52. /*
  53. * Pressure readback.
  54. *
  55. * Set to 1 to read back pen down pressure
  56. */
  57. static int pressure;
  58. module_param(pressure, int, 0);
  59. MODULE_PARM_DESC(pressure, "Pressure readback (1 = pressure, 0 = no pressure)");
  60. /*
  61. * AC97 touch data slot.
  62. *
  63. * Touch screen readback data ac97 slot
  64. */
  65. static int ac97_touch_slot = 5;
  66. module_param(ac97_touch_slot, int, 0);
  67. MODULE_PARM_DESC(ac97_touch_slot, "Touch screen data slot AC97 number");
  68. /* flush AC97 slot 5 FIFO machines */
  69. static void wm97xx_acc_pen_up(struct wm97xx *wm)
  70. {
  71. int i;
  72. msleep(1);
  73. for (i = 0; i < 16; i++)
  74. MODR;
  75. }
  76. static int wm97xx_acc_pen_down(struct wm97xx *wm)
  77. {
  78. u16 x, y, p = 0x100 | WM97XX_ADCSEL_PRES;
  79. int reads = 0;
  80. static u16 last, tries;
  81. /* When the AC97 queue has been drained we need to allow time
  82. * to buffer up samples otherwise we end up spinning polling
  83. * for samples. The controller can't have a suitably low
  84. * threshold set to use the notifications it gives.
  85. */
  86. msleep(1);
  87. if (tries > 5) {
  88. tries = 0;
  89. return RC_PENUP;
  90. }
  91. x = MODR;
  92. if (x == last) {
  93. tries++;
  94. return RC_AGAIN;
  95. }
  96. last = x;
  97. do {
  98. if (reads)
  99. x = MODR;
  100. y = MODR;
  101. if (pressure)
  102. p = MODR;
  103. dev_dbg(wm->dev, "Raw coordinates: x=%x, y=%x, p=%x\n",
  104. x, y, p);
  105. /* are samples valid */
  106. if ((x & WM97XX_ADCSEL_MASK) != WM97XX_ADCSEL_X ||
  107. (y & WM97XX_ADCSEL_MASK) != WM97XX_ADCSEL_Y ||
  108. (p & WM97XX_ADCSEL_MASK) != WM97XX_ADCSEL_PRES)
  109. goto up;
  110. /* coordinate is good */
  111. tries = 0;
  112. input_report_abs(wm->input_dev, ABS_X, x & 0xfff);
  113. input_report_abs(wm->input_dev, ABS_Y, y & 0xfff);
  114. input_report_abs(wm->input_dev, ABS_PRESSURE, p & 0xfff);
  115. input_report_key(wm->input_dev, BTN_TOUCH, (p != 0));
  116. input_sync(wm->input_dev);
  117. reads++;
  118. } while (reads < cinfo[sp_idx].reads);
  119. up:
  120. return RC_PENDOWN | RC_AGAIN;
  121. }
  122. static int wm97xx_acc_startup(struct wm97xx *wm)
  123. {
  124. int idx;
  125. /* check we have a codec */
  126. if (wm->ac97 == NULL)
  127. return -ENODEV;
  128. /* Go you big red fire engine */
  129. for (idx = 0; idx < ARRAY_SIZE(cinfo); idx++) {
  130. if (wm->id != cinfo[idx].id)
  131. continue;
  132. sp_idx = idx;
  133. if (cont_rate <= cinfo[idx].speed)
  134. break;
  135. }
  136. wm->acc_rate = cinfo[sp_idx].code;
  137. wm->acc_slot = ac97_touch_slot;
  138. dev_info(wm->dev,
  139. "zylonite accelerated touchscreen driver, %d samples/sec\n",
  140. cinfo[sp_idx].speed);
  141. return 0;
  142. }
  143. static void wm97xx_irq_enable(struct wm97xx *wm, int enable)
  144. {
  145. if (enable)
  146. enable_irq(wm->pen_irq);
  147. else
  148. disable_irq_nosync(wm->pen_irq);
  149. }
  150. static struct wm97xx_mach_ops zylonite_mach_ops = {
  151. .acc_enabled = 1,
  152. .acc_pen_up = wm97xx_acc_pen_up,
  153. .acc_pen_down = wm97xx_acc_pen_down,
  154. .acc_startup = wm97xx_acc_startup,
  155. .irq_enable = wm97xx_irq_enable,
  156. .irq_gpio = WM97XX_GPIO_2,
  157. };
  158. static int zylonite_wm97xx_probe(struct platform_device *pdev)
  159. {
  160. struct wm97xx *wm = platform_get_drvdata(pdev);
  161. int gpio_touch_irq;
  162. if (cpu_is_pxa320())
  163. gpio_touch_irq = mfp_to_gpio(MFP_PIN_GPIO15);
  164. else
  165. gpio_touch_irq = mfp_to_gpio(MFP_PIN_GPIO26);
  166. wm->pen_irq = gpio_to_irq(gpio_touch_irq);
  167. irq_set_irq_type(wm->pen_irq, IRQ_TYPE_EDGE_BOTH);
  168. wm97xx_config_gpio(wm, WM97XX_GPIO_13, WM97XX_GPIO_IN,
  169. WM97XX_GPIO_POL_HIGH,
  170. WM97XX_GPIO_STICKY,
  171. WM97XX_GPIO_WAKE);
  172. wm97xx_config_gpio(wm, WM97XX_GPIO_2, WM97XX_GPIO_OUT,
  173. WM97XX_GPIO_POL_HIGH,
  174. WM97XX_GPIO_NOTSTICKY,
  175. WM97XX_GPIO_NOWAKE);
  176. return wm97xx_register_mach_ops(wm, &zylonite_mach_ops);
  177. }
  178. static int zylonite_wm97xx_remove(struct platform_device *pdev)
  179. {
  180. struct wm97xx *wm = platform_get_drvdata(pdev);
  181. wm97xx_unregister_mach_ops(wm);
  182. return 0;
  183. }
  184. static struct platform_driver zylonite_wm97xx_driver = {
  185. .probe = zylonite_wm97xx_probe,
  186. .remove = zylonite_wm97xx_remove,
  187. .driver = {
  188. .name = "wm97xx-touch",
  189. },
  190. };
  191. module_platform_driver(zylonite_wm97xx_driver);
  192. /* Module information */
  193. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  194. MODULE_DESCRIPTION("wm97xx continuous touch driver for Zylonite");
  195. MODULE_LICENSE("GPL");