• 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 <linux/slab.h>
10 #include "gpio_if.h"
11 #include "audio_core.h"
12 #include "audio_platform_base.h"
13 #include "rk3568_dma_ops.h"
14 #include "osal_io.h"
15 #include "osal_mem.h"
16 #include "audio_driver_log.h"
17 
18 #define HDF_LOG_TAG rk3568_platform_adapter
19 
20 struct AudioDmaOps g_dmaDeviceOps = {
21     .DmaBufAlloc = Rk3568DmaBufAlloc,
22     .DmaBufFree = Rk3568DmaBufFree,
23     .DmaRequestChannel = Rk3568DmaRequestChannel,
24     .DmaConfigChannel = Rk3568DmaConfigChannel,
25     .DmaPrep = Rk3568DmaPrep,
26     .DmaSubmit = Rk3568DmaSubmit,
27     .DmaPending = Rk3568DmaPending,
28     .DmaPause = Rk3568DmaPause,
29     .DmaResume = Rk3568DmaResume,
30     .DmaPointer = Rk3568PcmPointer,
31 };
32 
33 struct PlatformData g_platformData = {
34     .PlatformInit = AudioDmaDeviceInit,
35     .ops = &g_dmaDeviceOps,
36 };
37 
38 /* HdfDriverEntry implementations */
PlatformDriverBind(struct HdfDeviceObject * device)39 static int32_t PlatformDriverBind(struct HdfDeviceObject *device)
40 {
41     struct PlatformHost *platformHost = NULL;
42 
43     if (device == NULL) {
44         AUDIO_DEVICE_LOG_ERR("input para is NULL.");
45         return HDF_FAILURE;
46     }
47 
48     platformHost = (struct PlatformHost *)OsalMemCalloc(sizeof(*platformHost));
49     if (platformHost == NULL) {
50         AUDIO_DEVICE_LOG_ERR("malloc host fail!");
51         return HDF_FAILURE;
52     }
53 
54     platformHost->device = device;
55     device->service = &platformHost->service;
56 
57     AUDIO_DEVICE_LOG_DEBUG("success!");
58     return HDF_SUCCESS;
59 }
60 
PlatformGetServiceName(const struct HdfDeviceObject * device)61 static int32_t PlatformGetServiceName(const struct HdfDeviceObject *device)
62 {
63     const struct DeviceResourceNode *node = NULL;
64     struct DeviceResourceIface *drsOps = NULL;
65     int32_t ret;
66 
67     if (device == NULL) {
68         AUDIO_DEVICE_LOG_ERR("para is NULL.");
69         return HDF_FAILURE;
70     }
71 
72     node = device->property;
73     if (node == NULL) {
74         AUDIO_DEVICE_LOG_ERR("node is NULL.");
75         return HDF_FAILURE;
76     }
77 
78     drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
79     if (drsOps == NULL || drsOps->GetString == NULL) {
80         AUDIO_DEVICE_LOG_ERR("get drsops object instance fail!");
81         return HDF_FAILURE;
82     }
83 
84     ret = drsOps->GetString(node, "serviceName", &g_platformData.drvPlatformName, 0);
85     if (ret != HDF_SUCCESS) {
86         AUDIO_DEVICE_LOG_ERR("read serviceName fail!");
87         return ret;
88     }
89     AUDIO_DEVICE_LOG_DEBUG("success!");
90 
91     return HDF_SUCCESS;
92 }
93 
PlatformDriverInit(struct HdfDeviceObject * device)94 static int32_t PlatformDriverInit(struct HdfDeviceObject *device)
95 {
96     int32_t ret;
97 
98     if (device == NULL) {
99         AUDIO_DEVICE_LOG_ERR("device is NULL.");
100         return HDF_ERR_INVALID_OBJECT;
101     }
102 
103     ret = PlatformGetServiceName(device);
104     if (ret !=  HDF_SUCCESS) {
105         AUDIO_DEVICE_LOG_ERR("get service name fail.");
106         return ret;
107     }
108 
109     ret = AudioSocRegisterPlatform(device, &g_platformData);
110     if (ret !=  HDF_SUCCESS) {
111         AUDIO_DEVICE_LOG_ERR("register dai fail.");
112         return ret;
113     }
114 
115     AUDIO_DEVICE_LOG_DEBUG("success.\n");
116     return HDF_SUCCESS;
117 }
118 
PlatformDriverRelease(struct HdfDeviceObject * device)119 static void PlatformDriverRelease(struct HdfDeviceObject *device)
120 {
121     struct PlatformHost *platformHost = NULL;
122     if (device == NULL) {
123         AUDIO_DEVICE_LOG_ERR("device is NULL");
124         return;
125     }
126 
127     platformHost = (struct PlatformHost *)device->service;
128     if (platformHost == NULL) {
129         AUDIO_DEVICE_LOG_ERR("platformHost is NULL");
130         return;
131     }
132     OsalMemFree(platformHost);
133     AUDIO_DEVICE_LOG_DEBUG("success.\n");
134     return;
135 }
136 
137 /* HdfDriverEntry definitions */
138 struct HdfDriverEntry g_platformDriverEntry = {
139     .moduleVersion = 1,
140     .moduleName = "DMA_RK3568",
141     .Bind = PlatformDriverBind,
142     .Init = PlatformDriverInit,
143     .Release = PlatformDriverRelease,
144 };
145 HDF_INIT(g_platformDriverEntry);
146