cyttsp_core.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Core Source for:
  4. * Cypress TrueTouch(TM) Standard Product (TTSP) touchscreen drivers.
  5. * For use with Cypress Txx3xx parts.
  6. * Supported parts include:
  7. * CY8CTST341
  8. * CY8CTMA340
  9. *
  10. * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc.
  11. * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org>
  12. *
  13. * Contact Cypress Semiconductor at www.cypress.com <kev@cypress.com>
  14. */
  15. #include <linux/delay.h>
  16. #include <linux/export.h>
  17. #include <linux/input.h>
  18. #include <linux/input/mt.h>
  19. #include <linux/input/touchscreen.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/slab.h>
  22. #include <linux/property.h>
  23. #include <linux/gpio/consumer.h>
  24. #include <linux/regulator/consumer.h>
  25. #include "cyttsp_core.h"
  26. /* Bootloader number of command keys */
  27. #define CY_NUM_BL_KEYS 8
  28. /* helpers */
  29. #define GET_NUM_TOUCHES(x) ((x) & 0x0F)
  30. #define IS_LARGE_AREA(x) (((x) & 0x10) >> 4)
  31. #define IS_BAD_PKT(x) ((x) & 0x20)
  32. #define IS_VALID_APP(x) ((x) & 0x01)
  33. #define IS_OPERATIONAL_ERR(x) ((x) & 0x3F)
  34. #define GET_HSTMODE(reg) (((reg) & 0x70) >> 4)
  35. #define GET_BOOTLOADERMODE(reg) (((reg) & 0x10) >> 4)
  36. #define CY_REG_BASE 0x00
  37. #define CY_REG_ACT_DIST 0x1E
  38. #define CY_REG_ACT_INTRVL 0x1D
  39. #define CY_REG_TCH_TMOUT (CY_REG_ACT_INTRVL + 1)
  40. #define CY_REG_LP_INTRVL (CY_REG_TCH_TMOUT + 1)
  41. #define CY_MAXZ 255
  42. #define CY_DELAY_DFLT 20 /* ms */
  43. #define CY_DELAY_MAX 500
  44. /* Active distance in pixels for a gesture to be reported */
  45. #define CY_ACT_DIST_DFLT 0xF8 /* pixels */
  46. #define CY_ACT_DIST_MASK 0x0F
  47. /* Active Power state scanning/processing refresh interval */
  48. #define CY_ACT_INTRVL_DFLT 0x00 /* ms */
  49. /* Low Power state scanning/processing refresh interval */
  50. #define CY_LP_INTRVL_DFLT 0x0A /* ms */
  51. /* touch timeout for the Active power */
  52. #define CY_TCH_TMOUT_DFLT 0xFF /* ms */
  53. #define CY_HNDSHK_BIT 0x80
  54. /* device mode bits */
  55. #define CY_OPERATE_MODE 0x00
  56. #define CY_SYSINFO_MODE 0x10
  57. /* power mode select bits */
  58. #define CY_SOFT_RESET_MODE 0x01 /* return to Bootloader mode */
  59. #define CY_DEEP_SLEEP_MODE 0x02
  60. #define CY_LOW_POWER_MODE 0x04
  61. /* Slots management */
  62. #define CY_MAX_FINGER 4
  63. #define CY_MAX_ID 16
  64. static const u8 bl_command[] = {
  65. 0x00, /* file offset */
  66. 0xFF, /* command */
  67. 0xA5, /* exit bootloader command */
  68. 0, 1, 2, 3, 4, 5, 6, 7 /* default keys */
  69. };
  70. static int ttsp_read_block_data(struct cyttsp *ts, u8 command,
  71. u8 length, void *buf)
  72. {
  73. int error;
  74. int tries;
  75. for (tries = 0; tries < CY_NUM_RETRY; tries++) {
  76. error = ts->bus_ops->read(ts->dev, ts->xfer_buf, command,
  77. length, buf);
  78. if (!error)
  79. return 0;
  80. msleep(CY_DELAY_DFLT);
  81. }
  82. return -EIO;
  83. }
  84. static int ttsp_write_block_data(struct cyttsp *ts, u8 command,
  85. u8 length, void *buf)
  86. {
  87. int error;
  88. int tries;
  89. for (tries = 0; tries < CY_NUM_RETRY; tries++) {
  90. error = ts->bus_ops->write(ts->dev, ts->xfer_buf, command,
  91. length, buf);
  92. if (!error)
  93. return 0;
  94. msleep(CY_DELAY_DFLT);
  95. }
  96. return -EIO;
  97. }
  98. static int ttsp_send_command(struct cyttsp *ts, u8 cmd)
  99. {
  100. return ttsp_write_block_data(ts, CY_REG_BASE, sizeof(cmd), &cmd);
  101. }
  102. static int cyttsp_handshake(struct cyttsp *ts)
  103. {
  104. if (ts->use_hndshk)
  105. return ttsp_send_command(ts,
  106. ts->xy_data.hst_mode ^ CY_HNDSHK_BIT);
  107. return 0;
  108. }
  109. static int cyttsp_load_bl_regs(struct cyttsp *ts)
  110. {
  111. memset(&ts->bl_data, 0, sizeof(ts->bl_data));
  112. ts->bl_data.bl_status = 0x10;
  113. return ttsp_read_block_data(ts, CY_REG_BASE,
  114. sizeof(ts->bl_data), &ts->bl_data);
  115. }
  116. static int cyttsp_exit_bl_mode(struct cyttsp *ts)
  117. {
  118. int error;
  119. u8 bl_cmd[sizeof(bl_command)];
  120. memcpy(bl_cmd, bl_command, sizeof(bl_command));
  121. if (ts->bl_keys)
  122. memcpy(&bl_cmd[sizeof(bl_command) - CY_NUM_BL_KEYS],
  123. ts->bl_keys, CY_NUM_BL_KEYS);
  124. error = ttsp_write_block_data(ts, CY_REG_BASE,
  125. sizeof(bl_cmd), bl_cmd);
  126. if (error)
  127. return error;
  128. /* wait for TTSP Device to complete the operation */
  129. msleep(CY_DELAY_DFLT);
  130. error = cyttsp_load_bl_regs(ts);
  131. if (error)
  132. return error;
  133. if (GET_BOOTLOADERMODE(ts->bl_data.bl_status))
  134. return -EIO;
  135. return 0;
  136. }
  137. static int cyttsp_set_operational_mode(struct cyttsp *ts)
  138. {
  139. int error;
  140. error = ttsp_send_command(ts, CY_OPERATE_MODE);
  141. if (error)
  142. return error;
  143. /* wait for TTSP Device to complete switch to Operational mode */
  144. error = ttsp_read_block_data(ts, CY_REG_BASE,
  145. sizeof(ts->xy_data), &ts->xy_data);
  146. if (error)
  147. return error;
  148. error = cyttsp_handshake(ts);
  149. if (error)
  150. return error;
  151. return ts->xy_data.act_dist == CY_ACT_DIST_DFLT ? -EIO : 0;
  152. }
  153. static int cyttsp_set_sysinfo_mode(struct cyttsp *ts)
  154. {
  155. int error;
  156. memset(&ts->sysinfo_data, 0, sizeof(ts->sysinfo_data));
  157. /* switch to sysinfo mode */
  158. error = ttsp_send_command(ts, CY_SYSINFO_MODE);
  159. if (error)
  160. return error;
  161. /* read sysinfo registers */
  162. msleep(CY_DELAY_DFLT);
  163. error = ttsp_read_block_data(ts, CY_REG_BASE, sizeof(ts->sysinfo_data),
  164. &ts->sysinfo_data);
  165. if (error)
  166. return error;
  167. error = cyttsp_handshake(ts);
  168. if (error)
  169. return error;
  170. if (!ts->sysinfo_data.tts_verh && !ts->sysinfo_data.tts_verl)
  171. return -EIO;
  172. return 0;
  173. }
  174. static int cyttsp_set_sysinfo_regs(struct cyttsp *ts)
  175. {
  176. int retval = 0;
  177. if (ts->act_intrvl != CY_ACT_INTRVL_DFLT ||
  178. ts->tch_tmout != CY_TCH_TMOUT_DFLT ||
  179. ts->lp_intrvl != CY_LP_INTRVL_DFLT) {
  180. u8 intrvl_ray[] = {
  181. ts->act_intrvl,
  182. ts->tch_tmout,
  183. ts->lp_intrvl
  184. };
  185. /* set intrvl registers */
  186. retval = ttsp_write_block_data(ts, CY_REG_ACT_INTRVL,
  187. sizeof(intrvl_ray), intrvl_ray);
  188. msleep(CY_DELAY_DFLT);
  189. }
  190. return retval;
  191. }
  192. static void cyttsp_hard_reset(struct cyttsp *ts)
  193. {
  194. if (ts->reset_gpio) {
  195. /*
  196. * According to the CY8CTMA340 datasheet page 21, the external
  197. * reset pulse width should be >= 1 ms. The datasheet does not
  198. * specify how long we have to wait after reset but a vendor
  199. * tree specifies 5 ms here.
  200. */
  201. gpiod_set_value_cansleep(ts->reset_gpio, 1);
  202. usleep_range(1000, 2000);
  203. gpiod_set_value_cansleep(ts->reset_gpio, 0);
  204. usleep_range(5000, 6000);
  205. }
  206. }
  207. static int cyttsp_soft_reset(struct cyttsp *ts)
  208. {
  209. int retval;
  210. /* wait for interrupt to set ready completion */
  211. reinit_completion(&ts->bl_ready);
  212. ts->state = CY_BL_STATE;
  213. enable_irq(ts->irq);
  214. retval = ttsp_send_command(ts, CY_SOFT_RESET_MODE);
  215. if (retval) {
  216. dev_err(ts->dev, "failed to send soft reset\n");
  217. goto out;
  218. }
  219. if (!wait_for_completion_timeout(&ts->bl_ready,
  220. msecs_to_jiffies(CY_DELAY_DFLT * CY_DELAY_MAX))) {
  221. dev_err(ts->dev, "timeout waiting for soft reset\n");
  222. retval = -EIO;
  223. }
  224. out:
  225. ts->state = CY_IDLE_STATE;
  226. disable_irq(ts->irq);
  227. return retval;
  228. }
  229. static int cyttsp_act_dist_setup(struct cyttsp *ts)
  230. {
  231. u8 act_dist_setup = ts->act_dist;
  232. /* Init gesture; active distance setup */
  233. return ttsp_write_block_data(ts, CY_REG_ACT_DIST,
  234. sizeof(act_dist_setup), &act_dist_setup);
  235. }
  236. static void cyttsp_extract_track_ids(struct cyttsp_xydata *xy_data, int *ids)
  237. {
  238. ids[0] = xy_data->touch12_id >> 4;
  239. ids[1] = xy_data->touch12_id & 0xF;
  240. ids[2] = xy_data->touch34_id >> 4;
  241. ids[3] = xy_data->touch34_id & 0xF;
  242. }
  243. static const struct cyttsp_tch *cyttsp_get_tch(struct cyttsp_xydata *xy_data,
  244. int idx)
  245. {
  246. switch (idx) {
  247. case 0:
  248. return &xy_data->tch1;
  249. case 1:
  250. return &xy_data->tch2;
  251. case 2:
  252. return &xy_data->tch3;
  253. case 3:
  254. return &xy_data->tch4;
  255. default:
  256. return NULL;
  257. }
  258. }
  259. static void cyttsp_report_tchdata(struct cyttsp *ts)
  260. {
  261. struct cyttsp_xydata *xy_data = &ts->xy_data;
  262. struct input_dev *input = ts->input;
  263. int num_tch = GET_NUM_TOUCHES(xy_data->tt_stat);
  264. const struct cyttsp_tch *tch;
  265. int ids[CY_MAX_ID];
  266. int i;
  267. DECLARE_BITMAP(used, CY_MAX_ID);
  268. if (IS_LARGE_AREA(xy_data->tt_stat) == 1) {
  269. /* terminate all active tracks */
  270. num_tch = 0;
  271. dev_dbg(ts->dev, "%s: Large area detected\n", __func__);
  272. } else if (num_tch > CY_MAX_FINGER) {
  273. /* terminate all active tracks */
  274. num_tch = 0;
  275. dev_dbg(ts->dev, "%s: Num touch error detected\n", __func__);
  276. } else if (IS_BAD_PKT(xy_data->tt_mode)) {
  277. /* terminate all active tracks */
  278. num_tch = 0;
  279. dev_dbg(ts->dev, "%s: Invalid buffer detected\n", __func__);
  280. }
  281. cyttsp_extract_track_ids(xy_data, ids);
  282. bitmap_zero(used, CY_MAX_ID);
  283. for (i = 0; i < num_tch; i++) {
  284. tch = cyttsp_get_tch(xy_data, i);
  285. input_mt_slot(input, ids[i]);
  286. input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
  287. input_report_abs(input, ABS_MT_POSITION_X, be16_to_cpu(tch->x));
  288. input_report_abs(input, ABS_MT_POSITION_Y, be16_to_cpu(tch->y));
  289. input_report_abs(input, ABS_MT_TOUCH_MAJOR, tch->z);
  290. __set_bit(ids[i], used);
  291. }
  292. for (i = 0; i < CY_MAX_ID; i++) {
  293. if (test_bit(i, used))
  294. continue;
  295. input_mt_slot(input, i);
  296. input_mt_report_slot_inactive(input);
  297. }
  298. input_sync(input);
  299. }
  300. static irqreturn_t cyttsp_irq(int irq, void *handle)
  301. {
  302. struct cyttsp *ts = handle;
  303. int error;
  304. if (unlikely(ts->state == CY_BL_STATE)) {
  305. complete(&ts->bl_ready);
  306. goto out;
  307. }
  308. /* Get touch data from CYTTSP device */
  309. error = ttsp_read_block_data(ts, CY_REG_BASE,
  310. sizeof(struct cyttsp_xydata), &ts->xy_data);
  311. if (error)
  312. goto out;
  313. /* provide flow control handshake */
  314. error = cyttsp_handshake(ts);
  315. if (error)
  316. goto out;
  317. if (unlikely(ts->state == CY_IDLE_STATE))
  318. goto out;
  319. if (GET_BOOTLOADERMODE(ts->xy_data.tt_mode)) {
  320. /*
  321. * TTSP device has reset back to bootloader mode.
  322. * Restore to operational mode.
  323. */
  324. error = cyttsp_exit_bl_mode(ts);
  325. if (error) {
  326. dev_err(ts->dev,
  327. "Could not return to operational mode, err: %d\n",
  328. error);
  329. ts->state = CY_IDLE_STATE;
  330. }
  331. } else {
  332. cyttsp_report_tchdata(ts);
  333. }
  334. out:
  335. return IRQ_HANDLED;
  336. }
  337. static int cyttsp_power_on(struct cyttsp *ts)
  338. {
  339. int error;
  340. error = cyttsp_soft_reset(ts);
  341. if (error)
  342. return error;
  343. error = cyttsp_load_bl_regs(ts);
  344. if (error)
  345. return error;
  346. if (GET_BOOTLOADERMODE(ts->bl_data.bl_status) &&
  347. IS_VALID_APP(ts->bl_data.bl_status)) {
  348. error = cyttsp_exit_bl_mode(ts);
  349. if (error) {
  350. dev_err(ts->dev, "failed to exit bootloader mode\n");
  351. return error;
  352. }
  353. }
  354. if (GET_HSTMODE(ts->bl_data.bl_file) != CY_OPERATE_MODE ||
  355. IS_OPERATIONAL_ERR(ts->bl_data.bl_status)) {
  356. return -ENODEV;
  357. }
  358. error = cyttsp_set_sysinfo_mode(ts);
  359. if (error)
  360. return error;
  361. error = cyttsp_set_sysinfo_regs(ts);
  362. if (error)
  363. return error;
  364. error = cyttsp_set_operational_mode(ts);
  365. if (error)
  366. return error;
  367. /* init active distance */
  368. error = cyttsp_act_dist_setup(ts);
  369. if (error)
  370. return error;
  371. ts->state = CY_ACTIVE_STATE;
  372. return 0;
  373. }
  374. static int cyttsp_enable(struct cyttsp *ts)
  375. {
  376. int error;
  377. /*
  378. * The device firmware can wake on an I2C or SPI memory slave
  379. * address match. So just reading a register is sufficient to
  380. * wake up the device. The first read attempt will fail but it
  381. * will wake it up making the second read attempt successful.
  382. */
  383. error = ttsp_read_block_data(ts, CY_REG_BASE,
  384. sizeof(ts->xy_data), &ts->xy_data);
  385. if (error)
  386. return error;
  387. if (GET_HSTMODE(ts->xy_data.hst_mode))
  388. return -EIO;
  389. enable_irq(ts->irq);
  390. return 0;
  391. }
  392. static int cyttsp_disable(struct cyttsp *ts)
  393. {
  394. int error;
  395. error = ttsp_send_command(ts, CY_LOW_POWER_MODE);
  396. if (error)
  397. return error;
  398. disable_irq(ts->irq);
  399. return 0;
  400. }
  401. static int cyttsp_suspend(struct device *dev)
  402. {
  403. struct cyttsp *ts = dev_get_drvdata(dev);
  404. int retval = 0;
  405. mutex_lock(&ts->input->mutex);
  406. if (input_device_enabled(ts->input)) {
  407. retval = cyttsp_disable(ts);
  408. if (retval == 0)
  409. ts->suspended = true;
  410. }
  411. mutex_unlock(&ts->input->mutex);
  412. return retval;
  413. }
  414. static int cyttsp_resume(struct device *dev)
  415. {
  416. struct cyttsp *ts = dev_get_drvdata(dev);
  417. mutex_lock(&ts->input->mutex);
  418. if (input_device_enabled(ts->input))
  419. cyttsp_enable(ts);
  420. ts->suspended = false;
  421. mutex_unlock(&ts->input->mutex);
  422. return 0;
  423. }
  424. EXPORT_GPL_SIMPLE_DEV_PM_OPS(cyttsp_pm_ops, cyttsp_suspend, cyttsp_resume);
  425. static int cyttsp_open(struct input_dev *dev)
  426. {
  427. struct cyttsp *ts = input_get_drvdata(dev);
  428. int retval = 0;
  429. if (!ts->suspended)
  430. retval = cyttsp_enable(ts);
  431. return retval;
  432. }
  433. static void cyttsp_close(struct input_dev *dev)
  434. {
  435. struct cyttsp *ts = input_get_drvdata(dev);
  436. if (!ts->suspended)
  437. cyttsp_disable(ts);
  438. }
  439. static int cyttsp_parse_properties(struct cyttsp *ts)
  440. {
  441. struct device *dev = ts->dev;
  442. u32 dt_value;
  443. int ret;
  444. ts->bl_keys = devm_kzalloc(dev, CY_NUM_BL_KEYS, GFP_KERNEL);
  445. if (!ts->bl_keys)
  446. return -ENOMEM;
  447. /* Set some default values */
  448. ts->use_hndshk = false;
  449. ts->act_dist = CY_ACT_DIST_DFLT;
  450. ts->act_intrvl = CY_ACT_INTRVL_DFLT;
  451. ts->tch_tmout = CY_TCH_TMOUT_DFLT;
  452. ts->lp_intrvl = CY_LP_INTRVL_DFLT;
  453. ret = device_property_read_u8_array(dev, "bootloader-key",
  454. ts->bl_keys, CY_NUM_BL_KEYS);
  455. if (ret) {
  456. dev_err(dev,
  457. "bootloader-key property could not be retrieved\n");
  458. return ret;
  459. }
  460. ts->use_hndshk = device_property_present(dev, "use-handshake");
  461. if (!device_property_read_u32(dev, "active-distance", &dt_value)) {
  462. if (dt_value > 15) {
  463. dev_err(dev, "active-distance (%u) must be [0-15]\n",
  464. dt_value);
  465. return -EINVAL;
  466. }
  467. ts->act_dist &= ~CY_ACT_DIST_MASK;
  468. ts->act_dist |= dt_value;
  469. }
  470. if (!device_property_read_u32(dev, "active-interval-ms", &dt_value)) {
  471. if (dt_value > 255) {
  472. dev_err(dev, "active-interval-ms (%u) must be [0-255]\n",
  473. dt_value);
  474. return -EINVAL;
  475. }
  476. ts->act_intrvl = dt_value;
  477. }
  478. if (!device_property_read_u32(dev, "lowpower-interval-ms", &dt_value)) {
  479. if (dt_value > 2550) {
  480. dev_err(dev, "lowpower-interval-ms (%u) must be [0-2550]\n",
  481. dt_value);
  482. return -EINVAL;
  483. }
  484. /* Register value is expressed in 0.01s / bit */
  485. ts->lp_intrvl = dt_value / 10;
  486. }
  487. if (!device_property_read_u32(dev, "touch-timeout-ms", &dt_value)) {
  488. if (dt_value > 2550) {
  489. dev_err(dev, "touch-timeout-ms (%u) must be [0-2550]\n",
  490. dt_value);
  491. return -EINVAL;
  492. }
  493. /* Register value is expressed in 0.01s / bit */
  494. ts->tch_tmout = dt_value / 10;
  495. }
  496. return 0;
  497. }
  498. struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
  499. struct device *dev, int irq, size_t xfer_buf_size)
  500. {
  501. /*
  502. * VCPIN is the analog voltage supply
  503. * VDD is the digital voltage supply
  504. */
  505. static const char * const supplies[] = { "vcpin", "vdd" };
  506. struct cyttsp *ts;
  507. struct input_dev *input_dev;
  508. int error;
  509. ts = devm_kzalloc(dev, sizeof(*ts) + xfer_buf_size, GFP_KERNEL);
  510. if (!ts)
  511. return ERR_PTR(-ENOMEM);
  512. input_dev = devm_input_allocate_device(dev);
  513. if (!input_dev)
  514. return ERR_PTR(-ENOMEM);
  515. ts->dev = dev;
  516. ts->input = input_dev;
  517. ts->bus_ops = bus_ops;
  518. ts->irq = irq;
  519. error = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(supplies),
  520. supplies);
  521. if (error) {
  522. dev_err(dev, "Failed to enable regulators: %d\n", error);
  523. return ERR_PTR(error);
  524. }
  525. ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
  526. if (IS_ERR(ts->reset_gpio)) {
  527. error = PTR_ERR(ts->reset_gpio);
  528. dev_err(dev, "Failed to request reset gpio, error %d\n", error);
  529. return ERR_PTR(error);
  530. }
  531. error = cyttsp_parse_properties(ts);
  532. if (error)
  533. return ERR_PTR(error);
  534. init_completion(&ts->bl_ready);
  535. input_dev->name = "Cypress TTSP TouchScreen";
  536. input_dev->id.bustype = bus_ops->bustype;
  537. input_dev->dev.parent = ts->dev;
  538. input_dev->open = cyttsp_open;
  539. input_dev->close = cyttsp_close;
  540. input_set_drvdata(input_dev, ts);
  541. input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X);
  542. input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y);
  543. /* One byte for width 0..255 so this is the limit */
  544. input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
  545. touchscreen_parse_properties(input_dev, true, NULL);
  546. error = input_mt_init_slots(input_dev, CY_MAX_ID, INPUT_MT_DIRECT);
  547. if (error) {
  548. dev_err(dev, "Unable to init MT slots.\n");
  549. return ERR_PTR(error);
  550. }
  551. error = devm_request_threaded_irq(dev, ts->irq, NULL, cyttsp_irq,
  552. IRQF_ONESHOT | IRQF_NO_AUTOEN,
  553. "cyttsp", ts);
  554. if (error) {
  555. dev_err(ts->dev, "failed to request IRQ %d, err: %d\n",
  556. ts->irq, error);
  557. return ERR_PTR(error);
  558. }
  559. cyttsp_hard_reset(ts);
  560. error = cyttsp_power_on(ts);
  561. if (error)
  562. return ERR_PTR(error);
  563. error = input_register_device(input_dev);
  564. if (error) {
  565. dev_err(ts->dev, "failed to register input device: %d\n",
  566. error);
  567. return ERR_PTR(error);
  568. }
  569. return ts;
  570. }
  571. EXPORT_SYMBOL_GPL(cyttsp_probe);
  572. MODULE_LICENSE("GPL");
  573. MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard touchscreen driver core");
  574. MODULE_AUTHOR("Cypress");