1 /* Copyright Statement:
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.
10 * MediaTek Inc. (C) 2012. All rights reserved.
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.
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.
38 * Release Date: 2013/08/28
39 * Contact: andrew@goodix.com, meta@goodix.com
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
48 * 1. pen/stylus support
49 * 2. slide wakeup, new esd optimization
52 * 1. read double check & fixed config support
53 * 2. other optimizations
56 * 1. compatible with GT9XXF
60 * 1. update gt9xx_config to compatible with Linux 3.10
62 * 3. pen separate input device, active-pen button support
63 * 4. coordinates & keys optimization
64 * 5. no longer support GT915S
67 * Special edition for GT910 flashless
70 * Special edition for GT910 flashless
71 * 1. modified to support gesture wakeup module
75 #include "tpd_custom_gt9xx.h"
76 #include <asm/ptrace.h>
79 #include "cust_gpio_usage.h"
82 #include <linux/hwmsensor.h>
83 #include <linux/hwmsen_dev.h>
84 #include <linux/sensors_io.h>
87 #if GTP_SUPPORT_I2C_DMA
88 #include <linux/dma-mapping.h>
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
;
96 int gtp_autotool_setting
;
97 EXPORT_SYMBOL(gtp_autotool_setting
);
98 extern struct tpd_device
*tpd
;
100 static int tpd_sleep_flag
= 0;
101 static int tpd_flag
= 0;
103 static struct task_struct
*thread
= NULL
;
104 static DECLARE_WAIT_QUEUE_HEAD(waiter
);
106 #ifdef TPD_HAVE_BUTTON
107 static int tpd_keys_local
[TPD_KEY_COUNT
] = TPD_KEYS
;
108 static int tpd_keys_dim_local
[TPD_KEY_COUNT
][4] = TPD_KEYS_DIM
;
117 static DOZE_T doze_status
= DOZE_DISABLED
;
118 static s8
gtp_enter_doze(struct i2c_client
*client
);
120 #if GTP_CHARGER_SWITCH
122 #define CHR_CON0 (0xF7000000+0x2FA00)
124 extern kal_bool
upmu_is_chr_det(void);
126 static void gtp_charger_switch(s32 dir_update
);
129 #if GTP_HAVE_TOUCH_KEY
130 const u16 touch_key_array
[] = GTP_KEY_TAB
;
131 #define GTP_MAX_KEY_NUM ( sizeof( touch_key_array )/sizeof( touch_key_array[0] ) )
134 #if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
135 static int tpd_wb_start_local
[TPD_WARP_CNT
] = TPD_WARP_START
;
136 static int tpd_wb_end_local
[TPD_WARP_CNT
] = TPD_WARP_END
;
139 #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
140 //static int tpd_calmat_local[8] = TPD_CALIBRATION_MATRIX;
141 static int tpd_def_calmat_local
[8] = TPD_CALIBRATION_MATRIX
;
144 #if GTP_SUPPORT_I2C_DMA
145 s32
i2c_dma_write(struct i2c_client
*client
, u16 addr
, u8
*txbuf
, s32 len
);
146 s32
i2c_dma_read(struct i2c_client
*client
, u16 addr
, u8
*rxbuf
, s32 len
);
148 static u8
*gpDMABuf_va
= NULL
;
149 static u32 gpDMABuf_pa
= 0;
152 s32
gtp_send_cfg(struct i2c_client
*client
);
153 void gtp_reset_guitar(struct i2c_client
*client
, s32 ms
);
154 static void tpd_eint_interrupt_handler(void);
155 static int touch_event_handler(void *unused
);
156 static int tpd_i2c_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
);
157 static int tpd_i2c_detect(struct i2c_client
*client
, struct i2c_board_info
*info
);
158 static int tpd_i2c_remove(struct i2c_client
*client
);
159 s32
gtp_i2c_read_dbl_check(struct i2c_client
*client
, u16 addr
, u8
*rxbuf
, int len
);
160 extern void mt_eint_unmask(unsigned int line
);
161 extern void mt_eint_mask(unsigned int line
);
163 #if GTP_CREATE_WR_NODE
164 extern s32
init_wr_node(struct i2c_client
*);
165 extern void uninit_wr_node(void);
168 #if (GTP_ESD_PROTECT || GTP_COMPATIBLE_MODE)
169 static s32
force_reset_guitar(s32
);
173 static int clk_tick_cnt
= 200;
176 extern unsigned char gtp_default_FW_fl
[];
177 static struct delayed_work gtp_esd_check_work
;
178 static struct workqueue_struct
*gtp_esd_check_workqueue
= NULL
;
179 static s32
gtp_init_ext_watchdog(struct i2c_client
*client
);
180 static void gtp_esd_check_func(struct work_struct
*);
181 void gtp_esd_switch(struct i2c_client
*client
, s32 on
);
185 #define TPD_PROXIMITY_VALID_REG 0x814E
186 #define TPD_PROXIMITY_ENABLE_REG 0x8042
187 static u8 tpd_proximity_flag
= 0;
188 static u8 tpd_proximity_detect
= 1;//0-->close ; 1--> far away
191 struct i2c_client
*i2c_client_point
= NULL
;
192 static const struct i2c_device_id tpd_i2c_id
[] = {{"gt9xx", 0}, {}};
193 static unsigned short force
[] = {0, 0xBA, I2C_CLIENT_END
, I2C_CLIENT_END
};
194 static const unsigned short *const forces
[] = { force
, NULL
};
195 //static struct i2c_client_address_data addr_data = { .forces = forces,};
196 static struct i2c_board_info __initdata i2c_tpd
= { I2C_BOARD_INFO("gt9xx", (0xBA >> 1))};
197 static struct i2c_driver tpd_i2c_driver
=
199 .probe
= tpd_i2c_probe
,
200 .remove
= tpd_i2c_remove
,
201 .detect
= tpd_i2c_detect
,
202 .driver
.name
= "gt9xx",
203 .id_table
= tpd_i2c_id
,
204 .address_list
= (const unsigned short *) forces
,
207 static u8 config
[GTP_CONFIG_MAX_LENGTH
+ GTP_ADDR_LENGTH
]
208 = {GTP_REG_CONFIG_DATA
>> 8, GTP_REG_CONFIG_DATA
& 0xff};
213 u16 pid
; //product id //
214 u16 vid
; //version id //
218 st_tpd_info tpd_info
;
222 u8 gtp_rawdiff_mode
= 0;
224 u8 grp_cfg_version
= 0;
226 u8 pnl_init_error
= 0;
229 struct input_dev
*pen_dev
;
232 #if GTP_COMPATIBLE_MODE
235 u8 gtp_ref_retries
= 0;
236 u8 gtp_clk_retries
= 0;
237 CHIP_TYPE_T gtp_chip_type
= CHIP_TYPE_GT9
;
238 u8 rqst_processing
= 0;
240 u8 after_912_1020
= 0;
243 //add by caoyang for ·À¶¶
244 //static struct timer_list buttons_timer;
245 //static DECLARE_WAIT_QUEUE_HEAD(button_waitq);
248 extern u8
gup_check_fs_mounted(char *path_name
);
249 extern u8
gup_clk_calibration(void);
250 extern int gup_reload_fw_dsp(void *dir
, u8 dwn_mode
);
251 extern s32
gup_fw_download_proc(void *dir
, u8 dwn_mode
);
252 void gtp_get_chip_type(struct i2c_client
*client
);
253 u8
gtp_fw_startup(struct i2c_client
*client
);
254 static u8
gtp_bak_ref_proc(struct i2c_client
*client
, u8 mode
);
255 static u8
gtp_main_clk_proc(struct i2c_client
*client
);
256 static void gtp_recovery_reset(struct i2c_client
*client
);
258 #if GTP_COMPATIBLE_MODE
259 u8 gtp_hopping_buf
[16] = {0};
262 #if GTP_FL_LITTLE_SYSTEM
263 u8 power_is_down
= 0;
264 u8 little_fw_mode
= 0;
265 u8 fw_block
= 0; // 0: not started, 1 ~ 11/12 ss51 seg a/b each 2K, 13: ss51 seg b, 10K/12K
266 u8 block_section
= 1; // 1 ~ 8, 2K total, 256 Bytes each
268 char symbolic_state1
[][20] = {"OTHERS", "BUFFER_FULL", "CHECK_COMPLETE", "CHECK_ERROR", "WAIT_CHECK", "OTHERS", "OTHERS", "OTHERS"};
269 char symbolic_state2
[][20] = {"OTHERS", "IS_A_SEG", "IS_B_SEG_FIRST", "IS_B_SEG_OTHER", "IS_B_SEG_LAST", "OTHERS", "OTHERS", "OTHERS"};
271 static void tpd_up(s32 x
, s32 y
, s32 id
);
272 extern u8
gup_burn_ss51_block(struct i2c_client
*client
, s32 block_section
, s32 fw_block
, u16
*fw_chksum
);
273 extern u8
gup_burn_ss51_seg_b(struct i2c_client
*client
, s32 size
, u16
*fw_chksum
);
278 /* proc file system */
279 s32
i2c_read_bytes(struct i2c_client
*client
, u16 addr
, u8
*rxbuf
, int len
);
280 s32
i2c_write_bytes(struct i2c_client
*client
, u16 addr
, u8
*txbuf
, int len
);
282 static ssize_t
gt91xx_config_read_proc(struct file
*, char __user
*, size_t, loff_t
*);
283 static ssize_t
gt91xx_config_write_proc(struct file
*, const char __user
*, size_t, loff_t
*);
285 static struct proc_dir_entry
*gt91xx_config_proc
= NULL
;
286 static const struct file_operations config_proc_ops
= {
287 .owner
= THIS_MODULE
,
288 .read
= gt91xx_config_read_proc
,
289 .write
= gt91xx_config_write_proc
,
292 #define VELOCITY_CUSTOM
293 #ifdef VELOCITY_CUSTOM
294 #include <linux/device.h>
295 #include <linux/miscdevice.h>
296 #include <asm/uaccess.h>
298 #ifndef TPD_VELOCITY_CUSTOM_X
299 #define TPD_VELOCITY_CUSTOM_X 10
301 #ifndef TPD_VELOCITY_CUSTOM_Y
302 #define TPD_VELOCITY_CUSTOM_Y 10
305 // for magnify velocity********************************************
306 #define TOUCH_IOC_MAGIC 'A'
308 #define TPD_GET_VELOCITY_CUSTOM_X _IO(TOUCH_IOC_MAGIC,0)
309 #define TPD_GET_VELOCITY_CUSTOM_Y _IO(TOUCH_IOC_MAGIC,1)
311 int g_v_magnify_x
= TPD_VELOCITY_CUSTOM_X
;
312 int g_v_magnify_y
= TPD_VELOCITY_CUSTOM_Y
;
313 static int tpd_misc_open(struct inode
*inode
, struct file
*file
)
315 return nonseekable_open(inode
, file
);
318 static int tpd_misc_release(struct inode
*inode
, struct file
*file
)
323 static long tpd_unlocked_ioctl(struct file
*file
, unsigned int cmd
,
331 if (_IOC_DIR(cmd
) & _IOC_READ
)
333 err
= !access_ok(VERIFY_WRITE
, (void __user
*)arg
, _IOC_SIZE(cmd
));
335 else if (_IOC_DIR(cmd
) & _IOC_WRITE
)
337 err
= !access_ok(VERIFY_READ
, (void __user
*)arg
, _IOC_SIZE(cmd
));
342 printk("tpd: access error: %08X, (%2d, %2d)\n", cmd
, _IOC_DIR(cmd
), _IOC_SIZE(cmd
));
348 case TPD_GET_VELOCITY_CUSTOM_X
:
349 data
= (void __user
*) arg
;
357 if (copy_to_user(data
, &g_v_magnify_x
, sizeof(g_v_magnify_x
)))
365 case TPD_GET_VELOCITY_CUSTOM_Y
:
366 data
= (void __user
*) arg
;
374 if (copy_to_user(data
, &g_v_magnify_y
, sizeof(g_v_magnify_y
)))
383 printk("tpd: unknown IOCTL: 0x%08x\n", cmd
);
393 static struct file_operations tpd_fops
=
395 // .owner = THIS_MODULE,
396 .open
= tpd_misc_open
,
397 .release
= tpd_misc_release
,
398 .unlocked_ioctl
= tpd_unlocked_ioctl
,
400 /*----------------------------------------------------------------------------*/
401 static struct miscdevice tpd_misc_device
=
403 .minor
= MISC_DYNAMIC_MINOR
,
404 .name
= "gt9xx_touch",
408 //**********************************************
411 static int tpd_i2c_detect(struct i2c_client
*client
, struct i2c_board_info
*info
)
413 strcpy(info
->type
, "mtk-tpd");
418 static s32
tpd_get_ps_value(void)
420 return tpd_proximity_detect
;
423 static s32
tpd_enable_ps(s32 enable
)
431 tpd_proximity_flag
= 1;
432 GTP_INFO("TPD proximity function to be on.");
437 tpd_proximity_flag
= 0;
438 GTP_INFO("TPD proximity function to be off.");
441 ret
= i2c_write_bytes(i2c_client_point
, TPD_PROXIMITY_ENABLE_REG
, &state
, 1);
445 GTP_ERROR("TPD %s proximity cmd failed.", state
? "enable" : "disable");
449 GTP_INFO("TPD proximity function %s success.", state
? "enable" : "disable");
453 s32
tpd_ps_operate(void *self
, u32 command
, void *buff_in
, s32 size_in
,
454 void *buff_out
, s32 size_out
, s32
*actualout
)
458 hwm_sensor_data
*sensor_data
;
463 if ((buff_in
== NULL
) || (size_in
< sizeof(int)))
465 GTP_ERROR("Set delay parameter error!");
473 if ((buff_in
== NULL
) || (size_in
< sizeof(int)))
475 GTP_ERROR("Enable sensor parameter error!");
480 value
= *(int *)buff_in
;
481 err
= tpd_enable_ps(value
);
486 case SENSOR_GET_DATA
:
487 if ((buff_out
== NULL
) || (size_out
< sizeof(hwm_sensor_data
)))
489 GTP_ERROR("Get sensor data parameter error!");
494 sensor_data
= (hwm_sensor_data
*)buff_out
;
495 sensor_data
->values
[0] = tpd_get_ps_value();
496 sensor_data
->value_divide
= 1;
497 sensor_data
->status
= SENSOR_STATUS_ACCURACY_MEDIUM
;
503 GTP_ERROR("proxmy sensor operate function no this parameter %d!\n", command
);
513 static ssize_t
gt91xx_config_read_proc(struct file
*file
, char __user
*page
, size_t size
, loff_t
*ppos
)
516 char temp_data
[GTP_CONFIG_MAX_LENGTH
+ 2] = {0};
519 if (*ppos
) // CMD call again
524 ptr
+= sprintf(ptr
, "==== GT9XX config init value====\n");
526 for (i
= 0 ; i
< GTP_CONFIG_MAX_LENGTH
; i
++)
528 ptr
+= sprintf(ptr
, "0x%02X ", config
[i
+ 2]);
531 ptr
+= sprintf(ptr
, "\n");
534 ptr
+= sprintf(ptr
, "\n");
536 ptr
+= sprintf(ptr
, "==== GT9XX config real value====\n");
537 i2c_read_bytes(i2c_client_point
, GTP_REG_CONFIG_DATA
, temp_data
, GTP_CONFIG_MAX_LENGTH
);
539 for (i
= 0 ; i
< GTP_CONFIG_MAX_LENGTH
; i
++)
541 ptr
+= sprintf(ptr
, "0x%02X ", temp_data
[i
]);
544 ptr
+= sprintf(ptr
, "\n");
550 static ssize_t
gt91xx_config_write_proc(struct file
*filp
, const char __user
*buffer
, size_t count
, loff_t
*off
)
554 GTP_DEBUG("write count %d\n", count
);
556 if (count
> GTP_CONFIG_MAX_LENGTH
)
558 GTP_ERROR("size not match [%d:%d]\n", GTP_CONFIG_MAX_LENGTH
, count
);
562 if (copy_from_user(&config
[2], buffer
, count
))
564 GTP_ERROR("copy from user fail\n");
568 ret
= gtp_send_cfg(i2c_client_point
);
569 abs_x_max
= (config
[RESOLUTION_LOC
+ 1] << 8) + config
[RESOLUTION_LOC
];
570 abs_y_max
= (config
[RESOLUTION_LOC
+ 3] << 8) + config
[RESOLUTION_LOC
+ 2];
571 int_type
= (config
[TRIGGER_LOC
]) & 0x03;
575 GTP_ERROR("send config failed.");
581 #if GTP_SUPPORT_I2C_DMA
582 s32
i2c_dma_read(struct i2c_client
*client
, u16 addr
, u8
*rxbuf
, s32 len
)
588 struct i2c_msg msg
[2] =
591 .addr
= (client
->addr
& I2C_MASK_FLAG
),
595 .timing
= I2C_MASTER_CLOCK
598 .addr
= (client
->addr
& I2C_MASK_FLAG
),
599 .ext_flag
= (client
->ext_flag
| I2C_ENEXT_FLAG
| I2C_DMA_FLAG
),
601 .buf
= (u8
*)gpDMABuf_pa
,
603 .timing
= I2C_MASTER_CLOCK
607 buffer
[0] = (addr
>> 8) & 0xFF;
608 buffer
[1] = addr
& 0xFF;
613 //GTP_DEBUG("dma i2c read: 0x%04X, %d bytes(s)", addr, len);
614 for (retry
= 0; retry
< 5; ++retry
)
616 ret
= i2c_transfer(client
->adapter
, &msg
[0], 2);
621 memcpy(rxbuf
, gpDMABuf_va
, len
);
624 GTP_ERROR("Dma I2C Read Error: 0x%04X, %d byte(s), err-code: %d", addr
, len
, ret
);
629 s32
i2c_dma_write(struct i2c_client
*client
, u16 addr
, u8
*txbuf
, s32 len
)
633 u8
*wr_buf
= gpDMABuf_va
;
637 .addr
= (client
->addr
& I2C_MASK_FLAG
),
638 .ext_flag
= (client
->ext_flag
| I2C_ENEXT_FLAG
| I2C_DMA_FLAG
),
640 .buf
= (u8
*)gpDMABuf_pa
,
642 .timing
= I2C_MASTER_CLOCK
645 wr_buf
[0] = (u8
)((addr
>> 8) & 0xFF);
646 wr_buf
[1] = (u8
)(addr
& 0xFF);
651 //GTP_DEBUG("dma i2c write: 0x%04X, %d bytes(s)", addr, len);
652 memcpy(wr_buf
+2, txbuf
, len
);
653 for (retry
= 0; retry
< 5; ++retry
)
655 ret
= i2c_transfer(client
->adapter
, &msg
, 1);
662 GTP_ERROR("Dma I2C Write Error: 0x%04X, %d byte(s), err-code: %d", addr
, len
, ret
);
666 s32
i2c_read_bytes_dma(struct i2c_client
*client
, u16 addr
, u8
*rxbuf
, s32 len
)
673 //GTP_DEBUG("Read bytes dma: 0x%04X, %d byte(s)", addr, len);
676 if (left
> GTP_DMA_MAX_TRANSACTION_LENGTH
)
678 read_len
= GTP_DMA_MAX_TRANSACTION_LENGTH
;
684 ret
= i2c_dma_read(client
, addr
, rd_buf
, read_len
);
687 GTP_ERROR("dma read failed");
698 s32
i2c_write_bytes_dma(struct i2c_client
*client
, u16 addr
, u8
*txbuf
, s32 len
)
706 //GTP_DEBUG("Write bytes dma: 0x%04X, %d byte(s)", addr, len);
709 if (left
> GTP_DMA_MAX_I2C_TRANSFER_SIZE
)
711 write_len
= GTP_DMA_MAX_I2C_TRANSFER_SIZE
;
717 ret
= i2c_dma_write(client
, addr
, wr_buf
, write_len
);
721 GTP_ERROR("dma i2c write failed!");
734 int i2c_read_bytes_non_dma(struct i2c_client
*client
, u16 addr
, u8
*rxbuf
, int len
)
736 u8 buffer
[GTP_ADDR_LENGTH
];
741 struct i2c_msg msg
[2] =
744 //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)),
745 .addr
= ((client
->addr
&I2C_MASK_FLAG
) | (I2C_PUSHPULL_FLAG
)),
748 .len
= GTP_ADDR_LENGTH
,
749 .timing
= I2C_MASTER_CLOCK
752 //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)),
753 .addr
= ((client
->addr
&I2C_MASK_FLAG
) | (I2C_PUSHPULL_FLAG
)),
755 .timing
= I2C_MASTER_CLOCK
762 //GTP_DEBUG("i2c_read_bytes to device %02X address %04X len %d\n", client->addr, addr, len);
766 buffer
[0] = ((addr
+ offset
) >> 8) & 0xFF;
767 buffer
[1] = (addr
+ offset
) & 0xFF;
769 msg
[1].buf
= &rxbuf
[offset
];
771 if (left
> MAX_TRANSACTION_LENGTH
)
773 msg
[1].len
= MAX_TRANSACTION_LENGTH
;
774 left
-= MAX_TRANSACTION_LENGTH
;
775 offset
+= MAX_TRANSACTION_LENGTH
;
785 while (i2c_transfer(client
->adapter
, &msg
[0], 2) != 2)
792 GTP_ERROR("I2C read 0x%X length=%d failed\n", addr
+ offset
, len
);
802 int i2c_read_bytes(struct i2c_client
*client
, u16 addr
, u8
*rxbuf
, int len
)
804 #if GTP_SUPPORT_I2C_DMA
805 return i2c_read_bytes_dma(client
, addr
, rxbuf
, len
);
807 return i2c_read_bytes_non_dma(client
, addr
, rxbuf
, len
);
811 s32
gtp_i2c_read(struct i2c_client
*client
, u8
*buf
, s32 len
)
814 u16 addr
= (buf
[0] << 8) + buf
[1];
816 ret
= i2c_read_bytes_non_dma(client
, addr
, &buf
[2], len
- 2);
824 //#if GTP_GESTURE_WAKEUP
825 if(gesture_value
> 0){
826 if (DOZE_ENABLED
== doze_status
)
832 #if GTP_COMPATIBLE_MODE
833 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
835 #if GTP_FL_LITTLE_SYSTEM
839 GTP_INFO("Little fw enabled, no esd reset.");
844 gtp_recovery_reset(client
);
850 gtp_reset_guitar(client
, 20);
857 s32
gtp_i2c_read_dbl_check(struct i2c_client
*client
, u16 addr
, u8
*rxbuf
, int len
)
860 u8 confirm_buf
[16] = {0};
865 memset(buf
, 0xAA, 16);
866 buf
[0] = (u8
)(addr
>> 8);
867 buf
[1] = (u8
)(addr
& 0xFF);
868 gtp_i2c_read(client
, buf
, len
+ 2);
870 memset(confirm_buf
, 0xAB, 16);
871 confirm_buf
[0] = (u8
)(addr
>> 8);
872 confirm_buf
[1] = (u8
)(addr
& 0xFF);
873 gtp_i2c_read(client
, confirm_buf
, len
+ 2);
875 if (!memcmp(buf
, confirm_buf
, len
+2))
877 memcpy(rxbuf
, confirm_buf
+2, len
);
881 GTP_ERROR("i2c read 0x%04X, %d bytes, double check failed!", addr
, len
);
885 int i2c_write_bytes_non_dma(struct i2c_client
*client
, u16 addr
, u8
*txbuf
, int len
)
887 u8 buffer
[MAX_TRANSACTION_LENGTH
];
894 //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)),
895 .addr
= ((client
->addr
&I2C_MASK_FLAG
) | (I2C_PUSHPULL_FLAG
)),
898 .timing
= I2C_MASTER_CLOCK
,
905 //GTP_DEBUG("i2c_write_bytes to device %02X address %04X len %d\n", client->addr, addr, len);
911 buffer
[0] = ((addr
+ offset
) >> 8) & 0xFF;
912 buffer
[1] = (addr
+ offset
) & 0xFF;
914 if (left
> MAX_I2C_TRANSFER_SIZE
)
916 memcpy(&buffer
[GTP_ADDR_LENGTH
], &txbuf
[offset
], MAX_I2C_TRANSFER_SIZE
);
917 msg
.len
= MAX_TRANSACTION_LENGTH
;
918 left
-= MAX_I2C_TRANSFER_SIZE
;
919 offset
+= MAX_I2C_TRANSFER_SIZE
;
923 memcpy(&buffer
[GTP_ADDR_LENGTH
], &txbuf
[offset
], left
);
924 msg
.len
= left
+ GTP_ADDR_LENGTH
;
928 //GTP_DEBUG("byte left %d offset %d\n", left, offset);
930 while (i2c_transfer(client
->adapter
, &msg
, 1) != 1)
938 GTP_ERROR("I2C write 0x%X%X length=%d failed\n", buffer
[0], buffer
[1], len
);
947 int i2c_write_bytes(struct i2c_client
*client
, u16 addr
, u8
*txbuf
, int len
)
949 #if GTP_SUPPORT_I2C_DMA
950 return i2c_write_bytes_dma(client
, addr
, txbuf
, len
);
952 return i2c_write_bytes_non_dma(client
, addr
, txbuf
, len
);
956 s32
gtp_i2c_write(struct i2c_client
*client
, u8
*buf
, s32 len
)
959 u16 addr
= (buf
[0] << 8) + buf
[1];
961 ret
= i2c_write_bytes_non_dma(client
, addr
, &buf
[2], len
- 2);
969 //#if GTP_GESTURE_WAKEUP
970 if(gesture_value
> 0){
971 if (DOZE_ENABLED
== doze_status
)
977 #if GTP_COMPATIBLE_MODE
978 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
980 #if GTP_FL_LITTLE_SYSTEM
984 GTP_INFO("Little fw enabled, no esd reset.");
989 gtp_recovery_reset(client
);
995 gtp_reset_guitar(client
, 20);
1003 /*******************************************************
1005 Send config Function.
1011 Executive outcomes.0--success,non-0--fail.
1012 *******************************************************/
1013 s32
gtp_send_cfg(struct i2c_client
*client
)
1017 #if GTP_DRIVER_SEND_CFG
1021 GTP_INFO("Ic fixed config, no config sent!");
1024 else if (pnl_init_error
)
1026 GTP_INFO("Error occurred in init_panel, no config sent!");
1030 GTP_INFO("Driver Send Config");
1031 for (retry
= 0; retry
< 5; retry
++)
1033 ret
= gtp_i2c_write(client
, config
, GTP_CONFIG_MAX_LENGTH
+ GTP_ADDR_LENGTH
);
1045 /*******************************************************
1047 Read goodix touchscreen version function.
1050 client: i2c client struct.
1051 version:address to store version info
1054 Executive outcomes.0---succeed.
1055 *******************************************************/
1056 s32
gtp_read_version(struct i2c_client
*client
, u16
*version
)
1060 u8 buf
[8] = {GTP_REG_VERSION
>> 8, GTP_REG_VERSION
& 0xff};
1064 ret
= gtp_i2c_read(client
, buf
, sizeof(buf
));
1068 GTP_ERROR("GTP read version failed");
1074 *version
= (buf
[7] << 8) | buf
[6];
1077 tpd_info
.vid
= *version
;
1078 tpd_info
.pid
= 0x00;
1080 for (i
= 0; i
< 4; i
++)
1082 if (buf
[i
+ 2] < 0x30)break;
1084 tpd_info
.pid
|= ((buf
[i
+ 2] - 0x30) << ((3 - i
) * 4));
1089 GTP_INFO("IC VERSION: %c%c%c_%02x%02x",
1090 buf
[2], buf
[3], buf
[4], buf
[7], buf
[6]);
1094 GTP_INFO("IC VERSION:%c%c%c%c_%02x%02x",
1095 buf
[2], buf
[3], buf
[4], buf
[5], buf
[7], buf
[6]);
1097 sprintf(tpd_firmware_version_val
,"%02x%02x",buf
[7], buf
[6]);
1098 tpd_firmware_version_val
[4] = '\0';
1099 printk(KERN_ERR
"caoyang test tpd_firmware_version_val:%s",tpd_firmware_version_val
);
1103 #if GTP_DRIVER_SEND_CFG
1104 /*******************************************************
1106 Get information from ic, such as resolution and
1109 client: i2c client private struct.
1112 FAIL: i2c failed, SUCCESS: i2c ok
1113 *******************************************************/
1114 static s32
gtp_get_info(struct i2c_client
*client
)
1116 u8 opr_buf
[6] = {0};
1119 opr_buf
[0] = (u8
)((GTP_REG_CONFIG_DATA
+1) >> 8);
1120 opr_buf
[1] = (u8
)((GTP_REG_CONFIG_DATA
+1) & 0xFF);
1122 ret
= gtp_i2c_read(client
, opr_buf
, 6);
1128 abs_x_max
= (opr_buf
[3] << 8) + opr_buf
[2];
1129 abs_y_max
= (opr_buf
[5] << 8) + opr_buf
[4];
1131 opr_buf
[0] = (u8
)((GTP_REG_CONFIG_DATA
+6) >> 8);
1132 opr_buf
[1] = (u8
)((GTP_REG_CONFIG_DATA
+6) & 0xFF);
1134 ret
= gtp_i2c_read(client
, opr_buf
, 3);
1139 int_type
= opr_buf
[2] & 0x03;
1141 GTP_INFO("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x",
1142 abs_x_max
,abs_y_max
, int_type
);
1149 /*******************************************************
1151 GTP initialize function.
1154 client: i2c client private struct.
1157 Executive outcomes.0---succeed.
1158 *******************************************************/
1159 static s32
gtp_init_panel(struct i2c_client
*client
)
1163 #if GTP_DRIVER_SEND_CFG
1169 u8 cfg_info_group1
[] = CTP_CFG_GROUP1
;
1170 u8 cfg_info_group2
[] = CTP_CFG_GROUP2
;
1171 u8 cfg_info_group3
[] = CTP_CFG_GROUP3
;
1172 u8 cfg_info_group4
[] = CTP_CFG_GROUP4
;
1173 u8 cfg_info_group5
[] = CTP_CFG_GROUP5
;
1174 u8 cfg_info_group6
[] = CTP_CFG_GROUP6
;
1175 u8
*send_cfg_buf
[] = {cfg_info_group1
, cfg_info_group2
, cfg_info_group3
,
1176 cfg_info_group4
, cfg_info_group5
, cfg_info_group6
};
1177 u8 cfg_info_len
[] = { CFG_GROUP_LEN(cfg_info_group1
),
1178 CFG_GROUP_LEN(cfg_info_group2
),
1179 CFG_GROUP_LEN(cfg_info_group3
),
1180 CFG_GROUP_LEN(cfg_info_group4
),
1181 CFG_GROUP_LEN(cfg_info_group5
),
1182 CFG_GROUP_LEN(cfg_info_group6
)};
1184 GTP_DEBUG("Config Groups\' Lengths: %d, %d, %d, %d, %d, %d",
1185 cfg_info_len
[0], cfg_info_len
[1], cfg_info_len
[2], cfg_info_len
[3],
1186 cfg_info_len
[4], cfg_info_len
[5]);
1188 if ((!cfg_info_len
[1]) && (!cfg_info_len
[2]) &&
1189 (!cfg_info_len
[3]) && (!cfg_info_len
[4]) &&
1196 #if GTP_COMPATIBLE_MODE
1197 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
1202 ret
= gtp_i2c_read_dbl_check(client
, GTP_REG_SENSOR_ID
, &sensor_id
, 1);
1205 if (sensor_id
>= 0x06)
1207 GTP_ERROR("Invalid sensor_id(0x%02X), No Config Sent!", sensor_id
);
1214 GTP_ERROR("Failed to get sensor_id, No config sent!");
1218 GTP_INFO("Sensor_ID: %d", sensor_id
);
1221 cfg_len
= cfg_info_len
[sensor_id
];
1222 tpd_config_version
= send_cfg_buf
[sensor_id
][0];
1223 GTP_INFO("CTP_CONFIG_GROUP%d used, config length: %d", sensor_id
+ 1, cfg_len
);
1225 if (cfg_len
< GTP_CONFIG_MIN_LENGTH
)
1227 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);
1232 #if GTP_COMPATIBLE_MODE
1233 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
1240 ret
= gtp_i2c_read_dbl_check(client
, GTP_REG_CONFIG_DATA
, &opr_buf
[0], 1);
1244 GTP_DEBUG("CFG_CONFIG_GROUP%d Config Version: %d, 0x%02X; IC Config Version: %d, 0x%02X", sensor_id
+1,
1245 send_cfg_buf
[sensor_id
][0], send_cfg_buf
[sensor_id
][0], opr_buf
[0], opr_buf
[0]);
1247 if (opr_buf
[0] < 90)
1249 grp_cfg_version
= send_cfg_buf
[sensor_id
][0]; // backup group config version
1250 send_cfg_buf
[sensor_id
][0] = 0x00;
1253 else // treated as fixed config, not send config
1255 GTP_INFO("Ic fixed config with config version(%d)", opr_buf
[0]);
1257 gtp_get_info(client
);
1263 GTP_ERROR("Failed to get ic config version!No config sent!");
1268 memset(&config
[GTP_ADDR_LENGTH
], 0, GTP_CONFIG_MAX_LENGTH
);
1269 memcpy(&config
[GTP_ADDR_LENGTH
], send_cfg_buf
[sensor_id
], cfg_len
);
1272 config
[RESOLUTION_LOC
] = (u8
)GTP_MAX_WIDTH
;
1273 config
[RESOLUTION_LOC
+ 1] = (u8
)(GTP_MAX_WIDTH
>>8);
1274 config
[RESOLUTION_LOC
+ 2] = (u8
)GTP_MAX_HEIGHT
;
1275 config
[RESOLUTION_LOC
+ 3] = (u8
)(GTP_MAX_HEIGHT
>>8);
1277 if (GTP_INT_TRIGGER
== 0) //RISING
1279 config
[TRIGGER_LOC
] &= 0xfe;
1281 else if (GTP_INT_TRIGGER
== 1) //FALLING
1283 config
[TRIGGER_LOC
] |= 0x01;
1285 #endif // GTP_CUSTOM_CFG
1288 for (i
= GTP_ADDR_LENGTH
; i
< cfg_len
; i
++)
1290 check_sum
+= config
[i
];
1292 config
[cfg_len
] = (~check_sum
) + 1;
1294 #else // DRIVER NOT SEND CONFIG
1295 cfg_len
= GTP_CONFIG_MAX_LENGTH
;
1296 ret
= gtp_i2c_read(client
, config
, cfg_len
+ GTP_ADDR_LENGTH
);
1299 GTP_ERROR("Read Config Failed, Using DEFAULT Resolution & INT Trigger!");
1300 abs_x_max
= GTP_MAX_WIDTH
;
1301 abs_y_max
= GTP_MAX_HEIGHT
;
1302 int_type
= GTP_INT_TRIGGER
;
1304 #endif // GTP_DRIVER_SEND_CFG
1307 if ((abs_x_max
== 0) && (abs_y_max
== 0))
1309 abs_x_max
= (config
[RESOLUTION_LOC
+ 1] << 8) + config
[RESOLUTION_LOC
];
1310 abs_y_max
= (config
[RESOLUTION_LOC
+ 3] << 8) + config
[RESOLUTION_LOC
+ 2];
1311 int_type
= (config
[TRIGGER_LOC
]) & 0x03;
1314 #if GTP_COMPATIBLE_MODE
1315 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
1320 driver_num
= config
[GTP_REG_MATRIX_DRVNUM
- GTP_REG_CONFIG_DATA
+ 2];
1321 sensor_num
= config
[GTP_REG_MATRIX_SENNUM
- GTP_REG_CONFIG_DATA
+ 2];
1325 driver_num
= (config
[CFG_LOC_DRVA_NUM
]&0x1F) + (config
[CFG_LOC_DRVB_NUM
]&0x1F);
1326 sensor_num
= (config
[CFG_LOC_SENS_NUM
]&0x0F) + ((config
[CFG_LOC_SENS_NUM
]>>4)&0x0F);
1329 have_key
= config
[GTP_REG_HAVE_KEY
- GTP_REG_CONFIG_DATA
+ 2] & 0x01; // have key or not
1335 if ((cfg_len
== 186) && after_912_1020
)
1337 GTP_DEBUG("Firmware after 912_1020, set config length to 228.");
1341 config
[GTP_ADDR_LENGTH
+ 226] = config
[GTP_ADDR_LENGTH
+ 184];
1343 memset(&config
[GTP_ADDR_LENGTH
+ 184], 0x00, 228 - 186);
1345 config
[GTP_ADDR_LENGTH
+ 227] = 0x01;
1348 tpd_x_line
= driver_num
;
1349 tpd_y_line
= sensor_num
;
1350 GTP_INFO("Driver * Sensor: %d * %d(Key: %d), X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x",
1351 driver_num
, sensor_num
, have_key
, abs_x_max
,abs_y_max
,int_type
);
1356 #if GTP_DRIVER_SEND_CFG
1357 ret
= gtp_send_cfg(client
);
1360 GTP_ERROR("Send config error.");
1362 // set config version to CTP_CFG_GROUP
1363 // for resume to send config
1364 config
[GTP_ADDR_LENGTH
] = grp_cfg_version
;
1366 for (i
= GTP_ADDR_LENGTH
; i
< cfg_len
; i
++)
1368 check_sum
+= config
[i
];
1370 config
[cfg_len
] = (~check_sum
) + 1;
1372 GTP_INFO("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x",
1373 abs_x_max
,abs_y_max
,int_type
);
1380 static s8
gtp_i2c_test(struct i2c_client
*client
)
1391 ret
= i2c_read_bytes(client
, GTP_REG_HW_INFO
, (u8
*)&hw_info
, sizeof(hw_info
));
1393 if ((!ret
) && (hw_info
== 0x00900600)) //20121212
1398 GTP_ERROR("GTP_REG_HW_INFO : %08X", hw_info
);
1399 GTP_ERROR("GTP i2c test failed time %d.", retry
);
1408 /*******************************************************
1410 Set INT pin as input for FW sync.
1413 If the INT is high, It means there is pull up resistor attached on the INT pin.
1414 Pull low the INT pin manaully for FW sync.
1415 *******************************************************/
1416 void gtp_int_sync(s32 ms
)
1418 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
1420 GTP_GPIO_AS_INT(GTP_INT_PORT
);
1423 void gtp_reset_guitar(struct i2c_client
*client
, s32 ms
)
1425 GTP_INFO("GTP RESET!\n");
1426 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 0);
1428 GTP_GPIO_OUTPUT(GTP_INT_PORT
, client
->addr
== 0x14);
1431 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 1);
1433 msleep(6); //must >= 6ms
1435 #if GTP_COMPATIBLE_MODE
1436 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
1444 gtp_init_ext_watchdog(i2c_client_point
);
1448 static int tpd_power_on(struct i2c_client
*client
)
1451 int reset_count
= 0;
1454 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 0);
1455 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
1460 mt_set_gpio_mode(GPIO_CTP_EN_PIN
, GPIO_CTP_EN_PIN_M_GPIO
);
1461 mt_set_gpio_dir(GPIO_CTP_EN_PIN
, GPIO_DIR_OUT
);
1462 mt_set_gpio_out(GPIO_CTP_EN_PIN
, GPIO_OUT_ONE
);
1464 #else // ( defined(MT6575) || defined(MT6577) || defined(MT6589) )
1466 #ifdef TPD_POWER_SOURCE_CUSTOM
1467 hwPowerOn(TPD_POWER_SOURCE_CUSTOM
, VOL_2800
, "TP");
1469 hwPowerOn(MT65XX_POWER_LDO_VGP2
, VOL_2800
, "TP");
1471 #ifdef TPD_POWER_SOURCE_1800
1472 hwPowerOn(TPD_POWER_SOURCE_1800
, VOL_1800
, "TP");
1477 gtp_reset_guitar(client
, 20);
1479 #if GTP_COMPATIBLE_MODE
1480 gtp_get_chip_type(client
);
1482 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
1484 ret
= gup_fw_download_proc(NULL
, GTP_FL_FW_BURN
);
1488 GTP_ERROR("[tpd_power_on]Download fw failed.");
1489 if(reset_count
++ < TPD_MAX_RESET_COUNT
)
1499 ret
= gtp_fw_startup(client
);
1502 GTP_ERROR("[tpd_power_on]Startup fw failed.");
1503 if(reset_count
++ < TPD_MAX_RESET_COUNT
)
1516 ret
= gtp_i2c_test(client
);
1520 GTP_ERROR("I2C communication ERROR!");
1522 if (reset_count
< TPD_MAX_RESET_COUNT
)
1532 //**************** For GT9XXF Start ********************//
1533 #if GTP_COMPATIBLE_MODE
1536 void gtp_get_chip_type(struct i2c_client
*client
)
1538 u8 opr_buf
[10] = {0x00};
1543 ret
= gtp_i2c_read_dbl_check(client
, GTP_REG_CHIP_TYPE
, opr_buf
, 10);
1547 GTP_ERROR("Failed to get chip-type, set chip type default: GOODIX_GT9");
1548 gtp_chip_type
= CHIP_TYPE_GT9
;
1552 if (!memcmp(opr_buf
, "GOODIX_GT9", 10))
1554 gtp_chip_type
= CHIP_TYPE_GT9
;
1558 gtp_chip_type
= CHIP_TYPE_GT9F
;
1560 GTP_INFO("Chip Type: %s", (gtp_chip_type
== CHIP_TYPE_GT9
) ? "GOODIX_GT9" : "GOODIX_GT9F");
1563 static u8
gtp_bak_ref_proc(struct i2c_client
*client
, u8 mode
)
1568 struct file
*flp
= NULL
;
1571 u32 ref_seg_len
= 0;
1576 GTP_DEBUG("[gtp_bak_ref_proc]Driver:%d,Sensor:%d.", driver_num
, sensor_num
);
1578 //check file-system mounted
1579 GTP_DEBUG("[gtp_bak_ref_proc]Waiting for FS %d", gtp_ref_retries
);
1580 if (gup_check_fs_mounted("/data") == FAIL
)
1582 GTP_DEBUG("[gtp_bak_ref_proc]/data not mounted");
1583 if(gtp_ref_retries
++ < GTP_CHK_FS_MNT_MAX
)
1590 GTP_DEBUG("[gtp_bak_ref_proc]/data mounted !!!!");
1595 ref_seg_len
= (driver_num
* (sensor_num
- 1) + 2) * 2;
1597 ref_len
= ref_seg_len
* 6; // for GT950, backup-reference for six segments
1601 ref_len
= driver_num
*(sensor_num
-2)*2 + 4;
1602 ref_seg_len
= ref_len
;
1606 refp
= (u8
*)kzalloc(ref_len
, GFP_KERNEL
);
1609 GTP_ERROR("Failed to allocate memory for reference buffer!");
1612 memset(refp
, 0, ref_len
);
1615 flp
= filp_open(GTP_BAK_REF_PATH
, O_RDWR
| O_CREAT
, 0666);
1618 GTP_ERROR("Failed to open/create %s.", GTP_BAK_REF_PATH
);
1619 if (GTP_BAK_REF_SEND
== mode
)
1621 goto default_bak_ref
;
1631 case GTP_BAK_REF_SEND
:
1633 flp
->f_op
->llseek(flp
, 0, SEEK_SET
);
1634 ret
= flp
->f_op
->read(flp
, (char *)refp
, ref_len
, &flp
->f_pos
);
1637 GTP_ERROR("Read ref file failed, send default bak ref.");
1638 goto default_bak_ref
;
1641 for (j
= 0; j
< ref_grps
; ++j
)
1644 for(i
=0; i
<ref_seg_len
-2; i
+=2)
1646 ref_chksum
+= ((refp
[i
+ j
* ref_seg_len
]<<8) + refp
[i
+ 1 + j
* ref_seg_len
]);
1649 GTP_DEBUG("Reference chksum:0x%04X", ref_chksum
&0xFF);
1650 tmp
= ref_chksum
+ (refp
[ref_seg_len
+ j
* ref_seg_len
-2]<<8) + refp
[ref_seg_len
+ j
* ref_seg_len
-1];
1653 GTP_DEBUG("Invalid checksum for reference, reset reference.");
1654 memset(&refp
[j
* ref_seg_len
], 0, ref_seg_len
);
1655 refp
[ref_seg_len
- 1 + j
* ref_seg_len
] = 0x01;
1659 if (j
== (ref_grps
- 1))
1661 GTP_INFO("Reference data in %s used.", GTP_BAK_REF_PATH
);
1666 ret
= i2c_write_bytes(client
, GTP_REG_BAK_REF
, refp
, ref_len
);
1669 GTP_ERROR("Write ref i2c error.");
1676 case GTP_BAK_REF_STORE
:
1678 ret
= i2c_read_bytes(client
, GTP_REG_BAK_REF
, refp
, ref_len
);
1681 GTP_ERROR("Read ref i2c error.");
1685 flp
->f_op
->llseek(flp
, 0, SEEK_SET
);
1686 flp
->f_op
->write(flp
, (char *)refp
, ref_len
, &flp
->f_pos
);
1691 GTP_ERROR("Invalid Argument(%d) for backup reference", mode
);
1700 for (j
= 0; j
< ref_grps
; ++j
)
1702 memset(&refp
[j
* ref_seg_len
], 0, ref_seg_len
);
1703 refp
[j
* ref_seg_len
+ ref_seg_len
- 1] = 0x01; // checksum = 1
1705 ret
= i2c_write_bytes(client
, GTP_REG_BAK_REF
, refp
, ref_len
);
1706 if (flp
&& !IS_ERR(flp
))
1708 GTP_INFO("Write backup-reference data into %s", GTP_BAK_REF_PATH
);
1709 flp
->f_op
->llseek(flp
, 0, SEEK_SET
);
1710 flp
->f_op
->write(flp
, (char*)refp
, ref_len
, &flp
->f_pos
);
1714 GTP_ERROR("Failed to load the default backup reference");
1726 if (flp
&& !IS_ERR(flp
))
1728 filp_close(flp
, NULL
);
1733 u8
gtp_fw_startup(struct i2c_client
*client
)
1740 ret
= i2c_write_bytes(client
, 0x8041, wr_buf
, 1);
1743 GTP_ERROR("I2C error to firmware startup.");
1746 //release SS51 & DSP
1748 i2c_write_bytes(client
, 0x4180, wr_buf
, 1);
1753 //check fw run status
1754 i2c_read_bytes(client
, 0x8041, wr_buf
, 1);
1755 if(0xAA == wr_buf
[0])
1757 GTP_ERROR("IC works abnormally,startup failed.");
1762 GTP_DEBUG("IC works normally,Startup success.");
1764 i2c_write_bytes(client
, 0x8041, wr_buf
, 1);
1770 static void gtp_recovery_reset(struct i2c_client
*client
)
1773 gtp_esd_switch(client
, SWITCH_OFF
);
1775 force_reset_guitar(0);
1777 gtp_esd_switch(client
, SWITCH_ON
);
1781 static u8
gtp_check_clk_legality(u8
*p_clk_buf
)
1784 u8 clk_chksum
= p_clk_buf
[5];
1786 for(i
= 0; i
< 5; i
++)
1788 if((p_clk_buf
[i
] < 50) || (p_clk_buf
[i
] > 120) ||
1789 (p_clk_buf
[i
] != p_clk_buf
[0]))
1793 clk_chksum
+= p_clk_buf
[i
];
1796 if((i
== 5) && (clk_chksum
== 0))
1798 GTP_DEBUG("Valid main clock data.");
1801 GTP_ERROR("Invalid main clock data.");
1805 static u8
gtp_main_clk_proc(struct i2c_client
*client
)
1809 u8 clk_cal_result
= 0;
1811 u8 gtp_clk_buf
[6] = {0};
1812 struct file
*flp
= NULL
;
1814 GTP_DEBUG("[gtp_main_clk_proc]Waiting for FS %d", gtp_ref_retries
);
1815 if (gup_check_fs_mounted("/data") == FAIL
)
1817 GTP_DEBUG("[gtp_main_clk_proc]/data not mounted");
1818 if(gtp_clk_retries
++ < GTP_CHK_FS_MNT_MAX
)
1824 GTP_ERROR("[gtp_main_clk_proc]Wait for file system timeout,need cal clk");
1829 GTP_DEBUG("[gtp_main_clk_proc]/data mounted !!!!");
1830 flp
= filp_open(GTP_MAIN_CLK_PATH
, O_RDWR
| O_CREAT
, 0666);
1833 flp
->f_op
->llseek(flp
, 0, SEEK_SET
);
1834 ret
= flp
->f_op
->read(flp
, (char *)gtp_clk_buf
, 6, &flp
->f_pos
);
1837 ret
= gtp_check_clk_legality(gtp_clk_buf
);
1840 GTP_DEBUG("[gtp_main_clk_proc]Open & read & check clk file success.");
1845 GTP_ERROR("[gtp_main_clk_proc]Check clk file failed,need cal clk");
1850 gtp_esd_switch(client
, SWITCH_OFF
);
1852 clk_cal_result
= gup_clk_calibration();
1853 force_reset_guitar(0);
1854 GTP_DEBUG("&&&&&&&&&&clk cal result:%d", clk_cal_result
);
1857 gtp_esd_switch(client
, SWITCH_ON
);
1860 if(clk_cal_result
< 50 || clk_cal_result
> 120)
1862 GTP_ERROR("Invalid main clock: %d", clk_cal_result
);
1867 for(i
= 0;i
< 5; i
++)
1869 gtp_clk_buf
[i
] = clk_cal_result
;
1870 clk_chksum
+= gtp_clk_buf
[i
];
1872 gtp_clk_buf
[5] = 0 - clk_chksum
;
1876 ret
= i2c_write_bytes(client
, 0x8020, gtp_clk_buf
, 6);
1878 if (flp
&& !IS_ERR(flp
))
1880 flp
->f_op
->llseek(flp
, 0, SEEK_SET
);
1881 flp
->f_op
->write(flp
, (char *)gtp_clk_buf
, 6, &flp
->f_pos
);
1886 GTP_ERROR("[gtp_main_clk_proc]send main clk i2c error!");
1895 if (flp
&& !IS_ERR(flp
))
1897 filp_close(flp
, NULL
);
1902 u8
gtp_verify_hopping_buf(struct i2c_client
*client
)
1907 for (i
= 0; i
< 6; i
+= 2)
1909 checksum
+= (gtp_hopping_buf
[i
] << 8) + gtp_hopping_buf
[i
+1];
1911 if ((checksum
+ ((u16
)(gtp_hopping_buf
[6] << 8) + (u16
)gtp_hopping_buf
[7])) & 0xFFFF)
1913 GTP_ERROR("Wrong checksum for hopping buffer, get hopping data from config instead!");
1914 goto get_config_hopping
;
1917 for (i
= 0; i
< 8; i
++)
1919 if (gtp_hopping_buf
[i
] != gtp_hopping_buf
[i
+8])
1921 GTP_ERROR("Hopping buffer is not identical, get data from config instead!");
1922 goto get_config_hopping
;
1925 GTP_DEBUG("Hopping buffer is okay");
1929 memcpy(gtp_hopping_buf
, &config
[2 + 0x8065 - GTP_REG_CONFIG_DATA
], 4);
1930 gtp_hopping_buf
[4] = 0xAA;
1931 gtp_hopping_buf
[5] = 0x55;
1934 for (i
= 0; i
< 6; i
+= 2)
1936 checksum
+= (gtp_hopping_buf
[i
] << 8) + gtp_hopping_buf
[i
+1];
1938 checksum
= 0 - checksum
;
1939 gtp_hopping_buf
[6] = (u8
)(checksum
>> 8);
1940 gtp_hopping_buf
[7] = (u8
)(checksum
& 0xFF);
1942 for (i
= 0; i
< 8; i
++)
1944 gtp_hopping_buf
[i
+8] = gtp_hopping_buf
[i
];
1949 u8
gtp_hopping_proc(struct i2c_client
*client
, s32 mode
)
1953 GTP_DEBUG("Store hopping data, wait for /data mounted.");
1955 ret
= gup_check_fs_mounted("/data");
1959 GTP_DEBUG("/data not mounted.");
1962 GTP_DEBUG("/data Mounted!");
1964 if (GTP_HOPPING_SEND
== mode
)
1966 gtp_verify_hopping_buf(client
);
1968 ret
= i2c_write_bytes(client
, 0x8030, gtp_hopping_buf
, 16);
1980 ret
= i2c_read_bytes(client
, 0x8030, gtp_hopping_buf
, 16);
1984 GTP_ERROR("Failed to read hopping data from hopping buffer, get from config instead.");
1987 return gtp_verify_hopping_buf(client
);
1991 #if GTP_FL_LITTLE_SYSTEM
1992 s32
gtp_resume_timeout(void *none
)
1995 GTP_DEBUG("Resume timeout thread kicks off.");
1997 while (timeout
++ < (10 * 10))
2000 if (!little_fw_mode
)
2002 GTP_DEBUG("Resume timeout thread terminated while counting.");
2009 GTP_INFO("Download big ss51 firmware timeout, process esd reset.");
2011 gtp_recovery_reset(i2c_client_point
);
2017 u8
gtp_get_state1(struct i2c_client
*client
)
2022 ret
= i2c_read_bytes(client
, GTP_REG_STATE1
, &state1
, 1);
2026 GTP_ERROR("Failed to get state1!");
2032 u8
gtp_get_state2(struct i2c_client
*client
)
2037 ret
= i2c_read_bytes(client
, GTP_REG_STATE2
, &state2
, 1);
2041 GTP_ERROR("Failed to get state2!");
2048 u8
gtp_send_check_info(struct i2c_client
*client
, u16 fw_chksum
)
2055 u16 start_addr
= 0x0000;
2056 u8 checkinfo_buf
[10] = {0};
2070 state1
= BUFFER_FULL
;
2072 start_addr
= (0xC000 + (fw_block
- 1) * 1024 * 2);
2077 state1
= BUFFER_FULL
;
2079 start_addr
= 0xF800;
2084 state1
= BUFFER_FULL
;
2086 start_addr
= 0xF000;
2091 state1
= BUFFER_FULL
;
2092 state2
= IS_B_SEG_FIRST
;
2093 start_addr
= 0xE800;
2098 state1
= WAIT_CHECK
;
2099 state2
= IS_B_SEG_LAST
;
2100 start_addr
= 0xC000;
2104 GTP_ERROR("Invalid firmware block(%d) for checkinfo.", fw_block
);
2108 checkinfo_buf
[3] = bank
;
2109 checkinfo_buf
[4] = (u8
)(start_addr
>> 8);
2110 checkinfo_buf
[5] = (u8
)(start_addr
& 0xFF);
2111 checkinfo_buf
[7] = state2
;
2112 checkinfo_buf
[8] = state1
;
2114 GTP_DEBUG("fw_block: %d, fw_chksum: 0x%04X", fw_block
, fw_chksum
);
2117 checkinfo_buf
[6] = 80;
2121 checkinfo_buf
[6] = 16;
2124 checkinfo_buf
[0] = (u8
)(fw_chksum
>> 8);
2125 checkinfo_buf
[1] = (u8
)(fw_chksum
& 0xFF);
2128 for (ret
= 0; ret
< 6; ret
++)
2130 checksum
+= checkinfo_buf
[3 + ret
];
2132 checkinfo_buf
[2] = 1 - checksum
;
2134 ret
= i2c_write_bytes(client
, GTP_REG_CHECKINFO
, checkinfo_buf
, 9);
2137 GTP_ERROR("Failed to send checkinfo!");
2142 GTP_DEBUG("Send checkinfo successfully!");
2149 u8
gtp_resume_fw_startup(struct i2c_client
*client
)
2155 GTP_INFO("Big ss51 firmware startup.");
2157 while (retry
++ < 10)
2160 ret
= i2c_write_bytes(client
, 0x4180, &buf
, 1); // hold ss51 & dsp
2163 GTP_ERROR("Failed to hold ss51 & dsp.");
2168 ret
= i2c_read_bytes(client
, 0x4180, &buf
, 1);
2171 GTP_ERROR("Failed to get hold ss51 & dsp status.");
2177 GTP_DEBUG("SS51 & Dsp confirm hold!");
2184 GTP_ERROR("Hold ss51 & dsp retry exhausted.");
2189 i2c_write_bytes(client
, 0x4048, &buf
, 1); // select bank3
2192 i2c_write_bytes(client
, 0x4049, &buf
, 1);
2194 return gtp_fw_startup(client
);
2197 u8
gtp_download_seg_b(struct i2c_client
*client
)
2203 if (block_section
!= 10)
2206 i2c_write_bytes(client
, 0x4048, &state1
, 1); // select bank0
2208 ret
= gup_burn_ss51_seg_b(client
, 10, &fw_chksum
);
2212 GTP_ERROR("Failed to burn ss51 seg B, process reburn.");
2216 ret
= gtp_send_check_info(i2c_client_point
, fw_chksum
);
2219 GTP_ERROR("Send checkinfo failed, process resend.");
2225 state1
= gtp_get_state1(client
);
2227 if (CHECK_COMPLETE
== state1
)
2229 GTP_INFO("Burn ss51 Block12 successfully");
2231 else if (CHECK_ERROR
== state1
)
2233 GTP_DEBUG("Big SS51 Seg B check error, process reburn!");
2238 GTP_ERROR("Big SS51 Seg B check imcomplete(state1:%s), process recheck.", symbolic_state1
[state1
&0x07]);
2242 ret
= gtp_resume_fw_startup(client
);
2247 GTP_ERROR("Big ss51 firmware startup failed, process esd reset.");
2250 gtp_recovery_reset(i2c_client_point
);
2255 GTP_INFO("Switch to big ss51 firmware successfully!");
2260 gtp_esd_switch(client
, SWITCH_ON
);
2267 u8
gtp_download_big_ss51(struct i2c_client
*client
)
2272 static u16 fw_chksum
= 0x0000;
2274 //GTP_DEBUG("Block: %d, Block Section: %d", fw_block, block_section);
2275 if (!little_fw_mode
)
2277 GTP_ERROR("Download big ss51 timeout!");
2281 if (block_section
== 10) // one firmware block burned
2288 state1
= gtp_get_state1(i2c_client_point
);
2289 state2
= gtp_get_state2(i2c_client_point
);
2291 GTP_DEBUG("state1: %02X (%s), state2: %02X (%s)", state1
, symbolic_state1
[state1
&0x07], state2
, symbolic_state2
[state2
&0x07]);
2293 if (CHECK_COMPLETE
== state1
)
2296 GTP_DEBUG("Burn ss51 Block%d successfully!", fw_block
);
2300 gtp_esd_switch(client
, SWITCH_OFF
);
2302 tpd_up(0, 0, 0); // release all
2303 input_sync(tpd
->dev
);
2304 GTP_DEBUG("Release touch manually.");
2306 for (i
= 0; i
< 5; i
++)
2308 if (!little_fw_mode
|| (fw_block
!= 12))
2310 GTP_ERROR("Download big ss51 timeout!");
2313 ret
= gtp_download_seg_b(client
);
2323 else if (CHECK_ERROR
== state1
)
2325 GTP_ERROR("Block%d check error, process reburn.", fw_block
);
2331 GTP_DEBUG("Block%d check incomplete, process recheck.", fw_block
);
2335 if (block_section
< 9)
2337 ret
= gup_burn_ss51_block(i2c_client_point
, block_section
, fw_block
+1, &fw_chksum
);
2340 GTP_ERROR("Burn block%d section%d failed, reburn block%d", fw_block
+1, block_section
, fw_block
+1);
2346 if (block_section
== 9) // one firmware block downloaded
2350 ret
= gtp_send_check_info(i2c_client_point
, fw_chksum
);
2358 //************* For GT9XXF End **********************//
2361 static void gtp_pen_init(void)
2365 pen_dev
= input_allocate_device();
2366 if (pen_dev
== NULL
)
2368 GTP_ERROR("Failed to allocate input device for pen/stylus.");
2372 pen_dev
->evbit
[0] = BIT_MASK(EV_SYN
) | BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
) ;
2373 pen_dev
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
2375 set_bit(BTN_TOOL_PEN
, pen_dev
->keybit
);
2376 set_bit(INPUT_PROP_DIRECT
, pen_dev
->propbit
);
2377 //set_bit(INPUT_PROP_POINTER, pen_dev->propbit);
2379 #if GTP_PEN_HAVE_BUTTON
2380 input_set_capability(pen_dev
, EV_KEY
, BTN_STYLUS
);
2381 input_set_capability(pen_dev
, EV_KEY
, BTN_STYLUS2
);
2384 input_set_abs_params(pen_dev
, ABS_MT_POSITION_X
, 0, TPD_RES_X
, 0, 0);
2385 input_set_abs_params(pen_dev
, ABS_MT_POSITION_Y
, 0, TPD_RES_Y
, 0, 0);
2386 input_set_abs_params(pen_dev
, ABS_MT_PRESSURE
, 0, 255, 0, 0);
2387 input_set_abs_params(pen_dev
, ABS_MT_TOUCH_MAJOR
, 0, 255, 0, 0);
2388 input_set_abs_params(pen_dev
, ABS_MT_TRACKING_ID
, 0, 255, 0, 0);
2390 pen_dev
->name
= "mtk-pen";
2391 pen_dev
->phys
= "input/ts";
2392 pen_dev
->id
.bustype
= BUS_I2C
;
2394 ret
= input_register_device(pen_dev
);
2397 GTP_ERROR("Register %s input device failed", pen_dev
->name
);
2402 static void gtp_pen_down(s32 x
, s32 y
, s32 size
, s32 id
)
2404 input_report_key(pen_dev
, BTN_TOOL_PEN
, 1);
2405 input_report_key(pen_dev
, BTN_TOUCH
, 1);
2406 input_report_abs(pen_dev
, ABS_MT_POSITION_X
, x
);
2407 input_report_abs(pen_dev
, ABS_MT_POSITION_Y
, y
);
2408 if ((!size
) && (!id
))
2410 input_report_abs(pen_dev
, ABS_MT_PRESSURE
, 100);
2411 input_report_abs(pen_dev
, ABS_MT_TOUCH_MAJOR
, 100);
2415 input_report_abs(pen_dev
, ABS_MT_PRESSURE
, size
);
2416 input_report_abs(pen_dev
, ABS_MT_TOUCH_MAJOR
, size
);
2417 input_report_abs(pen_dev
, ABS_MT_TRACKING_ID
, id
);
2419 input_mt_sync(pen_dev
);
2422 static void gtp_pen_up(void)
2424 input_report_key(pen_dev
, BTN_TOOL_PEN
, 0);
2425 input_report_key(pen_dev
, BTN_TOUCH
, 0);
2430 static s32
tpd_i2c_probe_next(struct i2c_client
*client
)
2438 ret
= tpd_power_on(client
);
2442 GTP_ERROR("I2C communication ERROR!");
2445 ret
= gtp_read_version(client
, &version_info
);
2449 GTP_ERROR("Read version failed.");
2452 ret
= gtp_init_panel(client
);
2456 GTP_ERROR("GTP init panel failed.");
2459 #if GTP_CREATE_WR_NODE
2460 init_wr_node(client
);
2462 thread
= kthread_run(touch_event_handler
, 0, TPD_DEVICE
);
2467 err
= PTR_ERR(thread
);
2468 GTP_ERROR(TPD_DEVICE
" failed to create kernel thread: %d\n", err
);
2471 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
2474 ret
= gup_init_update_proc(client
);
2478 GTP_ERROR("Create update thread error.");
2483 gtp_esd_switch(client
, SWITCH_ON
);
2490 static ssize_t
cfg_load_enable_store(struct device
*dev
,
2491 struct device_attribute
*attr
,
2492 const char *buf
, size_t count
)
2494 tpd_i2c_probe_next(i2c_client_point
);
2497 static ssize_t
cfg_load_enable_show(struct device
*dev
,
2498 struct device_attribute
*attr
,
2499 const char *buf
, size_t count
)
2503 static DEVICE_ATTR(cfg_load_enable
, S_IRUGO
|S_IWUSR
, cfg_load_enable_show
, cfg_load_enable_store
);
2505 static struct miscdevice cfg_misc_device
=
2507 .minor
= MISC_DYNAMIC_MINOR
,
2509 // .fops = &tpd_fops,
2513 static void buttons_timer_function(unsigned long data
)
2515 printk(KERN_ERR
"caoyang1\n");
2516 input_report_key(tpd
->dev
, KEY_POWER
, 1);
2517 input_sync(tpd
->dev
);
2518 input_report_key(tpd
->dev
, KEY_POWER
, 0);
2519 input_sync(tpd
->dev
);
2525 static s32
tpd_i2c_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
2531 #if GTP_HAVE_TOUCH_KEY
2534 #ifdef TPD_PROXIMITY
2535 struct hwmsen_object obj_ps
;
2538 i2c_client_point
= client
;
2539 //add by caoyang for ·À¶¶
2540 //do not use the timer because it cause bug
2542 init_timer(&buttons_timer
);
2543 buttons_timer
.function
= buttons_timer_function
;
2544 add_timer(&buttons_timer
);
2547 ret
= tpd_power_on(client
);
2551 GTP_ERROR("I2C communication ERROR!");
2554 #ifdef VELOCITY_CUSTOM
2556 if ((err
= misc_register(&tpd_misc_device
)))
2558 printk("mtk_tpd: tpd_misc_device register failed\n");
2563 ret
= gtp_read_version(client
, &version_info
);
2567 GTP_ERROR("Read version failed.");
2570 ret
= gtp_init_panel(client
);
2574 GTP_ERROR("GTP init panel failed.");
2577 // Create proc file system
2578 gt91xx_config_proc
= proc_create(GT91XX_CONFIG_PROC_FILE
, 0666, NULL
, &config_proc_ops
);
2579 if (gt91xx_config_proc
== NULL
)
2581 GTP_ERROR("create_proc_entry %s failed\n", GT91XX_CONFIG_PROC_FILE
);
2585 GTP_INFO("create proc entry %s success", GT91XX_CONFIG_PROC_FILE
);
2588 #if GTP_CREATE_WR_NODE
2589 init_wr_node(client
);
2592 thread
= kthread_run(touch_event_handler
, 0, TPD_DEVICE
);
2597 err
= PTR_ERR(thread
);
2598 GTP_ERROR(TPD_DEVICE
" failed to create kernel thread: %d\n", err
);
2603 #if GTP_HAVE_TOUCH_KEY
2605 for (idx
= 0; idx
< GTP_MAX_KEY_NUM
; idx
++)
2607 input_set_capability(tpd
->dev
, EV_KEY
, touch_key_array
[idx
]);
2611 input_set_capability(tpd
->dev
, EV_KEY
, KEY_POWER
);
2617 mt_set_gpio_mode(GPIO_CTP_EINT_PIN
, GPIO_CTP_EINT_PIN_M_EINT
);
2618 mt_set_gpio_dir(GPIO_CTP_EINT_PIN
, GPIO_DIR_IN
);
2619 mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN
, GPIO_PULL_DISABLE
);
2624 if (!int_type
) //EINTF_TRIGGER
2626 mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM
, EINTF_TRIGGER_RISING
, tpd_eint_interrupt_handler
, 1);
2630 mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM
, EINTF_TRIGGER_FALLING
, tpd_eint_interrupt_handler
, 1);
2636 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
2639 ret
= gup_init_update_proc(client
);
2643 GTP_ERROR("Create update thread error.");
2647 #ifdef TPD_PROXIMITY
2648 //obj_ps.self = cm3623_obj;
2649 obj_ps
.polling
= 0; //0--interrupt mode;1--polling mode;
2650 obj_ps
.sensor_operate
= tpd_ps_operate
;
2652 if ((err
= hwmsen_attach(ID_PROXIMITY
, &obj_ps
)))
2654 GTP_ERROR("hwmsen attach fail, return:%d.", err
);
2660 gtp_esd_switch(client
, SWITCH_ON
);
2663 tpd_load_status
= 1;
2665 misc_register(&cfg_misc_device
);
2666 device_create_file(cfg_misc_device
.this_device
, &dev_attr_cfg_load_enable
);
2667 tpd_load_status
= 1;
2672 static void tpd_eint_interrupt_handler(void)
2674 TPD_DEBUG_PRINT_INT
;
2678 wake_up_interruptible(&waiter
);
2680 static int tpd_i2c_remove(struct i2c_client
*client
)
2682 #if GTP_CREATE_WR_NODE
2687 destroy_workqueue(gtp_esd_check_workqueue
);
2692 #if (GTP_ESD_PROTECT || GTP_COMPATIBLE_MODE)
2693 static s32
force_reset_guitar(s32 resume
)
2700 GTP_INFO("Force_reset_guitar");
2704 GTP_INFO("Download little system.");
2707 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
2709 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 0);
2710 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
2713 mt_set_gpio_mode(GPIO_CTP_EN_PIN
, GPIO_CTP_EN_PIN_M_GPIO
);
2714 mt_set_gpio_dir(GPIO_CTP_EN_PIN
, GPIO_DIR_OUT
);
2715 mt_set_gpio_out(GPIO_CTP_EN_PIN
, GPIO_OUT_ZERO
);
2718 mt_set_gpio_out(GPIO_CTP_EN_PIN
, GPIO_OUT_ONE
);
2720 #else // ( defined(MT6575) || defined(MT6577) || defined(MT6589) )
2722 #ifdef TPD_POWER_SOURCE_CUSTOM
2723 hwPowerDown(TPD_POWER_SOURCE_CUSTOM
, "TP");
2725 hwPowerDown(MT65XX_POWER_LDO_VGP2
, "TP");
2730 #ifdef TPD_POWER_SOURCE_CUSTOM
2731 hwPowerOn(TPD_POWER_SOURCE_CUSTOM
, VOL_2800
, "TP");
2733 hwPowerOn(MT65XX_POWER_LDO_VGP2
, VOL_2800
, "TP");
2739 for (i
= 0; i
< 5; i
++)
2741 #if GTP_COMPATIBLE_MODE
2742 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
2744 #if GTP_FL_LITTLE_SYSTEM
2746 if (resume
) // poweroff resume
2748 ret
= gup_fw_download_proc(NULL
, GTP_FL_PWR_RESUME_BURN
);
2751 GTP_ERROR("Failed to download little system.");
2758 ret
= gup_fw_download_proc(NULL
, GTP_FL_ESD_RECOVERY
);
2762 GTP_ERROR("[force_reset_guitar]Check & repair fw failed.");
2766 ret
= gtp_fw_startup(i2c_client_point
);
2771 GTP_ERROR("Failed to startup little system.");
2775 GTP_ERROR("GT9XXF start up failed.");
2785 gtp_reset_guitar(i2c_client_point
, 20);
2788 ret
= gtp_send_cfg(i2c_client_point
);
2802 GTP_ERROR("Failed to download little system.");
2806 GTP_ERROR("Failed to reset guitar.");
2808 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
2811 #if (GTP_COMPATIBLE_MODE && GTP_FL_LITTLE_SYSTEM)
2812 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
2821 gtp_main_clk_proc(i2c_client_point
);
2822 gtp_hopping_proc(i2c_client_point
, GTP_HOPPING_SEND
);
2823 gtp_bak_ref_proc(i2c_client_point
, GTP_BAK_REF_SEND
);
2834 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
2840 static s32
gtp_init_ext_watchdog(struct i2c_client
*client
)
2842 u8 opr_buffer
[2] = {0xAA};
2843 GTP_DEBUG("Init external watchdog.");
2844 return i2c_write_bytes(client
, 0x8041, opr_buffer
, 1);
2847 void gtp_esd_switch(struct i2c_client
*client
, s32 on
)
2849 spin_lock(&esd_lock
);
2850 if (SWITCH_ON
== on
) // switch on esd
2855 spin_unlock(&esd_lock
);
2856 GTP_INFO("Esd started");
2857 queue_delayed_work(gtp_esd_check_workqueue
, >p_esd_check_work
, clk_tick_cnt
);
2861 spin_unlock(&esd_lock
);
2864 else // switch off esd
2869 spin_unlock(&esd_lock
);
2870 GTP_INFO("Esd cancelled");
2871 cancel_delayed_work_sync(>p_esd_check_work
);
2875 spin_unlock(&esd_lock
);
2880 static s32
gtp_check_fw(void)
2882 u8 versionBuff
[4] = {0};
2887 ret
= i2c_read_bytes_non_dma(i2c_client_point
, 0x8140, versionBuff
, sizeof(versionBuff
));
2892 if( memcmp(versionBuff
, >p_default_FW_fl
[4], 4) !=0 )
2900 GTP_ERROR("Check running fw version error!");
2904 static void gtp_esd_check_func(struct work_struct
*work
)
2908 u8 esd_buf
[3] = {0x00};
2912 GTP_INFO("Esd suspended!");
2915 for (i
= 0; i
< 3; i
++)
2917 ret
= i2c_read_bytes_non_dma(i2c_client_point
, 0x8040, esd_buf
, 2);
2919 GTP_DEBUG("[Esd]0x8040 = 0x%02X, 0x8041 = 0x%02X", esd_buf
[0], esd_buf
[1]);
2922 // IIC communication problem
2927 if ((esd_buf
[0] == 0xAA) || (esd_buf
[1] != 0xAA))
2929 u8 chk_buf
[2] = {0x00};
2930 i2c_read_bytes_non_dma(i2c_client_point
, 0x8040, chk_buf
, 2);
2932 GTP_DEBUG("[Check]0x8040 = 0x%02X, 0x8041 = 0x%02X", chk_buf
[0], chk_buf
[1]);
2934 if ( (chk_buf
[0] == 0xAA) || (chk_buf
[1] != 0xAA) )
2936 i
= 3; // jump to reset guitar
2946 // IC works normally, Write 0x8040 0xAA, feed the watchdog
2948 i2c_write_bytes_non_dma(i2c_client_point
, 0x8040, esd_buf
, 1);
2955 if (i
>= 3 || !gtp_check_fw())
2957 #if GTP_COMPATIBLE_MODE
2958 if ((CHIP_TYPE_GT9F
== gtp_chip_type
) && (1 == rqst_processing
))
2960 GTP_INFO("Request Processing, no reset guitar.");
2965 GTP_INFO("IC works abnormally! Process reset guitar.");
2969 i2c_write_bytes(i2c_client_point
, 0x4226, esd_buf
, 3);
2971 force_reset_guitar(0);
2977 queue_delayed_work(gtp_esd_check_workqueue
, >p_esd_check_work
, clk_tick_cnt
);
2981 GTP_INFO("Esd suspended!");
2988 static void tpd_down(s32 x
, s32 y
, s32 size
, s32 id
)
2990 if ((!size
) && (!id
))
2992 input_report_abs(tpd
->dev
, ABS_MT_PRESSURE
, 100);
2993 input_report_abs(tpd
->dev
, ABS_MT_TOUCH_MAJOR
, 100);
2997 input_report_abs(tpd
->dev
, ABS_MT_PRESSURE
, size
);
2998 input_report_abs(tpd
->dev
, ABS_MT_TOUCH_MAJOR
, size
);
2999 /* track id Start 0 */
3000 input_report_abs(tpd
->dev
, ABS_MT_TRACKING_ID
, id
);
3003 input_report_key(tpd
->dev
, BTN_TOUCH
, 1);
3004 input_report_abs(tpd
->dev
, ABS_MT_POSITION_X
, x
);
3005 input_report_abs(tpd
->dev
, ABS_MT_POSITION_Y
, y
);
3006 input_mt_sync(tpd
->dev
);
3007 TPD_EM_PRINT(x
, y
, x
, y
, id
, 1);
3009 #if (defined(MT6575)||defined(MT6577))
3011 if (FACTORY_BOOT
== get_boot_mode() || RECOVERY_BOOT
== get_boot_mode())
3013 tpd_button(x
, y
, 1);
3019 static void tpd_up(s32 x
, s32 y
, s32 id
)
3021 input_report_key(tpd
->dev
, BTN_TOUCH
, 0);
3022 input_mt_sync(tpd
->dev
);
3023 TPD_EM_PRINT(x
, y
, x
, y
, id
, 0);
3025 #if (defined(MT6575) || defined(MT6577))
3027 if (FACTORY_BOOT
== get_boot_mode() || RECOVERY_BOOT
== get_boot_mode())
3029 tpd_button(x
, y
, 0);
3034 #if GTP_CHARGER_SWITCH
3035 static void gtp_charger_switch(s32 dir_update
)
3038 u8 chr_cmd
[3] = {0x80, 0x40};
3039 static u8 chr_pluggedin
= 0;
3043 chr_status
= *(volatile u32
*)CHR_CON0
;
3044 chr_status
&= (1 << 13);
3045 #else // ( defined(MT6575) || defined(MT6577) || defined(MT6589) )
3046 chr_status
= upmu_is_chr_det();
3049 if (chr_status
) // charger plugged in
3051 if (!chr_pluggedin
|| dir_update
)
3054 ret
= gtp_i2c_write(i2c_client_point
, chr_cmd
, 3);
3057 GTP_INFO("Update status for Charger Plugin");
3062 else // charger plugged out
3064 if (chr_pluggedin
|| dir_update
)
3067 ret
= gtp_i2c_write(i2c_client_point
, chr_cmd
, 3);
3070 GTP_INFO("Update status for Charger Plugout");
3078 static int touch_event_handler(void *unused
)
3080 struct sched_param param
= { .sched_priority
= RTPM_PRIO_TPD
};
3081 u8 end_cmd
[3] = {GTP_READ_COOR_ADDR
>> 8, GTP_READ_COOR_ADDR
& 0xFF, 0};
3082 u8 point_data
[2 + 1 + 8 * GTP_MAX_TOUCH
+ 1] = {GTP_READ_COOR_ADDR
>> 8, GTP_READ_COOR_ADDR
& 0xFF};
3085 static u8 pre_touch
= 0;
3086 static u8 pre_key
= 0;
3089 static u8 pre_pen
= 0;
3092 u8
*coor_data
= NULL
;
3100 #if GTP_COMPATIBLE_MODE
3101 u8 rqst_data
[3] = {(u8
)(GTP_REG_RQST
>> 8), (u8
)(GTP_REG_RQST
& 0xFF), 0};
3104 #ifdef TPD_PROXIMITY
3106 hwm_sensor_data sensor_data
;
3107 u8 proximity_status
;
3109 u8 proximity_status
; //add by caoyang
3110 u8 doze_buf
[3] = {0x81, 0x4B};
3112 sched_setscheduler(current
, SCHED_RR
, ¶m
);
3115 set_current_state(TASK_INTERRUPTIBLE
);
3119 //#if GTP_GESTURE_WAKEUP
3120 if(gesture_value
> 0){
3121 if (DOZE_ENABLED
== doze_status
)
3131 wait_event_interruptible(waiter
, tpd_flag
!= 0);
3134 set_current_state(TASK_RUNNING
);
3136 #if GTP_CHARGER_SWITCH
3137 gtp_charger_switch(0);
3140 if(gesture_value
> 0){
3141 //#if GTP_GESTURE_WAKEUP
3142 if (DOZE_ENABLED
== doze_status
)
3144 ret
= gtp_i2c_read(i2c_client_point
, doze_buf
, 3);
3145 GTP_DEBUG("0x814B = 0x%02X", doze_buf
[2]);
3148 if ((doze_buf
[2] == 'a') || (doze_buf
[2] == 'b') || (doze_buf
[2] == 'c') ||
3149 (doze_buf
[2] == 'd') || (doze_buf
[2] == 'e') || (doze_buf
[2] == 'g') ||
3150 (doze_buf
[2] == 'h') || (doze_buf
[2] == 'm') || (doze_buf
[2] == 'o') ||
3151 (doze_buf
[2] == 'q') || (doze_buf
[2] == 's') || (doze_buf
[2] == 'v') ||
3152 (doze_buf
[2] == 'w') || (doze_buf
[2] == 'y') || (doze_buf
[2] == 'z') ||
3153 (doze_buf
[2] == 0x5E) /* ^ */
3156 if (doze_buf
[2] != 0x5E)
3158 GTP_INFO("Wakeup by gesture(%c), light up the screen!", doze_buf
[2]);
3162 GTP_INFO("Wakeup by gesture(^), light up the screen!");
3165 doze_status
= DOZE_WAKEUP
;
3166 input_report_key(tpd
->dev
, KEY_POWER
, 1);
3167 input_sync(tpd
->dev
);
3168 input_report_key(tpd
->dev
, KEY_POWER
, 0);
3169 input_sync(tpd
->dev
);
3172 gtp_i2c_write(i2c_client_point
, doze_buf
, 3);
3174 else if ( (doze_buf
[2] == 0xAA) || (doze_buf
[2] == 0xBB) ||
3175 (doze_buf
[2] == 0xAB) || (doze_buf
[2] == 0xBA) )
3177 char *direction
[4] = {"Right", "Down", "Up", "Left"};
3178 u8 type
= ((doze_buf
[2] & 0x0F) - 0x0A) + (((doze_buf
[2] >> 4) & 0x0F) - 0x0A) * 2;
3180 GTP_INFO("%s slide to light up the screen!", direction
[type
]);
3181 doze_status
= DOZE_WAKEUP
;
3182 input_report_key(tpd
->dev
, KEY_POWER
, 1);
3183 input_sync(tpd
->dev
);
3184 input_report_key(tpd
->dev
, KEY_POWER
, 0);
3185 input_sync(tpd
->dev
);
3188 gtp_i2c_write(i2c_client_point
, doze_buf
, 3);
3190 else if (0xCC == doze_buf
[2])
3192 GTP_INFO("Double click to light up the screen!");
3193 doze_status
= DOZE_WAKEUP
;
3194 input_report_key(tpd
->dev
, KEY_POWER
, 1);
3195 input_sync(tpd
->dev
);
3196 input_report_key(tpd
->dev
, KEY_POWER
, 0);
3197 input_sync(tpd
->dev
);
3200 gtp_i2c_write(i2c_client_point
, doze_buf
, 3);
3206 gtp_i2c_write(i2c_client_point
, doze_buf
, 3);
3207 gtp_enter_doze(i2c_client_point
);
3214 ret
= gtp_i2c_read(i2c_client_point
, point_data
, 12);
3217 GTP_ERROR("I2C transfer error. errno:%d\n ", ret
);
3220 finger
= point_data
[GTP_ADDR_LENGTH
];
3222 #if GTP_COMPATIBLE_MODE
3223 if ((finger
== 0x00) && (CHIP_TYPE_GT9F
== gtp_chip_type
))
3225 ret
= gtp_i2c_read(i2c_client_point
, rqst_data
, 3);
3229 GTP_ERROR("I2C transfer error. errno:%d\n ", ret
);
3232 switch (rqst_data
[2])
3234 case GTP_RQST_BAK_REF
:
3235 GTP_INFO("Request Ref.");
3236 rqst_processing
= 1;
3237 ret
= gtp_bak_ref_proc(i2c_client_point
, GTP_BAK_REF_SEND
);
3240 GTP_INFO("Send ref success.");
3241 rqst_data
[2] = GTP_RQST_RESPONDED
;
3242 gtp_i2c_write(i2c_client_point
, rqst_data
, 3);
3243 rqst_processing
= 0;
3245 goto exit_work_func
;
3247 case GTP_RQST_CONFIG
:
3248 GTP_INFO("Request Config.");
3249 ret
= gtp_send_cfg(i2c_client_point
);
3252 GTP_ERROR("Send config error.");
3256 GTP_INFO("Send config success.");
3257 rqst_data
[2] = GTP_RQST_RESPONDED
;
3258 gtp_i2c_write(i2c_client_point
, rqst_data
, 3);
3260 goto exit_work_func
;
3262 case GTP_RQST_MAIN_CLOCK
:
3263 GTP_INFO("Request main clock.");
3264 rqst_processing
= 1;
3265 ret
= gtp_main_clk_proc(i2c_client_point
);
3268 GTP_INFO("Send main clk success.");
3269 #if GTP_POWER_CTRL_SLEEP
3271 ret
= gtp_hopping_proc(i2c_client_point
, GTP_HOPPING_SEND
);
3274 GTP_ERROR("Failed to send hopping data.");
3275 goto exit_work_func
;
3279 GTP_INFO("Send hopping data success.");
3283 rqst_data
[2] = GTP_RQST_RESPONDED
;
3284 gtp_i2c_write(i2c_client_point
, rqst_data
, 3);
3285 rqst_processing
= 0;
3287 goto exit_work_func
;
3289 case GTP_RQST_RESET
:
3290 //#if GTP_GESTURE_WAKEUP
3291 if(gesture_value
> 0){
3292 if (DOZE_ENABLED
== doze_status
) {
3293 u8 reg_data
[3] = {(u8
)(0x801F >> 8), (u8
)(0x801F & 0xFF), 0};
3294 gtp_i2c_write(i2c_client_point
, reg_data
, 3);
3295 gtp_recovery_reset(i2c_client_point
);
3296 gtp_enter_doze(i2c_client_point
);
3301 gtp_recovery_reset(i2c_client_point
);
3303 GTP_INFO("Request Reset.");
3304 goto exit_work_func
;
3306 #if GTP_POWER_CTRL_SLEEP
3307 case GTP_RQST_STORE_HOPPING
:
3308 GTP_INFO("Request store hopping data.");
3309 ret
= gtp_hopping_proc(i2c_client_point
, GTP_HOPPING_STORE
);
3312 GTP_ERROR("Failed to store hopping data.");
3316 GTP_INFO("Hopping data stored.");
3317 rqst_data
[2] = GTP_RQST_RESPONDED
;
3318 gtp_i2c_write(i2c_client_point
, rqst_data
, 3);
3320 goto exit_work_func
;
3322 case GTP_RQST_STORE_BAK_REF
:
3323 GTP_INFO("Request store backup reference.");
3324 ret
= gtp_bak_ref_proc(i2c_client_point
, GTP_BAK_REF_STORE
);
3327 GTP_ERROR("Failed to store backup reference data.");
3331 GTP_INFO("Backup reference data stored.");
3332 rqst_data
[2] = GTP_RQST_RESPONDED
;
3333 gtp_i2c_write(i2c_client_point
, rqst_data
, 3);
3335 goto exit_work_func
;
3339 GTP_INFO("Undefined request code: 0x%02X", rqst_data
[2]);
3340 rqst_data
[2] = GTP_RQST_RESPONDED
;
3341 gtp_i2c_write(i2c_client_point
, rqst_data
, 3);
3352 if ((finger
& 0x80) == 0)
3354 goto exit_work_func
;
3356 if((gtp_autotool_setting
== 1) && !(point_data
[GTP_ADDR_LENGTH
] & 0x40)){
3357 gtp_autotool_setting
= 0;
3360 if(gesture_value
> 0){
3361 proximity_status
= point_data
[GTP_ADDR_LENGTH
];
3362 GTP_DEBUG("REG INDEX[0x814E]:0x%02X\n", proximity_status
);
3363 if(tpd_sleep_flag
== 1){
3364 goto exit_work_func
;
3366 if (proximity_status
& 0x40) //proximity or large touch detect,enable hwm_sensor.
3368 printk(KERN_ERR
"caoyang0 test for xipin\n");
3369 //mod_timer(&buttons_timer, jiffies+HZ/50);
3370 if(gtp_autotool_setting
== 1){
3371 gtp_autotool_setting
= 0;
3372 goto exit_work_func
;
3375 input_report_key(tpd
->dev
, KEY_POWER
, 1);
3376 input_sync(tpd
->dev
);
3377 input_report_key(tpd
->dev
, KEY_POWER
, 0);
3378 input_sync(tpd
->dev
);
3381 goto exit_work_func
;
3385 #ifdef TPD_PROXIMITY
3386 if (tpd_proximity_flag
== 1)
3388 proximity_status
= point_data
[GTP_ADDR_LENGTH
];
3389 GTP_DEBUG("REG INDEX[0x814E]:0x%02X\n", proximity_status
);
3391 if (proximity_status
& 0x60) //proximity or large touch detect,enable hwm_sensor.
3393 tpd_proximity_detect
= 0;
3394 //sensor_data.values[0] = 0;
3398 tpd_proximity_detect
= 1;
3399 //sensor_data.values[0] = 1;
3403 GTP_DEBUG(" ps change\n");
3404 GTP_DEBUG("PROXIMITY STATUS:0x%02X\n", tpd_proximity_detect
);
3405 //map and store data to hwm_sensor_data
3406 sensor_data
.values
[0] = tpd_get_ps_value();
3407 sensor_data
.value_divide
= 1;
3408 sensor_data
.status
= SENSOR_STATUS_ACCURACY_MEDIUM
;
3409 //report to the up-layer
3410 ret
= hwmsen_get_interrupt_data(ID_PROXIMITY
, &sensor_data
);
3414 GTP_ERROR("Call hwmsen_get_interrupt_data fail = %d\n", err
);
3420 touch_num
= finger
& 0x0f;
3422 if (touch_num
> GTP_MAX_TOUCH
)
3424 goto exit_work_func
;
3429 u8 buf
[8 * GTP_MAX_TOUCH
] = {(GTP_READ_COOR_ADDR
+ 10) >> 8, (GTP_READ_COOR_ADDR
+ 10) & 0xff};
3431 ret
= gtp_i2c_read(i2c_client_point
, buf
, 2 + 8 * (touch_num
- 1));
3432 memcpy(&point_data
[12], &buf
[2], 8 * (touch_num
- 1));
3435 #if (GTP_HAVE_TOUCH_KEY || GTP_PEN_HAVE_BUTTON)
3436 key_value
= point_data
[3 + 8 * touch_num
];
3438 if (key_value
|| pre_key
)
3440 #if GTP_PEN_HAVE_BUTTON
3441 if (key_value
== 0x40)
3443 GTP_DEBUG("BTN_STYLUS & BTN_STYLUS2 Down.");
3444 input_report_key(pen_dev
, BTN_STYLUS
, 1);
3445 input_report_key(pen_dev
, BTN_STYLUS2
, 1);
3448 else if (key_value
== 0x10)
3450 GTP_DEBUG("BTN_STYLUS Down, BTN_STYLUS2 Up.");
3451 input_report_key(pen_dev
, BTN_STYLUS
, 1);
3452 input_report_key(pen_dev
, BTN_STYLUS2
, 0);
3455 else if (key_value
== 0x20)
3457 GTP_DEBUG("BTN_STYLUS Up, BTN_STYLUS2 Down.");
3458 input_report_key(pen_dev
, BTN_STYLUS
, 0);
3459 input_report_key(pen_dev
, BTN_STYLUS2
, 1);
3464 GTP_DEBUG("BTN_STYLUS & BTN_STYLUS2 Up.");
3465 input_report_key(pen_dev
, BTN_STYLUS
, 0);
3466 input_report_key(pen_dev
, BTN_STYLUS2
, 0);
3467 if ( (pre_key
== 0x40) || (pre_key
== 0x20) ||
3476 touch_num
= 0; // shield pen point
3477 //pre_touch = 0; // clear last pen status
3480 #if GTP_HAVE_TOUCH_KEY
3483 for (i
= 0; i
< GTP_MAX_KEY_NUM
; i
++)
3485 input_report_key(tpd
->dev
, touch_key_array
[i
], key_value
& (0x01 << i
));
3487 touch_num
= 0; // shiled fingers
3492 pre_key
= key_value
;
3494 GTP_DEBUG("pre_touch:%02x, finger:%02x.", pre_touch
, finger
);
3498 for (i
= 0; i
< touch_num
; i
++)
3500 coor_data
= &point_data
[i
* 8 + 3];
3502 id
= coor_data
[0] & 0x0F;
3503 input_x
= coor_data
[1] | coor_data
[2] << 8;
3504 input_y
= coor_data
[3] | coor_data
[4] << 8;
3505 input_w
= coor_data
[5] | coor_data
[6] << 8;
3509 if ((id
& 0x80)) // pen/stylus is activated
3511 GTP_DEBUG("Pen touch DOWN!");
3515 GTP_DEBUG("(%d)(%d, %d)[%d]", id
, input_x
, input_y
, input_w
);
3516 gtp_pen_down(input_x
, input_y
, input_w
, id
);
3522 GTP_DEBUG(" (%d)(%d, %d)[%d]", id
, input_x
, input_y
, input_w
);
3523 tpd_down(input_x
, input_y
, input_w
, id
);
3534 GTP_DEBUG("Pen touch UP!");
3542 GTP_DEBUG("Touch Release!");
3547 pre_touch
= touch_num
;
3553 input_sync(pen_dev
);
3558 input_sync(tpd
->dev
);
3563 if (!gtp_rawdiff_mode
)
3565 ret
= gtp_i2c_write(i2c_client_point
, end_cmd
, 3);
3569 GTP_ERROR("I2C write end_cmd error!");
3572 #if (GTP_COMPATIBLE_MODE && GTP_FL_LITTLE_SYSTEM)
3573 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
3577 if ((fw_block
== 0) && (block_section
== 1))
3579 GTP_INFO("Begin downloading big ss51 firmware");
3581 gtp_download_big_ss51(i2c_client_point
);
3585 } while (!kthread_should_stop());
3590 static int tpd_local_init(void)
3593 clk_tick_cnt
= 2 * HZ
; // HZ: clock ticks in 1 second generated by system
3594 GTP_DEBUG("Clock ticks for an esd cycle: %d", clk_tick_cnt
);
3595 INIT_DELAYED_WORK(>p_esd_check_work
, gtp_esd_check_func
);
3596 gtp_esd_check_workqueue
= create_workqueue("gtp_esd_check");
3597 spin_lock_init(&esd_lock
); // 2.6.39 & later
3598 // esd_lock = SPIN_LOCK_UNLOCKED; // 2.6.39 & before
3601 #if GTP_SUPPORT_I2C_DMA
3602 gpDMABuf_va
= (u8
*)dma_alloc_coherent(NULL
, GTP_DMA_MAX_TRANSACTION_LENGTH
, &gpDMABuf_pa
, GFP_KERNEL
);
3604 GTP_ERROR("[Error] Allocate DMA I2C Buffer failed!\n");
3606 memset(gpDMABuf_va
, 0, GTP_DMA_MAX_TRANSACTION_LENGTH
);
3608 if (i2c_add_driver(&tpd_i2c_driver
) != 0)
3610 GTP_ERROR("unable to add i2c driver.\n");
3614 if (tpd_load_status
== 0) //if(tpd_load_status == 0) // disable auto load touch driver for linux3.0 porting
3616 GTP_ERROR("add error touch panel driver.\n");
3617 i2c_del_driver(&tpd_i2c_driver
);
3621 input_set_abs_params(tpd
->dev
, ABS_MT_TRACKING_ID
, 0, (GTP_MAX_TOUCH
- 1), 0, 0);
3622 #ifdef TPD_HAVE_BUTTON
3623 tpd_button_setting(TPD_KEY_COUNT
, tpd_keys_local
, tpd_keys_dim_local
);// initialize tpd button data
3626 #if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
3628 memcpy(tpd_wb_start
, tpd_wb_start_local
, TPD_WARP_CNT
* 4);
3629 memcpy(tpd_wb_end
, tpd_wb_start_local
, TPD_WARP_CNT
* 4);
3632 #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
3633 memcpy(tpd_calmat
, tpd_def_calmat_local
, 8 * 4);
3634 memcpy(tpd_def_calmat
, tpd_def_calmat_local
, 8 * 4);
3637 // set vendor string
3638 tpd
->dev
->id
.vendor
= 0x00;
3639 tpd
->dev
->id
.product
= tpd_info
.pid
;
3640 tpd
->dev
->id
.version
= tpd_info
.vid
;
3642 GTP_DEBUG("end %s, %d\n", __FUNCTION__
, __LINE__
);
3648 static s8
gtp_enter_doze(struct i2c_client
*client
)
3652 u8 i2c_control_buf
[3] = {(u8
)(GTP_REG_SLEEP
>> 8), (u8
)GTP_REG_SLEEP
, 8};
3656 GTP_DEBUG("Entering gesture mode...");
3659 i2c_control_buf
[0] = 0x80;
3660 i2c_control_buf
[1] = 0x46;
3661 ret
= gtp_i2c_write(client
, i2c_control_buf
, 3);
3664 GTP_DEBUG("Failed to set gesture flag into 0x8046, %d", retry
);
3667 i2c_control_buf
[0] = 0x80;
3668 i2c_control_buf
[1] = 0x40;
3669 ret
= gtp_i2c_write(client
, i2c_control_buf
, 3);
3672 doze_status
= DOZE_ENABLED
;
3673 GTP_INFO("Gesture mode enabled.");
3678 GTP_ERROR("GTP send gesture cmd failed.");
3682 /*******************************************************
3684 Eter sleep function.
3690 Executive outcomes.0--success,non-0--fail.
3691 *******************************************************/
3692 static s8
gtp_enter_sleep(struct i2c_client
*client
)
3694 #if (GTP_COMPATIBLE_MODE && !GTP_POWER_CTRL_SLEEP)
3695 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
3697 u8 i2c_status_buf
[3] = {0x80, 0x44, 0x00};
3700 ret
= gtp_i2c_read(client
, i2c_status_buf
, 3);
3703 GTP_ERROR("[gtp_enter_sleep]Read ref status reg error.");
3706 if (i2c_status_buf
[2] & 0x80)
3709 ret
= gtp_bak_ref_proc(client
, GTP_BAK_REF_STORE
);
3712 GTP_ERROR("[gtp_enter_sleep]Store bak ref failed.");
3717 #if GTP_POWER_CTRL_SLEEP
3719 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 0);
3720 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3724 mt_set_gpio_mode(GPIO_CTP_EN_PIN
, GPIO_CTP_EN_PIN_M_GPIO
);
3725 mt_set_gpio_dir(GPIO_CTP_EN_PIN
, GPIO_DIR_OUT
);
3726 mt_set_gpio_out(GPIO_CTP_EN_PIN
, GPIO_OUT_ZERO
);
3728 #else // ( defined(MT6575) || defined(MT6577) || defined(MT6589) )
3730 #ifdef TPD_POWER_SOURCE_1800
3731 hwPowerDown(TPD_POWER_SOURCE_1800
, "TP");
3734 #ifdef TPD_POWER_SOURCE_CUSTOM
3735 hwPowerDown(TPD_POWER_SOURCE_CUSTOM
, "TP");
3737 hwPowerDown(MT65XX_POWER_LDO_VGP2
, "TP");
3741 GTP_INFO("GTP enter sleep by poweroff!");
3748 u8 i2c_control_buf
[3] = {(u8
)(GTP_REG_SLEEP
>> 8), (u8
)GTP_REG_SLEEP
, 5};
3751 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3756 ret
= gtp_i2c_write(client
, i2c_control_buf
, 3);
3760 GTP_INFO("GTP enter sleep!");
3768 GTP_ERROR("GTP send sleep cmd failed.");
3774 /*******************************************************
3776 Wakeup from sleep mode Function.
3782 Executive outcomes.0--success,non-0--fail.
3783 *******************************************************/
3784 static s8
gtp_wakeup_sleep(struct i2c_client
*client
)
3789 GTP_DEBUG("GTP wakeup begin.");
3791 #if GTP_POWER_CTRL_SLEEP
3792 #if (GTP_COMPATIBLE_MODE && GTP_FL_LITTLE_SYSTEM)
3793 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
3797 kthread_run(gtp_resume_timeout
, (void*)NULL
, "resume_timeout");
3799 ret
= force_reset_guitar(1);
3803 gtp_recovery_reset(client
);
3805 if (!gtp_check_fw()) {
3807 gtp_recovery_reset(client
);
3811 #endif // end compatible mode & fl little system
3815 ret
= tpd_power_on(client
);
3819 GTP_ERROR("I2C Power on ERROR!");
3822 GTP_INFO("Ic wakeup by poweron");
3825 #else // esle PowerCtrlSleep
3826 while (retry
++ < 5) {
3827 //#if GTP_GESTURE_WAKEUP
3828 if(gesture_value
> 0){
3829 if (DOZE_WAKEUP
!= doze_status
)
3831 GTP_INFO("Powerkey wakeup.");
3835 GTP_INFO("Gesture wakeup.");
3837 doze_status
= DOZE_DISABLED
;
3839 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
3840 gtp_reset_guitar(client
, 20);
3841 ret
= gup_reload_fw_dsp(NULL
, GTP_FL_READ_REPAIR
);
3842 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
3844 GTP_ERROR("[gtp_wakeup_sleep]Reload dsp code failed.");
3847 ret
= gtp_fw_startup(client
);
3849 GTP_ERROR("[gtp_wakeup_sleep]Startup fw failed.");
3852 if (!gtp_check_fw()) {
3853 gtp_recovery_reset(client
);
3855 return 0; // succeed
3856 //#else // else gesture wakeup
3858 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 1); //wake up by int gpio
3861 #if GTP_COMPATIBLE_MODE
3862 if (CHIP_TYPE_GT9F
== gtp_chip_type
) {
3863 u8 opr_buf
[2] = {0};
3865 ret
= gtp_i2c_test(client
);
3869 ret
= i2c_write_bytes(client
, 0x4180, opr_buf
, 1);
3871 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
3877 ret
= i2c_read_bytes(client
, 0x4180, opr_buf
, 1);
3879 GTP_DEBUG("confirm ss51 & dsp hold, I2C error,retry:%d", retry
);
3882 if (0x0C != opr_buf
[0]) {
3883 GTP_DEBUG("ss51 & dsp not hold, val: %d, retry: %d", opr_buf
[0], retry
);
3886 GTP_DEBUG("ss51 & dsp has been hold");
3888 ret
= gtp_fw_startup(client
);
3890 GTP_ERROR("[gtp_wakeup_sleep]Startup fw failed.");
3893 GTP_INFO("flashless wakeup sleep success");
3896 force_reset_guitar(0);
3900 //#endif // end compatible mode
3902 ret
= gtp_i2c_test(client
);
3905 GTP_INFO("GTP wakeup sleep.");
3906 //#if (!GTP_GESTURE_WAKEUP)
3907 if(!(gesture_value
> 0))
3914 gtp_reset_guitar(client
, 20);
3915 #endif // end gesture wakeup
3919 GTP_ERROR("wakeup retry timeout, process esd reset");
3920 force_reset_guitar(0);
3922 #endif // end PowerCtrlSleep
3923 GTP_ERROR("GTP wakeup sleep failed.");
3927 /* Function to manage low power suspend */
3928 static void tpd_suspend(struct early_suspend
*h
)
3932 GTP_INFO("System suspend.");
3934 #ifdef TPD_PROXIMITY
3936 if (tpd_proximity_flag
== 1)
3942 #if (GTP_COMPATIBLE_MODE && GTP_FL_LITTLE_SYSTEM)
3949 gtp_esd_switch(i2c_client_point
, SWITCH_OFF
);
3951 //#if GTP_GESTURE_WAKEUP
3952 if(gesture_value
> 0){
3953 ret
= gtp_enter_doze(i2c_client_point
);
3956 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
3957 ret
= gtp_enter_sleep(i2c_client_point
);
3962 GTP_ERROR("GTP early suspend failed.");
3964 // to avoid waking up while not sleeping, delay 48 + 10ms to ensure reliability
3968 /* Function to manage power-on resume */
3969 static void tpd_resume(struct early_suspend
*h
)
3973 GTP_INFO("System resume.");
3975 #ifdef TPD_PROXIMITY
3977 if (tpd_proximity_flag
== 1)
3984 ret
= gtp_wakeup_sleep(i2c_client_point
);
3988 GTP_ERROR("GTP later resume failed.");
3991 #if GTP_COMPATIBLE_MODE
3992 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
3999 gtp_send_cfg(i2c_client_point
);
4002 #if GTP_CHARGER_SWITCH
4003 gtp_charger_switch(1); // force update
4007 //#if GTP_GESTURE_WAKEUP
4008 if(gesture_value
> 0){
4009 doze_status
= DOZE_DISABLED
;
4012 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
4017 gtp_init_ext_watchdog(i2c_client_point
);
4018 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
4023 static struct tpd_driver_t tpd_device_driver
=
4025 .tpd_device_name
= "gt9xx",
4026 .tpd_local_init
= tpd_local_init
,
4027 .suspend
= tpd_suspend
,
4028 .resume
= tpd_resume
,
4029 #ifdef TPD_HAVE_BUTTON
4030 .tpd_have_button
= 1,
4032 .tpd_have_button
= 0,
4036 /* called when loaded into kernel */
4037 static int __init
tpd_driver_init(void)
4039 if(g_boot_mode
== KERNEL_POWER_OFF_CHARGING_BOOT
|| g_boot_mode
== LOW_POWER_OFF_CHARGING_BOOT
) //add by zero
4041 GTP_INFO("MediaTek gt91xx touch panel driver init\n");
4042 #ifdef I2C_BUS_NUMBER
4043 i2c_register_board_info(I2C_BUS_NUMBER
, &i2c_tpd
, 1);
4045 i2c_register_board_info(0, &i2c_tpd
, 1);
4047 if (tpd_driver_add(&tpd_device_driver
) < 0)
4048 GTP_INFO("add generic driver failed\n");
4053 /* should never be called */
4054 static void __exit
tpd_driver_exit(void)
4056 GTP_INFO("MediaTek gt91xx touch panel driver exit\n");
4057 tpd_driver_remove(&tpd_device_driver
);
4060 module_init(tpd_driver_init
);
4061 module_exit(tpd_driver_exit
);