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