├── README.md ├── ft5x06.c └── ft5x06_ts.h /README.md: -------------------------------------------------------------------------------- 1 | drivers-input-touchscreen-FTS_driver 2 | ==================================== 3 | 4 | FocalTech ft5x06 TouchScreen driver 5 | 6 | FocalTech ft5x06 TouchScreen driver is include IC types such as: 7 | FT5x06,FT5606,FT5x16,FT6x06,Ft6x36,FT5x06i,FT5336,FT3316,FT5436i,FT5336i,FT5x46. 8 | -------------------------------------------------------------------------------- /ft5x06.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * FocalTech ft5x06 TouchScreen driver. 4 | * 5 | * Copyright (c) 2010 Focal tech Ltd. 6 | * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. 7 | * 8 | * This software is licensed under the terms of the GNU General Public 9 | * License version 2, as published by the Free Software Foundation, and 10 | * may be copied, distributed, and modified under those terms. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #if defined(CONFIG_FB) 39 | #include 40 | #include 41 | 42 | #elif defined(CONFIG_HAS_EARLYSUSPEND) 43 | #include 44 | /* Early-suspend level */ 45 | #define FT_SUSPEND_LEVEL 1 46 | #endif 47 | 48 | #ifdef CONFIG_TOUCHPANEL_PROXIMITY_SENSOR 49 | #include 50 | #include 51 | #endif 52 | 53 | #define FT_DRIVER_VERSION 0x02 54 | 55 | #define FT_META_REGS 3 56 | #define FT_ONE_TCH_LEN 6 57 | #define FT_TCH_LEN(x) (FT_META_REGS + FT_ONE_TCH_LEN * x) 58 | 59 | #define CFG_MAX_TOUCH_POINTS 10 60 | #define FT_PRESS 0x7F 61 | #define FT_MAX_ID 0x0F 62 | #define FT_TOUCH_X_H_POS 3 63 | #define FT_TOUCH_X_L_POS 4 64 | #define FT_TOUCH_Y_H_POS 5 65 | #define FT_TOUCH_Y_L_POS 6 66 | #define FT_TD_STATUS 2 67 | #define FT_TOUCH_EVENT_POS 3 68 | #define FT_TOUCH_ID_POS 5 69 | #define FT_TOUCH_DOWN 0 70 | #define FT_TOUCH_CONTACT 2 71 | 72 | #define POINT_READ_BUF (3 + FT_ONE_TCH_LEN * CFG_MAX_TOUCH_POINTS) 73 | 74 | /*register address*/ 75 | #define FT_REG_DEV_MODE 0x00 76 | #define FT_DEV_MODE_REG_CAL 0x02 77 | #define FT_REG_ID 0xA3 78 | #define FT_REG_PMODE 0xA5 79 | #define FT_REG_FW_VER 0xA6 80 | #define FT_REG_FW_VENDOR_ID 0xA8 81 | #define FT_REG_POINT_RATE 0x88 82 | #define FT_REG_THGROUP 0x80 83 | #define FT_REG_ECC 0xCC 84 | #define FT_REG_RESET_FW 0x07 85 | #define FT_REG_FW_MIN_VER 0xB2 86 | #define FT_REG_FW_SUB_MIN_VER 0xB3 87 | 88 | /* power register bits*/ 89 | #define FT_PMODE_ACTIVE 0x00 90 | #define FT_PMODE_MONITOR 0x01 91 | #define FT_PMODE_STANDBY 0x02 92 | #define FT_PMODE_HIBERNATE 0x03 93 | #define FT_FACTORYMODE_VALUE 0x40 94 | #define FT_WORKMODE_VALUE 0x00 95 | #define FT_RST_CMD_REG1 0xFC 96 | #define FT_RST_CMD_REG2 0xBC 97 | #define FT_READ_ID_REG 0x90 98 | #define FT_ERASE_APP_REG 0x61 99 | #define FT_ERASE_PANEL_REG 0x63 100 | #define FT_FW_START_REG 0xBF 101 | 102 | #define FT_STATUS_NUM_TP_MASK 0x0F 103 | 104 | #define FT_VTG_MIN_UV 2600000 105 | #define FT_VTG_MAX_UV 3300000 106 | #define FT_I2C_VTG_MIN_UV 1800000 107 | #define FT_I2C_VTG_MAX_UV 1800000 108 | 109 | #define FT_COORDS_ARR_SIZE 4 110 | #define MAX_BUTTONS 4 111 | 112 | #define FT_8BIT_SHIFT 8 113 | #define FT_4BIT_SHIFT 4 114 | #define FT_FW_NAME_MAX_LEN 50 115 | 116 | #define FT5X16_ID 0x0A 117 | #define FT5X06_ID 0x55 118 | #define FT6X06_ID 0x06 119 | #define FT6X36_ID 0x36 120 | 121 | #define FT_UPGRADE_AA 0xAA 122 | #define FT_UPGRADE_55 0x55 123 | 124 | #define FT_FW_MIN_SIZE 8 125 | #define FT_FW_MAX_SIZE (54 * 1024) 126 | 127 | /* Firmware file is not supporting minor and sub minor so use 0 */ 128 | #define FT_FW_FILE_MAJ_VER(x) ((x)->data[(x)->size - 2]) 129 | #define FT_FW_FILE_MIN_VER(x) 0 130 | #define FT_FW_FILE_SUB_MIN_VER(x) 0 131 | #define FT_FW_FILE_VENDOR_ID(x) ((x)->data[(x)->size - 1]) 132 | 133 | #define FT_FW_FILE_MAJ_VER_FT6X36(x) ((x)->data[0x10a]) 134 | #define FT_FW_FILE_VENDOR_ID_FT6X36(x) ((x)->data[0x108]) 135 | 136 | /** 137 | * Application data verification will be run before upgrade flow. 138 | * Firmware image stores some flags with negative and positive value 139 | * in corresponding addresses, we need pick them out do some check to 140 | * make sure the application data is valid. 141 | */ 142 | #define FT_FW_CHECK(x, ts_data) \ 143 | (ts_data->family_id == FT6X36_ID ? \ 144 | (((x)->data[0x104] ^ (x)->data[0x105]) == 0xFF \ 145 | && ((x)->data[0x106] ^ (x)->data[0x107]) == 0xFF) : \ 146 | (((x)->data[(x)->size - 8] ^ (x)->data[(x)->size - 6]) == 0xFF \ 147 | && ((x)->data[(x)->size - 7] ^ (x)->data[(x)->size - 5]) == 0xFF \ 148 | && ((x)->data[(x)->size - 3] ^ (x)->data[(x)->size - 4]) == 0xFF)) 149 | 150 | #define FT_MAX_TRIES 5 151 | #define FT_RETRY_DLY 20 152 | 153 | #define FT_MAX_WR_BUF 10 154 | #define FT_MAX_RD_BUF 2 155 | #define FT_FW_PKT_LEN 128 156 | #define FT_FW_PKT_META_LEN 6 157 | #define FT_FW_PKT_DLY_MS 20 158 | #define FT_FW_LAST_PKT 0x6ffa 159 | #define FT_EARSE_DLY_MS 100 160 | #define FT_55_AA_DLY_NS 5000 161 | 162 | #define FT_UPGRADE_LOOP 30 163 | #define FT_CAL_START 0x04 164 | #define FT_CAL_FIN 0x00 165 | #define FT_CAL_STORE 0x05 166 | #define FT_CAL_RETRY 100 167 | #define FT_REG_CAL 0x00 168 | #define FT_CAL_MASK 0x70 169 | 170 | #define FT_INFO_MAX_LEN 512 171 | 172 | #define FT_BLOADER_SIZE_OFF 12 173 | #define FT_BLOADER_NEW_SIZE 30 174 | #define FT_DATA_LEN_OFF_OLD_FW 8 175 | #define FT_DATA_LEN_OFF_NEW_FW 14 176 | #define FT_FINISHING_PKT_LEN_OLD_FW 6 177 | #define FT_FINISHING_PKT_LEN_NEW_FW 12 178 | #define FT_MAGIC_BLOADER_Z7 0x7bfa 179 | #define FT_MAGIC_BLOADER_LZ4 0x6ffa 180 | #define FT_MAGIC_BLOADER_GZF_30 0x7ff4 181 | #define FT_MAGIC_BLOADER_GZF 0x7bf4 182 | 183 | #define PINCTRL_STATE_ACTIVE "pmx_ts_active" 184 | #define PINCTRL_STATE_SUSPEND "pmx_ts_suspend" 185 | #define PINCTRL_STATE_RELEASE "pmx_ts_release" 186 | 187 | enum { 188 | FT_BLOADER_VERSION_LZ4 = 0, 189 | FT_BLOADER_VERSION_Z7 = 1, 190 | FT_BLOADER_VERSION_GZF = 2, 191 | }; 192 | 193 | enum { 194 | FT_FT5336_FAMILY_ID_0x11 = 0x11, 195 | FT_FT5336_FAMILY_ID_0x12 = 0x12, 196 | FT_FT5336_FAMILY_ID_0x13 = 0x13, 197 | FT_FT5336_FAMILY_ID_0x14 = 0x14, 198 | }; 199 | 200 | struct Upgrade_Info { 201 | u8 CHIP_ID; 202 | u8 FTS_NAME[20]; 203 | u8 TPD_MAX_POINTS; 204 | u8 AUTO_CLB; 205 | u16 delay_aa; /*delay of write FT_UPGRADE_AA */ 206 | u16 delay_55; /*delay of write FT_UPGRADE_55 */ 207 | u8 upgrade_id_1; /*upgrade id 1 */ 208 | u8 upgrade_id_2; /*upgrade id 2 */ 209 | u16 delay_readid; /*delay of read id */ 210 | u16 delay_earse_flash; /*delay of earse flash*/ 211 | }; 212 | 213 | struct Upgrade_Info fts_updateinfo[] = 214 | { 215 | {0x55,"FT5x06",TPD_MAX_POINTS_5,AUTO_CLB_NEED,50, 30, 0x79, 0x03, 10, 2000}, 216 | {0x08,"FT5606",TPD_MAX_POINTS_5,AUTO_CLB_NEED,50, 10, 0x79, 0x06, 100, 2000}, 217 | {0x0a,"FT5x16",TPD_MAX_POINTS_5,AUTO_CLB_NEED,50, 30, 0x79, 0x07, 10, 1500}, 218 | {0x06,"FT6x06",TPD_MAX_POINTS_2,AUTO_CLB_NONEED,100, 30, 0x79, 0x08, 10, 2000}, 219 | {0x36,"FT6x36",TPD_MAX_POINTS_2,AUTO_CLB_NONEED,10, 10, 0x79, 0x18, 10, 2000}, 220 | {0x55,"FT5x06i",TPD_MAX_POINTS_5,AUTO_CLB_NEED,50, 30, 0x79, 0x03, 10, 2000}, 221 | {0x14,"FT5336",TPD_MAX_POINTS_5,AUTO_CLB_NONEED,30, 30, 0x79, 0x11, 10, 2000}, 222 | {0x13,"FT3316",TPD_MAX_POINTS_5,AUTO_CLB_NONEED,30, 30, 0x79, 0x11, 10, 2000}, 223 | {0x12,"FT5436i",TPD_MAX_POINTS_5,AUTO_CLB_NONEED,30, 30, 0x79, 0x11, 10, 2000}, 224 | {0x11,"FT5336i",TPD_MAX_POINTS_5,AUTO_CLB_NONEED,30, 30, 0x79, 0x11, 10, 2000}, 225 | {0x54,"FT5x46",TPD_MAX_POINTS_5,AUTO_CLB_NONEED,2, 2, 0x54, 0x2c, 10, 2000}, 226 | }; 227 | 228 | #define FTS_DBG 229 | #ifdef FTS_DBG 230 | #define DBG(fmt, args...) printk("[FTS]" fmt, ## args) 231 | #else 232 | #define DBG(fmt, args...) do{}while(0) 233 | #endif 234 | 235 | struct Upgrade_Info fts_updateinfo_curr; 236 | 237 | struct i2c_client *fts_i2c_client = NULL; 238 | 239 | #define FTS_GESTRUE 240 | 241 | #ifdef FTS_GESTRUE 242 | #define KEY_GESTURE_U KEY_U 243 | #define KEY_GESTURE_UP KEY_UP 244 | #define KEY_GESTURE_DOWN KEY_DOWN 245 | #define KEY_GESTURE_LEFT KEY_LEFT 246 | #define KEY_GESTURE_RIGHT KEY_RIGHT 247 | #define KEY_GESTURE_O KEY_O 248 | #define KEY_GESTURE_E KEY_E 249 | #define KEY_GESTURE_M KEY_M 250 | #define KEY_GESTURE_L KEY_L 251 | #define KEY_GESTURE_W KEY_W 252 | #define KEY_GESTURE_S KEY_S 253 | #define KEY_GESTURE_V KEY_V 254 | #define KEY_GESTURE_Z KEY_Z 255 | 256 | #define GESTURE_LEFT 0x20 257 | #define GESTURE_RIGHT 0x21 258 | #define GESTURE_UP 0x22 259 | #define GESTURE_DOWN 0x23 260 | #define GESTURE_DOUBLECLICK 0x24 261 | #define GESTURE_O 0x30 262 | #define GESTURE_W 0x31 263 | #define GESTURE_M 0x32 264 | #define GESTURE_E 0x33 265 | #define GESTURE_L 0x44 266 | #define GESTURE_S 0x46 267 | #define GESTURE_V 0x54 268 | #define GESTURE_Z 0x41 269 | 270 | #define FTS_GESTRUE_POINTS 255 271 | #define FTS_GESTRUE_POINTS_ONETIME 62 272 | #define FTS_GESTRUE_POINTS_HEADER 8 273 | #define FTS_GESTURE_OUTPUT_ADRESS 0xD3 274 | #define FTS_GESTURE_OUTPUT_UNIT_LENGTH 4 275 | 276 | short pointnum = 0; 277 | unsigned short coordinate_x[150] = {0}; 278 | unsigned short coordinate_y[150] = {0}; 279 | #endif 280 | 281 | #define FT_STORE_TS_INFO(buf, id, name, max_tch, group_id, fw_vkey_support, \ 282 | fw_name, fw_maj, fw_min, fw_sub_min) \ 283 | snprintf(buf, FT_INFO_MAX_LEN, \ 284 | "controller\t= focaltech\n" \ 285 | "model\t\t= 0x%x\n" \ 286 | "name\t\t= %s\n" \ 287 | "max_touches\t= %d\n" \ 288 | "drv_ver\t\t= 0x%x\n" \ 289 | "group_id\t= 0x%x\n" \ 290 | "fw_vkey_support\t= %s\n" \ 291 | "fw_name\t\t= %s\n" \ 292 | "fw_ver\t\t= %d.%d.%d\n", id, name, \ 293 | max_tch, FT_DRIVER_VERSION, group_id, \ 294 | fw_vkey_support, fw_name, fw_maj, fw_min, \ 295 | fw_sub_min) 296 | 297 | #define FT_DEBUG_DIR_NAME "ts_debug" 298 | 299 | struct ts_event { 300 | u16 au16_x[TPD_MAX_POINTS_10]; /*x coordinate */ 301 | u16 au16_y[TPD_MAX_POINTS_10]; /*y coordinate */ 302 | u8 au8_touch_event[TPD_MAX_POINTS_10]; /*touch event: 303 | 0 -- down; 1-- up; 2 -- contact */ 304 | u8 au8_finger_id[TPD_MAX_POINTS_10]; /*touch ID */ 305 | u16 pressure; 306 | u8 touch_point; 307 | u8 point_num; 308 | }; 309 | 310 | struct ft5x06_ts_data { 311 | struct i2c_client *client; 312 | struct input_dev *input_dev; 313 | struct ts_event event; 314 | const struct ft5x06_ts_platform_data *pdata; 315 | struct work_struct touch_event_work; 316 | struct workqueue_struct *ts_workqueue; 317 | struct regulator *vdd; 318 | struct regulator *vcc_i2c; 319 | char fw_name[FT_FW_NAME_MAX_LEN]; 320 | bool loading_fw; 321 | u8 family_id; 322 | struct dentry *dir; 323 | u16 addr; 324 | bool suspended; 325 | char *ts_info; 326 | u8 *tch_data; 327 | u32 tch_data_len; 328 | u8 fw_ver[3]; 329 | u8 fw_vendor_id; 330 | #ifdef CONFIG_TOUCHPANEL_PROXIMITY_SENSOR 331 | struct input_dev *input_prox_dev; 332 | struct input_polled_dev *input_poll_dev; 333 | #endif 334 | #if defined(CONFIG_FB) 335 | struct notifier_block fb_notif; 336 | #elif defined(CONFIG_HAS_EARLYSUSPEND) 337 | struct early_suspend early_suspend; 338 | #endif 339 | struct pinctrl *ts_pinctrl; 340 | struct pinctrl_state *pinctrl_state_active; 341 | struct pinctrl_state *pinctrl_state_suspend; 342 | struct pinctrl_state *pinctrl_state_release; 343 | }; 344 | 345 | static struct ft5x06_ts_data *fts_wq_data; 346 | 347 | static DEFINE_MUTEX(i2c_rw_access); 348 | 349 | #ifdef CONFIG_TOUCHPANEL_PROXIMITY_SENSOR 350 | #define PROXIMITY_INPUT_DEV_NAME "proximity" 351 | 352 | #define SENSOR_PROX_TP_USE_WAKELOCK 353 | static struct i2c_client * i2c_prox_client = NULL; 354 | #ifdef SENSOR_PROX_TP_USE_WAKELOCK 355 | static struct wake_lock sensor_prox_tp_wake_lock; 356 | #endif 357 | static DEFINE_MUTEX(tp_prox_sensor_mutex); 358 | 359 | static int tp_prox_sensor_opened; 360 | static char tp_prox_sensor_data = 0; // 0 near 1 far 361 | static char tp_prox_sensor_data_changed = 0; 362 | static char tp_prox_pre_sensor_data = 1; 363 | 364 | static int is_suspend = 0; 365 | static int is_need_report_pointer = 1; 366 | 367 | static void tp_prox_sensor_enable(int enable); 368 | #endif 369 | 370 | static int ft5x06_i2c_read(struct i2c_client *client, char *writebuf, 371 | int writelen, char *readbuf, int readlen) 372 | { 373 | int ret; 374 | 375 | mutex_lock(&i2c_rw_access); 376 | 377 | if (writelen > 0) { 378 | struct i2c_msg msgs[] = { 379 | { 380 | .addr = client->addr, 381 | .flags = 0, 382 | .len = writelen, 383 | .buf = writebuf, 384 | }, 385 | { 386 | .addr = client->addr, 387 | .flags = I2C_M_RD, 388 | .len = readlen, 389 | .buf = readbuf, 390 | }, 391 | }; 392 | ret = i2c_transfer(client->adapter, msgs, 2); 393 | if (ret < 0) 394 | dev_err(&client->dev, "%s: i2c read error.\n", 395 | __func__); 396 | } else { 397 | struct i2c_msg msgs[] = { 398 | { 399 | .addr = client->addr, 400 | .flags = I2C_M_RD, 401 | .len = readlen, 402 | .buf = readbuf, 403 | }, 404 | }; 405 | ret = i2c_transfer(client->adapter, msgs, 1); 406 | if (ret < 0) 407 | dev_err(&client->dev, "%s:i2c read error.\n", __func__); 408 | } 409 | 410 | mutex_unlock(&i2c_rw_access); 411 | 412 | return ret; 413 | } 414 | 415 | static int ft5x06_i2c_write(struct i2c_client *client, char *writebuf, 416 | int writelen) 417 | { 418 | int ret; 419 | 420 | mutex_lock(&i2c_rw_access); 421 | 422 | struct i2c_msg msgs[] = { 423 | { 424 | .addr = client->addr, 425 | .flags = 0, 426 | .len = writelen, 427 | .buf = writebuf, 428 | }, 429 | }; 430 | ret = i2c_transfer(client->adapter, msgs, 1); 431 | if (ret < 0) 432 | dev_err(&client->dev, "%s: i2c write error.\n", __func__); 433 | 434 | mutex_unlock(&i2c_rw_access); 435 | 436 | return ret; 437 | } 438 | 439 | static int ft5x0x_write_reg(struct i2c_client *client, u8 addr, const u8 val) 440 | { 441 | u8 buf[2] = {0}; 442 | 443 | buf[0] = addr; 444 | buf[1] = val; 445 | 446 | return ft5x06_i2c_write(client, buf, sizeof(buf)); 447 | } 448 | 449 | static int ft5x0x_read_reg(struct i2c_client *client, u8 addr, u8 *val) 450 | { 451 | return ft5x06_i2c_read(client, &addr, 1, val, 1); 452 | } 453 | 454 | static void ft5x06_update_fw_vendor_id(struct ft5x06_ts_data *data) 455 | { 456 | struct i2c_client *client = data->client; 457 | u8 reg_addr; 458 | int err; 459 | 460 | reg_addr = FT_REG_FW_VENDOR_ID; 461 | err = ft5x06_i2c_read(client, ®_addr, 1, &data->fw_vendor_id, 1); 462 | if (err < 0) 463 | dev_err(&client->dev, "fw vendor id read failed"); 464 | } 465 | 466 | static void ft5x06_update_fw_ver(struct ft5x06_ts_data *data) 467 | { 468 | struct i2c_client *client = data->client; 469 | u8 reg_addr; 470 | int err; 471 | 472 | reg_addr = FT_REG_FW_VER; 473 | err = ft5x06_i2c_read(client, ®_addr, 1, &data->fw_ver[0], 1); 474 | if (err < 0) 475 | dev_err(&client->dev, "fw major version read failed"); 476 | 477 | reg_addr = FT_REG_FW_MIN_VER; 478 | err = ft5x06_i2c_read(client, ®_addr, 1, &data->fw_ver[1], 1); 479 | if (err < 0) 480 | dev_err(&client->dev, "fw minor version read failed"); 481 | 482 | reg_addr = FT_REG_FW_SUB_MIN_VER; 483 | err = ft5x06_i2c_read(client, ®_addr, 1, &data->fw_ver[2], 1); 484 | if (err < 0) 485 | dev_err(&client->dev, "fw sub minor version read failed"); 486 | 487 | dev_info(&client->dev, "Firmware version = %d.%d.%d\n", 488 | data->fw_ver[0], data->fw_ver[1], data->fw_ver[2]); 489 | } 490 | 491 | #ifdef CONFIG_TOUCHPANEL_PROXIMITY_SENSOR 492 | static void tp_prox_sensor_enable(int enable) 493 | { 494 | u8 state; 495 | int ret = -1; 496 | 497 | if(i2c_prox_client==NULL) 498 | return; 499 | 500 | 501 | ft5x0x_read_reg(i2c_prox_client, 0xB0, &state); 502 | DBG("[proxi_fts]read: 0xb0's value is 0x%02X\n", state); 503 | if (enable){ 504 | state |= 0x01; 505 | }else{ 506 | state &= 0x00; 507 | } 508 | ret = ft5x0x_write_reg(i2c_prox_client, 0xB0, &state); 509 | if(ret < 0) 510 | { 511 | DBG("[proxi_fts]write psensor switch command failed\n"); 512 | } 513 | return; 514 | } 515 | 516 | static ssize_t tp_prox_enable_show(struct device *dev, 517 | struct device_attribute *attr, char *buf) 518 | { 519 | return snprintf(buf, 4, "%d\n", tp_prox_sensor_opened); 520 | } 521 | 522 | static ssize_t tp_prox_enable_store(struct device *dev, 523 | struct device_attribute *attr, 524 | const char *buf, size_t count) 525 | { 526 | struct i2c_client *client = to_i2c_client(dev); 527 | struct fts_data *prox = i2c_get_clientdata(client); 528 | struct input_dev *input_dev = prox->input_prox_dev; 529 | unsigned long data; 530 | int error; 531 | 532 | error = kstrtoul(buf, 10, &data); 533 | if (error) 534 | return error; 535 | DBG("%s, data=%ld\n",__func__,data); 536 | mutex_lock(&input_dev->mutex); 537 | disable_irq(client->irq); 538 | 539 | mutex_lock(&tp_prox_sensor_mutex); 540 | tp_prox_sensor_enable((int)data); 541 | if(data){ 542 | #ifdef SENSOR_PROX_TP_USE_WAKELOCK 543 | wake_lock(&sensor_prox_tp_wake_lock); 544 | #endif 545 | tp_prox_sensor_opened = 1; 546 | tp_prox_sensor_data = 1; 547 | tp_prox_sensor_data_changed = 1; 548 | }else{ 549 | tp_prox_sensor_opened = 0; 550 | #ifdef SENSOR_PROX_TP_USE_WAKELOCK 551 | wake_unlock(&sensor_prox_tp_wake_lock); 552 | #endif 553 | } 554 | mutex_unlock(&tp_prox_sensor_mutex); 555 | 556 | enable_irq(client->irq); 557 | mutex_unlock(&input_dev->mutex); 558 | 559 | return count; 560 | } 561 | 562 | static DEVICE_ATTR(enable, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH, 563 | tp_prox_enable_show, tp_prox_enable_store); 564 | 565 | /* Returns currently selected poll interval (in ms) */ 566 | static ssize_t tp_prox_get_poll_delay(struct device *dev, 567 | struct device_attribute *attr, char *buf) 568 | { 569 | struct i2c_client *client = to_i2c_client(dev); 570 | struct fts_data *ps = i2c_get_clientdata(client); 571 | 572 | return sprintf(buf, "%d\n", ps->input_poll_dev->poll_interval); 573 | } 574 | 575 | /* Allow users to select a new poll interval (in ms) */ 576 | static ssize_t tp_prox_set_poll_delay(struct device *dev, 577 | struct device_attribute *attr, 578 | const char *buf, size_t count) 579 | { 580 | struct i2c_client *client = to_i2c_client(dev); 581 | struct fts_data *ps = i2c_get_clientdata(client); 582 | struct input_dev *input_dev = ps->input_prox_dev; 583 | unsigned int interval; 584 | int error; 585 | 586 | error = kstrtouint(buf, 10, &interval); 587 | if (error < 0) 588 | return error; 589 | 590 | /* Lock the device to prevent races with open/close (and itself) */ 591 | mutex_lock(&input_dev->mutex); 592 | 593 | disable_irq(client->irq); 594 | 595 | /* 596 | * Set current interval to the greater of the minimum interval or 597 | * the requested interval 598 | */ 599 | ps->input_poll_dev->poll_interval = max((int)interval,(int)ps->input_poll_dev->poll_interval_min); 600 | 601 | enable_irq(client->irq); 602 | mutex_unlock(&input_dev->mutex); 603 | 604 | return count; 605 | } 606 | 607 | static DEVICE_ATTR(poll_delay, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH, 608 | tp_prox_get_poll_delay, tp_prox_set_poll_delay); 609 | 610 | static struct attribute *tp_prox_attributes[] = { 611 | &dev_attr_enable.attr, 612 | &dev_attr_poll_delay.attr, 613 | NULL 614 | }; 615 | 616 | static struct attribute_group tp_prox_attribute_group = { 617 | .attrs = tp_prox_attributes 618 | }; 619 | 620 | static void __devinit tp_prox_init_input_device(struct fts_data *prox, 621 | struct input_dev *input_dev) 622 | { 623 | __set_bit(EV_ABS, input_dev->evbit); 624 | input_set_abs_params(input_dev, ABS_DISTANCE, 0, 1, 0, 0); 625 | 626 | input_dev->name = PROXIMITY_INPUT_DEV_NAME; 627 | input_dev->id.bustype = BUS_I2C; 628 | input_dev->dev.parent = &prox->client->dev; 629 | } 630 | 631 | static void tp_prox_poll(struct input_polled_dev *dev) 632 | { 633 | struct fts_data *prox = dev->private; 634 | 635 | if (tp_prox_sensor_data_changed){ 636 | mutex_lock(&tp_prox_sensor_mutex); 637 | tp_prox_sensor_data_changed = 0; 638 | mutex_unlock(&tp_prox_sensor_mutex); 639 | DBG("%s poll tp_prox_sensor_data=%d\n",__func__,tp_prox_sensor_data); 640 | input_report_abs(prox->input_prox_dev, ABS_DISTANCE, tp_prox_sensor_data); 641 | input_sync(prox->input_prox_dev); 642 | } 643 | } 644 | 645 | static int __devinit tp_prox_setup_polled_device(struct fts_data *ps) 646 | { 647 | int err; 648 | struct input_polled_dev *poll_dev; 649 | 650 | poll_dev = input_allocate_polled_device(); 651 | if (!poll_dev) { 652 | DBG("Failed to allocate polled device\n"); 653 | return -ENOMEM; 654 | } 655 | 656 | ps->input_poll_dev = poll_dev; 657 | ps->input_prox_dev = poll_dev->input; 658 | 659 | poll_dev->private = ps; 660 | poll_dev->poll = tp_prox_poll; 661 | //poll_dev->open = tp_prox_polled_input_open; 662 | //poll_dev->close = tp_prox_polled_input_close; 663 | poll_dev->poll_interval = 100; 664 | poll_dev->poll_interval_min= 0; 665 | 666 | tp_prox_init_input_device(ps, poll_dev->input); 667 | err = input_register_polled_device(poll_dev); 668 | DBG("%s, err=%d, poll-interval=%d\n",__func__,err,poll_dev->poll_interval); 669 | if (err) { 670 | DBG("Unable to register polled device, err=%d\n", err); 671 | input_free_polled_device(poll_dev); 672 | return -ENOMEM; 673 | } 674 | 675 | return 0; 676 | } 677 | 678 | static void tp_prox_teardown_polled_device(struct fts_data *ps) 679 | { 680 | input_unregister_polled_device(ps->input_poll_dev); 681 | input_free_polled_device(ps->input_poll_dev); 682 | } 683 | #endif 684 | 685 | #ifdef FTS_GESTRUE 686 | static void check_gesture(int gesture_id) 687 | { 688 | printk("fts gesture_id==0x%x\n ",gesture_id); 689 | 690 | switch(gesture_id) 691 | { 692 | case GESTURE_LEFT: 693 | input_report_key(tpd->dev, KEY_GESTURE_LEFT, 1); 694 | input_sync(tpd->dev); 695 | input_report_key(tpd->dev, KEY_GESTURE_LEFT, 0); 696 | input_sync(tpd->dev); 697 | break; 698 | case GESTURE_RIGHT: 699 | input_report_key(tpd->dev, KEY_GESTURE_RIGHT, 1); 700 | input_sync(tpd->dev); 701 | input_report_key(tpd->dev, KEY_GESTURE_RIGHT, 0); 702 | input_sync(tpd->dev); 703 | break; 704 | case GESTURE_UP: 705 | input_report_key(tpd->dev, KEY_GESTURE_UP, 1); 706 | input_sync(tpd->dev); 707 | input_report_key(tpd->dev, KEY_GESTURE_UP, 0); 708 | input_sync(tpd->dev); 709 | break; 710 | case GESTURE_DOWN: 711 | input_report_key(tpd->dev, KEY_GESTURE_DOWN, 1); 712 | input_sync(tpd->dev); 713 | input_report_key(tpd->dev, KEY_GESTURE_DOWN, 0); 714 | input_sync(tpd->dev); 715 | break; 716 | case GESTURE_DOUBLECLICK: 717 | input_report_key(tpd->dev, KEY_GESTURE_U, 1); 718 | input_sync(tpd->dev); 719 | input_report_key(tpd->dev, KEY_GESTURE_U, 0); 720 | input_sync(tpd->dev); 721 | break; 722 | case GESTURE_O: 723 | input_report_key(tpd->dev, KEY_GESTURE_O, 1); 724 | input_sync(tpd->dev); 725 | input_report_key(tpd->dev, KEY_GESTURE_O, 0); 726 | input_sync(tpd->dev); 727 | break; 728 | case GESTURE_W: 729 | input_report_key(tpd->dev, KEY_GESTURE_W, 1); 730 | input_sync(tpd->dev); 731 | input_report_key(tpd->dev, KEY_GESTURE_W, 0); 732 | input_sync(tpd->dev); 733 | break; 734 | case GESTURE_M: 735 | input_report_key(tpd->dev, KEY_GESTURE_M, 1); 736 | input_sync(tpd->dev); 737 | input_report_key(tpd->dev, KEY_GESTURE_M, 0); 738 | input_sync(tpd->dev); 739 | break; 740 | case GESTURE_E: 741 | input_report_key(tpd->dev, KEY_GESTURE_E, 1); 742 | input_sync(tpd->dev); 743 | input_report_key(tpd->dev, KEY_GESTURE_E, 0); 744 | input_sync(tpd->dev); 745 | break; 746 | case GESTURE_L: 747 | input_report_key(tpd->dev, KEY_GESTURE_L, 1); 748 | input_sync(tpd->dev); 749 | input_report_key(tpd->dev, KEY_GESTURE_L, 0); 750 | input_sync(tpd->dev); 751 | break; 752 | case GESTURE_S: 753 | input_report_key(tpd->dev, KEY_GESTURE_S, 1); 754 | input_sync(tpd->dev); 755 | input_report_key(tpd->dev, KEY_GESTURE_S, 0); 756 | input_sync(tpd->dev); 757 | break; 758 | case GESTURE_V: 759 | input_report_key(tpd->dev, KEY_GESTURE_V, 1); 760 | input_sync(tpd->dev); 761 | input_report_key(tpd->dev, KEY_GESTURE_V, 0); 762 | input_sync(tpd->dev); 763 | break; 764 | case GESTURE_Z: 765 | input_report_key(tpd->dev, KEY_GESTURE_Z, 1); 766 | input_sync(tpd->dev); 767 | input_report_key(tpd->dev, KEY_GESTURE_Z, 0); 768 | input_sync(tpd->dev); 769 | break; 770 | default: 771 | break; 772 | } 773 | 774 | } 775 | 776 | static int fts_read_Gestruedata(void) 777 | { 778 | unsigned char buf[FTS_GESTRUE_POINTS * 3] = { 0 }; 779 | int ret = -1; 780 | int i = 0; 781 | buf[0] = 0xd3; 782 | int gestrue_id = 0; 783 | 784 | pointnum = 0; 785 | 786 | ret = ft5x06_i2c_read(i2c_client, buf, 1, buf, FTS_GESTRUE_POINTS_HEADER); 787 | printk( "tpd read FTS_GESTRUE_POINTS_HEADER.\n"); 788 | 789 | if (ret < 0) 790 | { 791 | printk( "%s read touchdata failed.\n", __func__); 792 | return ret; 793 | } 794 | 795 | gestrue_id = buf[0]; 796 | pointnum = (short)(buf[1]) & 0xff; 797 | buf[0] = 0xd3; 798 | 799 | if((pointnum * 4 + 8)<255) 800 | { 801 | ret = ft5x06_i2c_read(i2c_client, buf, 1, buf, (pointnum * 4 + 8)); 802 | } 803 | else 804 | { 805 | ret = ft5x06_i2c_read(i2c_client, buf, 1, buf, 255); 806 | ret = ft5x06_i2c_read(i2c_client, buf, 0, buf+255, (pointnum * 4 + 8) -255); 807 | } 808 | if (ret < 0) 809 | { 810 | printk( "%s read touchdata failed.\n", __func__); 811 | return ret; 812 | } 813 | check_gesture(gestrue_id); 814 | for(i = 0;i < pointnum;i++) 815 | { 816 | coordinate_x[i] = (((s16) buf[0 + (4 * i)]) & 0x0F) << 817 | 8 | (((s16) buf[1 + (4 * i)])& 0xFF); 818 | coordinate_y[i] = (((s16) buf[2 + (4 * i)]) & 0x0F) << 819 | 8 | (((s16) buf[3 + (4 * i)]) & 0xFF); 820 | } 821 | return -1; 822 | } 823 | #endif 824 | static irqreturn_t ft5x06_ts_interrupt(int irq, void *dev_id) 825 | { 826 | struct ft5x06_ts_data *fts_ts = dev_id; 827 | 828 | if (!fts_ts) { 829 | pr_err("%s: Invalid fts_ts\n", __func__); 830 | return IRQ_HANDLED; 831 | } 832 | 833 | queue_work(fts_ts->ts_workqueue, &fts_ts->touch_event_work); 834 | 835 | return IRQ_HANDLED; 836 | } 837 | 838 | static int fts_read_Touchdata(struct ft5x06_ts_data *data) 839 | { 840 | struct ts_event *event = &data->event; 841 | u8 buf[POINT_READ_BUF] = { 0 }; 842 | int ret = -1; 843 | int i = 0; 844 | u8 pointid = FT_MAX_ID; 845 | 846 | u8 state; 847 | 848 | #ifdef CONFIG_TOUCHPANEL_PROXIMITY_SENSOR 849 | u8 proximity_status; 850 | #endif 851 | 852 | #ifdef CONFIG_TOUCHPANEL_PROXIMITY_SENSOR 853 | if (tp_prox_sensor_opened == 1) 854 | { 855 | ft5x0x_read_reg(data->client, 0xB0, &state); 856 | DBG("proxi_fts 0xB0 state value is 0x%02X\n", state); 857 | if(!(state&0x01)) 858 | { 859 | tp_prox_sensor_enable(1); 860 | } 861 | ft5x0x_read_reg(data->client, 0x01, &proximity_status); 862 | DBG("proxi_fts value is 0x%02X\n", proximity_status); 863 | tp_prox_pre_sensor_data = tp_prox_sensor_data; 864 | if (proximity_status == 0xC0) //near 865 | { 866 | tp_prox_sensor_data = 0; 867 | } 868 | else if(proximity_status == 0xE0) //far 869 | { 870 | tp_prox_sensor_data = 1; 871 | } 872 | DBG( "%s tp_pre_sensor_data=%d,tp_prox_sensor_data=%d\n", __func__,tp_pre_sensor_data,tp_prox_sensor_data); 873 | if( tp_prox_pre_sensor_data != tp_prox_sensor_data) 874 | { 875 | DBG( "%s ensor data changed\n", __func__); 876 | mutex_lock(&tp_prox_sensor_mutex); 877 | tp_prox_sensor_data_changed = 1; 878 | mutex_unlock(&tp_prox_sensor_mutex); 879 | return 1; 880 | } 881 | if(is_need_report_pointer == 0) 882 | { 883 | DBG( ":%s: we don not report pointer when sleep in call\n", __func__); 884 | return 1; 885 | } 886 | 887 | } 888 | #endif 889 | 890 | #ifdef FTS_GESTRUE 891 | ft5x0x_read_reg(data->client, 0xB0, &state); 892 | printk("tpd fts_read_Gestruedata state=%d\n",state); 893 | if(state ==1) 894 | { 895 | fts_read_Gestruedata(); 896 | return 1; 897 | } 898 | #endif 899 | 900 | ret = ft5x06_i2c_read(data->client, buf, 1, buf, POINT_READ_BUF); 901 | if (ret < 0) { 902 | dev_err(&data->client->dev, "%s read touchdata failed.\n", 903 | __func__); 904 | return ret; 905 | } 906 | memset(event, 0, sizeof(struct ts_event)); 907 | 908 | event->touch_point = 0; 909 | for (i = 0; i < CFG_MAX_TOUCH_POINTS; i++) { 910 | pointid = (buf[FT_TOUCH_ID_POS + FT_ONE_TCH_LEN * i]) >> 4; 911 | if (pointid >= FT_MAX_ID) 912 | break; 913 | else 914 | event->touch_point++; 915 | event->au16_x[i] = 916 | (s16) (buf[FT_TOUCH_X_H_POS + FT_ONE_TCH_LEN * i] & 0x0F) << 917 | 8 | (s16) buf[FT_TOUCH_X_L_POS + FT_ONE_TCH_LEN * i]; 918 | event->au16_y[i] = 919 | (s16) (buf[FT_TOUCH_Y_H_POS + FT_ONE_TCH_LEN * i] & 0x0F) << 920 | 8 | (s16) buf[FT_TOUCH_Y_L_POS + FT_ONE_TCH_LEN * i]; 921 | event->au8_touch_event[i] = 922 | buf[FT_TOUCH_EVENT_POS + FT_ONE_TCH_LEN * i] >> 6; 923 | event->au8_finger_id[i] = 924 | (buf[FT_TOUCH_ID_POS + FT_ONE_TCH_LEN * i]) >> 4; 925 | } 926 | 927 | event->pressure = FT_PRESS; 928 | 929 | return 0; 930 | } 931 | 932 | static void fts_report_value(struct ft5x06_ts_data *data) 933 | { 934 | struct ts_event *event = &data->event; 935 | int i; 936 | int uppoint = 0; 937 | 938 | /*protocol B*/ 939 | for (i = 0; i < event->touch_point; i++) 940 | { 941 | input_mt_slot(data->input_dev, event->au8_finger_id[i]); 942 | 943 | if (event->au8_touch_event[i]== 0 || event->au8_touch_event[i] == 2) 944 | { 945 | input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, 946 | true); 947 | input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, 948 | event->pressure); 949 | input_report_abs(data->input_dev, ABS_MT_POSITION_X, 950 | event->au16_x[i]); 951 | input_report_abs(data->input_dev, ABS_MT_POSITION_Y, 952 | event->au16_y[i]); 953 | } 954 | else 955 | { 956 | uppoint++; 957 | input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, 958 | false); 959 | } 960 | } 961 | if(event->touch_point == uppoint) 962 | input_report_key(data->input_dev, BTN_TOUCH, 0); 963 | else 964 | input_report_key(data->input_dev, BTN_TOUCH, event->touch_point > 0); 965 | input_sync(data->input_dev); 966 | 967 | 968 | } 969 | 970 | static void fts_touch_irq_work(struct work_struct *work) 971 | { 972 | int ret = -1; 973 | 974 | ret = fts_read_Touchdata(fts_wq_data); 975 | if (ret == 0) 976 | fts_report_value(fts_wq_data); 977 | 978 | //enable_irq(fts_wq_data->client->irq); 979 | } 980 | 981 | static int ft5x06_gpio_configure(struct ft5x06_ts_data *data, bool on) 982 | { 983 | int err = 0; 984 | 985 | if (on) { 986 | if (gpio_is_valid(data->pdata->irq_gpio)) { 987 | err = gpio_request(data->pdata->irq_gpio, 988 | "ft5x06_irq_gpio"); 989 | if (err) { 990 | dev_err(&data->client->dev, 991 | "irq gpio request failed"); 992 | goto err_irq_gpio_req; 993 | } 994 | 995 | err = gpio_direction_input(data->pdata->irq_gpio); 996 | if (err) { 997 | dev_err(&data->client->dev, 998 | "set_direction for irq gpio failed\n"); 999 | goto err_irq_gpio_dir; 1000 | } 1001 | } 1002 | 1003 | if (gpio_is_valid(data->pdata->reset_gpio)) { 1004 | err = gpio_request(data->pdata->reset_gpio, 1005 | "ft5x06_reset_gpio"); 1006 | if (err) { 1007 | dev_err(&data->client->dev, 1008 | "reset gpio request failed"); 1009 | goto err_irq_gpio_dir; 1010 | } 1011 | 1012 | err = gpio_direction_output(data->pdata->reset_gpio, 0); 1013 | if (err) { 1014 | dev_err(&data->client->dev, 1015 | "set_direction for reset gpio failed\n"); 1016 | goto err_reset_gpio_dir; 1017 | } 1018 | msleep(data->pdata->hard_rst_dly); 1019 | gpio_set_value_cansleep(data->pdata->reset_gpio, 1); 1020 | } 1021 | 1022 | return 0; 1023 | } else { 1024 | if (gpio_is_valid(data->pdata->irq_gpio)) 1025 | gpio_free(data->pdata->irq_gpio); 1026 | if (gpio_is_valid(data->pdata->reset_gpio)) { 1027 | /* 1028 | * This is intended to save leakage current 1029 | * only. Even if the call(gpio_direction_input) 1030 | * fails, only leakage current will be more but 1031 | * functionality will not be affected. 1032 | */ 1033 | err = gpio_direction_input(data->pdata->reset_gpio); 1034 | if (err) { 1035 | dev_err(&data->client->dev, 1036 | "unable to set direction for gpio " 1037 | "[%d]\n", data->pdata->irq_gpio); 1038 | } 1039 | gpio_free(data->pdata->reset_gpio); 1040 | } 1041 | 1042 | return 0; 1043 | } 1044 | 1045 | err_reset_gpio_dir: 1046 | if (gpio_is_valid(data->pdata->reset_gpio)) 1047 | gpio_free(data->pdata->reset_gpio); 1048 | err_irq_gpio_dir: 1049 | if (gpio_is_valid(data->pdata->irq_gpio)) 1050 | gpio_free(data->pdata->irq_gpio); 1051 | err_irq_gpio_req: 1052 | return err; 1053 | } 1054 | 1055 | static int ft5x06_power_on(struct ft5x06_ts_data *data, bool on) 1056 | { 1057 | int rc; 1058 | 1059 | if (!on) 1060 | goto power_off; 1061 | 1062 | rc = regulator_enable(data->vdd); 1063 | if (rc) { 1064 | dev_err(&data->client->dev, 1065 | "Regulator vdd enable failed rc=%d\n", rc); 1066 | return rc; 1067 | } 1068 | 1069 | rc = regulator_enable(data->vcc_i2c); 1070 | if (rc) { 1071 | dev_err(&data->client->dev, 1072 | "Regulator vcc_i2c enable failed rc=%d\n", rc); 1073 | regulator_disable(data->vdd); 1074 | } 1075 | 1076 | return rc; 1077 | 1078 | power_off: 1079 | rc = regulator_disable(data->vdd); 1080 | if (rc) { 1081 | dev_err(&data->client->dev, 1082 | "Regulator vdd disable failed rc=%d\n", rc); 1083 | return rc; 1084 | } 1085 | 1086 | rc = regulator_disable(data->vcc_i2c); 1087 | if (rc) { 1088 | dev_err(&data->client->dev, 1089 | "Regulator vcc_i2c disable failed rc=%d\n", rc); 1090 | rc = regulator_enable(data->vdd); 1091 | if (rc) { 1092 | dev_err(&data->client->dev, 1093 | "Regulator vdd enable failed rc=%d\n", rc); 1094 | } 1095 | } 1096 | 1097 | return rc; 1098 | } 1099 | 1100 | static int ft5x06_power_init(struct ft5x06_ts_data *data, bool on) 1101 | { 1102 | int rc; 1103 | 1104 | if (!on) 1105 | goto pwr_deinit; 1106 | 1107 | data->vdd = regulator_get(&data->client->dev, "vdd"); 1108 | if (IS_ERR(data->vdd)) { 1109 | rc = PTR_ERR(data->vdd); 1110 | dev_err(&data->client->dev, 1111 | "Regulator get failed vdd rc=%d\n", rc); 1112 | return rc; 1113 | } 1114 | 1115 | if (regulator_count_voltages(data->vdd) > 0) { 1116 | rc = regulator_set_voltage(data->vdd, FT_VTG_MIN_UV, 1117 | FT_VTG_MAX_UV); 1118 | if (rc) { 1119 | dev_err(&data->client->dev, 1120 | "Regulator set_vtg failed vdd rc=%d\n", rc); 1121 | goto reg_vdd_put; 1122 | } 1123 | } 1124 | 1125 | data->vcc_i2c = regulator_get(&data->client->dev, "vcc_i2c"); 1126 | if (IS_ERR(data->vcc_i2c)) { 1127 | rc = PTR_ERR(data->vcc_i2c); 1128 | dev_err(&data->client->dev, 1129 | "Regulator get failed vcc_i2c rc=%d\n", rc); 1130 | goto reg_vdd_set_vtg; 1131 | } 1132 | 1133 | if (regulator_count_voltages(data->vcc_i2c) > 0) { 1134 | rc = regulator_set_voltage(data->vcc_i2c, FT_I2C_VTG_MIN_UV, 1135 | FT_I2C_VTG_MAX_UV); 1136 | if (rc) { 1137 | dev_err(&data->client->dev, 1138 | "Regulator set_vtg failed vcc_i2c rc=%d\n", rc); 1139 | goto reg_vcc_i2c_put; 1140 | } 1141 | } 1142 | 1143 | return 0; 1144 | 1145 | reg_vcc_i2c_put: 1146 | regulator_put(data->vcc_i2c); 1147 | reg_vdd_set_vtg: 1148 | if (regulator_count_voltages(data->vdd) > 0) 1149 | regulator_set_voltage(data->vdd, 0, FT_VTG_MAX_UV); 1150 | reg_vdd_put: 1151 | regulator_put(data->vdd); 1152 | return rc; 1153 | 1154 | pwr_deinit: 1155 | if (regulator_count_voltages(data->vdd) > 0) 1156 | regulator_set_voltage(data->vdd, 0, FT_VTG_MAX_UV); 1157 | 1158 | regulator_put(data->vdd); 1159 | 1160 | if (regulator_count_voltages(data->vcc_i2c) > 0) 1161 | regulator_set_voltage(data->vcc_i2c, 0, FT_I2C_VTG_MAX_UV); 1162 | 1163 | regulator_put(data->vcc_i2c); 1164 | return 0; 1165 | } 1166 | 1167 | static int ft5x06_ts_pinctrl_init(struct ft5x06_ts_data *ft5x06_data) 1168 | { 1169 | int retval; 1170 | 1171 | /* Get pinctrl if target uses pinctrl */ 1172 | ft5x06_data->ts_pinctrl = devm_pinctrl_get(&(ft5x06_data->client->dev)); 1173 | if (IS_ERR_OR_NULL(ft5x06_data->ts_pinctrl)) { 1174 | retval = PTR_ERR(ft5x06_data->ts_pinctrl); 1175 | dev_dbg(&ft5x06_data->client->dev, 1176 | "Target does not use pinctrl %d\n", retval); 1177 | goto err_pinctrl_get; 1178 | } 1179 | 1180 | ft5x06_data->pinctrl_state_active 1181 | = pinctrl_lookup_state(ft5x06_data->ts_pinctrl, 1182 | PINCTRL_STATE_ACTIVE); 1183 | if (IS_ERR_OR_NULL(ft5x06_data->pinctrl_state_active)) { 1184 | retval = PTR_ERR(ft5x06_data->pinctrl_state_active); 1185 | dev_err(&ft5x06_data->client->dev, 1186 | "Can not lookup %s pinstate %d\n", 1187 | PINCTRL_STATE_ACTIVE, retval); 1188 | goto err_pinctrl_lookup; 1189 | } 1190 | 1191 | ft5x06_data->pinctrl_state_suspend 1192 | = pinctrl_lookup_state(ft5x06_data->ts_pinctrl, 1193 | PINCTRL_STATE_SUSPEND); 1194 | if (IS_ERR_OR_NULL(ft5x06_data->pinctrl_state_suspend)) { 1195 | retval = PTR_ERR(ft5x06_data->pinctrl_state_suspend); 1196 | dev_err(&ft5x06_data->client->dev, 1197 | "Can not lookup %s pinstate %d\n", 1198 | PINCTRL_STATE_SUSPEND, retval); 1199 | goto err_pinctrl_lookup; 1200 | } 1201 | 1202 | ft5x06_data->pinctrl_state_release 1203 | = pinctrl_lookup_state(ft5x06_data->ts_pinctrl, 1204 | PINCTRL_STATE_RELEASE); 1205 | if (IS_ERR_OR_NULL(ft5x06_data->pinctrl_state_release)) { 1206 | retval = PTR_ERR(ft5x06_data->pinctrl_state_release); 1207 | dev_dbg(&ft5x06_data->client->dev, 1208 | "Can not lookup %s pinstate %d\n", 1209 | PINCTRL_STATE_RELEASE, retval); 1210 | } 1211 | 1212 | return 0; 1213 | 1214 | err_pinctrl_lookup: 1215 | devm_pinctrl_put(ft5x06_data->ts_pinctrl); 1216 | err_pinctrl_get: 1217 | ft5x06_data->ts_pinctrl = NULL; 1218 | return retval; 1219 | } 1220 | 1221 | #ifdef CONFIG_PM 1222 | static int ft5x06_ts_suspend(struct device *dev) 1223 | { 1224 | struct ft5x06_ts_data *data = dev_get_drvdata(dev); 1225 | char txbuf[2], i; 1226 | int err; 1227 | 1228 | #ifdef CONFIG_TOUCHPANEL_PROXIMITY_SENSOR 1229 | if(tp_prox_sensor_opened){ 1230 | DBG("tp can not sleep in call\n"); 1231 | is_need_report_pointer = 0; 1232 | return; 1233 | } 1234 | #endif 1235 | 1236 | #ifdef FTS_GESTRUE 1237 | ft5x0x_write_reg(fts_i2c_client, 0xd0, 0x01); 1238 | if (fts_updateinfo_curr.CHIP_ID==0x54) 1239 | { 1240 | ft5x0x_write_reg(i2c_client, 0xd1, 0xff); 1241 | ft5x0x_write_reg(i2c_client, 0xd2, 0xff); 1242 | ft5x0x_write_reg(i2c_client, 0xd5, 0xff); 1243 | ft5x0x_write_reg(i2c_client, 0xd6, 0xff); 1244 | ft5x0x_write_reg(i2c_client, 0xd7, 0xff); 1245 | ft5x0x_write_reg(i2c_client, 0xd8, 0xff); 1246 | } 1247 | 1248 | data->suspended = true; 1249 | 1250 | return; 1251 | #endif 1252 | 1253 | if (data->loading_fw) { 1254 | dev_info(dev, "Firmware loading in process...\n"); 1255 | return 0; 1256 | } 1257 | 1258 | if (data->suspended) { 1259 | dev_info(dev, "Already in suspend state\n"); 1260 | return 0; 1261 | } 1262 | 1263 | disable_irq(data->client->irq); 1264 | 1265 | /* release all touches */ 1266 | for (i = 0; i < data->pdata->num_max_touches; i++) { 1267 | input_mt_slot(data->input_dev, i); 1268 | input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, 0); 1269 | } 1270 | input_mt_report_pointer_emulation(data->input_dev, false); 1271 | input_sync(data->input_dev); 1272 | 1273 | if (gpio_is_valid(data->pdata->reset_gpio)) { 1274 | txbuf[0] = FT_REG_PMODE; 1275 | txbuf[1] = FT_PMODE_HIBERNATE; 1276 | ft5x06_i2c_write(data->client, txbuf, sizeof(txbuf)); 1277 | } 1278 | 1279 | if (data->pdata->power_on) { 1280 | err = data->pdata->power_on(false); 1281 | if (err) { 1282 | dev_err(dev, "power off failed"); 1283 | goto pwr_off_fail; 1284 | } 1285 | } else { 1286 | err = ft5x06_power_on(data, false); 1287 | if (err) { 1288 | dev_err(dev, "power off failed"); 1289 | goto pwr_off_fail; 1290 | } 1291 | } 1292 | 1293 | if (data->ts_pinctrl) { 1294 | err = pinctrl_select_state(data->ts_pinctrl, 1295 | data->pinctrl_state_suspend); 1296 | if (err < 0) 1297 | dev_err(dev, "Cannot get suspend pinctrl state\n"); 1298 | } 1299 | 1300 | err = ft5x06_gpio_configure(data, false); 1301 | if (err < 0) { 1302 | dev_err(&data->client->dev, 1303 | "failed to put gpios in suspend state\n"); 1304 | goto gpio_configure_fail; 1305 | } 1306 | 1307 | data->suspended = true; 1308 | 1309 | #ifdef CONFIG_TOUCHPANEL_PROXIMITY_SENSOR 1310 | is_suspend = 1; 1311 | #endif 1312 | 1313 | return 0; 1314 | 1315 | gpio_configure_fail: 1316 | if (data->ts_pinctrl) { 1317 | err = pinctrl_select_state(data->ts_pinctrl, 1318 | data->pinctrl_state_active); 1319 | if (err < 0) 1320 | dev_err(dev, "Cannot get active pinctrl state\n"); 1321 | } 1322 | if (data->pdata->power_on) { 1323 | err = data->pdata->power_on(true); 1324 | if (err) 1325 | dev_err(dev, "power on failed"); 1326 | } else { 1327 | err = ft5x06_power_on(data, true); 1328 | if (err) 1329 | dev_err(dev, "power on failed"); 1330 | } 1331 | pwr_off_fail: 1332 | if (gpio_is_valid(data->pdata->reset_gpio)) { 1333 | gpio_set_value_cansleep(data->pdata->reset_gpio, 0); 1334 | msleep(data->pdata->hard_rst_dly); 1335 | gpio_set_value_cansleep(data->pdata->reset_gpio, 1); 1336 | } 1337 | enable_irq(data->client->irq); 1338 | return err; 1339 | } 1340 | 1341 | static int ft5x06_ts_resume(struct device *dev) 1342 | { 1343 | struct ft5x06_ts_data *data = dev_get_drvdata(dev); 1344 | int err; 1345 | 1346 | if (!data->suspended) { 1347 | dev_dbg(dev, "Already in awake state\n"); 1348 | return 0; 1349 | } 1350 | 1351 | #ifdef CONFIG_TOUCHPANEL_PROXIMITY_SENSOR 1352 | is_need_report_pointer = 1; 1353 | if((tp_prox_sensor_opened) && (is_suspend == 0)){ 1354 | DBG("%s tp no need to wake up in call\n",__func__); 1355 | return; 1356 | } 1357 | #endif 1358 | 1359 | if (data->pdata->power_on) { 1360 | err = data->pdata->power_on(true); 1361 | if (err) { 1362 | dev_err(dev, "power on failed"); 1363 | return err; 1364 | } 1365 | } else { 1366 | err = ft5x06_power_on(data, true); 1367 | if (err) { 1368 | dev_err(dev, "power on failed"); 1369 | return err; 1370 | } 1371 | } 1372 | 1373 | if (data->ts_pinctrl) { 1374 | err = pinctrl_select_state(data->ts_pinctrl, 1375 | data->pinctrl_state_active); 1376 | if (err < 0) 1377 | dev_err(dev, "Cannot get active pinctrl state\n"); 1378 | } 1379 | 1380 | err = ft5x06_gpio_configure(data, true); 1381 | if (err < 0) { 1382 | dev_err(&data->client->dev, 1383 | "failed to put gpios in resue state\n"); 1384 | goto err_gpio_configuration; 1385 | } 1386 | 1387 | if (gpio_is_valid(data->pdata->reset_gpio)) { 1388 | gpio_set_value_cansleep(data->pdata->reset_gpio, 0); 1389 | msleep(data->pdata->hard_rst_dly); 1390 | gpio_set_value_cansleep(data->pdata->reset_gpio, 1); 1391 | } 1392 | 1393 | msleep(data->pdata->soft_rst_dly); 1394 | 1395 | enable_irq(data->client->irq); 1396 | 1397 | data->suspended = false; 1398 | 1399 | #ifdef CONFIG_TOUCHPANEL_PROXIMITY_SENSOR 1400 | is_suspend = 0; 1401 | #endif 1402 | 1403 | #ifdef FTS_GESTRUE 1404 | ft5x0x_write_reg(fts_i2c_client,0xD0,0x00); 1405 | #endif 1406 | 1407 | return 0; 1408 | 1409 | err_gpio_configuration: 1410 | if (data->ts_pinctrl) { 1411 | err = pinctrl_select_state(data->ts_pinctrl, 1412 | data->pinctrl_state_suspend); 1413 | if (err < 0) 1414 | dev_err(dev, "Cannot get suspend pinctrl state\n"); 1415 | } 1416 | if (data->pdata->power_on) { 1417 | err = data->pdata->power_on(false); 1418 | if (err) 1419 | dev_err(dev, "power off failed"); 1420 | } else { 1421 | err = ft5x06_power_on(data, false); 1422 | if (err) 1423 | dev_err(dev, "power off failed"); 1424 | } 1425 | return err; 1426 | } 1427 | 1428 | static const struct dev_pm_ops ft5x06_ts_pm_ops = { 1429 | #if (!defined(CONFIG_FB) && !defined(CONFIG_HAS_EARLYSUSPEND)) 1430 | .suspend = ft5x06_ts_suspend, 1431 | .resume = ft5x06_ts_resume, 1432 | #endif 1433 | }; 1434 | 1435 | #else 1436 | static int ft5x06_ts_suspend(struct device *dev) 1437 | { 1438 | return 0; 1439 | } 1440 | 1441 | static int ft5x06_ts_resume(struct device *dev) 1442 | { 1443 | return 0; 1444 | } 1445 | 1446 | #endif 1447 | 1448 | #if defined(CONFIG_FB) 1449 | static int fb_notifier_callback(struct notifier_block *self, 1450 | unsigned long event, void *data) 1451 | { 1452 | struct fb_event *evdata = data; 1453 | int *blank; 1454 | struct ft5x06_ts_data *ft5x06_data = 1455 | container_of(self, struct ft5x06_ts_data, fb_notif); 1456 | 1457 | if (evdata && evdata->data && event == FB_EVENT_BLANK && 1458 | ft5x06_data && ft5x06_data->client) { 1459 | blank = evdata->data; 1460 | if (*blank == FB_BLANK_UNBLANK) 1461 | ft5x06_ts_resume(&ft5x06_data->client->dev); 1462 | else if (*blank == FB_BLANK_POWERDOWN) 1463 | ft5x06_ts_suspend(&ft5x06_data->client->dev); 1464 | } 1465 | 1466 | return 0; 1467 | } 1468 | #elif defined(CONFIG_HAS_EARLYSUSPEND) 1469 | static void ft5x06_ts_early_suspend(struct early_suspend *handler) 1470 | { 1471 | struct ft5x06_ts_data *data = container_of(handler, 1472 | struct ft5x06_ts_data, 1473 | early_suspend); 1474 | 1475 | ft5x06_ts_suspend(&data->client->dev); 1476 | } 1477 | 1478 | static void ft5x06_ts_late_resume(struct early_suspend *handler) 1479 | { 1480 | struct ft5x06_ts_data *data = container_of(handler, 1481 | struct ft5x06_ts_data, 1482 | early_suspend); 1483 | 1484 | ft5x06_ts_resume(&data->client->dev); 1485 | } 1486 | #endif 1487 | 1488 | void focaltech_get_upgrade_array(void) 1489 | { 1490 | 1491 | u8 chip_id; 1492 | u32 i; 1493 | u8 temp = FT_REG_ID; 1494 | 1495 | ft5x06_i2c_read(i2c_client,&temp,1,&chip_id); 1496 | 1497 | printk("%s chip_id = %x\n", __func__, chip_id); 1498 | 1499 | for(i=0;i= sizeof(fts_updateinfo)/sizeof(struct Upgrade_Info)) 1509 | { 1510 | memcpy(&fts_updateinfo_curr, &fts_updateinfo[0], sizeof(struct Upgrade_Info)); 1511 | } 1512 | } 1513 | 1514 | int fts_6x36_ctpm_fw_upgrade(struct i2c_client *client, u8 *pbt_buf, 1515 | u32 dw_lenth) 1516 | { 1517 | u8 reg_val[2] = {0}; 1518 | u32 i = 0; 1519 | u32 packet_number; 1520 | u32 j; 1521 | u32 temp; 1522 | u32 lenght; 1523 | u32 fw_length; 1524 | u8 packet_buf[FT_FW_PKT_LEN + 6]; 1525 | u8 auc_i2c_write_buf[10]; 1526 | u8 bt_ecc; 1527 | int i_ret; 1528 | 1529 | 1530 | if(pbt_buf[0] != 0x02) 1531 | { 1532 | DBG("[FTS] FW first byte is not 0x02. so it is invalid \n"); 1533 | return -1; 1534 | } 1535 | 1536 | if(dw_lenth > 0x11f) 1537 | { 1538 | fw_length = ((u32)pbt_buf[0x100]<<8) + pbt_buf[0x101]; 1539 | if(dw_lenth < fw_length) 1540 | { 1541 | DBG("[FTS] Fw length is invalid \n"); 1542 | return -1; 1543 | } 1544 | } 1545 | else 1546 | { 1547 | DBG("[FTS] Fw length is invalid \n"); 1548 | return -1; 1549 | } 1550 | 1551 | for (i = 0; i < FT_UPGRADE_LOOP; i++) { 1552 | /*********Step 1:Reset CTPM *****/ 1553 | /*write 0xaa to register 0xbc */ 1554 | 1555 | ft5x0x_write_reg(client, 0xbc, FT_UPGRADE_AA); 1556 | msleep(fts_updateinfo_curr.delay_aa); 1557 | 1558 | /*write 0x55 to register 0xbc */ 1559 | ft5x0x_write_reg(client, 0xbc, FT_UPGRADE_55); 1560 | 1561 | msleep(fts_updateinfo_curr.delay_55); 1562 | 1563 | /*********Step 2:Enter upgrade mode *****/ 1564 | auc_i2c_write_buf[0] = FT_UPGRADE_55; 1565 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); 1566 | 1567 | auc_i2c_write_buf[0] = FT_UPGRADE_AA; 1568 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); 1569 | msleep(fts_updateinfo_curr.delay_readid); 1570 | 1571 | /*********Step 3:check READ-ID***********************/ 1572 | auc_i2c_write_buf[0] = 0x90; 1573 | auc_i2c_write_buf[1] = auc_i2c_write_buf[2] = auc_i2c_write_buf[3] = 1574 | 0x00; 1575 | reg_val[0] = 0x00; 1576 | reg_val[1] = 0x00; 1577 | ft5x06_i2c_read(client, auc_i2c_write_buf, 4, reg_val, 2); 1578 | 1579 | 1580 | if (reg_val[0] == fts_updateinfo_curr.upgrade_id_1 1581 | && reg_val[1] == fts_updateinfo_curr.upgrade_id_2) { 1582 | DBG("[FTS] Step 3: GET CTPM ID OK,ID1 = 0x%x,ID2 = 0x%x\n", 1583 | reg_val[0], reg_val[1]); 1584 | break; 1585 | } else { 1586 | dev_err(&client->dev, "[FTS] Step 3: GET CTPM ID FAIL,ID1 = 0x%x,ID2 = 0x%x\n", 1587 | reg_val[0], reg_val[1]); 1588 | } 1589 | } 1590 | if (i >= FT_UPGRADE_LOOP) 1591 | return -EIO; 1592 | 1593 | auc_i2c_write_buf[0] = 0x90; 1594 | auc_i2c_write_buf[1] = 0x00; 1595 | auc_i2c_write_buf[2] = 0x00; 1596 | auc_i2c_write_buf[3] = 0x00; 1597 | auc_i2c_write_buf[4] = 0x00; 1598 | ft5x06_i2c_write(client, auc_i2c_write_buf, 5); 1599 | 1600 | //auc_i2c_write_buf[0] = 0xcd; 1601 | //ft5x06_i2c_read(client, auc_i2c_write_buf, 1, reg_val, 1); 1602 | 1603 | 1604 | /*Step 4:erase app and panel paramenter area*/ 1605 | DBG("Step 4:erase app and panel paramenter area\n"); 1606 | auc_i2c_write_buf[0] = 0x61; 1607 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); /*erase app area */ 1608 | msleep(fts_updateinfo_curr.delay_earse_flash); 1609 | 1610 | for(i = 0;i < 200;i++) 1611 | { 1612 | auc_i2c_write_buf[0] = 0x6a; 1613 | auc_i2c_write_buf[1] = 0x00; 1614 | auc_i2c_write_buf[2] = 0x00; 1615 | auc_i2c_write_buf[3] = 0x00; 1616 | reg_val[0] = 0x00; 1617 | reg_val[1] = 0x00; 1618 | ft5x06_i2c_read(client, auc_i2c_write_buf, 4, reg_val, 2); 1619 | if(0xb0 == reg_val[0] && 0x02 == reg_val[1]) 1620 | { 1621 | DBG("[FTS] erase app finished \n"); 1622 | break; 1623 | } 1624 | msleep(50); 1625 | } 1626 | 1627 | /*********Step 5:write firmware(FW) to ctpm flash*********/ 1628 | bt_ecc = 0; 1629 | DBG("Step 5:write firmware(FW) to ctpm flash\n"); 1630 | 1631 | dw_lenth = fw_length; 1632 | packet_number = (dw_lenth) / FT_FW_PKT_LEN; 1633 | packet_buf[0] = 0xbf; 1634 | packet_buf[1] = 0x00; 1635 | 1636 | for (j = 0; j < packet_number; j++) { 1637 | temp = j * FT_FW_PKT_LEN; 1638 | packet_buf[2] = (u8) (temp >> 8); 1639 | packet_buf[3] = (u8) temp; 1640 | lenght = FT_FW_PKT_LEN; 1641 | packet_buf[4] = (u8) (lenght >> 8); 1642 | packet_buf[5] = (u8) lenght; 1643 | 1644 | for (i = 0; i < FT_FW_PKT_LEN; i++) { 1645 | packet_buf[6 + i] = pbt_buf[j * FT_FW_PKT_LEN + i]; 1646 | bt_ecc ^= packet_buf[6 + i]; 1647 | } 1648 | 1649 | ft5x06_i2c_write(client, packet_buf, FT_FW_PKT_LEN + 6); 1650 | 1651 | for(i = 0;i < 30;i++) 1652 | { 1653 | auc_i2c_write_buf[0] = 0x6a; 1654 | auc_i2c_write_buf[1] = 0x00; 1655 | auc_i2c_write_buf[2] = 0x00; 1656 | auc_i2c_write_buf[3] = 0x00; 1657 | reg_val[0] = 0x00; 1658 | reg_val[1] = 0x00; 1659 | ft5x06_i2c_read(client, auc_i2c_write_buf, 4, reg_val, 2); 1660 | if(0xb0 == (reg_val[0] & 0xf0) && (0x03 + (j % 0x0ffd)) == (((reg_val[0] & 0x0f) << 8) |reg_val[1])) 1661 | { 1662 | DBG("[FTS] write a block data finished \n"); 1663 | break; 1664 | } 1665 | msleep(1); 1666 | } 1667 | } 1668 | 1669 | if ((dw_lenth) % FT_FW_PKT_LEN > 0) { 1670 | temp = packet_number * FT_FW_PKT_LEN; 1671 | packet_buf[2] = (u8) (temp >> 8); 1672 | packet_buf[3] = (u8) temp; 1673 | temp = (dw_lenth) % FT_FW_PKT_LEN; 1674 | packet_buf[4] = (u8) (temp >> 8); 1675 | packet_buf[5] = (u8) temp; 1676 | 1677 | for (i = 0; i < temp; i++) { 1678 | packet_buf[6 + i] = pbt_buf[packet_number * FT_FW_PKT_LEN + i]; 1679 | bt_ecc ^= packet_buf[6 + i]; 1680 | } 1681 | 1682 | ft5x06_i2c_write(client, packet_buf, temp + 6); 1683 | 1684 | for(i = 0;i < 30;i++) 1685 | { 1686 | auc_i2c_write_buf[0] = 0x6a; 1687 | auc_i2c_write_buf[1] = 0x00; 1688 | auc_i2c_write_buf[2] = 0x00; 1689 | auc_i2c_write_buf[3] = 0x00; 1690 | reg_val[0] = 0x00; 1691 | reg_val[1] = 0x00; 1692 | ft5x06_i2c_read(client, auc_i2c_write_buf, 4, reg_val, 2); 1693 | if(0xb0 == (reg_val[0] & 0xf0) && (0x03 + (j % 0x0ffd)) == (((reg_val[0] & 0x0f) << 8) |reg_val[1])) 1694 | { 1695 | DBG("[FTS] write a block data finished \n"); 1696 | break; 1697 | } 1698 | msleep(1); 1699 | } 1700 | } 1701 | 1702 | 1703 | /*********Step 6: read out checksum***********************/ 1704 | /*send the opration head */ 1705 | DBG("Step 6: read out checksum\n"); 1706 | auc_i2c_write_buf[0] = 0xcc; 1707 | ft5x06_i2c_read(client, auc_i2c_write_buf, 1, reg_val, 1); 1708 | if (reg_val[0] != bt_ecc) { 1709 | dev_err(&client->dev, "[FTS]--ecc error! FW=%02x bt_ecc=%02x\n", 1710 | reg_val[0], 1711 | bt_ecc); 1712 | return -EIO; 1713 | } 1714 | 1715 | /*********Step 7: reset the new FW***********************/ 1716 | DBG("Step 7: reset the new FW\n"); 1717 | auc_i2c_write_buf[0] = 0x07; 1718 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); 1719 | msleep(300); /*make sure CTP startup normally */ 1720 | 1721 | return 0; 1722 | } 1723 | 1724 | int fts_6x06_ctpm_fw_upgrade(struct i2c_client *client, u8 *pbt_buf, u32 dw_lenth) 1725 | { 1726 | u8 reg_val[2] = {0}; 1727 | u32 i = 0; 1728 | u32 packet_number; 1729 | u32 j; 1730 | u32 temp; 1731 | u32 lenght; 1732 | u8 packet_buf[FT_FW_PKT_LEN + 6]; 1733 | u8 auc_i2c_write_buf[10]; 1734 | u8 bt_ecc; 1735 | int i_ret; 1736 | 1737 | 1738 | for (i = 0; i < FT_UPGRADE_LOOP; i++) { 1739 | /*********Step 1:Reset CTPM *****/ 1740 | /*write 0xaa to register 0xbc */ 1741 | 1742 | ft5x0x_write_reg(client, 0xbc, FT_UPGRADE_AA); 1743 | msleep(fts_updateinfo_curr.delay_aa); 1744 | 1745 | /*write 0x55 to register 0xbc */ 1746 | ft5x0x_write_reg(client, 0xbc, FT_UPGRADE_55); 1747 | 1748 | msleep(fts_updateinfo_curr.delay_55); 1749 | 1750 | /*********Step 2:Enter upgrade mode *****/ 1751 | auc_i2c_write_buf[0] = FT_UPGRADE_55; 1752 | auc_i2c_write_buf[1] = FT_UPGRADE_AA; 1753 | do { 1754 | i++; 1755 | i_ret = ft5x06_i2c_write(client, auc_i2c_write_buf, 2); 1756 | msleep(5); 1757 | } while (i_ret <= 0 && i < 5); 1758 | 1759 | 1760 | /*********Step 3:check READ-ID***********************/ 1761 | msleep(fts_updateinfo_curr.delay_readid); 1762 | auc_i2c_write_buf[0] = 0x90; 1763 | auc_i2c_write_buf[1] = auc_i2c_write_buf[2] = auc_i2c_write_buf[3] = 1764 | 0x00; 1765 | ft5x06_i2c_read(client, auc_i2c_write_buf, 4, reg_val, 2); 1766 | 1767 | 1768 | if (reg_val[0] == fts_updateinfo_curr.upgrade_id_1 1769 | && reg_val[1] == fts_updateinfo_curr.upgrade_id_2) { 1770 | DBG("[FTS] Step 3: CTPM ID OK ,ID1 = 0x%x,ID2 = 0x%x\n", 1771 | reg_val[0], reg_val[1]); 1772 | break; 1773 | } else { 1774 | dev_err(&client->dev, "[FTS] Step 3: CTPM ID FAIL,ID1 = 0x%x,ID2 = 0x%x\n", 1775 | reg_val[0], reg_val[1]); 1776 | } 1777 | } 1778 | if (i > FT_UPGRADE_LOOP) 1779 | return -EIO; 1780 | auc_i2c_write_buf[0] = 0xcd; 1781 | 1782 | ft5x06_i2c_read(client, auc_i2c_write_buf, 1, reg_val, 1); 1783 | 1784 | 1785 | /*Step 4:erase app and panel paramenter area*/ 1786 | DBG("Step 4:erase app and panel paramenter area\n"); 1787 | auc_i2c_write_buf[0] = 0x61; 1788 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); /*erase app area */ 1789 | msleep(fts_updateinfo_curr.delay_earse_flash); 1790 | /*erase panel parameter area */ 1791 | auc_i2c_write_buf[0] = 0x63; 1792 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); 1793 | msleep(100); 1794 | 1795 | /*********Step 5:write firmware(FW) to ctpm flash*********/ 1796 | bt_ecc = 0; 1797 | DBG("Step 5:write firmware(FW) to ctpm flash\n"); 1798 | 1799 | dw_lenth = dw_lenth - 8; 1800 | packet_number = (dw_lenth) / FT_FW_PKT_LEN; 1801 | packet_buf[0] = 0xbf; 1802 | packet_buf[1] = 0x00; 1803 | 1804 | for (j = 0; j < packet_number; j++) { 1805 | temp = j * FT_FW_PKT_LEN; 1806 | packet_buf[2] = (u8) (temp >> 8); 1807 | packet_buf[3] = (u8) temp; 1808 | lenght = FT_FW_PKT_LEN; 1809 | packet_buf[4] = (u8) (lenght >> 8); 1810 | packet_buf[5] = (u8) lenght; 1811 | 1812 | for (i = 0; i < FT_FW_PKT_LEN; i++) { 1813 | packet_buf[6 + i] = pbt_buf[j * FT_FW_PKT_LEN + i]; 1814 | bt_ecc ^= packet_buf[6 + i]; 1815 | } 1816 | 1817 | ft5x06_i2c_write(client, packet_buf, FT_FW_PKT_LEN + 6); 1818 | msleep(FT_FW_PKT_LEN / 6 + 1); 1819 | } 1820 | 1821 | if ((dw_lenth) % FT_FW_PKT_LEN > 0) { 1822 | temp = packet_number * FT_FW_PKT_LEN; 1823 | packet_buf[2] = (u8) (temp >> 8); 1824 | packet_buf[3] = (u8) temp; 1825 | temp = (dw_lenth) % FT_FW_PKT_LEN; 1826 | packet_buf[4] = (u8) (temp >> 8); 1827 | packet_buf[5] = (u8) temp; 1828 | 1829 | for (i = 0; i < temp; i++) { 1830 | packet_buf[6 + i] = pbt_buf[packet_number * FT_FW_PKT_LEN + i]; 1831 | bt_ecc ^= packet_buf[6 + i]; 1832 | } 1833 | 1834 | ft5x06_i2c_write(client, packet_buf, temp + 6); 1835 | msleep(20); 1836 | } 1837 | 1838 | 1839 | /*send the last six byte */ 1840 | for (i = 0; i < 6; i++) { 1841 | temp = 0x6ffa + i; 1842 | packet_buf[2] = (u8) (temp >> 8); 1843 | packet_buf[3] = (u8) temp; 1844 | temp = 1; 1845 | packet_buf[4] = (u8) (temp >> 8); 1846 | packet_buf[5] = (u8) temp; 1847 | packet_buf[6] = pbt_buf[dw_lenth + i]; 1848 | bt_ecc ^= packet_buf[6]; 1849 | ft5x06_i2c_write(client, packet_buf, 7); 1850 | msleep(20); 1851 | } 1852 | 1853 | 1854 | /*********Step 6: read out checksum***********************/ 1855 | /*send the opration head */ 1856 | DBG("Step 6: read out checksum\n"); 1857 | auc_i2c_write_buf[0] = 0xcc; 1858 | ft5x06_i2c_read(client, auc_i2c_write_buf, 1, reg_val, 1); 1859 | if (reg_val[0] != bt_ecc) { 1860 | dev_err(&client->dev, "[FTS]--ecc error! FW=%02x bt_ecc=%02x\n", 1861 | reg_val[0], 1862 | bt_ecc); 1863 | return -EIO; 1864 | } 1865 | 1866 | /*********Step 7: reset the new FW***********************/ 1867 | DBG("Step 7: reset the new FW\n"); 1868 | auc_i2c_write_buf[0] = 0x07; 1869 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); 1870 | msleep(300); /*make sure CTP startup normally */ 1871 | 1872 | return 0; 1873 | } 1874 | 1875 | int fts_5x36_ctpm_fw_upgrade(struct i2c_client *client, u8 *pbt_buf, u32 dw_lenth) 1876 | { 1877 | u8 reg_val[2] = {0}; 1878 | u32 i = 0; 1879 | u8 is_5336_new_bootloader = 0; 1880 | u8 is_5336_fwsize_30 = 0; 1881 | u32 packet_number; 1882 | u32 j; 1883 | u32 temp; 1884 | u32 lenght; 1885 | u8 packet_buf[FT_FW_PKT_LEN + 6]; 1886 | u8 auc_i2c_write_buf[10]; 1887 | u8 bt_ecc; 1888 | int i_ret; 1889 | int fw_filenth = sizeof(CTPM_FW); 1890 | 1891 | if(CTPM_FW[fw_filenth-12] == 30) 1892 | { 1893 | is_5336_fwsize_30 = 1; 1894 | } 1895 | else 1896 | { 1897 | is_5336_fwsize_30 = 0; 1898 | } 1899 | 1900 | for (i = 0; i < FT_UPGRADE_LOOP; i++) { 1901 | /*********Step 1:Reset CTPM *****/ 1902 | /*write 0xaa to register 0xfc*/ 1903 | /*write 0xaa to register 0xfc*/ 1904 | ft5x0x_write_reg(client, 0xfc, FT_UPGRADE_AA); 1905 | msleep(fts_updateinfo_curr.delay_aa); 1906 | 1907 | /*write 0x55 to register 0xfc*/ 1908 | ft5x0x_write_reg(client, 0xfc, FT_UPGRADE_55); 1909 | msleep(fts_updateinfo_curr.delay_55); 1910 | 1911 | 1912 | /*********Step 2:Enter upgrade mode *****/ 1913 | auc_i2c_write_buf[0] = FT_UPGRADE_55; 1914 | auc_i2c_write_buf[1] = FT_UPGRADE_AA; 1915 | 1916 | i_ret = ft5x06_i2c_write(client, auc_i2c_write_buf, 2); 1917 | 1918 | /*********Step 3:check READ-ID***********************/ 1919 | msleep(fts_updateinfo_curr.delay_readid); 1920 | auc_i2c_write_buf[0] = 0x90; 1921 | auc_i2c_write_buf[1] = auc_i2c_write_buf[2] = auc_i2c_write_buf[3] = 0x00; 1922 | ft5x06_i2c_read(client, auc_i2c_write_buf, 4, reg_val, 2); 1923 | if (reg_val[0] == fts_updateinfo_curr.upgrade_id_1 1924 | && reg_val[1] == fts_updateinfo_curr.upgrade_id_2) 1925 | { 1926 | dev_dbg(&client->dev, "[FTS] Step 3: CTPM ID OK,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]); 1927 | break; 1928 | } 1929 | else 1930 | { 1931 | dev_err(&client->dev, "[FTS] Step 3: CTPM ID FAILD,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]); 1932 | continue; 1933 | } 1934 | 1935 | } 1936 | 1937 | if (i >= FT_UPGRADE_LOOP) 1938 | return -EIO; 1939 | 1940 | auc_i2c_write_buf[0] = 0xcd; 1941 | ft5x06_i2c_read(client, auc_i2c_write_buf, 1, reg_val, 1); 1942 | 1943 | /*********20130705 mshl ********************/ 1944 | if (reg_val[0] <= 4) 1945 | { 1946 | is_5336_new_bootloader = BL_VERSION_LZ4 ; 1947 | } 1948 | else if(reg_val[0] == 7) 1949 | { 1950 | is_5336_new_bootloader = BL_VERSION_Z7 ; 1951 | } 1952 | else if(reg_val[0] >= 0x0f) 1953 | { 1954 | is_5336_new_bootloader = BL_VERSION_GZF ; 1955 | } 1956 | 1957 | /*********Step 4:erase app and panel paramenter area ********************/ 1958 | if(is_5336_fwsize_30) 1959 | { 1960 | auc_i2c_write_buf[0] = 0x61; 1961 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); /*erase app area*/ 1962 | msleep(fts_updateinfo_curr.delay_earse_flash); 1963 | 1964 | auc_i2c_write_buf[0] = 0x63; 1965 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); /*erase config area*/ 1966 | msleep(50); 1967 | } 1968 | else 1969 | { 1970 | auc_i2c_write_buf[0] = 0x61; 1971 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); /*erase app area*/ 1972 | msleep(fts_updateinfo_curr.delay_earse_flash); 1973 | } 1974 | 1975 | /*********Step 5:write firmware(FW) to ctpm flash*********/ 1976 | bt_ecc = 0; 1977 | 1978 | if(is_5336_new_bootloader == BL_VERSION_LZ4 || is_5336_new_bootloader == BL_VERSION_Z7 ) 1979 | { 1980 | dw_lenth = dw_lenth - 8; 1981 | } 1982 | else if(is_5336_new_bootloader == BL_VERSION_GZF) dw_lenth = dw_lenth - 14; 1983 | packet_number = (dw_lenth) / FT_FW_PKT_LEN; 1984 | packet_buf[0] = 0xbf; 1985 | packet_buf[1] = 0x00; 1986 | for (j=0;j>8); 1990 | packet_buf[3] = (u8)temp; 1991 | lenght = FT_FW_PKT_LEN; 1992 | packet_buf[4] = (u8)(lenght>>8); 1993 | packet_buf[5] = (u8)lenght; 1994 | 1995 | for (i=0;i 0) 2006 | { 2007 | temp = packet_number * FT_FW_PKT_LEN; 2008 | packet_buf[2] = (u8)(temp>>8); 2009 | packet_buf[3] = (u8)temp; 2010 | 2011 | temp = (dw_lenth) % FT_FW_PKT_LEN; 2012 | packet_buf[4] = (u8)(temp>>8); 2013 | packet_buf[5] = (u8)temp; 2014 | 2015 | for (i=0;i>8); 2038 | packet_buf[3] = (u8)temp; 2039 | temp =1; 2040 | packet_buf[4] = (u8)(temp>>8); 2041 | packet_buf[5] = (u8)temp; 2042 | packet_buf[6] = pbt_buf[ dw_lenth + i]; 2043 | bt_ecc ^= packet_buf[6]; 2044 | ft5x06_i2c_write(client, packet_buf, 7); 2045 | msleep(10); 2046 | } 2047 | } 2048 | else if(is_5336_new_bootloader == BL_VERSION_GZF) 2049 | { 2050 | for (i = 0; i<12; i++) 2051 | { 2052 | if (is_5336_fwsize_30 /*&& DEVICE_IC_TYPE==IC_FT5x36*/) 2053 | { 2054 | temp = 0x7ff4 + i; 2055 | } 2056 | else if (1/*DEVICE_IC_TYPE==IC_FT5x36*/) 2057 | { 2058 | temp = 0x7bf4 + i; 2059 | } 2060 | packet_buf[2] = (u8)(temp>>8); 2061 | packet_buf[3] = (u8)temp; 2062 | temp =1; 2063 | packet_buf[4] = (u8)(temp>>8); 2064 | packet_buf[5] = (u8)temp; 2065 | packet_buf[6] = pbt_buf[ dw_lenth + i]; 2066 | bt_ecc ^= packet_buf[6]; 2067 | ft5x06_i2c_write(client, packet_buf, 7); 2068 | msleep(10); 2069 | } 2070 | } 2071 | 2072 | /*********Step 6: read out checksum***********************/ 2073 | /*send the opration head*/ 2074 | auc_i2c_write_buf[0] = 0xcc; 2075 | ft5x06_i2c_read(client, auc_i2c_write_buf, 1, reg_val, 1); 2076 | 2077 | if(reg_val[0] != bt_ecc) 2078 | { 2079 | dev_err(&client->dev, "[FTS]--ecc error! FW=%02x bt_ecc=%02x\n", reg_val[0], bt_ecc); 2080 | return -EIO; 2081 | } 2082 | 2083 | /*********Step 7: reset the new FW***********************/ 2084 | auc_i2c_write_buf[0] = 0x07; 2085 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); 2086 | msleep(300); /*make sure CTP startup normally*/ 2087 | 2088 | return 0; 2089 | } 2090 | 2091 | int fts_5x06_ctpm_fw_upgrade(struct i2c_client *client, u8 *pbt_buf, u32 dw_lenth) 2092 | { 2093 | u8 reg_val[2] = {0}; 2094 | u32 i = 0; 2095 | u32 packet_number; 2096 | u32 j; 2097 | u32 temp; 2098 | u32 lenght; 2099 | u8 packet_buf[FT_FW_PKT_LEN + 6]; 2100 | u8 auc_i2c_write_buf[10]; 2101 | u8 bt_ecc; 2102 | int i_ret; 2103 | 2104 | for (i = 0; i < FT_UPGRADE_LOOP; i++) { 2105 | /*********Step 1:Reset CTPM *****/ 2106 | /*write 0xaa to register 0xfc */ 2107 | ft5x0x_write_reg(client, 0xfc, FT_UPGRADE_AA); 2108 | msleep(fts_updateinfo_curr.delay_aa); 2109 | 2110 | /*write 0x55 to register 0xfc */ 2111 | ft5x0x_write_reg(client, 0xfc, FT_UPGRADE_55); 2112 | msleep(fts_updateinfo_curr.delay_55); 2113 | /*********Step 2:Enter upgrade mode *****/ 2114 | auc_i2c_write_buf[0] = FT_UPGRADE_55; 2115 | auc_i2c_write_buf[1] = FT_UPGRADE_AA; 2116 | do { 2117 | i++; 2118 | i_ret = ft5x06_i2c_write(client, auc_i2c_write_buf, 2); 2119 | msleep(5); 2120 | } while (i_ret <= 0 && i < 5); 2121 | 2122 | 2123 | /*********Step 3:check READ-ID***********************/ 2124 | msleep(fts_updateinfo_curr.delay_readid); 2125 | auc_i2c_write_buf[0] = 0x90; 2126 | auc_i2c_write_buf[1] = auc_i2c_write_buf[2] = auc_i2c_write_buf[3] = 2127 | 0x00; 2128 | ft5x06_i2c_read(client, auc_i2c_write_buf, 4, reg_val, 2); 2129 | 2130 | 2131 | if (reg_val[0] == fts_updateinfo_curr.upgrade_id_1 2132 | && reg_val[1] == fts_updateinfo_curr.upgrade_id_2) { 2133 | DBG("[FTS] Step 3: CTPM ID OK,ID1 = 0x%x,ID2 = 0x%x\n", 2134 | reg_val[0], reg_val[1]); 2135 | break; 2136 | } else { 2137 | dev_err(&client->dev, "[FTS] Step 3: CTPM ID FAIL,ID1 = 0x%x,ID2 = 0x%x\n", 2138 | reg_val[0], reg_val[1]); 2139 | } 2140 | } 2141 | if (i >= FT_UPGRADE_LOOP) 2142 | return -EIO; 2143 | /*Step 4:erase app and panel paramenter area*/ 2144 | DBG("Step 4:erase app and panel paramenter area\n"); 2145 | auc_i2c_write_buf[0] = 0x61; 2146 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); /*erase app area */ 2147 | msleep(fts_updateinfo_curr.delay_earse_flash); 2148 | /*erase panel parameter area */ 2149 | auc_i2c_write_buf[0] = 0x63; 2150 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); 2151 | msleep(100); 2152 | 2153 | /*********Step 5:write firmware(FW) to ctpm flash*********/ 2154 | bt_ecc = 0; 2155 | DBG("Step 5:write firmware(FW) to ctpm flash\n"); 2156 | 2157 | dw_lenth = dw_lenth - 8; 2158 | packet_number = (dw_lenth) / FT_FW_PKT_LEN; 2159 | packet_buf[0] = 0xbf; 2160 | packet_buf[1] = 0x00; 2161 | 2162 | for (j = 0; j < packet_number; j++) { 2163 | temp = j * FT_FW_PKT_LEN; 2164 | packet_buf[2] = (u8) (temp >> 8); 2165 | packet_buf[3] = (u8) temp; 2166 | lenght = FT_FW_PKT_LEN; 2167 | packet_buf[4] = (u8) (lenght >> 8); 2168 | packet_buf[5] = (u8) lenght; 2169 | 2170 | for (i = 0; i < FT_FW_PKT_LEN; i++) { 2171 | packet_buf[6 + i] = pbt_buf[j * FT_FW_PKT_LEN + i]; 2172 | bt_ecc ^= packet_buf[6 + i]; 2173 | } 2174 | 2175 | ft5x06_i2c_write(client, packet_buf, FT_FW_PKT_LEN + 6); 2176 | msleep(FT_FW_PKT_LEN / 6 + 1); 2177 | } 2178 | 2179 | if ((dw_lenth) % FT_FW_PKT_LEN > 0) { 2180 | temp = packet_number * FT_FW_PKT_LEN; 2181 | packet_buf[2] = (u8) (temp >> 8); 2182 | packet_buf[3] = (u8) temp; 2183 | temp = (dw_lenth) % FT_FW_PKT_LEN; 2184 | packet_buf[4] = (u8) (temp >> 8); 2185 | packet_buf[5] = (u8) temp; 2186 | 2187 | for (i = 0; i < temp; i++) { 2188 | packet_buf[6 + i] = pbt_buf[packet_number * FT_FW_PKT_LEN + i]; 2189 | bt_ecc ^= packet_buf[6 + i]; 2190 | } 2191 | 2192 | ft5x06_i2c_write(client, packet_buf, temp + 6); 2193 | msleep(20); 2194 | } 2195 | 2196 | 2197 | /*send the last six byte */ 2198 | for (i = 0; i < 6; i++) { 2199 | temp = 0x6ffa + i; 2200 | packet_buf[2] = (u8) (temp >> 8); 2201 | packet_buf[3] = (u8) temp; 2202 | temp = 1; 2203 | packet_buf[4] = (u8) (temp >> 8); 2204 | packet_buf[5] = (u8) temp; 2205 | packet_buf[6] = pbt_buf[dw_lenth + i]; 2206 | bt_ecc ^= packet_buf[6]; 2207 | ft5x06_i2c_write(client, packet_buf, 7); 2208 | msleep(20); 2209 | } 2210 | 2211 | 2212 | /*********Step 6: read out checksum***********************/ 2213 | /*send the opration head */ 2214 | DBG("Step 6: read out checksum\n"); 2215 | auc_i2c_write_buf[0] = 0xcc; 2216 | ft5x06_i2c_read(client, auc_i2c_write_buf, 1, reg_val, 1); 2217 | if (reg_val[0] != bt_ecc) { 2218 | dev_err(&client->dev, "[FTS]--ecc error! FW=%02x bt_ecc=%02x\n", 2219 | reg_val[0], 2220 | bt_ecc); 2221 | return -EIO; 2222 | } 2223 | 2224 | /*********Step 7: reset the new FW***********************/ 2225 | DBG("Step 7: reset the new FW\n"); 2226 | auc_i2c_write_buf[0] = 0x07; 2227 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); 2228 | msleep(300); /*make sure CTP startup normally */ 2229 | return 0; 2230 | } 2231 | 2232 | int hid_to_i2c(struct i2c_client * client) 2233 | { 2234 | u8 auc_i2c_write_buf[5] = {0}; 2235 | int bRet = 0; 2236 | 2237 | auc_i2c_write_buf[0] = 0xeb; 2238 | auc_i2c_write_buf[1] = 0xaa; 2239 | auc_i2c_write_buf[2] = 0x09; 2240 | 2241 | ft5x06_i2c_write(client, auc_i2c_write_buf, 3); 2242 | 2243 | msleep(10); 2244 | 2245 | auc_i2c_write_buf[0] = auc_i2c_write_buf[1] = auc_i2c_write_buf[2] = 0; 2246 | 2247 | ft5x06_i2c_read(client, auc_i2c_write_buf, 0, auc_i2c_write_buf, 3); 2248 | 2249 | if(0xeb==auc_i2c_write_buf[0] && 0xaa==auc_i2c_write_buf[1] && 0x08==auc_i2c_write_buf[2]) 2250 | { 2251 | bRet = 1; 2252 | } 2253 | else bRet = 0; 2254 | 2255 | return bRet; 2256 | 2257 | } 2258 | 2259 | int fts_5x46_ctpm_fw_upgrade(struct i2c_client * client, u8* pbt_buf, u32 dw_lenth) 2260 | { 2261 | 2262 | u8 reg_val[4] = {0}; 2263 | u32 i = 0; 2264 | u32 packet_number; 2265 | u32 j; 2266 | u32 temp; 2267 | u32 lenght; 2268 | u8 packet_buf[FT_FW_PKT_LEN + 6]; 2269 | u8 auc_i2c_write_buf[10]; 2270 | u8 bt_ecc; 2271 | int i_ret; 2272 | 2273 | i_ret = hid_to_i2c(client); 2274 | 2275 | if(i_ret == 0) 2276 | { 2277 | DBG("[FTS] hid change to i2c fail ! \n"); 2278 | } 2279 | 2280 | for (i = 0; i < FT_UPGRADE_LOOP; i++) { 2281 | /*********Step 1:Reset CTPM *****/ 2282 | /*write 0xaa to register 0xfc */ 2283 | ft5x0x_write_reg(client, 0xfc, FT_UPGRADE_AA); 2284 | msleep(fts_updateinfo_curr.delay_aa); 2285 | 2286 | //write 0x55 to register 0xfc 2287 | ft5x0x_write_reg(client, 0xfc, FT_UPGRADE_55); 2288 | msleep(200); 2289 | /*********Step 2:Enter upgrade mode *****/ 2290 | i_ret = hid_to_i2c(client); 2291 | 2292 | if(i_ret == 0) 2293 | { 2294 | DBG("[FTS] hid change to i2c fail ! \n"); 2295 | } 2296 | msleep(10); 2297 | auc_i2c_write_buf[0] = FT_UPGRADE_55; 2298 | auc_i2c_write_buf[1] = FT_UPGRADE_AA; 2299 | i_ret = ft5x06_i2c_write(client, auc_i2c_write_buf, 2); 2300 | if(i_ret < 0) 2301 | { 2302 | DBG("[FTS] failed writing 0x55 and 0xaa ! \n"); 2303 | continue; 2304 | } 2305 | 2306 | /*********Step 3:check READ-ID***********************/ 2307 | msleep(1); 2308 | auc_i2c_write_buf[0] = 0x90; 2309 | auc_i2c_write_buf[1] = auc_i2c_write_buf[2] = auc_i2c_write_buf[3] = 2310 | 0x00; 2311 | 2312 | reg_val[0] = reg_val[1] = 0x00; 2313 | 2314 | ft5x06_i2c_read(client, auc_i2c_write_buf, 4, reg_val, 2); 2315 | 2316 | if (reg_val[0] == fts_updateinfo_curr.upgrade_id_1 2317 | && reg_val[1] == fts_updateinfo_curr.upgrade_id_2) { 2318 | DBG("[FTS] Step 3: READ OK CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n", 2319 | reg_val[0], reg_val[1]); 2320 | break; 2321 | } else { 2322 | dev_err(&client->dev, "[FTS] Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n", 2323 | reg_val[0], reg_val[1]); 2324 | 2325 | continue; 2326 | } 2327 | } 2328 | if (i >= FT_UPGRADE_LOOP ) 2329 | return -EIO; 2330 | 2331 | /*Step 4:erase app and panel paramenter area*/ 2332 | DBG("Step 4:erase app and panel paramenter area\n"); 2333 | auc_i2c_write_buf[0] = 0x61; 2334 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); //erase app area 2335 | msleep(1350); 2336 | 2337 | for(i = 0;i < 15;i++) 2338 | { 2339 | auc_i2c_write_buf[0] = 0x6a; 2340 | reg_val[0] = reg_val[1] = 0x00; 2341 | ft5x06_i2c_read(client, auc_i2c_write_buf, 1, reg_val, 2); 2342 | 2343 | if(0xF0==reg_val[0] && 0xAA==reg_val[1]) 2344 | { 2345 | break; 2346 | } 2347 | msleep(50); 2348 | 2349 | } 2350 | 2351 | auc_i2c_write_buf[0] = 0xB0; 2352 | auc_i2c_write_buf[1] = (u8) ((dw_lenth >> 16) & 0xFF); 2353 | auc_i2c_write_buf[2] = (u8) ((dw_lenth >> 8) & 0xFF); 2354 | auc_i2c_write_buf[3] = (u8) (dw_lenth & 0xFF); 2355 | 2356 | ft5x06_i2c_write(client, auc_i2c_write_buf, 4); 2357 | 2358 | /*********Step 5:write firmware(FW) to ctpm flash*********/ 2359 | bt_ecc = 0; 2360 | DBG("Step 5:write firmware(FW) to ctpm flash\n"); 2361 | temp = 0; 2362 | packet_number = (dw_lenth) / FT_FW_PKT_LEN; 2363 | packet_buf[0] = 0xbf; 2364 | packet_buf[1] = 0x00; 2365 | 2366 | for (j = 0; j < packet_number; j++) { 2367 | temp = j * FT_FW_PKT_LEN; 2368 | packet_buf[2] = (u8) (temp >> 8); 2369 | packet_buf[3] = (u8) temp; 2370 | lenght = FT_FW_PKT_LEN; 2371 | packet_buf[4] = (u8) (lenght >> 8); 2372 | packet_buf[5] = (u8) lenght; 2373 | 2374 | for (i = 0; i < FT_FW_PKT_LEN; i++) { 2375 | packet_buf[6 + i] = pbt_buf[j * FT_FW_PKT_LEN + i]; 2376 | bt_ecc ^= packet_buf[6 + i]; 2377 | } 2378 | ft5x06_i2c_write(client, packet_buf, FT_FW_PKT_LEN + 6); 2379 | 2380 | for(i = 0;i < 30;i++) 2381 | { 2382 | auc_i2c_write_buf[0] = 0x6a; 2383 | reg_val[0] = reg_val[1] = 0x00; 2384 | ft5x06_i2c_read(client, auc_i2c_write_buf, 1, reg_val, 2); 2385 | 2386 | if ((j + 0x1000) == (((reg_val[0]) << 8) | reg_val[1])) 2387 | { 2388 | break; 2389 | } 2390 | msleep(1); 2391 | 2392 | } 2393 | } 2394 | 2395 | if ((dw_lenth) % FT_FW_PKT_LEN > 0) { 2396 | temp = packet_number * FT_FW_PKT_LEN; 2397 | packet_buf[2] = (u8) (temp >> 8); 2398 | packet_buf[3] = (u8) temp; 2399 | temp = (dw_lenth) % FT_FW_PKT_LEN; 2400 | packet_buf[4] = (u8) (temp >> 8); 2401 | packet_buf[5] = (u8) temp; 2402 | 2403 | for (i = 0; i < temp; i++) { 2404 | packet_buf[6 + i] = pbt_buf[packet_number * FT_FW_PKT_LEN + i]; 2405 | bt_ecc ^= packet_buf[6 + i]; 2406 | } 2407 | ft5x06_i2c_write(client, packet_buf, temp + 6); 2408 | 2409 | for(i = 0;i < 30;i++) 2410 | { 2411 | auc_i2c_write_buf[0] = 0x6a; 2412 | reg_val[0] = reg_val[1] = 0x00; 2413 | ft5x06_i2c_read(client, auc_i2c_write_buf, 1, reg_val, 2); 2414 | 2415 | if ((j + 0x1000) == (((reg_val[0]) << 8) | reg_val[1])) 2416 | { 2417 | break; 2418 | } 2419 | msleep(1); 2420 | 2421 | } 2422 | } 2423 | 2424 | msleep(50); 2425 | 2426 | /*********Step 6: read out checksum***********************/ 2427 | /*send the opration head */ 2428 | DBG("Step 6: read out checksum\n"); 2429 | auc_i2c_write_buf[0] = 0x64; 2430 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); 2431 | msleep(300); 2432 | 2433 | temp = 0; 2434 | auc_i2c_write_buf[0] = 0x65; 2435 | auc_i2c_write_buf[1] = (u8)(temp >> 16); 2436 | auc_i2c_write_buf[2] = (u8)(temp >> 8); 2437 | auc_i2c_write_buf[3] = (u8)(temp); 2438 | temp = dw_lenth; 2439 | auc_i2c_write_buf[4] = (u8)(temp >> 8); 2440 | auc_i2c_write_buf[5] = (u8)(temp); 2441 | i_ret = ft5x06_i2c_write(client, auc_i2c_write_buf, 6); 2442 | msleep(dw_lenth/256); 2443 | 2444 | for(i = 0;i < 100;i++) 2445 | { 2446 | auc_i2c_write_buf[0] = 0x6a; 2447 | reg_val[0] = reg_val[1] = 0x00; 2448 | ft5x06_i2c_read(client, auc_i2c_write_buf, 1, reg_val, 2); 2449 | 2450 | if (0xF0==reg_val[0] && 0x55==reg_val[1]) 2451 | { 2452 | break; 2453 | } 2454 | msleep(1); 2455 | 2456 | } 2457 | auc_i2c_write_buf[0] = 0x66; 2458 | ft5x06_i2c_read(client, auc_i2c_write_buf, 1, reg_val, 1); 2459 | if (reg_val[0] != bt_ecc) 2460 | { 2461 | dev_err(&client->dev, "[FTS]--ecc error! FW=%02x bt_ecc=%02x\n", 2462 | reg_val[0], 2463 | bt_ecc); 2464 | 2465 | return -EIO; 2466 | } 2467 | printk(KERN_WARNING "checksum %X %X \n",reg_val[0],bt_ecc); 2468 | /*********Step 7: reset the new FW***********************/ 2469 | DBG("Step 7: reset the new FW\n"); 2470 | auc_i2c_write_buf[0] = 0x07; 2471 | ft5x06_i2c_write(client, auc_i2c_write_buf, 1); 2472 | msleep(130); //make sure CTP startup normally 2473 | 2474 | return 0; 2475 | } 2476 | 2477 | /*create apk debug channel*/ 2478 | #define PROC_UPGRADE 0 2479 | #define PROC_READ_REGISTER 1 2480 | #define PROC_WRITE_REGISTER 2 2481 | #define PROC_AUTOCLB 4 2482 | #define PROC_UPGRADE_INFO 5 2483 | #define PROC_WRITE_DATA 6 2484 | #define PROC_READ_DATA 7 2485 | 2486 | 2487 | #define PROC_NAME "ft5x0x-debug" 2488 | static unsigned char proc_operate_mode = PROC_UPGRADE; 2489 | static struct proc_dir_entry *fts_proc_entry; 2490 | /*interface of write proc*/ 2491 | static int fts_debug_write(struct file *filp, 2492 | const char __user *buff, unsigned long len, void *data) 2493 | { 2494 | struct i2c_client *client = (struct i2c_client *)fts_proc_entry->data; 2495 | unsigned char writebuf[2 * 1024]; 2496 | int buflen = len; 2497 | int writelen = 0; 2498 | int ret = 0; 2499 | 2500 | if (copy_from_user(&writebuf, buff, buflen)) { 2501 | dev_err(&client->dev, "%s:copy from user error\n", __func__); 2502 | return -EFAULT; 2503 | } 2504 | proc_operate_mode = writebuf[0]; 2505 | 2506 | switch (proc_operate_mode) { 2507 | case PROC_UPGRADE: 2508 | { 2509 | char upgrade_file_path[128]; 2510 | memset(upgrade_file_path, 0, sizeof(upgrade_file_path)); 2511 | sprintf(upgrade_file_path, "%s", writebuf + 1); 2512 | upgrade_file_path[buflen-1] = '\0'; 2513 | DBG("%s\n", upgrade_file_path); 2514 | disable_irq(client->irq); 2515 | 2516 | ret = fts_ctpm_fw_upgrade_with_app_file(client, upgrade_file_path); 2517 | 2518 | enable_irq(client->irq); 2519 | if (ret < 0) { 2520 | dev_err(&client->dev, "%s:upgrade failed.\n", __func__); 2521 | return ret; 2522 | } 2523 | } 2524 | break; 2525 | case PROC_READ_REGISTER: 2526 | writelen = 1; 2527 | ret = ft5x06_i2c_write(client, writebuf + 1, writelen); 2528 | if (ret < 0) { 2529 | dev_err(&client->dev, "%s:write iic error\n", __func__); 2530 | return ret; 2531 | } 2532 | break; 2533 | case PROC_WRITE_REGISTER: 2534 | writelen = 2; 2535 | ret = ft5x06_i2c_write(client, writebuf + 1, writelen); 2536 | if (ret < 0) { 2537 | dev_err(&client->dev, "%s:write iic error\n", __func__); 2538 | return ret; 2539 | } 2540 | break; 2541 | case PROC_AUTOCLB: 2542 | DBG("%s: autoclb\n", __func__); 2543 | ft5x06_auto_cal(client); 2544 | break; 2545 | case PROC_READ_DATA: 2546 | case PROC_WRITE_DATA: 2547 | writelen = len - 1; 2548 | ret = ft5x06_i2c_write(client, writebuf + 1, writelen); 2549 | if (ret < 0) { 2550 | dev_err(&client->dev, "%s:write iic error\n", __func__); 2551 | return ret; 2552 | } 2553 | break; 2554 | default: 2555 | break; 2556 | } 2557 | 2558 | 2559 | return len; 2560 | } 2561 | 2562 | /*interface of read proc*/ 2563 | static int fts_debug_read( char *page, char **start, 2564 | off_t off, int count, int *eof, void *data ) 2565 | { 2566 | struct i2c_client *client = (struct i2c_client *)fts_proc_entry->data; 2567 | int ret = 0; 2568 | unsigned char buf[PAGE_SIZE]; 2569 | int num_read_chars = 0; 2570 | int readlen = 0; 2571 | u8 regvalue = 0x00, regaddr = 0x00; 2572 | 2573 | switch (proc_operate_mode) { 2574 | case PROC_UPGRADE: 2575 | /*after calling ft5x0x_debug_write to upgrade*/ 2576 | regaddr = 0xA6; 2577 | ret = ft5x0x_read_reg(client, regaddr, ®value); 2578 | if (ret < 0) 2579 | num_read_chars = sprintf(buf, "%s", "get fw version failed.\n"); 2580 | else 2581 | num_read_chars = sprintf(buf, "current fw version:0x%02x\n", regvalue); 2582 | break; 2583 | case PROC_READ_REGISTER: 2584 | readlen = 1; 2585 | ret = ft5x06_i2c_read(client, NULL, 0, buf, readlen); 2586 | if (ret < 0) { 2587 | dev_err(&client->dev, "%s:read iic error\n", __func__); 2588 | return ret; 2589 | } 2590 | num_read_chars = 1; 2591 | break; 2592 | case PROC_READ_DATA: 2593 | readlen = count; 2594 | ret = ft5x06_i2c_read(client, NULL, 0, buf, readlen); 2595 | if (ret < 0) { 2596 | dev_err(&client->dev, "%s:read iic error\n", __func__); 2597 | return ret; 2598 | } 2599 | 2600 | num_read_chars = readlen; 2601 | break; 2602 | case PROC_WRITE_DATA: 2603 | break; 2604 | default: 2605 | break; 2606 | } 2607 | 2608 | memcpy(page, buf, num_read_chars); 2609 | return num_read_chars; 2610 | } 2611 | int fts_create_apk_debug_channel(struct i2c_client * client) 2612 | { 2613 | fts_proc_entry = create_proc_entry(PROC_NAME, 0777, NULL); 2614 | if (NULL == fts_proc_entry) { 2615 | dev_err(&client->dev, "Couldn't create proc entry!\n"); 2616 | return -ENOMEM; 2617 | } else { 2618 | dev_info(&client->dev, "Create proc entry success!\n"); 2619 | fts_proc_entry->data = client; 2620 | fts_proc_entry->write_proc = fts_debug_write; 2621 | fts_proc_entry->read_proc = fts_debug_read; 2622 | } 2623 | return 0; 2624 | } 2625 | 2626 | void fts_release_apk_debug_channel(void) 2627 | { 2628 | if (fts_proc_entry) 2629 | remove_proc_entry(PROC_NAME, NULL); 2630 | } 2631 | 2632 | static int ft5x06_auto_cal(struct i2c_client *client) 2633 | { 2634 | struct ft5x06_ts_data *data = i2c_get_clientdata(client); 2635 | u8 temp = 0, i; 2636 | 2637 | /* set to factory mode */ 2638 | msleep(2 * data->pdata->soft_rst_dly); 2639 | ft5x0x_write_reg(client, FT_REG_DEV_MODE, FT_FACTORYMODE_VALUE); 2640 | msleep(data->pdata->soft_rst_dly); 2641 | 2642 | /* start calibration */ 2643 | ft5x0x_write_reg(client, FT_DEV_MODE_REG_CAL, FT_CAL_START); 2644 | msleep(2 * data->pdata->soft_rst_dly); 2645 | for (i = 0; i < FT_CAL_RETRY; i++) { 2646 | ft5x0x_read_reg(client, FT_REG_CAL, &temp); 2647 | /*return to normal mode, calibration finish */ 2648 | if (((temp & FT_CAL_MASK) >> FT_4BIT_SHIFT) == FT_CAL_FIN) 2649 | break; 2650 | } 2651 | 2652 | /*calibration OK */ 2653 | msleep(2 * data->pdata->soft_rst_dly); 2654 | ft5x0x_write_reg(client, FT_REG_DEV_MODE, FT_FACTORYMODE_VALUE); 2655 | msleep(data->pdata->soft_rst_dly); 2656 | 2657 | /* store calibration data */ 2658 | ft5x0x_write_reg(client, FT_DEV_MODE_REG_CAL, FT_CAL_STORE); 2659 | msleep(2 * data->pdata->soft_rst_dly); 2660 | 2661 | /* set to normal mode */ 2662 | ft5x0x_write_reg(client, FT_REG_DEV_MODE, FT_WORKMODE_VALUE); 2663 | msleep(2 * data->pdata->soft_rst_dly); 2664 | 2665 | return 0; 2666 | } 2667 | 2668 | static int ft5x06_fw_upgrade_start(struct i2c_client *client, 2669 | const u8 *data, u32 data_len) 2670 | { 2671 | struct ft5x06_ts_data *ts_data = i2c_get_clientdata(client); 2672 | struct fw_upgrade_info info = ts_data->pdata->info; 2673 | u8 reset_reg; 2674 | u8 w_buf[FT_MAX_WR_BUF] = {0}, r_buf[FT_MAX_RD_BUF] = {0}; 2675 | u8 pkt_buf[FT_FW_PKT_LEN + FT_FW_PKT_META_LEN]; 2676 | int i, j, temp; 2677 | u32 pkt_num, pkt_len; 2678 | u8 is_5336_new_bootloader = false; 2679 | u8 is_5336_fwsize_30 = false; 2680 | u8 fw_ecc; 2681 | 2682 | /* determine firmware size */ 2683 | if (*(data + data_len - FT_BLOADER_SIZE_OFF) == FT_BLOADER_NEW_SIZE) 2684 | is_5336_fwsize_30 = true; 2685 | else 2686 | is_5336_fwsize_30 = false; 2687 | 2688 | for (i = 0, j = 0; i < FT_UPGRADE_LOOP; i++) { 2689 | msleep(FT_EARSE_DLY_MS); 2690 | /* reset - write 0xaa and 0x55 to reset register */ 2691 | if (ts_data->family_id == FT6X06_ID 2692 | || ts_data->family_id == FT6X36_ID) 2693 | reset_reg = FT_RST_CMD_REG2; 2694 | else 2695 | reset_reg = FT_RST_CMD_REG1; 2696 | 2697 | ft5x0x_write_reg(client, reset_reg, FT_UPGRADE_AA); 2698 | msleep(info.delay_aa); 2699 | 2700 | ft5x0x_write_reg(client, reset_reg, FT_UPGRADE_55); 2701 | if (i <= (FT_UPGRADE_LOOP / 2)) 2702 | msleep(info.delay_55 + i * 3); 2703 | else 2704 | msleep(info.delay_55 - (i - (FT_UPGRADE_LOOP / 2)) * 2); 2705 | 2706 | /* Enter upgrade mode */ 2707 | w_buf[0] = FT_UPGRADE_55; 2708 | ft5x06_i2c_write(client, w_buf, 1); 2709 | usleep(FT_55_AA_DLY_NS); 2710 | w_buf[0] = FT_UPGRADE_AA; 2711 | ft5x06_i2c_write(client, w_buf, 1); 2712 | 2713 | /* check READ_ID */ 2714 | msleep(info.delay_readid); 2715 | w_buf[0] = FT_READ_ID_REG; 2716 | w_buf[1] = 0x00; 2717 | w_buf[2] = 0x00; 2718 | w_buf[3] = 0x00; 2719 | 2720 | ft5x06_i2c_read(client, w_buf, 4, r_buf, 2); 2721 | 2722 | if (r_buf[0] != info.upgrade_id_1 2723 | || r_buf[1] != info.upgrade_id_2) { 2724 | dev_err(&client->dev, "Upgrade ID mismatch(%d), IC=0x%x 0x%x, info=0x%x 0x%x\n", 2725 | i, r_buf[0], r_buf[1], 2726 | info.upgrade_id_1, info.upgrade_id_2); 2727 | } else 2728 | break; 2729 | } 2730 | 2731 | if (i >= FT_UPGRADE_LOOP) { 2732 | dev_err(&client->dev, "Abort upgrade\n"); 2733 | return -EIO; 2734 | } 2735 | 2736 | w_buf[0] = 0xcd; 2737 | ft5x06_i2c_read(client, w_buf, 1, r_buf, 1); 2738 | 2739 | if (r_buf[0] <= 4) 2740 | is_5336_new_bootloader = FT_BLOADER_VERSION_LZ4; 2741 | else if (r_buf[0] == 7) 2742 | is_5336_new_bootloader = FT_BLOADER_VERSION_Z7; 2743 | else if (r_buf[0] >= 0x0f && 2744 | ((ts_data->family_id == FT_FT5336_FAMILY_ID_0x11) || 2745 | (ts_data->family_id == FT_FT5336_FAMILY_ID_0x12) || 2746 | (ts_data->family_id == FT_FT5336_FAMILY_ID_0x13) || 2747 | (ts_data->family_id == FT_FT5336_FAMILY_ID_0x14))) 2748 | is_5336_new_bootloader = FT_BLOADER_VERSION_GZF; 2749 | else 2750 | is_5336_new_bootloader = FT_BLOADER_VERSION_LZ4; 2751 | 2752 | dev_dbg(&client->dev, "bootloader type=%d, r_buf=0x%x, family_id=0x%x\n", 2753 | is_5336_new_bootloader, r_buf[0], ts_data->family_id); 2754 | /* is_5336_new_bootloader = FT_BLOADER_VERSION_GZF; */ 2755 | 2756 | /* erase app and panel paramenter area */ 2757 | w_buf[0] = FT_ERASE_APP_REG; 2758 | ft5x06_i2c_write(client, w_buf, 1); 2759 | msleep(info.delay_erase_flash); 2760 | 2761 | if (is_5336_fwsize_30) { 2762 | w_buf[0] = FT_ERASE_PANEL_REG; 2763 | ft5x06_i2c_write(client, w_buf, 1); 2764 | } 2765 | msleep(FT_EARSE_DLY_MS); 2766 | 2767 | /* program firmware */ 2768 | if (is_5336_new_bootloader == FT_BLOADER_VERSION_LZ4 2769 | || is_5336_new_bootloader == FT_BLOADER_VERSION_Z7) 2770 | data_len = data_len - FT_DATA_LEN_OFF_OLD_FW; 2771 | else 2772 | data_len = data_len - FT_DATA_LEN_OFF_NEW_FW; 2773 | 2774 | pkt_num = (data_len) / FT_FW_PKT_LEN; 2775 | pkt_len = FT_FW_PKT_LEN; 2776 | pkt_buf[0] = FT_FW_START_REG; 2777 | pkt_buf[1] = 0x00; 2778 | fw_ecc = 0; 2779 | 2780 | for (i = 0; i < pkt_num; i++) { 2781 | temp = i * FT_FW_PKT_LEN; 2782 | pkt_buf[2] = (u8) (temp >> FT_8BIT_SHIFT); 2783 | pkt_buf[3] = (u8) temp; 2784 | pkt_buf[4] = (u8) (pkt_len >> FT_8BIT_SHIFT); 2785 | pkt_buf[5] = (u8) pkt_len; 2786 | 2787 | for (j = 0; j < FT_FW_PKT_LEN; j++) { 2788 | pkt_buf[6 + j] = data[i * FT_FW_PKT_LEN + j]; 2789 | fw_ecc ^= pkt_buf[6 + j]; 2790 | } 2791 | 2792 | ft5x06_i2c_write(client, pkt_buf, 2793 | FT_FW_PKT_LEN + FT_FW_PKT_META_LEN); 2794 | msleep(FT_FW_PKT_DLY_MS); 2795 | } 2796 | 2797 | /* send remaining bytes */ 2798 | if ((data_len) % FT_FW_PKT_LEN > 0) { 2799 | temp = pkt_num * FT_FW_PKT_LEN; 2800 | pkt_buf[2] = (u8) (temp >> FT_8BIT_SHIFT); 2801 | pkt_buf[3] = (u8) temp; 2802 | temp = (data_len) % FT_FW_PKT_LEN; 2803 | pkt_buf[4] = (u8) (temp >> FT_8BIT_SHIFT); 2804 | pkt_buf[5] = (u8) temp; 2805 | 2806 | for (i = 0; i < temp; i++) { 2807 | pkt_buf[6 + i] = data[pkt_num * FT_FW_PKT_LEN + i]; 2808 | fw_ecc ^= pkt_buf[6 + i]; 2809 | } 2810 | 2811 | ft5x06_i2c_write(client, pkt_buf, temp + FT_FW_PKT_META_LEN); 2812 | msleep(FT_FW_PKT_DLY_MS); 2813 | } 2814 | 2815 | /* send the finishing packet */ 2816 | if (is_5336_new_bootloader == FT_BLOADER_VERSION_LZ4 || 2817 | is_5336_new_bootloader == FT_BLOADER_VERSION_Z7) { 2818 | for (i = 0; i < FT_FINISHING_PKT_LEN_OLD_FW; i++) { 2819 | if (is_5336_new_bootloader == FT_BLOADER_VERSION_Z7) 2820 | temp = FT_MAGIC_BLOADER_Z7 + i; 2821 | else if (is_5336_new_bootloader == 2822 | FT_BLOADER_VERSION_LZ4) 2823 | temp = FT_MAGIC_BLOADER_LZ4 + i; 2824 | pkt_buf[2] = (u8)(temp >> 8); 2825 | pkt_buf[3] = (u8)temp; 2826 | temp = 1; 2827 | pkt_buf[4] = (u8)(temp >> 8); 2828 | pkt_buf[5] = (u8)temp; 2829 | pkt_buf[6] = data[data_len + i]; 2830 | fw_ecc ^= pkt_buf[6]; 2831 | 2832 | ft5x06_i2c_write(client, 2833 | pkt_buf, temp + FT_FW_PKT_META_LEN); 2834 | msleep(FT_FW_PKT_DLY_MS); 2835 | } 2836 | } else if (is_5336_new_bootloader == FT_BLOADER_VERSION_GZF) { 2837 | for (i = 0; i < FT_FINISHING_PKT_LEN_NEW_FW; i++) { 2838 | if (is_5336_fwsize_30) 2839 | temp = FT_MAGIC_BLOADER_GZF_30 + i; 2840 | else 2841 | temp = FT_MAGIC_BLOADER_GZF + i; 2842 | pkt_buf[2] = (u8)(temp >> 8); 2843 | pkt_buf[3] = (u8)temp; 2844 | temp = 1; 2845 | pkt_buf[4] = (u8)(temp >> 8); 2846 | pkt_buf[5] = (u8)temp; 2847 | pkt_buf[6] = data[data_len + i]; 2848 | fw_ecc ^= pkt_buf[6]; 2849 | 2850 | ft5x06_i2c_write(client, 2851 | pkt_buf, temp + FT_FW_PKT_META_LEN); 2852 | msleep(FT_FW_PKT_DLY_MS); 2853 | 2854 | } 2855 | } 2856 | 2857 | /* verify checksum */ 2858 | w_buf[0] = FT_REG_ECC; 2859 | ft5x06_i2c_read(client, w_buf, 1, r_buf, 1); 2860 | if (r_buf[0] != fw_ecc) { 2861 | dev_err(&client->dev, "ECC error! dev_ecc=%02x fw_ecc=%02x\n", 2862 | r_buf[0], fw_ecc); 2863 | return -EIO; 2864 | } 2865 | 2866 | /* reset */ 2867 | w_buf[0] = FT_REG_RESET_FW; 2868 | ft5x06_i2c_write(client, w_buf, 1); 2869 | msleep(ts_data->pdata->soft_rst_dly); 2870 | 2871 | dev_info(&client->dev, "Firmware upgrade successful\n"); 2872 | 2873 | return 0; 2874 | } 2875 | 2876 | static int ft5x06_fw_upgrade(struct device *dev, bool force) 2877 | { 2878 | struct ft5x06_ts_data *data = dev_get_drvdata(dev); 2879 | const struct firmware *pbt_buf = NULL; 2880 | u8 fw_file_maj, fw_file_min, fw_file_sub_min, fw_file_vendor_id; 2881 | bool fw_upgrade = false; 2882 | int i_ret; 2883 | int fw_len = 0; 2884 | 2885 | if (data->suspended) { 2886 | dev_err(dev, "Device is in suspend state: Exit FW upgrade\n"); 2887 | return -EBUSY; 2888 | } 2889 | 2890 | i_ret= request_firmware(&pbt_buf, data->fw_name, dev); 2891 | if (i_ret < 0) { 2892 | dev_err(dev, "Request firmware failed - %s (%d)\n", 2893 | data->fw_name, i_ret); 2894 | return i_ret; 2895 | } 2896 | 2897 | if (pbt_buf->size < FT_FW_MIN_SIZE || pbt_buf->size > FT_FW_MAX_SIZE) { 2898 | dev_err(dev, "Invalid firmware size (%zu)\n", pbt_buf->size); 2899 | rc = -EIO; 2900 | goto rel_fw; 2901 | } 2902 | 2903 | fw_len = pbt_buf->size; 2904 | 2905 | if ((fts_updateinfo_curr.CHIP_ID==0x11) ||(fts_updateinfo_curr.CHIP_ID==0x12) ||(fts_updateinfo_curr.CHIP_ID==0x13) ||(fts_updateinfo_curr.CHIP_ID==0x14) 2906 | ||(fts_updateinfo_curr.CHIP_ID==0x55) ||(fts_updateinfo_curr.CHIP_ID==0x06) ||(fts_updateinfo_curr.CHIP_ID==0x0a) ||(fts_updateinfo_curr.CHIP_ID==0x08)) 2907 | { 2908 | if (fw_len < 8 || fw_len > 32 * 1024) 2909 | { 2910 | dev_err(&client->dev, "%s:FW length error\n", __func__); 2911 | return -EIO; 2912 | } 2913 | 2914 | if ((CTPM_FW[fw_len - 8] ^ CTPM_FW[fw_len - 6]) == 0xFF 2915 | && (CTPM_FW[fw_len - 7] ^ CTPM_FW[fw_len - 5]) == 0xFF 2916 | && (CTPM_FW[fw_len - 3] ^ CTPM_FW[fw_len - 4]) == 0xFF) 2917 | { 2918 | /*FW upgrade */ 2919 | /*call the upgrade function */ 2920 | if ((fts_updateinfo_curr.CHIP_ID==0x55) ||(fts_updateinfo_curr.CHIP_ID==0x08) ||(fts_updateinfo_curr.CHIP_ID==0x0a)) 2921 | { 2922 | i_ret = fts_5x06_ctpm_fw_upgrade(client, pbt_buf->data, fw_len); 2923 | } 2924 | else if ((fts_updateinfo_curr.CHIP_ID==0x11) ||(fts_updateinfo_curr.CHIP_ID==0x12) ||(fts_updateinfo_curr.CHIP_ID==0x13) ||(fts_updateinfo_curr.CHIP_ID==0x14)) 2925 | { 2926 | i_ret = fts_5x36_ctpm_fw_upgrade(client, pbt_buf->data, fw_len); 2927 | } 2928 | else if ((fts_updateinfo_curr.CHIP_ID==0x06)) 2929 | { 2930 | i_ret = fts_6x06_ctpm_fw_upgrade(client, pbt_buf->data, fw_len); 2931 | } 2932 | if (i_ret != 0) 2933 | dev_err(&client->dev, "%s:upgrade failed. err.\n", 2934 | __func__); 2935 | else if(fts_updateinfo_curr.AUTO_CLB==AUTO_CLB_NEED) 2936 | { 2937 | fts_ctpm_auto_clb(client); 2938 | } 2939 | } 2940 | else 2941 | { 2942 | dev_err(&client->dev, "%s:FW format error\n", __func__); 2943 | return -EBADFD; 2944 | } 2945 | } 2946 | else if ((fts_updateinfo_curr.CHIP_ID==0x36)) 2947 | { 2948 | if (fw_len < 8 || fw_len > 32 * 1024) 2949 | { 2950 | dev_err(&client->dev, "%s:FW length error\n", __func__); 2951 | return -EIO; 2952 | } 2953 | i_ret = fts_6x36_ctpm_fw_upgrade(client, pbt_buf->data, fw_len); 2954 | if (i_ret != 0) 2955 | dev_err(&client->dev, "%s:upgrade failed. err.\n", 2956 | __func__); 2957 | } 2958 | else if ((fts_updateinfo_curr.CHIP_ID==0x54)) 2959 | { 2960 | if (fw_len < 8 || fw_len > 54 * 1024) 2961 | { 2962 | dev_err(&client->dev, "%s:FW length error\n", __func__); 2963 | return -EIO; 2964 | } 2965 | i_ret = fts_5x46_ctpm_fw_upgrade(client, pbt_buf->data, fw_len); 2966 | if (i_ret != 0) 2967 | dev_err(&client->dev, "%s:upgrade failed. err.\n", 2968 | __func__); 2969 | } 2970 | 2971 | /* 2972 | if (data->family_id == FT6X36_ID) { 2973 | fw_file_maj = FT_FW_FILE_MAJ_VER_FT6X36(fw); 2974 | fw_file_vendor_id = FT_FW_FILE_VENDOR_ID_FT6X36(fw); 2975 | } else { 2976 | fw_file_maj = FT_FW_FILE_MAJ_VER(fw); 2977 | fw_file_vendor_id = FT_FW_FILE_VENDOR_ID(fw); 2978 | } 2979 | fw_file_min = FT_FW_FILE_MIN_VER(fw); 2980 | fw_file_sub_min = FT_FW_FILE_SUB_MIN_VER(fw); 2981 | 2982 | dev_info(dev, "Current firmware: %d.%d.%d", data->fw_ver[0], 2983 | data->fw_ver[1], data->fw_ver[2]); 2984 | dev_info(dev, "New firmware: %d.%d.%d", fw_file_maj, 2985 | fw_file_min, fw_file_sub_min); 2986 | 2987 | if (force) 2988 | fw_upgrade = true; 2989 | else if ((data->fw_ver[0] < fw_file_maj) && 2990 | data->fw_vendor_id == fw_file_vendor_id) 2991 | fw_upgrade = true; 2992 | 2993 | if (!fw_upgrade) { 2994 | dev_info(dev, "Exiting fw upgrade...\n"); 2995 | rc = -EFAULT; 2996 | goto rel_fw; 2997 | } 2998 | 2999 | // start firmware upgrade 3000 | if (FT_FW_CHECK(fw, data)) { 3001 | rc = ft5x06_fw_upgrade_start(data->client, fw->data, fw->size); 3002 | if (rc < 0) 3003 | dev_err(dev, "update failed (%d). try later...\n", rc); 3004 | else if (data->pdata->info.auto_cal) 3005 | ft5x06_auto_cal(data->client); 3006 | } else { 3007 | dev_err(dev, "FW format error\n"); 3008 | rc = -EIO; 3009 | } 3010 | */ 3011 | 3012 | ft5x06_update_fw_ver(data); 3013 | 3014 | FT_STORE_TS_INFO(data->ts_info, data->family_id, data->pdata->name, 3015 | data->pdata->num_max_touches, data->pdata->group_id, 3016 | data->pdata->fw_vkey_support ? "yes" : "no", 3017 | data->pdata->fw_name, data->fw_ver[0], 3018 | data->fw_ver[1], data->fw_ver[2]); 3019 | rel_fw: 3020 | release_firmware(pbt_buf); 3021 | return i_ret; 3022 | } 3023 | 3024 | static ssize_t ft5x06_update_fw_show(struct device *dev, 3025 | struct device_attribute *attr, char *buf) 3026 | { 3027 | struct ft5x06_ts_data *data = dev_get_drvdata(dev); 3028 | return snprintf(buf, 2, "%d\n", data->loading_fw); 3029 | } 3030 | 3031 | static ssize_t ft5x06_update_fw_store(struct device *dev, 3032 | struct device_attribute *attr, 3033 | const char *buf, size_t size) 3034 | { 3035 | struct ft5x06_ts_data *data = dev_get_drvdata(dev); 3036 | unsigned long val; 3037 | int rc; 3038 | 3039 | if (size > 2) 3040 | return -EINVAL; 3041 | 3042 | rc = kstrtoul(buf, 10, &val); 3043 | if (rc != 0) 3044 | return rc; 3045 | 3046 | if (data->suspended) { 3047 | dev_info(dev, "In suspend state, try again later...\n"); 3048 | return size; 3049 | } 3050 | 3051 | mutex_lock(&data->input_dev->mutex); 3052 | if (!data->loading_fw && val) { 3053 | data->loading_fw = true; 3054 | ft5x06_fw_upgrade(dev, false); 3055 | data->loading_fw = false; 3056 | } 3057 | mutex_unlock(&data->input_dev->mutex); 3058 | 3059 | return size; 3060 | } 3061 | 3062 | static DEVICE_ATTR(update_fw, 0664, ft5x06_update_fw_show, 3063 | ft5x06_update_fw_store); 3064 | 3065 | static ssize_t ft5x06_force_update_fw_store(struct device *dev, 3066 | struct device_attribute *attr, 3067 | const char *buf, size_t size) 3068 | { 3069 | struct ft5x06_ts_data *data = dev_get_drvdata(dev); 3070 | unsigned long val; 3071 | int rc; 3072 | 3073 | if (size > 2) 3074 | return -EINVAL; 3075 | 3076 | rc = kstrtoul(buf, 10, &val); 3077 | if (rc != 0) 3078 | return rc; 3079 | 3080 | mutex_lock(&data->input_dev->mutex); 3081 | if (!data->loading_fw && val) { 3082 | data->loading_fw = true; 3083 | ft5x06_fw_upgrade(dev, true); 3084 | data->loading_fw = false; 3085 | } 3086 | mutex_unlock(&data->input_dev->mutex); 3087 | 3088 | return size; 3089 | } 3090 | 3091 | static DEVICE_ATTR(force_update_fw, 0664, ft5x06_update_fw_show, 3092 | ft5x06_force_update_fw_store); 3093 | 3094 | static ssize_t ft5x06_fw_name_show(struct device *dev, 3095 | struct device_attribute *attr, char *buf) 3096 | { 3097 | struct ft5x06_ts_data *data = dev_get_drvdata(dev); 3098 | return snprintf(buf, FT_FW_NAME_MAX_LEN - 1, "%s\n", data->fw_name); 3099 | } 3100 | 3101 | static ssize_t ft5x06_fw_name_store(struct device *dev, 3102 | struct device_attribute *attr, 3103 | const char *buf, size_t size) 3104 | { 3105 | struct ft5x06_ts_data *data = dev_get_drvdata(dev); 3106 | 3107 | if (size > FT_FW_NAME_MAX_LEN - 1) 3108 | return -EINVAL; 3109 | 3110 | strlcpy(data->fw_name, buf, size); 3111 | if (data->fw_name[size-1] == '\n') 3112 | data->fw_name[size-1] = 0; 3113 | 3114 | return size; 3115 | } 3116 | 3117 | static DEVICE_ATTR(fw_name, 0664, ft5x06_fw_name_show, ft5x06_fw_name_store); 3118 | 3119 | static bool ft5x06_debug_addr_is_valid(int addr) 3120 | { 3121 | if (addr < 0 || addr > 0xFF) { 3122 | pr_err("FT reg address is invalid: 0x%x\n", addr); 3123 | return false; 3124 | } 3125 | 3126 | return true; 3127 | } 3128 | 3129 | static int ft5x06_debug_data_set(void *_data, u64 val) 3130 | { 3131 | struct ft5x06_ts_data *data = _data; 3132 | 3133 | mutex_lock(&data->input_dev->mutex); 3134 | 3135 | if (ft5x06_debug_addr_is_valid(data->addr)) 3136 | dev_info(&data->client->dev, 3137 | "Writing into FT registers not supported\n"); 3138 | 3139 | mutex_unlock(&data->input_dev->mutex); 3140 | 3141 | return 0; 3142 | } 3143 | 3144 | static int ft5x06_debug_data_get(void *_data, u64 *val) 3145 | { 3146 | struct ft5x06_ts_data *data = _data; 3147 | int rc; 3148 | u8 reg; 3149 | 3150 | mutex_lock(&data->input_dev->mutex); 3151 | 3152 | if (ft5x06_debug_addr_is_valid(data->addr)) { 3153 | rc = ft5x0x_read_reg(data->client, data->addr, ®); 3154 | if (rc < 0) 3155 | dev_err(&data->client->dev, 3156 | "FT read register 0x%x failed (%d)\n", 3157 | data->addr, rc); 3158 | else 3159 | *val = reg; 3160 | } 3161 | 3162 | mutex_unlock(&data->input_dev->mutex); 3163 | 3164 | return 0; 3165 | } 3166 | 3167 | DEFINE_SIMPLE_ATTRIBUTE(debug_data_fops, ft5x06_debug_data_get, 3168 | ft5x06_debug_data_set, "0x%02llX\n"); 3169 | 3170 | static int ft5x06_debug_addr_set(void *_data, u64 val) 3171 | { 3172 | struct ft5x06_ts_data *data = _data; 3173 | 3174 | if (ft5x06_debug_addr_is_valid(val)) { 3175 | mutex_lock(&data->input_dev->mutex); 3176 | data->addr = val; 3177 | mutex_unlock(&data->input_dev->mutex); 3178 | } 3179 | 3180 | return 0; 3181 | } 3182 | 3183 | static int ft5x06_debug_addr_get(void *_data, u64 *val) 3184 | { 3185 | struct ft5x06_ts_data *data = _data; 3186 | 3187 | mutex_lock(&data->input_dev->mutex); 3188 | 3189 | if (ft5x06_debug_addr_is_valid(data->addr)) 3190 | *val = data->addr; 3191 | 3192 | mutex_unlock(&data->input_dev->mutex); 3193 | 3194 | return 0; 3195 | } 3196 | 3197 | DEFINE_SIMPLE_ATTRIBUTE(debug_addr_fops, ft5x06_debug_addr_get, 3198 | ft5x06_debug_addr_set, "0x%02llX\n"); 3199 | 3200 | static int ft5x06_debug_suspend_set(void *_data, u64 val) 3201 | { 3202 | struct ft5x06_ts_data *data = _data; 3203 | 3204 | mutex_lock(&data->input_dev->mutex); 3205 | 3206 | if (val) 3207 | ft5x06_ts_suspend(&data->client->dev); 3208 | else 3209 | ft5x06_ts_resume(&data->client->dev); 3210 | 3211 | mutex_unlock(&data->input_dev->mutex); 3212 | 3213 | return 0; 3214 | } 3215 | 3216 | static int ft5x06_debug_suspend_get(void *_data, u64 *val) 3217 | { 3218 | struct ft5x06_ts_data *data = _data; 3219 | 3220 | mutex_lock(&data->input_dev->mutex); 3221 | *val = data->suspended; 3222 | mutex_unlock(&data->input_dev->mutex); 3223 | 3224 | return 0; 3225 | } 3226 | 3227 | DEFINE_SIMPLE_ATTRIBUTE(debug_suspend_fops, ft5x06_debug_suspend_get, 3228 | ft5x06_debug_suspend_set, "%lld\n"); 3229 | 3230 | static int ft5x06_debug_dump_info(struct seq_file *m, void *v) 3231 | { 3232 | struct ft5x06_ts_data *data = m->private; 3233 | 3234 | seq_printf(m, "%s\n", data->ts_info); 3235 | 3236 | return 0; 3237 | } 3238 | 3239 | static int debugfs_dump_info_open(struct inode *inode, struct file *file) 3240 | { 3241 | return single_open(file, ft5x06_debug_dump_info, inode->i_private); 3242 | } 3243 | 3244 | static const struct file_operations debug_dump_info_fops = { 3245 | .owner = THIS_MODULE, 3246 | .open = debugfs_dump_info_open, 3247 | .read = seq_read, 3248 | .release = single_release, 3249 | }; 3250 | 3251 | #ifdef CONFIG_OF 3252 | static int ft5x06_get_dt_coords(struct device *dev, char *name, 3253 | struct ft5x06_ts_platform_data *pdata) 3254 | { 3255 | u32 coords[FT_COORDS_ARR_SIZE]; 3256 | struct property *prop; 3257 | struct device_node *np = dev->of_node; 3258 | int coords_size, rc; 3259 | 3260 | prop = of_find_property(np, name, NULL); 3261 | if (!prop) 3262 | return -EINVAL; 3263 | if (!prop->value) 3264 | return -ENODATA; 3265 | 3266 | coords_size = prop->length / sizeof(u32); 3267 | if (coords_size != FT_COORDS_ARR_SIZE) { 3268 | dev_err(dev, "invalid %s\n", name); 3269 | return -EINVAL; 3270 | } 3271 | 3272 | rc = of_property_read_u32_array(np, name, coords, coords_size); 3273 | if (rc && (rc != -EINVAL)) { 3274 | dev_err(dev, "Unable to read %s\n", name); 3275 | return rc; 3276 | } 3277 | 3278 | if (!strcmp(name, "focaltech,panel-coords")) { 3279 | pdata->panel_minx = coords[0]; 3280 | pdata->panel_miny = coords[1]; 3281 | pdata->panel_maxx = coords[2]; 3282 | pdata->panel_maxy = coords[3]; 3283 | } else if (!strcmp(name, "focaltech,display-coords")) { 3284 | pdata->x_min = coords[0]; 3285 | pdata->y_min = coords[1]; 3286 | pdata->x_max = coords[2]; 3287 | pdata->y_max = coords[3]; 3288 | } else { 3289 | dev_err(dev, "unsupported property %s\n", name); 3290 | return -EINVAL; 3291 | } 3292 | 3293 | return 0; 3294 | } 3295 | 3296 | static int ft5x06_parse_dt(struct device *dev, 3297 | struct ft5x06_ts_platform_data *pdata) 3298 | { 3299 | int rc; 3300 | struct device_node *np = dev->of_node; 3301 | struct property *prop; 3302 | u32 temp_val, num_buttons; 3303 | u32 button_map[MAX_BUTTONS]; 3304 | 3305 | pdata->name = "focaltech"; 3306 | rc = of_property_read_string(np, "focaltech,name", &pdata->name); 3307 | if (rc && (rc != -EINVAL)) { 3308 | dev_err(dev, "Unable to read name\n"); 3309 | return rc; 3310 | } 3311 | 3312 | rc = ft5x06_get_dt_coords(dev, "focaltech,panel-coords", pdata); 3313 | if (rc && (rc != -EINVAL)) 3314 | return rc; 3315 | 3316 | rc = ft5x06_get_dt_coords(dev, "focaltech,display-coords", pdata); 3317 | if (rc) 3318 | return rc; 3319 | 3320 | pdata->i2c_pull_up = of_property_read_bool(np, 3321 | "focaltech,i2c-pull-up"); 3322 | 3323 | pdata->no_force_update = of_property_read_bool(np, 3324 | "focaltech,no-force-update"); 3325 | /* reset, irq gpio info */ 3326 | pdata->reset_gpio = of_get_named_gpio_flags(np, "focaltech,reset-gpio", 3327 | 0, &pdata->reset_gpio_flags); 3328 | if (pdata->reset_gpio < 0) 3329 | return pdata->reset_gpio; 3330 | 3331 | pdata->irq_gpio = of_get_named_gpio_flags(np, "focaltech,irq-gpio", 3332 | 0, &pdata->irq_gpio_flags); 3333 | if (pdata->irq_gpio < 0) 3334 | return pdata->irq_gpio; 3335 | 3336 | pdata->fw_name = "ft_fw.bin"; 3337 | rc = of_property_read_string(np, "focaltech,fw-name", &pdata->fw_name); 3338 | if (rc && (rc != -EINVAL)) { 3339 | dev_err(dev, "Unable to read fw name\n"); 3340 | return rc; 3341 | } 3342 | 3343 | rc = of_property_read_u32(np, "focaltech,group-id", &temp_val); 3344 | if (!rc) 3345 | pdata->group_id = temp_val; 3346 | else 3347 | return rc; 3348 | 3349 | rc = of_property_read_u32(np, "focaltech,hard-reset-delay-ms", 3350 | &temp_val); 3351 | if (!rc) 3352 | pdata->hard_rst_dly = temp_val; 3353 | else 3354 | return rc; 3355 | 3356 | rc = of_property_read_u32(np, "focaltech,soft-reset-delay-ms", 3357 | &temp_val); 3358 | if (!rc) 3359 | pdata->soft_rst_dly = temp_val; 3360 | else 3361 | return rc; 3362 | 3363 | rc = of_property_read_u32(np, "focaltech,num-max-touches", &temp_val); 3364 | if (!rc) 3365 | pdata->num_max_touches = temp_val; 3366 | else 3367 | return rc; 3368 | 3369 | rc = of_property_read_u32(np, "focaltech,fw-delay-aa-ms", &temp_val); 3370 | if (rc && (rc != -EINVAL)) { 3371 | dev_err(dev, "Unable to read fw delay aa\n"); 3372 | return rc; 3373 | } else if (rc != -EINVAL) 3374 | pdata->info.delay_aa = temp_val; 3375 | 3376 | rc = of_property_read_u32(np, "focaltech,fw-delay-55-ms", &temp_val); 3377 | if (rc && (rc != -EINVAL)) { 3378 | dev_err(dev, "Unable to read fw delay 55\n"); 3379 | return rc; 3380 | } else if (rc != -EINVAL) 3381 | pdata->info.delay_55 = temp_val; 3382 | 3383 | rc = of_property_read_u32(np, "focaltech,fw-upgrade-id1", &temp_val); 3384 | if (rc && (rc != -EINVAL)) { 3385 | dev_err(dev, "Unable to read fw upgrade id1\n"); 3386 | return rc; 3387 | } else if (rc != -EINVAL) 3388 | pdata->info.upgrade_id_1 = temp_val; 3389 | 3390 | rc = of_property_read_u32(np, "focaltech,fw-upgrade-id2", &temp_val); 3391 | if (rc && (rc != -EINVAL)) { 3392 | dev_err(dev, "Unable to read fw upgrade id2\n"); 3393 | return rc; 3394 | } else if (rc != -EINVAL) 3395 | pdata->info.upgrade_id_2 = temp_val; 3396 | 3397 | rc = of_property_read_u32(np, "focaltech,fw-delay-readid-ms", 3398 | &temp_val); 3399 | if (rc && (rc != -EINVAL)) { 3400 | dev_err(dev, "Unable to read fw delay read id\n"); 3401 | return rc; 3402 | } else if (rc != -EINVAL) 3403 | pdata->info.delay_readid = temp_val; 3404 | 3405 | rc = of_property_read_u32(np, "focaltech,fw-delay-era-flsh-ms", 3406 | &temp_val); 3407 | if (rc && (rc != -EINVAL)) { 3408 | dev_err(dev, "Unable to read fw delay erase flash\n"); 3409 | return rc; 3410 | } else if (rc != -EINVAL) 3411 | pdata->info.delay_erase_flash = temp_val; 3412 | 3413 | pdata->info.auto_cal = of_property_read_bool(np, 3414 | "focaltech,fw-auto-cal"); 3415 | 3416 | pdata->fw_vkey_support = of_property_read_bool(np, 3417 | "focaltech,fw-vkey-support"); 3418 | 3419 | pdata->ignore_id_check = of_property_read_bool(np, 3420 | "focaltech,ignore-id-check"); 3421 | 3422 | rc = of_property_read_u32(np, "focaltech,family-id", &temp_val); 3423 | if (!rc) 3424 | pdata->family_id = temp_val; 3425 | else 3426 | return rc; 3427 | 3428 | prop = of_find_property(np, "focaltech,button-map", NULL); 3429 | if (prop) { 3430 | num_buttons = prop->length / sizeof(temp_val); 3431 | if (num_buttons > MAX_BUTTONS) 3432 | return -EINVAL; 3433 | 3434 | rc = of_property_read_u32_array(np, 3435 | "focaltech,button-map", button_map, 3436 | num_buttons); 3437 | if (rc) { 3438 | dev_err(dev, "Unable to read key codes\n"); 3439 | return rc; 3440 | } 3441 | } 3442 | 3443 | return 0; 3444 | } 3445 | #else 3446 | static int ft5x06_parse_dt(struct device *dev, 3447 | struct ft5x06_ts_platform_data *pdata) 3448 | { 3449 | return -ENODEV; 3450 | } 3451 | #endif 3452 | 3453 | static int ft5x06_ts_probe(struct i2c_client *client, 3454 | const struct i2c_device_id *id) 3455 | { 3456 | struct ft5x06_ts_platform_data *pdata; 3457 | struct ft5x06_ts_data *data; 3458 | struct input_dev *input_dev; 3459 | struct dentry *temp; 3460 | u8 reg_value; 3461 | u8 reg_addr; 3462 | int err, len; 3463 | 3464 | if (client->dev.of_node) { 3465 | pdata = devm_kzalloc(&client->dev, 3466 | sizeof(struct ft5x06_ts_platform_data), GFP_KERNEL); 3467 | if (!pdata) { 3468 | dev_err(&client->dev, "Failed to allocate memory\n"); 3469 | return -ENOMEM; 3470 | } 3471 | 3472 | err = ft5x06_parse_dt(&client->dev, pdata); 3473 | if (err) { 3474 | dev_err(&client->dev, "DT parsing failed\n"); 3475 | return err; 3476 | } 3477 | } else 3478 | pdata = client->dev.platform_data; 3479 | 3480 | if (!pdata) { 3481 | dev_err(&client->dev, "Invalid pdata\n"); 3482 | return -EINVAL; 3483 | } 3484 | 3485 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 3486 | dev_err(&client->dev, "I2C not supported\n"); 3487 | return -ENODEV; 3488 | } 3489 | 3490 | data = devm_kzalloc(&client->dev, 3491 | sizeof(struct ft5x06_ts_data), GFP_KERNEL); 3492 | if (!data) { 3493 | dev_err(&client->dev, "Not enough memory\n"); 3494 | return -ENOMEM; 3495 | } 3496 | 3497 | if (pdata->fw_name) { 3498 | len = strlen(pdata->fw_name); 3499 | if (len > FT_FW_NAME_MAX_LEN - 1) { 3500 | dev_err(&client->dev, "Invalid firmware name\n"); 3501 | return -EINVAL; 3502 | } 3503 | 3504 | strlcpy(data->fw_name, pdata->fw_name, len + 1); 3505 | } 3506 | 3507 | data->tch_data_len = FT_TCH_LEN(pdata->num_max_touches); 3508 | data->tch_data = devm_kzalloc(&client->dev, 3509 | data->tch_data_len, GFP_KERNEL); 3510 | if (!data->tch_data) { 3511 | dev_err(&client->dev, "Not enough memory\n"); 3512 | return -ENOMEM; 3513 | } 3514 | 3515 | input_dev = input_allocate_device(); 3516 | if (!input_dev) { 3517 | dev_err(&client->dev, "failed to allocate input device\n"); 3518 | return -ENOMEM; 3519 | } 3520 | 3521 | data->input_dev = input_dev; 3522 | data->client = client; 3523 | data->pdata = pdata; 3524 | 3525 | input_dev->name = "ft5x06_ts"; 3526 | input_dev->id.bustype = BUS_I2C; 3527 | input_dev->dev.parent = &client->dev; 3528 | 3529 | input_set_drvdata(input_dev, data); 3530 | i2c_set_clientdata(client, data); 3531 | 3532 | __set_bit(EV_KEY, input_dev->evbit); 3533 | __set_bit(EV_ABS, input_dev->evbit); 3534 | __set_bit(BTN_TOUCH, input_dev->keybit); 3535 | __set_bit(INPUT_PROP_DIRECT, input_dev->propbit); 3536 | 3537 | input_mt_init_slots(input_dev, pdata->num_max_touches, 0); 3538 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, pdata->x_min, 3539 | pdata->x_max, 0, 0); 3540 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, pdata->y_min, 3541 | pdata->y_max, 0, 0); 3542 | 3543 | err = input_register_device(input_dev); 3544 | if (err) { 3545 | dev_err(&client->dev, "Input device registration failed\n"); 3546 | goto free_inputdev; 3547 | } 3548 | 3549 | if (pdata->power_init) { 3550 | err = pdata->power_init(true); 3551 | if (err) { 3552 | dev_err(&client->dev, "power init failed"); 3553 | goto unreg_inputdev; 3554 | } 3555 | } else { 3556 | err = ft5x06_power_init(data, true); 3557 | if (err) { 3558 | dev_err(&client->dev, "power init failed"); 3559 | goto unreg_inputdev; 3560 | } 3561 | } 3562 | 3563 | if (pdata->power_on) { 3564 | err = pdata->power_on(true); 3565 | if (err) { 3566 | dev_err(&client->dev, "power on failed"); 3567 | goto pwr_deinit; 3568 | } 3569 | } else { 3570 | err = ft5x06_power_on(data, true); 3571 | if (err) { 3572 | dev_err(&client->dev, "power on failed"); 3573 | goto pwr_deinit; 3574 | } 3575 | } 3576 | 3577 | err = ft5x06_ts_pinctrl_init(data); 3578 | if (!err && data->ts_pinctrl) { 3579 | /* 3580 | * Pinctrl handle is optional. If pinctrl handle is found 3581 | * let pins to be configured in active state. If not 3582 | * found continue further without error. 3583 | */ 3584 | err = pinctrl_select_state(data->ts_pinctrl, 3585 | data->pinctrl_state_active); 3586 | if (err < 0) { 3587 | dev_err(&client->dev, 3588 | "failed to select pin to active state"); 3589 | } 3590 | } 3591 | 3592 | err = ft5x06_gpio_configure(data, true); 3593 | if (err < 0) { 3594 | dev_err(&client->dev, 3595 | "Failed to configure the gpios\n"); 3596 | goto err_gpio_req; 3597 | } 3598 | 3599 | /* make sure CTP already finish startup process */ 3600 | msleep(data->pdata->soft_rst_dly); 3601 | 3602 | /* check the controller id */ 3603 | reg_addr = FT_REG_ID; 3604 | err = ft5x06_i2c_read(client, ®_addr, 1, ®_value, 1); 3605 | if (err < 0) { 3606 | dev_err(&client->dev, "version read failed"); 3607 | goto free_gpio; 3608 | } 3609 | 3610 | dev_info(&client->dev, "Device ID = 0x%x\n", reg_value); 3611 | 3612 | if ((pdata->family_id != reg_value) && (!pdata->ignore_id_check)) { 3613 | dev_err(&client->dev, "%s:Unsupported controller\n", __func__); 3614 | goto free_gpio; 3615 | } 3616 | 3617 | data->family_id = pdata->family_id; 3618 | 3619 | fts_i2c_client = client; 3620 | 3621 | focaltech_get_upgrade_array(); 3622 | 3623 | INIT_WORK(&data->touch_event_work, fts_touch_irq_work); 3624 | data->ts_workqueue = create_workqueue(FTS_NAME); 3625 | if (!data->ts_workqueue) 3626 | { 3627 | err = -ESRCH; 3628 | goto exit_create_singlethread; 3629 | } 3630 | 3631 | err = request_threaded_irq(client->irq, NULL, 3632 | ft5x06_ts_interrupt, 3633 | pdata->irqflags | IRQF_ONESHOT | IRQF_TRIGGER_FALLING, 3634 | client->dev.driver->name, data); 3635 | if (err) { 3636 | dev_err(&client->dev, "request irq failed\n"); 3637 | goto free_gpio; 3638 | } 3639 | 3640 | disable_irq(client->irq); 3641 | 3642 | err = device_create_file(&client->dev, &dev_attr_fw_name); 3643 | if (err) { 3644 | dev_err(&client->dev, "sys file creation failed\n"); 3645 | goto irq_free; 3646 | } 3647 | 3648 | err = device_create_file(&client->dev, &dev_attr_update_fw); 3649 | if (err) { 3650 | dev_err(&client->dev, "sys file creation failed\n"); 3651 | goto free_fw_name_sys; 3652 | } 3653 | 3654 | err = device_create_file(&client->dev, &dev_attr_force_update_fw); 3655 | if (err) { 3656 | dev_err(&client->dev, "sys file creation failed\n"); 3657 | goto free_update_fw_sys; 3658 | } 3659 | 3660 | data->dir = debugfs_create_dir(FT_DEBUG_DIR_NAME, NULL); 3661 | if (data->dir == NULL || IS_ERR(data->dir)) { 3662 | pr_err("debugfs_create_dir failed(%ld)\n", PTR_ERR(data->dir)); 3663 | err = PTR_ERR(data->dir); 3664 | goto free_force_update_fw_sys; 3665 | } 3666 | 3667 | temp = debugfs_create_file("addr", S_IRUSR | S_IWUSR, data->dir, data, 3668 | &debug_addr_fops); 3669 | if (temp == NULL || IS_ERR(temp)) { 3670 | pr_err("debugfs_create_file failed: rc=%ld\n", PTR_ERR(temp)); 3671 | err = PTR_ERR(temp); 3672 | goto free_debug_dir; 3673 | } 3674 | 3675 | temp = debugfs_create_file("data", S_IRUSR | S_IWUSR, data->dir, data, 3676 | &debug_data_fops); 3677 | if (temp == NULL || IS_ERR(temp)) { 3678 | pr_err("debugfs_create_file failed: rc=%ld\n", PTR_ERR(temp)); 3679 | err = PTR_ERR(temp); 3680 | goto free_debug_dir; 3681 | } 3682 | 3683 | temp = debugfs_create_file("suspend", S_IRUSR | S_IWUSR, data->dir, 3684 | data, &debug_suspend_fops); 3685 | if (temp == NULL || IS_ERR(temp)) { 3686 | pr_err("debugfs_create_file failed: rc=%ld\n", PTR_ERR(temp)); 3687 | err = PTR_ERR(temp); 3688 | goto free_debug_dir; 3689 | } 3690 | 3691 | temp = debugfs_create_file("dump_info", S_IRUSR | S_IWUSR, data->dir, 3692 | data, &debug_dump_info_fops); 3693 | if (temp == NULL || IS_ERR(temp)) { 3694 | pr_err("debugfs_create_file failed: rc=%ld\n", PTR_ERR(temp)); 3695 | err = PTR_ERR(temp); 3696 | goto free_debug_dir; 3697 | } 3698 | 3699 | data->ts_info = devm_kzalloc(&client->dev, 3700 | FT_INFO_MAX_LEN, GFP_KERNEL); 3701 | if (!data->ts_info) { 3702 | dev_err(&client->dev, "Not enough memory\n"); 3703 | goto free_debug_dir; 3704 | } 3705 | 3706 | /*get some register information */ 3707 | reg_addr = FT_REG_POINT_RATE; 3708 | ft5x06_i2c_read(client, ®_addr, 1, ®_value, 1); 3709 | if (err < 0) 3710 | dev_err(&client->dev, "report rate read failed"); 3711 | 3712 | dev_info(&client->dev, "report rate = %dHz\n", reg_value * 10); 3713 | 3714 | reg_addr = FT_REG_THGROUP; 3715 | err = ft5x06_i2c_read(client, ®_addr, 1, ®_value, 1); 3716 | if (err < 0) 3717 | dev_err(&client->dev, "threshold read failed"); 3718 | 3719 | dev_dbg(&client->dev, "touch threshold = %d\n", reg_value * 4); 3720 | 3721 | ft5x06_update_fw_ver(data); 3722 | ft5x06_update_fw_vendor_id(data); 3723 | 3724 | FT_STORE_TS_INFO(data->ts_info, data->family_id, data->pdata->name, 3725 | data->pdata->num_max_touches, data->pdata->group_id, 3726 | data->pdata->fw_vkey_support ? "yes" : "no", 3727 | data->pdata->fw_name, data->fw_ver[0], 3728 | data->fw_ver[1], data->fw_ver[2]); 3729 | 3730 | #ifdef FTS_APK_DEBUG 3731 | fts_create_apk_debug_channel(client); 3732 | #endif 3733 | 3734 | #ifdef FTS_GESTRUE 3735 | input_set_capability(tpd->dev, EV_KEY, KEY_POWER); 3736 | input_set_capability(tpd->dev, EV_KEY, KEY_GESTURE_U); 3737 | input_set_capability(tpd->dev, EV_KEY, KEY_GESTURE_UP); 3738 | input_set_capability(tpd->dev, EV_KEY, KEY_GESTURE_DOWN); 3739 | input_set_capability(tpd->dev, EV_KEY, KEY_GESTURE_LEFT); 3740 | input_set_capability(tpd->dev, EV_KEY, KEY_GESTURE_RIGHT); 3741 | input_set_capability(tpd->dev, EV_KEY, KEY_GESTURE_O); 3742 | input_set_capability(tpd->dev, EV_KEY, KEY_GESTURE_E); 3743 | input_set_capability(tpd->dev, EV_KEY, KEY_GESTURE_M); 3744 | input_set_capability(tpd->dev, EV_KEY, KEY_GESTURE_L); 3745 | input_set_capability(tpd->dev, EV_KEY, KEY_GESTURE_W); 3746 | input_set_capability(tpd->dev, EV_KEY, KEY_GESTURE_S); 3747 | input_set_capability(tpd->dev, EV_KEY, KEY_GESTURE_V); 3748 | input_set_capability(tpd->dev, EV_KEY, KEY_GESTURE_Z); 3749 | 3750 | __set_bit(KEY_GESTURE_RIGHT, tpd->dev->keybit); 3751 | __set_bit(KEY_GESTURE_LEFT, tpd->dev->keybit); 3752 | __set_bit(KEY_GESTURE_UP, tpd->dev->keybit); 3753 | __set_bit(KEY_GESTURE_DOWN, tpd->dev->keybit); 3754 | __set_bit(KEY_GESTURE_U, tpd->dev->keybit); 3755 | __set_bit(KEY_GESTURE_O, tpd->dev->keybit); 3756 | __set_bit(KEY_GESTURE_E, tpd->dev->keybit); 3757 | __set_bit(KEY_GESTURE_M, tpd->dev->keybit); 3758 | __set_bit(KEY_GESTURE_W, tpd->dev->keybit); 3759 | __set_bit(KEY_GESTURE_L, tpd->dev->keybit); 3760 | __set_bit(KEY_GESTURE_S, tpd->dev->keybit); 3761 | __set_bit(KEY_GESTURE_V, tpd->dev->keybit); 3762 | __set_bit(KEY_GESTURE_Z, tpd->dev->keybit); 3763 | #endif 3764 | 3765 | #ifdef CONFIG_TOUCHPANEL_PROXIMITY_SENSOR 3766 | i2c_prox_client = client; 3767 | #ifdef SENSOR_PROX_TP_USE_WAKELOCK 3768 | wake_lock_init(&sensor_prox_tp_wake_lock, WAKE_LOCK_SUSPEND, "prox_tp"); 3769 | #endif 3770 | 3771 | err = sysfs_create_group(&client->dev.kobj, &tp_prox_attribute_group); 3772 | if (err) { 3773 | DBG( "sysfs create failed: %d\n", err); 3774 | } 3775 | 3776 | tp_prox_setup_polled_device(ft5x0x_ts); 3777 | #endif 3778 | 3779 | #if defined(CONFIG_FB) 3780 | data->fb_notif.notifier_call = fb_notifier_callback; 3781 | 3782 | err = fb_register_client(&data->fb_notif); 3783 | 3784 | if (err) 3785 | dev_err(&client->dev, "Unable to register fb_notifier: %d\n", 3786 | err); 3787 | #elif defined(CONFIG_HAS_EARLYSUSPEND) 3788 | data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 3789 | FT_SUSPEND_LEVEL; 3790 | data->early_suspend.suspend = ft5x06_ts_early_suspend; 3791 | data->early_suspend.resume = ft5x06_ts_late_resume; 3792 | register_early_suspend(&data->early_suspend); 3793 | #endif 3794 | 3795 | fts_wq_data = data; 3796 | enable_irq(client->irq); 3797 | 3798 | return 0; 3799 | 3800 | free_debug_dir: 3801 | debugfs_remove_recursive(data->dir); 3802 | free_force_update_fw_sys: 3803 | device_remove_file(&client->dev, &dev_attr_force_update_fw); 3804 | free_update_fw_sys: 3805 | device_remove_file(&client->dev, &dev_attr_update_fw); 3806 | free_fw_name_sys: 3807 | device_remove_file(&client->dev, &dev_attr_fw_name); 3808 | irq_free: 3809 | free_irq(client->irq, data); 3810 | free_gpio: 3811 | if (gpio_is_valid(pdata->reset_gpio)) 3812 | gpio_free(pdata->reset_gpio); 3813 | if (gpio_is_valid(pdata->irq_gpio)) 3814 | gpio_free(pdata->irq_gpio); 3815 | exit_create_singlethread: 3816 | printk("==singlethread error =\n"); 3817 | i2c_set_clientdata(client, NULL); 3818 | kfree(data); 3819 | err_gpio_req: 3820 | if (data->ts_pinctrl) { 3821 | if (IS_ERR_OR_NULL(data->pinctrl_state_release)) { 3822 | devm_pinctrl_put(data->ts_pinctrl); 3823 | data->ts_pinctrl = NULL; 3824 | } else { 3825 | err = pinctrl_select_state(data->ts_pinctrl, 3826 | data->pinctrl_state_release); 3827 | if (err) 3828 | pr_err("failed to select relase pinctrl state\n"); 3829 | } 3830 | } 3831 | if (pdata->power_on) 3832 | pdata->power_on(false); 3833 | else 3834 | ft5x06_power_on(data, false); 3835 | pwr_deinit: 3836 | if (pdata->power_init) 3837 | pdata->power_init(false); 3838 | else 3839 | ft5x06_power_init(data, false); 3840 | unreg_inputdev: 3841 | input_unregister_device(input_dev); 3842 | input_dev = NULL; 3843 | free_inputdev: 3844 | input_free_device(input_dev); 3845 | return err; 3846 | } 3847 | 3848 | static int ft5x06_ts_remove(struct i2c_client *client) 3849 | { 3850 | struct ft5x06_ts_data *data = i2c_get_clientdata(client); 3851 | int retval; 3852 | 3853 | cancel_work_sync(&data->touch_event_work); 3854 | destroy_workqueue(data->ts_workqueue); 3855 | 3856 | debugfs_remove_recursive(data->dir); 3857 | device_remove_file(&client->dev, &dev_attr_force_update_fw); 3858 | device_remove_file(&client->dev, &dev_attr_update_fw); 3859 | device_remove_file(&client->dev, &dev_attr_fw_name); 3860 | 3861 | #ifdef CONFIG_TOUCHPANEL_PROXIMITY_SENSOR 3862 | sysfs_remove_group(&client->dev.kobj, &tp_prox_attribute_group); 3863 | tp_prox_teardown_polled_device(ft5x0x_ts); 3864 | #ifdef SENSOR_PROX_TP_USE_WAKELOCK 3865 | wake_lock_destroy(&sensor_prox_tp_wake_lock); 3866 | #endif 3867 | #endif 3868 | 3869 | #ifdef FTS_APK_DEBUG 3870 | fts_release_apk_debug_channel(); 3871 | #endif 3872 | 3873 | #if defined(CONFIG_FB) 3874 | if (fb_unregister_client(&data->fb_notif)) 3875 | dev_err(&client->dev, "Error occurred while unregistering fb_notifier.\n"); 3876 | #elif defined(CONFIG_HAS_EARLYSUSPEND) 3877 | unregister_early_suspend(&data->early_suspend); 3878 | #endif 3879 | free_irq(client->irq, data); 3880 | 3881 | if (gpio_is_valid(data->pdata->reset_gpio)) 3882 | gpio_free(data->pdata->reset_gpio); 3883 | 3884 | if (gpio_is_valid(data->pdata->irq_gpio)) 3885 | gpio_free(data->pdata->irq_gpio); 3886 | 3887 | if (data->ts_pinctrl) { 3888 | if (IS_ERR_OR_NULL(data->pinctrl_state_release)) { 3889 | devm_pinctrl_put(data->ts_pinctrl); 3890 | data->ts_pinctrl = NULL; 3891 | } else { 3892 | retval = pinctrl_select_state(data->ts_pinctrl, 3893 | data->pinctrl_state_release); 3894 | if (retval < 0) 3895 | pr_err("failed to select release pinctrl state\n"); 3896 | } 3897 | } 3898 | 3899 | if (data->pdata->power_on) 3900 | data->pdata->power_on(false); 3901 | else 3902 | ft5x06_power_on(data, false); 3903 | 3904 | if (data->pdata->power_init) 3905 | data->pdata->power_init(false); 3906 | else 3907 | ft5x06_power_init(data, false); 3908 | 3909 | input_unregister_device(data->input_dev); 3910 | 3911 | return 0; 3912 | } 3913 | 3914 | static const struct i2c_device_id ft5x06_ts_id[] = { 3915 | {"ft5x06_ts", 0}, 3916 | {}, 3917 | }; 3918 | 3919 | MODULE_DEVICE_TABLE(i2c, ft5x06_ts_id); 3920 | 3921 | #ifdef CONFIG_OF 3922 | static struct of_device_id ft5x06_match_table[] = { 3923 | { .compatible = "focaltech,5x06",}, 3924 | { }, 3925 | }; 3926 | #else 3927 | #define ft5x06_match_table NULL 3928 | #endif 3929 | 3930 | static struct i2c_driver ft5x06_ts_driver = { 3931 | .probe = ft5x06_ts_probe, 3932 | .remove = ft5x06_ts_remove, 3933 | .driver = { 3934 | .name = "ft5x06_ts", 3935 | .owner = THIS_MODULE, 3936 | .of_match_table = ft5x06_match_table, 3937 | #ifdef CONFIG_PM 3938 | .pm = &ft5x06_ts_pm_ops, 3939 | #endif 3940 | }, 3941 | .id_table = ft5x06_ts_id, 3942 | }; 3943 | 3944 | static int __init ft5x06_ts_init(void) 3945 | { 3946 | return i2c_add_driver(&ft5x06_ts_driver); 3947 | } 3948 | module_init(ft5x06_ts_init); 3949 | 3950 | static void __exit ft5x06_ts_exit(void) 3951 | { 3952 | i2c_del_driver(&ft5x06_ts_driver); 3953 | } 3954 | module_exit(ft5x06_ts_exit); 3955 | 3956 | MODULE_DESCRIPTION("FocalTech ft5x06 TouchScreen driver"); 3957 | MODULE_LICENSE("GPL v2"); 3958 | -------------------------------------------------------------------------------- /ft5x06_ts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * FocalTech ft5x06 TouchScreen driver header file. 4 | * 5 | * Copyright (c) 2010 Focal tech Ltd. 6 | * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. 7 | * 8 | * This software is licensed under the terms of the GNU General Public 9 | * License version 2, as published by the Free Software Foundation, and 10 | * may be copied, distributed, and modified under those terms. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | */ 18 | #ifndef __LINUX_FT5X06_TS_H__ 19 | #define __LINUX_FT5X06_TS_H__ 20 | 21 | #define FT5X06_ID 0x55 22 | #define FT5X16_ID 0x0A 23 | #define FT5X36_ID 0x14 24 | #define FT6X06_ID 0x06 25 | #define FT6X36_ID 0x36 26 | 27 | #define FTS_APK_DEBUG 28 | #define CONFIG_TOUCHPANEL_PROXIMITY_SENSOR 29 | 30 | #define TPD_MAX_POINTS_2 2 31 | #define TPD_MAX_POINTS_5 5 32 | #define TPD_MAX_POINTS_10 10 33 | 34 | #define FTS_NAME "fts_wq" 35 | 36 | 37 | struct fw_upgrade_info { 38 | u8 auto_cal; 39 | u16 delay_aa; 40 | u16 delay_55; 41 | u8 upgrade_id_1; 42 | u8 upgrade_id_2; 43 | u16 delay_readid; 44 | u16 delay_erase_flash; 45 | }; 46 | 47 | struct ft5x06_ts_platform_data { 48 | struct fw_upgrade_info info; 49 | const char *name; 50 | const char *fw_name; 51 | u32 irqflags; 52 | u32 irq_gpio; 53 | u32 irq_gpio_flags; 54 | u32 reset_gpio; 55 | u32 reset_gpio_flags; 56 | u32 family_id; 57 | u32 x_max; 58 | u32 y_max; 59 | u32 x_min; 60 | u32 y_min; 61 | u32 panel_minx; 62 | u32 panel_miny; 63 | u32 panel_maxx; 64 | u32 panel_maxy; 65 | u32 group_id; 66 | u32 hard_rst_dly; 67 | u32 soft_rst_dly; 68 | u32 num_max_touches; 69 | bool fw_vkey_support; 70 | bool no_force_update; 71 | bool i2c_pull_up; 72 | bool ignore_id_check; 73 | int (*power_init) (bool); 74 | int (*power_on) (bool); 75 | }; 76 | 77 | #endif 78 | --------------------------------------------------------------------------------