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 "tfa9879_accessory_impl.h"
10 #include "audio_accessory_base.h"
11 #include "audio_accessory_if.h"
12 #include "audio_driver_log.h"
13
14 #define HDF_LOG_TAG "accessory"
15
16 struct AccessoryData g_tfa9879Data = {
17 .Init = Tfa9879DeviceInit,
18 .Read = AccessoryDeviceRegRead,
19 .Write = AccessoryDeviceRegWrite,
20 };
21
22 struct AudioDaiOps g_tfa9879DaiDeviceOps = {
23 .Startup = Tfa9879DaiStartup,
24 .HwParams = Tfa9879DaiHwParams,
25 };
26
27 struct DaiData g_tfa9879DaiData = {
28 .drvDaiName = "accessory_dai",
29 .DaiInit = Tfa9879DaiDeviceInit,
30 .ops = &g_tfa9879DaiDeviceOps,
31 };
32
33 /* HdfDriverEntry */
GetServiceName(const struct HdfDeviceObject * device)34 static int32_t GetServiceName(const struct HdfDeviceObject *device)
35 {
36 const struct DeviceResourceNode *node = NULL;
37 struct DeviceResourceIface *drsOps = NULL;
38 int32_t ret;
39 if (device == NULL) {
40 AUDIO_DRIVER_LOG_ERR("input HdfDeviceObject object is nullptr.");
41 return HDF_FAILURE;
42 }
43 node = device->property;
44 if (node == NULL) {
45 AUDIO_DRIVER_LOG_ERR("get drs node is nullptr.");
46 return HDF_FAILURE;
47 }
48 drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
49 if (drsOps == NULL || drsOps->GetString == NULL) {
50 AUDIO_DRIVER_LOG_ERR("drsOps or drsOps getString is null!");
51 return HDF_FAILURE;
52 }
53 ret = drsOps->GetString(node, "serviceName", &g_tfa9879Data.drvAccessoryName, 0);
54 if (ret != HDF_SUCCESS) {
55 AUDIO_DRIVER_LOG_ERR("read serviceName failed.");
56 return ret;
57 }
58 return HDF_SUCCESS;
59 }
60
61 /* HdfDriverEntry implementations */
Tfa9879DriverBind(struct HdfDeviceObject * device)62 static int32_t Tfa9879DriverBind(struct HdfDeviceObject *device)
63 {
64 (void)device;
65 AUDIO_DRIVER_LOG_INFO("success!");
66 return HDF_SUCCESS;
67 }
68
Tfa9879DriverInit(struct HdfDeviceObject * device)69 static int32_t Tfa9879DriverInit(struct HdfDeviceObject *device)
70 {
71 int32_t ret;
72 if (device == NULL) {
73 AUDIO_DRIVER_LOG_ERR("device is NULL.");
74 return HDF_ERR_INVALID_OBJECT;
75 }
76
77 ret = AccessoryGetConfigInfo(device, &g_tfa9879Data);
78 if (ret != HDF_SUCCESS) {
79 AUDIO_DRIVER_LOG_ERR("get config info failed.");
80 return ret;
81 }
82
83 ret = GetServiceName(device);
84 if (ret != HDF_SUCCESS) {
85 AUDIO_DRIVER_LOG_ERR("GetServiceName failed.");
86 return ret;
87 }
88
89 ret = AudioRegisterAccessory(device, &g_tfa9879Data, &g_tfa9879DaiData);
90 if (ret != HDF_SUCCESS) {
91 AUDIO_DRIVER_LOG_ERR("AudioRegisterAccessory failed.");
92 return ret;
93 }
94 AUDIO_DRIVER_LOG_INFO("success!");
95 return HDF_SUCCESS;
96 }
97
98 /* HdfDriverEntry definitions */
99 struct HdfDriverEntry g_tfa9879DriverEntry = {
100 .moduleVersion = 1,
101 .moduleName = "CODEC_TFA9879",
102 .Bind = Tfa9879DriverBind,
103 .Init = Tfa9879DriverInit,
104 .Release = NULL,
105 };
106 HDF_INIT(g_tfa9879DriverEntry);
107