diff --git a/drivers/regulator/Kconfig.max20335 b/drivers/regulator/Kconfig.max20335 index a9b739e1f2c9da..a92743afdb5367 100644 --- a/drivers/regulator/Kconfig.max20335 +++ b/drivers/regulator/Kconfig.max20335 @@ -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 diff --git a/drivers/regulator/regulator_max20335.c b/drivers/regulator/regulator_max20335.c index b94c0e0bb98da6..328e5179156ea4 100644 --- a/drivers/regulator/regulator_max20335.c +++ b/drivers/regulator/regulator_max20335.c @@ -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 @@ -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, @@ -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; @@ -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; @@ -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, @@ -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)