Zephyr API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Interfaces for regulators. More...

Topics

 Devicetree Regulator API
 
 
 Regulator Parent Interface
 Regulator Parent Interface .
 

Files

file  regulator.h
 Main header file for regulator driver API.
 

Data Structures

struct  regulator_event
 Regulator event structure. More...
 

Typedefs

typedef uint8_t regulator_dvs_state_t
 Opaque type to store regulator DVS states.
 
typedef uint8_t regulator_mode_t
 Opaque type to store regulator modes.
 
typedef uint8_t regulator_error_flags_t
 Opaque bit map for regulator error flags (see REGULATOR_ERRORS)
 
typedef void(* regulator_callback_t) (const struct device *dev, const struct regulator_event *const evt, const void *const user_data)
 Regulator callback function signature.
 

Enumerations

enum  regulator_event_type { REGULATOR_VOLTAGE_DETECTED , REGULATOR_VOLTAGE_REMOVED }
 Regulator event types. More...
 

Functions

int regulator_enable (const struct device *dev)
 Enable a regulator.
 
bool regulator_is_enabled (const struct device *dev)
 Check if a regulator is enabled.
 
int regulator_disable (const struct device *dev)
 Disable a regulator.
 
static unsigned int regulator_count_voltages (const struct device *dev)
 Obtain the number of supported voltage levels.
 
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.
 
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.
 
int regulator_set_voltage (const struct device *dev, int32_t min_uv, int32_t max_uv)
 Set the output voltage.
 
static int regulator_get_voltage (const struct device *dev, int32_t *volt_uv)
 Obtain output voltage.
 
static unsigned int regulator_count_current_limits (const struct device *dev)
 Obtain the number of supported current limit levels.
 
static int regulator_list_current_limit (const struct device *dev, unsigned int idx, int32_t *current_ua)
 Obtain the value of a current limit given an index.
 
int regulator_set_current_limit (const struct device *dev, int32_t min_ua, int32_t max_ua)
 Set output current limit.
 
static int regulator_get_current_limit (const struct device *dev, int32_t *curr_ua)
 Get output current limit.
 
int regulator_set_mode (const struct device *dev, regulator_mode_t mode)
 Set mode.
 
static int regulator_get_mode (const struct device *dev, regulator_mode_t *mode)
 Get mode.
 
static int regulator_set_active_discharge (const struct device *dev, bool active_discharge)
 Set active discharge setting.
 
static int regulator_get_active_discharge (const struct device *dev, bool *active_discharge)
 Get active discharge setting.
 
static int regulator_get_error_flags (const struct device *dev, regulator_error_flags_t *flags)
 Get active error flags.
 
static int regulator_set_callback (const struct device *dev, regulator_callback_t cb, const void *const user_data)
 Set event handler function.
 

Regulator error flags.

#define REGULATOR_ERROR_OVER_VOLTAGE   BIT(0)
 Voltage is too high.
 
#define REGULATOR_ERROR_OVER_CURRENT   BIT(1)
 Current is too high.
 
#define REGULATOR_ERROR_OVER_TEMP   BIT(2)
 Temperature is too high.
 

Detailed Description

Interfaces for regulators.

Since
2.4
Version
0.1.0

Macro Definition Documentation

◆ REGULATOR_ERROR_OVER_CURRENT

#define REGULATOR_ERROR_OVER_CURRENT   BIT(1)

#include <zephyr/drivers/regulator.h>

Current is too high.

◆ REGULATOR_ERROR_OVER_TEMP

#define REGULATOR_ERROR_OVER_TEMP   BIT(2)

#include <zephyr/drivers/regulator.h>

Temperature is too high.

◆ REGULATOR_ERROR_OVER_VOLTAGE

#define REGULATOR_ERROR_OVER_VOLTAGE   BIT(0)

#include <zephyr/drivers/regulator.h>

Voltage is too high.

Typedef Documentation

◆ regulator_callback_t

typedef void(* regulator_callback_t) (const struct device *dev, const struct regulator_event *const evt, const void *const user_data)

#include <zephyr/drivers/regulator.h>

Regulator callback function signature.

Parameters
devRegulator device instance
evtRegulator event
user_dataUser data

◆ regulator_dvs_state_t

#include <zephyr/drivers/regulator.h>

Opaque type to store regulator DVS states.

◆ regulator_error_flags_t

#include <zephyr/drivers/regulator.h>

Opaque bit map for regulator error flags (see REGULATOR_ERRORS)

◆ regulator_mode_t

#include <zephyr/drivers/regulator.h>

Opaque type to store regulator modes.

Enumeration Type Documentation

◆ regulator_event_type

#include <zephyr/drivers/regulator.h>

Regulator event types.

Enumerator
REGULATOR_VOLTAGE_DETECTED 

Regulator voltage is detected.

REGULATOR_VOLTAGE_REMOVED 

Regulator voltage is removed.

Function Documentation

◆ regulator_count_current_limits()

static unsigned int regulator_count_current_limits ( const struct device * dev)
inlinestatic

#include <zephyr/drivers/regulator.h>

Obtain the number of supported current limit levels.

Each current limit level supported by a regulator gets an index, starting from zero. The total number of supported current limit levels can be used together with regulator_list_current_limit() to list all supported current limit levels.

Parameters
devRegulator device instance.
Returns
Number of supported current limits.

◆ regulator_count_voltages()

static unsigned int regulator_count_voltages ( const struct device * dev)
inlinestatic

#include <zephyr/drivers/regulator.h>

Obtain the number of supported voltage levels.

Each voltage level supported by a regulator gets an index, starting from zero. The total number of supported voltage levels can be used together with regulator_list_voltage() to list all supported voltage levels.

Parameters
devRegulator device instance.
Returns
Number of supported voltages.

◆ regulator_disable()

int regulator_disable ( const struct device * dev)

#include <zephyr/drivers/regulator.h>

Disable a regulator.

Release a regulator after a previous regulator_enable() completed successfully. Regulators that are always on, or configured in devicetree with regulator-always-on will always stay enabled, and so this function will always succeed.

This must be invoked at most once for each successful regulator_enable().

Parameters
devRegulator device instance.
Returns
0 on success, negative errno value on failure.
Return values
-ENOTSUPRegulator disablement can not be controlled.

◆ regulator_enable()

int regulator_enable ( const struct device * dev)

#include <zephyr/drivers/regulator.h>

Enable a regulator.

Reference-counted request that a regulator be turned on. A regulator is considered "on" when it has reached a stable/usable state. Regulators that are always on, or configured in devicetree with regulator-always-on will always stay enabled, and so this function will always succeed.

Parameters
devRegulator device instance
Returns
0 on success, negative errno value on failure.
Return values
-ENOTSUPRegulator enablement can not be controlled.

◆ regulator_get_active_discharge()

static int regulator_get_active_discharge ( const struct device * dev,
bool * active_discharge )
inlinestatic

#include <zephyr/drivers/regulator.h>

Get active discharge setting.

Parameters
devRegulator device instance.
[out]active_dischargeWhere active discharge will be stored.
Returns
0 on success, negative errno value on failure.
Return values
-ENOSYSFunction is not implemented.

◆ regulator_get_current_limit()

static int regulator_get_current_limit ( const struct device * dev,
int32_t * curr_ua )
inlinestatic

#include <zephyr/drivers/regulator.h>

Get output current limit.

Parameters
devRegulator device instance.
[out]curr_uaWhere output current limit will be stored.
Returns
0 on success, negative errno value on failure.
Return values
-ENOSYSFunction is not implemented.

◆ regulator_get_error_flags()

static int regulator_get_error_flags ( const struct device * dev,
regulator_error_flags_t * flags )
inlinestatic

#include <zephyr/drivers/regulator.h>

Get active error flags.

Parameters
devRegulator device instance.
[out]flagsWhere error flags will be stored.
Returns
0 on success, negative errno value on failure.
Return values
-ENOSYSFunction is not implemented.

◆ regulator_get_mode()

static int regulator_get_mode ( const struct device * dev,
regulator_mode_t * mode )
inlinestatic

#include <zephyr/drivers/regulator.h>

Get mode.

Parameters
devRegulator device instance.
[out]modeWhere mode will be stored.
Returns
0 on success, negative errno value on failure.
Return values
-ENOSYSFunction is not implemented.

◆ regulator_get_voltage()

static int regulator_get_voltage ( const struct device * dev,
int32_t * volt_uv )
inlinestatic

#include <zephyr/drivers/regulator.h>

Obtain output voltage.

Parameters
devRegulator device instance.
[out]volt_uvWhere configured output voltage will be stored.
Returns
0 on success, negative errno value on failure.
Return values
-ENOSYSFunction is not implemented.

◆ regulator_is_enabled()

bool regulator_is_enabled ( const struct device * dev)

#include <zephyr/drivers/regulator.h>

Check if a regulator is enabled.

Parameters
devRegulator device instance.
Return values
trueRegulator is enabled.
falseRegulator is disabled.

◆ regulator_is_supported_voltage()

bool regulator_is_supported_voltage ( const struct device * dev,
int32_t min_uv,
int32_t max_uv )

#include <zephyr/drivers/regulator.h>

Check if a voltage within a window is supported.

Parameters
devRegulator device instance.
min_uvMinimum voltage in microvolts.
max_uvmaximum voltage in microvolts.
Return values
trueVoltage is supported.
falseVoltage is not supported.

◆ regulator_list_current_limit()

static int regulator_list_current_limit ( const struct device * dev,
unsigned int idx,
int32_t * current_ua )
inlinestatic

#include <zephyr/drivers/regulator.h>

Obtain the value of a current limit given an index.

Each current limit level supported by a regulator gets an index, starting from zero. Together with regulator_count_current_limits(), this function can be used to iterate over all supported current limits.

Parameters
devRegulator device instance.
idxCurrent index.
[out]current_uaWhere current for the given index will be stored, in microamps.
Return values
0index corresponds to a supported current limit.
-EINVALindex does not correspond to a supported current limit.

◆ regulator_list_voltage()

static int regulator_list_voltage ( const struct device * dev,
unsigned int idx,
int32_t * volt_uv )
inlinestatic

#include <zephyr/drivers/regulator.h>

Obtain the value of a voltage given an index.

Each voltage level supported by a regulator gets an index, starting from zero. Together with regulator_count_voltages(), this function can be used to iterate over all supported voltages.

Parameters
devRegulator device instance.
idxVoltage index.
[out]volt_uvWhere voltage for the given index will be stored, in microvolts.
Return values
0index corresponds to a supported voltage.
-EINVALindex does not correspond to a supported voltage.

◆ regulator_set_active_discharge()

static int regulator_set_active_discharge ( const struct device * dev,
bool active_discharge )
inlinestatic

#include <zephyr/drivers/regulator.h>

Set active discharge setting.

Parameters
devRegulator device instance.
active_dischargeActive discharge enable or disable.
Returns
0 on success, negative errno value on failure.
Return values
-ENOSYSFunction is not implemented.

◆ regulator_set_callback()

static int regulator_set_callback ( const struct device * dev,
regulator_callback_t cb,
const void *const user_data )
inlinestatic

#include <zephyr/drivers/regulator.h>

Set event handler function.

The regulator may generate an interrupt when, for example, the voltage is present. This can be used for USB VBUS voltage regulators to notify that a device is connected to a port.

Parameters
devRegulator device instance
cbEvent handler
user_dataUser data
Return values
0on success.
-ENOSYSFunction is not implemented.

◆ regulator_set_current_limit()

int regulator_set_current_limit ( const struct device * dev,
int32_t min_ua,
int32_t max_ua )

#include <zephyr/drivers/regulator.h>

Set output current limit.

The output current limit will be configured to the closest supported output current limit. regulator_get_current_limit() can be used to obtain the actual configured current limit. Current may be limited using current-min-microamp and/or current-max-microamp in Devicetree.

Parameters
devRegulator device instance.
min_uaMinimum acceptable current limit in microamps.
max_uaMaximum acceptable current limit in microamps.
Returns
0 on success, negative errno value on failure.
Return values
-EINVALGiven current limit window is not valid.
-ENOSYSFunction is not implemented.

◆ regulator_set_mode()

int regulator_set_mode ( const struct device * dev,
regulator_mode_t mode )

#include <zephyr/drivers/regulator.h>

Set mode.

Regulators can support multiple modes in order to permit different voltage configuration or better power savings. This API will apply a mode for the regulator. Allowed modes may be limited using regulator-allowed-modes devicetree property.

Parameters
devRegulator device instance.
modeMode to select for this regulator.
Returns
0 on success, negative errno value on failure.
Return values
-ENOTSUPMode is not supported.
-ENOSYSFunction is not implemented.

◆ regulator_set_voltage()

int regulator_set_voltage ( const struct device * dev,
int32_t min_uv,
int32_t max_uv )

#include <zephyr/drivers/regulator.h>

Set the output voltage.

The output voltage will be configured to the closest supported output voltage. regulator_get_voltage() can be used to obtain the actual configured voltage. The voltage will be applied to the active or selected mode. Output voltage may be limited using regulator-min-microvolt and/or regulator-max-microvolt in devicetree.

Parameters
devRegulator device instance.
min_uvMinimum acceptable voltage in microvolts.
max_uvMaximum acceptable voltage in microvolts.
Returns
0 on success, negative errno value on failure.
Return values
-EINVALGiven voltage window is not valid.
-ENOSYSFunction is not implemented.