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. #include <linux/slab.h>
  20. #define DRIVER_NAME "synaptics_i2c"
  21. /* maximum product id is 15 characters */
  22. #define PRODUCT_ID_LENGTH 15
  23. #define REGISTER_LENGTH 8
  24. /*
  25. * after soft reset, we should wait for 1 ms
  26. * before the device becomes operational
  27. */
  28. #define SOFT_RESET_DELAY_MS 3
  29. /* and after hard reset, we should wait for max 500ms */
  30. #define HARD_RESET_DELAY_MS 500
  31. /* Registers by SMBus address */
  32. #define PAGE_SEL_REG 0xff
  33. #define DEVICE_STATUS_REG 0x09
  34. /* Registers by RMI address */
  35. #define DEV_CONTROL_REG 0x0000
  36. #define INTERRUPT_EN_REG 0x0001
  37. #define ERR_STAT_REG 0x0002
  38. #define INT_REQ_STAT_REG 0x0003
  39. #define DEV_COMMAND_REG 0x0004
  40. #define RMI_PROT_VER_REG 0x0200
  41. #define MANUFACT_ID_REG 0x0201
  42. #define PHYS_INT_VER_REG 0x0202
  43. #define PROD_PROPERTY_REG 0x0203
  44. #define INFO_QUERY_REG0 0x0204
  45. #define INFO_QUERY_REG1 (INFO_QUERY_REG0 + 1)
  46. #define INFO_QUERY_REG2 (INFO_QUERY_REG0 + 2)
  47. #define INFO_QUERY_REG3 (INFO_QUERY_REG0 + 3)
  48. #define PRODUCT_ID_REG0 0x0210
  49. #define PRODUCT_ID_REG1 (PRODUCT_ID_REG0 + 1)
  50. #define PRODUCT_ID_REG2 (PRODUCT_ID_REG0 + 2)
  51. #define PRODUCT_ID_REG3 (PRODUCT_ID_REG0 + 3)
  52. #define PRODUCT_ID_REG4 (PRODUCT_ID_REG0 + 4)
  53. #define PRODUCT_ID_REG5 (PRODUCT_ID_REG0 + 5)
  54. #define PRODUCT_ID_REG6 (PRODUCT_ID_REG0 + 6)
  55. #define PRODUCT_ID_REG7 (PRODUCT_ID_REG0 + 7)
  56. #define PRODUCT_ID_REG8 (PRODUCT_ID_REG0 + 8)
  57. #define PRODUCT_ID_REG9 (PRODUCT_ID_REG0 + 9)
  58. #define PRODUCT_ID_REG10 (PRODUCT_ID_REG0 + 10)
  59. #define PRODUCT_ID_REG11 (PRODUCT_ID_REG0 + 11)
  60. #define PRODUCT_ID_REG12 (PRODUCT_ID_REG0 + 12)
  61. #define PRODUCT_ID_REG13 (PRODUCT_ID_REG0 + 13)
  62. #define PRODUCT_ID_REG14 (PRODUCT_ID_REG0 + 14)
  63. #define PRODUCT_ID_REG15 (PRODUCT_ID_REG0 + 15)
  64. #define DATA_REG0 0x0400
  65. #define ABS_PRESSURE_REG 0x0401
  66. #define ABS_MSB_X_REG 0x0402
  67. #define ABS_LSB_X_REG (ABS_MSB_X_REG + 1)
  68. #define ABS_MSB_Y_REG 0x0404
  69. #define ABS_LSB_Y_REG (ABS_MSB_Y_REG + 1)
  70. #define REL_X_REG 0x0406
  71. #define REL_Y_REG 0x0407
  72. #define DEV_QUERY_REG0 0x1000
  73. #define DEV_QUERY_REG1 (DEV_QUERY_REG0 + 1)
  74. #define DEV_QUERY_REG2 (DEV_QUERY_REG0 + 2)
  75. #define DEV_QUERY_REG3 (DEV_QUERY_REG0 + 3)
  76. #define DEV_QUERY_REG4 (DEV_QUERY_REG0 + 4)
  77. #define DEV_QUERY_REG5 (DEV_QUERY_REG0 + 5)
  78. #define DEV_QUERY_REG6 (DEV_QUERY_REG0 + 6)
  79. #define DEV_QUERY_REG7 (DEV_QUERY_REG0 + 7)
  80. #define DEV_QUERY_REG8 (DEV_QUERY_REG0 + 8)
  81. #define GENERAL_2D_CONTROL_REG 0x1041
  82. #define SENSOR_SENSITIVITY_REG 0x1044
  83. #define SENS_MAX_POS_MSB_REG 0x1046
  84. #define SENS_MAX_POS_LSB_REG (SENS_MAX_POS_UPPER_REG + 1)
  85. /* Register bits */
  86. /* Device Control Register Bits */
  87. #define REPORT_RATE_1ST_BIT 6
  88. /* Interrupt Enable Register Bits (INTERRUPT_EN_REG) */
  89. #define F10_ABS_INT_ENA 0
  90. #define F10_REL_INT_ENA 1
  91. #define F20_INT_ENA 2
  92. /* Interrupt Request Register Bits (INT_REQ_STAT_REG | DEVICE_STATUS_REG) */
  93. #define F10_ABS_INT_REQ 0
  94. #define F10_REL_INT_REQ 1
  95. #define F20_INT_REQ 2
  96. /* Device Status Register Bits (DEVICE_STATUS_REG) */
  97. #define STAT_CONFIGURED 6
  98. #define STAT_ERROR 7
  99. /* Device Command Register Bits (DEV_COMMAND_REG) */
  100. #define RESET_COMMAND 0x01
  101. #define REZERO_COMMAND 0x02
  102. /* Data Register 0 Bits (DATA_REG0) */
  103. #define GESTURE 3
  104. /* Device Query Registers Bits */
  105. /* DEV_QUERY_REG3 */
  106. #define HAS_PALM_DETECT 1
  107. #define HAS_MULTI_FING 2
  108. #define HAS_SCROLLER 4
  109. #define HAS_2D_SCROLL 5
  110. /* General 2D Control Register Bits (GENERAL_2D_CONTROL_REG) */
  111. #define NO_DECELERATION 1
  112. #define REDUCE_REPORTING 3
  113. #define NO_FILTER 5
  114. /* Function Masks */
  115. /* Device Control Register Masks (DEV_CONTROL_REG) */
  116. #define REPORT_RATE_MSK 0xc0
  117. #define SLEEP_MODE_MSK 0x07
  118. /* Device Sleep Modes */
  119. #define FULL_AWAKE 0x0
  120. #define NORMAL_OP 0x1
  121. #define LOW_PWR_OP 0x2
  122. #define VERY_LOW_PWR_OP 0x3
  123. #define SENS_SLEEP 0x4
  124. #define SLEEP_MOD 0x5
  125. #define DEEP_SLEEP 0x6
  126. #define HIBERNATE 0x7
  127. /* Interrupt Register Mask */
  128. /* (INT_REQ_STAT_REG | DEVICE_STATUS_REG | INTERRUPT_EN_REG) */
  129. #define INT_ENA_REQ_MSK 0x07
  130. #define INT_ENA_ABS_MSK 0x01
  131. #define INT_ENA_REL_MSK 0x02
  132. #define INT_ENA_F20_MSK 0x04
  133. /* Device Status Register Masks (DEVICE_STATUS_REG) */
  134. #define CONFIGURED_MSK 0x40
  135. #define ERROR_MSK 0x80
  136. /* Data Register 0 Masks */
  137. #define FINGER_WIDTH_MSK 0xf0
  138. #define GESTURE_MSK 0x08
  139. #define SENSOR_STATUS_MSK 0x07
  140. /*
  141. * MSB Position Register Masks
  142. * ABS_MSB_X_REG | ABS_MSB_Y_REG | SENS_MAX_POS_MSB_REG |
  143. * DEV_QUERY_REG3 | DEV_QUERY_REG5
  144. */
  145. #define MSB_POSITION_MSK 0x1f
  146. /* Device Query Registers Masks */
  147. /* DEV_QUERY_REG2 */
  148. #define NUM_EXTRA_POS_MSK 0x07
  149. /* When in IRQ mode read the device every THREAD_IRQ_SLEEP_SECS */
  150. #define THREAD_IRQ_SLEEP_SECS 2
  151. #define THREAD_IRQ_SLEEP_MSECS (THREAD_IRQ_SLEEP_SECS * MSEC_PER_SEC)
  152. /*
  153. * When in Polling mode and no data received for NO_DATA_THRES msecs
  154. * reduce the polling rate to NO_DATA_SLEEP_MSECS
  155. */
  156. #define NO_DATA_THRES (MSEC_PER_SEC)
  157. #define NO_DATA_SLEEP_MSECS (MSEC_PER_SEC / 4)
  158. /* Control touchpad's No Deceleration option */
  159. static int no_decel = 1;
  160. module_param(no_decel, bool, 0644);
  161. MODULE_PARM_DESC(no_decel, "No Deceleration. Default = 1 (on)");
  162. /* Control touchpad's Reduced Reporting option */
  163. static int reduce_report;
  164. module_param(reduce_report, bool, 0644);
  165. MODULE_PARM_DESC(reduce_report, "Reduced Reporting. Default = 0 (off)");
  166. /* Control touchpad's No Filter option */
  167. static int no_filter;
  168. module_param(no_filter, bool, 0644);
  169. MODULE_PARM_DESC(no_filter, "No Filter. Default = 0 (off)");
  170. /*
  171. * touchpad Attention line is Active Low and Open Drain,
  172. * therefore should be connected to pulled up line
  173. * and the irq configuration should be set to Falling Edge Trigger
  174. */
  175. /* Control IRQ / Polling option */
  176. static bool polling_req;
  177. module_param(polling_req, bool, 0444);
  178. MODULE_PARM_DESC(polling_req, "Request Polling. Default = 0 (use irq)");
  179. /* Control Polling Rate */
  180. static int scan_rate = 80;
  181. module_param(scan_rate, int, 0644);
  182. MODULE_PARM_DESC(scan_rate, "Polling rate in times/sec. Default = 80");
  183. /* The main device structure */
  184. struct synaptics_i2c {
  185. struct i2c_client *client;
  186. struct input_dev *input;
  187. struct delayed_work dwork;
  188. spinlock_t lock;
  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. msleep(SOFT_RESET_DELAY_MS);
  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 spontanious resets and errors */
  286. if (synaptics_i2c_check_error(touch->client))
  287. return 0;
  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 void synaptics_i2c_reschedule_work(struct synaptics_i2c *touch,
  308. unsigned long delay)
  309. {
  310. unsigned long flags;
  311. spin_lock_irqsave(&touch->lock, flags);
  312. /*
  313. * If work is already scheduled then subsequent schedules will not
  314. * change the scheduled time that's why we have to cancel it first.
  315. */
  316. __cancel_delayed_work(&touch->dwork);
  317. schedule_delayed_work(&touch->dwork, delay);
  318. spin_unlock_irqrestore(&touch->lock, flags);
  319. }
  320. static irqreturn_t synaptics_i2c_irq(int irq, void *dev_id)
  321. {
  322. struct synaptics_i2c *touch = dev_id;
  323. synaptics_i2c_reschedule_work(touch, 0);
  324. return IRQ_HANDLED;
  325. }
  326. static void synaptics_i2c_check_params(struct synaptics_i2c *touch)
  327. {
  328. bool reset = false;
  329. if (scan_rate != touch->scan_rate_param)
  330. set_scan_rate(touch, scan_rate);
  331. if (no_decel != touch->no_decel_param) {
  332. touch->no_decel_param = no_decel;
  333. reset = true;
  334. }
  335. if (no_filter != touch->no_filter_param) {
  336. touch->no_filter_param = no_filter;
  337. reset = true;
  338. }
  339. if (reduce_report != touch->reduce_report_param) {
  340. touch->reduce_report_param = reduce_report;
  341. reset = true;
  342. }
  343. if (reset)
  344. synaptics_i2c_reset_config(touch->client);
  345. }
  346. /* Control the Device polling rate / Work Handler sleep time */
  347. static unsigned long synaptics_i2c_adjust_delay(struct synaptics_i2c *touch,
  348. bool have_data)
  349. {
  350. unsigned long delay, nodata_count_thres;
  351. if (polling_req) {
  352. delay = touch->scan_ms;
  353. if (have_data) {
  354. touch->no_data_count = 0;
  355. } else {
  356. nodata_count_thres = NO_DATA_THRES / touch->scan_ms;
  357. if (touch->no_data_count < nodata_count_thres)
  358. touch->no_data_count++;
  359. else
  360. delay = NO_DATA_SLEEP_MSECS;
  361. }
  362. return msecs_to_jiffies(delay);
  363. } else {
  364. delay = msecs_to_jiffies(THREAD_IRQ_SLEEP_MSECS);
  365. return round_jiffies_relative(delay);
  366. }
  367. }
  368. /* Work Handler */
  369. static void synaptics_i2c_work_handler(struct work_struct *work)
  370. {
  371. bool have_data;
  372. struct synaptics_i2c *touch =
  373. container_of(work, struct synaptics_i2c, dwork.work);
  374. unsigned long delay;
  375. synaptics_i2c_check_params(touch);
  376. have_data = synaptics_i2c_get_input(touch);
  377. delay = synaptics_i2c_adjust_delay(touch, have_data);
  378. /*
  379. * While interrupt driven, there is no real need to poll the device.
  380. * But touchpads are very sensitive, so there could be errors
  381. * related to physical environment and the attention line isn't
  382. * neccesarily asserted. In such case we can lose the touchpad.
  383. * We poll the device once in THREAD_IRQ_SLEEP_SECS and
  384. * if error is detected, we try to reset and reconfigure the touchpad.
  385. */
  386. synaptics_i2c_reschedule_work(touch, delay);
  387. }
  388. static int synaptics_i2c_open(struct input_dev *input)
  389. {
  390. struct synaptics_i2c *touch = input_get_drvdata(input);
  391. int ret;
  392. ret = synaptics_i2c_reset_config(touch->client);
  393. if (ret)
  394. return ret;
  395. if (polling_req)
  396. synaptics_i2c_reschedule_work(touch,
  397. msecs_to_jiffies(NO_DATA_SLEEP_MSECS));
  398. return 0;
  399. }
  400. static void synaptics_i2c_close(struct input_dev *input)
  401. {
  402. struct synaptics_i2c *touch = input_get_drvdata(input);
  403. if (!polling_req)
  404. synaptics_i2c_reg_set(touch->client, INTERRUPT_EN_REG, 0);
  405. cancel_delayed_work_sync(&touch->dwork);
  406. /* Save some power */
  407. synaptics_i2c_reg_set(touch->client, DEV_CONTROL_REG, DEEP_SLEEP);
  408. }
  409. static void synaptics_i2c_set_input_params(struct synaptics_i2c *touch)
  410. {
  411. struct input_dev *input = touch->input;
  412. input->name = touch->client->name;
  413. input->phys = touch->client->adapter->name;
  414. input->id.bustype = BUS_I2C;
  415. input->id.version = synaptics_i2c_word_get(touch->client,
  416. INFO_QUERY_REG0);
  417. input->dev.parent = &touch->client->dev;
  418. input->open = synaptics_i2c_open;
  419. input->close = synaptics_i2c_close;
  420. input_set_drvdata(input, touch);
  421. /* Register the device as mouse */
  422. __set_bit(EV_REL, input->evbit);
  423. __set_bit(REL_X, input->relbit);
  424. __set_bit(REL_Y, input->relbit);
  425. /* Register device's buttons and keys */
  426. __set_bit(EV_KEY, input->evbit);
  427. __set_bit(BTN_LEFT, input->keybit);
  428. }
  429. static struct synaptics_i2c *synaptics_i2c_touch_create(struct i2c_client *client)
  430. {
  431. struct synaptics_i2c *touch;
  432. touch = kzalloc(sizeof(struct synaptics_i2c), GFP_KERNEL);
  433. if (!touch)
  434. return NULL;
  435. touch->client = client;
  436. touch->no_decel_param = no_decel;
  437. touch->scan_rate_param = scan_rate;
  438. set_scan_rate(touch, scan_rate);
  439. INIT_DELAYED_WORK(&touch->dwork, synaptics_i2c_work_handler);
  440. spin_lock_init(&touch->lock);
  441. return touch;
  442. }
  443. static int __devinit synaptics_i2c_probe(struct i2c_client *client,
  444. const struct i2c_device_id *dev_id)
  445. {
  446. int ret;
  447. struct synaptics_i2c *touch;
  448. touch = synaptics_i2c_touch_create(client);
  449. if (!touch)
  450. return -ENOMEM;
  451. ret = synaptics_i2c_reset_config(client);
  452. if (ret)
  453. goto err_mem_free;
  454. if (client->irq < 1)
  455. polling_req = true;
  456. touch->input = input_allocate_device();
  457. if (!touch->input) {
  458. ret = -ENOMEM;
  459. goto err_mem_free;
  460. }
  461. synaptics_i2c_set_input_params(touch);
  462. if (!polling_req) {
  463. dev_dbg(&touch->client->dev,
  464. "Requesting IRQ: %d\n", touch->client->irq);
  465. ret = request_irq(touch->client->irq, synaptics_i2c_irq,
  466. IRQF_DISABLED|IRQ_TYPE_EDGE_FALLING,
  467. DRIVER_NAME, touch);
  468. if (ret) {
  469. dev_warn(&touch->client->dev,
  470. "IRQ request failed: %d, "
  471. "falling back to polling\n", ret);
  472. polling_req = true;
  473. synaptics_i2c_reg_set(touch->client,
  474. INTERRUPT_EN_REG, 0);
  475. }
  476. }
  477. if (polling_req)
  478. dev_dbg(&touch->client->dev,
  479. "Using polling at rate: %d times/sec\n", scan_rate);
  480. /* Register the device in input subsystem */
  481. ret = input_register_device(touch->input);
  482. if (ret) {
  483. dev_err(&client->dev,
  484. "Input device register failed: %d\n", ret);
  485. goto err_input_free;
  486. }
  487. i2c_set_clientdata(client, touch);
  488. return 0;
  489. err_input_free:
  490. input_free_device(touch->input);
  491. err_mem_free:
  492. kfree(touch);
  493. return ret;
  494. }
  495. static int __devexit synaptics_i2c_remove(struct i2c_client *client)
  496. {
  497. struct synaptics_i2c *touch = i2c_get_clientdata(client);
  498. if (!polling_req)
  499. free_irq(client->irq, touch);
  500. input_unregister_device(touch->input);
  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");