synaptics_i2c.c 17 KB

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