1 /*
2 * Copyright (c) 2021 Huawei 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_core.h"
10 #include "audio_driver_log.h"
11 #include "hi3516_dma_ops.h"
12
13 #define HDF_LOG_TAG hi3516_platform_adapter
14
15 struct AudioDmaOps g_dmaDeviceOps = {
16 .DmaBufAlloc = Hi3516DmaBufAlloc,
17 .DmaBufFree = Hi3516DmaBufFree,
18 .DmaRequestChannel = Hi3516DmaRequestChannel,
19 .DmaConfigChannel = Hi3516DmaConfigChannel,
20 .DmaPrep = Hi3516DmaPrep,
21 .DmaSubmit = Hi3516DmaSubmit,
22 .DmaPending = Hi3516DmaPending,
23 .DmaPause = Hi3516DmaPause,
24 .DmaResume = Hi3516DmaResume,
25 .DmaPointer = Hi3516DmaPointer,
26 };
27
28 struct PlatformData g_platformData = {
29 .PlatformInit = AudioDmaDeviceInit,
30 .ops = &g_dmaDeviceOps,
31 };
32
33 /* HdfDriverEntry implementations */
Hi3516DmaDriverBind(struct HdfDeviceObject * device)34 static int32_t Hi3516DmaDriverBind(struct HdfDeviceObject *device)
35 {
36 struct PlatformHost *platformHost = NULL;
37
38 if (device == NULL) {
39 AUDIO_DRIVER_LOG_ERR("input para is NULL.");
40 return HDF_FAILURE;
41 }
42
43 platformHost = (struct PlatformHost *)OsalMemCalloc(sizeof(*platformHost));
44 if (platformHost == NULL) {
45 AUDIO_DRIVER_LOG_ERR("malloc host fail!");
46 return HDF_FAILURE;
47 }
48
49 platformHost->device = device;
50 device->service = &platformHost->service;
51
52 AUDIO_DRIVER_LOG_DEBUG("success!");
53 return HDF_SUCCESS;
54 }
55
Hi3516DmaGetServiceName(const struct HdfDeviceObject * device)56 static int32_t Hi3516DmaGetServiceName(const struct HdfDeviceObject *device)
57 {
58 if (device == NULL) {
59 AUDIO_DRIVER_LOG_ERR("para is NULL.");
60 return HDF_FAILURE;
61 }
62
63 const struct DeviceResourceNode *node = device->property;
64 if (node == NULL) {
65 AUDIO_DRIVER_LOG_ERR("node is NULL.");
66 return HDF_FAILURE;
67 }
68
69 struct DeviceResourceIface *drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
70 if (drsOps == NULL || drsOps->GetString == NULL) {
71 AUDIO_DRIVER_LOG_ERR("get drsops object instance fail!");
72 return HDF_FAILURE;
73 }
74
75 int32_t ret = drsOps->GetString(node, "serviceName", &g_platformData.drvPlatformName, 0);
76 if (ret != HDF_SUCCESS) {
77 AUDIO_DRIVER_LOG_ERR("read serviceName fail!");
78 return ret;
79 }
80
81 return HDF_SUCCESS;
82 }
83
Hi3516DmaDriverInit(struct HdfDeviceObject * device)84 static int32_t Hi3516DmaDriverInit(struct HdfDeviceObject *device)
85 {
86 if (device == NULL) {
87 AUDIO_DRIVER_LOG_ERR("device is NULL.");
88 return HDF_ERR_INVALID_OBJECT;
89 }
90
91 int32_t ret = Hi3516DmaGetServiceName(device);
92 if (ret != HDF_SUCCESS) {
93 AUDIO_DRIVER_LOG_ERR("get service name fail.");
94 return ret;
95 }
96 OsalMutexInit(&g_platformData.renderBufInfo.buffMutex);
97 OsalMutexInit(&g_platformData.captureBufInfo.buffMutex);
98 g_platformData.platformInitFlag = false;
99 ret = AudioSocRegisterPlatform(device, &g_platformData);
100 if (ret != HDF_SUCCESS) {
101 AUDIO_DRIVER_LOG_ERR("register dai fail.");
102 return ret;
103 }
104
105 AUDIO_DRIVER_LOG_INFO("success.\n");
106 return HDF_SUCCESS;
107 }
108
Hi3516DmaDriverRelease(struct HdfDeviceObject * device)109 static void Hi3516DmaDriverRelease(struct HdfDeviceObject *device)
110 {
111 struct PlatformHost *platformHost = NULL;
112
113 if (device == NULL) {
114 AUDIO_DRIVER_LOG_ERR("device is NULL");
115 return;
116 }
117
118 platformHost = (struct PlatformHost *)device->service;
119 if (platformHost == NULL) {
120 AUDIO_DRIVER_LOG_ERR("platformHost is NULL");
121 return;
122 }
123 OsalMutexDestroy(&g_platformData.renderBufInfo.buffMutex);
124 OsalMutexDestroy(&g_platformData.captureBufInfo.buffMutex);
125 OsalMemFree(platformHost);
126 }
127
128 /* HdfDriverEntry definitions */
129 struct HdfDriverEntry g_platformDriverEntry = {
130 .moduleVersion = 1,
131 .moduleName = "DMA_HI3516",
132 .Bind = Hi3516DmaDriverBind,
133 .Init = Hi3516DmaDriverInit,
134 .Release = Hi3516DmaDriverRelease,
135 };
136 HDF_INIT(g_platformDriverEntry);
137