synaptics_i2c.c 17 KB

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