auo-pixcir-ts.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /*
  2. * Driver for AUO in-cell touchscreens
  3. *
  4. * Copyright (c) 2011 Heiko Stuebner <heiko@sntech.de>
  5. *
  6. * loosely based on auo_touch.c from Dell Streak vendor-kernel
  7. *
  8. * Copyright (c) 2008 QUALCOMM Incorporated.
  9. * Copyright (c) 2008 QUALCOMM USA, INC.
  10. *
  11. *
  12. * This software is licensed under the terms of the GNU General Public
  13. * License version 2, as published by the Free Software Foundation, and
  14. * may be copied, distributed, and modified under those terms.
  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. */
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/slab.h>
  26. #include <linux/input.h>
  27. #include <linux/jiffies.h>
  28. #include <linux/i2c.h>
  29. #include <linux/mutex.h>
  30. #include <linux/delay.h>
  31. #include <linux/gpio.h>
  32. #include <linux/input/auo-pixcir-ts.h>
  33. #include <linux/of.h>
  34. #include <linux/of_gpio.h>
  35. /*
  36. * Coordinate calculation:
  37. * X1 = X1_LSB + X1_MSB*256
  38. * Y1 = Y1_LSB + Y1_MSB*256
  39. * X2 = X2_LSB + X2_MSB*256
  40. * Y2 = Y2_LSB + Y2_MSB*256
  41. */
  42. #define AUO_PIXCIR_REG_X1_LSB 0x00
  43. #define AUO_PIXCIR_REG_X1_MSB 0x01
  44. #define AUO_PIXCIR_REG_Y1_LSB 0x02
  45. #define AUO_PIXCIR_REG_Y1_MSB 0x03
  46. #define AUO_PIXCIR_REG_X2_LSB 0x04
  47. #define AUO_PIXCIR_REG_X2_MSB 0x05
  48. #define AUO_PIXCIR_REG_Y2_LSB 0x06
  49. #define AUO_PIXCIR_REG_Y2_MSB 0x07
  50. #define AUO_PIXCIR_REG_STRENGTH 0x0d
  51. #define AUO_PIXCIR_REG_STRENGTH_X1_LSB 0x0e
  52. #define AUO_PIXCIR_REG_STRENGTH_X1_MSB 0x0f
  53. #define AUO_PIXCIR_REG_RAW_DATA_X 0x2b
  54. #define AUO_PIXCIR_REG_RAW_DATA_Y 0x4f
  55. #define AUO_PIXCIR_REG_X_SENSITIVITY 0x6f
  56. #define AUO_PIXCIR_REG_Y_SENSITIVITY 0x70
  57. #define AUO_PIXCIR_REG_INT_SETTING 0x71
  58. #define AUO_PIXCIR_REG_INT_WIDTH 0x72
  59. #define AUO_PIXCIR_REG_POWER_MODE 0x73
  60. #define AUO_PIXCIR_REG_VERSION 0x77
  61. #define AUO_PIXCIR_REG_CALIBRATE 0x78
  62. #define AUO_PIXCIR_REG_TOUCHAREA_X1 0x1e
  63. #define AUO_PIXCIR_REG_TOUCHAREA_Y1 0x1f
  64. #define AUO_PIXCIR_REG_TOUCHAREA_X2 0x20
  65. #define AUO_PIXCIR_REG_TOUCHAREA_Y2 0x21
  66. #define AUO_PIXCIR_REG_EEPROM_CALIB_X 0x42
  67. #define AUO_PIXCIR_REG_EEPROM_CALIB_Y 0xad
  68. #define AUO_PIXCIR_INT_TPNUM_MASK 0xe0
  69. #define AUO_PIXCIR_INT_TPNUM_SHIFT 5
  70. #define AUO_PIXCIR_INT_RELEASE (1 << 4)
  71. #define AUO_PIXCIR_INT_ENABLE (1 << 3)
  72. #define AUO_PIXCIR_INT_POL_HIGH (1 << 2)
  73. #define AUO_PIXCIR_INT_MODE_MASK 0x03
  74. /*
  75. * Power modes:
  76. * active: scan speed 60Hz
  77. * sleep: scan speed 10Hz can be auto-activated, wakeup on 1st touch
  78. * deep sleep: scan speed 1Hz can only be entered or left manually.
  79. */
  80. #define AUO_PIXCIR_POWER_ACTIVE 0x00
  81. #define AUO_PIXCIR_POWER_SLEEP 0x01
  82. #define AUO_PIXCIR_POWER_DEEP_SLEEP 0x02
  83. #define AUO_PIXCIR_POWER_MASK 0x03
  84. #define AUO_PIXCIR_POWER_ALLOW_SLEEP (1 << 2)
  85. #define AUO_PIXCIR_POWER_IDLE_TIME(ms) ((ms & 0xf) << 4)
  86. #define AUO_PIXCIR_CALIBRATE 0x03
  87. #define AUO_PIXCIR_EEPROM_CALIB_X_LEN 62
  88. #define AUO_PIXCIR_EEPROM_CALIB_Y_LEN 36
  89. #define AUO_PIXCIR_RAW_DATA_X_LEN 18
  90. #define AUO_PIXCIR_RAW_DATA_Y_LEN 11
  91. #define AUO_PIXCIR_STRENGTH_ENABLE (1 << 0)
  92. /* Touchscreen absolute values */
  93. #define AUO_PIXCIR_REPORT_POINTS 2
  94. #define AUO_PIXCIR_MAX_AREA 0xff
  95. #define AUO_PIXCIR_PENUP_TIMEOUT_MS 10
  96. struct auo_pixcir_ts {
  97. struct i2c_client *client;
  98. struct input_dev *input;
  99. const struct auo_pixcir_ts_platdata *pdata;
  100. char phys[32];
  101. /* special handling for touch_indicate interupt mode */
  102. bool touch_ind_mode;
  103. wait_queue_head_t wait;
  104. bool stopped;
  105. };
  106. struct auo_point_t {
  107. int coord_x;
  108. int coord_y;
  109. int area_major;
  110. int area_minor;
  111. int orientation;
  112. };
  113. static int auo_pixcir_collect_data(struct auo_pixcir_ts *ts,
  114. struct auo_point_t *point)
  115. {
  116. struct i2c_client *client = ts->client;
  117. const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
  118. uint8_t raw_coord[8];
  119. uint8_t raw_area[4];
  120. int i, ret;
  121. /* touch coordinates */
  122. ret = i2c_smbus_read_i2c_block_data(client, AUO_PIXCIR_REG_X1_LSB,
  123. 8, raw_coord);
  124. if (ret < 0) {
  125. dev_err(&client->dev, "failed to read coordinate, %d\n", ret);
  126. return ret;
  127. }
  128. /* touch area */
  129. ret = i2c_smbus_read_i2c_block_data(client, AUO_PIXCIR_REG_TOUCHAREA_X1,
  130. 4, raw_area);
  131. if (ret < 0) {
  132. dev_err(&client->dev, "could not read touch area, %d\n", ret);
  133. return ret;
  134. }
  135. for (i = 0; i < AUO_PIXCIR_REPORT_POINTS; i++) {
  136. point[i].coord_x =
  137. raw_coord[4 * i + 1] << 8 | raw_coord[4 * i];
  138. point[i].coord_y =
  139. raw_coord[4 * i + 3] << 8 | raw_coord[4 * i + 2];
  140. if (point[i].coord_x > pdata->x_max ||
  141. point[i].coord_y > pdata->y_max) {
  142. dev_warn(&client->dev, "coordinates (%d,%d) invalid\n",
  143. point[i].coord_x, point[i].coord_y);
  144. point[i].coord_x = point[i].coord_y = 0;
  145. }
  146. /* determine touch major, minor and orientation */
  147. point[i].area_major = max(raw_area[2 * i], raw_area[2 * i + 1]);
  148. point[i].area_minor = min(raw_area[2 * i], raw_area[2 * i + 1]);
  149. point[i].orientation = raw_area[2 * i] > raw_area[2 * i + 1];
  150. }
  151. return 0;
  152. }
  153. static irqreturn_t auo_pixcir_interrupt(int irq, void *dev_id)
  154. {
  155. struct auo_pixcir_ts *ts = dev_id;
  156. const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
  157. struct auo_point_t point[AUO_PIXCIR_REPORT_POINTS];
  158. int i;
  159. int ret;
  160. int fingers = 0;
  161. int abs = -1;
  162. while (!ts->stopped) {
  163. /* check for up event in touch touch_ind_mode */
  164. if (ts->touch_ind_mode) {
  165. if (gpio_get_value(pdata->gpio_int) == 0) {
  166. input_mt_sync(ts->input);
  167. input_report_key(ts->input, BTN_TOUCH, 0);
  168. input_sync(ts->input);
  169. break;
  170. }
  171. }
  172. ret = auo_pixcir_collect_data(ts, point);
  173. if (ret < 0) {
  174. /* we want to loop only in touch_ind_mode */
  175. if (!ts->touch_ind_mode)
  176. break;
  177. wait_event_timeout(ts->wait, ts->stopped,
  178. msecs_to_jiffies(AUO_PIXCIR_PENUP_TIMEOUT_MS));
  179. continue;
  180. }
  181. for (i = 0; i < AUO_PIXCIR_REPORT_POINTS; i++) {
  182. if (point[i].coord_x > 0 || point[i].coord_y > 0) {
  183. input_report_abs(ts->input, ABS_MT_POSITION_X,
  184. point[i].coord_x);
  185. input_report_abs(ts->input, ABS_MT_POSITION_Y,
  186. point[i].coord_y);
  187. input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR,
  188. point[i].area_major);
  189. input_report_abs(ts->input, ABS_MT_TOUCH_MINOR,
  190. point[i].area_minor);
  191. input_report_abs(ts->input, ABS_MT_ORIENTATION,
  192. point[i].orientation);
  193. input_mt_sync(ts->input);
  194. /* use first finger as source for singletouch */
  195. if (fingers == 0)
  196. abs = i;
  197. /* number of touch points could also be queried
  198. * via i2c but would require an additional call
  199. */
  200. fingers++;
  201. }
  202. }
  203. input_report_key(ts->input, BTN_TOUCH, fingers > 0);
  204. if (abs > -1) {
  205. input_report_abs(ts->input, ABS_X, point[abs].coord_x);
  206. input_report_abs(ts->input, ABS_Y, point[abs].coord_y);
  207. }
  208. input_sync(ts->input);
  209. /* we want to loop only in touch_ind_mode */
  210. if (!ts->touch_ind_mode)
  211. break;
  212. wait_event_timeout(ts->wait, ts->stopped,
  213. msecs_to_jiffies(AUO_PIXCIR_PENUP_TIMEOUT_MS));
  214. }
  215. return IRQ_HANDLED;
  216. }
  217. /*
  218. * Set the power mode of the device.
  219. * Valid modes are
  220. * - AUO_PIXCIR_POWER_ACTIVE
  221. * - AUO_PIXCIR_POWER_SLEEP - automatically left on first touch
  222. * - AUO_PIXCIR_POWER_DEEP_SLEEP
  223. */
  224. static int auo_pixcir_power_mode(struct auo_pixcir_ts *ts, int mode)
  225. {
  226. struct i2c_client *client = ts->client;
  227. int ret;
  228. ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_POWER_MODE);
  229. if (ret < 0) {
  230. dev_err(&client->dev, "unable to read reg %Xh, %d\n",
  231. AUO_PIXCIR_REG_POWER_MODE, ret);
  232. return ret;
  233. }
  234. ret &= ~AUO_PIXCIR_POWER_MASK;
  235. ret |= mode;
  236. ret = i2c_smbus_write_byte_data(client, AUO_PIXCIR_REG_POWER_MODE, ret);
  237. if (ret) {
  238. dev_err(&client->dev, "unable to write reg %Xh, %d\n",
  239. AUO_PIXCIR_REG_POWER_MODE, ret);
  240. return ret;
  241. }
  242. return 0;
  243. }
  244. static int auo_pixcir_int_config(struct auo_pixcir_ts *ts,
  245. int int_setting)
  246. {
  247. struct i2c_client *client = ts->client;
  248. const struct auo_pixcir_ts_platdata *pdata = ts->pdata;
  249. int ret;
  250. ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_INT_SETTING);
  251. if (ret < 0) {
  252. dev_err(&client->dev, "unable to read reg %Xh, %d\n",
  253. AUO_PIXCIR_REG_INT_SETTING, ret);
  254. return ret;
  255. }
  256. ret &= ~AUO_PIXCIR_INT_MODE_MASK;
  257. ret |= int_setting;
  258. ret |= AUO_PIXCIR_INT_POL_HIGH; /* always use high for interrupts */
  259. ret = i2c_smbus_write_byte_data(client, AUO_PIXCIR_REG_INT_SETTING,
  260. ret);
  261. if (ret < 0) {
  262. dev_err(&client->dev, "unable to write reg %Xh, %d\n",
  263. AUO_PIXCIR_REG_INT_SETTING, ret);
  264. return ret;
  265. }
  266. ts->touch_ind_mode = pdata->int_setting == AUO_PIXCIR_INT_TOUCH_IND;
  267. return 0;
  268. }
  269. /* control the generation of interrupts on the device side */
  270. static int auo_pixcir_int_toggle(struct auo_pixcir_ts *ts, bool enable)
  271. {
  272. struct i2c_client *client = ts->client;
  273. int ret;
  274. ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_INT_SETTING);
  275. if (ret < 0) {
  276. dev_err(&client->dev, "unable to read reg %Xh, %d\n",
  277. AUO_PIXCIR_REG_INT_SETTING, ret);
  278. return ret;
  279. }
  280. if (enable)
  281. ret |= AUO_PIXCIR_INT_ENABLE;
  282. else
  283. ret &= ~AUO_PIXCIR_INT_ENABLE;
  284. ret = i2c_smbus_write_byte_data(client, AUO_PIXCIR_REG_INT_SETTING,
  285. ret);
  286. if (ret < 0) {
  287. dev_err(&client->dev, "unable to write reg %Xh, %d\n",
  288. AUO_PIXCIR_REG_INT_SETTING, ret);
  289. return ret;
  290. }
  291. return 0;
  292. }
  293. static int auo_pixcir_start(struct auo_pixcir_ts *ts)
  294. {
  295. struct i2c_client *client = ts->client;
  296. int ret;
  297. ret = auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_ACTIVE);
  298. if (ret < 0) {
  299. dev_err(&client->dev, "could not set power mode, %d\n",
  300. ret);
  301. return ret;
  302. }
  303. ts->stopped = false;
  304. mb();
  305. enable_irq(client->irq);
  306. ret = auo_pixcir_int_toggle(ts, 1);
  307. if (ret < 0) {
  308. dev_err(&client->dev, "could not enable interrupt, %d\n",
  309. ret);
  310. disable_irq(client->irq);
  311. return ret;
  312. }
  313. return 0;
  314. }
  315. static int auo_pixcir_stop(struct auo_pixcir_ts *ts)
  316. {
  317. struct i2c_client *client = ts->client;
  318. int ret;
  319. ret = auo_pixcir_int_toggle(ts, 0);
  320. if (ret < 0) {
  321. dev_err(&client->dev, "could not disable interrupt, %d\n",
  322. ret);
  323. return ret;
  324. }
  325. /* disable receiving of interrupts */
  326. disable_irq(client->irq);
  327. ts->stopped = true;
  328. mb();
  329. wake_up(&ts->wait);
  330. return auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_DEEP_SLEEP);
  331. }
  332. static int auo_pixcir_input_open(struct input_dev *dev)
  333. {
  334. struct auo_pixcir_ts *ts = input_get_drvdata(dev);
  335. return auo_pixcir_start(ts);
  336. }
  337. static void auo_pixcir_input_close(struct input_dev *dev)
  338. {
  339. struct auo_pixcir_ts *ts = input_get_drvdata(dev);
  340. auo_pixcir_stop(ts);
  341. return;
  342. }
  343. static int __maybe_unused auo_pixcir_suspend(struct device *dev)
  344. {
  345. struct i2c_client *client = to_i2c_client(dev);
  346. struct auo_pixcir_ts *ts = i2c_get_clientdata(client);
  347. struct input_dev *input = ts->input;
  348. int ret = 0;
  349. mutex_lock(&input->mutex);
  350. /* when configured as wakeup source, device should always wake system
  351. * therefore start device if necessary
  352. */
  353. if (device_may_wakeup(&client->dev)) {
  354. /* need to start device if not open, to be wakeup source */
  355. if (!input->users) {
  356. ret = auo_pixcir_start(ts);
  357. if (ret)
  358. goto unlock;
  359. }
  360. enable_irq_wake(client->irq);
  361. ret = auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_SLEEP);
  362. } else if (input->users) {
  363. ret = auo_pixcir_stop(ts);
  364. }
  365. unlock:
  366. mutex_unlock(&input->mutex);
  367. return ret;
  368. }
  369. static int __maybe_unused auo_pixcir_resume(struct device *dev)
  370. {
  371. struct i2c_client *client = to_i2c_client(dev);
  372. struct auo_pixcir_ts *ts = i2c_get_clientdata(client);
  373. struct input_dev *input = ts->input;
  374. int ret = 0;
  375. mutex_lock(&input->mutex);
  376. if (device_may_wakeup(&client->dev)) {
  377. disable_irq_wake(client->irq);
  378. /* need to stop device if it was not open on suspend */
  379. if (!input->users) {
  380. ret = auo_pixcir_stop(ts);
  381. if (ret)
  382. goto unlock;
  383. }
  384. /* device wakes automatically from SLEEP */
  385. } else if (input->users) {
  386. ret = auo_pixcir_start(ts);
  387. }
  388. unlock:
  389. mutex_unlock(&input->mutex);
  390. return ret;
  391. }
  392. static SIMPLE_DEV_PM_OPS(auo_pixcir_pm_ops,
  393. auo_pixcir_suspend, auo_pixcir_resume);
  394. #ifdef CONFIG_OF
  395. static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev)
  396. {
  397. struct auo_pixcir_ts_platdata *pdata;
  398. struct device_node *np = dev->of_node;
  399. if (!np)
  400. return ERR_PTR(-ENOENT);
  401. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  402. if (!pdata) {
  403. dev_err(dev, "failed to allocate platform data\n");
  404. return ERR_PTR(-ENOMEM);
  405. }
  406. pdata->gpio_int = of_get_gpio(np, 0);
  407. if (!gpio_is_valid(pdata->gpio_int)) {
  408. dev_err(dev, "failed to get interrupt gpio\n");
  409. return ERR_PTR(-EINVAL);
  410. }
  411. pdata->gpio_rst = of_get_gpio(np, 1);
  412. if (!gpio_is_valid(pdata->gpio_rst)) {
  413. dev_err(dev, "failed to get reset gpio\n");
  414. return ERR_PTR(-EINVAL);
  415. }
  416. if (of_property_read_u32(np, "x-size", &pdata->x_max)) {
  417. dev_err(dev, "failed to get x-size property\n");
  418. return ERR_PTR(-EINVAL);
  419. }
  420. if (of_property_read_u32(np, "y-size", &pdata->y_max)) {
  421. dev_err(dev, "failed to get y-size property\n");
  422. return ERR_PTR(-EINVAL);
  423. }
  424. /* default to asserting the interrupt when the screen is touched */
  425. pdata->int_setting = AUO_PIXCIR_INT_TOUCH_IND;
  426. return pdata;
  427. }
  428. #else
  429. static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev)
  430. {
  431. return ERR_PTR(-EINVAL);
  432. }
  433. #endif
  434. static void auo_pixcir_reset(void *data)
  435. {
  436. struct auo_pixcir_ts *ts = data;
  437. gpio_set_value(ts->pdata->gpio_rst, 0);
  438. }
  439. static int auo_pixcir_probe(struct i2c_client *client,
  440. const struct i2c_device_id *id)
  441. {
  442. const struct auo_pixcir_ts_platdata *pdata;
  443. struct auo_pixcir_ts *ts;
  444. struct input_dev *input_dev;
  445. int version;
  446. int error;
  447. pdata = dev_get_platdata(&client->dev);
  448. if (!pdata) {
  449. pdata = auo_pixcir_parse_dt(&client->dev);
  450. if (IS_ERR(pdata))
  451. return PTR_ERR(pdata);
  452. }
  453. ts = devm_kzalloc(&client->dev,
  454. sizeof(struct auo_pixcir_ts), GFP_KERNEL);
  455. if (!ts)
  456. return -ENOMEM;
  457. input_dev = devm_input_allocate_device(&client->dev);
  458. if (!input_dev) {
  459. dev_err(&client->dev, "could not allocate input device\n");
  460. return -ENOMEM;
  461. }
  462. ts->pdata = pdata;
  463. ts->client = client;
  464. ts->input = input_dev;
  465. ts->touch_ind_mode = 0;
  466. ts->stopped = true;
  467. init_waitqueue_head(&ts->wait);
  468. snprintf(ts->phys, sizeof(ts->phys),
  469. "%s/input0", dev_name(&client->dev));
  470. input_dev->name = "AUO-Pixcir touchscreen";
  471. input_dev->phys = ts->phys;
  472. input_dev->id.bustype = BUS_I2C;
  473. input_dev->open = auo_pixcir_input_open;
  474. input_dev->close = auo_pixcir_input_close;
  475. __set_bit(EV_ABS, input_dev->evbit);
  476. __set_bit(EV_KEY, input_dev->evbit);
  477. __set_bit(BTN_TOUCH, input_dev->keybit);
  478. /* For single touch */
  479. input_set_abs_params(input_dev, ABS_X, 0, pdata->x_max, 0, 0);
  480. input_set_abs_params(input_dev, ABS_Y, 0, pdata->y_max, 0, 0);
  481. /* For multi touch */
  482. input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
  483. pdata->x_max, 0, 0);
  484. input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
  485. pdata->y_max, 0, 0);
  486. input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0,
  487. AUO_PIXCIR_MAX_AREA, 0, 0);
  488. input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0,
  489. AUO_PIXCIR_MAX_AREA, 0, 0);
  490. input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
  491. input_set_drvdata(ts->input, ts);
  492. error = devm_gpio_request_one(&client->dev, pdata->gpio_int,
  493. GPIOF_DIR_IN, "auo_pixcir_ts_int");
  494. if (error) {
  495. dev_err(&client->dev, "request of gpio %d failed, %d\n",
  496. pdata->gpio_int, error);
  497. return error;
  498. }
  499. error = devm_gpio_request_one(&client->dev, pdata->gpio_rst,
  500. GPIOF_DIR_OUT | GPIOF_INIT_HIGH,
  501. "auo_pixcir_ts_rst");
  502. if (error) {
  503. dev_err(&client->dev, "request of gpio %d failed, %d\n",
  504. pdata->gpio_rst, error);
  505. return error;
  506. }
  507. error = devm_add_action(&client->dev, auo_pixcir_reset, ts);
  508. if (error) {
  509. auo_pixcir_reset(ts);
  510. dev_err(&client->dev, "failed to register reset action, %d\n",
  511. error);
  512. return error;
  513. }
  514. msleep(200);
  515. version = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_VERSION);
  516. if (version < 0) {
  517. error = version;
  518. return error;
  519. }
  520. dev_info(&client->dev, "firmware version 0x%X\n", version);
  521. error = auo_pixcir_int_config(ts, pdata->int_setting);
  522. if (error)
  523. return error;
  524. error = devm_request_threaded_irq(&client->dev, client->irq,
  525. NULL, auo_pixcir_interrupt,
  526. IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  527. input_dev->name, ts);
  528. if (error) {
  529. dev_err(&client->dev, "irq %d requested failed, %d\n",
  530. client->irq, error);
  531. return error;
  532. }
  533. /* stop device and put it into deep sleep until it is opened */
  534. error = auo_pixcir_stop(ts);
  535. if (error)
  536. return error;
  537. error = input_register_device(input_dev);
  538. if (error) {
  539. dev_err(&client->dev, "could not register input device, %d\n",
  540. error);
  541. return error;
  542. }
  543. i2c_set_clientdata(client, ts);
  544. return 0;
  545. }
  546. static const struct i2c_device_id auo_pixcir_idtable[] = {
  547. { "auo_pixcir_ts", 0 },
  548. { }
  549. };
  550. MODULE_DEVICE_TABLE(i2c, auo_pixcir_idtable);
  551. #ifdef CONFIG_OF
  552. static const struct of_device_id auo_pixcir_ts_dt_idtable[] = {
  553. { .compatible = "auo,auo_pixcir_ts" },
  554. {},
  555. };
  556. MODULE_DEVICE_TABLE(of, auo_pixcir_ts_dt_idtable);
  557. #endif
  558. static struct i2c_driver auo_pixcir_driver = {
  559. .driver = {
  560. .name = "auo_pixcir_ts",
  561. .pm = &auo_pixcir_pm_ops,
  562. .of_match_table = of_match_ptr(auo_pixcir_ts_dt_idtable),
  563. },
  564. .probe = auo_pixcir_probe,
  565. .id_table = auo_pixcir_idtable,
  566. };
  567. module_i2c_driver(auo_pixcir_driver);
  568. MODULE_DESCRIPTION("AUO-PIXCIR touchscreen driver");
  569. MODULE_LICENSE("GPL v2");
  570. MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");