Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions include/zephyr/drivers/regulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,33 @@ typedef uint8_t regulator_error_flags_t;

/** @} */

/**
* @brief Regulator event types
*/
enum regulator_event_type {
/** @brief Regulator voltage is detected */
REGULATOR_VOLTAGE_DETECTED,
/** @brief Regulator voltage is removed */
REGULATOR_VOLTAGE_REMOVED,
};

/** @brief Regulator event structure */
struct regulator_event {
enum regulator_event_type type;
};

/**
* @typedef regulator_callback_t
* @brief Regulator callback function signature
*
* @param dev Regulator device instance
* @param evt Regulator event
* @param user_data User data
*/
typedef void (*regulator_callback_t)(const struct device *dev,
const struct regulator_event *const evt,
const void *const user_data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/** @cond INTERNAL_HIDDEN */

typedef int (*regulator_dvs_state_set_t)(const struct device *dev,
Expand Down Expand Up @@ -102,6 +129,8 @@ typedef int (*regulator_get_active_discharge_t)(const struct device *dev,
bool *active_discharge);
typedef int (*regulator_get_error_flags_t)(
const struct device *dev, regulator_error_flags_t *flags);
typedef int (*regulator_set_callback_t)(const struct device *dev,
regulator_callback_t cb, const void *const user_data);

/** @brief Driver-specific API functions to support regulator control. */
__subsystem struct regulator_driver_api {
Expand All @@ -120,6 +149,7 @@ __subsystem struct regulator_driver_api {
regulator_set_active_discharge_t set_active_discharge;
regulator_get_active_discharge_t get_active_discharge;
regulator_get_error_flags_t get_error_flags;
regulator_set_callback_t set_callback;
};

/**
Expand Down Expand Up @@ -765,6 +795,34 @@ static inline int regulator_get_error_flags(const struct device *dev,
return api->get_error_flags(dev, flags);
}

/**
* @brief 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.
*
* @param dev Regulator device instance
* @param cb Event handler
* @param user_data User data
*
* @retval 0 If successful.
* @retval -ENOSYS If not supported by the device.
*/
static inline int regulator_set_callback(const struct device *dev,
regulator_callback_t cb,
const void *const user_data)
{
const struct regulator_driver_api *api =
(const struct regulator_driver_api *)dev->api;

if (api->set_callback == NULL) {
return -ENOSYS;
}

return api->set_callback(dev, cb, user_data);
}

#ifdef __cplusplus
}
#endif
Expand Down