1 /*
2 * Copyright (C) 2021–2022 Beijing OSWare Technology Co., Ltd
3 * This file contains confidential and proprietary information of
4 * OSWare Technology Co., Ltd
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 #include "audio_dsp_base.h"
20 #include "audio_core.h"
21 #include "dsp_ops.h"
22 #include "audio_dsp_if.h"
23 #include "audio_driver_log.h"
24 #include "osal_io.h"
25
26 #define HDF_LOG_TAG dsp_adapter
27
28 struct DspData g_dspData = {
29 .drvDspName = "dsp_service_0",
30 .DspInit = DspDeviceInit,
31 .Read = DspDeviceReadReg,
32 .Write = DspDeviceWriteReg,
33 .Decode = DspDecodeAudioStream,
34 .Encode = DspEncodeAudioStream,
35 .Equalizer = DspEqualizerActive,
36 };
37
38 struct AudioDaiOps g_dspDaiDeviceOps = {
39 .Startup = DspDaiStartup,
40 .HwParams = DspDaiHwParams,
41 };
42
43 struct DaiData g_dspDaiData = {
44 .drvDaiName = "dsp_dai",
45 .DaiInit = DspDaiDeviceInit,
46 .ops = &g_dspDaiDeviceOps,
47 };
48
DspDriverBind(struct HdfDeviceObject * device)49 static int32_t DspDriverBind(struct HdfDeviceObject *device)
50 {
51 AUDIO_DRIVER_LOG_INFO("entry");
52
53 if (device == NULL) {
54 AUDIO_DRIVER_LOG_ERR("device is NULL.");
55 return HDF_ERR_INVALID_OBJECT;
56 }
57
58 struct AudioHost *audioHost = AudioHostCreateAndBind(device);
59 if (audioHost == NULL) {
60 AUDIO_DRIVER_LOG_ERR("audioHost create failed!");
61 return HDF_FAILURE;
62 }
63
64 AUDIO_DRIVER_LOG_INFO("success");
65 return HDF_SUCCESS;
66 }
67
DspDriverInit(struct HdfDeviceObject * device)68 static int32_t DspDriverInit(struct HdfDeviceObject *device)
69 {
70 int32_t ret;
71
72 AUDIO_DRIVER_LOG_INFO("entry");
73
74 if (device == NULL) {
75 AUDIO_DRIVER_LOG_ERR("device is NULL.");
76 return HDF_ERR_INVALID_OBJECT;
77 }
78
79 ret = AudioRegisterDsp(device, &g_dspData, &g_dspDaiData);
80 if (ret != HDF_SUCCESS) {
81 return ret;
82 }
83
84 AUDIO_DRIVER_LOG_INFO("success");
85 return HDF_SUCCESS;
86 }
87
88
DspDriverRelease(struct HdfDeviceObject * device)89 static void DspDriverRelease(struct HdfDeviceObject *device)
90 {
91 AUDIO_DRIVER_LOG_INFO("entry");
92 if (device == NULL) {
93 AUDIO_DRIVER_LOG_ERR("device is NULL");
94 return;
95 }
96
97 struct DspHost *dspHost = (struct DspHost *)device->service;
98 if (dspHost == NULL) {
99 AUDIO_DRIVER_LOG_ERR("DspHost is NULL");
100 return;
101 }
102 if (dspHost->priv != NULL) {
103 OsalMemFree(dspHost->priv);
104 }
105 OsalMemFree(dspHost);
106 AUDIO_DRIVER_LOG_INFO("success");
107 }
108
109 /* HdfDriverEntry definitions */
110 struct HdfDriverEntry g_dspDriverEntry = {
111 .moduleVersion = 1,
112 .moduleName = "DSP",
113 .Bind = DspDriverBind,
114 .Init = DspDriverInit,
115 .Release = DspDriverRelease,
116 };
117 HDF_INIT(g_dspDriverEntry);
118