xref: /OK3568_Linux_fs/kernel/sound/soc/codecs/aw883xx/aw_bin_parse.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 
3 #ifndef __AW_BIN_PARSE_H__
4 #define __AW_BIN_PARSE_H__
5 
6 #include "aw_device.h"
7 
8 #define NULL				((void *)0)
9 #define GET_32_DATA(w, x, y, z)		((unsigned int)((((uint8_t)w) << 24) | (((uint8_t)x) << 16) | (((uint8_t)y) << 8) | ((uint8_t)z)))
10 #define BIN_NUM_MAX			100
11 #define HEADER_LEN			60
12 /*********************************************************
13  *
14  * header information
15  *
16  ********************************************************/
17 enum return_enum {
18 	BIN_HEADER_VER_ERR = 1,
19 	BIN_DATA_TYPE_ERR = 2,
20 	BIN_DATA_LEN_ERR = 3,
21 	DATA_VER_ERR = 4,
22 	REG_NUM_ERR = 5,
23 	DSP_REG_NUM_ERR = 6,
24 	SOC_APP_NUM_ERR = 7,
25 	BIN_IS_NULL = 8,
26 };
27 
28 enum bin_header_version_enum {
29 	HEADER_VERSION_1_0_0 = 0x01000000,
30 };
31 
32 enum data_type_enum {
33 	DATA_TYPE_REGISTER = 0x00000000,
34 	DATA_TYPE_DSP_REG = 0x00000010,
35 	DATA_TYPE_DSP_CFG = 0x00000011,
36 	DATA_TYPE_SOC_REG = 0x00000020,
37 	DATA_TYPE_SOC_APP = 0x00000021,
38 	DATA_TYPE_DSP_FW = DATA_TYPE_SOC_APP,
39 	DATA_TYPE_MULTI_BINS = 0x00002000,
40 };
41 
42 /**
43  * @DATA_VERSION_V1:default little edian
44  */
45 enum data_version_enum {
46 	DATA_VERSION_V1 = 0X00000001,
47 	DATA_VERSION_MAX,
48 };
49 
50 /**
51  * @header_len: Frame header length
52  * @check_sum: Frame header information-Checksum
53  * @header_ver: Frame header information-Frame header version
54  * @bin_data_type: Frame header information-Data type
55  * @bin_data_ver: Frame header information-Data version
56  * @bin_data_len: Frame header information-Data length
57  * @ui_ver: Frame header information-ui version
58  * @chip_type[8]: Frame header information-chip type
59  * @reg_byte_len: Frame header information-reg byte len
60  * @data_byte_len: Frame header information-data byte len
61  * @device_addr: Frame header information-device addr
62  * @valid_data_len: Length of valid data obtained after parsing
63  * @valid_data_addr: The offset address of the valid data obtained
64  *                   after parsing relative to info
65  * @reg_num: The number of registers obtained after parsing
66  * @reg_data_byte_len: The byte length of the register obtained after parsing
67  * @download_addr: The starting address or download address obtained
68  *                 after parsing
69  * @app_version: The software version number obtained after parsing
70  */
71 struct bin_header_info {
72 	unsigned int header_len;
73 	unsigned int check_sum;
74 	unsigned int header_ver;
75 	unsigned int bin_data_type;
76 	unsigned int bin_data_ver;
77 	unsigned int bin_data_len;
78 	unsigned int ui_ver;
79 	unsigned char chip_type[8];
80 	unsigned int reg_byte_len;
81 	unsigned int data_byte_len;
82 	unsigned int device_addr;
83 	unsigned int valid_data_len;
84 	unsigned int valid_data_addr;
85 
86 	unsigned int reg_num;
87 	unsigned int reg_data_byte_len;
88 	unsigned int download_addr;
89 	unsigned int app_version;
90 };
91 
92 /************************************************************
93 *
94 * function define
95 *
96 ************************************************************/
97 /**
98  * @len: The size of the bin file obtained from the firmware
99  * @data[]: Store the bin file obtained from the firmware
100  */
101 struct bin_container {
102 	unsigned int len;
103 	unsigned char data[];
104 };
105 
106 /**
107  * @p_addr: Offset pointer (backward offset pointer to obtain frame header
108  *          information and important information)
109  * @all_bin_parse_num: The number of all bin files
110  * @multi_bin_parse_num: The number of single bin files
111  * @single_bin_parse_num: The number of multiple bin files
112  * @header_info[BIN_NUM_MAX]: Frame header information and other important data
113  *                            obtained after parsing
114  * @info: Obtained bin file data that needs to be parsed
115  */
116 struct aw_bin {
117 	unsigned char *p_addr;
118 	unsigned int all_bin_parse_num;
119 	unsigned int multi_bin_parse_num;
120 	unsigned int single_bin_parse_num;
121 	struct bin_header_info header_info[BIN_NUM_MAX];
122 	struct bin_container info;
123 };
124 
125 int aw_parsing_bin_file(struct aw_bin *bin);
126 int aw_parse_bin_header_1_0_0(struct aw_bin *bin);
127 
128 /*******************awinic audio parse acf***********************/
129 int aw_dev_dsp_data_order(struct aw_device *aw_dev,
130 				uint8_t *data, uint32_t data_len);
131 int aw_dev_get_prof_data(struct aw_device *aw_dev, int index,
132 			struct aw_prof_desc **prof_desc);
133 char *aw_dev_get_prof_name(struct aw_device *aw_dev, int index);
134 int aw_dev_set_profile_index(struct aw_device *aw_dev, int index);
135 int aw_dev_get_profile_index(struct aw_device *aw_dev);
136 int aw_dev_check_profile_index(struct aw_device *aw_dev, int index);
137 int aw_dev_get_profile_count(struct aw_device *aw_dev);
138 int aw_dev_cfg_load(struct aw_device *aw_dev, struct aw_container *aw_cfg);
139 int aw_dev_load_acf_check(struct aw_container *aw_cfg);
140 
141 #endif
142