• 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 #include <linux/io.h>
9 #include <linux/delay.h>
10 #include "audio_core.h"
11 #include "audio_host.h"
12 #include "audio_platform_base.h"
13 #include "osal_io.h"
14 #include "audio_driver_log.h"
15 #include "rk3588_dai_ops.h"
16 #include "audio_dai_base.h"
17 #define HDF_LOG_TAG rk3588_dai_adapter
18 
19 struct AudioDaiOps g_daiDeviceOps = {
20     .Startup = Rk3588DaiStartup,
21     .HwParams = Rk3588DaiHwParams,
22     .Trigger = Rk3588NormalTrigger,
23 };
24 
25 struct DaiData g_daiData = {
26     .Read = Rk3588DeviceReadReg,
27     .Write = Rk3588DeviceWriteReg,
28     .DaiInit = Rk3588DaiDeviceInit,
29     .ops = &g_daiDeviceOps,
30 };
31 
32 
33 /* HdfDriverEntry implementations */
DaiDriverBind(struct HdfDeviceObject * device)34 static int32_t DaiDriverBind(struct HdfDeviceObject *device)
35 {
36     struct DaiHost *daiHost = NULL;
37     AUDIO_DRIVER_LOG_DEBUG("entry!");
38 
39     if (device == NULL) {
40         AUDIO_DEVICE_LOG_ERR("input para is NULL.");
41         return HDF_FAILURE;
42     }
43 
44     daiHost = (struct DaiHost *)OsalMemCalloc(sizeof(*daiHost));
45     if (daiHost == NULL) {
46         AUDIO_DEVICE_LOG_ERR("malloc host fail!");
47         return HDF_FAILURE;
48     }
49 
50     daiHost->device = device;
51     device->service = &daiHost->service;
52     g_daiData.daiInitFlag = false;
53 
54     AUDIO_DRIVER_LOG_DEBUG("success!");
55     return HDF_SUCCESS;
56 }
57 
58 
DaiGetServiceName(const struct HdfDeviceObject * device)59 static int32_t DaiGetServiceName(const struct HdfDeviceObject *device)
60 {
61     const struct DeviceResourceNode *node = NULL;
62     struct DeviceResourceIface *drsOps = NULL;
63     int32_t ret;
64     AUDIO_DRIVER_LOG_DEBUG("entry!");
65 
66     if (device == NULL) {
67         AUDIO_DEVICE_LOG_ERR("input para is nullptr.");
68         return HDF_FAILURE;
69     }
70 
71     node = device->property;
72     if (node == NULL) {
73         AUDIO_DEVICE_LOG_ERR("drs node is nullptr.");
74         return HDF_FAILURE;
75     }
76     drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
77     if (drsOps == NULL || drsOps->GetString == NULL) {
78         AUDIO_DEVICE_LOG_ERR("invalid drs ops fail!");
79         return HDF_FAILURE;
80     }
81 
82     ret = drsOps->GetString(node, "serviceName", &g_daiData.drvDaiName, 0);
83     if (ret != HDF_SUCCESS) {
84         AUDIO_DEVICE_LOG_ERR("read serviceName fail!");
85         return ret;
86     }
87 
88     AUDIO_DRIVER_LOG_DEBUG("success!");
89     return HDF_SUCCESS;
90 }
91 
DaiDriverInit(struct HdfDeviceObject * device)92 static int32_t DaiDriverInit(struct HdfDeviceObject *device)
93 {
94     int32_t ret = 0;
95     AUDIO_DRIVER_LOG_DEBUG("entry!");
96     if (device == NULL) {
97         AUDIO_DEVICE_LOG_ERR("device is nullptr.");
98         return HDF_ERR_INVALID_OBJECT;
99     }
100 
101     if (DaiGetConfigInfo(device, &g_daiData) !=  HDF_SUCCESS) {
102         AUDIO_DEVICE_LOG_ERR("get dai data fail.");
103         return HDF_FAILURE;
104     }
105 
106     if (DaiGetServiceName(device) !=  HDF_SUCCESS) {
107         AUDIO_DEVICE_LOG_ERR("get service name fail.");
108         return HDF_FAILURE;
109     }
110 
111     OsalMutexInit(&g_daiData.mutex);
112     ret = AudioSocRegisterDai(device, (void *)&g_daiData);
113     if (ret !=  HDF_SUCCESS) {
114         AUDIO_DEVICE_LOG_ERR("register dai fail.");
115         return ret;
116     }
117 
118     AUDIO_DRIVER_LOG_DEBUG("success.\n");
119     return HDF_SUCCESS;
120 }
121 
DaiDriverRelease(struct HdfDeviceObject * device)122 static void DaiDriverRelease(struct HdfDeviceObject *device)
123 {
124     struct DaiHost *daiHost;
125     AUDIO_DRIVER_LOG_DEBUG("entry!");
126     if (device == NULL) {
127         AUDIO_DEVICE_LOG_ERR("device is NULL");
128         return;
129     }
130 
131     OsalMutexDestroy(&g_daiData.mutex);
132 
133     daiHost = (struct DaiHost *)device->service;
134     if (daiHost == NULL) {
135         AUDIO_DEVICE_LOG_ERR("daiHost is NULL");
136         return;
137     }
138     OsalMemFree(daiHost);
139     AUDIO_DRIVER_LOG_DEBUG("success!");
140 }
141 
142 /* HdfDriverEntry definitions */
143 struct HdfDriverEntry g_daiDriverEntry = {
144     .moduleVersion = 1,
145     .moduleName = "DAI_RK3588",
146     .Bind = DaiDriverBind,
147     .Init = DaiDriverInit,
148     .Release = DaiDriverRelease,
149 };
150 HDF_INIT(g_daiDriverEntry);
151