tsc200x-core.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * TSC2004/TSC2005 touchscreen driver core
  3. *
  4. * Copyright (C) 2006-2010 Nokia Corporation
  5. * Copyright (C) 2015 QWERTY Embedded Design
  6. * Copyright (C) 2015 EMAC Inc.
  7. *
  8. * Author: Lauri Leukkunen <lauri.leukkunen@nokia.com>
  9. * based on TSC2301 driver by Klaus K. Pedersen <klaus.k.pedersen@nokia.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/input.h>
  24. #include <linux/input/touchscreen.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/delay.h>
  27. #include <linux/pm.h>
  28. #include <linux/of.h>
  29. #include <linux/spi/tsc2005.h>
  30. #include <linux/regulator/consumer.h>
  31. #include <linux/regmap.h>
  32. #include <linux/gpio/consumer.h>
  33. #include "tsc200x-core.h"
  34. /*
  35. * The touchscreen interface operates as follows:
  36. *
  37. * 1) Pen is pressed against the touchscreen.
  38. * 2) TSC200X performs AD conversion.
  39. * 3) After the conversion is done TSC200X drives DAV line down.
  40. * 4) GPIO IRQ is received and tsc200x_irq_thread() is scheduled.
  41. * 5) tsc200x_irq_thread() queues up a transfer to fetch the x, y, z1, z2
  42. * values.
  43. * 6) tsc200x_irq_thread() reports coordinates to input layer and sets up
  44. * tsc200x_penup_timer() to be called after TSC200X_PENUP_TIME_MS (40ms).
  45. * 7) When the penup timer expires, there have not been touch or DAV interrupts
  46. * during the last 40ms which means the pen has been lifted.
  47. *
  48. * ESD recovery via a hardware reset is done if the TSC200X doesn't respond
  49. * after a configurable period (in ms) of activity. If esd_timeout is 0, the
  50. * watchdog is disabled.
  51. */
  52. static const struct regmap_range tsc200x_writable_ranges[] = {
  53. regmap_reg_range(TSC200X_REG_AUX_HIGH, TSC200X_REG_CFR2),
  54. };
  55. static const struct regmap_access_table tsc200x_writable_table = {
  56. .yes_ranges = tsc200x_writable_ranges,
  57. .n_yes_ranges = ARRAY_SIZE(tsc200x_writable_ranges),
  58. };
  59. const struct regmap_config tsc200x_regmap_config = {
  60. .reg_bits = 8,
  61. .val_bits = 16,
  62. .reg_stride = 0x08,
  63. .max_register = 0x78,
  64. .read_flag_mask = TSC200X_REG_READ,
  65. .write_flag_mask = TSC200X_REG_PND0,
  66. .wr_table = &tsc200x_writable_table,
  67. .use_single_rw = true,
  68. };
  69. EXPORT_SYMBOL_GPL(tsc200x_regmap_config);
  70. struct tsc200x_data {
  71. u16 x;
  72. u16 y;
  73. u16 z1;
  74. u16 z2;
  75. } __packed;
  76. #define TSC200X_DATA_REGS 4
  77. struct tsc200x {
  78. struct device *dev;
  79. struct regmap *regmap;
  80. __u16 bustype;
  81. struct input_dev *idev;
  82. char phys[32];
  83. struct mutex mutex;
  84. /* raw copy of previous x,y,z */
  85. int in_x;
  86. int in_y;
  87. int in_z1;
  88. int in_z2;
  89. spinlock_t lock;
  90. struct timer_list penup_timer;
  91. unsigned int esd_timeout;
  92. struct delayed_work esd_work;
  93. unsigned long last_valid_interrupt;
  94. unsigned int x_plate_ohm;
  95. bool opened;
  96. bool suspended;
  97. bool pen_down;
  98. struct regulator *vio;
  99. struct gpio_desc *reset_gpio;
  100. void (*set_reset)(bool enable);
  101. int (*tsc200x_cmd)(struct device *dev, u8 cmd);
  102. int irq;
  103. };
  104. static void tsc200x_update_pen_state(struct tsc200x *ts,
  105. int x, int y, int pressure)
  106. {
  107. if (pressure) {
  108. input_report_abs(ts->idev, ABS_X, x);
  109. input_report_abs(ts->idev, ABS_Y, y);
  110. input_report_abs(ts->idev, ABS_PRESSURE, pressure);
  111. if (!ts->pen_down) {
  112. input_report_key(ts->idev, BTN_TOUCH, !!pressure);
  113. ts->pen_down = true;
  114. }
  115. } else {
  116. input_report_abs(ts->idev, ABS_PRESSURE, 0);
  117. if (ts->pen_down) {
  118. input_report_key(ts->idev, BTN_TOUCH, 0);
  119. ts->pen_down = false;
  120. }
  121. }
  122. input_sync(ts->idev);
  123. dev_dbg(ts->dev, "point(%4d,%4d), pressure (%4d)\n", x, y,
  124. pressure);
  125. }
  126. static irqreturn_t tsc200x_irq_thread(int irq, void *_ts)
  127. {
  128. struct tsc200x *ts = _ts;
  129. unsigned long flags;
  130. unsigned int pressure;
  131. struct tsc200x_data tsdata;
  132. int error;
  133. /* read the coordinates */
  134. error = regmap_bulk_read(ts->regmap, TSC200X_REG_X, &tsdata,
  135. TSC200X_DATA_REGS);
  136. if (unlikely(error))
  137. goto out;
  138. /* validate position */
  139. if (unlikely(tsdata.x > MAX_12BIT || tsdata.y > MAX_12BIT))
  140. goto out;
  141. /* Skip reading if the pressure components are out of range */
  142. if (unlikely(tsdata.z1 == 0 || tsdata.z2 > MAX_12BIT))
  143. goto out;
  144. if (unlikely(tsdata.z1 >= tsdata.z2))
  145. goto out;
  146. /*
  147. * Skip point if this is a pen down with the exact same values as
  148. * the value before pen-up - that implies SPI fed us stale data
  149. */
  150. if (!ts->pen_down &&
  151. ts->in_x == tsdata.x && ts->in_y == tsdata.y &&
  152. ts->in_z1 == tsdata.z1 && ts->in_z2 == tsdata.z2) {
  153. goto out;
  154. }
  155. /*
  156. * At this point we are happy we have a valid and useful reading.
  157. * Remember it for later comparisons. We may now begin downsampling.
  158. */
  159. ts->in_x = tsdata.x;
  160. ts->in_y = tsdata.y;
  161. ts->in_z1 = tsdata.z1;
  162. ts->in_z2 = tsdata.z2;
  163. /* Compute touch pressure resistance using equation #1 */
  164. pressure = tsdata.x * (tsdata.z2 - tsdata.z1) / tsdata.z1;
  165. pressure = pressure * ts->x_plate_ohm / 4096;
  166. if (unlikely(pressure > MAX_12BIT))
  167. goto out;
  168. spin_lock_irqsave(&ts->lock, flags);
  169. tsc200x_update_pen_state(ts, tsdata.x, tsdata.y, pressure);
  170. mod_timer(&ts->penup_timer,
  171. jiffies + msecs_to_jiffies(TSC200X_PENUP_TIME_MS));
  172. spin_unlock_irqrestore(&ts->lock, flags);
  173. ts->last_valid_interrupt = jiffies;
  174. out:
  175. return IRQ_HANDLED;
  176. }
  177. static void tsc200x_penup_timer(unsigned long data)
  178. {
  179. struct tsc200x *ts = (struct tsc200x *)data;
  180. unsigned long flags;
  181. spin_lock_irqsave(&ts->lock, flags);
  182. tsc200x_update_pen_state(ts, 0, 0, 0);
  183. spin_unlock_irqrestore(&ts->lock, flags);
  184. }
  185. static void tsc200x_start_scan(struct tsc200x *ts)
  186. {
  187. regmap_write(ts->regmap, TSC200X_REG_CFR0, TSC200X_CFR0_INITVALUE);
  188. regmap_write(ts->regmap, TSC200X_REG_CFR1, TSC200X_CFR1_INITVALUE);
  189. regmap_write(ts->regmap, TSC200X_REG_CFR2, TSC200X_CFR2_INITVALUE);
  190. ts->tsc200x_cmd(ts->dev, TSC200X_CMD_NORMAL);
  191. }
  192. static void tsc200x_stop_scan(struct tsc200x *ts)
  193. {
  194. ts->tsc200x_cmd(ts->dev, TSC200X_CMD_STOP);
  195. }
  196. static void tsc200x_set_reset(struct tsc200x *ts, bool enable)
  197. {
  198. if (ts->reset_gpio)
  199. gpiod_set_value_cansleep(ts->reset_gpio, enable);
  200. else if (ts->set_reset)
  201. ts->set_reset(enable);
  202. }
  203. /* must be called with ts->mutex held */
  204. static void __tsc200x_disable(struct tsc200x *ts)
  205. {
  206. tsc200x_stop_scan(ts);
  207. disable_irq(ts->irq);
  208. del_timer_sync(&ts->penup_timer);
  209. cancel_delayed_work_sync(&ts->esd_work);
  210. enable_irq(ts->irq);
  211. }
  212. /* must be called with ts->mutex held */
  213. static void __tsc200x_enable(struct tsc200x *ts)
  214. {
  215. tsc200x_start_scan(ts);
  216. if (ts->esd_timeout && (ts->set_reset || ts->reset_gpio)) {
  217. ts->last_valid_interrupt = jiffies;
  218. schedule_delayed_work(&ts->esd_work,
  219. round_jiffies_relative(
  220. msecs_to_jiffies(ts->esd_timeout)));
  221. }
  222. }
  223. static ssize_t tsc200x_selftest_show(struct device *dev,
  224. struct device_attribute *attr,
  225. char *buf)
  226. {
  227. struct tsc200x *ts = dev_get_drvdata(dev);
  228. unsigned int temp_high;
  229. unsigned int temp_high_orig;
  230. unsigned int temp_high_test;
  231. bool success = true;
  232. int error;
  233. mutex_lock(&ts->mutex);
  234. /*
  235. * Test TSC200X communications via temp high register.
  236. */
  237. __tsc200x_disable(ts);
  238. error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high_orig);
  239. if (error) {
  240. dev_warn(dev, "selftest failed: read error %d\n", error);
  241. success = false;
  242. goto out;
  243. }
  244. temp_high_test = (temp_high_orig - 1) & MAX_12BIT;
  245. error = regmap_write(ts->regmap, TSC200X_REG_TEMP_HIGH, temp_high_test);
  246. if (error) {
  247. dev_warn(dev, "selftest failed: write error %d\n", error);
  248. success = false;
  249. goto out;
  250. }
  251. error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high);
  252. if (error) {
  253. dev_warn(dev, "selftest failed: read error %d after write\n",
  254. error);
  255. success = false;
  256. goto out;
  257. }
  258. if (temp_high != temp_high_test) {
  259. dev_warn(dev, "selftest failed: %d != %d\n",
  260. temp_high, temp_high_test);
  261. success = false;
  262. }
  263. /* hardware reset */
  264. tsc200x_set_reset(ts, false);
  265. usleep_range(100, 500); /* only 10us required */
  266. tsc200x_set_reset(ts, true);
  267. if (!success)
  268. goto out;
  269. /* test that the reset really happened */
  270. error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high);
  271. if (error) {
  272. dev_warn(dev, "selftest failed: read error %d after reset\n",
  273. error);
  274. success = false;
  275. goto out;
  276. }
  277. if (temp_high != temp_high_orig) {
  278. dev_warn(dev, "selftest failed after reset: %d != %d\n",
  279. temp_high, temp_high_orig);
  280. success = false;
  281. }
  282. out:
  283. __tsc200x_enable(ts);
  284. mutex_unlock(&ts->mutex);
  285. return sprintf(buf, "%d\n", success);
  286. }
  287. static DEVICE_ATTR(selftest, S_IRUGO, tsc200x_selftest_show, NULL);
  288. static struct attribute *tsc200x_attrs[] = {
  289. &dev_attr_selftest.attr,
  290. NULL
  291. };
  292. static umode_t tsc200x_attr_is_visible(struct kobject *kobj,
  293. struct attribute *attr, int n)
  294. {
  295. struct device *dev = container_of(kobj, struct device, kobj);
  296. struct tsc200x *ts = dev_get_drvdata(dev);
  297. umode_t mode = attr->mode;
  298. if (attr == &dev_attr_selftest.attr) {
  299. if (!ts->set_reset && !ts->reset_gpio)
  300. mode = 0;
  301. }
  302. return mode;
  303. }
  304. static const struct attribute_group tsc200x_attr_group = {
  305. .is_visible = tsc200x_attr_is_visible,
  306. .attrs = tsc200x_attrs,
  307. };
  308. static void tsc200x_esd_work(struct work_struct *work)
  309. {
  310. struct tsc200x *ts = container_of(work, struct tsc200x, esd_work.work);
  311. int error;
  312. unsigned int r;
  313. if (!mutex_trylock(&ts->mutex)) {
  314. /*
  315. * If the mutex is taken, it means that disable or enable is in
  316. * progress. In that case just reschedule the work. If the work
  317. * is not needed, it will be canceled by disable.
  318. */
  319. goto reschedule;
  320. }
  321. if (time_is_after_jiffies(ts->last_valid_interrupt +
  322. msecs_to_jiffies(ts->esd_timeout)))
  323. goto out;
  324. /* We should be able to read register without disabling interrupts. */
  325. error = regmap_read(ts->regmap, TSC200X_REG_CFR0, &r);
  326. if (!error &&
  327. !((r ^ TSC200X_CFR0_INITVALUE) & TSC200X_CFR0_RW_MASK)) {
  328. goto out;
  329. }
  330. /*
  331. * If we could not read our known value from configuration register 0
  332. * then we should reset the controller as if from power-up and start
  333. * scanning again.
  334. */
  335. dev_info(ts->dev, "TSC200X not responding - resetting\n");
  336. disable_irq(ts->irq);
  337. del_timer_sync(&ts->penup_timer);
  338. tsc200x_update_pen_state(ts, 0, 0, 0);
  339. tsc200x_set_reset(ts, false);
  340. usleep_range(100, 500); /* only 10us required */
  341. tsc200x_set_reset(ts, true);
  342. enable_irq(ts->irq);
  343. tsc200x_start_scan(ts);
  344. out:
  345. mutex_unlock(&ts->mutex);
  346. reschedule:
  347. /* re-arm the watchdog */
  348. schedule_delayed_work(&ts->esd_work,
  349. round_jiffies_relative(
  350. msecs_to_jiffies(ts->esd_timeout)));
  351. }
  352. static int tsc200x_open(struct input_dev *input)
  353. {
  354. struct tsc200x *ts = input_get_drvdata(input);
  355. mutex_lock(&ts->mutex);
  356. if (!ts->suspended)
  357. __tsc200x_enable(ts);
  358. ts->opened = true;
  359. mutex_unlock(&ts->mutex);
  360. return 0;
  361. }
  362. static void tsc200x_close(struct input_dev *input)
  363. {
  364. struct tsc200x *ts = input_get_drvdata(input);
  365. mutex_lock(&ts->mutex);
  366. if (!ts->suspended)
  367. __tsc200x_disable(ts);
  368. ts->opened = false;
  369. mutex_unlock(&ts->mutex);
  370. }
  371. int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id,
  372. struct regmap *regmap,
  373. int (*tsc200x_cmd)(struct device *dev, u8 cmd))
  374. {
  375. const struct tsc2005_platform_data *pdata = dev_get_platdata(dev);
  376. struct device_node *np = dev->of_node;
  377. struct tsc200x *ts;
  378. struct input_dev *input_dev;
  379. unsigned int max_x = MAX_12BIT;
  380. unsigned int max_y = MAX_12BIT;
  381. unsigned int max_p = MAX_12BIT;
  382. unsigned int fudge_x = TSC200X_DEF_X_FUZZ;
  383. unsigned int fudge_y = TSC200X_DEF_Y_FUZZ;
  384. unsigned int fudge_p = TSC200X_DEF_P_FUZZ;
  385. unsigned int x_plate_ohm = TSC200X_DEF_RESISTOR;
  386. unsigned int esd_timeout;
  387. int error;
  388. if (!np && !pdata) {
  389. dev_err(dev, "no platform data\n");
  390. return -ENODEV;
  391. }
  392. if (irq <= 0) {
  393. dev_err(dev, "no irq\n");
  394. return -ENODEV;
  395. }
  396. if (IS_ERR(regmap))
  397. return PTR_ERR(regmap);
  398. if (!tsc200x_cmd) {
  399. dev_err(dev, "no cmd function\n");
  400. return -ENODEV;
  401. }
  402. if (pdata) {
  403. fudge_x = pdata->ts_x_fudge;
  404. fudge_y = pdata->ts_y_fudge;
  405. fudge_p = pdata->ts_pressure_fudge;
  406. max_x = pdata->ts_x_max;
  407. max_y = pdata->ts_y_max;
  408. max_p = pdata->ts_pressure_max;
  409. x_plate_ohm = pdata->ts_x_plate_ohm;
  410. esd_timeout = pdata->esd_timeout_ms;
  411. } else {
  412. x_plate_ohm = TSC200X_DEF_RESISTOR;
  413. of_property_read_u32(np, "ti,x-plate-ohms", &x_plate_ohm);
  414. esd_timeout = 0;
  415. of_property_read_u32(np, "ti,esd-recovery-timeout-ms",
  416. &esd_timeout);
  417. }
  418. ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL);
  419. if (!ts)
  420. return -ENOMEM;
  421. input_dev = devm_input_allocate_device(dev);
  422. if (!input_dev)
  423. return -ENOMEM;
  424. ts->irq = irq;
  425. ts->dev = dev;
  426. ts->idev = input_dev;
  427. ts->regmap = regmap;
  428. ts->tsc200x_cmd = tsc200x_cmd;
  429. ts->x_plate_ohm = x_plate_ohm;
  430. ts->esd_timeout = esd_timeout;
  431. ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
  432. if (IS_ERR(ts->reset_gpio)) {
  433. error = PTR_ERR(ts->reset_gpio);
  434. dev_err(dev, "error acquiring reset gpio: %d\n", error);
  435. return error;
  436. }
  437. ts->vio = devm_regulator_get_optional(dev, "vio");
  438. if (IS_ERR(ts->vio)) {
  439. error = PTR_ERR(ts->vio);
  440. dev_err(dev, "vio regulator missing (%d)", error);
  441. return error;
  442. }
  443. if (!ts->reset_gpio && pdata)
  444. ts->set_reset = pdata->set_reset;
  445. mutex_init(&ts->mutex);
  446. spin_lock_init(&ts->lock);
  447. setup_timer(&ts->penup_timer, tsc200x_penup_timer, (unsigned long)ts);
  448. INIT_DELAYED_WORK(&ts->esd_work, tsc200x_esd_work);
  449. snprintf(ts->phys, sizeof(ts->phys),
  450. "%s/input-ts", dev_name(dev));
  451. if (tsc_id->product == 2004) {
  452. input_dev->name = "TSC200X touchscreen";
  453. } else {
  454. input_dev->name = devm_kasprintf(dev, GFP_KERNEL,
  455. "TSC%04d touchscreen",
  456. tsc_id->product);
  457. if (!input_dev->name)
  458. return -ENOMEM;
  459. }
  460. input_dev->phys = ts->phys;
  461. input_dev->id = *tsc_id;
  462. input_dev->dev.parent = dev;
  463. input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
  464. input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
  465. input_set_abs_params(input_dev, ABS_X, 0, max_x, fudge_x, 0);
  466. input_set_abs_params(input_dev, ABS_Y, 0, max_y, fudge_y, 0);
  467. input_set_abs_params(input_dev, ABS_PRESSURE, 0, max_p, fudge_p, 0);
  468. if (np)
  469. touchscreen_parse_properties(input_dev, false);
  470. input_dev->open = tsc200x_open;
  471. input_dev->close = tsc200x_close;
  472. input_set_drvdata(input_dev, ts);
  473. /* Ensure the touchscreen is off */
  474. tsc200x_stop_scan(ts);
  475. error = devm_request_threaded_irq(dev, irq, NULL,
  476. tsc200x_irq_thread,
  477. IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  478. "tsc200x", ts);
  479. if (error) {
  480. dev_err(dev, "Failed to request irq, err: %d\n", error);
  481. return error;
  482. }
  483. /* enable regulator for DT */
  484. if (ts->vio) {
  485. error = regulator_enable(ts->vio);
  486. if (error)
  487. return error;
  488. }
  489. dev_set_drvdata(dev, ts);
  490. error = sysfs_create_group(&dev->kobj, &tsc200x_attr_group);
  491. if (error) {
  492. dev_err(dev,
  493. "Failed to create sysfs attributes, err: %d\n", error);
  494. goto disable_regulator;
  495. }
  496. error = input_register_device(ts->idev);
  497. if (error) {
  498. dev_err(dev,
  499. "Failed to register input device, err: %d\n", error);
  500. goto err_remove_sysfs;
  501. }
  502. irq_set_irq_wake(irq, 1);
  503. return 0;
  504. err_remove_sysfs:
  505. sysfs_remove_group(&dev->kobj, &tsc200x_attr_group);
  506. disable_regulator:
  507. if (ts->vio)
  508. regulator_disable(ts->vio);
  509. return error;
  510. }
  511. EXPORT_SYMBOL_GPL(tsc200x_probe);
  512. int tsc200x_remove(struct device *dev)
  513. {
  514. struct tsc200x *ts = dev_get_drvdata(dev);
  515. sysfs_remove_group(&dev->kobj, &tsc200x_attr_group);
  516. if (ts->vio)
  517. regulator_disable(ts->vio);
  518. return 0;
  519. }
  520. EXPORT_SYMBOL_GPL(tsc200x_remove);
  521. static int __maybe_unused tsc200x_suspend(struct device *dev)
  522. {
  523. struct tsc200x *ts = dev_get_drvdata(dev);
  524. mutex_lock(&ts->mutex);
  525. if (!ts->suspended && ts->opened)
  526. __tsc200x_disable(ts);
  527. ts->suspended = true;
  528. mutex_unlock(&ts->mutex);
  529. return 0;
  530. }
  531. static int __maybe_unused tsc200x_resume(struct device *dev)
  532. {
  533. struct tsc200x *ts = dev_get_drvdata(dev);
  534. mutex_lock(&ts->mutex);
  535. if (ts->suspended && ts->opened)
  536. __tsc200x_enable(ts);
  537. ts->suspended = false;
  538. mutex_unlock(&ts->mutex);
  539. return 0;
  540. }
  541. SIMPLE_DEV_PM_OPS(tsc200x_pm_ops, tsc200x_suspend, tsc200x_resume);
  542. EXPORT_SYMBOL_GPL(tsc200x_pm_ops);
  543. MODULE_AUTHOR("Lauri Leukkunen <lauri.leukkunen@nokia.com>");
  544. MODULE_DESCRIPTION("TSC200x Touchscreen Driver Core");
  545. MODULE_LICENSE("GPL");