@@ -76,6 +76,9 @@ typedef int (*regulator_set_voltage_t)(const struct device *dev, int32_t min_uv,
7676 int32_t max_uv );
7777typedef int (* regulator_get_voltage_t )(const struct device * dev ,
7878 int32_t * volt_uv );
79+ typedef unsigned int (* regulator_count_current_limits_t )(const struct device * dev );
80+ typedef int (* regulator_list_current_limit_t )(const struct device * dev ,
81+ unsigned int idx , int32_t * current_ua );
7982typedef int (* regulator_set_current_limit_t )(const struct device * dev ,
8083 int32_t min_ua , int32_t max_ua );
8184typedef int (* regulator_get_current_limit_t )(const struct device * dev ,
@@ -95,6 +98,8 @@ __subsystem struct regulator_driver_api {
9598 regulator_list_voltage_t list_voltage ;
9699 regulator_set_voltage_t set_voltage ;
97100 regulator_get_voltage_t get_voltage ;
101+ regulator_count_current_limits_t count_current_limits ;
102+ regulator_list_current_limit_t list_current_limit ;
98103 regulator_set_current_limit_t set_current_limit ;
99104 regulator_get_current_limit_t get_current_limit ;
100105 regulator_set_mode_t set_mode ;
@@ -485,6 +490,57 @@ static inline int regulator_get_voltage(const struct device *dev,
485490 return api -> get_voltage (dev , volt_uv );
486491}
487492
493+ /**
494+ * @brief Obtain the number of supported current limit levels.
495+ *
496+ * Each current limit level supported by a regulator gets an index, starting from
497+ * zero. The total number of supported current limit levels can be used together with
498+ * regulator_list_current_limit() to list all supported current limit levels.
499+ *
500+ * @param dev Regulator device instance.
501+ *
502+ * @return Number of supported current limits.
503+ */
504+ static inline unsigned int regulator_count_current_limits (const struct device * dev )
505+ {
506+ const struct regulator_driver_api * api =
507+ (const struct regulator_driver_api * )dev -> api ;
508+
509+ if (api -> count_current_limits == NULL ) {
510+ return 0U ;
511+ }
512+
513+ return api -> count_current_limits (dev );
514+ }
515+
516+ /**
517+ * @brief Obtain the value of a current limit given an index.
518+ *
519+ * Each current limit level supported by a regulator gets an index, starting from
520+ * zero. Together with regulator_count_current_limits(), this function can be used
521+ * to iterate over all supported current limits.
522+ *
523+ * @param dev Regulator device instance.
524+ * @param idx Current index.
525+ * @param[out] current_ua Where current for the given @p index will be stored, in
526+ * microamps.
527+ *
528+ * @retval 0 If @p index corresponds to a supported current limit.
529+ * @retval -EINVAL If @p index does not correspond to a supported current limit.
530+ */
531+ static inline int regulator_list_current_limit (const struct device * dev ,
532+ unsigned int idx , int32_t * current_ua )
533+ {
534+ const struct regulator_driver_api * api =
535+ (const struct regulator_driver_api * )dev -> api ;
536+
537+ if (api -> list_current_limit == NULL ) {
538+ return - EINVAL ;
539+ }
540+
541+ return api -> list_current_limit (dev , idx , current_ua );
542+ }
543+
488544/**
489545 * @brief Set output current limit.
490546 *
0 commit comments