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 "a311d_dma_ops.h"
12
13 #define HDF_LOG_TAG a311d_dma_adapter
14
15 struct AudioDmaOps g_dmaDeviceOps = {
16 .DmaBufAlloc = A311DAudioDmaBufAlloc,
17 .DmaBufFree = A311DAudioDmaBufFree,
18 .DmaRequestChannel = A311DAudioDmaRequestChannel,
19 .DmaConfigChannel = A311DAudioDmaConfigChannel,
20 .DmaPrep = A311DAudioDmaPrep,
21 .DmaSubmit = A311DAudioDmaSubmit,
22 .DmaPending = A311DAudioDmaPending,
23 .DmaPause = A311DAudioDmaPause,
24 .DmaResume = A311DAudioDmaResume,
25 .DmaPointer = A311DAudioDmaPointer,
26 };
27
28 struct PlatformData g_platformData = {
29 .PlatformInit = A311DAudioDmaDeviceInit,
30 .ops = &g_dmaDeviceOps,
31 };
32
33 /* HdfDriverEntry implementations */
DmaDriverBind(struct HdfDeviceObject * device)34 static int32_t DmaDriverBind(struct HdfDeviceObject *device)
35 {
36 struct PlatformHost *platformHost = NULL;
37
38 AUDIO_DRIVER_LOG_DEBUG("");
39
40 if (device == NULL) {
41 AUDIO_DRIVER_LOG_ERR("input para is NULL.");
42 return HDF_FAILURE;
43 }
44
45 platformHost = (struct PlatformHost *)OsalMemCalloc(sizeof(*platformHost));
46 if (platformHost == NULL) {
47 AUDIO_DRIVER_LOG_ERR("malloc host fail!");
48 return HDF_FAILURE;
49 }
50
51 platformHost->device = device;
52 device->service = &platformHost->service;
53
54 AUDIO_DRIVER_LOG_DEBUG("success!");
55 return HDF_SUCCESS;
56 }
57
DmaGetServiceName(const struct HdfDeviceObject * device)58 static int32_t DmaGetServiceName(const struct HdfDeviceObject *device)
59 {
60 const struct DeviceResourceNode *node = NULL;
61 struct DeviceResourceIface *drsOps = NULL;
62 int32_t ret;
63
64 if (device == NULL) {
65 AUDIO_DRIVER_LOG_ERR("para is NULL.");
66 return HDF_FAILURE;
67 }
68
69 node = device->property;
70 if (node == NULL) {
71 AUDIO_DRIVER_LOG_ERR("node is NULL.");
72 return HDF_FAILURE;
73 }
74
75 drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
76 if (drsOps == NULL || drsOps->GetString == NULL) {
77 AUDIO_DRIVER_LOG_ERR("get drsops object instance fail!");
78 return HDF_FAILURE;
79 }
80
81 ret = drsOps->GetString(node, "serviceName", &g_platformData.drvPlatformName, 0);
82 if (ret != HDF_SUCCESS) {
83 AUDIO_DRIVER_LOG_ERR("read serviceName fail!");
84 return ret;
85 }
86 AUDIO_DRIVER_LOG_DEBUG("success!");
87
88 return HDF_SUCCESS;
89 }
90
DmaDriverInit(struct HdfDeviceObject * device)91 static int32_t DmaDriverInit(struct HdfDeviceObject *device)
92 {
93 int32_t ret;
94
95 AUDIO_DRIVER_LOG_DEBUG("");
96
97 if (device == NULL) {
98 AUDIO_DRIVER_LOG_ERR("device is NULL.");
99 return HDF_ERR_INVALID_OBJECT;
100 }
101
102 ret = DmaGetServiceName(device);
103 if (ret != HDF_SUCCESS) {
104 AUDIO_DRIVER_LOG_ERR("get service name fail.");
105 return ret;
106 }
107 OsalMutexInit(&g_platformData.renderBufInfo.buffMutex);
108 OsalMutexInit(&g_platformData.captureBufInfo.buffMutex);
109 g_platformData.platformInitFlag = false;
110 ret = AudioSocRegisterPlatform(device, &g_platformData);
111 if (ret != HDF_SUCCESS) {
112 AUDIO_DRIVER_LOG_ERR("register dai fail.");
113 return ret;
114 }
115
116 AUDIO_DRIVER_LOG_DEBUG("success!");
117 return HDF_SUCCESS;
118 }
119
DmaDriverRelease(struct HdfDeviceObject * device)120 static void DmaDriverRelease(struct HdfDeviceObject *device)
121 {
122 struct PlatformHost *platformHost = NULL;
123
124 AUDIO_DRIVER_LOG_DEBUG("");
125
126 if (device == NULL) {
127 AUDIO_DRIVER_LOG_ERR("device is NULL");
128 return;
129 }
130
131 platformHost = (struct PlatformHost *)device->service;
132 if (platformHost == NULL) {
133 AUDIO_DRIVER_LOG_ERR("platformHost is NULL");
134 return;
135 }
136 OsalMutexDestroy(&g_platformData.renderBufInfo.buffMutex);
137 OsalMutexDestroy(&g_platformData.captureBufInfo.buffMutex);
138 OsalMemFree(platformHost);
139
140 AUDIO_DRIVER_LOG_DEBUG("success!");
141 }
142
143 /* HdfDriverEntry definitions */
144 struct HdfDriverEntry g_platformDriverEntry = {
145 .moduleVersion = 1,
146 .moduleName = "DMA_A311D",
147 .Bind = DmaDriverBind,
148 .Init = DmaDriverInit,
149 .Release = DmaDriverRelease,
150 };
151 HDF_INIT(g_platformDriverEntry);
152