Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | /* Copyright Statement: |
2 | * | |
3 | * This software/firmware and related documentation ("MediaTek Software") are | |
4 | * protected under relevant copyright laws. The information contained herein | |
5 | * is confidential and proprietary to MediaTek Inc. and/or its licensors. | |
6 | * Without the prior written permission of MediaTek inc. and/or its licensors, | |
7 | * any reproduction, modification, use or disclosure of MediaTek Software, | |
8 | * and information contained herein, in whole or in part, shall be strictly prohibited. | |
9 | * | |
10 | * MediaTek Inc. (C) 2012. All rights reserved. | |
11 | * | |
12 | * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES | |
13 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") | |
14 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON | |
15 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. | |
18 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE | |
19 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR | |
20 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH | |
21 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES | |
22 | * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES | |
23 | * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK | |
24 | * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR | |
25 | * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND | |
26 | * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, | |
27 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, | |
28 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO | |
29 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. | |
30 | * | |
31 | * The following software/firmware and/or related documentation ("MediaTek Software") | |
32 | * have been modified by MediaTek Inc. All revisions are subject to any receiver's | |
33 | * applicable license agreements with MediaTek Inc. | |
34 | */ | |
35 | ||
36 | /* | |
37 | * Version: V2.0 | |
38 | * Release Date: 2013/08/28 | |
39 | * Contact: andrew@goodix.com, meta@goodix.com | |
40 | * Revision Record: | |
41 | * V1.4: | |
42 | * 1. New Heartbeat/ESD-protect Mechanism(external watchdog) | |
43 | * 2. doze mode, sliding wakeup | |
44 | * 3. config length verification & 3 more config groups(GT9 Sensor_ID: 0 ~ 5) | |
45 | * 4. charger status switch | |
46 | * By Meta, 2013/03/11 | |
47 | * V1.6: | |
48 | * 1. pen/stylus support | |
49 | * 2. slide wakeup, new esd optimization | |
50 | * By Meta, 2013/04/18 | |
51 | * V1.8: | |
52 | * 1. read double check & fixed config support | |
53 | * 2. other optimizations | |
54 | * By Meta, 2013/06/08 | |
55 | * V2.0: | |
56 | * 1. compatible with GT9XXF | |
57 | * 2. I2C DMA support | |
58 | * By Meta, 2013/08/28 | |
59 | * V2.2: | |
60 | * 1. update gt9xx_config to compatible with Linux 3.10 | |
61 | * 2. gesture wakeup | |
62 | * 3. pen separate input device, active-pen button support | |
63 | * 4. coordinates & keys optimization | |
64 | * 5. no longer support GT915S | |
65 | * By Meta, 2014/01/14 | |
66 | * V2.2.6: | |
67 | * Special edition for GT910 flashless | |
68 | * 1. firmware check | |
69 | * V2.2.7 | |
70 | * Special edition for GT910 flashless | |
71 | * 1. modified to support gesture wakeup module | |
72 | */ | |
73 | ||
74 | #include "tpd.h" | |
75 | #include "tpd_custom_gt9xx.h" | |
76 | #include <asm/ptrace.h> | |
77 | ||
78 | #ifndef TPD_NO_GPIO | |
79 | #include "cust_gpio_usage.h" | |
80 | #endif | |
81 | #ifdef TPD_PROXIMITY | |
82 | #include <linux/hwmsensor.h> | |
83 | #include <linux/hwmsen_dev.h> | |
84 | #include <linux/sensors_io.h> | |
85 | #endif | |
86 | ||
87 | #if GTP_SUPPORT_I2C_DMA | |
88 | #include <linux/dma-mapping.h> | |
89 | #endif | |
90 | ||
91 | extern int gesture_value; | |
92 | extern char tpd_firmware_version_val[5]; | |
93 | extern int tpd_config_version; | |
94 | extern int tpd_x_line; | |
95 | extern int tpd_y_line; | |
4b9e9796 S |
96 | extern u8 tpd_sensor_id; |
97 | ||
6fa3eb70 S |
98 | int gtp_autotool_setting; |
99 | EXPORT_SYMBOL(gtp_autotool_setting); | |
100 | extern struct tpd_device *tpd; | |
101 | ||
102 | static int tpd_sleep_flag = 0; | |
103 | static int tpd_flag = 0; | |
104 | int tpd_halt = 0; | |
105 | static struct task_struct *thread = NULL; | |
106 | static DECLARE_WAIT_QUEUE_HEAD(waiter); | |
107 | ||
108 | #ifdef TPD_HAVE_BUTTON | |
109 | static int tpd_keys_local[TPD_KEY_COUNT] = TPD_KEYS; | |
110 | static int tpd_keys_dim_local[TPD_KEY_COUNT][4] = TPD_KEYS_DIM; | |
111 | #endif | |
112 | ||
113 | typedef enum | |
114 | { | |
115 | DOZE_DISABLED = 0, | |
116 | DOZE_ENABLED = 1, | |
117 | DOZE_WAKEUP = 2, | |
118 | }DOZE_T; | |
119 | static DOZE_T doze_status = DOZE_DISABLED; | |
120 | static s8 gtp_enter_doze(struct i2c_client *client); | |
121 | ||
122 | #if GTP_CHARGER_SWITCH | |
123 | #ifdef MT6573 | |
124 | #define CHR_CON0 (0xF7000000+0x2FA00) | |
125 | #else | |
126 | extern kal_bool upmu_is_chr_det(void); | |
127 | #endif | |
128 | static void gtp_charger_switch(s32 dir_update); | |
129 | #endif | |
130 | ||
131 | #if GTP_HAVE_TOUCH_KEY | |
132 | const u16 touch_key_array[] = GTP_KEY_TAB; | |
133 | #define GTP_MAX_KEY_NUM ( sizeof( touch_key_array )/sizeof( touch_key_array[0] ) ) | |
134 | #endif | |
135 | ||
136 | #if (defined(TPD_WARP_START) && defined(TPD_WARP_END)) | |
137 | static int tpd_wb_start_local[TPD_WARP_CNT] = TPD_WARP_START; | |
138 | static int tpd_wb_end_local[TPD_WARP_CNT] = TPD_WARP_END; | |
139 | #endif | |
140 | ||
141 | #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION)) | |
142 | //static int tpd_calmat_local[8] = TPD_CALIBRATION_MATRIX; | |
143 | static int tpd_def_calmat_local[8] = TPD_CALIBRATION_MATRIX; | |
144 | #endif | |
145 | ||
146 | #if GTP_SUPPORT_I2C_DMA | |
147 | s32 i2c_dma_write(struct i2c_client *client, u16 addr, u8 *txbuf, s32 len); | |
148 | s32 i2c_dma_read(struct i2c_client *client, u16 addr, u8 *rxbuf, s32 len); | |
149 | ||
150 | static u8 *gpDMABuf_va = NULL; | |
151 | static u32 gpDMABuf_pa = 0; | |
152 | #endif | |
153 | ||
154 | s32 gtp_send_cfg(struct i2c_client *client); | |
155 | void gtp_reset_guitar(struct i2c_client *client, s32 ms); | |
156 | static void tpd_eint_interrupt_handler(void); | |
157 | static int touch_event_handler(void *unused); | |
158 | static int tpd_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id); | |
159 | static int tpd_i2c_detect(struct i2c_client *client, struct i2c_board_info *info); | |
160 | static int tpd_i2c_remove(struct i2c_client *client); | |
161 | s32 gtp_i2c_read_dbl_check(struct i2c_client *client, u16 addr, u8 *rxbuf, int len); | |
162 | extern void mt_eint_unmask(unsigned int line); | |
163 | extern void mt_eint_mask(unsigned int line); | |
164 | ||
165 | #if GTP_CREATE_WR_NODE | |
166 | extern s32 init_wr_node(struct i2c_client *); | |
167 | extern void uninit_wr_node(void); | |
168 | #endif | |
169 | ||
170 | #if (GTP_ESD_PROTECT || GTP_COMPATIBLE_MODE) | |
171 | static s32 force_reset_guitar(s32); | |
172 | #endif | |
173 | ||
174 | #if GTP_ESD_PROTECT | |
175 | static int clk_tick_cnt = 200; | |
176 | u8 esd_running = 0; | |
177 | spinlock_t esd_lock; | |
178 | extern unsigned char gtp_default_FW_fl[]; | |
179 | static struct delayed_work gtp_esd_check_work; | |
180 | static struct workqueue_struct *gtp_esd_check_workqueue = NULL; | |
181 | static s32 gtp_init_ext_watchdog(struct i2c_client *client); | |
182 | static void gtp_esd_check_func(struct work_struct *); | |
183 | void gtp_esd_switch(struct i2c_client *client, s32 on); | |
184 | #endif | |
185 | ||
186 | #ifdef TPD_PROXIMITY | |
187 | #define TPD_PROXIMITY_VALID_REG 0x814E | |
188 | #define TPD_PROXIMITY_ENABLE_REG 0x8042 | |
189 | static u8 tpd_proximity_flag = 0; | |
190 | static u8 tpd_proximity_detect = 1;//0-->close ; 1--> far away | |
191 | #endif | |
192 | ||
193 | struct i2c_client *i2c_client_point = NULL; | |
194 | static const struct i2c_device_id tpd_i2c_id[] = {{"gt9xx", 0}, {}}; | |
195 | static unsigned short force[] = {0, 0xBA, I2C_CLIENT_END, I2C_CLIENT_END}; | |
196 | static const unsigned short *const forces[] = { force, NULL }; | |
197 | //static struct i2c_client_address_data addr_data = { .forces = forces,}; | |
198 | static struct i2c_board_info __initdata i2c_tpd = { I2C_BOARD_INFO("gt9xx", (0xBA >> 1))}; | |
199 | static struct i2c_driver tpd_i2c_driver = | |
200 | { | |
201 | .probe = tpd_i2c_probe, | |
202 | .remove = tpd_i2c_remove, | |
203 | .detect = tpd_i2c_detect, | |
204 | .driver.name = "gt9xx", | |
205 | .id_table = tpd_i2c_id, | |
206 | .address_list = (const unsigned short *) forces, | |
207 | }; | |
208 | ||
209 | static u8 config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH] | |
210 | = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; | |
211 | ||
212 | #pragma pack(1) | |
213 | typedef struct | |
214 | { | |
215 | u16 pid; //product id // | |
216 | u16 vid; //version id // | |
217 | } st_tpd_info; | |
218 | #pragma pack() | |
219 | ||
220 | st_tpd_info tpd_info; | |
221 | u8 int_type = 0; | |
222 | u32 abs_x_max = 0; | |
223 | u32 abs_y_max = 0; | |
224 | u8 gtp_rawdiff_mode = 0; | |
225 | u8 cfg_len = 0; | |
226 | u8 grp_cfg_version = 0; | |
227 | u8 fixed_config = 0; | |
228 | u8 pnl_init_error = 0; | |
229 | ||
230 | #if GTP_WITH_PEN | |
231 | struct input_dev *pen_dev; | |
232 | #endif | |
233 | ||
234 | #if GTP_COMPATIBLE_MODE | |
235 | u8 driver_num = 0; | |
236 | u8 sensor_num = 0; | |
4b9e9796 S |
237 | /*[PLATFORM]-Add-BEGIN by falin.luo@tcl.com 2015/4/29*/ |
238 | /*change counter data type to u16, because GTP_CHK_FS_MNT_MAX is 300 */ | |
239 | u16 gtp_ref_retries = 0; | |
240 | u16 gtp_clk_retries = 0; | |
241 | static u16 is_data_mounted = 0; | |
242 | /*[PLATFORM]-Add-NED by falin.luo@tcl.com 2015/4/29*/ | |
6fa3eb70 S |
243 | CHIP_TYPE_T gtp_chip_type = CHIP_TYPE_GT9; |
244 | u8 rqst_processing = 0; | |
245 | u8 is_950 = 0; | |
246 | u8 after_912_1020 = 0; | |
247 | ||
248 | ||
249 | //add by caoyang for ·À¶¶ | |
250 | //static struct timer_list buttons_timer; | |
251 | //static DECLARE_WAIT_QUEUE_HEAD(button_waitq); | |
252 | //end | |
253 | ||
254 | extern u8 gup_check_fs_mounted(char *path_name); | |
255 | extern u8 gup_clk_calibration(void); | |
256 | extern int gup_reload_fw_dsp(void *dir, u8 dwn_mode); | |
257 | extern s32 gup_fw_download_proc(void *dir, u8 dwn_mode); | |
258 | void gtp_get_chip_type(struct i2c_client *client); | |
259 | u8 gtp_fw_startup(struct i2c_client *client); | |
260 | static u8 gtp_bak_ref_proc(struct i2c_client *client, u8 mode); | |
261 | static u8 gtp_main_clk_proc(struct i2c_client *client); | |
262 | static void gtp_recovery_reset(struct i2c_client *client); | |
263 | ||
264 | #if GTP_COMPATIBLE_MODE | |
265 | u8 gtp_hopping_buf[16] = {0}; | |
266 | #endif | |
267 | ||
268 | #if GTP_FL_LITTLE_SYSTEM | |
269 | u8 power_is_down = 0; | |
270 | u8 little_fw_mode = 0; | |
271 | u8 fw_block = 0; // 0: not started, 1 ~ 11/12 ss51 seg a/b each 2K, 13: ss51 seg b, 10K/12K | |
272 | u8 block_section = 1; // 1 ~ 8, 2K total, 256 Bytes each | |
273 | ||
274 | char symbolic_state1[][20] = {"OTHERS", "BUFFER_FULL", "CHECK_COMPLETE", "CHECK_ERROR", "WAIT_CHECK", "OTHERS", "OTHERS", "OTHERS"}; | |
275 | char symbolic_state2[][20] = {"OTHERS", "IS_A_SEG", "IS_B_SEG_FIRST", "IS_B_SEG_OTHER", "IS_B_SEG_LAST", "OTHERS", "OTHERS", "OTHERS"}; | |
276 | ||
277 | static void tpd_up(s32 x, s32 y, s32 id); | |
278 | extern u8 gup_burn_ss51_block(struct i2c_client *client, s32 block_section, s32 fw_block, u16 *fw_chksum); | |
279 | extern u8 gup_burn_ss51_seg_b(struct i2c_client *client, s32 size, u16 *fw_chksum); | |
280 | #endif | |
281 | ||
282 | #endif | |
283 | ||
284 | /* proc file system */ | |
285 | s32 i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *rxbuf, int len); | |
286 | s32 i2c_write_bytes(struct i2c_client *client, u16 addr, u8 *txbuf, int len); | |
287 | ||
288 | static ssize_t gt91xx_config_read_proc(struct file *, char __user *, size_t, loff_t *); | |
289 | static ssize_t gt91xx_config_write_proc(struct file *, const char __user *, size_t, loff_t *); | |
290 | ||
291 | static struct proc_dir_entry *gt91xx_config_proc = NULL; | |
292 | static const struct file_operations config_proc_ops = { | |
293 | .owner = THIS_MODULE, | |
294 | .read = gt91xx_config_read_proc, | |
295 | .write = gt91xx_config_write_proc, | |
296 | }; | |
297 | ||
298 | #define VELOCITY_CUSTOM | |
299 | #ifdef VELOCITY_CUSTOM | |
300 | #include <linux/device.h> | |
301 | #include <linux/miscdevice.h> | |
302 | #include <asm/uaccess.h> | |
303 | ||
304 | #ifndef TPD_VELOCITY_CUSTOM_X | |
305 | #define TPD_VELOCITY_CUSTOM_X 10 | |
306 | #endif | |
307 | #ifndef TPD_VELOCITY_CUSTOM_Y | |
308 | #define TPD_VELOCITY_CUSTOM_Y 10 | |
309 | #endif | |
310 | ||
311 | // for magnify velocity******************************************** | |
312 | #define TOUCH_IOC_MAGIC 'A' | |
313 | ||
314 | #define TPD_GET_VELOCITY_CUSTOM_X _IO(TOUCH_IOC_MAGIC,0) | |
315 | #define TPD_GET_VELOCITY_CUSTOM_Y _IO(TOUCH_IOC_MAGIC,1) | |
316 | ||
317 | int g_v_magnify_x = TPD_VELOCITY_CUSTOM_X; | |
318 | int g_v_magnify_y = TPD_VELOCITY_CUSTOM_Y; | |
319 | static int tpd_misc_open(struct inode *inode, struct file *file) | |
320 | { | |
321 | return nonseekable_open(inode, file); | |
322 | } | |
323 | ||
324 | static int tpd_misc_release(struct inode *inode, struct file *file) | |
325 | { | |
326 | return 0; | |
327 | } | |
328 | ||
329 | static long tpd_unlocked_ioctl(struct file *file, unsigned int cmd, | |
330 | unsigned long arg) | |
331 | { | |
332 | //char strbuf[256]; | |
333 | void __user *data; | |
334 | ||
335 | long err = 0; | |
336 | ||
337 | if (_IOC_DIR(cmd) & _IOC_READ) | |
338 | { | |
339 | err = !access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd)); | |
340 | } | |
341 | else if (_IOC_DIR(cmd) & _IOC_WRITE) | |
342 | { | |
343 | err = !access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd)); | |
344 | } | |
345 | ||
346 | if (err) | |
347 | { | |
348 | printk("tpd: access error: %08X, (%2d, %2d)\n", cmd, _IOC_DIR(cmd), _IOC_SIZE(cmd)); | |
349 | return -EFAULT; | |
350 | } | |
351 | ||
352 | switch (cmd) | |
353 | { | |
354 | case TPD_GET_VELOCITY_CUSTOM_X: | |
355 | data = (void __user *) arg; | |
356 | ||
357 | if (data == NULL) | |
358 | { | |
359 | err = -EINVAL; | |
360 | break; | |
361 | } | |
362 | ||
363 | if (copy_to_user(data, &g_v_magnify_x, sizeof(g_v_magnify_x))) | |
364 | { | |
365 | err = -EFAULT; | |
366 | break; | |
367 | } | |
368 | ||
369 | break; | |
370 | ||
371 | case TPD_GET_VELOCITY_CUSTOM_Y: | |
372 | data = (void __user *) arg; | |
373 | ||
374 | if (data == NULL) | |
375 | { | |
376 | err = -EINVAL; | |
377 | break; | |
378 | } | |
379 | ||
380 | if (copy_to_user(data, &g_v_magnify_y, sizeof(g_v_magnify_y))) | |
381 | { | |
382 | err = -EFAULT; | |
383 | break; | |
384 | } | |
385 | ||
386 | break; | |
387 | ||
388 | default: | |
389 | printk("tpd: unknown IOCTL: 0x%08x\n", cmd); | |
390 | err = -ENOIOCTLCMD; | |
391 | break; | |
392 | ||
393 | } | |
394 | ||
395 | return err; | |
396 | } | |
397 | ||
398 | ||
399 | static struct file_operations tpd_fops = | |
400 | { | |
401 | // .owner = THIS_MODULE, | |
402 | .open = tpd_misc_open, | |
403 | .release = tpd_misc_release, | |
404 | .unlocked_ioctl = tpd_unlocked_ioctl, | |
405 | }; | |
406 | /*----------------------------------------------------------------------------*/ | |
407 | static struct miscdevice tpd_misc_device = | |
408 | { | |
409 | .minor = MISC_DYNAMIC_MINOR, | |
410 | .name = "gt9xx_touch", | |
411 | .fops = &tpd_fops, | |
412 | }; | |
413 | ||
414 | //********************************************** | |
415 | #endif | |
416 | ||
417 | static int tpd_i2c_detect(struct i2c_client *client, struct i2c_board_info *info) | |
418 | { | |
419 | strcpy(info->type, "mtk-tpd"); | |
420 | return 0; | |
421 | } | |
422 | ||
423 | #ifdef TPD_PROXIMITY | |
424 | static s32 tpd_get_ps_value(void) | |
425 | { | |
426 | return tpd_proximity_detect; | |
427 | } | |
428 | ||
429 | static s32 tpd_enable_ps(s32 enable) | |
430 | { | |
431 | u8 state; | |
432 | s32 ret = -1; | |
433 | ||
434 | if (enable) | |
435 | { | |
436 | state = 1; | |
437 | tpd_proximity_flag = 1; | |
438 | GTP_INFO("TPD proximity function to be on."); | |
439 | } | |
440 | else | |
441 | { | |
442 | state = 0; | |
443 | tpd_proximity_flag = 0; | |
444 | GTP_INFO("TPD proximity function to be off."); | |
445 | } | |
446 | ||
447 | ret = i2c_write_bytes(i2c_client_point, TPD_PROXIMITY_ENABLE_REG, &state, 1); | |
448 | ||
449 | if (ret < 0) | |
450 | { | |
451 | GTP_ERROR("TPD %s proximity cmd failed.", state ? "enable" : "disable"); | |
452 | return ret; | |
453 | } | |
454 | ||
455 | GTP_INFO("TPD proximity function %s success.", state ? "enable" : "disable"); | |
456 | return 0; | |
457 | } | |
458 | ||
459 | s32 tpd_ps_operate(void *self, u32 command, void *buff_in, s32 size_in, | |
460 | void *buff_out, s32 size_out, s32 *actualout) | |
461 | { | |
462 | s32 err = 0; | |
463 | s32 value; | |
464 | hwm_sensor_data *sensor_data; | |
465 | ||
466 | switch (command) | |
467 | { | |
468 | case SENSOR_DELAY: | |
469 | if ((buff_in == NULL) || (size_in < sizeof(int))) | |
470 | { | |
471 | GTP_ERROR("Set delay parameter error!"); | |
472 | err = -EINVAL; | |
473 | } | |
474 | ||
475 | // Do nothing | |
476 | break; | |
477 | ||
478 | case SENSOR_ENABLE: | |
479 | if ((buff_in == NULL) || (size_in < sizeof(int))) | |
480 | { | |
481 | GTP_ERROR("Enable sensor parameter error!"); | |
482 | err = -EINVAL; | |
483 | } | |
484 | else | |
485 | { | |
486 | value = *(int *)buff_in; | |
487 | err = tpd_enable_ps(value); | |
488 | } | |
489 | ||
490 | break; | |
491 | ||
492 | case SENSOR_GET_DATA: | |
493 | if ((buff_out == NULL) || (size_out < sizeof(hwm_sensor_data))) | |
494 | { | |
495 | GTP_ERROR("Get sensor data parameter error!"); | |
496 | err = -EINVAL; | |
497 | } | |
498 | else | |
499 | { | |
500 | sensor_data = (hwm_sensor_data *)buff_out; | |
501 | sensor_data->values[0] = tpd_get_ps_value(); | |
502 | sensor_data->value_divide = 1; | |
503 | sensor_data->status = SENSOR_STATUS_ACCURACY_MEDIUM; | |
504 | } | |
505 | ||
506 | break; | |
507 | ||
508 | default: | |
509 | GTP_ERROR("proxmy sensor operate function no this parameter %d!\n", command); | |
510 | err = -1; | |
511 | break; | |
512 | } | |
513 | ||
514 | return err; | |
515 | } | |
516 | #endif | |
517 | ||
518 | ||
519 | static ssize_t gt91xx_config_read_proc(struct file *file, char __user *page, size_t size, loff_t *ppos) | |
520 | { | |
521 | char *ptr = page; | |
522 | char temp_data[GTP_CONFIG_MAX_LENGTH + 2] = {0}; | |
523 | int i; | |
524 | ||
525 | if (*ppos) // CMD call again | |
526 | { | |
527 | return 0; | |
528 | } | |
529 | ||
530 | ptr += sprintf(ptr, "==== GT9XX config init value====\n"); | |
531 | ||
532 | for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++) | |
533 | { | |
534 | ptr += sprintf(ptr, "0x%02X ", config[i + 2]); | |
535 | ||
536 | if (i % 8 == 7) | |
537 | ptr += sprintf(ptr, "\n"); | |
538 | } | |
539 | ||
540 | ptr += sprintf(ptr, "\n"); | |
541 | ||
542 | ptr += sprintf(ptr, "==== GT9XX config real value====\n"); | |
543 | i2c_read_bytes(i2c_client_point, GTP_REG_CONFIG_DATA, temp_data, GTP_CONFIG_MAX_LENGTH); | |
544 | ||
545 | for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++) | |
546 | { | |
547 | ptr += sprintf(ptr, "0x%02X ", temp_data[i]); | |
548 | ||
549 | if (i % 8 == 7) | |
550 | ptr += sprintf(ptr, "\n"); | |
551 | } | |
552 | *ppos += ptr - page; | |
553 | return (ptr - page); | |
554 | } | |
555 | ||
556 | static ssize_t gt91xx_config_write_proc(struct file *filp, const char __user *buffer, size_t count, loff_t *off) | |
557 | { | |
558 | s32 ret = 0; | |
559 | ||
560 | GTP_DEBUG("write count %d\n", count); | |
561 | ||
562 | if (count > GTP_CONFIG_MAX_LENGTH) | |
563 | { | |
564 | GTP_ERROR("size not match [%d:%d]\n", GTP_CONFIG_MAX_LENGTH, count); | |
565 | return -EFAULT; | |
566 | } | |
567 | ||
568 | if (copy_from_user(&config[2], buffer, count)) | |
569 | { | |
570 | GTP_ERROR("copy from user fail\n"); | |
571 | return -EFAULT; | |
572 | } | |
573 | ||
574 | ret = gtp_send_cfg(i2c_client_point); | |
575 | abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC]; | |
576 | abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2]; | |
577 | int_type = (config[TRIGGER_LOC]) & 0x03; | |
578 | ||
579 | if (ret < 0) | |
580 | { | |
581 | GTP_ERROR("send config failed."); | |
582 | } | |
583 | ||
584 | return count; | |
585 | } | |
586 | ||
587 | #if GTP_SUPPORT_I2C_DMA | |
588 | s32 i2c_dma_read(struct i2c_client *client, u16 addr, u8 *rxbuf, s32 len) | |
589 | { | |
590 | int ret; | |
591 | s32 retry = 0; | |
592 | u8 buffer[2]; | |
593 | ||
594 | struct i2c_msg msg[2] = | |
595 | { | |
596 | { | |
597 | .addr = (client->addr & I2C_MASK_FLAG), | |
598 | .flags = 0, | |
599 | .buf = buffer, | |
600 | .len = 2, | |
601 | .timing = I2C_MASTER_CLOCK | |
602 | }, | |
603 | { | |
604 | .addr = (client->addr & I2C_MASK_FLAG), | |
605 | .ext_flag = (client->ext_flag | I2C_ENEXT_FLAG | I2C_DMA_FLAG), | |
606 | .flags = I2C_M_RD, | |
607 | .buf = (u8*)gpDMABuf_pa, | |
608 | .len = len, | |
609 | .timing = I2C_MASTER_CLOCK | |
610 | }, | |
611 | }; | |
612 | ||
613 | buffer[0] = (addr >> 8) & 0xFF; | |
614 | buffer[1] = addr & 0xFF; | |
615 | ||
616 | if (rxbuf == NULL) | |
617 | return -1; | |
618 | ||
619 | //GTP_DEBUG("dma i2c read: 0x%04X, %d bytes(s)", addr, len); | |
620 | for (retry = 0; retry < 5; ++retry) | |
621 | { | |
622 | ret = i2c_transfer(client->adapter, &msg[0], 2); | |
623 | if (ret < 0) | |
624 | { | |
625 | continue; | |
626 | } | |
627 | memcpy(rxbuf, gpDMABuf_va, len); | |
628 | return 0; | |
629 | } | |
630 | GTP_ERROR("Dma I2C Read Error: 0x%04X, %d byte(s), err-code: %d", addr, len, ret); | |
631 | return ret; | |
632 | } | |
633 | ||
634 | ||
635 | s32 i2c_dma_write(struct i2c_client *client, u16 addr, u8 *txbuf, s32 len) | |
636 | { | |
637 | int ret; | |
638 | s32 retry = 0; | |
639 | u8 *wr_buf = gpDMABuf_va; | |
640 | ||
641 | struct i2c_msg msg = | |
642 | { | |
643 | .addr = (client->addr & I2C_MASK_FLAG), | |
644 | .ext_flag = (client->ext_flag | I2C_ENEXT_FLAG | I2C_DMA_FLAG), | |
645 | .flags = 0, | |
646 | .buf = (u8*)gpDMABuf_pa, | |
647 | .len = 2 + len, | |
648 | .timing = I2C_MASTER_CLOCK | |
649 | }; | |
650 | ||
651 | wr_buf[0] = (u8)((addr >> 8) & 0xFF); | |
652 | wr_buf[1] = (u8)(addr & 0xFF); | |
653 | ||
654 | if (txbuf == NULL) | |
655 | return -1; | |
656 | ||
657 | //GTP_DEBUG("dma i2c write: 0x%04X, %d bytes(s)", addr, len); | |
658 | memcpy(wr_buf+2, txbuf, len); | |
659 | for (retry = 0; retry < 5; ++retry) | |
660 | { | |
661 | ret = i2c_transfer(client->adapter, &msg, 1); | |
662 | if (ret < 0) | |
663 | { | |
664 | continue; | |
665 | } | |
666 | return 0; | |
667 | } | |
668 | GTP_ERROR("Dma I2C Write Error: 0x%04X, %d byte(s), err-code: %d", addr, len, ret); | |
669 | return ret; | |
670 | } | |
671 | ||
672 | s32 i2c_read_bytes_dma(struct i2c_client *client, u16 addr, u8 *rxbuf, s32 len) | |
673 | { | |
674 | s32 left = len; | |
675 | s32 read_len = 0; | |
676 | u8 *rd_buf = rxbuf; | |
677 | s32 ret = 0; | |
678 | ||
679 | //GTP_DEBUG("Read bytes dma: 0x%04X, %d byte(s)", addr, len); | |
680 | while (left > 0) | |
681 | { | |
682 | if (left > GTP_DMA_MAX_TRANSACTION_LENGTH) | |
683 | { | |
684 | read_len = GTP_DMA_MAX_TRANSACTION_LENGTH; | |
685 | } | |
686 | else | |
687 | { | |
688 | read_len = left; | |
689 | } | |
690 | ret = i2c_dma_read(client, addr, rd_buf, read_len); | |
691 | if (ret < 0) | |
692 | { | |
693 | GTP_ERROR("dma read failed"); | |
694 | return -1; | |
695 | } | |
696 | ||
697 | left -= read_len; | |
698 | addr += read_len; | |
699 | rd_buf += read_len; | |
700 | } | |
701 | return 0; | |
702 | } | |
703 | ||
704 | s32 i2c_write_bytes_dma(struct i2c_client *client, u16 addr, u8 *txbuf, s32 len) | |
705 | { | |
706 | ||
707 | s32 ret = 0; | |
708 | s32 write_len = 0; | |
709 | s32 left = len; | |
710 | u8 *wr_buf = txbuf; | |
711 | ||
712 | //GTP_DEBUG("Write bytes dma: 0x%04X, %d byte(s)", addr, len); | |
713 | while (left > 0) | |
714 | { | |
715 | if (left > GTP_DMA_MAX_I2C_TRANSFER_SIZE) | |
716 | { | |
717 | write_len = GTP_DMA_MAX_I2C_TRANSFER_SIZE; | |
718 | } | |
719 | else | |
720 | { | |
721 | write_len = left; | |
722 | } | |
723 | ret = i2c_dma_write(client, addr, wr_buf, write_len); | |
724 | ||
725 | if (ret < 0) | |
726 | { | |
727 | GTP_ERROR("dma i2c write failed!"); | |
728 | return -1; | |
729 | } | |
730 | ||
731 | left -= write_len; | |
732 | addr += write_len; | |
733 | wr_buf += write_len; | |
734 | } | |
735 | return 0; | |
736 | } | |
737 | #endif | |
738 | ||
739 | ||
740 | int i2c_read_bytes_non_dma(struct i2c_client *client, u16 addr, u8 *rxbuf, int len) | |
741 | { | |
742 | u8 buffer[GTP_ADDR_LENGTH]; | |
743 | u8 retry; | |
744 | u16 left = len; | |
745 | u16 offset = 0; | |
746 | ||
747 | struct i2c_msg msg[2] = | |
748 | { | |
749 | { | |
750 | //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)), | |
751 | .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_PUSHPULL_FLAG)), | |
752 | .flags = 0, | |
753 | .buf = buffer, | |
754 | .len = GTP_ADDR_LENGTH, | |
755 | .timing = I2C_MASTER_CLOCK | |
756 | }, | |
757 | { | |
758 | //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)), | |
759 | .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_PUSHPULL_FLAG)), | |
760 | .flags = I2C_M_RD, | |
761 | .timing = I2C_MASTER_CLOCK | |
762 | }, | |
763 | }; | |
764 | ||
765 | if (rxbuf == NULL) | |
766 | return -1; | |
767 | ||
768 | //GTP_DEBUG("i2c_read_bytes to device %02X address %04X len %d\n", client->addr, addr, len); | |
769 | ||
770 | while (left > 0) | |
771 | { | |
772 | buffer[0] = ((addr + offset) >> 8) & 0xFF; | |
773 | buffer[1] = (addr + offset) & 0xFF; | |
774 | ||
775 | msg[1].buf = &rxbuf[offset]; | |
776 | ||
777 | if (left > MAX_TRANSACTION_LENGTH) | |
778 | { | |
779 | msg[1].len = MAX_TRANSACTION_LENGTH; | |
780 | left -= MAX_TRANSACTION_LENGTH; | |
781 | offset += MAX_TRANSACTION_LENGTH; | |
782 | } | |
783 | else | |
784 | { | |
785 | msg[1].len = left; | |
786 | left = 0; | |
787 | } | |
788 | ||
789 | retry = 0; | |
790 | ||
791 | while (i2c_transfer(client->adapter, &msg[0], 2) != 2) | |
792 | { | |
793 | retry++; | |
794 | ||
795 | //if (retry == 20) | |
796 | if (retry == 5) | |
797 | { | |
798 | GTP_ERROR("I2C read 0x%X length=%d failed\n", addr + offset, len); | |
799 | return -1; | |
800 | } | |
801 | } | |
802 | } | |
803 | ||
804 | return 0; | |
805 | } | |
806 | ||
807 | ||
808 | int i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *rxbuf, int len) | |
809 | { | |
810 | #if GTP_SUPPORT_I2C_DMA | |
811 | return i2c_read_bytes_dma(client, addr, rxbuf, len); | |
812 | #else | |
813 | return i2c_read_bytes_non_dma(client, addr, rxbuf, len); | |
814 | #endif | |
815 | } | |
816 | ||
817 | s32 gtp_i2c_read(struct i2c_client *client, u8 *buf, s32 len) | |
818 | { | |
819 | s32 ret = -1; | |
820 | u16 addr = (buf[0] << 8) + buf[1]; | |
821 | ||
822 | ret = i2c_read_bytes_non_dma(client, addr, &buf[2], len - 2); | |
823 | ||
824 | if (!ret) | |
825 | { | |
826 | return 2; | |
827 | } | |
828 | else | |
829 | { | |
830 | //#if GTP_GESTURE_WAKEUP | |
831 | if(gesture_value > 0){ | |
832 | if (DOZE_ENABLED == doze_status) | |
833 | { | |
834 | return ret; | |
835 | } | |
836 | //#endif | |
837 | } | |
838 | #if GTP_COMPATIBLE_MODE | |
839 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
840 | { | |
841 | #if GTP_FL_LITTLE_SYSTEM | |
842 | if (little_fw_mode) | |
843 | { | |
844 | // do nothing | |
845 | GTP_INFO("Little fw enabled, no esd reset."); | |
846 | } | |
847 | else | |
848 | #endif | |
849 | { | |
850 | gtp_recovery_reset(client); | |
851 | } | |
852 | } | |
853 | else | |
854 | #endif | |
855 | { | |
856 | gtp_reset_guitar(client, 20); | |
857 | } | |
858 | return ret; | |
859 | } | |
860 | } | |
861 | ||
862 | ||
863 | s32 gtp_i2c_read_dbl_check(struct i2c_client *client, u16 addr, u8 *rxbuf, int len) | |
864 | { | |
865 | u8 buf[16] = {0}; | |
866 | u8 confirm_buf[16] = {0}; | |
867 | u8 retry = 0; | |
868 | ||
869 | while (retry++ < 3) | |
870 | { | |
871 | memset(buf, 0xAA, 16); | |
872 | buf[0] = (u8)(addr >> 8); | |
873 | buf[1] = (u8)(addr & 0xFF); | |
874 | gtp_i2c_read(client, buf, len + 2); | |
875 | ||
876 | memset(confirm_buf, 0xAB, 16); | |
877 | confirm_buf[0] = (u8)(addr >> 8); | |
878 | confirm_buf[1] = (u8)(addr & 0xFF); | |
879 | gtp_i2c_read(client, confirm_buf, len + 2); | |
880 | ||
881 | if (!memcmp(buf, confirm_buf, len+2)) | |
882 | { | |
883 | memcpy(rxbuf, confirm_buf+2, len); | |
884 | return SUCCESS; | |
885 | } | |
886 | } | |
887 | GTP_ERROR("i2c read 0x%04X, %d bytes, double check failed!", addr, len); | |
888 | return FAIL; | |
889 | } | |
890 | ||
891 | int i2c_write_bytes_non_dma(struct i2c_client *client, u16 addr, u8 *txbuf, int len) | |
892 | { | |
893 | u8 buffer[MAX_TRANSACTION_LENGTH]; | |
894 | u16 left = len; | |
895 | u16 offset = 0; | |
896 | u8 retry = 0; | |
897 | ||
898 | struct i2c_msg msg = | |
899 | { | |
900 | //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)), | |
901 | .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_PUSHPULL_FLAG)), | |
902 | .flags = 0, | |
903 | .buf = buffer, | |
904 | .timing = I2C_MASTER_CLOCK, | |
905 | }; | |
906 | ||
907 | ||
908 | if (txbuf == NULL) | |
909 | return -1; | |
910 | ||
911 | //GTP_DEBUG("i2c_write_bytes to device %02X address %04X len %d\n", client->addr, addr, len); | |
912 | ||
913 | while (left > 0) | |
914 | { | |
915 | retry = 0; | |
916 | ||
917 | buffer[0] = ((addr + offset) >> 8) & 0xFF; | |
918 | buffer[1] = (addr + offset) & 0xFF; | |
919 | ||
920 | if (left > MAX_I2C_TRANSFER_SIZE) | |
921 | { | |
922 | memcpy(&buffer[GTP_ADDR_LENGTH], &txbuf[offset], MAX_I2C_TRANSFER_SIZE); | |
923 | msg.len = MAX_TRANSACTION_LENGTH; | |
924 | left -= MAX_I2C_TRANSFER_SIZE; | |
925 | offset += MAX_I2C_TRANSFER_SIZE; | |
926 | } | |
927 | else | |
928 | { | |
929 | memcpy(&buffer[GTP_ADDR_LENGTH], &txbuf[offset], left); | |
930 | msg.len = left + GTP_ADDR_LENGTH; | |
931 | left = 0; | |
932 | } | |
933 | ||
934 | //GTP_DEBUG("byte left %d offset %d\n", left, offset); | |
935 | ||
936 | while (i2c_transfer(client->adapter, &msg, 1) != 1) | |
937 | { | |
938 | retry++; | |
939 | ||
940 | //if (retry == 20) | |
941 | if (retry == 5) | |
942 | { | |
943 | //dump_stack(); | |
944 | GTP_ERROR("I2C write 0x%X%X length=%d failed\n", buffer[0], buffer[1], len); | |
945 | return -1; | |
946 | } | |
947 | } | |
948 | } | |
949 | ||
950 | return 0; | |
951 | } | |
952 | ||
953 | int i2c_write_bytes(struct i2c_client *client, u16 addr, u8 *txbuf, int len) | |
954 | { | |
955 | #if GTP_SUPPORT_I2C_DMA | |
956 | return i2c_write_bytes_dma(client, addr, txbuf, len); | |
957 | #else | |
958 | return i2c_write_bytes_non_dma(client, addr, txbuf, len); | |
959 | #endif | |
960 | } | |
961 | ||
962 | s32 gtp_i2c_write(struct i2c_client *client, u8 *buf, s32 len) | |
963 | { | |
964 | s32 ret = -1; | |
965 | u16 addr = (buf[0] << 8) + buf[1]; | |
966 | ||
967 | ret = i2c_write_bytes_non_dma(client, addr, &buf[2], len - 2); | |
968 | ||
969 | if (!ret) | |
970 | { | |
971 | return 1; | |
972 | } | |
973 | else | |
974 | { | |
975 | //#if GTP_GESTURE_WAKEUP | |
976 | if(gesture_value > 0){ | |
977 | if (DOZE_ENABLED == doze_status) | |
978 | { | |
979 | return ret; | |
980 | } | |
981 | //#endif | |
982 | } | |
983 | #if GTP_COMPATIBLE_MODE | |
984 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
985 | { | |
986 | #if GTP_FL_LITTLE_SYSTEM | |
987 | if (little_fw_mode) | |
988 | { | |
989 | // do nothing | |
990 | GTP_INFO("Little fw enabled, no esd reset."); | |
991 | } | |
992 | else | |
993 | #endif | |
994 | { | |
995 | gtp_recovery_reset(client); | |
996 | } | |
997 | } | |
998 | else | |
999 | #endif | |
1000 | { | |
1001 | gtp_reset_guitar(client, 20); | |
1002 | } | |
1003 | return ret; | |
1004 | } | |
1005 | } | |
1006 | ||
1007 | ||
1008 | ||
1009 | /******************************************************* | |
1010 | Function: | |
1011 | Send config Function. | |
1012 | ||
1013 | Input: | |
1014 | client: i2c client. | |
1015 | ||
1016 | Output: | |
1017 | Executive outcomes.0--success,non-0--fail. | |
1018 | *******************************************************/ | |
1019 | s32 gtp_send_cfg(struct i2c_client *client) | |
1020 | { | |
1021 | s32 ret = 1; | |
1022 | ||
1023 | #if GTP_DRIVER_SEND_CFG | |
1024 | s32 retry = 0; | |
1025 | if (fixed_config) | |
1026 | { | |
1027 | GTP_INFO("Ic fixed config, no config sent!"); | |
1028 | return 0; | |
1029 | } | |
1030 | else if (pnl_init_error) | |
1031 | { | |
1032 | GTP_INFO("Error occurred in init_panel, no config sent!"); | |
1033 | return 0; | |
1034 | } | |
1035 | ||
1036 | GTP_INFO("Driver Send Config"); | |
1037 | for (retry = 0; retry < 5; retry++) | |
1038 | { | |
1039 | ret = gtp_i2c_write(client, config, GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); | |
1040 | ||
1041 | if (ret > 0) | |
1042 | { | |
1043 | break; | |
1044 | } | |
1045 | } | |
1046 | #endif | |
1047 | return ret; | |
1048 | } | |
1049 | ||
1050 | ||
1051 | /******************************************************* | |
1052 | Function: | |
1053 | Read goodix touchscreen version function. | |
1054 | ||
1055 | Input: | |
1056 | client: i2c client struct. | |
1057 | version:address to store version info | |
1058 | ||
1059 | Output: | |
1060 | Executive outcomes.0---succeed. | |
1061 | *******************************************************/ | |
1062 | s32 gtp_read_version(struct i2c_client *client, u16 *version) | |
1063 | { | |
1064 | s32 ret = -1; | |
1065 | s32 i; | |
1066 | u8 buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff}; | |
1067 | ||
1068 | GTP_DEBUG_FUNC(); | |
1069 | ||
1070 | ret = gtp_i2c_read(client, buf, sizeof(buf)); | |
1071 | ||
1072 | if (ret < 0) | |
1073 | { | |
1074 | GTP_ERROR("GTP read version failed"); | |
1075 | return ret; | |
1076 | } | |
1077 | ||
1078 | if (version) | |
1079 | { | |
1080 | *version = (buf[7] << 8) | buf[6]; | |
1081 | } | |
1082 | ||
1083 | tpd_info.vid = *version; | |
1084 | tpd_info.pid = 0x00; | |
1085 | ||
1086 | for (i = 0; i < 4; i++) | |
1087 | { | |
1088 | if (buf[i + 2] < 0x30)break; | |
1089 | ||
1090 | tpd_info.pid |= ((buf[i + 2] - 0x30) << ((3 - i) * 4)); | |
1091 | } | |
1092 | ||
1093 | if (buf[5] == 0x00) | |
1094 | { | |
1095 | GTP_INFO("IC VERSION: %c%c%c_%02x%02x", | |
1096 | buf[2], buf[3], buf[4], buf[7], buf[6]); | |
1097 | } | |
1098 | else | |
1099 | { | |
1100 | GTP_INFO("IC VERSION:%c%c%c%c_%02x%02x", | |
1101 | buf[2], buf[3], buf[4], buf[5], buf[7], buf[6]); | |
1102 | } | |
1103 | sprintf(tpd_firmware_version_val,"%02x%02x",buf[7], buf[6]); | |
1104 | tpd_firmware_version_val[4] = '\0'; | |
1105 | printk(KERN_ERR"caoyang test tpd_firmware_version_val:%s",tpd_firmware_version_val); | |
1106 | return ret; | |
1107 | } | |
1108 | ||
1109 | #if GTP_DRIVER_SEND_CFG | |
1110 | /******************************************************* | |
1111 | Function: | |
1112 | Get information from ic, such as resolution and | |
1113 | int trigger type | |
1114 | Input: | |
1115 | client: i2c client private struct. | |
1116 | ||
1117 | Output: | |
1118 | FAIL: i2c failed, SUCCESS: i2c ok | |
1119 | *******************************************************/ | |
1120 | static s32 gtp_get_info(struct i2c_client *client) | |
1121 | { | |
1122 | u8 opr_buf[6] = {0}; | |
1123 | s32 ret = 0; | |
1124 | ||
1125 | opr_buf[0] = (u8)((GTP_REG_CONFIG_DATA+1) >> 8); | |
1126 | opr_buf[1] = (u8)((GTP_REG_CONFIG_DATA+1) & 0xFF); | |
1127 | ||
1128 | ret = gtp_i2c_read(client, opr_buf, 6); | |
1129 | if (ret < 0) | |
1130 | { | |
1131 | return FAIL; | |
1132 | } | |
1133 | ||
1134 | abs_x_max = (opr_buf[3] << 8) + opr_buf[2]; | |
1135 | abs_y_max = (opr_buf[5] << 8) + opr_buf[4]; | |
1136 | ||
1137 | opr_buf[0] = (u8)((GTP_REG_CONFIG_DATA+6) >> 8); | |
1138 | opr_buf[1] = (u8)((GTP_REG_CONFIG_DATA+6) & 0xFF); | |
1139 | ||
1140 | ret = gtp_i2c_read(client, opr_buf, 3); | |
1141 | if (ret < 0) | |
1142 | { | |
1143 | return FAIL; | |
1144 | } | |
1145 | int_type = opr_buf[2] & 0x03; | |
1146 | ||
1147 | GTP_INFO("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x", | |
1148 | abs_x_max,abs_y_max, int_type); | |
1149 | ||
1150 | return SUCCESS; | |
1151 | } | |
1152 | #endif | |
1153 | ||
1154 | ||
1155 | /******************************************************* | |
1156 | Function: | |
1157 | GTP initialize function. | |
1158 | ||
1159 | Input: | |
1160 | client: i2c client private struct. | |
1161 | ||
1162 | Output: | |
1163 | Executive outcomes.0---succeed. | |
1164 | *******************************************************/ | |
1165 | static s32 gtp_init_panel(struct i2c_client *client) | |
1166 | { | |
1167 | s32 ret = 0; | |
1168 | ||
1169 | #if GTP_DRIVER_SEND_CFG | |
1170 | s32 i; | |
1171 | u8 check_sum = 0; | |
1172 | u8 opr_buf[16]; | |
1173 | u8 sensor_id = 0; | |
1174 | ||
1175 | u8 cfg_info_group1[] = CTP_CFG_GROUP1; | |
1176 | u8 cfg_info_group2[] = CTP_CFG_GROUP2; | |
1177 | u8 cfg_info_group3[] = CTP_CFG_GROUP3; | |
1178 | u8 cfg_info_group4[] = CTP_CFG_GROUP4; | |
1179 | u8 cfg_info_group5[] = CTP_CFG_GROUP5; | |
1180 | u8 cfg_info_group6[] = CTP_CFG_GROUP6; | |
1181 | u8 *send_cfg_buf[] = {cfg_info_group1, cfg_info_group2, cfg_info_group3, | |
1182 | cfg_info_group4, cfg_info_group5, cfg_info_group6}; | |
1183 | u8 cfg_info_len[] = { CFG_GROUP_LEN(cfg_info_group1), | |
1184 | CFG_GROUP_LEN(cfg_info_group2), | |
1185 | CFG_GROUP_LEN(cfg_info_group3), | |
1186 | CFG_GROUP_LEN(cfg_info_group4), | |
1187 | CFG_GROUP_LEN(cfg_info_group5), | |
1188 | CFG_GROUP_LEN(cfg_info_group6)}; | |
1189 | ||
1190 | GTP_DEBUG("Config Groups\' Lengths: %d, %d, %d, %d, %d, %d", | |
1191 | cfg_info_len[0], cfg_info_len[1], cfg_info_len[2], cfg_info_len[3], | |
1192 | cfg_info_len[4], cfg_info_len[5]); | |
1193 | ||
1194 | if ((!cfg_info_len[1]) && (!cfg_info_len[2]) && | |
1195 | (!cfg_info_len[3]) && (!cfg_info_len[4]) && | |
1196 | (!cfg_info_len[5])) | |
1197 | { | |
1198 | sensor_id = 0; | |
1199 | } | |
1200 | else | |
1201 | { | |
1202 | #if GTP_COMPATIBLE_MODE | |
1203 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
1204 | { | |
1205 | msleep(50); | |
1206 | } | |
1207 | #endif | |
1208 | ret = gtp_i2c_read_dbl_check(client, GTP_REG_SENSOR_ID, &sensor_id, 1); | |
1209 | if (SUCCESS == ret) | |
1210 | { | |
1211 | if (sensor_id >= 0x06) | |
1212 | { | |
1213 | GTP_ERROR("Invalid sensor_id(0x%02X), No Config Sent!", sensor_id); | |
1214 | pnl_init_error = 1; | |
1215 | return -1; | |
1216 | } | |
1217 | } | |
1218 | else | |
1219 | { | |
1220 | GTP_ERROR("Failed to get sensor_id, No config sent!"); | |
1221 | pnl_init_error = 1; | |
1222 | return -1; | |
1223 | } | |
1224 | GTP_INFO("Sensor_ID: %d", sensor_id); | |
1225 | } | |
1226 | ||
1227 | cfg_len = cfg_info_len[sensor_id]; | |
1228 | tpd_config_version= send_cfg_buf[sensor_id][0]; | |
4b9e9796 | 1229 | tpd_sensor_id = sensor_id; |
6fa3eb70 S |
1230 | GTP_INFO("CTP_CONFIG_GROUP%d used, config length: %d", sensor_id + 1, cfg_len); |
1231 | ||
1232 | if (cfg_len < GTP_CONFIG_MIN_LENGTH) | |
1233 | { | |
1234 | GTP_ERROR("CTP_CONFIG_GROUP%d is INVALID CONFIG GROUP! NO Config Sent! You need to check you header file CFG_GROUP section!", sensor_id+1); | |
1235 | pnl_init_error = 1; | |
1236 | return -1; | |
1237 | } | |
1238 | ||
1239 | #if GTP_COMPATIBLE_MODE | |
1240 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
1241 | { | |
1242 | fixed_config = 0; | |
1243 | } | |
1244 | else | |
1245 | #endif | |
1246 | { | |
1247 | ret = gtp_i2c_read_dbl_check(client, GTP_REG_CONFIG_DATA, &opr_buf[0], 1); | |
1248 | ||
1249 | if (ret == SUCCESS) | |
1250 | { | |
1251 | GTP_DEBUG("CFG_CONFIG_GROUP%d Config Version: %d, 0x%02X; IC Config Version: %d, 0x%02X", sensor_id+1, | |
1252 | send_cfg_buf[sensor_id][0], send_cfg_buf[sensor_id][0], opr_buf[0], opr_buf[0]); | |
1253 | ||
1254 | if (opr_buf[0] < 90) | |
1255 | { | |
1256 | grp_cfg_version = send_cfg_buf[sensor_id][0]; // backup group config version | |
1257 | send_cfg_buf[sensor_id][0] = 0x00; | |
1258 | fixed_config = 0; | |
1259 | } | |
1260 | else // treated as fixed config, not send config | |
1261 | { | |
1262 | GTP_INFO("Ic fixed config with config version(%d)", opr_buf[0]); | |
1263 | fixed_config = 1; | |
1264 | gtp_get_info(client); | |
1265 | return 0; | |
1266 | } | |
1267 | } | |
1268 | else | |
1269 | { | |
1270 | GTP_ERROR("Failed to get ic config version!No config sent!"); | |
1271 | return -1; | |
1272 | } | |
1273 | } | |
1274 | ||
1275 | memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); | |
1276 | memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[sensor_id], cfg_len); | |
1277 | ||
1278 | #if GTP_CUSTOM_CFG | |
1279 | config[RESOLUTION_LOC] = (u8)GTP_MAX_WIDTH; | |
1280 | config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH>>8); | |
1281 | config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT; | |
1282 | config[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT>>8); | |
1283 | ||
1284 | if (GTP_INT_TRIGGER == 0) //RISING | |
1285 | { | |
1286 | config[TRIGGER_LOC] &= 0xfe; | |
1287 | } | |
1288 | else if (GTP_INT_TRIGGER == 1) //FALLING | |
1289 | { | |
1290 | config[TRIGGER_LOC] |= 0x01; | |
1291 | } | |
1292 | #endif // GTP_CUSTOM_CFG | |
1293 | ||
1294 | check_sum = 0; | |
1295 | for (i = GTP_ADDR_LENGTH; i < cfg_len; i++) | |
1296 | { | |
1297 | check_sum += config[i]; | |
1298 | } | |
1299 | config[cfg_len] = (~check_sum) + 1; | |
1300 | ||
1301 | #else // DRIVER NOT SEND CONFIG | |
1302 | cfg_len = GTP_CONFIG_MAX_LENGTH; | |
1303 | ret = gtp_i2c_read(client, config, cfg_len + GTP_ADDR_LENGTH); | |
1304 | if (ret < 0) | |
1305 | { | |
1306 | GTP_ERROR("Read Config Failed, Using DEFAULT Resolution & INT Trigger!"); | |
1307 | abs_x_max = GTP_MAX_WIDTH; | |
1308 | abs_y_max = GTP_MAX_HEIGHT; | |
1309 | int_type = GTP_INT_TRIGGER; | |
1310 | } | |
1311 | #endif // GTP_DRIVER_SEND_CFG | |
1312 | ||
1313 | GTP_DEBUG_FUNC(); | |
1314 | if ((abs_x_max == 0) && (abs_y_max == 0)) | |
1315 | { | |
1316 | abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC]; | |
1317 | abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2]; | |
1318 | int_type = (config[TRIGGER_LOC]) & 0x03; | |
1319 | } | |
1320 | ||
1321 | #if GTP_COMPATIBLE_MODE | |
1322 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
1323 | { | |
1324 | u8 have_key = 0; | |
1325 | if (is_950) | |
1326 | { | |
1327 | driver_num = config[GTP_REG_MATRIX_DRVNUM - GTP_REG_CONFIG_DATA + 2]; | |
1328 | sensor_num = config[GTP_REG_MATRIX_SENNUM - GTP_REG_CONFIG_DATA + 2]; | |
1329 | } | |
1330 | else | |
1331 | { | |
1332 | driver_num = (config[CFG_LOC_DRVA_NUM]&0x1F) + (config[CFG_LOC_DRVB_NUM]&0x1F); | |
1333 | sensor_num = (config[CFG_LOC_SENS_NUM]&0x0F) + ((config[CFG_LOC_SENS_NUM]>>4)&0x0F); | |
1334 | } | |
1335 | ||
1336 | have_key = config[GTP_REG_HAVE_KEY - GTP_REG_CONFIG_DATA + 2] & 0x01; // have key or not | |
1337 | if (1 == have_key) | |
1338 | { | |
1339 | driver_num--; | |
1340 | } | |
1341 | ||
1342 | if ((cfg_len == 186) && after_912_1020) | |
1343 | { | |
1344 | GTP_DEBUG("Firmware after 912_1020, set config length to 228."); | |
1345 | ||
1346 | cfg_len = 228; | |
1347 | ||
1348 | config[GTP_ADDR_LENGTH + 226] = config[GTP_ADDR_LENGTH + 184]; | |
1349 | ||
1350 | memset(&config[GTP_ADDR_LENGTH + 184], 0x00, 228 - 186); | |
1351 | ||
1352 | config[GTP_ADDR_LENGTH + 227] = 0x01; | |
1353 | ||
1354 | } | |
1355 | tpd_x_line = driver_num; | |
1356 | tpd_y_line = sensor_num; | |
1357 | GTP_INFO("Driver * Sensor: %d * %d(Key: %d), X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x", | |
1358 | driver_num, sensor_num, have_key, abs_x_max,abs_y_max,int_type); | |
1359 | } | |
1360 | else | |
1361 | #endif | |
1362 | { | |
1363 | #if GTP_DRIVER_SEND_CFG | |
1364 | ret = gtp_send_cfg(client); | |
1365 | if (ret < 0) | |
1366 | { | |
1367 | GTP_ERROR("Send config error."); | |
1368 | } | |
1369 | // set config version to CTP_CFG_GROUP | |
1370 | // for resume to send config | |
1371 | config[GTP_ADDR_LENGTH] = grp_cfg_version; | |
1372 | check_sum = 0; | |
1373 | for (i = GTP_ADDR_LENGTH; i < cfg_len; i++) | |
1374 | { | |
1375 | check_sum += config[i]; | |
1376 | } | |
1377 | config[cfg_len] = (~check_sum) + 1; | |
1378 | #endif | |
1379 | GTP_INFO("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x", | |
1380 | abs_x_max,abs_y_max,int_type); | |
1381 | } | |
1382 | ||
1383 | msleep(10); | |
1384 | return 0; | |
1385 | } | |
1386 | ||
1387 | static s8 gtp_i2c_test(struct i2c_client *client) | |
1388 | { | |
1389 | ||
1390 | u8 retry = 0; | |
1391 | s8 ret = -1; | |
1392 | u32 hw_info = 0; | |
1393 | ||
1394 | GTP_DEBUG_FUNC(); | |
1395 | ||
1396 | while (retry++ < 5) | |
1397 | { | |
1398 | ret = i2c_read_bytes(client, GTP_REG_HW_INFO, (u8 *)&hw_info, sizeof(hw_info)); | |
1399 | ||
1400 | if ((!ret) && (hw_info == 0x00900600)) //20121212 | |
1401 | { | |
1402 | return ret; | |
1403 | } | |
1404 | ||
1405 | GTP_ERROR("GTP_REG_HW_INFO : %08X", hw_info); | |
1406 | GTP_ERROR("GTP i2c test failed time %d.", retry); | |
1407 | msleep(10); | |
1408 | } | |
1409 | ||
1410 | return -1; | |
1411 | } | |
1412 | ||
1413 | ||
1414 | ||
1415 | /******************************************************* | |
1416 | Function: | |
1417 | Set INT pin as input for FW sync. | |
1418 | ||
1419 | Note: | |
1420 | If the INT is high, It means there is pull up resistor attached on the INT pin. | |
1421 | Pull low the INT pin manaully for FW sync. | |
1422 | *******************************************************/ | |
1423 | void gtp_int_sync(s32 ms) | |
1424 | { | |
1425 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); | |
1426 | msleep(ms); | |
1427 | GTP_GPIO_AS_INT(GTP_INT_PORT); | |
1428 | } | |
1429 | ||
1430 | void gtp_reset_guitar(struct i2c_client *client, s32 ms) | |
1431 | { | |
1432 | GTP_INFO("GTP RESET!\n"); | |
1433 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); | |
1434 | msleep(ms); | |
1435 | GTP_GPIO_OUTPUT(GTP_INT_PORT, client->addr == 0x14); | |
1436 | ||
1437 | msleep(2); | |
1438 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 1); | |
1439 | ||
1440 | msleep(6); //must >= 6ms | |
1441 | ||
1442 | #if GTP_COMPATIBLE_MODE | |
1443 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
1444 | { | |
1445 | return; | |
1446 | } | |
1447 | #endif | |
1448 | ||
1449 | gtp_int_sync(50); | |
1450 | #if GTP_ESD_PROTECT | |
1451 | gtp_init_ext_watchdog(i2c_client_point); | |
1452 | #endif | |
1453 | } | |
1454 | ||
1455 | static int tpd_power_on(struct i2c_client *client) | |
1456 | { | |
1457 | int ret = 0; | |
1458 | int reset_count = 0; | |
1459 | ||
1460 | reset_proc: | |
1461 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); | |
1462 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); | |
1463 | msleep(10); | |
1464 | ||
1465 | #ifdef MT6573 | |
1466 | // power on CTP | |
1467 | mt_set_gpio_mode(GPIO_CTP_EN_PIN, GPIO_CTP_EN_PIN_M_GPIO); | |
1468 | mt_set_gpio_dir(GPIO_CTP_EN_PIN, GPIO_DIR_OUT); | |
1469 | mt_set_gpio_out(GPIO_CTP_EN_PIN, GPIO_OUT_ONE); | |
1470 | ||
1471 | #else // ( defined(MT6575) || defined(MT6577) || defined(MT6589) ) | |
1472 | ||
1473 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
1474 | hwPowerOn(TPD_POWER_SOURCE_CUSTOM, VOL_2800, "TP"); | |
1475 | #else | |
1476 | hwPowerOn(MT65XX_POWER_LDO_VGP2, VOL_2800, "TP"); | |
1477 | #endif | |
1478 | #ifdef TPD_POWER_SOURCE_1800 | |
1479 | hwPowerOn(TPD_POWER_SOURCE_1800, VOL_1800, "TP"); | |
1480 | #endif | |
1481 | ||
1482 | #endif | |
1483 | ||
1484 | gtp_reset_guitar(client, 20); | |
1485 | ||
1486 | #if GTP_COMPATIBLE_MODE | |
1487 | gtp_get_chip_type(client); | |
1488 | ||
1489 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
1490 | { | |
1491 | ret = gup_fw_download_proc(NULL, GTP_FL_FW_BURN); | |
1492 | ||
1493 | if(FAIL == ret) | |
1494 | { | |
1495 | GTP_ERROR("[tpd_power_on]Download fw failed."); | |
1496 | if(reset_count++ < TPD_MAX_RESET_COUNT) | |
1497 | { | |
1498 | goto reset_proc; | |
1499 | } | |
1500 | else | |
1501 | { | |
1502 | return -1; | |
1503 | } | |
1504 | } | |
1505 | ||
1506 | ret = gtp_fw_startup(client); | |
1507 | if(FAIL == ret) | |
1508 | { | |
1509 | GTP_ERROR("[tpd_power_on]Startup fw failed."); | |
1510 | if(reset_count++ < TPD_MAX_RESET_COUNT) | |
1511 | { | |
1512 | goto reset_proc; | |
1513 | } | |
1514 | else | |
1515 | { | |
1516 | return -1; | |
1517 | } | |
1518 | } | |
1519 | } | |
1520 | else | |
1521 | #endif | |
1522 | { | |
1523 | ret = gtp_i2c_test(client); | |
1524 | ||
1525 | if (ret < 0) | |
1526 | { | |
1527 | GTP_ERROR("I2C communication ERROR!"); | |
1528 | ||
1529 | if (reset_count < TPD_MAX_RESET_COUNT) | |
1530 | { | |
1531 | reset_count++; | |
1532 | goto reset_proc; | |
1533 | } | |
1534 | } | |
1535 | } | |
1536 | return ret; | |
1537 | } | |
1538 | ||
1539 | //**************** For GT9XXF Start ********************// | |
1540 | #if GTP_COMPATIBLE_MODE | |
1541 | ||
1542 | ||
1543 | void gtp_get_chip_type(struct i2c_client *client) | |
1544 | { | |
1545 | u8 opr_buf[10] = {0x00}; | |
1546 | s32 ret = 0; | |
1547 | ||
1548 | msleep(10); | |
1549 | ||
1550 | ret = gtp_i2c_read_dbl_check(client, GTP_REG_CHIP_TYPE, opr_buf, 10); | |
1551 | ||
1552 | if (FAIL == ret) | |
1553 | { | |
1554 | GTP_ERROR("Failed to get chip-type, set chip type default: GOODIX_GT9"); | |
1555 | gtp_chip_type = CHIP_TYPE_GT9; | |
1556 | return; | |
1557 | } | |
1558 | ||
1559 | if (!memcmp(opr_buf, "GOODIX_GT9", 10)) | |
1560 | { | |
1561 | gtp_chip_type = CHIP_TYPE_GT9; | |
1562 | } | |
1563 | else // GT9XXF | |
1564 | { | |
1565 | gtp_chip_type = CHIP_TYPE_GT9F; | |
1566 | } | |
1567 | GTP_INFO("Chip Type: %s", (gtp_chip_type == CHIP_TYPE_GT9) ? "GOODIX_GT9" : "GOODIX_GT9F"); | |
1568 | } | |
1569 | ||
1570 | static u8 gtp_bak_ref_proc(struct i2c_client *client, u8 mode) | |
1571 | { | |
1572 | s32 i = 0; | |
1573 | s32 j = 0; | |
1574 | s32 ret = 0; | |
1575 | struct file *flp = NULL; | |
1576 | u8 *refp = NULL; | |
1577 | u32 ref_len = 0; | |
1578 | u32 ref_seg_len = 0; | |
1579 | s32 ref_grps = 0; | |
1580 | s32 ref_chksum = 0; | |
1581 | u16 tmp = 0; | |
1582 | ||
1583 | GTP_DEBUG("[gtp_bak_ref_proc]Driver:%d,Sensor:%d.", driver_num, sensor_num); | |
1584 | ||
1585 | //check file-system mounted | |
1586 | GTP_DEBUG("[gtp_bak_ref_proc]Waiting for FS %d", gtp_ref_retries); | |
979dc3df | 1587 | if (gup_check_fs_mounted("/cache") == FAIL)/*[PLATFORM]-MOD by falin.luo@tcl.com 2015/4/29*/ |
6fa3eb70 | 1588 | { |
979dc3df | 1589 | GTP_DEBUG("[gtp_bak_ref_proc]/cache not mounted"); |
6fa3eb70 S |
1590 | if(gtp_ref_retries++ < GTP_CHK_FS_MNT_MAX) |
1591 | { | |
4b9e9796 | 1592 | msleep(100);/*[PLATFORM]-ADD by falin.luo@tcl.com 2015/4/29*/ |
6fa3eb70 S |
1593 | return FAIL; |
1594 | } | |
1595 | } | |
1596 | else | |
1597 | { | |
979dc3df | 1598 | GTP_DEBUG("[gtp_bak_ref_proc]/cache mounted !!!!"); |
6fa3eb70 S |
1599 | } |
1600 | ||
1601 | if (is_950) | |
1602 | { | |
1603 | ref_seg_len = (driver_num * (sensor_num - 1) + 2) * 2; | |
1604 | ref_grps = 6; | |
1605 | ref_len = ref_seg_len * 6; // for GT950, backup-reference for six segments | |
1606 | } | |
1607 | else | |
1608 | { | |
1609 | ref_len = driver_num*(sensor_num-2)*2 + 4; | |
1610 | ref_seg_len = ref_len; | |
1611 | ref_grps = 1; | |
1612 | } | |
1613 | ||
1614 | refp = (u8 *)kzalloc(ref_len, GFP_KERNEL); | |
1615 | if(refp == NULL) | |
1616 | { | |
1617 | GTP_ERROR("Failed to allocate memory for reference buffer!"); | |
1618 | return FAIL; | |
1619 | } | |
1620 | memset(refp, 0, ref_len); | |
1621 | ||
1622 | //get ref file data | |
1623 | flp = filp_open(GTP_BAK_REF_PATH, O_RDWR | O_CREAT, 0666); | |
1624 | if (IS_ERR(flp)) | |
1625 | { | |
1626 | GTP_ERROR("Failed to open/create %s.", GTP_BAK_REF_PATH); | |
1627 | if (GTP_BAK_REF_SEND == mode) | |
1628 | { | |
1629 | goto default_bak_ref; | |
1630 | } | |
1631 | else | |
1632 | { | |
1633 | goto exit_ref_proc; | |
1634 | } | |
1635 | } | |
1636 | ||
1637 | switch (mode) | |
1638 | { | |
1639 | case GTP_BAK_REF_SEND: | |
1640 | { | |
1641 | flp->f_op->llseek(flp, 0, SEEK_SET); | |
1642 | ret = flp->f_op->read(flp, (char *)refp, ref_len, &flp->f_pos); | |
1643 | if(ret < 0) | |
1644 | { | |
1645 | GTP_ERROR("Read ref file failed, send default bak ref."); | |
1646 | goto default_bak_ref; | |
1647 | } | |
1648 | //checksum ref file | |
1649 | for (j = 0; j < ref_grps; ++j) | |
1650 | { | |
1651 | ref_chksum = 0; | |
1652 | for(i=0; i<ref_seg_len-2; i+=2) | |
1653 | { | |
1654 | ref_chksum += ((refp[i + j * ref_seg_len]<<8) + refp[i + 1 + j * ref_seg_len]); | |
1655 | } | |
1656 | ||
1657 | GTP_DEBUG("Reference chksum:0x%04X", ref_chksum&0xFF); | |
1658 | tmp = ref_chksum + (refp[ref_seg_len + j * ref_seg_len -2]<<8) + refp[ref_seg_len + j * ref_seg_len -1]; | |
1659 | if(1 != tmp) | |
1660 | { | |
1661 | GTP_DEBUG("Invalid checksum for reference, reset reference."); | |
1662 | memset(&refp[j * ref_seg_len], 0, ref_seg_len); | |
1663 | refp[ref_seg_len - 1 + j * ref_seg_len] = 0x01; | |
1664 | } | |
1665 | else | |
1666 | { | |
1667 | if (j == (ref_grps - 1)) | |
1668 | { | |
1669 | GTP_INFO("Reference data in %s used.", GTP_BAK_REF_PATH); | |
1670 | } | |
1671 | } | |
1672 | ||
1673 | } | |
1674 | ret = i2c_write_bytes(client, GTP_REG_BAK_REF, refp, ref_len); | |
1675 | if(-1 == ret) | |
1676 | { | |
1677 | GTP_ERROR("Write ref i2c error."); | |
1678 | ret = FAIL; | |
1679 | goto exit_ref_proc; | |
1680 | } | |
1681 | } | |
1682 | break; | |
1683 | ||
1684 | case GTP_BAK_REF_STORE: | |
1685 | { | |
1686 | ret = i2c_read_bytes(client, GTP_REG_BAK_REF, refp, ref_len); | |
1687 | if(-1 == ret) | |
1688 | { | |
1689 | GTP_ERROR("Read ref i2c error."); | |
1690 | ret = FAIL; | |
1691 | goto exit_ref_proc; | |
1692 | } | |
1693 | flp->f_op->llseek(flp, 0, SEEK_SET); | |
1694 | flp->f_op->write(flp, (char *)refp, ref_len, &flp->f_pos); | |
1695 | } | |
1696 | break; | |
1697 | ||
1698 | default: | |
1699 | GTP_ERROR("Invalid Argument(%d) for backup reference", mode); | |
1700 | ret = FAIL; | |
1701 | goto exit_ref_proc; | |
1702 | } | |
1703 | ||
1704 | ret = SUCCESS; | |
1705 | goto exit_ref_proc; | |
1706 | ||
1707 | default_bak_ref: | |
1708 | for (j = 0; j < ref_grps; ++j) | |
1709 | { | |
1710 | memset(&refp[j * ref_seg_len], 0, ref_seg_len); | |
1711 | refp[j * ref_seg_len + ref_seg_len - 1] = 0x01; // checksum = 1 | |
1712 | } | |
1713 | ret = i2c_write_bytes(client, GTP_REG_BAK_REF, refp, ref_len); | |
1714 | if (flp && !IS_ERR(flp)) | |
1715 | { | |
1716 | GTP_INFO("Write backup-reference data into %s", GTP_BAK_REF_PATH); | |
1717 | flp->f_op->llseek(flp, 0, SEEK_SET); | |
1718 | flp->f_op->write(flp, (char*)refp, ref_len, &flp->f_pos); | |
1719 | } | |
1720 | if (ret < 0) | |
1721 | { | |
1722 | GTP_ERROR("Failed to load the default backup reference"); | |
1723 | ret = FAIL; | |
1724 | } | |
1725 | else | |
1726 | { | |
1727 | ret = SUCCESS; | |
1728 | } | |
1729 | exit_ref_proc: | |
1730 | if (refp) | |
1731 | { | |
1732 | kfree(refp); | |
1733 | } | |
1734 | if (flp && !IS_ERR(flp)) | |
1735 | { | |
1736 | filp_close(flp, NULL); | |
1737 | } | |
1738 | return ret; | |
1739 | } | |
1740 | ||
1741 | u8 gtp_fw_startup(struct i2c_client *client) | |
1742 | { | |
1743 | u8 wr_buf[4]; | |
1744 | s32 ret = 0; | |
1745 | ||
1746 | //init sw WDT | |
1747 | wr_buf[0] = 0xAA; | |
1748 | ret = i2c_write_bytes(client, 0x8041, wr_buf, 1); | |
1749 | if (ret < 0) | |
1750 | { | |
1751 | GTP_ERROR("I2C error to firmware startup."); | |
1752 | return FAIL; | |
1753 | } | |
1754 | //release SS51 & DSP | |
1755 | wr_buf[0] = 0x00; | |
1756 | i2c_write_bytes(client, 0x4180, wr_buf, 1); | |
1757 | ||
1758 | //int sync | |
1759 | gtp_int_sync(25); | |
1760 | ||
1761 | //check fw run status | |
1762 | i2c_read_bytes(client, 0x8041, wr_buf, 1); | |
1763 | if(0xAA == wr_buf[0]) | |
1764 | { | |
1765 | GTP_ERROR("IC works abnormally,startup failed."); | |
1766 | return FAIL; | |
1767 | } | |
1768 | else | |
1769 | { | |
1770 | GTP_DEBUG("IC works normally,Startup success."); | |
1771 | wr_buf[0] = 0xAA; | |
1772 | i2c_write_bytes(client, 0x8041, wr_buf, 1); | |
1773 | return SUCCESS; | |
1774 | } | |
1775 | } | |
1776 | ||
1777 | ||
1778 | static void gtp_recovery_reset(struct i2c_client *client) | |
1779 | { | |
1780 | #if GTP_ESD_PROTECT | |
1781 | gtp_esd_switch(client, SWITCH_OFF); | |
1782 | #endif | |
1783 | force_reset_guitar(0); | |
1784 | #if GTP_ESD_PROTECT | |
1785 | gtp_esd_switch(client, SWITCH_ON); | |
1786 | #endif | |
1787 | } | |
1788 | ||
1789 | static u8 gtp_check_clk_legality(u8 *p_clk_buf) | |
1790 | { | |
1791 | u8 i = 0; | |
1792 | u8 clk_chksum = p_clk_buf[5]; | |
1793 | ||
1794 | for(i = 0; i < 5; i++) | |
1795 | { | |
1796 | if((p_clk_buf[i] < 50) || (p_clk_buf[i] > 120) || | |
1797 | (p_clk_buf[i] != p_clk_buf[0])) | |
1798 | { | |
1799 | break; | |
1800 | } | |
1801 | clk_chksum += p_clk_buf[i]; | |
1802 | } | |
1803 | ||
1804 | if((i == 5) && (clk_chksum == 0)) | |
1805 | { | |
1806 | GTP_DEBUG("Valid main clock data."); | |
1807 | return SUCCESS; | |
1808 | } | |
1809 | GTP_ERROR("Invalid main clock data."); | |
1810 | return FAIL; | |
1811 | } | |
1812 | ||
1813 | static u8 gtp_main_clk_proc(struct i2c_client *client) | |
1814 | { | |
1815 | s32 ret = 0; | |
1816 | u8 i = 0; | |
1817 | u8 clk_cal_result = 0; | |
1818 | u8 clk_chksum = 0; | |
1819 | u8 gtp_clk_buf[6] = {0}; | |
1820 | struct file *flp = NULL; | |
1821 | ||
4b9e9796 | 1822 | GTP_DEBUG("[gtp_main_clk_proc]Waiting for FS %d", gtp_clk_retries);/*[PLATFORM]-MOD by falin.luo@tcl.com 2015/4/29*/ |
979dc3df | 1823 | if (gup_check_fs_mounted("/cache") == FAIL)/*[PLATFORM]-MOD by falin.luo@tcl.com 2015/4/29*/ |
6fa3eb70 | 1824 | { |
979dc3df | 1825 | GTP_DEBUG("[gtp_main_clk_proc]/cache not mounted"); |
6fa3eb70 S |
1826 | if(gtp_clk_retries++ < GTP_CHK_FS_MNT_MAX) |
1827 | { | |
4b9e9796 | 1828 | msleep(100);/*[PLATFORM]-ADD by falin.luo@tcl.com 2015/4/29*/ |
6fa3eb70 S |
1829 | return FAIL; |
1830 | } | |
1831 | else | |
1832 | { | |
1833 | GTP_ERROR("[gtp_main_clk_proc]Wait for file system timeout,need cal clk"); | |
1834 | } | |
1835 | } | |
1836 | else | |
1837 | { | |
979dc3df | 1838 | GTP_DEBUG("[gtp_main_clk_proc]/cache mounted !!!!"); |
6fa3eb70 S |
1839 | flp = filp_open(GTP_MAIN_CLK_PATH, O_RDWR | O_CREAT, 0666); |
1840 | if (!IS_ERR(flp)) | |
1841 | { | |
1842 | flp->f_op->llseek(flp, 0, SEEK_SET); | |
1843 | ret = flp->f_op->read(flp, (char *)gtp_clk_buf, 6, &flp->f_pos); | |
1844 | if(ret > 0) | |
1845 | { | |
1846 | ret = gtp_check_clk_legality(gtp_clk_buf); | |
1847 | if(SUCCESS == ret) | |
1848 | { | |
1849 | GTP_DEBUG("[gtp_main_clk_proc]Open & read & check clk file success."); | |
1850 | goto send_main_clk; | |
1851 | } | |
1852 | } | |
1853 | } | |
1854 | GTP_ERROR("[gtp_main_clk_proc]Check clk file failed,need cal clk"); | |
1855 | } | |
1856 | ||
1857 | //cal clk | |
1858 | #if GTP_ESD_PROTECT | |
1859 | gtp_esd_switch(client, SWITCH_OFF); | |
1860 | #endif | |
1861 | clk_cal_result = gup_clk_calibration(); | |
1862 | force_reset_guitar(0); | |
1863 | GTP_DEBUG("&&&&&&&&&&clk cal result:%d", clk_cal_result); | |
1864 | ||
1865 | #if GTP_ESD_PROTECT | |
1866 | gtp_esd_switch(client, SWITCH_ON); | |
1867 | #endif | |
1868 | ||
1869 | if(clk_cal_result < 50 || clk_cal_result > 120) | |
1870 | { | |
1871 | GTP_ERROR("Invalid main clock: %d", clk_cal_result); | |
1872 | ret = FAIL; | |
1873 | goto exit_clk_proc; | |
1874 | } | |
1875 | ||
1876 | for(i = 0;i < 5; i++) | |
1877 | { | |
1878 | gtp_clk_buf[i] = clk_cal_result; | |
1879 | clk_chksum += gtp_clk_buf[i]; | |
1880 | } | |
1881 | gtp_clk_buf[5] = 0 - clk_chksum; | |
1882 | ||
1883 | send_main_clk: | |
1884 | ||
1885 | ret = i2c_write_bytes(client, 0x8020, gtp_clk_buf, 6); | |
1886 | ||
1887 | if (flp && !IS_ERR(flp)) | |
1888 | { | |
1889 | flp->f_op->llseek(flp, 0, SEEK_SET); | |
1890 | flp->f_op->write(flp, (char *)gtp_clk_buf, 6, &flp->f_pos); | |
1891 | } | |
1892 | ||
1893 | if(-1 == ret) | |
1894 | { | |
1895 | GTP_ERROR("[gtp_main_clk_proc]send main clk i2c error!"); | |
1896 | ret = FAIL; | |
1897 | } | |
1898 | else | |
1899 | { | |
1900 | ret = SUCCESS; | |
1901 | } | |
1902 | ||
1903 | exit_clk_proc: | |
1904 | if (flp && !IS_ERR(flp)) | |
1905 | { | |
1906 | filp_close(flp, NULL); | |
1907 | } | |
1908 | return ret; | |
1909 | } | |
1910 | ||
1911 | u8 gtp_verify_hopping_buf(struct i2c_client *client) | |
1912 | { | |
1913 | u16 checksum = 0; | |
1914 | s32 i = 0; | |
1915 | ||
1916 | for (i = 0; i < 6; i += 2) | |
1917 | { | |
1918 | checksum += (gtp_hopping_buf[i] << 8) + gtp_hopping_buf[i+1]; | |
1919 | } | |
1920 | if ((checksum + ((u16)(gtp_hopping_buf[6] << 8) + (u16)gtp_hopping_buf[7])) & 0xFFFF) | |
1921 | { | |
1922 | GTP_ERROR("Wrong checksum for hopping buffer, get hopping data from config instead!"); | |
1923 | goto get_config_hopping; | |
1924 | } | |
1925 | ||
1926 | for (i = 0; i < 8; i++) | |
1927 | { | |
1928 | if (gtp_hopping_buf[i] != gtp_hopping_buf[i+8]) | |
1929 | { | |
1930 | GTP_ERROR("Hopping buffer is not identical, get data from config instead!"); | |
1931 | goto get_config_hopping; | |
1932 | } | |
1933 | } | |
1934 | GTP_DEBUG("Hopping buffer is okay"); | |
1935 | return SUCCESS; | |
1936 | ||
1937 | get_config_hopping: | |
1938 | memcpy(gtp_hopping_buf, &config[2 + 0x8065 - GTP_REG_CONFIG_DATA], 4); | |
1939 | gtp_hopping_buf[4] = 0xAA; | |
1940 | gtp_hopping_buf[5] = 0x55; | |
1941 | ||
1942 | checksum = 0; | |
1943 | for (i = 0; i < 6; i += 2) | |
1944 | { | |
1945 | checksum += (gtp_hopping_buf[i] << 8) + gtp_hopping_buf[i+1]; | |
1946 | } | |
1947 | checksum = 0 - checksum; | |
1948 | gtp_hopping_buf[6] = (u8)(checksum >> 8); | |
1949 | gtp_hopping_buf[7] = (u8)(checksum & 0xFF); | |
1950 | ||
1951 | for (i = 0; i < 8; i++) | |
1952 | { | |
1953 | gtp_hopping_buf[i+8] = gtp_hopping_buf[i]; | |
1954 | } | |
1955 | return SUCCESS; | |
1956 | } | |
1957 | ||
1958 | u8 gtp_hopping_proc(struct i2c_client *client, s32 mode) | |
1959 | { | |
1960 | s32 ret = 0; | |
1961 | ||
979dc3df | 1962 | GTP_DEBUG("Store hopping data, wait for /cache mounted."); |
4b9e9796 | 1963 | /*[PLATFORM]-MOD-BEGIN by falin.luo@tcl.com 2015/4/29*/ |
979dc3df | 1964 | ret = gup_check_fs_mounted("/cache"); |
4b9e9796 | 1965 | /*[PLATFORM]-MOD-END by falin.luo@tcl.com 2015/4/29*/ |
6fa3eb70 S |
1966 | |
1967 | if (FAIL == ret) | |
1968 | { | |
979dc3df | 1969 | GTP_DEBUG("/cache not mounted."); |
6fa3eb70 S |
1970 | return FAIL; |
1971 | } | |
979dc3df | 1972 | GTP_DEBUG("/cache Mounted!"); |
6fa3eb70 S |
1973 | |
1974 | if (GTP_HOPPING_SEND == mode) | |
1975 | { | |
1976 | gtp_verify_hopping_buf(client); | |
1977 | ||
1978 | ret = i2c_write_bytes(client, 0x8030, gtp_hopping_buf, 16); | |
1979 | if (ret < 0) | |
1980 | { | |
1981 | return FAIL; | |
1982 | } | |
1983 | else | |
1984 | { | |
1985 | return SUCCESS; | |
1986 | } | |
1987 | } | |
1988 | else | |
1989 | { | |
1990 | ret = i2c_read_bytes(client, 0x8030, gtp_hopping_buf, 16); | |
1991 | ||
1992 | if (ret < 0) | |
1993 | { | |
1994 | GTP_ERROR("Failed to read hopping data from hopping buffer, get from config instead."); | |
1995 | return FAIL; | |
1996 | } | |
1997 | return gtp_verify_hopping_buf(client); | |
1998 | } | |
1999 | } | |
2000 | ||
2001 | #if GTP_FL_LITTLE_SYSTEM | |
2002 | s32 gtp_resume_timeout(void *none) | |
2003 | { | |
2004 | s32 timeout = 0; | |
2005 | GTP_DEBUG("Resume timeout thread kicks off."); | |
2006 | ||
2007 | while (timeout++ < (10 * 10)) | |
2008 | { | |
2009 | msleep(100); | |
2010 | if (!little_fw_mode) | |
2011 | { | |
2012 | GTP_DEBUG("Resume timeout thread terminated while counting."); | |
2013 | return 0; | |
2014 | } | |
2015 | } | |
2016 | ||
2017 | if (little_fw_mode) | |
2018 | { | |
2019 | GTP_INFO("Download big ss51 firmware timeout, process esd reset."); | |
2020 | little_fw_mode = 0; | |
2021 | gtp_recovery_reset(i2c_client_point); | |
2022 | } | |
2023 | ||
2024 | return 0; | |
2025 | } | |
2026 | ||
2027 | u8 gtp_get_state1(struct i2c_client *client) | |
2028 | { | |
2029 | u8 state1 = 0; | |
2030 | s32 ret = 0; | |
2031 | ||
2032 | ret = i2c_read_bytes(client, GTP_REG_STATE1, &state1, 1); | |
2033 | ||
2034 | if (ret < 0) | |
2035 | { | |
2036 | GTP_ERROR("Failed to get state1!"); | |
2037 | return 0xFF; | |
2038 | } | |
2039 | return state1; | |
2040 | } | |
2041 | ||
2042 | u8 gtp_get_state2(struct i2c_client *client) | |
2043 | { | |
2044 | u8 state2 = 0; | |
2045 | s32 ret = 0; | |
2046 | ||
2047 | ret = i2c_read_bytes(client, GTP_REG_STATE2, &state2, 1); | |
2048 | ||
2049 | if (ret < 0) | |
2050 | { | |
2051 | GTP_ERROR("Failed to get state2!"); | |
2052 | return 0xFF; | |
2053 | } | |
2054 | return state2; | |
2055 | } | |
2056 | ||
2057 | // size: k in unit | |
2058 | u8 gtp_send_check_info(struct i2c_client *client, u16 fw_chksum) | |
2059 | { | |
2060 | s32 ret = 0; | |
2061 | u8 checksum = 0; | |
2062 | u8 bank = 0; | |
2063 | u8 state1 = 0x00; | |
2064 | u8 state2 = 0x00; | |
2065 | u16 start_addr = 0x0000; | |
2066 | u8 checkinfo_buf[10] = {0}; | |
2067 | ||
2068 | ||
2069 | switch (fw_block) | |
2070 | { | |
2071 | case 1: | |
2072 | case 2: | |
2073 | case 3: | |
2074 | case 4: | |
2075 | case 5: | |
2076 | case 6: | |
2077 | case 7: | |
2078 | case 8: | |
2079 | bank = 0x01; | |
2080 | state1 = BUFFER_FULL; | |
2081 | state2 = IS_A_SEG; | |
2082 | start_addr = (0xC000 + (fw_block - 1) * 1024 * 2); | |
2083 | break; | |
2084 | ||
2085 | case 9: | |
2086 | bank = 0x00; | |
2087 | state1 = BUFFER_FULL; | |
2088 | state2 = IS_A_SEG; | |
2089 | start_addr = 0xF800; | |
2090 | break; | |
2091 | ||
2092 | case 10: | |
2093 | bank = 0x00; | |
2094 | state1 = BUFFER_FULL; | |
2095 | state2 = IS_A_SEG; | |
2096 | start_addr = 0xF000; | |
2097 | break; | |
2098 | ||
2099 | case 11: | |
2100 | bank = 0x00; | |
2101 | state1 = BUFFER_FULL; | |
2102 | state2 = IS_B_SEG_FIRST; | |
2103 | start_addr = 0xE800; | |
2104 | break; | |
2105 | ||
2106 | case 12: | |
2107 | bank = 0x00; | |
2108 | state1 = WAIT_CHECK; | |
2109 | state2 = IS_B_SEG_LAST; | |
2110 | start_addr = 0xC000; | |
2111 | break; | |
2112 | ||
2113 | default: | |
2114 | GTP_ERROR("Invalid firmware block(%d) for checkinfo.", fw_block); | |
2115 | return FAIL; | |
2116 | } | |
2117 | ||
2118 | checkinfo_buf[3] = bank; | |
2119 | checkinfo_buf[4] = (u8)(start_addr >> 8); | |
2120 | checkinfo_buf[5] = (u8)(start_addr & 0xFF); | |
2121 | checkinfo_buf[7] = state2; | |
2122 | checkinfo_buf[8] = state1; | |
2123 | ||
2124 | GTP_DEBUG("fw_block: %d, fw_chksum: 0x%04X", fw_block, fw_chksum); | |
2125 | if (fw_block == 12) | |
2126 | { | |
2127 | checkinfo_buf[6] = 80; | |
2128 | } | |
2129 | else | |
2130 | { | |
2131 | checkinfo_buf[6] = 16; | |
2132 | } | |
2133 | ||
2134 | checkinfo_buf[0] = (u8)(fw_chksum >> 8); | |
2135 | checkinfo_buf[1] = (u8)(fw_chksum & 0xFF); | |
2136 | ||
2137 | checksum = 0; | |
2138 | for (ret = 0; ret < 6; ret++) | |
2139 | { | |
2140 | checksum += checkinfo_buf[3 + ret]; | |
2141 | } | |
2142 | checkinfo_buf[2] = 1 - checksum; | |
2143 | ||
2144 | ret = i2c_write_bytes(client, GTP_REG_CHECKINFO, checkinfo_buf, 9); | |
2145 | if (ret < 0) | |
2146 | { | |
2147 | GTP_ERROR("Failed to send checkinfo!"); | |
2148 | return FAIL; | |
2149 | } | |
2150 | else | |
2151 | { | |
2152 | GTP_DEBUG("Send checkinfo successfully!"); | |
2153 | } | |
2154 | return SUCCESS; | |
2155 | } | |
2156 | ||
2157 | ||
2158 | ||
2159 | u8 gtp_resume_fw_startup(struct i2c_client *client) | |
2160 | { | |
2161 | u8 buf; | |
2162 | u32 retry = 0; | |
2163 | s32 ret = 0; | |
2164 | ||
2165 | GTP_INFO("Big ss51 firmware startup."); | |
2166 | ||
2167 | while (retry++ < 10) | |
2168 | { | |
2169 | buf = 0x0C; | |
2170 | ret = i2c_write_bytes(client, 0x4180, &buf, 1); // hold ss51 & dsp | |
2171 | if (ret < 0) | |
2172 | { | |
2173 | GTP_ERROR("Failed to hold ss51 & dsp."); | |
2174 | return FAIL; | |
2175 | } | |
2176 | ||
2177 | buf = 0x00; | |
2178 | ret = i2c_read_bytes(client, 0x4180, &buf, 1); | |
2179 | if (ret < 0) | |
2180 | { | |
2181 | GTP_ERROR("Failed to get hold ss51 & dsp status."); | |
2182 | return FAIL; | |
2183 | } | |
2184 | ||
2185 | if (buf == 0x0C) | |
2186 | { | |
2187 | GTP_DEBUG("SS51 & Dsp confirm hold!"); | |
2188 | break; | |
2189 | } | |
2190 | } | |
2191 | ||
2192 | if (retry >= 10) | |
2193 | { | |
2194 | GTP_ERROR("Hold ss51 & dsp retry exhausted."); | |
2195 | return FAIL; | |
2196 | } | |
2197 | ||
2198 | buf = 0x03; | |
2199 | i2c_write_bytes(client, 0x4048, &buf, 1); // select bank3 | |
2200 | ||
2201 | buf = 0x00; | |
2202 | i2c_write_bytes(client, 0x4049, &buf, 1); | |
2203 | ||
2204 | return gtp_fw_startup(client); | |
2205 | } | |
2206 | ||
2207 | u8 gtp_download_seg_b(struct i2c_client *client) | |
2208 | { | |
2209 | s32 ret = 0; | |
2210 | u16 fw_chksum = 0; | |
2211 | u8 state1 = 0; | |
2212 | ||
2213 | if (block_section != 10) | |
2214 | { | |
2215 | state1 = 0x00; | |
2216 | i2c_write_bytes(client, 0x4048, &state1, 1); // select bank0 | |
2217 | ||
2218 | ret = gup_burn_ss51_seg_b(client, 10, &fw_chksum); | |
2219 | ||
2220 | if (FAIL == ret) | |
2221 | { | |
2222 | GTP_ERROR("Failed to burn ss51 seg B, process reburn."); | |
2223 | return FAIL; | |
2224 | } | |
2225 | ||
2226 | ret = gtp_send_check_info(i2c_client_point, fw_chksum); | |
2227 | if (FAIL == ret) | |
2228 | { | |
2229 | GTP_ERROR("Send checkinfo failed, process resend."); | |
2230 | return FAIL; | |
2231 | } | |
2232 | } | |
2233 | msleep(1); | |
2234 | ||
2235 | state1 = gtp_get_state1(client); | |
2236 | ||
2237 | if (CHECK_COMPLETE == state1) | |
2238 | { | |
2239 | GTP_INFO("Burn ss51 Block12 successfully"); | |
2240 | } | |
2241 | else if (CHECK_ERROR == state1) | |
2242 | { | |
2243 | GTP_DEBUG("Big SS51 Seg B check error, process reburn!"); | |
2244 | return FAIL; | |
2245 | } | |
2246 | else | |
2247 | { | |
2248 | GTP_ERROR("Big SS51 Seg B check imcomplete(state1:%s), process recheck.", symbolic_state1[state1&0x07]); | |
2249 | block_section = 10; | |
2250 | return FAIL; | |
2251 | } | |
2252 | ret = gtp_resume_fw_startup(client); | |
2253 | ||
2254 | little_fw_mode = 0; | |
2255 | if (FAIL == ret) | |
2256 | { | |
2257 | GTP_ERROR("Big ss51 firmware startup failed, process esd reset."); | |
2258 | if (!tpd_halt) | |
2259 | { | |
2260 | gtp_recovery_reset(i2c_client_point); | |
2261 | } | |
2262 | } | |
2263 | else | |
2264 | { | |
2265 | GTP_INFO("Switch to big ss51 firmware successfully!"); | |
2266 | } | |
2267 | #if GTP_ESD_PROTECT | |
2268 | if (!tpd_halt) | |
2269 | { | |
2270 | gtp_esd_switch(client, SWITCH_ON); | |
2271 | } | |
2272 | #endif | |
2273 | return SUCCESS; | |
2274 | } | |
2275 | ||
2276 | ||
2277 | u8 gtp_download_big_ss51(struct i2c_client *client) | |
2278 | { | |
2279 | u8 state1, state2; | |
2280 | s32 ret = 0; | |
2281 | s32 i = 0; | |
2282 | static u16 fw_chksum = 0x0000; | |
2283 | ||
2284 | //GTP_DEBUG("Block: %d, Block Section: %d", fw_block, block_section); | |
2285 | if (!little_fw_mode) | |
2286 | { | |
2287 | GTP_ERROR("Download big ss51 timeout!"); | |
2288 | return FAIL; | |
2289 | } | |
2290 | ||
2291 | if (block_section == 10) // one firmware block burned | |
2292 | { | |
2293 | if (fw_block == 11) | |
2294 | { | |
2295 | mdelay(3); | |
2296 | } | |
2297 | ||
2298 | state1 = gtp_get_state1(i2c_client_point); | |
2299 | state2 = gtp_get_state2(i2c_client_point); | |
2300 | ||
2301 | GTP_DEBUG("state1: %02X (%s), state2: %02X (%s)", state1, symbolic_state1[state1&0x07], state2, symbolic_state2[state2&0x07]); | |
2302 | ||
2303 | if (CHECK_COMPLETE == state1) | |
2304 | { | |
2305 | block_section = 1; | |
2306 | GTP_DEBUG("Burn ss51 Block%d successfully!", fw_block); | |
2307 | if (fw_block == 11) | |
2308 | { | |
2309 | #if GTP_ESD_PROTECT | |
2310 | gtp_esd_switch(client, SWITCH_OFF); | |
2311 | #endif | |
2312 | tpd_up(0, 0, 0); // release all | |
2313 | input_sync(tpd->dev); | |
2314 | GTP_DEBUG("Release touch manually."); | |
2315 | fw_block = 12; | |
2316 | for (i = 0; i < 5; i++) | |
2317 | { | |
2318 | if (!little_fw_mode || (fw_block != 12)) | |
2319 | { | |
2320 | GTP_ERROR("Download big ss51 timeout!"); | |
2321 | return FAIL; | |
2322 | } | |
2323 | ret = gtp_download_seg_b(client); | |
2324 | ||
2325 | if (SUCCESS == ret) | |
2326 | { | |
2327 | break; | |
2328 | } | |
2329 | } | |
2330 | return SUCCESS; | |
2331 | } | |
2332 | } | |
2333 | else if (CHECK_ERROR == state1) | |
2334 | { | |
2335 | GTP_ERROR("Block%d check error, process reburn.", fw_block); | |
2336 | block_section = 1; | |
2337 | fw_block--; | |
2338 | } | |
2339 | else | |
2340 | { | |
2341 | GTP_DEBUG("Block%d check incomplete, process recheck.", fw_block); | |
2342 | block_section = 10; | |
2343 | } | |
2344 | } | |
2345 | if (block_section < 9) | |
2346 | { | |
2347 | ret = gup_burn_ss51_block(i2c_client_point, block_section, fw_block+1, &fw_chksum); | |
2348 | if (FAIL == ret) | |
2349 | { | |
2350 | GTP_ERROR("Burn block%d section%d failed, reburn block%d", fw_block+1, block_section, fw_block+1); | |
2351 | } | |
2352 | else | |
2353 | { | |
2354 | block_section++; | |
2355 | } | |
2356 | if (block_section == 9) // one firmware block downloaded | |
2357 | { | |
2358 | fw_block++; | |
2359 | block_section = 10; | |
2360 | ret = gtp_send_check_info(i2c_client_point, fw_chksum); | |
2361 | } | |
2362 | } | |
2363 | return ret; | |
2364 | } | |
2365 | #endif | |
2366 | ||
2367 | #endif | |
2368 | //************* For GT9XXF End **********************// | |
2369 | ||
2370 | #if GTP_WITH_PEN | |
2371 | static void gtp_pen_init(void) | |
2372 | { | |
2373 | s32 ret = 0; | |
2374 | ||
2375 | pen_dev = input_allocate_device(); | |
2376 | if (pen_dev == NULL) | |
2377 | { | |
2378 | GTP_ERROR("Failed to allocate input device for pen/stylus."); | |
2379 | return; | |
2380 | } | |
2381 | ||
2382 | pen_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ; | |
2383 | pen_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); | |
2384 | ||
2385 | set_bit(BTN_TOOL_PEN, pen_dev->keybit); | |
2386 | set_bit(INPUT_PROP_DIRECT, pen_dev->propbit); | |
2387 | //set_bit(INPUT_PROP_POINTER, pen_dev->propbit); | |
2388 | ||
2389 | #if GTP_PEN_HAVE_BUTTON | |
2390 | input_set_capability(pen_dev, EV_KEY, BTN_STYLUS); | |
2391 | input_set_capability(pen_dev, EV_KEY, BTN_STYLUS2); | |
2392 | #endif | |
2393 | ||
2394 | input_set_abs_params(pen_dev, ABS_MT_POSITION_X, 0, TPD_RES_X, 0, 0); | |
2395 | input_set_abs_params(pen_dev, ABS_MT_POSITION_Y, 0, TPD_RES_Y, 0, 0); | |
2396 | input_set_abs_params(pen_dev, ABS_MT_PRESSURE, 0, 255, 0, 0); | |
2397 | input_set_abs_params(pen_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); | |
2398 | input_set_abs_params(pen_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0); | |
2399 | ||
2400 | pen_dev->name = "mtk-pen"; | |
2401 | pen_dev->phys = "input/ts"; | |
2402 | pen_dev->id.bustype = BUS_I2C; | |
2403 | ||
2404 | ret = input_register_device(pen_dev); | |
2405 | if (ret) | |
2406 | { | |
2407 | GTP_ERROR("Register %s input device failed", pen_dev->name); | |
2408 | return; | |
2409 | } | |
2410 | } | |
2411 | ||
2412 | static void gtp_pen_down(s32 x, s32 y, s32 size, s32 id) | |
2413 | { | |
2414 | input_report_key(pen_dev, BTN_TOOL_PEN, 1); | |
2415 | input_report_key(pen_dev, BTN_TOUCH, 1); | |
2416 | input_report_abs(pen_dev, ABS_MT_POSITION_X, x); | |
2417 | input_report_abs(pen_dev, ABS_MT_POSITION_Y, y); | |
2418 | if ((!size) && (!id)) | |
2419 | { | |
2420 | input_report_abs(pen_dev, ABS_MT_PRESSURE, 100); | |
2421 | input_report_abs(pen_dev, ABS_MT_TOUCH_MAJOR, 100); | |
2422 | } | |
2423 | else | |
2424 | { | |
2425 | input_report_abs(pen_dev, ABS_MT_PRESSURE, size); | |
2426 | input_report_abs(pen_dev, ABS_MT_TOUCH_MAJOR, size); | |
2427 | input_report_abs(pen_dev, ABS_MT_TRACKING_ID, id); | |
2428 | } | |
2429 | input_mt_sync(pen_dev); | |
2430 | } | |
2431 | ||
2432 | static void gtp_pen_up(void) | |
2433 | { | |
2434 | input_report_key(pen_dev, BTN_TOOL_PEN, 0); | |
2435 | input_report_key(pen_dev, BTN_TOUCH, 0); | |
2436 | } | |
2437 | #endif | |
2438 | ||
2439 | ||
2440 | static s32 tpd_i2c_probe_next(struct i2c_client *client) | |
2441 | { | |
2442 | s32 err = 0; | |
2443 | s32 ret = 0; | |
2444 | ||
2445 | u16 version_info; | |
2446 | ||
2447 | ||
2448 | ret = tpd_power_on(client); | |
2449 | ||
2450 | if (ret < 0) | |
2451 | { | |
2452 | GTP_ERROR("I2C communication ERROR!"); | |
2453 | } | |
2454 | ||
2455 | ret = gtp_read_version(client, &version_info); | |
2456 | ||
2457 | if (ret < 0) | |
2458 | { | |
2459 | GTP_ERROR("Read version failed."); | |
2460 | } | |
2461 | ||
2462 | ret = gtp_init_panel(client); | |
2463 | ||
2464 | if (ret < 0) | |
2465 | { | |
2466 | GTP_ERROR("GTP init panel failed."); | |
2467 | } | |
2468 | ||
2469 | #if GTP_CREATE_WR_NODE | |
2470 | init_wr_node(client); | |
2471 | #endif | |
2472 | thread = kthread_run(touch_event_handler, 0, TPD_DEVICE); | |
2473 | ||
2474 | ||
2475 | if (IS_ERR(thread)) | |
2476 | { | |
2477 | err = PTR_ERR(thread); | |
2478 | GTP_ERROR(TPD_DEVICE " failed to create kernel thread: %d\n", err); | |
2479 | } | |
2480 | ||
2481 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
2482 | ||
2483 | #if GTP_AUTO_UPDATE | |
2484 | ret = gup_init_update_proc(client); | |
2485 | ||
2486 | if (ret < 0) | |
2487 | { | |
2488 | GTP_ERROR("Create update thread error."); | |
2489 | } | |
2490 | #endif | |
2491 | ||
2492 | #if GTP_ESD_PROTECT | |
2493 | gtp_esd_switch(client, SWITCH_ON); | |
2494 | #endif | |
2495 | ||
2496 | ||
2497 | return 0; | |
2498 | } | |
2499 | ||
2500 | static ssize_t cfg_load_enable_store(struct device *dev, | |
2501 | struct device_attribute *attr, | |
2502 | const char *buf, size_t count) | |
2503 | { | |
2504 | tpd_i2c_probe_next(i2c_client_point); | |
2505 | return count; | |
2506 | } | |
2507 | static ssize_t cfg_load_enable_show(struct device *dev, | |
4b9e9796 S |
2508 | struct device_attribute *attr, |
2509 | char *buf) | |
2510 | { | |
2511 | return 1; | |
2512 | } | |
2513 | static DEVICE_ATTR(cfg_load_enable, S_IRUGO|S_IWUSR, cfg_load_enable_show, cfg_load_enable_store); | |
2514 | ||
2515 | /*[PLATFORM]-Add-BEGIN by falin.luo@tcl.com 2015/4/29*/ | |
2516 | /*sys interface to get and set the data partition mount status*/ | |
2517 | #ifdef GTP_COMPATIBLE_MODE | |
2518 | ||
2519 | static ssize_t data_is_mount_store(struct device *dev, | |
6fa3eb70 S |
2520 | struct device_attribute *attr, |
2521 | const char *buf, size_t count) | |
2522 | { | |
4b9e9796 S |
2523 | GTP_INFO("enter %s", __func__); |
2524 | ||
2525 | ||
2526 | is_data_mounted = ((buf[0] == '1') ? 1 : 0); | |
2527 | ||
2528 | GTP_INFO("is_data_mount = %d, buf = %s", is_data_mounted, buf); | |
2529 | ||
6fa3eb70 S |
2530 | return count; |
2531 | } | |
4b9e9796 S |
2532 | static ssize_t data_is_mount_show(struct device *dev, |
2533 | struct device_attribute *attr, | |
2534 | char *buf) | |
2535 | { | |
2536 | return snprintf(buf, PAGE_SIZE, "is_data_mounted = %d\n", is_data_mounted); | |
2537 | } | |
2538 | ||
2539 | static DEVICE_ATTR(data_is_mount, 0644, data_is_mount_show, data_is_mount_store); | |
2540 | ||
2541 | #endif | |
2542 | ||
2543 | /*[PLATFORM]-Add-END by falin.luo@tcl.com 2015/4/29*/ | |
2544 | ||
6fa3eb70 S |
2545 | |
2546 | static struct miscdevice cfg_misc_device = | |
2547 | { | |
2548 | .minor = MISC_DYNAMIC_MINOR, | |
2549 | .name = "tp_cfg", | |
2550 | // .fops = &tpd_fops, | |
2551 | }; | |
2552 | ||
2553 | #if 0 | |
2554 | static void buttons_timer_function(unsigned long data) | |
2555 | { | |
2556 | printk(KERN_ERR"caoyang1\n"); | |
2557 | input_report_key(tpd->dev, KEY_POWER, 1); | |
2558 | input_sync(tpd->dev); | |
2559 | input_report_key(tpd->dev, KEY_POWER, 0); | |
2560 | input_sync(tpd->dev); | |
2561 | tpd_sleep_flag = 1; | |
2562 | ||
2563 | } | |
2564 | #endif | |
2565 | ||
2566 | static s32 tpd_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) | |
2567 | { | |
2568 | s32 err = 0; | |
4b9e9796 | 2569 | #if 0 |
6fa3eb70 | 2570 | s32 ret = 0; |
6fa3eb70 | 2571 | u16 version_info; |
4b9e9796 | 2572 | #endif |
6fa3eb70 S |
2573 | #if GTP_HAVE_TOUCH_KEY |
2574 | s32 idx = 0; | |
2575 | #endif | |
2576 | #ifdef TPD_PROXIMITY | |
2577 | struct hwmsen_object obj_ps; | |
2578 | #endif | |
2579 | ||
2580 | i2c_client_point = client; | |
2581 | //add by caoyang for ·À¶¶ | |
2582 | //do not use the timer because it cause bug | |
2583 | #if 0 | |
2584 | init_timer(&buttons_timer); | |
2585 | buttons_timer.function = buttons_timer_function; | |
2586 | add_timer(&buttons_timer); | |
2587 | #endif | |
2588 | #if 0 | |
2589 | ret = tpd_power_on(client); | |
2590 | ||
2591 | if (ret < 0) | |
2592 | { | |
2593 | GTP_ERROR("I2C communication ERROR!"); | |
2594 | } | |
2595 | #endif | |
2596 | #ifdef VELOCITY_CUSTOM | |
2597 | ||
2598 | if ((err = misc_register(&tpd_misc_device))) | |
2599 | { | |
2600 | printk("mtk_tpd: tpd_misc_device register failed\n"); | |
2601 | } | |
2602 | ||
2603 | #endif | |
2604 | #if 0 | |
2605 | ret = gtp_read_version(client, &version_info); | |
2606 | ||
2607 | if (ret < 0) | |
2608 | { | |
2609 | GTP_ERROR("Read version failed."); | |
2610 | } | |
2611 | ||
2612 | ret = gtp_init_panel(client); | |
2613 | ||
2614 | if (ret < 0) | |
2615 | { | |
2616 | GTP_ERROR("GTP init panel failed."); | |
2617 | } | |
2618 | #endif | |
2619 | // Create proc file system | |
2620 | gt91xx_config_proc = proc_create(GT91XX_CONFIG_PROC_FILE, 0666, NULL, &config_proc_ops); | |
2621 | if (gt91xx_config_proc == NULL) | |
2622 | { | |
2623 | GTP_ERROR("create_proc_entry %s failed\n", GT91XX_CONFIG_PROC_FILE); | |
2624 | } | |
2625 | else | |
2626 | { | |
2627 | GTP_INFO("create proc entry %s success", GT91XX_CONFIG_PROC_FILE); | |
2628 | } | |
2629 | #if 0 | |
2630 | #if GTP_CREATE_WR_NODE | |
2631 | init_wr_node(client); | |
2632 | #endif | |
2633 | ||
2634 | thread = kthread_run(touch_event_handler, 0, TPD_DEVICE); | |
2635 | ||
2636 | ||
2637 | if (IS_ERR(thread)) | |
2638 | { | |
2639 | err = PTR_ERR(thread); | |
2640 | GTP_ERROR(TPD_DEVICE " failed to create kernel thread: %d\n", err); | |
2641 | } | |
2642 | #endif | |
2643 | ||
2644 | ||
2645 | #if GTP_HAVE_TOUCH_KEY | |
2646 | ||
2647 | for (idx = 0; idx < GTP_MAX_KEY_NUM; idx++) | |
2648 | { | |
2649 | input_set_capability(tpd->dev, EV_KEY, touch_key_array[idx]); | |
2650 | } | |
2651 | ||
2652 | #endif | |
2653 | input_set_capability(tpd->dev, EV_KEY, KEY_POWER); | |
2654 | ||
2655 | #if GTP_WITH_PEN | |
2656 | gtp_pen_init(); | |
2657 | #endif | |
2658 | // set INT mode | |
2659 | mt_set_gpio_mode(GPIO_CTP_EINT_PIN, GPIO_CTP_EINT_PIN_M_EINT); | |
2660 | mt_set_gpio_dir(GPIO_CTP_EINT_PIN, GPIO_DIR_IN); | |
2661 | mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN, GPIO_PULL_DISABLE); | |
2662 | ||
2663 | msleep(50); | |
2664 | ||
2665 | #if 1 | |
2666 | if (!int_type) //EINTF_TRIGGER | |
2667 | { | |
2668 | mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, EINTF_TRIGGER_RISING, tpd_eint_interrupt_handler, 1); | |
2669 | } | |
2670 | else | |
2671 | { | |
2672 | mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, EINTF_TRIGGER_FALLING, tpd_eint_interrupt_handler, 1); | |
2673 | } | |
2674 | ||
2675 | #endif | |
2676 | ||
2677 | #if 0 | |
2678 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
2679 | ||
2680 | #if GTP_AUTO_UPDATE | |
2681 | ret = gup_init_update_proc(client); | |
2682 | ||
2683 | if (ret < 0) | |
2684 | { | |
2685 | GTP_ERROR("Create update thread error."); | |
2686 | } | |
2687 | #endif | |
2688 | #endif | |
2689 | #ifdef TPD_PROXIMITY | |
2690 | //obj_ps.self = cm3623_obj; | |
2691 | obj_ps.polling = 0; //0--interrupt mode;1--polling mode; | |
2692 | obj_ps.sensor_operate = tpd_ps_operate; | |
2693 | ||
2694 | if ((err = hwmsen_attach(ID_PROXIMITY, &obj_ps))) | |
2695 | { | |
2696 | GTP_ERROR("hwmsen attach fail, return:%d.", err); | |
2697 | } | |
2698 | ||
2699 | #endif | |
2700 | #if 0 | |
2701 | #if GTP_ESD_PROTECT | |
2702 | gtp_esd_switch(client, SWITCH_ON); | |
2703 | #endif | |
2704 | ||
2705 | tpd_load_status = 1; | |
2706 | #endif | |
2707 | misc_register(&cfg_misc_device); | |
4b9e9796 S |
2708 | /*[PLATFORM]-Add-BEGIN by falin.luo@tcl.com 2015/4/29*/ |
2709 | #ifdef GTP_COMPATIBLE_MODE | |
2710 | device_create_file(cfg_misc_device.this_device, &dev_attr_data_is_mount); | |
2711 | #endif | |
2712 | /*[PLATFORM]-Add-END by falin.luo@tcl.com 2015/4/29*/ | |
2713 | ||
6fa3eb70 S |
2714 | device_create_file(cfg_misc_device.this_device, &dev_attr_cfg_load_enable); |
2715 | tpd_load_status = 1; | |
2716 | return 0; | |
2717 | } | |
2718 | ||
2719 | ||
2720 | static void tpd_eint_interrupt_handler(void) | |
2721 | { | |
2722 | TPD_DEBUG_PRINT_INT; | |
2723 | ||
2724 | tpd_flag = 1; | |
2725 | ||
2726 | wake_up_interruptible(&waiter); | |
2727 | } | |
2728 | static int tpd_i2c_remove(struct i2c_client *client) | |
2729 | { | |
2730 | #if GTP_CREATE_WR_NODE | |
2731 | uninit_wr_node(); | |
2732 | #endif | |
2733 | ||
2734 | #if GTP_ESD_PROTECT | |
2735 | destroy_workqueue(gtp_esd_check_workqueue); | |
2736 | #endif | |
2737 | ||
2738 | return 0; | |
2739 | } | |
2740 | #if (GTP_ESD_PROTECT || GTP_COMPATIBLE_MODE) | |
2741 | static s32 force_reset_guitar(s32 resume) | |
2742 | { | |
2743 | s32 i = 0; | |
2744 | s32 ret = 0; | |
2745 | ||
2746 | if (!resume) | |
2747 | { | |
2748 | GTP_INFO("Force_reset_guitar"); | |
2749 | } | |
2750 | else | |
2751 | { | |
2752 | GTP_INFO("Download little system."); | |
2753 | } | |
2754 | ||
2755 | mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM); | |
2756 | ||
2757 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); | |
2758 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); | |
2759 | #ifdef MT6573 | |
2760 | //Power off TP | |
2761 | mt_set_gpio_mode(GPIO_CTP_EN_PIN, GPIO_CTP_EN_PIN_M_GPIO); | |
2762 | mt_set_gpio_dir(GPIO_CTP_EN_PIN, GPIO_DIR_OUT); | |
2763 | mt_set_gpio_out(GPIO_CTP_EN_PIN, GPIO_OUT_ZERO); | |
2764 | msleep(30); | |
2765 | //Power on TP | |
2766 | mt_set_gpio_out(GPIO_CTP_EN_PIN, GPIO_OUT_ONE); | |
2767 | msleep(30); | |
2768 | #else // ( defined(MT6575) || defined(MT6577) || defined(MT6589) ) | |
2769 | // Power off TP | |
2770 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
2771 | hwPowerDown(TPD_POWER_SOURCE_CUSTOM, "TP"); | |
2772 | #else | |
2773 | hwPowerDown(MT65XX_POWER_LDO_VGP2, "TP"); | |
2774 | #endif | |
2775 | msleep(30); | |
2776 | ||
2777 | // Power on TP | |
2778 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
2779 | hwPowerOn(TPD_POWER_SOURCE_CUSTOM, VOL_2800, "TP"); | |
2780 | #else | |
2781 | hwPowerOn(MT65XX_POWER_LDO_VGP2, VOL_2800, "TP"); | |
2782 | #endif | |
2783 | msleep(30); | |
2784 | ||
2785 | #endif | |
2786 | ||
2787 | for (i = 0; i < 5; i++) | |
2788 | { | |
2789 | #if GTP_COMPATIBLE_MODE | |
2790 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
2791 | { | |
2792 | #if GTP_FL_LITTLE_SYSTEM | |
2793 | //check code ram | |
2794 | if (resume) // poweroff resume | |
2795 | { | |
2796 | ret = gup_fw_download_proc(NULL, GTP_FL_PWR_RESUME_BURN); | |
2797 | if (FAIL == ret) | |
2798 | { | |
2799 | GTP_ERROR("Failed to download little system."); | |
2800 | continue; | |
2801 | } | |
2802 | } | |
2803 | else | |
2804 | #endif | |
2805 | { | |
2806 | ret = gup_fw_download_proc(NULL, GTP_FL_ESD_RECOVERY); | |
2807 | } | |
2808 | if(FAIL == ret) | |
2809 | { | |
2810 | GTP_ERROR("[force_reset_guitar]Check & repair fw failed."); | |
2811 | continue; | |
2812 | } | |
2813 | //startup fw | |
2814 | ret = gtp_fw_startup(i2c_client_point); | |
2815 | if(FAIL == ret) | |
2816 | { | |
2817 | if (resume) | |
2818 | { | |
2819 | GTP_ERROR("Failed to startup little system."); | |
2820 | } | |
2821 | else | |
2822 | { | |
2823 | GTP_ERROR("GT9XXF start up failed."); | |
2824 | } | |
2825 | continue; | |
2826 | } | |
2827 | break; | |
2828 | } | |
2829 | else | |
2830 | #endif | |
2831 | { | |
2832 | //Reset Guitar | |
2833 | gtp_reset_guitar(i2c_client_point, 20); | |
2834 | msleep(50); | |
2835 | //Send config | |
2836 | ret = gtp_send_cfg(i2c_client_point); | |
2837 | ||
2838 | if (ret < 0) | |
2839 | { | |
2840 | continue; | |
2841 | } | |
2842 | } | |
2843 | break; | |
2844 | } | |
2845 | ||
2846 | if (i >= 5) | |
2847 | { | |
2848 | if (resume) | |
2849 | { | |
2850 | GTP_ERROR("Failed to download little system."); | |
2851 | } | |
2852 | else | |
2853 | { | |
2854 | GTP_ERROR("Failed to reset guitar."); | |
2855 | } | |
2856 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
2857 | return FAIL; | |
2858 | } | |
2859 | #if (GTP_COMPATIBLE_MODE && GTP_FL_LITTLE_SYSTEM) | |
2860 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
2861 | { | |
2862 | if (resume) | |
2863 | { | |
2864 | little_fw_mode = 1; | |
2865 | fw_block = 0; | |
2866 | block_section = 1; | |
2867 | ||
2868 | msleep(1); | |
2869 | gtp_main_clk_proc(i2c_client_point); | |
2870 | gtp_hopping_proc(i2c_client_point, GTP_HOPPING_SEND); | |
2871 | gtp_bak_ref_proc(i2c_client_point, GTP_BAK_REF_SEND); | |
2872 | } | |
2873 | else | |
2874 | { | |
2875 | little_fw_mode = 0; | |
2876 | fw_block = 0; | |
2877 | block_section = 0; | |
2878 | } | |
2879 | } | |
2880 | #endif | |
2881 | ||
2882 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
2883 | return SUCCESS; | |
2884 | } | |
2885 | #endif | |
2886 | ||
2887 | #if GTP_ESD_PROTECT | |
2888 | static s32 gtp_init_ext_watchdog(struct i2c_client *client) | |
2889 | { | |
2890 | u8 opr_buffer[2] = {0xAA}; | |
2891 | GTP_DEBUG("Init external watchdog."); | |
2892 | return i2c_write_bytes(client, 0x8041, opr_buffer, 1); | |
2893 | } | |
2894 | ||
2895 | void gtp_esd_switch(struct i2c_client *client, s32 on) | |
2896 | { | |
2897 | spin_lock(&esd_lock); | |
2898 | if (SWITCH_ON == on) // switch on esd | |
2899 | { | |
2900 | if (!esd_running) | |
2901 | { | |
2902 | esd_running = 1; | |
2903 | spin_unlock(&esd_lock); | |
2904 | GTP_INFO("Esd started"); | |
2905 | queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, clk_tick_cnt); | |
2906 | } | |
2907 | else | |
2908 | { | |
2909 | spin_unlock(&esd_lock); | |
2910 | } | |
2911 | } | |
2912 | else // switch off esd | |
2913 | { | |
2914 | if (esd_running) | |
2915 | { | |
2916 | esd_running = 0; | |
2917 | spin_unlock(&esd_lock); | |
2918 | GTP_INFO("Esd cancelled"); | |
2919 | cancel_delayed_work_sync(>p_esd_check_work); | |
2920 | } | |
2921 | else | |
2922 | { | |
2923 | spin_unlock(&esd_lock); | |
2924 | } | |
2925 | } | |
2926 | } | |
2927 | ||
2928 | static s32 gtp_check_fw(void) | |
2929 | { | |
2930 | u8 versionBuff[4] = {0}; | |
2931 | s32 ret,retry = 0; | |
2932 | ||
2933 | while(retry++ < 3) | |
2934 | { | |
2935 | ret = i2c_read_bytes_non_dma(i2c_client_point, 0x8140, versionBuff, sizeof(versionBuff)); | |
2936 | if(ret < 0) | |
2937 | { | |
2938 | continue; | |
2939 | } | |
2940 | if( memcmp(versionBuff, >p_default_FW_fl[4], 4) !=0 ) | |
2941 | { | |
2942 | continue; | |
2943 | } | |
2944 | ||
2945 | return 1; | |
2946 | } | |
2947 | ||
2948 | GTP_ERROR("Check running fw version error!"); | |
2949 | return 0; | |
2950 | } | |
2951 | ||
2952 | static void gtp_esd_check_func(struct work_struct *work) | |
2953 | { | |
2954 | s32 i = 0; | |
2955 | s32 ret = -1; | |
2956 | u8 esd_buf[3] = {0x00}; | |
2957 | ||
2958 | if (tpd_halt) | |
2959 | { | |
2960 | GTP_INFO("Esd suspended!"); | |
2961 | return; | |
2962 | } | |
2963 | for (i = 0; i < 3; i++) | |
2964 | { | |
2965 | ret = i2c_read_bytes_non_dma(i2c_client_point, 0x8040, esd_buf, 2); | |
2966 | ||
2967 | GTP_DEBUG("[Esd]0x8040 = 0x%02X, 0x8041 = 0x%02X", esd_buf[0], esd_buf[1]); | |
2968 | if (ret < 0) | |
2969 | { | |
2970 | // IIC communication problem | |
2971 | continue; | |
2972 | } | |
2973 | else | |
2974 | { | |
2975 | if ((esd_buf[0] == 0xAA) || (esd_buf[1] != 0xAA)) | |
2976 | { | |
2977 | u8 chk_buf[2] = {0x00}; | |
2978 | i2c_read_bytes_non_dma(i2c_client_point, 0x8040, chk_buf, 2); | |
2979 | ||
2980 | GTP_DEBUG("[Check]0x8040 = 0x%02X, 0x8041 = 0x%02X", chk_buf[0], chk_buf[1]); | |
2981 | ||
2982 | if ( (chk_buf[0] == 0xAA) || (chk_buf[1] != 0xAA) ) | |
2983 | { | |
2984 | i = 3; // jump to reset guitar | |
2985 | break; | |
2986 | } | |
2987 | else | |
2988 | { | |
2989 | continue; | |
2990 | } | |
2991 | } | |
2992 | else | |
2993 | { | |
2994 | // IC works normally, Write 0x8040 0xAA, feed the watchdog | |
2995 | esd_buf[0] = 0xAA; | |
2996 | i2c_write_bytes_non_dma(i2c_client_point, 0x8040, esd_buf, 1); | |
2997 | ||
2998 | break; | |
2999 | } | |
3000 | } | |
3001 | } | |
3002 | ||
3003 | if (i >= 3 || !gtp_check_fw()) | |
3004 | { | |
3005 | #if GTP_COMPATIBLE_MODE | |
3006 | if ((CHIP_TYPE_GT9F == gtp_chip_type) && (1 == rqst_processing)) | |
3007 | { | |
3008 | GTP_INFO("Request Processing, no reset guitar."); | |
3009 | } | |
3010 | else | |
3011 | #endif | |
3012 | { | |
3013 | GTP_INFO("IC works abnormally! Process reset guitar."); | |
3014 | esd_buf[0] = 0x01; | |
3015 | esd_buf[1] = 0x01; | |
3016 | esd_buf[2] = 0x01; | |
3017 | i2c_write_bytes(i2c_client_point, 0x4226, esd_buf, 3); | |
3018 | msleep(50); | |
3019 | force_reset_guitar(0); | |
3020 | } | |
3021 | } | |
3022 | ||
3023 | if (!tpd_halt) | |
3024 | { | |
3025 | queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, clk_tick_cnt); | |
3026 | } | |
3027 | else | |
3028 | { | |
3029 | GTP_INFO("Esd suspended!"); | |
3030 | } | |
3031 | ||
3032 | return; | |
3033 | } | |
3034 | #endif | |
3035 | ||
3036 | static void tpd_down(s32 x, s32 y, s32 size, s32 id) | |
3037 | { | |
3038 | if ((!size) && (!id)) | |
3039 | { | |
3040 | input_report_abs(tpd->dev, ABS_MT_PRESSURE, 100); | |
3041 | input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, 100); | |
3042 | } | |
3043 | else | |
3044 | { | |
3045 | input_report_abs(tpd->dev, ABS_MT_PRESSURE, size); | |
3046 | input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, size); | |
3047 | /* track id Start 0 */ | |
3048 | input_report_abs(tpd->dev, ABS_MT_TRACKING_ID, id); | |
3049 | } | |
3050 | ||
3051 | input_report_key(tpd->dev, BTN_TOUCH, 1); | |
3052 | input_report_abs(tpd->dev, ABS_MT_POSITION_X, x); | |
3053 | input_report_abs(tpd->dev, ABS_MT_POSITION_Y, y); | |
3054 | input_mt_sync(tpd->dev); | |
3055 | TPD_EM_PRINT(x, y, x, y, id, 1); | |
3056 | ||
3057 | #if (defined(MT6575)||defined(MT6577)) | |
3058 | ||
3059 | if (FACTORY_BOOT == get_boot_mode() || RECOVERY_BOOT == get_boot_mode()) | |
3060 | { | |
3061 | tpd_button(x, y, 1); | |
3062 | } | |
3063 | ||
3064 | #endif | |
3065 | } | |
3066 | ||
3067 | static void tpd_up(s32 x, s32 y, s32 id) | |
3068 | { | |
3069 | input_report_key(tpd->dev, BTN_TOUCH, 0); | |
3070 | input_mt_sync(tpd->dev); | |
3071 | TPD_EM_PRINT(x, y, x, y, id, 0); | |
3072 | ||
3073 | #if (defined(MT6575) || defined(MT6577)) | |
3074 | ||
3075 | if (FACTORY_BOOT == get_boot_mode() || RECOVERY_BOOT == get_boot_mode()) | |
3076 | { | |
3077 | tpd_button(x, y, 0); | |
3078 | } | |
3079 | ||
3080 | #endif | |
3081 | } | |
3082 | #if GTP_CHARGER_SWITCH | |
3083 | static void gtp_charger_switch(s32 dir_update) | |
3084 | { | |
3085 | u32 chr_status = 0; | |
3086 | u8 chr_cmd[3] = {0x80, 0x40}; | |
3087 | static u8 chr_pluggedin = 0; | |
3088 | int ret = 0; | |
3089 | ||
3090 | #ifdef MT6573 | |
3091 | chr_status = *(volatile u32 *)CHR_CON0; | |
3092 | chr_status &= (1 << 13); | |
3093 | #else // ( defined(MT6575) || defined(MT6577) || defined(MT6589) ) | |
3094 | chr_status = upmu_is_chr_det(); | |
3095 | #endif | |
3096 | ||
3097 | if (chr_status) // charger plugged in | |
3098 | { | |
3099 | if (!chr_pluggedin || dir_update) | |
3100 | { | |
3101 | chr_cmd[2] = 6; | |
3102 | ret = gtp_i2c_write(i2c_client_point, chr_cmd, 3); | |
3103 | if (ret > 0) | |
3104 | { | |
3105 | GTP_INFO("Update status for Charger Plugin"); | |
3106 | } | |
3107 | chr_pluggedin = 1; | |
3108 | } | |
3109 | } | |
3110 | else // charger plugged out | |
3111 | { | |
3112 | if (chr_pluggedin || dir_update) | |
3113 | { | |
3114 | chr_cmd[2] = 7; | |
3115 | ret = gtp_i2c_write(i2c_client_point, chr_cmd, 3); | |
3116 | if (ret > 0) | |
3117 | { | |
3118 | GTP_INFO("Update status for Charger Plugout"); | |
3119 | } | |
3120 | chr_pluggedin = 0; | |
3121 | } | |
3122 | } | |
3123 | } | |
3124 | #endif | |
3125 | ||
3126 | static int touch_event_handler(void *unused) | |
3127 | { | |
3128 | struct sched_param param = { .sched_priority = RTPM_PRIO_TPD }; | |
3129 | u8 end_cmd[3] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0}; | |
3130 | u8 point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF}; | |
3131 | u8 touch_num = 0; | |
3132 | u8 finger = 0; | |
3133 | static u8 pre_touch = 0; | |
3134 | static u8 pre_key = 0; | |
3135 | #if GTP_WITH_PEN | |
3136 | u8 pen_active = 0; | |
3137 | static u8 pre_pen = 0; | |
3138 | #endif | |
3139 | u8 key_value = 0; | |
3140 | u8 *coor_data = NULL; | |
3141 | s32 input_x = 0; | |
3142 | s32 input_y = 0; | |
3143 | s32 input_w = 0; | |
3144 | s32 id = 0; | |
3145 | s32 i = 0; | |
3146 | s32 ret = -1; | |
3147 | ||
3148 | #if GTP_COMPATIBLE_MODE | |
3149 | u8 rqst_data[3] = {(u8)(GTP_REG_RQST >> 8), (u8)(GTP_REG_RQST & 0xFF), 0}; | |
3150 | #endif | |
3151 | ||
3152 | #ifdef TPD_PROXIMITY | |
3153 | s32 err = 0; | |
3154 | hwm_sensor_data sensor_data; | |
3155 | u8 proximity_status; | |
3156 | #endif | |
3157 | u8 proximity_status; //add by caoyang | |
3158 | u8 doze_buf[3] = {0x81, 0x4B}; | |
3159 | ||
3160 | sched_setscheduler(current, SCHED_RR, ¶m); | |
3161 | do | |
3162 | { | |
3163 | set_current_state(TASK_INTERRUPTIBLE); | |
3164 | ||
3165 | while (tpd_halt) | |
3166 | { | |
3167 | //#if GTP_GESTURE_WAKEUP | |
3168 | if(gesture_value > 0){ | |
3169 | if (DOZE_ENABLED == doze_status) | |
3170 | { | |
3171 | break; | |
3172 | } | |
3173 | //#endif | |
3174 | } | |
3175 | tpd_flag = 0; | |
3176 | msleep(20); | |
3177 | } | |
3178 | ||
3179 | wait_event_interruptible(waiter, tpd_flag != 0); | |
3180 | tpd_flag = 0; | |
3181 | TPD_DEBUG_SET_TIME; | |
3182 | set_current_state(TASK_RUNNING); | |
3183 | ||
3184 | #if GTP_CHARGER_SWITCH | |
3185 | gtp_charger_switch(0); | |
3186 | #endif | |
3187 | ||
3188 | if(gesture_value > 0){ | |
3189 | //#if GTP_GESTURE_WAKEUP | |
3190 | if (DOZE_ENABLED == doze_status) | |
3191 | { | |
3192 | ret = gtp_i2c_read(i2c_client_point, doze_buf, 3); | |
3193 | GTP_DEBUG("0x814B = 0x%02X", doze_buf[2]); | |
3194 | if (ret > 0) | |
3195 | { | |
3196 | if ((doze_buf[2] == 'a') || (doze_buf[2] == 'b') || (doze_buf[2] == 'c') || | |
3197 | (doze_buf[2] == 'd') || (doze_buf[2] == 'e') || (doze_buf[2] == 'g') || | |
3198 | (doze_buf[2] == 'h') || (doze_buf[2] == 'm') || (doze_buf[2] == 'o') || | |
3199 | (doze_buf[2] == 'q') || (doze_buf[2] == 's') || (doze_buf[2] == 'v') || | |
3200 | (doze_buf[2] == 'w') || (doze_buf[2] == 'y') || (doze_buf[2] == 'z') || | |
3201 | (doze_buf[2] == 0x5E) /* ^ */ | |
3202 | ) | |
3203 | { | |
3204 | if (doze_buf[2] != 0x5E) | |
3205 | { | |
3206 | GTP_INFO("Wakeup by gesture(%c), light up the screen!", doze_buf[2]); | |
3207 | } | |
3208 | else | |
3209 | { | |
3210 | GTP_INFO("Wakeup by gesture(^), light up the screen!"); | |
3211 | } | |
3212 | ||
3213 | doze_status = DOZE_WAKEUP; | |
3214 | input_report_key(tpd->dev, KEY_POWER, 1); | |
3215 | input_sync(tpd->dev); | |
3216 | input_report_key(tpd->dev, KEY_POWER, 0); | |
3217 | input_sync(tpd->dev); | |
3218 | // clear 0x814B | |
3219 | doze_buf[2] = 0x00; | |
3220 | gtp_i2c_write(i2c_client_point, doze_buf, 3); | |
3221 | } | |
3222 | else if ( (doze_buf[2] == 0xAA) || (doze_buf[2] == 0xBB) || | |
3223 | (doze_buf[2] == 0xAB) || (doze_buf[2] == 0xBA) ) | |
3224 | { | |
3225 | char *direction[4] = {"Right", "Down", "Up", "Left"}; | |
3226 | u8 type = ((doze_buf[2] & 0x0F) - 0x0A) + (((doze_buf[2] >> 4) & 0x0F) - 0x0A) * 2; | |
3227 | ||
3228 | GTP_INFO("%s slide to light up the screen!", direction[type]); | |
3229 | doze_status = DOZE_WAKEUP; | |
3230 | input_report_key(tpd->dev, KEY_POWER, 1); | |
3231 | input_sync(tpd->dev); | |
3232 | input_report_key(tpd->dev, KEY_POWER, 0); | |
3233 | input_sync(tpd->dev); | |
3234 | // clear 0x814B | |
3235 | doze_buf[2] = 0x00; | |
3236 | gtp_i2c_write(i2c_client_point, doze_buf, 3); | |
3237 | } | |
3238 | else if (0xCC == doze_buf[2]) | |
3239 | { | |
3240 | GTP_INFO("Double click to light up the screen!"); | |
3241 | doze_status = DOZE_WAKEUP; | |
3242 | input_report_key(tpd->dev, KEY_POWER, 1); | |
3243 | input_sync(tpd->dev); | |
3244 | input_report_key(tpd->dev, KEY_POWER, 0); | |
3245 | input_sync(tpd->dev); | |
3246 | // clear 0x814B | |
3247 | doze_buf[2] = 0x00; | |
3248 | gtp_i2c_write(i2c_client_point, doze_buf, 3); | |
3249 | } | |
3250 | else | |
3251 | { | |
3252 | // clear 0x814B | |
3253 | doze_buf[2] = 0x00; | |
3254 | gtp_i2c_write(i2c_client_point, doze_buf, 3); | |
3255 | gtp_enter_doze(i2c_client_point); | |
3256 | } | |
3257 | } | |
3258 | continue; | |
3259 | } | |
3260 | //#endif | |
3261 | } | |
3262 | ret = gtp_i2c_read(i2c_client_point, point_data, 12); | |
3263 | if (ret < 0) | |
3264 | { | |
3265 | GTP_ERROR("I2C transfer error. errno:%d\n ", ret); | |
3266 | continue; | |
3267 | } | |
3268 | finger = point_data[GTP_ADDR_LENGTH]; | |
3269 | ||
3270 | #if GTP_COMPATIBLE_MODE | |
3271 | if ((finger == 0x00) && (CHIP_TYPE_GT9F == gtp_chip_type)) | |
3272 | { | |
3273 | ret = gtp_i2c_read(i2c_client_point, rqst_data, 3); | |
3274 | ||
3275 | if(ret < 0) | |
3276 | { | |
3277 | GTP_ERROR("I2C transfer error. errno:%d\n ", ret); | |
3278 | continue; | |
3279 | } | |
3280 | switch (rqst_data[2]) | |
3281 | { | |
3282 | case GTP_RQST_BAK_REF: | |
3283 | GTP_INFO("Request Ref."); | |
3284 | rqst_processing = 1; | |
3285 | ret = gtp_bak_ref_proc(i2c_client_point, GTP_BAK_REF_SEND); | |
3286 | if(SUCCESS == ret) | |
3287 | { | |
3288 | GTP_INFO("Send ref success."); | |
3289 | rqst_data[2] = GTP_RQST_RESPONDED; | |
3290 | gtp_i2c_write(i2c_client_point, rqst_data, 3); | |
3291 | rqst_processing = 0; | |
3292 | } | |
3293 | goto exit_work_func; | |
3294 | ||
3295 | case GTP_RQST_CONFIG: | |
3296 | GTP_INFO("Request Config."); | |
3297 | ret = gtp_send_cfg(i2c_client_point); | |
3298 | if (ret < 0) | |
3299 | { | |
3300 | GTP_ERROR("Send config error."); | |
3301 | } | |
3302 | else | |
3303 | { | |
3304 | GTP_INFO("Send config success."); | |
3305 | rqst_data[2] = GTP_RQST_RESPONDED; | |
3306 | gtp_i2c_write(i2c_client_point, rqst_data, 3); | |
3307 | } | |
3308 | goto exit_work_func; | |
3309 | ||
3310 | case GTP_RQST_MAIN_CLOCK: | |
3311 | GTP_INFO("Request main clock."); | |
3312 | rqst_processing = 1; | |
3313 | ret = gtp_main_clk_proc(i2c_client_point); | |
3314 | if(SUCCESS == ret) | |
3315 | { | |
3316 | GTP_INFO("Send main clk success."); | |
3317 | #if GTP_POWER_CTRL_SLEEP | |
3318 | { | |
3319 | ret = gtp_hopping_proc(i2c_client_point, GTP_HOPPING_SEND); | |
3320 | if (FAIL == ret) | |
3321 | { | |
3322 | GTP_ERROR("Failed to send hopping data."); | |
3323 | goto exit_work_func; | |
3324 | } | |
3325 | else | |
3326 | { | |
3327 | GTP_INFO("Send hopping data success."); | |
3328 | } | |
3329 | } | |
3330 | #endif | |
3331 | rqst_data[2] = GTP_RQST_RESPONDED; | |
3332 | gtp_i2c_write(i2c_client_point, rqst_data, 3); | |
3333 | rqst_processing = 0; | |
3334 | } | |
3335 | goto exit_work_func; | |
3336 | ||
3337 | case GTP_RQST_RESET: | |
3338 | //#if GTP_GESTURE_WAKEUP | |
3339 | if(gesture_value > 0){ | |
3340 | if (DOZE_ENABLED == doze_status) { | |
3341 | u8 reg_data[3] = {(u8)(0x801F >> 8), (u8)(0x801F & 0xFF), 0}; | |
3342 | gtp_i2c_write(i2c_client_point, reg_data, 3); | |
3343 | gtp_recovery_reset(i2c_client_point); | |
3344 | gtp_enter_doze(i2c_client_point); | |
3345 | } | |
3346 | }else | |
3347 | //#endif | |
3348 | { | |
3349 | gtp_recovery_reset(i2c_client_point); | |
3350 | } | |
3351 | GTP_INFO("Request Reset."); | |
3352 | goto exit_work_func; | |
3353 | ||
3354 | #if GTP_POWER_CTRL_SLEEP | |
3355 | case GTP_RQST_STORE_HOPPING: | |
3356 | GTP_INFO("Request store hopping data."); | |
3357 | ret = gtp_hopping_proc(i2c_client_point, GTP_HOPPING_STORE); | |
3358 | if (FAIL == ret) | |
3359 | { | |
3360 | GTP_ERROR("Failed to store hopping data."); | |
3361 | } | |
3362 | else | |
3363 | { | |
3364 | GTP_INFO("Hopping data stored."); | |
3365 | rqst_data[2] = GTP_RQST_RESPONDED; | |
3366 | gtp_i2c_write(i2c_client_point, rqst_data, 3); | |
3367 | } | |
3368 | goto exit_work_func; | |
3369 | ||
3370 | case GTP_RQST_STORE_BAK_REF: | |
3371 | GTP_INFO("Request store backup reference."); | |
3372 | ret = gtp_bak_ref_proc(i2c_client_point, GTP_BAK_REF_STORE); | |
3373 | if (FAIL == ret) | |
3374 | { | |
3375 | GTP_ERROR("Failed to store backup reference data."); | |
3376 | } | |
3377 | else | |
3378 | { | |
3379 | GTP_INFO("Backup reference data stored."); | |
3380 | rqst_data[2] = GTP_RQST_RESPONDED; | |
3381 | gtp_i2c_write(i2c_client_point, rqst_data, 3); | |
3382 | } | |
3383 | goto exit_work_func; | |
3384 | #endif | |
3385 | ||
3386 | default: | |
3387 | GTP_INFO("Undefined request code: 0x%02X", rqst_data[2]); | |
3388 | rqst_data[2] = GTP_RQST_RESPONDED; | |
3389 | gtp_i2c_write(i2c_client_point, rqst_data, 3); | |
3390 | break; | |
3391 | } | |
3392 | } | |
3393 | #endif | |
3394 | ||
3395 | if (finger == 0x00) | |
3396 | { | |
3397 | continue; | |
3398 | } | |
3399 | ||
3400 | if ((finger & 0x80) == 0) | |
3401 | { | |
3402 | goto exit_work_func; | |
3403 | } | |
3404 | if((gtp_autotool_setting == 1) && !(point_data[GTP_ADDR_LENGTH] & 0x40)){ | |
3405 | gtp_autotool_setting = 0; | |
3406 | } | |
3407 | //add by caoyang | |
3408 | if(gesture_value > 0){ | |
3409 | proximity_status = point_data[GTP_ADDR_LENGTH]; | |
3410 | GTP_DEBUG("REG INDEX[0x814E]:0x%02X\n", proximity_status); | |
3411 | if(tpd_sleep_flag == 1){ | |
3412 | goto exit_work_func; | |
3413 | } | |
3414 | if (proximity_status & 0x40) //proximity or large touch detect,enable hwm_sensor. | |
3415 | { | |
3416 | printk(KERN_ERR"caoyang0 test for xipin\n"); | |
3417 | //mod_timer(&buttons_timer, jiffies+HZ/50); | |
3418 | if(gtp_autotool_setting == 1){ | |
3419 | gtp_autotool_setting = 0; | |
3420 | goto exit_work_func; | |
3421 | } | |
3422 | #if 1 | |
3423 | input_report_key(tpd->dev, KEY_POWER, 1); | |
3424 | input_sync(tpd->dev); | |
3425 | input_report_key(tpd->dev, KEY_POWER, 0); | |
3426 | input_sync(tpd->dev); | |
3427 | tpd_sleep_flag = 1; | |
3428 | #endif | |
3429 | goto exit_work_func; | |
3430 | } | |
3431 | //end | |
3432 | } | |
3433 | #ifdef TPD_PROXIMITY | |
3434 | if (tpd_proximity_flag == 1) | |
3435 | { | |
3436 | proximity_status = point_data[GTP_ADDR_LENGTH]; | |
3437 | GTP_DEBUG("REG INDEX[0x814E]:0x%02X\n", proximity_status); | |
3438 | ||
3439 | if (proximity_status & 0x60) //proximity or large touch detect,enable hwm_sensor. | |
3440 | { | |
3441 | tpd_proximity_detect = 0; | |
3442 | //sensor_data.values[0] = 0; | |
3443 | } | |
3444 | else | |
3445 | { | |
3446 | tpd_proximity_detect = 1; | |
3447 | //sensor_data.values[0] = 1; | |
3448 | } | |
3449 | ||
3450 | //get raw data | |
3451 | GTP_DEBUG(" ps change\n"); | |
3452 | GTP_DEBUG("PROXIMITY STATUS:0x%02X\n", tpd_proximity_detect); | |
3453 | //map and store data to hwm_sensor_data | |
3454 | sensor_data.values[0] = tpd_get_ps_value(); | |
3455 | sensor_data.value_divide = 1; | |
3456 | sensor_data.status = SENSOR_STATUS_ACCURACY_MEDIUM; | |
3457 | //report to the up-layer | |
3458 | ret = hwmsen_get_interrupt_data(ID_PROXIMITY, &sensor_data); | |
3459 | ||
3460 | if (ret) | |
3461 | { | |
3462 | GTP_ERROR("Call hwmsen_get_interrupt_data fail = %d\n", err); | |
3463 | } | |
3464 | } | |
3465 | ||
3466 | #endif | |
3467 | ||
3468 | touch_num = finger & 0x0f; | |
3469 | ||
3470 | if (touch_num > GTP_MAX_TOUCH) | |
3471 | { | |
3472 | goto exit_work_func; | |
3473 | } | |
3474 | ||
3475 | if (touch_num > 1) | |
3476 | { | |
3477 | u8 buf[8 * GTP_MAX_TOUCH] = {(GTP_READ_COOR_ADDR + 10) >> 8, (GTP_READ_COOR_ADDR + 10) & 0xff}; | |
3478 | ||
3479 | ret = gtp_i2c_read(i2c_client_point, buf, 2 + 8 * (touch_num - 1)); | |
3480 | memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1)); | |
3481 | } | |
3482 | ||
3483 | #if (GTP_HAVE_TOUCH_KEY || GTP_PEN_HAVE_BUTTON) | |
3484 | key_value = point_data[3 + 8 * touch_num]; | |
3485 | ||
3486 | if (key_value || pre_key) | |
3487 | { | |
3488 | #if GTP_PEN_HAVE_BUTTON | |
3489 | if (key_value == 0x40) | |
3490 | { | |
3491 | GTP_DEBUG("BTN_STYLUS & BTN_STYLUS2 Down."); | |
3492 | input_report_key(pen_dev, BTN_STYLUS, 1); | |
3493 | input_report_key(pen_dev, BTN_STYLUS2, 1); | |
3494 | pen_active = 1; | |
3495 | } | |
3496 | else if (key_value == 0x10) | |
3497 | { | |
3498 | GTP_DEBUG("BTN_STYLUS Down, BTN_STYLUS2 Up."); | |
3499 | input_report_key(pen_dev, BTN_STYLUS, 1); | |
3500 | input_report_key(pen_dev, BTN_STYLUS2, 0); | |
3501 | pen_active = 1; | |
3502 | } | |
3503 | else if (key_value == 0x20) | |
3504 | { | |
3505 | GTP_DEBUG("BTN_STYLUS Up, BTN_STYLUS2 Down."); | |
3506 | input_report_key(pen_dev, BTN_STYLUS, 0); | |
3507 | input_report_key(pen_dev, BTN_STYLUS2, 1); | |
3508 | pen_active = 1; | |
3509 | } | |
3510 | else | |
3511 | { | |
3512 | GTP_DEBUG("BTN_STYLUS & BTN_STYLUS2 Up."); | |
3513 | input_report_key(pen_dev, BTN_STYLUS, 0); | |
3514 | input_report_key(pen_dev, BTN_STYLUS2, 0); | |
3515 | if ( (pre_key == 0x40) || (pre_key == 0x20) || | |
3516 | (pre_key == 0x10) | |
3517 | ) | |
3518 | { | |
3519 | pen_active = 1; | |
3520 | } | |
3521 | } | |
3522 | if (pen_active) | |
3523 | { | |
3524 | touch_num = 0; // shield pen point | |
3525 | //pre_touch = 0; // clear last pen status | |
3526 | } | |
3527 | #endif | |
3528 | #if GTP_HAVE_TOUCH_KEY | |
3529 | if (!pre_touch) | |
3530 | { | |
3531 | for (i = 0; i < GTP_MAX_KEY_NUM; i++) | |
3532 | { | |
3533 | input_report_key(tpd->dev, touch_key_array[i], key_value & (0x01 << i)); | |
3534 | } | |
3535 | touch_num = 0; // shiled fingers | |
3536 | } | |
3537 | #endif | |
3538 | } | |
3539 | #endif | |
3540 | pre_key = key_value; | |
3541 | ||
3542 | GTP_DEBUG("pre_touch:%02x, finger:%02x.", pre_touch, finger); | |
3543 | ||
3544 | if (touch_num) | |
3545 | { | |
3546 | for (i = 0; i < touch_num; i++) | |
3547 | { | |
3548 | coor_data = &point_data[i * 8 + 3]; | |
3549 | ||
3550 | id = coor_data[0] & 0x0F; | |
3551 | input_x = coor_data[1] | coor_data[2] << 8; | |
3552 | input_y = coor_data[3] | coor_data[4] << 8; | |
3553 | input_w = coor_data[5] | coor_data[6] << 8; | |
3554 | ||
3555 | #if GTP_WITH_PEN | |
3556 | id = coor_data[0]; | |
3557 | if ((id & 0x80)) // pen/stylus is activated | |
3558 | { | |
3559 | GTP_DEBUG("Pen touch DOWN!"); | |
3560 | pre_pen = 1; | |
3561 | //id &= 0x7F; | |
3562 | id = 0; | |
3563 | GTP_DEBUG("(%d)(%d, %d)[%d]", id, input_x, input_y, input_w); | |
3564 | gtp_pen_down(input_x, input_y, input_w, id); | |
3565 | pen_active = 1; | |
3566 | } | |
3567 | else | |
3568 | #endif | |
3569 | { | |
3570 | GTP_DEBUG(" (%d)(%d, %d)[%d]", id, input_x, input_y, input_w); | |
3571 | tpd_down(input_x, input_y, input_w, id); | |
3572 | } | |
3573 | } | |
3574 | } | |
3575 | else | |
3576 | { | |
3577 | if (pre_touch) | |
3578 | { | |
3579 | #if GTP_WITH_PEN | |
3580 | if (pre_pen) | |
3581 | { | |
3582 | GTP_DEBUG("Pen touch UP!"); | |
3583 | gtp_pen_up(); | |
3584 | pre_pen = 0; | |
3585 | pen_active = 1; | |
3586 | } | |
3587 | else | |
3588 | #endif | |
3589 | { | |
3590 | GTP_DEBUG("Touch Release!"); | |
3591 | tpd_up(0, 0, 0); | |
3592 | } | |
3593 | } | |
3594 | } | |
3595 | pre_touch = touch_num; | |
3596 | ||
3597 | #if GTP_WITH_PEN | |
3598 | if (pen_active) | |
3599 | { | |
3600 | pen_active = 0; | |
3601 | input_sync(pen_dev); | |
3602 | } | |
3603 | else | |
3604 | #endif | |
3605 | { | |
3606 | input_sync(tpd->dev); | |
3607 | } | |
3608 | ||
3609 | exit_work_func: | |
3610 | ||
3611 | if (!gtp_rawdiff_mode) | |
3612 | { | |
3613 | ret = gtp_i2c_write(i2c_client_point, end_cmd, 3); | |
3614 | ||
3615 | if (ret < 0) | |
3616 | { | |
3617 | GTP_ERROR("I2C write end_cmd error!"); | |
3618 | } | |
3619 | } | |
3620 | #if (GTP_COMPATIBLE_MODE && GTP_FL_LITTLE_SYSTEM) | |
3621 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
3622 | { | |
3623 | if (little_fw_mode) | |
3624 | { | |
3625 | if ((fw_block == 0) && (block_section == 1)) | |
3626 | { | |
3627 | GTP_INFO("Begin downloading big ss51 firmware"); | |
3628 | } | |
3629 | gtp_download_big_ss51(i2c_client_point); | |
3630 | } | |
3631 | } | |
3632 | #endif | |
3633 | } while (!kthread_should_stop()); | |
3634 | ||
3635 | return 0; | |
3636 | } | |
3637 | ||
3638 | static int tpd_local_init(void) | |
3639 | { | |
3640 | #if GTP_ESD_PROTECT | |
3641 | clk_tick_cnt = 2 * HZ; // HZ: clock ticks in 1 second generated by system | |
3642 | GTP_DEBUG("Clock ticks for an esd cycle: %d", clk_tick_cnt); | |
3643 | INIT_DELAYED_WORK(>p_esd_check_work, gtp_esd_check_func); | |
3644 | gtp_esd_check_workqueue = create_workqueue("gtp_esd_check"); | |
3645 | spin_lock_init(&esd_lock); // 2.6.39 & later | |
3646 | // esd_lock = SPIN_LOCK_UNLOCKED; // 2.6.39 & before | |
3647 | #endif | |
3648 | ||
3649 | #if GTP_SUPPORT_I2C_DMA | |
3650 | gpDMABuf_va = (u8 *)dma_alloc_coherent(NULL, GTP_DMA_MAX_TRANSACTION_LENGTH, &gpDMABuf_pa, GFP_KERNEL); | |
3651 | if(!gpDMABuf_va){ | |
3652 | GTP_ERROR("[Error] Allocate DMA I2C Buffer failed!\n"); | |
3653 | } | |
3654 | memset(gpDMABuf_va, 0, GTP_DMA_MAX_TRANSACTION_LENGTH); | |
3655 | #endif | |
3656 | if (i2c_add_driver(&tpd_i2c_driver) != 0) | |
3657 | { | |
3658 | GTP_ERROR("unable to add i2c driver.\n"); | |
3659 | return -1; | |
3660 | } | |
3661 | ||
3662 | if (tpd_load_status == 0) //if(tpd_load_status == 0) // disable auto load touch driver for linux3.0 porting | |
3663 | { | |
3664 | GTP_ERROR("add error touch panel driver.\n"); | |
3665 | i2c_del_driver(&tpd_i2c_driver); | |
3666 | return -1; | |
3667 | } | |
3668 | ||
3669 | input_set_abs_params(tpd->dev, ABS_MT_TRACKING_ID, 0, (GTP_MAX_TOUCH - 1), 0, 0); | |
3670 | #ifdef TPD_HAVE_BUTTON | |
3671 | tpd_button_setting(TPD_KEY_COUNT, tpd_keys_local, tpd_keys_dim_local);// initialize tpd button data | |
3672 | #endif | |
3673 | ||
3674 | #if (defined(TPD_WARP_START) && defined(TPD_WARP_END)) | |
3675 | TPD_DO_WARP = 1; | |
3676 | memcpy(tpd_wb_start, tpd_wb_start_local, TPD_WARP_CNT * 4); | |
3677 | memcpy(tpd_wb_end, tpd_wb_start_local, TPD_WARP_CNT * 4); | |
3678 | #endif | |
3679 | ||
3680 | #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION)) | |
3681 | memcpy(tpd_calmat, tpd_def_calmat_local, 8 * 4); | |
3682 | memcpy(tpd_def_calmat, tpd_def_calmat_local, 8 * 4); | |
3683 | #endif | |
3684 | ||
3685 | // set vendor string | |
3686 | tpd->dev->id.vendor = 0x00; | |
3687 | tpd->dev->id.product = tpd_info.pid; | |
3688 | tpd->dev->id.version = tpd_info.vid; | |
3689 | ||
3690 | GTP_DEBUG("end %s, %d\n", __FUNCTION__, __LINE__); | |
3691 | tpd_type_cap = 1; | |
3692 | ||
757110aa S |
3693 | if (get_boot_mode() == RECOVERY_BOOT) { |
3694 | tpd_i2c_probe_next(i2c_client_point); | |
3695 | } | |
3696 | ||
6fa3eb70 S |
3697 | return 0; |
3698 | } | |
3699 | ||
3700 | static s8 gtp_enter_doze(struct i2c_client *client) | |
3701 | { | |
3702 | s8 ret = -1; | |
3703 | s8 retry = 0; | |
3704 | u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 8}; | |
3705 | ||
3706 | GTP_DEBUG_FUNC(); | |
3707 | ||
3708 | GTP_DEBUG("Entering gesture mode..."); | |
3709 | while(retry++ < 5) | |
3710 | { | |
3711 | i2c_control_buf[0] = 0x80; | |
3712 | i2c_control_buf[1] = 0x46; | |
3713 | ret = gtp_i2c_write(client, i2c_control_buf, 3); | |
3714 | if (ret < 0) | |
3715 | { | |
3716 | GTP_DEBUG("Failed to set gesture flag into 0x8046, %d", retry); | |
3717 | continue; | |
3718 | } | |
3719 | i2c_control_buf[0] = 0x80; | |
3720 | i2c_control_buf[1] = 0x40; | |
3721 | ret = gtp_i2c_write(client, i2c_control_buf, 3); | |
3722 | if (ret > 0) | |
3723 | { | |
3724 | doze_status = DOZE_ENABLED; | |
3725 | GTP_INFO("Gesture mode enabled."); | |
3726 | return ret; | |
3727 | } | |
3728 | msleep(10); | |
3729 | } | |
3730 | GTP_ERROR("GTP send gesture cmd failed."); | |
3731 | return ret; | |
3732 | } | |
3733 | ||
3734 | /******************************************************* | |
3735 | Function: | |
3736 | Eter sleep function. | |
3737 | ||
3738 | Input: | |
3739 | client:i2c_client. | |
3740 | ||
3741 | Output: | |
3742 | Executive outcomes.0--success,non-0--fail. | |
3743 | *******************************************************/ | |
3744 | static s8 gtp_enter_sleep(struct i2c_client *client) | |
3745 | { | |
3746 | #if (GTP_COMPATIBLE_MODE && !GTP_POWER_CTRL_SLEEP) | |
3747 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
3748 | { | |
3749 | u8 i2c_status_buf[3] = {0x80, 0x44, 0x00}; | |
3750 | s32 ret = 0; | |
3751 | ||
3752 | ret = gtp_i2c_read(client, i2c_status_buf, 3); | |
3753 | if(ret <= 0) | |
3754 | { | |
3755 | GTP_ERROR("[gtp_enter_sleep]Read ref status reg error."); | |
3756 | } | |
3757 | ||
3758 | if (i2c_status_buf[2] & 0x80) | |
3759 | { | |
3760 | //Store bak ref | |
3761 | ret = gtp_bak_ref_proc(client, GTP_BAK_REF_STORE); | |
3762 | if(FAIL == ret) | |
3763 | { | |
3764 | GTP_ERROR("[gtp_enter_sleep]Store bak ref failed."); | |
3765 | } | |
3766 | } | |
3767 | } | |
3768 | #endif | |
3769 | #if GTP_POWER_CTRL_SLEEP | |
3770 | ||
3771 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); | |
3772 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); | |
3773 | msleep(10); | |
3774 | ||
3775 | #ifdef MT6573 | |
3776 | mt_set_gpio_mode(GPIO_CTP_EN_PIN, GPIO_CTP_EN_PIN_M_GPIO); | |
3777 | mt_set_gpio_dir(GPIO_CTP_EN_PIN, GPIO_DIR_OUT); | |
3778 | mt_set_gpio_out(GPIO_CTP_EN_PIN, GPIO_OUT_ZERO); | |
3779 | msleep(30); | |
3780 | #else // ( defined(MT6575) || defined(MT6577) || defined(MT6589) ) | |
3781 | ||
3782 | #ifdef TPD_POWER_SOURCE_1800 | |
3783 | hwPowerDown(TPD_POWER_SOURCE_1800, "TP"); | |
3784 | #endif | |
3785 | ||
3786 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
3787 | hwPowerDown(TPD_POWER_SOURCE_CUSTOM, "TP"); | |
3788 | #else | |
3789 | hwPowerDown(MT65XX_POWER_LDO_VGP2, "TP"); | |
3790 | #endif | |
3791 | #endif | |
3792 | ||
3793 | GTP_INFO("GTP enter sleep by poweroff!"); | |
3794 | return 0; | |
3795 | ||
3796 | #else | |
3797 | { | |
3798 | s8 ret = -1; | |
3799 | s8 retry = 0; | |
3800 | u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 5}; | |
3801 | ||
3802 | ||
3803 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); | |
3804 | msleep(5); | |
3805 | ||
3806 | while (retry++ < 5) | |
3807 | { | |
3808 | ret = gtp_i2c_write(client, i2c_control_buf, 3); | |
3809 | ||
3810 | if (ret > 0) | |
3811 | { | |
3812 | GTP_INFO("GTP enter sleep!"); | |
3813 | ||
3814 | return ret; | |
3815 | } | |
3816 | ||
3817 | msleep(10); | |
3818 | } | |
3819 | ||
3820 | GTP_ERROR("GTP send sleep cmd failed."); | |
3821 | return ret; | |
3822 | } | |
3823 | #endif | |
3824 | } | |
3825 | ||
3826 | /******************************************************* | |
3827 | Function: | |
3828 | Wakeup from sleep mode Function. | |
3829 | ||
3830 | Input: | |
3831 | client:i2c_client. | |
3832 | ||
3833 | Output: | |
3834 | Executive outcomes.0--success,non-0--fail. | |
3835 | *******************************************************/ | |
3836 | static s8 gtp_wakeup_sleep(struct i2c_client *client) | |
3837 | { | |
3838 | u8 retry = 0; | |
3839 | s8 ret = -1; | |
3840 | ||
3841 | GTP_DEBUG("GTP wakeup begin."); | |
3842 | ||
3843 | #if GTP_POWER_CTRL_SLEEP | |
3844 | #if (GTP_COMPATIBLE_MODE && GTP_FL_LITTLE_SYSTEM) | |
3845 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
3846 | { | |
3847 | power_is_down = 0; | |
3848 | little_fw_mode = 1; | |
3849 | kthread_run(gtp_resume_timeout, (void*)NULL, "resume_timeout"); | |
3850 | ||
3851 | ret = force_reset_guitar(1); | |
3852 | if (FAIL == ret) | |
3853 | { | |
3854 | little_fw_mode = 0; | |
3855 | gtp_recovery_reset(client); | |
3856 | } | |
3857 | if (!gtp_check_fw()) { | |
3858 | little_fw_mode = 0; | |
3859 | gtp_recovery_reset(client); | |
3860 | } | |
3861 | return 0; | |
3862 | } | |
3863 | #endif // end compatible mode & fl little system | |
3864 | ||
3865 | while (retry++ < 5) | |
3866 | { | |
3867 | ret = tpd_power_on(client); | |
3868 | ||
3869 | if (ret < 0) | |
3870 | { | |
3871 | GTP_ERROR("I2C Power on ERROR!"); | |
3872 | continue; | |
3873 | } | |
3874 | GTP_INFO("Ic wakeup by poweron"); | |
3875 | return 0; | |
3876 | } | |
3877 | #else // esle PowerCtrlSleep | |
3878 | while (retry++ < 5) { | |
3879 | //#if GTP_GESTURE_WAKEUP | |
3880 | if(gesture_value > 0){ | |
3881 | if (DOZE_WAKEUP != doze_status) | |
3882 | { | |
3883 | GTP_INFO("Powerkey wakeup."); | |
3884 | } | |
3885 | else | |
3886 | { | |
3887 | GTP_INFO("Gesture wakeup."); | |
3888 | } | |
3889 | doze_status = DOZE_DISABLED; | |
3890 | ||
3891 | mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM); | |
3892 | gtp_reset_guitar(client, 20); | |
3893 | ret = gup_reload_fw_dsp(NULL, GTP_FL_READ_REPAIR); | |
3894 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
3895 | if (ret == FAIL) { | |
3896 | GTP_ERROR("[gtp_wakeup_sleep]Reload dsp code failed."); | |
3897 | continue; | |
3898 | } | |
3899 | ret = gtp_fw_startup(client); | |
3900 | if (ret == FAIL) { | |
3901 | GTP_ERROR("[gtp_wakeup_sleep]Startup fw failed."); | |
3902 | continue; | |
3903 | } | |
3904 | if (!gtp_check_fw()) { | |
3905 | gtp_recovery_reset(client); | |
3906 | } | |
3907 | return 0; // succeed | |
3908 | //#else // else gesture wakeup | |
3909 | }else{ | |
3910 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 1); //wake up by int gpio | |
3911 | msleep(5); | |
3912 | ||
3913 | #if GTP_COMPATIBLE_MODE | |
3914 | if (CHIP_TYPE_GT9F == gtp_chip_type) { | |
3915 | u8 opr_buf[2] = {0}; | |
3916 | ||
3917 | ret = gtp_i2c_test(client); | |
3918 | if (ret >= 0) { | |
3919 | // Hold ss51 & dsp | |
3920 | opr_buf[0] = 0x0C; | |
3921 | ret = i2c_write_bytes(client, 0x4180, opr_buf, 1); | |
3922 | if (ret < 0) { | |
3923 | GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry); | |
3924 | continue; | |
3925 | } | |
3926 | ||
3927 | // Confirm hold | |
3928 | opr_buf[0] = 0x00; | |
3929 | ret = i2c_read_bytes(client, 0x4180, opr_buf, 1); | |
3930 | if (ret < 0) { | |
3931 | GTP_DEBUG("confirm ss51 & dsp hold, I2C error,retry:%d", retry); | |
3932 | continue; | |
3933 | } | |
3934 | if (0x0C != opr_buf[0]) { | |
3935 | GTP_DEBUG("ss51 & dsp not hold, val: %d, retry: %d", opr_buf[0], retry); | |
3936 | continue; | |
3937 | } | |
3938 | GTP_DEBUG("ss51 & dsp has been hold"); | |
3939 | ||
3940 | ret = gtp_fw_startup(client); | |
3941 | if (FAIL == ret) { | |
3942 | GTP_ERROR("[gtp_wakeup_sleep]Startup fw failed."); | |
3943 | continue; | |
3944 | } | |
3945 | GTP_INFO("flashless wakeup sleep success"); | |
3946 | return ret; | |
3947 | } | |
3948 | force_reset_guitar(0); | |
3949 | retry = 0; | |
3950 | break; | |
3951 | } | |
3952 | //#endif // end compatible mode | |
3953 | } | |
3954 | ret = gtp_i2c_test(client); | |
3955 | if (ret >= 0) | |
3956 | { | |
3957 | GTP_INFO("GTP wakeup sleep."); | |
3958 | //#if (!GTP_GESTURE_WAKEUP) | |
3959 | if(!(gesture_value > 0)) | |
3960 | { | |
3961 | gtp_int_sync(25); | |
3962 | } | |
3963 | //#endif | |
3964 | return ret; | |
3965 | } | |
3966 | gtp_reset_guitar(client, 20); | |
3967 | #endif // end gesture wakeup | |
3968 | } | |
3969 | ||
3970 | if (retry >= 5) { | |
3971 | GTP_ERROR("wakeup retry timeout, process esd reset"); | |
3972 | force_reset_guitar(0); | |
3973 | } | |
3974 | #endif // end PowerCtrlSleep | |
3975 | GTP_ERROR("GTP wakeup sleep failed."); | |
3976 | return ret; | |
3977 | } | |
3978 | ||
3979 | /* Function to manage low power suspend */ | |
3980 | static void tpd_suspend(struct early_suspend *h) | |
3981 | { | |
3982 | s32 ret = -1; | |
3983 | ||
3984 | GTP_INFO("System suspend."); | |
3985 | ||
3986 | #ifdef TPD_PROXIMITY | |
3987 | ||
3988 | if (tpd_proximity_flag == 1) | |
3989 | { | |
3990 | return ; | |
3991 | } | |
3992 | ||
3993 | #endif | |
3994 | #if (GTP_COMPATIBLE_MODE && GTP_FL_LITTLE_SYSTEM) | |
3995 | little_fw_mode = 0; | |
3996 | power_is_down = 1; | |
3997 | #endif | |
3998 | ||
3999 | tpd_halt = 1; | |
4000 | #if GTP_ESD_PROTECT | |
4001 | gtp_esd_switch(i2c_client_point, SWITCH_OFF); | |
4002 | #endif | |
4003 | //#if GTP_GESTURE_WAKEUP | |
4004 | if(gesture_value > 0){ | |
4005 | ret = gtp_enter_doze(i2c_client_point); | |
4006 | //#else | |
4007 | }else{ | |
4008 | mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM); | |
4009 | ret = gtp_enter_sleep(i2c_client_point); | |
4010 | //#endif | |
4011 | } | |
4012 | if (ret < 0) | |
4013 | { | |
4014 | GTP_ERROR("GTP early suspend failed."); | |
4015 | } | |
4016 | // to avoid waking up while not sleeping, delay 48 + 10ms to ensure reliability | |
4017 | msleep(58); | |
4018 | } | |
4019 | ||
4020 | /* Function to manage power-on resume */ | |
4021 | static void tpd_resume(struct early_suspend *h) | |
4022 | { | |
4023 | s32 ret = -1; | |
4024 | ||
4025 | GTP_INFO("System resume."); | |
4026 | ||
4027 | #ifdef TPD_PROXIMITY | |
4028 | ||
4029 | if (tpd_proximity_flag == 1) | |
4030 | { | |
4031 | return ; | |
4032 | } | |
4033 | ||
4034 | #endif | |
4035 | tpd_sleep_flag = 0; | |
4036 | ret = gtp_wakeup_sleep(i2c_client_point); | |
4037 | ||
4038 | if (ret < 0) | |
4039 | { | |
4040 | GTP_ERROR("GTP later resume failed."); | |
4041 | } | |
4042 | ||
4043 | #if GTP_COMPATIBLE_MODE | |
4044 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
4045 | { | |
4046 | // do nothing | |
4047 | } | |
4048 | else | |
4049 | #endif | |
4050 | { | |
4051 | gtp_send_cfg(i2c_client_point); | |
4052 | } | |
4053 | ||
4054 | #if GTP_CHARGER_SWITCH | |
4055 | gtp_charger_switch(1); // force update | |
4056 | #endif | |
4057 | ||
4058 | tpd_halt = 0; | |
4059 | //#if GTP_GESTURE_WAKEUP | |
4060 | if(gesture_value > 0){ | |
4061 | doze_status = DOZE_DISABLED; | |
4062 | //#else | |
4063 | }else{ | |
4064 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
4065 | //#endif | |
4066 | } | |
4067 | ||
4068 | #if GTP_ESD_PROTECT | |
4069 | gtp_init_ext_watchdog(i2c_client_point); | |
4070 | gtp_esd_switch(i2c_client_point, SWITCH_ON); | |
4071 | #endif | |
4072 | ||
4073 | } | |
4074 | ||
4075 | static struct tpd_driver_t tpd_device_driver = | |
4076 | { | |
4077 | .tpd_device_name = "gt9xx", | |
4078 | .tpd_local_init = tpd_local_init, | |
4079 | .suspend = tpd_suspend, | |
4080 | .resume = tpd_resume, | |
4081 | #ifdef TPD_HAVE_BUTTON | |
4082 | .tpd_have_button = 1, | |
4083 | #else | |
4084 | .tpd_have_button = 0, | |
4085 | #endif | |
4086 | }; | |
4087 | ||
4088 | /* called when loaded into kernel */ | |
4089 | static int __init tpd_driver_init(void) | |
4090 | { | |
4091 | if(g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT || g_boot_mode == LOW_POWER_OFF_CHARGING_BOOT) //add by zero | |
4092 | return 0; | |
4093 | GTP_INFO("MediaTek gt91xx touch panel driver init\n"); | |
4094 | #ifdef I2C_BUS_NUMBER | |
4095 | i2c_register_board_info(I2C_BUS_NUMBER, &i2c_tpd, 1); | |
4096 | #else | |
4097 | i2c_register_board_info(0, &i2c_tpd, 1); | |
4098 | #endif | |
4099 | if (tpd_driver_add(&tpd_device_driver) < 0) | |
4100 | GTP_INFO("add generic driver failed\n"); | |
4101 | ||
4102 | return 0; | |
4103 | } | |
4104 | ||
4105 | /* should never be called */ | |
4106 | static void __exit tpd_driver_exit(void) | |
4107 | { | |
4108 | GTP_INFO("MediaTek gt91xx touch panel driver exit\n"); | |
4109 | tpd_driver_remove(&tpd_device_driver); | |
4110 | } | |
4111 | ||
4112 | module_init(tpd_driver_init); | |
4113 | module_exit(tpd_driver_exit); | |
4114 |