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