1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * ELAN HID-I2C TouchScreen driver. 4 * 5 * Copyright (C) 2014 Elan Microelectronics Corporation. 6 * 7 * Author: Chuming Zhang <chuming.zhang@elanic.com.cn> 8 */ 9 10 #ifndef _LINUX_ELAN_TS_H 11 #define _LINUX_ELAN_TS_H 12 13 #include <linux/i2c.h> 14 #include <linux/miscdevice.h> 15 #include <linux/regulator/consumer.h> 16 #include <linux/uaccess.h> 17 #include <linux/fs.h> 18 #include <linux/delay.h> 19 #include <linux/kernel.h> 20 #include <linux/errno.h> 21 #include <linux/slab.h> 22 #include <linux/firmware.h> 23 #ifdef CONFIG_HAS_EARLYSUSPEND 24 #include <linux/pm.h> 25 #include <linux/earlysuspend.h> 26 #endif 27 28 #if defined(CONFIG_FB) 29 #include <linux/notifier.h> 30 #include <linux/fb.h> 31 #endif 32 #include <linux/poll.h> 33 #include <linux/wait.h> 34 /*fw upgrade fuction switch*/ 35 //#define IAP_PORTION 36 37 /*define elan device name*/ 38 #define ELAN_TS_NAME "elan_ts" 39 40 #define MIN(x,y) ((((x) - (y)) < 0) ? (x) : (y)) 41 #define FLASH_PAGE_PER_TIMES (30) 42 #define FW_PAGE_SIZE (132) 43 #define IAP_CMD_HEADER_LEN (9) 44 #define IAP_FLASH_SIZE (FLASH_PAGE_PER_TIMES * FW_PAGE_SIZE) 45 46 #define ELAN_VTG_MIN_UV 3300000//2850000 47 #define ELAN_VTG_MAX_UV 3300000//2850000 48 #define ELAN_I2C_VTG_MIN_UV 1800000 49 #define ELAN_I2C_VTG_MAX_UV 1800000 50 51 #define HID_REPORT_MAX_LEN (67*2) 52 #define NORMAL_REPORT_MAX_LEN (55) 53 #define HID_CMD_LEN (37) 54 #define HID_RECV_LEN (67) 55 56 57 #define RETRY_TIMES (3) 58 59 #define FINGERS_NUM 10 60 61 struct ts_chip_hw_info { 62 int intr_gpio; 63 int rst_gpio; 64 int irq_num; 65 uint16_t screen_x; 66 uint16_t screen_y; 67 }; 68 69 struct elan_fw_info { 70 int fw_ver; 71 int fw_id; 72 int fw_bcv; 73 int fw_bcl; 74 int tx; /*tp module y<->tx*/ 75 int rx; /*tp module x<->rx*/ 76 int finger_xres; 77 int finger_yres; 78 int pen_xres; 79 int pen_yres; 80 int finger_osr; 81 int testsolversion; 82 int testversion; 83 int solutionversion; 84 int whck_ver; 85 }; 86 87 struct elan_update_fw_info { 88 char *FwName; 89 char fw_local_path[50]; 90 const u8 *FwData; 91 const struct firmware *p_fw_entry; 92 int PageNum; 93 int FwSize; 94 int PageSize; 95 u16 remark_id; 96 }; 97 98 struct elan_i2c_operation{ 99 int (*send)(const uint8_t *, int len); 100 int (*recv)(uint8_t *, int len); 101 int (*poll)(void); 102 }; 103 104 struct elan_packet_struct { 105 int finger_num; 106 int finger_id; 107 int pen_id; 108 int vaild_size; 109 }; 110 111 112 struct elan_finger_struct { 113 int fid; /*finger identify*/ 114 int fsupport_num; /*support finger num*/ 115 int fbuf_valid_size; /*hid: 67/67*2, normal:8/18/35/55*/ 116 int fvalid_num; /*current buf support finger num*/ 117 int fbits; /*current finger is contact or not*/ 118 int fbutton_value; /*mutual button*/ 119 int freport_idx; /*parse coordinate start byte*/ 120 int fshift_byte; /*parse shift byte*/ 121 }; 122 123 struct elan_stylus_struct { 124 int pid; /*stylus identify*/ 125 int pbuf_valid_size; /*stylus buf size*/ 126 int pbutton_value; /*mutual button,may not use*/ 127 int preport_idx; /*parse coordinate start byte*/ 128 int shitf_byte; /*may not use*/ 129 // int tip_status; /**/ 130 int tip_status; /*contact status*/ 131 int inrange_status; /*hover status*/ 132 int key; /*key status*/ 133 int eraser; /*eraser*/ 134 int inver; /*inver*/ 135 int barrel; /*barrel*/ 136 int barrel_tip; /*barrel+tip*/ 137 }; 138 139 struct elan_report_struct { 140 struct elan_finger_struct finger; 141 struct elan_stylus_struct stylus; 142 // uint8_t *buf; /*elan report recv buf*/ 143 // int finger_id; /*finger identify*/ 144 // int pen_id; /*stylu identify*/ 145 // int buf_valid_size; /*hid: 67/67*2, normal:8/18/35/55*/ 146 // int finger_num; /*support finger num*/ 147 // int valid_finger_num; /*current buf support finger num*/ 148 // int button_byte; /*muxtual button*/ 149 // int report_idx; /*coordinate calculate start index*/ 150 // int shift_byte; /*calculate shift*/ 151 // int fbits; /*current finger/pen index is valid or not*/ 152 int tool_type; /**/ 153 }; 154 155 156 struct elan_ts_data { 157 struct ts_chip_hw_info hw_info; /*elan touch need gpio*/ 158 struct i2c_client *client; 159 struct elan_fw_info fw_info; 160 struct elan_update_fw_info update_info; 161 struct elan_i2c_operation *ops; 162 struct elan_report_struct report; 163 #ifdef CONFIG_HAS_EARLYSUSPEND 164 struct early_suspend early_suspend; /*for early suspend*/ 165 #endif 166 167 struct regulator *vdd; /*tp vdd*/ 168 struct regulator *vcc_i2c; /*tp vio*/ 169 bool power_enabled; /*power setting flag*/ 170 171 int power_lock; /*for i2ctransfer on power off flage*/ 172 int recover; /*fw incomplete flag*/ 173 struct miscdevice firmware; /*for misc dev*/ 174 struct proc_dir_entry *p; /*creat proc dev*/ 175 176 struct input_dev *finger_idev; /*for register finger input device*/ 177 struct input_dev *pen_idev; /*for register pen inpur device*/ 178 179 #if defined(CONFIG_FB) 180 struct notifier_block fb_notif; /*FB callback*/ 181 #endif 182 183 int chip_type; /*chip protocol */ 184 int report_type; /*report protocol*/ 185 int fw_store_type; /*fw stroe*/ 186 187 188 struct workqueue_struct *init_elan_ic_wq; /*for ic initial*/ 189 struct delayed_work init_work; 190 191 struct workqueue_struct *elan_wq; /*for irq handler*/ 192 struct work_struct ts_work; 193 uint8_t level; 194 195 int int_val; /*for user space*/ 196 int user_handle_irq; /*for switch user or kernel handle irq*/ 197 wait_queue_head_t elan_userqueue; /*wait queue for user space read data*/ 198 int irq_lock_flag; /*irq enable/disable flage, 1=>irq has been disable, 0=>has been enable*/ 199 struct mutex irq_mutex; /* Guards against concurrent access to the irq_lock_flag*/ 200 }; 201 202 203 struct vendor_map 204 { 205 int vendor_id; //lcm ID 206 char vendor_name[30]; //lcm vendor name 207 uint8_t* fw_array; // lcm_vendor_fw 208 int fw_size; 209 int fw_id; 210 }; 211 212 213 214 enum elan_get_vendor_fw_type { 215 FROM_SYS_ETC_FIRMWARE, 216 FROM_SDCARD_FIRMWARE, 217 FROM_DRIVER_FIRMWARE, 218 }; 219 220 enum elan_report_protocol_type { 221 PROTOCOL_TYPE_A = 0x00, 222 PROTOCOL_TYPE_B = 0x01, 223 }; 224 225 enum elan_chip_protocol_type { 226 HID_TYPE_PROTOCOL = 0x01, 227 NORMAL_TYPE_PROTOCOL = 0x00, 228 }; 229 230 enum elan_fw_status { 231 HID_FW_NORMAL_MODE = 0x20, 232 HID_FW_RECOVERY_MODE = 0x56, 233 NORMAL_FW_NORMAL_MODE = 0x55, 234 NORMAL_FW_RECOVERY_MODE = 0x80, 235 }; 236 237 enum fw_update_type { 238 FORCED_UPGRADE = 0x01, 239 COMPARE_UPGRADE = 0x02, 240 UNKNOW_TYPE = -1, 241 }; 242 243 enum packet_head_type { 244 CMD_S_PKT = 0x52, 245 CMD_R_PKT = 0x53, 246 CMD_W_PKT = 0x54, 247 REG_R_PKT = 0x5B, 248 REG_S_PKT = 0x9B, 249 }; 250 251 252 enum report_packet_size { 253 NOR2_SIZE = 8, 254 NOR5_SIZE = 18, 255 NOR10_SIZE = 35, 256 HID5_SIZE = 67, 257 HID10_SIZE = 67*2, 258 }; 259 260 enum report_packet_id { 261 NOR2_FID = 0x5A, 262 NOR5_FID = 0x5D, 263 NOR10_FID = 0x62, 264 HID_FID = 0x01, 265 HID_PID = 0x07, 266 }; 267 268 enum report_tool_type { 269 ELAN_FINGER = 0x01, 270 ELAN_PEN = 0x02, 271 }; 272 273 enum elan_power_status { 274 PWR_STATE_DEEP_SLEEP = 0x00, 275 PWR_STATE_NORMAL = 0x01, 276 }; 277 278 279 280 281 282 /*************************dev file macro switch********************/ 283 #define ELAN_IAP_DEV 284 285 #ifdef ELAN_IAP_DEV 286 #define ELAN_IOCTLID 0xD0 287 #define IOCTL_I2C_SLAVE _IOW(ELAN_IOCTLID, 1, int) 288 #define IOCTL_MAJOR_FW_VER _IOR(ELAN_IOCTLID, 2, int) 289 #define IOCTL_MINOR_FW_VER _IOR(ELAN_IOCTLID, 3, int) 290 #define IOCTL_RESET _IOR(ELAN_IOCTLID, 4, int) 291 #define IOCTL_IAP_MODE_LOCK _IOR(ELAN_IOCTLID, 5, int) 292 #define IOCTL_CHECK_RECOVERY_MODE _IOR(ELAN_IOCTLID, 6, int) 293 #define IOCTL_FW_VER _IOR(ELAN_IOCTLID, 7, int) 294 #define IOCTL_X_RESOLUTION _IOR(ELAN_IOCTLID, 8, int) 295 #define IOCTL_Y_RESOLUTION _IOR(ELAN_IOCTLID, 9, int) 296 #define IOCTL_FW_ID _IOR(ELAN_IOCTLID, 10, int) 297 #define IOCTL_ROUGH_CALIBRATE _IOR(ELAN_IOCTLID, 11, int) 298 #define IOCTL_IAP_MODE_UNLOCK _IOR(ELAN_IOCTLID, 12, int) 299 #define IOCTL_I2C_INT _IOR(ELAN_IOCTLID, 13, int) 300 #define IOCTL_RESUME _IOR(ELAN_IOCTLID, 14, int) 301 #define IOCTL_POWER_LOCK _IOR(ELAN_IOCTLID, 15, int) 302 #define IOCTL_POWER_UNLOCK _IOR(ELAN_IOCTLID, 16, int) 303 #define IOCTL_FW_UPDATE _IOR(ELAN_IOCTLID, 17, int) 304 #define IOCTL_BC_VER _IOR(ELAN_IOCTLID, 18, int) 305 #define IOCTL_2WIREICE _IOR(ELAN_IOCTLID, 19, int) 306 #define IOCTL_VIAROM _IOR(ELAN_IOCTLID, 20, int) 307 #define IOCTL_VIAROM_CHECKSUM _IOW(ELAN_IOCTLID, 21, unsigned long) 308 #define IOCTL_GET_UPDATE_PROGREE _IOR(CUSTOMER_IOCTLID, 2, int) 309 #define IOCTL_USER_HANDLE_IRQ _IOR(ELAN_IOCTLID, 22, int) 310 #define IOCTL_KERN_HANDLE_IRQ _IOR(ELAN_IOCTLID, 23, int) 311 #endif 312 313 314 //define print log 315 //#define LOG_TAG(tag) "[tag]: %s() line: %d " 316 #define TP_DEBUG 0//"dbg" 317 #define TP_WARNING 1 318 #define TP_INFO 2//"info" 319 #define TP_ERR 4//"err" 320 321 #define print_log(level, fmt, args...) \ 322 do { \ 323 if (level > TP_WARNING) \ 324 printk("[elan]:"fmt"\n",##args);\ 325 } while(0) 326 327 328 //extern function 329 extern void elan_check_update_flage(struct elan_ts_data *ts); 330 extern int elan__fw_packet_handler(struct i2c_client *client); 331 extern int elan__hello_packet_handler(struct i2c_client *client, int chip_type); 332 extern void elan_ts_hw_reset(struct ts_chip_hw_info *hw_info); 333 extern void elan_switch_irq(struct elan_ts_data *ts, int on); 334 extern int elan_ts_calibrate(struct i2c_client *client); 335 extern int elan_FW_Update(struct i2c_client *client); 336 extern int elan_ic_status(struct i2c_client *client); 337 extern int elan_ts_check_calibrate(struct i2c_client *client); 338 extern int elan_sysfs_attri_file(struct elan_ts_data *ts); 339 extern void elan_sysfs_attri_file_remove(struct elan_ts_data *ts); 340 extern int elan_get_vendor_fw(struct elan_ts_data *ts, int type); 341 extern int elan_tp_module_test(struct elan_ts_data *ts); 342 #endif /* _LINUX_ELAN_KTF_H */ 343