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