Skip to content

Commit 5dcaf07

Browse files
JordanYateskartben
authored andcommitted
regulator: npm1300: configure active discharge
Configure the active discharge feature for both the BUCK and LDO/LDSW blocks through the appropriate registers. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 0c7fbd1 commit 5dcaf07

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

drivers/regulator/regulator_npm1300.c

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,20 @@ enum npm1300_gpio_type {
6262
/* nPM1300 ship register offsets */
6363
#define SHIP_OFFSET_SHIP 0x02U
6464

65-
#define BUCK1_ON_MASK 0x04U
66-
#define BUCK2_ON_MASK 0x40U
65+
#define BUCK1_ON_MASK 0x04U
66+
#define BUCK2_ON_MASK 0x40U
67+
#define BUCK1_EN_PULLDOWN_MASK BIT(2)
68+
#define BUCK2_EN_PULLDOWN_MASK BIT(3)
6769

6870
#define LDSW1_ON_MASK 0x03U
6971
#define LDSW2_ON_MASK 0x0CU
7072

71-
#define LDSW1_SOFTSTART_MASK 0x0CU
72-
#define LDSW1_SOFTSTART_SHIFT 2U
73-
#define LDSW2_SOFTSTART_MASK 0x30U
74-
#define LDSW2_SOFTSTART_SHIFT 4U
73+
#define LDSW1_SOFTSTART_MASK 0x0CU
74+
#define LDSW1_SOFTSTART_SHIFT 2U
75+
#define LDSW1_ACTIVE_DISCHARGE_MASK BIT(6)
76+
#define LDSW2_SOFTSTART_MASK 0x30U
77+
#define LDSW2_SOFTSTART_SHIFT 4U
78+
#define LDSW2_ACTIVE_DISCHARGE_MASK BIT(7)
7579

7680
#define NPM1300_GPIO_UNUSED UINT8_MAX
7781

@@ -94,6 +98,7 @@ struct regulator_npm1300_config {
9498
struct npm1300_gpio_info retention_gpios;
9599
struct npm1300_gpio_info pwm_gpios;
96100
uint8_t soft_start;
101+
bool active_discharge;
97102
bool ldo_disable_workaround;
98103
};
99104

@@ -603,6 +608,32 @@ static int soft_start_set(const struct device *dev, uint8_t soft_start)
603608
}
604609
}
605610

611+
static int active_discharge_set(const struct device *dev, bool enabled)
612+
{
613+
const struct regulator_npm1300_config *config = dev->config;
614+
615+
switch (config->source) {
616+
case NPM1300_SOURCE_BUCK1:
617+
return mfd_npm1300_reg_update(config->mfd, BUCK_BASE, BUCK_OFFSET_CTRL0,
618+
enabled ? BUCK1_EN_PULLDOWN_MASK : 0,
619+
BUCK1_EN_PULLDOWN_MASK);
620+
case NPM1300_SOURCE_BUCK2:
621+
return mfd_npm1300_reg_update(config->mfd, BUCK_BASE, BUCK_OFFSET_CTRL0,
622+
enabled ? BUCK2_EN_PULLDOWN_MASK : 0,
623+
BUCK2_EN_PULLDOWN_MASK);
624+
case NPM1300_SOURCE_LDO1:
625+
return mfd_npm1300_reg_update(config->mfd, LDSW_BASE, LDSW_OFFSET_CONFIG,
626+
enabled ? LDSW1_ACTIVE_DISCHARGE_MASK : 0,
627+
LDSW1_ACTIVE_DISCHARGE_MASK);
628+
case NPM1300_SOURCE_LDO2:
629+
return mfd_npm1300_reg_update(config->mfd, LDSW_BASE, LDSW_OFFSET_CONFIG,
630+
enabled ? LDSW2_ACTIVE_DISCHARGE_MASK : 0,
631+
LDSW2_ACTIVE_DISCHARGE_MASK);
632+
default:
633+
return -ENODEV;
634+
}
635+
}
636+
606637
int regulator_npm1300_init(const struct device *dev)
607638
{
608639
const struct regulator_npm1300_config *config = dev->config;
@@ -639,6 +670,12 @@ int regulator_npm1300_init(const struct device *dev)
639670
}
640671
}
641672

673+
/* Configure active discharge */
674+
ret = active_discharge_set(dev, config->active_discharge);
675+
if (ret != 0) {
676+
return ret;
677+
}
678+
642679
/* Configure GPIO pin control */
643680
ret = regulator_npm1300_set_pin_ctrl(dev, &config->enable_gpios, NPM1300_GPIO_TYPE_ENABLE);
644681
if (ret != 0) {
@@ -690,6 +727,7 @@ static DEVICE_API(regulator, api) = {
690727
.enable_gpios = GPIO_CONFIG_DEFINE(node_id, enable_gpio_config), \
691728
.retention_gpios = GPIO_CONFIG_DEFINE(node_id, retention_gpio_config), \
692729
.pwm_gpios = GPIO_CONFIG_DEFINE(node_id, pwm_gpio_config), \
730+
.active_discharge = DT_PROP(node_id, active_discharge), \
693731
.ldo_disable_workaround = DT_PROP(node_id, nordic_anomaly38_disable_workaround)}; \
694732
\
695733
DEVICE_DT_DEFINE(node_id, regulator_npm1300_init, NULL, &data_##id, &config_##id, \

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ child-binding:
9797
description: |
9898
Soft start current limit in microamps.
9999
100+
active-discharge:
101+
type: boolean
102+
description: |
103+
Enable active-discharge on the BUCK/LDO/LDSW output when disabled.
104+
100105
nordic,anomaly38-disable-workaround:
101106
type: boolean
102107
description: |

0 commit comments

Comments
 (0)