Staging: HTC Dream: touchscreen driver for staging
[deliverable/linux.git] / drivers / staging / dream / synaptics_i2c_rmi.c
1 /* drivers/input/keyboard/synaptics_i2c_rmi.c
2 *
3 * Copyright (C) 2007 Google, Inc.
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15
16 #include <linux/module.h>
17 #include <linux/delay.h>
18 #include <linux/hrtimer.h>
19 #include <linux/i2c.h>
20 #include <linux/input.h>
21 #include <linux/interrupt.h>
22 #include <linux/io.h>
23 #include <linux/platform_device.h>
24 #include "synaptics_i2c_rmi.h"
25
26 #define swap(x, y) do { typeof(x) z = x; x = y; y = z; } while (0)
27
28 static struct workqueue_struct *synaptics_wq;
29
30 struct synaptics_ts_data {
31 uint16_t addr;
32 struct i2c_client *client;
33 struct input_dev *input_dev;
34 int use_irq;
35 struct hrtimer timer;
36 struct work_struct work;
37 uint16_t max[2];
38 int snap_state[2][2];
39 int snap_down_on[2];
40 int snap_down_off[2];
41 int snap_up_on[2];
42 int snap_up_off[2];
43 int snap_down[2];
44 int snap_up[2];
45 uint32_t flags;
46 int (*power)(int on);
47 #ifdef CONFIG_HAS_EARLYSUSPEND
48 struct early_suspend early_suspend;
49 #endif
50 };
51
52 #ifdef CONFIG_HAS_EARLYSUSPEND
53 static void synaptics_ts_early_suspend(struct early_suspend *h);
54 static void synaptics_ts_late_resume(struct early_suspend *h);
55 #endif
56
57 static int synaptics_init_panel(struct synaptics_ts_data *ts)
58 {
59 int ret;
60
61 ret = i2c_smbus_write_byte_data(ts->client, 0xff, 0x10); /* page select = 0x10 */
62 if (ret < 0) {
63 printk(KERN_ERR "i2c_smbus_write_byte_data failed for page select\n");
64 goto err_page_select_failed;
65 }
66 ret = i2c_smbus_write_byte_data(ts->client, 0x41, 0x04); /* Set "No Clip Z" */
67 if (ret < 0)
68 printk(KERN_ERR "i2c_smbus_write_byte_data failed for No Clip Z\n");
69
70 err_page_select_failed:
71 ret = i2c_smbus_write_byte_data(ts->client, 0xff, 0x04); /* page select = 0x04 */
72 if (ret < 0)
73 printk(KERN_ERR "i2c_smbus_write_byte_data failed for page select\n");
74 ret = i2c_smbus_write_byte_data(ts->client, 0xf0, 0x81); /* normal operation, 80 reports per second */
75 if (ret < 0)
76 printk(KERN_ERR "synaptics_ts_resume: i2c_smbus_write_byte_data failed\n");
77 return ret;
78 }
79
80 static void synaptics_ts_work_func(struct work_struct *work)
81 {
82 int i;
83 int ret;
84 int bad_data = 0;
85 struct i2c_msg msg[2];
86 uint8_t start_reg;
87 uint8_t buf[15];
88 struct synaptics_ts_data *ts = container_of(work, struct synaptics_ts_data, work);
89
90 msg[0].addr = ts->client->addr;
91 msg[0].flags = 0;
92 msg[0].len = 1;
93 msg[0].buf = &start_reg;
94 start_reg = 0x00;
95 msg[1].addr = ts->client->addr;
96 msg[1].flags = I2C_M_RD;
97 msg[1].len = sizeof(buf);
98 msg[1].buf = buf;
99
100 /* printk("synaptics_ts_work_func\n"); */
101 for (i = 0; i < ((ts->use_irq && !bad_data) ? 1 : 10); i++) {
102 ret = i2c_transfer(ts->client->adapter, msg, 2);
103 if (ret < 0) {
104 printk(KERN_ERR "synaptics_ts_work_func: i2c_transfer failed\n");
105 bad_data = 1;
106 } else {
107 /* printk("synaptics_ts_work_func: %x %x %x %x %x %x" */
108 /* " %x %x %x %x %x %x %x %x %x, ret %d\n", */
109 /* buf[0], buf[1], buf[2], buf[3], */
110 /* buf[4], buf[5], buf[6], buf[7], */
111 /* buf[8], buf[9], buf[10], buf[11], */
112 /* buf[12], buf[13], buf[14], ret); */
113 if ((buf[14] & 0xc0) != 0x40) {
114 printk(KERN_WARNING "synaptics_ts_work_func:"
115 " bad read %x %x %x %x %x %x %x %x %x"
116 " %x %x %x %x %x %x, ret %d\n",
117 buf[0], buf[1], buf[2], buf[3],
118 buf[4], buf[5], buf[6], buf[7],
119 buf[8], buf[9], buf[10], buf[11],
120 buf[12], buf[13], buf[14], ret);
121 if (bad_data)
122 synaptics_init_panel(ts);
123 bad_data = 1;
124 continue;
125 }
126 bad_data = 0;
127 if ((buf[14] & 1) == 0) {
128 /* printk("read %d coordinates\n", i); */
129 break;
130 } else {
131 int pos[2][2];
132 int f, a;
133 int base;
134 /* int x = buf[3] | (uint16_t)(buf[2] & 0x1f) << 8; */
135 /* int y = buf[5] | (uint16_t)(buf[4] & 0x1f) << 8; */
136 int z = buf[1];
137 int w = buf[0] >> 4;
138 int finger = buf[0] & 7;
139
140 /* int x2 = buf[3+6] | (uint16_t)(buf[2+6] & 0x1f) << 8; */
141 /* int y2 = buf[5+6] | (uint16_t)(buf[4+6] & 0x1f) << 8; */
142 /* int z2 = buf[1+6]; */
143 /* int w2 = buf[0+6] >> 4; */
144 /* int finger2 = buf[0+6] & 7; */
145
146 /* int dx = (int8_t)buf[12]; */
147 /* int dy = (int8_t)buf[13]; */
148 int finger2_pressed;
149
150 /* printk("x %4d, y %4d, z %3d, w %2d, F %d, 2nd: x %4d, y %4d, z %3d, w %2d, F %d, dx %4d, dy %4d\n", */
151 /* x, y, z, w, finger, */
152 /* x2, y2, z2, w2, finger2, */
153 /* dx, dy); */
154
155 base = 2;
156 for (f = 0; f < 2; f++) {
157 uint32_t flip_flag = SYNAPTICS_FLIP_X;
158 for (a = 0; a < 2; a++) {
159 int p = buf[base + 1];
160 p |= (uint16_t)(buf[base] & 0x1f) << 8;
161 if (ts->flags & flip_flag)
162 p = ts->max[a] - p;
163 if (ts->flags & SYNAPTICS_SNAP_TO_INACTIVE_EDGE) {
164 if (ts->snap_state[f][a]) {
165 if (p <= ts->snap_down_off[a])
166 p = ts->snap_down[a];
167 else if (p >= ts->snap_up_off[a])
168 p = ts->snap_up[a];
169 else
170 ts->snap_state[f][a] = 0;
171 } else {
172 if (p <= ts->snap_down_on[a]) {
173 p = ts->snap_down[a];
174 ts->snap_state[f][a] = 1;
175 } else if (p >= ts->snap_up_on[a]) {
176 p = ts->snap_up[a];
177 ts->snap_state[f][a] = 1;
178 }
179 }
180 }
181 pos[f][a] = p;
182 base += 2;
183 flip_flag <<= 1;
184 }
185 base += 2;
186 if (ts->flags & SYNAPTICS_SWAP_XY)
187 swap(pos[f][0], pos[f][1]);
188 }
189 if (z) {
190 input_report_abs(ts->input_dev, ABS_X, pos[0][0]);
191 input_report_abs(ts->input_dev, ABS_Y, pos[0][1]);
192 }
193 input_report_abs(ts->input_dev, ABS_PRESSURE, z);
194 input_report_abs(ts->input_dev, ABS_TOOL_WIDTH, w);
195 input_report_key(ts->input_dev, BTN_TOUCH, finger);
196 finger2_pressed = finger > 1 && finger != 7;
197 input_report_key(ts->input_dev, BTN_2, finger2_pressed);
198 if (finger2_pressed) {
199 input_report_abs(ts->input_dev, ABS_HAT0X, pos[1][0]);
200 input_report_abs(ts->input_dev, ABS_HAT0Y, pos[1][1]);
201 }
202 input_sync(ts->input_dev);
203 }
204 }
205 }
206 if (ts->use_irq)
207 enable_irq(ts->client->irq);
208 }
209
210 static enum hrtimer_restart synaptics_ts_timer_func(struct hrtimer *timer)
211 {
212 struct synaptics_ts_data *ts = container_of(timer, struct synaptics_ts_data, timer);
213 /* printk("synaptics_ts_timer_func\n"); */
214
215 queue_work(synaptics_wq, &ts->work);
216
217 hrtimer_start(&ts->timer, ktime_set(0, 12500000), HRTIMER_MODE_REL);
218 return HRTIMER_NORESTART;
219 }
220
221 static irqreturn_t synaptics_ts_irq_handler(int irq, void *dev_id)
222 {
223 struct synaptics_ts_data *ts = dev_id;
224
225 /* printk("synaptics_ts_irq_handler\n"); */
226 disable_irq(ts->client->irq);
227 queue_work(synaptics_wq, &ts->work);
228 return IRQ_HANDLED;
229 }
230
231 static int synaptics_ts_probe(
232 struct i2c_client *client, const struct i2c_device_id *id)
233 {
234 struct synaptics_ts_data *ts;
235 uint8_t buf0[4];
236 uint8_t buf1[8];
237 struct i2c_msg msg[2];
238 int ret = 0;
239 uint16_t max_x, max_y;
240 int fuzz_x, fuzz_y, fuzz_p, fuzz_w;
241 struct synaptics_i2c_rmi_platform_data *pdata;
242 int inactive_area_left;
243 int inactive_area_right;
244 int inactive_area_top;
245 int inactive_area_bottom;
246 int snap_left_on;
247 int snap_left_off;
248 int snap_right_on;
249 int snap_right_off;
250 int snap_top_on;
251 int snap_top_off;
252 int snap_bottom_on;
253 int snap_bottom_off;
254 uint32_t panel_version;
255
256 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
257 printk(KERN_ERR "synaptics_ts_probe: need I2C_FUNC_I2C\n");
258 ret = -ENODEV;
259 goto err_check_functionality_failed;
260 }
261
262 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
263 if (ts == NULL) {
264 ret = -ENOMEM;
265 goto err_alloc_data_failed;
266 }
267 INIT_WORK(&ts->work, synaptics_ts_work_func);
268 ts->client = client;
269 i2c_set_clientdata(client, ts);
270 pdata = client->dev.platform_data;
271 if (pdata)
272 ts->power = pdata->power;
273 if (ts->power) {
274 ret = ts->power(1);
275 if (ret < 0) {
276 printk(KERN_ERR "synaptics_ts_probe power on failed\n");
277 goto err_power_failed;
278 }
279 }
280
281 ret = i2c_smbus_write_byte_data(ts->client, 0xf4, 0x01); /* device command = reset */
282 if (ret < 0) {
283 printk(KERN_ERR "i2c_smbus_write_byte_data failed\n");
284 /* fail? */
285 }
286 {
287 int retry = 10;
288 while (retry-- > 0) {
289 ret = i2c_smbus_read_byte_data(ts->client, 0xe4);
290 if (ret >= 0)
291 break;
292 msleep(100);
293 }
294 }
295 if (ret < 0) {
296 printk(KERN_ERR "i2c_smbus_read_byte_data failed\n");
297 goto err_detect_failed;
298 }
299 printk(KERN_INFO "synaptics_ts_probe: Product Major Version %x\n", ret);
300 panel_version = ret << 8;
301 ret = i2c_smbus_read_byte_data(ts->client, 0xe5);
302 if (ret < 0) {
303 printk(KERN_ERR "i2c_smbus_read_byte_data failed\n");
304 goto err_detect_failed;
305 }
306 printk(KERN_INFO "synaptics_ts_probe: Product Minor Version %x\n", ret);
307 panel_version |= ret;
308
309 ret = i2c_smbus_read_byte_data(ts->client, 0xe3);
310 if (ret < 0) {
311 printk(KERN_ERR "i2c_smbus_read_byte_data failed\n");
312 goto err_detect_failed;
313 }
314 printk(KERN_INFO "synaptics_ts_probe: product property %x\n", ret);
315
316 if (pdata) {
317 while (pdata->version > panel_version)
318 pdata++;
319 ts->flags = pdata->flags;
320 inactive_area_left = pdata->inactive_left;
321 inactive_area_right = pdata->inactive_right;
322 inactive_area_top = pdata->inactive_top;
323 inactive_area_bottom = pdata->inactive_bottom;
324 snap_left_on = pdata->snap_left_on;
325 snap_left_off = pdata->snap_left_off;
326 snap_right_on = pdata->snap_right_on;
327 snap_right_off = pdata->snap_right_off;
328 snap_top_on = pdata->snap_top_on;
329 snap_top_off = pdata->snap_top_off;
330 snap_bottom_on = pdata->snap_bottom_on;
331 snap_bottom_off = pdata->snap_bottom_off;
332 fuzz_x = pdata->fuzz_x;
333 fuzz_y = pdata->fuzz_y;
334 fuzz_p = pdata->fuzz_p;
335 fuzz_w = pdata->fuzz_w;
336 } else {
337 inactive_area_left = 0;
338 inactive_area_right = 0;
339 inactive_area_top = 0;
340 inactive_area_bottom = 0;
341 snap_left_on = 0;
342 snap_left_off = 0;
343 snap_right_on = 0;
344 snap_right_off = 0;
345 snap_top_on = 0;
346 snap_top_off = 0;
347 snap_bottom_on = 0;
348 snap_bottom_off = 0;
349 fuzz_x = 0;
350 fuzz_y = 0;
351 fuzz_p = 0;
352 fuzz_w = 0;
353 }
354
355 ret = i2c_smbus_read_byte_data(ts->client, 0xf0);
356 if (ret < 0) {
357 printk(KERN_ERR "i2c_smbus_read_byte_data failed\n");
358 goto err_detect_failed;
359 }
360 printk(KERN_INFO "synaptics_ts_probe: device control %x\n", ret);
361
362 ret = i2c_smbus_read_byte_data(ts->client, 0xf1);
363 if (ret < 0) {
364 printk(KERN_ERR "i2c_smbus_read_byte_data failed\n");
365 goto err_detect_failed;
366 }
367 printk(KERN_INFO "synaptics_ts_probe: interrupt enable %x\n", ret);
368
369 ret = i2c_smbus_write_byte_data(ts->client, 0xf1, 0); /* disable interrupt */
370 if (ret < 0) {
371 printk(KERN_ERR "i2c_smbus_write_byte_data failed\n");
372 goto err_detect_failed;
373 }
374
375 msg[0].addr = ts->client->addr;
376 msg[0].flags = 0;
377 msg[0].len = 1;
378 msg[0].buf = buf0;
379 buf0[0] = 0xe0;
380 msg[1].addr = ts->client->addr;
381 msg[1].flags = I2C_M_RD;
382 msg[1].len = 8;
383 msg[1].buf = buf1;
384 ret = i2c_transfer(ts->client->adapter, msg, 2);
385 if (ret < 0) {
386 printk(KERN_ERR "i2c_transfer failed\n");
387 goto err_detect_failed;
388 }
389 printk(KERN_INFO "synaptics_ts_probe: 0xe0: %x %x %x %x %x %x %x %x\n",
390 buf1[0], buf1[1], buf1[2], buf1[3],
391 buf1[4], buf1[5], buf1[6], buf1[7]);
392
393 ret = i2c_smbus_write_byte_data(ts->client, 0xff, 0x10); /* page select = 0x10 */
394 if (ret < 0) {
395 printk(KERN_ERR "i2c_smbus_write_byte_data failed for page select\n");
396 goto err_detect_failed;
397 }
398 ret = i2c_smbus_read_word_data(ts->client, 0x04);
399 if (ret < 0) {
400 printk(KERN_ERR "i2c_smbus_read_word_data failed\n");
401 goto err_detect_failed;
402 }
403 ts->max[0] = max_x = (ret >> 8 & 0xff) | ((ret & 0x1f) << 8);
404 ret = i2c_smbus_read_word_data(ts->client, 0x06);
405 if (ret < 0) {
406 printk(KERN_ERR "i2c_smbus_read_word_data failed\n");
407 goto err_detect_failed;
408 }
409 ts->max[1] = max_y = (ret >> 8 & 0xff) | ((ret & 0x1f) << 8);
410 if (ts->flags & SYNAPTICS_SWAP_XY)
411 swap(max_x, max_y);
412
413 ret = synaptics_init_panel(ts); /* will also switch back to page 0x04 */
414 if (ret < 0) {
415 printk(KERN_ERR "synaptics_init_panel failed\n");
416 goto err_detect_failed;
417 }
418
419 ts->input_dev = input_allocate_device();
420 if (ts->input_dev == NULL) {
421 ret = -ENOMEM;
422 printk(KERN_ERR "synaptics_ts_probe: Failed to allocate input device\n");
423 goto err_input_dev_alloc_failed;
424 }
425 ts->input_dev->name = "synaptics-rmi-touchscreen";
426 set_bit(EV_SYN, ts->input_dev->evbit);
427 set_bit(EV_KEY, ts->input_dev->evbit);
428 set_bit(BTN_TOUCH, ts->input_dev->keybit);
429 set_bit(BTN_2, ts->input_dev->keybit);
430 set_bit(EV_ABS, ts->input_dev->evbit);
431 inactive_area_left = inactive_area_left * max_x / 0x10000;
432 inactive_area_right = inactive_area_right * max_x / 0x10000;
433 inactive_area_top = inactive_area_top * max_y / 0x10000;
434 inactive_area_bottom = inactive_area_bottom * max_y / 0x10000;
435 snap_left_on = snap_left_on * max_x / 0x10000;
436 snap_left_off = snap_left_off * max_x / 0x10000;
437 snap_right_on = snap_right_on * max_x / 0x10000;
438 snap_right_off = snap_right_off * max_x / 0x10000;
439 snap_top_on = snap_top_on * max_y / 0x10000;
440 snap_top_off = snap_top_off * max_y / 0x10000;
441 snap_bottom_on = snap_bottom_on * max_y / 0x10000;
442 snap_bottom_off = snap_bottom_off * max_y / 0x10000;
443 fuzz_x = fuzz_x * max_x / 0x10000;
444 fuzz_y = fuzz_y * max_y / 0x10000;
445 ts->snap_down[!!(ts->flags & SYNAPTICS_SWAP_XY)] = -inactive_area_left;
446 ts->snap_up[!!(ts->flags & SYNAPTICS_SWAP_XY)] = max_x + inactive_area_right;
447 ts->snap_down[!(ts->flags & SYNAPTICS_SWAP_XY)] = -inactive_area_top;
448 ts->snap_up[!(ts->flags & SYNAPTICS_SWAP_XY)] = max_y + inactive_area_bottom;
449 ts->snap_down_on[!!(ts->flags & SYNAPTICS_SWAP_XY)] = snap_left_on;
450 ts->snap_down_off[!!(ts->flags & SYNAPTICS_SWAP_XY)] = snap_left_off;
451 ts->snap_up_on[!!(ts->flags & SYNAPTICS_SWAP_XY)] = max_x - snap_right_on;
452 ts->snap_up_off[!!(ts->flags & SYNAPTICS_SWAP_XY)] = max_x - snap_right_off;
453 ts->snap_down_on[!(ts->flags & SYNAPTICS_SWAP_XY)] = snap_top_on;
454 ts->snap_down_off[!(ts->flags & SYNAPTICS_SWAP_XY)] = snap_top_off;
455 ts->snap_up_on[!(ts->flags & SYNAPTICS_SWAP_XY)] = max_y - snap_bottom_on;
456 ts->snap_up_off[!(ts->flags & SYNAPTICS_SWAP_XY)] = max_y - snap_bottom_off;
457 printk(KERN_INFO "synaptics_ts_probe: max_x %d, max_y %d\n", max_x, max_y);
458 printk(KERN_INFO "synaptics_ts_probe: inactive_x %d %d, inactive_y %d %d\n",
459 inactive_area_left, inactive_area_right,
460 inactive_area_top, inactive_area_bottom);
461 printk(KERN_INFO "synaptics_ts_probe: snap_x %d-%d %d-%d, snap_y %d-%d %d-%d\n",
462 snap_left_on, snap_left_off, snap_right_on, snap_right_off,
463 snap_top_on, snap_top_off, snap_bottom_on, snap_bottom_off);
464 input_set_abs_params(ts->input_dev, ABS_X, -inactive_area_left, max_x + inactive_area_right, fuzz_x, 0);
465 input_set_abs_params(ts->input_dev, ABS_Y, -inactive_area_top, max_y + inactive_area_bottom, fuzz_y, 0);
466 input_set_abs_params(ts->input_dev, ABS_PRESSURE, 0, 255, fuzz_p, 0);
467 input_set_abs_params(ts->input_dev, ABS_TOOL_WIDTH, 0, 15, fuzz_w, 0);
468 input_set_abs_params(ts->input_dev, ABS_HAT0X, -inactive_area_left, max_x + inactive_area_right, fuzz_x, 0);
469 input_set_abs_params(ts->input_dev, ABS_HAT0Y, -inactive_area_top, max_y + inactive_area_bottom, fuzz_y, 0);
470 /* ts->input_dev->name = ts->keypad_info->name; */
471 ret = input_register_device(ts->input_dev);
472 if (ret) {
473 printk(KERN_ERR "synaptics_ts_probe: Unable to register %s input device\n", ts->input_dev->name);
474 goto err_input_register_device_failed;
475 }
476 if (client->irq) {
477 ret = request_irq(client->irq, synaptics_ts_irq_handler, 0, client->name, ts);
478 if (ret == 0) {
479 ret = i2c_smbus_write_byte_data(ts->client, 0xf1, 0x01); /* enable abs int */
480 if (ret)
481 free_irq(client->irq, ts);
482 }
483 if (ret == 0)
484 ts->use_irq = 1;
485 else
486 dev_err(&client->dev, "request_irq failed\n");
487 }
488 if (!ts->use_irq) {
489 hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
490 ts->timer.function = synaptics_ts_timer_func;
491 hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
492 }
493 #ifdef CONFIG_HAS_EARLYSUSPEND
494 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
495 ts->early_suspend.suspend = synaptics_ts_early_suspend;
496 ts->early_suspend.resume = synaptics_ts_late_resume;
497 register_early_suspend(&ts->early_suspend);
498 #endif
499
500 printk(KERN_INFO "synaptics_ts_probe: Start touchscreen %s in %s mode\n", ts->input_dev->name, ts->use_irq ? "interrupt" : "polling");
501
502 return 0;
503
504 err_input_register_device_failed:
505 input_free_device(ts->input_dev);
506
507 err_input_dev_alloc_failed:
508 err_detect_failed:
509 err_power_failed:
510 kfree(ts);
511 err_alloc_data_failed:
512 err_check_functionality_failed:
513 return ret;
514 }
515
516 static int synaptics_ts_remove(struct i2c_client *client)
517 {
518 struct synaptics_ts_data *ts = i2c_get_clientdata(client);
519 #ifdef CONFIG_HAS_EARLYSUSPEND
520 unregister_early_suspend(&ts->early_suspend);
521 #endif
522 if (ts->use_irq)
523 free_irq(client->irq, ts);
524 else
525 hrtimer_cancel(&ts->timer);
526 input_unregister_device(ts->input_dev);
527 kfree(ts);
528 return 0;
529 }
530
531 static int synaptics_ts_suspend(struct i2c_client *client, pm_message_t mesg)
532 {
533 int ret;
534 struct synaptics_ts_data *ts = i2c_get_clientdata(client);
535
536 if (ts->use_irq)
537 disable_irq(client->irq);
538 else
539 hrtimer_cancel(&ts->timer);
540 ret = cancel_work_sync(&ts->work);
541 if (ret && ts->use_irq) /* if work was pending disable-count is now 2 */
542 enable_irq(client->irq);
543 ret = i2c_smbus_write_byte_data(ts->client, 0xf1, 0); /* disable interrupt */
544 if (ret < 0)
545 printk(KERN_ERR "synaptics_ts_suspend: i2c_smbus_write_byte_data failed\n");
546
547 ret = i2c_smbus_write_byte_data(client, 0xf0, 0x86); /* deep sleep */
548 if (ret < 0)
549 printk(KERN_ERR "synaptics_ts_suspend: i2c_smbus_write_byte_data failed\n");
550 if (ts->power) {
551 ret = ts->power(0);
552 if (ret < 0)
553 printk(KERN_ERR "synaptics_ts_resume power off failed\n");
554 }
555 return 0;
556 }
557
558 static int synaptics_ts_resume(struct i2c_client *client)
559 {
560 int ret;
561 struct synaptics_ts_data *ts = i2c_get_clientdata(client);
562
563 if (ts->power) {
564 ret = ts->power(1);
565 if (ret < 0)
566 printk(KERN_ERR "synaptics_ts_resume power on failed\n");
567 }
568
569 synaptics_init_panel(ts);
570
571 if (ts->use_irq)
572 enable_irq(client->irq);
573
574 if (!ts->use_irq)
575 hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
576 else
577 i2c_smbus_write_byte_data(ts->client, 0xf1, 0x01); /* enable abs int */
578
579 return 0;
580 }
581
582 #ifdef CONFIG_HAS_EARLYSUSPEND
583 static void synaptics_ts_early_suspend(struct early_suspend *h)
584 {
585 struct synaptics_ts_data *ts;
586 ts = container_of(h, struct synaptics_ts_data, early_suspend);
587 synaptics_ts_suspend(ts->client, PMSG_SUSPEND);
588 }
589
590 static void synaptics_ts_late_resume(struct early_suspend *h)
591 {
592 struct synaptics_ts_data *ts;
593 ts = container_of(h, struct synaptics_ts_data, early_suspend);
594 synaptics_ts_resume(ts->client);
595 }
596 #endif
597
598 static const struct i2c_device_id synaptics_ts_id[] = {
599 { SYNAPTICS_I2C_RMI_NAME, 0 },
600 { }
601 };
602
603 static struct i2c_driver synaptics_ts_driver = {
604 .probe = synaptics_ts_probe,
605 .remove = synaptics_ts_remove,
606 #ifndef CONFIG_HAS_EARLYSUSPEND
607 .suspend = synaptics_ts_suspend,
608 .resume = synaptics_ts_resume,
609 #endif
610 .id_table = synaptics_ts_id,
611 .driver = {
612 .name = SYNAPTICS_I2C_RMI_NAME,
613 },
614 };
615
616 static int __devinit synaptics_ts_init(void)
617 {
618 synaptics_wq = create_singlethread_workqueue("synaptics_wq");
619 if (!synaptics_wq)
620 return -ENOMEM;
621 return i2c_add_driver(&synaptics_ts_driver);
622 }
623
624 static void __exit synaptics_ts_exit(void)
625 {
626 i2c_del_driver(&synaptics_ts_driver);
627 if (synaptics_wq)
628 destroy_workqueue(synaptics_wq);
629 }
630
631 module_init(synaptics_ts_init);
632 module_exit(synaptics_ts_exit);
633
634 MODULE_DESCRIPTION("Synaptics Touchscreen Driver");
635 MODULE_LICENSE("GPL");
This page took 0.056495 seconds and 5 git commands to generate.