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