1 /*
2 * Copyright (c) 2021 iSoftStone 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 struct AudioHost *audioHost;
40
41 AUDIO_DRIVER_LOG_DEBUG("entry");
42
43 if (device == NULL) {
44 AUDIO_DRIVER_LOG_ERR("device is NULL.");
45 return HDF_ERR_INVALID_OBJECT;
46 }
47
48 audioHost = AudioHostCreateAndBind(device);
49 if (audioHost == NULL) {
50 AUDIO_DRIVER_LOG_ERR("audioHost create failed!");
51 return HDF_FAILURE;
52 }
53
54 AUDIO_DRIVER_LOG_DEBUG("success");
55 return HDF_SUCCESS;
56 }
57
DspDriverInit(struct HdfDeviceObject * device)58 static int32_t DspDriverInit(struct HdfDeviceObject *device)
59 {
60 int32_t ret;
61
62 AUDIO_DRIVER_LOG_DEBUG("entry");
63
64 if (device == NULL) {
65 AUDIO_DRIVER_LOG_ERR("device is NULL.");
66 return HDF_ERR_INVALID_OBJECT;
67 }
68
69 ret = DspGetServiceName(device, &g_dspData.drvDspName);
70 if (ret != HDF_SUCCESS) {
71 return ret;
72 }
73
74 ret = DspGetDaiName(device, &g_dspDaiData.drvDaiName);
75 if (ret != HDF_SUCCESS) {
76 return ret;
77 }
78
79 ret = AudioRegisterDsp(device, &g_dspData, &g_dspDaiData);
80 if (ret != HDF_SUCCESS) {
81 return ret;
82 }
83
84 AUDIO_DRIVER_LOG_DEBUG("success");
85 return HDF_SUCCESS;
86 }
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_T507",
115 .Bind = DspDriverBind,
116 .Init = DspDriverInit,
117 .Release = DspDriverRelease,
118 };
119 HDF_INIT(g_dspDriverEntry);
120