9#ifndef ZEPHYR_INCLUDE_DRIVERS_REGULATOR_H_
10#define ZEPHYR_INCLUDE_DRIVERS_REGULATOR_H_
24#ifdef CONFIG_REGULATOR_THREAD_SAFE_REFCNT
49#define REGULATOR_ERROR_OVER_VOLTAGE BIT(0)
51#define REGULATOR_ERROR_OVER_CURRENT BIT(1)
53#define REGULATOR_ERROR_OVER_TEMP BIT(2)
59typedef int (*regulator_dvs_state_set_t)(
const struct device *dev,
62typedef int (*regulator_ship_mode_t)(
const struct device *dev);
65__subsystem
struct regulator_parent_driver_api {
66 regulator_dvs_state_set_t dvs_state_set;
67 regulator_ship_mode_t ship_mode;
70typedef int (*regulator_enable_t)(
const struct device *dev);
71typedef int (*regulator_disable_t)(
const struct device *dev);
72typedef unsigned int (*regulator_count_voltages_t)(
const struct device *dev);
73typedef int (*regulator_list_voltage_t)(
const struct device *dev,
74 unsigned int idx,
int32_t *volt_uv);
75typedef int (*regulator_set_voltage_t)(
const struct device *dev,
int32_t min_uv,
77typedef int (*regulator_get_voltage_t)(
const struct device *dev,
79typedef int (*regulator_set_current_limit_t)(
const struct device *dev,
81typedef int (*regulator_get_current_limit_t)(
const struct device *dev,
83typedef int (*regulator_set_mode_t)(
const struct device *dev,
85typedef int (*regulator_get_mode_t)(
const struct device *dev,
87typedef int (*regulator_get_error_flags_t)(
91__subsystem
struct regulator_driver_api {
92 regulator_enable_t enable;
93 regulator_disable_t disable;
94 regulator_count_voltages_t count_voltages;
95 regulator_list_voltage_t list_voltage;
96 regulator_set_voltage_t set_voltage;
97 regulator_get_voltage_t get_voltage;
98 regulator_set_current_limit_t set_current_limit;
99 regulator_get_current_limit_t get_current_limit;
100 regulator_set_mode_t set_mode;
101 regulator_get_mode_t get_mode;
102 regulator_get_error_flags_t get_error_flags;
111#define REGULATOR_ALWAYS_ON BIT(0)
113#define REGULATOR_BOOT_ON BIT(1)
115#define REGULATOR_INIT_ENABLED (REGULATOR_ALWAYS_ON | REGULATOR_BOOT_ON)
120#define REGULATOR_INITIAL_MODE_UNKNOWN UINT8_MAX
127struct regulator_common_config {
153#define REGULATOR_DT_COMMON_CONFIG_INIT(node_id) \
155 .min_uv = DT_PROP_OR(node_id, regulator_min_microvolt, \
157 .max_uv = DT_PROP_OR(node_id, regulator_max_microvolt, \
159 .init_uv = DT_PROP_OR(node_id, regulator_init_microvolt, \
161 .min_ua = DT_PROP_OR(node_id, regulator_min_microamp, \
163 .max_ua = DT_PROP_OR(node_id, regulator_max_microamp, \
165 .allowed_modes = (const regulator_mode_t []) \
166 DT_PROP_OR(node_id, regulator_allowed_modes, {}), \
167 .allowed_modes_cnt = \
168 DT_PROP_LEN_OR(node_id, regulator_allowed_modes, 0), \
169 .initial_mode = DT_PROP_OR(node_id, regulator_initial_mode, \
170 REGULATOR_INITIAL_MODE_UNKNOWN), \
171 .flags = ((DT_PROP_OR(node_id, regulator_always_on, 0U) * \
172 REGULATOR_ALWAYS_ON) | \
173 (DT_PROP_OR(node_id, regulator_boot_on, 0U) * \
174 REGULATOR_BOOT_ON)), \
182#define REGULATOR_DT_INST_COMMON_CONFIG_INIT(inst) \
183 REGULATOR_DT_COMMON_CONFIG_INIT(DT_DRV_INST(inst))
190struct regulator_common_data {
191#if defined(CONFIG_REGULATOR_THREAD_SAFE_REFCNT) || defined(__DOXYGEN__)
206void regulator_common_data_init(
const struct device *dev);
229int regulator_common_init(
const struct device *dev,
bool is_enabled);
238static inline bool regulator_common_is_init_enabled(
const struct device *dev)
240 const struct regulator_common_config *config =
241 (
const struct regulator_common_config *)dev->
config;
243 return (config->flags & REGULATOR_INIT_ENABLED) != 0U;
255static inline int regulator_common_get_min_voltage(
const struct device *dev,
int32_t *min_uv)
257 const struct regulator_common_config *config =
258 (
const struct regulator_common_config *)dev->
config;
264 *min_uv = config->min_uv;
298 const struct regulator_parent_driver_api *api =
299 (
const struct regulator_parent_driver_api *)dev->
api;
301 if (api->dvs_state_set == NULL) {
305 return api->dvs_state_set(dev,
state);
324 const struct regulator_parent_driver_api *api =
325 (
const struct regulator_parent_driver_api *)dev->
api;
327 if (api->ship_mode == NULL) {
331 return api->ship_mode(dev);
393 const struct regulator_driver_api *api =
394 (
const struct regulator_driver_api *)dev->
api;
396 if (api->count_voltages == NULL) {
400 return api->count_voltages(dev);
419 unsigned int idx,
int32_t *volt_uv)
421 const struct regulator_driver_api *api =
422 (
const struct regulator_driver_api *)dev->
api;
424 if (api->list_voltage == NULL) {
428 return api->list_voltage(dev, idx, volt_uv);
478 const struct regulator_driver_api *api =
479 (
const struct regulator_driver_api *)dev->
api;
481 if (api->get_voltage == NULL) {
485 return api->get_voltage(dev, volt_uv);
521 const struct regulator_driver_api *api =
522 (
const struct regulator_driver_api *)dev->
api;
524 if (api->get_current_limit == NULL) {
528 return api->get_current_limit(dev, curr_ua);
562 const struct regulator_driver_api *api =
563 (
const struct regulator_driver_api *)dev->
api;
565 if (api->get_mode == NULL) {
569 return api->get_mode(dev, mode);
585 const struct regulator_driver_api *api =
586 (
const struct regulator_driver_api *)dev->
api;
588 if (api->get_error_flags == NULL) {
592 return api->get_error_flags(dev,
flags);
int regulator_enable(const struct device *dev)
Enable a regulator.
int regulator_set_mode(const struct device *dev, regulator_mode_t mode)
Set mode.
uint8_t regulator_mode_t
Opaque type to store regulator modes.
Definition: regulator.h:37
bool regulator_is_enabled(const struct device *dev)
Check if a regulator is enabled.
int regulator_set_voltage(const struct device *dev, int32_t min_uv, int32_t max_uv)
Set the output voltage.
int regulator_set_current_limit(const struct device *dev, int32_t min_ua, int32_t max_ua)
Set output current limit.
bool regulator_is_supported_voltage(const struct device *dev, int32_t min_uv, int32_t max_uv)
Check if a voltage within a window is supported.
uint8_t regulator_error_flags_t
Opaque bit map for regulator error flags (see REGULATOR_ERRORS)
Definition: regulator.h:40
static int regulator_list_voltage(const struct device *dev, unsigned int idx, int32_t *volt_uv)
Obtain the value of a voltage given an index.
Definition: regulator.h:418
static int regulator_get_current_limit(const struct device *dev, int32_t *curr_ua)
Get output current limit.
Definition: regulator.h:518
static int regulator_get_error_flags(const struct device *dev, regulator_error_flags_t *flags)
Get active error flags.
Definition: regulator.h:582
static unsigned int regulator_count_voltages(const struct device *dev)
Obtain the number of supported voltage levels.
Definition: regulator.h:391
uint8_t regulator_dvs_state_t
Opaque type to store regulator DVS states.
Definition: regulator.h:34
static int regulator_get_mode(const struct device *dev, regulator_mode_t *mode)
Get mode.
Definition: regulator.h:559
static int regulator_get_voltage(const struct device *dev, int32_t *volt_uv)
Obtain output voltage.
Definition: regulator.h:475
int regulator_disable(const struct device *dev)
Disable a regulator.
static int regulator_parent_dvs_state_set(const struct device *dev, regulator_dvs_state_t state)
Set a DVS state.
Definition: regulator.h:295
static int regulator_parent_ship_mode(const struct device *dev)
Enter ship mode.
Definition: regulator.h:322
#define ENOENT
No such file or directory.
Definition: errno.h:41
#define EINVAL
Invalid argument.
Definition: errno.h:61
#define ENOSYS
Function not implemented.
Definition: errno.h:83
flags
Definition: parser.h:96
state
Definition: parser_state.h:29
__INT32_TYPE__ int32_t
Definition: stdint.h:74
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
#define INT32_MIN
Definition: stdint.h:24
Runtime device structure (in ROM) per driver instance.
Definition: device.h:381
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:387
const void * config
Address of device instance config information.
Definition: device.h:385
Mutex Structure.
Definition: kernel.h:2911