Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: regulator: max20335: add support for ship mode #67222

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions drivers/regulator/Kconfig.max20335
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@ config REGULATOR_MAX20335
help
Enable the Maxim MAX20335 PMIC regulator driver

if REGULATOR_MAX20335

config REGULATOR_MAXIM_MAX20335_COMMON_INIT_PRIORITY
int "MAX20335 regulator driver init priority (common part)"
default 86
help
Init priority for the Maxim MAX20335 regulator driver
(common part). It must be greater than I2C and MFD init priority.

config REGULATOR_MAXIM_MAX20335_INIT_PRIORITY
int "MAX20335 regulator driver init priority"
default 86
depends on REGULATOR_MAX20335
default 87
help
Init priority for the Maxim MAX20335 regulator driver.
Init priority for the Maxim MAX20335 regulator driver. It must be
greater than REGULATOR_MAXIM_MAX20335_COMMON_INIT_PRIORITY

endif
40 changes: 39 additions & 1 deletion drivers/regulator/regulator_max20335.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define MAX20335_BUCK2_CFG 0x0FU
#define MAX20335_BUCK2_VSET 0x10U
#define MAX20335_BUCK12_CSET 0x11U
#define MAX20335_PWR_CMD 0x1FU
#define MAX20335_BUCK1_CSET_MASK 0xF0U
#define MAX20335_BUCK2_CSET_MASK 0x0FU
#define MAX20335_BUCK2_CSET_SHIFT 4
Expand All @@ -32,6 +33,8 @@
#define MAX20335_LDO_EN BIT(1)
#define MAX20335_LDO_EN_MASK GENMASK(2, 1)

#define MAX20335_OFF_MODE 0xB2U

enum max20335_pmic_sources {
MAX20335_PMIC_SOURCE_BUCK1,
MAX20335_PMIC_SOURCE_BUCK2,
Expand All @@ -49,6 +52,10 @@ struct regulator_max20335_desc {
const struct linear_range *ua_range;
};

struct regulator_max20335_common_config {
struct i2c_dt_spec bus;
};

struct regulator_max20335_config {
struct regulator_common_config common;
struct i2c_dt_spec bus;
Expand Down Expand Up @@ -283,6 +290,13 @@ static int regulator_max20335_set_current_limit(const struct device *dev,
return i2c_reg_write_byte_dt(&config->bus, MAX20335_BUCK12_CSET, val);
}

static int regulator_max20335_power_off(const struct device *dev)
{
const struct regulator_max20335_common_config *common_config = dev->config;

return i2c_reg_write_byte_dt(&common_config->bus, MAX20335_PWR_CMD, MAX20335_OFF_MODE);
}

static int regulator_max20335_init(const struct device *dev)
{
const struct regulator_max20335_config *config = dev->config;
Expand All @@ -296,6 +310,21 @@ static int regulator_max20335_init(const struct device *dev)
return regulator_common_init(dev, false);
}

static int regulator_max20335_common_init(const struct device *dev)
{
const struct regulator_max20335_common_config *common_config = dev->config;

if (!i2c_is_ready_dt(&common_config->bus)) {
return -ENODEV;
}

return 0;
}

static const struct regulator_parent_driver_api parent_api = {
.ship_mode = regulator_max20335_power_off,
};

static const struct regulator_driver_api api = {
.enable = regulator_max20335_enable,
.disable = regulator_max20335_disable,
Expand Down Expand Up @@ -332,10 +361,19 @@ static const struct regulator_driver_api api = {
())

#define REGULATOR_MAX20335_DEFINE_ALL(inst) \
static const struct regulator_max20335_common_config common_config_##inst = { \
.bus = I2C_DT_SPEC_GET(DT_INST_PARENT(inst)), \
}; \
\
DEVICE_DT_INST_DEFINE(inst, regulator_max20335_common_init, \
NULL, NULL, &common_config_##inst, POST_KERNEL, \
CONFIG_REGULATOR_MAXIM_MAX20335_COMMON_INIT_PRIORITY, \
&parent_api); \
\
REGULATOR_MAX20335_DEFINE_COND(inst, buck1, MAX20335_PMIC_SOURCE_BUCK1) \
REGULATOR_MAX20335_DEFINE_COND(inst, buck2, MAX20335_PMIC_SOURCE_BUCK2) \
REGULATOR_MAX20335_DEFINE_COND(inst, ldo1, MAX20335_PMIC_SOURCE_LDO1) \
REGULATOR_MAX20335_DEFINE_COND(inst, ldo2, MAX20335_PMIC_SOURCE_LDO2) \
REGULATOR_MAX20335_DEFINE_COND(inst, ldo3, MAX20335_PMIC_SOURCE_LDO3)

DT_INST_FOREACH_STATUS_OKAY(REGULATOR_MAX20335_DEFINE_ALL);
DT_INST_FOREACH_STATUS_OKAY(REGULATOR_MAX20335_DEFINE_ALL)