Skip to content

Commit

Permalink
drivers: regulator: npm1300: Add PFM mode
Browse files Browse the repository at this point in the history
Set regulator mode updated to support forced PFM mode

Signed-off-by: Andy Sinclair <[email protected]>
  • Loading branch information
aasinclair authored and carlescufi committed Sep 13, 2023
1 parent 450dbb1 commit 49ef9be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
25 changes: 21 additions & 4 deletions drivers/regulator/regulator_npm1300.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,34 @@ int regulator_npm1300_get_voltage(const struct device *dev, int32_t *volt_uv)
static int set_buck_mode(const struct device *dev, uint8_t chan, regulator_mode_t mode)
{
const struct regulator_npm1300_config *config = dev->config;
uint8_t pfm_mask = BIT(chan);
uint8_t pfm_data;
uint8_t pwm_reg;
int ret;

switch (mode) {
case NPM1300_BUCK_MODE_PWM:
return mfd_npm1300_reg_write(config->mfd, BUCK_BASE,
BUCK_OFFSET_PWM_SET + (chan * 2U), 1U);
pfm_data = 0U;
pwm_reg = BUCK_OFFSET_PWM_SET;
break;
case NPM1300_BUCK_MODE_AUTO:
return mfd_npm1300_reg_write(config->mfd, BUCK_BASE,
BUCK_OFFSET_PWM_CLR + (chan * 2U), 1U);
pfm_data = 0U;
pwm_reg = BUCK_OFFSET_PWM_CLR;
break;
case NPM1300_BUCK_MODE_PFM:
pfm_data = pfm_mask;
pwm_reg = BUCK_OFFSET_PWM_CLR;
break;
default:
return -ENOTSUP;
}

ret = mfd_npm1300_reg_update(config->mfd, BUCK_BASE, BUCK_OFFSET_CTRL0, pfm_data, pfm_mask);
if (ret < 0) {
return ret;
}

return mfd_npm1300_reg_write(config->mfd, BUCK_BASE, pwm_reg + (chan * 2U), 1U);
}

static int set_ldsw_mode(const struct device *dev, uint8_t chan, regulator_mode_t mode)
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/dt-bindings/regulator/npm1300.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/* Buck modes */
#define NPM1300_BUCK_MODE_AUTO 0x00U
#define NPM1300_BUCK_MODE_PWM 0x01U
#define NPM1300_BUCK_MODE_PFM 0x04U

/* LDSW / LDO modes */
#define NPM1300_LDSW_MODE_LDO 0x02U
Expand Down

0 comments on commit 49ef9be

Please sign in to comment.