cyttsp_core.c 16 KB

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