blob: 2c21056dc37514f7336df0c8c4b8a3b9c1edf0f1 [file] [log] [blame]
Nick Dyer29fd0ec2016-11-22 17:44:12 -08001/*
2 * Copyright (c) 2007-2016, Synaptics Incorporated
3 * Copyright (C) 2016 Zodiac Inflight Innovations
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 */
9
10#ifndef _RMI_F34_H
11#define _RMI_F34_H
12
13/* F34 image file offsets. */
14#define F34_FW_IMAGE_OFFSET 0x100
15
16/* F34 register offsets. */
17#define F34_BLOCK_DATA_OFFSET 2
18
19/* F34 commands */
20#define F34_WRITE_FW_BLOCK 0x2
21#define F34_ERASE_ALL 0x3
22#define F34_READ_CONFIG_BLOCK 0x5
23#define F34_WRITE_CONFIG_BLOCK 0x6
24#define F34_ERASE_CONFIG 0x7
25#define F34_ENABLE_FLASH_PROG 0xf
26
27#define F34_STATUS_IN_PROGRESS 0xff
28#define F34_STATUS_IDLE 0x80
29
30#define F34_IDLE_WAIT_MS 500
31#define F34_ENABLE_WAIT_MS 300
32#define F34_ERASE_WAIT_MS 5000
33
34#define F34_BOOTLOADER_ID_LEN 2
35
Nick Dyer5191d88a2016-12-10 23:27:32 -080036/* F34 V7 defines */
37#define V7_FLASH_STATUS_OFFSET 0
38#define V7_PARTITION_ID_OFFSET 1
39#define V7_BLOCK_NUMBER_OFFSET 2
40#define V7_TRANSFER_LENGTH_OFFSET 3
41#define V7_COMMAND_OFFSET 4
42#define V7_PAYLOAD_OFFSET 5
43#define V7_BOOTLOADER_ID_OFFSET 1
44
45#define IMAGE_HEADER_VERSION_10 0x10
46
47#define CONFIG_ID_SIZE 32
48#define PRODUCT_ID_SIZE 10
49
50#define ENABLE_WAIT_MS (1 * 1000)
51#define WRITE_WAIT_MS (3 * 1000)
52
53#define MIN_SLEEP_TIME_US 50
54#define MAX_SLEEP_TIME_US 100
55
56#define HAS_BSR BIT(5)
57#define HAS_CONFIG_ID BIT(3)
58#define HAS_GUEST_CODE BIT(6)
59#define HAS_DISP_CFG BIT(5)
60
61/* F34 V7 commands */
62#define CMD_V7_IDLE 0
63#define CMD_V7_ENTER_BL 1
64#define CMD_V7_READ 2
65#define CMD_V7_WRITE 3
66#define CMD_V7_ERASE 4
67#define CMD_V7_ERASE_AP 5
68#define CMD_V7_SENSOR_ID 6
69
70#define v7_CMD_IDLE 0
71#define v7_CMD_WRITE_FW 1
72#define v7_CMD_WRITE_CONFIG 2
73#define v7_CMD_WRITE_LOCKDOWN 3
74#define v7_CMD_WRITE_GUEST_CODE 4
75#define v7_CMD_READ_CONFIG 5
76#define v7_CMD_ERASE_ALL 6
77#define v7_CMD_ERASE_UI_FIRMWARE 7
78#define v7_CMD_ERASE_UI_CONFIG 8
79#define v7_CMD_ERASE_BL_CONFIG 9
80#define v7_CMD_ERASE_DISP_CONFIG 10
81#define v7_CMD_ERASE_FLASH_CONFIG 11
82#define v7_CMD_ERASE_GUEST_CODE 12
83#define v7_CMD_ENABLE_FLASH_PROG 13
84
85#define v7_UI_CONFIG_AREA 0
86#define v7_PM_CONFIG_AREA 1
87#define v7_BL_CONFIG_AREA 2
88#define v7_DP_CONFIG_AREA 3
89#define v7_FLASH_CONFIG_AREA 4
90
91/* F34 V7 partition IDs */
92#define BOOTLOADER_PARTITION 1
93#define DEVICE_CONFIG_PARTITION 2
94#define FLASH_CONFIG_PARTITION 3
95#define MANUFACTURING_BLOCK_PARTITION 4
96#define GUEST_SERIALIZATION_PARTITION 5
97#define GLOBAL_PARAMETERS_PARTITION 6
98#define CORE_CODE_PARTITION 7
99#define CORE_CONFIG_PARTITION 8
100#define GUEST_CODE_PARTITION 9
101#define DISPLAY_CONFIG_PARTITION 10
102
103/* F34 V7 container IDs */
104#define TOP_LEVEL_CONTAINER 0
105#define UI_CONTAINER 1
106#define UI_CONFIG_CONTAINER 2
107#define BL_CONTAINER 3
108#define BL_IMAGE_CONTAINER 4
109#define BL_CONFIG_CONTAINER 5
110#define BL_LOCKDOWN_INFO_CONTAINER 6
111#define PERMANENT_CONFIG_CONTAINER 7
112#define GUEST_CODE_CONTAINER 8
113#define BL_PROTOCOL_DESCRIPTOR_CONTAINER 9
114#define UI_PROTOCOL_DESCRIPTOR_CONTAINER 10
115#define RMI_SELF_DISCOVERY_CONTAINER 11
116#define RMI_PAGE_CONTENT_CONTAINER 12
117#define GENERAL_INFORMATION_CONTAINER 13
118#define DEVICE_CONFIG_CONTAINER 14
119#define FLASH_CONFIG_CONTAINER 15
120#define GUEST_SERIALIZATION_CONTAINER 16
121#define GLOBAL_PARAMETERS_CONTAINER 17
122#define CORE_CODE_CONTAINER 18
123#define CORE_CONFIG_CONTAINER 19
124#define DISPLAY_CONFIG_CONTAINER 20
125
126struct f34v7_query_1_7 {
127 u8 bl_minor_revision; /* query 1 */
128 u8 bl_major_revision;
129 __le32 bl_fw_id; /* query 2 */
130 u8 minimum_write_size; /* query 3 */
131 __le16 block_size;
132 __le16 flash_page_size;
133 __le16 adjustable_partition_area_size; /* query 4 */
134 __le16 flash_config_length; /* query 5 */
135 __le16 payload_length; /* query 6 */
136 u8 partition_support[4]; /* query 7 */
137} __packed;
138
139struct f34v7_data_1_5 {
140 u8 partition_id;
141 __le16 block_offset;
142 __le16 transfer_length;
143 u8 command;
144 u8 payload[2];
145} __packed;
146
147struct block_data {
148 const void *data;
149 int size;
150};
151
152struct partition_table {
153 u8 partition_id;
154 u8 byte_1_reserved;
155 __le16 partition_length;
156 __le16 start_physical_address;
157 __le16 partition_properties;
158} __packed;
159
160struct physical_address {
161 u16 ui_firmware;
162 u16 ui_config;
163 u16 dp_config;
164 u16 guest_code;
165};
166
167struct container_descriptor {
168 __le32 content_checksum;
169 __le16 container_id;
170 u8 minor_version;
171 u8 major_version;
172 u8 reserved_08;
173 u8 reserved_09;
174 u8 reserved_0a;
175 u8 reserved_0b;
176 u8 container_option_flags[4];
177 __le32 content_options_length;
178 __le32 content_options_address;
179 __le32 content_length;
180 __le32 content_address;
181} __packed;
182
183struct block_count {
184 u16 ui_firmware;
185 u16 ui_config;
186 u16 dp_config;
187 u16 fl_config;
188 u16 pm_config;
189 u16 bl_config;
190 u16 lockdown;
191 u16 guest_code;
192};
193
194struct image_header_10 {
195 __le32 checksum;
196 u8 reserved_04;
197 u8 reserved_05;
198 u8 minor_header_version;
199 u8 major_header_version;
200 u8 reserved_08;
201 u8 reserved_09;
202 u8 reserved_0a;
203 u8 reserved_0b;
204 __le32 top_level_container_start_addr;
205};
206
207struct image_metadata {
208 bool contains_firmware_id;
209 bool contains_bootloader;
210 bool contains_display_cfg;
211 bool contains_guest_code;
212 bool contains_flash_config;
213 unsigned int firmware_id;
214 unsigned int checksum;
215 unsigned int bootloader_size;
216 unsigned int display_cfg_offset;
217 unsigned char bl_version;
218 unsigned char product_id[PRODUCT_ID_SIZE + 1];
219 unsigned char cstmr_product_id[PRODUCT_ID_SIZE + 1];
220 struct block_data bootloader;
221 struct block_data ui_firmware;
222 struct block_data ui_config;
223 struct block_data dp_config;
224 struct block_data fl_config;
225 struct block_data bl_config;
226 struct block_data guest_code;
227 struct block_data lockdown;
228 struct block_count blkcount;
229 struct physical_address phyaddr;
230};
231
232struct register_offset {
233 u8 properties;
234 u8 properties_2;
235 u8 block_size;
236 u8 block_count;
237 u8 gc_block_count;
238 u8 flash_status;
239 u8 partition_id;
240 u8 block_number;
241 u8 transfer_length;
242 u8 flash_cmd;
243 u8 payload;
244};
245
Nick Dyer29fd0ec2016-11-22 17:44:12 -0800246struct rmi_f34_firmware {
247 __le32 checksum;
248 u8 pad1[3];
249 u8 bootloader_version;
250 __le32 image_size;
251 __le32 config_size;
252 u8 product_id[10];
253 u8 product_info[2];
254 u8 pad2[228];
255 u8 data[];
256};
257
258struct f34v5_data {
259 u16 block_size;
260 u16 fw_blocks;
261 u16 config_blocks;
262 u16 ctrl_address;
263 u8 status;
264
265 struct completion cmd_done;
266 struct mutex flash_mutex;
267};
268
Nick Dyer5191d88a2016-12-10 23:27:32 -0800269struct f34v7_data {
270 bool has_display_cfg;
271 bool has_guest_code;
272 bool force_update;
273 bool in_bl_mode;
274 u8 *read_config_buf;
275 size_t read_config_buf_size;
276 u8 command;
277 u8 flash_status;
278 u16 block_size;
279 u16 config_block_count;
280 u16 config_size;
281 u16 config_area;
282 u16 flash_config_length;
283 u16 payload_length;
284 u8 partitions;
285 u16 partition_table_bytes;
286 bool new_partition_table;
287
288 struct register_offset off;
289 struct block_count blkcount;
290 struct physical_address phyaddr;
291 struct image_metadata img;
292
293 const void *config_data;
294 const void *image;
295};
296
Nick Dyer29fd0ec2016-11-22 17:44:12 -0800297struct f34_data {
298 struct rmi_function *fn;
299
Nick Dyer5191d88a2016-12-10 23:27:32 -0800300 u8 bl_version;
Nick Dyer29fd0ec2016-11-22 17:44:12 -0800301 unsigned char bootloader_id[5];
Nick Dyer5191d88a2016-12-10 23:27:32 -0800302 unsigned char configuration_id[CONFIG_ID_SIZE*2 + 1];
Nick Dyer29fd0ec2016-11-22 17:44:12 -0800303
Nick Dyer5191d88a2016-12-10 23:27:32 -0800304 union {
305 struct f34v5_data v5;
306 struct f34v7_data v7;
307 };
Nick Dyer29fd0ec2016-11-22 17:44:12 -0800308};
309
Nick Dyer5191d88a2016-12-10 23:27:32 -0800310int rmi_f34v7_start_reflash(struct f34_data *f34, const struct firmware *fw);
311int rmi_f34v7_do_reflash(struct f34_data *f34, const struct firmware *fw);
312int rmi_f34v7_probe(struct f34_data *f34);
313
Nick Dyer29fd0ec2016-11-22 17:44:12 -0800314#endif /* _RMI_F34_H */