drivers: regulator: improve regulator_get_voltage
- Function now returns error, value is obtained by reference. This allows to propagate potential bus errors. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
b909d0e560
commit
3d47b6dfba
3 changed files with 15 additions and 12 deletions
|
@ -295,15 +295,13 @@ static int regulator_pca9420_set_voltage(const struct device *dev,
|
|||
* Part of the extended regulator consumer API
|
||||
* Gets the current output voltage in uV
|
||||
*/
|
||||
static int32_t regulator_pca9420_get_voltage(const struct device *dev)
|
||||
static int regulator_pca9420_get_voltage(const struct device *dev,
|
||||
int32_t *volt_uv)
|
||||
{
|
||||
const struct regulator_pca9420_config *config = dev->config;
|
||||
struct regulator_pca9420_common_data *cdata = config->parent->data;
|
||||
int32_t voltage = 0;
|
||||
|
||||
(void)regulator_pca9420_get_voltage_mode(dev, cdata->mode, &voltage);
|
||||
|
||||
return voltage;
|
||||
return regulator_pca9420_get_voltage_mode(dev, cdata->mode, volt_uv);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,6 +56,7 @@ static int cmd_reg_dis(const struct shell *sh, size_t argc, char **argv)
|
|||
static int cmd_set_vol(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
int lvol, uvol, ret;
|
||||
int32_t volt_uv;
|
||||
const struct device *reg_dev;
|
||||
|
||||
reg_dev = device_get_binding(argv[1]);
|
||||
|
@ -72,12 +73,12 @@ static int cmd_set_vol(const struct shell *sh, size_t argc, char **argv)
|
|||
shell_error(sh, "failed to set voltage, error %d", ret);
|
||||
return ret;
|
||||
}
|
||||
ret = regulator_get_voltage(reg_dev);
|
||||
ret = regulator_get_voltage(reg_dev, &volt_uv);
|
||||
if (ret < 0) {
|
||||
shell_error(sh, "failed to read voltage, error %d", ret);
|
||||
return ret;
|
||||
}
|
||||
shell_print(sh, "set voltage to %d uV", ret);
|
||||
shell_print(sh, "set voltage to %d uV", volt_uv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ __subsystem struct regulator_driver_api {
|
|||
int32_t *volt_uv);
|
||||
int (*set_voltage)(const struct device *dev, int32_t min_uv,
|
||||
int32_t max_uv);
|
||||
int32_t (*get_voltage)(const struct device *dev);
|
||||
int (*get_voltage)(const struct device *dev, int32_t *volt_uv);
|
||||
int (*set_current_limit)(const struct device *dev, int32_t min_ua,
|
||||
int32_t max_ua);
|
||||
int (*get_current_limit)(const struct device *dev);
|
||||
|
@ -195,19 +195,23 @@ static inline int regulator_set_voltage(const struct device *dev,
|
|||
* @brief Obtain output voltage.
|
||||
*
|
||||
* @param dev Regulator device instance.
|
||||
* @param[out] volt_uv Where configured output voltage will be stored.
|
||||
*
|
||||
* @return Voltage level in microvolts.
|
||||
* @retval 0 If successful
|
||||
* @retval -ENOSYS If function is not implemented.
|
||||
* @retval -errno In case of any other error.
|
||||
*/
|
||||
static inline int32_t regulator_get_voltage(const struct device *dev)
|
||||
static inline int regulator_get_voltage(const struct device *dev,
|
||||
int32_t *volt_uv)
|
||||
{
|
||||
const struct regulator_driver_api *api =
|
||||
(const struct regulator_driver_api *)dev->api;
|
||||
|
||||
if (api->get_voltage == NULL) {
|
||||
return 0;
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
return api->get_voltage(dev);
|
||||
return api->get_voltage(dev, volt_uv);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue