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 #include "audio_dsp_base.h"
10 #include "audio_core.h"
11 #include "dsp_ops.h"
12 #include "audio_dsp_if.h"
13 #include "audio_driver_log.h"
14 #include "osal_io.h"
15
16 #define HDF_LOG_TAG dsp_adapter
17
18 struct DspData g_dspData = {
19 .DspInit = DspDeviceInit,
20 .Read = DspDeviceReadReg,
21 .Write = DspDeviceWriteReg,
22 .Decode = DspDecodeAudioStream,
23 .Encode = DspEncodeAudioStream,
24 .Equalizer = DspEqualizerActive,
25 };
26
27 struct AudioDaiOps g_dspDaiDeviceOps = {
28 .Startup = DspDaiStartup,
29 .HwParams = DspDaiHwParams,
30 };
31
32 struct DaiData g_dspDaiData = {
33 .DaiInit = DspDaiDeviceInit,
34 .ops = &g_dspDaiDeviceOps,
35 };
36
DspDriverBind(struct HdfDeviceObject * device)37 static int32_t DspDriverBind(struct HdfDeviceObject *device)
38 {
39 AUDIO_DRIVER_LOG_INFO("entry");
40
41 if (device == NULL) {
42 AUDIO_DRIVER_LOG_ERR("device is NULL.");
43 return HDF_ERR_INVALID_OBJECT;
44 }
45
46 AUDIO_DRIVER_LOG_INFO("success");
47 return HDF_SUCCESS;
48 }
49
DspDriverInit(struct HdfDeviceObject * device)50 static int32_t DspDriverInit(struct HdfDeviceObject *device)
51 {
52 AUDIO_DRIVER_LOG_INFO("entry");
53
54 if (device == NULL) {
55 AUDIO_DRIVER_LOG_ERR("device is NULL.");
56 return HDF_ERR_INVALID_OBJECT;
57 }
58
59 int32_t ret = DspGetServiceName(device, &g_dspData.drvDspName);
60 if (ret != HDF_SUCCESS) {
61 return ret;
62 }
63
64 ret = DspGetDaiName(device, &g_dspDaiData.drvDaiName);
65 if (ret != HDF_SUCCESS) {
66 return ret;
67 }
68
69 ret = AudioRegisterDsp(device, &g_dspData, &g_dspDaiData);
70 if (ret != HDF_SUCCESS) {
71 return ret;
72 }
73
74 AUDIO_DRIVER_LOG_INFO("success");
75 return HDF_SUCCESS;
76 }
77
78
DspDriverRelease(struct HdfDeviceObject * device)79 static void DspDriverRelease(struct HdfDeviceObject *device)
80 {
81 AUDIO_DRIVER_LOG_INFO("entry");
82 if (device == NULL) {
83 AUDIO_DRIVER_LOG_ERR("device is NULL");
84 return;
85 }
86
87 struct DspHost *dspHost = (struct DspHost *)device->service;
88 if (dspHost == NULL) {
89 AUDIO_DRIVER_LOG_ERR("DspHost is NULL");
90 return;
91 }
92 if (dspHost->priv != NULL) {
93 OsalMemFree(dspHost->priv);
94 }
95 OsalMemFree(dspHost);
96 AUDIO_DRIVER_LOG_INFO("success");
97 }
98
99 /* HdfDriverEntry definitions */
100 struct HdfDriverEntry g_dspDriverEntry = {
101 .moduleVersion = 1,
102 .moduleName = "DSP",
103 .Bind = DspDriverBind,
104 .Init = DspDriverInit,
105 .Release = DspDriverRelease,
106 };
107 HDF_INIT(g_dspDriverEntry);
108