Skip to content

Commit 4904c27

Browse files
JordanYateskartben
authored andcommitted
regulator: npm1300: convert regulator GPIOs to array
Convert the enable, pwm, and retention `gpios` properties away from the GPIO specifier space to an integer array. While this is a less specific type than the GPIO property, it has the advantage of not requiring the PMIC gpios node to be both present and enabled. Signed-off-by: Jordan Yates <[email protected]>
1 parent da197fe commit 4904c27

File tree

3 files changed

+57
-31
lines changed

3 files changed

+57
-31
lines changed

doc/releases/migration-guide-4.2.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ DMA
114114
* Renamed the devicetree property ``nxp,a_on`` to ``nxp,a-on``.
115115
* Renamed the devicetree property ``dma_channels`` to ``dma-channels``.
116116

117+
Regulator
118+
=========
119+
120+
* :dtcompatible:`nordic,npm1300-regulator` BUCK and LDO node GPIO properties are now specified as an
121+
integer array without a GPIO controller, removing the requirement for a
122+
:dtcompatible:`nordic,npm1300-gpio` node to be present and enabled for GPIO control of the output
123+
rails. For example, ``enable-gpios = <&pmic_gpios 3 GPIO_ACTIVE_LOW>;`` is now specified as
124+
``enable-gpio-config = <3 GPIO_ACTIVE_LOW>;``.
125+
117126
Counter
118127
=======
119128

drivers/regulator/regulator_npm1300.c

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
7683
struct 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, \

dts/bindings/regulator/nordic,npm1300-regulator.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,22 @@ child-binding:
7070
description: |
7171
Retention mode voltage in microvolts.
7272
73-
enable-gpios:
74-
type: phandle-array
73+
enable-gpio-config:
74+
type: array
7575
description: |
76-
Regulator enable controlled by specified regulator GPIO pin.
76+
Regulator enable controlled by specified GPIO pin <idx flags>.
7777
When set regulator must be enabled/disabled using set_dvs_mode.
7878
79-
pwm-gpios:
80-
type: phandle-array
79+
pwm-gpio-config:
80+
type: array
8181
description: |
82-
Regulator enable controlled by specified regulator GPIO pin.
82+
Regulator enable controlled by specified GPIO pin <idx flags>.
8383
When set regulator must be enabled/disabled using set_dvs_mode.
8484
85-
retention-gpios:
86-
type: phandle-array
85+
retention-gpio-config:
86+
type: array
8787
description: |
88-
Retention mode controlled by specified regulator GPIO pin.
88+
Retention mode controlled by specified GPIO pin <idx flags>.
8989
9090
soft-start-microamp:
9191
type: int

0 commit comments

Comments
 (0)