Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | /* |
2 | * Synaptics DSX touchscreen driver | |
3 | * | |
4 | * Copyright (C) 2012 Synaptics Incorporated | |
5 | * | |
6 | * Copyright (C) 2012 Alexandra Chin <alexandra.chin@tw.synaptics.com> | |
7 | * Copyright (C) 2012 Scott Lin <scott.lin@tw.synaptics.com> | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | */ | |
19 | #define DEBUG 1 | |
20 | #include <linux/kernel.h> | |
21 | #include <linux/module.h> | |
22 | #include <linux/slab.h> | |
23 | #include <linux/i2c.h> | |
24 | #include <linux/interrupt.h> | |
25 | #include <linux/delay.h> | |
26 | #include <linux/input.h> | |
27 | #include <linux/gpio.h> | |
28 | #include <linux/regulator/consumer.h> | |
29 | #include <linux/dma-mapping.h> | |
30 | #include <linux/kthread.h> | |
31 | #include <cust_eint.h> | |
32 | #include <mach/mt_pm_ldo.h> | |
33 | #include <mach/mt_typedefs.h> | |
34 | #include <mach/mt_boot.h> | |
35 | #include "cust_gpio_usage.h" | |
36 | #include "tpd.h" | |
37 | ||
38 | #include "synaptics_dsx_i2c.h" | |
39 | #include "synaptics_dsx.h" | |
40 | #include "tpd_custom_synaptics.h" | |
41 | #ifdef KERNEL_ABOVE_2_6_38 | |
42 | #include <linux/input/mt.h> | |
43 | #endif | |
44 | ||
45 | #define DRIVER_NAME "synaptics_dsx_i2c" | |
46 | #define INPUT_PHYS_NAME "synaptics_dsx_i2c/input0" | |
47 | ||
48 | ||
49 | #define TPD_POWER_SOURCE MT6323_POWER_LDO_VGP1 | |
50 | #define TPD_I2C_NUMBER 0 | |
51 | #define TPD_I2C_ADDR 0x38 | |
52 | ||
53 | #ifdef KERNEL_ABOVE_2_6_38 | |
54 | #define TYPE_B_PROTOCOL | |
55 | #endif | |
56 | ||
57 | #define NO_0D_WHILE_2D | |
58 | /* | |
59 | #define REPORT_2D_Z | |
60 | */ | |
61 | #define REPORT_2D_W | |
62 | ||
63 | #define F12_DATA_15_WORKAROUND | |
64 | ||
65 | /* | |
66 | #define IGNORE_FN_INIT_FAILURE | |
67 | */ | |
68 | ||
69 | #define RPT_TYPE (1 << 0) | |
70 | #define RPT_X_LSB (1 << 1) | |
71 | #define RPT_X_MSB (1 << 2) | |
72 | #define RPT_Y_LSB (1 << 3) | |
73 | #define RPT_Y_MSB (1 << 4) | |
74 | #define RPT_Z (1 << 5) | |
75 | #define RPT_WX (1 << 6) | |
76 | #define RPT_WY (1 << 7) | |
77 | #define RPT_DEFAULT (RPT_TYPE | RPT_X_LSB | RPT_X_MSB | RPT_Y_LSB | RPT_Y_MSB) | |
78 | ||
79 | #define EXP_FN_WORK_DELAY_MS 1000 /* ms */ | |
80 | #define SYN_I2C_RETRY_TIMES 10 | |
81 | #define MAX_F11_TOUCH_WIDTH 15 | |
82 | ||
83 | #define CHECK_STATUS_TIMEOUT_MS 100 | |
84 | #define DELAY_S7300_BOOT_READY 160 | |
85 | #define DELAY_S7300_RESET 20 | |
86 | #define DELAY_S7300_RESET_READY 90 | |
87 | #define I2C_DMA_LIMIT 252 | |
88 | ||
89 | #define F01_STD_QUERY_LEN 21 | |
90 | #define F01_BUID_ID_OFFSET 18 | |
91 | #define F11_STD_QUERY_LEN 9 | |
92 | #define F11_STD_CTRL_LEN 10 | |
93 | #define F11_STD_DATA_LEN 12 | |
94 | ||
95 | #define STATUS_NO_ERROR 0x00 | |
96 | #define STATUS_RESET_OCCURRED 0x01 | |
97 | #define STATUS_INVALID_CONFIG 0x02 | |
98 | #define STATUS_DEVICE_FAILURE 0x03 | |
99 | #define STATUS_CONFIG_CRC_FAILURE 0x04 | |
100 | #define STATUS_FIRMWARE_CRC_FAILURE 0x05 | |
101 | #define STATUS_CRC_IN_PROGRESS 0x06 | |
102 | ||
103 | #define NORMAL_OPERATION (0 << 0) | |
104 | #define SENSOR_SLEEP (1 << 0) | |
105 | #define NO_SLEEP_OFF (0 << 2) | |
106 | #define NO_SLEEP_ON (1 << 2) | |
107 | #define CONFIGURED (1 << 7) | |
108 | ||
109 | // for MTK | |
110 | static struct task_struct *thread = NULL; | |
111 | static DECLARE_WAIT_QUEUE_HEAD(waiter); | |
112 | static int tpd_halt = 0; | |
113 | static int tpd_flag = 0; | |
114 | #ifdef TPD_HAVE_BUTTON | |
115 | static int tpd_keys_local[TPD_KEY_COUNT] = TPD_KEYS; | |
116 | static int tpd_keys_dim_local[TPD_KEY_COUNT][4] = TPD_KEYS_DIM; | |
117 | #endif | |
118 | static u8 boot_mode; | |
119 | ||
120 | // for DMA accessing | |
121 | static u8 *gpwDMABuf_va = NULL; | |
122 | static u32 gpwDMABuf_pa = NULL; | |
123 | static u8 *gprDMABuf_va = NULL; | |
124 | static u32 gprDMABuf_pa = NULL; | |
125 | struct i2c_msg *read_msg; | |
126 | ||
127 | // extern function | |
128 | ||
129 | extern void mt_eint_unmask(unsigned int line); | |
130 | extern void mt_eint_mask(unsigned int line); | |
131 | extern void mt_eint_set_hw_debounce(unsigned int eintno, unsigned int ms); | |
132 | extern unsigned int mt_eint_set_sens(unsigned int eintno, unsigned int sens); | |
133 | extern void mt_eint_registration(unsigned int eint_num, unsigned int flag, void (EINT_FUNC_PTR) (void), unsigned int is_auto_umask); | |
134 | ||
135 | ||
136 | static void tpd_eint_handler(void); | |
137 | static int touch_event_handler(void *data); | |
138 | ||
139 | static int synaptics_rmi4_i2c_read(struct synaptics_rmi4_data *rmi4_data, | |
140 | unsigned short addr, unsigned char *data, | |
141 | unsigned short length); | |
142 | ||
143 | static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data, | |
144 | unsigned short addr, unsigned char *data, | |
145 | unsigned short length); | |
146 | ||
147 | static int synaptics_rmi4_f12_set_enables(struct synaptics_rmi4_data *rmi4_data, | |
148 | unsigned short ctrl28); | |
149 | ||
150 | static int synaptics_rmi4_free_fingers(struct synaptics_rmi4_data *rmi4_data); | |
151 | static int synaptics_rmi4_reinit_device(struct synaptics_rmi4_data *rmi4_data); | |
152 | static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data); | |
153 | ||
154 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
155 | static ssize_t synaptics_rmi4_full_pm_cycle_show(struct device *dev, | |
156 | struct device_attribute *attr, char *buf); | |
157 | ||
158 | static ssize_t synaptics_rmi4_full_pm_cycle_store(struct device *dev, | |
159 | struct device_attribute *attr, const char *buf, size_t count); | |
160 | ||
161 | static void synaptics_rmi4_early_suspend(struct early_suspend *h); | |
162 | ||
163 | static void synaptics_rmi4_late_resume(struct early_suspend *h); | |
164 | #endif | |
165 | ||
166 | static int synaptics_rmi4_suspend(struct device *dev); | |
167 | ||
168 | static int synaptics_rmi4_resume(struct device *dev); | |
169 | ||
170 | static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev, | |
171 | struct device_attribute *attr, const char *buf, size_t count); | |
172 | ||
173 | static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev, | |
174 | struct device_attribute *attr, char *buf); | |
175 | ||
176 | static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev, | |
177 | struct device_attribute *attr, char *buf); | |
178 | ||
179 | static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev, | |
180 | struct device_attribute *attr, char *buf); | |
181 | ||
182 | static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev, | |
183 | struct device_attribute *attr, char *buf); | |
184 | ||
185 | static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev, | |
186 | struct device_attribute *attr, const char *buf, size_t count); | |
187 | ||
188 | static ssize_t synaptics_rmi4_suspend_store(struct device *dev, | |
189 | struct device_attribute *attr, const char *buf, size_t count); | |
190 | ||
191 | struct synaptics_rmi4_f01_device_status { | |
192 | union { | |
193 | struct { | |
194 | unsigned char status_code:4; | |
195 | unsigned char reserved:2; | |
196 | unsigned char flash_prog:1; | |
197 | unsigned char unconfigured:1; | |
198 | } __packed; | |
199 | unsigned char data[1]; | |
200 | }; | |
201 | }; | |
202 | ||
203 | struct synaptics_rmi4_f12_query_5 { | |
204 | union { | |
205 | struct { | |
206 | unsigned char size_of_query6; | |
207 | struct { | |
208 | unsigned char ctrl0_is_present:1; | |
209 | unsigned char ctrl1_is_present:1; | |
210 | unsigned char ctrl2_is_present:1; | |
211 | unsigned char ctrl3_is_present:1; | |
212 | unsigned char ctrl4_is_present:1; | |
213 | unsigned char ctrl5_is_present:1; | |
214 | unsigned char ctrl6_is_present:1; | |
215 | unsigned char ctrl7_is_present:1; | |
216 | } __packed; | |
217 | struct { | |
218 | unsigned char ctrl8_is_present:1; | |
219 | unsigned char ctrl9_is_present:1; | |
220 | unsigned char ctrl10_is_present:1; | |
221 | unsigned char ctrl11_is_present:1; | |
222 | unsigned char ctrl12_is_present:1; | |
223 | unsigned char ctrl13_is_present:1; | |
224 | unsigned char ctrl14_is_present:1; | |
225 | unsigned char ctrl15_is_present:1; | |
226 | } __packed; | |
227 | struct { | |
228 | unsigned char ctrl16_is_present:1; | |
229 | unsigned char ctrl17_is_present:1; | |
230 | unsigned char ctrl18_is_present:1; | |
231 | unsigned char ctrl19_is_present:1; | |
232 | unsigned char ctrl20_is_present:1; | |
233 | unsigned char ctrl21_is_present:1; | |
234 | unsigned char ctrl22_is_present:1; | |
235 | unsigned char ctrl23_is_present:1; | |
236 | } __packed; | |
237 | struct { | |
238 | unsigned char ctrl24_is_present:1; | |
239 | unsigned char ctrl25_is_present:1; | |
240 | unsigned char ctrl26_is_present:1; | |
241 | unsigned char ctrl27_is_present:1; | |
242 | unsigned char ctrl28_is_present:1; | |
243 | unsigned char ctrl29_is_present:1; | |
244 | unsigned char ctrl30_is_present:1; | |
245 | unsigned char ctrl31_is_present:1; | |
246 | } __packed; | |
247 | }; | |
248 | unsigned char data[5]; | |
249 | }; | |
250 | }; | |
251 | ||
252 | struct synaptics_rmi4_f12_query_8 { | |
253 | union { | |
254 | struct { | |
255 | unsigned char size_of_query9; | |
256 | struct { | |
257 | unsigned char data0_is_present:1; | |
258 | unsigned char data1_is_present:1; | |
259 | unsigned char data2_is_present:1; | |
260 | unsigned char data3_is_present:1; | |
261 | unsigned char data4_is_present:1; | |
262 | unsigned char data5_is_present:1; | |
263 | unsigned char data6_is_present:1; | |
264 | unsigned char data7_is_present:1; | |
265 | } __packed; | |
266 | struct { | |
267 | unsigned char data8_is_present:1; | |
268 | unsigned char data9_is_present:1; | |
269 | unsigned char data10_is_present:1; | |
270 | unsigned char data11_is_present:1; | |
271 | unsigned char data12_is_present:1; | |
272 | unsigned char data13_is_present:1; | |
273 | unsigned char data14_is_present:1; | |
274 | unsigned char data15_is_present:1; | |
275 | } __packed; | |
276 | }; | |
277 | unsigned char data[3]; | |
278 | }; | |
279 | }; | |
280 | ||
281 | struct synaptics_rmi4_f12_ctrl_8 { | |
282 | union { | |
283 | struct { | |
284 | unsigned char max_x_coord_lsb; | |
285 | unsigned char max_x_coord_msb; | |
286 | unsigned char max_y_coord_lsb; | |
287 | unsigned char max_y_coord_msb; | |
288 | unsigned char rx_pitch_lsb; | |
289 | unsigned char rx_pitch_msb; | |
290 | unsigned char tx_pitch_lsb; | |
291 | unsigned char tx_pitch_msb; | |
292 | unsigned char low_rx_clip; | |
293 | unsigned char high_rx_clip; | |
294 | unsigned char low_tx_clip; | |
295 | unsigned char high_tx_clip; | |
296 | unsigned char num_of_rx; | |
297 | unsigned char num_of_tx; | |
298 | }; | |
299 | unsigned char data[14]; | |
300 | }; | |
301 | }; | |
302 | ||
303 | struct synaptics_rmi4_f12_ctrl_23 { | |
304 | union { | |
305 | struct { | |
306 | unsigned char obj_type_enable; | |
307 | unsigned char max_reported_objects; | |
308 | }; | |
309 | unsigned char data[2]; | |
310 | }; | |
311 | }; | |
312 | ||
313 | struct synaptics_rmi4_f12_finger_data { | |
314 | unsigned char object_type_and_status; | |
315 | unsigned char x_lsb; | |
316 | unsigned char x_msb; | |
317 | unsigned char y_lsb; | |
318 | unsigned char y_msb; | |
319 | #ifdef REPORT_2D_Z | |
320 | unsigned char z; | |
321 | #endif | |
322 | #ifdef REPORT_2D_W | |
323 | unsigned char wx; | |
324 | unsigned char wy; | |
325 | #endif | |
326 | }; | |
327 | ||
328 | struct synaptics_rmi4_f1a_query { | |
329 | union { | |
330 | struct { | |
331 | unsigned char max_button_count:3; | |
332 | unsigned char reserved:5; | |
333 | unsigned char has_general_control:1; | |
334 | unsigned char has_interrupt_enable:1; | |
335 | unsigned char has_multibutton_select:1; | |
336 | unsigned char has_tx_rx_map:1; | |
337 | unsigned char has_perbutton_threshold:1; | |
338 | unsigned char has_release_threshold:1; | |
339 | unsigned char has_strongestbtn_hysteresis:1; | |
340 | unsigned char has_filter_strength:1; | |
341 | } __packed; | |
342 | unsigned char data[2]; | |
343 | }; | |
344 | }; | |
345 | ||
346 | struct synaptics_rmi4_f1a_control_0 { | |
347 | union { | |
348 | struct { | |
349 | unsigned char multibutton_report:2; | |
350 | unsigned char filter_mode:2; | |
351 | unsigned char reserved:4; | |
352 | } __packed; | |
353 | unsigned char data[1]; | |
354 | }; | |
355 | }; | |
356 | ||
357 | struct synaptics_rmi4_f1a_control { | |
358 | struct synaptics_rmi4_f1a_control_0 general_control; | |
359 | unsigned char button_int_enable; | |
360 | unsigned char multi_button; | |
361 | unsigned char *txrx_map; | |
362 | unsigned char *button_threshold; | |
363 | unsigned char button_release_threshold; | |
364 | unsigned char strongest_button_hysteresis; | |
365 | unsigned char filter_strength; | |
366 | }; | |
367 | ||
368 | struct synaptics_rmi4_f1a_handle { | |
369 | int button_bitmask_size; | |
370 | unsigned char max_count; | |
371 | unsigned char valid_button_count; | |
372 | unsigned char *button_data_buffer; | |
373 | unsigned char *button_map; | |
374 | struct synaptics_rmi4_f1a_query button_query; | |
375 | struct synaptics_rmi4_f1a_control button_control; | |
376 | }; | |
377 | ||
378 | struct synaptics_rmi4_exp_fhandler { | |
379 | struct synaptics_rmi4_exp_fn *exp_fn; | |
380 | bool insert; | |
381 | bool remove; | |
382 | struct list_head link; | |
383 | }; | |
384 | ||
385 | struct synaptics_rmi4_exp_fn_data { | |
386 | bool initialized; | |
387 | bool queue_work; | |
388 | struct mutex mutex; | |
389 | struct list_head list; | |
390 | struct delayed_work work; | |
391 | struct workqueue_struct *workqueue; | |
392 | struct synaptics_rmi4_data *rmi4_data; | |
393 | }; | |
394 | ||
395 | static struct synaptics_rmi4_exp_fn_data exp_data; | |
396 | ||
397 | static struct device_attribute attrs[] = { | |
398 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
399 | __ATTR(full_pm_cycle, (S_IRUGO | S_IWUGO), | |
400 | synaptics_rmi4_full_pm_cycle_show, | |
401 | synaptics_rmi4_full_pm_cycle_store), | |
402 | #endif | |
403 | __ATTR(reset, S_IWUGO, | |
404 | synaptics_rmi4_show_error, | |
405 | synaptics_rmi4_f01_reset_store), | |
406 | __ATTR(productinfo, S_IRUGO, | |
407 | synaptics_rmi4_f01_productinfo_show, | |
408 | synaptics_rmi4_store_error), | |
409 | __ATTR(buildid, S_IRUGO, | |
410 | synaptics_rmi4_f01_buildid_show, | |
411 | synaptics_rmi4_store_error), | |
412 | __ATTR(flashprog, S_IRUGO, | |
413 | synaptics_rmi4_f01_flashprog_show, | |
414 | synaptics_rmi4_store_error), | |
415 | __ATTR(0dbutton, (S_IRUGO | S_IWUGO), | |
416 | synaptics_rmi4_0dbutton_show, | |
417 | synaptics_rmi4_0dbutton_store), | |
418 | __ATTR(suspend, S_IWUGO, | |
419 | synaptics_rmi4_show_error, | |
420 | synaptics_rmi4_suspend_store), | |
421 | }; | |
422 | ||
423 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
424 | static ssize_t synaptics_rmi4_full_pm_cycle_show(struct device *dev, | |
425 | struct device_attribute *attr, char *buf) | |
426 | { | |
427 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); | |
428 | ||
429 | return snprintf(buf, PAGE_SIZE, "%u\n", | |
430 | rmi4_data->full_pm_cycle); | |
431 | } | |
432 | ||
433 | static ssize_t synaptics_rmi4_full_pm_cycle_store(struct device *dev, | |
434 | struct device_attribute *attr, const char *buf, size_t count) | |
435 | { | |
436 | unsigned int input; | |
437 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); | |
438 | ||
439 | if (sscanf(buf, "%u", &input) != 1) | |
440 | return -EINVAL; | |
441 | ||
442 | rmi4_data->full_pm_cycle = input > 0 ? 1 : 0; | |
443 | ||
444 | return count; | |
445 | } | |
446 | #endif | |
447 | ||
448 | static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev, | |
449 | struct device_attribute *attr, const char *buf, size_t count) | |
450 | { | |
451 | int retval; | |
452 | unsigned int reset; | |
453 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); | |
454 | ||
455 | if (sscanf(buf, "%u", &reset) != 1) | |
456 | return -EINVAL; | |
457 | ||
458 | if (reset != 1) | |
459 | return -EINVAL; | |
460 | ||
461 | retval = synaptics_rmi4_reset_device(rmi4_data); | |
462 | if (retval < 0) { | |
463 | dev_err(dev, | |
464 | "%s: Failed to issue reset command, error = %d\n", | |
465 | __func__, retval); | |
466 | return retval; | |
467 | } | |
468 | ||
469 | return count; | |
470 | } | |
471 | ||
472 | static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev, | |
473 | struct device_attribute *attr, char *buf) | |
474 | { | |
475 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); | |
476 | ||
477 | return snprintf(buf, PAGE_SIZE, "0x%02x 0x%02x\n", | |
478 | (rmi4_data->rmi4_mod_info.product_info[0]), | |
479 | (rmi4_data->rmi4_mod_info.product_info[1])); | |
480 | } | |
481 | ||
482 | static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev, | |
483 | struct device_attribute *attr, char *buf) | |
484 | { | |
485 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); | |
486 | ||
487 | return snprintf(buf, PAGE_SIZE, "%u\n", | |
488 | rmi4_data->firmware_id); | |
489 | } | |
490 | ||
491 | static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev, | |
492 | struct device_attribute *attr, char *buf) | |
493 | { | |
494 | int retval; | |
495 | struct synaptics_rmi4_f01_device_status device_status; | |
496 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); | |
497 | ||
498 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
499 | rmi4_data->f01_data_base_addr, | |
500 | device_status.data, | |
501 | sizeof(device_status.data)); | |
502 | if (retval < 0) { | |
503 | dev_err(dev, | |
504 | "%s: Failed to read device status, error = %d\n", | |
505 | __func__, retval); | |
506 | return retval; | |
507 | } | |
508 | ||
509 | return snprintf(buf, PAGE_SIZE, "%u\n", | |
510 | device_status.flash_prog); | |
511 | } | |
512 | ||
513 | static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev, | |
514 | struct device_attribute *attr, char *buf) | |
515 | { | |
516 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); | |
517 | ||
518 | return snprintf(buf, PAGE_SIZE, "%u\n", | |
519 | rmi4_data->button_0d_enabled); | |
520 | } | |
521 | ||
522 | static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev, | |
523 | struct device_attribute *attr, const char *buf, size_t count) | |
524 | { | |
525 | int retval; | |
526 | unsigned int input; | |
527 | unsigned char ii; | |
528 | unsigned char intr_enable; | |
529 | struct synaptics_rmi4_fn *fhandler; | |
530 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); | |
531 | struct synaptics_rmi4_device_info *rmi; | |
532 | ||
533 | rmi = &(rmi4_data->rmi4_mod_info); | |
534 | ||
535 | if (sscanf(buf, "%u", &input) != 1) | |
536 | return -EINVAL; | |
537 | ||
538 | input = input > 0 ? 1 : 0; | |
539 | ||
540 | if (rmi4_data->button_0d_enabled == input) | |
541 | return count; | |
542 | ||
543 | if (list_empty(&rmi->support_fn_list)) | |
544 | return -ENODEV; | |
545 | ||
546 | list_for_each_entry(fhandler, &rmi->support_fn_list, link) { | |
547 | if (fhandler->fn_number == SYNAPTICS_RMI4_F1A) { | |
548 | ii = fhandler->intr_reg_num; | |
549 | ||
550 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
551 | rmi4_data->f01_ctrl_base_addr + 1 + ii, | |
552 | &intr_enable, | |
553 | sizeof(intr_enable)); | |
554 | if (retval < 0) | |
555 | return retval; | |
556 | ||
557 | if (input == 1) | |
558 | intr_enable |= fhandler->intr_mask; | |
559 | else | |
560 | intr_enable &= ~fhandler->intr_mask; | |
561 | ||
562 | retval = synaptics_rmi4_i2c_write(rmi4_data, | |
563 | rmi4_data->f01_ctrl_base_addr + 1 + ii, | |
564 | &intr_enable, | |
565 | sizeof(intr_enable)); | |
566 | if (retval < 0) | |
567 | return retval; | |
568 | } | |
569 | } | |
570 | ||
571 | rmi4_data->button_0d_enabled = input; | |
572 | ||
573 | return count; | |
574 | } | |
575 | ||
576 | static ssize_t synaptics_rmi4_suspend_store(struct device *dev, | |
577 | struct device_attribute *attr, const char *buf, size_t count) | |
578 | { | |
579 | unsigned int input; | |
580 | ||
581 | if (sscanf(buf, "%u", &input) != 1) | |
582 | return -EINVAL; | |
583 | ||
584 | if (input == 1) | |
585 | synaptics_rmi4_suspend(dev); | |
586 | else if (input == 0) | |
587 | synaptics_rmi4_resume(dev); | |
588 | else | |
589 | return -EINVAL; | |
590 | ||
591 | return count; | |
592 | } | |
593 | ||
594 | /** | |
595 | * synaptics_rmi4_set_page() | |
596 | * | |
597 | * Called by synaptics_rmi4_i2c_read() and synaptics_rmi4_i2c_write(). | |
598 | * | |
599 | * This function writes to the page select register to switch to the | |
600 | * assigned page. | |
601 | */ | |
602 | static int synaptics_rmi4_set_page(struct synaptics_rmi4_data *rmi4_data, | |
603 | unsigned int address) | |
604 | { | |
605 | int retval = 0; | |
606 | unsigned char retry; | |
607 | unsigned char buf[PAGE_SELECT_LEN]; | |
608 | unsigned char page; | |
609 | struct i2c_client *i2c = rmi4_data->i2c_client; | |
610 | ||
611 | page = ((address >> 8) & MASK_8BIT); | |
612 | if (page != rmi4_data->current_page) { | |
613 | buf[0] = MASK_8BIT; | |
614 | buf[1] = page; | |
615 | for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) { | |
616 | retval = i2c_master_send(i2c, buf, PAGE_SELECT_LEN); | |
617 | if (retval != PAGE_SELECT_LEN) { | |
618 | dev_err(&i2c->dev, | |
619 | "%s: I2C retry %d\n", | |
620 | __func__, retry + 1); | |
621 | msleep(20); | |
622 | } else { | |
623 | rmi4_data->current_page = page; | |
624 | break; | |
625 | } | |
626 | } | |
627 | } else { | |
628 | retval = PAGE_SELECT_LEN; | |
629 | } | |
630 | ||
631 | return (retval == PAGE_SELECT_LEN) ? retval : -EIO; | |
632 | } | |
633 | ||
634 | /** | |
635 | * synaptics_rmi4_i2c_read() | |
636 | * | |
637 | * Called by various functions in this driver, and also exported to | |
638 | * other expansion Function modules such as rmi_dev. | |
639 | * | |
640 | * This function reads data of an arbitrary length from the sensor, | |
641 | * starting from an assigned register address of the sensor, via I2C | |
642 | * with a retry mechanism. | |
643 | */ | |
644 | static int synaptics_rmi4_i2c_read(struct synaptics_rmi4_data *rmi4_data, | |
645 | unsigned short addr, unsigned char *data, unsigned short length) | |
646 | { | |
647 | int retval; | |
648 | unsigned char retry; | |
649 | unsigned char buf; | |
650 | unsigned char *buf_va = NULL; | |
651 | int full = length / I2C_DMA_LIMIT; | |
652 | int partial = length % I2C_DMA_LIMIT; | |
653 | int total; | |
654 | int last; | |
655 | int ii; | |
656 | static int msg_length; | |
657 | ||
658 | mutex_lock(&(rmi4_data->rmi4_io_ctrl_mutex)); | |
659 | ||
660 | if(!gprDMABuf_va){ | |
661 | gprDMABuf_va = (u8 *)dma_alloc_coherent(NULL, 4096, &gprDMABuf_pa, GFP_KERNEL); | |
662 | if(!gprDMABuf_va){ | |
663 | printk("[Error] Allocate DMA I2C Buffer failed!\n"); | |
664 | } | |
665 | } | |
666 | ||
667 | buf_va = gprDMABuf_va; | |
668 | ||
669 | if ((full + 2) > msg_length) { | |
670 | kfree(read_msg); | |
671 | msg_length = full + 2; | |
672 | read_msg = kcalloc(msg_length, sizeof(struct i2c_msg), GFP_KERNEL); | |
673 | } | |
674 | ||
675 | read_msg[0].addr = rmi4_data->i2c_client->addr; | |
676 | read_msg[0].flags = 0; | |
677 | read_msg[0].len = 1; | |
678 | read_msg[0].buf = &buf; | |
679 | read_msg[0].timing = 400; | |
680 | ||
681 | if (partial) { | |
682 | total = full + 1; | |
683 | last = partial; | |
684 | } else { | |
685 | total = full; | |
686 | last = I2C_DMA_LIMIT; | |
687 | } | |
688 | ||
689 | for (ii = 1; ii <= total; ii++) { | |
690 | read_msg[ii].addr = rmi4_data->i2c_client->addr; | |
691 | read_msg[ii].flags = I2C_M_RD; | |
692 | read_msg[ii].len = (ii == total) ? last : I2C_DMA_LIMIT; | |
693 | read_msg[ii].buf = gprDMABuf_pa + I2C_DMA_LIMIT * (ii - 1); | |
694 | read_msg[ii].ext_flag = (rmi4_data->i2c_client->ext_flag | I2C_ENEXT_FLAG | I2C_DMA_FLAG); | |
695 | read_msg[ii].timing = 400; | |
696 | } | |
697 | ||
698 | buf = addr & MASK_8BIT; | |
699 | ||
700 | retval = synaptics_rmi4_set_page(rmi4_data, addr); | |
701 | if (retval != PAGE_SELECT_LEN) | |
702 | goto exit; | |
703 | ||
704 | for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) { | |
705 | if (i2c_transfer(rmi4_data->i2c_client->adapter, read_msg, (total + 1)) == (total + 1)) { | |
706 | ||
707 | retval = length; | |
708 | break; | |
709 | } | |
710 | dev_err(&rmi4_data->i2c_client->dev, | |
711 | "%s: I2C retry %d\n", | |
712 | __func__, retry + 1); | |
713 | msleep(20); | |
714 | } | |
715 | ||
716 | if (retry == SYN_I2C_RETRY_TIMES) { | |
717 | dev_err(&rmi4_data->i2c_client->dev, | |
718 | "%s: I2C read over retry limit\n", | |
719 | __func__); | |
720 | retval = -EIO; | |
721 | } | |
722 | ||
723 | memcpy(data, buf_va, length); | |
724 | ||
725 | exit: | |
726 | /* if(gprDMABuf_va){ */ | |
727 | /* dma_free_coherent(NULL, 4096, gprDMABuf_va, gprDMABuf_pa); */ | |
728 | /* gprDMABuf_va = NULL; */ | |
729 | /* gprDMABuf_pa = NULL; */ | |
730 | /* } */ | |
731 | mutex_unlock(&(rmi4_data->rmi4_io_ctrl_mutex)); | |
732 | ||
733 | return retval; | |
734 | } | |
735 | ||
736 | /** | |
737 | * synaptics_rmi4_i2c_write() | |
738 | * | |
739 | * Called by various functions in this driver, and also exported to | |
740 | * other expansion Function modules such as rmi_dev. | |
741 | * | |
742 | * This function writes data of an arbitrary length to the sensor, | |
743 | * starting from an assigned register address of the sensor, via I2C with | |
744 | * a retry mechanism. | |
745 | */ | |
746 | static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data, | |
747 | unsigned short addr, unsigned char *data, unsigned short length) | |
748 | { | |
749 | int retval; | |
750 | unsigned char retry; | |
751 | unsigned char buf[length + 1]; | |
752 | unsigned char *buf_va = NULL; | |
753 | mutex_lock(&(rmi4_data->rmi4_io_ctrl_mutex)); | |
754 | ||
755 | if(!gpwDMABuf_va){ | |
756 | gpwDMABuf_va = (u8 *)dma_alloc_coherent(NULL, 1024, &gpwDMABuf_pa, GFP_KERNEL); | |
757 | if(!gpwDMABuf_va){ | |
758 | printk("[Error] Allocate DMA I2C Buffer failed!\n"); | |
759 | } | |
760 | } | |
761 | buf_va = gpwDMABuf_va; | |
762 | ||
763 | struct i2c_msg msg[] = { | |
764 | { | |
765 | .addr = rmi4_data->i2c_client->addr, | |
766 | .flags = 0, | |
767 | .len = length + 1, | |
768 | .buf = gpwDMABuf_pa, | |
769 | .ext_flag=(rmi4_data->i2c_client->ext_flag|I2C_ENEXT_FLAG|I2C_DMA_FLAG), | |
770 | .timing = 400, | |
771 | } | |
772 | }; | |
773 | ||
774 | retval = synaptics_rmi4_set_page(rmi4_data, addr); | |
775 | if (retval != PAGE_SELECT_LEN) | |
776 | goto exit; | |
777 | ||
778 | buf_va[0] = addr & MASK_8BIT; | |
779 | ||
780 | memcpy(&buf_va[1],&data[0] , length); | |
781 | ||
782 | for (retry = 0; retry < SYN_I2C_RETRY_TIMES; retry++) { | |
783 | if (i2c_transfer(rmi4_data->i2c_client->adapter, msg, 1) == 1) { | |
784 | retval = length; | |
785 | break; | |
786 | } | |
787 | dev_err(&rmi4_data->i2c_client->dev, | |
788 | "%s: I2C retry %d\n", | |
789 | __func__, retry + 1); | |
790 | msleep(20); | |
791 | } | |
792 | ||
793 | if (retry == SYN_I2C_RETRY_TIMES) { | |
794 | dev_err(&rmi4_data->i2c_client->dev, | |
795 | "%s: I2C write over retry limit\n", | |
796 | __func__); | |
797 | retval = -EIO; | |
798 | } | |
799 | ||
800 | exit: | |
801 | /* if(gpwDMABuf_va){ */ | |
802 | /* dma_free_coherent(NULL, 1024, gpwDMABuf_va, gpwDMABuf_pa); */ | |
803 | /* gpwDMABuf_va = NULL; */ | |
804 | /* gpwDMABuf_pa = NULL; */ | |
805 | /* } */ | |
806 | mutex_unlock(&(rmi4_data->rmi4_io_ctrl_mutex)); | |
807 | ||
808 | return retval; | |
809 | } | |
810 | ||
811 | /** | |
812 | * synaptics_rmi4_f11_abs_report() | |
813 | * | |
814 | * Called by synaptics_rmi4_report_touch() when valid Function $11 | |
815 | * finger data has been detected. | |
816 | * | |
817 | * This function reads the Function $11 data registers, determines the | |
818 | * status of each finger supported by the Function, processes any | |
819 | * necessary coordinate manipulation, reports the finger data to | |
820 | * the input subsystem, and returns the number of fingers detected. | |
821 | */ | |
822 | static int synaptics_rmi4_f11_abs_report(struct synaptics_rmi4_data *rmi4_data, | |
823 | struct synaptics_rmi4_fn *fhandler) | |
824 | { | |
825 | int retval; | |
826 | unsigned char touch_count = 0; /* number of touch points */ | |
827 | unsigned char reg_index; | |
828 | unsigned char finger; | |
829 | unsigned char fingers_supported; | |
830 | unsigned char num_of_finger_status_regs; | |
831 | unsigned char finger_shift; | |
832 | unsigned char finger_status; | |
833 | unsigned char data_reg_blk_size; | |
834 | unsigned char finger_status_reg[3]; | |
835 | unsigned char data[F11_STD_DATA_LEN]; | |
836 | unsigned short data_addr; | |
837 | unsigned short data_offset; | |
838 | int x; | |
839 | int y; | |
840 | int wx; | |
841 | int wy; | |
842 | int temp; | |
843 | ||
844 | /* | |
845 | * The number of finger status registers is determined by the | |
846 | * maximum number of fingers supported - 2 bits per finger. So | |
847 | * the number of finger status registers to read is: | |
848 | * register_count = ceil(max_num_of_fingers / 4) | |
849 | */ | |
850 | fingers_supported = fhandler->num_of_data_points; | |
851 | num_of_finger_status_regs = (fingers_supported + 3) / 4; | |
852 | data_addr = fhandler->full_addr.data_base; | |
853 | data_reg_blk_size = fhandler->size_of_data_register_block; | |
854 | ||
855 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
856 | data_addr, | |
857 | finger_status_reg, | |
858 | num_of_finger_status_regs); | |
859 | if (retval < 0) | |
860 | return 0; | |
861 | ||
862 | for (finger = 0; finger < fingers_supported; finger++) { | |
863 | reg_index = finger / 4; | |
864 | finger_shift = (finger % 4) * 2; | |
865 | finger_status = (finger_status_reg[reg_index] >> finger_shift) | |
866 | & MASK_2BIT; | |
867 | ||
868 | /* | |
869 | * Each 2-bit finger status field represents the following: | |
870 | * 00 = finger not present | |
871 | * 01 = finger present and data accurate | |
872 | * 10 = finger present but data may be inaccurate | |
873 | * 11 = reserved | |
874 | */ | |
875 | #ifdef TYPE_B_PROTOCOL | |
876 | input_mt_slot(rmi4_data->input_dev, finger); | |
877 | input_mt_report_slot_state(rmi4_data->input_dev, | |
878 | MT_TOOL_FINGER, finger_status); | |
879 | #endif | |
880 | ||
881 | if (finger_status) { | |
882 | data_offset = data_addr + | |
883 | num_of_finger_status_regs + | |
884 | (finger * data_reg_blk_size); | |
885 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
886 | data_offset, | |
887 | data, | |
888 | data_reg_blk_size); | |
889 | if (retval < 0) | |
890 | return 0; | |
891 | ||
892 | x = (data[0] << 4) | (data[2] & MASK_4BIT); | |
893 | y = (data[1] << 4) | ((data[2] >> 4) & MASK_4BIT); | |
894 | wx = (data[3] & MASK_4BIT); | |
895 | wy = (data[3] >> 4) & MASK_4BIT; | |
896 | ||
897 | input_report_key(rmi4_data->input_dev, | |
898 | BTN_TOUCH, 1); | |
899 | input_report_key(rmi4_data->input_dev, | |
900 | BTN_TOOL_FINGER, 1); | |
901 | input_report_abs(rmi4_data->input_dev, | |
902 | ABS_MT_POSITION_X, x); | |
903 | input_report_abs(rmi4_data->input_dev, | |
904 | ABS_MT_POSITION_Y, y); | |
905 | #ifdef REPORT_2D_W | |
906 | input_report_abs(rmi4_data->input_dev, | |
907 | ABS_MT_TOUCH_MAJOR, max(wx, wy)); | |
908 | input_report_abs(rmi4_data->input_dev, | |
909 | ABS_MT_TOUCH_MINOR, min(wx, wy)); | |
910 | #endif | |
911 | #ifndef TYPE_B_PROTOCOL | |
912 | input_mt_sync(rmi4_data->input_dev); | |
913 | #endif | |
914 | ||
915 | #ifdef TPD_HAVE_BUTTON | |
916 | if (NORMAL_BOOT != boot_mode) | |
917 | { | |
918 | tpd_button(x, y, 1); | |
919 | } | |
920 | #endif | |
921 | dev_dbg(&rmi4_data->i2c_client->dev, | |
922 | "%s: SynFinger %d: status = 0x%02x [%4d %4d] [%4d %4d]\n", | |
923 | __func__, finger, | |
924 | finger_status, | |
925 | x, y, wx, wy); | |
926 | ||
927 | touch_count++; | |
928 | } | |
929 | } | |
930 | ||
931 | if (touch_count == 0) { | |
932 | input_report_key(rmi4_data->input_dev, | |
933 | BTN_TOUCH, 0); | |
934 | input_report_key(rmi4_data->input_dev, | |
935 | BTN_TOOL_FINGER, 0); | |
936 | #ifndef TYPE_B_PROTOCOL | |
937 | input_mt_sync(rmi4_data->input_dev); | |
938 | #endif | |
939 | #ifdef TPD_HAVE_BUTTON | |
940 | if (NORMAL_BOOT != boot_mode) | |
941 | { | |
942 | tpd_button(x, y, 0); | |
943 | } | |
944 | #endif | |
945 | } | |
946 | ||
947 | input_sync(rmi4_data->input_dev); | |
948 | ||
949 | return touch_count; | |
950 | } | |
951 | ||
952 | /** | |
953 | * synaptics_rmi4_f12_abs_report() | |
954 | * | |
955 | * Called by synaptics_rmi4_report_touch() when valid Function $12 | |
956 | * finger data has been detected. | |
957 | * | |
958 | * This function reads the Function $12 data registers, determines the | |
959 | * status of each finger supported by the Function, processes any | |
960 | * necessary coordinate manipulation, reports the finger data to | |
961 | * the input subsystem, and returns the number of fingers detected. | |
962 | */ | |
963 | static int synaptics_rmi4_f12_abs_report(struct synaptics_rmi4_data *rmi4_data, | |
964 | struct synaptics_rmi4_fn *fhandler) | |
965 | { | |
966 | int retval; | |
967 | unsigned char touch_count = 0; /* number of touch points */ | |
968 | unsigned char finger; | |
969 | unsigned char fingers_to_process; | |
970 | unsigned char finger_status; | |
971 | unsigned char size_of_2d_data; | |
972 | unsigned short data_addr; | |
973 | int x; | |
974 | int y; | |
975 | int wx; | |
976 | int wy; | |
977 | int temp; | |
978 | struct synaptics_rmi4_f12_extra_data *extra_data; | |
979 | struct synaptics_rmi4_f12_finger_data *data; | |
980 | struct synaptics_rmi4_f12_finger_data *finger_data; | |
981 | #ifdef F12_DATA_15_WORKAROUND | |
982 | static unsigned char fingers_already_present; | |
983 | #endif | |
984 | ||
985 | fingers_to_process = fhandler->num_of_data_points; | |
986 | data_addr = fhandler->full_addr.data_base; | |
987 | extra_data = (struct synaptics_rmi4_f12_extra_data *)fhandler->extra; | |
988 | size_of_2d_data = sizeof(struct synaptics_rmi4_f12_finger_data); | |
989 | ||
990 | ||
991 | /* Determine the total number of fingers to process */ | |
992 | if (extra_data->data15_size) { | |
993 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
994 | data_addr + extra_data->data15_offset, | |
995 | extra_data->data15_data, | |
996 | extra_data->data15_size); | |
997 | if (retval < 0) | |
998 | return 0; | |
999 | ||
1000 | /* Start checking from the highest bit */ | |
1001 | temp = extra_data->data15_size - 1; /* Highest byte */ | |
1002 | finger = (fingers_to_process - 1) % 8; /* Highest bit */ | |
1003 | do { | |
1004 | if (extra_data->data15_data[temp] & (1 << finger)) | |
1005 | break; | |
1006 | ||
1007 | if (finger) { | |
1008 | finger--; | |
1009 | } else { | |
1010 | temp--; /* Move to the next lower byte */ | |
1011 | finger = 7; | |
1012 | } | |
1013 | ||
1014 | fingers_to_process--; | |
1015 | } while (fingers_to_process); | |
1016 | ||
1017 | dev_dbg(&rmi4_data->i2c_client->dev, | |
1018 | "%s: Number of fingers to process = %d\n", | |
1019 | __func__, fingers_to_process); | |
1020 | } | |
1021 | ||
1022 | #ifdef F12_DATA_15_WORKAROUND | |
1023 | fingers_to_process = max(fingers_to_process, fingers_already_present); | |
1024 | #endif | |
1025 | ||
1026 | if (!fingers_to_process) { | |
1027 | synaptics_rmi4_free_fingers(rmi4_data); | |
1028 | return 0; | |
1029 | } | |
1030 | ||
1031 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1032 | data_addr + extra_data->data1_offset, | |
1033 | (unsigned char *)fhandler->data, | |
1034 | fingers_to_process * size_of_2d_data); | |
1035 | if (retval < 0) | |
1036 | return 0; | |
1037 | ||
1038 | data = (struct synaptics_rmi4_f12_finger_data *)fhandler->data; | |
1039 | ||
1040 | for (finger = 0; finger < fingers_to_process; finger++) { | |
1041 | finger_data = data + finger; | |
1042 | finger_status = finger_data->object_type_and_status & MASK_1BIT; | |
1043 | ||
1044 | #ifdef TYPE_B_PROTOCOL | |
1045 | input_mt_slot(rmi4_data->input_dev, finger); | |
1046 | input_mt_report_slot_state(rmi4_data->input_dev, | |
1047 | MT_TOOL_FINGER, finger_status); | |
1048 | #endif | |
1049 | ||
1050 | if (finger_status) { | |
1051 | #ifdef F12_DATA_15_WORKAROUND | |
1052 | fingers_already_present = finger + 1; | |
1053 | #endif | |
1054 | ||
1055 | x = (finger_data->x_msb << 8) | (finger_data->x_lsb); | |
1056 | y = (finger_data->y_msb << 8) | (finger_data->y_lsb); | |
1057 | #ifdef REPORT_2D_W | |
1058 | wx = finger_data->wx; | |
1059 | wy = finger_data->wy; | |
1060 | #endif | |
1061 | ||
1062 | input_report_key(rmi4_data->input_dev, | |
1063 | BTN_TOUCH, 1); | |
1064 | input_report_key(rmi4_data->input_dev, | |
1065 | BTN_TOOL_FINGER, 1); | |
1066 | input_report_abs(rmi4_data->input_dev, | |
1067 | ABS_MT_POSITION_X, x); | |
1068 | input_report_abs(rmi4_data->input_dev, | |
1069 | ABS_MT_POSITION_Y, y); | |
1070 | #ifdef REPORT_2D_W | |
1071 | input_report_abs(rmi4_data->input_dev, | |
1072 | ABS_MT_TOUCH_MAJOR, max(wx, wy)); | |
1073 | input_report_abs(rmi4_data->input_dev, | |
1074 | ABS_MT_TOUCH_MINOR, min(wx, wy)); | |
1075 | #endif | |
1076 | #ifndef TYPE_B_PROTOCOL | |
1077 | input_mt_sync(rmi4_data->input_dev); | |
1078 | #endif | |
1079 | ||
1080 | dev_dbg(&rmi4_data->i2c_client->dev, | |
1081 | "%s: SynFinger %d: status = 0x%02x [%4d %4d] [%4d %4d]\n", | |
1082 | __func__, finger, | |
1083 | finger_status, | |
1084 | x, y, wx, wy); | |
1085 | ||
1086 | touch_count++; | |
1087 | } | |
1088 | } | |
1089 | ||
1090 | if (touch_count == 0) { | |
1091 | input_report_key(rmi4_data->input_dev, | |
1092 | BTN_TOUCH, 0); | |
1093 | input_report_key(rmi4_data->input_dev, | |
1094 | BTN_TOOL_FINGER, 0); | |
1095 | #ifndef TYPE_B_PROTOCOL | |
1096 | input_mt_sync(rmi4_data->input_dev); | |
1097 | #endif | |
1098 | } | |
1099 | ||
1100 | input_sync(rmi4_data->input_dev); | |
1101 | ||
1102 | return touch_count; | |
1103 | } | |
1104 | ||
1105 | static void synaptics_rmi4_f1a_report(struct synaptics_rmi4_data *rmi4_data, | |
1106 | struct synaptics_rmi4_fn *fhandler) | |
1107 | { | |
1108 | int retval; | |
1109 | unsigned char touch_count = 0; | |
1110 | unsigned char button; | |
1111 | unsigned char index; | |
1112 | unsigned char shift; | |
1113 | unsigned char status; | |
1114 | unsigned char *data; | |
1115 | unsigned short data_addr = fhandler->full_addr.data_base; | |
1116 | struct synaptics_rmi4_f1a_handle *f1a = fhandler->data; | |
1117 | static unsigned char do_once = 1; | |
1118 | static bool current_status[MAX_NUMBER_OF_BUTTONS]; | |
1119 | #ifdef NO_0D_WHILE_2D | |
1120 | static bool before_2d_status[MAX_NUMBER_OF_BUTTONS]; | |
1121 | static bool while_2d_status[MAX_NUMBER_OF_BUTTONS]; | |
1122 | #endif | |
1123 | ||
1124 | if (do_once) { | |
1125 | memset(current_status, 0, sizeof(current_status)); | |
1126 | #ifdef NO_0D_WHILE_2D | |
1127 | memset(before_2d_status, 0, sizeof(before_2d_status)); | |
1128 | memset(while_2d_status, 0, sizeof(while_2d_status)); | |
1129 | #endif | |
1130 | do_once = 0; | |
1131 | } | |
1132 | ||
1133 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1134 | data_addr, | |
1135 | f1a->button_data_buffer, | |
1136 | f1a->button_bitmask_size); | |
1137 | if (retval < 0) { | |
1138 | dev_err(&rmi4_data->i2c_client->dev, | |
1139 | "%s: Failed to read button data registers\n", | |
1140 | __func__); | |
1141 | return; | |
1142 | } | |
1143 | ||
1144 | data = f1a->button_data_buffer; | |
1145 | ||
1146 | for (button = 0; button < f1a->valid_button_count; button++) { | |
1147 | index = button / 8; | |
1148 | shift = button % 8; | |
1149 | status = ((data[index] >> shift) & MASK_1BIT); | |
1150 | ||
1151 | if (current_status[button] == status) | |
1152 | continue; | |
1153 | else | |
1154 | current_status[button] = status; | |
1155 | ||
1156 | dev_dbg(&rmi4_data->i2c_client->dev, | |
1157 | "%s: Button %d (code %d) ->%d\n", | |
1158 | __func__, button, | |
1159 | f1a->button_map[button], | |
1160 | status); | |
1161 | #ifdef NO_0D_WHILE_2D | |
1162 | if (rmi4_data->fingers_on_2d == false) { | |
1163 | if (status == 1) { | |
1164 | before_2d_status[button] = 1; | |
1165 | } else { | |
1166 | if (while_2d_status[button] == 1) { | |
1167 | while_2d_status[button] = 0; | |
1168 | continue; | |
1169 | } else { | |
1170 | before_2d_status[button] = 0; | |
1171 | } | |
1172 | } | |
1173 | touch_count++; | |
1174 | input_report_key(rmi4_data->input_dev, | |
1175 | f1a->button_map[button], | |
1176 | status); | |
1177 | } else { | |
1178 | if (before_2d_status[button] == 1) { | |
1179 | before_2d_status[button] = 0; | |
1180 | touch_count++; | |
1181 | input_report_key(rmi4_data->input_dev, | |
1182 | f1a->button_map[button], | |
1183 | status); | |
1184 | } else { | |
1185 | if (status == 1) | |
1186 | while_2d_status[button] = 1; | |
1187 | else | |
1188 | while_2d_status[button] = 0; | |
1189 | } | |
1190 | } | |
1191 | #else | |
1192 | touch_count++; | |
1193 | input_report_key(rmi4_data->input_dev, | |
1194 | f1a->button_map[button], | |
1195 | status); | |
1196 | #endif | |
1197 | } | |
1198 | ||
1199 | if (touch_count) | |
1200 | input_sync(rmi4_data->input_dev); | |
1201 | ||
1202 | return; | |
1203 | } | |
1204 | ||
1205 | /** | |
1206 | * synaptics_rmi4_report_touch() | |
1207 | * | |
1208 | * Called by synaptics_rmi4_sensor_report(). | |
1209 | * | |
1210 | * This function calls the appropriate finger data reporting function | |
1211 | * based on the function handler it receives and returns the number of | |
1212 | * fingers detected. | |
1213 | */ | |
1214 | static void synaptics_rmi4_report_touch(struct synaptics_rmi4_data *rmi4_data, | |
1215 | struct synaptics_rmi4_fn *fhandler) | |
1216 | { | |
1217 | unsigned char touch_count_2d; | |
1218 | ||
1219 | dev_dbg(&rmi4_data->i2c_client->dev, | |
1220 | "%s: Function %02x reporting\n", | |
1221 | __func__, fhandler->fn_number); | |
1222 | ||
1223 | switch (fhandler->fn_number) { | |
1224 | case SYNAPTICS_RMI4_F11: | |
1225 | touch_count_2d = synaptics_rmi4_f11_abs_report(rmi4_data, | |
1226 | fhandler); | |
1227 | ||
1228 | if (touch_count_2d) | |
1229 | rmi4_data->fingers_on_2d = true; | |
1230 | else | |
1231 | rmi4_data->fingers_on_2d = false; | |
1232 | break; | |
1233 | case SYNAPTICS_RMI4_F12: | |
1234 | touch_count_2d = synaptics_rmi4_f12_abs_report(rmi4_data, | |
1235 | fhandler); | |
1236 | ||
1237 | if (touch_count_2d) | |
1238 | rmi4_data->fingers_on_2d = true; | |
1239 | else | |
1240 | rmi4_data->fingers_on_2d = false; | |
1241 | break; | |
1242 | case SYNAPTICS_RMI4_F1A: | |
1243 | synaptics_rmi4_f1a_report(rmi4_data, fhandler); | |
1244 | break; | |
1245 | default: | |
1246 | break; | |
1247 | } | |
1248 | ||
1249 | return; | |
1250 | } | |
1251 | ||
1252 | /** | |
1253 | * synaptics_rmi4_sensor_report() | |
1254 | * | |
1255 | * Called by synaptics_rmi4_irq(). | |
1256 | * | |
1257 | * This function determines the interrupt source(s) from the sensor | |
1258 | * and calls synaptics_rmi4_report_touch() with the appropriate | |
1259 | * function handler for each function with valid data inputs. | |
1260 | */ | |
1261 | static void synaptics_rmi4_sensor_report(struct synaptics_rmi4_data *rmi4_data) | |
1262 | { | |
1263 | int retval; | |
1264 | unsigned char data[MAX_INTR_REGISTERS + 1]; | |
1265 | unsigned char *intr = &data[1]; | |
1266 | struct synaptics_rmi4_f01_device_status status; | |
1267 | struct synaptics_rmi4_fn *fhandler; | |
1268 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; | |
1269 | struct synaptics_rmi4_device_info *rmi; | |
1270 | ||
1271 | rmi = &(rmi4_data->rmi4_mod_info); | |
1272 | ||
1273 | /* | |
1274 | * Get interrupt status information from F01 Data1 register to | |
1275 | * determine the source(s) that are flagging the interrupt. | |
1276 | */ | |
1277 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1278 | rmi4_data->f01_data_base_addr, | |
1279 | data, | |
1280 | rmi4_data->num_of_intr_regs + 1); | |
1281 | if (retval < 0) { | |
1282 | dev_err(&rmi4_data->i2c_client->dev, | |
1283 | "%s: Failed to read interrupt status\n", | |
1284 | __func__); | |
1285 | return; | |
1286 | } | |
1287 | ||
1288 | status.data[0] = data[0]; | |
1289 | if (status.unconfigured && !status.flash_prog) { | |
1290 | pr_notice("%s: spontaneous reset detected\n", __func__); | |
1291 | retval = synaptics_rmi4_reinit_device(rmi4_data); | |
1292 | if (retval < 0) { | |
1293 | dev_err(&rmi4_data->i2c_client->dev, | |
1294 | "%s: Failed to reinit device\n", | |
1295 | __func__); | |
1296 | } | |
1297 | return; | |
1298 | } | |
1299 | ||
1300 | /* | |
1301 | * Traverse the function handler list and service the source(s) | |
1302 | * of the interrupt accordingly. | |
1303 | */ | |
1304 | if (!list_empty(&rmi->support_fn_list)) { | |
1305 | list_for_each_entry(fhandler, &rmi->support_fn_list, link) { | |
1306 | if (fhandler->num_of_data_sources) { | |
1307 | if (fhandler->intr_mask & | |
1308 | intr[fhandler->intr_reg_num]) { | |
1309 | synaptics_rmi4_report_touch(rmi4_data, | |
1310 | fhandler); | |
1311 | } | |
1312 | } | |
1313 | } | |
1314 | } | |
1315 | ||
1316 | mutex_lock(&exp_data.mutex); | |
1317 | if (!list_empty(&exp_data.list)) { | |
1318 | list_for_each_entry(exp_fhandler, &exp_data.list, link) { | |
1319 | if (!exp_fhandler->insert && | |
1320 | !exp_fhandler->remove && | |
1321 | (exp_fhandler->exp_fn->attn != NULL)) | |
1322 | exp_fhandler->exp_fn->attn(rmi4_data, intr[0]); | |
1323 | } | |
1324 | } | |
1325 | mutex_unlock(&exp_data.mutex); | |
1326 | ||
1327 | return; | |
1328 | } | |
1329 | ||
1330 | /** | |
1331 | * synaptics_rmi4_irq() | |
1332 | * | |
1333 | * Called by the kernel when an interrupt occurs (when the sensor | |
1334 | * asserts the attention irq). | |
1335 | * | |
1336 | * This function is the ISR thread and handles the acquisition | |
1337 | * and the reporting of finger data when the presence of fingers | |
1338 | * is detected. | |
1339 | */ | |
1340 | ||
1341 | static void tpd_eint_handler(void) | |
1342 | { | |
1343 | TPD_DEBUG_PRINT_INT; | |
1344 | tpd_flag=1; | |
1345 | wake_up_interruptible(&waiter); | |
1346 | } | |
1347 | ||
1348 | static int touch_event_handler(void *data) | |
1349 | { | |
1350 | struct synaptics_rmi4_data *rmi4_data = data; | |
1351 | struct sched_param param = { .sched_priority = RTPM_PRIO_TPD }; | |
1352 | ||
1353 | sched_setscheduler(current, SCHED_RR, ¶m); | |
1354 | do{ | |
1355 | set_current_state(TASK_INTERRUPTIBLE); | |
1356 | ||
1357 | while (tpd_halt) { | |
1358 | tpd_flag = 0; | |
1359 | msleep(20); | |
1360 | } | |
1361 | ||
1362 | wait_event_interruptible(waiter, tpd_flag != 0); | |
1363 | tpd_flag = 0; | |
1364 | TPD_DEBUG_SET_TIME; | |
1365 | set_current_state(TASK_RUNNING); | |
1366 | ||
1367 | if (!rmi4_data->touch_stopped) | |
1368 | synaptics_rmi4_sensor_report(rmi4_data); | |
1369 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
1370 | }while(1); | |
1371 | ||
1372 | return 0; | |
1373 | } | |
1374 | ||
1375 | /** | |
1376 | * synaptics_rmi4_irq_enable() | |
1377 | * | |
1378 | * Called by synaptics_rmi4_probe() and the power management functions | |
1379 | * in this driver and also exported to other expansion Function modules | |
1380 | * such as rmi_dev. | |
1381 | * | |
1382 | * This function handles the enabling and disabling of the attention | |
1383 | * irq including the setting up of the ISR thread. | |
1384 | */ | |
1385 | static int synaptics_rmi4_irq_enable(struct synaptics_rmi4_data *rmi4_data, | |
1386 | bool enable) | |
1387 | { | |
1388 | int retval = 0; | |
1389 | unsigned char intr_status[MAX_INTR_REGISTERS]; | |
1390 | ||
1391 | if (enable) { | |
1392 | ||
1393 | /* Clear interrupts first */ | |
1394 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1395 | rmi4_data->f01_data_base_addr + 1, | |
1396 | intr_status, | |
1397 | rmi4_data->num_of_intr_regs); | |
1398 | if (retval < 0) | |
1399 | return retval; | |
1400 | ||
1401 | // set up irq | |
1402 | if (!rmi4_data->irq_enabled) { | |
1403 | mt_eint_set_sens(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_SENSITIVE); | |
1404 | mt_eint_set_hw_debounce(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_DEBOUNCE_CN); | |
1405 | //mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_DEBOUNCE_EN, CUST_EINT_POLARITY_LOW, , 1); | |
1406 | mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, EINTF_TRIGGER_FALLING, tpd_eint_handler, 1); | |
1407 | } | |
1408 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
1409 | rmi4_data->irq_enabled = true; | |
1410 | } else { | |
1411 | if (rmi4_data->irq_enabled) { | |
1412 | mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM); | |
1413 | rmi4_data->irq_enabled = false; | |
1414 | } | |
1415 | } | |
1416 | ||
1417 | return retval; | |
1418 | } | |
1419 | ||
1420 | static void synaptics_rmi4_set_intr_mask(struct synaptics_rmi4_fn *fhandler, | |
1421 | struct synaptics_rmi4_fn_desc *fd, | |
1422 | unsigned int intr_count) | |
1423 | { | |
1424 | unsigned char ii; | |
1425 | unsigned char intr_offset; | |
1426 | ||
1427 | fhandler->intr_reg_num = (intr_count + 7) / 8; | |
1428 | if (fhandler->intr_reg_num != 0) | |
1429 | fhandler->intr_reg_num -= 1; | |
1430 | ||
1431 | /* Set an enable bit for each data source */ | |
1432 | intr_offset = intr_count % 8; | |
1433 | fhandler->intr_mask = 0; | |
1434 | for (ii = intr_offset; | |
1435 | ii < ((fd->intr_src_count & MASK_3BIT) + | |
1436 | intr_offset); | |
1437 | ii++) | |
1438 | fhandler->intr_mask |= 1 << ii; | |
1439 | ||
1440 | return; | |
1441 | } | |
1442 | ||
1443 | static int synaptics_rmi4_f01_init(struct synaptics_rmi4_data *rmi4_data, | |
1444 | struct synaptics_rmi4_fn *fhandler, | |
1445 | struct synaptics_rmi4_fn_desc *fd, | |
1446 | unsigned int intr_count) | |
1447 | { | |
1448 | fhandler->fn_number = fd->fn_number; | |
1449 | fhandler->num_of_data_sources = fd->intr_src_count; | |
1450 | fhandler->data = NULL; | |
1451 | fhandler->extra = NULL; | |
1452 | ||
1453 | synaptics_rmi4_set_intr_mask(fhandler, fd, intr_count); | |
1454 | ||
1455 | rmi4_data->f01_query_base_addr = fd->query_base_addr; | |
1456 | rmi4_data->f01_ctrl_base_addr = fd->ctrl_base_addr; | |
1457 | rmi4_data->f01_data_base_addr = fd->data_base_addr; | |
1458 | rmi4_data->f01_cmd_base_addr = fd->cmd_base_addr; | |
1459 | ||
1460 | return 0; | |
1461 | } | |
1462 | ||
1463 | /** | |
1464 | * synaptics_rmi4_f11_init() | |
1465 | * | |
1466 | * Called by synaptics_rmi4_query_device(). | |
1467 | * | |
1468 | * This funtion parses information from the Function 11 registers | |
1469 | * and determines the number of fingers supported, x and y data ranges, | |
1470 | * offset to the associated interrupt status register, interrupt bit | |
1471 | * mask, and gathers finger data acquisition capabilities from the query | |
1472 | * registers. | |
1473 | */ | |
1474 | static int synaptics_rmi4_f11_init(struct synaptics_rmi4_data *rmi4_data, | |
1475 | struct synaptics_rmi4_fn *fhandler, | |
1476 | struct synaptics_rmi4_fn_desc *fd, | |
1477 | unsigned int intr_count) | |
1478 | { | |
1479 | int retval; | |
1480 | unsigned char abs_data_size; | |
1481 | unsigned char abs_data_blk_size; | |
1482 | unsigned char query[F11_STD_QUERY_LEN]; | |
1483 | unsigned char control[F11_STD_CTRL_LEN]; | |
1484 | ||
1485 | fhandler->fn_number = fd->fn_number; | |
1486 | fhandler->num_of_data_sources = fd->intr_src_count; | |
1487 | ||
1488 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1489 | fhandler->full_addr.query_base, | |
1490 | query, | |
1491 | sizeof(query)); | |
1492 | if (retval < 0) | |
1493 | return retval; | |
1494 | ||
1495 | /* Maximum number of fingers supported */ | |
1496 | if ((query[1] & MASK_3BIT) <= 4) | |
1497 | fhandler->num_of_data_points = (query[1] & MASK_3BIT) + 1; | |
1498 | else if ((query[1] & MASK_3BIT) == 5) | |
1499 | fhandler->num_of_data_points = 10; | |
1500 | ||
1501 | rmi4_data->num_of_fingers = fhandler->num_of_data_points; | |
1502 | ||
1503 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1504 | fhandler->full_addr.ctrl_base, | |
1505 | control, | |
1506 | sizeof(control)); | |
1507 | if (retval < 0) | |
1508 | return retval; | |
1509 | ||
1510 | /* Maximum x and y */ | |
1511 | rmi4_data->sensor_max_x = ((control[6] & MASK_8BIT) << 0) | | |
1512 | ((control[7] & MASK_4BIT) << 8); | |
1513 | rmi4_data->sensor_max_y = ((control[8] & MASK_8BIT) << 0) | | |
1514 | ((control[9] & MASK_4BIT) << 8); | |
1515 | #ifdef TPD_HAVE_BUTTON | |
1516 | rmi4_data->sensor_max_y = rmi4_data->sensor_max_y * TPD_DISPLAY_HEIGH_RATIO / TPD_TOUCH_HEIGH_RATIO; | |
1517 | #endif | |
1518 | dev_dbg(&rmi4_data->i2c_client->dev, | |
1519 | "%s: Function %02x max x = %d max y = %d\n", | |
1520 | __func__, fhandler->fn_number, | |
1521 | rmi4_data->sensor_max_x, | |
1522 | rmi4_data->sensor_max_y); | |
1523 | ||
1524 | rmi4_data->max_touch_width = MAX_F11_TOUCH_WIDTH; | |
1525 | ||
1526 | synaptics_rmi4_set_intr_mask(fhandler, fd, intr_count); | |
1527 | ||
1528 | abs_data_size = query[5] & MASK_2BIT; | |
1529 | abs_data_blk_size = 3 + (2 * (abs_data_size == 0 ? 1 : 0)); | |
1530 | fhandler->size_of_data_register_block = abs_data_blk_size; | |
1531 | fhandler->data = NULL; | |
1532 | fhandler->extra = NULL; | |
1533 | ||
1534 | return retval; | |
1535 | } | |
1536 | ||
1537 | static int synaptics_rmi4_f12_set_enables(struct synaptics_rmi4_data *rmi4_data, | |
1538 | unsigned short ctrl28) | |
1539 | { | |
1540 | int retval; | |
1541 | static unsigned short ctrl_28_address; | |
1542 | ||
1543 | if (ctrl28) | |
1544 | ctrl_28_address = ctrl28; | |
1545 | ||
1546 | retval = synaptics_rmi4_i2c_write(rmi4_data, | |
1547 | ctrl_28_address, | |
1548 | &rmi4_data->report_enable, | |
1549 | sizeof(rmi4_data->report_enable)); | |
1550 | if (retval < 0) | |
1551 | return retval; | |
1552 | ||
1553 | return retval; | |
1554 | } | |
1555 | ||
1556 | /** | |
1557 | * synaptics_rmi4_f12_init() | |
1558 | * | |
1559 | * Called by synaptics_rmi4_query_device(). | |
1560 | * | |
1561 | * This funtion parses information from the Function 12 registers and | |
1562 | * determines the number of fingers supported, offset to the data1 | |
1563 | * register, x and y data ranges, offset to the associated interrupt | |
1564 | * status register, interrupt bit mask, and allocates memory resources | |
1565 | * for finger data acquisition. | |
1566 | */ | |
1567 | static int synaptics_rmi4_f12_init(struct synaptics_rmi4_data *rmi4_data, | |
1568 | struct synaptics_rmi4_fn *fhandler, | |
1569 | struct synaptics_rmi4_fn_desc *fd, | |
1570 | unsigned int intr_count) | |
1571 | { | |
1572 | int retval; | |
1573 | unsigned char size_of_2d_data; | |
1574 | unsigned char size_of_query8; | |
1575 | unsigned char ctrl_8_offset; | |
1576 | unsigned char ctrl_23_offset; | |
1577 | unsigned char ctrl_28_offset; | |
1578 | unsigned char num_of_fingers; | |
1579 | struct synaptics_rmi4_f12_extra_data *extra_data; | |
1580 | struct synaptics_rmi4_f12_query_5 query_5; | |
1581 | struct synaptics_rmi4_f12_query_8 query_8; | |
1582 | struct synaptics_rmi4_f12_ctrl_8 ctrl_8; | |
1583 | struct synaptics_rmi4_f12_ctrl_23 ctrl_23; | |
1584 | ||
1585 | fhandler->fn_number = fd->fn_number; | |
1586 | fhandler->num_of_data_sources = fd->intr_src_count; | |
1587 | fhandler->extra = kmalloc(sizeof(*extra_data), GFP_KERNEL); | |
1588 | extra_data = (struct synaptics_rmi4_f12_extra_data *)fhandler->extra; | |
1589 | size_of_2d_data = sizeof(struct synaptics_rmi4_f12_finger_data); | |
1590 | ||
1591 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1592 | fhandler->full_addr.query_base + 5, | |
1593 | query_5.data, | |
1594 | sizeof(query_5.data)); | |
1595 | if (retval < 0) | |
1596 | return retval; | |
1597 | ||
1598 | ctrl_8_offset = query_5.ctrl0_is_present + | |
1599 | query_5.ctrl1_is_present + | |
1600 | query_5.ctrl2_is_present + | |
1601 | query_5.ctrl3_is_present + | |
1602 | query_5.ctrl4_is_present + | |
1603 | query_5.ctrl5_is_present + | |
1604 | query_5.ctrl6_is_present + | |
1605 | query_5.ctrl7_is_present; | |
1606 | ||
1607 | ctrl_23_offset = ctrl_8_offset + | |
1608 | query_5.ctrl8_is_present + | |
1609 | query_5.ctrl9_is_present + | |
1610 | query_5.ctrl10_is_present + | |
1611 | query_5.ctrl11_is_present + | |
1612 | query_5.ctrl12_is_present + | |
1613 | query_5.ctrl13_is_present + | |
1614 | query_5.ctrl14_is_present + | |
1615 | query_5.ctrl15_is_present + | |
1616 | query_5.ctrl16_is_present + | |
1617 | query_5.ctrl17_is_present + | |
1618 | query_5.ctrl18_is_present + | |
1619 | query_5.ctrl19_is_present + | |
1620 | query_5.ctrl20_is_present + | |
1621 | query_5.ctrl21_is_present + | |
1622 | query_5.ctrl22_is_present; | |
1623 | ||
1624 | ctrl_28_offset = ctrl_23_offset + | |
1625 | query_5.ctrl23_is_present + | |
1626 | query_5.ctrl24_is_present + | |
1627 | query_5.ctrl25_is_present + | |
1628 | query_5.ctrl26_is_present + | |
1629 | query_5.ctrl27_is_present; | |
1630 | ||
1631 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1632 | fhandler->full_addr.ctrl_base + ctrl_23_offset, | |
1633 | ctrl_23.data, | |
1634 | sizeof(ctrl_23.data)); | |
1635 | if (retval < 0) | |
1636 | return retval; | |
1637 | ||
1638 | /* Maximum number of fingers supported */ | |
1639 | fhandler->num_of_data_points = min(ctrl_23.max_reported_objects, | |
1640 | (unsigned char)F12_FINGERS_TO_SUPPORT); | |
1641 | ||
1642 | num_of_fingers = fhandler->num_of_data_points; | |
1643 | rmi4_data->num_of_fingers = num_of_fingers; | |
1644 | ||
1645 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1646 | fhandler->full_addr.query_base + 7, | |
1647 | &size_of_query8, | |
1648 | sizeof(size_of_query8)); | |
1649 | if (retval < 0) | |
1650 | return retval; | |
1651 | ||
1652 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1653 | fhandler->full_addr.query_base + 8, | |
1654 | query_8.data, | |
1655 | size_of_query8); | |
1656 | if (retval < 0) | |
1657 | return retval; | |
1658 | ||
1659 | /* Determine the presence of the Data0 register */ | |
1660 | extra_data->data1_offset = query_8.data0_is_present; | |
1661 | ||
1662 | if ((size_of_query8 >= 3) && (query_8.data15_is_present)) { | |
1663 | extra_data->data15_offset = query_8.data0_is_present + | |
1664 | query_8.data1_is_present + | |
1665 | query_8.data2_is_present + | |
1666 | query_8.data3_is_present + | |
1667 | query_8.data4_is_present + | |
1668 | query_8.data5_is_present + | |
1669 | query_8.data6_is_present + | |
1670 | query_8.data7_is_present + | |
1671 | query_8.data8_is_present + | |
1672 | query_8.data9_is_present + | |
1673 | query_8.data10_is_present + | |
1674 | query_8.data11_is_present + | |
1675 | query_8.data12_is_present + | |
1676 | query_8.data13_is_present + | |
1677 | query_8.data14_is_present; | |
1678 | extra_data->data15_size = (num_of_fingers + 7) / 8; | |
1679 | } else { | |
1680 | extra_data->data15_size = 0; | |
1681 | } | |
1682 | ||
1683 | rmi4_data->report_enable = RPT_DEFAULT; | |
1684 | #ifdef REPORT_2D_Z | |
1685 | rmi4_data->report_enable |= RPT_Z; | |
1686 | #endif | |
1687 | #ifdef REPORT_2D_W | |
1688 | rmi4_data->report_enable |= (RPT_WX | RPT_WY); | |
1689 | #endif | |
1690 | ||
1691 | retval = synaptics_rmi4_f12_set_enables(rmi4_data, | |
1692 | fhandler->full_addr.ctrl_base + ctrl_28_offset); | |
1693 | if (retval < 0) | |
1694 | return retval; | |
1695 | ||
1696 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1697 | fhandler->full_addr.ctrl_base + ctrl_8_offset, | |
1698 | ctrl_8.data, | |
1699 | sizeof(ctrl_8.data)); | |
1700 | if (retval < 0) | |
1701 | return retval; | |
1702 | ||
1703 | /* Maximum x and y */ | |
1704 | rmi4_data->sensor_max_x = | |
1705 | ((unsigned short)ctrl_8.max_x_coord_lsb << 0) | | |
1706 | ((unsigned short)ctrl_8.max_x_coord_msb << 8); | |
1707 | rmi4_data->sensor_max_y = | |
1708 | ((unsigned short)ctrl_8.max_y_coord_lsb << 0) | | |
1709 | ((unsigned short)ctrl_8.max_y_coord_msb << 8); | |
1710 | #ifdef TPD_HAVE_BUTTON | |
1711 | rmi4_data->sensor_max_y = rmi4_data->sensor_max_y * TPD_DISPLAY_HEIGH_RATIO / TPD_TOUCH_HEIGH_RATIO; | |
1712 | #endif | |
1713 | dev_dbg(&rmi4_data->i2c_client->dev, | |
1714 | "%s: Function %02x max x = %d max y = %d\n", | |
1715 | __func__, fhandler->fn_number, | |
1716 | rmi4_data->sensor_max_x, | |
1717 | rmi4_data->sensor_max_y); | |
1718 | ||
1719 | rmi4_data->num_of_rx = ctrl_8.num_of_rx; | |
1720 | rmi4_data->num_of_tx = ctrl_8.num_of_tx; | |
1721 | rmi4_data->max_touch_width = max(rmi4_data->num_of_rx, | |
1722 | rmi4_data->num_of_tx); | |
1723 | ||
1724 | synaptics_rmi4_set_intr_mask(fhandler, fd, intr_count); | |
1725 | ||
1726 | /* Allocate memory for finger data storage space */ | |
1727 | fhandler->data_size = num_of_fingers * size_of_2d_data; | |
1728 | fhandler->data = kmalloc(fhandler->data_size, GFP_KERNEL); | |
1729 | ||
1730 | return retval; | |
1731 | } | |
1732 | ||
1733 | static int synaptics_rmi4_f1a_alloc_mem(struct synaptics_rmi4_data *rmi4_data, | |
1734 | struct synaptics_rmi4_fn *fhandler) | |
1735 | { | |
1736 | int retval; | |
1737 | struct synaptics_rmi4_f1a_handle *f1a; | |
1738 | ||
1739 | f1a = kzalloc(sizeof(*f1a), GFP_KERNEL); | |
1740 | if (!f1a) { | |
1741 | dev_err(&rmi4_data->i2c_client->dev, | |
1742 | "%s: Failed to alloc mem for function handle\n", | |
1743 | __func__); | |
1744 | return -ENOMEM; | |
1745 | } | |
1746 | ||
1747 | fhandler->data = (void *)f1a; | |
1748 | fhandler->extra = NULL; | |
1749 | ||
1750 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1751 | fhandler->full_addr.query_base, | |
1752 | f1a->button_query.data, | |
1753 | sizeof(f1a->button_query.data)); | |
1754 | if (retval < 0) { | |
1755 | dev_err(&rmi4_data->i2c_client->dev, | |
1756 | "%s: Failed to read query registers\n", | |
1757 | __func__); | |
1758 | return retval; | |
1759 | } | |
1760 | ||
1761 | f1a->max_count = f1a->button_query.max_button_count + 1; | |
1762 | ||
1763 | f1a->button_control.txrx_map = kzalloc(f1a->max_count * 2, GFP_KERNEL); | |
1764 | if (!f1a->button_control.txrx_map) { | |
1765 | dev_err(&rmi4_data->i2c_client->dev, | |
1766 | "%s: Failed to alloc mem for tx rx mapping\n", | |
1767 | __func__); | |
1768 | return -ENOMEM; | |
1769 | } | |
1770 | ||
1771 | f1a->button_bitmask_size = (f1a->max_count + 7) / 8; | |
1772 | ||
1773 | f1a->button_data_buffer = kcalloc(f1a->button_bitmask_size, | |
1774 | sizeof(*(f1a->button_data_buffer)), GFP_KERNEL); | |
1775 | if (!f1a->button_data_buffer) { | |
1776 | dev_err(&rmi4_data->i2c_client->dev, | |
1777 | "%s: Failed to alloc mem for data buffer\n", | |
1778 | __func__); | |
1779 | return -ENOMEM; | |
1780 | } | |
1781 | ||
1782 | f1a->button_map = kcalloc(f1a->max_count, | |
1783 | sizeof(*(f1a->button_map)), GFP_KERNEL); | |
1784 | if (!f1a->button_map) { | |
1785 | dev_err(&rmi4_data->i2c_client->dev, | |
1786 | "%s: Failed to alloc mem for button map\n", | |
1787 | __func__); | |
1788 | return -ENOMEM; | |
1789 | } | |
1790 | ||
1791 | return 0; | |
1792 | } | |
1793 | ||
1794 | static int synaptics_rmi4_f1a_button_map(struct synaptics_rmi4_data *rmi4_data, | |
1795 | struct synaptics_rmi4_fn *fhandler) | |
1796 | { | |
1797 | int retval; | |
1798 | unsigned char ii; | |
1799 | unsigned char mapping_offset = 0; | |
1800 | struct synaptics_rmi4_f1a_handle *f1a = fhandler->data; | |
1801 | ||
1802 | mapping_offset = f1a->button_query.has_general_control + | |
1803 | f1a->button_query.has_interrupt_enable + | |
1804 | f1a->button_query.has_multibutton_select; | |
1805 | ||
1806 | if (f1a->button_query.has_tx_rx_map) { | |
1807 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1808 | fhandler->full_addr.ctrl_base + mapping_offset, | |
1809 | f1a->button_control.txrx_map, | |
1810 | sizeof(f1a->button_control.txrx_map)); | |
1811 | if (retval < 0) { | |
1812 | dev_err(&rmi4_data->i2c_client->dev, | |
1813 | "%s: Failed to read tx rx mapping\n", | |
1814 | __func__); | |
1815 | return retval; | |
1816 | } | |
1817 | ||
1818 | rmi4_data->button_txrx_mapping = f1a->button_control.txrx_map; | |
1819 | } | |
1820 | ||
1821 | return 0; | |
1822 | } | |
1823 | ||
1824 | static void synaptics_rmi4_f1a_kfree(struct synaptics_rmi4_fn *fhandler) | |
1825 | { | |
1826 | struct synaptics_rmi4_f1a_handle *f1a = fhandler->data; | |
1827 | ||
1828 | if (f1a) { | |
1829 | kfree(f1a->button_control.txrx_map); | |
1830 | kfree(f1a->button_data_buffer); | |
1831 | kfree(f1a->button_map); | |
1832 | kfree(f1a); | |
1833 | fhandler->data = NULL; | |
1834 | } | |
1835 | ||
1836 | return; | |
1837 | } | |
1838 | ||
1839 | static int synaptics_rmi4_f1a_init(struct synaptics_rmi4_data *rmi4_data, | |
1840 | struct synaptics_rmi4_fn *fhandler, | |
1841 | struct synaptics_rmi4_fn_desc *fd, | |
1842 | unsigned int intr_count) | |
1843 | { | |
1844 | int retval; | |
1845 | ||
1846 | fhandler->fn_number = fd->fn_number; | |
1847 | fhandler->num_of_data_sources = fd->intr_src_count; | |
1848 | ||
1849 | synaptics_rmi4_set_intr_mask(fhandler, fd, intr_count); | |
1850 | ||
1851 | retval = synaptics_rmi4_f1a_alloc_mem(rmi4_data, fhandler); | |
1852 | if (retval < 0) | |
1853 | goto error_exit; | |
1854 | ||
1855 | retval = synaptics_rmi4_f1a_button_map(rmi4_data, fhandler); | |
1856 | if (retval < 0) | |
1857 | goto error_exit; | |
1858 | ||
1859 | rmi4_data->button_0d_enabled = 0; | |
1860 | ||
1861 | return 0; | |
1862 | ||
1863 | error_exit: | |
1864 | synaptics_rmi4_f1a_kfree(fhandler); | |
1865 | ||
1866 | return retval; | |
1867 | } | |
1868 | ||
1869 | static void synaptics_rmi4_empty_fn_list(struct synaptics_rmi4_data *rmi4_data) | |
1870 | { | |
1871 | struct synaptics_rmi4_fn *fhandler; | |
1872 | struct synaptics_rmi4_fn *fhandler_temp; | |
1873 | struct synaptics_rmi4_device_info *rmi; | |
1874 | ||
1875 | rmi = &(rmi4_data->rmi4_mod_info); | |
1876 | ||
1877 | if (!list_empty(&rmi->support_fn_list)) { | |
1878 | list_for_each_entry_safe(fhandler, | |
1879 | fhandler_temp, | |
1880 | &rmi->support_fn_list, | |
1881 | link) { | |
1882 | if (fhandler->fn_number == SYNAPTICS_RMI4_F1A) { | |
1883 | synaptics_rmi4_f1a_kfree(fhandler); | |
1884 | } else { | |
1885 | kfree(fhandler->extra); | |
1886 | kfree(fhandler->data); | |
1887 | } | |
1888 | list_del(&fhandler->link); | |
1889 | kfree(fhandler); | |
1890 | } | |
1891 | } | |
1892 | INIT_LIST_HEAD(&rmi->support_fn_list); | |
1893 | ||
1894 | return; | |
1895 | } | |
1896 | ||
1897 | static int synaptics_rmi4_check_status(struct synaptics_rmi4_data *rmi4_data, | |
1898 | bool *was_in_bl_mode) | |
1899 | { | |
1900 | int retval; | |
1901 | int timeout = CHECK_STATUS_TIMEOUT_MS; | |
1902 | unsigned char command = 0x01; | |
1903 | unsigned char intr_status; | |
1904 | struct synaptics_rmi4_f01_device_status status; | |
1905 | ||
1906 | /* Do a device reset first */ | |
1907 | retval = synaptics_rmi4_i2c_write(rmi4_data, | |
1908 | rmi4_data->f01_cmd_base_addr, | |
1909 | &command, | |
1910 | sizeof(command)); | |
1911 | if (retval < 0) | |
1912 | return retval; | |
1913 | ||
1914 | msleep(DELAY_S7300_RESET_READY); | |
1915 | ||
1916 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1917 | rmi4_data->f01_data_base_addr, | |
1918 | status.data, | |
1919 | sizeof(status.data)); | |
1920 | if (retval < 0) | |
1921 | return retval; | |
1922 | ||
1923 | while (status.status_code == STATUS_CRC_IN_PROGRESS) { | |
1924 | if (timeout > 0) | |
1925 | msleep(20); | |
1926 | else | |
1927 | return -1; | |
1928 | ||
1929 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1930 | rmi4_data->f01_data_base_addr, | |
1931 | status.data, | |
1932 | sizeof(status.data)); | |
1933 | if (retval < 0) | |
1934 | return retval; | |
1935 | ||
1936 | timeout -= 20; | |
1937 | } | |
1938 | ||
1939 | if (timeout != CHECK_STATUS_TIMEOUT_MS) | |
1940 | *was_in_bl_mode = true; | |
1941 | ||
1942 | if (status.flash_prog == 1) { | |
1943 | rmi4_data->flash_prog_mode = true; | |
1944 | pr_notice("%s: In flash prog mode, status = 0x%02x\n", | |
1945 | __func__, | |
1946 | status.status_code); | |
1947 | } else { | |
1948 | rmi4_data->flash_prog_mode = false; | |
1949 | } | |
1950 | ||
1951 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1952 | rmi4_data->f01_data_base_addr + 1, | |
1953 | &intr_status, | |
1954 | sizeof(intr_status)); | |
1955 | if (retval < 0) { | |
1956 | dev_err(&rmi4_data->i2c_client->dev, | |
1957 | "%s: Failed to read interrupt status\n", | |
1958 | __func__); | |
1959 | return retval; | |
1960 | } | |
1961 | ||
1962 | return 0; | |
1963 | } | |
1964 | ||
1965 | static void synaptics_rmi4_set_configured(struct synaptics_rmi4_data *rmi4_data) | |
1966 | { | |
1967 | int retval; | |
1968 | unsigned char device_ctrl; | |
1969 | ||
1970 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
1971 | rmi4_data->f01_ctrl_base_addr, | |
1972 | &device_ctrl, | |
1973 | sizeof(device_ctrl)); | |
1974 | if (retval < 0) { | |
1975 | dev_err(&(rmi4_data->input_dev->dev), | |
1976 | "%s: Failed to set configured\n", | |
1977 | __func__); | |
1978 | return; | |
1979 | } | |
1980 | ||
1981 | rmi4_data->no_sleep_setting = device_ctrl & NO_SLEEP_ON; | |
1982 | device_ctrl |= CONFIGURED; | |
1983 | ||
1984 | retval = synaptics_rmi4_i2c_write(rmi4_data, | |
1985 | rmi4_data->f01_ctrl_base_addr, | |
1986 | &device_ctrl, | |
1987 | sizeof(device_ctrl)); | |
1988 | if (retval < 0) { | |
1989 | dev_err(&(rmi4_data->input_dev->dev), | |
1990 | "%s: Failed to set configured\n", | |
1991 | __func__); | |
1992 | } | |
1993 | ||
1994 | return; | |
1995 | } | |
1996 | ||
1997 | static int synaptics_rmi4_alloc_fh(struct synaptics_rmi4_fn **fhandler, | |
1998 | struct synaptics_rmi4_fn_desc *rmi_fd, int page_number) | |
1999 | { | |
2000 | *fhandler = kmalloc(sizeof(**fhandler), GFP_KERNEL); | |
2001 | if (!(*fhandler)) | |
2002 | return -ENOMEM; | |
2003 | ||
2004 | (*fhandler)->full_addr.data_base = | |
2005 | (rmi_fd->data_base_addr | | |
2006 | (page_number << 8)); | |
2007 | (*fhandler)->full_addr.ctrl_base = | |
2008 | (rmi_fd->ctrl_base_addr | | |
2009 | (page_number << 8)); | |
2010 | (*fhandler)->full_addr.cmd_base = | |
2011 | (rmi_fd->cmd_base_addr | | |
2012 | (page_number << 8)); | |
2013 | (*fhandler)->full_addr.query_base = | |
2014 | (rmi_fd->query_base_addr | | |
2015 | (page_number << 8)); | |
2016 | ||
2017 | return 0; | |
2018 | } | |
2019 | ||
2020 | /** | |
2021 | * synaptics_rmi4_query_device() | |
2022 | * | |
2023 | * Called by synaptics_rmi4_probe(). | |
2024 | * | |
2025 | * This funtion scans the page description table, records the offsets | |
2026 | * to the register types of Function $01, sets up the function handlers | |
2027 | * for Function $11 and Function $12, determines the number of interrupt | |
2028 | * sources from the sensor, adds valid Functions with data inputs to the | |
2029 | * Function linked list, parses information from the query registers of | |
2030 | * Function $01, and enables the interrupt sources from the valid Functions | |
2031 | * with data inputs. | |
2032 | */ | |
2033 | static int synaptics_rmi4_query_device(struct synaptics_rmi4_data *rmi4_data) | |
2034 | { | |
2035 | int retval; | |
2036 | unsigned char ii; | |
2037 | unsigned char page_number; | |
2038 | unsigned char intr_count; | |
2039 | unsigned char f01_query[F01_STD_QUERY_LEN]; | |
2040 | unsigned short pdt_entry_addr; | |
2041 | unsigned short intr_addr; | |
2042 | bool was_in_bl_mode; | |
2043 | struct synaptics_rmi4_fn_desc rmi_fd; | |
2044 | struct synaptics_rmi4_fn *fhandler; | |
2045 | struct synaptics_rmi4_device_info *rmi; | |
2046 | ||
2047 | rmi = &(rmi4_data->rmi4_mod_info); | |
2048 | ||
2049 | rescan_pdt: | |
2050 | was_in_bl_mode = false; | |
2051 | intr_count = 0; | |
2052 | INIT_LIST_HEAD(&rmi->support_fn_list); | |
2053 | ||
2054 | /* Scan the page description tables of the pages to service */ | |
2055 | for (page_number = 0; page_number < PAGES_TO_SERVICE; page_number++) { | |
2056 | for (pdt_entry_addr = PDT_START; pdt_entry_addr > PDT_END; | |
2057 | pdt_entry_addr -= PDT_ENTRY_SIZE) { | |
2058 | pdt_entry_addr |= (page_number << 8); | |
2059 | ||
2060 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
2061 | pdt_entry_addr, | |
2062 | (unsigned char *)&rmi_fd, | |
2063 | sizeof(rmi_fd)); | |
2064 | if (retval < 0) | |
2065 | return retval; | |
2066 | ||
2067 | fhandler = NULL; | |
2068 | ||
2069 | if (rmi_fd.fn_number == 0) { | |
2070 | dev_dbg(&rmi4_data->i2c_client->dev, | |
2071 | "%s: Reached end of PDT\n", | |
2072 | __func__); | |
2073 | break; | |
2074 | } | |
2075 | ||
2076 | dev_dbg(&rmi4_data->i2c_client->dev, | |
2077 | "%s: F%02x found (page %d)\n", | |
2078 | __func__, rmi_fd.fn_number, | |
2079 | page_number); | |
2080 | ||
2081 | switch (rmi_fd.fn_number) { | |
2082 | case SYNAPTICS_RMI4_F01: | |
2083 | if (rmi_fd.intr_src_count == 0) | |
2084 | break; | |
2085 | ||
2086 | retval = synaptics_rmi4_alloc_fh(&fhandler, | |
2087 | &rmi_fd, page_number); | |
2088 | if (retval < 0) { | |
2089 | dev_err(&rmi4_data->i2c_client->dev, | |
2090 | "%s: Failed to alloc for F%d\n", | |
2091 | __func__, | |
2092 | rmi_fd.fn_number); | |
2093 | return retval; | |
2094 | } | |
2095 | ||
2096 | retval = synaptics_rmi4_f01_init(rmi4_data, | |
2097 | fhandler, &rmi_fd, intr_count); | |
2098 | if (retval < 0) | |
2099 | return retval; | |
2100 | ||
2101 | retval = synaptics_rmi4_check_status(rmi4_data, | |
2102 | &was_in_bl_mode); | |
2103 | if (retval < 0) { | |
2104 | dev_err(&rmi4_data->i2c_client->dev, | |
2105 | "%s: Failed to check status\n", | |
2106 | __func__); | |
2107 | return retval; | |
2108 | } | |
2109 | ||
2110 | if (was_in_bl_mode) { | |
2111 | kfree(fhandler); | |
2112 | fhandler = NULL; | |
2113 | goto rescan_pdt; | |
2114 | } | |
2115 | ||
2116 | if (rmi4_data->flash_prog_mode) | |
2117 | goto flash_prog_mode; | |
2118 | ||
2119 | break; | |
2120 | case SYNAPTICS_RMI4_F11: | |
2121 | if (rmi_fd.intr_src_count == 0) | |
2122 | break; | |
2123 | ||
2124 | retval = synaptics_rmi4_alloc_fh(&fhandler, | |
2125 | &rmi_fd, page_number); | |
2126 | if (retval < 0) { | |
2127 | dev_err(&rmi4_data->i2c_client->dev, | |
2128 | "%s: Failed to alloc for F%d\n", | |
2129 | __func__, | |
2130 | rmi_fd.fn_number); | |
2131 | return retval; | |
2132 | } | |
2133 | ||
2134 | retval = synaptics_rmi4_f11_init(rmi4_data, | |
2135 | fhandler, &rmi_fd, intr_count); | |
2136 | if (retval < 0) | |
2137 | return retval; | |
2138 | break; | |
2139 | case SYNAPTICS_RMI4_F12: | |
2140 | if (rmi_fd.intr_src_count == 0) | |
2141 | break; | |
2142 | ||
2143 | retval = synaptics_rmi4_alloc_fh(&fhandler, | |
2144 | &rmi_fd, page_number); | |
2145 | if (retval < 0) { | |
2146 | dev_err(&rmi4_data->i2c_client->dev, | |
2147 | "%s: Failed to alloc for F%d\n", | |
2148 | __func__, | |
2149 | rmi_fd.fn_number); | |
2150 | return retval; | |
2151 | } | |
2152 | ||
2153 | retval = synaptics_rmi4_f12_init(rmi4_data, | |
2154 | fhandler, &rmi_fd, intr_count); | |
2155 | if (retval < 0) | |
2156 | return retval; | |
2157 | break; | |
2158 | case SYNAPTICS_RMI4_F1A: | |
2159 | if (rmi_fd.intr_src_count == 0) | |
2160 | break; | |
2161 | ||
2162 | retval = synaptics_rmi4_alloc_fh(&fhandler, | |
2163 | &rmi_fd, page_number); | |
2164 | if (retval < 0) { | |
2165 | dev_err(&rmi4_data->i2c_client->dev, | |
2166 | "%s: Failed to alloc for F%d\n", | |
2167 | __func__, | |
2168 | rmi_fd.fn_number); | |
2169 | return retval; | |
2170 | } | |
2171 | ||
2172 | retval = synaptics_rmi4_f1a_init(rmi4_data, | |
2173 | fhandler, &rmi_fd, intr_count); | |
2174 | if (retval < 0) { | |
2175 | #ifdef IGNORE_FN_INIT_FAILURE | |
2176 | kfree(fhandler); | |
2177 | fhandler = NULL; | |
2178 | #else | |
2179 | return retval; | |
2180 | #endif | |
2181 | } | |
2182 | break; | |
2183 | } | |
2184 | ||
2185 | /* Accumulate the interrupt count */ | |
2186 | intr_count += (rmi_fd.intr_src_count & MASK_3BIT); | |
2187 | ||
2188 | if (fhandler && rmi_fd.intr_src_count) { | |
2189 | list_add_tail(&fhandler->link, | |
2190 | &rmi->support_fn_list); | |
2191 | } | |
2192 | } | |
2193 | } | |
2194 | ||
2195 | flash_prog_mode: | |
2196 | rmi4_data->num_of_intr_regs = (intr_count + 7) / 8; | |
2197 | dev_dbg(&rmi4_data->i2c_client->dev, | |
2198 | "%s: Number of interrupt registers = %d\n", | |
2199 | __func__, rmi4_data->num_of_intr_regs); | |
2200 | ||
2201 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
2202 | rmi4_data->f01_query_base_addr, | |
2203 | f01_query, | |
2204 | sizeof(f01_query)); | |
2205 | if (retval < 0) | |
2206 | return retval; | |
2207 | ||
2208 | /* RMI Version 4.0 currently supported */ | |
2209 | rmi->version_major = 4; | |
2210 | rmi->version_minor = 0; | |
2211 | ||
2212 | rmi->manufacturer_id = f01_query[0]; | |
2213 | rmi->product_props = f01_query[1]; | |
2214 | rmi->product_info[0] = f01_query[2] & MASK_7BIT; | |
2215 | rmi->product_info[1] = f01_query[3] & MASK_7BIT; | |
2216 | rmi->date_code[0] = f01_query[4] & MASK_5BIT; | |
2217 | rmi->date_code[1] = f01_query[5] & MASK_4BIT; | |
2218 | rmi->date_code[2] = f01_query[6] & MASK_5BIT; | |
2219 | rmi->tester_id = ((f01_query[7] & MASK_7BIT) << 8) | | |
2220 | (f01_query[8] & MASK_7BIT); | |
2221 | rmi->serial_number = ((f01_query[9] & MASK_7BIT) << 8) | | |
2222 | (f01_query[10] & MASK_7BIT); | |
2223 | memcpy(rmi->product_id_string, &f01_query[11], 10); | |
2224 | ||
2225 | if (rmi->manufacturer_id != 1) { | |
2226 | dev_err(&rmi4_data->i2c_client->dev, | |
2227 | "%s: Non-Synaptics device found, manufacturer ID = %d\n", | |
2228 | __func__, rmi->manufacturer_id); | |
2229 | } | |
2230 | ||
2231 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
2232 | rmi4_data->f01_query_base_addr + F01_BUID_ID_OFFSET, | |
2233 | rmi->build_id, | |
2234 | sizeof(rmi->build_id)); | |
2235 | if (retval < 0) | |
2236 | return retval; | |
2237 | ||
2238 | rmi4_data->firmware_id = (unsigned int)rmi->build_id[0] + | |
2239 | (unsigned int)rmi->build_id[1] * 0x100 + | |
2240 | (unsigned int)rmi->build_id[2] * 0x10000; | |
2241 | ||
2242 | memset(rmi4_data->intr_mask, 0x00, sizeof(rmi4_data->intr_mask)); | |
2243 | ||
2244 | /* | |
2245 | * Map out the interrupt bit masks for the interrupt sources | |
2246 | * from the registered function handlers. | |
2247 | */ | |
2248 | if (!list_empty(&rmi->support_fn_list)) { | |
2249 | list_for_each_entry(fhandler, &rmi->support_fn_list, link) { | |
2250 | if (fhandler->num_of_data_sources) { | |
2251 | rmi4_data->intr_mask[fhandler->intr_reg_num] |= | |
2252 | fhandler->intr_mask; | |
2253 | } | |
2254 | } | |
2255 | } | |
2256 | ||
2257 | /* Enable the interrupt sources */ | |
2258 | for (ii = 0; ii < rmi4_data->num_of_intr_regs; ii++) { | |
2259 | if (rmi4_data->intr_mask[ii] != 0x00) { | |
2260 | dev_dbg(&rmi4_data->i2c_client->dev, | |
2261 | "%s: Interrupt enable mask %d = 0x%02x\n", | |
2262 | __func__, ii, rmi4_data->intr_mask[ii]); | |
2263 | intr_addr = rmi4_data->f01_ctrl_base_addr + 1 + ii; | |
2264 | retval = synaptics_rmi4_i2c_write(rmi4_data, | |
2265 | intr_addr, | |
2266 | &(rmi4_data->intr_mask[ii]), | |
2267 | sizeof(rmi4_data->intr_mask[ii])); | |
2268 | if (retval < 0) | |
2269 | return retval; | |
2270 | } | |
2271 | } | |
2272 | ||
2273 | synaptics_rmi4_set_configured(rmi4_data); | |
2274 | ||
2275 | return 0; | |
2276 | } | |
2277 | ||
2278 | static void synaptics_rmi4_set_params(struct synaptics_rmi4_data *rmi4_data) | |
2279 | { | |
2280 | unsigned char ii; | |
2281 | struct synaptics_rmi4_f1a_handle *f1a; | |
2282 | struct synaptics_rmi4_fn *fhandler; | |
2283 | struct synaptics_rmi4_device_info *rmi; | |
2284 | ||
2285 | rmi = &(rmi4_data->rmi4_mod_info); | |
2286 | ||
2287 | input_set_abs_params(rmi4_data->input_dev, | |
2288 | ABS_MT_POSITION_X, 0, | |
2289 | rmi4_data->sensor_max_x, 0, 0); | |
2290 | input_set_abs_params(rmi4_data->input_dev, | |
2291 | ABS_MT_POSITION_Y, 0, | |
2292 | rmi4_data->sensor_max_y, 0, 0); | |
2293 | #ifdef REPORT_2D_W | |
2294 | input_set_abs_params(rmi4_data->input_dev, | |
2295 | ABS_MT_TOUCH_MAJOR, 0, | |
2296 | rmi4_data->max_touch_width, 0, 0); | |
2297 | input_set_abs_params(rmi4_data->input_dev, | |
2298 | ABS_MT_TOUCH_MINOR, 0, | |
2299 | rmi4_data->max_touch_width, 0, 0); | |
2300 | #endif | |
2301 | ||
2302 | #ifdef TYPE_B_PROTOCOL | |
2303 | input_mt_init_slots(rmi4_data->input_dev, | |
2304 | rmi4_data->num_of_fingers); | |
2305 | #endif | |
2306 | ||
2307 | f1a = NULL; | |
2308 | if (!list_empty(&rmi->support_fn_list)) { | |
2309 | list_for_each_entry(fhandler, &rmi->support_fn_list, link) { | |
2310 | if (fhandler->fn_number == SYNAPTICS_RMI4_F1A) | |
2311 | f1a = fhandler->data; | |
2312 | } | |
2313 | } | |
2314 | ||
2315 | if (f1a) { | |
2316 | for (ii = 0; ii < f1a->valid_button_count; ii++) { | |
2317 | set_bit(f1a->button_map[ii], | |
2318 | rmi4_data->input_dev->keybit); | |
2319 | input_set_capability(rmi4_data->input_dev, | |
2320 | EV_KEY, f1a->button_map[ii]); | |
2321 | } | |
2322 | } | |
2323 | ||
2324 | return; | |
2325 | } | |
2326 | ||
2327 | static int synaptics_rmi4_set_input_dev(struct synaptics_rmi4_data *rmi4_data) | |
2328 | { | |
2329 | int retval; | |
2330 | int temp; | |
2331 | ||
2332 | rmi4_data->input_dev = input_allocate_device(); | |
2333 | if (rmi4_data->input_dev == NULL) { | |
2334 | dev_err(&rmi4_data->i2c_client->dev, | |
2335 | "%s: Failed to allocate input device\n", | |
2336 | __func__); | |
2337 | retval = -ENOMEM; | |
2338 | goto err_input_device; | |
2339 | } | |
2340 | ||
2341 | retval = synaptics_rmi4_query_device(rmi4_data); | |
2342 | if (retval < 0) { | |
2343 | dev_err(&rmi4_data->i2c_client->dev, | |
2344 | "%s: Failed to query device\n", | |
2345 | __func__); | |
2346 | goto err_query_device; | |
2347 | } | |
2348 | ||
2349 | rmi4_data->input_dev->name = DRIVER_NAME; | |
2350 | rmi4_data->input_dev->phys = INPUT_PHYS_NAME; | |
2351 | rmi4_data->input_dev->id.product = SYNAPTICS_DSX_DRIVER_PRODUCT; | |
2352 | rmi4_data->input_dev->id.version = SYNAPTICS_DSX_DRIVER_VERSION; | |
2353 | rmi4_data->input_dev->id.bustype = BUS_I2C; | |
2354 | rmi4_data->input_dev->dev.parent = &rmi4_data->i2c_client->dev; | |
2355 | input_set_drvdata(rmi4_data->input_dev, rmi4_data); | |
2356 | ||
2357 | set_bit(EV_SYN, rmi4_data->input_dev->evbit); | |
2358 | set_bit(EV_KEY, rmi4_data->input_dev->evbit); | |
2359 | set_bit(EV_ABS, rmi4_data->input_dev->evbit); | |
2360 | set_bit(BTN_TOUCH, rmi4_data->input_dev->keybit); | |
2361 | set_bit(BTN_TOOL_FINGER, rmi4_data->input_dev->keybit); | |
2362 | #ifdef INPUT_PROP_DIRECT | |
2363 | set_bit(INPUT_PROP_DIRECT, rmi4_data->input_dev->propbit); | |
2364 | #endif | |
2365 | ||
2366 | synaptics_rmi4_set_params(rmi4_data); | |
2367 | ||
2368 | retval = input_register_device(rmi4_data->input_dev); | |
2369 | if (retval) { | |
2370 | dev_err(&rmi4_data->i2c_client->dev, | |
2371 | "%s: Failed to register input device\n", | |
2372 | __func__); | |
2373 | goto err_register_input; | |
2374 | } | |
2375 | ||
2376 | return 0; | |
2377 | ||
2378 | err_register_input: | |
2379 | err_query_device: | |
2380 | synaptics_rmi4_empty_fn_list(rmi4_data); | |
2381 | input_free_device(rmi4_data->input_dev); | |
2382 | ||
2383 | err_input_device: | |
2384 | return retval; | |
2385 | } | |
2386 | ||
2387 | static int synaptics_rmi4_free_fingers(struct synaptics_rmi4_data *rmi4_data) | |
2388 | { | |
2389 | unsigned char ii; | |
2390 | ||
2391 | #ifdef TYPE_B_PROTOCOL | |
2392 | for (ii = 0; ii < rmi4_data->num_of_fingers; ii++) { | |
2393 | input_mt_slot(rmi4_data->input_dev, ii); | |
2394 | input_mt_report_slot_state(rmi4_data->input_dev, | |
2395 | MT_TOOL_FINGER, 0); | |
2396 | } | |
2397 | #endif | |
2398 | input_report_key(rmi4_data->input_dev, | |
2399 | BTN_TOUCH, 0); | |
2400 | input_report_key(rmi4_data->input_dev, | |
2401 | BTN_TOOL_FINGER, 0); | |
2402 | #ifndef TYPE_B_PROTOCOL | |
2403 | input_mt_sync(rmi4_data->input_dev); | |
2404 | #endif | |
2405 | input_sync(rmi4_data->input_dev); | |
2406 | ||
2407 | rmi4_data->fingers_on_2d = false; | |
2408 | ||
2409 | return 0; | |
2410 | } | |
2411 | ||
2412 | static int synaptics_rmi4_reinit_device(struct synaptics_rmi4_data *rmi4_data) | |
2413 | { | |
2414 | int retval; | |
2415 | unsigned char ii; | |
2416 | unsigned short intr_addr; | |
2417 | struct synaptics_rmi4_fn *fhandler; | |
2418 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; | |
2419 | struct synaptics_rmi4_device_info *rmi; | |
2420 | ||
2421 | rmi = &(rmi4_data->rmi4_mod_info); | |
2422 | ||
2423 | mutex_lock(&(rmi4_data->rmi4_reset_mutex)); | |
2424 | ||
2425 | synaptics_rmi4_free_fingers(rmi4_data); | |
2426 | ||
2427 | if (!list_empty(&rmi->support_fn_list)) { | |
2428 | list_for_each_entry(fhandler, &rmi->support_fn_list, link) { | |
2429 | if (fhandler->fn_number == SYNAPTICS_RMI4_F12) { | |
2430 | synaptics_rmi4_f12_set_enables(rmi4_data, 0); | |
2431 | break; | |
2432 | } | |
2433 | } | |
2434 | } | |
2435 | ||
2436 | for (ii = 0; ii < rmi4_data->num_of_intr_regs; ii++) { | |
2437 | if (rmi4_data->intr_mask[ii] != 0x00) { | |
2438 | dev_dbg(&rmi4_data->i2c_client->dev, | |
2439 | "%s: Interrupt enable mask %d = 0x%02x\n", | |
2440 | __func__, ii, rmi4_data->intr_mask[ii]); | |
2441 | intr_addr = rmi4_data->f01_ctrl_base_addr + 1 + ii; | |
2442 | retval = synaptics_rmi4_i2c_write(rmi4_data, | |
2443 | intr_addr, | |
2444 | &(rmi4_data->intr_mask[ii]), | |
2445 | sizeof(rmi4_data->intr_mask[ii])); | |
2446 | if (retval < 0) | |
2447 | goto exit; | |
2448 | } | |
2449 | } | |
2450 | ||
2451 | mutex_lock(&exp_data.mutex); | |
2452 | if (!list_empty(&exp_data.list)) { | |
2453 | list_for_each_entry(exp_fhandler, &exp_data.list, link) | |
2454 | if (exp_fhandler->exp_fn->reinit != NULL) | |
2455 | exp_fhandler->exp_fn->reinit(rmi4_data); | |
2456 | } | |
2457 | mutex_unlock(&exp_data.mutex); | |
2458 | ||
2459 | synaptics_rmi4_set_configured(rmi4_data); | |
2460 | ||
2461 | retval = 0; | |
2462 | ||
2463 | exit: | |
2464 | mutex_unlock(&(rmi4_data->rmi4_reset_mutex)); | |
2465 | return retval; | |
2466 | } | |
2467 | ||
2468 | static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data) | |
2469 | { | |
2470 | int retval; | |
2471 | int temp; | |
2472 | unsigned char command = 0x01; | |
2473 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; | |
2474 | ||
2475 | mutex_lock(&(rmi4_data->rmi4_reset_mutex)); | |
2476 | ||
2477 | rmi4_data->touch_stopped = true; | |
2478 | ||
2479 | retval = synaptics_rmi4_i2c_write(rmi4_data, | |
2480 | rmi4_data->f01_cmd_base_addr, | |
2481 | &command, | |
2482 | sizeof(command)); | |
2483 | if (retval < 0) { | |
2484 | dev_err(&rmi4_data->i2c_client->dev, | |
2485 | "%s: Failed to issue reset command, error = %d\n", | |
2486 | __func__, retval); | |
2487 | mutex_unlock(&(rmi4_data->rmi4_reset_mutex)); | |
2488 | return retval; | |
2489 | } | |
2490 | ||
2491 | msleep(DELAY_S7300_RESET_READY); | |
2492 | ||
2493 | synaptics_rmi4_free_fingers(rmi4_data); | |
2494 | ||
2495 | synaptics_rmi4_empty_fn_list(rmi4_data); | |
2496 | ||
2497 | retval = synaptics_rmi4_query_device(rmi4_data); | |
2498 | if (retval < 0) { | |
2499 | dev_err(&rmi4_data->i2c_client->dev, | |
2500 | "%s: Failed to query device\n", | |
2501 | __func__); | |
2502 | mutex_unlock(&(rmi4_data->rmi4_reset_mutex)); | |
2503 | return retval; | |
2504 | } | |
2505 | ||
2506 | synaptics_rmi4_set_params(rmi4_data); | |
2507 | ||
2508 | mutex_lock(&exp_data.mutex); | |
2509 | if (!list_empty(&exp_data.list)) { | |
2510 | list_for_each_entry(exp_fhandler, &exp_data.list, link) | |
2511 | if (exp_fhandler->exp_fn->reset != NULL) | |
2512 | exp_fhandler->exp_fn->reset(rmi4_data); | |
2513 | } | |
2514 | mutex_unlock(&exp_data.mutex); | |
2515 | ||
2516 | rmi4_data->touch_stopped = false; | |
2517 | ||
2518 | mutex_unlock(&(rmi4_data->rmi4_reset_mutex)); | |
2519 | ||
2520 | return 0; | |
2521 | } | |
2522 | ||
2523 | /** | |
2524 | * synaptics_rmi4_exp_fn_work() | |
2525 | * | |
2526 | * Called by the kernel at the scheduled time. | |
2527 | * | |
2528 | * This function is a work thread that checks for the insertion and | |
2529 | * removal of other expansion Function modules such as rmi_dev and calls | |
2530 | * their initialization and removal callback functions accordingly. | |
2531 | */ | |
2532 | static void synaptics_rmi4_exp_fn_work(struct work_struct *work) | |
2533 | { | |
2534 | int retval; | |
2535 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; | |
2536 | struct synaptics_rmi4_exp_fhandler *exp_fhandler_temp; | |
2537 | struct synaptics_rmi4_data *rmi4_data = exp_data.rmi4_data; | |
2538 | ||
2539 | mutex_lock(&exp_data.mutex); | |
2540 | if (!list_empty(&exp_data.list)) { | |
2541 | list_for_each_entry_safe(exp_fhandler, | |
2542 | exp_fhandler_temp, | |
2543 | &exp_data.list, | |
2544 | link) { | |
2545 | if ((exp_fhandler->exp_fn->init != NULL) && | |
2546 | exp_fhandler->insert) { | |
2547 | retval = exp_fhandler->exp_fn->init(rmi4_data); | |
2548 | if (retval < 0) { | |
2549 | list_del(&exp_fhandler->link); | |
2550 | kfree(exp_fhandler); | |
2551 | } else { | |
2552 | exp_fhandler->insert = false; | |
2553 | } | |
2554 | } else if ((exp_fhandler->exp_fn->remove != NULL) && | |
2555 | exp_fhandler->remove) { | |
2556 | exp_fhandler->exp_fn->remove(rmi4_data); | |
2557 | list_del(&exp_fhandler->link); | |
2558 | kfree(exp_fhandler); | |
2559 | } | |
2560 | } | |
2561 | } | |
2562 | mutex_unlock(&exp_data.mutex); | |
2563 | ||
2564 | return; | |
2565 | } | |
2566 | ||
2567 | /** | |
2568 | * synaptics_rmi4_new_function() | |
2569 | * | |
2570 | * Called by other expansion Function modules in their module init and | |
2571 | * module exit functions. | |
2572 | * | |
2573 | * This function is used by other expansion Function modules such as | |
2574 | * rmi_dev to register themselves with the driver by providing their | |
2575 | * initialization and removal callback function pointers so that they | |
2576 | * can be inserted or removed dynamically at module init and exit times, | |
2577 | * respectively. | |
2578 | */ | |
2579 | void synaptics_rmi4_new_function(struct synaptics_rmi4_exp_fn *exp_fn, | |
2580 | bool insert) | |
2581 | { | |
2582 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; | |
2583 | ||
2584 | if (!exp_data.initialized) { | |
2585 | mutex_init(&exp_data.mutex); | |
2586 | INIT_LIST_HEAD(&exp_data.list); | |
2587 | exp_data.initialized = true; | |
2588 | } | |
2589 | ||
2590 | mutex_lock(&exp_data.mutex); | |
2591 | if (insert) { | |
2592 | exp_fhandler = kzalloc(sizeof(*exp_fhandler), GFP_KERNEL); | |
2593 | if (!exp_fhandler) { | |
2594 | pr_err("%s: Failed to alloc mem for expansion function\n", | |
2595 | __func__); | |
2596 | goto exit; | |
2597 | } | |
2598 | exp_fhandler->exp_fn = exp_fn; | |
2599 | exp_fhandler->insert = true; | |
2600 | exp_fhandler->remove = false; | |
2601 | list_add_tail(&exp_fhandler->link, &exp_data.list); | |
2602 | } else if (!list_empty(&exp_data.list)) { | |
2603 | list_for_each_entry(exp_fhandler, &exp_data.list, link) { | |
2604 | if (exp_fhandler->exp_fn->fn_type == exp_fn->fn_type) { | |
2605 | exp_fhandler->insert = false; | |
2606 | exp_fhandler->remove = true; | |
2607 | goto exit; | |
2608 | } | |
2609 | } | |
2610 | } | |
2611 | ||
2612 | exit: | |
2613 | mutex_unlock(&exp_data.mutex); | |
2614 | ||
2615 | if (exp_data.queue_work) { | |
2616 | queue_delayed_work(exp_data.workqueue, | |
2617 | &exp_data.work, | |
2618 | msecs_to_jiffies(EXP_FN_WORK_DELAY_MS)); | |
2619 | } | |
2620 | ||
2621 | return; | |
2622 | } | |
2623 | EXPORT_SYMBOL(synaptics_rmi4_new_function); | |
2624 | ||
2625 | /** | |
2626 | * synaptics_rmi4_probe() | |
2627 | * | |
2628 | * Called by the kernel when an association with an I2C device of the | |
2629 | * same name is made (after doing i2c_add_driver). | |
2630 | * | |
2631 | * This funtion allocates and initializes the resources for the driver | |
2632 | * as an input driver, turns on the power to the sensor, queries the | |
2633 | * sensor for its supported Functions and characteristics, registers | |
2634 | * the driver to the input subsystem, sets up the interrupt, handles | |
2635 | * the registration of the early_suspend and late_resume functions, | |
2636 | * and creates a work queue for detection of other expansion Function | |
2637 | * modules. | |
2638 | */ | |
2639 | static int __devinit synaptics_rmi4_probe(struct i2c_client *client, | |
2640 | const struct i2c_device_id *dev_id) | |
2641 | { | |
2642 | int retval; | |
2643 | unsigned char attr_count; | |
2644 | struct synaptics_rmi4_data *rmi4_data; | |
2645 | ||
2646 | if (!i2c_check_functionality(client->adapter, | |
2647 | I2C_FUNC_SMBUS_BYTE_DATA)) { | |
2648 | dev_err(&client->dev, | |
2649 | "%s: SMBus byte data not supported\n", | |
2650 | __func__); | |
2651 | return -EIO; | |
2652 | } | |
2653 | ||
2654 | // gpio setting | |
2655 | mt_set_gpio_mode(GPIO_CTP_EINT_PIN, GPIO_CTP_EINT_PIN_M_EINT); | |
2656 | mt_set_gpio_dir(GPIO_CTP_EINT_PIN, GPIO_DIR_IN); | |
2657 | mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN, GPIO_PULL_ENABLE); | |
2658 | mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN, GPIO_PULL_UP); | |
2659 | ||
2660 | mt_set_gpio_mode(GPIO_CTP_RST_PIN, GPIO_CTP_RST_PIN_M_GPIO); | |
2661 | mt_set_gpio_dir(GPIO_CTP_RST_PIN, GPIO_DIR_OUT); | |
2662 | mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ONE); | |
2663 | ||
2664 | // power up sequence | |
2665 | hwPowerOn(TPD_POWER_SOURCE, VOL_2800, "TP"); | |
2666 | msleep(DELAY_S7300_BOOT_READY); | |
2667 | mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ZERO); | |
2668 | msleep(DELAY_S7300_RESET); | |
2669 | mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ONE); | |
2670 | msleep(DELAY_S7300_RESET_READY); | |
2671 | ||
2672 | ||
2673 | rmi4_data = kzalloc(sizeof(*rmi4_data), GFP_KERNEL); | |
2674 | if (!rmi4_data) { | |
2675 | dev_err(&client->dev, | |
2676 | "%s: Failed to alloc mem for rmi4_data\n", | |
2677 | __func__); | |
2678 | return -ENOMEM; | |
2679 | } | |
2680 | ||
2681 | rmi4_data->i2c_client = client; | |
2682 | rmi4_data->current_page = MASK_8BIT; | |
2683 | rmi4_data->touch_stopped = false; | |
2684 | rmi4_data->sensor_sleep = false; | |
2685 | rmi4_data->irq_enabled = false; | |
2686 | rmi4_data->fingers_on_2d = false; | |
2687 | ||
2688 | rmi4_data->i2c_read = synaptics_rmi4_i2c_read; | |
2689 | rmi4_data->i2c_write = synaptics_rmi4_i2c_write; | |
2690 | rmi4_data->irq_enable = synaptics_rmi4_irq_enable; | |
2691 | rmi4_data->reset_device = synaptics_rmi4_reset_device; | |
2692 | ||
2693 | mutex_init(&(rmi4_data->rmi4_io_ctrl_mutex)); | |
2694 | mutex_init(&(rmi4_data->rmi4_reset_mutex)); | |
2695 | ||
2696 | i2c_set_clientdata(client, rmi4_data); | |
2697 | retval = synaptics_rmi4_set_input_dev(rmi4_data); | |
2698 | if (retval < 0) { | |
2699 | dev_err(&client->dev, | |
2700 | "%s: Failed to set up input device\n", | |
2701 | __func__); | |
2702 | goto err_set_input_dev; | |
2703 | } | |
2704 | ||
2705 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
2706 | rmi4_data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; | |
2707 | rmi4_data->early_suspend.suspend = synaptics_rmi4_early_suspend; | |
2708 | rmi4_data->early_suspend.resume = synaptics_rmi4_late_resume; | |
2709 | register_early_suspend(&rmi4_data->early_suspend); | |
2710 | #endif | |
2711 | ||
2712 | thread = kthread_run(touch_event_handler, rmi4_data, "synaptics-tpd"); | |
2713 | if ( IS_ERR(thread) ) { | |
2714 | retval = PTR_ERR(thread); | |
2715 | pr_err(" %s: failed to create kernel thread: %d\n",__func__, retval); | |
2716 | } | |
2717 | ||
2718 | retval = synaptics_rmi4_irq_enable(rmi4_data, true); | |
2719 | if (retval < 0) { | |
2720 | dev_err(&client->dev, | |
2721 | "%s: Failed to enable attention interrupt\n", | |
2722 | __func__); | |
2723 | goto err_enable_irq; | |
2724 | } | |
2725 | ||
2726 | if (!exp_data.initialized) { | |
2727 | mutex_init(&exp_data.mutex); | |
2728 | INIT_LIST_HEAD(&exp_data.list); | |
2729 | exp_data.initialized = true; | |
2730 | } | |
2731 | ||
2732 | ||
2733 | exp_data.workqueue = create_singlethread_workqueue("dsx_exp_workqueue"); | |
2734 | INIT_DELAYED_WORK(&exp_data.work, synaptics_rmi4_exp_fn_work); | |
2735 | exp_data.rmi4_data = rmi4_data; | |
2736 | exp_data.queue_work = true; | |
2737 | queue_delayed_work(exp_data.workqueue, | |
2738 | &exp_data.work, | |
2739 | msecs_to_jiffies(EXP_FN_WORK_DELAY_MS)); | |
2740 | ||
2741 | for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) { | |
2742 | retval = sysfs_create_file(&rmi4_data->input_dev->dev.kobj, | |
2743 | &attrs[attr_count].attr); | |
2744 | if (retval < 0) { | |
2745 | dev_err(&client->dev, | |
2746 | "%s: Failed to create sysfs attributes\n", | |
2747 | __func__); | |
2748 | goto err_sysfs; | |
2749 | } | |
2750 | } | |
2751 | ||
2752 | tpd_load_status = 1; | |
2753 | return retval; | |
2754 | ||
2755 | err_sysfs: | |
2756 | for (attr_count--; attr_count >= 0; attr_count--) { | |
2757 | sysfs_remove_file(&rmi4_data->input_dev->dev.kobj, | |
2758 | &attrs[attr_count].attr); | |
2759 | } | |
2760 | ||
2761 | cancel_delayed_work_sync(&exp_data.work); | |
2762 | flush_workqueue(exp_data.workqueue); | |
2763 | destroy_workqueue(exp_data.workqueue); | |
2764 | ||
2765 | synaptics_rmi4_irq_enable(rmi4_data, false); | |
2766 | ||
2767 | err_enable_irq: | |
2768 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
2769 | unregister_early_suspend(&rmi4_data->early_suspend); | |
2770 | #endif | |
2771 | ||
2772 | synaptics_rmi4_empty_fn_list(rmi4_data); | |
2773 | input_unregister_device(rmi4_data->input_dev); | |
2774 | rmi4_data->input_dev = NULL; | |
2775 | ||
2776 | err_set_input_dev: | |
2777 | kfree(rmi4_data); | |
2778 | ||
2779 | return retval; | |
2780 | } | |
2781 | ||
2782 | /** | |
2783 | * synaptics_rmi4_remove() | |
2784 | * | |
2785 | * Called by the kernel when the association with an I2C device of the | |
2786 | * same name is broken (when the driver is unloaded). | |
2787 | * | |
2788 | * This funtion terminates the work queue, stops sensor data acquisition, | |
2789 | * frees the interrupt, unregisters the driver from the input subsystem, | |
2790 | * turns off the power to the sensor, and frees other allocated resources. | |
2791 | */ | |
2792 | static int __devexit synaptics_rmi4_remove(struct i2c_client *client) | |
2793 | { | |
2794 | unsigned char attr_count; | |
2795 | struct synaptics_rmi4_data *rmi4_data = i2c_get_clientdata(client); | |
2796 | ||
2797 | for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) { | |
2798 | sysfs_remove_file(&rmi4_data->input_dev->dev.kobj, | |
2799 | &attrs[attr_count].attr); | |
2800 | } | |
2801 | ||
2802 | cancel_delayed_work_sync(&exp_data.work); | |
2803 | flush_workqueue(exp_data.workqueue); | |
2804 | destroy_workqueue(exp_data.workqueue); | |
2805 | ||
2806 | synaptics_rmi4_irq_enable(rmi4_data, false); | |
2807 | ||
2808 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
2809 | unregister_early_suspend(&rmi4_data->early_suspend); | |
2810 | #endif | |
2811 | ||
2812 | synaptics_rmi4_empty_fn_list(rmi4_data); | |
2813 | input_unregister_device(rmi4_data->input_dev); | |
2814 | rmi4_data->input_dev = NULL; | |
2815 | ||
2816 | kfree(rmi4_data); | |
2817 | ||
2818 | return 0; | |
2819 | } | |
2820 | ||
2821 | #ifdef CONFIG_PM | |
2822 | /** | |
2823 | * synaptics_rmi4_sensor_sleep() | |
2824 | * | |
2825 | * Called by synaptics_rmi4_early_suspend() and synaptics_rmi4_suspend(). | |
2826 | * | |
2827 | * This function stops finger data acquisition and puts the sensor to sleep. | |
2828 | */ | |
2829 | static void synaptics_rmi4_sensor_sleep(struct synaptics_rmi4_data *rmi4_data) | |
2830 | { | |
2831 | int retval; | |
2832 | unsigned char device_ctrl; | |
2833 | ||
2834 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
2835 | rmi4_data->f01_ctrl_base_addr, | |
2836 | &device_ctrl, | |
2837 | sizeof(device_ctrl)); | |
2838 | if (retval < 0) { | |
2839 | dev_err(&(rmi4_data->input_dev->dev), | |
2840 | "%s: Failed to enter sleep mode\n", | |
2841 | __func__); | |
2842 | rmi4_data->sensor_sleep = false; | |
2843 | return; | |
2844 | } | |
2845 | ||
2846 | device_ctrl = (device_ctrl & ~MASK_3BIT); | |
2847 | device_ctrl = (device_ctrl | NO_SLEEP_OFF | SENSOR_SLEEP); | |
2848 | ||
2849 | retval = synaptics_rmi4_i2c_write(rmi4_data, | |
2850 | rmi4_data->f01_ctrl_base_addr, | |
2851 | &device_ctrl, | |
2852 | sizeof(device_ctrl)); | |
2853 | if (retval < 0) { | |
2854 | dev_err(&(rmi4_data->input_dev->dev), | |
2855 | "%s: Failed to enter sleep mode\n", | |
2856 | __func__); | |
2857 | rmi4_data->sensor_sleep = false; | |
2858 | return; | |
2859 | } else { | |
2860 | rmi4_data->sensor_sleep = true; | |
2861 | } | |
2862 | ||
2863 | return; | |
2864 | } | |
2865 | ||
2866 | /** | |
2867 | * synaptics_rmi4_sensor_wake() | |
2868 | * | |
2869 | * Called by synaptics_rmi4_resume() and synaptics_rmi4_late_resume(). | |
2870 | * | |
2871 | * This function wakes the sensor from sleep. | |
2872 | */ | |
2873 | static void synaptics_rmi4_sensor_wake(struct synaptics_rmi4_data *rmi4_data) | |
2874 | { | |
2875 | int retval; | |
2876 | unsigned char device_ctrl; | |
2877 | unsigned char no_sleep_setting = rmi4_data->no_sleep_setting; | |
2878 | ||
2879 | retval = synaptics_rmi4_i2c_read(rmi4_data, | |
2880 | rmi4_data->f01_ctrl_base_addr, | |
2881 | &device_ctrl, | |
2882 | sizeof(device_ctrl)); | |
2883 | if (retval < 0) { | |
2884 | dev_err(&(rmi4_data->input_dev->dev), | |
2885 | "%s: Failed to wake from sleep mode\n", | |
2886 | __func__); | |
2887 | rmi4_data->sensor_sleep = true; | |
2888 | return; | |
2889 | } | |
2890 | ||
2891 | device_ctrl = (device_ctrl & ~MASK_3BIT); | |
2892 | device_ctrl = (device_ctrl | no_sleep_setting | NORMAL_OPERATION); | |
2893 | ||
2894 | retval = synaptics_rmi4_i2c_write(rmi4_data, | |
2895 | rmi4_data->f01_ctrl_base_addr, | |
2896 | &device_ctrl, | |
2897 | sizeof(device_ctrl)); | |
2898 | if (retval < 0) { | |
2899 | dev_err(&(rmi4_data->input_dev->dev), | |
2900 | "%s: Failed to wake from sleep mode\n", | |
2901 | __func__); | |
2902 | rmi4_data->sensor_sleep = true; | |
2903 | return; | |
2904 | } else { | |
2905 | rmi4_data->sensor_sleep = false; | |
2906 | } | |
2907 | ||
2908 | return; | |
2909 | } | |
2910 | ||
2911 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
2912 | /** | |
2913 | * synaptics_rmi4_early_suspend() | |
2914 | * | |
2915 | * Called by the kernel during the early suspend phase when the system | |
2916 | * enters suspend. | |
2917 | * | |
2918 | * This function calls synaptics_rmi4_sensor_sleep() to stop finger | |
2919 | * data acquisition and put the sensor to sleep. | |
2920 | */ | |
2921 | static void synaptics_rmi4_early_suspend(struct early_suspend *h) | |
2922 | { | |
2923 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; | |
2924 | struct synaptics_rmi4_data *rmi4_data = | |
2925 | container_of(h, struct synaptics_rmi4_data, | |
2926 | early_suspend); | |
2927 | ||
2928 | if (rmi4_data->stay_awake) { | |
2929 | rmi4_data->staying_awake = true; | |
2930 | return; | |
2931 | } else { | |
2932 | rmi4_data->staying_awake = false; | |
2933 | } | |
2934 | ||
2935 | rmi4_data->touch_stopped = true; | |
2936 | synaptics_rmi4_irq_enable(rmi4_data, false); | |
2937 | synaptics_rmi4_sensor_sleep(rmi4_data); | |
2938 | synaptics_rmi4_free_fingers(rmi4_data); | |
2939 | ||
2940 | mutex_lock(&exp_data.mutex); | |
2941 | if (!list_empty(&exp_data.list)) { | |
2942 | list_for_each_entry(exp_fhandler, &exp_data.list, link) | |
2943 | if (exp_fhandler->exp_fn->early_suspend != NULL) | |
2944 | exp_fhandler->exp_fn->early_suspend(rmi4_data); | |
2945 | } | |
2946 | mutex_unlock(&exp_data.mutex); | |
2947 | ||
2948 | if (rmi4_data->full_pm_cycle) | |
2949 | synaptics_rmi4_suspend(&(rmi4_data->input_dev->dev)); | |
2950 | ||
2951 | return; | |
2952 | } | |
2953 | ||
2954 | /** | |
2955 | * synaptics_rmi4_late_resume() | |
2956 | * | |
2957 | * Called by the kernel during the late resume phase when the system | |
2958 | * wakes up from suspend. | |
2959 | * | |
2960 | * This function goes through the sensor wake process if the system wakes | |
2961 | * up from early suspend (without going into suspend). | |
2962 | */ | |
2963 | static void synaptics_rmi4_late_resume(struct early_suspend *h) | |
2964 | { | |
2965 | int retval; | |
2966 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; | |
2967 | struct synaptics_rmi4_data *rmi4_data = | |
2968 | container_of(h, struct synaptics_rmi4_data, | |
2969 | early_suspend); | |
2970 | ||
2971 | if (rmi4_data->staying_awake) | |
2972 | return; | |
2973 | ||
2974 | if (rmi4_data->full_pm_cycle) | |
2975 | synaptics_rmi4_resume(&(rmi4_data->input_dev->dev)); | |
2976 | ||
2977 | if (rmi4_data->sensor_sleep == true) { | |
2978 | synaptics_rmi4_sensor_wake(rmi4_data); | |
2979 | synaptics_rmi4_irq_enable(rmi4_data, true); | |
2980 | retval = synaptics_rmi4_reinit_device(rmi4_data); | |
2981 | if (retval < 0) { | |
2982 | dev_err(&rmi4_data->i2c_client->dev, | |
2983 | "%s: Failed to reinit device\n", | |
2984 | __func__); | |
2985 | } | |
2986 | } | |
2987 | ||
2988 | mutex_lock(&exp_data.mutex); | |
2989 | if (!list_empty(&exp_data.list)) { | |
2990 | list_for_each_entry(exp_fhandler, &exp_data.list, link) | |
2991 | if (exp_fhandler->exp_fn->late_resume != NULL) | |
2992 | exp_fhandler->exp_fn->late_resume(rmi4_data); | |
2993 | } | |
2994 | mutex_unlock(&exp_data.mutex); | |
2995 | ||
2996 | rmi4_data->touch_stopped = false; | |
2997 | ||
2998 | return; | |
2999 | } | |
3000 | #endif | |
3001 | ||
3002 | /** | |
3003 | * synaptics_rmi4_suspend() | |
3004 | * | |
3005 | * Called by the kernel during the suspend phase when the system | |
3006 | * enters suspend. | |
3007 | * | |
3008 | * This function stops finger data acquisition and puts the sensor to | |
3009 | * sleep (if not already done so during the early suspend phase), | |
3010 | * disables the interrupt, and turns off the power to the sensor. | |
3011 | */ | |
3012 | static int synaptics_rmi4_suspend(struct device *dev) | |
3013 | { | |
3014 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; | |
3015 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); | |
3016 | ||
3017 | if (rmi4_data->staying_awake) | |
3018 | return 0; | |
3019 | ||
3020 | if (!rmi4_data->sensor_sleep) { | |
3021 | rmi4_data->touch_stopped = true; | |
3022 | synaptics_rmi4_irq_enable(rmi4_data, false); | |
3023 | synaptics_rmi4_sensor_sleep(rmi4_data); | |
3024 | synaptics_rmi4_free_fingers(rmi4_data); | |
3025 | } | |
3026 | ||
3027 | mutex_lock(&exp_data.mutex); | |
3028 | if (!list_empty(&exp_data.list)) { | |
3029 | list_for_each_entry(exp_fhandler, &exp_data.list, link) | |
3030 | if (exp_fhandler->exp_fn->suspend != NULL) | |
3031 | exp_fhandler->exp_fn->suspend(rmi4_data); | |
3032 | } | |
3033 | mutex_unlock(&exp_data.mutex); | |
3034 | tpd_halt = 1; | |
3035 | return 0; | |
3036 | } | |
3037 | ||
3038 | /** | |
3039 | * synaptics_rmi4_resume() | |
3040 | * | |
3041 | * Called by the kernel during the resume phase when the system | |
3042 | * wakes up from suspend. | |
3043 | * | |
3044 | * This function turns on the power to the sensor, wakes the sensor | |
3045 | * from sleep, enables the interrupt, and starts finger data | |
3046 | * acquisition. | |
3047 | */ | |
3048 | static int synaptics_rmi4_resume(struct device *dev) | |
3049 | { | |
3050 | int retval; | |
3051 | struct synaptics_rmi4_exp_fhandler *exp_fhandler; | |
3052 | struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev); | |
3053 | ||
3054 | if (rmi4_data->staying_awake) | |
3055 | return 0; | |
3056 | ||
3057 | synaptics_rmi4_sensor_wake(rmi4_data); | |
3058 | synaptics_rmi4_irq_enable(rmi4_data, true); | |
3059 | retval = synaptics_rmi4_reinit_device(rmi4_data); | |
3060 | if (retval < 0) { | |
3061 | dev_err(&rmi4_data->i2c_client->dev, | |
3062 | "%s: Failed to reinit device\n", | |
3063 | __func__); | |
3064 | return retval; | |
3065 | } | |
3066 | ||
3067 | mutex_lock(&exp_data.mutex); | |
3068 | if (!list_empty(&exp_data.list)) { | |
3069 | list_for_each_entry(exp_fhandler, &exp_data.list, link) | |
3070 | if (exp_fhandler->exp_fn->resume != NULL) | |
3071 | exp_fhandler->exp_fn->resume(rmi4_data); | |
3072 | } | |
3073 | mutex_unlock(&exp_data.mutex); | |
3074 | ||
3075 | rmi4_data->touch_stopped = false; | |
3076 | tpd_halt = 0; | |
3077 | ||
3078 | return 0; | |
3079 | } | |
3080 | ||
3081 | static const struct dev_pm_ops synaptics_rmi4_dev_pm_ops = { | |
3082 | .suspend = synaptics_rmi4_suspend, | |
3083 | .resume = synaptics_rmi4_resume, | |
3084 | }; | |
3085 | #endif | |
3086 | ||
3087 | static const struct i2c_device_id synaptics_rmi4_id_table[] = { | |
3088 | {"synaptics-tpd", 0}, | |
3089 | {}, | |
3090 | }; | |
3091 | unsigned short force[] = {0,TPD_I2C_ADDR,I2C_CLIENT_END,I2C_CLIENT_END}; | |
3092 | static const unsigned short * const forces[] = { force, NULL }; | |
3093 | //static int tpd_detect(struct i2c_client *client, struct i2c_board_info *info); | |
3094 | ||
3095 | MODULE_DEVICE_TABLE(i2c, synaptics_rmi4_id_table); | |
3096 | ||
3097 | static struct i2c_driver tpd_i2c_driver = { | |
3098 | .probe = synaptics_rmi4_probe, | |
3099 | .remove = __devexit_p(synaptics_rmi4_remove), | |
3100 | //.detect = tpd_detect, | |
3101 | .driver.name = "synaptics-tpd", | |
3102 | .id_table = synaptics_rmi4_id_table, | |
3103 | .address_list = (const unsigned short*) forces, | |
3104 | }; | |
3105 | ||
3106 | static int tpd_local_init(void) | |
3107 | { | |
3108 | TPD_DMESG("synaptics I2C Touchscreen Driver (Built %s @ %s)\n", __DATE__, __TIME__); | |
3109 | ||
3110 | if(i2c_add_driver(&tpd_i2c_driver)!=0) | |
3111 | { | |
3112 | TPD_DMESG("tangjie Error unable to add i2c driver.\n"); | |
3113 | return -1; | |
3114 | } | |
3115 | #ifdef TPD_HAVE_BUTTON | |
3116 | tpd_button_setting(TPD_KEY_COUNT, tpd_keys_local, tpd_keys_dim_local);// initialize tpd button data | |
3117 | #endif | |
3118 | boot_mode = get_boot_mode(); | |
3119 | if (boot_mode == 3) { | |
3120 | boot_mode = NORMAL_BOOT; | |
3121 | } | |
3122 | return 0; | |
3123 | } | |
3124 | ||
3125 | static struct tpd_driver_t synaptics_rmi4_driver = { | |
3126 | .tpd_device_name = "synaptics_tpd", | |
3127 | .tpd_local_init = tpd_local_init, | |
3128 | .suspend = synaptics_rmi4_suspend, | |
3129 | .resume = synaptics_rmi4_resume, | |
3130 | #ifdef TPD_HAVE_BUTTON | |
3131 | .tpd_have_button = 1, | |
3132 | #else | |
3133 | .tpd_have_button = 0, | |
3134 | #endif | |
3135 | }; | |
3136 | ||
3137 | struct i2c_board_info __initdata i2c_tpd={ I2C_BOARD_INFO("synaptics-tpd", TPD_I2C_ADDR)}; | |
3138 | ||
3139 | /** | |
3140 | * synaptics_rmi4_init() | |
3141 | * | |
3142 | * Called by the kernel during do_initcalls (if built-in) | |
3143 | * or when the driver is loaded (if a module). | |
3144 | * | |
3145 | * This function registers the driver to the I2C subsystem. | |
3146 | * | |
3147 | */ | |
3148 | static int __init synaptics_rmi4_init(void) | |
3149 | { | |
3150 | i2c_register_board_info(TPD_I2C_NUMBER, &i2c_tpd, 1); | |
3151 | if(tpd_driver_add(&synaptics_rmi4_driver) < 0){ | |
3152 | pr_err("Fail to add tpd driver\n"); | |
3153 | return -1; | |
3154 | } | |
3155 | ||
3156 | return 0; | |
3157 | } | |
3158 | ||
3159 | /** | |
3160 | * synaptics_rmi4_exit() | |
3161 | * | |
3162 | * Called by the kernel when the driver is unloaded. | |
3163 | * | |
3164 | * This funtion unregisters the driver from the I2C subsystem. | |
3165 | * | |
3166 | */ | |
3167 | static void __exit synaptics_rmi4_exit(void) | |
3168 | { | |
3169 | i2c_del_driver(&synaptics_rmi4_driver); | |
3170 | return; | |
3171 | } | |
3172 | ||
3173 | module_init(synaptics_rmi4_init); | |
3174 | module_exit(synaptics_rmi4_exit); | |
3175 | ||
3176 | MODULE_AUTHOR("Synaptics, Inc."); | |
3177 | MODULE_DESCRIPTION("Synaptics DSX I2C Touch Driver"); | |
3178 | MODULE_LICENSE("GPL v2"); |