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:
Gerard Marull-Paretas 2023-05-24 11:59:51 +02:00 committed by Anas Nashif
commit 5521db3576

View file

@ -29,41 +29,40 @@ enum npm6001_sources {
#define NPM6001_TASKS_START_LDO0 0x03U
#define NPM6001_TASKS_START_LDO1 0x04U
#define NPM6001_TASKS_STOP_BUCK3 0x08U
#define NPM6001_TASKS_STOP_LDO0 0x09U
#define NPM6001_TASKS_STOP_LDO1 0x0AU
#define NPM6001_TASKS_STOP_LDO0 0x09U
#define NPM6001_TASKS_STOP_LDO1 0x0AU
#define NPM6001_TASKS_UPDATE_VOUTPWM 0x0EU
#define NPM6001_EVENTS_THWARN 0x1EU
#define NPM6001_EVENTS_BUCK0OC 0x1FU
#define NPM6001_EVENTS_BUCK1OC 0x20U
#define NPM6001_EVENTS_BUCK2OC 0x21U
#define NPM6001_EVENTS_BUCK3OC 0x22U
#define NPM6001_BUCK0VOUTULP 0x3AU
#define NPM6001_BUCK1VOUTULP 0x3CU
#define NPM6001_BUCK2VOUTULP 0x40U
#define NPM6001_BUCK3SELDAC 0x44U
#define NPM6001_BUCK3VOUT 0x45U
#define NPM6001_LDO0VOUT 0x46U
#define NPM6001_EVENTS_THWARN 0x1EU
#define NPM6001_EVENTS_BUCK0OC 0x1FU
#define NPM6001_EVENTS_BUCK1OC 0x20U
#define NPM6001_EVENTS_BUCK2OC 0x21U
#define NPM6001_EVENTS_BUCK3OC 0x22U
#define NPM6001_BUCK0VOUTULP 0x3AU
#define NPM6001_BUCK1VOUTULP 0x3CU
#define NPM6001_BUCK2VOUTULP 0x40U
#define NPM6001_BUCK3SELDAC 0x44U
#define NPM6001_BUCK3VOUT 0x45U
#define NPM6001_LDO0VOUT 0x46U
#define NPM6001_BUCK0CONFPWMMODE 0x4AU
#define NPM6001_BUCK1CONFPWMMODE 0x4BU
#define NPM6001_BUCK2CONFPWMMODE 0x4CU
#define NPM6001_BUCK3CONFPWMMODE 0x4DU
#define NPM6001_BUCKMODEPADCONF 0x4EU
#define NPM6001_BUCKMODEPADCONF 0x4EU
#define NPM6001_PADDRIVESTRENGTH 0x53U
#define NPM6001_OVERRIDEPWRUPBUCK 0xABU
/* nPM6001 LDO0VOUT values */
#define NPM6001_LDO0VOUT_SET1V8 0x06U
#define NPM6001_LDO0VOUT_SET2V1 0x0BU
#define NPM6001_LDO0VOUT_SET1V8 0x06U
#define NPM6001_LDO0VOUT_SET2V1 0x0BU
#define NPM6001_LDO0VOUT_SET2V41 0x10U
#define NPM6001_LDO0VOUT_SET2V7 0x15U
#define NPM6001_LDO0VOUT_SET3V0 0x1AU
#define NPM6001_LDO0VOUT_SET3V3 0x1EU
#define NPM6001_LDO0VOUT_SET2V7 0x15U
#define NPM6001_LDO0VOUT_SET3V0 0x1AU
#define NPM6001_LDO0VOUT_SET3V3 0x1EU
/* nPM6001 BUCKXCONFPWMMODE fields */
#define NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_MSK 0x8U
#define NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_POS 3
#define NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM \
BIT(NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_POS)
#define NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM BIT(NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_POS)
#define NPM6001_BUCKMODEPADCONF_BUCKMODE0PADTYPE_CMOS BIT(0)
#define NPM6001_BUCKMODEPADCONF_BUCKMODE1PADTYPE_CMOS BIT(1)
@ -104,29 +103,21 @@ struct regulator_npm6001_vmap {
int32_t volt_uv;
};
static const struct linear_range buck0_range =
LINEAR_RANGE_INIT(1800000, 100000U, 0x0U, 0xFU);
static const struct linear_range buck0_range = LINEAR_RANGE_INIT(1800000, 100000U, 0x0U, 0xFU);
static const struct linear_range buck1_range =
LINEAR_RANGE_INIT(700000, 50000U, 0x0U, 0xEU);
static const struct linear_range buck1_range = LINEAR_RANGE_INIT(700000, 50000U, 0x0U, 0xEU);
static const struct linear_range buck2_range =
LINEAR_RANGE_INIT(1200000, 50000U, 0xAU, 0xEU);
static const struct linear_range buck2_range = LINEAR_RANGE_INIT(1200000, 50000U, 0xAU, 0xEU);
static const struct linear_range buck3_range =
LINEAR_RANGE_INIT(500000, 25000U, 0x0U, 0x70U);
static const struct linear_range buck3_range = LINEAR_RANGE_INIT(500000, 25000U, 0x0U, 0x70U);
static const struct regulator_npm6001_vmap ldo0_voltages[] = {
{ NPM6001_LDO0VOUT_SET1V8, 1800000 },
{ NPM6001_LDO0VOUT_SET2V1, 2100000 },
{ NPM6001_LDO0VOUT_SET2V41, 2410000 },
{ NPM6001_LDO0VOUT_SET2V7, 2700000 },
{ NPM6001_LDO0VOUT_SET3V0, 3000000 },
{ NPM6001_LDO0VOUT_SET3V3, 3300000 },
{NPM6001_LDO0VOUT_SET1V8, 1800000}, {NPM6001_LDO0VOUT_SET2V1, 2100000},
{NPM6001_LDO0VOUT_SET2V41, 2410000}, {NPM6001_LDO0VOUT_SET2V7, 2700000},
{NPM6001_LDO0VOUT_SET3V0, 3000000}, {NPM6001_LDO0VOUT_SET3V3, 3300000},
};
static int regulator_npm6001_ldo0_list_voltage(const struct device *dev,
unsigned int idx,
static int regulator_npm6001_ldo0_list_voltage(const struct device *dev, unsigned int idx,
int32_t *volt_uv)
{
if (idx >= ARRAY_SIZE(ldo0_voltages)) {
@ -138,9 +129,9 @@ static int regulator_npm6001_ldo0_list_voltage(const struct device *dev,
return 0;
}
static int regulator_npm6001_buck012_set_voltage(
const struct device *dev, int32_t min_uv, int32_t max_uv,
const struct linear_range *range, uint8_t vout_reg, uint8_t conf_reg)
static int regulator_npm6001_buck012_set_voltage(const struct device *dev, int32_t min_uv,
int32_t max_uv, const struct linear_range *range,
uint8_t vout_reg, uint8_t conf_reg)
{
const struct regulator_npm6001_config *config = dev->config;
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
@ -160,9 +151,8 @@ static int regulator_npm6001_buck012_set_voltage(
}
if ((conf & NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM) == 0U) {
ret = i2c_reg_write_byte_dt(
&pconfig->i2c, conf_reg,
conf | NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM);
ret = i2c_reg_write_byte_dt(&pconfig->i2c, conf_reg,
conf | NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM);
if (ret < 0) {
return ret;
}
@ -178,8 +168,7 @@ static int regulator_npm6001_buck012_set_voltage(
return ret;
}
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_UPDATE_VOUTPWM,
1U);
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_UPDATE_VOUTPWM, 1U);
if (ret < 0) {
return ret;
}
@ -195,8 +184,8 @@ static int regulator_npm6001_buck012_set_voltage(
return 0;
}
static int regulator_npm6001_buck3_set_voltage(const struct device *dev,
int32_t min_uv, int32_t max_uv)
static int regulator_npm6001_buck3_set_voltage(const struct device *dev, int32_t min_uv,
int32_t max_uv)
{
const struct regulator_npm6001_config *config = dev->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 */
ret = i2c_reg_read_byte_dt(&pconfig->i2c, NPM6001_BUCK3CONFPWMMODE,
&conf);
ret = i2c_reg_read_byte_dt(&pconfig->i2c, NPM6001_BUCK3CONFPWMMODE, &conf);
if (ret < 0) {
return ret;
}
if ((conf & NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM) == 0U) {
ret = i2c_reg_write_byte_dt(
&pconfig->i2c, NPM6001_BUCK3CONFPWMMODE,
conf | NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM);
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_BUCK3CONFPWMMODE,
conf | NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM);
if (ret < 0) {
return ret;
}
}
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_BUCK3VOUT,
(uint8_t)idx);
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_BUCK3VOUT, (uint8_t)idx);
if (ret < 0) {
return ret;
}
/* restore HYS mode if enabled before */
if ((conf & NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM) == 0U) {
ret = i2c_reg_write_byte_dt(&pconfig->i2c,
NPM6001_BUCK3CONFPWMMODE, conf);
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_BUCK3CONFPWMMODE, conf);
if (ret < 0) {
return ret;
}
@ -243,8 +228,8 @@ static int regulator_npm6001_buck3_set_voltage(const struct device *dev,
return 0;
}
static int regulator_npm6001_ldo0_set_voltage(const struct device *dev,
int32_t min_uv, int32_t max_uv)
static int regulator_npm6001_ldo0_set_voltage(const struct device *dev, int32_t min_uv,
int32_t max_uv)
{
const struct regulator_npm6001_config *config = dev->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;
for (i = 0U; i < ARRAY_SIZE(ldo0_voltages); i++) {
if ((min_uv <= ldo0_voltages[i].volt_uv) &&
(max_uv >= ldo0_voltages[i].volt_uv)) {
if ((min_uv <= ldo0_voltages[i].volt_uv) && (max_uv >= ldo0_voltages[i].volt_uv)) {
val = ldo0_voltages[i].reg_val;
break;
}
@ -266,10 +250,9 @@ static int regulator_npm6001_ldo0_set_voltage(const struct device *dev,
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_LDO0VOUT, val);
}
static int
regulator_npm6001_buck0123_get_voltage(const struct device *dev,
const struct linear_range *range,
uint8_t vout_reg, int32_t *volt_uv)
static int regulator_npm6001_buck0123_get_voltage(const struct device *dev,
const struct linear_range *range,
uint8_t vout_reg, int32_t *volt_uv)
{
const struct regulator_npm6001_config *config = dev->config;
const struct regulator_npm6001_pconfig *pconfig = config->p->config;
@ -284,8 +267,7 @@ regulator_npm6001_buck0123_get_voltage(const struct device *dev,
return linear_range_get_value(range, idx, volt_uv);
}
static int regulator_npm6001_ldo0_get_voltage(const struct device *dev,
int32_t *volt_uv)
static int regulator_npm6001_ldo0_get_voltage(const struct device *dev, int32_t *volt_uv)
{
const struct regulator_npm6001_config *config = dev->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;
}
static int regulator_npm6001_list_voltage(const struct device *dev,
unsigned int idx, int32_t *volt_uv)
static int regulator_npm6001_list_voltage(const struct device *dev, unsigned int idx,
int32_t *volt_uv)
{
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:
return linear_range_get_value(&buck1_range, idx, volt_uv);
case NPM6001_SOURCE_BUCK2:
return linear_range_get_value(
&buck2_range, idx + buck2_range.min_idx, volt_uv);
return linear_range_get_value(&buck2_range, idx + buck2_range.min_idx, volt_uv);
case NPM6001_SOURCE_BUCK3:
return linear_range_get_value(&buck3_range, idx, volt_uv);
case NPM6001_SOURCE_LDO0:
@ -360,24 +341,23 @@ static int regulator_npm6001_list_voltage(const struct device *dev,
return 0;
}
static int regulator_npm6001_set_voltage(const struct device *dev,
int32_t min_uv, int32_t max_uv)
static int regulator_npm6001_set_voltage(const struct device *dev, int32_t min_uv, int32_t max_uv)
{
const struct regulator_npm6001_config *config = dev->config;
switch (config->source) {
case NPM6001_SOURCE_BUCK0:
return regulator_npm6001_buck012_set_voltage(
dev, min_uv, max_uv, &buck0_range, NPM6001_BUCK0VOUTULP,
NPM6001_BUCK0CONFPWMMODE);
return regulator_npm6001_buck012_set_voltage(dev, min_uv, max_uv, &buck0_range,
NPM6001_BUCK0VOUTULP,
NPM6001_BUCK0CONFPWMMODE);
case NPM6001_SOURCE_BUCK1:
return regulator_npm6001_buck012_set_voltage(
dev, min_uv, max_uv, &buck1_range, NPM6001_BUCK1VOUTULP,
NPM6001_BUCK1CONFPWMMODE);
return regulator_npm6001_buck012_set_voltage(dev, min_uv, max_uv, &buck1_range,
NPM6001_BUCK1VOUTULP,
NPM6001_BUCK1CONFPWMMODE);
case NPM6001_SOURCE_BUCK2:
return regulator_npm6001_buck012_set_voltage(
dev, min_uv, max_uv, &buck2_range, NPM6001_BUCK2VOUTULP,
NPM6001_BUCK2CONFPWMMODE);
return regulator_npm6001_buck012_set_voltage(dev, min_uv, max_uv, &buck2_range,
NPM6001_BUCK2VOUTULP,
NPM6001_BUCK2CONFPWMMODE);
case NPM6001_SOURCE_BUCK3:
return regulator_npm6001_buck3_set_voltage(dev, min_uv, max_uv);
case NPM6001_SOURCE_LDO0:
@ -394,24 +374,23 @@ static int regulator_npm6001_set_voltage(const struct device *dev,
return 0;
}
static int regulator_npm6001_get_voltage(const struct device *dev,
int32_t *volt_uv)
static int regulator_npm6001_get_voltage(const struct device *dev, int32_t *volt_uv)
{
const struct regulator_npm6001_config *config = dev->config;
switch (config->source) {
case NPM6001_SOURCE_BUCK0:
return regulator_npm6001_buck0123_get_voltage(
dev, &buck0_range, NPM6001_BUCK0VOUTULP, volt_uv);
return regulator_npm6001_buck0123_get_voltage(dev, &buck0_range,
NPM6001_BUCK0VOUTULP, volt_uv);
case NPM6001_SOURCE_BUCK1:
return regulator_npm6001_buck0123_get_voltage(
dev, &buck1_range, NPM6001_BUCK1VOUTULP, volt_uv);
return regulator_npm6001_buck0123_get_voltage(dev, &buck1_range,
NPM6001_BUCK1VOUTULP, volt_uv);
case NPM6001_SOURCE_BUCK2:
return regulator_npm6001_buck0123_get_voltage(
dev, &buck2_range, NPM6001_BUCK2VOUTULP, volt_uv);
return regulator_npm6001_buck0123_get_voltage(dev, &buck2_range,
NPM6001_BUCK2VOUTULP, volt_uv);
case NPM6001_SOURCE_BUCK3:
return regulator_npm6001_buck0123_get_voltage(
dev, &buck3_range, NPM6001_BUCK3VOUT, volt_uv);
return regulator_npm6001_buck0123_get_voltage(dev, &buck3_range, NPM6001_BUCK3VOUT,
volt_uv);
case NPM6001_SOURCE_LDO0:
return regulator_npm6001_ldo0_get_voltage(dev, volt_uv);
case NPM6001_SOURCE_LDO1:
@ -424,8 +403,7 @@ static int regulator_npm6001_get_voltage(const struct device *dev,
return 0;
}
static int regulator_npm6001_set_mode(const struct device *dev,
regulator_mode_t mode)
static int regulator_npm6001_set_mode(const struct device *dev, regulator_mode_t mode)
{
const struct regulator_npm6001_config *config = dev->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 i2c_reg_update_byte_dt(
&pconfig->i2c, conf_reg,
NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_MSK,
mode << NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_POS);
return i2c_reg_update_byte_dt(&pconfig->i2c, conf_reg,
NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_MSK,
mode << NPM6001_BUCKXCONFPWMMODE_SETFORCEPWM_POS);
}
static int regulator_npm6001_get_mode(const struct device *dev,
regulator_mode_t *mode)
static int regulator_npm6001_get_mode(const struct device *dev, regulator_mode_t *mode)
{
const struct regulator_npm6001_config *config = dev->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) {
case NPM6001_SOURCE_BUCK1:
return i2c_reg_update_byte_dt(
&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
NPM6001_OVERRIDEPWRUPBUCK_BUCK1DISABLE_MSK, 0U);
return i2c_reg_update_byte_dt(&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
NPM6001_OVERRIDEPWRUPBUCK_BUCK1DISABLE_MSK, 0U);
case NPM6001_SOURCE_BUCK2:
return i2c_reg_update_byte_dt(
&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
NPM6001_OVERRIDEPWRUPBUCK_BUCK2DISABLE_MSK, 0U);
return i2c_reg_update_byte_dt(&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
NPM6001_OVERRIDEPWRUPBUCK_BUCK2DISABLE_MSK, 0U);
case NPM6001_SOURCE_BUCK3:
return i2c_reg_write_byte_dt(&pconfig->i2c,
NPM6001_TASKS_START_BUCK3, 1U);
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_START_BUCK3, 1U);
case NPM6001_SOURCE_LDO0:
return i2c_reg_write_byte_dt(&pconfig->i2c,
NPM6001_TASKS_START_LDO0, 1U);
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_START_LDO0, 1U);
case NPM6001_SOURCE_LDO1:
return i2c_reg_write_byte_dt(&pconfig->i2c,
NPM6001_TASKS_START_LDO1, 1U);
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_START_LDO1, 1U);
default:
return 0;
}
@ -529,24 +500,19 @@ static int regulator_npm6001_disable(const struct device *dev)
switch (config->source) {
case NPM6001_SOURCE_BUCK1:
return i2c_reg_update_byte_dt(
&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
NPM6001_OVERRIDEPWRUPBUCK_BUCK1DISABLE_MSK,
NPM6001_OVERRIDEPWRUPBUCK_BUCK1DISABLE);
return i2c_reg_update_byte_dt(&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
NPM6001_OVERRIDEPWRUPBUCK_BUCK1DISABLE_MSK,
NPM6001_OVERRIDEPWRUPBUCK_BUCK1DISABLE);
case NPM6001_SOURCE_BUCK2:
return i2c_reg_update_byte_dt(
&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
NPM6001_OVERRIDEPWRUPBUCK_BUCK2DISABLE_MSK,
NPM6001_OVERRIDEPWRUPBUCK_BUCK2DISABLE);
return i2c_reg_update_byte_dt(&pconfig->i2c, NPM6001_OVERRIDEPWRUPBUCK,
NPM6001_OVERRIDEPWRUPBUCK_BUCK2DISABLE_MSK,
NPM6001_OVERRIDEPWRUPBUCK_BUCK2DISABLE);
case NPM6001_SOURCE_BUCK3:
return i2c_reg_write_byte_dt(&pconfig->i2c,
NPM6001_TASKS_STOP_BUCK3, 1U);
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_STOP_BUCK3, 1U);
case NPM6001_SOURCE_LDO0:
return i2c_reg_write_byte_dt(&pconfig->i2c,
NPM6001_TASKS_STOP_LDO0, 1U);
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_STOP_LDO0, 1U);
case NPM6001_SOURCE_LDO1:
return i2c_reg_write_byte_dt(&pconfig->i2c,
NPM6001_TASKS_STOP_LDO1, 1U);
return i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_TASKS_STOP_LDO1, 1U);
default:
return 0;
}
@ -570,8 +536,7 @@ static int regulator_npm6001_get_error_flags(const struct device *dev,
if (val != 0U) {
/* clear thermal warning */
ret = i2c_reg_write_byte_dt(&pconfig->i2c,
NPM6001_EVENTS_THWARN, 0U);
ret = i2c_reg_write_byte_dt(&pconfig->i2c, NPM6001_EVENTS_THWARN, 0U);
if (ret < 0) {
return ret;
}
@ -649,14 +614,12 @@ static int regulator_npm6001_common_init(const struct device *dev)
}
/* configure pad properties */
ret = i2c_reg_write_byte_dt(&config->i2c, NPM6001_BUCKMODEPADCONF,
config->buck_pad_val);
ret = i2c_reg_write_byte_dt(&config->i2c, NPM6001_BUCKMODEPADCONF, config->buck_pad_val);
if (ret < 0) {
return ret;
}
ret = i2c_reg_write_byte_dt(&config->i2c, NPM6001_PADDRIVESTRENGTH,
config->pad_val);
ret = i2c_reg_write_byte_dt(&config->i2c, NPM6001_PADDRIVESTRENGTH, config->pad_val);
if (ret < 0) {
return ret;
}
@ -676,68 +639,55 @@ static const struct regulator_driver_api api = {
.get_error_flags = regulator_npm6001_get_error_flags,
};
#define REGULATOR_NPM6001_DEFINE(node_id, id, _source, parent) \
static struct regulator_npm6001_data data_##id; \
\
static const struct regulator_npm6001_config config_##id = { \
.common = REGULATOR_DT_COMMON_CONFIG_INIT(node_id), \
.p = parent, \
.source = _source, \
}; \
\
DEVICE_DT_DEFINE(node_id, regulator_npm6001_init, NULL, &data_##id, \
&config_##id, POST_KERNEL, \
CONFIG_REGULATOR_NPM6001_INIT_PRIORITY, &api);
#define REGULATOR_NPM6001_DEFINE(node_id, id, _source, parent) \
static struct regulator_npm6001_data data_##id; \
\
static const struct regulator_npm6001_config config_##id = { \
.common = REGULATOR_DT_COMMON_CONFIG_INIT(node_id), \
.p = parent, \
.source = _source, \
}; \
\
DEVICE_DT_DEFINE(node_id, regulator_npm6001_init, NULL, &data_##id, &config_##id, \
POST_KERNEL, CONFIG_REGULATOR_NPM6001_INIT_PRIORITY, &api);
#define REGULATOR_NPM6001_DEFINE_COND(inst, child, source, parent) \
COND_CODE_1(DT_NODE_EXISTS(DT_INST_CHILD(inst, child)), \
(REGULATOR_NPM6001_DEFINE(DT_INST_CHILD(inst, child), \
child##inst, source, parent)), \
#define REGULATOR_NPM6001_DEFINE_COND(inst, child, source, parent) \
COND_CODE_1(DT_NODE_EXISTS(DT_INST_CHILD(inst, child)), \
(REGULATOR_NPM6001_DEFINE(DT_INST_CHILD(inst, child), child##inst, source, \
parent)), \
())
#define REGULATOR_NPM6001_DEFINE_ALL(inst) \
static const struct regulator_npm6001_pconfig config_##inst = { \
.i2c = I2C_DT_SPEC_GET(DT_INST_PARENT(inst)), \
.buck_pad_val = \
((DT_INST_ENUM_IDX(inst, \
nordic_buck_mode0_input_type) * \
NPM6001_BUCKMODEPADCONF_BUCKMODE0PADTYPE_CMOS) | \
(DT_INST_ENUM_IDX(inst, \
nordic_buck_mode1_input_type) * \
NPM6001_BUCKMODEPADCONF_BUCKMODE1PADTYPE_CMOS) | \
(DT_INST_ENUM_IDX(inst, \
nordic_buck_mode2_input_type) * \
NPM6001_BUCKMODEPADCONF_BUCKMODE2PADTYPE_CMOS) | \
(DT_INST_PROP(inst, nordic_buck_mode0_pull_down) * \
NPM6001_BUCKMODEPADCONF_BUCKMODE0PULLD_ENABLED) | \
(DT_INST_PROP(inst, nordic_buck_mode1_pull_down) * \
NPM6001_BUCKMODEPADCONF_BUCKMODE1PULLD_ENABLED) | \
(DT_INST_PROP(inst, nordic_buck_mode2_pull_down) * \
NPM6001_BUCKMODEPADCONF_BUCKMODE2PULLD_ENABLED)), \
.pad_val = ((DT_INST_PROP(inst, nordic_ready_high_drive) * \
NPM6001_PADDRIVESTRENGTH_READY_HIGH) | \
(DT_INST_PROP(inst, nordic_nint_high_drive) * \
NPM6001_PADDRIVESTRENGTH_NINT_HIGH) | \
(DT_INST_PROP(inst, nordic_sda_high_drive) * \
NPM6001_PADDRIVESTRENGTH_SDA_HIGH)), \
}; \
\
DEVICE_DT_INST_DEFINE(inst, regulator_npm6001_common_init, NULL, NULL, \
&config_##inst, POST_KERNEL, \
CONFIG_REGULATOR_NPM6001_COMMON_INIT_PRIORITY, \
NULL); \
\
REGULATOR_NPM6001_DEFINE_COND(inst, buck0, NPM6001_SOURCE_BUCK0, \
DEVICE_DT_INST_GET(inst)) \
REGULATOR_NPM6001_DEFINE_COND(inst, buck1, NPM6001_SOURCE_BUCK1, \
DEVICE_DT_INST_GET(inst)) \
REGULATOR_NPM6001_DEFINE_COND(inst, buck2, NPM6001_SOURCE_BUCK2, \
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))
#define REGULATOR_NPM6001_DEFINE_ALL(inst) \
static const struct regulator_npm6001_pconfig config_##inst = { \
.i2c = I2C_DT_SPEC_GET(DT_INST_PARENT(inst)), \
.buck_pad_val = ((DT_INST_ENUM_IDX(inst, nordic_buck_mode0_input_type) * \
NPM6001_BUCKMODEPADCONF_BUCKMODE0PADTYPE_CMOS) | \
(DT_INST_ENUM_IDX(inst, nordic_buck_mode1_input_type) * \
NPM6001_BUCKMODEPADCONF_BUCKMODE1PADTYPE_CMOS) | \
(DT_INST_ENUM_IDX(inst, nordic_buck_mode2_input_type) * \
NPM6001_BUCKMODEPADCONF_BUCKMODE2PADTYPE_CMOS) | \
(DT_INST_PROP(inst, nordic_buck_mode0_pull_down) * \
NPM6001_BUCKMODEPADCONF_BUCKMODE0PULLD_ENABLED) | \
(DT_INST_PROP(inst, nordic_buck_mode1_pull_down) * \
NPM6001_BUCKMODEPADCONF_BUCKMODE1PULLD_ENABLED) | \
(DT_INST_PROP(inst, nordic_buck_mode2_pull_down) * \
NPM6001_BUCKMODEPADCONF_BUCKMODE2PULLD_ENABLED)), \
.pad_val = ((DT_INST_PROP(inst, nordic_ready_high_drive) * \
NPM6001_PADDRIVESTRENGTH_READY_HIGH) | \
(DT_INST_PROP(inst, nordic_nint_high_drive) * \
NPM6001_PADDRIVESTRENGTH_NINT_HIGH) | \
(DT_INST_PROP(inst, nordic_sda_high_drive) * \
NPM6001_PADDRIVESTRENGTH_SDA_HIGH)), \
}; \
\
DEVICE_DT_INST_DEFINE(inst, regulator_npm6001_common_init, NULL, NULL, &config_##inst, \
POST_KERNEL, CONFIG_REGULATOR_NPM6001_COMMON_INIT_PRIORITY, NULL); \
\
REGULATOR_NPM6001_DEFINE_COND(inst, buck0, NPM6001_SOURCE_BUCK0, DEVICE_DT_INST_GET(inst)) \
REGULATOR_NPM6001_DEFINE_COND(inst, buck1, NPM6001_SOURCE_BUCK1, DEVICE_DT_INST_GET(inst)) \
REGULATOR_NPM6001_DEFINE_COND(inst, buck2, NPM6001_SOURCE_BUCK2, 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)