zylonite-wm97xx.c 5.6 KB

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