1 /*
2  * Copyright 2012 The Android Open Source Project
3  * Copyright (c) 2013, The Linux Foundation. All rights reserved.
4  * Not a Contribution.
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  */
18 #ifndef HW_ROME_H
19 #define HW_ROME_H
20 
21 /******************************************************************************
22 **  Constants & Macros
23 ******************************************************************************/
24 #define HCI_MAX_CMD_SIZE        260
25 #define HCI_MAX_EVENT_SIZE     260
26 #define PRINT_BUF_SIZE              ((HCI_MAX_CMD_SIZE * 3) + 2)
27 
28 #define HCI_CHG_BAUD_CMD_OCF        0x0C
29 #define HCI_VENDOR_CMD_OGF             0x3F
30 #define WRITE_BDADDR_CMD_LEN        14
31 #define WRITE_BAUD_CMD_LEN             6
32 #define MAX_CMD_LEN                    WRITE_BDADDR_CMD_LEN
33 #define GET_VERSION_OCF            0x1E
34 
35 #define PS_HDR_LEN                         4
36 #define HCI_VENDOR_CMD_OGF      0x3F
37 #define HCI_PS_CMD_OCF                0x0B
38 
39 #define HCI_COMMAND_HDR_SIZE        3
40 #define EVT_CMD_COMPLETE_SIZE       3
41 #define EVT_CMD_STATUS                     0x0F
42 #define EVT_CMD_STATUS_SIZE           4
43 #define HCI_EVENT_HDR_SIZE              2
44 #define HCI_EV_SUCCESS                      0x00
45 /* HCI Socket options */
46 #define HCI_DATA_DIR            1
47 #define HCI_FILTER                  2
48 #define HCI_TIME_STAMP        3
49 
50 #define P_ID_OFFSET                                     (0)
51 #define HCI_CMD_IND                                   (1)
52 #define EVENTCODE_OFFSET                      (1)
53 #define EVT_PLEN                                             (2)
54 #define PLEN                                                       (3)
55 #define CMD_RSP_OFFSET                             (3)
56 #define RSP_TYPE_OFFSET                            (4)
57 #define BAUDRATE_RSP_STATUS_OFFSET    (4)
58 #define CMD_STATUS_OFFSET                      (5)
59 #define P_ROME_VER_OFFSET                       (4)
60 #define P_BUILD_VER_OFFSET                      (6)
61 #define P_BASE_ADDR_OFFSET                     (8)
62 #define P_ENTRY_ADDR_OFFSET                   (12)
63 #define P_LEN_OFFSET                                   (16)
64 #define P_CRC_OFFSET                                  (20)
65 #define P_CONTROL_OFFSET                          (24)
66 #define PATCH_HDR_LEN                               (28)
67 #define MAX_DATA_PER_SEGMENT                (239)
68 #define VSEVENT_CODE                                 (0xFF)
69 #define HC_VS_MAX_CMD_EVENT                 (0xFF)
70 #define PATCH_PROD_ID_OFFSET                (5)
71 #define PATCH_PATCH_VER_OFFSET            (9)
72 #define PATCH_ROM_BUILD_VER_OFFSET       (11)
73 #define PATCH_SOC_VER_OFFSET             (13)
74 #define MAX_SIZE_PER_TLV_SEGMENT        (243)
75 
76 /* VS Opcode */
77 #define HCI_PATCH_CMD_OCF                       (0)
78 #define EDL_SET_BAUDRATE_CMD_OCF        (0x48)
79 #define EDL_WIPOWER_VS_CMD_OCF          (0x1f)
80 #define HCI_VS_GET_ADDON_FEATURES_SUPPORT   (0x1d)
81 #define EDL_GET_BOARD_ID              (0x23)
82 
83 /* VS Commands */
84 #define VSC_SET_BAUDRATE_REQ_LEN        (1)
85 #define EDL_PATCH_CMD_LEN	                       (1)
86 #define EDL_PATCH_CMD_REQ_LEN               (1)
87 #define EDL_WIP_QUERY_CHARGING_STATUS_LEN   (0x01)
88 #define EDL_WIP_START_HANDOFF_TO_HOST_LEN   (0x01)
89 #define EDL_PATCH_DLD_REQ_CMD               (0x01)
90 #define EDL_PATCH_RST_REQ_CMD               (0x05)
91 #define EDL_PATCH_SET_REQ_CMD               (0x16)
92 #define EDL_PATCH_ATCH_REQ_CMD            (0x17)
93 #define EDL_PATCH_VER_REQ_CMD               (0x19)
94 #define EDL_GET_BUILD_INFO                  (0x20)
95 #define EDL_PATCH_TLV_REQ_CMD               (0x1E)
96 #define EDL_WIP_QUERY_CHARGING_STATUS_CMD   (0x1D)
97 #define EDL_WIP_START_HANDOFF_TO_HOST_CMD   (0x1E)
98 
99 /* VS Event */
100 #define EDL_CMD_REQ_RES_EVT                 (0x00)
101 #define EDL_CMD_EXE_STATUS_EVT           (0x00)
102 #define EDL_SET_BAUDRATE_RSP_EVT       (0x92)
103 #define EDL_PATCH_VER_RES_EVT             (0x19)
104 #define EDL_TVL_DNLD_RES_EVT                (0x04)
105 #define EDL_APP_VER_RES_EVT                  (0x02)
106 #define EDL_WIP_QUERY_CHARGING_STATUS_EVT    (0x18)
107 #define EDL_WIP_START_HANDOFF_TO_HOST_EVENT  (0x19)
108 #define HCI_VS_GET_ADDON_FEATURES_EVENT      (0x1B)
109 #define EDL_BOARD_ID_RESPONSE                (0x23)
110 #define HCI_VS_GET_BUILD_VER_EVT             (0x05)
111 
112 /* Status Codes of HCI CMD execution*/
113 #define HCI_CMD_SUCCESS                     (0x0)
114 #define PATCH_LEN_ERROR                       (0x1)
115 #define PATCH_VER_ERROR                       (0x2)
116 #define PATCH_CRC_ERROR                     (0x3)
117 #define PATCH_NOT_FOUND                      (0x4)
118 #define TLV_TYPE_ERROR                         (0x10)
119 #define NVM_ACCESS_CODE                     (0x0B)
120 #define BAUDRATE_CHANGE_SUCCESS   (1)
121 
122 /* Wipower status codes */
123 #define WIPOWER_IN_EMBEDDED_MODE 0x01
124 #define NON_WIPOWER_MODE 0x02
125 
126 /* mask to validate support for wipower */
127 #define ADDON_FEATURES_EVT_WIPOWER_MASK      (0x01)
128 
129 /* TLV_TYPE */
130 #define TLV_TYPE_PATCH                  (1)
131 #define TLV_TYPE_NVM                      (2)
132 
133 /* NVM */
134 #define MAX_TAG_CMD                 30
135 #define TAG_END                           0xFF
136 #define NVM_ACCESS_SET            0x01
137 #define TAG_NUM_OFFSET             5
138 #define TAG_NUM_2                       2
139 #define TAG_BDADDR_OFFSET     7
140 
141 /* NVM Tags specifically used for ROME 1.0 */
142 #define ROME_1_0_100022_1       0x101000221
143 #define ROME_1_0_100019           0x101000190
144 #define ROME_1_0_6002               0x100600200
145 
146 /* Default NVM Version setting for ROME 1.0 */
147 #define NVM_VERSION                  ROME_1_0_100022_1
148 
149 
150 #define LSH(val, n)     ((uint32_t)(val) << (n))
151 #define EXTRACT_BYTE(val, pos)      (char) (((val) >> (8 * (pos))) & 0xFF)
152 #define CALC_SEG_SIZE(len, max)   ((plen) % (max))?((plen/max)+1) : ((plen) / (max))
153 
154 #define ROME_FW_PATH        "/system/etc/firmware/rampatch.img"
155 #define ROME_RAMPATCH_TLV_PATH      "/system/etc/firmware/rampatch_tlv.img"
156 #define ROME_NVM_TLV_PATH         "/system/etc/firmware/nvm_tlv.bin"
157 #define ROME_RAMPATCH_TLV_1_0_3_PATH    "/system/etc/firmware/rampatch_tlv_1.3.tlv"
158 #define ROME_NVM_TLV_1_0_3_PATH         "/system/etc/firmware/nvm_tlv_1.3.bin"
159 #define ROME_RAMPATCH_TLV_2_0_1_PATH    "/system/etc/firmware/rampatch_tlv_2.1.tlv"
160 #define ROME_NVM_TLV_2_0_1_PATH         "/system/etc/firmware/nvm_tlv_2.1.bin"
161 #define ROME_RAMPATCH_TLV_3_0_0_PATH    "/vendor/firmware/btfw30.tlv"
162 #define ROME_NVM_TLV_3_0_0_PATH         "/vendor/firmware/btnv30.bin"
163 //#define ROME_RAMPATCH_TLV_3_0_0_PATH    "/system/etc/firmware/rampatch_tlv_3.0.tlv"
164 //#define ROME_NVM_TLV_3_0_0_PATH         "/system/etc/firmware/nvm_tlv_3.0.bin"
165 #define ROME_RAMPATCH_TLV_3_0_2_PATH    "/vendor/firmware/btfw32.tlv"
166 #define ROME_NVM_TLV_3_0_2_PATH         "/vendor/firmware/btnv32.bin"
167 //#define ROME_RAMPATCH_TLV_3_0_2_PATH    "/system/etc/firmware/rampatch_tlv_3.2.tlv"
168 //#define ROME_NVM_TLV_3_0_2_PATH         "/system/etc/firmware/nvm_tlv_3.2.bin"
169 
170 #define ROME_3_1_FW_SU  "bprm.cnss.3.1"
171 #define ROME_3_2_FW_SU  "btfwp.cnss.3.2"
172 
173 /* Rome 3.1 FW SU release has been branched from rome 3.0 SU 224
174     So, rome 3.1 formula is SU = patch version -(0xE0 = 224) - 0x111 -1
175 */
176 #define ROME_3_1_FW_SW_OFFSET   0x01F2
177 
178 /* Rome 3.2 FW SU formula is SU = patch version - 0x111 -1 */
179 #define ROME_3_2_FW_SW_OFFSET   0x0112
180 
181 /* This header value in rampatch file decides event handling mechanism in the HOST */
182 #define ROME_SKIP_EVT_NONE     0x00
183 #define ROME_SKIP_EVT_VSE      0x01
184 #define ROME_SKIP_EVT_CC       0x02
185 #define ROME_SKIP_EVT_VSE_CC   0x03
186 
187 /******************************************************************************
188 **  Local type definitions
189 ******************************************************************************/
190 typedef struct {
191     unsigned short rom_version;
192     unsigned short build_version;
193 } __attribute__ ((packed)) patch_version;
194 
195 typedef struct {
196     unsigned int patch_id;
197     patch_version patch_ver;
198     unsigned int patch_base_addr;
199     unsigned int patch_entry_addr;
200     unsigned short patch_length;
201     int patch_crc;
202     unsigned short patch_ctrl;
203 } __attribute__ ((packed)) patch_info;
204 
205 typedef struct {
206     unsigned int  tlv_data_len;
207     unsigned int  tlv_patch_data_len;
208     unsigned char sign_ver;
209     unsigned char sign_algorithm;
210     unsigned char dwnd_cfg;
211     unsigned char reserved1;
212     unsigned short prod_id;
213     unsigned short build_ver;
214     unsigned short patch_ver;
215     unsigned short reserved2;
216     unsigned int patch_entry_addr;
217 } __attribute__ ((packed)) tlv_patch_hdr;
218 
219 typedef struct {
220     unsigned short tag_id;
221     unsigned short tag_len;
222     unsigned int tag_ptr;
223     unsigned int tag_ex_flag;
224 } __attribute__ ((packed)) tlv_nvm_hdr;
225 
226 typedef struct {
227     unsigned char tlv_type;
228     unsigned char tlv_length1;
229     unsigned char tlv_length2;
230     unsigned char tlv_length3;
231 
232     union{
233         tlv_patch_hdr patch;
234         tlv_nvm_hdr nvm;
235     }tlv;
236 } __attribute__ ((packed)) tlv_patch_info;
237 
238 
239 enum{
240     BAUDRATE_115200     = 0x00,
241     BAUDRATE_57600       = 0x01,
242     BAUDRATE_38400       = 0x02,
243     BAUDRATE_19200       = 0x03,
244     BAUDRATE_9600         = 0x04,
245     BAUDRATE_230400     = 0x05,
246     BAUDRATE_250000     = 0x06,
247     BAUDRATE_460800     = 0x07,
248     BAUDRATE_500000     = 0x08,
249     BAUDRATE_720000     = 0x09,
250     BAUDRATE_921600     = 0x0A,
251     BAUDRATE_1000000   = 0x0B,
252     BAUDRATE_1250000   = 0x0C,
253     BAUDRATE_2000000   = 0x0D,
254     BAUDRATE_3000000   = 0x0E,
255     BAUDRATE_4000000   = 0x0F,
256     BAUDRATE_1600000   = 0x10,
257     BAUDRATE_3200000   = 0x11,
258     BAUDRATE_3500000   = 0x12,
259     BAUDRATE_AUTO        = 0xFE,
260     BAUDRATE_Reserved  = 0xFF
261 };
262 
263 enum{
264     ROME_PATCH_VER_0100 = 0x0100,
265     ROME_PATCH_VER_0101 = 0x0101,
266     ROME_PATCH_VER_0200 = 0x0200,
267     ROME_PATCH_VER_0300 = 0x0300,
268     ROME_PATCH_VER_0302 = 0x0302
269  };
270 
271 enum{
272     ROME_SOC_ID_00 = 0x00000000,
273     ROME_SOC_ID_11 = 0x00000011,
274     ROME_SOC_ID_22 = 0x00000022,
275     ROME_SOC_ID_44 = 0x00000044
276 };
277 
278 enum{
279     ROME_VER_UNKNOWN = 0,
280     ROME_VER_1_0 = ((ROME_PATCH_VER_0100 << 16 ) | ROME_SOC_ID_00 ),
281     ROME_VER_1_1 = ((ROME_PATCH_VER_0101 << 16 ) | ROME_SOC_ID_00 ),
282     ROME_VER_1_3 = ((ROME_PATCH_VER_0200 << 16 ) | ROME_SOC_ID_00 ),
283     ROME_VER_2_1 = ((ROME_PATCH_VER_0200 << 16 ) | ROME_SOC_ID_11 ),
284     ROME_VER_3_0 = ((ROME_PATCH_VER_0300 << 16 ) | ROME_SOC_ID_22 ),
285     ROME_VER_3_2 = ((ROME_PATCH_VER_0302 << 16 ) | ROME_SOC_ID_44 )
286 };
287 #endif /* HW_ROME_H */
288