• 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 #include "regulator_if.h"
9 #include "hdf_log.h"
10 #include "regulator_core.h"
11 
RegulatorOpen(const char * name)12 DevHandle RegulatorOpen(const char *name)
13 {
14     if (name == NULL) {
15         HDF_LOGE("%s: name is null", __func__);
16         return NULL;
17     }
18 
19     return (DevHandle)RegulatorNodeOpen(name);
20 }
21 
RegulatorClose(DevHandle handle)22 void RegulatorClose(DevHandle handle)
23 {
24     struct RegulatorNode *node = (struct RegulatorNode *)handle;
25     if (node == NULL) {
26         HDF_LOGE("%s: node is null", __func__);
27         return;
28     }
29 
30     if (RegulatorNodeClose(node) != HDF_SUCCESS) {
31         HDF_LOGE("%s: RegulatorNodeClose fail", __func__);
32         return;
33     }
34 }
35 
RegulatorEnable(DevHandle handle)36 int32_t RegulatorEnable(DevHandle handle)
37 {
38     struct RegulatorNode *node = (struct RegulatorNode *)handle;
39     if (node == NULL) {
40         HDF_LOGE("%s: node is null", __func__);
41         return HDF_FAILURE;
42     }
43 
44     int ret = RegulatorNodeEnable(node);
45     if (ret != HDF_SUCCESS) {
46         HDF_LOGE("%s: RegulatorNodeEnable fail", __func__);
47         return HDF_FAILURE;
48     }
49 
50     return HDF_SUCCESS;
51 }
52 
RegulatorDisable(DevHandle handle)53 int32_t RegulatorDisable(DevHandle handle)
54 {
55     struct RegulatorNode *node = (struct RegulatorNode *)handle;
56     if (node == NULL) {
57         HDF_LOGE("%s: node is null", __func__);
58         return HDF_FAILURE;
59     }
60 
61     int ret = RegulatorNodeDisable(node);
62     if (ret != HDF_SUCCESS) {
63         HDF_LOGE("%s: RegulatorNodeDisable fail", __func__);
64         return HDF_FAILURE;
65     }
66 
67     return HDF_SUCCESS;
68 }
69 
RegulatorForceDisable(DevHandle handle)70 int32_t RegulatorForceDisable(DevHandle handle)
71 {
72     struct RegulatorNode *node = (struct RegulatorNode *)handle;
73     if (node == NULL) {
74         HDF_LOGE("%s: node is null", __func__);
75         return HDF_FAILURE;
76     }
77 
78     int ret = RegulatorNodeForceDisable(node);
79     if (ret != HDF_SUCCESS) {
80         HDF_LOGE("%s: RegulatorNodeForceDisable fail", __func__);
81         return HDF_FAILURE;
82     }
83 
84     return HDF_SUCCESS;
85 }
86 
RegulatorSetVoltage(DevHandle handle,uint32_t minUv,uint32_t maxUv)87 int32_t RegulatorSetVoltage(DevHandle handle, uint32_t minUv, uint32_t maxUv)
88 {
89     struct RegulatorNode *node = (struct RegulatorNode *)handle;
90     if (node == NULL) {
91         HDF_LOGE("%s: node is null", __func__);
92         return HDF_FAILURE;
93     }
94 
95     if (minUv > maxUv) {
96         HDF_LOGE("RegulatorSetVoltage: %s Uv [%d, %d] invalid!",
97             node->regulatorInfo.name, minUv, maxUv);
98         return HDF_FAILURE;
99     }
100 
101     int ret = RegulatorNodeSetVoltage(node, minUv, maxUv);
102     if (ret != HDF_SUCCESS) {
103         HDF_LOGE("%s: RegulatorSetVoltage fail", __func__);
104         return HDF_FAILURE;
105     }
106 
107     return HDF_SUCCESS;
108 }
109 
RegulatorGetVoltage(DevHandle handle,uint32_t * voltage)110 int32_t RegulatorGetVoltage(DevHandle handle, uint32_t *voltage)
111 {
112     struct RegulatorNode *node = (struct RegulatorNode *)handle;
113     if (node == NULL || voltage == NULL) {
114         HDF_LOGE("%s: param is null", __func__);
115         return HDF_FAILURE;
116     }
117 
118     int ret = RegulatorNodeGetVoltage(node, voltage);
119     if (ret != HDF_SUCCESS) {
120         HDF_LOGE("%s: RegulatorNodeGetVoltage fail", __func__);
121         return HDF_FAILURE;
122     }
123 
124     return HDF_SUCCESS;
125 }
126 
RegulatorSetCurrent(DevHandle handle,uint32_t minUa,uint32_t maxUa)127 int32_t RegulatorSetCurrent(DevHandle handle, uint32_t minUa, uint32_t maxUa)
128 {
129     struct RegulatorNode *node = (struct RegulatorNode *)handle;
130     if (node == NULL) {
131         HDF_LOGE("%s: node is null", __func__);
132         return HDF_FAILURE;
133     }
134 
135     if (minUa > maxUa) {
136         HDF_LOGE("RegulatorSetCurrent: %s Ua [%d, %d] invalid!",
137             node->regulatorInfo.name, minUa, maxUa);
138         return HDF_FAILURE;
139     }
140 
141     int ret = RegulatorNodeSetCurrent(node, minUa, maxUa);
142     if (ret != HDF_SUCCESS) {
143         HDF_LOGE("%s: RegulatorNodeSetCurrent fail", __func__);
144         return HDF_FAILURE;
145     }
146 
147     return HDF_SUCCESS;
148 }
149 
RegulatorGetCurrent(DevHandle handle,uint32_t * regCurrent)150 int32_t RegulatorGetCurrent(DevHandle handle, uint32_t *regCurrent)
151 {
152     struct RegulatorNode *node = (struct RegulatorNode *)handle;
153     if (node == NULL || regCurrent == NULL) {
154         HDF_LOGE("%s: param is null", __func__);
155         return HDF_FAILURE;
156     }
157 
158     int ret = RegulatorNodeGetCurrent(node, regCurrent);
159     if (ret != HDF_SUCCESS) {
160         HDF_LOGE("%s: RegulatorNodeGetCurrent fail", __func__);
161         return HDF_FAILURE;
162     }
163 
164     return HDF_SUCCESS;
165 }
166 
RegulatorGetStatus(DevHandle handle,uint32_t * status)167 int32_t RegulatorGetStatus(DevHandle handle, uint32_t *status)
168 {
169     struct RegulatorNode *node = (struct RegulatorNode *)handle;
170     if (node == NULL || status == NULL) {
171         HDF_LOGE("%s: param is null", __func__);
172         return HDF_FAILURE;
173     }
174 
175     int ret = RegulatorNodeGetStatus(node, status);
176     if (ret != HDF_SUCCESS) {
177         HDF_LOGE("%s: RegulatorNodeGetStatus fail", __func__);
178         return HDF_FAILURE;
179     }
180 
181     return HDF_SUCCESS;
182 }
183