rmi_f34.h 7.1 KB

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