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