From 0042c880e43c54c9bf19c24a72e54eeea37995e3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Draszik?= Date: Thu, 22 Jan 2026 15:43:42 +0000 Subject: [PATCH] regulator: s2mps11: refactor handling of external rail control MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Refactor s2mps14_pmic_enable_ext_control() and s2mps11_of_parse_cb() slightly as a preparation for adding S2MPG10 and S2MPG11 support, as both of those PMICs also support control of rails via GPIOs. This also includes the following to avoid further updates in follow-up commits: * On S2MPG10 and S2MPG11, external rail control can be via GPIO or via non-GPIO signals, hence passing a GPIO is allowed to be optional. This avoids inappropriate verbose driver messages. * Prepare to allow use of standard DT property name 'enable-gpios' for newer platforms instead of vendor-specific 'samsung,ext-control'. Signed-off-by: André Draszik Link: https://patch.msgid.link/20260122-s2mpg1x-regulators-v7-15-3b1f9831fffd@linaro.org Signed-off-by: Mark Brown --- drivers/regulator/s2mps11.c | 100 ++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 33 deletions(-) diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c index 88e21c90832a..7f4db6673b43 100644 --- a/drivers/regulator/s2mps11.c +++ b/drivers/regulator/s2mps11.c @@ -328,29 +328,15 @@ static int s2mps11_regulator_set_suspend_disable(struct regulator_dev *rdev) rdev->desc->enable_mask, state); } -static int s2mps11_of_parse_cb(struct device_node *np, - const struct regulator_desc *desc, - struct regulator_config *config) +static int s2mps11_of_parse_gpiod(struct device_node *np, + const char *con_id, bool optional, + const struct regulator_desc *desc, + struct regulator_config *config) { - const struct s2mps11_info *s2mps11 = config->driver_data; struct gpio_desc *ena_gpiod; int ret; - if (s2mps11->dev_type == S2MPS14X) - switch (desc->id) { - case S2MPS14_LDO10: - case S2MPS14_LDO11: - case S2MPS14_LDO12: - break; - - default: - return 0; - } - else - return 0; - - ena_gpiod = fwnode_gpiod_get_index(of_fwnode_handle(np), - "samsung,ext-control", 0, + ena_gpiod = fwnode_gpiod_get_index(of_fwnode_handle(np), con_id, 0, GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE, "s2mps11-regulator"); @@ -361,14 +347,19 @@ static int s2mps11_of_parse_cb(struct device_node *np, if (ret == -EPROBE_DEFER) return ret; - if (ret == -ENOENT) + if (ret == -ENOENT) { + if (optional) + return 0; + dev_info(config->dev, "No entry for control GPIO for %d/%s in node %pOF\n", desc->id, desc->name, np); - else + } else { dev_warn_probe(config->dev, ret, "Failed to get control GPIO for %d/%s in node %pOF\n", desc->id, desc->name, np); + } + return 0; } @@ -380,6 +371,29 @@ static int s2mps11_of_parse_cb(struct device_node *np, return 0; } +static int s2mps11_of_parse_cb(struct device_node *np, + const struct regulator_desc *desc, + struct regulator_config *config) +{ + const struct s2mps11_info *s2mps11 = config->driver_data; + + if (s2mps11->dev_type == S2MPS14X) + switch (desc->id) { + case S2MPS14_LDO10: + case S2MPS14_LDO11: + case S2MPS14_LDO12: + break; + + default: + return 0; + } + else + return 0; + + return s2mps11_of_parse_gpiod(np, "samsung,ext-control", false, desc, + config); +} + static const struct regulator_ops s2mps11_ldo_ops = { .list_voltage = regulator_list_voltage_linear, .map_voltage = regulator_map_voltage_linear, @@ -903,10 +917,16 @@ static const struct regulator_desc s2mps15_regulators[] = { }; static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11, - struct regulator_dev *rdev) + struct regulator_dev *rdev) { - return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, - rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL); + int ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, + rdev->desc->enable_mask, + S2MPS14_ENABLE_EXT_CONTROL); + if (ret < 0) + return dev_err_probe(rdev_get_dev(rdev), ret, + "failed to enable GPIO control over %d/%s\n", + rdev->desc->id, rdev->desc->name); + return 0; } static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) @@ -1244,6 +1264,26 @@ static const struct regulator_desc s2mpu05_regulators[] = { regulator_desc_s2mpu05_buck45(5), }; +static int s2mps11_handle_ext_control(struct s2mps11_info *s2mps11, + struct regulator_dev *rdev) +{ + int ret; + + switch (s2mps11->dev_type) { + case S2MPS14X: + if (!rdev->ena_pin) + return 0; + + ret = s2mps14_pmic_enable_ext_control(s2mps11, rdev); + break; + + default: + return 0; + } + + return ret; +} + static int s2mps11_pmic_probe(struct platform_device *pdev) { struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); @@ -1314,15 +1354,9 @@ static int s2mps11_pmic_probe(struct platform_device *pdev) regulators[i].id, regulators[i].name); - if (regulator->ena_pin) { - ret = s2mps14_pmic_enable_ext_control(s2mps11, - regulator); - if (ret < 0) - return dev_err_probe(&pdev->dev, ret, - "failed to enable GPIO control over %d/%s\n", - regulator->desc->id, - regulator->desc->name); - } + ret = s2mps11_handle_ext_control(s2mps11, regulator); + if (ret < 0) + return ret; } return 0; -- 2.47.3