• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 HiHope Open Source Organization .
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 "rk3568_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 rk3568_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     if (device == NULL) {
41         AUDIO_DRIVER_LOG_ERR("device is NULL.");
42         return HDF_ERR_INVALID_OBJECT;
43     }
44 
45     audioHost = AudioHostCreateAndBind(device);
46     if (audioHost == NULL) {
47         AUDIO_DRIVER_LOG_ERR("audioHost create failed!");
48         return HDF_FAILURE;
49     }
50 
51     AUDIO_DRIVER_LOG_INFO("success");
52     return HDF_SUCCESS;
53 }
54 
DspDriverInit(struct HdfDeviceObject * device)55 static int32_t DspDriverInit(struct HdfDeviceObject *device)
56 {
57     int32_t ret = 0;
58     AUDIO_DRIVER_LOG_INFO("entry");
59 
60     if (device == NULL) {
61         AUDIO_DRIVER_LOG_ERR("device is NULL.");
62         return HDF_ERR_INVALID_OBJECT;
63     }
64 
65     ret = DspGetServiceName(device, &g_dspData.drvDspName);
66     if (ret != HDF_SUCCESS) {
67         return ret;
68     }
69 
70     ret = DspGetDaiName(device, &g_dspDaiData.drvDaiName);
71     if (ret != HDF_SUCCESS) {
72         return ret;
73     }
74 
75     ret = AudioRegisterDsp(device, &g_dspData, &g_dspDaiData);
76     if (ret !=  HDF_SUCCESS) {
77         return ret;
78     }
79 
80     AUDIO_DRIVER_LOG_INFO("success");
81     return HDF_SUCCESS;
82 }
83 
84 
DspDriverRelease(struct HdfDeviceObject * device)85 static void DspDriverRelease(struct HdfDeviceObject *device)
86 {
87     struct DspHost *dspHost;
88     AUDIO_DRIVER_LOG_INFO("entry");
89     if (device == NULL) {
90         AUDIO_DRIVER_LOG_ERR("device is NULL");
91         return;
92     }
93 
94     dspHost = (struct DspHost *)device->service;
95     if (dspHost == NULL) {
96         AUDIO_DRIVER_LOG_ERR("DspHost is NULL");
97         return;
98     }
99     if (dspHost->priv != NULL) {
100         OsalMemFree(dspHost->priv);
101     }
102     OsalMemFree(dspHost);
103     AUDIO_DRIVER_LOG_INFO("success");
104 }
105 
106 /* HdfDriverEntry definitions */
107 struct HdfDriverEntry g_dspDriverEntry = {
108     .moduleVersion = 1,
109     .moduleName = "DSP_RK3568",
110     .Bind = DspDriverBind,
111     .Init = DspDriverInit,
112     .Release = DspDriverRelease,
113 };
114 HDF_INIT(g_dspDriverEntry);
115