fsl-imx25-tcq.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. /*
  2. * Copyright (C) 2014-2015 Pengutronix, Markus Pargmann <mpa@pengutronix.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU General Public License version 2 as published by the
  6. * Free Software Foundation.
  7. *
  8. * Based on driver from 2011:
  9. * Juergen Beisert, Pengutronix <kernel@pengutronix.de>
  10. *
  11. * This is the driver for the imx25 TCQ (Touchscreen Conversion Queue)
  12. * connected to the imx25 ADC.
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/device.h>
  16. #include <linux/input.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/mfd/imx25-tsadc.h>
  19. #include <linux/module.h>
  20. #include <linux/of.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/regmap.h>
  23. static const char mx25_tcq_name[] = "mx25-tcq";
  24. enum mx25_tcq_mode {
  25. MX25_TS_4WIRE,
  26. };
  27. struct mx25_tcq_priv {
  28. struct regmap *regs;
  29. struct regmap *core_regs;
  30. struct input_dev *idev;
  31. enum mx25_tcq_mode mode;
  32. unsigned int pen_threshold;
  33. unsigned int sample_count;
  34. unsigned int expected_samples;
  35. unsigned int pen_debounce;
  36. unsigned int settling_time;
  37. struct clk *clk;
  38. int irq;
  39. struct device *dev;
  40. };
  41. static struct regmap_config mx25_tcq_regconfig = {
  42. .fast_io = true,
  43. .max_register = 0x5c,
  44. .reg_bits = 32,
  45. .val_bits = 32,
  46. .reg_stride = 4,
  47. };
  48. static const struct of_device_id mx25_tcq_ids[] = {
  49. { .compatible = "fsl,imx25-tcq", },
  50. { /* Sentinel */ }
  51. };
  52. #define TSC_4WIRE_PRE_INDEX 0
  53. #define TSC_4WIRE_X_INDEX 1
  54. #define TSC_4WIRE_Y_INDEX 2
  55. #define TSC_4WIRE_POST_INDEX 3
  56. #define TSC_4WIRE_LEAVE 4
  57. #define MX25_TSC_DEF_THRESHOLD 80
  58. #define TSC_MAX_SAMPLES 16
  59. #define MX25_TSC_REPEAT_WAIT 14
  60. enum mx25_adc_configurations {
  61. MX25_CFG_PRECHARGE = 0,
  62. MX25_CFG_TOUCH_DETECT,
  63. MX25_CFG_X_MEASUREMENT,
  64. MX25_CFG_Y_MEASUREMENT,
  65. };
  66. #define MX25_PRECHARGE_VALUE (\
  67. MX25_ADCQ_CFG_YPLL_OFF | \
  68. MX25_ADCQ_CFG_XNUR_OFF | \
  69. MX25_ADCQ_CFG_XPUL_HIGH | \
  70. MX25_ADCQ_CFG_REFP_INT | \
  71. MX25_ADCQ_CFG_IN_XP | \
  72. MX25_ADCQ_CFG_REFN_NGND2 | \
  73. MX25_ADCQ_CFG_IGS)
  74. #define MX25_TOUCH_DETECT_VALUE (\
  75. MX25_ADCQ_CFG_YNLR | \
  76. MX25_ADCQ_CFG_YPLL_OFF | \
  77. MX25_ADCQ_CFG_XNUR_OFF | \
  78. MX25_ADCQ_CFG_XPUL_OFF | \
  79. MX25_ADCQ_CFG_REFP_INT | \
  80. MX25_ADCQ_CFG_IN_XP | \
  81. MX25_ADCQ_CFG_REFN_NGND2 | \
  82. MX25_ADCQ_CFG_PENIACK)
  83. static void imx25_setup_queue_cfgs(struct mx25_tcq_priv *priv,
  84. unsigned int settling_cnt)
  85. {
  86. u32 precharge_cfg =
  87. MX25_PRECHARGE_VALUE |
  88. MX25_ADCQ_CFG_SETTLING_TIME(settling_cnt);
  89. u32 touch_detect_cfg =
  90. MX25_TOUCH_DETECT_VALUE |
  91. MX25_ADCQ_CFG_NOS(1) |
  92. MX25_ADCQ_CFG_SETTLING_TIME(settling_cnt);
  93. regmap_write(priv->core_regs, MX25_TSC_TICR, precharge_cfg);
  94. /* PRECHARGE */
  95. regmap_write(priv->regs, MX25_ADCQ_CFG(MX25_CFG_PRECHARGE),
  96. precharge_cfg);
  97. /* TOUCH_DETECT */
  98. regmap_write(priv->regs, MX25_ADCQ_CFG(MX25_CFG_TOUCH_DETECT),
  99. touch_detect_cfg);
  100. /* X Measurement */
  101. regmap_write(priv->regs, MX25_ADCQ_CFG(MX25_CFG_X_MEASUREMENT),
  102. MX25_ADCQ_CFG_YPLL_OFF |
  103. MX25_ADCQ_CFG_XNUR_LOW |
  104. MX25_ADCQ_CFG_XPUL_HIGH |
  105. MX25_ADCQ_CFG_REFP_XP |
  106. MX25_ADCQ_CFG_IN_YP |
  107. MX25_ADCQ_CFG_REFN_XN |
  108. MX25_ADCQ_CFG_NOS(priv->sample_count) |
  109. MX25_ADCQ_CFG_SETTLING_TIME(settling_cnt));
  110. /* Y Measurement */
  111. regmap_write(priv->regs, MX25_ADCQ_CFG(MX25_CFG_Y_MEASUREMENT),
  112. MX25_ADCQ_CFG_YNLR |
  113. MX25_ADCQ_CFG_YPLL_HIGH |
  114. MX25_ADCQ_CFG_XNUR_OFF |
  115. MX25_ADCQ_CFG_XPUL_OFF |
  116. MX25_ADCQ_CFG_REFP_YP |
  117. MX25_ADCQ_CFG_IN_XP |
  118. MX25_ADCQ_CFG_REFN_YN |
  119. MX25_ADCQ_CFG_NOS(priv->sample_count) |
  120. MX25_ADCQ_CFG_SETTLING_TIME(settling_cnt));
  121. /* Enable the touch detection right now */
  122. regmap_write(priv->core_regs, MX25_TSC_TICR, touch_detect_cfg |
  123. MX25_ADCQ_CFG_IGS);
  124. }
  125. static int imx25_setup_queue_4wire(struct mx25_tcq_priv *priv,
  126. unsigned settling_cnt, int *items)
  127. {
  128. imx25_setup_queue_cfgs(priv, settling_cnt);
  129. /* Setup the conversion queue */
  130. regmap_write(priv->regs, MX25_ADCQ_ITEM_7_0,
  131. MX25_ADCQ_ITEM(0, MX25_CFG_PRECHARGE) |
  132. MX25_ADCQ_ITEM(1, MX25_CFG_TOUCH_DETECT) |
  133. MX25_ADCQ_ITEM(2, MX25_CFG_X_MEASUREMENT) |
  134. MX25_ADCQ_ITEM(3, MX25_CFG_Y_MEASUREMENT) |
  135. MX25_ADCQ_ITEM(4, MX25_CFG_PRECHARGE) |
  136. MX25_ADCQ_ITEM(5, MX25_CFG_TOUCH_DETECT));
  137. /*
  138. * We measure X/Y with 'sample_count' number of samples and execute a
  139. * touch detection twice, with 1 sample each
  140. */
  141. priv->expected_samples = priv->sample_count * 2 + 2;
  142. *items = 6;
  143. return 0;
  144. }
  145. static void mx25_tcq_disable_touch_irq(struct mx25_tcq_priv *priv)
  146. {
  147. regmap_update_bits(priv->regs, MX25_ADCQ_CR, MX25_ADCQ_CR_PDMSK,
  148. MX25_ADCQ_CR_PDMSK);
  149. }
  150. static void mx25_tcq_enable_touch_irq(struct mx25_tcq_priv *priv)
  151. {
  152. regmap_update_bits(priv->regs, MX25_ADCQ_CR, MX25_ADCQ_CR_PDMSK, 0);
  153. }
  154. static void mx25_tcq_disable_fifo_irq(struct mx25_tcq_priv *priv)
  155. {
  156. regmap_update_bits(priv->regs, MX25_ADCQ_MR, MX25_ADCQ_MR_FDRY_IRQ,
  157. MX25_ADCQ_MR_FDRY_IRQ);
  158. }
  159. static void mx25_tcq_enable_fifo_irq(struct mx25_tcq_priv *priv)
  160. {
  161. regmap_update_bits(priv->regs, MX25_ADCQ_MR, MX25_ADCQ_MR_FDRY_IRQ, 0);
  162. }
  163. static void mx25_tcq_force_queue_start(struct mx25_tcq_priv *priv)
  164. {
  165. regmap_update_bits(priv->regs, MX25_ADCQ_CR,
  166. MX25_ADCQ_CR_FQS,
  167. MX25_ADCQ_CR_FQS);
  168. }
  169. static void mx25_tcq_force_queue_stop(struct mx25_tcq_priv *priv)
  170. {
  171. regmap_update_bits(priv->regs, MX25_ADCQ_CR,
  172. MX25_ADCQ_CR_FQS, 0);
  173. }
  174. static void mx25_tcq_fifo_reset(struct mx25_tcq_priv *priv)
  175. {
  176. u32 tcqcr;
  177. regmap_read(priv->regs, MX25_ADCQ_CR, &tcqcr);
  178. regmap_update_bits(priv->regs, MX25_ADCQ_CR, MX25_ADCQ_CR_FRST,
  179. MX25_ADCQ_CR_FRST);
  180. regmap_update_bits(priv->regs, MX25_ADCQ_CR, MX25_ADCQ_CR_FRST, 0);
  181. regmap_write(priv->regs, MX25_ADCQ_CR, tcqcr);
  182. }
  183. static void mx25_tcq_re_enable_touch_detection(struct mx25_tcq_priv *priv)
  184. {
  185. /* stop the queue from looping */
  186. mx25_tcq_force_queue_stop(priv);
  187. /* for a clean touch detection, preload the X plane */
  188. regmap_write(priv->core_regs, MX25_TSC_TICR, MX25_PRECHARGE_VALUE);
  189. /* waste some time now to pre-load the X plate to high voltage */
  190. mx25_tcq_fifo_reset(priv);
  191. /* re-enable the detection right now */
  192. regmap_write(priv->core_regs, MX25_TSC_TICR,
  193. MX25_TOUCH_DETECT_VALUE | MX25_ADCQ_CFG_IGS);
  194. regmap_update_bits(priv->regs, MX25_ADCQ_SR, MX25_ADCQ_SR_PD,
  195. MX25_ADCQ_SR_PD);
  196. /* enable the pen down event to be a source for the interrupt */
  197. regmap_update_bits(priv->regs, MX25_ADCQ_MR, MX25_ADCQ_MR_PD_IRQ, 0);
  198. /* lets fire the next IRQ if someone touches the touchscreen */
  199. mx25_tcq_enable_touch_irq(priv);
  200. }
  201. static void mx25_tcq_create_event_for_4wire(struct mx25_tcq_priv *priv,
  202. u32 *sample_buf,
  203. unsigned int samples)
  204. {
  205. unsigned int x_pos = 0;
  206. unsigned int y_pos = 0;
  207. unsigned int touch_pre = 0;
  208. unsigned int touch_post = 0;
  209. unsigned int i;
  210. for (i = 0; i < samples; i++) {
  211. unsigned int index = MX25_ADCQ_FIFO_ID(sample_buf[i]);
  212. unsigned int val = MX25_ADCQ_FIFO_DATA(sample_buf[i]);
  213. switch (index) {
  214. case 1:
  215. touch_pre = val;
  216. break;
  217. case 2:
  218. x_pos = val;
  219. break;
  220. case 3:
  221. y_pos = val;
  222. break;
  223. case 5:
  224. touch_post = val;
  225. break;
  226. default:
  227. dev_dbg(priv->dev, "Dropped samples because of invalid index %d\n",
  228. index);
  229. return;
  230. }
  231. }
  232. if (samples != 0) {
  233. /*
  234. * only if both touch measures are below a threshold,
  235. * the position is valid
  236. */
  237. if (touch_pre < priv->pen_threshold &&
  238. touch_post < priv->pen_threshold) {
  239. /* valid samples, generate a report */
  240. x_pos /= priv->sample_count;
  241. y_pos /= priv->sample_count;
  242. input_report_abs(priv->idev, ABS_X, x_pos);
  243. input_report_abs(priv->idev, ABS_Y, y_pos);
  244. input_report_key(priv->idev, BTN_TOUCH, 1);
  245. input_sync(priv->idev);
  246. /* get next sample */
  247. mx25_tcq_enable_fifo_irq(priv);
  248. } else if (touch_pre >= priv->pen_threshold &&
  249. touch_post >= priv->pen_threshold) {
  250. /*
  251. * if both samples are invalid,
  252. * generate a release report
  253. */
  254. input_report_key(priv->idev, BTN_TOUCH, 0);
  255. input_sync(priv->idev);
  256. mx25_tcq_re_enable_touch_detection(priv);
  257. } else {
  258. /*
  259. * if only one of both touch measurements are
  260. * below the threshold, still some bouncing
  261. * happens. Take additional samples in this
  262. * case to be sure
  263. */
  264. mx25_tcq_enable_fifo_irq(priv);
  265. }
  266. }
  267. }
  268. static irqreturn_t mx25_tcq_irq_thread(int irq, void *dev_id)
  269. {
  270. struct mx25_tcq_priv *priv = dev_id;
  271. u32 sample_buf[TSC_MAX_SAMPLES];
  272. unsigned int samples;
  273. u32 stats;
  274. unsigned int i;
  275. /*
  276. * Check how many samples are available. We always have to read exactly
  277. * sample_count samples from the fifo, or a multiple of sample_count.
  278. * Otherwise we mixup samples into different touch events.
  279. */
  280. regmap_read(priv->regs, MX25_ADCQ_SR, &stats);
  281. samples = MX25_ADCQ_SR_FDN(stats);
  282. samples -= samples % priv->sample_count;
  283. if (!samples)
  284. return IRQ_HANDLED;
  285. for (i = 0; i != samples; ++i)
  286. regmap_read(priv->regs, MX25_ADCQ_FIFO, &sample_buf[i]);
  287. mx25_tcq_create_event_for_4wire(priv, sample_buf, samples);
  288. return IRQ_HANDLED;
  289. }
  290. static irqreturn_t mx25_tcq_irq(int irq, void *dev_id)
  291. {
  292. struct mx25_tcq_priv *priv = dev_id;
  293. u32 stat;
  294. int ret = IRQ_HANDLED;
  295. regmap_read(priv->regs, MX25_ADCQ_SR, &stat);
  296. if (stat & (MX25_ADCQ_SR_FRR | MX25_ADCQ_SR_FUR | MX25_ADCQ_SR_FOR))
  297. mx25_tcq_re_enable_touch_detection(priv);
  298. if (stat & MX25_ADCQ_SR_PD) {
  299. mx25_tcq_disable_touch_irq(priv);
  300. mx25_tcq_force_queue_start(priv);
  301. mx25_tcq_enable_fifo_irq(priv);
  302. }
  303. if (stat & MX25_ADCQ_SR_FDRY) {
  304. mx25_tcq_disable_fifo_irq(priv);
  305. ret = IRQ_WAKE_THREAD;
  306. }
  307. regmap_update_bits(priv->regs, MX25_ADCQ_SR, MX25_ADCQ_SR_FRR |
  308. MX25_ADCQ_SR_FUR | MX25_ADCQ_SR_FOR |
  309. MX25_ADCQ_SR_PD,
  310. MX25_ADCQ_SR_FRR | MX25_ADCQ_SR_FUR |
  311. MX25_ADCQ_SR_FOR | MX25_ADCQ_SR_PD);
  312. return ret;
  313. }
  314. /* configure the state machine for a 4-wire touchscreen */
  315. static int mx25_tcq_init(struct mx25_tcq_priv *priv)
  316. {
  317. u32 tgcr;
  318. unsigned int ipg_div;
  319. unsigned int adc_period;
  320. unsigned int debounce_cnt;
  321. unsigned int settling_cnt;
  322. int itemct;
  323. int error;
  324. regmap_read(priv->core_regs, MX25_TSC_TGCR, &tgcr);
  325. ipg_div = max_t(unsigned int, 4, MX25_TGCR_GET_ADCCLK(tgcr));
  326. adc_period = USEC_PER_SEC * ipg_div * 2 + 2;
  327. adc_period /= clk_get_rate(priv->clk) / 1000 + 1;
  328. debounce_cnt = DIV_ROUND_UP(priv->pen_debounce, adc_period * 8) - 1;
  329. settling_cnt = DIV_ROUND_UP(priv->settling_time, adc_period * 8) - 1;
  330. /* Reset */
  331. regmap_write(priv->regs, MX25_ADCQ_CR,
  332. MX25_ADCQ_CR_QRST | MX25_ADCQ_CR_FRST);
  333. regmap_update_bits(priv->regs, MX25_ADCQ_CR,
  334. MX25_ADCQ_CR_QRST | MX25_ADCQ_CR_FRST, 0);
  335. /* up to 128 * 8 ADC clocks are possible */
  336. if (debounce_cnt > 127)
  337. debounce_cnt = 127;
  338. /* up to 255 * 8 ADC clocks are possible */
  339. if (settling_cnt > 255)
  340. settling_cnt = 255;
  341. error = imx25_setup_queue_4wire(priv, settling_cnt, &itemct);
  342. if (error)
  343. return error;
  344. regmap_update_bits(priv->regs, MX25_ADCQ_CR,
  345. MX25_ADCQ_CR_LITEMID_MASK | MX25_ADCQ_CR_WMRK_MASK,
  346. MX25_ADCQ_CR_LITEMID(itemct - 1) |
  347. MX25_ADCQ_CR_WMRK(priv->expected_samples - 1));
  348. /* setup debounce count */
  349. regmap_update_bits(priv->core_regs, MX25_TSC_TGCR,
  350. MX25_TGCR_PDBTIME_MASK,
  351. MX25_TGCR_PDBTIME(debounce_cnt));
  352. /* enable debounce */
  353. regmap_update_bits(priv->core_regs, MX25_TSC_TGCR, MX25_TGCR_PDBEN,
  354. MX25_TGCR_PDBEN);
  355. regmap_update_bits(priv->core_regs, MX25_TSC_TGCR, MX25_TGCR_PDEN,
  356. MX25_TGCR_PDEN);
  357. /* enable the engine on demand */
  358. regmap_update_bits(priv->regs, MX25_ADCQ_CR, MX25_ADCQ_CR_QSM_MASK,
  359. MX25_ADCQ_CR_QSM_FQS);
  360. /* Enable repeat and repeat wait */
  361. regmap_update_bits(priv->regs, MX25_ADCQ_CR,
  362. MX25_ADCQ_CR_RPT | MX25_ADCQ_CR_RWAIT_MASK,
  363. MX25_ADCQ_CR_RPT |
  364. MX25_ADCQ_CR_RWAIT(MX25_TSC_REPEAT_WAIT));
  365. return 0;
  366. }
  367. static int mx25_tcq_parse_dt(struct platform_device *pdev,
  368. struct mx25_tcq_priv *priv)
  369. {
  370. struct device_node *np = pdev->dev.of_node;
  371. u32 wires;
  372. int error;
  373. /* Setup defaults */
  374. priv->pen_threshold = 500;
  375. priv->sample_count = 3;
  376. priv->pen_debounce = 1000000;
  377. priv->settling_time = 250000;
  378. error = of_property_read_u32(np, "fsl,wires", &wires);
  379. if (error) {
  380. dev_err(&pdev->dev, "Failed to find fsl,wires properties\n");
  381. return error;
  382. }
  383. if (wires == 4) {
  384. priv->mode = MX25_TS_4WIRE;
  385. } else {
  386. dev_err(&pdev->dev, "%u-wire mode not supported\n", wires);
  387. return -EINVAL;
  388. }
  389. /* These are optional, we don't care about the return values */
  390. of_property_read_u32(np, "fsl,pen-threshold", &priv->pen_threshold);
  391. of_property_read_u32(np, "fsl,settling-time-ns", &priv->settling_time);
  392. of_property_read_u32(np, "fsl,pen-debounce-ns", &priv->pen_debounce);
  393. return 0;
  394. }
  395. static int mx25_tcq_open(struct input_dev *idev)
  396. {
  397. struct device *dev = &idev->dev;
  398. struct mx25_tcq_priv *priv = dev_get_drvdata(dev);
  399. int error;
  400. error = clk_prepare_enable(priv->clk);
  401. if (error) {
  402. dev_err(dev, "Failed to enable ipg clock\n");
  403. return error;
  404. }
  405. error = mx25_tcq_init(priv);
  406. if (error) {
  407. dev_err(dev, "Failed to init tcq\n");
  408. clk_disable_unprepare(priv->clk);
  409. return error;
  410. }
  411. mx25_tcq_re_enable_touch_detection(priv);
  412. return 0;
  413. }
  414. static void mx25_tcq_close(struct input_dev *idev)
  415. {
  416. struct mx25_tcq_priv *priv = input_get_drvdata(idev);
  417. mx25_tcq_force_queue_stop(priv);
  418. mx25_tcq_disable_touch_irq(priv);
  419. mx25_tcq_disable_fifo_irq(priv);
  420. clk_disable_unprepare(priv->clk);
  421. }
  422. static int mx25_tcq_probe(struct platform_device *pdev)
  423. {
  424. struct device *dev = &pdev->dev;
  425. struct input_dev *idev;
  426. struct mx25_tcq_priv *priv;
  427. struct mx25_tsadc *tsadc = dev_get_drvdata(pdev->dev.parent);
  428. struct resource *res;
  429. void __iomem *mem;
  430. int error;
  431. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  432. if (!priv)
  433. return -ENOMEM;
  434. priv->dev = dev;
  435. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  436. mem = devm_ioremap_resource(dev, res);
  437. if (IS_ERR(mem))
  438. return PTR_ERR(mem);
  439. error = mx25_tcq_parse_dt(pdev, priv);
  440. if (error)
  441. return error;
  442. priv->regs = devm_regmap_init_mmio(dev, mem, &mx25_tcq_regconfig);
  443. if (IS_ERR(priv->regs)) {
  444. dev_err(dev, "Failed to initialize regmap\n");
  445. return PTR_ERR(priv->regs);
  446. }
  447. priv->irq = platform_get_irq(pdev, 0);
  448. if (priv->irq <= 0) {
  449. dev_err(dev, "Failed to get IRQ\n");
  450. return priv->irq;
  451. }
  452. idev = devm_input_allocate_device(dev);
  453. if (!idev) {
  454. dev_err(dev, "Failed to allocate input device\n");
  455. return -ENOMEM;
  456. }
  457. idev->name = mx25_tcq_name;
  458. input_set_capability(idev, EV_KEY, BTN_TOUCH);
  459. input_set_abs_params(idev, ABS_X, 0, 0xfff, 0, 0);
  460. input_set_abs_params(idev, ABS_Y, 0, 0xfff, 0, 0);
  461. idev->id.bustype = BUS_HOST;
  462. idev->open = mx25_tcq_open;
  463. idev->close = mx25_tcq_close;
  464. priv->idev = idev;
  465. input_set_drvdata(idev, priv);
  466. priv->core_regs = tsadc->regs;
  467. if (!priv->core_regs)
  468. return -EINVAL;
  469. priv->clk = tsadc->clk;
  470. if (!priv->clk)
  471. return -EINVAL;
  472. platform_set_drvdata(pdev, priv);
  473. error = devm_request_threaded_irq(dev, priv->irq, mx25_tcq_irq,
  474. mx25_tcq_irq_thread, 0, pdev->name,
  475. priv);
  476. if (error) {
  477. dev_err(dev, "Failed requesting IRQ\n");
  478. return error;
  479. }
  480. error = input_register_device(idev);
  481. if (error) {
  482. dev_err(dev, "Failed to register input device\n");
  483. return error;
  484. }
  485. return 0;
  486. }
  487. static struct platform_driver mx25_tcq_driver = {
  488. .driver = {
  489. .name = "mx25-tcq",
  490. .of_match_table = mx25_tcq_ids,
  491. },
  492. .probe = mx25_tcq_probe,
  493. };
  494. module_platform_driver(mx25_tcq_driver);
  495. MODULE_DESCRIPTION("TS input driver for Freescale mx25");
  496. MODULE_AUTHOR("Markus Pargmann <mpa@pengutronix.de>");
  497. MODULE_LICENSE("GPL v2");