]>
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]; | |
112 | int w = buf[0] >> 4; | |
113 | int finger = buf[0] & 7; | |
114 | int finger2_pressed; | |
115 | ||
116 | for (f = 0; f < 2; f++) { | |
117 | u32 flip_flag = SYNAPTICS_FLIP_X; | |
118 | for (a = 0; a < 2; a++) { | |
119 | int p = buf[base + 1]; | |
120 | p |= (u16)(buf[base] & 0x1f) << 8; | |
121 | if (ts->flags & flip_flag) | |
122 | p = ts->max[a] - p; | |
123 | if (ts->flags & SYNAPTICS_SNAP_TO_INACTIVE_EDGE) { | |
124 | if (ts->snap_state[f][a]) { | |
125 | if (p <= ts->snap_down_off[a]) | |
126 | p = ts->snap_down[a]; | |
127 | else if (p >= ts->snap_up_off[a]) | |
128 | p = ts->snap_up[a]; | |
129 | else | |
130 | ts->snap_state[f][a] = 0; | |
131 | } else { | |
132 | if (p <= ts->snap_down_on[a]) { | |
133 | p = ts->snap_down[a]; | |
134 | ts->snap_state[f][a] = 1; | |
135 | } else if (p >= ts->snap_up_on[a]) { | |
136 | p = ts->snap_up[a]; | |
137 | ts->snap_state[f][a] = 1; | |
138 | } | |
139 | } | |
140 | } | |
141 | pos[f][a] = p; | |
142 | base += 2; | |
143 | flip_flag <<= 1; | |
144 | } | |
145 | base += 2; | |
146 | if (ts->flags & SYNAPTICS_SWAP_XY) | |
147 | swap(pos[f][0], pos[f][1]); | |
148 | } | |
149 | if (z) { | |
150 | input_report_abs(ts->input_dev, ABS_X, pos[0][0]); | |
151 | input_report_abs(ts->input_dev, ABS_Y, pos[0][1]); | |
152 | } | |
153 | input_report_abs(ts->input_dev, ABS_PRESSURE, z); | |
154 | input_report_abs(ts->input_dev, ABS_TOOL_WIDTH, w); | |
155 | input_report_key(ts->input_dev, BTN_TOUCH, finger); | |
156 | finger2_pressed = finger > 1 && finger != 7; | |
157 | input_report_key(ts->input_dev, BTN_2, finger2_pressed); | |
158 | if (finger2_pressed) { | |
159 | input_report_abs(ts->input_dev, ABS_HAT0X, pos[1][0]); | |
160 | input_report_abs(ts->input_dev, ABS_HAT0Y, pos[1][1]); | |
161 | } | |
162 | input_sync(ts->input_dev); | |
163 | } | |
164 | ||
2e4d2af9 AH |
165 | static void synaptics_ts_work_func(struct work_struct *work) |
166 | { | |
167 | int i; | |
168 | int ret; | |
169 | int bad_data = 0; | |
170 | struct i2c_msg msg[2]; | |
261314a9 PM |
171 | u8 start_reg = 0; |
172 | u8 buf[15]; | |
173 | struct synaptics_ts_data *ts = | |
174 | container_of(work, struct synaptics_ts_data, work); | |
2e4d2af9 AH |
175 | |
176 | msg[0].addr = ts->client->addr; | |
177 | msg[0].flags = 0; | |
178 | msg[0].len = 1; | |
179 | msg[0].buf = &start_reg; | |
2e4d2af9 AH |
180 | msg[1].addr = ts->client->addr; |
181 | msg[1].flags = I2C_M_RD; | |
182 | msg[1].len = sizeof(buf); | |
183 | msg[1].buf = buf; | |
184 | ||
2e4d2af9 AH |
185 | for (i = 0; i < ((ts->use_irq && !bad_data) ? 1 : 10); i++) { |
186 | ret = i2c_transfer(ts->client->adapter, msg, 2); | |
187 | if (ret < 0) { | |
261314a9 | 188 | pr_err("ts_work: i2c_transfer failed\n"); |
2e4d2af9 | 189 | bad_data = 1; |
261314a9 | 190 | continue; |
2e4d2af9 | 191 | } |
261314a9 PM |
192 | if ((buf[14] & 0xc0) != 0x40) { |
193 | pr_warning("synaptics_ts_work_func:" | |
194 | " bad read %x %x %x %x %x %x %x %x %x" | |
195 | " %x %x %x %x %x %x, ret %d\n", | |
196 | buf[0], buf[1], buf[2], buf[3], | |
197 | buf[4], buf[5], buf[6], buf[7], | |
198 | buf[8], buf[9], buf[10], buf[11], | |
199 | buf[12], buf[13], buf[14], ret); | |
200 | if (bad_data) | |
201 | synaptics_init_panel(ts); | |
202 | bad_data = 1; | |
203 | continue; | |
204 | } | |
205 | bad_data = 0; | |
206 | if ((buf[14] & 1) == 0) | |
207 | break; | |
208 | ||
209 | decode_report(ts, buf); | |
2e4d2af9 AH |
210 | } |
211 | if (ts->use_irq) | |
212 | enable_irq(ts->client->irq); | |
213 | } | |
214 | ||
215 | static enum hrtimer_restart synaptics_ts_timer_func(struct hrtimer *timer) | |
216 | { | |
261314a9 PM |
217 | struct synaptics_ts_data *ts = |
218 | container_of(timer, struct synaptics_ts_data, timer); | |
2e4d2af9 AH |
219 | |
220 | queue_work(synaptics_wq, &ts->work); | |
221 | ||
222 | hrtimer_start(&ts->timer, ktime_set(0, 12500000), HRTIMER_MODE_REL); | |
223 | return HRTIMER_NORESTART; | |
224 | } | |
225 | ||
226 | static irqreturn_t synaptics_ts_irq_handler(int irq, void *dev_id) | |
227 | { | |
228 | struct synaptics_ts_data *ts = dev_id; | |
229 | ||
261314a9 | 230 | disable_irq_nosync(ts->client->irq); |
2e4d2af9 AH |
231 | queue_work(synaptics_wq, &ts->work); |
232 | return IRQ_HANDLED; | |
233 | } | |
234 | ||
261314a9 PM |
235 | static int detect(struct synaptics_ts_data *ts, u32 *panel_version) |
236 | { | |
237 | int ret; | |
238 | int retry = 10; | |
239 | ||
240 | ret = i2c_set(ts, 0xf4, 0x01, "reset device"); | |
241 | ||
242 | while (retry-- > 0) { | |
243 | ret = i2c_smbus_read_byte_data(ts->client, 0xe4); | |
244 | if (ret >= 0) | |
245 | break; | |
246 | msleep(100); | |
247 | } | |
248 | if (ret < 0) { | |
249 | pr_err("i2c_smbus_read_byte_data failed\n"); | |
250 | return ret; | |
251 | } | |
252 | ||
253 | *panel_version = ret << 8; | |
254 | ret = i2c_read(ts, 0xe5, "product minor"); | |
255 | if (ret < 0) | |
256 | return ret; | |
257 | *panel_version |= ret; | |
258 | ||
259 | ret = i2c_read(ts, 0xe3, "property"); | |
260 | if (ret < 0) | |
261 | return ret; | |
262 | ||
263 | pr_info("synaptics: version %x, product property %x\n", | |
264 | *panel_version, ret); | |
265 | return 0; | |
266 | } | |
267 | ||
4191934c PM |
268 | static void compute_areas(struct synaptics_ts_data *ts, |
269 | struct synaptics_i2c_rmi_platform_data *pdata, | |
270 | u16 max_x, u16 max_y) | |
2e4d2af9 | 271 | { |
2e4d2af9 AH |
272 | int inactive_area_left; |
273 | int inactive_area_right; | |
274 | int inactive_area_top; | |
275 | int inactive_area_bottom; | |
276 | int snap_left_on; | |
277 | int snap_left_off; | |
278 | int snap_right_on; | |
279 | int snap_right_off; | |
280 | int snap_top_on; | |
281 | int snap_top_off; | |
282 | int snap_bottom_on; | |
283 | int snap_bottom_off; | |
4191934c PM |
284 | int fuzz_x; |
285 | int fuzz_y; | |
286 | int fuzz_p; | |
287 | int fuzz_w; | |
288 | int swapped = !!(ts->flags & SYNAPTICS_SWAP_XY); | |
289 | ||
290 | inactive_area_left = pdata->inactive_left; | |
291 | inactive_area_right = pdata->inactive_right; | |
292 | inactive_area_top = pdata->inactive_top; | |
293 | inactive_area_bottom = pdata->inactive_bottom; | |
294 | snap_left_on = pdata->snap_left_on; | |
295 | snap_left_off = pdata->snap_left_off; | |
296 | snap_right_on = pdata->snap_right_on; | |
297 | snap_right_off = pdata->snap_right_off; | |
298 | snap_top_on = pdata->snap_top_on; | |
299 | snap_top_off = pdata->snap_top_off; | |
300 | snap_bottom_on = pdata->snap_bottom_on; | |
301 | snap_bottom_off = pdata->snap_bottom_off; | |
302 | fuzz_x = pdata->fuzz_x; | |
303 | fuzz_y = pdata->fuzz_y; | |
304 | fuzz_p = pdata->fuzz_p; | |
305 | fuzz_w = pdata->fuzz_w; | |
306 | ||
307 | inactive_area_left = inactive_area_left * max_x / 0x10000; | |
308 | inactive_area_right = inactive_area_right * max_x / 0x10000; | |
309 | inactive_area_top = inactive_area_top * max_y / 0x10000; | |
310 | inactive_area_bottom = inactive_area_bottom * max_y / 0x10000; | |
311 | snap_left_on = snap_left_on * max_x / 0x10000; | |
312 | snap_left_off = snap_left_off * max_x / 0x10000; | |
313 | snap_right_on = snap_right_on * max_x / 0x10000; | |
314 | snap_right_off = snap_right_off * max_x / 0x10000; | |
315 | snap_top_on = snap_top_on * max_y / 0x10000; | |
316 | snap_top_off = snap_top_off * max_y / 0x10000; | |
317 | snap_bottom_on = snap_bottom_on * max_y / 0x10000; | |
318 | snap_bottom_off = snap_bottom_off * max_y / 0x10000; | |
319 | fuzz_x = fuzz_x * max_x / 0x10000; | |
320 | fuzz_y = fuzz_y * max_y / 0x10000; | |
321 | ||
322 | ||
323 | ts->snap_down[swapped] = -inactive_area_left; | |
324 | ts->snap_up[swapped] = max_x + inactive_area_right; | |
325 | ts->snap_down[!swapped] = -inactive_area_top; | |
326 | ts->snap_up[!swapped] = max_y + inactive_area_bottom; | |
327 | ts->snap_down_on[swapped] = snap_left_on; | |
328 | ts->snap_down_off[swapped] = snap_left_off; | |
329 | ts->snap_up_on[swapped] = max_x - snap_right_on; | |
330 | ts->snap_up_off[swapped] = max_x - snap_right_off; | |
331 | ts->snap_down_on[!swapped] = snap_top_on; | |
332 | ts->snap_down_off[!swapped] = snap_top_off; | |
333 | ts->snap_up_on[!swapped] = max_y - snap_bottom_on; | |
334 | ts->snap_up_off[!swapped] = max_y - snap_bottom_off; | |
335 | pr_info("synaptics_ts_probe: max_x %d, max_y %d\n", max_x, max_y); | |
336 | pr_info("synaptics_ts_probe: inactive_x %d %d, inactive_y %d %d\n", | |
337 | inactive_area_left, inactive_area_right, | |
338 | inactive_area_top, inactive_area_bottom); | |
339 | pr_info("synaptics_ts_probe: snap_x %d-%d %d-%d, snap_y %d-%d %d-%d\n", | |
340 | snap_left_on, snap_left_off, snap_right_on, snap_right_off, | |
341 | snap_top_on, snap_top_off, snap_bottom_on, snap_bottom_off); | |
342 | ||
343 | input_set_abs_params(ts->input_dev, ABS_X, | |
344 | -inactive_area_left, max_x + inactive_area_right, | |
345 | fuzz_x, 0); | |
346 | input_set_abs_params(ts->input_dev, ABS_Y, | |
347 | -inactive_area_top, max_y + inactive_area_bottom, | |
348 | fuzz_y, 0); | |
349 | input_set_abs_params(ts->input_dev, ABS_PRESSURE, 0, 255, fuzz_p, 0); | |
350 | input_set_abs_params(ts->input_dev, ABS_TOOL_WIDTH, 0, 15, fuzz_w, 0); | |
351 | input_set_abs_params(ts->input_dev, ABS_HAT0X, -inactive_area_left, | |
352 | max_x + inactive_area_right, fuzz_x, 0); | |
353 | input_set_abs_params(ts->input_dev, ABS_HAT0Y, -inactive_area_top, | |
354 | max_y + inactive_area_bottom, fuzz_y, 0); | |
355 | } | |
356 | ||
357 | static struct synaptics_i2c_rmi_platform_data fake_pdata; | |
358 | ||
359 | static int __devinit synaptics_ts_probe( | |
360 | struct i2c_client *client, const struct i2c_device_id *id) | |
361 | { | |
362 | struct synaptics_ts_data *ts; | |
363 | u8 buf0[4]; | |
364 | u8 buf1[8]; | |
365 | struct i2c_msg msg[2]; | |
366 | int ret = 0; | |
367 | struct synaptics_i2c_rmi_platform_data *pdata; | |
368 | u32 panel_version = 0; | |
369 | u16 max_x, max_y; | |
2e4d2af9 AH |
370 | |
371 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { | |
4191934c | 372 | pr_err("synaptics_ts_probe: need I2C_FUNC_I2C\n"); |
2e4d2af9 AH |
373 | ret = -ENODEV; |
374 | goto err_check_functionality_failed; | |
05d42522 PM |
375 | } |
376 | ||
377 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) { | |
378 | pr_err("synaptics_ts_probe: need I2C_FUNC_SMBUS_WORD_DATA\n"); | |
379 | ret = -ENODEV; | |
380 | goto err_check_functionality_failed; | |
2e4d2af9 AH |
381 | } |
382 | ||
c60adf37 PM |
383 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) { |
384 | pr_err("synaptics_ts_probe: need I2C_FUNC_SMBUS_WORD_DATA\n"); | |
385 | ret = -ENODEV; | |
386 | goto err_check_functionality_failed; | |
387 | } | |
388 | ||
2e4d2af9 AH |
389 | ts = kzalloc(sizeof(*ts), GFP_KERNEL); |
390 | if (ts == NULL) { | |
391 | ret = -ENOMEM; | |
392 | goto err_alloc_data_failed; | |
393 | } | |
394 | INIT_WORK(&ts->work, synaptics_ts_work_func); | |
395 | ts->client = client; | |
396 | i2c_set_clientdata(client, ts); | |
397 | pdata = client->dev.platform_data; | |
398 | if (pdata) | |
399 | ts->power = pdata->power; | |
261314a9 PM |
400 | else |
401 | pdata = &fake_pdata; | |
402 | ||
2e4d2af9 AH |
403 | if (ts->power) { |
404 | ret = ts->power(1); | |
405 | if (ret < 0) { | |
261314a9 | 406 | pr_err("synaptics_ts_probe power on failed\n"); |
2e4d2af9 AH |
407 | goto err_power_failed; |
408 | } | |
409 | } | |
410 | ||
261314a9 PM |
411 | ret = detect(ts, &panel_version); |
412 | if (ret) | |
2e4d2af9 | 413 | goto err_detect_failed; |
2e4d2af9 | 414 | |
4191934c PM |
415 | while (pdata->version > panel_version) |
416 | pdata++; | |
417 | ts->flags = pdata->flags; | |
2e4d2af9 | 418 | |
4191934c PM |
419 | ret = i2c_read(ts, 0xf0, "device control"); |
420 | if (ret < 0) | |
2e4d2af9 | 421 | goto err_detect_failed; |
4191934c | 422 | pr_info("synaptics: device control %x\n", ret); |
2e4d2af9 | 423 | |
4191934c PM |
424 | ret = i2c_read(ts, 0xf1, "interrupt enable"); |
425 | if (ret < 0) | |
2e4d2af9 | 426 | goto err_detect_failed; |
4191934c | 427 | pr_info("synaptics_ts_probe: interrupt enable %x\n", ret); |
2e4d2af9 | 428 | |
4191934c PM |
429 | ret = i2c_set(ts, 0xf1, 0, "disable interrupt"); |
430 | if (ret < 0) | |
2e4d2af9 | 431 | goto err_detect_failed; |
2e4d2af9 AH |
432 | |
433 | msg[0].addr = ts->client->addr; | |
434 | msg[0].flags = 0; | |
435 | msg[0].len = 1; | |
436 | msg[0].buf = buf0; | |
437 | buf0[0] = 0xe0; | |
438 | msg[1].addr = ts->client->addr; | |
439 | msg[1].flags = I2C_M_RD; | |
440 | msg[1].len = 8; | |
441 | msg[1].buf = buf1; | |
442 | ret = i2c_transfer(ts->client->adapter, msg, 2); | |
443 | if (ret < 0) { | |
4191934c | 444 | pr_err("i2c_transfer failed\n"); |
2e4d2af9 AH |
445 | goto err_detect_failed; |
446 | } | |
4191934c | 447 | pr_info("synaptics_ts_probe: 0xe0: %x %x %x %x %x %x %x %x\n", |
2e4d2af9 AH |
448 | buf1[0], buf1[1], buf1[2], buf1[3], |
449 | buf1[4], buf1[5], buf1[6], buf1[7]); | |
450 | ||
4191934c PM |
451 | ret = i2c_set(ts, 0xff, 0x10, "page select = 0x10"); |
452 | if (ret < 0) | |
2e4d2af9 | 453 | goto err_detect_failed; |
4191934c | 454 | |
2e4d2af9 AH |
455 | ret = i2c_smbus_read_word_data(ts->client, 0x04); |
456 | if (ret < 0) { | |
261314a9 | 457 | pr_err("i2c_smbus_read_word_data failed\n"); |
2e4d2af9 AH |
458 | goto err_detect_failed; |
459 | } | |
460 | ts->max[0] = max_x = (ret >> 8 & 0xff) | ((ret & 0x1f) << 8); | |
461 | ret = i2c_smbus_read_word_data(ts->client, 0x06); | |
462 | if (ret < 0) { | |
261314a9 | 463 | pr_err("i2c_smbus_read_word_data failed\n"); |
2e4d2af9 AH |
464 | goto err_detect_failed; |
465 | } | |
466 | ts->max[1] = max_y = (ret >> 8 & 0xff) | ((ret & 0x1f) << 8); | |
467 | if (ts->flags & SYNAPTICS_SWAP_XY) | |
468 | swap(max_x, max_y); | |
469 | ||
261314a9 PM |
470 | /* will also switch back to page 0x04 */ |
471 | ret = synaptics_init_panel(ts); | |
2e4d2af9 | 472 | if (ret < 0) { |
261314a9 | 473 | pr_err("synaptics_init_panel failed\n"); |
2e4d2af9 AH |
474 | goto err_detect_failed; |
475 | } | |
476 | ||
477 | ts->input_dev = input_allocate_device(); | |
478 | if (ts->input_dev == NULL) { | |
479 | ret = -ENOMEM; | |
261314a9 | 480 | pr_err("synaptics: Failed to allocate input device\n"); |
2e4d2af9 AH |
481 | goto err_input_dev_alloc_failed; |
482 | } | |
483 | ts->input_dev->name = "synaptics-rmi-touchscreen"; | |
4191934c PM |
484 | ts->input_dev->phys = "msm/input0"; |
485 | ts->input_dev->id.bustype = BUS_I2C; | |
486 | ||
487 | __set_bit(EV_SYN, ts->input_dev->evbit); | |
488 | __set_bit(EV_KEY, ts->input_dev->evbit); | |
489 | __set_bit(BTN_TOUCH, ts->input_dev->keybit); | |
490 | __set_bit(BTN_2, ts->input_dev->keybit); | |
491 | __set_bit(EV_ABS, ts->input_dev->evbit); | |
492 | ||
493 | compute_areas(ts, pdata, max_x, max_y); | |
494 | ||
495 | ||
2e4d2af9 AH |
496 | ret = input_register_device(ts->input_dev); |
497 | if (ret) { | |
4191934c PM |
498 | pr_err("synaptics: Unable to register %s input device\n", |
499 | ts->input_dev->name); | |
2e4d2af9 AH |
500 | goto err_input_register_device_failed; |
501 | } | |
502 | if (client->irq) { | |
4191934c PM |
503 | ret = request_irq(client->irq, synaptics_ts_irq_handler, |
504 | 0, client->name, ts); | |
2e4d2af9 | 505 | if (ret == 0) { |
4191934c | 506 | ret = i2c_set(ts, 0xf1, 0x01, "enable abs int"); |
2e4d2af9 AH |
507 | if (ret) |
508 | free_irq(client->irq, ts); | |
509 | } | |
510 | if (ret == 0) | |
511 | ts->use_irq = 1; | |
512 | else | |
513 | dev_err(&client->dev, "request_irq failed\n"); | |
514 | } | |
515 | if (!ts->use_irq) { | |
516 | hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | |
517 | ts->timer.function = synaptics_ts_timer_func; | |
518 | hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL); | |
519 | } | |
520 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
521 | ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; | |
522 | ts->early_suspend.suspend = synaptics_ts_early_suspend; | |
523 | ts->early_suspend.resume = synaptics_ts_late_resume; | |
524 | register_early_suspend(&ts->early_suspend); | |
525 | #endif | |
526 | ||
261314a9 PM |
527 | pr_info("synaptics: Start touchscreen %s in %s mode\n", |
528 | ts->input_dev->name, ts->use_irq ? "interrupt" : "polling"); | |
2e4d2af9 AH |
529 | |
530 | return 0; | |
531 | ||
532 | err_input_register_device_failed: | |
533 | input_free_device(ts->input_dev); | |
534 | ||
535 | err_input_dev_alloc_failed: | |
536 | err_detect_failed: | |
537 | err_power_failed: | |
538 | kfree(ts); | |
539 | err_alloc_data_failed: | |
540 | err_check_functionality_failed: | |
541 | return ret; | |
542 | } | |
543 | ||
544 | static int synaptics_ts_remove(struct i2c_client *client) | |
545 | { | |
546 | struct synaptics_ts_data *ts = i2c_get_clientdata(client); | |
547 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
548 | unregister_early_suspend(&ts->early_suspend); | |
549 | #endif | |
550 | if (ts->use_irq) | |
551 | free_irq(client->irq, ts); | |
552 | else | |
553 | hrtimer_cancel(&ts->timer); | |
554 | input_unregister_device(ts->input_dev); | |
555 | kfree(ts); | |
556 | return 0; | |
557 | } | |
558 | ||
261314a9 | 559 | #ifdef CONFIG_PM |
2e4d2af9 AH |
560 | static int synaptics_ts_suspend(struct i2c_client *client, pm_message_t mesg) |
561 | { | |
562 | int ret; | |
563 | struct synaptics_ts_data *ts = i2c_get_clientdata(client); | |
564 | ||
565 | if (ts->use_irq) | |
566 | disable_irq(client->irq); | |
567 | else | |
568 | hrtimer_cancel(&ts->timer); | |
569 | ret = cancel_work_sync(&ts->work); | |
570 | if (ret && ts->use_irq) /* if work was pending disable-count is now 2 */ | |
571 | enable_irq(client->irq); | |
261314a9 PM |
572 | i2c_set(ts, 0xf1, 0, "disable interrupt"); |
573 | i2c_set(ts, 0xf0, 0x86, "deep sleep"); | |
2e4d2af9 | 574 | |
2e4d2af9 AH |
575 | if (ts->power) { |
576 | ret = ts->power(0); | |
577 | if (ret < 0) | |
261314a9 | 578 | pr_err("synaptics_ts_suspend power off failed\n"); |
2e4d2af9 AH |
579 | } |
580 | return 0; | |
581 | } | |
582 | ||
583 | static int synaptics_ts_resume(struct i2c_client *client) | |
584 | { | |
585 | int ret; | |
586 | struct synaptics_ts_data *ts = i2c_get_clientdata(client); | |
587 | ||
588 | if (ts->power) { | |
589 | ret = ts->power(1); | |
590 | if (ret < 0) | |
261314a9 | 591 | pr_err("synaptics_ts_resume power on failed\n"); |
2e4d2af9 AH |
592 | } |
593 | ||
594 | synaptics_init_panel(ts); | |
595 | ||
261314a9 | 596 | if (ts->use_irq) { |
2e4d2af9 | 597 | enable_irq(client->irq); |
261314a9 PM |
598 | i2c_set(ts, 0xf1, 0x01, "enable abs int"); |
599 | } else | |
2e4d2af9 | 600 | hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL); |
2e4d2af9 AH |
601 | |
602 | return 0; | |
603 | } | |
604 | ||
605 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
606 | static void synaptics_ts_early_suspend(struct early_suspend *h) | |
607 | { | |
608 | struct synaptics_ts_data *ts; | |
609 | ts = container_of(h, struct synaptics_ts_data, early_suspend); | |
610 | synaptics_ts_suspend(ts->client, PMSG_SUSPEND); | |
611 | } | |
612 | ||
613 | static void synaptics_ts_late_resume(struct early_suspend *h) | |
614 | { | |
615 | struct synaptics_ts_data *ts; | |
616 | ts = container_of(h, struct synaptics_ts_data, early_suspend); | |
617 | synaptics_ts_resume(ts->client); | |
618 | } | |
619 | #endif | |
261314a9 PM |
620 | #else |
621 | #define synaptics_ts_suspend NULL | |
622 | #define synaptics_ts_resume NULL | |
623 | #endif | |
624 | ||
625 | ||
2e4d2af9 AH |
626 | |
627 | static const struct i2c_device_id synaptics_ts_id[] = { | |
628 | { SYNAPTICS_I2C_RMI_NAME, 0 }, | |
629 | { } | |
630 | }; | |
631 | ||
632 | static struct i2c_driver synaptics_ts_driver = { | |
633 | .probe = synaptics_ts_probe, | |
634 | .remove = synaptics_ts_remove, | |
635 | #ifndef CONFIG_HAS_EARLYSUSPEND | |
636 | .suspend = synaptics_ts_suspend, | |
637 | .resume = synaptics_ts_resume, | |
638 | #endif | |
639 | .id_table = synaptics_ts_id, | |
640 | .driver = { | |
641 | .name = SYNAPTICS_I2C_RMI_NAME, | |
642 | }, | |
643 | }; | |
644 | ||
645 | static int __devinit synaptics_ts_init(void) | |
646 | { | |
647 | synaptics_wq = create_singlethread_workqueue("synaptics_wq"); | |
648 | if (!synaptics_wq) | |
649 | return -ENOMEM; | |
650 | return i2c_add_driver(&synaptics_ts_driver); | |
651 | } | |
652 | ||
653 | static void __exit synaptics_ts_exit(void) | |
654 | { | |
655 | i2c_del_driver(&synaptics_ts_driver); | |
656 | if (synaptics_wq) | |
657 | destroy_workqueue(synaptics_wq); | |
658 | } | |
659 | ||
660 | module_init(synaptics_ts_init); | |
661 | module_exit(synaptics_ts_exit); | |
662 | ||
663 | MODULE_DESCRIPTION("Synaptics Touchscreen Driver"); | |
664 | MODULE_LICENSE("GPL"); | |
261314a9 | 665 | MODULE_AUTHOR("Arve Hjønnevåg <arve@android.com>"); |