xref: /OK3568_Linux_fs/kernel/sound/soc/codecs/aw87xxx/aw_bin_parse.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0+ */
2*4882a593Smuzhiyun 
3*4882a593Smuzhiyun #ifndef __AW_BIN_PARSE_H__
4*4882a593Smuzhiyun #define __AW_BIN_PARSE_H__
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun #define NULL    ((void *)0)
7*4882a593Smuzhiyun #define GET_32_DATA(w, x, y, z) ((unsigned int)(((w) << 24) | ((x) << 16) | ((y) << 8) | (z)))
8*4882a593Smuzhiyun #define BIN_NUM_MAX   100
9*4882a593Smuzhiyun #define HEADER_LEN    60
10*4882a593Smuzhiyun /*********************************************************
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * header information
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  ********************************************************/
15*4882a593Smuzhiyun enum bin_header_version_enum {
16*4882a593Smuzhiyun 	HEADER_VERSION_1_0_0 = 0x01000000,
17*4882a593Smuzhiyun };
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun enum data_type_enum {
20*4882a593Smuzhiyun 	DATA_TYPE_REGISTER = 0x00000000,
21*4882a593Smuzhiyun 	DATA_TYPE_DSP_REG = 0x00000010,
22*4882a593Smuzhiyun 	DATA_TYPE_DSP_CFG = 0x00000011,
23*4882a593Smuzhiyun 	DATA_TYPE_SOC_REG = 0x00000020,
24*4882a593Smuzhiyun 	DATA_TYPE_SOC_APP = 0x00000021,
25*4882a593Smuzhiyun 	DATA_TYPE_MULTI_BINS = 0x00002000,
26*4882a593Smuzhiyun 	DATA_TYPE_MONITOR_ANALOG = 0x00020000,
27*4882a593Smuzhiyun };
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun enum data_version_enum {
30*4882a593Smuzhiyun 	DATA_VERSION_V1 = 0X00000001,	/*default little edian */
31*4882a593Smuzhiyun 	DATA_VERSION_MAX,
32*4882a593Smuzhiyun };
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun struct bin_header_info {
35*4882a593Smuzhiyun 	unsigned int header_len; /* Frame header length */
36*4882a593Smuzhiyun 	unsigned int check_sum; /* Frame header information-Checksum */
37*4882a593Smuzhiyun 	unsigned int header_ver; /* Frame header information-Frame header version */
38*4882a593Smuzhiyun 	unsigned int bin_data_type; /* Frame header information-Data type */
39*4882a593Smuzhiyun 	unsigned int bin_data_ver; /* Frame header information-Data version */
40*4882a593Smuzhiyun 	unsigned int bin_data_len; /* Frame header information-Data length */
41*4882a593Smuzhiyun 	unsigned int ui_ver; /* Frame header information-ui version */
42*4882a593Smuzhiyun 	unsigned char chip_type[8]; /* Frame header information-chip type */
43*4882a593Smuzhiyun 	unsigned int reg_byte_len; /* Frame header information-reg byte len */
44*4882a593Smuzhiyun 	unsigned int data_byte_len; /* Frame header information-data byte len */
45*4882a593Smuzhiyun 	unsigned int device_addr; /* Frame header information-device addr */
46*4882a593Smuzhiyun 	unsigned int valid_data_len; /* Length of valid data obtained after parsing */
47*4882a593Smuzhiyun 	unsigned int valid_data_addr; /* The offset address of the valid data obtained after parsing relative to info */
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun 	unsigned int reg_num; /* The number of registers obtained after parsing */
50*4882a593Smuzhiyun 	unsigned int reg_data_byte_len; /* The byte length of the register obtained after parsing */
51*4882a593Smuzhiyun 	unsigned int download_addr; /* The starting address or download address obtained after parsing */
52*4882a593Smuzhiyun 	unsigned int app_version; /* The software version number obtained after parsing */
53*4882a593Smuzhiyun };
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun /************************************************************
56*4882a593Smuzhiyun *
57*4882a593Smuzhiyun * function define
58*4882a593Smuzhiyun *
59*4882a593Smuzhiyun ************************************************************/
60*4882a593Smuzhiyun struct bin_container {
61*4882a593Smuzhiyun 	unsigned int len; /* The size of the bin file obtained from the firmware */
62*4882a593Smuzhiyun 	unsigned char data[]; /* Store the bin file obtained from the firmware */
63*4882a593Smuzhiyun };
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun struct aw_bin {
66*4882a593Smuzhiyun 	char *p_addr; /* Offset pointer (backward offset pointer to obtain frame header information and important information) */
67*4882a593Smuzhiyun 	unsigned int all_bin_parse_num; /* The number of all bin files */
68*4882a593Smuzhiyun 	unsigned int multi_bin_parse_num; /* The number of single bin files */
69*4882a593Smuzhiyun 	unsigned int single_bin_parse_num; /* The number of multiple bin files */
70*4882a593Smuzhiyun 	struct bin_header_info header_info[BIN_NUM_MAX]; /* Frame header information and other important data obtained after parsing */
71*4882a593Smuzhiyun 	struct bin_container info; /* Obtained bin file data that needs to be parsed */
72*4882a593Smuzhiyun };
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun extern int aw_parsing_bin_file(struct aw_bin *bin);
75*4882a593Smuzhiyun int aw_parse_bin_header_1_0_0(struct aw_bin *bin);
76*4882a593Smuzhiyun #endif
77