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 "es8323_codec_impl.h"
10 #include "audio_codec_if.h"
11 #include "audio_codec_base.h"
12 #include "audio_driver_log.h"
13
14 #define HDF_LOG_TAG "es8323_codec_adapter"
15
16 struct CodecData g_es8323Data = {
17 .Init = Es8323DeviceInit,
18 .Read = Es8323DeviceRegRead,
19 .Write = Es8323DeviceRegWrite,
20 };
21
22 struct AudioDaiOps g_es8323DaiDeviceOps = {
23 .Startup = Es8323DaiStartup,
24 .HwParams = Es8323DaiHwParams,
25 .Trigger = Es8323NormalTrigger,
26 };
27
28 struct DaiData g_es8323DaiData = {
29 .drvDaiName = "codec_dai",
30 .DaiInit = Es8323DaiDeviceInit,
31 .ops = &g_es8323DaiDeviceOps,
32 };
33
34 /* HdfDriverEntry */
GetServiceName(const struct HdfDeviceObject * device)35 static int32_t GetServiceName(const struct HdfDeviceObject *device)
36 {
37 const struct DeviceResourceNode *node = NULL;
38 struct DeviceResourceIface *drsOps = NULL;
39 int32_t ret;
40 if (device == NULL) {
41 AUDIO_DRIVER_LOG_ERR("input HdfDeviceObject object is nullptr.");
42 return HDF_FAILURE;
43 }
44 node = device->property;
45 if (node == NULL) {
46 AUDIO_DRIVER_LOG_ERR("get drs node is nullptr.");
47 return HDF_FAILURE;
48 }
49 drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
50 if (drsOps == NULL || drsOps->GetString == NULL) {
51 AUDIO_DRIVER_LOG_ERR("drsOps or drsOps getString is null!");
52 return HDF_FAILURE;
53 }
54 ret = drsOps->GetString(node, "serviceName", &g_es8323Data.drvCodecName, 0);
55 if (ret != HDF_SUCCESS) {
56 AUDIO_DRIVER_LOG_ERR("read serviceName failed.");
57 return ret;
58 }
59 AUDIO_DRIVER_LOG_ERR("g_es8323Data.drvCodecName = %s", g_es8323Data.drvCodecName);
60 return HDF_SUCCESS;
61 }
62
63 /* HdfDriverEntry implementations */
Es8323DriverBind(struct HdfDeviceObject * device)64 static int32_t Es8323DriverBind(struct HdfDeviceObject *device)
65 {
66 (void)device;
67 AUDIO_DRIVER_LOG_DEBUG("success!");
68 return HDF_SUCCESS;
69 }
70
Es8323DriverInit(struct HdfDeviceObject * device)71 static int32_t Es8323DriverInit(struct HdfDeviceObject *device)
72 {
73 int32_t ret;
74 if (device == NULL) {
75 AUDIO_DRIVER_LOG_ERR("device is NULL.");
76 return HDF_ERR_INVALID_OBJECT;
77 }
78
79 ret = Es8323GetConfigInfo(device, &g_es8323Data);
80 if (ret != HDF_SUCCESS) {
81 AUDIO_DRIVER_LOG_ERR("Es8323GetConfigInfo failed.");
82 return ret;
83 }
84 if (CodecDaiGetPortConfigInfo(device, &g_es8323DaiData) != HDF_SUCCESS) {
85 AUDIO_DRIVER_LOG_ERR("get port config info failed.");
86 return HDF_FAILURE;
87 }
88
89 if (CodecSetConfigInfoOfControls(&g_es8323Data, &g_es8323DaiData) != HDF_SUCCESS) {
90 AUDIO_DRIVER_LOG_ERR("set config info failed.");
91 return HDF_FAILURE;
92 }
93 ret = GetServiceName(device);
94 if (ret != HDF_SUCCESS) {
95 AUDIO_DRIVER_LOG_ERR("GetServiceName failed.");
96 return ret;
97 }
98
99 ret = AudioRegisterCodec(device, &g_es8323Data, &g_es8323DaiData);
100 if (ret != HDF_SUCCESS) {
101 AUDIO_DRIVER_LOG_ERR("AudioRegisterCodec failed.");
102 return ret;
103 }
104 AUDIO_DRIVER_LOG_DEBUG("success!");
105 return HDF_SUCCESS;
106 }
107
108 /* HdfDriverEntry definitions */
109 struct HdfDriverEntry g_es8323DriverEntry = {
110 .moduleVersion = 1,
111 .moduleName = "CODEC_ES8323",
112 .Bind = Es8323DriverBind,
113 .Init = Es8323DriverInit,
114 .Release = NULL,
115 };
116 HDF_INIT(g_es8323DriverEntry);