1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef AUDIO_PARSE_H
10 #define AUDIO_PARSE_H
11 
12 #include "audio_host.h"
13 #include "audio_control.h"
14 
15 #ifdef __cplusplus
16 #if __cplusplus
17 extern "C" {
18 #endif
19 #endif /* __cplusplus */
20 
21 #define AUDIO_CONFIG_MAX_ITEM 500
22 #define AUDIO_CTRL_LIST_MAX 100
23 #define AUDIO_SAPM_COMP_NAME_LIST_MAX 100
24 #define AUDIO_SAPM_CFG_NAME_LIST_MAX 100
25 
26 enum AudioRegOpsType {
27     AUDIO_RSET_GROUP = 0,
28     AUDIO_INIT_GROUP,
29     AUDIO_CTRL_PATAM_GROUP,
30     AUDIO_CTRL_PATAM_MUX_GROUP,
31     AUDIO_CTRL_SAPM_PATAM_GROUP,
32     AUDIO_CTRL_SAPM_PATAM_MUX_GROUP,
33     AUDIO_DAI_STARTUP_PATAM_GROUP,
34     AUDIO_DAI_PATAM_GROUP,
35     AUDIO_DAI_TRIGGER_GROUP,
36     AUDIO_CTRL_CFG_GROUP,
37     AUDIO_SAPM_COMP_GROUP,
38     AUDIO_SAPM_CFG_GROUP,
39     AUDIO_GROUP_MAX
40 };
41 
42 enum AudioControlType {
43     AUDIO_CONTROL_MIXER = 0,
44     AUDIO_CONTROL_MUX,
45 };
46 
47 struct AudioIdInfo {
48     const char *chipName;
49     uint32_t chipIdRegister;
50     uint32_t chipIdSize;
51 };
52 
53 struct AudioControlConfig {
54     uint16_t arrayIndex;
55     uint16_t iface;
56     uint16_t type;
57     uint8_t enable;
58 };
59 
60 struct AudioAddrConfig {
61     uint32_t addr;
62     uint32_t value;
63 };
64 
65 struct AudioSapmCtrlConfig {
66     uint8_t sapmType;
67     uint16_t compNameIndex;
68     uint32_t reg;
69     uint32_t mask;
70     uint8_t shift;
71     uint8_t invert;
72     uint32_t kcontrolNews;
73     uint32_t kcontrolsNum;
74 };
75 
76 /* enumerated kcontrol */
77 struct AudioEnumCtrlConfig {
78     uint32_t reg;
79     uint32_t reg2;
80     uint8_t shiftLeft;
81     uint8_t shiftRight;
82     uint32_t max;
83     uint32_t mask;
84     uint32_t texts;
85     uint32_t values;
86     uint32_t sapm;
87 };
88 
89 struct AudioRegCfgGroupNode {
90     uint8_t itemNum;
91     enum AudioRegOpsType groupIndex;
92     struct AudioAddrConfig *addrCfgItem;
93     struct AudioMixerControl *regCfgItem;
94     struct AudioEnumCtrlConfig *regEnumCfgItem;
95     struct AudioControlConfig *ctrlCfgItem;
96     struct AudioSapmCtrlConfig *sapmCompItem;
97 };
98 
99 struct AudioRegCfgData {
100     struct AudioIdInfo audioIdInfo;
101     struct AudioRegCfgGroupNode *audioRegParams[AUDIO_GROUP_MAX];
102 };
103 
104 int32_t AudioFillConfigData(const struct HdfDeviceObject *device, struct AudioConfigData *configData);
105 
106 int32_t AudioGetRegConfig(const struct HdfDeviceObject *device, struct AudioRegCfgData *configData);
107 
108 int32_t AudioGetPortConfig(const struct HdfDeviceObject *device, struct AudioPortInfo *configData);
109 
110 #ifdef __cplusplus
111 #if __cplusplus
112 }
113 #endif
114 #endif /* __cplusplus */
115 
116 #endif /* AUDIO_PARSE_H */
117