drivers: regulator: npm6001: format code
Format code using clang-format. This will ease incoming refactor. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
9c340776ff
commit
5521db3576
1 changed files with 141 additions and 191 deletions
|
@ -62,8 +62,7 @@ enum npm6001_sources {
|
||||||
/* nPM6001 BUCKXCONFPWMMODE fields */
|
/* nPM6001 BUCKXCONFPWMMODE fields */
|
||||||
#define NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_MSK 0x8U
|
#define NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_MSK 0x8U
|
||||||
#define NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_POS 3
|
#define NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_POS 3
|
||||||
#define NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM \
|
#define NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM BIT(NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_POS)
|
||||||
BIT(NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_POS)
|
|
||||||
|
|
||||||
#define NPM6001_BUCKMODEPADCONF_BUCKMODE0PADTYPE_CMOS BIT(0)
|
#define NPM6001_BUCKMODEPADCONF_BUCKMODE0PADTYPE_CMOS BIT(0)
|
||||||
#define NPM6001_BUCKMODEPADCONF_BUCKMODE1PADTYPE_CMOS BIT(1)
|
#define NPM6001_BUCKMODEPADCONF_BUCKMODE1PADTYPE_CMOS BIT(1)
|
||||||
|
@ -104,29 +103,21 @@ struct regulator_npm6001_vmap {
|
||||||
int32_t volt_uv;
|
int32_t volt_uv;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct linear_range buck0_range =
|
static const struct linear_range buck0_range = LINEAR_RANGE_INIT(1800000, 100000U, 0x0U, 0xFU);
|
||||||
LINEAR_RANGE_INIT(1800000, 100000U, 0x0U, 0xFU);
|
|
||||||
|
|
||||||
static const struct linear_range buck1_range =
|
static const struct linear_range buck1_range = LINEAR_RANGE_INIT(700000, 50000U, 0x0U, 0xEU);
|
||||||
LINEAR_RANGE_INIT(700000, 50000U, 0x0U, 0xEU);
|
|
||||||
|
|
||||||
static const struct linear_range buck2_range =
|
static const struct linear_range buck2_range = LINEAR_RANGE_INIT(1200000, 50000U, 0xAU, 0xEU);
|
||||||
LINEAR_RANGE_INIT(1200000, 50000U, 0xAU, 0xEU);
|
|
||||||
|
|
||||||
static const struct linear_range buck3_range =
|
static const struct linear_range buck3_range = LINEAR_RANGE_INIT(500000, 25000U, 0x0U, 0x70U);
|
||||||
LINEAR_RANGE_INIT(500000, 25000U, 0x0U, 0x70U);
|
|
||||||
|
|
||||||
static const struct regulator_npm6001_vmap ldo0_voltages[] = {
|
static const struct regulator_npm6001_vmap ldo0_voltages[] = {
|
||||||
{ NPM6001_LDO0VOUT_SET1V8, 1800000 },
|
{NPM6001_LDO0VOUT_SET1V8, 1800000}, {NPM6001_LDO0VOUT_SET2V1, 2100000},
|
||||||
{ NPM6001_LDO0VOUT_SET2V1, 2100000 },
|
{NPM6001_LDO0VOUT_SET2V41, 2410000}, {NPM6001_LDO0VOUT_SET2V7, 2700000},
|
||||||
{ NPM6001_LDO0VOUT_SET2V41, 2410000 },
|
{NPM6001_LDO0VOUT_SET3V0, 3000000}, {NPM6001_LDO0VOUT_SET3V3, 3300000},
|
||||||
{ NPM6001_LDO0VOUT_SET2V7, 2700000 },
|
|
||||||
{ NPM6001_LDO0VOUT_SET3V0, 3000000 },
|
|
||||||
{ NPM6001_LDO0VOUT_SET3V3, 3300000 },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int regulator_npm6001_ldo0_list_voltage(const struct device *dev,
|
static int regulator_npm6001_ldo0_list_voltage(const struct device *dev, unsigned int idx,
|
||||||
unsigned int idx,
|
|
||||||
int32_t *volt_uv)
|
int32_t *volt_uv)
|
||||||
{
|
{
|
||||||
if (idx >= ARRAY_SIZE(ldo0_voltages)) {
|
if (idx >= ARRAY_SIZE(ldo0_voltages)) {
|
||||||
|
@ -138,9 +129,9 @@ static int regulator_npm6001_ldo0_list_voltage(const struct device *dev,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int regulator_npm6001_buck012_set_voltage(
|
static int regulator_npm6001_buck012_set_voltage(const struct device *dev, int32_t min_uv,
|
||||||
const struct device *dev, int32_t min_uv, int32_t max_uv,
|
int32_t max_uv, const struct linear_range *range,
|
||||||
const struct linear_range *range, uint8_t vout_reg, uint8_t conf_reg)
|
uint8_t vout_reg, uint8_t conf_reg)
|
||||||
{
|
{
|
||||||
const struct regulator_npm6001_config *config = dev->config;
|
const struct regulator_npm6001_config *config = dev->config;
|
||||||
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
|
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
|
||||||
|
@ -160,8 +151,7 @@ static int regulator_npm6001_buck012_set_voltage(
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((conf & NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM) == 0U) {
|
if ((conf & NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM) == 0U) {
|
||||||
ret = i2c_reg_write_byte_dt(
|
ret = i2c_reg_write_byte_dt(&pconfig->i2c, conf_reg,
|
||||||
&pconfig->i2c, conf_reg,
|
|
||||||
conf | NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM);
|
conf | NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -178,8 +168,7 @@ static int regulator_npm6001_buck012_set_voltage(
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_UPDATE_VOUTPWM,
|
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_UPDATE_VOUTPWM, 1U);
|
||||||
1U);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -195,8 +184,8 @@ static int regulator_npm6001_buck012_set_voltage(
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int regulator_npm6001_buck3_set_voltage(const struct device *dev,
|
static int regulator_npm6001_buck3_set_voltage(const struct device *dev, int32_t min_uv,
|
||||||
int32_t min_uv, int32_t max_uv)
|
int32_t max_uv)
|
||||||
{
|
{
|
||||||
const struct regulator_npm6001_config *config = dev->config;
|
const struct regulator_npm6001_config *config = dev->config;
|
||||||
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
|
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
|
||||||
|
@ -210,31 +199,27 @@ static int regulator_npm6001_buck3_set_voltage(const struct device *dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* force PWM mode when updating voltage */
|
/* force PWM mode when updating voltage */
|
||||||
ret = i2c_reg_read_byte_dt(&pconfig->i2c, NPM6001_BUCK3CONFPWMMODE,
|
ret = i2c_reg_read_byte_dt(&pconfig->i2c, NPM6001_BUCK3CONFPWMMODE, &conf);
|
||||||
&conf);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((conf & NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM) == 0U) {
|
if ((conf & NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM) == 0U) {
|
||||||
ret = i2c_reg_write_byte_dt(
|
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_BUCK3CONFPWMMODE,
|
||||||
&pconfig->i2c, NPM6001_BUCK3CONFPWMMODE,
|
|
||||||
conf | NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM);
|
conf | NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_BUCK3VOUT,
|
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_BUCK3VOUT, (uint8_t)idx);
|
||||||
(uint8_t)idx);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* restore HYS mode if enabled before */
|
/* restore HYS mode if enabled before */
|
||||||
if ((conf & NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM) == 0U) {
|
if ((conf & NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM) == 0U) {
|
||||||
ret = i2c_reg_write_byte_dt(&pconfig->i2c,
|
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_BUCK3CONFPWMMODE, conf);
|
||||||
NPM6001_BUCK3CONFPWMMODE, conf);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -243,8 +228,8 @@ static int regulator_npm6001_buck3_set_voltage(const struct device *dev,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int regulator_npm6001_ldo0_set_voltage(const struct device *dev,
|
static int regulator_npm6001_ldo0_set_voltage(const struct device *dev, int32_t min_uv,
|
||||||
int32_t min_uv, int32_t max_uv)
|
int32_t max_uv)
|
||||||
{
|
{
|
||||||
const struct regulator_npm6001_config *config = dev->config;
|
const struct regulator_npm6001_config *config = dev->config;
|
||||||
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
|
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
|
||||||
|
@ -252,8 +237,7 @@ static int regulator_npm6001_ldo0_set_voltage(const struct device *dev,
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0U; i < ARRAY_SIZE(ldo0_voltages); i++) {
|
for (i = 0U; i < ARRAY_SIZE(ldo0_voltages); i++) {
|
||||||
if ((min_uv <= ldo0_voltages[i].volt_uv) &&
|
if ((min_uv <= ldo0_voltages[i].volt_uv) && (max_uv >= ldo0_voltages[i].volt_uv)) {
|
||||||
(max_uv >= ldo0_voltages[i].volt_uv)) {
|
|
||||||
val = ldo0_voltages[i].reg_val;
|
val = ldo0_voltages[i].reg_val;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -266,8 +250,7 @@ static int regulator_npm6001_ldo0_set_voltage(const struct device *dev,
|
||||||
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_LDO0VOUT, val);
|
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_LDO0VOUT, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int regulator_npm6001_buck0123_get_voltage(const struct device *dev,
|
||||||
regulator_npm6001_buck0123_get_voltage(const struct device *dev,
|
|
||||||
const struct linear_range *range,
|
const struct linear_range *range,
|
||||||
uint8_t vout_reg, int32_t *volt_uv)
|
uint8_t vout_reg, int32_t *volt_uv)
|
||||||
{
|
{
|
||||||
|
@ -284,8 +267,7 @@ regulator_npm6001_buck0123_get_voltage(const struct device *dev,
|
||||||
return linear_range_get_value(range, idx, volt_uv);
|
return linear_range_get_value(range, idx, volt_uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int regulator_npm6001_ldo0_get_voltage(const struct device *dev,
|
static int regulator_npm6001_ldo0_get_voltage(const struct device *dev, int32_t *volt_uv)
|
||||||
int32_t *volt_uv)
|
|
||||||
{
|
{
|
||||||
const struct regulator_npm6001_config *config = dev->config;
|
const struct regulator_npm6001_config *config = dev->config;
|
||||||
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
|
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
|
||||||
|
@ -333,8 +315,8 @@ static unsigned int regulator_npm6001_count_voltages(const struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int regulator_npm6001_list_voltage(const struct device *dev,
|
static int regulator_npm6001_list_voltage(const struct device *dev, unsigned int idx,
|
||||||
unsigned int idx, int32_t *volt_uv)
|
int32_t *volt_uv)
|
||||||
{
|
{
|
||||||
const struct regulator_npm6001_config *config = dev->config;
|
const struct regulator_npm6001_config *config = dev->config;
|
||||||
|
|
||||||
|
@ -344,8 +326,7 @@ static int regulator_npm6001_list_voltage(const struct device *dev,
|
||||||
case NPM6001_SOURCE_BUCK1:
|
case NPM6001_SOURCE_BUCK1:
|
||||||
return linear_range_get_value(&buck1_range, idx, volt_uv);
|
return linear_range_get_value(&buck1_range, idx, volt_uv);
|
||||||
case NPM6001_SOURCE_BUCK2:
|
case NPM6001_SOURCE_BUCK2:
|
||||||
return linear_range_get_value(
|
return linear_range_get_value(&buck2_range, idx + buck2_range.min_idx, volt_uv);
|
||||||
&buck2_range, idx + buck2_range.min_idx, volt_uv);
|
|
||||||
case NPM6001_SOURCE_BUCK3:
|
case NPM6001_SOURCE_BUCK3:
|
||||||
return linear_range_get_value(&buck3_range, idx, volt_uv);
|
return linear_range_get_value(&buck3_range, idx, volt_uv);
|
||||||
case NPM6001_SOURCE_LDO0:
|
case NPM6001_SOURCE_LDO0:
|
||||||
|
@ -360,23 +341,22 @@ static int regulator_npm6001_list_voltage(const struct device *dev,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int regulator_npm6001_set_voltage(const struct device *dev,
|
static int regulator_npm6001_set_voltage(const struct device *dev, int32_t min_uv, int32_t max_uv)
|
||||||
int32_t min_uv, int32_t max_uv)
|
|
||||||
{
|
{
|
||||||
const struct regulator_npm6001_config *config = dev->config;
|
const struct regulator_npm6001_config *config = dev->config;
|
||||||
|
|
||||||
switch (config->source) {
|
switch (config->source) {
|
||||||
case NPM6001_SOURCE_BUCK0:
|
case NPM6001_SOURCE_BUCK0:
|
||||||
return regulator_npm6001_buck012_set_voltage(
|
return regulator_npm6001_buck012_set_voltage(dev, min_uv, max_uv, &buck0_range,
|
||||||
dev, min_uv, max_uv, &buck0_range, NPM6001_BUCK0VOUTULP,
|
NPM6001_BUCK0VOUTULP,
|
||||||
NPM6001_BUCK0CONFPWMMODE);
|
NPM6001_BUCK0CONFPWMMODE);
|
||||||
case NPM6001_SOURCE_BUCK1:
|
case NPM6001_SOURCE_BUCK1:
|
||||||
return regulator_npm6001_buck012_set_voltage(
|
return regulator_npm6001_buck012_set_voltage(dev, min_uv, max_uv, &buck1_range,
|
||||||
dev, min_uv, max_uv, &buck1_range, NPM6001_BUCK1VOUTULP,
|
NPM6001_BUCK1VOUTULP,
|
||||||
NPM6001_BUCK1CONFPWMMODE);
|
NPM6001_BUCK1CONFPWMMODE);
|
||||||
case NPM6001_SOURCE_BUCK2:
|
case NPM6001_SOURCE_BUCK2:
|
||||||
return regulator_npm6001_buck012_set_voltage(
|
return regulator_npm6001_buck012_set_voltage(dev, min_uv, max_uv, &buck2_range,
|
||||||
dev, min_uv, max_uv, &buck2_range, NPM6001_BUCK2VOUTULP,
|
NPM6001_BUCK2VOUTULP,
|
||||||
NPM6001_BUCK2CONFPWMMODE);
|
NPM6001_BUCK2CONFPWMMODE);
|
||||||
case NPM6001_SOURCE_BUCK3:
|
case NPM6001_SOURCE_BUCK3:
|
||||||
return regulator_npm6001_buck3_set_voltage(dev, min_uv, max_uv);
|
return regulator_npm6001_buck3_set_voltage(dev, min_uv, max_uv);
|
||||||
|
@ -394,24 +374,23 @@ static int regulator_npm6001_set_voltage(const struct device *dev,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int regulator_npm6001_get_voltage(const struct device *dev,
|
static int regulator_npm6001_get_voltage(const struct device *dev, int32_t *volt_uv)
|
||||||
int32_t *volt_uv)
|
|
||||||
{
|
{
|
||||||
const struct regulator_npm6001_config *config = dev->config;
|
const struct regulator_npm6001_config *config = dev->config;
|
||||||
|
|
||||||
switch (config->source) {
|
switch (config->source) {
|
||||||
case NPM6001_SOURCE_BUCK0:
|
case NPM6001_SOURCE_BUCK0:
|
||||||
return regulator_npm6001_buck0123_get_voltage(
|
return regulator_npm6001_buck0123_get_voltage(dev, &buck0_range,
|
||||||
dev, &buck0_range, NPM6001_BUCK0VOUTULP, volt_uv);
|
NPM6001_BUCK0VOUTULP, volt_uv);
|
||||||
case NPM6001_SOURCE_BUCK1:
|
case NPM6001_SOURCE_BUCK1:
|
||||||
return regulator_npm6001_buck0123_get_voltage(
|
return regulator_npm6001_buck0123_get_voltage(dev, &buck1_range,
|
||||||
dev, &buck1_range, NPM6001_BUCK1VOUTULP, volt_uv);
|
NPM6001_BUCK1VOUTULP, volt_uv);
|
||||||
case NPM6001_SOURCE_BUCK2:
|
case NPM6001_SOURCE_BUCK2:
|
||||||
return regulator_npm6001_buck0123_get_voltage(
|
return regulator_npm6001_buck0123_get_voltage(dev, &buck2_range,
|
||||||
dev, &buck2_range, NPM6001_BUCK2VOUTULP, volt_uv);
|
NPM6001_BUCK2VOUTULP, volt_uv);
|
||||||
case NPM6001_SOURCE_BUCK3:
|
case NPM6001_SOURCE_BUCK3:
|
||||||
return regulator_npm6001_buck0123_get_voltage(
|
return regulator_npm6001_buck0123_get_voltage(dev, &buck3_range, NPM6001_BUCK3VOUT,
|
||||||
dev, &buck3_range, NPM6001_BUCK3VOUT, volt_uv);
|
volt_uv);
|
||||||
case NPM6001_SOURCE_LDO0:
|
case NPM6001_SOURCE_LDO0:
|
||||||
return regulator_npm6001_ldo0_get_voltage(dev, volt_uv);
|
return regulator_npm6001_ldo0_get_voltage(dev, volt_uv);
|
||||||
case NPM6001_SOURCE_LDO1:
|
case NPM6001_SOURCE_LDO1:
|
||||||
|
@ -424,8 +403,7 @@ static int regulator_npm6001_get_voltage(const struct device *dev,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int regulator_npm6001_set_mode(const struct device *dev,
|
static int regulator_npm6001_set_mode(const struct device *dev, regulator_mode_t mode)
|
||||||
regulator_mode_t mode)
|
|
||||||
{
|
{
|
||||||
const struct regulator_npm6001_config *config = dev->config;
|
const struct regulator_npm6001_config *config = dev->config;
|
||||||
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
|
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
|
||||||
|
@ -452,14 +430,12 @@ static int regulator_npm6001_set_mode(const struct device *dev,
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i2c_reg_update_byte_dt(
|
return i2c_reg_update_byte_dt(&pconfig->i2c, conf_reg,
|
||||||
&pconfig->i2c, conf_reg,
|
|
||||||
NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_MSK,
|
NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_MSK,
|
||||||
mode << NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_POS);
|
mode << NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_POS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int regulator_npm6001_get_mode(const struct device *dev,
|
static int regulator_npm6001_get_mode(const struct device *dev, regulator_mode_t *mode)
|
||||||
regulator_mode_t *mode)
|
|
||||||
{
|
{
|
||||||
const struct regulator_npm6001_config *config = dev->config;
|
const struct regulator_npm6001_config *config = dev->config;
|
||||||
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
|
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
|
||||||
|
@ -501,22 +477,17 @@ static int regulator_npm6001_enable(const struct device *dev)
|
||||||
|
|
||||||
switch (config->source) {
|
switch (config->source) {
|
||||||
case NPM6001_SOURCE_BUCK1:
|
case NPM6001_SOURCE_BUCK1:
|
||||||
return i2c_reg_update_byte_dt(
|
return i2c_reg_update_byte_dt(&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
|
||||||
&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
|
|
||||||
NPM6001_OVERRIDEPWRUPBUCK_BUCK1DISABLE_MSK, 0U);
|
NPM6001_OVERRIDEPWRUPBUCK_BUCK1DISABLE_MSK, 0U);
|
||||||
case NPM6001_SOURCE_BUCK2:
|
case NPM6001_SOURCE_BUCK2:
|
||||||
return i2c_reg_update_byte_dt(
|
return i2c_reg_update_byte_dt(&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
|
||||||
&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
|
|
||||||
NPM6001_OVERRIDEPWRUPBUCK_BUCK2DISABLE_MSK, 0U);
|
NPM6001_OVERRIDEPWRUPBUCK_BUCK2DISABLE_MSK, 0U);
|
||||||
case NPM6001_SOURCE_BUCK3:
|
case NPM6001_SOURCE_BUCK3:
|
||||||
return i2c_reg_write_byte_dt(&pconfig->i2c,
|
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_START_BUCK3, 1U);
|
||||||
NPM6001_TASKS_START_BUCK3, 1U);
|
|
||||||
case NPM6001_SOURCE_LDO0:
|
case NPM6001_SOURCE_LDO0:
|
||||||
return i2c_reg_write_byte_dt(&pconfig->i2c,
|
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_START_LDO0, 1U);
|
||||||
NPM6001_TASKS_START_LDO0, 1U);
|
|
||||||
case NPM6001_SOURCE_LDO1:
|
case NPM6001_SOURCE_LDO1:
|
||||||
return i2c_reg_write_byte_dt(&pconfig->i2c,
|
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_START_LDO1, 1U);
|
||||||
NPM6001_TASKS_START_LDO1, 1U);
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -529,24 +500,19 @@ static int regulator_npm6001_disable(const struct device *dev)
|
||||||
|
|
||||||
switch (config->source) {
|
switch (config->source) {
|
||||||
case NPM6001_SOURCE_BUCK1:
|
case NPM6001_SOURCE_BUCK1:
|
||||||
return i2c_reg_update_byte_dt(
|
return i2c_reg_update_byte_dt(&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
|
||||||
&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
|
|
||||||
NPM6001_OVERRIDEPWRUPBUCK_BUCK1DISABLE_MSK,
|
NPM6001_OVERRIDEPWRUPBUCK_BUCK1DISABLE_MSK,
|
||||||
NPM6001_OVERRIDEPWRUPBUCK_BUCK1DISABLE);
|
NPM6001_OVERRIDEPWRUPBUCK_BUCK1DISABLE);
|
||||||
case NPM6001_SOURCE_BUCK2:
|
case NPM6001_SOURCE_BUCK2:
|
||||||
return i2c_reg_update_byte_dt(
|
return i2c_reg_update_byte_dt(&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
|
||||||
&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
|
|
||||||
NPM6001_OVERRIDEPWRUPBUCK_BUCK2DISABLE_MSK,
|
NPM6001_OVERRIDEPWRUPBUCK_BUCK2DISABLE_MSK,
|
||||||
NPM6001_OVERRIDEPWRUPBUCK_BUCK2DISABLE);
|
NPM6001_OVERRIDEPWRUPBUCK_BUCK2DISABLE);
|
||||||
case NPM6001_SOURCE_BUCK3:
|
case NPM6001_SOURCE_BUCK3:
|
||||||
return i2c_reg_write_byte_dt(&pconfig->i2c,
|
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_STOP_BUCK3, 1U);
|
||||||
NPM6001_TASKS_STOP_BUCK3, 1U);
|
|
||||||
case NPM6001_SOURCE_LDO0:
|
case NPM6001_SOURCE_LDO0:
|
||||||
return i2c_reg_write_byte_dt(&pconfig->i2c,
|
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_STOP_LDO0, 1U);
|
||||||
NPM6001_TASKS_STOP_LDO0, 1U);
|
|
||||||
case NPM6001_SOURCE_LDO1:
|
case NPM6001_SOURCE_LDO1:
|
||||||
return i2c_reg_write_byte_dt(&pconfig->i2c,
|
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_STOP_LDO1, 1U);
|
||||||
NPM6001_TASKS_STOP_LDO1, 1U);
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -570,8 +536,7 @@ static int regulator_npm6001_get_error_flags(const struct device *dev,
|
||||||
|
|
||||||
if (val != 0U) {
|
if (val != 0U) {
|
||||||
/* clear thermal warning */
|
/* clear thermal warning */
|
||||||
ret = i2c_reg_write_byte_dt(&pconfig->i2c,
|
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_EVENTS_THWARN, 0U);
|
||||||
NPM6001_EVENTS_THWARN, 0U);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -649,14 +614,12 @@ static int regulator_npm6001_common_init(const struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* configure pad properties */
|
/* configure pad properties */
|
||||||
ret = i2c_reg_write_byte_dt(&config->i2c, NPM6001_BUCKMODEPADCONF,
|
ret = i2c_reg_write_byte_dt(&config->i2c, NPM6001_BUCKMODEPADCONF, config->buck_pad_val);
|
||||||
config->buck_pad_val);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = i2c_reg_write_byte_dt(&config->i2c, NPM6001_PADDRIVESTRENGTH,
|
ret = i2c_reg_write_byte_dt(&config->i2c, NPM6001_PADDRIVESTRENGTH, config->pad_val);
|
||||||
config->pad_val);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -685,28 +648,23 @@ static const struct regulator_driver_api api = {
|
||||||
.source = _source, \
|
.source = _source, \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
DEVICE_DT_DEFINE(node_id, regulator_npm6001_init, NULL, &data_##id, \
|
DEVICE_DT_DEFINE(node_id, regulator_npm6001_init, NULL, &data_##id, &config_##id, \
|
||||||
&config_##id, POST_KERNEL, \
|
POST_KERNEL, CONFIG_REGULATOR_NPM6001_INIT_PRIORITY, &api);
|
||||||
CONFIG_REGULATOR_NPM6001_INIT_PRIORITY, &api);
|
|
||||||
|
|
||||||
#define REGULATOR_NPM6001_DEFINE_COND(inst, child, source, parent) \
|
#define REGULATOR_NPM6001_DEFINE_COND(inst, child, source, parent) \
|
||||||
COND_CODE_1(DT_NODE_EXISTS(DT_INST_CHILD(inst, child)), \
|
COND_CODE_1(DT_NODE_EXISTS(DT_INST_CHILD(inst, child)), \
|
||||||
(REGULATOR_NPM6001_DEFINE(DT_INST_CHILD(inst, child), \
|
(REGULATOR_NPM6001_DEFINE(DT_INST_CHILD(inst, child), child##inst, source, \
|
||||||
child##inst, source, parent)), \
|
parent)), \
|
||||||
())
|
())
|
||||||
|
|
||||||
#define REGULATOR_NPM6001_DEFINE_ALL(inst) \
|
#define REGULATOR_NPM6001_DEFINE_ALL(inst) \
|
||||||
static const struct regulator_npm6001_pconfig config_##inst = { \
|
static const struct regulator_npm6001_pconfig config_##inst = { \
|
||||||
.i2c = I2C_DT_SPEC_GET(DT_INST_PARENT(inst)), \
|
.i2c = I2C_DT_SPEC_GET(DT_INST_PARENT(inst)), \
|
||||||
.buck_pad_val = \
|
.buck_pad_val = ((DT_INST_ENUM_IDX(inst, nordic_buck_mode0_input_type) * \
|
||||||
((DT_INST_ENUM_IDX(inst, \
|
|
||||||
nordic_buck_mode0_input_type) * \
|
|
||||||
NPM6001_BUCKMODEPADCONF_BUCKMODE0PADTYPE_CMOS) | \
|
NPM6001_BUCKMODEPADCONF_BUCKMODE0PADTYPE_CMOS) | \
|
||||||
(DT_INST_ENUM_IDX(inst, \
|
(DT_INST_ENUM_IDX(inst, nordic_buck_mode1_input_type) * \
|
||||||
nordic_buck_mode1_input_type) * \
|
|
||||||
NPM6001_BUCKMODEPADCONF_BUCKMODE1PADTYPE_CMOS) | \
|
NPM6001_BUCKMODEPADCONF_BUCKMODE1PADTYPE_CMOS) | \
|
||||||
(DT_INST_ENUM_IDX(inst, \
|
(DT_INST_ENUM_IDX(inst, nordic_buck_mode2_input_type) * \
|
||||||
nordic_buck_mode2_input_type) * \
|
|
||||||
NPM6001_BUCKMODEPADCONF_BUCKMODE2PADTYPE_CMOS) | \
|
NPM6001_BUCKMODEPADCONF_BUCKMODE2PADTYPE_CMOS) | \
|
||||||
(DT_INST_PROP(inst, nordic_buck_mode0_pull_down) * \
|
(DT_INST_PROP(inst, nordic_buck_mode0_pull_down) * \
|
||||||
NPM6001_BUCKMODEPADCONF_BUCKMODE0PULLD_ENABLED) | \
|
NPM6001_BUCKMODEPADCONF_BUCKMODE0PULLD_ENABLED) | \
|
||||||
|
@ -722,22 +680,14 @@ static const struct regulator_driver_api api = {
|
||||||
NPM6001_PADDRIVESTRENGTH_SDA_HIGH)), \
|
NPM6001_PADDRIVESTRENGTH_SDA_HIGH)), \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
DEVICE_DT_INST_DEFINE(inst, regulator_npm6001_common_init, NULL, NULL, \
|
DEVICE_DT_INST_DEFINE(inst, regulator_npm6001_common_init, NULL, NULL, &config_##inst, \
|
||||||
&config_##inst, POST_KERNEL, \
|
POST_KERNEL, CONFIG_REGULATOR_NPM6001_COMMON_INIT_PRIORITY, NULL); \
|
||||||
CONFIG_REGULATOR_NPM6001_COMMON_INIT_PRIORITY, \
|
|
||||||
NULL); \
|
|
||||||
\
|
\
|
||||||
REGULATOR_NPM6001_DEFINE_COND(inst, buck0, NPM6001_SOURCE_BUCK0, \
|
REGULATOR_NPM6001_DEFINE_COND(inst, buck0, NPM6001_SOURCE_BUCK0, DEVICE_DT_INST_GET(inst)) \
|
||||||
DEVICE_DT_INST_GET(inst)) \
|
REGULATOR_NPM6001_DEFINE_COND(inst, buck1, NPM6001_SOURCE_BUCK1, DEVICE_DT_INST_GET(inst)) \
|
||||||
REGULATOR_NPM6001_DEFINE_COND(inst, buck1, NPM6001_SOURCE_BUCK1, \
|
REGULATOR_NPM6001_DEFINE_COND(inst, buck2, NPM6001_SOURCE_BUCK2, DEVICE_DT_INST_GET(inst)) \
|
||||||
DEVICE_DT_INST_GET(inst)) \
|
REGULATOR_NPM6001_DEFINE_COND(inst, buck3, NPM6001_SOURCE_BUCK3, DEVICE_DT_INST_GET(inst)) \
|
||||||
REGULATOR_NPM6001_DEFINE_COND(inst, buck2, NPM6001_SOURCE_BUCK2, \
|
REGULATOR_NPM6001_DEFINE_COND(inst, ldo0, NPM6001_SOURCE_LDO0, DEVICE_DT_INST_GET(inst)) \
|
||||||
DEVICE_DT_INST_GET(inst)) \
|
REGULATOR_NPM6001_DEFINE_COND(inst, ldo1, NPM6001_SOURCE_LDO1, DEVICE_DT_INST_GET(inst))
|
||||||
REGULATOR_NPM6001_DEFINE_COND(inst, buck3, NPM6001_SOURCE_BUCK3, \
|
|
||||||
DEVICE_DT_INST_GET(inst)) \
|
|
||||||
REGULATOR_NPM6001_DEFINE_COND(inst, ldo0, NPM6001_SOURCE_LDO0, \
|
|
||||||
DEVICE_DT_INST_GET(inst)) \
|
|
||||||
REGULATOR_NPM6001_DEFINE_COND(inst, ldo1, NPM6001_SOURCE_LDO1, \
|
|
||||||
DEVICE_DT_INST_GET(inst))
|
|
||||||
|
|
||||||
DT_INST_FOREACH_STATUS_OKAY(REGULATOR_NPM6001_DEFINE_ALL)
|
DT_INST_FOREACH_STATUS_OKAY(REGULATOR_NPM6001_DEFINE_ALL)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue