drivers: regulator: use int32_t for voltages/currents
Right now we had a mix of int (signed) and uint32_t (fixed-width unsigned integer). Use int32_t for all cases, both values may be either positive/negative, and we have a defined range when using fixed-width integers. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
561eb2b5b5
commit
6d744d3dd2
2 changed files with 44 additions and 38 deletions
|
@ -36,8 +36,8 @@ struct regulator_config {
|
||||||
int num_modes;
|
int num_modes;
|
||||||
uint8_t vsel_reg;
|
uint8_t vsel_reg;
|
||||||
uint8_t vsel_mask;
|
uint8_t vsel_mask;
|
||||||
uint32_t max_uV;
|
int32_t max_uV;
|
||||||
uint32_t min_uV;
|
int32_t min_uV;
|
||||||
uint8_t enable_reg;
|
uint8_t enable_reg;
|
||||||
uint8_t enable_mask;
|
uint8_t enable_mask;
|
||||||
uint8_t enable_val;
|
uint8_t enable_val;
|
||||||
|
@ -56,7 +56,8 @@ struct regulator_config {
|
||||||
};
|
};
|
||||||
|
|
||||||
static int regulator_pca9420_is_supported_voltage(const struct device *dev,
|
static int regulator_pca9420_is_supported_voltage(const struct device *dev,
|
||||||
int min_uV, int max_uV);
|
int32_t min_uV,
|
||||||
|
int32_t max_uV);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a register from the PMIC
|
* Reads a register from the PMIC
|
||||||
|
@ -101,7 +102,8 @@ static int regulator_modify_register(const struct device *dev,
|
||||||
* offset applied to the vsel_reg. Useful to support reading voltages
|
* offset applied to the vsel_reg. Useful to support reading voltages
|
||||||
* in another target mode
|
* in another target mode
|
||||||
*/
|
*/
|
||||||
static int regulator_get_voltage_offset(const struct device *dev, uint32_t off)
|
static int32_t regulator_get_voltage_offset(const struct device *dev,
|
||||||
|
uint32_t off)
|
||||||
{
|
{
|
||||||
const struct regulator_config *config = dev->config;
|
const struct regulator_config *config = dev->config;
|
||||||
struct regulator_data *data = dev->data;
|
struct regulator_data *data = dev->data;
|
||||||
|
@ -130,8 +132,9 @@ static int regulator_get_voltage_offset(const struct device *dev, uint32_t off)
|
||||||
* offset applied to the vsel_reg. Useful to support setting voltages in
|
* offset applied to the vsel_reg. Useful to support setting voltages in
|
||||||
* another target mode.
|
* another target mode.
|
||||||
*/
|
*/
|
||||||
static int regulator_set_voltage_offset(const struct device *dev, int min_uV,
|
static int regulator_set_voltage_offset(const struct device *dev,
|
||||||
int max_uV, uint32_t off)
|
int32_t min_uV, int32_t max_uV,
|
||||||
|
uint32_t off)
|
||||||
{
|
{
|
||||||
const struct regulator_config *config = dev->config;
|
const struct regulator_config *config = dev->config;
|
||||||
struct regulator_data *data = dev->data;
|
struct regulator_data *data = dev->data;
|
||||||
|
@ -187,8 +190,8 @@ static int regulator_pca9420_count_modes(const struct device *dev)
|
||||||
* Part of the extended regulator consumer API
|
* Part of the extended regulator consumer API
|
||||||
* Returns the supported voltage in uV for a given selector value
|
* Returns the supported voltage in uV for a given selector value
|
||||||
*/
|
*/
|
||||||
static int regulator_pca9420_list_voltages(const struct device *dev,
|
static int32_t regulator_pca9420_list_voltages(const struct device *dev,
|
||||||
unsigned int selector)
|
unsigned int selector)
|
||||||
{
|
{
|
||||||
const struct regulator_config *config = dev->config;
|
const struct regulator_config *config = dev->config;
|
||||||
struct regulator_data *data = dev->data;
|
struct regulator_data *data = dev->data;
|
||||||
|
@ -204,7 +207,8 @@ static int regulator_pca9420_list_voltages(const struct device *dev,
|
||||||
* Returns true if the regulator supports a voltage in the given range.
|
* Returns true if the regulator supports a voltage in the given range.
|
||||||
*/
|
*/
|
||||||
static int regulator_pca9420_is_supported_voltage(const struct device *dev,
|
static int regulator_pca9420_is_supported_voltage(const struct device *dev,
|
||||||
int min_uV, int max_uV)
|
int32_t min_uV,
|
||||||
|
int32_t max_uV)
|
||||||
{
|
{
|
||||||
const struct regulator_config *config = dev->config;
|
const struct regulator_config *config = dev->config;
|
||||||
|
|
||||||
|
@ -215,8 +219,8 @@ static int regulator_pca9420_is_supported_voltage(const struct device *dev,
|
||||||
* Part of the extended regulator consumer API
|
* Part of the extended regulator consumer API
|
||||||
* Sets the output voltage to the closest supported voltage value
|
* Sets the output voltage to the closest supported voltage value
|
||||||
*/
|
*/
|
||||||
static int regulator_pca9420_set_voltage(const struct device *dev, int min_uV,
|
static int regulator_pca9420_set_voltage(const struct device *dev,
|
||||||
int max_uV)
|
int32_t min_uV, int32_t max_uV)
|
||||||
{
|
{
|
||||||
return regulator_set_voltage_offset(dev, min_uV, max_uV, 0);
|
return regulator_set_voltage_offset(dev, min_uV, max_uV, 0);
|
||||||
}
|
}
|
||||||
|
@ -226,7 +230,7 @@ static int regulator_pca9420_set_voltage(const struct device *dev, int min_uV,
|
||||||
* Part of the extended regulator consumer API
|
* Part of the extended regulator consumer API
|
||||||
* Gets the current output voltage in uV
|
* Gets the current output voltage in uV
|
||||||
*/
|
*/
|
||||||
static int regulator_pca9420_get_voltage(const struct device *dev)
|
static int32_t regulator_pca9420_get_voltage(const struct device *dev)
|
||||||
{
|
{
|
||||||
return regulator_get_voltage_offset(dev, 0);
|
return regulator_get_voltage_offset(dev, 0);
|
||||||
}
|
}
|
||||||
|
@ -236,7 +240,7 @@ static int regulator_pca9420_get_voltage(const struct device *dev)
|
||||||
* Set the current limit for this device
|
* Set the current limit for this device
|
||||||
*/
|
*/
|
||||||
static int regulator_pca9420_set_current_limit(const struct device *dev,
|
static int regulator_pca9420_set_current_limit(const struct device *dev,
|
||||||
int min_uA, int max_uA)
|
int32_t min_uA, int32_t max_uA)
|
||||||
{
|
{
|
||||||
const struct regulator_config *config = dev->config;
|
const struct regulator_config *config = dev->config;
|
||||||
struct regulator_data *data = dev->data;
|
struct regulator_data *data = dev->data;
|
||||||
|
@ -297,8 +301,8 @@ static int regulator_pca9420_get_current_limit(const struct device *dev)
|
||||||
* with the regulator_pca9420_set_mode api
|
* with the regulator_pca9420_set_mode api
|
||||||
*/
|
*/
|
||||||
static int regulator_pca9420_set_mode_voltage(const struct device *dev,
|
static int regulator_pca9420_set_mode_voltage(const struct device *dev,
|
||||||
uint32_t mode, uint32_t min_uV,
|
uint32_t mode, int32_t min_uV,
|
||||||
uint32_t max_uV)
|
int32_t max_uV)
|
||||||
{
|
{
|
||||||
const struct regulator_config *config = dev->config;
|
const struct regulator_config *config = dev->config;
|
||||||
uint8_t i, sel_off;
|
uint8_t i, sel_off;
|
||||||
|
@ -389,8 +393,8 @@ static int regulator_pca9420_mode_enable(const struct device *dev,
|
||||||
* not need to be the active mode. This API can be used to read voltages
|
* not need to be the active mode. This API can be used to read voltages
|
||||||
* from a regulator mode other than the default.
|
* from a regulator mode other than the default.
|
||||||
*/
|
*/
|
||||||
static int regulator_pca9420_get_mode_voltage(const struct device *dev,
|
static int32_t regulator_pca9420_get_mode_voltage(const struct device *dev,
|
||||||
uint32_t mode)
|
uint32_t mode)
|
||||||
{
|
{
|
||||||
const struct regulator_config *config = dev->config;
|
const struct regulator_config *config = dev->config;
|
||||||
uint8_t i, sel_off;
|
uint8_t i, sel_off;
|
||||||
|
|
|
@ -33,18 +33,20 @@ __subsystem struct regulator_driver_api {
|
||||||
int (*disable)(const struct device *dev);
|
int (*disable)(const struct device *dev);
|
||||||
int (*count_voltages)(const struct device *dev);
|
int (*count_voltages)(const struct device *dev);
|
||||||
int (*count_modes)(const struct device *dev);
|
int (*count_modes)(const struct device *dev);
|
||||||
int (*list_voltages)(const struct device *dev, unsigned int selector);
|
int32_t (*list_voltages)(const struct device *dev,
|
||||||
int (*is_supported_voltage)(const struct device *dev, int min_uV,
|
unsigned int selector);
|
||||||
int max_uV);
|
int (*is_supported_voltage)(const struct device *dev, int32_t min_uV,
|
||||||
int (*set_voltage)(const struct device *dev, int min_uV, int max_uV);
|
int32_t max_uV);
|
||||||
int (*get_voltage)(const struct device *dev);
|
int (*set_voltage)(const struct device *dev, int32_t min_uV,
|
||||||
int (*set_current_limit)(const struct device *dev, int min_uA,
|
int32_t max_uV);
|
||||||
int max_uA);
|
int32_t (*get_voltage)(const struct device *dev);
|
||||||
|
int (*set_current_limit)(const struct device *dev, int32_t min_uA,
|
||||||
|
int32_t max_uA);
|
||||||
int (*get_current_limit)(const struct device *dev);
|
int (*get_current_limit)(const struct device *dev);
|
||||||
int (*set_mode)(const struct device *dev, uint32_t mode);
|
int (*set_mode)(const struct device *dev, uint32_t mode);
|
||||||
int (*set_mode_voltage)(const struct device *dev, uint32_t mode,
|
int (*set_mode_voltage)(const struct device *dev, uint32_t mode,
|
||||||
uint32_t min_uV, uint32_t max_uV);
|
int32_t min_uV, int32_t max_uV);
|
||||||
int (*get_mode_voltage)(const struct device *dev, uint32_t mode);
|
int32_t (*get_mode_voltage)(const struct device *dev, uint32_t mode);
|
||||||
int (*mode_disable)(const struct device *dev, uint32_t mode);
|
int (*mode_disable)(const struct device *dev, uint32_t mode);
|
||||||
int (*mode_enable)(const struct device *dev, uint32_t mode);
|
int (*mode_enable)(const struct device *dev, uint32_t mode);
|
||||||
};
|
};
|
||||||
|
@ -161,8 +163,8 @@ static inline int regulator_count_modes(const struct device *dev)
|
||||||
* @return voltage Voltage level in microvolts.
|
* @return voltage Voltage level in microvolts.
|
||||||
* @retval 0 If selector code can't be used.
|
* @retval 0 If selector code can't be used.
|
||||||
*/
|
*/
|
||||||
static inline int regulator_list_voltages(const struct device *dev,
|
static inline int32_t regulator_list_voltages(const struct device *dev,
|
||||||
unsigned int selector)
|
unsigned int selector)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
@ -186,7 +188,7 @@ static inline int regulator_list_voltages(const struct device *dev,
|
||||||
* @retval -errno In case of any other error.
|
* @retval -errno In case of any other error.
|
||||||
*/
|
*/
|
||||||
static inline int regulator_is_supported_voltage(const struct device *dev,
|
static inline int regulator_is_supported_voltage(const struct device *dev,
|
||||||
int min_uV, int max_uV)
|
int32_t min_uV, int32_t max_uV)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
@ -213,8 +215,8 @@ static inline int regulator_is_supported_voltage(const struct device *dev,
|
||||||
* @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 int regulator_set_voltage(const struct device *dev, int min_uV,
|
static inline int regulator_set_voltage(const struct device *dev,
|
||||||
int max_uV)
|
int32_t min_uV, int32_t max_uV)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
@ -233,7 +235,7 @@ static inline int regulator_set_voltage(const struct device *dev, int min_uV,
|
||||||
*
|
*
|
||||||
* @return Voltage level in microvolts.
|
* @return Voltage level in microvolts.
|
||||||
*/
|
*/
|
||||||
static inline int regulator_get_voltage(const struct device *dev)
|
static inline int32_t regulator_get_voltage(const struct device *dev)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
@ -257,7 +259,7 @@ static inline int regulator_get_voltage(const struct device *dev)
|
||||||
* @retval -errno In case of any other error.
|
* @retval -errno In case of any other error.
|
||||||
*/
|
*/
|
||||||
static inline int regulator_set_current_limit(const struct device *dev,
|
static inline int regulator_set_current_limit(const struct device *dev,
|
||||||
int min_uA, int max_uA)
|
int32_t min_uA, int32_t max_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;
|
||||||
|
@ -278,7 +280,7 @@ static inline int regulator_set_current_limit(const struct device *dev,
|
||||||
* @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 int regulator_get_current_limit(const struct device *dev)
|
static inline int32_t regulator_get_current_limit(const struct device *dev)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
@ -333,8 +335,8 @@ static inline int regulator_set_mode(const struct device *dev, uint32_t mode)
|
||||||
* @retval -errno In case of any other error.
|
* @retval -errno In case of any other error.
|
||||||
*/
|
*/
|
||||||
static inline int regulator_set_mode_voltage(const struct device *dev,
|
static inline int regulator_set_mode_voltage(const struct device *dev,
|
||||||
uint32_t mode, uint32_t min_uV,
|
uint32_t mode, int32_t min_uV,
|
||||||
uint32_t max_uV)
|
int32_t max_uV)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
@ -357,8 +359,8 @@ static inline int regulator_set_mode_voltage(const struct device *dev,
|
||||||
*
|
*
|
||||||
* @return Voltage level in microvolts.
|
* @return Voltage level in microvolts.
|
||||||
*/
|
*/
|
||||||
static inline int regulator_get_mode_voltage(const struct device *dev,
|
static inline int32_t regulator_get_mode_voltage(const struct device *dev,
|
||||||
uint32_t mode)
|
uint32_t mode)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue