diff mbox series

[RFT,2/2] regulator: richtek,rt4801: use existing ena_gpiod feature

Message ID 20220401154237.1061331-3-krzysztof.kozlowski@linaro.org
State New
Headers show
Series [RFT,1/2] regulator: dt-bindings: richtek,rt4801: use existing ena_gpiod feature | expand

Commit Message

Krzysztof Kozlowski April 1, 2022, 3:42 p.m. UTC
The driver duplicated regulator core feature of controlling
regulators with GPIOs (of_parse_cb + ena_gpiod) and created its own
enable-gpios property with multiple GPIOs.

The core already does it. Keep old method for backwards compatibility.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/regulator/rt4801-regulator.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox series

Patch

diff --git a/drivers/regulator/rt4801-regulator.c b/drivers/regulator/rt4801-regulator.c
index 7a87788d3f09..9d88b7858a21 100644
--- a/drivers/regulator/rt4801-regulator.c
+++ b/drivers/regulator/rt4801-regulator.c
@@ -34,6 +34,28 @@  struct rt4801_priv {
 	unsigned int volt_sel[DSV_OUT_MAX];
 };
 
+static int rt4801_of_parse_cb(struct device_node *np,
+			      const struct regulator_desc *desc,
+			      struct regulator_config *config)
+{
+	struct rt4801_priv *priv = config->driver_data;
+
+	if (priv->enable_gpios) {
+		dev_warn(priv->dev, "duplicated enable-gpios property\n");
+		return 0;
+	}
+	config->ena_gpiod = fwnode_gpiod_get_index(of_fwnode_handle(np),
+						   "enable-gpios",
+						   0,
+						   GPIOD_OUT_HIGH |
+						   GPIOD_FLAGS_BIT_NONEXCLUSIVE,
+						   "rt4801");
+	if (IS_ERR(config->ena_gpiod))
+		config->ena_gpiod = NULL;
+
+	return 0;
+}
+
 static int rt4801_set_voltage_sel(struct regulator_dev *rdev, unsigned int selector)
 {
 	struct rt4801_priv *priv = rdev_get_drvdata(rdev);
@@ -122,6 +144,7 @@  static const struct regulator_desc rt4801_regulator_descs[] = {
 		.name = "DSVP",
 		.ops = &rt4801_regulator_ops,
 		.of_match = of_match_ptr("DSVP"),
+		.of_parse_cb = rt4801_of_parse_cb,
 		.type = REGULATOR_VOLTAGE,
 		.id = DSV_OUT_POS,
 		.min_uV = MIN_UV,
@@ -135,6 +158,7 @@  static const struct regulator_desc rt4801_regulator_descs[] = {
 		.name = "DSVN",
 		.ops = &rt4801_regulator_ops,
 		.of_match = of_match_ptr("DSVN"),
+		.of_parse_cb = rt4801_of_parse_cb,
 		.type = REGULATOR_VOLTAGE,
 		.id = DSV_OUT_NEG,
 		.min_uV = MIN_UV,