ads7846.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * ADS7846 based touchscreen and sensor driver
  3. *
  4. * Copyright (c) 2005 David Brownell
  5. *
  6. * Using code from:
  7. * - corgi_ts.c
  8. * Copyright (C) 2004-2005 Richard Purdie
  9. * - omap_ts.[hc], ads7846.h, ts_osk.c
  10. * Copyright (C) 2002 MontaVista Software
  11. * Copyright (C) 2004 Texas Instruments
  12. * Copyright (C) 2005 Dirk Behme
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. */
  18. #include <linux/device.h>
  19. #include <linux/init.h>
  20. #include <linux/delay.h>
  21. #include <linux/input.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/slab.h>
  24. #include <linux/spi/spi.h>
  25. #include <linux/spi/ads7846.h>
  26. #include <asm/irq.h>
  27. #ifdef CONFIG_ARM
  28. #include <asm/mach-types.h>
  29. #ifdef CONFIG_ARCH_OMAP
  30. #include <asm/arch/gpio.h>
  31. #endif
  32. #endif
  33. /*
  34. * This code has been lightly tested on an ads7846.
  35. * Support for ads7843 and ads7845 has only been stubbed in.
  36. *
  37. * Not yet done: investigate the values reported. Are x/y/pressure
  38. * event values sane enough for X11? How accurate are the temperature
  39. * and voltage readings? (System-specific calibration should support
  40. * accuracy of 0.3 degrees C; otherwise it's 2.0 degrees.)
  41. *
  42. * app note sbaa036 talks in more detail about accurate sampling...
  43. * that ought to help in situations like LCDs inducing noise (which
  44. * can also be helped by using synch signals) and more generally.
  45. */
  46. #define TS_POLL_PERIOD msecs_to_jiffies(10)
  47. /* this driver doesn't aim at the peak continuous sample rate */
  48. #define SAMPLE_BITS (8 /*cmd*/ + 16 /*sample*/ + 2 /* before, after */)
  49. struct ts_event {
  50. /* For portability, we can't read 12 bit values using SPI (which
  51. * would make the controller deliver them as native byteorder u16
  52. * with msbs zeroed). Instead, we read them as two 8-bit values,
  53. * which need byteswapping then range adjustment.
  54. */
  55. __be16 x;
  56. __be16 y;
  57. __be16 z1, z2;
  58. };
  59. struct ads7846 {
  60. struct input_dev *input;
  61. char phys[32];
  62. struct spi_device *spi;
  63. u16 model;
  64. u16 vref_delay_usecs;
  65. u16 x_plate_ohms;
  66. u8 read_x, read_y, read_z1, read_z2, pwrdown;
  67. u16 dummy; /* for the pwrdown read */
  68. struct ts_event tc;
  69. struct spi_transfer xfer[10];
  70. struct spi_message msg;
  71. spinlock_t lock;
  72. struct timer_list timer; /* P: lock */
  73. unsigned pendown:1; /* P: lock */
  74. unsigned pending:1; /* P: lock */
  75. // FIXME remove "irq_disabled"
  76. unsigned irq_disabled:1; /* P: lock */
  77. };
  78. /* leave chip selected when we're done, for quicker re-select? */
  79. #if 0
  80. #define CS_CHANGE(xfer) ((xfer).cs_change = 1)
  81. #else
  82. #define CS_CHANGE(xfer) ((xfer).cs_change = 0)
  83. #endif
  84. /*--------------------------------------------------------------------------*/
  85. /* The ADS7846 has touchscreen and other sensors.
  86. * Earlier ads784x chips are somewhat compatible.
  87. */
  88. #define ADS_START (1 << 7)
  89. #define ADS_A2A1A0_d_y (1 << 4) /* differential */
  90. #define ADS_A2A1A0_d_z1 (3 << 4) /* differential */
  91. #define ADS_A2A1A0_d_z2 (4 << 4) /* differential */
  92. #define ADS_A2A1A0_d_x (5 << 4) /* differential */
  93. #define ADS_A2A1A0_temp0 (0 << 4) /* non-differential */
  94. #define ADS_A2A1A0_vbatt (2 << 4) /* non-differential */
  95. #define ADS_A2A1A0_vaux (6 << 4) /* non-differential */
  96. #define ADS_A2A1A0_temp1 (7 << 4) /* non-differential */
  97. #define ADS_8_BIT (1 << 3)
  98. #define ADS_12_BIT (0 << 3)
  99. #define ADS_SER (1 << 2) /* non-differential */
  100. #define ADS_DFR (0 << 2) /* differential */
  101. #define ADS_PD10_PDOWN (0 << 0) /* lowpower mode + penirq */
  102. #define ADS_PD10_ADC_ON (1 << 0) /* ADC on */
  103. #define ADS_PD10_REF_ON (2 << 0) /* vREF on + penirq */
  104. #define ADS_PD10_ALL_ON (3 << 0) /* ADC + vREF on */
  105. #define MAX_12BIT ((1<<12)-1)
  106. /* leave ADC powered up (disables penirq) between differential samples */
  107. #define READ_12BIT_DFR(x) (ADS_START | ADS_A2A1A0_d_ ## x \
  108. | ADS_12_BIT | ADS_DFR)
  109. #define READ_Y (READ_12BIT_DFR(y) | ADS_PD10_ADC_ON)
  110. #define READ_Z1 (READ_12BIT_DFR(z1) | ADS_PD10_ADC_ON)
  111. #define READ_Z2 (READ_12BIT_DFR(z2) | ADS_PD10_ADC_ON)
  112. #define READ_X (READ_12BIT_DFR(x) | ADS_PD10_ADC_ON)
  113. #define PWRDOWN (READ_12BIT_DFR(y) | ADS_PD10_PDOWN) /* LAST */
  114. /* single-ended samples need to first power up reference voltage;
  115. * we leave both ADC and VREF powered
  116. */
  117. #define READ_12BIT_SER(x) (ADS_START | ADS_A2A1A0_ ## x \
  118. | ADS_12_BIT | ADS_SER)
  119. #define REF_ON (READ_12BIT_DFR(x) | ADS_PD10_ALL_ON)
  120. #define REF_OFF (READ_12BIT_DFR(y) | ADS_PD10_PDOWN)
  121. /*--------------------------------------------------------------------------*/
  122. /*
  123. * Non-touchscreen sensors only use single-ended conversions.
  124. */
  125. struct ser_req {
  126. u8 ref_on;
  127. u8 command;
  128. u8 ref_off;
  129. u16 scratch;
  130. __be16 sample;
  131. struct spi_message msg;
  132. struct spi_transfer xfer[6];
  133. };
  134. static int ads7846_read12_ser(struct device *dev, unsigned command)
  135. {
  136. struct spi_device *spi = to_spi_device(dev);
  137. struct ads7846 *ts = dev_get_drvdata(dev);
  138. struct ser_req *req = kzalloc(sizeof *req, SLAB_KERNEL);
  139. int status;
  140. int sample;
  141. int i;
  142. if (!req)
  143. return -ENOMEM;
  144. INIT_LIST_HEAD(&req->msg.transfers);
  145. /* activate reference, so it has time to settle; */
  146. req->ref_on = REF_ON;
  147. req->xfer[0].tx_buf = &req->ref_on;
  148. req->xfer[0].len = 1;
  149. req->xfer[1].rx_buf = &req->scratch;
  150. req->xfer[1].len = 2;
  151. /*
  152. * for external VREF, 0 usec (and assume it's always on);
  153. * for 1uF, use 800 usec;
  154. * no cap, 100 usec.
  155. */
  156. req->xfer[1].delay_usecs = ts->vref_delay_usecs;
  157. /* take sample */
  158. req->command = (u8) command;
  159. req->xfer[2].tx_buf = &req->command;
  160. req->xfer[2].len = 1;
  161. req->xfer[3].rx_buf = &req->sample;
  162. req->xfer[3].len = 2;
  163. /* REVISIT: take a few more samples, and compare ... */
  164. /* turn off reference */
  165. req->ref_off = REF_OFF;
  166. req->xfer[4].tx_buf = &req->ref_off;
  167. req->xfer[4].len = 1;
  168. req->xfer[5].rx_buf = &req->scratch;
  169. req->xfer[5].len = 2;
  170. CS_CHANGE(req->xfer[5]);
  171. /* group all the transfers together, so we can't interfere with
  172. * reading touchscreen state; disable penirq while sampling
  173. */
  174. for (i = 0; i < 6; i++)
  175. spi_message_add_tail(&req->xfer[i], &req->msg);
  176. disable_irq(spi->irq);
  177. status = spi_sync(spi, &req->msg);
  178. enable_irq(spi->irq);
  179. if (req->msg.status)
  180. status = req->msg.status;
  181. sample = be16_to_cpu(req->sample);
  182. sample = sample >> 4;
  183. kfree(req);
  184. return status ? status : sample;
  185. }
  186. #define SHOW(name) static ssize_t \
  187. name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \
  188. { \
  189. ssize_t v = ads7846_read12_ser(dev, \
  190. READ_12BIT_SER(name) | ADS_PD10_ALL_ON); \
  191. if (v < 0) \
  192. return v; \
  193. return sprintf(buf, "%u\n", (unsigned) v); \
  194. } \
  195. static DEVICE_ATTR(name, S_IRUGO, name ## _show, NULL);
  196. SHOW(temp0)
  197. SHOW(temp1)
  198. SHOW(vaux)
  199. SHOW(vbatt)
  200. static int is_pen_down(struct device *dev)
  201. {
  202. struct ads7846 *ts = dev_get_drvdata(dev);
  203. return ts->pendown;
  204. }
  205. static ssize_t ads7846_pen_down_show(struct device *dev,
  206. struct device_attribute *attr, char *buf)
  207. {
  208. return sprintf(buf, "%u\n", is_pen_down(dev));
  209. }
  210. static DEVICE_ATTR(pen_down, S_IRUGO, ads7846_pen_down_show, NULL);
  211. /*--------------------------------------------------------------------------*/
  212. /*
  213. * PENIRQ only kicks the timer. The timer only reissues the SPI transfer,
  214. * to retrieve touchscreen status.
  215. *
  216. * The SPI transfer completion callback does the real work. It reports
  217. * touchscreen events and reactivates the timer (or IRQ) as appropriate.
  218. */
  219. static void ads7846_rx(void *ads)
  220. {
  221. struct ads7846 *ts = ads;
  222. struct input_dev *input_dev = ts->input;
  223. unsigned Rt;
  224. unsigned sync = 0;
  225. u16 x, y, z1, z2;
  226. unsigned long flags;
  227. /* adjust: 12 bit samples (left aligned), built from
  228. * two 8 bit values writen msb-first.
  229. */
  230. x = be16_to_cpu(ts->tc.x) >> 4;
  231. y = be16_to_cpu(ts->tc.y) >> 4;
  232. z1 = be16_to_cpu(ts->tc.z1) >> 4;
  233. z2 = be16_to_cpu(ts->tc.z2) >> 4;
  234. /* range filtering */
  235. if (x == MAX_12BIT)
  236. x = 0;
  237. if (x && z1 && ts->spi->dev.power.power_state.event == PM_EVENT_ON) {
  238. /* compute touch pressure resistance using equation #2 */
  239. Rt = z2;
  240. Rt -= z1;
  241. Rt *= x;
  242. Rt *= ts->x_plate_ohms;
  243. Rt /= z1;
  244. Rt = (Rt + 2047) >> 12;
  245. } else
  246. Rt = 0;
  247. /* NOTE: "pendown" is inferred from pressure; we don't rely on
  248. * being able to check nPENIRQ status, or "friendly" trigger modes
  249. * (both-edges is much better than just-falling or low-level).
  250. *
  251. * REVISIT: some boards may require reading nPENIRQ; it's
  252. * needed on 7843. and 7845 reads pressure differently...
  253. *
  254. * REVISIT: the touchscreen might not be connected; this code
  255. * won't notice that, even if nPENIRQ never fires ...
  256. */
  257. if (!ts->pendown && Rt != 0) {
  258. input_report_key(input_dev, BTN_TOUCH, 1);
  259. sync = 1;
  260. } else if (ts->pendown && Rt == 0) {
  261. input_report_key(input_dev, BTN_TOUCH, 0);
  262. sync = 1;
  263. }
  264. if (Rt) {
  265. input_report_abs(input_dev, ABS_X, x);
  266. input_report_abs(input_dev, ABS_Y, y);
  267. input_report_abs(input_dev, ABS_PRESSURE, Rt);
  268. sync = 1;
  269. }
  270. if (sync)
  271. input_sync(input_dev);
  272. #ifdef VERBOSE
  273. if (Rt || ts->pendown)
  274. pr_debug("%s: %d/%d/%d%s\n", ts->spi->dev.bus_id,
  275. x, y, Rt, Rt ? "" : " UP");
  276. #endif
  277. /* don't retrigger while we're suspended */
  278. spin_lock_irqsave(&ts->lock, flags);
  279. ts->pendown = (Rt != 0);
  280. ts->pending = 0;
  281. if (ts->spi->dev.power.power_state.event == PM_EVENT_ON) {
  282. if (ts->pendown)
  283. mod_timer(&ts->timer, jiffies + TS_POLL_PERIOD);
  284. else if (ts->irq_disabled) {
  285. ts->irq_disabled = 0;
  286. enable_irq(ts->spi->irq);
  287. }
  288. }
  289. spin_unlock_irqrestore(&ts->lock, flags);
  290. }
  291. static void ads7846_timer(unsigned long handle)
  292. {
  293. struct ads7846 *ts = (void *)handle;
  294. int status = 0;
  295. unsigned long flags;
  296. spin_lock_irqsave(&ts->lock, flags);
  297. if (!ts->pending) {
  298. ts->pending = 1;
  299. if (!ts->irq_disabled) {
  300. ts->irq_disabled = 1;
  301. disable_irq(ts->spi->irq);
  302. }
  303. status = spi_async(ts->spi, &ts->msg);
  304. if (status)
  305. dev_err(&ts->spi->dev, "spi_async --> %d\n",
  306. status);
  307. }
  308. spin_unlock_irqrestore(&ts->lock, flags);
  309. }
  310. static irqreturn_t ads7846_irq(int irq, void *handle, struct pt_regs *regs)
  311. {
  312. ads7846_timer((unsigned long) handle);
  313. return IRQ_HANDLED;
  314. }
  315. /*--------------------------------------------------------------------------*/
  316. static int
  317. ads7846_suspend(struct spi_device *spi, pm_message_t message)
  318. {
  319. struct ads7846 *ts = dev_get_drvdata(&spi->dev);
  320. unsigned long flags;
  321. spin_lock_irqsave(&ts->lock, flags);
  322. spi->dev.power.power_state = message;
  323. /* are we waiting for IRQ, or polling? */
  324. if (!ts->pendown) {
  325. if (!ts->irq_disabled) {
  326. ts->irq_disabled = 1;
  327. disable_irq(ts->spi->irq);
  328. }
  329. } else {
  330. /* polling; force a final SPI completion;
  331. * that will clean things up neatly
  332. */
  333. if (!ts->pending)
  334. mod_timer(&ts->timer, jiffies);
  335. while (ts->pendown || ts->pending) {
  336. spin_unlock_irqrestore(&ts->lock, flags);
  337. udelay(10);
  338. spin_lock_irqsave(&ts->lock, flags);
  339. }
  340. }
  341. /* we know the chip's in lowpower mode since we always
  342. * leave it that way after every request
  343. */
  344. spin_unlock_irqrestore(&ts->lock, flags);
  345. return 0;
  346. }
  347. static int ads7846_resume(struct spi_device *spi)
  348. {
  349. struct ads7846 *ts = dev_get_drvdata(&spi->dev);
  350. ts->irq_disabled = 0;
  351. enable_irq(ts->spi->irq);
  352. spi->dev.power.power_state = PMSG_ON;
  353. return 0;
  354. }
  355. static int __devinit ads7846_probe(struct spi_device *spi)
  356. {
  357. struct ads7846 *ts;
  358. struct input_dev *input_dev;
  359. struct ads7846_platform_data *pdata = spi->dev.platform_data;
  360. struct spi_transfer *x;
  361. int err;
  362. if (!spi->irq) {
  363. dev_dbg(&spi->dev, "no IRQ?\n");
  364. return -ENODEV;
  365. }
  366. if (!pdata) {
  367. dev_dbg(&spi->dev, "no platform data?\n");
  368. return -ENODEV;
  369. }
  370. /* don't exceed max specified sample rate */
  371. if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) {
  372. dev_dbg(&spi->dev, "f(sample) %d KHz?\n",
  373. (spi->max_speed_hz/SAMPLE_BITS)/1000);
  374. return -EINVAL;
  375. }
  376. /* We'd set the wordsize to 12 bits ... except that some controllers
  377. * will then treat the 8 bit command words as 12 bits (and drop the
  378. * four MSBs of the 12 bit result). Result: inputs must be shifted
  379. * to discard the four garbage LSBs.
  380. */
  381. ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL);
  382. input_dev = input_allocate_device();
  383. if (!ts || !input_dev) {
  384. err = -ENOMEM;
  385. goto err_free_mem;
  386. }
  387. dev_set_drvdata(&spi->dev, ts);
  388. spi->dev.power.power_state = PMSG_ON;
  389. ts->spi = spi;
  390. ts->input = input_dev;
  391. init_timer(&ts->timer);
  392. ts->timer.data = (unsigned long) ts;
  393. ts->timer.function = ads7846_timer;
  394. ts->model = pdata->model ? : 7846;
  395. ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100;
  396. ts->x_plate_ohms = pdata->x_plate_ohms ? : 400;
  397. snprintf(ts->phys, sizeof(ts->phys), "%s/input0", spi->dev.bus_id);
  398. input_dev->name = "ADS784x Touchscreen";
  399. input_dev->phys = ts->phys;
  400. input_dev->cdev.dev = &spi->dev;
  401. input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
  402. input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
  403. input_set_abs_params(input_dev, ABS_X,
  404. pdata->x_min ? : 0,
  405. pdata->x_max ? : MAX_12BIT,
  406. 0, 0);
  407. input_set_abs_params(input_dev, ABS_Y,
  408. pdata->y_min ? : 0,
  409. pdata->y_max ? : MAX_12BIT,
  410. 0, 0);
  411. input_set_abs_params(input_dev, ABS_PRESSURE,
  412. pdata->pressure_min, pdata->pressure_max, 0, 0);
  413. /* set up the transfers to read touchscreen state; this assumes we
  414. * use formula #2 for pressure, not #3.
  415. */
  416. INIT_LIST_HEAD(&ts->msg.transfers);
  417. x = ts->xfer;
  418. /* y- still on; turn on only y+ (and ADC) */
  419. ts->read_y = READ_Y;
  420. x->tx_buf = &ts->read_y;
  421. x->len = 1;
  422. spi_message_add_tail(x, &ts->msg);
  423. x++;
  424. x->rx_buf = &ts->tc.y;
  425. x->len = 2;
  426. spi_message_add_tail(x, &ts->msg);
  427. /* turn y+ off, x- on; we'll use formula #2 */
  428. if (ts->model == 7846) {
  429. x++;
  430. ts->read_z1 = READ_Z1;
  431. x->tx_buf = &ts->read_z1;
  432. x->len = 1;
  433. spi_message_add_tail(x, &ts->msg);
  434. x++;
  435. x->rx_buf = &ts->tc.z1;
  436. x->len = 2;
  437. spi_message_add_tail(x, &ts->msg);
  438. x++;
  439. ts->read_z2 = READ_Z2;
  440. x->tx_buf = &ts->read_z2;
  441. x->len = 1;
  442. spi_message_add_tail(x, &ts->msg);
  443. x++;
  444. x->rx_buf = &ts->tc.z2;
  445. x->len = 2;
  446. spi_message_add_tail(x, &ts->msg);
  447. }
  448. /* turn y- off, x+ on, then leave in lowpower */
  449. x++;
  450. ts->read_x = READ_X;
  451. x->tx_buf = &ts->read_x;
  452. x->len = 1;
  453. spi_message_add_tail(x, &ts->msg);
  454. x++;
  455. x->rx_buf = &ts->tc.x;
  456. x->len = 2;
  457. spi_message_add_tail(x, &ts->msg);
  458. /* power down */
  459. x++;
  460. ts->pwrdown = PWRDOWN;
  461. x->tx_buf = &ts->pwrdown;
  462. x->len = 1;
  463. spi_message_add_tail(x, &ts->msg);
  464. x++;
  465. x->rx_buf = &ts->dummy;
  466. x->len = 2;
  467. CS_CHANGE(*x);
  468. spi_message_add_tail(x, &ts->msg);
  469. ts->msg.complete = ads7846_rx;
  470. ts->msg.context = ts;
  471. if (request_irq(spi->irq, ads7846_irq,
  472. SA_SAMPLE_RANDOM | SA_TRIGGER_FALLING,
  473. spi->dev.bus_id, ts)) {
  474. dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
  475. err = -EBUSY;
  476. goto err_free_mem;
  477. }
  478. dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq);
  479. /* take a first sample, leaving nPENIRQ active; avoid
  480. * the touchscreen, in case it's not connected.
  481. */
  482. (void) ads7846_read12_ser(&spi->dev,
  483. READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
  484. /* ads7843/7845 don't have temperature sensors, and
  485. * use the other sensors a bit differently too
  486. */
  487. if (ts->model == 7846) {
  488. device_create_file(&spi->dev, &dev_attr_temp0);
  489. device_create_file(&spi->dev, &dev_attr_temp1);
  490. }
  491. if (ts->model != 7845)
  492. device_create_file(&spi->dev, &dev_attr_vbatt);
  493. device_create_file(&spi->dev, &dev_attr_vaux);
  494. device_create_file(&spi->dev, &dev_attr_pen_down);
  495. err = input_register_device(input_dev);
  496. if (err)
  497. goto err_free_irq;
  498. return 0;
  499. err_free_irq:
  500. free_irq(spi->irq, ts);
  501. err_free_mem:
  502. input_free_device(input_dev);
  503. kfree(ts);
  504. return err;
  505. }
  506. static int __devexit ads7846_remove(struct spi_device *spi)
  507. {
  508. struct ads7846 *ts = dev_get_drvdata(&spi->dev);
  509. ads7846_suspend(spi, PMSG_SUSPEND);
  510. free_irq(ts->spi->irq, ts);
  511. if (ts->irq_disabled)
  512. enable_irq(ts->spi->irq);
  513. device_remove_file(&spi->dev, &dev_attr_pen_down);
  514. if (ts->model == 7846) {
  515. device_remove_file(&spi->dev, &dev_attr_temp0);
  516. device_remove_file(&spi->dev, &dev_attr_temp1);
  517. }
  518. if (ts->model != 7845)
  519. device_remove_file(&spi->dev, &dev_attr_vbatt);
  520. device_remove_file(&spi->dev, &dev_attr_vaux);
  521. input_unregister_device(ts->input);
  522. kfree(ts);
  523. dev_dbg(&spi->dev, "unregistered touchscreen\n");
  524. return 0;
  525. }
  526. static struct spi_driver ads7846_driver = {
  527. .driver = {
  528. .name = "ads7846",
  529. .bus = &spi_bus_type,
  530. .owner = THIS_MODULE,
  531. },
  532. .probe = ads7846_probe,
  533. .remove = __devexit_p(ads7846_remove),
  534. .suspend = ads7846_suspend,
  535. .resume = ads7846_resume,
  536. };
  537. static int __init ads7846_init(void)
  538. {
  539. /* grr, board-specific init should stay out of drivers!! */
  540. #ifdef CONFIG_ARCH_OMAP
  541. if (machine_is_omap_osk()) {
  542. /* GPIO4 = PENIRQ; GPIO6 = BUSY */
  543. omap_request_gpio(4);
  544. omap_set_gpio_direction(4, 1);
  545. omap_request_gpio(6);
  546. omap_set_gpio_direction(6, 1);
  547. }
  548. // also TI 1510 Innovator, bitbanging through FPGA
  549. // also Nokia 770
  550. // also Palm Tungsten T2
  551. #endif
  552. // PXA:
  553. // also Dell Axim X50
  554. // also HP iPaq H191x/H192x/H415x/H435x
  555. // also Intel Lubbock (additional to UCB1400; as temperature sensor)
  556. // also Sharp Zaurus C7xx, C8xx (corgi/sheperd/husky)
  557. // Atmel at91sam9261-EK uses ads7843
  558. // also various AMD Au1x00 devel boards
  559. return spi_register_driver(&ads7846_driver);
  560. }
  561. module_init(ads7846_init);
  562. static void __exit ads7846_exit(void)
  563. {
  564. spi_unregister_driver(&ads7846_driver);
  565. #ifdef CONFIG_ARCH_OMAP
  566. if (machine_is_omap_osk()) {
  567. omap_free_gpio(4);
  568. omap_free_gpio(6);
  569. }
  570. #endif
  571. }
  572. module_exit(ads7846_exit);
  573. MODULE_DESCRIPTION("ADS7846 TouchScreen Driver");
  574. MODULE_LICENSE("GPL");