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 10 #ifndef REGULATOR_IF_H 11 #define REGULATOR_IF_H 12 13 #include "platform_if.h" 14 15 #ifdef __cplusplus 16 #if __cplusplus 17 extern "C" { 18 #endif 19 #endif /* __cplusplus */ 20 21 /* regulator status on or off */ 22 enum RegulatorStatus { 23 REGULATOR_STATUS_ON = 1, 24 REGULATOR_STATUS_OFF, 25 }; 26 27 /* regulator mode, set voltage or current */ 28 enum RegulatorChangeMode { 29 REGULATOR_CHANGE_VOLTAGE = 1, 30 REGULATOR_CHANGE_CURRENT, 31 }; 32 /** 33 * @brief Gets a regulator. 34 * 35 * This function must be called to get its device handle before operating the regulator. 36 * 37 * @param name Indicates regulator name. 38 * 39 * @return If the operation is successful, a pointer to the regulator device handle is returned. 40 * 41 * @since 1.0 42 */ 43 DevHandle RegulatorOpen(const char *name); 44 /** 45 * @brief Releases a regulator. 46 * 47 * If you no longer need the regulator, call this function to release it 48 * 49 * @param handle Represents a pointer to the regulator device handle. 50 * 51 * @since 1.0 52 */ 53 void RegulatorClose(DevHandle handle); 54 /** 55 * @brief Enables a regulator. 56 * 57 * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}. 58 * @return <b>0</b> If the regulator enables successfully; Otherwise, a negative value is returned. 59 * 60 * @attention That if the regulator has been enabled before calling this function, calling this function will succeed. 61 * 62 * @since 1.0 63 */ 64 int32_t RegulatorEnable(DevHandle handle); 65 /** 66 * @brief Disable a regulator. 67 * 68 * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}. 69 * @return <b>0</b> If the regulator disable successfully; Otherwise, a negative value is returned. 70 * 71 * @attention If the regulator status alwayson is true or there is regulator child not disable, disabling fail 72 * 73 * @since 1.0 74 */ 75 int32_t RegulatorDisable(DevHandle handle); 76 /** 77 * @brief Force disable a regulator. 78 * 79 * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}. 80 * @return <b>0</b> If the regulator disable successfully; Otherwise, a negative value is returned. 81 * 82 * @attention No matter whether the status of the regulator is alwayson or the status of the child is enable, 83 * the regulator is disabled. 84 * 85 * @since 1.0 86 */ 87 int32_t RegulatorForceDisable(DevHandle handle); 88 /** 89 * @brief Set the output voltage range of a regulator. 90 * 91 * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}. 92 * @param minUv Represents minimum voltage 93 * @param minUv Represents maximum voltage 94 * @return <b>0</b> If the regulator setVoltage successfully; Otherwise, a negative value is returned. 95 * 96 * @attention If the set voltage is not within the contrants, the setting fails. 97 * 98 * @since 1.0 99 */ 100 int32_t RegulatorSetVoltage(DevHandle handle, uint32_t minUv, uint32_t maxUv); 101 /** 102 * @brief Get a regulator voltage. 103 * 104 * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}. 105 * @param voltage Voltage obtained. 106 * @return <b>0</b> If the regulator get voltage successfully; Otherwise, a negative value is returned. 107 * 108 * @since 1.0 109 */ 110 int32_t RegulatorGetVoltage(DevHandle handle, uint32_t *voltage); 111 /** 112 * @brief Set regulator current range 113 * 114 * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}. 115 * @param minUa Minimum current 116 * @param maxUa Maximum current 117 * @return <b>0</b> If the regulator set current range successfully; Otherwise, a negative value is returned. 118 * 119 * @attention If the setting range exceeds the limit, the setting fails 120 * 121 * @since 1.0 122 */ 123 int32_t RegulatorSetCurrent(DevHandle handle, uint32_t minUa, uint32_t maxUa); 124 /** 125 * @brief Get a regulator current 126 * 127 * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}. 128 * @param voltage Current obtained 129 * @return <b>0</b> If the regulator getCurrent successfully; Otherwise, a negative value is returned. 130 * 131 * @since 1.0 132 */ 133 int32_t RegulatorGetCurrent(DevHandle handle, uint32_t *regCurrent); 134 /** 135 * @brief Get a regulator status 136 * 137 * @param handle Represents a pointer to the regulator handle, which is obtained through {@ link RegulatorOpen}. 138 * @param status Status obtained, enable or disable 139 * @return <b>0</b> If the regulator get status successfully; Otherwise, a negative value is returned. 140 * 141 * @since 1.0 142 */ 143 int32_t RegulatorGetStatus(DevHandle handle, uint32_t *status); 144 #ifdef __cplusplus 145 #if __cplusplus 146 } 147 #endif 148 #endif /* __cplusplus */ 149 150 #endif /* REGULATOR_IF_H */ 151 /** @} */ 152