@@ -73,6 +73,13 @@ enum npm1300_gpio_type {
7373#define LDSW2_SOFTSTART_MASK 0x30U
7474#define LDSW2_SOFTSTART_SHIFT 4U
7575
76+ #define NPM1300_GPIO_UNUSED UINT8_MAX
77+
78+ struct npm1300_gpio_info {
79+ uint8_t pin ;
80+ bool invert ;
81+ };
82+
7683struct regulator_npm1300_pconfig {
7784 const struct device * mfd ;
7885 struct gpio_dt_spec dvs_state_pins [5 ];
@@ -83,9 +90,9 @@ struct regulator_npm1300_config {
8390 const struct device * mfd ;
8491 uint8_t source ;
8592 int32_t retention_uv ;
86- struct gpio_dt_spec enable_gpios ;
87- struct gpio_dt_spec retention_gpios ;
88- struct gpio_dt_spec pwm_gpios ;
93+ struct npm1300_gpio_info enable_gpios ;
94+ struct npm1300_gpio_info retention_gpios ;
95+ struct npm1300_gpio_info pwm_gpios ;
8996 uint8_t soft_start ;
9097 bool ldo_disable_workaround ;
9198};
@@ -407,22 +414,24 @@ int regulator_npm1300_disable(const struct device *dev)
407414 }
408415}
409416
410- static int regulator_npm1300_set_buck_pin_ctrl (const struct device * dev , uint8_t chan , uint8_t pin ,
411- uint8_t inv , enum npm1300_gpio_type type )
417+ static int regulator_npm1300_set_buck_pin_ctrl (const struct device * dev , uint8_t chan ,
418+ const struct npm1300_gpio_info * pin_info ,
419+ enum npm1300_gpio_type type )
412420{
413421 const struct regulator_npm1300_config * config = dev -> config ;
422+ uint8_t inv = pin_info -> invert ? 1 : 0 ;
414423 uint8_t ctrl ;
415424 uint8_t mask ;
416425
417426 switch (chan ) {
418427 case 0 :
419428 /* Invert control in bit 6, pin control in bits 2-0 */
420- ctrl = (inv << 6U ) | (pin + 1U );
429+ ctrl = (inv << 6U ) | (pin_info -> pin + 1U );
421430 mask = BIT (6U ) | BIT_MASK (3U );
422431 break ;
423432 case 1 :
424433 /* Invert control in bit 7, pin control in bits 5-3 */
425- ctrl = (inv << 7U ) | ((pin + 1U ) << 3U );
434+ ctrl = (inv << 7U ) | ((pin_info -> pin + 1U ) << 3U );
426435 mask = BIT (7U ) | (BIT_MASK (3U ) << 3U );
427436 break ;
428437 default :
@@ -444,42 +453,41 @@ static int regulator_npm1300_set_buck_pin_ctrl(const struct device *dev, uint8_t
444453 }
445454}
446455
447- static int regulator_npm1300_set_ldsw_pin_ctrl (const struct device * dev , uint8_t chan , uint8_t pin ,
448- uint8_t inv , enum npm1300_gpio_type type )
456+ static int regulator_npm1300_set_ldsw_pin_ctrl (const struct device * dev , uint8_t chan ,
457+ const struct npm1300_gpio_info * pin_info ,
458+ enum npm1300_gpio_type type )
449459{
450460 const struct regulator_npm1300_config * config = dev -> config ;
461+ uint8_t inv = pin_info -> invert ? 1 : 0 ;
451462 uint8_t ctrl ;
452463
453464 if (type != NPM1300_GPIO_TYPE_ENABLE ) {
454465 return - ENOTSUP ;
455466 }
456467
457- ctrl = (pin + 1U ) | (inv << 3U );
468+ ctrl = (pin_info -> pin + 1U ) | (inv << 3U );
458469
459470 return mfd_npm1300_reg_write (config -> mfd , LDSW_BASE , LDSW_OFFSET_GPISEL + chan , ctrl );
460471}
461472
462- int regulator_npm1300_set_pin_ctrl (const struct device * dev , const struct gpio_dt_spec * spec ,
473+ int regulator_npm1300_set_pin_ctrl (const struct device * dev , const struct npm1300_gpio_info * info ,
463474 enum npm1300_gpio_type type )
464475{
465476 const struct regulator_npm1300_config * config = dev -> config ;
466- uint8_t inv ;
467477
468- if (spec -> port == NULL ) {
478+ if (info -> pin == NPM1300_GPIO_UNUSED ) {
469479 return 0 ;
470480 }
471481
472- inv = (spec -> dt_flags & GPIO_ACTIVE_LOW ) != 0U ;
473-
474482 switch (config -> source ) {
475483 case NPM1300_SOURCE_BUCK1 :
476- return regulator_npm1300_set_buck_pin_ctrl (dev , 0 , spec -> pin , inv , type );
484+ return regulator_npm1300_set_buck_pin_ctrl (dev , 0 , info , type );
477485 case NPM1300_SOURCE_BUCK2 :
478- return regulator_npm1300_set_buck_pin_ctrl (dev , 1 , spec -> pin , inv , type );
486+ return regulator_npm1300_set_buck_pin_ctrl (dev , 1 , info , type );
479487 case NPM1300_SOURCE_LDO1 :
480- return regulator_npm1300_set_ldsw_pin_ctrl (dev , 0 , spec -> pin , inv , type );
488+ return regulator_npm1300_set_ldsw_pin_ctrl (dev , 0 , info , type );
481489 case NPM1300_SOURCE_LDO2 :
482- return regulator_npm1300_set_ldsw_pin_ctrl (dev , 1 , spec -> pin , inv , type );
490+ return regulator_npm1300_set_ldsw_pin_ctrl (dev , 1 , info , type );
483491 default :
484492 return - ENODEV ;
485493 }
@@ -661,7 +669,16 @@ static DEVICE_API(regulator, api) = {
661669 .set_mode = regulator_npm1300_set_mode ,
662670};
663671
672+ #define GPIO_CONFIG_DEFINE (node_id , prop ) \
673+ COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
674+ ({DT_PROP_BY_IDX(node_id, prop, 0), \
675+ !!(DT_PROP_BY_IDX(node_id, prop, 1) & GPIO_ACTIVE_LOW)}), \
676+ ({NPM1300_GPIO_UNUSED, false}))
677+
664678#define REGULATOR_NPM1300_DEFINE (node_id , id , _source ) \
679+ BUILD_ASSERT(DT_PROP_LEN_OR(node_id, enable_gpio_config, 2) == 2); \
680+ BUILD_ASSERT(DT_PROP_LEN_OR(node_id, retention_gpio_config, 2) == 2); \
681+ BUILD_ASSERT(DT_PROP_LEN_OR(node_id, pwm_gpio_config, 2) == 2); \
665682 static struct regulator_npm1300_data data_##id; \
666683 \
667684 static const struct regulator_npm1300_config config_##id = { \
@@ -670,9 +687,9 @@ static DEVICE_API(regulator, api) = {
670687 .source = _source, \
671688 .retention_uv = DT_PROP_OR(node_id, retention_microvolt, 0), \
672689 .soft_start = DT_ENUM_IDX_OR(node_id, soft_start_microamp, UINT8_MAX), \
673- .enable_gpios = GPIO_DT_SPEC_GET_OR (node_id, enable_gpios, {0} ), \
674- .retention_gpios = GPIO_DT_SPEC_GET_OR (node_id, retention_gpios, {0} ), \
675- .pwm_gpios = GPIO_DT_SPEC_GET_OR (node_id, pwm_gpios, {0} ), \
690+ .enable_gpios = GPIO_CONFIG_DEFINE (node_id, enable_gpio_config ), \
691+ .retention_gpios = GPIO_CONFIG_DEFINE (node_id, retention_gpio_config ), \
692+ .pwm_gpios = GPIO_CONFIG_DEFINE (node_id, pwm_gpio_config ), \
676693 .ldo_disable_workaround = DT_PROP(node_id, nordic_anomaly38_disable_workaround)}; \
677694 \
678695 DEVICE_DT_DEFINE(node_id, regulator_npm1300_init, NULL, &data_##id, &config_##id, \
0 commit comments