18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2007-2016, Synaptics Incorporated
48c2ecf20Sopenharmony_ci * Copyright (C) 2016 Zodiac Inflight Innovations
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef _RMI_F34_H
88c2ecf20Sopenharmony_ci#define _RMI_F34_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/* F34 image file offsets. */
118c2ecf20Sopenharmony_ci#define F34_FW_IMAGE_OFFSET	0x100
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* F34 register offsets. */
148c2ecf20Sopenharmony_ci#define F34_BLOCK_DATA_OFFSET	2
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/* F34 commands */
178c2ecf20Sopenharmony_ci#define F34_WRITE_FW_BLOCK	0x2
188c2ecf20Sopenharmony_ci#define F34_ERASE_ALL		0x3
198c2ecf20Sopenharmony_ci#define F34_READ_CONFIG_BLOCK	0x5
208c2ecf20Sopenharmony_ci#define F34_WRITE_CONFIG_BLOCK	0x6
218c2ecf20Sopenharmony_ci#define F34_ERASE_CONFIG	0x7
228c2ecf20Sopenharmony_ci#define F34_ENABLE_FLASH_PROG	0xf
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define F34_STATUS_IN_PROGRESS	0xff
258c2ecf20Sopenharmony_ci#define F34_STATUS_IDLE		0x80
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define F34_IDLE_WAIT_MS	500
288c2ecf20Sopenharmony_ci#define F34_ENABLE_WAIT_MS	300
298c2ecf20Sopenharmony_ci#define F34_ERASE_WAIT_MS	5000
308c2ecf20Sopenharmony_ci#define F34_WRITE_WAIT_MS	3000
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define F34_BOOTLOADER_ID_LEN	2
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* F34 V7 defines */
358c2ecf20Sopenharmony_ci#define V7_FLASH_STATUS_OFFSET		0
368c2ecf20Sopenharmony_ci#define V7_PARTITION_ID_OFFSET		1
378c2ecf20Sopenharmony_ci#define V7_BLOCK_NUMBER_OFFSET		2
388c2ecf20Sopenharmony_ci#define V7_TRANSFER_LENGTH_OFFSET	3
398c2ecf20Sopenharmony_ci#define V7_COMMAND_OFFSET		4
408c2ecf20Sopenharmony_ci#define V7_PAYLOAD_OFFSET		5
418c2ecf20Sopenharmony_ci#define V7_BOOTLOADER_ID_OFFSET		1
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define IMAGE_HEADER_VERSION_10		0x10
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define CONFIG_ID_SIZE			32
468c2ecf20Sopenharmony_ci#define PRODUCT_ID_SIZE			10
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define HAS_BSR				BIT(5)
508c2ecf20Sopenharmony_ci#define HAS_CONFIG_ID			BIT(3)
518c2ecf20Sopenharmony_ci#define HAS_GUEST_CODE			BIT(6)
528c2ecf20Sopenharmony_ci#define HAS_DISP_CFG			BIT(5)
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/* F34 V7 commands */
558c2ecf20Sopenharmony_ci#define CMD_V7_IDLE			0
568c2ecf20Sopenharmony_ci#define CMD_V7_ENTER_BL			1
578c2ecf20Sopenharmony_ci#define CMD_V7_READ			2
588c2ecf20Sopenharmony_ci#define CMD_V7_WRITE			3
598c2ecf20Sopenharmony_ci#define CMD_V7_ERASE			4
608c2ecf20Sopenharmony_ci#define CMD_V7_ERASE_AP			5
618c2ecf20Sopenharmony_ci#define CMD_V7_SENSOR_ID		6
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define v7_CMD_IDLE			0
648c2ecf20Sopenharmony_ci#define v7_CMD_WRITE_FW			1
658c2ecf20Sopenharmony_ci#define v7_CMD_WRITE_CONFIG		2
668c2ecf20Sopenharmony_ci#define v7_CMD_WRITE_LOCKDOWN		3
678c2ecf20Sopenharmony_ci#define v7_CMD_WRITE_GUEST_CODE		4
688c2ecf20Sopenharmony_ci#define v7_CMD_READ_CONFIG		5
698c2ecf20Sopenharmony_ci#define v7_CMD_ERASE_ALL		6
708c2ecf20Sopenharmony_ci#define v7_CMD_ERASE_UI_FIRMWARE	7
718c2ecf20Sopenharmony_ci#define v7_CMD_ERASE_UI_CONFIG		8
728c2ecf20Sopenharmony_ci#define v7_CMD_ERASE_BL_CONFIG		9
738c2ecf20Sopenharmony_ci#define v7_CMD_ERASE_DISP_CONFIG	10
748c2ecf20Sopenharmony_ci#define v7_CMD_ERASE_FLASH_CONFIG	11
758c2ecf20Sopenharmony_ci#define v7_CMD_ERASE_GUEST_CODE		12
768c2ecf20Sopenharmony_ci#define v7_CMD_ENABLE_FLASH_PROG	13
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define v7_UI_CONFIG_AREA		0
798c2ecf20Sopenharmony_ci#define v7_PM_CONFIG_AREA		1
808c2ecf20Sopenharmony_ci#define v7_BL_CONFIG_AREA		2
818c2ecf20Sopenharmony_ci#define v7_DP_CONFIG_AREA		3
828c2ecf20Sopenharmony_ci#define v7_FLASH_CONFIG_AREA		4
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/* F34 V7 partition IDs */
858c2ecf20Sopenharmony_ci#define BOOTLOADER_PARTITION		1
868c2ecf20Sopenharmony_ci#define DEVICE_CONFIG_PARTITION		2
878c2ecf20Sopenharmony_ci#define FLASH_CONFIG_PARTITION		3
888c2ecf20Sopenharmony_ci#define MANUFACTURING_BLOCK_PARTITION	4
898c2ecf20Sopenharmony_ci#define GUEST_SERIALIZATION_PARTITION	5
908c2ecf20Sopenharmony_ci#define GLOBAL_PARAMETERS_PARTITION	6
918c2ecf20Sopenharmony_ci#define CORE_CODE_PARTITION		7
928c2ecf20Sopenharmony_ci#define CORE_CONFIG_PARTITION		8
938c2ecf20Sopenharmony_ci#define GUEST_CODE_PARTITION		9
948c2ecf20Sopenharmony_ci#define DISPLAY_CONFIG_PARTITION	10
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/* F34 V7 container IDs */
978c2ecf20Sopenharmony_ci#define TOP_LEVEL_CONTAINER			0
988c2ecf20Sopenharmony_ci#define UI_CONTAINER				1
998c2ecf20Sopenharmony_ci#define UI_CONFIG_CONTAINER			2
1008c2ecf20Sopenharmony_ci#define BL_CONTAINER				3
1018c2ecf20Sopenharmony_ci#define BL_IMAGE_CONTAINER			4
1028c2ecf20Sopenharmony_ci#define BL_CONFIG_CONTAINER			5
1038c2ecf20Sopenharmony_ci#define BL_LOCKDOWN_INFO_CONTAINER		6
1048c2ecf20Sopenharmony_ci#define PERMANENT_CONFIG_CONTAINER		7
1058c2ecf20Sopenharmony_ci#define GUEST_CODE_CONTAINER			8
1068c2ecf20Sopenharmony_ci#define BL_PROTOCOL_DESCRIPTOR_CONTAINER	9
1078c2ecf20Sopenharmony_ci#define UI_PROTOCOL_DESCRIPTOR_CONTAINER	10
1088c2ecf20Sopenharmony_ci#define RMI_SELF_DISCOVERY_CONTAINER		11
1098c2ecf20Sopenharmony_ci#define RMI_PAGE_CONTENT_CONTAINER		12
1108c2ecf20Sopenharmony_ci#define GENERAL_INFORMATION_CONTAINER		13
1118c2ecf20Sopenharmony_ci#define DEVICE_CONFIG_CONTAINER			14
1128c2ecf20Sopenharmony_ci#define FLASH_CONFIG_CONTAINER			15
1138c2ecf20Sopenharmony_ci#define GUEST_SERIALIZATION_CONTAINER		16
1148c2ecf20Sopenharmony_ci#define GLOBAL_PARAMETERS_CONTAINER		17
1158c2ecf20Sopenharmony_ci#define CORE_CODE_CONTAINER			18
1168c2ecf20Sopenharmony_ci#define CORE_CONFIG_CONTAINER			19
1178c2ecf20Sopenharmony_ci#define DISPLAY_CONFIG_CONTAINER		20
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_cistruct f34v7_query_1_7 {
1208c2ecf20Sopenharmony_ci	u8 bl_minor_revision;			/* query 1 */
1218c2ecf20Sopenharmony_ci	u8 bl_major_revision;
1228c2ecf20Sopenharmony_ci	__le32 bl_fw_id;			/* query 2 */
1238c2ecf20Sopenharmony_ci	u8 minimum_write_size;			/* query 3 */
1248c2ecf20Sopenharmony_ci	__le16 block_size;
1258c2ecf20Sopenharmony_ci	__le16 flash_page_size;
1268c2ecf20Sopenharmony_ci	__le16 adjustable_partition_area_size;	/* query 4 */
1278c2ecf20Sopenharmony_ci	__le16 flash_config_length;		/* query 5 */
1288c2ecf20Sopenharmony_ci	__le16 payload_length;			/* query 6 */
1298c2ecf20Sopenharmony_ci	u8 partition_support[4];		/* query 7 */
1308c2ecf20Sopenharmony_ci} __packed;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistruct f34v7_data_1_5 {
1338c2ecf20Sopenharmony_ci	u8 partition_id;
1348c2ecf20Sopenharmony_ci	__le16 block_offset;
1358c2ecf20Sopenharmony_ci	__le16 transfer_length;
1368c2ecf20Sopenharmony_ci	u8 command;
1378c2ecf20Sopenharmony_ci	u8 payload[2];
1388c2ecf20Sopenharmony_ci} __packed;
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistruct block_data {
1418c2ecf20Sopenharmony_ci	const void *data;
1428c2ecf20Sopenharmony_ci	int size;
1438c2ecf20Sopenharmony_ci};
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistruct partition_table {
1468c2ecf20Sopenharmony_ci	u8 partition_id;
1478c2ecf20Sopenharmony_ci	u8 byte_1_reserved;
1488c2ecf20Sopenharmony_ci	__le16 partition_length;
1498c2ecf20Sopenharmony_ci	__le16 start_physical_address;
1508c2ecf20Sopenharmony_ci	__le16 partition_properties;
1518c2ecf20Sopenharmony_ci} __packed;
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_cistruct physical_address {
1548c2ecf20Sopenharmony_ci	u16 ui_firmware;
1558c2ecf20Sopenharmony_ci	u16 ui_config;
1568c2ecf20Sopenharmony_ci	u16 dp_config;
1578c2ecf20Sopenharmony_ci	u16 guest_code;
1588c2ecf20Sopenharmony_ci};
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cistruct container_descriptor {
1618c2ecf20Sopenharmony_ci	__le32 content_checksum;
1628c2ecf20Sopenharmony_ci	__le16 container_id;
1638c2ecf20Sopenharmony_ci	u8 minor_version;
1648c2ecf20Sopenharmony_ci	u8 major_version;
1658c2ecf20Sopenharmony_ci	u8 reserved_08;
1668c2ecf20Sopenharmony_ci	u8 reserved_09;
1678c2ecf20Sopenharmony_ci	u8 reserved_0a;
1688c2ecf20Sopenharmony_ci	u8 reserved_0b;
1698c2ecf20Sopenharmony_ci	u8 container_option_flags[4];
1708c2ecf20Sopenharmony_ci	__le32 content_options_length;
1718c2ecf20Sopenharmony_ci	__le32 content_options_address;
1728c2ecf20Sopenharmony_ci	__le32 content_length;
1738c2ecf20Sopenharmony_ci	__le32 content_address;
1748c2ecf20Sopenharmony_ci} __packed;
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_cistruct block_count {
1778c2ecf20Sopenharmony_ci	u16 ui_firmware;
1788c2ecf20Sopenharmony_ci	u16 ui_config;
1798c2ecf20Sopenharmony_ci	u16 dp_config;
1808c2ecf20Sopenharmony_ci	u16 fl_config;
1818c2ecf20Sopenharmony_ci	u16 pm_config;
1828c2ecf20Sopenharmony_ci	u16 bl_config;
1838c2ecf20Sopenharmony_ci	u16 lockdown;
1848c2ecf20Sopenharmony_ci	u16 guest_code;
1858c2ecf20Sopenharmony_ci};
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_cistruct image_header_10 {
1888c2ecf20Sopenharmony_ci	__le32 checksum;
1898c2ecf20Sopenharmony_ci	u8 reserved_04;
1908c2ecf20Sopenharmony_ci	u8 reserved_05;
1918c2ecf20Sopenharmony_ci	u8 minor_header_version;
1928c2ecf20Sopenharmony_ci	u8 major_header_version;
1938c2ecf20Sopenharmony_ci	u8 reserved_08;
1948c2ecf20Sopenharmony_ci	u8 reserved_09;
1958c2ecf20Sopenharmony_ci	u8 reserved_0a;
1968c2ecf20Sopenharmony_ci	u8 reserved_0b;
1978c2ecf20Sopenharmony_ci	__le32 top_level_container_start_addr;
1988c2ecf20Sopenharmony_ci};
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_cistruct image_metadata {
2018c2ecf20Sopenharmony_ci	bool contains_firmware_id;
2028c2ecf20Sopenharmony_ci	bool contains_bootloader;
2038c2ecf20Sopenharmony_ci	bool contains_display_cfg;
2048c2ecf20Sopenharmony_ci	bool contains_guest_code;
2058c2ecf20Sopenharmony_ci	bool contains_flash_config;
2068c2ecf20Sopenharmony_ci	unsigned int firmware_id;
2078c2ecf20Sopenharmony_ci	unsigned int checksum;
2088c2ecf20Sopenharmony_ci	unsigned int bootloader_size;
2098c2ecf20Sopenharmony_ci	unsigned int display_cfg_offset;
2108c2ecf20Sopenharmony_ci	unsigned char bl_version;
2118c2ecf20Sopenharmony_ci	unsigned char product_id[PRODUCT_ID_SIZE + 1];
2128c2ecf20Sopenharmony_ci	unsigned char cstmr_product_id[PRODUCT_ID_SIZE + 1];
2138c2ecf20Sopenharmony_ci	struct block_data bootloader;
2148c2ecf20Sopenharmony_ci	struct block_data ui_firmware;
2158c2ecf20Sopenharmony_ci	struct block_data ui_config;
2168c2ecf20Sopenharmony_ci	struct block_data dp_config;
2178c2ecf20Sopenharmony_ci	struct block_data fl_config;
2188c2ecf20Sopenharmony_ci	struct block_data bl_config;
2198c2ecf20Sopenharmony_ci	struct block_data guest_code;
2208c2ecf20Sopenharmony_ci	struct block_data lockdown;
2218c2ecf20Sopenharmony_ci	struct block_count blkcount;
2228c2ecf20Sopenharmony_ci	struct physical_address phyaddr;
2238c2ecf20Sopenharmony_ci};
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_cistruct register_offset {
2268c2ecf20Sopenharmony_ci	u8 properties;
2278c2ecf20Sopenharmony_ci	u8 properties_2;
2288c2ecf20Sopenharmony_ci	u8 block_size;
2298c2ecf20Sopenharmony_ci	u8 block_count;
2308c2ecf20Sopenharmony_ci	u8 gc_block_count;
2318c2ecf20Sopenharmony_ci	u8 flash_status;
2328c2ecf20Sopenharmony_ci	u8 partition_id;
2338c2ecf20Sopenharmony_ci	u8 block_number;
2348c2ecf20Sopenharmony_ci	u8 transfer_length;
2358c2ecf20Sopenharmony_ci	u8 flash_cmd;
2368c2ecf20Sopenharmony_ci	u8 payload;
2378c2ecf20Sopenharmony_ci};
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_cistruct rmi_f34_firmware {
2408c2ecf20Sopenharmony_ci	__le32 checksum;
2418c2ecf20Sopenharmony_ci	u8 pad1[3];
2428c2ecf20Sopenharmony_ci	u8 bootloader_version;
2438c2ecf20Sopenharmony_ci	__le32 image_size;
2448c2ecf20Sopenharmony_ci	__le32 config_size;
2458c2ecf20Sopenharmony_ci	u8 product_id[10];
2468c2ecf20Sopenharmony_ci	u8 product_info[2];
2478c2ecf20Sopenharmony_ci	u8 pad2[228];
2488c2ecf20Sopenharmony_ci	u8 data[];
2498c2ecf20Sopenharmony_ci};
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_cistruct f34v5_data {
2528c2ecf20Sopenharmony_ci	u16 block_size;
2538c2ecf20Sopenharmony_ci	u16 fw_blocks;
2548c2ecf20Sopenharmony_ci	u16 config_blocks;
2558c2ecf20Sopenharmony_ci	u16 ctrl_address;
2568c2ecf20Sopenharmony_ci	u8 status;
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci	struct completion cmd_done;
2598c2ecf20Sopenharmony_ci	struct mutex flash_mutex;
2608c2ecf20Sopenharmony_ci};
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_cistruct f34v7_data {
2638c2ecf20Sopenharmony_ci	bool has_display_cfg;
2648c2ecf20Sopenharmony_ci	bool has_guest_code;
2658c2ecf20Sopenharmony_ci	bool force_update;
2668c2ecf20Sopenharmony_ci	bool in_bl_mode;
2678c2ecf20Sopenharmony_ci	u8 *read_config_buf;
2688c2ecf20Sopenharmony_ci	size_t read_config_buf_size;
2698c2ecf20Sopenharmony_ci	u8 command;
2708c2ecf20Sopenharmony_ci	u8 flash_status;
2718c2ecf20Sopenharmony_ci	u16 block_size;
2728c2ecf20Sopenharmony_ci	u16 config_block_count;
2738c2ecf20Sopenharmony_ci	u16 config_size;
2748c2ecf20Sopenharmony_ci	u16 config_area;
2758c2ecf20Sopenharmony_ci	u16 flash_config_length;
2768c2ecf20Sopenharmony_ci	u16 payload_length;
2778c2ecf20Sopenharmony_ci	u8 partitions;
2788c2ecf20Sopenharmony_ci	u16 partition_table_bytes;
2798c2ecf20Sopenharmony_ci	bool new_partition_table;
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	struct register_offset off;
2828c2ecf20Sopenharmony_ci	struct block_count blkcount;
2838c2ecf20Sopenharmony_ci	struct physical_address phyaddr;
2848c2ecf20Sopenharmony_ci	struct image_metadata img;
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci	const void *config_data;
2878c2ecf20Sopenharmony_ci	const void *image;
2888c2ecf20Sopenharmony_ci	struct completion cmd_done;
2898c2ecf20Sopenharmony_ci};
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_cistruct f34_data {
2928c2ecf20Sopenharmony_ci	struct rmi_function *fn;
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	u8 bl_version;
2958c2ecf20Sopenharmony_ci	unsigned char bootloader_id[5];
2968c2ecf20Sopenharmony_ci	unsigned char configuration_id[CONFIG_ID_SIZE*2 + 1];
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci	int update_status;
2998c2ecf20Sopenharmony_ci	int update_progress;
3008c2ecf20Sopenharmony_ci	int update_size;
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	union {
3038c2ecf20Sopenharmony_ci		struct f34v5_data v5;
3048c2ecf20Sopenharmony_ci		struct f34v7_data v7;
3058c2ecf20Sopenharmony_ci	};
3068c2ecf20Sopenharmony_ci};
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ciint rmi_f34v7_start_reflash(struct f34_data *f34, const struct firmware *fw);
3098c2ecf20Sopenharmony_ciint rmi_f34v7_do_reflash(struct f34_data *f34, const struct firmware *fw);
3108c2ecf20Sopenharmony_ciint rmi_f34v7_probe(struct f34_data *f34);
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci#endif /* _RMI_F34_H */
313