synaptics_i2c.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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_MS 3
  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. spinlock_t lock;
  190. int no_data_count;
  191. int no_decel_param;
  192. int reduce_report_param;
  193. int no_filter_param;
  194. int scan_rate_param;
  195. int scan_ms;
  196. };
  197. static inline void set_scan_rate(struct synaptics_i2c *touch, int scan_rate)
  198. {
  199. touch->scan_ms = MSEC_PER_SEC / scan_rate;
  200. touch->scan_rate_param = scan_rate;
  201. }
  202. /*
  203. * Driver's initial design makes no race condition possible on i2c bus,
  204. * so there is no need in any locking.
  205. * Keep it in mind, while playing with the code.
  206. */
  207. static s32 synaptics_i2c_reg_get(struct i2c_client *client, u16 reg)
  208. {
  209. int ret;
  210. ret = i2c_smbus_write_byte_data(client, PAGE_SEL_REG, reg >> 8);
  211. if (ret == 0)
  212. ret = i2c_smbus_read_byte_data(client, reg & 0xff);
  213. return ret;
  214. }
  215. static s32 synaptics_i2c_reg_set(struct i2c_client *client, u16 reg, u8 val)
  216. {
  217. int ret;
  218. ret = i2c_smbus_write_byte_data(client, PAGE_SEL_REG, reg >> 8);
  219. if (ret == 0)
  220. ret = i2c_smbus_write_byte_data(client, reg & 0xff, val);
  221. return ret;
  222. }
  223. static s32 synaptics_i2c_word_get(struct i2c_client *client, u16 reg)
  224. {
  225. int ret;
  226. ret = i2c_smbus_write_byte_data(client, PAGE_SEL_REG, reg >> 8);
  227. if (ret == 0)
  228. ret = i2c_smbus_read_word_data(client, reg & 0xff);
  229. return ret;
  230. }
  231. static int synaptics_i2c_config(struct i2c_client *client)
  232. {
  233. int ret, control;
  234. u8 int_en;
  235. /* set Report Rate to Device Highest (>=80) and Sleep to normal */
  236. ret = synaptics_i2c_reg_set(client, DEV_CONTROL_REG, 0xc1);
  237. if (ret)
  238. return ret;
  239. /* set Interrupt Disable to Func20 / Enable to Func10) */
  240. int_en = (polling_req) ? 0 : INT_ENA_ABS_MSK | INT_ENA_REL_MSK;
  241. ret = synaptics_i2c_reg_set(client, INTERRUPT_EN_REG, int_en);
  242. if (ret)
  243. return ret;
  244. control = synaptics_i2c_reg_get(client, GENERAL_2D_CONTROL_REG);
  245. /* No Deceleration */
  246. control |= no_decel ? 1 << NO_DECELERATION : 0;
  247. /* Reduced Reporting */
  248. control |= reduce_report ? 1 << REDUCE_REPORTING : 0;
  249. /* No Filter */
  250. control |= no_filter ? 1 << NO_FILTER : 0;
  251. ret = synaptics_i2c_reg_set(client, GENERAL_2D_CONTROL_REG, control);
  252. if (ret)
  253. return ret;
  254. return 0;
  255. }
  256. static int synaptics_i2c_reset_config(struct i2c_client *client)
  257. {
  258. int ret;
  259. /* Reset the Touchpad */
  260. ret = synaptics_i2c_reg_set(client, DEV_COMMAND_REG, RESET_COMMAND);
  261. if (ret) {
  262. dev_err(&client->dev, "Unable to reset device\n");
  263. } else {
  264. msleep(SOFT_RESET_DELAY_MS);
  265. ret = synaptics_i2c_config(client);
  266. if (ret)
  267. dev_err(&client->dev, "Unable to config device\n");
  268. }
  269. return ret;
  270. }
  271. static int synaptics_i2c_check_error(struct i2c_client *client)
  272. {
  273. int status, ret = 0;
  274. status = i2c_smbus_read_byte_data(client, DEVICE_STATUS_REG) &
  275. (CONFIGURED_MSK | ERROR_MSK);
  276. if (status != CONFIGURED_MSK)
  277. ret = synaptics_i2c_reset_config(client);
  278. return ret;
  279. }
  280. static bool synaptics_i2c_get_input(struct synaptics_i2c *touch)
  281. {
  282. struct input_dev *input = touch->input;
  283. int xy_delta, gesture;
  284. s32 data;
  285. s8 x_delta, y_delta;
  286. /* Deal with spontaneous resets and errors */
  287. if (synaptics_i2c_check_error(touch->client))
  288. return false;
  289. /* Get Gesture Bit */
  290. data = synaptics_i2c_reg_get(touch->client, DATA_REG0);
  291. gesture = (data >> GESTURE) & 0x1;
  292. /*
  293. * Get Relative axes. we have to get them in one shot,
  294. * so we get 2 bytes starting from REL_X_REG.
  295. */
  296. xy_delta = synaptics_i2c_word_get(touch->client, REL_X_REG) & 0xffff;
  297. /* Separate X from Y */
  298. x_delta = xy_delta & 0xff;
  299. y_delta = (xy_delta >> REGISTER_LENGTH) & 0xff;
  300. /* Report the button event */
  301. input_report_key(input, BTN_LEFT, gesture);
  302. /* Report the deltas */
  303. input_report_rel(input, REL_X, x_delta);
  304. input_report_rel(input, REL_Y, -y_delta);
  305. input_sync(input);
  306. return xy_delta || gesture;
  307. }
  308. static void synaptics_i2c_reschedule_work(struct synaptics_i2c *touch,
  309. unsigned long delay)
  310. {
  311. unsigned long flags;
  312. spin_lock_irqsave(&touch->lock, flags);
  313. mod_delayed_work(system_wq, &touch->dwork, delay);
  314. spin_unlock_irqrestore(&touch->lock, flags);
  315. }
  316. static irqreturn_t synaptics_i2c_irq(int irq, void *dev_id)
  317. {
  318. struct synaptics_i2c *touch = dev_id;
  319. synaptics_i2c_reschedule_work(touch, 0);
  320. return IRQ_HANDLED;
  321. }
  322. static void synaptics_i2c_check_params(struct synaptics_i2c *touch)
  323. {
  324. bool reset = false;
  325. if (scan_rate != touch->scan_rate_param)
  326. set_scan_rate(touch, scan_rate);
  327. if (no_decel != touch->no_decel_param) {
  328. touch->no_decel_param = no_decel;
  329. reset = true;
  330. }
  331. if (no_filter != touch->no_filter_param) {
  332. touch->no_filter_param = no_filter;
  333. reset = true;
  334. }
  335. if (reduce_report != touch->reduce_report_param) {
  336. touch->reduce_report_param = reduce_report;
  337. reset = true;
  338. }
  339. if (reset)
  340. synaptics_i2c_reset_config(touch->client);
  341. }
  342. /* Control the Device polling rate / Work Handler sleep time */
  343. static unsigned long synaptics_i2c_adjust_delay(struct synaptics_i2c *touch,
  344. bool have_data)
  345. {
  346. unsigned long delay, nodata_count_thres;
  347. if (polling_req) {
  348. delay = touch->scan_ms;
  349. if (have_data) {
  350. touch->no_data_count = 0;
  351. } else {
  352. nodata_count_thres = NO_DATA_THRES / touch->scan_ms;
  353. if (touch->no_data_count < nodata_count_thres)
  354. touch->no_data_count++;
  355. else
  356. delay = NO_DATA_SLEEP_MSECS;
  357. }
  358. return msecs_to_jiffies(delay);
  359. } else {
  360. delay = msecs_to_jiffies(THREAD_IRQ_SLEEP_MSECS);
  361. return round_jiffies_relative(delay);
  362. }
  363. }
  364. /* Work Handler */
  365. static void synaptics_i2c_work_handler(struct work_struct *work)
  366. {
  367. bool have_data;
  368. struct synaptics_i2c *touch =
  369. container_of(work, struct synaptics_i2c, dwork.work);
  370. unsigned long delay;
  371. synaptics_i2c_check_params(touch);
  372. have_data = synaptics_i2c_get_input(touch);
  373. delay = synaptics_i2c_adjust_delay(touch, have_data);
  374. /*
  375. * While interrupt driven, there is no real need to poll the device.
  376. * But touchpads are very sensitive, so there could be errors
  377. * related to physical environment and the attention line isn't
  378. * necessarily asserted. In such case we can lose the touchpad.
  379. * We poll the device once in THREAD_IRQ_SLEEP_SECS and
  380. * if error is detected, we try to reset and reconfigure the touchpad.
  381. */
  382. synaptics_i2c_reschedule_work(touch, delay);
  383. }
  384. static int synaptics_i2c_open(struct input_dev *input)
  385. {
  386. struct synaptics_i2c *touch = input_get_drvdata(input);
  387. int ret;
  388. ret = synaptics_i2c_reset_config(touch->client);
  389. if (ret)
  390. return ret;
  391. if (polling_req)
  392. synaptics_i2c_reschedule_work(touch,
  393. msecs_to_jiffies(NO_DATA_SLEEP_MSECS));
  394. return 0;
  395. }
  396. static void synaptics_i2c_close(struct input_dev *input)
  397. {
  398. struct synaptics_i2c *touch = input_get_drvdata(input);
  399. if (!polling_req)
  400. synaptics_i2c_reg_set(touch->client, INTERRUPT_EN_REG, 0);
  401. cancel_delayed_work_sync(&touch->dwork);
  402. /* Save some power */
  403. synaptics_i2c_reg_set(touch->client, DEV_CONTROL_REG, DEEP_SLEEP);
  404. }
  405. static void synaptics_i2c_set_input_params(struct synaptics_i2c *touch)
  406. {
  407. struct input_dev *input = touch->input;
  408. input->name = touch->client->name;
  409. input->phys = touch->client->adapter->name;
  410. input->id.bustype = BUS_I2C;
  411. input->id.version = synaptics_i2c_word_get(touch->client,
  412. INFO_QUERY_REG0);
  413. input->dev.parent = &touch->client->dev;
  414. input->open = synaptics_i2c_open;
  415. input->close = synaptics_i2c_close;
  416. input_set_drvdata(input, touch);
  417. /* Register the device as mouse */
  418. __set_bit(EV_REL, input->evbit);
  419. __set_bit(REL_X, input->relbit);
  420. __set_bit(REL_Y, input->relbit);
  421. /* Register device's buttons and keys */
  422. __set_bit(EV_KEY, input->evbit);
  423. __set_bit(BTN_LEFT, input->keybit);
  424. }
  425. static struct synaptics_i2c *synaptics_i2c_touch_create(struct i2c_client *client)
  426. {
  427. struct synaptics_i2c *touch;
  428. touch = kzalloc(sizeof(struct synaptics_i2c), GFP_KERNEL);
  429. if (!touch)
  430. return NULL;
  431. touch->client = client;
  432. touch->no_decel_param = no_decel;
  433. touch->scan_rate_param = scan_rate;
  434. set_scan_rate(touch, scan_rate);
  435. INIT_DELAYED_WORK(&touch->dwork, synaptics_i2c_work_handler);
  436. spin_lock_init(&touch->lock);
  437. return touch;
  438. }
  439. static int synaptics_i2c_probe(struct i2c_client *client,
  440. const struct i2c_device_id *dev_id)
  441. {
  442. int ret;
  443. struct synaptics_i2c *touch;
  444. touch = synaptics_i2c_touch_create(client);
  445. if (!touch)
  446. return -ENOMEM;
  447. ret = synaptics_i2c_reset_config(client);
  448. if (ret)
  449. goto err_mem_free;
  450. if (client->irq < 1)
  451. polling_req = true;
  452. touch->input = input_allocate_device();
  453. if (!touch->input) {
  454. ret = -ENOMEM;
  455. goto err_mem_free;
  456. }
  457. synaptics_i2c_set_input_params(touch);
  458. if (!polling_req) {
  459. dev_dbg(&touch->client->dev,
  460. "Requesting IRQ: %d\n", touch->client->irq);
  461. ret = request_irq(touch->client->irq, synaptics_i2c_irq,
  462. IRQ_TYPE_EDGE_FALLING,
  463. DRIVER_NAME, touch);
  464. if (ret) {
  465. dev_warn(&touch->client->dev,
  466. "IRQ request failed: %d, "
  467. "falling back to polling\n", ret);
  468. polling_req = true;
  469. synaptics_i2c_reg_set(touch->client,
  470. INTERRUPT_EN_REG, 0);
  471. }
  472. }
  473. if (polling_req)
  474. dev_dbg(&touch->client->dev,
  475. "Using polling at rate: %d times/sec\n", scan_rate);
  476. /* Register the device in input subsystem */
  477. ret = input_register_device(touch->input);
  478. if (ret) {
  479. dev_err(&client->dev,
  480. "Input device register failed: %d\n", ret);
  481. goto err_input_free;
  482. }
  483. i2c_set_clientdata(client, touch);
  484. return 0;
  485. err_input_free:
  486. input_free_device(touch->input);
  487. err_mem_free:
  488. kfree(touch);
  489. return ret;
  490. }
  491. static int synaptics_i2c_remove(struct i2c_client *client)
  492. {
  493. struct synaptics_i2c *touch = i2c_get_clientdata(client);
  494. if (!polling_req)
  495. free_irq(client->irq, touch);
  496. input_unregister_device(touch->input);
  497. kfree(touch);
  498. return 0;
  499. }
  500. static int __maybe_unused synaptics_i2c_suspend(struct device *dev)
  501. {
  502. struct i2c_client *client = to_i2c_client(dev);
  503. struct synaptics_i2c *touch = i2c_get_clientdata(client);
  504. cancel_delayed_work_sync(&touch->dwork);
  505. /* Save some power */
  506. synaptics_i2c_reg_set(touch->client, DEV_CONTROL_REG, DEEP_SLEEP);
  507. return 0;
  508. }
  509. static int __maybe_unused synaptics_i2c_resume(struct device *dev)
  510. {
  511. int ret;
  512. struct i2c_client *client = to_i2c_client(dev);
  513. struct synaptics_i2c *touch = i2c_get_clientdata(client);
  514. ret = synaptics_i2c_reset_config(client);
  515. if (ret)
  516. return ret;
  517. synaptics_i2c_reschedule_work(touch,
  518. msecs_to_jiffies(NO_DATA_SLEEP_MSECS));
  519. return 0;
  520. }
  521. static SIMPLE_DEV_PM_OPS(synaptics_i2c_pm, synaptics_i2c_suspend,
  522. synaptics_i2c_resume);
  523. static const struct i2c_device_id synaptics_i2c_id_table[] = {
  524. { "synaptics_i2c", 0 },
  525. { },
  526. };
  527. MODULE_DEVICE_TABLE(i2c, synaptics_i2c_id_table);
  528. static struct i2c_driver synaptics_i2c_driver = {
  529. .driver = {
  530. .name = DRIVER_NAME,
  531. .pm = &synaptics_i2c_pm,
  532. },
  533. .probe = synaptics_i2c_probe,
  534. .remove = synaptics_i2c_remove,
  535. .id_table = synaptics_i2c_id_table,
  536. };
  537. module_i2c_driver(synaptics_i2c_driver);
  538. MODULE_DESCRIPTION("Synaptics I2C touchpad driver");
  539. MODULE_AUTHOR("Mike Rapoport, Igor Grinberg, Compulab");
  540. MODULE_LICENSE("GPL");