Skip to contentSkip to conversation

Use devm helpers for regulator get and enable

PATCH RESEND Superseded Matti Vaittinen 3 participants 6 messages Nov 16, 2022 – Nov 29, 2022

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v4 cover Use devm helpers for regulator get and enable

Simplify couple of drivers by using the new devm_regulator_*get_enable*()

Found these patches when doing some clean-up for my local git. Seems like these two fell through the cracks while other were merged. So, this is a respin of subset of original series v4.

These patches were previously part of the series:
https://lore.kernel.org/lkml/[email protected]/
"Devm helpers for regulator get and enable". I did keep the patch series versioning even though I changed the series name (subject of this mail) to "Use devm helpers for regulator get and enable". Name was changed because the devm helpers are already in 6.1-rc1.

Also, most of the patches in the series are already merged to subsystem trees so this series now contains only the patches that have not yet been merged. I hope they can be now directly taken sirectly into respective subsystem trees as the dependencies should be in v6.1-rc1.

Please note that these changes are only compile-tested as I don't have the HW to do proper testing. Thus, reviewing / testing is highly appreciated.

Revision history:

v3 => v4:
- Drop applied patches
- rewrite cover-letter
- rebase on v6.1-rc1
- split meson and sii902x into own patches as requested.
- slightly modify dev_err_probe() return in sii902x.

Matti Vaittinen (2):
gpu: drm: sii902x: Use devm_regulator_bulk_get_enable()
gpu: drm: meson: Use devm_regulator_*get_enable*()

 drivers/gpu/drm/bridge/sii902x.c      | 26 ++++----------------------
 drivers/gpu/drm/meson/meson_dw_hdmi.c | 23 +++--------------------
 2 files changed, 7 insertions(+), 42 deletions(-)

base-commit: 094226ad94f471a9f19e8f8e7140a09c2625abaa

Signature · 14 lines
2.38.1


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =] 
#1 lore raw

PATCH RESEND v4 1/2 gpu: drm: sii902x: Use devm_regulator_bulk_get_enable()

Simplify using devm_regulator_bulk_get_enable()

---
I am doing a clean-up for my local git and encountered this one. Respinning as it seems this one fell through the cracks.

---
 drivers/gpu/drm/bridge/sii902x.c | 26 ++++----------------------
 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/gpu/drm/bridge/sii902x.c +4 -22
index 878fb7d3732b..f6e8b401069b 100644
@@ -171,7 +171,6 @@ struct sii902x {
 	struct drm_connector connector;
 	struct gpio_desc *reset_gpio;
 	struct i2c_mux_core *i2cmux;
-	struct regulator_bulk_data supplies[2];
 	bool sink_is_hdmi;
 	/*
 	 * Mutex protects audio and video functions from interfering
@@ -1072,6 +1071,7 @@ static int sii902x_probe(struct i2c_client *client,
 	struct device *dev = &client->dev;
 	struct device_node *endpoint;
 	struct sii902x *sii902x;
+	static const char * const supplies[] = {"iovcc", "cvcc12"};
 	int ret;
 
 	ret = i2c_check_functionality(client->adapter,
@@ -1122,27 +1122,11 @@ static int sii902x_probe(struct i2c_client *client,
 
 	mutex_init(&sii902x->mutex);
 
-	sii902x->supplies[0].supply = "iovcc";
-	sii902x->supplies[1].supply = "cvcc12";
-	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(sii902x->supplies),
-				      sii902x->supplies);
+	ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(supplies), supplies);
 	if (ret < 0)
-		return ret;
-
-	ret = regulator_bulk_enable(ARRAY_SIZE(sii902x->supplies),
-				    sii902x->supplies);
-	if (ret < 0) {
-		dev_err_probe(dev, ret, "Failed to enable supplies");
-		return ret;
-	}
+		return dev_err_probe(dev, ret, "Failed to enable supplies");
 
-	ret = sii902x_init(sii902x);
-	if (ret < 0) {
-		regulator_bulk_disable(ARRAY_SIZE(sii902x->supplies),
-				       sii902x->supplies);
-	}
-
-	return ret;
+	return sii902x_init(sii902x);
 }
 
 static void sii902x_remove(struct i2c_client *client)
@@ -1152,8 +1136,6 @@ static void sii902x_remove(struct i2c_client *client)
 
 	i2c_mux_del_adapters(sii902x->i2cmux);
 	drm_bridge_remove(&sii902x->bridge);
-	regulator_bulk_disable(ARRAY_SIZE(sii902x->supplies),
-			       sii902x->supplies);
 }
 
 static const struct of_device_id sii902x_dt_ids[] = {
Signature · 14 lines
2.38.1


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =] 
#2 lore raw

Re: [PATCH RESEND v4 1/2] gpu: drm: sii902x: Use devm_regulator_bulk_get_enable()

Hey Matti,

Can you use an already used prefix for this commit title:
- drm/bridge: sii902x:

Quoted 88 lines · Matti Vaittinen

Simplify using devm_regulator_bulk_get_enable()

---
I am doing a clean-up for my local git and encountered this one. Respinning as it seems this one fell through the cracks.

---
 drivers/gpu/drm/bridge/sii902x.c | 26 ++++----------------------
 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/gpu/drm/bridge/sii902x.c +4 -23
index 878fb7d3732b..f6e8b401069b 100644
@@ -171,7 +171,6 @@ struct sii902x {
        struct drm_connector connector;
        struct gpio_desc *reset_gpio;
        struct i2c_mux_core *i2cmux;
-       struct regulator_bulk_data supplies[2];
        bool sink_is_hdmi;
        /*
         * Mutex protects audio and video functions from interfering
@@ -1072,6 +1071,7 @@ static int sii902x_probe(struct i2c_client *client,
        struct device *dev = &client->dev;
        struct device_node *endpoint;
        struct sii902x *sii902x;
+       static const char * const supplies[] = {"iovcc", "cvcc12"};
        int ret;
 
        ret = i2c_check_functionality(client->adapter,
@@ -1122,27 +1122,11 @@ static int sii902x_probe(struct i2c_client *client,
 
        mutex_init(&sii902x->mutex);
 
-       sii902x->supplies[0].supply = "iovcc";
-       sii902x->supplies[1].supply = "cvcc12";
-       ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(sii902x->supplies),
-                                     sii902x->supplies);
+       ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(supplies), supplies);
        if (ret < 0)
-               return ret;
-
-       ret = regulator_bulk_enable(ARRAY_SIZE(sii902x->supplies),
-                                   sii902x->supplies);
-       if (ret < 0) {
-               dev_err_probe(dev, ret, "Failed to enable supplies");
-               return ret;
-       }
+               return dev_err_probe(dev, ret, "Failed to enable supplies");
 
-       ret = sii902x_init(sii902x);
-       if (ret < 0) {
-               regulator_bulk_disable(ARRAY_SIZE(sii902x->supplies),
-                                      sii902x->supplies);
-       }
-
-       return ret;
+       return sii902x_init(sii902x);
 }
 
 static void sii902x_remove(struct i2c_client *client)
@@ -1152,8 +1136,6 @@ static void sii902x_remove(struct i2c_client *client)
 
        i2c_mux_del_adapters(sii902x->i2cmux);
        drm_bridge_remove(&sii902x->bridge);
-       regulator_bulk_disable(ARRAY_SIZE(sii902x->supplies),
-                              sii902x->supplies);
 }
 
 static const struct of_device_id sii902x_dt_ids[] = {
--

2.38.1

--
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~ Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~ Thanks to Simon Glass for the translation =]

#3 lore raw

PATCH RESEND v4 2/2 gpu: drm: meson: Use devm_regulator_*get_enable*()

In reply to Matti Vaittinen

Simplify using the devm_regulator_get_enable_optional(). Also drop the seemingly unused struct member 'hdmi_supply'.

---
I am doing a clean-up for my local git and encountered this one. Respinning as it seems this one fell through the cracks.

---
 drivers/gpu/drm/meson/meson_dw_hdmi.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)
drivers/gpu/drm/meson/meson_dw_hdmi.c +3 -20
index 5cd2b2ebbbd3..7642f740272b 100644
@@ -140,7 +140,6 @@ struct meson_dw_hdmi {
 	struct reset_control *hdmitx_apb;
 	struct reset_control *hdmitx_ctrl;
 	struct reset_control *hdmitx_phy;
-	struct regulator *hdmi_supply;
 	u32 irq_stat;
 	struct dw_hdmi *hdmi;
 	struct drm_bridge *bridge;
@@ -665,11 +664,6 @@ static void meson_dw_hdmi_init(struct meson_dw_hdmi *meson_dw_hdmi)
 
 }
 
-static void meson_disable_regulator(void *data)
-{
-	regulator_disable(data);
-}
-
 static void meson_disable_clk(void *data)
 {
 	clk_disable_unprepare(data);
@@ -723,20 +717,9 @@ static int meson_dw_hdmi_bind(struct device *dev, struct device *master,
 	meson_dw_hdmi->data = match;
 	dw_plat_data = &meson_dw_hdmi->dw_plat_data;
 
-	meson_dw_hdmi->hdmi_supply = devm_regulator_get_optional(dev, "hdmi");
-	if (IS_ERR(meson_dw_hdmi->hdmi_supply)) {
-		if (PTR_ERR(meson_dw_hdmi->hdmi_supply) == -EPROBE_DEFER)
-			return -EPROBE_DEFER;
-		meson_dw_hdmi->hdmi_supply = NULL;
-	} else {
-		ret = regulator_enable(meson_dw_hdmi->hdmi_supply);
-		if (ret)
-			return ret;
-		ret = devm_add_action_or_reset(dev, meson_disable_regulator,
-					       meson_dw_hdmi->hdmi_supply);
-		if (ret)
-			return ret;
-	}
+	ret = devm_regulator_get_enable_optional(dev, "hdmi");
+	if (ret != -ENODEV)
+		return ret;
 
 	meson_dw_hdmi->hdmitx_apb = devm_reset_control_get_exclusive(dev,
 						"hdmitx_apb");
Signature · 14 lines
2.38.1


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =] 
reviewer Acked-by on v4 2/2
#4 lore raw

Re: [PATCH RESEND v4 2/2] gpu: drm: meson: Use devm_regulator_*get_enable*()

Quoted 3 lines · Matti Vaittinen

Simplify using the devm_regulator_get_enable_optional(). Also drop the seemingly unused struct member 'hdmi_supply'.

Personally I'd replace "seemingly" with "now" because hdmi_supply was used before (although only in this one function, which makes it a bit pointless).
This is minor enough. So with or without that change this gets my:

#5 lore raw

Re: [PATCH RESEND v4 2/2] gpu: drm: meson: Use devm_regulator_*get_enable*()

In reply to Matti Vaittinen

The prefix to the commit title is a new one, let's use an existing one:
- drm/meson: dw-hdmi:
- drm: meson: dw-hdmi:

Quoted 76 lines · Matti Vaittinen

Simplify using the devm_regulator_get_enable_optional(). Also drop the seemingly unused struct member 'hdmi_supply'.

---
I am doing a clean-up for my local git and encountered this one. Respinning as it seems this one fell through the cracks.

---
 drivers/gpu/drm/meson/meson_dw_hdmi.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)
drivers/gpu/drm/meson/meson_dw_hdmi.c +3 -21
index 5cd2b2ebbbd3..7642f740272b 100644
@@ -140,7 +140,6 @@ struct meson_dw_hdmi {
        struct reset_control *hdmitx_apb;
        struct reset_control *hdmitx_ctrl;
        struct reset_control *hdmitx_phy;
-       struct regulator *hdmi_supply;
        u32 irq_stat;
        struct dw_hdmi *hdmi;
        struct drm_bridge *bridge;
@@ -665,11 +664,6 @@ static void meson_dw_hdmi_init(struct meson_dw_hdmi *meson_dw_hdmi)
 
 }
 
-static void meson_disable_regulator(void *data)
-{
-       regulator_disable(data);
-}
-
 static void meson_disable_clk(void *data)
 {
        clk_disable_unprepare(data);
@@ -723,20 +717,9 @@ static int meson_dw_hdmi_bind(struct device *dev, struct device *master,
        meson_dw_hdmi->data = match;
        dw_plat_data = &meson_dw_hdmi->dw_plat_data;
 
-       meson_dw_hdmi->hdmi_supply = devm_regulator_get_optional(dev, "hdmi");
-       if (IS_ERR(meson_dw_hdmi->hdmi_supply)) {
-               if (PTR_ERR(meson_dw_hdmi->hdmi_supply) == -EPROBE_DEFER)
-                       return -EPROBE_DEFER;
-               meson_dw_hdmi->hdmi_supply = NULL;
-       } else {
-               ret = regulator_enable(meson_dw_hdmi->hdmi_supply);
-               if (ret)
-                       return ret;
-               ret = devm_add_action_or_reset(dev, meson_disable_regulator,
-                                              meson_dw_hdmi->hdmi_supply);
-               if (ret)
-                       return ret;
-       }
+       ret = devm_regulator_get_enable_optional(dev, "hdmi");
+       if (ret != -ENODEV)
+               return ret;
 
        meson_dw_hdmi->hdmitx_apb = devm_reset_control_get_exclusive(dev,
                                                "hdmitx_apb");
--

2.38.1

--
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~ Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~ Thanks to Simon Glass for the translation =]