tracychui | bab38f0 | 2020-04-29 16:24:36 +0800 | [diff] [blame] | 1 | /* Himax Android Driver Sample Code for common functions |
| 2 | * |
| 3 | * Copyright (C) 2017 Himax Corporation. |
| 4 | * |
| 5 | * This software is licensed under the terms of the GNU General Public |
| 6 | * License version 2, as published by the Free Software Foundation, and |
| 7 | * may be copied, distributed, and modified under those terms. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include "himax_common.h" |
| 17 | #include "himax_ic.h" |
| 18 | |
| 19 | #define SUPPORT_FINGER_DATA_CHECKSUM 0x0F |
| 20 | #define TS_WAKE_LOCK_TIMEOUT (2 * HZ) |
| 21 | #define FRAME_COUNT 5 |
| 22 | |
| 23 | #ifdef HX_RST_PIN_FUNC |
| 24 | extern void himax_ic_reset(uint8_t loadconfig,uint8_t int_off); |
| 25 | #endif |
jinjiawu | 7ec5b25 | 2020-12-09 18:30:05 +0800 | [diff] [blame^] | 26 | /*[Arima_8901][jinjia] Upgrade himax fw CID0804_D02_C15 for Ghost touch 20201209 begin*/ |
tracychui | bab38f0 | 2020-04-29 16:24:36 +0800 | [diff] [blame] | 27 | /*[Arima_8901][jinjia] Upgrade himax fw CID0804_D02_C14 for 0.9mm CG performance 20190903 begin*/ |
| 28 | /*[Arima_8901][TracyChui]Add usb plug detect function and updated FW CID0804_D02_C13 20190816 start */ |
| 29 | /*[Arima_8901][jinjia] Upgrade himax fw CID0804_D02_C12 for 0.9mm CG performance 20190812 begin*/ |
| 30 | /*[Arima_8901][allen_yu] Upgrade himax fw CID0802_D02_C06 for DQA low ground issue 20190530 begin*/ |
| 31 | /*[Arima_8901][allen_yu] Modify to edge trigger and upgrade fw to CID0802_D02_C05 20190322 begin*/ |
| 32 | /*[Arima_8901][allen_yu] Upgrade himax fw CID0802_D02_C04 20190116 begin*/ |
| 33 | /*[Arima_8901][allen_yu] Upgrade himax fw CID0802_D02_C03 20181226 begin*/ |
| 34 | /*[Arima_8901][allen_yu] Modify to edge trigger and upgrade himax fw CIDFF00_D01_C02 20181128 begin*/ |
| 35 | /*[Arima_8901][allen_yu] Upgrade himax first fw CIDFF00_D01_C01 20181122 begin*/ |
| 36 | #if defined(HX_AUTO_UPDATE_FW) |
| 37 | |
| 38 | unsigned char i_CTPM_FW_HX83112A[]= |
| 39 | { |
| 40 | 0 |
| 41 | //#include "Yandex_Truly_Arima_CIDFF04_D02_C04_20180801.i" |
| 42 | }; |
| 43 | unsigned char i_CTPM_FW_HX83112B[]= |
| 44 | { |
jinjiawu | 7ec5b25 | 2020-12-09 18:30:05 +0800 | [diff] [blame^] | 45 | #include "FP_DJN_Arima_CID0804_D02_C15_20201209.i" |
tracychui | bab38f0 | 2020-04-29 16:24:36 +0800 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | #endif |
| 49 | /*[Arima_8901][allen_yu] 20181122 end*/ |
| 50 | /*[Arima_8901][allen_yu] 20181128 end*/ |
| 51 | /*[Arima_8901][allen_yu] 20181226 end*/ |
| 52 | /*[Arima_8901][allen_yu] 20190116 end*/ |
| 53 | /*[Arima_8901][allen_yu] 20190322 end*/ |
| 54 | /*[Arima_8901][allen_yu] 20190530 end*/ |
| 55 | /*[Arima_8901][jinjia] 20190812 end*/ |
| 56 | /*[Arima_8901][TracyChui] 20190816 end */ |
| 57 | /*[Arima_8901][jinjia] 20190812 end*/ |
jinjiawu | 7ec5b25 | 2020-12-09 18:30:05 +0800 | [diff] [blame^] | 58 | /*[Arima_8901][jinjia] 20201209 end*/ |
tracychui | bab38f0 | 2020-04-29 16:24:36 +0800 | [diff] [blame] | 59 | |
| 60 | /*[Arima_8710][allen_yu] Solve the report point issue 20180619 begin*/ |
| 61 | static void himax_release_all_finger(void); |
| 62 | /*[Arima_8710][allen_yu] 20180619 end*/ |
| 63 | |
| 64 | #if defined(HX_SMART_WAKEUP)||defined(HX_HIGH_SENSE)||defined(HX_USB_DETECT_GLOBAL) |
| 65 | extern void himax_resend_cmd_func(bool suspended); |
| 66 | /*[Arima_7947][allen_yu] Change the rule of upgrading fw 20171221 begin*/ |
| 67 | extern void himax_rst_cmd_recovery_func(bool suspended); |
| 68 | /*[Arima_7947][allen_yu] 20171221 end*/ |
| 69 | #endif |
| 70 | |
| 71 | /*[Arima_8710][allen_yu] Fix TP I2C error in suspend 20180423 begin*/ |
| 72 | #ifdef HX_RST_PIN_FUNC |
| 73 | int reset_flag =1; |
| 74 | #endif |
| 75 | /*[Arima_8710][allen_yu] 20180423 end*/ |
| 76 | |
| 77 | struct himax_ts_data *private_ts; |
| 78 | struct himax_ic_data *ic_data; |
| 79 | struct himax_report_data *hx_touch_data; |
| 80 | |
| 81 | static int HX_TOUCH_INFO_POINT_CNT = 0; |
| 82 | |
| 83 | unsigned long FW_VER_MAJ_FLASH_ADDR; |
| 84 | unsigned long FW_VER_MIN_FLASH_ADDR; |
| 85 | unsigned long CFG_VER_MAJ_FLASH_ADDR; |
| 86 | unsigned long CFG_VER_MIN_FLASH_ADDR; |
| 87 | unsigned long CID_VER_MAJ_FLASH_ADDR; |
| 88 | unsigned long CID_VER_MIN_FLASH_ADDR; |
| 89 | //unsigned long PANEL_VERSION_ADDR; |
| 90 | |
| 91 | unsigned long FW_VER_MAJ_FLASH_LENG; |
| 92 | unsigned long FW_VER_MIN_FLASH_LENG; |
| 93 | unsigned long CFG_VER_MAJ_FLASH_LENG; |
| 94 | unsigned long CFG_VER_MIN_FLASH_LENG; |
| 95 | unsigned long CID_VER_MAJ_FLASH_LENG; |
| 96 | unsigned long CID_VER_MIN_FLASH_LENG; |
| 97 | //unsigned long PANEL_VERSION_LENG; |
| 98 | |
| 99 | unsigned long FW_CFG_VER_FLASH_ADDR; |
| 100 | |
| 101 | #ifdef HX_AUTO_UPDATE_FW |
| 102 | int g_i_FW_VER = 0; |
| 103 | int g_i_CFG_VER = 0; |
| 104 | int g_i_CID_MAJ = 0; //GUEST ID |
| 105 | int g_i_CID_MIN = 0; //VER for GUEST |
| 106 | #endif |
| 107 | |
| 108 | unsigned char IC_TYPE = 11; |
| 109 | unsigned char IC_CHECKSUM = 0; |
| 110 | |
| 111 | #ifdef HX_ESD_RECOVERY |
| 112 | u8 HX_ESD_RESET_ACTIVATE = 0; |
| 113 | int hx_EB_event_flag = 0; |
| 114 | int hx_EC_event_flag = 0; |
| 115 | int hx_ED_event_flag = 0; |
| 116 | extern int g_zero_event_count; |
| 117 | #endif |
| 118 | u8 HX_HW_RESET_ACTIVATE = 0; |
| 119 | |
| 120 | #if defined(CONFIG_TOUCHSCREEN_HIMAX_DEBUG) |
| 121 | extern int himax_touch_proc_init(void); |
| 122 | extern void himax_touch_proc_deinit(void); |
| 123 | //PROC-START |
| 124 | #ifdef HX_TP_PROC_FLASH_DUMP |
| 125 | extern void himax_ts_flash_func(void); |
| 126 | extern void setFlashBuffer(void); |
| 127 | extern bool getFlashDumpGoing(void); |
| 128 | extern uint8_t getSysOperation(void); |
| 129 | extern void setSysOperation(uint8_t operation); |
| 130 | #endif |
| 131 | /*[Arima_7947][allen_yu] Change the rule of upgrading fw 20171221 begin*/ |
| 132 | #ifdef HX_TP_PROC_GUEST_INFO |
| 133 | extern int himax_guest_info_get_status(void); |
| 134 | extern void himax_guest_info_set_status(int setting); |
| 135 | extern int himax_read_project_id(void); |
| 136 | #endif |
| 137 | /*[Arima_7947][allen_yu] 20171221 end*/ |
| 138 | |
| 139 | #if defined(HX_PLATFOME_DEFINE_KEY) |
| 140 | extern void himax_platform_key(void); |
| 141 | #endif |
| 142 | |
| 143 | #ifdef HX_TP_PROC_DIAG |
| 144 | extern void himax_ts_diag_func(void); |
| 145 | |
| 146 | extern int16_t *getMutualBuffer(void); |
| 147 | extern int16_t *getMutualNewBuffer(void); |
| 148 | extern int16_t *getMutualOldBuffer(void); |
| 149 | extern int16_t *getSelfBuffer(void); |
| 150 | extern uint8_t getXChannel(void); |
| 151 | extern uint8_t getYChannel(void); |
| 152 | extern uint8_t getDiagCommand(void); |
| 153 | extern void setXChannel(uint8_t x); |
| 154 | extern void setYChannel(uint8_t y); |
| 155 | extern void setMutualBuffer(void); |
| 156 | extern void setMutualNewBuffer(void); |
| 157 | extern void setMutualOldBuffer(void); |
| 158 | extern uint8_t diag_coor[128]; |
| 159 | extern int himax_set_diag_cmd(struct himax_ic_data *ic_data,struct himax_report_data *hx_touch_data); |
| 160 | #ifdef HX_TP_PROC_2T2R |
| 161 | extern bool Is_2T2R; |
| 162 | extern int16_t *getMutualBuffer_2(void); |
| 163 | extern uint8_t getXChannel_2(void); |
| 164 | extern uint8_t getYChannel_2(void); |
| 165 | extern void setXChannel_2(uint8_t x); |
| 166 | extern void setYChannel_2(uint8_t y); |
| 167 | extern void setMutualBuffer_2(void); |
| 168 | #endif |
| 169 | #endif |
| 170 | //PROC-END |
| 171 | #endif |
| 172 | |
| 173 | extern int himax_parse_dt(struct himax_ts_data *ts, |
| 174 | struct himax_i2c_platform_data *pdata); |
| 175 | extern bool himax_calculateChecksum(struct i2c_client *client, bool change_iref); |
| 176 | #if defined(HX_EN_SEL_BUTTON) || defined(HX_EN_MUT_BUTTON) |
| 177 | static uint8_t vk_press = 0x00; |
| 178 | #endif |
| 179 | static uint8_t AA_press = 0x00; |
| 180 | static uint8_t EN_NoiseFilter = 0x00; |
| 181 | static uint8_t Last_EN_NoiseFilter = 0x00; |
| 182 | static int hx_point_num = 0; // for himax_ts_work_func use |
| 183 | static int p_point_num = 0xFFFF; |
| 184 | static int tpd_key = 0x00; |
| 185 | static int tpd_key_old = 0x00; |
| 186 | static int probe_fail_flag = 0; |
| 187 | /*[Arima_8901][TracyChui]Add usb plug detect function and updated FW CID0804_D02_C13 20190816 start */ |
| 188 | #ifdef HX_USB_DETECT_GLOBAL |
| 189 | //bool USB_detect_flag = 0; |
| 190 | #endif |
| 191 | /*[Arima_8901][TracyChui] 20190816 end */ |
| 192 | |
| 193 | #if defined(CONFIG_FB) |
| 194 | int fb_notifier_callback(struct notifier_block *self, |
| 195 | unsigned long event, void *data); |
| 196 | #elif defined(CONFIG_HAS_EARLYSUSPEND) |
| 197 | static void himax_ts_early_suspend(struct early_suspend *h); |
| 198 | static void himax_ts_late_resume(struct early_suspend *h); |
| 199 | #endif |
| 200 | |
| 201 | #if defined(HX_PALM_REPORT) |
| 202 | int himax_palm_detect(uint8_t *buf); |
| 203 | #endif |
| 204 | |
| 205 | #ifdef HX_GESTURE_TRACK |
| 206 | static int gest_pt_cnt; |
| 207 | static int gest_pt_x[GEST_PT_MAX_NUM]; |
| 208 | static int gest_pt_y[GEST_PT_MAX_NUM]; |
| 209 | static int gest_start_x=0,gest_start_y=0,gest_end_x=0,gest_end_y=0; |
| 210 | static int gest_width=0,gest_height=0,gest_mid_x=0,gest_mid_y=0; |
| 211 | static int gn_gesture_coor[16]; |
| 212 | #endif |
| 213 | |
| 214 | #ifdef HX_CHIP_STATUS_MONITOR |
| 215 | struct chip_monitor_data *g_chip_monitor_data; |
| 216 | #endif |
| 217 | |
| 218 | #if defined(HX_TP_PROC_SELF_TEST)|| defined(CONFIG_TOUCHSCREEN_HIMAX_ITO_TEST) |
| 219 | extern int g_self_test_entered; |
| 220 | #endif |
| 221 | |
| 222 | int himax_report_data_init(void); |
| 223 | extern int himax_get_touch_data_size(void); |
| 224 | //void himax_HW_reset(uint8_t loadconfig,uint8_t int_off); |
| 225 | extern void himax_log_touch_data(uint8_t *buf,struct himax_report_data *hx_touch_data); |
| 226 | extern void himax_log_touch_event(int x,int y,int w,int loop_i,uint8_t EN_NoiseFilter,int touched); |
| 227 | extern void himax_log_touch_event_detail(struct himax_ts_data *ts,int x,int y,int w,int loop_i,uint8_t EN_NoiseFilter,int touched,uint16_t old_finger); |
| 228 | |
| 229 | #if defined(HX_ESD_RECOVERY) |
| 230 | extern void himax_esd_ic_reset(void); |
| 231 | extern int himax_ic_esd_recovery(int hx_esd_event,int hx_zero_event,int length); |
| 232 | #endif |
| 233 | |
| 234 | extern int himax_dev_set(struct himax_ts_data *ts); |
| 235 | extern int himax_input_register_device(struct input_dev *input_dev); |
| 236 | |
| 237 | |
| 238 | #ifdef HX_ZERO_FLASH |
| 239 | extern void himax_0f_operation(struct work_struct *work); |
| 240 | #endif |
| 241 | |
| 242 | int himax_input_register(struct himax_ts_data *ts) |
| 243 | { |
| 244 | int ret = 0; |
| 245 | |
| 246 | ret = himax_dev_set(ts); |
| 247 | if(ret < 0) |
| 248 | goto input_device_fail; |
| 249 | |
| 250 | set_bit(EV_SYN, ts->input_dev->evbit); |
| 251 | set_bit(EV_ABS, ts->input_dev->evbit); |
| 252 | set_bit(EV_KEY, ts->input_dev->evbit); |
| 253 | |
| 254 | #if defined(HX_EN_SEL_BUTTON) || defined(HX_EN_MUT_BUTTON) |
| 255 | #if defined(HX_PLATFOME_DEFINE_KEY) |
| 256 | himax_platform_key(); |
| 257 | #else |
| 258 | set_bit(KEY_BACK, ts->input_dev->keybit); |
| 259 | set_bit(KEY_HOME, ts->input_dev->keybit); |
| 260 | set_bit(KEY_MENU, ts->input_dev->keybit); |
| 261 | set_bit(KEY_SEARCH, ts->input_dev->keybit); |
| 262 | set_bit(KEY_APP_SWITCH, ts->input_dev->keybit); |
| 263 | #endif |
| 264 | #endif |
| 265 | |
| 266 | #if defined(HX_SMART_WAKEUP) || defined(HX_PALM_REPORT) |
| 267 | set_bit(KEY_POWER, ts->input_dev->keybit); |
| 268 | #endif |
| 269 | #if defined(HX_SMART_WAKEUP) |
| 270 | set_bit(KEY_CUST_01, ts->input_dev->keybit); |
| 271 | set_bit(KEY_CUST_02, ts->input_dev->keybit); |
| 272 | set_bit(KEY_CUST_03, ts->input_dev->keybit); |
| 273 | set_bit(KEY_CUST_04, ts->input_dev->keybit); |
| 274 | set_bit(KEY_CUST_05, ts->input_dev->keybit); |
| 275 | set_bit(KEY_CUST_06, ts->input_dev->keybit); |
| 276 | set_bit(KEY_CUST_07, ts->input_dev->keybit); |
| 277 | set_bit(KEY_CUST_08, ts->input_dev->keybit); |
| 278 | set_bit(KEY_CUST_09, ts->input_dev->keybit); |
| 279 | set_bit(KEY_CUST_10, ts->input_dev->keybit); |
| 280 | set_bit(KEY_CUST_11, ts->input_dev->keybit); |
| 281 | set_bit(KEY_CUST_12, ts->input_dev->keybit); |
| 282 | set_bit(KEY_CUST_13, ts->input_dev->keybit); |
| 283 | set_bit(KEY_CUST_14, ts->input_dev->keybit); |
| 284 | set_bit(KEY_CUST_15, ts->input_dev->keybit); |
| 285 | #endif |
| 286 | set_bit(BTN_TOUCH, ts->input_dev->keybit); |
| 287 | set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit); |
| 288 | |
| 289 | #ifdef HX_PROTOCOL_A |
| 290 | //ts->input_dev->mtsize = ts->nFinger_support; |
| 291 | input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, |
| 292 | 0, 3, 0, 0); |
| 293 | #else |
| 294 | set_bit(MT_TOOL_FINGER, ts->input_dev->keybit); |
| 295 | #if defined(HX_PROTOCOL_B_3PA) |
| 296 | input_mt_init_slots(ts->input_dev, ts->nFinger_support,0); |
| 297 | #else |
| 298 | input_mt_init_slots(ts->input_dev, ts->nFinger_support); |
| 299 | #endif |
| 300 | #endif |
| 301 | |
| 302 | I("input_set_abs_params: mix_x %d, max_x %d, min_y %d, max_y %d\n", |
| 303 | ts->pdata->abs_x_min, ts->pdata->abs_x_max, ts->pdata->abs_y_min, ts->pdata->abs_y_max); |
| 304 | |
| 305 | input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X,ts->pdata->abs_x_min, ts->pdata->abs_x_max, ts->pdata->abs_x_fuzz, 0); |
| 306 | input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y,ts->pdata->abs_y_min, ts->pdata->abs_y_max, ts->pdata->abs_y_fuzz, 0); |
| 307 | input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR,ts->pdata->abs_pressure_min, ts->pdata->abs_pressure_max, ts->pdata->abs_pressure_fuzz, 0); |
| 308 | #ifndef HX_PROTOCOL_A |
| 309 | input_set_abs_params(ts->input_dev, ABS_MT_PRESSURE,ts->pdata->abs_pressure_min, ts->pdata->abs_pressure_max, ts->pdata->abs_pressure_fuzz, 0); |
| 310 | input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR,ts->pdata->abs_width_min, ts->pdata->abs_width_max, ts->pdata->abs_pressure_fuzz, 0); |
| 311 | #endif |
| 312 | // input_set_abs_params(ts->input_dev, ABS_MT_AMPLITUDE, 0, ((ts->pdata->abs_pressure_max << 16) | ts->pdata->abs_width_max), 0, 0); |
| 313 | // input_set_abs_params(ts->input_dev, ABS_MT_POSITION, 0, (BIT(31) | (ts->pdata->abs_x_max << 16) | ts->pdata->abs_y_max), 0, 0); |
| 314 | |
| 315 | |
| 316 | if(himax_input_register_device(ts->input_dev) == 0) |
| 317 | return NO_ERR; |
| 318 | else |
| 319 | ret = INPUT_REGISTER_FAIL; |
| 320 | |
| 321 | input_device_fail: |
| 322 | I("%s, input device register fail!\n",__func__); |
| 323 | return ret; |
| 324 | } |
| 325 | |
| 326 | static void calcDataSize(uint8_t finger_num) |
| 327 | { |
| 328 | struct himax_ts_data *ts_data = private_ts; |
| 329 | ts_data->coord_data_size = 4 * finger_num; |
| 330 | ts_data->area_data_size = ((finger_num / 4) + (finger_num % 4 ? 1 : 0)) * 4; |
| 331 | //printk("allenyu : area_data_size = %d \n",ts_data->area_data_size ); |
| 332 | ts_data->coordInfoSize = ts_data->coord_data_size + ts_data->area_data_size + 4; |
| 333 | ts_data->raw_data_frame_size = 128 - ts_data->coord_data_size - ts_data->area_data_size - 4 - 4 - 1; |
| 334 | if(ts_data->raw_data_frame_size == 0) |
| 335 | { |
| 336 | E("%s: could NOT calculate! \n", __func__); |
| 337 | return; |
| 338 | } |
| 339 | ts_data->raw_data_nframes = ((uint32_t)ts_data->x_channel * ts_data->y_channel + |
| 340 | ts_data->x_channel + ts_data->y_channel) / ts_data->raw_data_frame_size + |
| 341 | (((uint32_t)ts_data->x_channel * ts_data->y_channel + |
| 342 | ts_data->x_channel + ts_data->y_channel) % ts_data->raw_data_frame_size)? 1 : 0; |
| 343 | I("%s: coord_data_size: %d, area_data_size:%d, raw_data_frame_size:%d, raw_data_nframes:%d", __func__, ts_data->coord_data_size, ts_data->area_data_size, ts_data->raw_data_frame_size, ts_data->raw_data_nframes); |
| 344 | } |
| 345 | |
| 346 | void calculate_point_number(void) |
| 347 | { |
| 348 | HX_TOUCH_INFO_POINT_CNT = ic_data->HX_MAX_PT * 4 ; |
| 349 | |
| 350 | if ( (ic_data->HX_MAX_PT % 4) == 0) |
| 351 | HX_TOUCH_INFO_POINT_CNT += (ic_data->HX_MAX_PT / 4) * 4 ; |
| 352 | else |
| 353 | HX_TOUCH_INFO_POINT_CNT += ((ic_data->HX_MAX_PT / 4) +1) * 4 ; |
| 354 | } |
| 355 | |
| 356 | #ifdef HX_AUTO_UPDATE_FW |
| 357 | static int i_update_FW(void) |
| 358 | { |
| 359 | int upgrade_times = 0; |
| 360 | /*[Arima_8710][allen_yu] Dynamic detect Yandex LCM/TP 2nd source and add PCBA node 20180828 begin*/ |
| 361 | //unsigned char* ImageBuffer = i_CTPM_FW; |
| 362 | //int fullFileLength = sizeof(i_CTPM_FW); |
| 363 | unsigned char* ImageBuffer = NULL; |
| 364 | int fullFileLength = 0; |
| 365 | /*[Arima_8710][allen_yu] 20180828 end*/ |
| 366 | uint8_t ret = 0, result = 0; |
| 367 | |
| 368 | /*[Arima_8710][allen_yu] Dynamic detect Yandex LCM/TP 2nd source and add PCBA node 20180828 begin*/ |
| 369 | if(IC_TYPE == HX_83112A_SERIES_PWON) |
| 370 | { |
| 371 | ImageBuffer = i_CTPM_FW_HX83112A; |
| 372 | fullFileLength = sizeof(i_CTPM_FW_HX83112A); |
| 373 | } |
| 374 | else/*HX_83112B_SERIES_PWON*/ |
| 375 | { |
| 376 | /*[Arima_8710][allen_yu] Modify the touch fw dynamic auto upgtade rule 20180830 begin*/ |
| 377 | //printk("%s: (%d)No upgrade 2nd source fw\n", __func__, __LINE__); |
| 378 | //return false; |
| 379 | ImageBuffer = i_CTPM_FW_HX83112B; |
| 380 | fullFileLength = sizeof(i_CTPM_FW_HX83112B); |
| 381 | /*[Arima_8710][allen_yu] 20180830 end*/ |
| 382 | } |
| 383 | /*[Arima_8710][allen_yu] 20180828 end*/ |
| 384 | I("%s: i_fullFileLength = %d\n", __func__,fullFileLength); |
| 385 | |
| 386 | himax_int_enable(private_ts->client->irq,0); |
| 387 | update_retry: |
| 388 | if(fullFileLength == FW_SIZE_32k) |
| 389 | { |
| 390 | ret = fts_ctpm_fw_upgrade_with_sys_fs_32k(private_ts->client,ImageBuffer,fullFileLength,false); |
| 391 | } |
| 392 | else if(fullFileLength == FW_SIZE_60k) |
| 393 | { |
| 394 | ret = fts_ctpm_fw_upgrade_with_sys_fs_60k(private_ts->client,ImageBuffer,fullFileLength,false); |
| 395 | } |
| 396 | else if (fullFileLength == FW_SIZE_64k) |
| 397 | { |
| 398 | ret = fts_ctpm_fw_upgrade_with_sys_fs_64k(private_ts->client,ImageBuffer,fullFileLength,false); |
| 399 | } |
| 400 | else if (fullFileLength == FW_SIZE_124k) |
| 401 | { |
| 402 | ret = fts_ctpm_fw_upgrade_with_sys_fs_124k(private_ts->client,ImageBuffer,fullFileLength,false); |
| 403 | } |
| 404 | else if (fullFileLength == FW_SIZE_128k) |
| 405 | { |
| 406 | ret = fts_ctpm_fw_upgrade_with_sys_fs_128k(private_ts->client,ImageBuffer,fullFileLength,false); |
| 407 | } |
| 408 | if(ret == 0) |
| 409 | { |
| 410 | upgrade_times++; |
| 411 | E("%s: TP upgrade error, upgrade_times = %d\n", __func__, upgrade_times); |
| 412 | if(upgrade_times < 3) |
| 413 | goto update_retry; |
| 414 | else |
| 415 | result = -1;//upgrade fail |
| 416 | } |
| 417 | else |
| 418 | { |
| 419 | ic_data->vendor_fw_ver = g_i_FW_VER; |
| 420 | ic_data->vendor_config_ver = g_i_CFG_VER; |
| 421 | result = 1;//upgrade success |
| 422 | I("%s: TP upgrade OK\n", __func__); |
| 423 | } |
| 424 | #ifdef HX_RST_PIN_FUNC |
| 425 | himax_ic_reset(true,false); |
| 426 | #endif |
| 427 | himax_int_enable(private_ts->client->irq,1); |
| 428 | return result; |
| 429 | } |
| 430 | #endif |
| 431 | |
| 432 | int himax_loadSensorConfig(struct i2c_client *client, struct himax_i2c_platform_data *pdata) |
| 433 | { |
| 434 | |
| 435 | if (!client) |
| 436 | { |
| 437 | E("%s: Necessary parameters client are null!\n", __func__); |
| 438 | return -1; |
| 439 | } |
| 440 | |
| 441 | I("%s: initialization complete\n", __func__); |
| 442 | |
| 443 | return NO_ERR; |
| 444 | } |
| 445 | |
| 446 | #ifdef HX_ESD_RECOVERY |
| 447 | void himax_esd_hw_reset(void) |
| 448 | { |
| 449 | I("START_Himax TP: ESD - Reset\n"); |
| 450 | #if defined(HX_TP_PROC_SELF_TEST) || defined(CONFIG_TOUCHSCREEN_HIMAX_ITO_TEST) |
| 451 | if (g_self_test_entered == 1) |
| 452 | { |
| 453 | I("In self test ,not TP: ESD - Reset\n"); |
| 454 | return; |
| 455 | } |
| 456 | #endif |
| 457 | HX_ESD_RESET_ACTIVATE = 1; |
| 458 | #if defined(HX_CHIP_STATUS_MONITOR) |
| 459 | g_chip_monitor_data->HX_CHIP_POLLING_COUNT=0; |
| 460 | #endif |
| 461 | himax_esd_ic_reset(); |
| 462 | |
| 463 | I("END_Himax TP: ESD - Reset\n"); |
| 464 | } |
| 465 | #endif |
| 466 | |
| 467 | #ifdef HX_CHIP_STATUS_MONITOR |
| 468 | static void himax_chip_monitor_function(struct work_struct *work) //for ESD solution |
| 469 | { |
| 470 | int ret=0; |
| 471 | |
| 472 | I(" %s: POLLING_COUNT=%x, STATUS=%x\n", __func__,g_chip_monitor_data->HX_CHIP_POLLING_COUNT,ret); |
| 473 | if(g_chip_monitor_data->HX_CHIP_POLLING_COUNT >= (g_chip_monitor_data->HX_POLLING_TIMES-1))//POLLING TIME |
| 474 | { |
| 475 | g_chip_monitor_data->HX_ON_HAND_SHAKING=1; |
| 476 | ret = himax_hand_shaking(private_ts->client); //0:Running, 1:Stop, 2:I2C Fail |
| 477 | g_chip_monitor_data->HX_ON_HAND_SHAKING=0; |
| 478 | if(ret == 2) |
| 479 | { |
| 480 | I(" %s: I2C Fail \n", __func__); |
| 481 | himax_esd_hw_reset(); |
| 482 | } |
| 483 | else if(ret == 1) |
| 484 | { |
| 485 | I(" %s: MCU Stop \n", __func__); |
| 486 | himax_esd_hw_reset(); |
| 487 | } |
| 488 | g_chip_monitor_data->HX_CHIP_POLLING_COUNT = 0;//clear polling counter |
| 489 | } |
| 490 | else |
| 491 | g_chip_monitor_data->HX_CHIP_POLLING_COUNT++; |
| 492 | |
| 493 | |
| 494 | g_chip_monitor_data->HX_CHIP_MONITOR_EN = 1; |
| 495 | queue_delayed_work(private_ts->himax_chip_monitor_wq, &private_ts->himax_chip_monitor, g_chip_monitor_data->HX_POLLING_TIMER*HZ); |
| 496 | |
| 497 | return; |
| 498 | } |
| 499 | #endif |
| 500 | |
| 501 | #ifdef HX_SMART_WAKEUP |
| 502 | #ifdef HX_GESTURE_TRACK |
| 503 | static void gest_pt_log_coordinate(int rx, int tx) |
| 504 | { |
| 505 | //driver report x y with range 0 - 255 , we scale it up to x/y pixel |
| 506 | gest_pt_x[gest_pt_cnt] = rx*(ic_data->HX_X_RES)/255; |
| 507 | gest_pt_y[gest_pt_cnt] = tx*(ic_data->HX_Y_RES)/255; |
| 508 | } |
| 509 | #endif |
| 510 | static int himax_parse_wake_event(struct himax_ts_data *ts) |
| 511 | { |
| 512 | uint8_t *buf; |
| 513 | #ifdef HX_GESTURE_TRACK |
| 514 | int tmp_max_x=0x00,tmp_min_x=0xFFFF,tmp_max_y=0x00,tmp_min_y=0xFFFF; |
| 515 | int gest_len; |
| 516 | #endif |
| 517 | int i=0, check_FC = 0, gesture_flag = 0; |
| 518 | |
| 519 | buf = kzalloc(hx_touch_data->event_size*sizeof(uint8_t),GFP_KERNEL); |
| 520 | memcpy(buf,hx_touch_data->hx_event_buf,hx_touch_data->event_size); |
| 521 | |
| 522 | for(i=0; i<GEST_PTLG_ID_LEN; i++) |
| 523 | { |
| 524 | if (check_FC==0) |
| 525 | { |
| 526 | if((buf[0]!=0x00)&&((buf[0]<=0x0F)||(buf[0]==0x80))) |
| 527 | { |
| 528 | check_FC = 1; |
| 529 | gesture_flag = buf[i]; |
| 530 | } |
| 531 | else |
| 532 | { |
| 533 | check_FC = 0; |
| 534 | I("ID START at %x , value = %x skip the event\n", i, buf[i]); |
| 535 | break; |
| 536 | } |
| 537 | } |
| 538 | else |
| 539 | { |
| 540 | if(buf[i]!=gesture_flag) |
| 541 | { |
| 542 | check_FC = 0; |
| 543 | I("ID NOT the same %x != %x So STOP parse event\n", buf[i], gesture_flag); |
| 544 | break; |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | I("0x%2.2X ", buf[i]); |
| 549 | if (i % 8 == 7) |
| 550 | I("\n"); |
| 551 | } |
| 552 | I("Himax gesture_flag= %x\n",gesture_flag ); |
| 553 | I("Himax check_FC is %d\n", check_FC); |
| 554 | |
| 555 | if (check_FC == 0) |
| 556 | return 0; |
| 557 | if(buf[GEST_PTLG_ID_LEN] != GEST_PTLG_HDR_ID1 || |
| 558 | buf[GEST_PTLG_ID_LEN+1] != GEST_PTLG_HDR_ID2) |
| 559 | return 0; |
| 560 | |
| 561 | #ifdef HX_GESTURE_TRACK |
| 562 | if(buf[GEST_PTLG_ID_LEN] == GEST_PTLG_HDR_ID1 && |
| 563 | buf[GEST_PTLG_ID_LEN+1] == GEST_PTLG_HDR_ID2) |
| 564 | { |
| 565 | gest_len = buf[GEST_PTLG_ID_LEN+2]; |
| 566 | |
| 567 | I("gest_len = %d ",gest_len); |
| 568 | |
| 569 | i = 0; |
| 570 | gest_pt_cnt = 0; |
| 571 | I("gest doornidate start \n %s",__func__); |
| 572 | while(i<(gest_len+1)/2) |
| 573 | { |
| 574 | gest_pt_log_coordinate(buf[GEST_PTLG_ID_LEN+4+i*2],buf[GEST_PTLG_ID_LEN+4+i*2+1]); |
| 575 | i++; |
| 576 | |
| 577 | I("gest_pt_x[%d]=%d \n",gest_pt_cnt,gest_pt_x[gest_pt_cnt]); |
| 578 | I("gest_pt_y[%d]=%d \n",gest_pt_cnt,gest_pt_y[gest_pt_cnt]); |
| 579 | |
| 580 | gest_pt_cnt +=1; |
| 581 | } |
| 582 | if(gest_pt_cnt) |
| 583 | { |
| 584 | for(i=0; i<gest_pt_cnt; i++) |
| 585 | { |
| 586 | if(tmp_max_x<gest_pt_x[i]) |
| 587 | tmp_max_x=gest_pt_x[i]; |
| 588 | if(tmp_min_x>gest_pt_x[i]) |
| 589 | tmp_min_x=gest_pt_x[i]; |
| 590 | if(tmp_max_y<gest_pt_y[i]) |
| 591 | tmp_max_y=gest_pt_y[i]; |
| 592 | if(tmp_min_y>gest_pt_y[i]) |
| 593 | tmp_min_y=gest_pt_y[i]; |
| 594 | } |
| 595 | I("gest_point x_min= %d, x_max= %d, y_min= %d, y_max= %d\n",tmp_min_x,tmp_max_x,tmp_min_y,tmp_max_y); |
| 596 | gest_start_x=gest_pt_x[0]; |
| 597 | gn_gesture_coor[0] = gest_start_x; |
| 598 | gest_start_y=gest_pt_y[0]; |
| 599 | gn_gesture_coor[1] = gest_start_y; |
| 600 | gest_end_x=gest_pt_x[gest_pt_cnt-1]; |
| 601 | gn_gesture_coor[2] = gest_end_x; |
| 602 | gest_end_y=gest_pt_y[gest_pt_cnt-1]; |
| 603 | gn_gesture_coor[3] = gest_end_y; |
| 604 | gest_width = tmp_max_x - tmp_min_x; |
| 605 | gn_gesture_coor[4] = gest_width; |
| 606 | gest_height = tmp_max_y - tmp_min_y; |
| 607 | gn_gesture_coor[5] = gest_height; |
| 608 | gest_mid_x = (tmp_max_x + tmp_min_x)/2; |
| 609 | gn_gesture_coor[6] = gest_mid_x; |
| 610 | gest_mid_y = (tmp_max_y + tmp_min_y)/2; |
| 611 | gn_gesture_coor[7] = gest_mid_y; |
| 612 | gn_gesture_coor[8] = gest_mid_x;//gest_up_x |
| 613 | gn_gesture_coor[9] = gest_mid_y-gest_height/2;//gest_up_y |
| 614 | gn_gesture_coor[10] = gest_mid_x;//gest_down_x |
| 615 | gn_gesture_coor[11] = gest_mid_y+gest_height/2; //gest_down_y |
| 616 | gn_gesture_coor[12] = gest_mid_x-gest_width/2; //gest_left_x |
| 617 | gn_gesture_coor[13] = gest_mid_y; //gest_left_y |
| 618 | gn_gesture_coor[14] = gest_mid_x+gest_width/2; //gest_right_x |
| 619 | gn_gesture_coor[15] = gest_mid_y; //gest_right_y |
| 620 | |
| 621 | } |
| 622 | |
| 623 | } |
| 624 | #endif |
| 625 | if(gesture_flag != 0x80) |
| 626 | { |
| 627 | if(!ts->gesture_cust_en[gesture_flag]) |
| 628 | { |
| 629 | I("%s NOT report customer key \n ",__func__); |
| 630 | return 0;//NOT report customer key |
| 631 | } |
| 632 | } |
| 633 | else |
| 634 | { |
| 635 | if(!ts->gesture_cust_en[0]) |
| 636 | { |
| 637 | I("%s NOT report report double click \n",__func__); |
| 638 | return 0;//NOT report power key |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | if(gesture_flag == 0x80) |
| 643 | return EV_GESTURE_PWR; |
| 644 | else |
| 645 | return gesture_flag; |
| 646 | } |
| 647 | |
| 648 | void himax_wake_check_func(void) |
| 649 | { |
| 650 | int ret_event = 0, KEY_EVENT = 0; |
| 651 | |
| 652 | ret_event = himax_parse_wake_event(private_ts); |
| 653 | switch (ret_event) |
| 654 | { |
| 655 | case EV_GESTURE_PWR: |
| 656 | KEY_EVENT = KEY_POWER; |
| 657 | break; |
| 658 | case EV_GESTURE_01: |
| 659 | KEY_EVENT = KEY_CUST_01; |
| 660 | break; |
| 661 | case EV_GESTURE_02: |
| 662 | KEY_EVENT = KEY_CUST_02; |
| 663 | break; |
| 664 | case EV_GESTURE_03: |
| 665 | KEY_EVENT = KEY_CUST_03; |
| 666 | break; |
| 667 | case EV_GESTURE_04: |
| 668 | KEY_EVENT = KEY_CUST_04; |
| 669 | break; |
| 670 | case EV_GESTURE_05: |
| 671 | KEY_EVENT = KEY_CUST_05; |
| 672 | break; |
| 673 | case EV_GESTURE_06: |
| 674 | KEY_EVENT = KEY_CUST_06; |
| 675 | break; |
| 676 | case EV_GESTURE_07: |
| 677 | KEY_EVENT = KEY_CUST_07; |
| 678 | break; |
| 679 | case EV_GESTURE_08: |
| 680 | KEY_EVENT = KEY_CUST_08; |
| 681 | break; |
| 682 | case EV_GESTURE_09: |
| 683 | KEY_EVENT = KEY_CUST_09; |
| 684 | break; |
| 685 | case EV_GESTURE_10: |
| 686 | KEY_EVENT = KEY_CUST_10; |
| 687 | break; |
| 688 | case EV_GESTURE_11: |
| 689 | KEY_EVENT = KEY_CUST_11; |
| 690 | break; |
| 691 | case EV_GESTURE_12: |
| 692 | KEY_EVENT = KEY_CUST_12; |
| 693 | break; |
| 694 | case EV_GESTURE_13: |
| 695 | KEY_EVENT = KEY_CUST_13; |
| 696 | break; |
| 697 | case EV_GESTURE_14: |
| 698 | KEY_EVENT = KEY_CUST_14; |
| 699 | break; |
| 700 | case EV_GESTURE_15: |
| 701 | KEY_EVENT = KEY_CUST_15; |
| 702 | break; |
| 703 | } |
| 704 | if(ret_event) |
| 705 | { |
| 706 | I(" %s SMART WAKEUP KEY event %x press\n",__func__,KEY_EVENT); |
| 707 | input_report_key(private_ts->input_dev, KEY_EVENT, 1); |
| 708 | input_sync(private_ts->input_dev); |
| 709 | //msleep(100); |
| 710 | I(" %s SMART WAKEUP KEY event %x release\n",__func__,KEY_EVENT); |
| 711 | input_report_key(private_ts->input_dev, KEY_EVENT, 0); |
| 712 | input_sync(private_ts->input_dev); |
| 713 | FAKE_POWER_KEY_SEND=true; |
| 714 | #ifdef HX_GESTURE_TRACK |
| 715 | I("gest_start_x= %d, gest_start_y= %d, gest_end_x= %d, gest_end_y= %d\n",gest_start_x,gest_start_y, |
| 716 | gest_end_x,gest_end_y); |
| 717 | I("gest_width= %d, gest_height= %d, gest_mid_x= %d, gest_mid_y= %d\n",gest_width,gest_height, |
| 718 | gest_mid_x,gest_mid_y); |
| 719 | I("gest_up_x= %d, gest_up_y= %d, gest_down_x= %d, gest_down_y= %d\n",gn_gesture_coor[8],gn_gesture_coor[9], |
| 720 | gn_gesture_coor[10],gn_gesture_coor[11]); |
| 721 | I("gest_left_x= %d, gest_left_y= %d, gest_right_x= %d, gest_right_y= %d\n",gn_gesture_coor[12],gn_gesture_coor[13], |
| 722 | gn_gesture_coor[14],gn_gesture_coor[15]); |
| 723 | #endif |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | #endif |
| 728 | |
| 729 | #if defined(HX_EN_SEL_BUTTON) || defined(HX_EN_MUT_BUTTON) |
| 730 | static void himax_ts_button_func(int tp_key_index,struct himax_ts_data *ts) |
| 731 | { |
| 732 | uint16_t x_position = 0, y_position = 0; |
| 733 | if ( tp_key_index != 0x00) |
| 734 | { |
| 735 | I("virtual key index =%x\n",tp_key_index); |
| 736 | if ( tp_key_index == 0x01) |
| 737 | { |
| 738 | vk_press = 1; |
| 739 | I("back key pressed\n"); |
| 740 | if (ts->pdata->virtual_key) |
| 741 | { |
| 742 | if (ts->button[0].index) |
| 743 | { |
| 744 | x_position = (ts->button[0].x_range_min + ts->button[0].x_range_max) / 2; |
| 745 | y_position = (ts->button[0].y_range_min + ts->button[0].y_range_max) / 2; |
| 746 | } |
| 747 | #ifdef HX_PROTOCOL_A |
| 748 | input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, |
| 749 | 100); |
| 750 | input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, 0); |
| 751 | |
| 752 | input_report_abs(ts->input_dev, ABS_MT_POSITION_X, |
| 753 | x_position); |
| 754 | input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, |
| 755 | y_position); |
| 756 | input_mt_sync(ts->input_dev); |
| 757 | #else |
| 758 | input_mt_slot(ts->input_dev, 0); |
| 759 | input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, |
| 760 | 1); |
| 761 | input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, |
| 762 | 100); |
| 763 | input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, |
| 764 | 100); |
| 765 | input_report_abs(ts->input_dev, ABS_MT_PRESSURE, |
| 766 | 100); |
| 767 | input_report_abs(ts->input_dev, ABS_MT_POSITION_X, |
| 768 | x_position); |
| 769 | input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, |
| 770 | y_position); |
| 771 | #endif |
| 772 | } |
| 773 | else |
| 774 | input_report_key(ts->input_dev, KEY_BACK, 1); |
| 775 | } |
| 776 | else if ( tp_key_index == 0x02) |
| 777 | { |
| 778 | vk_press = 1; |
| 779 | I("home key pressed\n"); |
| 780 | if (ts->pdata->virtual_key) |
| 781 | { |
| 782 | if (ts->button[1].index) |
| 783 | { |
| 784 | x_position = (ts->button[1].x_range_min + ts->button[1].x_range_max) / 2; |
| 785 | y_position = (ts->button[1].y_range_min + ts->button[1].y_range_max) / 2; |
| 786 | } |
| 787 | #ifdef HX_PROTOCOL_A |
| 788 | input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, 0); |
| 789 | input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, |
| 790 | 100); |
| 791 | |
| 792 | input_report_abs(ts->input_dev, ABS_MT_POSITION_X, |
| 793 | x_position); |
| 794 | input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, |
| 795 | y_position); |
| 796 | input_mt_sync(ts->input_dev); |
| 797 | #else |
| 798 | input_mt_slot(ts->input_dev, 0); |
| 799 | input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, |
| 800 | 1); |
| 801 | input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, |
| 802 | 100); |
| 803 | input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, |
| 804 | 100); |
| 805 | input_report_abs(ts->input_dev, ABS_MT_PRESSURE, |
| 806 | 100); |
| 807 | input_report_abs(ts->input_dev, ABS_MT_POSITION_X, |
| 808 | x_position); |
| 809 | input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, |
| 810 | y_position); |
| 811 | #endif |
| 812 | } |
| 813 | else |
| 814 | input_report_key(ts->input_dev, KEY_HOME, 1); |
| 815 | } |
| 816 | else if ( tp_key_index == 0x04) |
| 817 | { |
| 818 | vk_press = 1; |
| 819 | I("APP_switch key pressed\n"); |
| 820 | if (ts->pdata->virtual_key) |
| 821 | { |
| 822 | if (ts->button[2].index) |
| 823 | { |
| 824 | x_position = (ts->button[2].x_range_min + ts->button[2].x_range_max) / 2; |
| 825 | y_position = (ts->button[2].y_range_min + ts->button[2].y_range_max) / 2; |
| 826 | } |
| 827 | #ifdef HX_PROTOCOL_A |
| 828 | input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, 0); |
| 829 | |
| 830 | input_report_abs(ts->input_dev, ABS_MT_PRESSURE, |
| 831 | 100); |
| 832 | input_report_abs(ts->input_dev, ABS_MT_POSITION_X, |
| 833 | x_position); |
| 834 | input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, |
| 835 | y_position); |
| 836 | input_mt_sync(ts->input_dev); |
| 837 | #else |
| 838 | input_mt_slot(ts->input_dev, 0); |
| 839 | input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, |
| 840 | 1); |
| 841 | input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, |
| 842 | 100); |
| 843 | input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, |
| 844 | 100); |
| 845 | input_report_abs(ts->input_dev, ABS_MT_PRESSURE, |
| 846 | 100); |
| 847 | input_report_abs(ts->input_dev, ABS_MT_POSITION_X, |
| 848 | x_position); |
| 849 | input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, |
| 850 | y_position); |
| 851 | #endif |
| 852 | } |
| 853 | else |
| 854 | input_report_key(ts->input_dev, KEY_APP_SWITCH, 1); |
| 855 | } |
| 856 | input_sync(ts->input_dev); |
| 857 | } |
| 858 | else/*tp_key_index =0x00*/ |
| 859 | { |
| 860 | I("virtual key released\n"); |
| 861 | vk_press = 0; |
| 862 | #ifndef HX_PROTOCOL_A |
| 863 | input_mt_slot(ts->input_dev, 0); |
| 864 | input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, 0); |
| 865 | #else |
| 866 | input_mt_sync(ts->input_dev); |
| 867 | #endif |
| 868 | input_report_key(ts->input_dev, KEY_BACK, 0); |
| 869 | input_report_key(ts->input_dev, KEY_HOME, 0); |
| 870 | input_report_key(ts->input_dev, KEY_APP_SWITCH, 0); |
| 871 | #ifndef HX_PROTOCOL_A |
| 872 | input_sync(ts->input_dev); |
| 873 | #endif |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | void himax_report_key(struct himax_ts_data *ts) |
| 878 | { |
| 879 | if(hx_point_num!=0) |
| 880 | { |
| 881 | //Touch KEY |
| 882 | if ((tpd_key_old != 0x00)&&(tpd_key == 0x00)) |
| 883 | { |
| 884 | //temp_x[0] = 0xFFFF; |
| 885 | //temp_y[0] = 0xFFFF; |
| 886 | //temp_x[1] = 0xFFFF; |
| 887 | //temp_y[1] = 0xFFFF; |
| 888 | hx_touch_data->finger_on = 0; |
| 889 | #ifdef HX_PROTOCOL_A |
| 890 | input_report_key(ts->input_dev, BTN_TOUCH, hx_touch_data->finger_on); |
| 891 | #endif |
| 892 | himax_ts_button_func(tpd_key,ts); |
| 893 | } |
| 894 | #ifndef HX_PROTOCOL_A |
| 895 | input_report_key(ts->input_dev, BTN_TOUCH, hx_touch_data->finger_on); |
| 896 | #endif |
| 897 | input_sync(ts->input_dev); |
| 898 | } |
| 899 | else |
| 900 | { |
| 901 | if (tpd_key != 0x00) |
| 902 | { |
| 903 | hx_touch_data->finger_on = 1; |
| 904 | #ifdef HX_PROTOCOL_A |
| 905 | input_report_key(ts->input_dev, BTN_TOUCH, hx_touch_data->finger_on); |
| 906 | #endif |
| 907 | himax_ts_button_func(tpd_key,ts); |
| 908 | |
| 909 | } |
| 910 | else if ((tpd_key_old != 0x00)&&(tpd_key == 0x00)) |
| 911 | { |
| 912 | hx_touch_data->finger_on = 0; |
| 913 | #ifdef HX_PROTOCOL_A |
| 914 | input_report_key(ts->input_dev, BTN_TOUCH, hx_touch_data->finger_on); |
| 915 | #endif |
| 916 | himax_ts_button_func(tpd_key,ts); |
| 917 | |
| 918 | } |
| 919 | #ifndef HX_PROTOCOL_A |
| 920 | input_report_key(ts->input_dev, BTN_TOUCH, hx_touch_data->finger_on); |
| 921 | #endif |
| 922 | input_sync(ts->input_dev); |
| 923 | } |
| 924 | tpd_key_old = tpd_key; |
| 925 | Last_EN_NoiseFilter = EN_NoiseFilter; |
| 926 | } |
| 927 | #endif |
| 928 | |
| 929 | int himax_report_data_init(void) |
| 930 | { |
| 931 | if(hx_touch_data->hx_coord_buf!=NULL) |
| 932 | { |
| 933 | kfree(hx_touch_data->hx_coord_buf); |
| 934 | } |
| 935 | #ifdef HX_TP_PROC_DIAG |
| 936 | if(hx_touch_data->hx_rawdata_buf!=NULL) |
| 937 | { |
| 938 | kfree(hx_touch_data->hx_rawdata_buf); |
| 939 | } |
| 940 | #endif |
| 941 | |
| 942 | #if defined(HX_SMART_WAKEUP) |
| 943 | hx_touch_data->event_size = himax_get_touch_data_size(); |
| 944 | if(hx_touch_data->hx_event_buf!=NULL) |
| 945 | { |
| 946 | kfree(hx_touch_data->hx_event_buf); |
| 947 | } |
| 948 | #endif |
| 949 | |
| 950 | hx_touch_data->touch_all_size = himax_get_touch_data_size(); |
| 951 | hx_touch_data->raw_cnt_max = ic_data->HX_MAX_PT/4; |
| 952 | hx_touch_data->raw_cnt_rmd = ic_data->HX_MAX_PT%4; |
| 953 | |
| 954 | if (hx_touch_data->raw_cnt_rmd != 0x00) //more than 4 fingers |
| 955 | { |
| 956 | hx_touch_data->rawdata_size = cal_data_len(hx_touch_data->raw_cnt_rmd, ic_data->HX_MAX_PT, hx_touch_data->raw_cnt_max); |
| 957 | hx_touch_data->touch_info_size = (ic_data->HX_MAX_PT+hx_touch_data->raw_cnt_max+2)*4; |
| 958 | } |
| 959 | else //less than 4 fingers |
| 960 | { |
| 961 | hx_touch_data->rawdata_size = cal_data_len(hx_touch_data->raw_cnt_rmd, ic_data->HX_MAX_PT, hx_touch_data->raw_cnt_max); |
| 962 | hx_touch_data->touch_info_size = (ic_data->HX_MAX_PT+hx_touch_data->raw_cnt_max+1)*4; |
| 963 | } |
| 964 | if((ic_data->HX_TX_NUM * ic_data->HX_RX_NUM + ic_data->HX_TX_NUM + ic_data->HX_RX_NUM) % hx_touch_data->rawdata_size == 0) |
| 965 | hx_touch_data->rawdata_frame_size = (ic_data->HX_TX_NUM * ic_data->HX_RX_NUM + ic_data->HX_TX_NUM + ic_data->HX_RX_NUM) / hx_touch_data->rawdata_size; |
| 966 | else |
| 967 | hx_touch_data->rawdata_frame_size = (ic_data->HX_TX_NUM * ic_data->HX_RX_NUM + ic_data->HX_TX_NUM + ic_data->HX_RX_NUM) / hx_touch_data->rawdata_size + 1; |
| 968 | I("%s: rawdata_frame_size = %d ",__func__,hx_touch_data->rawdata_frame_size); |
| 969 | I("%s: ic_data->HX_MAX_PT:%d,hx_raw_cnt_max:%d,hx_raw_cnt_rmd:%d,g_hx_rawdata_size:%d,hx_touch_data->touch_info_size:%d\n",__func__,ic_data->HX_MAX_PT,hx_touch_data->raw_cnt_max,hx_touch_data->raw_cnt_rmd,hx_touch_data->rawdata_size,hx_touch_data->touch_info_size); |
| 970 | |
| 971 | hx_touch_data->hx_coord_buf = kzalloc(sizeof(uint8_t)*(hx_touch_data->touch_info_size),GFP_KERNEL); |
| 972 | if(hx_touch_data->hx_coord_buf == NULL) |
| 973 | goto mem_alloc_fail; |
| 974 | #ifdef HX_TP_PROC_DIAG |
| 975 | hx_touch_data->hx_rawdata_buf = kzalloc(sizeof(uint8_t)*(hx_touch_data->touch_all_size - hx_touch_data->touch_info_size),GFP_KERNEL); |
| 976 | if(hx_touch_data->hx_rawdata_buf == NULL) |
| 977 | goto mem_alloc_fail; |
| 978 | #endif |
| 979 | |
| 980 | #if defined(HX_SMART_WAKEUP) |
| 981 | hx_touch_data->hx_event_buf = kzalloc(sizeof(uint8_t)*(hx_touch_data->event_size),GFP_KERNEL); |
| 982 | if(hx_touch_data->hx_event_buf == NULL) |
| 983 | goto mem_alloc_fail; |
| 984 | #endif |
| 985 | |
| 986 | return NO_ERR; |
| 987 | |
| 988 | mem_alloc_fail: |
| 989 | kfree(hx_touch_data->hx_coord_buf); |
| 990 | #if defined(HX_TP_PROC_DIAG) |
| 991 | kfree(hx_touch_data->hx_rawdata_buf); |
| 992 | #endif |
| 993 | #if defined(HX_SMART_WAKEUP) |
| 994 | kfree(hx_touch_data->hx_event_buf); |
| 995 | #endif |
| 996 | |
| 997 | I("%s: Memory allocate fail!\n",__func__); |
| 998 | return MEM_ALLOC_FAIL; |
| 999 | |
| 1000 | } |
| 1001 | |
| 1002 | |
| 1003 | #if defined(HX_USB_DETECT_GLOBAL) |
| 1004 | /*[Arima_8901][TracyChui]Add usb plug detect function and updated FW CID0804_D02_C13 20190816 start */ |
| 1005 | void himax_read_file_func(char *pFilePath, u8 *pBuf, u16 nLength) |
| 1006 | { |
| 1007 | struct file *pFile = NULL; |
| 1008 | mm_segment_t old_fs; |
| 1009 | ssize_t nReadBytes = 0; |
| 1010 | |
| 1011 | old_fs = get_fs(); |
| 1012 | set_fs(get_ds()); |
| 1013 | |
| 1014 | pFile = filp_open(pFilePath, O_RDONLY, 0); |
| 1015 | |
| 1016 | if (IS_ERR(pFile)) { |
| 1017 | printk ( "[Tracy]Open file failed: %s\n", pFilePath); |
| 1018 | return; |
| 1019 | } |
| 1020 | |
| 1021 | pFile->f_op->llseek(pFile, 0, SEEK_SET); |
| 1022 | nReadBytes = pFile->f_op->read(pFile, pBuf, nLength, &pFile->f_pos); |
| 1023 | |
| 1024 | set_fs(old_fs); |
| 1025 | |
| 1026 | filp_close(pFile, NULL); |
| 1027 | |
| 1028 | } |
| 1029 | |
| 1030 | void himax_cable_detect_func(bool force_renew) |
| 1031 | { |
| 1032 | struct himax_ts_data *ts; |
| 1033 | u32 connect_status = 0; |
| 1034 | u8 szChargerStatus[20] = {0}; |
| 1035 | |
| 1036 | ts = private_ts; |
| 1037 | |
| 1038 | if (ts->suspended==false) |
| 1039 | { |
| 1040 | himax_read_file_func(POWER_SUPPLY_BATTERY_STATUS_PATCH, szChargerStatus, 20); |
| 1041 | if (strstr(szChargerStatus, "Charging") != NULL || strstr(szChargerStatus, "Full") != NULL || strstr(szChargerStatus, "Fully charged") != NULL) // Charging |
| 1042 | { |
| 1043 | connect_status=1; |
| 1044 | } |
| 1045 | else |
| 1046 | { |
| 1047 | connect_status=0; |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | if (ts->cable_config) |
| 1052 | { |
| 1053 | if (((!!connect_status) != ts->usb_connected) || force_renew) |
| 1054 | { |
| 1055 | if (!!connect_status) |
| 1056 | { |
| 1057 | ts->cable_config[1] = 0x01; |
| 1058 | ts->usb_connected = 0x01; |
| 1059 | } |
| 1060 | else |
| 1061 | { |
| 1062 | ts->cable_config[1] = 0x00; |
| 1063 | ts->usb_connected = 0x00; |
| 1064 | } |
| 1065 | himax_usb_detect_set(ts->client,ts->cable_config); |
| 1066 | printk("%s: Cable status change: 0x%2.2X\n", __func__, ts->usb_connected); |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | /*[Arima_8901][TracyChui] 20190816 end */ |
| 1071 | #endif |
| 1072 | |
| 1073 | |
| 1074 | void himax_report_points(struct himax_ts_data *ts) |
| 1075 | { |
| 1076 | int x = 0; |
| 1077 | int y = 0; |
| 1078 | int w = 0; |
| 1079 | int base = 0; |
| 1080 | int32_t loop_i = 0; |
| 1081 | uint16_t old_finger = 0; |
| 1082 | |
| 1083 | //I("%s:Entering\n",__func__); |
| 1084 | |
| 1085 | /* finger on/press */ |
| 1086 | if (hx_point_num != 0 ) |
| 1087 | { |
| 1088 | old_finger = ts->pre_finger_mask; |
| 1089 | ts->pre_finger_mask = 0; |
| 1090 | hx_touch_data->finger_num = hx_touch_data->hx_coord_buf[ts->coordInfoSize - 4] & 0x0F; |
| 1091 | hx_touch_data->finger_on = 1; |
| 1092 | AA_press = 1; |
| 1093 | for (loop_i = 0; loop_i < ts->nFinger_support; loop_i++) |
| 1094 | { |
| 1095 | base = loop_i * 4; |
| 1096 | x = hx_touch_data->hx_coord_buf[base] << 8 | hx_touch_data->hx_coord_buf[base + 1]; |
| 1097 | y = (hx_touch_data->hx_coord_buf[base + 2] << 8 | hx_touch_data->hx_coord_buf[base + 3]); |
| 1098 | w = hx_touch_data->hx_coord_buf[(ts->nFinger_support * 4) + loop_i]; |
| 1099 | //x = ic_data->HX_X_RES - x; |
| 1100 | //y = ic_data->HX_Y_RES - y; |
| 1101 | //printk("allenyu:abs_x_max = %d \n",ts->pdata->abs_x_max); |
| 1102 | //printk("allenyu:abs_y_max = %d \n",ts->pdata->abs_y_max); |
| 1103 | if(x >= 0 && x <= ts->pdata->abs_x_max && y >= 0 && y <= ts->pdata->abs_y_max) |
| 1104 | { |
| 1105 | /*[Arima_8710][allen_yu] close touch driver log 20180411 begin*/ |
| 1106 | //printk("allenyu_010\n"); |
| 1107 | /*[Arima_8710][allen_yu] 20180411 end*/ |
| 1108 | hx_touch_data->finger_num--; |
| 1109 | if ((ts->debug_log_level & BIT(3)) > 0) |
| 1110 | { |
| 1111 | himax_log_touch_event_detail(ts,x,y,w,loop_i,EN_NoiseFilter,HX_FINGER_ON,old_finger); |
| 1112 | } |
| 1113 | #ifndef HX_PROTOCOL_A |
| 1114 | |
| 1115 | input_mt_slot(ts->input_dev, loop_i); |
| 1116 | #endif |
| 1117 | input_report_key(ts->input_dev, BTN_TOUCH, hx_touch_data->finger_on); |
| 1118 | input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w); |
| 1119 | input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, loop_i); |
| 1120 | #ifndef HX_PROTOCOL_A |
| 1121 | input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w); |
| 1122 | input_report_abs(ts->input_dev, ABS_MT_PRESSURE, w); |
| 1123 | #endif |
| 1124 | input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x); |
| 1125 | input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y); |
| 1126 | |
| 1127 | #ifndef HX_PROTOCOL_A |
| 1128 | ts->last_slot = loop_i; |
| 1129 | input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, 1); |
| 1130 | #else |
| 1131 | input_mt_sync(ts->input_dev); |
| 1132 | #endif |
| 1133 | |
| 1134 | if (!ts->first_pressed) |
| 1135 | { |
| 1136 | ts->first_pressed = 1; |
| 1137 | I("S1@%d, %d\n", x, y); |
| 1138 | } |
| 1139 | |
| 1140 | ts->pre_finger_data[loop_i][0] = x; |
| 1141 | ts->pre_finger_data[loop_i][1] = y; |
| 1142 | if (ts->debug_log_level & BIT(1)) |
| 1143 | himax_log_touch_event(x, y, w,loop_i,EN_NoiseFilter,HX_FINGER_ON); |
| 1144 | |
| 1145 | ts->pre_finger_mask = ts->pre_finger_mask + (1 << loop_i); |
| 1146 | } |
| 1147 | /* report coordinates */ |
| 1148 | else |
| 1149 | { |
| 1150 | //printk("allenyu_020\n"); |
| 1151 | #ifndef HX_PROTOCOL_A |
| 1152 | input_mt_slot(ts->input_dev, loop_i); |
| 1153 | input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, 0); |
| 1154 | #endif |
| 1155 | |
| 1156 | if (loop_i == 0 && ts->first_pressed == 1) |
| 1157 | { |
| 1158 | ts->first_pressed = 2; |
| 1159 | I("E1@%d, %d\n", |
| 1160 | ts->pre_finger_data[0][0], ts->pre_finger_data[0][1]); |
| 1161 | } |
| 1162 | if ((ts->debug_log_level & BIT(3)) > 0) |
| 1163 | { |
| 1164 | himax_log_touch_event_detail(ts,x,y,w,loop_i,Last_EN_NoiseFilter,HX_FINGER_LEAVE,old_finger); |
| 1165 | } |
| 1166 | } |
| 1167 | } |
| 1168 | #ifndef HX_PROTOCOL_A |
| 1169 | input_report_key(ts->input_dev, BTN_TOUCH, hx_touch_data->finger_on); |
| 1170 | #endif |
| 1171 | input_sync(ts->input_dev); |
| 1172 | } |
| 1173 | |
| 1174 | /* finger leave/release */ |
| 1175 | else |
| 1176 | { |
| 1177 | #if defined(HX_PALM_REPORT) |
| 1178 | if(himax_palm_detect(hx_touch_data->hx_coord_buf) == NO_ERR) |
| 1179 | { |
| 1180 | I(" %s HX_PALM_REPORT KEY power event press\n",__func__); |
| 1181 | input_report_key(ts->input_dev, KEY_POWER, 1); |
| 1182 | input_sync(ts->input_dev); |
| 1183 | msleep(100); |
| 1184 | I(" %s HX_PALM_REPORT KEY power event release\n",__func__); |
| 1185 | input_report_key(ts->input_dev, KEY_POWER, 0); |
| 1186 | input_sync(ts->input_dev); |
| 1187 | return; |
| 1188 | } |
| 1189 | #endif |
| 1190 | hx_touch_data->finger_on = 0; |
| 1191 | AA_press = 0; |
| 1192 | #ifdef HX_PROTOCOL_A |
| 1193 | input_mt_sync(ts->input_dev); |
| 1194 | #endif |
| 1195 | |
| 1196 | for (loop_i = 0; loop_i < ts->nFinger_support; loop_i++) |
| 1197 | { |
| 1198 | if (((ts->pre_finger_mask >> loop_i) & 1) == 1) |
| 1199 | { |
| 1200 | #ifndef HX_PROTOCOL_A |
| 1201 | input_mt_slot(ts->input_dev, loop_i); |
| 1202 | input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, 0); |
| 1203 | #endif |
| 1204 | } |
| 1205 | if(ts->pre_finger_mask > 0 && (ts->debug_log_level & BIT(3)) > 0) |
| 1206 | { |
| 1207 | if (((ts->pre_finger_mask >> loop_i) & 1) == 1) |
| 1208 | { |
| 1209 | if (ts->useScreenRes) |
| 1210 | { |
| 1211 | I("status:%X, Screen:F:%02d Up, X:%d, Y:%d, N:%d\n", 0, loop_i+1, ts->pre_finger_data[loop_i][0] * ts->widthFactor >> SHIFTBITS, |
| 1212 | ts->pre_finger_data[loop_i][1] * ts->heightFactor >> SHIFTBITS, Last_EN_NoiseFilter); |
| 1213 | } |
| 1214 | else |
| 1215 | { |
| 1216 | I("status:%X, Raw:F:%02d Up, X:%d, Y:%d, N:%d\n",0, loop_i+1, ts->pre_finger_data[loop_i][0],ts->pre_finger_data[loop_i][1], Last_EN_NoiseFilter); |
| 1217 | } |
| 1218 | } |
| 1219 | } |
| 1220 | } |
| 1221 | if (ts->pre_finger_mask > 0) |
| 1222 | { |
| 1223 | /*for (loop_i = 0; loop_i < ts->nFinger_support && (ts->debug_log_level & BIT(3)) > 0; loop_i++) |
| 1224 | { |
| 1225 | if (((ts->pre_finger_mask >> loop_i) & 1) == 1) |
| 1226 | { |
| 1227 | if (ts->useScreenRes) |
| 1228 | { |
| 1229 | I("status:%X, Screen:F:%02d Up, X:%d, Y:%d, N:%d\n", 0, loop_i+1, ts->pre_finger_data[loop_i][0] * ts->widthFactor >> SHIFTBITS, |
| 1230 | ts->pre_finger_data[loop_i][1] * ts->heightFactor >> SHIFTBITS, Last_EN_NoiseFilter); |
| 1231 | } |
| 1232 | else |
| 1233 | { |
| 1234 | I("status:%X, Raw:F:%02d Up, X:%d, Y:%d, N:%d\n",0, loop_i+1, ts->pre_finger_data[loop_i][0],ts->pre_finger_data[loop_i][1], Last_EN_NoiseFilter); |
| 1235 | } |
| 1236 | } |
| 1237 | }*/ |
| 1238 | ts->pre_finger_mask = 0; |
| 1239 | } |
| 1240 | |
| 1241 | if (ts->first_pressed == 1) |
| 1242 | { |
| 1243 | ts->first_pressed = 2; |
| 1244 | I("E1@%d, %d\n",ts->pre_finger_data[0][0], ts->pre_finger_data[0][1]); |
| 1245 | } |
| 1246 | |
| 1247 | if (ts->debug_log_level & BIT(1)) |
| 1248 | himax_log_touch_event(x, y, w,loop_i,EN_NoiseFilter,HX_FINGER_LEAVE); |
| 1249 | |
| 1250 | input_report_key(ts->input_dev, BTN_TOUCH, hx_touch_data->finger_on); |
| 1251 | input_sync(ts->input_dev); |
| 1252 | } |
| 1253 | Last_EN_NoiseFilter = EN_NoiseFilter; |
| 1254 | |
| 1255 | //I("%s:End\n",__func__); |
| 1256 | } |
| 1257 | |
| 1258 | int himax_touch_get(struct himax_ts_data *ts,uint8_t *buf,int ts_status) |
| 1259 | { |
| 1260 | int ret = 0; |
| 1261 | |
| 1262 | switch(ts_status) |
| 1263 | { |
| 1264 | /*normal*/ |
| 1265 | case 1: |
| 1266 | #ifdef HX_TP_PROC_DIAG |
| 1267 | hx_touch_data->diag_cmd = getDiagCommand(); |
| 1268 | |
| 1269 | if((hx_touch_data->diag_cmd) |
| 1270 | || (HX_HW_RESET_ACTIVATE) |
| 1271 | #ifdef HX_ESD_RECOVERY |
| 1272 | || (HX_ESD_RESET_ACTIVATE) |
| 1273 | #endif |
| 1274 | ) |
| 1275 | { |
| 1276 | ret = himax_read_event_stack(ts->client, buf, 128); |
| 1277 | } |
| 1278 | else |
| 1279 | { |
| 1280 | ret = himax_read_event_stack(ts->client, buf, hx_touch_data->touch_info_size); |
| 1281 | } |
| 1282 | |
| 1283 | if (!ret) |
| 1284 | #else |
| 1285 | if(!himax_read_event_stack(ts->client, buf, hx_touch_data->touch_info_size)) |
| 1286 | #endif |
| 1287 | { |
| 1288 | E("%s: can't read data from chip!\n", __func__); |
| 1289 | goto err_workqueue_out; |
| 1290 | } |
| 1291 | break; |
| 1292 | #if defined(HX_SMART_WAKEUP) |
| 1293 | /*SMWP*/ |
| 1294 | case 2: |
| 1295 | himax_burst_enable(ts->client, 0); |
| 1296 | if(!himax_read_event_stack(ts->client,buf,hx_touch_data->event_size)) |
| 1297 | { |
| 1298 | E("%s: can't read data from chip!\n", __func__); |
| 1299 | goto err_workqueue_out; |
| 1300 | } |
| 1301 | break; |
| 1302 | #endif |
| 1303 | default: |
| 1304 | break; |
| 1305 | } |
| 1306 | return NO_ERR; |
| 1307 | |
| 1308 | err_workqueue_out: |
| 1309 | return I2C_FAIL; |
| 1310 | |
| 1311 | } |
| 1312 | |
| 1313 | int himax_checksum_cal(struct himax_ts_data *ts,uint8_t *buf,int ts_status) |
| 1314 | { |
| 1315 | #if defined(HX_ESD_RECOVERY) |
| 1316 | int hx_EB_event = 0; |
| 1317 | int hx_EC_event = 0; |
| 1318 | int hx_ED_event = 0; |
| 1319 | int hx_esd_event = 0; |
| 1320 | int hx_zero_event = 0; |
| 1321 | int shaking_ret = 0; |
| 1322 | #endif |
| 1323 | uint16_t check_sum_cal = 0; |
| 1324 | int32_t loop_i = 0; |
| 1325 | int length = 0; |
| 1326 | |
| 1327 | /* Normal */ |
| 1328 | if(ts_status == HX_REPORT_COORD) |
| 1329 | length = hx_touch_data->touch_info_size; |
| 1330 | #if defined(HX_SMART_WAKEUP) |
| 1331 | /* SMWP */ |
| 1332 | else if(ts_status == HX_REPORT_SMWP_EVENT) |
| 1333 | length = (GEST_PTLG_ID_LEN+GEST_PTLG_HDR_LEN); |
| 1334 | #endif |
| 1335 | else |
| 1336 | { |
| 1337 | I("%s, Neither Normal Nor SMWP error!\n",__func__); |
| 1338 | } |
| 1339 | //I("Now status=%d,length=%d\n",ts_status,length); |
| 1340 | for (loop_i = 0; loop_i < length; loop_i++) |
| 1341 | { |
| 1342 | check_sum_cal+=buf[loop_i]; |
| 1343 | |
| 1344 | /*if (ts->debug_log_level & BIT(0)) |
| 1345 | { |
| 1346 | I("P %d = 0x%2.2X ", loop_i, hx_touch_data->hx_coord_buf[loop_i]); |
| 1347 | if (loop_i % 8 == 7) |
| 1348 | I("\n"); |
| 1349 | }*/ |
| 1350 | |
| 1351 | #ifdef HX_ESD_RECOVERY |
| 1352 | if(ts_status == HX_REPORT_COORD) |
| 1353 | { |
| 1354 | /* case 1 ESD recovery flow */ |
| 1355 | if(buf[loop_i] == 0xEB) |
| 1356 | hx_EB_event++; |
| 1357 | else if(buf[loop_i] == 0xEC) |
| 1358 | hx_EC_event++; |
| 1359 | else if(buf[loop_i] == 0xED) |
| 1360 | hx_ED_event++; |
| 1361 | /* case 2 ESD recovery flow-Disable */ |
| 1362 | else if(buf[loop_i] == 0x00) |
| 1363 | hx_zero_event++; |
| 1364 | else |
| 1365 | { |
| 1366 | hx_EB_event = 0; |
| 1367 | hx_EC_event = 0; |
| 1368 | hx_ED_event = 0; |
| 1369 | hx_zero_event = 0; |
| 1370 | g_zero_event_count = 0; |
| 1371 | } |
| 1372 | |
| 1373 | if(hx_EB_event == length) |
| 1374 | { |
| 1375 | hx_esd_event = length; |
| 1376 | hx_EB_event_flag ++; |
| 1377 | I("[HIMAX TP MSG]: ESD event checked - ALL 0xEB.\n"); |
| 1378 | } |
| 1379 | else if(hx_EC_event == length) |
| 1380 | { |
| 1381 | hx_esd_event = length; |
| 1382 | hx_EC_event_flag ++; |
| 1383 | I("[HIMAX TP MSG]: ESD event checked - ALL 0xEC.\n"); |
| 1384 | } |
| 1385 | else if(hx_ED_event == length) |
| 1386 | { |
| 1387 | hx_esd_event = length; |
| 1388 | hx_ED_event_flag ++; |
| 1389 | I("[HIMAX TP MSG]: ESD event checked - ALL 0xED.\n"); |
| 1390 | } |
| 1391 | else |
| 1392 | { |
| 1393 | hx_esd_event = 0; |
| 1394 | } |
| 1395 | } |
| 1396 | #endif |
| 1397 | } |
| 1398 | |
| 1399 | if(ts_status == HX_REPORT_COORD) |
| 1400 | { |
| 1401 | #ifdef HX_ESD_RECOVERY |
| 1402 | if ((hx_esd_event == length || hx_zero_event == length) |
| 1403 | && (HX_HW_RESET_ACTIVATE == 0) |
| 1404 | && (HX_ESD_RESET_ACTIVATE == 0) |
| 1405 | #if defined(HX_TP_PROC_DIAG) |
| 1406 | && (hx_touch_data->diag_cmd == 0) |
| 1407 | #endif |
| 1408 | #if defined(HX_TP_PROC_SELF_TEST) || defined(CONFIG_TOUCHSCREEN_HIMAX_ITO_TEST) |
| 1409 | && (g_self_test_entered == 0) |
| 1410 | #endif |
| 1411 | ) |
| 1412 | { |
| 1413 | shaking_ret = himax_ic_esd_recovery(hx_esd_event,hx_zero_event,length); |
| 1414 | if(shaking_ret == CHECKSUM_FAIL) |
| 1415 | { |
| 1416 | himax_esd_hw_reset(); |
| 1417 | goto checksum_fail; |
| 1418 | } |
| 1419 | else if(shaking_ret == ERR_WORK_OUT) |
| 1420 | goto err_workqueue_out; |
| 1421 | else |
| 1422 | { |
| 1423 | //I("I2C running. Nothing to be done!\n"); |
| 1424 | goto workqueue_out; |
| 1425 | } |
| 1426 | } |
| 1427 | else if (HX_ESD_RESET_ACTIVATE) |
| 1428 | { |
| 1429 | #if defined(HX_SMART_WAKEUP)||defined(HX_HIGH_SENSE)||defined(HX_USB_DETECT_GLOBAL) |
| 1430 | #ifdef HX_RESUME_SEND_CMD |
| 1431 | /*[Arima_7947][allen_yu] Change the rule of upgrading fw 20171221 begin*/ |
| 1432 | #if 0 |
| 1433 | himax_resend_cmd_func(ts->suspended); |
| 1434 | #endif |
| 1435 | himax_rst_cmd_recovery_func(ts->suspended); |
| 1436 | /*[Arima_7947][allen_yu] 20171221 end*/ |
| 1437 | #endif |
| 1438 | #endif |
| 1439 | /* drop 1st interrupts after chip reset */ |
| 1440 | HX_ESD_RESET_ACTIVATE = 0; |
| 1441 | I("[HX_ESD_RESET_ACTIVATE]:%s: Back from reset, ready to serve.\n", __func__); |
| 1442 | goto checksum_fail; |
| 1443 | } |
| 1444 | |
| 1445 | else if (HX_HW_RESET_ACTIVATE) |
| 1446 | #else |
| 1447 | if (HX_HW_RESET_ACTIVATE) |
| 1448 | #endif |
| 1449 | { |
| 1450 | #if defined(HX_SMART_WAKEUP)||defined(HX_HIGH_SENSE)||defined(HX_USB_DETECT_GLOBAL) |
| 1451 | #ifdef HX_RESUME_SEND_CMD |
| 1452 | /*[Arima_7947][allen_yu] Change the rule of upgrading fw 20171221 begin*/ |
| 1453 | #if 0 |
| 1454 | himax_resend_cmd_func(ts->suspended); |
| 1455 | #endif |
| 1456 | himax_rst_cmd_recovery_func(ts->suspended); |
| 1457 | /*[Arima_7947][allen_yu] 20171221 end*/ |
| 1458 | #endif |
| 1459 | #endif |
| 1460 | /* drop 1st interrupts after chip reset */ |
| 1461 | HX_HW_RESET_ACTIVATE = 0; |
| 1462 | I("[HX_HW_RESET_ACTIVATE]:%s: Back from reset, ready to serve.\n", __func__); |
| 1463 | goto ready_to_serve; |
| 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | if ((check_sum_cal % 0x100 != 0) ) |
| 1468 | { |
| 1469 | I("[HIMAX TP MSG] checksum fail : check_sum_cal: 0x%02X\n", check_sum_cal); |
| 1470 | goto checksum_fail; |
| 1471 | } |
| 1472 | |
| 1473 | /* I("%s:End\n",__func__); */ |
| 1474 | return NO_ERR; |
| 1475 | |
| 1476 | ready_to_serve: |
| 1477 | return READY_TO_SERVE; |
| 1478 | checksum_fail: |
| 1479 | return CHECKSUM_FAIL; |
| 1480 | #ifdef HX_ESD_RECOVERY |
| 1481 | err_workqueue_out: |
| 1482 | return ERR_WORK_OUT; |
| 1483 | workqueue_out: |
| 1484 | return WORK_OUT; |
| 1485 | #endif |
| 1486 | } |
| 1487 | |
| 1488 | int himax_ts_work_status(struct himax_ts_data *ts) |
| 1489 | { |
| 1490 | /* 1: normal, 2:SMWP */ |
| 1491 | int result = HX_REPORT_COORD; |
| 1492 | uint8_t diag_cmd = 0; |
| 1493 | |
| 1494 | #ifdef HX_TP_PROC_DIAG |
| 1495 | diag_cmd = getDiagCommand(); |
| 1496 | #endif |
| 1497 | |
| 1498 | #ifdef HX_SMART_WAKEUP |
| 1499 | if (atomic_read(&ts->suspend_mode)&&(!FAKE_POWER_KEY_SEND)&&(ts->SMWP_enable)&&(!diag_cmd)) |
| 1500 | { |
| 1501 | result = HX_REPORT_SMWP_EVENT; |
| 1502 | } |
| 1503 | #endif |
| 1504 | /* I("Now Status is %d\n",result); */ |
| 1505 | return result; |
| 1506 | } |
| 1507 | |
| 1508 | void himax_assign_touch_data(uint8_t *buf,int ts_status) |
| 1509 | { |
| 1510 | uint8_t hx_state_info_pos = hx_touch_data->touch_info_size - 3; |
| 1511 | |
| 1512 | if(ts_status == HX_REPORT_COORD) |
| 1513 | { |
| 1514 | memcpy(hx_touch_data->hx_coord_buf,&buf[0],hx_touch_data->touch_info_size); |
| 1515 | if(buf[hx_state_info_pos] != 0xFF && buf[hx_state_info_pos + 1] != 0xFF ) |
| 1516 | memcpy(hx_touch_data->hx_state_info,&buf[hx_state_info_pos],2); |
| 1517 | else |
| 1518 | memset(hx_touch_data->hx_state_info, 0x00, sizeof(hx_touch_data->hx_state_info)); |
| 1519 | } |
| 1520 | #if defined(HX_SMART_WAKEUP) |
| 1521 | else |
| 1522 | memcpy(hx_touch_data->hx_event_buf,buf,hx_touch_data->event_size); |
| 1523 | #endif |
| 1524 | |
| 1525 | #ifdef HX_TP_PROC_DIAG |
| 1526 | if((hx_touch_data->diag_cmd) |
| 1527 | || (HX_HW_RESET_ACTIVATE) |
| 1528 | #ifdef HX_ESD_RECOVERY |
| 1529 | || (HX_ESD_RESET_ACTIVATE) |
| 1530 | #endif |
| 1531 | ) |
| 1532 | { |
| 1533 | memcpy(hx_touch_data->hx_rawdata_buf,&buf[hx_touch_data->touch_info_size],hx_touch_data->touch_all_size - hx_touch_data->touch_info_size); |
| 1534 | } |
| 1535 | #endif |
| 1536 | |
| 1537 | } |
| 1538 | |
| 1539 | void himax_coord_report(struct himax_ts_data *ts) |
| 1540 | { |
| 1541 | |
| 1542 | #if defined(HX_TP_PROC_DIAG) |
| 1543 | //touch monitor raw data fetch |
| 1544 | if(himax_set_diag_cmd(ic_data,hx_touch_data)) |
| 1545 | I("%s: coordinate dump fail and bypass with checksum err\n",__func__); |
| 1546 | #endif |
| 1547 | EN_NoiseFilter = (hx_touch_data->hx_coord_buf[HX_TOUCH_INFO_POINT_CNT+2]>>3); |
| 1548 | //I("EN_NoiseFilter=%d\n",EN_NoiseFilter); |
| 1549 | EN_NoiseFilter = EN_NoiseFilter & 0x01; |
| 1550 | //I("EN_NoiseFilter2=%d\n",EN_NoiseFilter); |
| 1551 | |
| 1552 | #if defined(HX_EN_SEL_BUTTON) || defined(HX_EN_MUT_BUTTON) |
| 1553 | tpd_key = (hx_touch_data->hx_coord_buf[HX_TOUCH_INFO_POINT_CNT+2]>>4); |
| 1554 | /* All (VK+AA)leave */ |
| 1555 | if (tpd_key == 0x0F) |
| 1556 | { |
| 1557 | tpd_key = 0x00; |
| 1558 | } |
| 1559 | //I("[DEBUG] tpd_key: %x\r\n", tpd_key); |
| 1560 | #else |
| 1561 | tpd_key = 0x00; |
| 1562 | #endif |
| 1563 | |
| 1564 | p_point_num = hx_point_num; |
| 1565 | |
| 1566 | if (hx_touch_data->hx_coord_buf[HX_TOUCH_INFO_POINT_CNT] == 0xff) |
| 1567 | hx_point_num = 0; |
| 1568 | else |
| 1569 | hx_point_num= hx_touch_data->hx_coord_buf[HX_TOUCH_INFO_POINT_CNT] & 0x0f; |
| 1570 | |
| 1571 | /* Touch Point information */ |
| 1572 | if(!tpd_key && !tpd_key_old) |
| 1573 | himax_report_points(ts); |
| 1574 | #if defined(HX_EN_SEL_BUTTON) || defined(HX_EN_MUT_BUTTON) |
| 1575 | else |
| 1576 | himax_report_key(ts); |
| 1577 | #endif |
| 1578 | /* I("%s:END\n",__func__); */ |
| 1579 | |
| 1580 | } |
| 1581 | |
| 1582 | void himax_ts_work(struct himax_ts_data *ts) |
| 1583 | { |
| 1584 | uint8_t hw_reset_check[2]; |
| 1585 | uint8_t buf[128]; |
| 1586 | int check_sum_cal = 0; |
| 1587 | //int loop_i = 0; |
| 1588 | int ts_status = 0; |
| 1589 | #ifdef HX_CHIP_STATUS_MONITOR |
| 1590 | int j=0; |
| 1591 | #endif |
| 1592 | |
| 1593 | #if defined(HX_USB_DETECT_GLOBAL) |
| 1594 | himax_cable_detect_func(false); |
| 1595 | #endif |
| 1596 | |
| 1597 | #if defined(HX_CHIP_STATUS_MONITOR) |
| 1598 | g_chip_monitor_data->HX_CHIP_POLLING_COUNT=0; |
| 1599 | if(g_chip_monitor_data->HX_ON_HAND_SHAKING)//chip on hand shaking,wait hand shaking |
| 1600 | { |
| 1601 | for(j=0; j<100; j++) |
| 1602 | { |
| 1603 | if(g_chip_monitor_data->HX_ON_HAND_SHAKING==0)//chip on hand shaking end |
| 1604 | { |
| 1605 | I("%s:HX_ON_HAND_SHAKING OK check %d times\n",__func__,j); |
| 1606 | break; |
| 1607 | } |
| 1608 | else |
| 1609 | msleep(1); |
| 1610 | } |
| 1611 | if(j==100) |
| 1612 | { |
| 1613 | E("%s:HX_ON_HAND_SHAKING timeout reject interrupt\n",__func__); |
| 1614 | return; |
| 1615 | } |
| 1616 | } |
| 1617 | #endif |
| 1618 | |
| 1619 | ts_status = himax_ts_work_status(ts); |
| 1620 | if(ts_status > HX_REPORT_SMWP_EVENT || ts_status < HX_REPORT_COORD) |
| 1621 | goto neither_normal_nor_smwp; |
| 1622 | |
| 1623 | memset(buf, 0x00, sizeof(buf)); |
| 1624 | memset(hw_reset_check, 0x00, sizeof(hw_reset_check)); |
| 1625 | |
| 1626 | //I("New Method for ts_work\n"); |
| 1627 | |
| 1628 | if(himax_touch_get(ts,buf,ts_status)) |
| 1629 | goto err_workqueue_out; |
| 1630 | |
| 1631 | if (ts->debug_log_level & BIT(0)) |
| 1632 | { |
| 1633 | |
| 1634 | himax_log_touch_data(buf,hx_touch_data); |
| 1635 | |
| 1636 | } |
| 1637 | |
| 1638 | check_sum_cal = himax_checksum_cal(ts,buf,ts_status); |
| 1639 | if (check_sum_cal == CHECKSUM_FAIL) |
| 1640 | goto checksum_fail; |
| 1641 | else if (check_sum_cal == READY_TO_SERVE) |
| 1642 | goto ready_to_serve; |
| 1643 | else if (check_sum_cal == ERR_WORK_OUT) |
| 1644 | goto err_workqueue_out; |
| 1645 | else if (check_sum_cal == WORK_OUT) |
| 1646 | goto workqueue_out; |
| 1647 | /* checksum calculate pass and assign data to global touch data*/ |
| 1648 | else |
| 1649 | himax_assign_touch_data(buf,ts_status); |
| 1650 | |
| 1651 | if(ts_status == HX_REPORT_COORD) |
| 1652 | himax_coord_report(ts); |
| 1653 | #if defined(HX_SMART_WAKEUP) |
| 1654 | else |
| 1655 | { |
| 1656 | //wake_lock_timeout(&ts->ts_SMWP_wake_lock, TS_WAKE_LOCK_TIMEOUT); |
| 1657 | __pm_wakeup_event(&ts->ts_SMWP_wake_lock, TS_WAKE_LOCK_TIMEOUT); |
| 1658 | msleep(200); |
| 1659 | himax_wake_check_func(); |
| 1660 | } |
| 1661 | #endif |
| 1662 | |
| 1663 | checksum_fail: |
| 1664 | workqueue_out: |
| 1665 | ready_to_serve: |
| 1666 | neither_normal_nor_smwp: |
| 1667 | return; |
| 1668 | |
| 1669 | err_workqueue_out: |
| 1670 | I("%s: Now reset the Touch chip.\n", __func__); |
| 1671 | |
| 1672 | #ifdef HX_RST_PIN_FUNC |
| 1673 | himax_ic_reset(false,true); |
| 1674 | #endif |
| 1675 | |
| 1676 | goto workqueue_out; |
| 1677 | } |
| 1678 | enum hrtimer_restart himax_ts_timer_func(struct hrtimer *timer) |
| 1679 | { |
| 1680 | struct himax_ts_data *ts; |
| 1681 | |
| 1682 | ts = container_of(timer, struct himax_ts_data, timer); |
| 1683 | queue_work(ts->himax_wq, &ts->work); |
| 1684 | hrtimer_start(&ts->timer, ktime_set(0, 12500000), HRTIMER_MODE_REL); |
| 1685 | return HRTIMER_NORESTART; |
| 1686 | } |
| 1687 | |
| 1688 | #if defined( HX_USB_DETECT_CALLBACK) |
| 1689 | static void himax_cable_tp_status_handler_func(int connect_status) |
| 1690 | { |
| 1691 | struct himax_ts_data *ts; |
| 1692 | I("Touch: cable change to %d\n", connect_status); |
| 1693 | ts = private_ts; |
| 1694 | if (ts->cable_config) |
| 1695 | { |
| 1696 | if (!atomic_read(&ts->suspend_mode)) |
| 1697 | { |
| 1698 | if ((!!connect_status) != ts->usb_connected) |
| 1699 | { |
| 1700 | if (!!connect_status) |
| 1701 | { |
| 1702 | ts->cable_config[1] = 0x01; |
| 1703 | ts->usb_connected = 0x01; |
| 1704 | } |
| 1705 | else |
| 1706 | { |
| 1707 | ts->cable_config[1] = 0x00; |
| 1708 | ts->usb_connected = 0x00; |
| 1709 | } |
| 1710 | |
| 1711 | i2c_himax_master_write(ts->client, ts->cable_config, |
| 1712 | sizeof(ts->cable_config), DEFAULT_RETRY_CNT); |
| 1713 | |
| 1714 | I("%s: Cable status change: 0x%2.2X\n", __func__, ts->cable_config[1]); |
| 1715 | } |
| 1716 | else |
| 1717 | I("%s: Cable status is the same as previous one, ignore.\n", __func__); |
| 1718 | } |
| 1719 | else |
| 1720 | { |
| 1721 | if (connect_status) |
| 1722 | ts->usb_connected = 0x01; |
| 1723 | else |
| 1724 | ts->usb_connected = 0x00; |
| 1725 | I("%s: Cable status remembered: 0x%2.2X\n", __func__, ts->usb_connected); |
| 1726 | } |
| 1727 | } |
| 1728 | } |
| 1729 | |
| 1730 | static struct t_cable_status_notifier himax_cable_status_handler = |
| 1731 | { |
| 1732 | .name = "usb_tp_connected", |
| 1733 | .func = himax_cable_tp_status_handler_func, |
| 1734 | }; |
| 1735 | |
| 1736 | #endif |
| 1737 | |
| 1738 | #ifdef HX_AUTO_UPDATE_FW |
| 1739 | static void himax_update_register(struct work_struct *work) |
| 1740 | { |
| 1741 | I(" %s in", __func__); |
| 1742 | #if defined(HX_CHIP_STATUS_MONITOR) |
| 1743 | I("Cancel Chip monitor during auto-updating!\n"); |
| 1744 | g_chip_monitor_data->HX_CHIP_POLLING_COUNT = 0; |
| 1745 | g_chip_monitor_data->HX_CHIP_MONITOR_EN = 0; |
| 1746 | cancel_delayed_work_sync(&private_ts->himax_chip_monitor); |
| 1747 | #endif |
| 1748 | if(i_update_FW() == false) |
| 1749 | I("NOT Have new FW=NOT UPDATE=\n"); |
| 1750 | else |
| 1751 | I("Have new FW=UPDATE=\n"); |
| 1752 | #ifdef HX_CHIP_STATUS_MONITOR |
| 1753 | I("Auto-updating over, now chip monitor working!\n"); |
| 1754 | g_chip_monitor_data->HX_CHIP_POLLING_COUNT = 0; |
| 1755 | g_chip_monitor_data->HX_CHIP_MONITOR_EN = 1; |
| 1756 | queue_delayed_work(private_ts->himax_chip_monitor_wq, &private_ts->himax_chip_monitor, g_chip_monitor_data->HX_POLLING_TIMER*HZ); |
| 1757 | #endif |
| 1758 | } |
| 1759 | #endif |
| 1760 | |
| 1761 | #ifdef CONFIG_FB |
| 1762 | static void himax_fb_register(struct work_struct *work) |
| 1763 | { |
| 1764 | int ret = 0; |
| 1765 | struct himax_ts_data *ts = container_of(work, struct himax_ts_data, |
| 1766 | work_att.work); |
| 1767 | I(" %s in\n", __func__); |
| 1768 | |
| 1769 | ts->fb_notif.notifier_call = fb_notifier_callback; |
| 1770 | /*[Arima_7947][allen_yu] Modify Mutex initialization in callback function 20180305 begin*/ |
| 1771 | //ParisKuong modified Mutex initialization +++ |
| 1772 | mutex_init(&ts->ops_lock); |
| 1773 | //ParisKuong modified Mutex initialization --- |
| 1774 | /*[Arima_7947][allen_yu] 20180305 end*/ |
| 1775 | ret = fb_register_client(&ts->fb_notif); |
| 1776 | if (ret) |
| 1777 | E(" Unable to register fb_notifier: %d\n", ret); |
| 1778 | } |
| 1779 | #endif |
| 1780 | |
| 1781 | #if defined(CONFIG_TOUCHSCREEN_HIMAX_ITO_TEST) |
| 1782 | static void himax_ito_test_work(struct work_struct *work) |
| 1783 | { |
| 1784 | I(" %s in\n", __func__); |
| 1785 | himax_ito_test(); |
| 1786 | } |
| 1787 | #endif |
| 1788 | |
| 1789 | #ifdef HX_TP_PROC_FLASH_DUMP |
| 1790 | static void himax_ts_flash_work_func(struct work_struct *work) |
| 1791 | { |
| 1792 | himax_ts_flash_func(); |
| 1793 | } |
| 1794 | #endif |
| 1795 | /*[Arima_7947][allen_yu] Change the rule of upgrading fw 20171221 begin*/ |
| 1796 | #ifdef HX_TP_PROC_GUEST_INFO |
| 1797 | static void himax_ts_guest_info_work_func(struct work_struct *work) |
| 1798 | { |
| 1799 | |
| 1800 | himax_read_project_id(); |
| 1801 | |
| 1802 | } |
| 1803 | #endif |
| 1804 | /*[Arima_7947][allen_yu] 20171221 end*/ |
| 1805 | #ifdef HX_TP_PROC_DIAG |
| 1806 | static void himax_ts_diag_work_func(struct work_struct *work) |
| 1807 | { |
| 1808 | himax_ts_diag_func(); |
| 1809 | } |
| 1810 | #endif |
| 1811 | |
| 1812 | /*[Arima_8710][allen_yu] Solve the report point issue 20180619 begin*/ |
| 1813 | static void himax_release_all_finger(void) |
| 1814 | { |
| 1815 | struct input_dev *input_dev = private_ts->input_dev; |
| 1816 | u32 finger_count = 0; |
| 1817 | |
| 1818 | |
| 1819 | I("%s: enter \n", __func__); |
| 1820 | mutex_lock(&private_ts->report_mutex); |
| 1821 | for (finger_count = 0; finger_count < private_ts->nFinger_support; finger_count++) { |
| 1822 | input_mt_slot(input_dev, finger_count); |
| 1823 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, 0); |
| 1824 | } |
| 1825 | input_report_key(input_dev, BTN_TOUCH, 0); |
| 1826 | input_sync(input_dev); |
| 1827 | mutex_unlock(&private_ts->report_mutex); |
| 1828 | I("%s: exit \n", __func__); |
| 1829 | } |
| 1830 | /*[Arima_8710][allen_yu] 20180619 end*/ |
| 1831 | |
| 1832 | int himax_chip_common_probe(struct i2c_client *client, const struct i2c_device_id *id) |
| 1833 | { |
| 1834 | int ret = 0, err = 0; |
| 1835 | bool auto_update_flag = false; |
| 1836 | struct himax_ts_data *ts; |
| 1837 | struct himax_i2c_platform_data *pdata; |
| 1838 | |
| 1839 | printk("himax probe enter \n"); |
| 1840 | |
| 1841 | //Check I2C functionality |
| 1842 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) |
| 1843 | { |
| 1844 | E("%s: i2c check functionality error\n", __func__); |
| 1845 | err = -ENODEV; |
| 1846 | goto err_check_functionality_failed; |
| 1847 | } |
| 1848 | |
| 1849 | ts = kzalloc(sizeof(struct himax_ts_data), GFP_KERNEL); |
| 1850 | if (ts == NULL) |
| 1851 | { |
| 1852 | E("%s: allocate himax_ts_data failed\n", __func__); |
| 1853 | err = -ENOMEM; |
| 1854 | goto err_alloc_data_failed; |
| 1855 | } |
| 1856 | |
| 1857 | i2c_set_clientdata(client, ts); |
| 1858 | ts->client = client; |
| 1859 | ts->dev = &client->dev; |
| 1860 | mutex_init(&ts->rw_lock); |
| 1861 | |
| 1862 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); |
| 1863 | if (pdata == NULL) /*Allocate Platform data space*/ |
| 1864 | { |
| 1865 | err = -ENOMEM; |
| 1866 | goto err_dt_platform_data_fail; |
| 1867 | } |
| 1868 | |
| 1869 | ic_data = kzalloc(sizeof(*ic_data), GFP_KERNEL); |
| 1870 | if (ic_data == NULL) /*Allocate IC data space*/ |
| 1871 | { |
| 1872 | err = -ENOMEM; |
| 1873 | goto err_dt_ic_data_fail; |
| 1874 | } |
| 1875 | |
| 1876 | /* allocate report data */ |
| 1877 | hx_touch_data = kzalloc(sizeof(struct himax_report_data),GFP_KERNEL); |
| 1878 | if(hx_touch_data == NULL) |
| 1879 | { |
| 1880 | err = -ENOMEM; |
| 1881 | goto err_alloc_data_failed; |
| 1882 | } |
| 1883 | |
| 1884 | if (himax_parse_dt(ts, pdata) < 0) |
| 1885 | { |
| 1886 | I(" pdata is NULL for DT\n"); |
| 1887 | goto err_alloc_dt_pdata_failed; |
| 1888 | } |
| 1889 | |
| 1890 | #ifdef HX_RST_PIN_FUNC |
| 1891 | ts->rst_gpio = pdata->gpio_reset; |
| 1892 | #endif |
| 1893 | |
| 1894 | himax_gpio_power_config(ts->client, pdata); |
| 1895 | |
| 1896 | #ifndef CONFIG_OF |
| 1897 | if (pdata->power) |
| 1898 | { |
| 1899 | ret = pdata->power(1); |
| 1900 | if (ret < 0) |
| 1901 | { |
| 1902 | E("%s: power on failed\n", __func__); |
| 1903 | goto err_power_failed; |
| 1904 | } |
| 1905 | } |
| 1906 | #endif |
| 1907 | private_ts = ts; |
| 1908 | |
| 1909 | if (himax_ic_package_check(ts->client) == false) |
| 1910 | { |
| 1911 | E("Himax chip doesn NOT EXIST"); |
| 1912 | goto err_ic_package_failed; |
| 1913 | } |
| 1914 | |
| 1915 | if (pdata->virtual_key) |
| 1916 | ts->button = pdata->virtual_key; |
| 1917 | #ifdef HX_TP_PROC_FLASH_DUMP |
| 1918 | ts->flash_wq = create_singlethread_workqueue("himax_flash_wq"); |
| 1919 | if (!ts->flash_wq) |
| 1920 | { |
| 1921 | E("%s: create flash workqueue failed\n", __func__); |
| 1922 | err = -ENOMEM; |
| 1923 | goto err_create_wq_failed; |
| 1924 | } |
| 1925 | |
| 1926 | INIT_WORK(&ts->flash_work, himax_ts_flash_work_func); |
| 1927 | |
| 1928 | setSysOperation(0); |
| 1929 | setFlashBuffer(); |
| 1930 | #endif |
| 1931 | /*[Arima_7947][allen_yu] Change the rule of upgrading fw 20171221 begin*/ |
| 1932 | #ifdef HX_TP_PROC_GUEST_INFO |
| 1933 | ts->guest_info_wq = create_singlethread_workqueue("himax_guest_info_wq"); |
| 1934 | if (!ts->guest_info_wq) |
| 1935 | { |
| 1936 | E("%s: create guest info workqueue failed\n", __func__); |
| 1937 | err = -ENOMEM; |
| 1938 | goto err_create_guest_info_wq_failed; |
| 1939 | } |
| 1940 | INIT_WORK(&ts->guest_info_work, himax_ts_guest_info_work_func); |
| 1941 | #endif |
| 1942 | /*[Arima_7947][allen_yu] 20171221 end*/ |
| 1943 | #ifdef HX_TP_PROC_DIAG |
| 1944 | ts->himax_diag_wq = create_singlethread_workqueue("himax_diag"); |
| 1945 | if (!ts->himax_diag_wq) |
| 1946 | { |
| 1947 | E("%s: create diag workqueue failed\n", __func__); |
| 1948 | err = -ENOMEM; |
| 1949 | goto err_create_wq_failed; |
| 1950 | } |
| 1951 | INIT_DELAYED_WORK(&ts->himax_diag_delay_wrok, himax_ts_diag_work_func); |
| 1952 | #endif |
| 1953 | |
| 1954 | himax_read_FW_ver(client); |
| 1955 | auto_update_flag = !himax_calculateChecksum(client, false); |
| 1956 | #ifdef HX_AUTO_UPDATE_FW |
| 1957 | /*[Arima_7947][allen_yu] Change the rule of upgrading fw 20171221 begin*/ |
| 1958 | #if 0 |
| 1959 | auto_update_flag |= (( ic_data->vendor_fw_ver < g_i_FW_VER ) || ( ic_data->vendor_config_ver < g_i_CFG_VER )); |
| 1960 | /* Not sure to do */ |
| 1961 | auto_update_flag |= ((ic_data->vendor_cid_maj_ver != g_i_CID_MAJ) || (ic_data->vendor_cid_min_ver < g_i_CID_MIN)); |
| 1962 | /*[Arima_8710][allen_yu] Modify the touch fw dynamic auto upgtade rule 20180830 begin*/ |
| 1963 | auto_update_flag |= (( ic_data->vendor_touch_cfg_ver < ((g_i_CFG_VER >> 8)&0xff) ) || ( ic_data->vendor_display_cfg_ver < ((g_i_CFG_VER)&0xff) )); |
| 1964 | #endif |
| 1965 | |
| 1966 | /*wrong FW in IC cases need to force FW upgrade*/ |
| 1967 | if (IC_TYPE == HX_83112A_SERIES_PWON) |
| 1968 | { |
| 1969 | if (ic_data->vendor_hx_ic_id == 0x51) |
| 1970 | { |
| 1971 | if (( ic_data->vendor_touch_cfg_ver < ((g_i_CFG_VER >> 8)&0xff) ) || ( ic_data->vendor_display_cfg_ver < ((g_i_CFG_VER)&0xff) )) |
| 1972 | { |
| 1973 | auto_update_flag |= true; |
| 1974 | } |
| 1975 | else |
| 1976 | { |
| 1977 | auto_update_flag |= false; |
| 1978 | } |
| 1979 | } |
| 1980 | else |
| 1981 | { |
| 1982 | auto_update_flag |= true; |
| 1983 | } |
| 1984 | } |
| 1985 | else if (IC_TYPE == HX_83112B_SERIES_PWON) |
| 1986 | { |
| 1987 | if (ic_data->vendor_hx_ic_id == 0x52) |
| 1988 | { |
| 1989 | if (( ic_data->vendor_touch_cfg_ver < ((g_i_CFG_VER >> 8)&0xff) ) || ( ic_data->vendor_display_cfg_ver < ((g_i_CFG_VER)&0xff) )) |
| 1990 | { |
| 1991 | auto_update_flag |= true; |
| 1992 | } |
| 1993 | else |
| 1994 | { |
| 1995 | auto_update_flag |= false; |
| 1996 | } |
| 1997 | } |
| 1998 | else |
| 1999 | { |
| 2000 | auto_update_flag |= true; |
| 2001 | } |
| 2002 | } |
| 2003 | /*[Arima_8710][allen_yu] 20180830 end*/ |
| 2004 | /*[Arima_7947][allen_yu] 20171221 end*/ |
| 2005 | if (auto_update_flag) |
| 2006 | { |
| 2007 | ts->himax_update_wq = create_singlethread_workqueue("HMX_update_reuqest"); |
| 2008 | if (!ts->himax_update_wq) |
| 2009 | { |
| 2010 | E(" allocate syn_update_wq failed\n"); |
| 2011 | err = -ENOMEM; |
| 2012 | goto err_update_wq_failed; |
| 2013 | } |
| 2014 | INIT_DELAYED_WORK(&ts->work_update, himax_update_register); |
| 2015 | queue_delayed_work(ts->himax_update_wq, &ts->work_update, msecs_to_jiffies(2000)); |
| 2016 | } |
| 2017 | #endif |
| 2018 | |
| 2019 | #ifdef HX_ZERO_FLASH |
| 2020 | ts->himax_0f_update_wq = create_singlethread_workqueue("HMX_0f_update_reuqest"); |
| 2021 | INIT_DELAYED_WORK(&ts->work_0f_update, himax_0f_operation); |
| 2022 | queue_delayed_work(ts->himax_0f_update_wq, &ts->work_0f_update, msecs_to_jiffies(2000)); |
| 2023 | #endif |
| 2024 | //Himax Power On and Load Config |
| 2025 | if (himax_loadSensorConfig(client, pdata)) |
| 2026 | { |
| 2027 | E("%s: Load Sesnsor configuration failed, unload driver.\n", __func__); |
| 2028 | goto err_detect_failed; |
| 2029 | } |
| 2030 | himax_power_on_init(client); |
| 2031 | |
| 2032 | calculate_point_number(); |
| 2033 | #ifdef HX_TP_PROC_DIAG |
| 2034 | setXChannel(ic_data->HX_RX_NUM); // X channel |
| 2035 | setYChannel(ic_data->HX_TX_NUM); // Y channel |
| 2036 | |
| 2037 | setMutualBuffer(); |
| 2038 | setMutualNewBuffer(); |
| 2039 | setMutualOldBuffer(); |
| 2040 | if (getMutualBuffer() == NULL) |
| 2041 | { |
| 2042 | E("%s: mutual buffer allocate fail failed\n", __func__); |
| 2043 | return -1; |
| 2044 | } |
| 2045 | #ifdef HX_TP_PROC_2T2R |
| 2046 | if(Is_2T2R) |
| 2047 | { |
| 2048 | setXChannel_2(ic_data->HX_RX_NUM_2); // X channel |
| 2049 | setYChannel_2(ic_data->HX_TX_NUM_2); // Y channel |
| 2050 | |
| 2051 | setMutualBuffer_2(); |
| 2052 | |
| 2053 | if (getMutualBuffer_2() == NULL) |
| 2054 | { |
| 2055 | E("%s: mutual buffer 2 allocate fail failed\n", __func__); |
| 2056 | return -1; |
| 2057 | } |
| 2058 | } |
| 2059 | #endif |
| 2060 | #endif |
| 2061 | #ifdef CONFIG_OF |
| 2062 | ts->power = pdata->power; |
| 2063 | #endif |
| 2064 | ts->pdata = pdata; |
| 2065 | |
| 2066 | ts->x_channel = ic_data->HX_RX_NUM; |
| 2067 | ts->y_channel = ic_data->HX_TX_NUM; |
| 2068 | ts->nFinger_support = ic_data->HX_MAX_PT; |
| 2069 | //calculate the i2c data size |
| 2070 | calcDataSize(ts->nFinger_support); |
| 2071 | I("%s: calcDataSize complete\n", __func__); |
| 2072 | #ifdef CONFIG_OF |
| 2073 | ts->pdata->abs_pressure_min = 0; |
| 2074 | ts->pdata->abs_pressure_max = 200; |
| 2075 | ts->pdata->abs_width_min = 0; |
| 2076 | ts->pdata->abs_width_max = 200; |
| 2077 | pdata->cable_config[0] = 0xF0; |
| 2078 | pdata->cable_config[1] = 0x00; |
| 2079 | #endif |
| 2080 | ts->suspended = false; |
| 2081 | #if defined( HX_USB_DETECT_CALLBACK)||defined(HX_USB_DETECT_GLOBAL) |
| 2082 | ts->usb_connected = 0x00; |
| 2083 | ts->cable_config = pdata->cable_config; |
| 2084 | #endif |
| 2085 | #ifdef HX_PROTOCOL_A |
| 2086 | ts->protocol_type = PROTOCOL_TYPE_A; |
| 2087 | #else |
| 2088 | ts->protocol_type = PROTOCOL_TYPE_B; |
| 2089 | #endif |
| 2090 | I("%s: Use Protocol Type %c\n", __func__, |
| 2091 | ts->protocol_type == PROTOCOL_TYPE_A ? 'A' : 'B'); |
| 2092 | |
| 2093 | ret = himax_input_register(ts); |
| 2094 | if (ret) |
| 2095 | { |
| 2096 | E("%s: Unable to register %s input device\n", |
| 2097 | __func__, ts->input_dev->name); |
| 2098 | goto err_input_register_device_failed; |
| 2099 | } |
| 2100 | #ifdef CONFIG_FB |
| 2101 | ts->himax_att_wq = create_singlethread_workqueue("HMX_ATT_reuqest"); |
| 2102 | if (!ts->himax_att_wq) |
| 2103 | { |
| 2104 | E(" allocate syn_att_wq failed\n"); |
| 2105 | err = -ENOMEM; |
| 2106 | goto err_get_intr_bit_failed; |
| 2107 | } |
| 2108 | INIT_DELAYED_WORK(&ts->work_att, himax_fb_register); |
| 2109 | queue_delayed_work(ts->himax_att_wq, &ts->work_att, msecs_to_jiffies(15000)); |
| 2110 | #endif |
| 2111 | |
| 2112 | /*[Arima_8710][allen_yu] Solve the report point issue 20180619 begin*/ |
| 2113 | mutex_init(&ts->report_mutex); |
| 2114 | /*[Arima_8710][allen_yu] 20180619 end*/ |
| 2115 | |
| 2116 | #if defined(HX_CHIP_STATUS_MONITOR)//for ESD solution |
| 2117 | I("Enter HX_CHIP_STATUS_MONITOR! \n"); |
| 2118 | |
| 2119 | g_chip_monitor_data = kzalloc(sizeof(struct chip_monitor_data),GFP_KERNEL); |
| 2120 | if(g_chip_monitor_data == NULL) |
| 2121 | { |
| 2122 | err = -ENOMEM; |
| 2123 | goto err_alloc_monitor_data; |
| 2124 | } |
| 2125 | g_chip_monitor_data->HX_CHIP_POLLING_COUNT = 0; |
| 2126 | g_chip_monitor_data->HX_POLLING_TIMER = 5;//unit:sec |
| 2127 | g_chip_monitor_data->HX_POLLING_TIMES = 2;//ex:5(timer)x2(times)=10sec(polling time) |
| 2128 | g_chip_monitor_data->HX_ON_HAND_SHAKING = 0;// |
| 2129 | g_chip_monitor_data->HX_CHIP_MONITOR_EN = 1; |
| 2130 | |
| 2131 | ts->himax_chip_monitor_wq = create_singlethread_workqueue("himax_chip_monitor_wq"); |
| 2132 | if (!ts->himax_chip_monitor_wq) |
| 2133 | { |
| 2134 | E(" %s: create workqueue failed\n", __func__); |
| 2135 | err = -ENOMEM; |
| 2136 | goto err_create_chip_monitor_wq_failed; |
| 2137 | } |
| 2138 | g_chip_monitor_data->HX_CHIP_MONITOR_EN = 1; |
| 2139 | |
| 2140 | INIT_DELAYED_WORK(&ts->himax_chip_monitor, himax_chip_monitor_function); |
| 2141 | |
| 2142 | queue_delayed_work(ts->himax_chip_monitor_wq, &ts->himax_chip_monitor, g_chip_monitor_data->HX_POLLING_TIMER*HZ); |
| 2143 | |
| 2144 | #endif |
| 2145 | |
| 2146 | #ifdef HX_SMART_WAKEUP |
| 2147 | ts->SMWP_enable=0; |
| 2148 | //wake_lock_init(&ts->ts_SMWP_wake_lock, WAKE_LOCK_SUSPEND, HIMAX_common_NAME); |
| 2149 | wakeup_source_init(&ts->ts_SMWP_wake_lock, HIMAX_common_NAME); |
| 2150 | #endif |
| 2151 | #ifdef HX_HIGH_SENSE |
| 2152 | ts->HSEN_enable=0; |
| 2153 | #endif |
| 2154 | |
| 2155 | #if defined(CONFIG_TOUCHSCREEN_HIMAX_ITO_TEST) |
| 2156 | ts->ito_test_wq = create_singlethread_workqueue("himax_ito_test_wq"); |
| 2157 | if (!ts->ito_test_wq) |
| 2158 | { |
| 2159 | E("%s: ito test workqueue failed\n", __func__); |
| 2160 | err = -ENOMEM; |
| 2161 | goto err_ito_test_wq_failed; |
| 2162 | } |
| 2163 | |
| 2164 | INIT_WORK(&ts->ito_test_work, himax_ito_test_work); |
| 2165 | #endif |
| 2166 | |
| 2167 | //touch data init |
| 2168 | err=himax_report_data_init(); |
| 2169 | if(err) |
| 2170 | goto err_report_data_init_failed; |
| 2171 | |
| 2172 | #if defined(CONFIG_TOUCHSCREEN_HIMAX_DEBUG) |
| 2173 | himax_touch_proc_init(); |
| 2174 | #endif |
| 2175 | |
| 2176 | #if defined( HX_USB_DETECT_CALLBACK) |
| 2177 | if (ts->cable_config) |
| 2178 | cable_detect_register_notifier(&himax_cable_status_handler); |
| 2179 | #endif |
| 2180 | |
| 2181 | err = himax_ts_register_interrupt(ts->client); |
| 2182 | if (err) |
| 2183 | goto err_register_interrupt_failed; |
| 2184 | |
| 2185 | #if defined(HX_AUTO_UPDATE_FW) || defined(HX_ZERO_FLASH) |
| 2186 | if (auto_update_flag) |
| 2187 | { |
| 2188 | himax_int_enable(client->irq,0); |
| 2189 | } |
| 2190 | #endif |
| 2191 | |
| 2192 | return 0; |
| 2193 | |
| 2194 | err_register_interrupt_failed: |
| 2195 | err_report_data_init_failed: |
| 2196 | |
| 2197 | #if defined(CONFIG_TOUCHSCREEN_HIMAX_ITO_TEST) |
| 2198 | err_ito_test_wq_failed: |
| 2199 | #endif |
| 2200 | #ifdef HX_SMART_WAKEUP |
| 2201 | //wake_lock_destroy(&ts->ts_SMWP_wake_lock); |
| 2202 | wakeup_source_trash(&ts->ts_SMWP_wake_lock); |
| 2203 | #endif |
| 2204 | #ifdef HX_CHIP_STATUS_MONITOR |
| 2205 | g_chip_monitor_data->HX_CHIP_MONITOR_EN = 0; |
| 2206 | cancel_delayed_work_sync(&ts->himax_chip_monitor); |
| 2207 | destroy_workqueue(ts->himax_chip_monitor_wq); |
| 2208 | err_create_chip_monitor_wq_failed: |
| 2209 | err_alloc_monitor_data: |
| 2210 | kfree(g_chip_monitor_data); |
| 2211 | #endif |
| 2212 | #ifdef CONFIG_FB |
| 2213 | err_get_intr_bit_failed: |
| 2214 | #endif |
| 2215 | err_input_register_device_failed: |
| 2216 | input_free_device(ts->input_dev); |
| 2217 | err_detect_failed: |
| 2218 | #ifdef HX_AUTO_UPDATE_FW |
| 2219 | err_update_wq_failed: |
| 2220 | #endif |
| 2221 | /*[Arima_7947][allen_yu] Change the rule of upgrading fw 20171221 begin*/ |
| 2222 | #ifdef HX_TP_PROC_GUEST_INFO |
| 2223 | err_create_guest_info_wq_failed: |
| 2224 | #endif |
| 2225 | /*[Arima_7947][allen_yu] 20171221 end*/ |
| 2226 | #ifdef HX_TP_PROC_FLASH_DUMP |
| 2227 | err_create_wq_failed: |
| 2228 | #endif |
| 2229 | err_ic_package_failed: |
| 2230 | |
| 2231 | if (gpio_is_valid(pdata->gpio_irq)) |
| 2232 | gpio_free(pdata->gpio_irq); |
| 2233 | #ifdef HX_RST_PIN_FUNC |
| 2234 | if (gpio_is_valid(pdata->gpio_reset)) |
| 2235 | gpio_free(pdata->gpio_reset); |
| 2236 | #endif |
| 2237 | |
| 2238 | err_alloc_dt_pdata_failed: |
| 2239 | #ifndef CONFIG_OF |
| 2240 | err_power_failed: |
| 2241 | #endif |
| 2242 | |
| 2243 | kfree(ic_data); |
| 2244 | |
| 2245 | err_dt_ic_data_fail: |
| 2246 | kfree(pdata); |
| 2247 | |
| 2248 | err_dt_platform_data_fail: |
| 2249 | kfree(ts); |
| 2250 | |
| 2251 | err_alloc_data_failed: |
| 2252 | kfree(hx_touch_data); |
| 2253 | |
| 2254 | err_check_functionality_failed: |
| 2255 | probe_fail_flag = 1; |
| 2256 | return err; |
| 2257 | |
| 2258 | } |
| 2259 | |
| 2260 | int himax_chip_common_remove(struct i2c_client *client) |
| 2261 | { |
| 2262 | struct himax_ts_data *ts = i2c_get_clientdata(client); |
| 2263 | #if defined(CONFIG_TOUCHSCREEN_HIMAX_DEBUG) |
| 2264 | himax_touch_proc_deinit(); |
| 2265 | #endif |
| 2266 | #ifdef HX_CHIP_STATUS_MONITOR |
| 2267 | g_chip_monitor_data->HX_CHIP_MONITOR_EN = 0; |
| 2268 | cancel_delayed_work_sync(&ts->himax_chip_monitor); |
| 2269 | destroy_workqueue(ts->himax_chip_monitor_wq); |
| 2270 | kfree(g_chip_monitor_data); |
| 2271 | #endif |
| 2272 | #ifdef CONFIG_FB |
| 2273 | if (fb_unregister_client(&ts->fb_notif)) |
| 2274 | dev_err(&client->dev, "Error occurred while unregistering fb_notifier.\n"); |
| 2275 | #endif |
| 2276 | |
| 2277 | if (!ts->use_irq) |
| 2278 | hrtimer_cancel(&ts->timer); |
| 2279 | |
| 2280 | destroy_workqueue(ts->himax_wq); |
| 2281 | |
| 2282 | #ifndef HX_PROTOCOL_A |
| 2283 | input_mt_destroy_slots(ts->input_dev); |
| 2284 | #endif |
| 2285 | |
| 2286 | input_unregister_device(ts->input_dev); |
| 2287 | |
| 2288 | #ifdef HX_SMART_WAKEUP |
| 2289 | //wake_lock_destroy(&ts->ts_SMWP_wake_lock); |
| 2290 | wakeup_source_trash(&ts->ts_SMWP_wake_lock); |
| 2291 | #endif |
| 2292 | kfree(ts); |
| 2293 | |
| 2294 | return 0; |
| 2295 | |
| 2296 | } |
| 2297 | |
| 2298 | int himax_chip_common_suspend(struct himax_ts_data *ts) |
| 2299 | { |
| 2300 | int ret; |
| 2301 | #ifdef HX_CHIP_STATUS_MONITOR |
| 2302 | int t = 0; |
| 2303 | #endif |
| 2304 | |
| 2305 | if(ts->suspended) |
| 2306 | { |
| 2307 | I("%s: Already suspended. Skipped. \n", __func__); |
| 2308 | return 0; |
| 2309 | } |
| 2310 | else |
| 2311 | { |
| 2312 | ts->suspended = true; |
| 2313 | I("%s: enter \n", __func__); |
| 2314 | } |
| 2315 | |
| 2316 | #ifdef HX_TP_PROC_FLASH_DUMP |
| 2317 | if (getFlashDumpGoing()) |
| 2318 | { |
| 2319 | I("[himax] %s: Flash dump is going, reject suspend\n",__func__); |
| 2320 | return 0; |
| 2321 | } |
| 2322 | #endif |
| 2323 | /*[Arima_7947][allen_yu] Change the rule of upgrading fw 20171221 begin*/ |
| 2324 | #ifdef HX_TP_PROC_GUEST_INFO |
| 2325 | if (himax_guest_info_get_status()) |
| 2326 | { |
| 2327 | I("[himax] %s: GUEST INFO dump is going, reject suspend\n",__func__); |
| 2328 | return 0; |
| 2329 | } |
| 2330 | #endif |
| 2331 | /*[Arima_7947][allen_yu] 20171221 end*/ |
| 2332 | #ifdef HX_CHIP_STATUS_MONITOR |
| 2333 | if(g_chip_monitor_data->HX_ON_HAND_SHAKING)//chip on hand shaking,wait hand shaking |
| 2334 | { |
| 2335 | for(t=0; t<100; t++) |
| 2336 | { |
| 2337 | if(g_chip_monitor_data->HX_ON_HAND_SHAKING==0)//chip on hand shaking end |
| 2338 | { |
| 2339 | I("%s:HX_ON_HAND_SHAKING OK check %d times\n",__func__,t); |
| 2340 | break; |
| 2341 | } |
| 2342 | else |
| 2343 | msleep(1); |
| 2344 | } |
| 2345 | if(t==100) |
| 2346 | { |
| 2347 | E("%s:HX_ON_HAND_SHAKING timeout reject suspend\n",__func__); |
| 2348 | return 0; |
| 2349 | } |
| 2350 | } |
| 2351 | g_chip_monitor_data->HX_CHIP_MONITOR_EN = 0; |
| 2352 | g_chip_monitor_data->HX_CHIP_POLLING_COUNT = 0; |
| 2353 | cancel_delayed_work_sync(&ts->himax_chip_monitor); |
| 2354 | #endif |
| 2355 | |
| 2356 | #if defined(HX_SMART_WAKEUP)||defined(HX_HIGH_SENSE)||defined(HX_USB_DETECT_GLOBAL) |
| 2357 | #ifndef HX_RESUME_SEND_CMD |
| 2358 | himax_resend_cmd_func(ts->suspended); |
| 2359 | #endif |
| 2360 | #endif |
| 2361 | |
| 2362 | #ifdef HX_SMART_WAKEUP |
| 2363 | if(ts->SMWP_enable) |
| 2364 | { |
| 2365 | atomic_set(&ts->suspend_mode, 1); |
| 2366 | ts->pre_finger_mask = 0; |
| 2367 | FAKE_POWER_KEY_SEND=false; |
| 2368 | I("[himax] %s: SMART_WAKEUP enable, reject suspend\n",__func__); |
| 2369 | return 0; |
| 2370 | } |
| 2371 | #endif |
| 2372 | |
| 2373 | himax_int_enable(ts->client->irq,0); |
| 2374 | /*[Arima_8710][allen_yu] Fix TP I2C error in suspend 20180423 begin*/ |
| 2375 | #ifdef HX_RST_PIN_FUNC |
| 2376 | reset_flag = 0; |
| 2377 | #endif |
| 2378 | /*[Arima_8710][allen_yu] 20180423 end*/ |
| 2379 | himax_suspend_ic_action(ts->client); |
| 2380 | |
| 2381 | if (!ts->use_irq) |
| 2382 | { |
| 2383 | ret = cancel_work_sync(&ts->work); |
| 2384 | if (ret) |
| 2385 | himax_int_enable(ts->client->irq,1); |
| 2386 | } |
| 2387 | |
| 2388 | //ts->first_pressed = 0; |
| 2389 | atomic_set(&ts->suspend_mode, 1); |
| 2390 | ts->pre_finger_mask = 0; |
| 2391 | if (ts->pdata->powerOff3V3 && ts->pdata->power) |
| 2392 | ts->pdata->power(0); |
| 2393 | I("%s: END \n", __func__); |
| 2394 | return 0; |
| 2395 | } |
| 2396 | |
| 2397 | int himax_chip_common_resume(struct himax_ts_data *ts) |
| 2398 | { |
| 2399 | |
| 2400 | #ifdef HX_CHIP_STATUS_MONITOR |
| 2401 | int t=0; |
| 2402 | #endif |
| 2403 | |
| 2404 | I("%s: enter \n", __func__); |
| 2405 | if(ts->suspended == false) |
| 2406 | { |
| 2407 | I("%s: It had entered resume,skip this step \n", __func__); |
| 2408 | return 0; |
| 2409 | } |
| 2410 | else |
| 2411 | ts->suspended = false; |
| 2412 | |
| 2413 | atomic_set(&ts->suspend_mode, 0); |
| 2414 | |
| 2415 | /*[Arima_8710][allen_yu] Solve the report point issue 20180619 begin*/ |
| 2416 | himax_release_all_finger(); |
| 2417 | /*[Arima_8710][allen_yu] 20180619 end*/ |
| 2418 | |
| 2419 | if (ts->pdata->powerOff3V3 && ts->pdata->power) |
| 2420 | ts->pdata->power(1); |
| 2421 | |
| 2422 | #ifdef HX_CHIP_STATUS_MONITOR |
| 2423 | if(g_chip_monitor_data->HX_ON_HAND_SHAKING)//chip on hand shaking,wait hand shaking |
| 2424 | { |
| 2425 | for(t=0; t<100; t++) |
| 2426 | { |
| 2427 | if(g_chip_monitor_data->HX_ON_HAND_SHAKING == 0)//chip on hand shaking end |
| 2428 | { |
| 2429 | I("%s:HX_ON_HAND_SHAKING OK check %d times\n",__func__,t); |
| 2430 | break; |
| 2431 | } |
| 2432 | else |
| 2433 | msleep(1); |
| 2434 | } |
| 2435 | if(t==100) |
| 2436 | { |
| 2437 | E("%s:HX_ON_HAND_SHAKING timeout reject resume\n",__func__); |
| 2438 | return 0; |
| 2439 | } |
| 2440 | } |
| 2441 | #endif |
| 2442 | |
| 2443 | #if defined(HX_SMART_WAKEUP)||defined(HX_HIGH_SENSE)||defined(HX_USB_DETECT_GLOBAL) |
| 2444 | #if defined(HX_RESUME_SEND_CMD) |
| 2445 | himax_resend_cmd_func(ts->suspended); |
| 2446 | #endif |
| 2447 | #elif defined(HX_RESUME_HW_RESET) |
| 2448 | himax_ic_reset(false,false); |
| 2449 | #endif |
| 2450 | |
| 2451 | himax_resume_ic_action(ts->client); |
| 2452 | |
| 2453 | himax_int_enable(ts->client->irq,1); |
| 2454 | /*[Arima_8710][allen_yu] Fix TP I2C error in suspend 20180423 begin*/ |
| 2455 | #ifdef HX_RST_PIN_FUNC |
| 2456 | reset_flag = 1; |
| 2457 | #endif |
| 2458 | /*[Arima_8710][allen_yu] 20180423 end*/ |
| 2459 | #ifdef HX_CHIP_STATUS_MONITOR |
| 2460 | g_chip_monitor_data->HX_CHIP_POLLING_COUNT = 0; |
| 2461 | g_chip_monitor_data->HX_CHIP_MONITOR_EN = 1; |
| 2462 | queue_delayed_work(ts->himax_chip_monitor_wq, &ts->himax_chip_monitor, g_chip_monitor_data->HX_POLLING_TIMER*HZ); //for ESD solution |
| 2463 | #endif |
| 2464 | I("%s: END \n", __func__); |
| 2465 | return 0; |
| 2466 | } |