synaptics_i2c.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /*
  2. * Synaptics touchpad with I2C interface
  3. *
  4. * Copyright (C) 2009 Compulab, Ltd.
  5. * Mike Rapoport <mike@compulab.co.il>
  6. * Igor Grinberg <grinberg@compulab.co.il>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file COPYING in the main directory of this archive for
  10. * more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/i2c.h>
  14. #include <linux/irq.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/input.h>
  17. #include <linux/delay.h>
  18. #include <linux/workqueue.h>
  19. #define DRIVER_NAME "synaptics_i2c"
  20. /* maximum product id is 15 characters */
  21. #define PRODUCT_ID_LENGTH 15
  22. #define REGISTER_LENGTH 8
  23. /*
  24. * after soft reset, we should wait for 1 ms
  25. * before the device becomes operational
  26. */
  27. #define SOFT_RESET_DELAY_MS 3
  28. /* and after hard reset, we should wait for max 500ms */
  29. #define HARD_RESET_DELAY_MS 500
  30. /* Registers by SMBus address */
  31. #define PAGE_SEL_REG 0xff
  32. #define DEVICE_STATUS_REG 0x09
  33. /* Registers by RMI address */
  34. #define DEV_CONTROL_REG 0x0000
  35. #define INTERRUPT_EN_REG 0x0001
  36. #define ERR_STAT_REG 0x0002
  37. #define INT_REQ_STAT_REG 0x0003
  38. #define DEV_COMMAND_REG 0x0004
  39. #define RMI_PROT_VER_REG 0x0200
  40. #define MANUFACT_ID_REG 0x0201
  41. #define PHYS_INT_VER_REG 0x0202
  42. #define PROD_PROPERTY_REG 0x0203
  43. #define INFO_QUERY_REG0 0x0204
  44. #define INFO_QUERY_REG1 (INFO_QUERY_REG0 + 1)
  45. #define INFO_QUERY_REG2 (INFO_QUERY_REG0 + 2)
  46. #define INFO_QUERY_REG3 (INFO_QUERY_REG0 + 3)
  47. #define PRODUCT_ID_REG0 0x0210
  48. #define PRODUCT_ID_REG1 (PRODUCT_ID_REG0 + 1)
  49. #define PRODUCT_ID_REG2 (PRODUCT_ID_REG0 + 2)
  50. #define PRODUCT_ID_REG3 (PRODUCT_ID_REG0 + 3)
  51. #define PRODUCT_ID_REG4 (PRODUCT_ID_REG0 + 4)
  52. #define PRODUCT_ID_REG5 (PRODUCT_ID_REG0 + 5)
  53. #define PRODUCT_ID_REG6 (PRODUCT_ID_REG0 + 6)
  54. #define PRODUCT_ID_REG7 (PRODUCT_ID_REG0 + 7)
  55. #define PRODUCT_ID_REG8 (PRODUCT_ID_REG0 + 8)
  56. #define PRODUCT_ID_REG9 (PRODUCT_ID_REG0 + 9)
  57. #define PRODUCT_ID_REG10 (PRODUCT_ID_REG0 + 10)
  58. #define PRODUCT_ID_REG11 (PRODUCT_ID_REG0 + 11)
  59. #define PRODUCT_ID_REG12 (PRODUCT_ID_REG0 + 12)
  60. #define PRODUCT_ID_REG13 (PRODUCT_ID_REG0 + 13)
  61. #define PRODUCT_ID_REG14 (PRODUCT_ID_REG0 + 14)
  62. #define PRODUCT_ID_REG15 (PRODUCT_ID_REG0 + 15)
  63. #define DATA_REG0 0x0400
  64. #define ABS_PRESSURE_REG 0x0401
  65. #define ABS_MSB_X_REG 0x0402
  66. #define ABS_LSB_X_REG (ABS_MSB_X_REG + 1)
  67. #define ABS_MSB_Y_REG 0x0404
  68. #define ABS_LSB_Y_REG (ABS_MSB_Y_REG + 1)
  69. #define REL_X_REG 0x0406
  70. #define REL_Y_REG 0x0407
  71. #define DEV_QUERY_REG0 0x1000
  72. #define DEV_QUERY_REG1 (DEV_QUERY_REG0 + 1)
  73. #define DEV_QUERY_REG2 (DEV_QUERY_REG0 + 2)
  74. #define DEV_QUERY_REG3 (DEV_QUERY_REG0 + 3)
  75. #define DEV_QUERY_REG4 (DEV_QUERY_REG0 + 4)
  76. #define DEV_QUERY_REG5 (DEV_QUERY_REG0 + 5)
  77. #define DEV_QUERY_REG6 (DEV_QUERY_REG0 + 6)
  78. #define DEV_QUERY_REG7 (DEV_QUERY_REG0 + 7)
  79. #define DEV_QUERY_REG8 (DEV_QUERY_REG0 + 8)
  80. #define GENERAL_2D_CONTROL_REG 0x1041
  81. #define SENSOR_SENSITIVITY_REG 0x1044
  82. #define SENS_MAX_POS_MSB_REG 0x1046
  83. #define SENS_MAX_POS_LSB_REG (SENS_MAX_POS_UPPER_REG + 1)
  84. /* Register bits */
  85. /* Device Control Register Bits */
  86. #define REPORT_RATE_1ST_BIT 6
  87. /* Interrupt Enable Register Bits (INTERRUPT_EN_REG) */
  88. #define F10_ABS_INT_ENA 0
  89. #define F10_REL_INT_ENA 1
  90. #define F20_INT_ENA 2
  91. /* Interrupt Request Register Bits (INT_REQ_STAT_REG | DEVICE_STATUS_REG) */
  92. #define F10_ABS_INT_REQ 0
  93. #define F10_REL_INT_REQ 1
  94. #define F20_INT_REQ 2
  95. /* Device Status Register Bits (DEVICE_STATUS_REG) */
  96. #define STAT_CONFIGURED 6
  97. #define STAT_ERROR 7
  98. /* Device Command Register Bits (DEV_COMMAND_REG) */
  99. #define RESET_COMMAND 0x01
  100. #define REZERO_COMMAND 0x02
  101. /* Data Register 0 Bits (DATA_REG0) */
  102. #define GESTURE 3
  103. /* Device Query Registers Bits */
  104. /* DEV_QUERY_REG3 */
  105. #define HAS_PALM_DETECT 1
  106. #define HAS_MULTI_FING 2
  107. #define HAS_SCROLLER 4
  108. #define HAS_2D_SCROLL 5
  109. /* General 2D Control Register Bits (GENERAL_2D_CONTROL_REG) */
  110. #define NO_DECELERATION 1
  111. #define REDUCE_REPORTING 3
  112. #define NO_FILTER 5
  113. /* Function Masks */
  114. /* Device Control Register Masks (DEV_CONTROL_REG) */
  115. #define REPORT_RATE_MSK 0xc0
  116. #define SLEEP_MODE_MSK 0x07
  117. /* Device Sleep Modes */
  118. #define FULL_AWAKE 0x0
  119. #define NORMAL_OP 0x1
  120. #define LOW_PWR_OP 0x2
  121. #define VERY_LOW_PWR_OP 0x3
  122. #define SENS_SLEEP 0x4
  123. #define SLEEP_MOD 0x5
  124. #define DEEP_SLEEP 0x6
  125. #define HIBERNATE 0x7
  126. /* Interrupt Register Mask */
  127. /* (INT_REQ_STAT_REG | DEVICE_STATUS_REG | INTERRUPT_EN_REG) */
  128. #define INT_ENA_REQ_MSK 0x07
  129. #define INT_ENA_ABS_MSK 0x01
  130. #define INT_ENA_REL_MSK 0x02
  131. #define INT_ENA_F20_MSK 0x04
  132. /* Device Status Register Masks (DEVICE_STATUS_REG) */
  133. #define CONFIGURED_MSK 0x40
  134. #define ERROR_MSK 0x80
  135. /* Data Register 0 Masks */
  136. #define FINGER_WIDTH_MSK 0xf0
  137. #define GESTURE_MSK 0x08
  138. #define SENSOR_STATUS_MSK 0x07
  139. /*
  140. * MSB Position Register Masks
  141. * ABS_MSB_X_REG | ABS_MSB_Y_REG | SENS_MAX_POS_MSB_REG |
  142. * DEV_QUERY_REG3 | DEV_QUERY_REG5
  143. */
  144. #define MSB_POSITION_MSK 0x1f
  145. /* Device Query Registers Masks */
  146. /* DEV_QUERY_REG2 */
  147. #define NUM_EXTRA_POS_MSK 0x07
  148. /* When in IRQ mode read the device every THREAD_IRQ_SLEEP_SECS */
  149. #define THREAD_IRQ_SLEEP_SECS 2
  150. #define THREAD_IRQ_SLEEP_MSECS (THREAD_IRQ_SLEEP_SECS * MSEC_PER_SEC)
  151. /*
  152. * When in Polling mode and no data received for NO_DATA_THRES msecs
  153. * reduce the polling rate to NO_DATA_SLEEP_MSECS
  154. */
  155. #define NO_DATA_THRES (MSEC_PER_SEC)
  156. #define NO_DATA_SLEEP_MSECS (MSEC_PER_SEC / 4)
  157. /* Control touchpad's No Deceleration option */
  158. static int no_decel = 1;
  159. module_param(no_decel, bool, 0644);
  160. MODULE_PARM_DESC(no_decel, "No Deceleration. Default = 1 (on)");
  161. /* Control touchpad's Reduced Reporting option */
  162. static int reduce_report;
  163. module_param(reduce_report, bool, 0644);
  164. MODULE_PARM_DESC(reduce_report, "Reduced Reporting. Default = 0 (off)");
  165. /* Control touchpad's No Filter option */
  166. static int no_filter;
  167. module_param(no_filter, bool, 0644);
  168. MODULE_PARM_DESC(no_filter, "No Filter. Default = 0 (off)");
  169. /*
  170. * touchpad Attention line is Active Low and Open Drain,
  171. * therefore should be connected to pulled up line
  172. * and the irq configuration should be set to Falling Edge Trigger
  173. */
  174. /* Control IRQ / Polling option */
  175. static int polling_req;
  176. module_param(polling_req, bool, 0444);
  177. MODULE_PARM_DESC(polling_req, "Request Polling. Default = 0 (use irq)");
  178. /* Control Polling Rate */
  179. static int scan_rate = 80;
  180. module_param(scan_rate, int, 0644);
  181. MODULE_PARM_DESC(scan_rate, "Polling rate in times/sec. Default = 80");
  182. /* The main device structure */
  183. struct synaptics_i2c {
  184. struct i2c_client *client;
  185. struct input_dev *input;
  186. struct delayed_work dwork;
  187. int no_data_count;
  188. int no_decel_param;
  189. int reduce_report_param;
  190. int no_filter_param;
  191. int scan_rate_param;
  192. int scan_ms;
  193. };
  194. static inline void set_scan_rate(struct synaptics_i2c *touch, int scan_rate)
  195. {
  196. touch->scan_ms = MSEC_PER_SEC / scan_rate;
  197. touch->scan_rate_param = scan_rate;
  198. }
  199. /*
  200. * Driver's initial design makes no race condition possible on i2c bus,
  201. * so there is no need in any locking.
  202. * Keep it in mind, while playing with the code.
  203. */
  204. static s32 synaptics_i2c_reg_get(struct i2c_client *client, u16 reg)
  205. {
  206. int ret;
  207. ret = i2c_smbus_write_byte_data(client, PAGE_SEL_REG, reg >> 8);
  208. if (ret == 0)
  209. ret = i2c_smbus_read_byte_data(client, reg & 0xff);
  210. return ret;
  211. }
  212. static s32 synaptics_i2c_reg_set(struct i2c_client *client, u16 reg, u8 val)
  213. {
  214. int ret;
  215. ret = i2c_smbus_write_byte_data(client, PAGE_SEL_REG, reg >> 8);
  216. if (ret == 0)
  217. ret = i2c_smbus_write_byte_data(client, reg & 0xff, val);
  218. return ret;
  219. }
  220. static s32 synaptics_i2c_word_get(struct i2c_client *client, u16 reg)
  221. {
  222. int ret;
  223. ret = i2c_smbus_write_byte_data(client, PAGE_SEL_REG, reg >> 8);
  224. if (ret == 0)
  225. ret = i2c_smbus_read_word_data(client, reg & 0xff);
  226. return ret;
  227. }
  228. static int synaptics_i2c_config(struct i2c_client *client)
  229. {
  230. int ret, control;
  231. u8 int_en;
  232. /* set Report Rate to Device Highest (>=80) and Sleep to normal */
  233. ret = synaptics_i2c_reg_set(client, DEV_CONTROL_REG, 0xc1);
  234. if (ret)
  235. return ret;
  236. /* set Interrupt Disable to Func20 / Enable to Func10) */
  237. int_en = (polling_req) ? 0 : INT_ENA_ABS_MSK | INT_ENA_REL_MSK;
  238. ret = synaptics_i2c_reg_set(client, INTERRUPT_EN_REG, int_en);
  239. if (ret)
  240. return ret;
  241. control = synaptics_i2c_reg_get(client, GENERAL_2D_CONTROL_REG);
  242. /* No Deceleration */
  243. control |= no_decel ? 1 << NO_DECELERATION : 0;
  244. /* Reduced Reporting */
  245. control |= reduce_report ? 1 << REDUCE_REPORTING : 0;
  246. /* No Filter */
  247. control |= no_filter ? 1 << NO_FILTER : 0;
  248. ret = synaptics_i2c_reg_set(client, GENERAL_2D_CONTROL_REG, control);
  249. if (ret)
  250. return ret;
  251. return 0;
  252. }
  253. static int synaptics_i2c_reset_config(struct i2c_client *client)
  254. {
  255. int ret;
  256. /* Reset the Touchpad */
  257. ret = synaptics_i2c_reg_set(client, DEV_COMMAND_REG, RESET_COMMAND);
  258. if (ret) {
  259. dev_err(&client->dev, "Unable to reset device\n");
  260. } else {
  261. msleep(SOFT_RESET_DELAY_MS);
  262. ret = synaptics_i2c_config(client);
  263. if (ret)
  264. dev_err(&client->dev, "Unable to config device\n");
  265. }
  266. return ret;
  267. }
  268. static int synaptics_i2c_check_error(struct i2c_client *client)
  269. {
  270. int status, ret = 0;
  271. status = i2c_smbus_read_byte_data(client, DEVICE_STATUS_REG) &
  272. (CONFIGURED_MSK | ERROR_MSK);
  273. if (status != CONFIGURED_MSK)
  274. ret = synaptics_i2c_reset_config(client);
  275. return ret;
  276. }
  277. static bool synaptics_i2c_get_input(struct synaptics_i2c *touch)
  278. {
  279. struct input_dev *input = touch->input;
  280. int xy_delta, gesture;
  281. s32 data;
  282. s8 x_delta, y_delta;
  283. /* Deal with spontanious resets and errors */
  284. if (synaptics_i2c_check_error(touch->client))
  285. return 0;
  286. /* Get Gesture Bit */
  287. data = synaptics_i2c_reg_get(touch->client, DATA_REG0);
  288. gesture = (data >> GESTURE) & 0x1;
  289. /*
  290. * Get Relative axes. we have to get them in one shot,
  291. * so we get 2 bytes starting from REL_X_REG.
  292. */
  293. xy_delta = synaptics_i2c_word_get(touch->client, REL_X_REG) & 0xffff;
  294. /* Separate X from Y */
  295. x_delta = xy_delta & 0xff;
  296. y_delta = (xy_delta >> REGISTER_LENGTH) & 0xff;
  297. /* Report the button event */
  298. input_report_key(input, BTN_LEFT, gesture);
  299. /* Report the deltas */
  300. input_report_rel(input, REL_X, x_delta);
  301. input_report_rel(input, REL_Y, -y_delta);
  302. input_sync(input);
  303. return xy_delta || gesture;
  304. }
  305. static irqreturn_t synaptics_i2c_irq(int irq, void *dev_id)
  306. {
  307. struct synaptics_i2c *touch = dev_id;
  308. /*
  309. * We want to have the work run immediately but it might have
  310. * already been scheduled with a delay, that's why we have to
  311. * cancel it first.
  312. */
  313. cancel_delayed_work(&touch->dwork);
  314. schedule_delayed_work(&touch->dwork, 0);
  315. return IRQ_HANDLED;
  316. }
  317. static void synaptics_i2c_check_params(struct synaptics_i2c *touch)
  318. {
  319. bool reset = false;
  320. if (scan_rate != touch->scan_rate_param)
  321. set_scan_rate(touch, scan_rate);
  322. if (no_decel != touch->no_decel_param) {
  323. touch->no_decel_param = no_decel;
  324. reset = true;
  325. }
  326. if (no_filter != touch->no_filter_param) {
  327. touch->no_filter_param = no_filter;
  328. reset = true;
  329. }
  330. if (reduce_report != touch->reduce_report_param) {
  331. touch->reduce_report_param = reduce_report;
  332. reset = true;
  333. }
  334. if (reset)
  335. synaptics_i2c_reset_config(touch->client);
  336. }
  337. /* Control the Device polling rate / Work Handler sleep time */
  338. unsigned long synaptics_i2c_adjust_delay(struct synaptics_i2c *touch,
  339. bool have_data)
  340. {
  341. unsigned long delay, nodata_count_thres;
  342. if (polling_req) {
  343. delay = touch->scan_ms;
  344. if (have_data) {
  345. touch->no_data_count = 0;
  346. } else {
  347. nodata_count_thres = NO_DATA_THRES / touch->scan_ms;
  348. if (touch->no_data_count < nodata_count_thres)
  349. touch->no_data_count++;
  350. else
  351. delay = NO_DATA_SLEEP_MSECS;
  352. }
  353. return msecs_to_jiffies(delay);
  354. } else {
  355. delay = msecs_to_jiffies(THREAD_IRQ_SLEEP_MSECS);
  356. return round_jiffies_relative(delay);
  357. }
  358. }
  359. /* Work Handler */
  360. static void synaptics_i2c_work_handler(struct work_struct *work)
  361. {
  362. bool have_data;
  363. struct synaptics_i2c *touch =
  364. container_of(work, struct synaptics_i2c, dwork.work);
  365. unsigned long delay;
  366. synaptics_i2c_check_params(touch);
  367. have_data = synaptics_i2c_get_input(touch);
  368. delay = synaptics_i2c_adjust_delay(touch, have_data);
  369. /*
  370. * While interrupt driven, there is no real need to poll the device.
  371. * But touchpads are very sensitive, so there could be errors
  372. * related to physical environment and the attention line isn't
  373. * neccesarily asserted. In such case we can lose the touchpad.
  374. * We poll the device once in THREAD_IRQ_SLEEP_SECS and
  375. * if error is detected, we try to reset and reconfigure the touchpad.
  376. */
  377. schedule_delayed_work(&touch->dwork, delay);
  378. }
  379. static int synaptics_i2c_open(struct input_dev *input)
  380. {
  381. struct synaptics_i2c *touch = input_get_drvdata(input);
  382. int ret;
  383. ret = synaptics_i2c_reset_config(touch->client);
  384. if (ret)
  385. return ret;
  386. if (polling_req)
  387. schedule_delayed_work(&touch->dwork,
  388. msecs_to_jiffies(NO_DATA_SLEEP_MSECS));
  389. return 0;
  390. }
  391. static void synaptics_i2c_close(struct input_dev *input)
  392. {
  393. struct synaptics_i2c *touch = input_get_drvdata(input);
  394. if (!polling_req)
  395. synaptics_i2c_reg_set(touch->client, INTERRUPT_EN_REG, 0);
  396. cancel_delayed_work_sync(&touch->dwork);
  397. /* Save some power */
  398. synaptics_i2c_reg_set(touch->client, DEV_CONTROL_REG, DEEP_SLEEP);
  399. }
  400. static void synaptics_i2c_set_input_params(struct synaptics_i2c *touch)
  401. {
  402. struct input_dev *input = touch->input;
  403. input->name = touch->client->name;
  404. input->phys = touch->client->adapter->name;
  405. input->id.bustype = BUS_I2C;
  406. input->id.version = synaptics_i2c_word_get(touch->client,
  407. INFO_QUERY_REG0);
  408. input->dev.parent = &touch->client->dev;
  409. input->open = synaptics_i2c_open;
  410. input->close = synaptics_i2c_close;
  411. input_set_drvdata(input, touch);
  412. /* Register the device as mouse */
  413. __set_bit(EV_REL, input->evbit);
  414. __set_bit(REL_X, input->relbit);
  415. __set_bit(REL_Y, input->relbit);
  416. /* Register device's buttons and keys */
  417. __set_bit(EV_KEY, input->evbit);
  418. __set_bit(BTN_LEFT, input->keybit);
  419. }
  420. struct synaptics_i2c *synaptics_i2c_touch_create(struct i2c_client *client)
  421. {
  422. struct synaptics_i2c *touch;
  423. touch = kzalloc(sizeof(struct synaptics_i2c), GFP_KERNEL);
  424. if (!touch)
  425. return NULL;
  426. touch->client = client;
  427. touch->no_decel_param = no_decel;
  428. touch->scan_rate_param = scan_rate;
  429. set_scan_rate(touch, scan_rate);
  430. INIT_DELAYED_WORK(&touch->dwork, synaptics_i2c_work_handler);
  431. return touch;
  432. }
  433. static int __devinit synaptics_i2c_probe(struct i2c_client *client,
  434. const struct i2c_device_id *dev_id)
  435. {
  436. int ret;
  437. struct synaptics_i2c *touch;
  438. touch = synaptics_i2c_touch_create(client);
  439. if (!touch)
  440. return -ENOMEM;
  441. i2c_set_clientdata(client, touch);
  442. ret = synaptics_i2c_reset_config(client);
  443. if (ret)
  444. goto err_mem_free;
  445. if (client->irq < 1)
  446. polling_req = 1;
  447. touch->input = input_allocate_device();
  448. if (!touch->input) {
  449. ret = -ENOMEM;
  450. goto err_mem_free;
  451. }
  452. synaptics_i2c_set_input_params(touch);
  453. if (!polling_req) {
  454. dev_dbg(&touch->client->dev,
  455. "Requesting IRQ: %d\n", touch->client->irq);
  456. ret = request_irq(touch->client->irq, synaptics_i2c_irq,
  457. IRQF_DISABLED|IRQ_TYPE_EDGE_FALLING,
  458. DRIVER_NAME, touch);
  459. if (ret) {
  460. dev_warn(&touch->client->dev,
  461. "IRQ request failed: %d, "
  462. "falling back to polling\n", ret);
  463. polling_req = 1;
  464. synaptics_i2c_reg_set(touch->client,
  465. INTERRUPT_EN_REG, 0);
  466. }
  467. }
  468. if (polling_req)
  469. dev_dbg(&touch->client->dev,
  470. "Using polling at rate: %d times/sec\n", scan_rate);
  471. /* Register the device in input subsystem */
  472. ret = input_register_device(touch->input);
  473. if (ret) {
  474. dev_err(&client->dev,
  475. "Input device register failed: %d\n", ret);
  476. goto err_input_free;
  477. }
  478. return 0;
  479. err_input_free:
  480. input_free_device(touch->input);
  481. err_mem_free:
  482. i2c_set_clientdata(client, NULL);
  483. kfree(touch);
  484. return ret;
  485. }
  486. static int __devexit synaptics_i2c_remove(struct i2c_client *client)
  487. {
  488. struct synaptics_i2c *touch = i2c_get_clientdata(client);
  489. if (!polling_req)
  490. free_irq(touch->client->irq, touch);
  491. input_unregister_device(touch->input);
  492. i2c_set_clientdata(client, NULL);
  493. kfree(touch);
  494. return 0;
  495. }
  496. #ifdef CONFIG_PM
  497. static int synaptics_i2c_suspend(struct i2c_client *client, pm_message_t mesg)
  498. {
  499. struct synaptics_i2c *touch = i2c_get_clientdata(client);
  500. cancel_delayed_work_sync(&touch->dwork);
  501. /* Save some power */
  502. synaptics_i2c_reg_set(touch->client, DEV_CONTROL_REG, DEEP_SLEEP);
  503. return 0;
  504. }
  505. static int synaptics_i2c_resume(struct i2c_client *client)
  506. {
  507. int ret;
  508. struct synaptics_i2c *touch = i2c_get_clientdata(client);
  509. ret = synaptics_i2c_reset_config(client);
  510. if (ret)
  511. return ret;
  512. schedule_delayed_work(&touch->dwork,
  513. msecs_to_jiffies(NO_DATA_SLEEP_MSECS));
  514. return 0;
  515. }
  516. #else
  517. #define synaptics_i2c_suspend NULL
  518. #define synaptics_i2c_resume NULL
  519. #endif
  520. static const struct i2c_device_id synaptics_i2c_id_table[] = {
  521. { "synaptics_i2c", 0 },
  522. { },
  523. };
  524. MODULE_DEVICE_TABLE(i2c, synaptics_i2c_id_table);
  525. static struct i2c_driver synaptics_i2c_driver = {
  526. .driver = {
  527. .name = DRIVER_NAME,
  528. .owner = THIS_MODULE,
  529. },
  530. .probe = synaptics_i2c_probe,
  531. .remove = __devexit_p(synaptics_i2c_remove),
  532. .suspend = synaptics_i2c_suspend,
  533. .resume = synaptics_i2c_resume,
  534. .id_table = synaptics_i2c_id_table,
  535. };
  536. static int __init synaptics_i2c_init(void)
  537. {
  538. return i2c_add_driver(&synaptics_i2c_driver);
  539. }
  540. static void __exit synaptics_i2c_exit(void)
  541. {
  542. i2c_del_driver(&synaptics_i2c_driver);
  543. }
  544. module_init(synaptics_i2c_init);
  545. module_exit(synaptics_i2c_exit);
  546. MODULE_DESCRIPTION("Synaptics I2C touchpad driver");
  547. MODULE_AUTHOR("Mike Rapoport, Igor Grinberg, Compulab");
  548. MODULE_LICENSE("GPL");