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_DSP_IF_H
10 #define AUDIO_DSP_IF_H
11 #include "audio_host.h"
12 #ifdef __cplusplus
13 #if __cplusplus
14 extern "C" {
15 #endif
16 #endif /* __cplusplus */
17 
18 /**
19  * @brief Defines Dsp device name and data.
20  *
21  * @since 1.0
22  * @version 1.0
23  */
24 struct DspDevice {
25     const char *devDspName;         /**< Dsp device name */
26     struct DspData *devData;        /**< Dsp module private data */
27     struct HdfDeviceObject *device; /**< HDF device */
28     struct DListHead list;          /**< Dsp list */
29 };
30 
31 /**
32  * @brief Defines Dsp operation function set.
33  *
34  * @since 1.0
35  * @version 1.0
36  */
37 struct AudioDspOps {
38     /**
39      * @brief Defines Dsp device start up function.
40      *
41      * @param audioCard Indicates an audio card device.
42      * @param dsp Indicates a dsp device.
43      *
44      * @return Returns <b>0</b> if Dsp device start up success; returns a non-zero value otherwise.
45      *
46      * @since 1.0
47      * @version 1.0
48      */
49     int32_t (*Startup)(const struct AudioCard *audioCard, const struct DspDevice *dsp);
50 
51     /**
52      * @brief Defines Dsp device hardware param function.
53      *
54      * @param audioCard Indicates an audio card device.
55      * @param param Indicates pcm params set.
56      *
57      * @return Returns <b>0</b> if dsp param set success; returns a non-zero value otherwise.
58      *
59      * @since 1.0
60      * @version 1.0
61      */
62     int32_t (*HwParams)(const struct AudioCard *audioCard, const struct AudioPcmHwParams *param);
63 
64     /**
65      * @brief Defines Dsp device trigger function.
66      *
67      * @param audioCard Indicates an audio card device.
68      * @param dsp Indicates a dsp device.
69      *
70      * @return Returns <b>0</b> if dsp device trigger success; returns a non-zero value otherwise.
71      *
72      * @since 1.0
73      * @version 1.0
74      */
75     int32_t (*Trigger)(struct AudioCard *audioCard, int, struct DspDevice *dsp);
76 };
77 
78 /**
79  * @brief Defines Dsp host in audio driver.
80  *
81  * @since 1.0
82  * @version 1.0
83  */
84 struct DspHost {
85     struct IDeviceIoService service; /**< Services provided by dsp */
86     struct HdfDeviceObject *device;  /**< HDF device */
87     void *priv;                      /**< Dsp private data interface */
88 };
89 
90 /**
91  * @brief Defines dsp private data.
92  *
93  * @since 1.0
94  * @version 1.0
95  */
96 struct DspData {
97     const char *drvDspName; /**< Dsp driver name */
98 
99     /**
100      * @brief Defines Dsp device init.
101      *
102      * @param dsp Indicates a Dsp device.
103      *
104      * @return Returns <b>0</b> if dsp device init success; returns a non-zero value otherwise.
105      *
106      * @since 1.0
107      * @version 1.0
108      */
109     int32_t (*DspInit)(const struct DspDevice *dsp);
110 
111     /**
112      * @brief Defines Dsp device msgs read.
113      *
114      * @param dsp Indicates a dsp device.
115      * @param msgs Indicates transfer msgs data.
116      * @param len Indicates msgs length.
117      *
118      * @return Returns <b>0</b> if dsp device read msgs success; returns a non-zero value otherwise.
119      *
120      * @since 1.0
121      * @version 1.0
122      */
123     int32_t (*Read)(const struct DspDevice *dsp, const void *msgs, const uint32_t len);
124 
125     /**
126      * @brief Defines Dsp device msgs write.
127      *
128      * @param dsp Indicates a dsp device.
129      * @param msgs Indicates transfer msgs data.
130      * @param len Indicates msgs length.
131      *
132      * @return Returns <b>0</b> if dsp device write msgs success; returns a non-zero value otherwise.
133      *
134      * @since 1.0
135      * @version 1.0
136      */
137     int32_t (*Write)(const struct DspDevice *dsp, const void *msgs, const uint32_t len);
138 
139     /**
140      * @brief Defines Dsp device decode.
141      *
142      * @param audioCard Indicates an audio card.
143      * @param buf Indicates decode pcm buffer data.
144      * @param dsp Indicates a dsp device.
145      *
146      * @return Returns <b>0</b> if Dsp device decode success; returns a non-zero value otherwise.
147      *
148      * @since 1.0
149      * @version 1.0
150      */
151     int32_t (*Decode)(const struct AudioCard *audioCard, const uint8_t *buf, const struct DspDevice *dsp);
152 
153     /**
154      * @brief Defines Dsp device encode.
155      *
156      * @param audioCard audioCard Indicates an audio card.
157      * @param buf Indicates encode pcm buffer data.
158      * @param dsp Indicates a dsp device.
159      *
160      * @return Returns <b>0</b> if Dsp device encode success; returns a non-zero value otherwise.
161      *
162      * @since 1.0
163      * @version 1.0
164      */
165     int32_t (*Encode)(const struct AudioCard *audioCard, const uint8_t *buf, const struct DspDevice *dsp);
166 
167     /**
168      * @brief Defines Dsp device equalizer.
169      *
170      * @param audioCard audioCard Indicates an audio card.
171      * @param buf Indicates equalizer pcm buffer data.
172      * @param dsp Indicates a dsp device.
173      *
174      * @return Returns <b>0</b> if Dsp device equalizer success; returns a non-zero value otherwise.
175      *
176      * @since 1.0
177      * @version 1.0
178      */
179     int32_t (*Equalizer)(const struct AudioCard *audioCard, const uint8_t *buf, const struct DspDevice *dsp);
180 };
181 
182 #ifdef __cplusplus
183 #if __cplusplus
184 }
185 #endif
186 #endif /* __cplusplus */
187 #endif
188