synaptics_i2c_rmi.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /* drivers/input/keyboard/synaptics_i2c_rmi.c
  2. *
  3. * Copyright (C) 2007 Google, Inc.
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #include <linux/module.h>
  16. #include <linux/delay.h>
  17. #include <linux/earlysuspend.h>
  18. #include <linux/hrtimer.h>
  19. #include <linux/i2c.h>
  20. #include <linux/input.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/io.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/slab.h>
  25. #include <linux/synaptics_i2c_rmi.h>
  26. static struct workqueue_struct *synaptics_wq;
  27. struct synaptics_ts_data {
  28. uint16_t addr;
  29. struct i2c_client *client;
  30. struct input_dev *input_dev;
  31. int use_irq;
  32. bool has_relative_report;
  33. struct hrtimer timer;
  34. struct work_struct work;
  35. uint16_t max[2];
  36. int snap_state[2][2];
  37. int snap_down_on[2];
  38. int snap_down_off[2];
  39. int snap_up_on[2];
  40. int snap_up_off[2];
  41. int snap_down[2];
  42. int snap_up[2];
  43. uint32_t flags;
  44. int reported_finger_count;
  45. int8_t sensitivity_adjust;
  46. int (*power)(int on);
  47. struct early_suspend early_suspend;
  48. };
  49. #ifdef CONFIG_HAS_EARLYSUSPEND
  50. static void synaptics_ts_early_suspend(struct early_suspend *h);
  51. static void synaptics_ts_late_resume(struct early_suspend *h);
  52. #endif
  53. static int synaptics_init_panel(struct synaptics_ts_data *ts)
  54. {
  55. int ret;
  56. ret = i2c_smbus_write_byte_data(ts->client, 0xff, 0x10); /* page select = 0x10 */
  57. if (ret < 0) {
  58. printk(KERN_ERR "i2c_smbus_write_byte_data failed for page select\n");
  59. goto err_page_select_failed;
  60. }
  61. ret = i2c_smbus_write_byte_data(ts->client, 0x41, 0x04); /* Set "No Clip Z" */
  62. if (ret < 0)
  63. printk(KERN_ERR "i2c_smbus_write_byte_data failed for No Clip Z\n");
  64. ret = i2c_smbus_write_byte_data(ts->client, 0x44,
  65. ts->sensitivity_adjust);
  66. if (ret < 0)
  67. pr_err("synaptics_ts: failed to set Sensitivity Adjust\n");
  68. err_page_select_failed:
  69. ret = i2c_smbus_write_byte_data(ts->client, 0xff, 0x04); /* page select = 0x04 */
  70. if (ret < 0)
  71. printk(KERN_ERR "i2c_smbus_write_byte_data failed for page select\n");
  72. ret = i2c_smbus_write_byte_data(ts->client, 0xf0, 0x81); /* normal operation, 80 reports per second */
  73. if (ret < 0)
  74. printk(KERN_ERR "synaptics_ts_resume: i2c_smbus_write_byte_data failed\n");
  75. return ret;
  76. }
  77. static void synaptics_ts_work_func(struct work_struct *work)
  78. {
  79. int i;
  80. int ret;
  81. int bad_data = 0;
  82. struct i2c_msg msg[2];
  83. uint8_t start_reg;
  84. uint8_t buf[15];
  85. struct synaptics_ts_data *ts = container_of(work, struct synaptics_ts_data, work);
  86. int buf_len = ts->has_relative_report ? 15 : 13;
  87. msg[0].addr = ts->client->addr;
  88. msg[0].flags = 0;
  89. msg[0].len = 1;
  90. msg[0].buf = &start_reg;
  91. start_reg = 0x00;
  92. msg[1].addr = ts->client->addr;
  93. msg[1].flags = I2C_M_RD;
  94. msg[1].len = buf_len;
  95. msg[1].buf = buf;
  96. /* printk("synaptics_ts_work_func\n"); */
  97. for (i = 0; i < ((ts->use_irq && !bad_data) ? 1 : 10); i++) {
  98. ret = i2c_transfer(ts->client->adapter, msg, 2);
  99. if (ret < 0) {
  100. printk(KERN_ERR "synaptics_ts_work_func: i2c_transfer failed\n");
  101. bad_data = 1;
  102. } else {
  103. /* printk("synaptics_ts_work_func: %x %x %x %x %x %x" */
  104. /* " %x %x %x %x %x %x %x %x %x, ret %d\n", */
  105. /* buf[0], buf[1], buf[2], buf[3], */
  106. /* buf[4], buf[5], buf[6], buf[7], */
  107. /* buf[8], buf[9], buf[10], buf[11], */
  108. /* buf[12], buf[13], buf[14], ret); */
  109. if ((buf[buf_len - 1] & 0xc0) != 0x40) {
  110. printk(KERN_WARNING "synaptics_ts_work_func:"
  111. " bad read %x %x %x %x %x %x %x %x %x"
  112. " %x %x %x %x %x %x, ret %d\n",
  113. buf[0], buf[1], buf[2], buf[3],
  114. buf[4], buf[5], buf[6], buf[7],
  115. buf[8], buf[9], buf[10], buf[11],
  116. buf[12], buf[13], buf[14], ret);
  117. if (bad_data)
  118. synaptics_init_panel(ts);
  119. bad_data = 1;
  120. continue;
  121. }
  122. bad_data = 0;
  123. if ((buf[buf_len - 1] & 1) == 0) {
  124. /* printk("read %d coordinates\n", i); */
  125. break;
  126. } else {
  127. int pos[2][2];
  128. int f, a;
  129. int base;
  130. /* int x = buf[3] | (uint16_t)(buf[2] & 0x1f) << 8; */
  131. /* int y = buf[5] | (uint16_t)(buf[4] & 0x1f) << 8; */
  132. int z = buf[1];
  133. int w = buf[0] >> 4;
  134. int finger = buf[0] & 7;
  135. /* int x2 = buf[3+6] | (uint16_t)(buf[2+6] & 0x1f) << 8; */
  136. /* int y2 = buf[5+6] | (uint16_t)(buf[4+6] & 0x1f) << 8; */
  137. /* int z2 = buf[1+6]; */
  138. /* int w2 = buf[0+6] >> 4; */
  139. /* int finger2 = buf[0+6] & 7; */
  140. /* int dx = (int8_t)buf[12]; */
  141. /* int dy = (int8_t)buf[13]; */
  142. int finger2_pressed;
  143. /* printk("x %4d, y %4d, z %3d, w %2d, F %d, 2nd: x %4d, y %4d, z %3d, w %2d, F %d, dx %4d, dy %4d\n", */
  144. /* x, y, z, w, finger, */
  145. /* x2, y2, z2, w2, finger2, */
  146. /* dx, dy); */
  147. base = 2;
  148. for (f = 0; f < 2; f++) {
  149. uint32_t flip_flag = SYNAPTICS_FLIP_X;
  150. for (a = 0; a < 2; a++) {
  151. int p = buf[base + 1];
  152. p |= (uint16_t)(buf[base] & 0x1f) << 8;
  153. if (ts->flags & flip_flag)
  154. p = ts->max[a] - p;
  155. if (ts->flags & SYNAPTICS_SNAP_TO_INACTIVE_EDGE) {
  156. if (ts->snap_state[f][a]) {
  157. if (p <= ts->snap_down_off[a])
  158. p = ts->snap_down[a];
  159. else if (p >= ts->snap_up_off[a])
  160. p = ts->snap_up[a];
  161. else
  162. ts->snap_state[f][a] = 0;
  163. } else {
  164. if (p <= ts->snap_down_on[a]) {
  165. p = ts->snap_down[a];
  166. ts->snap_state[f][a] = 1;
  167. } else if (p >= ts->snap_up_on[a]) {
  168. p = ts->snap_up[a];
  169. ts->snap_state[f][a] = 1;
  170. }
  171. }
  172. }
  173. pos[f][a] = p;
  174. base += 2;
  175. flip_flag <<= 1;
  176. }
  177. base += 2;
  178. if (ts->flags & SYNAPTICS_SWAP_XY)
  179. swap(pos[f][0], pos[f][1]);
  180. }
  181. if (z) {
  182. input_report_abs(ts->input_dev, ABS_X, pos[0][0]);
  183. input_report_abs(ts->input_dev, ABS_Y, pos[0][1]);
  184. }
  185. input_report_abs(ts->input_dev, ABS_PRESSURE, z);
  186. input_report_abs(ts->input_dev, ABS_TOOL_WIDTH, w);
  187. input_report_key(ts->input_dev, BTN_TOUCH, finger);
  188. finger2_pressed = finger > 1 && finger != 7;
  189. input_report_key(ts->input_dev, BTN_2, finger2_pressed);
  190. if (finger2_pressed) {
  191. input_report_abs(ts->input_dev, ABS_HAT0X, pos[1][0]);
  192. input_report_abs(ts->input_dev, ABS_HAT0Y, pos[1][1]);
  193. }
  194. if (!finger)
  195. z = 0;
  196. input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, z);
  197. input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
  198. input_report_abs(ts->input_dev, ABS_MT_POSITION_X, pos[0][0]);
  199. input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, pos[0][1]);
  200. input_mt_sync(ts->input_dev);
  201. if (finger2_pressed) {
  202. input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, z);
  203. input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
  204. input_report_abs(ts->input_dev, ABS_MT_POSITION_X, pos[1][0]);
  205. input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, pos[1][1]);
  206. input_mt_sync(ts->input_dev);
  207. } else if (ts->reported_finger_count > 1) {
  208. input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);
  209. input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);
  210. input_mt_sync(ts->input_dev);
  211. }
  212. ts->reported_finger_count = finger;
  213. input_sync(ts->input_dev);
  214. }
  215. }
  216. }
  217. if (ts->use_irq)
  218. enable_irq(ts->client->irq);
  219. }
  220. static enum hrtimer_restart synaptics_ts_timer_func(struct hrtimer *timer)
  221. {
  222. struct synaptics_ts_data *ts = container_of(timer, struct synaptics_ts_data, timer);
  223. /* printk("synaptics_ts_timer_func\n"); */
  224. queue_work(synaptics_wq, &ts->work);
  225. hrtimer_start(&ts->timer, ktime_set(0, 12500000), HRTIMER_MODE_REL);
  226. return HRTIMER_NORESTART;
  227. }
  228. static irqreturn_t synaptics_ts_irq_handler(int irq, void *dev_id)
  229. {
  230. struct synaptics_ts_data *ts = dev_id;
  231. /* printk("synaptics_ts_irq_handler\n"); */
  232. disable_irq_nosync(ts->client->irq);
  233. queue_work(synaptics_wq, &ts->work);
  234. return IRQ_HANDLED;
  235. }
  236. static int synaptics_ts_probe(
  237. struct i2c_client *client, const struct i2c_device_id *id)
  238. {
  239. struct synaptics_ts_data *ts;
  240. uint8_t buf0[4];
  241. uint8_t buf1[8];
  242. struct i2c_msg msg[2];
  243. int ret = 0;
  244. uint16_t max_x, max_y;
  245. int fuzz_x, fuzz_y, fuzz_p, fuzz_w;
  246. struct synaptics_i2c_rmi_platform_data *pdata;
  247. unsigned long irqflags;
  248. int inactive_area_left;
  249. int inactive_area_right;
  250. int inactive_area_top;
  251. int inactive_area_bottom;
  252. int snap_left_on;
  253. int snap_left_off;
  254. int snap_right_on;
  255. int snap_right_off;
  256. int snap_top_on;
  257. int snap_top_off;
  258. int snap_bottom_on;
  259. int snap_bottom_off;
  260. uint32_t panel_version;
  261. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  262. printk(KERN_ERR "synaptics_ts_probe: need I2C_FUNC_I2C\n");
  263. ret = -ENODEV;
  264. goto err_check_functionality_failed;
  265. }
  266. ts = kzalloc(sizeof(*ts), GFP_KERNEL);
  267. if (ts == NULL) {
  268. ret = -ENOMEM;
  269. goto err_alloc_data_failed;
  270. }
  271. INIT_WORK(&ts->work, synaptics_ts_work_func);
  272. ts->client = client;
  273. i2c_set_clientdata(client, ts);
  274. pdata = client->dev.platform_data;
  275. if (pdata)
  276. ts->power = pdata->power;
  277. if (ts->power) {
  278. ret = ts->power(1);
  279. if (ret < 0) {
  280. printk(KERN_ERR "synaptics_ts_probe power on failed\n");
  281. goto err_power_failed;
  282. }
  283. }
  284. ret = i2c_smbus_write_byte_data(ts->client, 0xf4, 0x01); /* device command = reset */
  285. if (ret < 0) {
  286. printk(KERN_ERR "i2c_smbus_write_byte_data failed\n");
  287. /* fail? */
  288. }
  289. {
  290. int retry = 10;
  291. while (retry-- > 0) {
  292. ret = i2c_smbus_read_byte_data(ts->client, 0xe4);
  293. if (ret >= 0)
  294. break;
  295. msleep(100);
  296. }
  297. }
  298. if (ret < 0) {
  299. printk(KERN_ERR "i2c_smbus_read_byte_data failed\n");
  300. goto err_detect_failed;
  301. }
  302. printk(KERN_INFO "synaptics_ts_probe: Product Major Version %x\n", ret);
  303. panel_version = ret << 8;
  304. ret = i2c_smbus_read_byte_data(ts->client, 0xe5);
  305. if (ret < 0) {
  306. printk(KERN_ERR "i2c_smbus_read_byte_data failed\n");
  307. goto err_detect_failed;
  308. }
  309. printk(KERN_INFO "synaptics_ts_probe: Product Minor Version %x\n", ret);
  310. panel_version |= ret;
  311. ret = i2c_smbus_read_byte_data(ts->client, 0xe3);
  312. if (ret < 0) {
  313. printk(KERN_ERR "i2c_smbus_read_byte_data failed\n");
  314. goto err_detect_failed;
  315. }
  316. printk(KERN_INFO "synaptics_ts_probe: product property %x\n", ret);
  317. if (pdata) {
  318. while (pdata->version > panel_version)
  319. pdata++;
  320. ts->flags = pdata->flags;
  321. ts->sensitivity_adjust = pdata->sensitivity_adjust;
  322. irqflags = pdata->irqflags;
  323. inactive_area_left = pdata->inactive_left;
  324. inactive_area_right = pdata->inactive_right;
  325. inactive_area_top = pdata->inactive_top;
  326. inactive_area_bottom = pdata->inactive_bottom;
  327. snap_left_on = pdata->snap_left_on;
  328. snap_left_off = pdata->snap_left_off;
  329. snap_right_on = pdata->snap_right_on;
  330. snap_right_off = pdata->snap_right_off;
  331. snap_top_on = pdata->snap_top_on;
  332. snap_top_off = pdata->snap_top_off;
  333. snap_bottom_on = pdata->snap_bottom_on;
  334. snap_bottom_off = pdata->snap_bottom_off;
  335. fuzz_x = pdata->fuzz_x;
  336. fuzz_y = pdata->fuzz_y;
  337. fuzz_p = pdata->fuzz_p;
  338. fuzz_w = pdata->fuzz_w;
  339. } else {
  340. irqflags = 0;
  341. inactive_area_left = 0;
  342. inactive_area_right = 0;
  343. inactive_area_top = 0;
  344. inactive_area_bottom = 0;
  345. snap_left_on = 0;
  346. snap_left_off = 0;
  347. snap_right_on = 0;
  348. snap_right_off = 0;
  349. snap_top_on = 0;
  350. snap_top_off = 0;
  351. snap_bottom_on = 0;
  352. snap_bottom_off = 0;
  353. fuzz_x = 0;
  354. fuzz_y = 0;
  355. fuzz_p = 0;
  356. fuzz_w = 0;
  357. }
  358. ret = i2c_smbus_read_byte_data(ts->client, 0xf0);
  359. if (ret < 0) {
  360. printk(KERN_ERR "i2c_smbus_read_byte_data failed\n");
  361. goto err_detect_failed;
  362. }
  363. printk(KERN_INFO "synaptics_ts_probe: device control %x\n", ret);
  364. ret = i2c_smbus_read_byte_data(ts->client, 0xf1);
  365. if (ret < 0) {
  366. printk(KERN_ERR "i2c_smbus_read_byte_data failed\n");
  367. goto err_detect_failed;
  368. }
  369. printk(KERN_INFO "synaptics_ts_probe: interrupt enable %x\n", ret);
  370. ret = i2c_smbus_write_byte_data(ts->client, 0xf1, 0); /* disable interrupt */
  371. if (ret < 0) {
  372. printk(KERN_ERR "i2c_smbus_write_byte_data failed\n");
  373. goto err_detect_failed;
  374. }
  375. msg[0].addr = ts->client->addr;
  376. msg[0].flags = 0;
  377. msg[0].len = 1;
  378. msg[0].buf = buf0;
  379. buf0[0] = 0xe0;
  380. msg[1].addr = ts->client->addr;
  381. msg[1].flags = I2C_M_RD;
  382. msg[1].len = 8;
  383. msg[1].buf = buf1;
  384. ret = i2c_transfer(ts->client->adapter, msg, 2);
  385. if (ret < 0) {
  386. printk(KERN_ERR "i2c_transfer failed\n");
  387. goto err_detect_failed;
  388. }
  389. printk(KERN_INFO "synaptics_ts_probe: 0xe0: %x %x %x %x %x %x %x %x\n",
  390. buf1[0], buf1[1], buf1[2], buf1[3],
  391. buf1[4], buf1[5], buf1[6], buf1[7]);
  392. ret = i2c_smbus_write_byte_data(ts->client, 0xff, 0x10); /* page select = 0x10 */
  393. if (ret < 0) {
  394. printk(KERN_ERR "i2c_smbus_write_byte_data failed for page select\n");
  395. goto err_detect_failed;
  396. }
  397. ret = i2c_smbus_read_word_data(ts->client, 0x02);
  398. if (ret < 0) {
  399. printk(KERN_ERR "i2c_smbus_read_word_data failed\n");
  400. goto err_detect_failed;
  401. }
  402. ts->has_relative_report = !(ret & 0x100);
  403. printk(KERN_INFO "synaptics_ts_probe: Sensor properties %x\n", ret);
  404. ret = i2c_smbus_read_word_data(ts->client, 0x04);
  405. if (ret < 0) {
  406. printk(KERN_ERR "i2c_smbus_read_word_data failed\n");
  407. goto err_detect_failed;
  408. }
  409. ts->max[0] = max_x = (ret >> 8 & 0xff) | ((ret & 0x1f) << 8);
  410. ret = i2c_smbus_read_word_data(ts->client, 0x06);
  411. if (ret < 0) {
  412. printk(KERN_ERR "i2c_smbus_read_word_data failed\n");
  413. goto err_detect_failed;
  414. }
  415. ts->max[1] = max_y = (ret >> 8 & 0xff) | ((ret & 0x1f) << 8);
  416. if (ts->flags & SYNAPTICS_SWAP_XY)
  417. swap(max_x, max_y);
  418. ret = synaptics_init_panel(ts); /* will also switch back to page 0x04 */
  419. if (ret < 0) {
  420. printk(KERN_ERR "synaptics_init_panel failed\n");
  421. goto err_detect_failed;
  422. }
  423. ts->input_dev = input_allocate_device();
  424. if (ts->input_dev == NULL) {
  425. ret = -ENOMEM;
  426. printk(KERN_ERR "synaptics_ts_probe: Failed to allocate input device\n");
  427. goto err_input_dev_alloc_failed;
  428. }
  429. ts->input_dev->name = "synaptics-rmi-touchscreen";
  430. set_bit(EV_SYN, ts->input_dev->evbit);
  431. set_bit(EV_KEY, ts->input_dev->evbit);
  432. set_bit(BTN_TOUCH, ts->input_dev->keybit);
  433. set_bit(BTN_2, ts->input_dev->keybit);
  434. set_bit(EV_ABS, ts->input_dev->evbit);
  435. inactive_area_left = inactive_area_left * max_x / 0x10000;
  436. inactive_area_right = inactive_area_right * max_x / 0x10000;
  437. inactive_area_top = inactive_area_top * max_y / 0x10000;
  438. inactive_area_bottom = inactive_area_bottom * max_y / 0x10000;
  439. snap_left_on = snap_left_on * max_x / 0x10000;
  440. snap_left_off = snap_left_off * max_x / 0x10000;
  441. snap_right_on = snap_right_on * max_x / 0x10000;
  442. snap_right_off = snap_right_off * max_x / 0x10000;
  443. snap_top_on = snap_top_on * max_y / 0x10000;
  444. snap_top_off = snap_top_off * max_y / 0x10000;
  445. snap_bottom_on = snap_bottom_on * max_y / 0x10000;
  446. snap_bottom_off = snap_bottom_off * max_y / 0x10000;
  447. fuzz_x = fuzz_x * max_x / 0x10000;
  448. fuzz_y = fuzz_y * max_y / 0x10000;
  449. ts->snap_down[!!(ts->flags & SYNAPTICS_SWAP_XY)] = -inactive_area_left;
  450. ts->snap_up[!!(ts->flags & SYNAPTICS_SWAP_XY)] = max_x + inactive_area_right;
  451. ts->snap_down[!(ts->flags & SYNAPTICS_SWAP_XY)] = -inactive_area_top;
  452. ts->snap_up[!(ts->flags & SYNAPTICS_SWAP_XY)] = max_y + inactive_area_bottom;
  453. ts->snap_down_on[!!(ts->flags & SYNAPTICS_SWAP_XY)] = snap_left_on;
  454. ts->snap_down_off[!!(ts->flags & SYNAPTICS_SWAP_XY)] = snap_left_off;
  455. ts->snap_up_on[!!(ts->flags & SYNAPTICS_SWAP_XY)] = max_x - snap_right_on;
  456. ts->snap_up_off[!!(ts->flags & SYNAPTICS_SWAP_XY)] = max_x - snap_right_off;
  457. ts->snap_down_on[!(ts->flags & SYNAPTICS_SWAP_XY)] = snap_top_on;
  458. ts->snap_down_off[!(ts->flags & SYNAPTICS_SWAP_XY)] = snap_top_off;
  459. ts->snap_up_on[!(ts->flags & SYNAPTICS_SWAP_XY)] = max_y - snap_bottom_on;
  460. ts->snap_up_off[!(ts->flags & SYNAPTICS_SWAP_XY)] = max_y - snap_bottom_off;
  461. printk(KERN_INFO "synaptics_ts_probe: max_x %d, max_y %d\n", max_x, max_y);
  462. printk(KERN_INFO "synaptics_ts_probe: inactive_x %d %d, inactive_y %d %d\n",
  463. inactive_area_left, inactive_area_right,
  464. inactive_area_top, inactive_area_bottom);
  465. printk(KERN_INFO "synaptics_ts_probe: snap_x %d-%d %d-%d, snap_y %d-%d %d-%d\n",
  466. snap_left_on, snap_left_off, snap_right_on, snap_right_off,
  467. snap_top_on, snap_top_off, snap_bottom_on, snap_bottom_off);
  468. input_set_abs_params(ts->input_dev, ABS_X, -inactive_area_left, max_x + inactive_area_right, fuzz_x, 0);
  469. input_set_abs_params(ts->input_dev, ABS_Y, -inactive_area_top, max_y + inactive_area_bottom, fuzz_y, 0);
  470. input_set_abs_params(ts->input_dev, ABS_PRESSURE, 0, 255, fuzz_p, 0);
  471. input_set_abs_params(ts->input_dev, ABS_TOOL_WIDTH, 0, 15, fuzz_w, 0);
  472. input_set_abs_params(ts->input_dev, ABS_HAT0X, -inactive_area_left, max_x + inactive_area_right, fuzz_x, 0);
  473. input_set_abs_params(ts->input_dev, ABS_HAT0Y, -inactive_area_top, max_y + inactive_area_bottom, fuzz_y, 0);
  474. input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, -inactive_area_left, max_x + inactive_area_right, fuzz_x, 0);
  475. input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, -inactive_area_top, max_y + inactive_area_bottom, fuzz_y, 0);
  476. input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, fuzz_p, 0);
  477. input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 15, fuzz_w, 0);
  478. /* ts->input_dev->name = ts->keypad_info->name; */
  479. ret = input_register_device(ts->input_dev);
  480. if (ret) {
  481. printk(KERN_ERR "synaptics_ts_probe: Unable to register %s input device\n", ts->input_dev->name);
  482. goto err_input_register_device_failed;
  483. }
  484. if (client->irq) {
  485. ret = request_irq(client->irq, synaptics_ts_irq_handler, irqflags, client->name, ts);
  486. if (ret == 0) {
  487. ret = i2c_smbus_write_byte_data(ts->client, 0xf1, 0x01); /* enable abs int */
  488. if (ret)
  489. free_irq(client->irq, ts);
  490. }
  491. if (ret == 0)
  492. ts->use_irq = 1;
  493. else
  494. dev_err(&client->dev, "request_irq failed\n");
  495. }
  496. if (!ts->use_irq) {
  497. hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  498. ts->timer.function = synaptics_ts_timer_func;
  499. hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
  500. }
  501. #ifdef CONFIG_HAS_EARLYSUSPEND
  502. ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
  503. ts->early_suspend.suspend = synaptics_ts_early_suspend;
  504. ts->early_suspend.resume = synaptics_ts_late_resume;
  505. register_early_suspend(&ts->early_suspend);
  506. #endif
  507. printk(KERN_INFO "synaptics_ts_probe: Start touchscreen %s in %s mode\n", ts->input_dev->name, ts->use_irq ? "interrupt" : "polling");
  508. return 0;
  509. err_input_register_device_failed:
  510. input_free_device(ts->input_dev);
  511. err_input_dev_alloc_failed:
  512. err_detect_failed:
  513. err_power_failed:
  514. kfree(ts);
  515. err_alloc_data_failed:
  516. err_check_functionality_failed:
  517. return ret;
  518. }
  519. static int synaptics_ts_remove(struct i2c_client *client)
  520. {
  521. struct synaptics_ts_data *ts = i2c_get_clientdata(client);
  522. unregister_early_suspend(&ts->early_suspend);
  523. if (ts->use_irq)
  524. free_irq(client->irq, ts);
  525. else
  526. hrtimer_cancel(&ts->timer);
  527. input_unregister_device(ts->input_dev);
  528. kfree(ts);
  529. return 0;
  530. }
  531. static int synaptics_ts_suspend(struct i2c_client *client, pm_message_t mesg)
  532. {
  533. int ret;
  534. struct synaptics_ts_data *ts = i2c_get_clientdata(client);
  535. if (ts->use_irq)
  536. disable_irq(client->irq);
  537. else
  538. hrtimer_cancel(&ts->timer);
  539. ret = cancel_work_sync(&ts->work);
  540. if (ret && ts->use_irq) /* if work was pending disable-count is now 2 */
  541. enable_irq(client->irq);
  542. ret = i2c_smbus_write_byte_data(ts->client, 0xf1, 0); /* disable interrupt */
  543. if (ret < 0)
  544. printk(KERN_ERR "synaptics_ts_suspend: i2c_smbus_write_byte_data failed\n");
  545. ret = i2c_smbus_write_byte_data(client, 0xf0, 0x86); /* deep sleep */
  546. if (ret < 0)
  547. printk(KERN_ERR "synaptics_ts_suspend: i2c_smbus_write_byte_data failed\n");
  548. if (ts->power) {
  549. ret = ts->power(0);
  550. if (ret < 0)
  551. printk(KERN_ERR "synaptics_ts_resume power off failed\n");
  552. }
  553. return 0;
  554. }
  555. static int synaptics_ts_resume(struct i2c_client *client)
  556. {
  557. int ret;
  558. struct synaptics_ts_data *ts = i2c_get_clientdata(client);
  559. if (ts->power) {
  560. ret = ts->power(1);
  561. if (ret < 0)
  562. printk(KERN_ERR "synaptics_ts_resume power on failed\n");
  563. }
  564. synaptics_init_panel(ts);
  565. if (ts->use_irq)
  566. enable_irq(client->irq);
  567. if (!ts->use_irq)
  568. hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
  569. else
  570. i2c_smbus_write_byte_data(ts->client, 0xf1, 0x01); /* enable abs int */
  571. return 0;
  572. }
  573. #ifdef CONFIG_HAS_EARLYSUSPEND
  574. static void synaptics_ts_early_suspend(struct early_suspend *h)
  575. {
  576. struct synaptics_ts_data *ts;
  577. ts = container_of(h, struct synaptics_ts_data, early_suspend);
  578. synaptics_ts_suspend(ts->client, PMSG_SUSPEND);
  579. }
  580. static void synaptics_ts_late_resume(struct early_suspend *h)
  581. {
  582. struct synaptics_ts_data *ts;
  583. ts = container_of(h, struct synaptics_ts_data, early_suspend);
  584. synaptics_ts_resume(ts->client);
  585. }
  586. #endif
  587. static const struct i2c_device_id synaptics_ts_id[] = {
  588. { SYNAPTICS_I2C_RMI_NAME, 0 },
  589. { }
  590. };
  591. static struct i2c_driver synaptics_ts_driver = {
  592. .probe = synaptics_ts_probe,
  593. .remove = synaptics_ts_remove,
  594. #ifndef CONFIG_HAS_EARLYSUSPEND
  595. .suspend = synaptics_ts_suspend,
  596. .resume = synaptics_ts_resume,
  597. #endif
  598. .id_table = synaptics_ts_id,
  599. .driver = {
  600. .name = SYNAPTICS_I2C_RMI_NAME,
  601. },
  602. };
  603. static int __devinit synaptics_ts_init(void)
  604. {
  605. synaptics_wq = create_singlethread_workqueue("synaptics_wq");
  606. if (!synaptics_wq)
  607. return -ENOMEM;
  608. return i2c_add_driver(&synaptics_ts_driver);
  609. }
  610. static void __exit synaptics_ts_exit(void)
  611. {
  612. i2c_del_driver(&synaptics_ts_driver);
  613. if (synaptics_wq)
  614. destroy_workqueue(synaptics_wq);
  615. }
  616. module_init(synaptics_ts_init);
  617. module_exit(synaptics_ts_exit);
  618. MODULE_DESCRIPTION("Synaptics Touchscreen Driver");
  619. MODULE_LICENSE("GPL");