ad7879.c 16 KB

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