Skip to contentSkip to conversation

usb: ehci-exynos: Use devm_clk_get_enabled() helpers

PATCH Superseded Anand Moon 4 participants 25 messages Mar 1, 2024 – Apr 8, 2024 1 message not in the archive

Subsystems (6)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Anand Moon

author
#1 lore raw

PATCH 1/4 usb: ehci-exynos: Use devm_clk_get_enabled() helpers

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

While at it, use dev_err_probe consistently, and use its return value to return the error code.

---
 drivers/usb/host/ehci-exynos.c | 30 +++++-------------------------
 1 file changed, 5 insertions(+), 25 deletions(-)
drivers/usb/host/ehci-exynos.c +5 -25
index f644b131cc0b..05aa3d9c2a3b 100644
@@ -159,19 +159,12 @@ static int exynos_ehci_probe(struct platform_device *pdev)
 
 	err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci);
 	if (err)
-		goto fail_clk;
-
-	exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost");
-
-	if (IS_ERR(exynos_ehci->clk)) {
-		dev_err(&pdev->dev, "Failed to get usbhost clock\n");
-		err = PTR_ERR(exynos_ehci->clk);
-		goto fail_clk;
-	}
+		goto fail_io;
 
-	err = clk_prepare_enable(exynos_ehci->clk);
-	if (err)
-		goto fail_clk;
+	exynos_ehci->clk = devm_clk_get_enabled(&pdev->dev, "usbhost");
+	if (IS_ERR(exynos_ehci->clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(exynos_ehci->clk),
+				  "Failed to get usbhost clock\n");
 
 	hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
 	if (IS_ERR(hcd->regs)) {
@@ -223,8 +216,6 @@ static int exynos_ehci_probe(struct platform_device *pdev)
 	exynos_ehci_phy_disable(&pdev->dev);
 	pdev->dev.of_node = exynos_ehci->of_node;
 fail_io:
-	clk_disable_unprepare(exynos_ehci->clk);
-fail_clk:
 	usb_put_hcd(hcd);
 	return err;
 }
@@ -240,8 +231,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
 
 	exynos_ehci_phy_disable(&pdev->dev);
 
-	clk_disable_unprepare(exynos_ehci->clk);
-
 	usb_put_hcd(hcd);
 }
 
@@ -249,7 +238,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
 static int exynos_ehci_suspend(struct device *dev)
 {
 	struct usb_hcd *hcd = dev_get_drvdata(dev);
-	struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
 
 	bool do_wakeup = device_may_wakeup(dev);
 	int rc;
@@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev)
 
 	exynos_ehci_phy_disable(dev);
 
-	clk_disable_unprepare(exynos_ehci->clk);
-
 	return rc;
 }
 
 static int exynos_ehci_resume(struct device *dev)
 {
 	struct usb_hcd *hcd = dev_get_drvdata(dev);
-	struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
 	int ret;
 
-	ret = clk_prepare_enable(exynos_ehci->clk);
-	if (ret)
-		return ret;
-
 	ret = exynos_ehci_phy_enable(dev);
 	if (ret) {
 		dev_err(dev, "Failed to enable USB phy\n");
-		clk_disable_unprepare(exynos_ehci->clk);
 		return ret;
 	}
 
Signature · 1 line
2.43.0
maintainer
#2 lore raw
Quoted 31 lines · Anand Moon

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

While at it, use dev_err_probe consistently, and use its return value to return the error code.

---
 drivers/usb/host/ehci-exynos.c | 30 +++++-------------------------
 1 file changed, 5 insertions(+), 25 deletions(-)
drivers/usb/host/ehci-exynos.c +0 -8
index f644b131cc0b..05aa3d9c2a3b 100644
@@ -159,19 +159,12 @@ static int exynos_ehci_probe(struct platform_device *pdev)
 
 	err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci);
 	if (err)
-		goto fail_clk;
-
-	exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost");
-
-	if (IS_ERR(exynos_ehci->clk)) {
-		dev_err(&pdev->dev, "Failed to get usbhost clock\n");
-		err = PTR_ERR(exynos_ehci->clk);
-		goto fail_clk;

drivers/usb/host/ehci-exynos.c static int exynos_ehci_probe(struct platform_device *pdev) · line 167

Quoted 10 lines
drivers/usb/host/ehci-exynos.c +5 -4
-	}
+		goto fail_io;
 
-	err = clk_prepare_enable(exynos_ehci->clk);
-	if (err)
-		goto fail_clk;
+	exynos_ehci->clk = devm_clk_get_enabled(&pdev->dev, "usbhost");
+	if (IS_ERR(exynos_ehci->clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(exynos_ehci->clk),
+				  "Failed to get usbhost clock\n");

What about the usb_put_hcd(hcd) call that used to happen here?

Alan Stern

Quoted 58 lines
drivers/usb/host/ehci-exynos.c +0 -13
 	hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
 	if (IS_ERR(hcd->regs)) {
@@ -223,8 +216,6 @@ static int exynos_ehci_probe(struct platform_device *pdev)
 	exynos_ehci_phy_disable(&pdev->dev);
 	pdev->dev.of_node = exynos_ehci->of_node;
 fail_io:
-	clk_disable_unprepare(exynos_ehci->clk);
-fail_clk:
 	usb_put_hcd(hcd);
 	return err;
 }
@@ -240,8 +231,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
 
 	exynos_ehci_phy_disable(&pdev->dev);
 
-	clk_disable_unprepare(exynos_ehci->clk);
-
 	usb_put_hcd(hcd);
 }
 
@@ -249,7 +238,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
 static int exynos_ehci_suspend(struct device *dev)
 {
 	struct usb_hcd *hcd = dev_get_drvdata(dev);
-	struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
 
 	bool do_wakeup = device_may_wakeup(dev);
 	int rc;
@@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev)
 
 	exynos_ehci_phy_disable(dev);
 
-	clk_disable_unprepare(exynos_ehci->clk);
-
 	return rc;
 }
 
 static int exynos_ehci_resume(struct device *dev)
 {
 	struct usb_hcd *hcd = dev_get_drvdata(dev);
-	struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
 	int ret;
 
-	ret = clk_prepare_enable(exynos_ehci->clk);
-	if (ret)
-		return ret;
-
 	ret = exynos_ehci_phy_enable(dev);
 	if (ret) {
 		dev_err(dev, "Failed to enable USB phy\n");
-		clk_disable_unprepare(exynos_ehci->clk);
 		return ret;
 	}
 
Signature · 1 line
2.43.0
author
#3 lore raw

Hi Alan

Quoted 36 lines · Alan Stern
Quoted 34 lines · Anand Moon

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

While at it, use dev_err_probe consistently, and use its return value to return the error code.

---
 drivers/usb/host/ehci-exynos.c | 30 +++++-------------------------
 1 file changed, 5 insertions(+), 25 deletions(-)
drivers/usb/host/ehci-exynos.c +1 -9
index f644b131cc0b..05aa3d9c2a3b 100644
@@ -159,19 +159,12 @@ static int exynos_ehci_probe(struct platform_device *pdev)
 
      err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci);
      if (err)
-             goto fail_clk;
-
-     exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost");
-
-     if (IS_ERR(exynos_ehci->clk)) {
-             dev_err(&pdev->dev, "Failed to get usbhost clock\n");
-             err = PTR_ERR(exynos_ehci->clk);
-             goto fail_clk;
-     }
+             goto fail_io;
 
Quoted 10 lines

drivers/usb/host/ehci-exynos.c static int exynos_ehci_probe(struct platform_device *pdev) · line 167

Quoted 7 lines
drivers/usb/host/ehci-exynos.c +4 -3
-     err = clk_prepare_enable(exynos_ehci->clk);
-     if (err)
-             goto fail_clk;
+     exynos_ehci->clk = devm_clk_get_enabled(&pdev->dev, "usbhost");
+     if (IS_ERR(exynos_ehci->clk))
+             return dev_err_probe(&pdev->dev, PTR_ERR(exynos_ehci->clk),
+                               "Failed to get usbhost clock\n");

What about the usb_put_hcd(hcd) call that used to happen here?

Ok, I will update this in the next version.

Quoted 1 line

Alan Stern

Thanks

-Anand

#4 lore raw
In reply to Anand Moon

Le 01/03/2024 à 20:38, Anand Moon a écrit :

Quoted 71 lines

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

While at it, use dev_err_probe consistently, and use its return value to return the error code.

---
  drivers/usb/host/ehci-exynos.c | 30 +++++-------------------------
  1 file changed, 5 insertions(+), 25 deletions(-)
drivers/usb/host/ehci-exynos.c +5 -17
index f644b131cc0b..05aa3d9c2a3b 100644
@@ -159,19 +159,12 @@ static int exynos_ehci_probe(struct platform_device *pdev)
 
  	err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci);
  	if (err)
-		goto fail_clk;
-
-	exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost");
-
-	if (IS_ERR(exynos_ehci->clk)) {
-		dev_err(&pdev->dev, "Failed to get usbhost clock\n");
-		err = PTR_ERR(exynos_ehci->clk);
-		goto fail_clk;
-	}
+		goto fail_io;
 
-	err = clk_prepare_enable(exynos_ehci->clk);
-	if (err)
-		goto fail_clk;
+	exynos_ehci->clk = devm_clk_get_enabled(&pdev->dev, "usbhost");
+	if (IS_ERR(exynos_ehci->clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(exynos_ehci->clk),
+				  "Failed to get usbhost clock\n");
 
  	hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
  	if (IS_ERR(hcd->regs)) {
@@ -223,8 +216,6 @@ static int exynos_ehci_probe(struct platform_device *pdev)
  	exynos_ehci_phy_disable(&pdev->dev);
  	pdev->dev.of_node = exynos_ehci->of_node;
  fail_io:
-	clk_disable_unprepare(exynos_ehci->clk);
-fail_clk:
  	usb_put_hcd(hcd);
  	return err;
  }
@@ -240,8 +231,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
 
  	exynos_ehci_phy_disable(&pdev->dev);
 
-	clk_disable_unprepare(exynos_ehci->clk);
-
  	usb_put_hcd(hcd);
  }
 
@@ -249,7 +238,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
  static int exynos_ehci_suspend(struct device *dev)
  {
  	struct usb_hcd *hcd = dev_get_drvdata(dev);
-	struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
 
  	bool do_wakeup = device_may_wakeup(dev);
  	int rc;

drivers/usb/host/ehci-exynos.c static int exynos_ehci_suspend(struct device *dev) · line 263

Quoted 4 lines
drivers/usb/host/ehci-exynos.c +0 -1
@@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev)
 
  	exynos_ehci_phy_disable(dev);
 
-	clk_disable_unprepare(exynos_ehci->clk);

Hi,

I don't think that removing clk_[en|dis]abble from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Why did you removed it?

CJ

Quoted 21 lines
drivers/usb/host/ehci-exynos.c +0 -7
-
  	return rc;
  }
 
  static int exynos_ehci_resume(struct device *dev)
  {
  	struct usb_hcd *hcd = dev_get_drvdata(dev);
-	struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
  	int ret;
 
-	ret = clk_prepare_enable(exynos_ehci->clk);
-	if (ret)
-		return ret;
-
  	ret = exynos_ehci_phy_enable(dev);
  	if (ret) {
  		dev_err(dev, "Failed to enable USB phy\n");
-		clk_disable_unprepare(exynos_ehci->clk);
  		return ret;
  	}
 
author
#5 lore raw

Hi Christophe,

Quoted 80 lines · Christophe JAILLET
Quoted 71 lines · Anand Moon

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

While at it, use dev_err_probe consistently, and use its return value to return the error code.

---
  drivers/usb/host/ehci-exynos.c | 30 +++++-------------------------
  1 file changed, 5 insertions(+), 25 deletions(-)
drivers/usb/host/ehci-exynos.c +5 -17
index f644b131cc0b..05aa3d9c2a3b 100644
@@ -159,19 +159,12 @@ static int exynos_ehci_probe(struct platform_device *pdev)
 
      err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci);
      if (err)
-             goto fail_clk;
-
-     exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost");
-
-     if (IS_ERR(exynos_ehci->clk)) {
-             dev_err(&pdev->dev, "Failed to get usbhost clock\n");
-             err = PTR_ERR(exynos_ehci->clk);
-             goto fail_clk;
-     }
+             goto fail_io;
 
-     err = clk_prepare_enable(exynos_ehci->clk);
-     if (err)
-             goto fail_clk;
+     exynos_ehci->clk = devm_clk_get_enabled(&pdev->dev, "usbhost");
+     if (IS_ERR(exynos_ehci->clk))
+             return dev_err_probe(&pdev->dev, PTR_ERR(exynos_ehci->clk),
+                               "Failed to get usbhost clock\n");
 
      hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
      if (IS_ERR(hcd->regs)) {
@@ -223,8 +216,6 @@ static int exynos_ehci_probe(struct platform_device *pdev)
      exynos_ehci_phy_disable(&pdev->dev);
      pdev->dev.of_node = exynos_ehci->of_node;
  fail_io:
-     clk_disable_unprepare(exynos_ehci->clk);
-fail_clk:
      usb_put_hcd(hcd);
      return err;
  }
@@ -240,8 +231,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
 
      exynos_ehci_phy_disable(&pdev->dev);
 
-     clk_disable_unprepare(exynos_ehci->clk);
-
      usb_put_hcd(hcd);
  }
 
@@ -249,7 +238,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
  static int exynos_ehci_suspend(struct device *dev)
  {
      struct usb_hcd *hcd = dev_get_drvdata(dev);
-     struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
 
      bool do_wakeup = device_may_wakeup(dev);
      int rc;

drivers/usb/host/ehci-exynos.c static int exynos_ehci_suspend(struct device *dev) · line 263

Quoted 4 lines
drivers/usb/host/ehci-exynos.c +0 -1
@@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev)
 
      exynos_ehci_phy_disable(dev);
 
-     clk_disable_unprepare(exynos_ehci->clk);

Hi,

Quoted 5 lines

I don't think that removing clk_[en|dis]abble from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Yes correct,

Quoted 3 lines

Why did you removed it?

devm_clk_get_enabled function register callback for clk_prepare_enable and clk_disable_unprepare, so when the clock resource is not used it should get disabled.

[0] https://elixir.bootlin.com/linux/latest/source/drivers/clk/clk-devres.c#L75

I have also tested with rtc suspend & resume and did not find any issue.

Quoted 1 line

CJ

Thanks
-Anand

Quoted 23 lines
Quoted 22 lines
drivers/usb/host/ehci-exynos.c +0 -7
-
      return rc;
  }
 
  static int exynos_ehci_resume(struct device *dev)
  {
      struct usb_hcd *hcd = dev_get_drvdata(dev);
-     struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
      int ret;
 
-     ret = clk_prepare_enable(exynos_ehci->clk);
-     if (ret)
-             return ret;
-
      ret = exynos_ehci_phy_enable(dev);
      if (ret) {
              dev_err(dev, "Failed to enable USB phy\n");
-             clk_disable_unprepare(exynos_ehci->clk);
              return ret;
      }
 
#6 lore raw

Le 02/03/2024 à 17:35, Anand Moon a écrit :

Quoted 89 lines

Hi Christophe,

Quoted 80 lines · Christophe JAILLET
Quoted 71 lines · Anand Moon

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

While at it, use dev_err_probe consistently, and use its return value to return the error code.

---
   drivers/usb/host/ehci-exynos.c | 30 +++++-------------------------
   1 file changed, 5 insertions(+), 25 deletions(-)
drivers/usb/host/ehci-exynos.c +5 -17
index f644b131cc0b..05aa3d9c2a3b 100644
@@ -159,19 +159,12 @@ static int exynos_ehci_probe(struct platform_device *pdev)
 
       err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci);
       if (err)
-             goto fail_clk;
-
-     exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost");
-
-     if (IS_ERR(exynos_ehci->clk)) {
-             dev_err(&pdev->dev, "Failed to get usbhost clock\n");
-             err = PTR_ERR(exynos_ehci->clk);
-             goto fail_clk;
-     }
+             goto fail_io;
 
-     err = clk_prepare_enable(exynos_ehci->clk);
-     if (err)
-             goto fail_clk;
+     exynos_ehci->clk = devm_clk_get_enabled(&pdev->dev, "usbhost");
+     if (IS_ERR(exynos_ehci->clk))
+             return dev_err_probe(&pdev->dev, PTR_ERR(exynos_ehci->clk),
+                               "Failed to get usbhost clock\n");
 
       hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
       if (IS_ERR(hcd->regs)) {
@@ -223,8 +216,6 @@ static int exynos_ehci_probe(struct platform_device *pdev)
       exynos_ehci_phy_disable(&pdev->dev);
       pdev->dev.of_node = exynos_ehci->of_node;
   fail_io:
-     clk_disable_unprepare(exynos_ehci->clk);
-fail_clk:
       usb_put_hcd(hcd);
       return err;
   }
@@ -240,8 +231,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
 
       exynos_ehci_phy_disable(&pdev->dev);
 
-     clk_disable_unprepare(exynos_ehci->clk);
-
       usb_put_hcd(hcd);
   }
 
@@ -249,7 +238,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
   static int exynos_ehci_suspend(struct device *dev)
   {
       struct usb_hcd *hcd = dev_get_drvdata(dev);
-     struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
 
       bool do_wakeup = device_may_wakeup(dev);
       int rc;

drivers/usb/host/ehci-exynos.c static int exynos_ehci_suspend(struct device *dev) · line 263

Quoted 4 lines
drivers/usb/host/ehci-exynos.c +0 -1
@@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev)
 
       exynos_ehci_phy_disable(dev);
 
-     clk_disable_unprepare(exynos_ehci->clk);

Hi,

Quoted 5 lines

I don't think that removing clk_[en|dis]abble from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Quoted 8 lines

Yes correct,

Quoted 3 lines

Why did you removed it?

devm_clk_get_enabled function register callback for clk_prepare_enable and clk_disable_unprepare, so when the clock resource is not used it should get disabled.

Same explanation as in the other patch.

The registered function is called when the driver is *unloaded*, not when it magically knows that some things can be disabled or enabled.

CJ

Quoted 34 lines

[0] https://elixir.bootlin.com/linux/latest/source/drivers/clk/clk-devres.c#L75

I have also tested with rtc suspend & resume and did not find any issue.

Quoted 1 line

CJ

Thanks
-Anand

Quoted 23 lines
Quoted 22 lines
drivers/usb/host/ehci-exynos.c +0 -7
-
       return rc;
   }
 
   static int exynos_ehci_resume(struct device *dev)
   {
       struct usb_hcd *hcd = dev_get_drvdata(dev);
-     struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
       int ret;
 
-     ret = clk_prepare_enable(exynos_ehci->clk);
-     if (ret)
-             return ret;
-
       ret = exynos_ehci_phy_enable(dev);
       if (ret) {
               dev_err(dev, "Failed to enable USB phy\n");
-             clk_disable_unprepare(exynos_ehci->clk);
               return ret;
       }
 
#7 lore raw
In reply to Anand Moon

Le 02/03/2024 à 17:35, Anand Moon a écrit :

Quoted 89 lines

Hi Christophe,

Quoted 80 lines · Christophe JAILLET
Quoted 71 lines · Anand Moon

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

While at it, use dev_err_probe consistently, and use its return value to return the error code.

---
   drivers/usb/host/ehci-exynos.c | 30 +++++-------------------------
   1 file changed, 5 insertions(+), 25 deletions(-)
drivers/usb/host/ehci-exynos.c +5 -17
index f644b131cc0b..05aa3d9c2a3b 100644
@@ -159,19 +159,12 @@ static int exynos_ehci_probe(struct platform_device *pdev)
 
       err = exynos_ehci_get_phy(&pdev->dev, exynos_ehci);
       if (err)
-             goto fail_clk;
-
-     exynos_ehci->clk = devm_clk_get(&pdev->dev, "usbhost");
-
-     if (IS_ERR(exynos_ehci->clk)) {
-             dev_err(&pdev->dev, "Failed to get usbhost clock\n");
-             err = PTR_ERR(exynos_ehci->clk);
-             goto fail_clk;
-     }
+             goto fail_io;
 
-     err = clk_prepare_enable(exynos_ehci->clk);
-     if (err)
-             goto fail_clk;
+     exynos_ehci->clk = devm_clk_get_enabled(&pdev->dev, "usbhost");
+     if (IS_ERR(exynos_ehci->clk))
+             return dev_err_probe(&pdev->dev, PTR_ERR(exynos_ehci->clk),
+                               "Failed to get usbhost clock\n");
 
       hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
       if (IS_ERR(hcd->regs)) {
@@ -223,8 +216,6 @@ static int exynos_ehci_probe(struct platform_device *pdev)
       exynos_ehci_phy_disable(&pdev->dev);
       pdev->dev.of_node = exynos_ehci->of_node;
   fail_io:
-     clk_disable_unprepare(exynos_ehci->clk);
-fail_clk:
       usb_put_hcd(hcd);
       return err;
   }
@@ -240,8 +231,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
 
       exynos_ehci_phy_disable(&pdev->dev);
 
-     clk_disable_unprepare(exynos_ehci->clk);
-
       usb_put_hcd(hcd);
   }
 
@@ -249,7 +238,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
   static int exynos_ehci_suspend(struct device *dev)
   {
       struct usb_hcd *hcd = dev_get_drvdata(dev);
-     struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
 
       bool do_wakeup = device_may_wakeup(dev);
       int rc;

drivers/usb/host/ehci-exynos.c static int exynos_ehci_suspend(struct device *dev) · line 263

Quoted 4 lines
drivers/usb/host/ehci-exynos.c +0 -1
@@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev)
 
       exynos_ehci_phy_disable(dev);
 
-     clk_disable_unprepare(exynos_ehci->clk);

Hi,

Quoted 5 lines

I don't think that removing clk_[en|dis]abble from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Quoted 8 lines

Yes correct,

Quoted 3 lines

Why did you removed it?

devm_clk_get_enabled function register callback for clk_prepare_enable and clk_disable_unprepare, so when the clock resource is not used it should get disabled.

Same explanation as in the other patch.

The registered function is called when the driver is *unloaded*, not when it magically knows that some things can be disabled or enabled.

CJ

Quoted 34 lines

[0] https://elixir.bootlin.com/linux/latest/source/drivers/clk/clk-devres.c#L75

I have also tested with rtc suspend & resume and did not find any issue.

Quoted 1 line

CJ

Thanks
-Anand

Quoted 23 lines
Quoted 22 lines
drivers/usb/host/ehci-exynos.c +0 -7
-
       return rc;
   }
 
   static int exynos_ehci_resume(struct device *dev)
   {
       struct usb_hcd *hcd = dev_get_drvdata(dev);
-     struct exynos_ehci_hcd *exynos_ehci = to_exynos_ehci(hcd);
       int ret;
 
-     ret = clk_prepare_enable(exynos_ehci->clk);
-     if (ret)
-             return ret;
-
       ret = exynos_ehci_phy_enable(dev);
       if (ret) {
               dev_err(dev, "Failed to enable USB phy\n");
-             clk_disable_unprepare(exynos_ehci->clk);
               return ret;
       }
 
#8 lore raw
In reply to Anand Moon
Quoted 29 lines · Anand Moon
Quoted 16 lines · Christophe JAILLET
Quoted 14 lines · Anand Moon

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

While at it, use dev_err_probe consistently, and use its return value to return the error code.

drivers/usb/host/ehci-exynos.c +0 -0
@@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev)
 
      exynos_ehci_phy_disable(dev);
 
Quoted 7 lines

Review static int exynos_ehci_suspend(struct device *dev) · line 263

Quoted 1 line
(quoted diff) +0 -1
-     clk_disable_unprepare(exynos_ehci->clk);

I don't think that removing clk_[en|dis]abble from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Yes correct,

Quoted 2 lines

Why did you removed it?

Quoted 7 lines

devm_clk_get_enabled function register callback for clk_prepare_enable and clk_disable_unprepare, so when the clock resource is not used it should get disabled.

[0] https://elixir.bootlin.com/linux/latest/source/drivers/clk/clk-devres.c#L75

I have also tested with rtc suspend & resume and did not find any issue.

You seem to be totally confused about how devres works, and arguing back after Christophe points this out to you instead of going back and doing the homework you should have done before posting these patches is really not OK (e.g. as you're wasting other people's time).

And you clearly did not test these patches enough to confirm that you didn't break the driver.

Johan

author
#9 lore raw

Hi Johon, Christophe,

Quoted 35 lines · Johan Hovold
Quoted 33 lines · Anand Moon
Quoted 16 lines · Christophe JAILLET
Quoted 14 lines · Anand Moon

The devm_clk_get_enabled() helpers:
- call devm_clk_get()
- call clk_prepare_enable() and register what is needed in order to call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

While at it, use dev_err_probe consistently, and use its return value to return the error code.

drivers/usb/host/ehci-exynos.c +0 -0
@@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev)
 
      exynos_ehci_phy_disable(dev);
 
Quoted 7 lines

Review static int exynos_ehci_suspend(struct device *dev) · line 263

Quoted 1 line
(quoted diff) +0 -1
-     clk_disable_unprepare(exynos_ehci->clk);

I don't think that removing clk_[en|dis]abble from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Yes correct,

Quoted 2 lines

Why did you removed it?

devm_clk_get_enabled function register callback for clk_prepare_enable and clk_disable_unprepare, so when the clock resource is not used it should get disabled.

Quoted 9 lines
Quoted 3 lines

[0] https://elixir.bootlin.com/linux/latest/source/drivers/clk/clk-devres.c#L75

I have also tested with rtc suspend & resume and did not find any issue.

You seem to be totally confused about how devres works, and arguing back after Christophe points this out to you instead of going back and doing the homework you should have done before posting these patches is really not OK (e.g. as you're wasting other people's time).

Ok, It seems to have fallen short in my understanding..

Quoted 2 lines

And you clearly did not test these patches enough to confirm that you didn't break the driver.

Ok I missed the failure of the ehci driver. while testing.

[root@archl-xu4 alarm]# echo no > /sys/module/printk/parameters/console_suspend [root@archl-xu4 alarm]#
echo no > /sys/module/printk/parameters/console_suspend [root@archl-xu4 alarm]# echo no > /sys/module/printk/parameters/console_suspend [root@archl-xu4 alarm]# time rtcwake -s 30 -m mem
rtcwake: assuming RTC uses UTC ...
rtcwake: wakeup from "mem" using /dev/rtc0 at Mon Mar 4 09:44:25 2024

[11969.792928] PM: suspend entry (deep)
[11969.798423] Filesystems sync: 0.003 seconds
[11969.819722] Freezing user space processes
[11969.825818] Freezing user space processes completed (elapsed 0.003 seconds)
[11969.831585] OOM killer disabled.
[11969.834586] Freezing remaining freezable tasks
[11969.841553] Freezing remaining freezable tasks completed (elapsed
0.002 seconds)
[11969.919178] sd 0:0:0:0: [sda] Synchronizing SCSI cache
[11970.091681] wake enabled for irq 129 (gpx0-4)
[11970.135766] wake enabled for irq 149 (gpx0-3)
[11970.157943] samsung-pinctrl 13400000.pinctrl: Setting external
wakeup interrupt mask: 0xffffffe7
[11970.179304] Disabling non-boot CPUs ...
[11970.276394] s3c2410-wdt 101d0000.watchdog: watchdog disabled
[11970.281961] wake disabled for irq 149 (gpx0-3)
[11970.288997] phy phy-12130000.phy.6: phy_power_on was called before phy_init
[11970.358899] exynos-ohci 12120000.usb: init err (00000000 0000)
[11970.363298] exynos-ohci 12120000.usb: can't restart, -75
[11970.368581] usb usb2: root hub lost power or was reset
[11970.373819] wake disabled for irq 129 (gpx0-4)
[11970.382641] xhci-hcd xhci-hcd.8.auto: xHC error in resume, USBSTS
0x411, Reinit
[11970.383237] s3c-rtc 101e0000.rtc: rtc disabled, re-enabling
[11970.383355] xhci-hcd xhci-hcd.9.auto: xHC error in resume, USBSTS
0x401, Reinit
[11970.383376] usb usb5: root hub lost power or was reset
[11970.383396] usb usb6: root hub lost power or was reset
[11970.388471] usb usb3: root hub lost power or was reset
[11970.416740] usb usb4: root hub lost power or was reset
[11970.770122] usb 3-1: reset high-speed USB device number 2 using xhci-hcd
[11971.100601] usb 4-1: reset SuperSpeed USB device number 3 using xhci-hcd
[11971.569524] usb 3-1.2: reset high-speed USB device number 3 using xhci-hcd
[11974.575262] OOM killer enabled.
[11974.576964] Restarting tasks ... done.
[11974.580608] r8152-cfgselector 6-1: USB disconnect, device number 4
[11974.589302] random: crng reseeded on system resumption
[11974.596363] PM: suspend exit
real    0m34.951s
user    0m0.012s
sys     0m0.259s
[root@archl-xu4 alarm]# [11974.640778] mmc_host mmc0: Bus speed (slot
0) = 50000000Hz (slot req 400000Hz, actual 396825HZ div = 63)
[11975.180552] mmc_host mmc0: Bus speed (slot 0) = 50000000Hz (slot
req 52000000Hz, actual 50000000HZ div = 0)
[11975.192142] mmc_host mmc0: Bus speed (slot 0) = 200000000Hz (slot
req 200000000Hz, actual 200000000HZ div = 0)
[11975.282474] mmc_host mmc0: Bus speed (slot 0) = 50000000Hz (slot
req 52000000Hz, actual 50000000HZ div = 0)
[11975.296174] mmc_host mmc0: Bus speed (slot 0) = 400000000Hz (slot
req 200000000Hz, actual 200000000HZ div = 1)
[11975.569457] usb 6-1: new SuperSpeed USB device number 5 using xhci-hcd
[11975.614390] usb 6-1: New USB device found, idVendor=0bda,
idProduct=8153, bcdDevice=30.00
[11975.622196] usb 6-1: New USB device strings: Mfr=1, Product=2, SerialNumber=6
[11975.629284] usb 6-1: Product: USB 10/100/1000 LAN
[11975.633352] usb 6-1: Manufacturer: Realtek
[11975.637458] usb 6-1: SerialNumber: 000001000000
[11975.871080] r8152-cfgselector 6-1: reset SuperSpeed USB device
number 5 using xhci-hcd
[11975.955112] r8152 6-1:1.0: load rtl8153a-3 v2 02/07/20 successfully
[11976.032484] r8152 6-1:1.0 eth0: v1.12.13
[11976.134078] r8152 6-1:1.0 enu1: renamed from eth0

[root@archl-xu4 alarm]# [11981.522603] r8152 6-1:1.0 enu1: carrier on

[root@archl-xu4 alarm]#

Quoted 1 line

Ok, I will restore the clk changes in the suspend / resume functions in the next version and do thought testing.

Quoted 1 line

Johan

Thanks

-Anand

author
#10 lore raw

PATCH 2/4 usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr()

In reply to a message not in the archive

Use the new PM macros for the suspend and resume functions to be automatically dropped by the compiler when CONFIG_PM are disabled, without having to use #ifdef guards. If CONFIG_PM unused, they will simply be discarded by the compiler.

Use RUNTIME_PM_OPS runtime macro for suspend/resume function.

---
 drivers/usb/host/ehci-exynos.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/usb/host/ehci-exynos.c +2 -8
index 05aa3d9c2a3b..4676f45655cd 100644
@@ -234,7 +234,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
 	usb_put_hcd(hcd);
 }
 
-#ifdef CONFIG_PM
 static int exynos_ehci_suspend(struct device *dev)
 {
 	struct usb_hcd *hcd = dev_get_drvdata(dev);
@@ -268,14 +267,9 @@ static int exynos_ehci_resume(struct device *dev)
 	ehci_resume(hcd, false);
 	return 0;
 }
-#else
-#define exynos_ehci_suspend	NULL
-#define exynos_ehci_resume	NULL
-#endif
 
 static const struct dev_pm_ops exynos_ehci_pm_ops = {
-	.suspend	= exynos_ehci_suspend,
-	.resume		= exynos_ehci_resume,
+	RUNTIME_PM_OPS(exynos_ehci_suspend, exynos_ehci_resume, NULL)
 };
 
 #ifdef CONFIG_OF
@@ -292,7 +286,7 @@ static struct platform_driver exynos_ehci_driver = {
 	.shutdown	= usb_hcd_platform_shutdown,
 	.driver = {
 		.name	= "exynos-ehci",
-		.pm	= &exynos_ehci_pm_ops,
+		.pm	= pm_ptr(&exynos_ehci_pm_ops),
 		.of_match_table = of_match_ptr(exynos_ehci_match),
 	}
 };
Signature · 1 line
2.43.0
maintainer
#11 lore raw

Re: [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr()

Quoted 25 lines · Anand Moon

Use the new PM macros for the suspend and resume functions to be automatically dropped by the compiler when CONFIG_PM are disabled, without having to use #ifdef guards. If CONFIG_PM unused, they will simply be discarded by the compiler.

Use RUNTIME_PM_OPS runtime macro for suspend/resume function.

---
 drivers/usb/host/ehci-exynos.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/usb/host/ehci-exynos.c +0 -1
index 05aa3d9c2a3b..4676f45655cd 100644
@@ -234,7 +234,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
 	usb_put_hcd(hcd);
 }
 
-#ifdef CONFIG_PM
 static int exynos_ehci_suspend(struct device *dev)
 {
 	struct usb_hcd *hcd = dev_get_drvdata(dev);

drivers/usb/host/ehci-exynos.c static int exynos_ehci_resume(struct device *dev) · line 274

Quoted 7 lines
drivers/usb/host/ehci-exynos.c +0 -4
@@ -268,14 +267,9 @@ static int exynos_ehci_resume(struct device *dev)
 	ehci_resume(hcd, false);
 	return 0;
 }
-#else
-#define exynos_ehci_suspend	NULL
-#define exynos_ehci_resume	NULL
-#endif

Doesn't this now generate warnings about functions being defined but not used when you build with CONFIG_PM disabled?

Alan Stern

Quoted 20 lines
drivers/usb/host/ehci-exynos.c +2 -3
 static const struct dev_pm_ops exynos_ehci_pm_ops = {
-	.suspend	= exynos_ehci_suspend,
-	.resume		= exynos_ehci_resume,
+	RUNTIME_PM_OPS(exynos_ehci_suspend, exynos_ehci_resume, NULL)
 };
 
 #ifdef CONFIG_OF
@@ -292,7 +286,7 @@ static struct platform_driver exynos_ehci_driver = {
 	.shutdown	= usb_hcd_platform_shutdown,
 	.driver = {
 		.name	= "exynos-ehci",
-		.pm	= &exynos_ehci_pm_ops,
+		.pm	= pm_ptr(&exynos_ehci_pm_ops),
 		.of_match_table = of_match_ptr(exynos_ehci_match),
 	}
 };
Signature · 1 line
2.43.0
author
#12 lore raw

Re: [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr()

Hi Alan,

Quoted 22 lines · Alan Stern
Quoted 20 lines · Anand Moon

Use the new PM macros for the suspend and resume functions to be automatically dropped by the compiler when CONFIG_PM are disabled, without having to use #ifdef guards. If CONFIG_PM unused, they will simply be discarded by the compiler.

Use RUNTIME_PM_OPS runtime macro for suspend/resume function.

---
 drivers/usb/host/ehci-exynos.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/usb/host/ehci-exynos.c +0 -0
index 05aa3d9c2a3b..4676f45655cd 100644
@@ -234,7 +234,6 @@ static void exynos_ehci_remove(struct platform_device *pdev)
      usb_put_hcd(hcd);
 }
 
Quoted 16 lines

drivers/usb/host/ehci-exynos.c static int exynos_ehci_resume(struct device *dev) · line 274

Quoted 12 lines
drivers/usb/host/ehci-exynos.c +0 -5
-#ifdef CONFIG_PM
 static int exynos_ehci_suspend(struct device *dev)
 {
      struct usb_hcd *hcd = dev_get_drvdata(dev);
@@ -268,14 +267,9 @@ static int exynos_ehci_resume(struct device *dev)
      ehci_resume(hcd, false);
      return 0;
 }
-#else
-#define exynos_ehci_suspend  NULL
-#define exynos_ehci_resume   NULL
-#endif

Doesn't this now generate warnings about functions being defined but not used when you build with CONFIG_PM disabled?

Yes I have tried compile the kernel with disable CONFIG_PM=n and CONFIG_PM_SLEEP=n
But it's getting selected by default.

Also compiled with W=1 and found no warning with these patches. To be safe I will add __maybe_unused to suspend / resume functions in the next version.

(quoted diff) +0 -0

b/arch/arm/configs/exynos_defconfig
index c98d5ff8a1ed..e96f5c3bf8c1 100644

arch/arm/configs/exynos_defconfig +4 -2
@@ -29,8 +29,10 @@ CONFIG_ARM_EXYNOS_CPUIDLE=y
 CONFIG_VFP=y
 CONFIG_NEON=y
 CONFIG_KERNEL_MODE_NEON=y
-CONFIG_PM_DEBUG=y
-CONFIG_PM_ADVANCED_DEBUG=y
+# CONFIG_PM_SLEEP is not set
+# CONFIG_PM is not set
+# CONFIG_PM_DEBUG is not set
+# CONFIG_PM_ADVANCED_DEBUG is not set
 CONFIG_ENERGY_MODEL=y
 CONFIG_KALLSYMS_ALL=y
 CONFIG_MODULES=y
Quoted 1 line

Alan Stern

Thanks

-Anand

#13 lore raw

Re: [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr()

In reply to Anand Moon
Quoted 13 lines · Anand Moon

Use the new PM macros for the suspend and resume functions to be automatically dropped by the compiler when CONFIG_PM are disabled, without having to use #ifdef guards. If CONFIG_PM unused, they will simply be discarded by the compiler.

Use RUNTIME_PM_OPS runtime macro for suspend/resume function.

---
 drivers/usb/host/ehci-exynos.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

static const struct dev_pm_ops exynos_ehci_pm_ops = {

drivers/usb/host/ehci-exynos.c static int exynos_ehci_resume(struct device *dev) · line 273

Quoted 4 lines
drivers/usb/host/ehci-exynos.c +1 -2
-	.suspend	= exynos_ehci_suspend,
-	.resume		= exynos_ehci_resume,
+	RUNTIME_PM_OPS(exynos_ehci_suspend, exynos_ehci_resume, NULL)
 };

This is also broken and clearly not tested. See the definition of RUNTIME_PM_OPS() which sets the runtime pm callbacks, not the suspend ones:

	#define RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
		.runtime_suspend = suspend_fn, \
		.runtime_resume = resume_fn, \
		.runtime_idle = idle_fn,

Johan

author
#14 lore raw

Re: [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr()

Hi Johan,

Quoted 24 lines · Johan Hovold
Quoted 13 lines · Anand Moon

Use the new PM macros for the suspend and resume functions to be automatically dropped by the compiler when CONFIG_PM are disabled, without having to use #ifdef guards. If CONFIG_PM unused, they will simply be discarded by the compiler.

Use RUNTIME_PM_OPS runtime macro for suspend/resume function.

---
 drivers/usb/host/ehci-exynos.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

static const struct dev_pm_ops exynos_ehci_pm_ops = {

drivers/usb/host/ehci-exynos.c static int exynos_ehci_resume(struct device *dev) · line 273

Quoted 4 lines
drivers/usb/host/ehci-exynos.c +1 -2
-     .suspend        = exynos_ehci_suspend,
-     .resume         = exynos_ehci_resume,
+     RUNTIME_PM_OPS(exynos_ehci_suspend, exynos_ehci_resume, NULL)
 };

This is also broken and clearly not tested. See the definition of RUNTIME_PM_OPS() which sets the runtime pm callbacks, not the suspend ones:

Quoted 6 lines
        #define RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
                .runtime_suspend = suspend_fn, \
                .runtime_resume = resume_fn, \
                .runtime_idle = idle_fn,

Johan

Ok, I will drop these changes.

Thanks.
-Anand

author
#15 lore raw

PATCH 3/4 usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function

In reply to a message not in the archive

Use devm_regulator_bulk_get_enable() instead of open coded 'devm_regulator_get(), regulator_enable(), regulator_disable().

---
 drivers/usb/dwc3/dwc3-exynos.c | 49 +++-------------------------------
 1 file changed, 4 insertions(+), 45 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +4 -45
index 5d365ca51771..7c77f3c69825 100644
@@ -32,9 +32,6 @@ struct dwc3_exynos {
 	struct clk		*clks[DWC3_EXYNOS_MAX_CLOCKS];
 	int			num_clks;
 	int			suspend_clk_idx;
-
-	struct regulator	*vdd33;
-	struct regulator	*vdd10;
 };
 
 static int dwc3_exynos_probe(struct platform_device *pdev)
@@ -44,6 +41,7 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
 	struct device_node	*node = dev->of_node;
 	const struct dwc3_exynos_driverdata *driver_data;
 	int			i, ret;
+	static const char * const regulators[] = { "vdd33", "vdd10" };
 
 	exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
 	if (!exynos)
@@ -78,27 +76,9 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
 	if (exynos->suspend_clk_idx >= 0)
 		clk_prepare_enable(exynos->clks[exynos->suspend_clk_idx]);
 
-	exynos->vdd33 = devm_regulator_get(dev, "vdd33");
-	if (IS_ERR(exynos->vdd33)) {
-		ret = PTR_ERR(exynos->vdd33);
-		goto vdd33_err;
-	}
-	ret = regulator_enable(exynos->vdd33);
-	if (ret) {
-		dev_err(dev, "Failed to enable VDD33 supply\n");
-		goto vdd33_err;
-	}
-
-	exynos->vdd10 = devm_regulator_get(dev, "vdd10");
-	if (IS_ERR(exynos->vdd10)) {
-		ret = PTR_ERR(exynos->vdd10);
-		goto vdd10_err;
-	}
-	ret = regulator_enable(exynos->vdd10);
-	if (ret) {
-		dev_err(dev, "Failed to enable VDD10 supply\n");
-		goto vdd10_err;
-	}
+	ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), regulators);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to enable regulators\n");
 
 	if (node) {
 		ret = of_platform_populate(node, NULL, NULL, dev);
@@ -115,10 +95,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
 	return 0;
 
 populate_err:
-	regulator_disable(exynos->vdd10);
-vdd10_err:
-	regulator_disable(exynos->vdd33);
-vdd33_err:
 	for (i = exynos->num_clks - 1; i >= 0; i--)
 		clk_disable_unprepare(exynos->clks[i]);
 
@@ -140,9 +116,6 @@ static void dwc3_exynos_remove(struct platform_device *pdev)
 
 	if (exynos->suspend_clk_idx >= 0)
 		clk_disable_unprepare(exynos->clks[exynos->suspend_clk_idx]);
-
-	regulator_disable(exynos->vdd33);
-	regulator_disable(exynos->vdd10);
 }
 
 static const struct dwc3_exynos_driverdata exynos5250_drvdata = {
@@ -196,9 +169,6 @@ static int dwc3_exynos_suspend(struct device *dev)
 	for (i = exynos->num_clks - 1; i >= 0; i--)
 		clk_disable_unprepare(exynos->clks[i]);
 
-	regulator_disable(exynos->vdd33);
-	regulator_disable(exynos->vdd10);
-
 	return 0;
 }
 
@@ -207,17 +177,6 @@ static int dwc3_exynos_resume(struct device *dev)
 	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
 	int i, ret;
 
-	ret = regulator_enable(exynos->vdd33);
-	if (ret) {
-		dev_err(dev, "Failed to enable VDD33 supply\n");
-		return ret;
-	}
-	ret = regulator_enable(exynos->vdd10);
-	if (ret) {
-		dev_err(dev, "Failed to enable VDD10 supply\n");
-		return ret;
-	}
-
 	for (i = 0; i < exynos->num_clks; i++) {
 		ret = clk_prepare_enable(exynos->clks[i]);
 		if (ret) {
Signature · 1 line
2.43.0
#16 lore raw

Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function

Le 01/03/2024 à 20:38, Anand Moon a écrit :

Quoted 83 lines

Use devm_regulator_bulk_get_enable() instead of open coded 'devm_regulator_get(), regulator_enable(), regulator_disable().

---
  drivers/usb/dwc3/dwc3-exynos.c | 49 +++-------------------------------
  1 file changed, 4 insertions(+), 45 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +4 -31
index 5d365ca51771..7c77f3c69825 100644
@@ -32,9 +32,6 @@ struct dwc3_exynos {
  	struct clk		*clks[DWC3_EXYNOS_MAX_CLOCKS];
  	int			num_clks;
  	int			suspend_clk_idx;
-
-	struct regulator	*vdd33;
-	struct regulator	*vdd10;
  };
 
  static int dwc3_exynos_probe(struct platform_device *pdev)
@@ -44,6 +41,7 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
  	struct device_node	*node = dev->of_node;
  	const struct dwc3_exynos_driverdata *driver_data;
  	int			i, ret;
+	static const char * const regulators[] = { "vdd33", "vdd10" };
 
  	exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
  	if (!exynos)
@@ -78,27 +76,9 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
  	if (exynos->suspend_clk_idx >= 0)
  		clk_prepare_enable(exynos->clks[exynos->suspend_clk_idx]);
 
-	exynos->vdd33 = devm_regulator_get(dev, "vdd33");
-	if (IS_ERR(exynos->vdd33)) {
-		ret = PTR_ERR(exynos->vdd33);
-		goto vdd33_err;
-	}
-	ret = regulator_enable(exynos->vdd33);
-	if (ret) {
-		dev_err(dev, "Failed to enable VDD33 supply\n");
-		goto vdd33_err;
-	}
-
-	exynos->vdd10 = devm_regulator_get(dev, "vdd10");
-	if (IS_ERR(exynos->vdd10)) {
-		ret = PTR_ERR(exynos->vdd10);
-		goto vdd10_err;
-	}
-	ret = regulator_enable(exynos->vdd10);
-	if (ret) {
-		dev_err(dev, "Failed to enable VDD10 supply\n");
-		goto vdd10_err;
-	}
+	ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), regulators);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to enable regulators\n");
 
  	if (node) {
  		ret = of_platform_populate(node, NULL, NULL, dev);
@@ -115,10 +95,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
  	return 0;
 
  populate_err:
-	regulator_disable(exynos->vdd10);
-vdd10_err:
-	regulator_disable(exynos->vdd33);
-vdd33_err:
  	for (i = exynos->num_clks - 1; i >= 0; i--)
  		clk_disable_unprepare(exynos->clks[i]);
 
@@ -140,9 +116,6 @@ static void dwc3_exynos_remove(struct platform_device *pdev)
 
  	if (exynos->suspend_clk_idx >= 0)
  		clk_disable_unprepare(exynos->clks[exynos->suspend_clk_idx]);
-
-	regulator_disable(exynos->vdd33);
-	regulator_disable(exynos->vdd10);
  }
 
  static const struct dwc3_exynos_driverdata exynos5250_drvdata = {

drivers/usb/dwc3/dwc3-exynos.c static int dwc3_exynos_suspend(struct device *dev) · line 200

Quoted 5 lines
drivers/usb/dwc3/dwc3-exynos.c +0 -2
@@ -196,9 +169,6 @@ static int dwc3_exynos_suspend(struct device *dev)
  	for (i = exynos->num_clks - 1; i >= 0; i--)
  		clk_disable_unprepare(exynos->clks[i]);
 
-	regulator_disable(exynos->vdd33);
-	regulator_disable(exynos->vdd10);

Hi,

Same here, I don't think that removing regulator_[en|dis]able from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Why did you removed it?

CJ

Quoted 22 lines
drivers/usb/dwc3/dwc3-exynos.c +0 -12
-
  	return 0;
  }
 
@@ -207,17 +177,6 @@ static int dwc3_exynos_resume(struct device *dev)
  	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
  	int i, ret;
 
-	ret = regulator_enable(exynos->vdd33);
-	if (ret) {
-		dev_err(dev, "Failed to enable VDD33 supply\n");
-		return ret;
-	}
-	ret = regulator_enable(exynos->vdd10);
-	if (ret) {
-		dev_err(dev, "Failed to enable VDD10 supply\n");
-		return ret;
-	}
-
  	for (i = 0; i < exynos->num_clks; i++) {
  		ret = clk_prepare_enable(exynos->clks[i]);
  		if (ret) {
author
#17 lore raw

Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function

Hi Christophe,

Quoted 93 lines · Christophe JAILLET
Quoted 83 lines · Anand Moon

Use devm_regulator_bulk_get_enable() instead of open coded 'devm_regulator_get(), regulator_enable(), regulator_disable().

---
  drivers/usb/dwc3/dwc3-exynos.c | 49 +++-------------------------------
  1 file changed, 4 insertions(+), 45 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +4 -31
index 5d365ca51771..7c77f3c69825 100644
@@ -32,9 +32,6 @@ struct dwc3_exynos {
      struct clk              *clks[DWC3_EXYNOS_MAX_CLOCKS];
      int                     num_clks;
      int                     suspend_clk_idx;
-
-     struct regulator        *vdd33;
-     struct regulator        *vdd10;
  };
 
  static int dwc3_exynos_probe(struct platform_device *pdev)
@@ -44,6 +41,7 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
      struct device_node      *node = dev->of_node;
      const struct dwc3_exynos_driverdata *driver_data;
      int                     i, ret;
+     static const char * const regulators[] = { "vdd33", "vdd10" };
 
      exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
      if (!exynos)
@@ -78,27 +76,9 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
      if (exynos->suspend_clk_idx >= 0)
              clk_prepare_enable(exynos->clks[exynos->suspend_clk_idx]);
 
-     exynos->vdd33 = devm_regulator_get(dev, "vdd33");
-     if (IS_ERR(exynos->vdd33)) {
-             ret = PTR_ERR(exynos->vdd33);
-             goto vdd33_err;
-     }
-     ret = regulator_enable(exynos->vdd33);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD33 supply\n");
-             goto vdd33_err;
-     }
-
-     exynos->vdd10 = devm_regulator_get(dev, "vdd10");
-     if (IS_ERR(exynos->vdd10)) {
-             ret = PTR_ERR(exynos->vdd10);
-             goto vdd10_err;
-     }
-     ret = regulator_enable(exynos->vdd10);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD10 supply\n");
-             goto vdd10_err;
-     }
+     ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), regulators);
+     if (ret)
+             return dev_err_probe(dev, ret, "Failed to enable regulators\n");
 
      if (node) {
              ret = of_platform_populate(node, NULL, NULL, dev);
@@ -115,10 +95,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
      return 0;
 
  populate_err:
-     regulator_disable(exynos->vdd10);
-vdd10_err:
-     regulator_disable(exynos->vdd33);
-vdd33_err:
      for (i = exynos->num_clks - 1; i >= 0; i--)
              clk_disable_unprepare(exynos->clks[i]);
 
@@ -140,9 +116,6 @@ static void dwc3_exynos_remove(struct platform_device *pdev)
 
      if (exynos->suspend_clk_idx >= 0)
              clk_disable_unprepare(exynos->clks[exynos->suspend_clk_idx]);
-
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);
  }
 
  static const struct dwc3_exynos_driverdata exynos5250_drvdata = {

drivers/usb/dwc3/dwc3-exynos.c static int dwc3_exynos_suspend(struct device *dev) · line 200

Quoted 5 lines
drivers/usb/dwc3/dwc3-exynos.c +0 -2
@@ -196,9 +169,6 @@ static int dwc3_exynos_suspend(struct device *dev)
      for (i = exynos->num_clks - 1; i >= 0; i--)
              clk_disable_unprepare(exynos->clks[i]);
 
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);

Hi,

Quoted 5 lines

Same here, I don't think that removing regulator_[en|dis]able from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Ok,

Quoted 2 lines

Why did you removed it?

As per the description of the function devm_regulator_bulk_get_enable

* This helper function allows drivers to get several regulator
* consumers in one operation with management, the regulators will
* automatically be freed when the device is unbound. If any of the
* regulators cannot be acquired then any regulators that were
* allocated will be freed before returning to the caller.

[0] https://elixir.bootlin.com/linux/latest/source/drivers/regulator/devres.c#L330

I have tested with rtc suspend resume and did not find any issue with this.patch.

Quoted 3 lines

CJ

Thanks
-Anand

#18 lore raw

Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function

Le 02/03/2024 à 17:48, Anand Moon a écrit :

Quoted 106 lines

Hi Christophe,

Quoted 93 lines · Christophe JAILLET
Quoted 83 lines · Anand Moon

Use devm_regulator_bulk_get_enable() instead of open coded 'devm_regulator_get(), regulator_enable(), regulator_disable().

---
   drivers/usb/dwc3/dwc3-exynos.c | 49 +++-------------------------------
   1 file changed, 4 insertions(+), 45 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +4 -31
index 5d365ca51771..7c77f3c69825 100644
@@ -32,9 +32,6 @@ struct dwc3_exynos {
       struct clk              *clks[DWC3_EXYNOS_MAX_CLOCKS];
       int                     num_clks;
       int                     suspend_clk_idx;
-
-     struct regulator        *vdd33;
-     struct regulator        *vdd10;
   };
 
   static int dwc3_exynos_probe(struct platform_device *pdev)
@@ -44,6 +41,7 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
       struct device_node      *node = dev->of_node;
       const struct dwc3_exynos_driverdata *driver_data;
       int                     i, ret;
+     static const char * const regulators[] = { "vdd33", "vdd10" };
 
       exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
       if (!exynos)
@@ -78,27 +76,9 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
       if (exynos->suspend_clk_idx >= 0)
               clk_prepare_enable(exynos->clks[exynos->suspend_clk_idx]);
 
-     exynos->vdd33 = devm_regulator_get(dev, "vdd33");
-     if (IS_ERR(exynos->vdd33)) {
-             ret = PTR_ERR(exynos->vdd33);
-             goto vdd33_err;
-     }
-     ret = regulator_enable(exynos->vdd33);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD33 supply\n");
-             goto vdd33_err;
-     }
-
-     exynos->vdd10 = devm_regulator_get(dev, "vdd10");
-     if (IS_ERR(exynos->vdd10)) {
-             ret = PTR_ERR(exynos->vdd10);
-             goto vdd10_err;
-     }
-     ret = regulator_enable(exynos->vdd10);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD10 supply\n");
-             goto vdd10_err;
-     }
+     ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), regulators);
+     if (ret)
+             return dev_err_probe(dev, ret, "Failed to enable regulators\n");
 
       if (node) {
               ret = of_platform_populate(node, NULL, NULL, dev);
@@ -115,10 +95,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
       return 0;
 
   populate_err:
-     regulator_disable(exynos->vdd10);
-vdd10_err:
-     regulator_disable(exynos->vdd33);
-vdd33_err:
       for (i = exynos->num_clks - 1; i >= 0; i--)
               clk_disable_unprepare(exynos->clks[i]);
 
@@ -140,9 +116,6 @@ static void dwc3_exynos_remove(struct platform_device *pdev)
 
       if (exynos->suspend_clk_idx >= 0)
               clk_disable_unprepare(exynos->clks[exynos->suspend_clk_idx]);
-
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);
   }
 
   static const struct dwc3_exynos_driverdata exynos5250_drvdata = {

drivers/usb/dwc3/dwc3-exynos.c static int dwc3_exynos_suspend(struct device *dev) · line 200

Quoted 5 lines
drivers/usb/dwc3/dwc3-exynos.c +0 -2
@@ -196,9 +169,6 @@ static int dwc3_exynos_suspend(struct device *dev)
       for (i = exynos->num_clks - 1; i >= 0; i--)
               clk_disable_unprepare(exynos->clks[i]);
 
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);

Hi,

Quoted 5 lines

Same here, I don't think that removing regulator_[en|dis]able from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Ok,

Quoted 2 lines

Why did you removed it?

Quoted 7 lines

As per the description of the function devm_regulator_bulk_get_enable

* This helper function allows drivers to get several regulator
* consumers in one operation with management, the regulators will
* automatically be freed when the device is unbound. If any of the
* regulators cannot be acquired then any regulators that were
* allocated will be freed before returning to the caller.

The code in suspend/resume is not about freeing some resources. It is about enabling/disabling some hardware to save some power.

Think to the probe/remove functions as the software in the kernel that knows how to handle some hardawre, and the suspend/resume as the on/off button to power-on and off the electrical chips.

When the system is suspended, the software is still around. But some hardware can be set in a low consumption mode to save some power.

IMHO, part of the code you removed changed this behaviour and increase the power consumption when the system is suspended.

CJ

Quoted 13 lines

[0] https://elixir.bootlin.com/linux/latest/source/drivers/regulator/devres.c#L330

I have tested with rtc suspend resume and did not find any issue with this.patch.

Quoted 3 lines

CJ

Thanks
-Anand

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#19 lore raw

Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function

Hi Christophe,

Quoted 123 lines · Christophe JAILLET
Quoted 106 lines · Anand Moon

Hi Christophe,

Quoted 93 lines · Christophe JAILLET
Quoted 83 lines · Anand Moon

Use devm_regulator_bulk_get_enable() instead of open coded 'devm_regulator_get(), regulator_enable(), regulator_disable().

---
   drivers/usb/dwc3/dwc3-exynos.c | 49 +++-------------------------------
   1 file changed, 4 insertions(+), 45 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +4 -31
index 5d365ca51771..7c77f3c69825 100644
@@ -32,9 +32,6 @@ struct dwc3_exynos {
       struct clk              *clks[DWC3_EXYNOS_MAX_CLOCKS];
       int                     num_clks;
       int                     suspend_clk_idx;
-
-     struct regulator        *vdd33;
-     struct regulator        *vdd10;
   };
 
   static int dwc3_exynos_probe(struct platform_device *pdev)
@@ -44,6 +41,7 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
       struct device_node      *node = dev->of_node;
       const struct dwc3_exynos_driverdata *driver_data;
       int                     i, ret;
+     static const char * const regulators[] = { "vdd33", "vdd10" };
 
       exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
       if (!exynos)
@@ -78,27 +76,9 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
       if (exynos->suspend_clk_idx >= 0)
               clk_prepare_enable(exynos->clks[exynos->suspend_clk_idx]);
 
-     exynos->vdd33 = devm_regulator_get(dev, "vdd33");
-     if (IS_ERR(exynos->vdd33)) {
-             ret = PTR_ERR(exynos->vdd33);
-             goto vdd33_err;
-     }
-     ret = regulator_enable(exynos->vdd33);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD33 supply\n");
-             goto vdd33_err;
-     }
-
-     exynos->vdd10 = devm_regulator_get(dev, "vdd10");
-     if (IS_ERR(exynos->vdd10)) {
-             ret = PTR_ERR(exynos->vdd10);
-             goto vdd10_err;
-     }
-     ret = regulator_enable(exynos->vdd10);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD10 supply\n");
-             goto vdd10_err;
-     }
+     ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), regulators);
+     if (ret)
+             return dev_err_probe(dev, ret, "Failed to enable regulators\n");
 
       if (node) {
               ret = of_platform_populate(node, NULL, NULL, dev);
@@ -115,10 +95,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
       return 0;
 
   populate_err:
-     regulator_disable(exynos->vdd10);
-vdd10_err:
-     regulator_disable(exynos->vdd33);
-vdd33_err:
       for (i = exynos->num_clks - 1; i >= 0; i--)
               clk_disable_unprepare(exynos->clks[i]);
 
@@ -140,9 +116,6 @@ static void dwc3_exynos_remove(struct platform_device *pdev)
 
       if (exynos->suspend_clk_idx >= 0)
               clk_disable_unprepare(exynos->clks[exynos->suspend_clk_idx]);
-
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);
   }
 
   static const struct dwc3_exynos_driverdata exynos5250_drvdata = {

drivers/usb/dwc3/dwc3-exynos.c static int dwc3_exynos_suspend(struct device *dev) · line 200

Quoted 5 lines
drivers/usb/dwc3/dwc3-exynos.c +0 -2
@@ -196,9 +169,6 @@ static int dwc3_exynos_suspend(struct device *dev)
       for (i = exynos->num_clks - 1; i >= 0; i--)
               clk_disable_unprepare(exynos->clks[i]);
 
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);

Hi,

Quoted 5 lines

Same here, I don't think that removing regulator_[en|dis]able from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Ok,

Quoted 2 lines

Why did you removed it?

Quoted 7 lines

As per the description of the function devm_regulator_bulk_get_enable

* This helper function allows drivers to get several regulator
* consumers in one operation with management, the regulators will
* automatically be freed when the device is unbound. If any of the
* regulators cannot be acquired then any regulators that were
* allocated will be freed before returning to the caller.

The code in suspend/resume is not about freeing some resources. It is about enabling/disabling some hardware to save some power.

Think to the probe/remove functions as the software in the kernel that knows how to handle some hardawre, and the suspend/resume as the on/off button to power-on and off the electrical chips.

Quoted 6 lines

When the system is suspended, the software is still around. But some hardware can be set in a low consumption mode to save some power.

IMHO, part of the code you removed changed this behaviour and increase the power consumption when the system is suspended.

You are correct, I have changed the regulator API from devm_regulator_get_enable to devm_regulator_bulk_get_enable which changes this behavior.
I will fix it in the next version.

Quoted 1 line

CJ

Thanks
-Anand

author
#20 lore raw

Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function

Hi Christophe, Krzysztof,

Quoted 131 lines · Anand Moon

Hi Christophe,

Quoted 126 lines · Christophe JAILLET
Quoted 106 lines · Anand Moon

Hi Christophe,

Quoted 93 lines · Christophe JAILLET
Quoted 83 lines · Anand Moon

Use devm_regulator_bulk_get_enable() instead of open coded 'devm_regulator_get(), regulator_enable(), regulator_disable().

---
   drivers/usb/dwc3/dwc3-exynos.c | 49 +++-------------------------------
   1 file changed, 4 insertions(+), 45 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +4 -31
index 5d365ca51771..7c77f3c69825 100644
@@ -32,9 +32,6 @@ struct dwc3_exynos {
       struct clk              *clks[DWC3_EXYNOS_MAX_CLOCKS];
       int                     num_clks;
       int                     suspend_clk_idx;
-
-     struct regulator        *vdd33;
-     struct regulator        *vdd10;
   };
 
   static int dwc3_exynos_probe(struct platform_device *pdev)
@@ -44,6 +41,7 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
       struct device_node      *node = dev->of_node;
       const struct dwc3_exynos_driverdata *driver_data;
       int                     i, ret;
+     static const char * const regulators[] = { "vdd33", "vdd10" };
 
       exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
       if (!exynos)
@@ -78,27 +76,9 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
       if (exynos->suspend_clk_idx >= 0)
               clk_prepare_enable(exynos->clks[exynos->suspend_clk_idx]);
 
-     exynos->vdd33 = devm_regulator_get(dev, "vdd33");
-     if (IS_ERR(exynos->vdd33)) {
-             ret = PTR_ERR(exynos->vdd33);
-             goto vdd33_err;
-     }
-     ret = regulator_enable(exynos->vdd33);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD33 supply\n");
-             goto vdd33_err;
-     }
-
-     exynos->vdd10 = devm_regulator_get(dev, "vdd10");
-     if (IS_ERR(exynos->vdd10)) {
-             ret = PTR_ERR(exynos->vdd10);
-             goto vdd10_err;
-     }
-     ret = regulator_enable(exynos->vdd10);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD10 supply\n");
-             goto vdd10_err;
-     }
+     ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), regulators);
+     if (ret)
+             return dev_err_probe(dev, ret, "Failed to enable regulators\n");
 
       if (node) {
               ret = of_platform_populate(node, NULL, NULL, dev);
@@ -115,10 +95,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
       return 0;
 
   populate_err:
-     regulator_disable(exynos->vdd10);
-vdd10_err:
-     regulator_disable(exynos->vdd33);
-vdd33_err:
       for (i = exynos->num_clks - 1; i >= 0; i--)
               clk_disable_unprepare(exynos->clks[i]);
 
@@ -140,9 +116,6 @@ static void dwc3_exynos_remove(struct platform_device *pdev)
 
       if (exynos->suspend_clk_idx >= 0)
               clk_disable_unprepare(exynos->clks[exynos->suspend_clk_idx]);
-
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);
   }
 
   static const struct dwc3_exynos_driverdata exynos5250_drvdata = {

drivers/usb/dwc3/dwc3-exynos.c static int dwc3_exynos_suspend(struct device *dev) · line 200

Quoted 5 lines
drivers/usb/dwc3/dwc3-exynos.c +0 -2
@@ -196,9 +169,6 @@ static int dwc3_exynos_suspend(struct device *dev)
       for (i = exynos->num_clks - 1; i >= 0; i--)
               clk_disable_unprepare(exynos->clks[i]);
 
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);

Hi,

Quoted 5 lines

Same here, I don't think that removing regulator_[en|dis]able from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Ok,

Quoted 2 lines

Why did you removed it?

Quoted 7 lines

As per the description of the function devm_regulator_bulk_get_enable

* This helper function allows drivers to get several regulator
* consumers in one operation with management, the regulators will
* automatically be freed when the device is unbound. If any of the
* regulators cannot be acquired then any regulators that were
* allocated will be freed before returning to the caller.

The code in suspend/resume is not about freeing some resources. It is about enabling/disabling some hardware to save some power.

Think to the probe/remove functions as the software in the kernel that knows how to handle some hardawre, and the suspend/resume as the on/off button to power-on and off the electrical chips.

When the system is suspended, the software is still around. But some hardware can be set in a low consumption mode to save some power.

Quoted 10 lines
Quoted 3 lines

IMHO, part of the code you removed changed this behaviour and increase the power consumption when the system is suspended.

You are correct, I have changed the regulator API from devm_regulator_get_enable to devm_regulator_bulk_get_enable which changes this behavior.
I will fix it in the next version.

Quoted 1 line

CJ

I could not find any example in the kernel to support devm_regulator_bulk_disable
but here is my modified file.

If you have any suggestions for this plz let me know. -----8<----------8<----------

drivers/usb/dwc3/dwc3-exynos.c +2 -1
index 6d07592ad022..2f808cb9a006 100644
@@ -34,6 +34,8 @@ struct dwc3_exynos {
        int                     suspend_clk_idx;
 };
 
+static const char * const regulators[] = { "vdd33", "vdd10" };
+
 static int dwc3_exynos_probe(struct platform_device *pdev)
 {
        struct dwc3_exynos      *exynos;
@@ -41,7 +43,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
        struct device_node      *node = dev->of_node;
        const struct dwc3_exynos_driverdata *driver_data;
        int                     i, ret;
-       static const char * const regulators[] = { "vdd33", "vdd10" };
 
        exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
        if (!exynos)
@@ -166,6 +167,8 @@ static int __maybe_unused

dwc3_exynos_suspend(struct device *dev)

        struct dwc3_exynos *exynos = dev_get_drvdata(dev);
        int i;

+ devm_regulator_bulk_disable(dev);
+

        for (i = exynos->num_clks - 1; i >= 0; i--)
                clk_disable_unprepare(exynos->clks[i]);

@@ -177,6 +180,11 @@ static int __maybe_unused
dwc3_exynos_resume(struct device *dev)

        struct dwc3_exynos *exynos = dev_get_drvdata(dev);
        int i, ret;

+ ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators),
+ regulators);
+ if (ret)
+ dev_err(dev, "Failed to enable regulators\n");
+

        for (i = 0; i < exynos->num_clks; i++) {
                ret = clk_prepare_enable(exynos->clks[i]);
                if (ret) {

To support these changes we need to export the
devm_regulator_bulk_disable function.
-----8<----------8<----------

drivers/regulator/devres.c +0 -0
index 90bb0d178885..97eed739f929 100644
@@ -318,7 +318,7 @@ void devm_regulator_bulk_put(struct

regulator_bulk_data *consumers)
}
EXPORT_SYMBOL_GPL(devm_regulator_bulk_put);

-static void devm_regulator_bulk_disable(void *res) +void devm_regulator_bulk_disable(void *res)

 {
        struct regulator_bulk_devres *devres = res;
        int i;
@@ -326,6 +326,7 @@ static void devm_regulator_bulk_disable(void *res)
        for (i = 0; i < devres->num_consumers; i++)
                regulator_disable(devres->consumers[i].consumer);

}
+EXPORT_SYMBOL_GPL(devm_regulator_bulk_disable);

/**
* devm_regulator_bulk_get_enable - managed get'n enable multiple regulators

(quoted diff) +0 -0

b/include/linux/regulator/consumer.h
index 4660582a3302..ce7d28306b17 100644

include/linux/regulator/consumer.h +1 -0
@@ -214,6 +214,7 @@ int __must_check regulator_bulk_enable(int num_consumers,
                                       struct regulator_bulk_data *consumers);
 int devm_regulator_bulk_get_enable(struct device *dev, int num_consumers,
                                   const char * const *id);
+void devm_regulator_bulk_disable(void *res);
 int regulator_bulk_disable(int num_consumers,
                           struct regulator_bulk_data *consumers);
 int regulator_bulk_force_disable(int num_consumers,

--------------------------------------------------------------------------

Thanks
-Anand

#21 lore raw

Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function

Le 05/04/2024 à 08:10, Anand Moon a écrit :

Quoted 143 lines

Hi Christophe, Krzysztof,

Quoted 140 lines · Anand Moon

Hi Christophe,

Quoted 123 lines · Christophe JAILLET
Quoted 106 lines · Anand Moon

Hi Christophe,

Quoted 93 lines · Christophe JAILLET
Quoted 83 lines · Anand Moon

Use devm_regulator_bulk_get_enable() instead of open coded 'devm_regulator_get(), regulator_enable(), regulator_disable().

---
    drivers/usb/dwc3/dwc3-exynos.c | 49 +++-------------------------------
    1 file changed, 4 insertions(+), 45 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +4 -31
index 5d365ca51771..7c77f3c69825 100644
@@ -32,9 +32,6 @@ struct dwc3_exynos {
        struct clk              *clks[DWC3_EXYNOS_MAX_CLOCKS];
        int                     num_clks;
        int                     suspend_clk_idx;
-
-     struct regulator        *vdd33;
-     struct regulator        *vdd10;
    };
 
    static int dwc3_exynos_probe(struct platform_device *pdev)
@@ -44,6 +41,7 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
        struct device_node      *node = dev->of_node;
        const struct dwc3_exynos_driverdata *driver_data;
        int                     i, ret;
+     static const char * const regulators[] = { "vdd33", "vdd10" };
 
        exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
        if (!exynos)
@@ -78,27 +76,9 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
        if (exynos->suspend_clk_idx >= 0)
                clk_prepare_enable(exynos->clks[exynos->suspend_clk_idx]);
 
-     exynos->vdd33 = devm_regulator_get(dev, "vdd33");
-     if (IS_ERR(exynos->vdd33)) {
-             ret = PTR_ERR(exynos->vdd33);
-             goto vdd33_err;
-     }
-     ret = regulator_enable(exynos->vdd33);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD33 supply\n");
-             goto vdd33_err;
-     }
-
-     exynos->vdd10 = devm_regulator_get(dev, "vdd10");
-     if (IS_ERR(exynos->vdd10)) {
-             ret = PTR_ERR(exynos->vdd10);
-             goto vdd10_err;
-     }
-     ret = regulator_enable(exynos->vdd10);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD10 supply\n");
-             goto vdd10_err;
-     }
+     ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), regulators);
+     if (ret)
+             return dev_err_probe(dev, ret, "Failed to enable regulators\n");
 
        if (node) {
                ret = of_platform_populate(node, NULL, NULL, dev);
@@ -115,10 +95,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
        return 0;
 
    populate_err:
-     regulator_disable(exynos->vdd10);
-vdd10_err:
-     regulator_disable(exynos->vdd33);
-vdd33_err:
        for (i = exynos->num_clks - 1; i >= 0; i--)
                clk_disable_unprepare(exynos->clks[i]);
 
@@ -140,9 +116,6 @@ static void dwc3_exynos_remove(struct platform_device *pdev)
 
        if (exynos->suspend_clk_idx >= 0)
                clk_disable_unprepare(exynos->clks[exynos->suspend_clk_idx]);
-
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);
    }
 
    static const struct dwc3_exynos_driverdata exynos5250_drvdata = {

drivers/usb/dwc3/dwc3-exynos.c static int dwc3_exynos_suspend(struct device *dev) · line 200

Quoted 5 lines
drivers/usb/dwc3/dwc3-exynos.c +0 -2
@@ -196,9 +169,6 @@ static int dwc3_exynos_suspend(struct device *dev)
        for (i = exynos->num_clks - 1; i >= 0; i--)
                clk_disable_unprepare(exynos->clks[i]);
 
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);

Hi,

Quoted 5 lines

Same here, I don't think that removing regulator_[en|dis]able from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Ok,

Quoted 2 lines

Why did you removed it?

Quoted 7 lines

As per the description of the function devm_regulator_bulk_get_enable

* This helper function allows drivers to get several regulator
* consumers in one operation with management, the regulators will
* automatically be freed when the device is unbound. If any of the
* regulators cannot be acquired then any regulators that were
* allocated will be freed before returning to the caller.

The code in suspend/resume is not about freeing some resources. It is about enabling/disabling some hardware to save some power.

Think to the probe/remove functions as the software in the kernel that knows how to handle some hardawre, and the suspend/resume as the on/off button to power-on and off the electrical chips.

Quoted 6 lines

When the system is suspended, the software is still around. But some hardware can be set in a low consumption mode to save some power.

IMHO, part of the code you removed changed this behaviour and increase the power consumption when the system is suspended.

You are correct, I have changed the regulator API from devm_regulator_get_enable to devm_regulator_bulk_get_enable which changes this behavior.
I will fix it in the next version.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

CJ

I could not find any example in the kernel to support devm_regulator_bulk_disable
but here is my modified file.

If you have any suggestions for this plz let me know.

I don't think that your approach is correct, and I don't think that the proposed patch does what you expect it to do.

Calling a devm_ function in suspend/resume functions looks really strange to me and is likely broken.

Especially here, devm_regulator_bulk_get_enable() in the resume function allocates some memory that is not freed in devm_regulator_bulk_disable(), because the API is not designed to work like that. So this could generate a kind of memory leak.

*I think that the code is good enough as-is*, but if you really want to change something, maybe:
- devm_regulator_get()+regulator_enable() in the probe could be
changed to devm_regulator_get_enable()
- the resume/suspend function should be left as-is with
regulator_disable()/regulator_ensable()
- remove regulator_disable() from the error handling path of the
probe and from the remove function.

I *think* it would work.

CJ

Quoted 86 lines

-----8<----------8<----------

drivers/usb/dwc3/dwc3-exynos.c +9 -1
index 6d07592ad022..2f808cb9a006 100644
@@ -34,6 +34,8 @@ struct dwc3_exynos {
         int                     suspend_clk_idx;
  };
 
+static const char * const regulators[] = { "vdd33", "vdd10" };
+
  static int dwc3_exynos_probe(struct platform_device *pdev)
  {
         struct dwc3_exynos      *exynos;
@@ -41,7 +43,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
         struct device_node      *node = dev->of_node;
         const struct dwc3_exynos_driverdata *driver_data;
         int                     i, ret;
-       static const char * const regulators[] = { "vdd33", "vdd10" };
 
         exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
         if (!exynos)
@@ -166,6 +167,8 @@ static int __maybe_unused
 dwc3_exynos_suspend(struct device *dev)
         struct dwc3_exynos *exynos = dev_get_drvdata(dev);
         int i;
 
+       devm_regulator_bulk_disable(dev);
+
         for (i = exynos->num_clks - 1; i >= 0; i--)
                 clk_disable_unprepare(exynos->clks[i]);
@@ -177,6 +180,11 @@ static int __maybe_unused
 dwc3_exynos_resume(struct device *dev)
         struct dwc3_exynos *exynos = dev_get_drvdata(dev);
         int i, ret;
 
+       ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators),
+                                               regulators);
+       if (ret)
+               dev_err(dev, "Failed to enable regulators\n");
+
         for (i = 0; i < exynos->num_clks; i++) {
                 ret = clk_prepare_enable(exynos->clks[i]);
                 if (ret) {

To support these changes we need to export the
devm_regulator_bulk_disable function.
-----8<----------8<----------

drivers/regulator/devres.c +1 -1
index 90bb0d178885..97eed739f929 100644
@@ -318,7 +318,7 @@ void devm_regulator_bulk_put(struct
 regulator_bulk_data *consumers)
  }
  EXPORT_SYMBOL_GPL(devm_regulator_bulk_put);
 
-static void devm_regulator_bulk_disable(void *res)
+void devm_regulator_bulk_disable(void *res)
  {
         struct regulator_bulk_devres *devres = res;
         int i;
drivers/regulator/devres.c +1 -0
@@ -326,6 +326,7 @@ static void devm_regulator_bulk_disable(void *res)
         for (i = 0; i < devres->num_consumers; i++)
                 regulator_disable(devres->consumers[i].consumer);
  }
+EXPORT_SYMBOL_GPL(devm_regulator_bulk_disable);
 
  /**
   * devm_regulator_bulk_get_enable - managed get'n enable multiple regulators
include/linux/regulator/consumer.h +1 -1
index 4660582a3302..ce7d28306b17 100644
@@ -214,6 +214,7 @@ int __must_check regulator_bulk_enable(int num_consumers,
                                        struct regulator_bulk_data *consumers);
  int devm_regulator_bulk_get_enable(struct device *dev, int num_consumers,
                                    const char * const *id);
+void devm_regulator_bulk_disable(void *res);
  int regulator_bulk_disable(int num_consumers,
                            struct regulator_bulk_data *consumers);
  int regulator_bulk_force_disable(int num_consumers,
--------------------------------------------------------------------------
Quoted 4 lines

Thanks
-Anand

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#22 lore raw

Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function

Hi Christophe

Quoted 174 lines · Christophe JAILLET
Quoted 143 lines · Anand Moon

Hi Christophe, Krzysztof,

Quoted 140 lines · Anand Moon

Hi Christophe,

Quoted 123 lines · Christophe JAILLET
Quoted 106 lines · Anand Moon

Hi Christophe,

Quoted 93 lines · Christophe JAILLET
Quoted 83 lines · Anand Moon

Use devm_regulator_bulk_get_enable() instead of open coded 'devm_regulator_get(), regulator_enable(), regulator_disable().

---
    drivers/usb/dwc3/dwc3-exynos.c | 49 +++-------------------------------
    1 file changed, 4 insertions(+), 45 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +4 -31
index 5d365ca51771..7c77f3c69825 100644
@@ -32,9 +32,6 @@ struct dwc3_exynos {
        struct clk              *clks[DWC3_EXYNOS_MAX_CLOCKS];
        int                     num_clks;
        int                     suspend_clk_idx;
-
-     struct regulator        *vdd33;
-     struct regulator        *vdd10;
    };
 
    static int dwc3_exynos_probe(struct platform_device *pdev)
@@ -44,6 +41,7 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
        struct device_node      *node = dev->of_node;
        const struct dwc3_exynos_driverdata *driver_data;
        int                     i, ret;
+     static const char * const regulators[] = { "vdd33", "vdd10" };
 
        exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
        if (!exynos)
@@ -78,27 +76,9 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
        if (exynos->suspend_clk_idx >= 0)
                clk_prepare_enable(exynos->clks[exynos->suspend_clk_idx]);
 
-     exynos->vdd33 = devm_regulator_get(dev, "vdd33");
-     if (IS_ERR(exynos->vdd33)) {
-             ret = PTR_ERR(exynos->vdd33);
-             goto vdd33_err;
-     }
-     ret = regulator_enable(exynos->vdd33);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD33 supply\n");
-             goto vdd33_err;
-     }
-
-     exynos->vdd10 = devm_regulator_get(dev, "vdd10");
-     if (IS_ERR(exynos->vdd10)) {
-             ret = PTR_ERR(exynos->vdd10);
-             goto vdd10_err;
-     }
-     ret = regulator_enable(exynos->vdd10);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD10 supply\n");
-             goto vdd10_err;
-     }
+     ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), regulators);
+     if (ret)
+             return dev_err_probe(dev, ret, "Failed to enable regulators\n");
 
        if (node) {
                ret = of_platform_populate(node, NULL, NULL, dev);
@@ -115,10 +95,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
        return 0;
 
    populate_err:
-     regulator_disable(exynos->vdd10);
-vdd10_err:
-     regulator_disable(exynos->vdd33);
-vdd33_err:
        for (i = exynos->num_clks - 1; i >= 0; i--)
                clk_disable_unprepare(exynos->clks[i]);
 
@@ -140,9 +116,6 @@ static void dwc3_exynos_remove(struct platform_device *pdev)
 
        if (exynos->suspend_clk_idx >= 0)
                clk_disable_unprepare(exynos->clks[exynos->suspend_clk_idx]);
-
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);
    }
 
    static const struct dwc3_exynos_driverdata exynos5250_drvdata = {

drivers/usb/dwc3/dwc3-exynos.c static int dwc3_exynos_suspend(struct device *dev) · line 200

Quoted 5 lines
drivers/usb/dwc3/dwc3-exynos.c +0 -2
@@ -196,9 +169,6 @@ static int dwc3_exynos_suspend(struct device *dev)
        for (i = exynos->num_clks - 1; i >= 0; i--)
                clk_disable_unprepare(exynos->clks[i]);
 
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);

Hi,

Quoted 5 lines

Same here, I don't think that removing regulator_[en|dis]able from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Ok,

Quoted 2 lines

Why did you removed it?

Quoted 7 lines

As per the description of the function devm_regulator_bulk_get_enable

* This helper function allows drivers to get several regulator
* consumers in one operation with management, the regulators will
* automatically be freed when the device is unbound. If any of the
* regulators cannot be acquired then any regulators that were
* allocated will be freed before returning to the caller.

The code in suspend/resume is not about freeing some resources. It is about enabling/disabling some hardware to save some power.

Think to the probe/remove functions as the software in the kernel that knows how to handle some hardawre, and the suspend/resume as the on/off button to power-on and off the electrical chips.

Quoted 6 lines

When the system is suspended, the software is still around. But some hardware can be set in a low consumption mode to save some power.

IMHO, part of the code you removed changed this behaviour and increase the power consumption when the system is suspended.

You are correct, I have changed the regulator API from devm_regulator_get_enable to devm_regulator_bulk_get_enable which changes this behavior.
I will fix it in the next version.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

CJ

I could not find any example in the kernel to support devm_regulator_bulk_disable
but here is my modified file.

If you have any suggestions for this plz let me know.

I don't think that your approach is correct, and I don't think that the proposed patch does what you expect it to do.

Calling a devm_ function in suspend/resume functions looks really strange to me and is likely broken.

Especially here, devm_regulator_bulk_get_enable() in the resume function allocates some memory that is not freed in devm_regulator_bulk_disable(), because the API is not designed to work like that. So this could generate a kind of memory leak.

*I think that the code is good enough as-is*, but if you really want to change something, maybe:
- devm_regulator_get()+regulator_enable() in the probe could be
changed to devm_regulator_get_enable()
- the resume/suspend function should be left as-is with
regulator_disable()/regulator_ensable()
- remove regulator_disable() from the error handling path of the
probe and from the remove function.

Quoted 2 lines

I *think* it would work.

Thanks OK, I will test this and update in the next version. .

Quoted 1 line

CJ

Thanks
-Anand

author
#23 lore raw

Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function

In reply to Christophe JAILLET

Hi Christophe,

Quoted 174 lines · Christophe JAILLET
Quoted 143 lines · Anand Moon

Hi Christophe, Krzysztof,

Quoted 140 lines · Anand Moon

Hi Christophe,

Quoted 123 lines · Christophe JAILLET
Quoted 106 lines · Anand Moon

Hi Christophe,

Quoted 93 lines · Christophe JAILLET
Quoted 83 lines · Anand Moon

Use devm_regulator_bulk_get_enable() instead of open coded 'devm_regulator_get(), regulator_enable(), regulator_disable().

---
    drivers/usb/dwc3/dwc3-exynos.c | 49 +++-------------------------------
    1 file changed, 4 insertions(+), 45 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +4 -31
index 5d365ca51771..7c77f3c69825 100644
@@ -32,9 +32,6 @@ struct dwc3_exynos {
        struct clk              *clks[DWC3_EXYNOS_MAX_CLOCKS];
        int                     num_clks;
        int                     suspend_clk_idx;
-
-     struct regulator        *vdd33;
-     struct regulator        *vdd10;
    };
 
    static int dwc3_exynos_probe(struct platform_device *pdev)
@@ -44,6 +41,7 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
        struct device_node      *node = dev->of_node;
        const struct dwc3_exynos_driverdata *driver_data;
        int                     i, ret;
+     static const char * const regulators[] = { "vdd33", "vdd10" };
 
        exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
        if (!exynos)
@@ -78,27 +76,9 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
        if (exynos->suspend_clk_idx >= 0)
                clk_prepare_enable(exynos->clks[exynos->suspend_clk_idx]);
 
-     exynos->vdd33 = devm_regulator_get(dev, "vdd33");
-     if (IS_ERR(exynos->vdd33)) {
-             ret = PTR_ERR(exynos->vdd33);
-             goto vdd33_err;
-     }
-     ret = regulator_enable(exynos->vdd33);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD33 supply\n");
-             goto vdd33_err;
-     }
-
-     exynos->vdd10 = devm_regulator_get(dev, "vdd10");
-     if (IS_ERR(exynos->vdd10)) {
-             ret = PTR_ERR(exynos->vdd10);
-             goto vdd10_err;
-     }
-     ret = regulator_enable(exynos->vdd10);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD10 supply\n");
-             goto vdd10_err;
-     }
+     ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), regulators);
+     if (ret)
+             return dev_err_probe(dev, ret, "Failed to enable regulators\n");
 
        if (node) {
                ret = of_platform_populate(node, NULL, NULL, dev);
@@ -115,10 +95,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
        return 0;
 
    populate_err:
-     regulator_disable(exynos->vdd10);
-vdd10_err:
-     regulator_disable(exynos->vdd33);
-vdd33_err:
        for (i = exynos->num_clks - 1; i >= 0; i--)
                clk_disable_unprepare(exynos->clks[i]);
 
@@ -140,9 +116,6 @@ static void dwc3_exynos_remove(struct platform_device *pdev)
 
        if (exynos->suspend_clk_idx >= 0)
                clk_disable_unprepare(exynos->clks[exynos->suspend_clk_idx]);
-
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);
    }
 
    static const struct dwc3_exynos_driverdata exynos5250_drvdata = {

drivers/usb/dwc3/dwc3-exynos.c static int dwc3_exynos_suspend(struct device *dev) · line 200

Quoted 5 lines
drivers/usb/dwc3/dwc3-exynos.c +0 -2
@@ -196,9 +169,6 @@ static int dwc3_exynos_suspend(struct device *dev)
        for (i = exynos->num_clks - 1; i >= 0; i--)
                clk_disable_unprepare(exynos->clks[i]);
 
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);

Hi,

Quoted 5 lines

Same here, I don't think that removing regulator_[en|dis]able from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Ok,

Quoted 2 lines

Why did you removed it?

Quoted 7 lines

As per the description of the function devm_regulator_bulk_get_enable

* This helper function allows drivers to get several regulator
* consumers in one operation with management, the regulators will
* automatically be freed when the device is unbound. If any of the
* regulators cannot be acquired then any regulators that were
* allocated will be freed before returning to the caller.

The code in suspend/resume is not about freeing some resources. It is about enabling/disabling some hardware to save some power.

Think to the probe/remove functions as the software in the kernel that knows how to handle some hardawre, and the suspend/resume as the on/off button to power-on and off the electrical chips.

Quoted 6 lines

When the system is suspended, the software is still around. But some hardware can be set in a low consumption mode to save some power.

IMHO, part of the code you removed changed this behaviour and increase the power consumption when the system is suspended.

You are correct, I have changed the regulator API from devm_regulator_get_enable to devm_regulator_bulk_get_enable which changes this behavior.
I will fix it in the next version.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

CJ

I could not find any example in the kernel to support devm_regulator_bulk_disable
but here is my modified file.

If you have any suggestions for this plz let me know.

I don't think that your approach is correct, and I don't think that the proposed patch does what you expect it to do.

Calling a devm_ function in suspend/resume functions looks really strange to me and is likely broken.

Especially here, devm_regulator_bulk_get_enable() in the resume function allocates some memory that is not freed in devm_regulator_bulk_disable(), because the API is not designed to work like that. So this could generate a kind of memory leak.

*I think that the code is good enough as-is*, but if you really want to change something, maybe:
- devm_regulator_get()+regulator_enable() in the probe could be
changed to devm_regulator_get_enable()
- the resume/suspend function should be left as-is with
regulator_disable()/regulator_ensable()
- remove regulator_disable() from the error handling path of the
probe and from the remove function.

Quoted 2 lines

I *think* it would work.

No devm_regulator_get_enable use the same logic as devm_regulator_bulk_get_enable
to enable the regulator.

[0] https://elixir.bootlin.com/linux/latest/source/drivers/regulator/devres.c#L126

So as of now I am dropping the changes on the regulator in this patch series.

Quoted 2 lines

CJ

Thanks for your inputs.

Thanks

-Anand

#24 lore raw

Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function

Le 08/04/2024 à 12:02, Anand Moon a écrit :

Quoted 178 lines

Hi Christophe,

Quoted 174 lines · Christophe JAILLET
Quoted 143 lines · Anand Moon

Hi Christophe, Krzysztof,

Quoted 140 lines · Anand Moon

Hi Christophe,

Quoted 123 lines · Christophe JAILLET
Quoted 106 lines · Anand Moon

Hi Christophe,

Quoted 93 lines · Christophe JAILLET
Quoted 83 lines · Anand Moon

Use devm_regulator_bulk_get_enable() instead of open coded 'devm_regulator_get(), regulator_enable(), regulator_disable().

---
     drivers/usb/dwc3/dwc3-exynos.c | 49 +++-------------------------------
     1 file changed, 4 insertions(+), 45 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +4 -31
index 5d365ca51771..7c77f3c69825 100644
@@ -32,9 +32,6 @@ struct dwc3_exynos {
         struct clk              *clks[DWC3_EXYNOS_MAX_CLOCKS];
         int                     num_clks;
         int                     suspend_clk_idx;
-
-     struct regulator        *vdd33;
-     struct regulator        *vdd10;
     };
 
     static int dwc3_exynos_probe(struct platform_device *pdev)
@@ -44,6 +41,7 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
         struct device_node      *node = dev->of_node;
         const struct dwc3_exynos_driverdata *driver_data;
         int                     i, ret;
+     static const char * const regulators[] = { "vdd33", "vdd10" };
 
         exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
         if (!exynos)
@@ -78,27 +76,9 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
         if (exynos->suspend_clk_idx >= 0)
                 clk_prepare_enable(exynos->clks[exynos->suspend_clk_idx]);
 
-     exynos->vdd33 = devm_regulator_get(dev, "vdd33");
-     if (IS_ERR(exynos->vdd33)) {
-             ret = PTR_ERR(exynos->vdd33);
-             goto vdd33_err;
-     }
-     ret = regulator_enable(exynos->vdd33);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD33 supply\n");
-             goto vdd33_err;
-     }
-
-     exynos->vdd10 = devm_regulator_get(dev, "vdd10");
-     if (IS_ERR(exynos->vdd10)) {
-             ret = PTR_ERR(exynos->vdd10);
-             goto vdd10_err;
-     }
-     ret = regulator_enable(exynos->vdd10);
-     if (ret) {
-             dev_err(dev, "Failed to enable VDD10 supply\n");
-             goto vdd10_err;
-     }
+     ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators), regulators);
+     if (ret)
+             return dev_err_probe(dev, ret, "Failed to enable regulators\n");
 
         if (node) {
                 ret = of_platform_populate(node, NULL, NULL, dev);
@@ -115,10 +95,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
         return 0;
 
     populate_err:
-     regulator_disable(exynos->vdd10);
-vdd10_err:
-     regulator_disable(exynos->vdd33);
-vdd33_err:
         for (i = exynos->num_clks - 1; i >= 0; i--)
                 clk_disable_unprepare(exynos->clks[i]);
 
@@ -140,9 +116,6 @@ static void dwc3_exynos_remove(struct platform_device *pdev)
 
         if (exynos->suspend_clk_idx >= 0)
                 clk_disable_unprepare(exynos->clks[exynos->suspend_clk_idx]);
-
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);
     }
 
     static const struct dwc3_exynos_driverdata exynos5250_drvdata = {

drivers/usb/dwc3/dwc3-exynos.c static int dwc3_exynos_suspend(struct device *dev) · line 200

Quoted 5 lines
drivers/usb/dwc3/dwc3-exynos.c +0 -2
@@ -196,9 +169,6 @@ static int dwc3_exynos_suspend(struct device *dev)
         for (i = exynos->num_clks - 1; i >= 0; i--)
                 clk_disable_unprepare(exynos->clks[i]);
 
-     regulator_disable(exynos->vdd33);
-     regulator_disable(exynos->vdd10);

Hi,

Quoted 5 lines

Same here, I don't think that removing regulator_[en|dis]able from the suspend and resume function is correct.

The goal is to stop some hardware when the system is suspended, in order to save some power.

Ok,

Quoted 2 lines

Why did you removed it?

Quoted 7 lines

As per the description of the function devm_regulator_bulk_get_enable

* This helper function allows drivers to get several regulator
* consumers in one operation with management, the regulators will
* automatically be freed when the device is unbound. If any of the
* regulators cannot be acquired then any regulators that were
* allocated will be freed before returning to the caller.

The code in suspend/resume is not about freeing some resources. It is about enabling/disabling some hardware to save some power.

Think to the probe/remove functions as the software in the kernel that knows how to handle some hardawre, and the suspend/resume as the on/off button to power-on and off the electrical chips.

Quoted 6 lines

When the system is suspended, the software is still around. But some hardware can be set in a low consumption mode to save some power.

IMHO, part of the code you removed changed this behaviour and increase the power consumption when the system is suspended.

You are correct, I have changed the regulator API from devm_regulator_get_enable to devm_regulator_bulk_get_enable which changes this behavior.
I will fix it in the next version.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

CJ

I could not find any example in the kernel to support devm_regulator_bulk_disable
but here is my modified file.

If you have any suggestions for this plz let me know.

I don't think that your approach is correct, and I don't think that the proposed patch does what you expect it to do.

Calling a devm_ function in suspend/resume functions looks really strange to me and is likely broken.

Especially here, devm_regulator_bulk_get_enable() in the resume function allocates some memory that is not freed in devm_regulator_bulk_disable(), because the API is not designed to work like that. So this could generate a kind of memory leak.

*I think that the code is good enough as-is*, but if you really want to change something, maybe:
- devm_regulator_get()+regulator_enable() in the probe could be
changed to devm_regulator_get_enable()
- the resume/suspend function should be left as-is with
regulator_disable()/regulator_ensable()
- remove regulator_disable() from the error handling path of the
probe and from the remove function.

Quoted 5 lines
Quoted 2 lines

I *think* it would work.

No devm_regulator_get_enable use the same logic as devm_regulator_bulk_get_enable
to enable the regulator.

Yes, the logic is the same, but you get a pointer to the "struct regulator" which can be used to disable/enable in the suspend/resume functions.

With the bulk version, you can not do that.

See my first reply on your 3/4 patch.

Quoted 4 lines

[0] https://elixir.bootlin.com/linux/latest/source/drivers/regulator/devres.c#L126

So as of now I am dropping the changes on the regulator in this patch series.

I do agree that it is certainly the way to go here.

CJ

Quoted 10 lines
Quoted 3 lines

CJ

Thanks for your inputs.

Thanks

-Anand

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#25 lore raw

PATCH 4/4 usb: dwc3: exynos: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()

In reply to a message not in the archive

Use the new PM macros for the suspend and resume functions to be automatically dropped by the compiler when CONFIG_PM_SLEEP are disabled, without having to use #ifdef guards. If CONFIG_PM_SLEEP unused, they will simply be discarded by the compiler.

---
 drivers/usb/dwc3/dwc3-exynos.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +1 -7
index 7c77f3c69825..645a4ec0cd92 100644
@@ -160,7 +160,6 @@ static const struct of_device_id exynos_dwc3_match[] = {
 };
 MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
 
-#ifdef CONFIG_PM_SLEEP
 static int dwc3_exynos_suspend(struct device *dev)
 {
 	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
@@ -193,18 +192,13 @@ static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
 };
 
-#define DEV_PM_OPS	(&dwc3_exynos_dev_pm_ops)
-#else
-#define DEV_PM_OPS	NULL
-#endif /* CONFIG_PM_SLEEP */
-
 static struct platform_driver dwc3_exynos_driver = {
 	.probe		= dwc3_exynos_probe,
 	.remove_new	= dwc3_exynos_remove,
 	.driver		= {
 		.name	= "exynos-dwc3",
 		.of_match_table = exynos_dwc3_match,
-		.pm	= DEV_PM_OPS,
+		.pm	= pm_sleep_ptr(&dwc3_exynos_dev_pm_ops),
 	},
 };
 
Signature · 1 line
2.43.0