GNU Linux-libre 4.14.251-gnu1
[releases.git] / drivers / input / rmi4 / rmi_f34.h
1 /*
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 #define F34_WRITE_WAIT_MS       3000
34
35 #define F34_BOOTLOADER_ID_LEN   2
36
37 /* F34 V7 defines */
38 #define V7_FLASH_STATUS_OFFSET          0
39 #define V7_PARTITION_ID_OFFSET          1
40 #define V7_BLOCK_NUMBER_OFFSET          2
41 #define V7_TRANSFER_LENGTH_OFFSET       3
42 #define V7_COMMAND_OFFSET               4
43 #define V7_PAYLOAD_OFFSET               5
44 #define V7_BOOTLOADER_ID_OFFSET         1
45
46 #define IMAGE_HEADER_VERSION_10         0x10
47
48 #define CONFIG_ID_SIZE                  32
49 #define PRODUCT_ID_SIZE                 10
50
51
52 #define HAS_BSR                         BIT(5)
53 #define HAS_CONFIG_ID                   BIT(3)
54 #define HAS_GUEST_CODE                  BIT(6)
55 #define HAS_DISP_CFG                    BIT(5)
56
57 /* F34 V7 commands */
58 #define CMD_V7_IDLE                     0
59 #define CMD_V7_ENTER_BL                 1
60 #define CMD_V7_READ                     2
61 #define CMD_V7_WRITE                    3
62 #define CMD_V7_ERASE                    4
63 #define CMD_V7_ERASE_AP                 5
64 #define CMD_V7_SENSOR_ID                6
65
66 #define v7_CMD_IDLE                     0
67 #define v7_CMD_WRITE_FW                 1
68 #define v7_CMD_WRITE_CONFIG             2
69 #define v7_CMD_WRITE_LOCKDOWN           3
70 #define v7_CMD_WRITE_GUEST_CODE         4
71 #define v7_CMD_READ_CONFIG              5
72 #define v7_CMD_ERASE_ALL                6
73 #define v7_CMD_ERASE_UI_FIRMWARE        7
74 #define v7_CMD_ERASE_UI_CONFIG          8
75 #define v7_CMD_ERASE_BL_CONFIG          9
76 #define v7_CMD_ERASE_DISP_CONFIG        10
77 #define v7_CMD_ERASE_FLASH_CONFIG       11
78 #define v7_CMD_ERASE_GUEST_CODE         12
79 #define v7_CMD_ENABLE_FLASH_PROG        13
80
81 #define v7_UI_CONFIG_AREA               0
82 #define v7_PM_CONFIG_AREA               1
83 #define v7_BL_CONFIG_AREA               2
84 #define v7_DP_CONFIG_AREA               3
85 #define v7_FLASH_CONFIG_AREA            4
86
87 /* F34 V7 partition IDs */
88 #define BOOTLOADER_PARTITION            1
89 #define DEVICE_CONFIG_PARTITION         2
90 #define FLASH_CONFIG_PARTITION          3
91 #define MANUFACTURING_BLOCK_PARTITION   4
92 #define GUEST_SERIALIZATION_PARTITION   5
93 #define GLOBAL_PARAMETERS_PARTITION     6
94 #define CORE_CODE_PARTITION             7
95 #define CORE_CONFIG_PARTITION           8
96 #define GUEST_CODE_PARTITION            9
97 #define DISPLAY_CONFIG_PARTITION        10
98
99 /* F34 V7 container IDs */
100 #define TOP_LEVEL_CONTAINER                     0
101 #define UI_CONTAINER                            1
102 #define UI_CONFIG_CONTAINER                     2
103 #define BL_CONTAINER                            3
104 #define BL_IMAGE_CONTAINER                      4
105 #define BL_CONFIG_CONTAINER                     5
106 #define BL_LOCKDOWN_INFO_CONTAINER              6
107 #define PERMANENT_CONFIG_CONTAINER              7
108 #define GUEST_CODE_CONTAINER                    8
109 #define BL_PROTOCOL_DESCRIPTOR_CONTAINER        9
110 #define UI_PROTOCOL_DESCRIPTOR_CONTAINER        10
111 #define RMI_SELF_DISCOVERY_CONTAINER            11
112 #define RMI_PAGE_CONTENT_CONTAINER              12
113 #define GENERAL_INFORMATION_CONTAINER           13
114 #define DEVICE_CONFIG_CONTAINER                 14
115 #define FLASH_CONFIG_CONTAINER                  15
116 #define GUEST_SERIALIZATION_CONTAINER           16
117 #define GLOBAL_PARAMETERS_CONTAINER             17
118 #define CORE_CODE_CONTAINER                     18
119 #define CORE_CONFIG_CONTAINER                   19
120 #define DISPLAY_CONFIG_CONTAINER                20
121
122 struct f34v7_query_1_7 {
123         u8 bl_minor_revision;                   /* query 1 */
124         u8 bl_major_revision;
125         __le32 bl_fw_id;                        /* query 2 */
126         u8 minimum_write_size;                  /* query 3 */
127         __le16 block_size;
128         __le16 flash_page_size;
129         __le16 adjustable_partition_area_size;  /* query 4 */
130         __le16 flash_config_length;             /* query 5 */
131         __le16 payload_length;                  /* query 6 */
132         u8 partition_support[4];                /* query 7 */
133 } __packed;
134
135 struct f34v7_data_1_5 {
136         u8 partition_id;
137         __le16 block_offset;
138         __le16 transfer_length;
139         u8 command;
140         u8 payload[2];
141 } __packed;
142
143 struct block_data {
144         const void *data;
145         int size;
146 };
147
148 struct partition_table {
149         u8 partition_id;
150         u8 byte_1_reserved;
151         __le16 partition_length;
152         __le16 start_physical_address;
153         __le16 partition_properties;
154 } __packed;
155
156 struct physical_address {
157         u16 ui_firmware;
158         u16 ui_config;
159         u16 dp_config;
160         u16 guest_code;
161 };
162
163 struct container_descriptor {
164         __le32 content_checksum;
165         __le16 container_id;
166         u8 minor_version;
167         u8 major_version;
168         u8 reserved_08;
169         u8 reserved_09;
170         u8 reserved_0a;
171         u8 reserved_0b;
172         u8 container_option_flags[4];
173         __le32 content_options_length;
174         __le32 content_options_address;
175         __le32 content_length;
176         __le32 content_address;
177 } __packed;
178
179 struct block_count {
180         u16 ui_firmware;
181         u16 ui_config;
182         u16 dp_config;
183         u16 fl_config;
184         u16 pm_config;
185         u16 bl_config;
186         u16 lockdown;
187         u16 guest_code;
188 };
189
190 struct image_header_10 {
191         __le32 checksum;
192         u8 reserved_04;
193         u8 reserved_05;
194         u8 minor_header_version;
195         u8 major_header_version;
196         u8 reserved_08;
197         u8 reserved_09;
198         u8 reserved_0a;
199         u8 reserved_0b;
200         __le32 top_level_container_start_addr;
201 };
202
203 struct image_metadata {
204         bool contains_firmware_id;
205         bool contains_bootloader;
206         bool contains_display_cfg;
207         bool contains_guest_code;
208         bool contains_flash_config;
209         unsigned int firmware_id;
210         unsigned int checksum;
211         unsigned int bootloader_size;
212         unsigned int display_cfg_offset;
213         unsigned char bl_version;
214         unsigned char product_id[PRODUCT_ID_SIZE + 1];
215         unsigned char cstmr_product_id[PRODUCT_ID_SIZE + 1];
216         struct block_data bootloader;
217         struct block_data ui_firmware;
218         struct block_data ui_config;
219         struct block_data dp_config;
220         struct block_data fl_config;
221         struct block_data bl_config;
222         struct block_data guest_code;
223         struct block_data lockdown;
224         struct block_count blkcount;
225         struct physical_address phyaddr;
226 };
227
228 struct register_offset {
229         u8 properties;
230         u8 properties_2;
231         u8 block_size;
232         u8 block_count;
233         u8 gc_block_count;
234         u8 flash_status;
235         u8 partition_id;
236         u8 block_number;
237         u8 transfer_length;
238         u8 flash_cmd;
239         u8 payload;
240 };
241
242 struct rmi_f34_firmware {
243         __le32 checksum;
244         u8 pad1[3];
245         u8 bootloader_version;
246         __le32 image_size;
247         __le32 config_size;
248         u8 product_id[10];
249         u8 product_info[2];
250         u8 pad2[228];
251         u8 data[];
252 };
253
254 struct f34v5_data {
255         u16 block_size;
256         u16 fw_blocks;
257         u16 config_blocks;
258         u16 ctrl_address;
259         u8 status;
260
261         struct completion cmd_done;
262         struct mutex flash_mutex;
263 };
264
265 struct f34v7_data {
266         bool has_display_cfg;
267         bool has_guest_code;
268         bool force_update;
269         bool in_bl_mode;
270         u8 *read_config_buf;
271         size_t read_config_buf_size;
272         u8 command;
273         u8 flash_status;
274         u16 block_size;
275         u16 config_block_count;
276         u16 config_size;
277         u16 config_area;
278         u16 flash_config_length;
279         u16 payload_length;
280         u8 partitions;
281         u16 partition_table_bytes;
282         bool new_partition_table;
283
284         struct register_offset off;
285         struct block_count blkcount;
286         struct physical_address phyaddr;
287         struct image_metadata img;
288
289         const void *config_data;
290         const void *image;
291         struct completion cmd_done;
292 };
293
294 struct f34_data {
295         struct rmi_function *fn;
296
297         u8 bl_version;
298         unsigned char bootloader_id[5];
299         unsigned char configuration_id[CONFIG_ID_SIZE*2 + 1];
300
301         int update_status;
302         int update_progress;
303         int update_size;
304
305         union {
306                 struct f34v5_data v5;
307                 struct f34v7_data v7;
308         };
309 };
310
311 int rmi_f34v7_start_reflash(struct f34_data *f34, const struct firmware *fw);
312 int rmi_f34v7_do_reflash(struct f34_data *f34, const struct firmware *fw);
313 int rmi_f34v7_probe(struct f34_data *f34);
314
315 #endif /* _RMI_F34_H */