ad7879.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * AD7879/AD7889 based touchscreen and GPIO driver
  3. *
  4. * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. *
  8. * History:
  9. * Copyright (c) 2005 David Brownell
  10. * Copyright (c) 2006 Nokia Corporation
  11. * Various changes: Imre Deak <imre.deak@nokia.com>
  12. *
  13. * Using code from:
  14. * - corgi_ts.c
  15. * Copyright (C) 2004-2005 Richard Purdie
  16. * - omap_ts.[hc], ads7846.h, ts_osk.c
  17. * Copyright (C) 2002 MontaVista Software
  18. * Copyright (C) 2004 Texas Instruments
  19. * Copyright (C) 2005 Dirk Behme
  20. * - ad7877.c
  21. * Copyright (C) 2006-2008 Analog Devices Inc.
  22. */
  23. #include <linux/device.h>
  24. #include <linux/delay.h>
  25. #include <linux/input.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/irq.h>
  28. #include <linux/slab.h>
  29. #include <linux/spi/spi.h>
  30. #include <linux/i2c.h>
  31. #include <linux/gpio.h>
  32. #include <linux/spi/ad7879.h>
  33. #include <linux/module.h>
  34. #include "ad7879.h"
  35. #define AD7879_REG_ZEROS 0
  36. #define AD7879_REG_CTRL1 1
  37. #define AD7879_REG_CTRL2 2
  38. #define AD7879_REG_CTRL3 3
  39. #define AD7879_REG_AUX1HIGH 4
  40. #define AD7879_REG_AUX1LOW 5
  41. #define AD7879_REG_TEMP1HIGH 6
  42. #define AD7879_REG_TEMP1LOW 7
  43. #define AD7879_REG_XPLUS 8
  44. #define AD7879_REG_YPLUS 9
  45. #define AD7879_REG_Z1 10
  46. #define AD7879_REG_Z2 11
  47. #define AD7879_REG_AUXVBAT 12
  48. #define AD7879_REG_TEMP 13
  49. #define AD7879_REG_REVID 14
  50. /* Control REG 1 */
  51. #define AD7879_TMR(x) ((x & 0xFF) << 0)
  52. #define AD7879_ACQ(x) ((x & 0x3) << 8)
  53. #define AD7879_MODE_NOC (0 << 10) /* Do not convert */
  54. #define AD7879_MODE_SCC (1 << 10) /* Single channel conversion */
  55. #define AD7879_MODE_SEQ0 (2 << 10) /* Sequence 0 in Slave Mode */
  56. #define AD7879_MODE_SEQ1 (3 << 10) /* Sequence 1 in Master Mode */
  57. #define AD7879_MODE_INT (1 << 15) /* PENIRQ disabled INT enabled */
  58. /* Control REG 2 */
  59. #define AD7879_FCD(x) ((x & 0x3) << 0)
  60. #define AD7879_RESET (1 << 4)
  61. #define AD7879_MFS(x) ((x & 0x3) << 5)
  62. #define AD7879_AVG(x) ((x & 0x3) << 7)
  63. #define AD7879_SER (1 << 9) /* non-differential */
  64. #define AD7879_DFR (0 << 9) /* differential */
  65. #define AD7879_GPIOPOL (1 << 10)
  66. #define AD7879_GPIODIR (1 << 11)
  67. #define AD7879_GPIO_DATA (1 << 12)
  68. #define AD7879_GPIO_EN (1 << 13)
  69. #define AD7879_PM(x) ((x & 0x3) << 14)
  70. #define AD7879_PM_SHUTDOWN (0)
  71. #define AD7879_PM_DYN (1)
  72. #define AD7879_PM_FULLON (2)
  73. /* Control REG 3 */
  74. #define AD7879_TEMPMASK_BIT (1<<15)
  75. #define AD7879_AUXVBATMASK_BIT (1<<14)
  76. #define AD7879_INTMODE_BIT (1<<13)
  77. #define AD7879_GPIOALERTMASK_BIT (1<<12)
  78. #define AD7879_AUXLOW_BIT (1<<11)
  79. #define AD7879_AUXHIGH_BIT (1<<10)
  80. #define AD7879_TEMPLOW_BIT (1<<9)
  81. #define AD7879_TEMPHIGH_BIT (1<<8)
  82. #define AD7879_YPLUS_BIT (1<<7)
  83. #define AD7879_XPLUS_BIT (1<<6)
  84. #define AD7879_Z1_BIT (1<<5)
  85. #define AD7879_Z2_BIT (1<<4)
  86. #define AD7879_AUX_BIT (1<<3)
  87. #define AD7879_VBAT_BIT (1<<2)
  88. #define AD7879_TEMP_BIT (1<<1)
  89. enum {
  90. AD7879_SEQ_XPOS = 0,
  91. AD7879_SEQ_YPOS = 1,
  92. AD7879_SEQ_Z1 = 2,
  93. AD7879_SEQ_Z2 = 3,
  94. AD7879_NR_SENSE = 4,
  95. };
  96. #define MAX_12BIT ((1<<12)-1)
  97. #define TS_PEN_UP_TIMEOUT msecs_to_jiffies(50)
  98. struct ad7879 {
  99. const struct ad7879_bus_ops *bops;
  100. struct device *dev;
  101. struct input_dev *input;
  102. struct timer_list timer;
  103. #ifdef CONFIG_GPIOLIB
  104. struct gpio_chip gc;
  105. struct mutex mutex;
  106. #endif
  107. unsigned int irq;
  108. bool disabled; /* P: input->mutex */
  109. bool suspended; /* P: input->mutex */
  110. bool swap_xy;
  111. u16 conversion_data[AD7879_NR_SENSE];
  112. char phys[32];
  113. u8 first_conversion_delay;
  114. u8 acquisition_time;
  115. u8 averaging;
  116. u8 pen_down_acc_interval;
  117. u8 median;
  118. u16 x_plate_ohms;
  119. u16 pressure_max;
  120. u16 cmd_crtl1;
  121. u16 cmd_crtl2;
  122. u16 cmd_crtl3;
  123. int x;
  124. int y;
  125. int Rt;
  126. };
  127. static int ad7879_read(struct ad7879 *ts, u8 reg)
  128. {
  129. return ts->bops->read(ts->dev, reg);
  130. }
  131. static int ad7879_multi_read(struct ad7879 *ts, u8 first_reg, u8 count, u16 *buf)
  132. {
  133. return ts->bops->multi_read(ts->dev, first_reg, count, buf);
  134. }
  135. static int ad7879_write(struct ad7879 *ts, u8 reg, u16 val)
  136. {
  137. return ts->bops->write(ts->dev, reg, val);
  138. }
  139. static int ad7879_report(struct ad7879 *ts)
  140. {
  141. struct input_dev *input_dev = ts->input;
  142. unsigned Rt;
  143. u16 x, y, z1, z2;
  144. x = ts->conversion_data[AD7879_SEQ_XPOS] & MAX_12BIT;
  145. y = ts->conversion_data[AD7879_SEQ_YPOS] & MAX_12BIT;
  146. z1 = ts->conversion_data[AD7879_SEQ_Z1] & MAX_12BIT;
  147. z2 = ts->conversion_data[AD7879_SEQ_Z2] & MAX_12BIT;
  148. if (ts->swap_xy)
  149. swap(x, y);
  150. /*
  151. * The samples processed here are already preprocessed by the AD7879.
  152. * The preprocessing function consists of a median and an averaging
  153. * filter. The combination of these two techniques provides a robust
  154. * solution, discarding the spurious noise in the signal and keeping
  155. * only the data of interest. The size of both filters is
  156. * programmable. (dev.platform_data, see linux/spi/ad7879.h) Other
  157. * user-programmable conversion controls include variable acquisition
  158. * time, and first conversion delay. Up to 16 averages can be taken
  159. * per conversion.
  160. */
  161. if (likely(x && z1)) {
  162. /* compute touch pressure resistance using equation #1 */
  163. Rt = (z2 - z1) * x * ts->x_plate_ohms;
  164. Rt /= z1;
  165. Rt = (Rt + 2047) >> 12;
  166. /*
  167. * Sample found inconsistent, pressure is beyond
  168. * the maximum. Don't report it to user space.
  169. */
  170. if (Rt > ts->pressure_max)
  171. return -EINVAL;
  172. /*
  173. * Note that we delay reporting events by one sample.
  174. * This is done to avoid reporting last sample of the
  175. * touch sequence, which may be incomplete if finger
  176. * leaves the surface before last reading is taken.
  177. */
  178. if (timer_pending(&ts->timer)) {
  179. /* Touch continues */
  180. input_report_key(input_dev, BTN_TOUCH, 1);
  181. input_report_abs(input_dev, ABS_X, ts->x);
  182. input_report_abs(input_dev, ABS_Y, ts->y);
  183. input_report_abs(input_dev, ABS_PRESSURE, ts->Rt);
  184. input_sync(input_dev);
  185. }
  186. ts->x = x;
  187. ts->y = y;
  188. ts->Rt = Rt;
  189. return 0;
  190. }
  191. return -EINVAL;
  192. }
  193. static void ad7879_ts_event_release(struct ad7879 *ts)
  194. {
  195. struct input_dev *input_dev = ts->input;
  196. input_report_abs(input_dev, ABS_PRESSURE, 0);
  197. input_report_key(input_dev, BTN_TOUCH, 0);
  198. input_sync(input_dev);
  199. }
  200. static void ad7879_timer(unsigned long handle)
  201. {
  202. struct ad7879 *ts = (void *)handle;
  203. ad7879_ts_event_release(ts);
  204. }
  205. static irqreturn_t ad7879_irq(int irq, void *handle)
  206. {
  207. struct ad7879 *ts = handle;
  208. ad7879_multi_read(ts, AD7879_REG_XPLUS, AD7879_NR_SENSE, ts->conversion_data);
  209. if (!ad7879_report(ts))
  210. mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT);
  211. return IRQ_HANDLED;
  212. }
  213. static void __ad7879_enable(struct ad7879 *ts)
  214. {
  215. ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2);
  216. ad7879_write(ts, AD7879_REG_CTRL3, ts->cmd_crtl3);
  217. ad7879_write(ts, AD7879_REG_CTRL1, ts->cmd_crtl1);
  218. enable_irq(ts->irq);
  219. }
  220. static void __ad7879_disable(struct ad7879 *ts)
  221. {
  222. u16 reg = (ts->cmd_crtl2 & ~AD7879_PM(-1)) |
  223. AD7879_PM(AD7879_PM_SHUTDOWN);
  224. disable_irq(ts->irq);
  225. if (del_timer_sync(&ts->timer))
  226. ad7879_ts_event_release(ts);
  227. ad7879_write(ts, AD7879_REG_CTRL2, reg);
  228. }
  229. static int ad7879_open(struct input_dev *input)
  230. {
  231. struct ad7879 *ts = input_get_drvdata(input);
  232. /* protected by input->mutex */
  233. if (!ts->disabled && !ts->suspended)
  234. __ad7879_enable(ts);
  235. return 0;
  236. }
  237. static void ad7879_close(struct input_dev* input)
  238. {
  239. struct ad7879 *ts = input_get_drvdata(input);
  240. /* protected by input->mutex */
  241. if (!ts->disabled && !ts->suspended)
  242. __ad7879_disable(ts);
  243. }
  244. static int __maybe_unused ad7879_suspend(struct device *dev)
  245. {
  246. struct ad7879 *ts = dev_get_drvdata(dev);
  247. mutex_lock(&ts->input->mutex);
  248. if (!ts->suspended && !ts->disabled && ts->input->users)
  249. __ad7879_disable(ts);
  250. ts->suspended = true;
  251. mutex_unlock(&ts->input->mutex);
  252. return 0;
  253. }
  254. static int __maybe_unused ad7879_resume(struct device *dev)
  255. {
  256. struct ad7879 *ts = dev_get_drvdata(dev);
  257. mutex_lock(&ts->input->mutex);
  258. if (ts->suspended && !ts->disabled && ts->input->users)
  259. __ad7879_enable(ts);
  260. ts->suspended = false;
  261. mutex_unlock(&ts->input->mutex);
  262. return 0;
  263. }
  264. SIMPLE_DEV_PM_OPS(ad7879_pm_ops, ad7879_suspend, ad7879_resume);
  265. EXPORT_SYMBOL(ad7879_pm_ops);
  266. static void ad7879_toggle(struct ad7879 *ts, bool disable)
  267. {
  268. mutex_lock(&ts->input->mutex);
  269. if (!ts->suspended && ts->input->users != 0) {
  270. if (disable) {
  271. if (ts->disabled)
  272. __ad7879_enable(ts);
  273. } else {
  274. if (!ts->disabled)
  275. __ad7879_disable(ts);
  276. }
  277. }
  278. ts->disabled = disable;
  279. mutex_unlock(&ts->input->mutex);
  280. }
  281. static ssize_t ad7879_disable_show(struct device *dev,
  282. struct device_attribute *attr, char *buf)
  283. {
  284. struct ad7879 *ts = dev_get_drvdata(dev);
  285. return sprintf(buf, "%u\n", ts->disabled);
  286. }
  287. static ssize_t ad7879_disable_store(struct device *dev,
  288. struct device_attribute *attr,
  289. const char *buf, size_t count)
  290. {
  291. struct ad7879 *ts = dev_get_drvdata(dev);
  292. unsigned int val;
  293. int error;
  294. error = kstrtouint(buf, 10, &val);
  295. if (error)
  296. return error;
  297. ad7879_toggle(ts, val);
  298. return count;
  299. }
  300. static DEVICE_ATTR(disable, 0664, ad7879_disable_show, ad7879_disable_store);
  301. static struct attribute *ad7879_attributes[] = {
  302. &dev_attr_disable.attr,
  303. NULL
  304. };
  305. static const struct attribute_group ad7879_attr_group = {
  306. .attrs = ad7879_attributes,
  307. };
  308. #ifdef CONFIG_GPIOLIB
  309. static int ad7879_gpio_direction_input(struct gpio_chip *chip,
  310. unsigned gpio)
  311. {
  312. struct ad7879 *ts = container_of(chip, struct ad7879, gc);
  313. int err;
  314. mutex_lock(&ts->mutex);
  315. ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIODIR | AD7879_GPIOPOL;
  316. err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2);
  317. mutex_unlock(&ts->mutex);
  318. return err;
  319. }
  320. static int ad7879_gpio_direction_output(struct gpio_chip *chip,
  321. unsigned gpio, int level)
  322. {
  323. struct ad7879 *ts = container_of(chip, struct ad7879, gc);
  324. int err;
  325. mutex_lock(&ts->mutex);
  326. ts->cmd_crtl2 &= ~AD7879_GPIODIR;
  327. ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIOPOL;
  328. if (level)
  329. ts->cmd_crtl2 |= AD7879_GPIO_DATA;
  330. else
  331. ts->cmd_crtl2 &= ~AD7879_GPIO_DATA;
  332. err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2);
  333. mutex_unlock(&ts->mutex);
  334. return err;
  335. }
  336. static int ad7879_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
  337. {
  338. struct ad7879 *ts = container_of(chip, struct ad7879, gc);
  339. u16 val;
  340. mutex_lock(&ts->mutex);
  341. val = ad7879_read(ts, AD7879_REG_CTRL2);
  342. mutex_unlock(&ts->mutex);
  343. return !!(val & AD7879_GPIO_DATA);
  344. }
  345. static void ad7879_gpio_set_value(struct gpio_chip *chip,
  346. unsigned gpio, int value)
  347. {
  348. struct ad7879 *ts = container_of(chip, struct ad7879, gc);
  349. mutex_lock(&ts->mutex);
  350. if (value)
  351. ts->cmd_crtl2 |= AD7879_GPIO_DATA;
  352. else
  353. ts->cmd_crtl2 &= ~AD7879_GPIO_DATA;
  354. ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2);
  355. mutex_unlock(&ts->mutex);
  356. }
  357. static int ad7879_gpio_add(struct ad7879 *ts,
  358. const struct ad7879_platform_data *pdata)
  359. {
  360. int ret = 0;
  361. mutex_init(&ts->mutex);
  362. if (pdata->gpio_export) {
  363. ts->gc.direction_input = ad7879_gpio_direction_input;
  364. ts->gc.direction_output = ad7879_gpio_direction_output;
  365. ts->gc.get = ad7879_gpio_get_value;
  366. ts->gc.set = ad7879_gpio_set_value;
  367. ts->gc.can_sleep = 1;
  368. ts->gc.base = pdata->gpio_base;
  369. ts->gc.ngpio = 1;
  370. ts->gc.label = "AD7879-GPIO";
  371. ts->gc.owner = THIS_MODULE;
  372. ts->gc.dev = ts->dev;
  373. ret = gpiochip_add(&ts->gc);
  374. if (ret)
  375. dev_err(ts->dev, "failed to register gpio %d\n",
  376. ts->gc.base);
  377. }
  378. return ret;
  379. }
  380. static void ad7879_gpio_remove(struct ad7879 *ts)
  381. {
  382. const struct ad7879_platform_data *pdata = dev_get_platdata(ts->dev);
  383. if (pdata->gpio_export)
  384. gpiochip_remove(&ts->gc);
  385. }
  386. #else
  387. static inline int ad7879_gpio_add(struct ad7879 *ts,
  388. const struct ad7879_platform_data *pdata)
  389. {
  390. return 0;
  391. }
  392. static inline void ad7879_gpio_remove(struct ad7879 *ts)
  393. {
  394. }
  395. #endif
  396. struct ad7879 *ad7879_probe(struct device *dev, u8 devid, unsigned int irq,
  397. const struct ad7879_bus_ops *bops)
  398. {
  399. struct ad7879_platform_data *pdata = dev_get_platdata(dev);
  400. struct ad7879 *ts;
  401. struct input_dev *input_dev;
  402. int err;
  403. u16 revid;
  404. if (!irq) {
  405. dev_err(dev, "no IRQ?\n");
  406. err = -EINVAL;
  407. goto err_out;
  408. }
  409. if (!pdata) {
  410. dev_err(dev, "no platform data?\n");
  411. err = -EINVAL;
  412. goto err_out;
  413. }
  414. ts = kzalloc(sizeof(*ts), GFP_KERNEL);
  415. input_dev = input_allocate_device();
  416. if (!ts || !input_dev) {
  417. err = -ENOMEM;
  418. goto err_free_mem;
  419. }
  420. ts->bops = bops;
  421. ts->dev = dev;
  422. ts->input = input_dev;
  423. ts->irq = irq;
  424. ts->swap_xy = pdata->swap_xy;
  425. setup_timer(&ts->timer, ad7879_timer, (unsigned long) ts);
  426. ts->x_plate_ohms = pdata->x_plate_ohms ? : 400;
  427. ts->pressure_max = pdata->pressure_max ? : ~0;
  428. ts->first_conversion_delay = pdata->first_conversion_delay;
  429. ts->acquisition_time = pdata->acquisition_time;
  430. ts->averaging = pdata->averaging;
  431. ts->pen_down_acc_interval = pdata->pen_down_acc_interval;
  432. ts->median = pdata->median;
  433. snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev));
  434. input_dev->name = "AD7879 Touchscreen";
  435. input_dev->phys = ts->phys;
  436. input_dev->dev.parent = dev;
  437. input_dev->id.bustype = bops->bustype;
  438. input_dev->open = ad7879_open;
  439. input_dev->close = ad7879_close;
  440. input_set_drvdata(input_dev, ts);
  441. __set_bit(EV_ABS, input_dev->evbit);
  442. __set_bit(ABS_X, input_dev->absbit);
  443. __set_bit(ABS_Y, input_dev->absbit);
  444. __set_bit(ABS_PRESSURE, input_dev->absbit);
  445. __set_bit(EV_KEY, input_dev->evbit);
  446. __set_bit(BTN_TOUCH, input_dev->keybit);
  447. input_set_abs_params(input_dev, ABS_X,
  448. pdata->x_min ? : 0,
  449. pdata->x_max ? : MAX_12BIT,
  450. 0, 0);
  451. input_set_abs_params(input_dev, ABS_Y,
  452. pdata->y_min ? : 0,
  453. pdata->y_max ? : MAX_12BIT,
  454. 0, 0);
  455. input_set_abs_params(input_dev, ABS_PRESSURE,
  456. pdata->pressure_min, pdata->pressure_max, 0, 0);
  457. err = ad7879_write(ts, AD7879_REG_CTRL2, AD7879_RESET);
  458. if (err < 0) {
  459. dev_err(dev, "Failed to write %s\n", input_dev->name);
  460. goto err_free_mem;
  461. }
  462. revid = ad7879_read(ts, AD7879_REG_REVID);
  463. input_dev->id.product = (revid & 0xff);
  464. input_dev->id.version = revid >> 8;
  465. if (input_dev->id.product != devid) {
  466. dev_err(dev, "Failed to probe %s (%x vs %x)\n",
  467. input_dev->name, devid, revid);
  468. err = -ENODEV;
  469. goto err_free_mem;
  470. }
  471. ts->cmd_crtl3 = AD7879_YPLUS_BIT |
  472. AD7879_XPLUS_BIT |
  473. AD7879_Z2_BIT |
  474. AD7879_Z1_BIT |
  475. AD7879_TEMPMASK_BIT |
  476. AD7879_AUXVBATMASK_BIT |
  477. AD7879_GPIOALERTMASK_BIT;
  478. ts->cmd_crtl2 = AD7879_PM(AD7879_PM_DYN) | AD7879_DFR |
  479. AD7879_AVG(ts->averaging) |
  480. AD7879_MFS(ts->median) |
  481. AD7879_FCD(ts->first_conversion_delay);
  482. ts->cmd_crtl1 = AD7879_MODE_INT | AD7879_MODE_SEQ1 |
  483. AD7879_ACQ(ts->acquisition_time) |
  484. AD7879_TMR(ts->pen_down_acc_interval);
  485. err = request_threaded_irq(ts->irq, NULL, ad7879_irq,
  486. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  487. dev_name(dev), ts);
  488. if (err) {
  489. dev_err(dev, "irq %d busy?\n", ts->irq);
  490. goto err_free_mem;
  491. }
  492. __ad7879_disable(ts);
  493. err = sysfs_create_group(&dev->kobj, &ad7879_attr_group);
  494. if (err)
  495. goto err_free_irq;
  496. err = ad7879_gpio_add(ts, pdata);
  497. if (err)
  498. goto err_remove_attr;
  499. err = input_register_device(input_dev);
  500. if (err)
  501. goto err_remove_gpio;
  502. return ts;
  503. err_remove_gpio:
  504. ad7879_gpio_remove(ts);
  505. err_remove_attr:
  506. sysfs_remove_group(&dev->kobj, &ad7879_attr_group);
  507. err_free_irq:
  508. free_irq(ts->irq, ts);
  509. err_free_mem:
  510. input_free_device(input_dev);
  511. kfree(ts);
  512. err_out:
  513. return ERR_PTR(err);
  514. }
  515. EXPORT_SYMBOL(ad7879_probe);
  516. void ad7879_remove(struct ad7879 *ts)
  517. {
  518. ad7879_gpio_remove(ts);
  519. sysfs_remove_group(&ts->dev->kobj, &ad7879_attr_group);
  520. free_irq(ts->irq, ts);
  521. input_unregister_device(ts->input);
  522. kfree(ts);
  523. }
  524. EXPORT_SYMBOL(ad7879_remove);
  525. MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
  526. MODULE_DESCRIPTION("AD7879(-1) touchscreen Driver");
  527. MODULE_LICENSE("GPL");