xref: /OK3568_Linux_fs/kernel/drivers/input/touchscreen/focaltech_touch/focaltech_flash.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *
3  * FocalTech ftxxxx TouchScreen driver.
4  *
5  * Copyright (c) 2012-2018, Focaltech Ltd. All rights reserved.
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  */
17 
18 #ifndef __LINUX_FOCALTECH_FLASH_H__
19 #define __LINUX_FOCALTECH_FLASH_H__
20 
21 /*****************************************************************************
22 * 1.Included header files
23 *****************************************************************************/
24 #include "focaltech_core.h"
25 
26 /*****************************************************************************
27 * Private constant and macro definitions using #define
28 *****************************************************************************/
29 #define FTS_CMD_RESET                               0x07
30 #define FTS_ROMBOOT_CMD_WRITE                       0xAE
31 #define FTS_ROMBOOT_CMD_START_APP                   0x08
32 #define FTS_DELAY_PRAMBOOT_START                    10
33 #define FTS_ROMBOOT_CMD_ECC                         0xCC
34 
35 #define FTS_CMD_READ                                0x03
36 #define FTS_CMD_READ_DELAY                          1
37 #define FTS_CMD_READ_LEN                            4
38 #define FTS_CMD_FLASH_TYPE                          0x05
39 #define FTS_CMD_FLASH_MODE                          0x09
40 #define FLASH_MODE_WRITE_FLASH_VALUE                0x0A
41 #define FLASH_MODE_UPGRADE_VALUE                    0x0B
42 #define FLASH_MODE_LIC_VALUE                        0x0C
43 #define FLASH_MODE_PARAM_VALUE                      0x0D
44 #define FTS_CMD_ERASE_APP                           0x61
45 #define FTS_REASE_APP_DELAY                         1350
46 #define FTS_ERASE_SECTOR_DELAY                      60
47 #define FTS_RETRIES_REASE                           50
48 #define FTS_RETRIES_DELAY_REASE                     200
49 #define FTS_CMD_FLASH_STATUS                        0x6A
50 #define FTS_CMD_FLASH_STATUS_LEN                    2
51 #define FTS_CMD_FLASH_STATUS_NOP                    0x0000
52 #define FTS_CMD_FLASH_STATUS_ECC_OK                 0xF055
53 #define FTS_CMD_FLASH_STATUS_ERASE_OK               0xF0AA
54 #define FTS_CMD_FLASH_STATUS_WRITE_OK               0x1000
55 #define FTS_CMD_ECC_INIT                            0x64
56 #define FTS_CMD_ECC_CAL                             0x65
57 #define FTS_CMD_ECC_CAL_LEN                         6
58 #define FTS_RETRIES_ECC_CAL                         10
59 #define FTS_RETRIES_DELAY_ECC_CAL                   50
60 #define FTS_CMD_ECC_READ                            0x66
61 #define FTS_CMD_DATA_LEN                            0xB0
62 #define FTS_CMD_APP_DATA_LEN_INCELL                 0x7A
63 #define FTS_CMD_DATA_LEN_LEN                        4
64 #define FTS_CMD_WRITE                               0xBF
65 #define FTS_RETRIES_WRITE                           100
66 #define FTS_RETRIES_DELAY_WRITE                     1
67 #define FTS_CMD_WRITE_LEN                           6
68 #define FTS_DELAY_READ_ID                           20
69 #define FTS_DELAY_UPGRADE_RESET                     80
70 #define PRAMBOOT_MIN_SIZE                           0x120
71 #define PRAMBOOT_MAX_SIZE                           (64*1024)
72 #define FTS_FLASH_PACKET_LENGTH                     32     /* max=128 */
73 #define FTS_MAX_LEN_ECC_CALC                        0xFFFE /* must be even */
74 #define FTS_MIN_LEN                                 0x120
75 #define FTS_MAX_LEN_FILE                            (128 * 1024)
76 #define FTS_MAX_LEN_APP                             (64 * 1024)
77 #define FTS_MAX_LEN_SECTOR                          (4 * 1024)
78 #define FTS_CONIFG_VENDORID_OFF                     0x04
79 #define FTS_CONIFG_MODULEID_OFF                     0x1E
80 #define FTS_CONIFG_PROJECTID_OFF                    0x20
81 #define FTS_APPINFO_OFF                             0x100
82 #define FTS_APPINFO_APPLEN_OFF                      0x00
83 #define FTS_APPINFO_APPLEN2_OFF                     0x12
84 #define FTS_REG_UPGRADE                             0xFC
85 #define FTS_UPGRADE_AA                              0xAA
86 #define FTS_UPGRADE_55                              0x55
87 #define FTS_DELAY_FC_AA                             10
88 #define FTS_UPGRADE_LOOP                            30
89 #define FTS_HEADER_LEN                              32
90 #define FTS_FW_BIN_FILEPATH                         "/sdcard/"
91 #define FTS_FW_IDE_SIG                              "IDE_"
92 #define FTS_FW_IDE_SIG_LEN                          4
93 
94 #define FTS_ROMBOOT_CMD_ECC_NEW_LEN                 7
95 #define FTS_ROMBOOT_CMD_ECC_FINISH                  0xCE
96 #define FTS_CMD_READ_ECC                            0xCD
97 #define AL2_FCS_COEF                ((1 << 15) + (1 << 10) + (1 << 3))
98 
99 enum FW_STATUS {
100     FTS_RUN_IN_ERROR,
101     FTS_RUN_IN_APP,
102     FTS_RUN_IN_ROM,
103     FTS_RUN_IN_PRAM,
104     FTS_RUN_IN_BOOTLOADER,
105 };
106 
107 enum FW_FLASH_MODE {
108     FLASH_MODE_APP,
109     FLASH_MODE_LIC,
110     FLASH_MODE_PARAM,
111     FLASH_MODE_ALL,
112 };
113 
114 enum ECC_CHECK_MODE {
115     ECC_CHECK_MODE_XOR,
116     ECC_CHECK_MODE_CRC16,
117 };
118 
119 /*****************************************************************************
120 * Private enumerations, structures and unions using typedef
121 *****************************************************************************/
122 /* IC info */
123 struct upgrade_func {
124     u64 ctype[FTX_MAX_COMPATIBLE_TYPE];
125     int newmode;
126     u32 fwveroff;
127     u32 fwcfgoff;
128     u32 appoff;
129     u32 licoff;
130     u32 paramcfgoff;
131     u32 paramcfgveroff;
132     u32 paramcfg2off;
133     int ecc_check_mode;
134     bool read_boot_id_need_reset;
135     bool hid_supported;
136     bool pramboot_supported;
137     u8 *pramboot;
138     u32 pb_length;
139     int (*init)(void);
140     int (*upgrade)(struct i2c_client *, u8 *, u32);
141     int (*get_hlic_ver)(u8 *);
142     int (*lic_upgrade)(struct i2c_client *, u8 *, u32);
143     int (*param_upgrade)(struct i2c_client *, u8 *, u32);
144     int (*force_upgrade)(struct i2c_client *, u8 *, u32);
145 };
146 
147 struct fts_upgrade {
148     u8 *fw;
149     u32 fw_length;
150     u8 *lic;
151     u32 lic_length;
152     struct upgrade_func *func;
153 };
154 
155 struct upgrade_fw {
156     u16 vendor_id;
157     u8 *fw_file;
158     u32 fw_len;
159 };
160 
161 /*****************************************************************************
162 * Global variable or extern global variabls/functions
163 *****************************************************************************/
164 extern struct fts_upgrade *fwupgrade;
165 extern struct upgrade_func upgrade_func_ft8006m;
166 
167 /*****************************************************************************
168 * Static function prototypes
169 *****************************************************************************/
170 bool fts_fwupg_check_fw_valid(struct i2c_client *client);
171 int fts_fwupg_get_boot_state(struct i2c_client *client, enum FW_STATUS *fw_sts);
172 bool fts_fwupg_check_state(struct i2c_client *client, enum FW_STATUS rstate);
173 int fts_fwupg_reset_in_boot(struct i2c_client *client);
174 int fts_fwupg_reset_to_boot(struct i2c_client *client);
175 int fts_fwupg_reset_to_romboot(struct i2c_client *client);
176 int fts_fwupg_enter_into_boot(struct i2c_client *client);
177 int fts_fwupg_erase(struct i2c_client *client, u32 delay);
178 int fts_fwupg_ecc_cal(struct i2c_client *client, u32 saddr, u32 len);
179 int fts_flash_write_buf(struct i2c_client *client, u32 saddr, u8 *buf, u32 len, u32 delay);
180 int fts_fwupg_upgrade(struct i2c_client *client, struct fts_upgrade *upg);
181 u16 fts_crc16_calc_host(u8 *pbuf, u16 length);
182 #endif
183