auo-pixcir-ts.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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. int ret;
  336. ret = auo_pixcir_start(ts);
  337. if (ret)
  338. return ret;
  339. return 0;
  340. }
  341. static void auo_pixcir_input_close(struct input_dev *dev)
  342. {
  343. struct auo_pixcir_ts *ts = input_get_drvdata(dev);
  344. auo_pixcir_stop(ts);
  345. return;
  346. }
  347. #ifdef CONFIG_PM_SLEEP
  348. static int auo_pixcir_suspend(struct device *dev)
  349. {
  350. struct i2c_client *client = to_i2c_client(dev);
  351. struct auo_pixcir_ts *ts = i2c_get_clientdata(client);
  352. struct input_dev *input = ts->input;
  353. int ret = 0;
  354. mutex_lock(&input->mutex);
  355. /* when configured as wakeup source, device should always wake system
  356. * therefore start device if necessary
  357. */
  358. if (device_may_wakeup(&client->dev)) {
  359. /* need to start device if not open, to be wakeup source */
  360. if (!input->users) {
  361. ret = auo_pixcir_start(ts);
  362. if (ret)
  363. goto unlock;
  364. }
  365. enable_irq_wake(client->irq);
  366. ret = auo_pixcir_power_mode(ts, AUO_PIXCIR_POWER_SLEEP);
  367. } else if (input->users) {
  368. ret = auo_pixcir_stop(ts);
  369. }
  370. unlock:
  371. mutex_unlock(&input->mutex);
  372. return ret;
  373. }
  374. static int auo_pixcir_resume(struct device *dev)
  375. {
  376. struct i2c_client *client = to_i2c_client(dev);
  377. struct auo_pixcir_ts *ts = i2c_get_clientdata(client);
  378. struct input_dev *input = ts->input;
  379. int ret = 0;
  380. mutex_lock(&input->mutex);
  381. if (device_may_wakeup(&client->dev)) {
  382. disable_irq_wake(client->irq);
  383. /* need to stop device if it was not open on suspend */
  384. if (!input->users) {
  385. ret = auo_pixcir_stop(ts);
  386. if (ret)
  387. goto unlock;
  388. }
  389. /* device wakes automatically from SLEEP */
  390. } else if (input->users) {
  391. ret = auo_pixcir_start(ts);
  392. }
  393. unlock:
  394. mutex_unlock(&input->mutex);
  395. return ret;
  396. }
  397. #endif
  398. static SIMPLE_DEV_PM_OPS(auo_pixcir_pm_ops,
  399. auo_pixcir_suspend, auo_pixcir_resume);
  400. #ifdef CONFIG_OF
  401. static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev)
  402. {
  403. struct auo_pixcir_ts_platdata *pdata;
  404. struct device_node *np = dev->of_node;
  405. if (!np)
  406. return ERR_PTR(-ENOENT);
  407. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  408. if (!pdata) {
  409. dev_err(dev, "failed to allocate platform data\n");
  410. return ERR_PTR(-ENOMEM);
  411. }
  412. pdata->gpio_int = of_get_gpio(np, 0);
  413. if (!gpio_is_valid(pdata->gpio_int)) {
  414. dev_err(dev, "failed to get interrupt gpio\n");
  415. return ERR_PTR(-EINVAL);
  416. }
  417. pdata->gpio_rst = of_get_gpio(np, 1);
  418. if (!gpio_is_valid(pdata->gpio_rst)) {
  419. dev_err(dev, "failed to get reset gpio\n");
  420. return ERR_PTR(-EINVAL);
  421. }
  422. if (of_property_read_u32(np, "x-size", &pdata->x_max)) {
  423. dev_err(dev, "failed to get x-size property\n");
  424. return ERR_PTR(-EINVAL);
  425. }
  426. if (of_property_read_u32(np, "y-size", &pdata->y_max)) {
  427. dev_err(dev, "failed to get y-size property\n");
  428. return ERR_PTR(-EINVAL);
  429. }
  430. /* default to asserting the interrupt when the screen is touched */
  431. pdata->int_setting = AUO_PIXCIR_INT_TOUCH_IND;
  432. return pdata;
  433. }
  434. #else
  435. static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev)
  436. {
  437. return ERR_PTR(-EINVAL);
  438. }
  439. #endif
  440. static void auo_pixcir_reset(void *data)
  441. {
  442. struct auo_pixcir_ts *ts = data;
  443. gpio_set_value(ts->pdata->gpio_rst, 0);
  444. }
  445. static int auo_pixcir_probe(struct i2c_client *client,
  446. const struct i2c_device_id *id)
  447. {
  448. const struct auo_pixcir_ts_platdata *pdata;
  449. struct auo_pixcir_ts *ts;
  450. struct input_dev *input_dev;
  451. int version;
  452. int error;
  453. pdata = dev_get_platdata(&client->dev);
  454. if (!pdata) {
  455. pdata = auo_pixcir_parse_dt(&client->dev);
  456. if (IS_ERR(pdata))
  457. return PTR_ERR(pdata);
  458. }
  459. ts = devm_kzalloc(&client->dev,
  460. sizeof(struct auo_pixcir_ts), GFP_KERNEL);
  461. if (!ts)
  462. return -ENOMEM;
  463. input_dev = devm_input_allocate_device(&client->dev);
  464. if (!input_dev) {
  465. dev_err(&client->dev, "could not allocate input device\n");
  466. return -ENOMEM;
  467. }
  468. ts->pdata = pdata;
  469. ts->client = client;
  470. ts->input = input_dev;
  471. ts->touch_ind_mode = 0;
  472. ts->stopped = true;
  473. init_waitqueue_head(&ts->wait);
  474. snprintf(ts->phys, sizeof(ts->phys),
  475. "%s/input0", dev_name(&client->dev));
  476. input_dev->name = "AUO-Pixcir touchscreen";
  477. input_dev->phys = ts->phys;
  478. input_dev->id.bustype = BUS_I2C;
  479. input_dev->open = auo_pixcir_input_open;
  480. input_dev->close = auo_pixcir_input_close;
  481. __set_bit(EV_ABS, input_dev->evbit);
  482. __set_bit(EV_KEY, input_dev->evbit);
  483. __set_bit(BTN_TOUCH, input_dev->keybit);
  484. /* For single touch */
  485. input_set_abs_params(input_dev, ABS_X, 0, pdata->x_max, 0, 0);
  486. input_set_abs_params(input_dev, ABS_Y, 0, pdata->y_max, 0, 0);
  487. /* For multi touch */
  488. input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
  489. pdata->x_max, 0, 0);
  490. input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
  491. pdata->y_max, 0, 0);
  492. input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0,
  493. AUO_PIXCIR_MAX_AREA, 0, 0);
  494. input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0,
  495. AUO_PIXCIR_MAX_AREA, 0, 0);
  496. input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
  497. input_set_drvdata(ts->input, ts);
  498. error = devm_gpio_request_one(&client->dev, pdata->gpio_int,
  499. GPIOF_DIR_IN, "auo_pixcir_ts_int");
  500. if (error) {
  501. dev_err(&client->dev, "request of gpio %d failed, %d\n",
  502. pdata->gpio_int, error);
  503. return error;
  504. }
  505. error = devm_gpio_request_one(&client->dev, pdata->gpio_rst,
  506. GPIOF_DIR_OUT | GPIOF_INIT_HIGH,
  507. "auo_pixcir_ts_rst");
  508. if (error) {
  509. dev_err(&client->dev, "request of gpio %d failed, %d\n",
  510. pdata->gpio_rst, error);
  511. return error;
  512. }
  513. error = devm_add_action(&client->dev, auo_pixcir_reset, ts);
  514. if (error) {
  515. auo_pixcir_reset(ts);
  516. dev_err(&client->dev, "failed to register reset action, %d\n",
  517. error);
  518. return error;
  519. }
  520. msleep(200);
  521. version = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_VERSION);
  522. if (version < 0) {
  523. error = version;
  524. return error;
  525. }
  526. dev_info(&client->dev, "firmware version 0x%X\n", version);
  527. error = auo_pixcir_int_config(ts, pdata->int_setting);
  528. if (error)
  529. return error;
  530. error = devm_request_threaded_irq(&client->dev, client->irq,
  531. NULL, auo_pixcir_interrupt,
  532. IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  533. input_dev->name, ts);
  534. if (error) {
  535. dev_err(&client->dev, "irq %d requested failed, %d\n",
  536. client->irq, error);
  537. return error;
  538. }
  539. /* stop device and put it into deep sleep until it is opened */
  540. error = auo_pixcir_stop(ts);
  541. if (error)
  542. return error;
  543. error = input_register_device(input_dev);
  544. if (error) {
  545. dev_err(&client->dev, "could not register input device, %d\n",
  546. error);
  547. return error;
  548. }
  549. i2c_set_clientdata(client, ts);
  550. return 0;
  551. }
  552. static const struct i2c_device_id auo_pixcir_idtable[] = {
  553. { "auo_pixcir_ts", 0 },
  554. { }
  555. };
  556. MODULE_DEVICE_TABLE(i2c, auo_pixcir_idtable);
  557. #ifdef CONFIG_OF
  558. static struct of_device_id auo_pixcir_ts_dt_idtable[] = {
  559. { .compatible = "auo,auo_pixcir_ts" },
  560. {},
  561. };
  562. MODULE_DEVICE_TABLE(of, auo_pixcir_ts_dt_idtable);
  563. #endif
  564. static struct i2c_driver auo_pixcir_driver = {
  565. .driver = {
  566. .owner = THIS_MODULE,
  567. .name = "auo_pixcir_ts",
  568. .pm = &auo_pixcir_pm_ops,
  569. .of_match_table = of_match_ptr(auo_pixcir_ts_dt_idtable),
  570. },
  571. .probe = auo_pixcir_probe,
  572. .id_table = auo_pixcir_idtable,
  573. };
  574. module_i2c_driver(auo_pixcir_driver);
  575. MODULE_DESCRIPTION("AUO-PIXCIR touchscreen driver");
  576. MODULE_LICENSE("GPL v2");
  577. MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");