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