• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "audio_codec_base.h"
10 
11 #define HDF_LOG_TAG audio_codec_base
12 
CodecDeviceReadReg(const struct CodecDevice * codec,uint32_t reg,uint32_t * val)13 int32_t CodecDeviceReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val)
14 {
15     unsigned long acodecVir;
16     struct VirtualAddress *virtualAdd = NULL;
17     AUDIO_DRIVER_LOG_DEBUG("entry");
18 
19     if ((codec == NULL) || (codec->device == NULL) || (val == NULL)) {
20         AUDIO_DRIVER_LOG_ERR("input param codec or codec->device is NULL.");
21         return HDF_ERR_INVALID_OBJECT;
22     }
23     virtualAdd = (struct VirtualAddress *)((volatile uintptr_t)codec->device->priv);
24     if (virtualAdd == NULL) {
25         AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL.");
26         return HDF_ERR_INVALID_OBJECT;
27     }
28     acodecVir = virtualAdd->acodecVir;
29     *val = OSAL_READL((void *)(acodecVir + reg));
30 
31     AUDIO_DRIVER_LOG_DEBUG("success");
32     return HDF_SUCCESS;
33 }
34 
CodecDeviceWriteReg(const struct CodecDevice * codec,uint32_t reg,uint32_t value)35 int32_t CodecDeviceWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t value)
36 {
37     unsigned long acodecVir;
38     struct VirtualAddress *virtualAdd = NULL;
39     AUDIO_DRIVER_LOG_DEBUG("entry");
40 
41     if ((codec == NULL) || (codec->device == NULL)) {
42         AUDIO_DRIVER_LOG_ERR("param  codec or codec->device is NULL.");
43         return HDF_ERR_INVALID_OBJECT;
44     }
45 
46     virtualAdd = (struct VirtualAddress *)((volatile uintptr_t)codec->device->priv);
47     if (virtualAdd == NULL) {
48         AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL.");
49         return HDF_ERR_INVALID_OBJECT;
50     }
51 
52     acodecVir = virtualAdd->acodecVir;
53     OSAL_WRITEL(value, (void *)(acodecVir + reg));
54 
55     AUDIO_DRIVER_LOG_DEBUG("success");
56     return HDF_SUCCESS;
57 }
58 
CodecAiaoDeviceReadReg(const struct CodecDevice * codec,uint32_t reg,uint32_t * val)59 int32_t CodecAiaoDeviceReadReg(const struct CodecDevice *codec, uint32_t reg, uint32_t *val)
60 {
61     unsigned long aiaoVir;
62     struct VirtualAddress *virtualAdd = NULL;
63     AUDIO_DRIVER_LOG_DEBUG("entry");
64 
65     if ((codec == NULL) || (codec->device == NULL) || (val == NULL)) {
66         AUDIO_DRIVER_LOG_ERR("codec or codec->device is NULL.");
67         return HDF_ERR_INVALID_OBJECT;
68     }
69 
70     virtualAdd = (struct VirtualAddress *)((volatile uintptr_t)codec->device->priv);
71     if (virtualAdd == NULL) {
72         AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL.");
73         return HDF_ERR_INVALID_OBJECT;
74     }
75 
76     aiaoVir = virtualAdd->aiaoVir;
77     *val = OSAL_READL((void *)(aiaoVir + reg));
78 
79     AUDIO_DRIVER_LOG_DEBUG("success");
80     return HDF_SUCCESS;
81 }
82 
CodecAiaoDeviceWriteReg(const struct CodecDevice * codec,uint32_t reg,uint32_t value)83 int32_t CodecAiaoDeviceWriteReg(const struct CodecDevice *codec, uint32_t reg, uint32_t value)
84 {
85     unsigned long aiaoVir;
86     struct VirtualAddress *virtualAdd = NULL;
87     AUDIO_DRIVER_LOG_DEBUG("entry");
88 
89     if ((codec == NULL) || (codec->device == NULL)) {
90         AUDIO_DRIVER_LOG_ERR("codec or codec->device is NULL.");
91         return HDF_ERR_INVALID_OBJECT;
92     }
93     virtualAdd = (struct VirtualAddress *)((volatile uintptr_t)codec->device->priv);
94     if (virtualAdd == NULL) {
95         AUDIO_DRIVER_LOG_ERR("virtualAdd is NULL.");
96         return HDF_ERR_INVALID_OBJECT;
97     }
98 
99     aiaoVir = virtualAdd->aiaoVir;
100     OSAL_WRITEL(value, (void *)(aiaoVir + reg));
101 
102     AUDIO_DRIVER_LOG_DEBUG("success");
103     return HDF_SUCCESS;
104 }
105 
CodecGetServiceName(const struct HdfDeviceObject * device,const char ** drvCodecName)106 int32_t CodecGetServiceName(const struct HdfDeviceObject *device, const char **drvCodecName)
107 {
108     const struct DeviceResourceNode *node = NULL;
109     struct DeviceResourceIface *drsOps = NULL;
110     int32_t ret;
111 
112     if (device == NULL) {
113         AUDIO_DRIVER_LOG_ERR("input device para is nullptr.");
114         return HDF_FAILURE;
115     }
116 
117     node = device->property;
118     if (node == NULL) {
119         AUDIO_DRIVER_LOG_ERR("node instance is nullptr.");
120         return HDF_FAILURE;
121     }
122     drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
123     if (drsOps == NULL || drsOps->GetString == NULL) {
124         AUDIO_DRIVER_LOG_ERR("from resouce get drsOps fail!");
125         return HDF_FAILURE;
126     }
127 
128     ret = drsOps->GetString(node, "serviceName", drvCodecName, 0);
129     if (ret != HDF_SUCCESS) {
130         AUDIO_DRIVER_LOG_ERR("read codecServiceName fail!");
131         return ret;
132     }
133 
134     return HDF_SUCCESS;
135 }
136 
CodecGetDaiName(const struct HdfDeviceObject * device,const char ** drvDaiName)137 int32_t CodecGetDaiName(const struct HdfDeviceObject *device, const char **drvDaiName)
138 {
139     const struct DeviceResourceNode *node = NULL;
140     struct DeviceResourceIface *drsOps = NULL;
141     int32_t ret;
142 
143     if (device == NULL) {
144         AUDIO_DRIVER_LOG_ERR("input para is NULL.");
145         return HDF_FAILURE;
146     }
147 
148     node = device->property;
149     if (node == NULL) {
150         AUDIO_DRIVER_LOG_ERR("drs node is NULL.");
151         return HDF_FAILURE;
152     }
153     drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
154     if (drsOps == NULL || drsOps->GetString == NULL) {
155         AUDIO_DRIVER_LOG_ERR("drs ops failed!");
156         return HDF_FAILURE;
157     }
158 
159     ret = drsOps->GetString(node, "codecDaiName", drvDaiName, 0);
160     if (ret != HDF_SUCCESS) {
161         AUDIO_DRIVER_LOG_ERR("read codecDaiName fail!");
162         return ret;
163     }
164 
165     return HDF_SUCCESS;
166 }
167