• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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 HDF_AUDIO_DRIVER
27 
28 struct DspData g_dspData = {
29     .DspInit = DspDeviceInit,
30     .Read = DspDeviceReadReg,
31     .Write = DspDeviceWriteReg,
32     .Decode = DspDecodeAudioStream,
33     .Encode = DspEncodeAudioStream,
34     .Equalizer = DspEqualizerActive,
35 };
36 
37 struct AudioDaiOps g_dspDaiDeviceOps = {
38     .Startup = DspDaiStartup,
39     .HwParams = DspDaiHwParams,
40 };
41 
42 struct DaiData g_dspDaiData = {
43     .DaiInit = DspDaiDeviceInit,
44     .ops = &g_dspDaiDeviceOps,
45 };
46 
DspDriverBind(struct HdfDeviceObject * device)47 static int32_t DspDriverBind(struct HdfDeviceObject *device)
48 {
49     AUDIO_DRIVER_LOG_INFO("entry");
50 
51     if (device == NULL) {
52         AUDIO_DRIVER_LOG_ERR("device is NULL.");
53         return HDF_ERR_INVALID_OBJECT;
54     }
55 
56     AUDIO_DRIVER_LOG_INFO("success");
57     return HDF_SUCCESS;
58 }
59 
DspDriverInit(struct HdfDeviceObject * device)60 static int32_t DspDriverInit(struct HdfDeviceObject *device)
61 {
62     AUDIO_DRIVER_LOG_INFO("entry");
63 
64     if (device == NULL) {
65         AUDIO_DRIVER_LOG_ERR("device is NULL.");
66         return HDF_ERR_INVALID_OBJECT;
67     }
68 
69     int32_t 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_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