* [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers [not found] <20240301193831.3346-1-linux.amoon@gmail.com> @ 2024-03-01 19:38 ` Anand Moon 2024-03-01 20:19 ` Alan Stern 2024-03-02 15:49 ` Christophe JAILLET 2024-03-01 19:38 ` [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr() Anand Moon ` (2 subsequent siblings) 3 siblings, 2 replies; 24+ messages in thread From: Anand Moon @ 2024-03-01 19:38 UTC (permalink / raw) To: Alan Stern, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar Cc: Anand Moon, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel 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. Signed-off-by: Anand Moon <linux.amoon@gmail.com> --- drivers/usb/host/ehci-exynos.c | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c index f644b131cc0b..05aa3d9c2a3b 100644 --- a/drivers/usb/host/ehci-exynos.c +++ b/drivers/usb/host/ehci-exynos.c @@ -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; } -- 2.43.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers 2024-03-01 19:38 ` [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers Anand Moon @ 2024-03-01 20:19 ` Alan Stern 2024-03-02 15:41 ` Anand Moon 2024-03-02 15:49 ` Christophe JAILLET 1 sibling, 1 reply; 24+ messages in thread From: Alan Stern @ 2024-03-01 20:19 UTC (permalink / raw) To: Anand Moon Cc: Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel On Sat, Mar 02, 2024 at 01:08:08AM +0530, Anand Moon wrote: > 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. > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > --- > drivers/usb/host/ehci-exynos.c | 30 +++++------------------------- > 1 file changed, 5 insertions(+), 25 deletions(-) > > diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c > index f644b131cc0b..05aa3d9c2a3b 100644 > --- a/drivers/usb/host/ehci-exynos.c > +++ b/drivers/usb/host/ehci-exynos.c > @@ -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"); What about the usb_put_hcd(hcd) call that used to happen here? Alan Stern > > 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; > } > > -- > 2.43.0 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers 2024-03-01 20:19 ` Alan Stern @ 2024-03-02 15:41 ` Anand Moon 0 siblings, 0 replies; 24+ messages in thread From: Anand Moon @ 2024-03-02 15:41 UTC (permalink / raw) To: Alan Stern Cc: Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Hi Alan On Sat, 2 Mar 2024 at 01:49, Alan Stern <stern@rowland.harvard.edu> wrote: > > On Sat, Mar 02, 2024 at 01:08:08AM +0530, Anand Moon wrote: > > 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. > > > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > > --- > > drivers/usb/host/ehci-exynos.c | 30 +++++------------------------- > > 1 file changed, 5 insertions(+), 25 deletions(-) > > > > diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c > > index f644b131cc0b..05aa3d9c2a3b 100644 > > --- a/drivers/usb/host/ehci-exynos.c > > +++ b/drivers/usb/host/ehci-exynos.c > > @@ -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"); > > What about the usb_put_hcd(hcd) call that used to happen here? > Ok, I will update this in the next version. > Alan Stern Thanks -Anand _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers 2024-03-01 19:38 ` [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers Anand Moon 2024-03-01 20:19 ` Alan Stern @ 2024-03-02 15:49 ` Christophe JAILLET 2024-03-02 16:35 ` Anand Moon 1 sibling, 1 reply; 24+ messages in thread From: Christophe JAILLET @ 2024-03-02 15:49 UTC (permalink / raw) To: Anand Moon, Alan Stern, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar Cc: linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Le 01/03/2024 à 20:38, Anand Moon a écrit : > 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. > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > --- > drivers/usb/host/ehci-exynos.c | 30 +++++------------------------- > 1 file changed, 5 insertions(+), 25 deletions(-) > > diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c > index f644b131cc0b..05aa3d9c2a3b 100644 > --- a/drivers/usb/host/ehci-exynos.c > +++ b/drivers/usb/host/ehci-exynos.c > @@ -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); 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 > - > 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; > } > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers 2024-03-02 15:49 ` Christophe JAILLET @ 2024-03-02 16:35 ` Anand Moon 2024-03-02 18:41 ` Christophe JAILLET 2024-03-04 9:18 ` Johan Hovold 0 siblings, 2 replies; 24+ messages in thread From: Anand Moon @ 2024-03-02 16:35 UTC (permalink / raw) To: Christophe JAILLET Cc: Alan Stern, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Hi Christophe, On Sat, 2 Mar 2024 at 21:19, Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote: > > Le 01/03/2024 à 20:38, Anand Moon a écrit : > > 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. > > > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > > --- > > drivers/usb/host/ehci-exynos.c | 30 +++++------------------------- > > 1 file changed, 5 insertions(+), 25 deletions(-) > > > > diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c > > index f644b131cc0b..05aa3d9c2a3b 100644 > > --- a/drivers/usb/host/ehci-exynos.c > > +++ b/drivers/usb/host/ehci-exynos.c > > @@ -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); > > 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. Yes correct, > > 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. > CJ Thanks -Anand > > > - > > 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; > > } > > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers 2024-03-02 16:35 ` Anand Moon @ 2024-03-02 18:41 ` Christophe JAILLET 2024-03-04 9:18 ` Johan Hovold 1 sibling, 0 replies; 24+ messages in thread From: Christophe JAILLET @ 2024-03-02 18:41 UTC (permalink / raw) To: Anand Moon Cc: Alan Stern, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Le 02/03/2024 à 17:35, Anand Moon a écrit : > Hi Christophe, > > On Sat, 2 Mar 2024 at 21:19, Christophe JAILLET > <christophe.jaillet@wanadoo.fr> wrote: >> >> Le 01/03/2024 à 20:38, Anand Moon a écrit : >>> 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. >>> >>> Signed-off-by: Anand Moon <linux.amoon@gmail.com> >>> --- >>> drivers/usb/host/ehci-exynos.c | 30 +++++------------------------- >>> 1 file changed, 5 insertions(+), 25 deletions(-) >>> >>> diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c >>> index f644b131cc0b..05aa3d9c2a3b 100644 >>> --- a/drivers/usb/host/ehci-exynos.c >>> +++ b/drivers/usb/host/ehci-exynos.c >>> @@ -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); >> >> 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. > Yes correct, >> >> 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 > > [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. > >> CJ > > Thanks > -Anand >> >>> - >>> 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; >>> } >>> >> > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers 2024-03-02 16:35 ` Anand Moon 2024-03-02 18:41 ` Christophe JAILLET @ 2024-03-04 9:18 ` Johan Hovold 2024-03-04 10:05 ` Anand Moon 1 sibling, 1 reply; 24+ messages in thread From: Johan Hovold @ 2024-03-04 9:18 UTC (permalink / raw) To: Anand Moon Cc: Christophe JAILLET, Alan Stern, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel On Sat, Mar 02, 2024 at 10:05:46PM +0530, Anand Moon wrote: > On Sat, 2 Mar 2024 at 21:19, Christophe JAILLET > <christophe.jaillet@wanadoo.fr> wrote: > > Le 01/03/2024 à 20:38, Anand Moon a écrit : > > > 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. > > > @@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev) > > > > > > exynos_ehci_phy_disable(dev); > > > > > > - 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, > > > > 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. 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers 2024-03-04 9:18 ` Johan Hovold @ 2024-03-04 10:05 ` Anand Moon 0 siblings, 0 replies; 24+ messages in thread From: Anand Moon @ 2024-03-04 10:05 UTC (permalink / raw) To: Johan Hovold Cc: Christophe JAILLET, Alan Stern, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Hi Johon, Christophe, On Mon, 4 Mar 2024 at 14:48, Johan Hovold <johan@kernel.org> wrote: > > On Sat, Mar 02, 2024 at 10:05:46PM +0530, Anand Moon wrote: > > On Sat, 2 Mar 2024 at 21:19, Christophe JAILLET > > <christophe.jaillet@wanadoo.fr> wrote: > > > Le 01/03/2024 à 20:38, Anand Moon a écrit : > > > > > 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. > > > > > @@ -260,25 +248,17 @@ static int exynos_ehci_suspend(struct device *dev) > > > > > > > > exynos_ehci_phy_disable(dev); > > > > > > > > - 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, > > > > > > 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. > > 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.. > 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]# > Ok, I will restore the clk changes in the suspend / resume functions in the next version and do thought testing. > Johan Thanks -Anand _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr() [not found] <20240301193831.3346-1-linux.amoon@gmail.com> 2024-03-01 19:38 ` [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers Anand Moon @ 2024-03-01 19:38 ` Anand Moon 2024-03-01 20:28 ` Alan Stern 2024-03-04 9:21 ` Johan Hovold 2024-03-01 19:38 ` [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function Anand Moon 2024-03-01 19:38 ` [PATCH v1 4/4] usb: dwc3: exynos: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() Anand Moon 3 siblings, 2 replies; 24+ messages in thread From: Anand Moon @ 2024-03-01 19:38 UTC (permalink / raw) To: Alan Stern, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar Cc: Anand Moon, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel 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. Signed-off-by: Anand Moon <linux.amoon@gmail.com> --- drivers/usb/host/ehci-exynos.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c index 05aa3d9c2a3b..4676f45655cd 100644 --- a/drivers/usb/host/ehci-exynos.c +++ b/drivers/usb/host/ehci-exynos.c @@ -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), } }; -- 2.43.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr() 2024-03-01 19:38 ` [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr() Anand Moon @ 2024-03-01 20:28 ` Alan Stern 2024-03-02 15:41 ` Anand Moon 2024-03-04 9:21 ` Johan Hovold 1 sibling, 1 reply; 24+ messages in thread From: Alan Stern @ 2024-03-01 20:28 UTC (permalink / raw) To: Anand Moon Cc: Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel On Sat, Mar 02, 2024 at 01:08:09AM +0530, Anand Moon wrote: > 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. > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > --- > drivers/usb/host/ehci-exynos.c | 10 ++-------- > 1 file changed, 2 insertions(+), 8 deletions(-) > > diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c > index 05aa3d9c2a3b..4676f45655cd 100644 > --- a/drivers/usb/host/ehci-exynos.c > +++ b/drivers/usb/host/ehci-exynos.c > @@ -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 Doesn't this now generate warnings about functions being defined but not used when you build with CONFIG_PM disabled? Alan Stern > > 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), > } > }; > -- > 2.43.0 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr() 2024-03-01 20:28 ` Alan Stern @ 2024-03-02 15:41 ` Anand Moon 0 siblings, 0 replies; 24+ messages in thread From: Anand Moon @ 2024-03-02 15:41 UTC (permalink / raw) To: Alan Stern Cc: Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Hi Alan, On Sat, 2 Mar 2024 at 01:58, Alan Stern <stern@rowland.harvard.edu> wrote: > > On Sat, Mar 02, 2024 at 01:08:09AM +0530, Anand Moon wrote: > > 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. > > > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > > --- > > drivers/usb/host/ehci-exynos.c | 10 ++-------- > > 1 file changed, 2 insertions(+), 8 deletions(-) > > > > diff --git a/drivers/usb/host/ehci-exynos.c b/drivers/usb/host/ehci-exynos.c > > index 05aa3d9c2a3b..4676f45655cd 100644 > > --- a/drivers/usb/host/ehci-exynos.c > > +++ b/drivers/usb/host/ehci-exynos.c > > @@ -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 > > 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. diff --git a/arch/arm/configs/exynos_defconfig b/arch/arm/configs/exynos_defconfig index c98d5ff8a1ed..e96f5c3bf8c1 100644 --- a/arch/arm/configs/exynos_defconfig +++ b/arch/arm/configs/exynos_defconfig @@ -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 > Alan Stern Thanks -Anand _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr() 2024-03-01 19:38 ` [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr() Anand Moon 2024-03-01 20:28 ` Alan Stern @ 2024-03-04 9:21 ` Johan Hovold 2024-03-04 10:16 ` Anand Moon 1 sibling, 1 reply; 24+ messages in thread From: Johan Hovold @ 2024-03-04 9:21 UTC (permalink / raw) To: Anand Moon Cc: Alan Stern, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel On Sat, Mar 02, 2024 at 01:08:09AM +0530, Anand Moon wrote: > 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. > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > --- > drivers/usb/host/ehci-exynos.c | 10 ++-------- > 1 file changed, 2 insertions(+), 8 deletions(-) > 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) > }; 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr() 2024-03-04 9:21 ` Johan Hovold @ 2024-03-04 10:16 ` Anand Moon 0 siblings, 0 replies; 24+ messages in thread From: Anand Moon @ 2024-03-04 10:16 UTC (permalink / raw) To: Johan Hovold Cc: Alan Stern, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Hi Johan, On Mon, 4 Mar 2024 at 14:51, Johan Hovold <johan@kernel.org> wrote: > > On Sat, Mar 02, 2024 at 01:08:09AM +0530, Anand Moon wrote: > > 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. > > > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > > --- > > drivers/usb/host/ehci-exynos.c | 10 ++-------- > > 1 file changed, 2 insertions(+), 8 deletions(-) > > > 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) > > }; > > 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 Ok, I will drop these changes. Thanks. -Anand _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function [not found] <20240301193831.3346-1-linux.amoon@gmail.com> 2024-03-01 19:38 ` [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers Anand Moon 2024-03-01 19:38 ` [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr() Anand Moon @ 2024-03-01 19:38 ` Anand Moon 2024-03-02 15:50 ` Christophe JAILLET 2024-03-01 19:38 ` [PATCH v1 4/4] usb: dwc3: exynos: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() Anand Moon 3 siblings, 1 reply; 24+ messages in thread From: Anand Moon @ 2024-03-01 19:38 UTC (permalink / raw) To: Thinh Nguyen, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar Cc: Anand Moon, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Use devm_regulator_bulk_get_enable() instead of open coded 'devm_regulator_get(), regulator_enable(), regulator_disable(). Signed-off-by: Anand Moon <linux.amoon@gmail.com> --- drivers/usb/dwc3/dwc3-exynos.c | 49 +++------------------------------- 1 file changed, 4 insertions(+), 45 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c index 5d365ca51771..7c77f3c69825 100644 --- a/drivers/usb/dwc3/dwc3-exynos.c +++ b/drivers/usb/dwc3/dwc3-exynos.c @@ -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) { -- 2.43.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function 2024-03-01 19:38 ` [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function Anand Moon @ 2024-03-02 15:50 ` Christophe JAILLET 2024-03-02 16:48 ` Anand Moon 0 siblings, 1 reply; 24+ messages in thread From: Christophe JAILLET @ 2024-03-02 15:50 UTC (permalink / raw) To: Anand Moon, Thinh Nguyen, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar Cc: linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Le 01/03/2024 à 20:38, Anand Moon a écrit : > Use devm_regulator_bulk_get_enable() instead of open coded > 'devm_regulator_get(), regulator_enable(), regulator_disable(). > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > --- > drivers/usb/dwc3/dwc3-exynos.c | 49 +++------------------------------- > 1 file changed, 4 insertions(+), 45 deletions(-) > > diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c > index 5d365ca51771..7c77f3c69825 100644 > --- a/drivers/usb/dwc3/dwc3-exynos.c > +++ b/drivers/usb/dwc3/dwc3-exynos.c > @@ -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); 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 > - > 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) { _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function 2024-03-02 15:50 ` Christophe JAILLET @ 2024-03-02 16:48 ` Anand Moon 2024-03-02 18:37 ` Christophe JAILLET 0 siblings, 1 reply; 24+ messages in thread From: Anand Moon @ 2024-03-02 16:48 UTC (permalink / raw) To: Christophe JAILLET Cc: Thinh Nguyen, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Hi Christophe, On Sat, 2 Mar 2024 at 21:20, Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote: > > Le 01/03/2024 à 20:38, Anand Moon a écrit : > > Use devm_regulator_bulk_get_enable() instead of open coded > > 'devm_regulator_get(), regulator_enable(), regulator_disable(). > > > > Signed-off-by: Anand Moon <linux.amoon@gmail.com> > > --- > > drivers/usb/dwc3/dwc3-exynos.c | 49 +++------------------------------- > > 1 file changed, 4 insertions(+), 45 deletions(-) > > > > diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c > > index 5d365ca51771..7c77f3c69825 100644 > > --- a/drivers/usb/dwc3/dwc3-exynos.c > > +++ b/drivers/usb/dwc3/dwc3-exynos.c > > @@ -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); > > 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. Ok, > > 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. > > CJ > Thanks -Anand _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function 2024-03-02 16:48 ` Anand Moon @ 2024-03-02 18:37 ` Christophe JAILLET 2024-03-04 11:46 ` Anand Moon 0 siblings, 1 reply; 24+ messages in thread From: Christophe JAILLET @ 2024-03-02 18:37 UTC (permalink / raw) To: Anand Moon Cc: Thinh Nguyen, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Le 02/03/2024 à 17:48, Anand Moon a écrit : > Hi Christophe, > > On Sat, 2 Mar 2024 at 21:20, Christophe JAILLET > <christophe.jaillet@wanadoo.fr> wrote: >> >> Le 01/03/2024 à 20:38, Anand Moon a écrit : >>> Use devm_regulator_bulk_get_enable() instead of open coded >>> 'devm_regulator_get(), regulator_enable(), regulator_disable(). >>> >>> Signed-off-by: Anand Moon <linux.amoon@gmail.com> >>> --- >>> drivers/usb/dwc3/dwc3-exynos.c | 49 +++------------------------------- >>> 1 file changed, 4 insertions(+), 45 deletions(-) >>> >>> diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c >>> index 5d365ca51771..7c77f3c69825 100644 >>> --- a/drivers/usb/dwc3/dwc3-exynos.c >>> +++ b/drivers/usb/dwc3/dwc3-exynos.c >>> @@ -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); >> >> 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. > Ok, >> >> 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. 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 > > [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. > >> >> CJ >> > Thanks > -Anand > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function 2024-03-02 18:37 ` Christophe JAILLET @ 2024-03-04 11:46 ` Anand Moon 2024-04-05 6:10 ` Anand Moon 0 siblings, 1 reply; 24+ messages in thread From: Anand Moon @ 2024-03-04 11:46 UTC (permalink / raw) To: Christophe JAILLET Cc: Thinh Nguyen, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Hi Christophe, On Sun, 3 Mar 2024 at 00:07, Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote: > > Le 02/03/2024 à 17:48, Anand Moon a écrit : > > Hi Christophe, > > > > On Sat, 2 Mar 2024 at 21:20, Christophe JAILLET > > <christophe.jaillet@wanadoo.fr> wrote: > >> > >> Le 01/03/2024 à 20:38, Anand Moon a écrit : > >>> Use devm_regulator_bulk_get_enable() instead of open coded > >>> 'devm_regulator_get(), regulator_enable(), regulator_disable(). > >>> > >>> Signed-off-by: Anand Moon <linux.amoon@gmail.com> > >>> --- > >>> drivers/usb/dwc3/dwc3-exynos.c | 49 +++------------------------------- > >>> 1 file changed, 4 insertions(+), 45 deletions(-) > >>> > >>> diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c > >>> index 5d365ca51771..7c77f3c69825 100644 > >>> --- a/drivers/usb/dwc3/dwc3-exynos.c > >>> +++ b/drivers/usb/dwc3/dwc3-exynos.c > >>> @@ -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); > >> > >> 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. > > Ok, > >> > >> 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. > > 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. > 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. > CJ Thanks -Anand _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function 2024-03-04 11:46 ` Anand Moon @ 2024-04-05 6:10 ` Anand Moon 2024-04-05 16:12 ` Christophe JAILLET 0 siblings, 1 reply; 24+ messages in thread From: Anand Moon @ 2024-04-05 6:10 UTC (permalink / raw) To: Christophe JAILLET Cc: Thinh Nguyen, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Hi Christophe, Krzysztof, On Mon, 4 Mar 2024 at 17:16, Anand Moon <linux.amoon@gmail.com> wrote: > > Hi Christophe, > > On Sun, 3 Mar 2024 at 00:07, Christophe JAILLET > <christophe.jaillet@wanadoo.fr> wrote: > > > > Le 02/03/2024 à 17:48, Anand Moon a écrit : > > > Hi Christophe, > > > > > > On Sat, 2 Mar 2024 at 21:20, Christophe JAILLET > > > <christophe.jaillet@wanadoo.fr> wrote: > > >> > > >> Le 01/03/2024 à 20:38, Anand Moon a écrit : > > >>> Use devm_regulator_bulk_get_enable() instead of open coded > > >>> 'devm_regulator_get(), regulator_enable(), regulator_disable(). > > >>> > > >>> Signed-off-by: Anand Moon <linux.amoon@gmail.com> > > >>> --- > > >>> drivers/usb/dwc3/dwc3-exynos.c | 49 +++------------------------------- > > >>> 1 file changed, 4 insertions(+), 45 deletions(-) > > >>> > > >>> diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c > > >>> index 5d365ca51771..7c77f3c69825 100644 > > >>> --- a/drivers/usb/dwc3/dwc3-exynos.c > > >>> +++ b/drivers/usb/dwc3/dwc3-exynos.c > > >>> @@ -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); > > >> > > >> 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. > > > Ok, > > >> > > >> 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. > > > > 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. > > > > 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. > > > 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<---------- diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c index 6d07592ad022..2f808cb9a006 100644 --- a/drivers/usb/dwc3/dwc3-exynos.c +++ b/drivers/usb/dwc3/dwc3-exynos.c @@ -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<---------- diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c index 90bb0d178885..97eed739f929 100644 --- a/drivers/regulator/devres.c +++ b/drivers/regulator/devres.c @@ -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 diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index 4660582a3302..ce7d28306b17 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function 2024-04-05 6:10 ` Anand Moon @ 2024-04-05 16:12 ` Christophe JAILLET 2024-04-06 3:40 ` Anand Moon 2024-04-08 10:02 ` Anand Moon 0 siblings, 2 replies; 24+ messages in thread From: Christophe JAILLET @ 2024-04-05 16:12 UTC (permalink / raw) To: Anand Moon Cc: Thinh Nguyen, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Le 05/04/2024 à 08:10, Anand Moon a écrit : > Hi Christophe, Krzysztof, > > On Mon, 4 Mar 2024 at 17:16, Anand Moon <linux.amoon@gmail.com> wrote: >> >> Hi Christophe, >> >> On Sun, 3 Mar 2024 at 00:07, Christophe JAILLET >> <christophe.jaillet@wanadoo.fr> wrote: >>> >>> Le 02/03/2024 à 17:48, Anand Moon a écrit : >>>> Hi Christophe, >>>> >>>> On Sat, 2 Mar 2024 at 21:20, Christophe JAILLET >>>> <christophe.jaillet@wanadoo.fr> wrote: >>>>> >>>>> Le 01/03/2024 à 20:38, Anand Moon a écrit : >>>>>> Use devm_regulator_bulk_get_enable() instead of open coded >>>>>> 'devm_regulator_get(), regulator_enable(), regulator_disable(). >>>>>> >>>>>> Signed-off-by: Anand Moon <linux.amoon@gmail.com> >>>>>> --- >>>>>> drivers/usb/dwc3/dwc3-exynos.c | 49 +++------------------------------- >>>>>> 1 file changed, 4 insertions(+), 45 deletions(-) >>>>>> >>>>>> diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c >>>>>> index 5d365ca51771..7c77f3c69825 100644 >>>>>> --- a/drivers/usb/dwc3/dwc3-exynos.c >>>>>> +++ b/drivers/usb/dwc3/dwc3-exynos.c >>>>>> @@ -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); >>>>> >>>>> 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. >>>> Ok, >>>>> >>>>> 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. >>> >>> 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. >>> >> >> 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. >> >>> 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 > -----8<----------8<---------- > diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c > index 6d07592ad022..2f808cb9a006 100644 > --- a/drivers/usb/dwc3/dwc3-exynos.c > +++ b/drivers/usb/dwc3/dwc3-exynos.c > @@ -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<---------- > diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c > index 90bb0d178885..97eed739f929 100644 > --- a/drivers/regulator/devres.c > +++ b/drivers/regulator/devres.c > @@ -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 > diff --git a/include/linux/regulator/consumer.h > b/include/linux/regulator/consumer.h > index 4660582a3302..ce7d28306b17 100644 > --- a/include/linux/regulator/consumer.h > +++ b/include/linux/regulator/consumer.h > @@ -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 > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function 2024-04-05 16:12 ` Christophe JAILLET @ 2024-04-06 3:40 ` Anand Moon 2024-04-08 10:02 ` Anand Moon 1 sibling, 0 replies; 24+ messages in thread From: Anand Moon @ 2024-04-06 3:40 UTC (permalink / raw) To: Christophe JAILLET Cc: Thinh Nguyen, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Hi Christophe On Fri, 5 Apr 2024 at 21:42, Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote: > > Le 05/04/2024 à 08:10, Anand Moon a écrit : > > Hi Christophe, Krzysztof, > > > > On Mon, 4 Mar 2024 at 17:16, Anand Moon <linux.amoon@gmail.com> wrote: > >> > >> Hi Christophe, > >> > >> On Sun, 3 Mar 2024 at 00:07, Christophe JAILLET > >> <christophe.jaillet@wanadoo.fr> wrote: > >>> > >>> Le 02/03/2024 à 17:48, Anand Moon a écrit : > >>>> Hi Christophe, > >>>> > >>>> On Sat, 2 Mar 2024 at 21:20, Christophe JAILLET > >>>> <christophe.jaillet@wanadoo.fr> wrote: > >>>>> > >>>>> Le 01/03/2024 à 20:38, Anand Moon a écrit : > >>>>>> Use devm_regulator_bulk_get_enable() instead of open coded > >>>>>> 'devm_regulator_get(), regulator_enable(), regulator_disable(). > >>>>>> > >>>>>> Signed-off-by: Anand Moon <linux.amoon@gmail.com> > >>>>>> --- > >>>>>> drivers/usb/dwc3/dwc3-exynos.c | 49 +++------------------------------- > >>>>>> 1 file changed, 4 insertions(+), 45 deletions(-) > >>>>>> > >>>>>> diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c > >>>>>> index 5d365ca51771..7c77f3c69825 100644 > >>>>>> --- a/drivers/usb/dwc3/dwc3-exynos.c > >>>>>> +++ b/drivers/usb/dwc3/dwc3-exynos.c > >>>>>> @@ -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); > >>>>> > >>>>> 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. > >>>> Ok, > >>>>> > >>>>> 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. > >>> > >>> 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. > >>> > >> > >> 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. > >> > >>> 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. > Thanks OK, I will test this and update in the next version. . > CJ Thanks -Anand _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function 2024-04-05 16:12 ` Christophe JAILLET 2024-04-06 3:40 ` Anand Moon @ 2024-04-08 10:02 ` Anand Moon 2024-04-08 20:26 ` Christophe JAILLET 1 sibling, 1 reply; 24+ messages in thread From: Anand Moon @ 2024-04-08 10:02 UTC (permalink / raw) To: Christophe JAILLET Cc: Thinh Nguyen, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Hi Christophe, On Fri, 5 Apr 2024 at 21:42, Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote: > > Le 05/04/2024 à 08:10, Anand Moon a écrit : > > Hi Christophe, Krzysztof, > > > > On Mon, 4 Mar 2024 at 17:16, Anand Moon <linux.amoon@gmail.com> wrote: > >> > >> Hi Christophe, > >> > >> On Sun, 3 Mar 2024 at 00:07, Christophe JAILLET > >> <christophe.jaillet@wanadoo.fr> wrote: > >>> > >>> Le 02/03/2024 à 17:48, Anand Moon a écrit : > >>>> Hi Christophe, > >>>> > >>>> On Sat, 2 Mar 2024 at 21:20, Christophe JAILLET > >>>> <christophe.jaillet@wanadoo.fr> wrote: > >>>>> > >>>>> Le 01/03/2024 à 20:38, Anand Moon a écrit : > >>>>>> Use devm_regulator_bulk_get_enable() instead of open coded > >>>>>> 'devm_regulator_get(), regulator_enable(), regulator_disable(). > >>>>>> > >>>>>> Signed-off-by: Anand Moon <linux.amoon@gmail.com> > >>>>>> --- > >>>>>> drivers/usb/dwc3/dwc3-exynos.c | 49 +++------------------------------- > >>>>>> 1 file changed, 4 insertions(+), 45 deletions(-) > >>>>>> > >>>>>> diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c > >>>>>> index 5d365ca51771..7c77f3c69825 100644 > >>>>>> --- a/drivers/usb/dwc3/dwc3-exynos.c > >>>>>> +++ b/drivers/usb/dwc3/dwc3-exynos.c > >>>>>> @@ -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); > >>>>> > >>>>> 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. > >>>> Ok, > >>>>> > >>>>> 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. > >>> > >>> 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. > >>> > >> > >> 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. > >> > >>> 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. > 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. > CJ > Thanks for your inputs. Thanks -Anand _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function 2024-04-08 10:02 ` Anand Moon @ 2024-04-08 20:26 ` Christophe JAILLET 0 siblings, 0 replies; 24+ messages in thread From: Christophe JAILLET @ 2024-04-08 20:26 UTC (permalink / raw) To: Anand Moon Cc: Thinh Nguyen, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel Le 08/04/2024 à 12:02, Anand Moon a écrit : > Hi Christophe, > > On Fri, 5 Apr 2024 at 21:42, Christophe JAILLET > <christophe.jaillet@wanadoo.fr> wrote: >> >> Le 05/04/2024 à 08:10, Anand Moon a écrit : >>> Hi Christophe, Krzysztof, >>> >>> On Mon, 4 Mar 2024 at 17:16, Anand Moon <linux.amoon@gmail.com> wrote: >>>> >>>> Hi Christophe, >>>> >>>> On Sun, 3 Mar 2024 at 00:07, Christophe JAILLET >>>> <christophe.jaillet@wanadoo.fr> wrote: >>>>> >>>>> Le 02/03/2024 à 17:48, Anand Moon a écrit : >>>>>> Hi Christophe, >>>>>> >>>>>> On Sat, 2 Mar 2024 at 21:20, Christophe JAILLET >>>>>> <christophe.jaillet@wanadoo.fr> wrote: >>>>>>> >>>>>>> Le 01/03/2024 à 20:38, Anand Moon a écrit : >>>>>>>> Use devm_regulator_bulk_get_enable() instead of open coded >>>>>>>> 'devm_regulator_get(), regulator_enable(), regulator_disable(). >>>>>>>> >>>>>>>> Signed-off-by: Anand Moon <linux.amoon@gmail.com> >>>>>>>> --- >>>>>>>> drivers/usb/dwc3/dwc3-exynos.c | 49 +++------------------------------- >>>>>>>> 1 file changed, 4 insertions(+), 45 deletions(-) >>>>>>>> >>>>>>>> diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c >>>>>>>> index 5d365ca51771..7c77f3c69825 100644 >>>>>>>> --- a/drivers/usb/dwc3/dwc3-exynos.c >>>>>>>> +++ b/drivers/usb/dwc3/dwc3-exynos.c >>>>>>>> @@ -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); >>>>>>> >>>>>>> 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. >>>>>> Ok, >>>>>>> >>>>>>> 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. >>>>> >>>>> 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. >>>>> >>>> >>>> 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. >>>> >>>>> 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. >> > 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. > > [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 > >> CJ >> > Thanks for your inputs. > > Thanks > > -Anand > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH v1 4/4] usb: dwc3: exynos: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() [not found] <20240301193831.3346-1-linux.amoon@gmail.com> ` (2 preceding siblings ...) 2024-03-01 19:38 ` [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function Anand Moon @ 2024-03-01 19:38 ` Anand Moon 3 siblings, 0 replies; 24+ messages in thread From: Anand Moon @ 2024-03-01 19:38 UTC (permalink / raw) To: Thinh Nguyen, Greg Kroah-Hartman, Krzysztof Kozlowski, Alim Akhtar Cc: Anand Moon, linux-usb, linux-arm-kernel, linux-samsung-soc, linux-kernel 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. Signed-off-by: Anand Moon <linux.amoon@gmail.com> --- drivers/usb/dwc3/dwc3-exynos.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c index 7c77f3c69825..645a4ec0cd92 100644 --- a/drivers/usb/dwc3/dwc3-exynos.c +++ b/drivers/usb/dwc3/dwc3-exynos.c @@ -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), }, }; -- 2.43.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 24+ messages in thread
end of thread, other threads:[~2024-04-08 20:26 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20240301193831.3346-1-linux.amoon@gmail.com>
2024-03-01 19:38 ` [PATCH v1 1/4] usb: ehci-exynos: Use devm_clk_get_enabled() helpers Anand Moon
2024-03-01 20:19 ` Alan Stern
2024-03-02 15:41 ` Anand Moon
2024-03-02 15:49 ` Christophe JAILLET
2024-03-02 16:35 ` Anand Moon
2024-03-02 18:41 ` Christophe JAILLET
2024-03-04 9:18 ` Johan Hovold
2024-03-04 10:05 ` Anand Moon
2024-03-01 19:38 ` [PATCH v1 2/4] usb: ehci-exynos: Switch from CONFIG_PM guards to pm_ptr() Anand Moon
2024-03-01 20:28 ` Alan Stern
2024-03-02 15:41 ` Anand Moon
2024-03-04 9:21 ` Johan Hovold
2024-03-04 10:16 ` Anand Moon
2024-03-01 19:38 ` [PATCH v1 3/4] usb: dwc3: exynos: Use devm_regulator_bulk_get_enable() helper function Anand Moon
2024-03-02 15:50 ` Christophe JAILLET
2024-03-02 16:48 ` Anand Moon
2024-03-02 18:37 ` Christophe JAILLET
2024-03-04 11:46 ` Anand Moon
2024-04-05 6:10 ` Anand Moon
2024-04-05 16:12 ` Christophe JAILLET
2024-04-06 3:40 ` Anand Moon
2024-04-08 10:02 ` Anand Moon
2024-04-08 20:26 ` Christophe JAILLET
2024-03-01 19:38 ` [PATCH v1 4/4] usb: dwc3: exynos: Switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr() Anand Moon
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).