drivers: regulator: improve regulator_get_current_limit
- Function returns now the value by reference, similar to voltage counterparts. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
8db7e046c5
commit
2bd6d50934
3 changed files with 15 additions and 9 deletions
|
@ -308,16 +308,19 @@ static int regulator_pca9420_get_voltage(const struct device *dev,
|
||||||
* Part of the extended regulator consumer API
|
* Part of the extended regulator consumer API
|
||||||
* Gets the set current limit for the regulator
|
* Gets the set current limit for the regulator
|
||||||
*/
|
*/
|
||||||
static int regulator_pca9420_get_current_limit(const struct device *dev)
|
static int regulator_pca9420_get_current_limit(const struct device *dev,
|
||||||
|
int32_t *curr_ua)
|
||||||
{
|
{
|
||||||
const struct regulator_pca9420_config *config = dev->config;
|
const struct regulator_pca9420_config *config = dev->config;
|
||||||
const struct regulator_pca9420_common_config *cconfig = config->parent->config;
|
const struct regulator_pca9420_common_config *cconfig = config->parent->config;
|
||||||
|
|
||||||
if (cconfig->vin_ilim_ua == 0U) {
|
if (cconfig->vin_ilim_ua == 0U) {
|
||||||
return config->max_ua;
|
*curr_ua = config->max_ua;
|
||||||
|
} else {
|
||||||
|
*curr_ua = MIN(config->max_ua, cconfig->vin_ilim_ua);
|
||||||
}
|
}
|
||||||
|
|
||||||
return MIN(config->max_ua, cconfig->vin_ilim_ua);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int regulator_pca9420_set_mode(const struct device *dev, uint32_t mode)
|
static int regulator_pca9420_set_mode(const struct device *dev, uint32_t mode)
|
||||||
|
|
|
@ -85,6 +85,7 @@ static int cmd_set_vol(const struct shell *sh, size_t argc, char **argv)
|
||||||
static int cmd_set_ilim(const struct shell *sh, size_t argc, char **argv)
|
static int cmd_set_ilim(const struct shell *sh, size_t argc, char **argv)
|
||||||
{
|
{
|
||||||
int lcur, ucur, ret;
|
int lcur, ucur, ret;
|
||||||
|
int32_t curr_ua;
|
||||||
const struct device *reg_dev;
|
const struct device *reg_dev;
|
||||||
|
|
||||||
reg_dev = device_get_binding(argv[1]);
|
reg_dev = device_get_binding(argv[1]);
|
||||||
|
@ -101,12 +102,12 @@ static int cmd_set_ilim(const struct shell *sh, size_t argc, char **argv)
|
||||||
shell_error(sh, "failed to set current, error %d", ret);
|
shell_error(sh, "failed to set current, error %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = regulator_get_current_limit(reg_dev);
|
ret = regulator_get_current_limit(reg_dev, &curr_ua);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
shell_error(sh, "failed to read current, error %d", ret);
|
shell_error(sh, "failed to read current, error %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
shell_print(sh, "set current limit to %d uA", ret);
|
shell_print(sh, "set current limit to %d uA", curr_ua);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ __subsystem struct regulator_driver_api {
|
||||||
int (*get_voltage)(const struct device *dev, int32_t *volt_uv);
|
int (*get_voltage)(const struct device *dev, int32_t *volt_uv);
|
||||||
int (*set_current_limit)(const struct device *dev, int32_t min_ua,
|
int (*set_current_limit)(const struct device *dev, int32_t min_ua,
|
||||||
int32_t max_ua);
|
int32_t max_ua);
|
||||||
int (*get_current_limit)(const struct device *dev);
|
int (*get_current_limit)(const struct device *dev, int32_t *curr_ua);
|
||||||
int (*set_mode)(const struct device *dev, uint32_t mode);
|
int (*set_mode)(const struct device *dev, uint32_t mode);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -242,12 +242,14 @@ static inline int regulator_set_current_limit(const struct device *dev,
|
||||||
* @brief Get output current limit.
|
* @brief Get output current limit.
|
||||||
*
|
*
|
||||||
* @param dev Regulator device instance.
|
* @param dev Regulator device instance.
|
||||||
|
* @param[out] curr_ua Where output current limit will be stored.
|
||||||
*
|
*
|
||||||
* @retval current Current limit in microamperes
|
* @retval 0 If successful.
|
||||||
* @retval -ENOSYS If function is not implemented.
|
* @retval -ENOSYS If function is not implemented.
|
||||||
* @retval -errno In case of any other error.
|
* @retval -errno In case of any other error.
|
||||||
*/
|
*/
|
||||||
static inline int32_t regulator_get_current_limit(const struct device *dev)
|
static inline int regulator_get_current_limit(const struct device *dev,
|
||||||
|
int32_t *curr_ua)
|
||||||
{
|
{
|
||||||
const struct regulator_driver_api *api =
|
const struct regulator_driver_api *api =
|
||||||
(const struct regulator_driver_api *)dev->api;
|
(const struct regulator_driver_api *)dev->api;
|
||||||
|
@ -256,7 +258,7 @@ static inline int32_t regulator_get_current_limit(const struct device *dev)
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return api->get_current_limit(dev);
|
return api->get_current_limit(dev, curr_ua);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue