rmi_f34.h 7.0 KB

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