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