mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] usb: phy: generic: Miscellaneous improvements
@ 2026-01-21 14:11 Geert Uytterhoeven
  2026-01-21 14:11 ` [PATCH 1/4] usb: phy: generic: Always use dev in usb_phy_generic_probe() Geert Uytterhoeven
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2026-01-21 14:11 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-usb, linux-renesas-soc, linux-kernel, Geert Uytterhoeven

	Hi Greg,

This patch series contains a few improvements for the generic USB PHY
driver.  it has been tested on a Renesas Ebisu-4D board with R-Car E3.

Thanks for your comments!

Geert Uytterhoeven (4):
  usb: phy: generic: Always use dev in usb_phy_generic_probe()
  usb: phy: generic: Convert to devm_clk_get_optional()
  usb: phy: generic: Convert to dev_err_probe()
  usb: phy: generic: Convert to device property API

 drivers/usb/phy/phy-generic.c | 74 ++++++++++++-----------------------
 1 file changed, 26 insertions(+), 48 deletions(-)

-- 
2.43.0

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] usb: phy: generic: Always use dev in usb_phy_generic_probe()
  2026-01-21 14:11 [PATCH 0/4] usb: phy: generic: Miscellaneous improvements Geert Uytterhoeven
@ 2026-01-21 14:11 ` Geert Uytterhoeven
  2026-01-21 14:11 ` [PATCH 2/4] usb: phy: generic: Convert to devm_clk_get_optional() Geert Uytterhoeven
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2026-01-21 14:11 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-usb, linux-renesas-soc, linux-kernel, Geert Uytterhoeven

usb_phy_generic_probe() already has a "dev" variable that serves as a
shorthand for "&pdev->dev".  Use it where appropriate, to shorten the
code.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/usb/phy/phy-generic.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
index 8423be59ec0ffbe8..13bd16668932dc90 100644
--- a/drivers/usb/phy/phy-generic.c
+++ b/drivers/usb/phy/phy-generic.c
@@ -294,13 +294,13 @@ static int usb_phy_generic_probe(struct platform_device *pdev)
 	if (err)
 		return err;
 	if (nop->gpiod_vbus) {
-		err = devm_request_threaded_irq(&pdev->dev,
+		err = devm_request_threaded_irq(dev,
 						gpiod_to_irq(nop->gpiod_vbus),
 						NULL, nop_gpio_vbus_thread,
 						VBUS_IRQ_FLAGS, "vbus_detect",
 						nop);
 		if (err) {
-			dev_err(&pdev->dev, "can't request irq %i, err: %d\n",
+			dev_err(dev, "can't request irq %i, err: %d\n",
 				gpiod_to_irq(nop->gpiod_vbus), err);
 			return err;
 		}
@@ -313,14 +313,13 @@ static int usb_phy_generic_probe(struct platform_device *pdev)
 
 	err = usb_add_phy_dev(&nop->phy);
 	if (err) {
-		dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
-			err);
+		dev_err(dev, "can't register transceiver, err: %d\n", err);
 		return err;
 	}
 
 	platform_set_drvdata(pdev, nop);
 
-	device_set_wakeup_capable(&pdev->dev,
+	device_set_wakeup_capable(dev,
 				  of_property_read_bool(dn, "wakeup-source"));
 
 	return 0;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] usb: phy: generic: Convert to devm_clk_get_optional()
  2026-01-21 14:11 [PATCH 0/4] usb: phy: generic: Miscellaneous improvements Geert Uytterhoeven
  2026-01-21 14:11 ` [PATCH 1/4] usb: phy: generic: Always use dev in usb_phy_generic_probe() Geert Uytterhoeven
@ 2026-01-21 14:11 ` Geert Uytterhoeven
  2026-01-21 14:11 ` [PATCH 3/4] usb: phy: generic: Convert to dev_err_probe() Geert Uytterhoeven
  2026-01-21 14:11 ` [PATCH 4/4] usb: phy: generic: Convert to device property API Geert Uytterhoeven
  3 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2026-01-21 14:11 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-usb, linux-renesas-soc, linux-kernel, Geert Uytterhoeven

The generic USB PHY driver uses the existence of the "clocks" property
to see if a clock is optional or not.  Use devm_clk_get_optional()
instead, which exists for this purpose.  As usb_phy_generic.clk is now
either a valid clock pointer or NULL, and all clock operations handle
NULL pointers gracefully, several IS_ERR() checks can be removed,
simplifying the code.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

...
---
 drivers/usb/phy/phy-generic.c | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
index 13bd16668932dc90..53b0262e6e306ada 100644
--- a/drivers/usb/phy/phy-generic.c
+++ b/drivers/usb/phy/phy-generic.c
@@ -49,15 +49,13 @@ static int nop_set_suspend(struct usb_phy *x, int suspend)
 	int ret = 0;
 
 	if (suspend) {
-		if (!IS_ERR(nop->clk))
-			clk_disable_unprepare(nop->clk);
+		clk_disable_unprepare(nop->clk);
 		if (!IS_ERR(nop->vcc) && !device_may_wakeup(x->dev))
 			ret = regulator_disable(nop->vcc);
 	} else {
 		if (!IS_ERR(nop->vcc) && !device_may_wakeup(x->dev))
 			ret = regulator_enable(nop->vcc);
-		if (!IS_ERR(nop->clk))
-			clk_prepare_enable(nop->clk);
+		clk_prepare_enable(nop->clk);
 	}
 
 	return ret;
@@ -137,11 +135,9 @@ int usb_gen_phy_init(struct usb_phy *phy)
 			dev_err(phy->dev, "Failed to enable power\n");
 	}
 
-	if (!IS_ERR(nop->clk)) {
-		ret = clk_prepare_enable(nop->clk);
-		if (ret)
-			return ret;
-	}
+	ret = clk_prepare_enable(nop->clk);
+	if (ret)
+		return ret;
 
 	nop_reset(nop);
 
@@ -155,8 +151,7 @@ void usb_gen_phy_shutdown(struct usb_phy *phy)
 
 	gpiod_set_value_cansleep(nop->gpiod_reset, 1);
 
-	if (!IS_ERR(nop->clk))
-		clk_disable_unprepare(nop->clk);
+	clk_disable_unprepare(nop->clk);
 
 	if (!IS_ERR(nop->vcc)) {
 		if (regulator_disable(nop->vcc))
@@ -202,17 +197,13 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop)
 {
 	enum usb_phy_type type = USB_PHY_TYPE_USB2;
 	int err = 0;
-
 	u32 clk_rate = 0;
-	bool needs_clk = false;
 
 	if (dev->of_node) {
 		struct device_node *node = dev->of_node;
 
 		if (of_property_read_u32(node, "clock-frequency", &clk_rate))
 			clk_rate = 0;
-
-		needs_clk = of_property_present(node, "clocks");
 	}
 	nop->gpiod_reset = devm_gpiod_get_optional(dev, "reset",
 						   GPIOD_ASIS);
@@ -235,15 +226,14 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop)
 	if (!nop->phy.otg)
 		return -ENOMEM;
 
-	nop->clk = devm_clk_get(dev, "main_clk");
+	nop->clk = devm_clk_get_optional(dev, "main_clk");
 	if (IS_ERR(nop->clk)) {
 		dev_dbg(dev, "Can't get phy clock: %ld\n",
 					PTR_ERR(nop->clk));
-		if (needs_clk)
-			return PTR_ERR(nop->clk);
+		return PTR_ERR(nop->clk);
 	}
 
-	if (!IS_ERR(nop->clk) && clk_rate) {
+	if (clk_rate) {
 		err = clk_set_rate(nop->clk, clk_rate);
 		if (err) {
 			dev_err(dev, "Error setting clock rate\n");
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] usb: phy: generic: Convert to dev_err_probe()
  2026-01-21 14:11 [PATCH 0/4] usb: phy: generic: Miscellaneous improvements Geert Uytterhoeven
  2026-01-21 14:11 ` [PATCH 1/4] usb: phy: generic: Always use dev in usb_phy_generic_probe() Geert Uytterhoeven
  2026-01-21 14:11 ` [PATCH 2/4] usb: phy: generic: Convert to devm_clk_get_optional() Geert Uytterhoeven
@ 2026-01-21 14:11 ` Geert Uytterhoeven
  2026-01-21 14:11 ` [PATCH 4/4] usb: phy: generic: Convert to device property API Geert Uytterhoeven
  3 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2026-01-21 14:11 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-usb, linux-renesas-soc, linux-kernel, Geert Uytterhoeven

Convert the remaining error handling in the probe path to use the
dev_err_probe() helper, to make sure error messages and codes are not
missed, and recorded properly.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/usb/phy/phy-generic.c | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
index 53b0262e6e306ada..9f3a38b93f2649a8 100644
--- a/drivers/usb/phy/phy-generic.c
+++ b/drivers/usb/phy/phy-generic.c
@@ -227,18 +227,15 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop)
 		return -ENOMEM;
 
 	nop->clk = devm_clk_get_optional(dev, "main_clk");
-	if (IS_ERR(nop->clk)) {
-		dev_dbg(dev, "Can't get phy clock: %ld\n",
-					PTR_ERR(nop->clk));
-		return PTR_ERR(nop->clk);
-	}
+	if (IS_ERR(nop->clk))
+		return dev_err_probe(dev, PTR_ERR(nop->clk),
+				     "Can't get phy clock\n");
 
 	if (clk_rate) {
 		err = clk_set_rate(nop->clk, clk_rate);
-		if (err) {
-			dev_err(dev, "Error setting clock rate\n");
-			return err;
-		}
+		if (err)
+			return dev_err_probe(dev, err,
+					     "Error setting clock rate\n");
 	}
 
 	nop->vcc = devm_regulator_get_optional(dev, "vcc");
@@ -283,17 +280,17 @@ static int usb_phy_generic_probe(struct platform_device *pdev)
 	err = usb_phy_gen_create_phy(dev, nop);
 	if (err)
 		return err;
+
 	if (nop->gpiod_vbus) {
 		err = devm_request_threaded_irq(dev,
 						gpiod_to_irq(nop->gpiod_vbus),
 						NULL, nop_gpio_vbus_thread,
 						VBUS_IRQ_FLAGS, "vbus_detect",
 						nop);
-		if (err) {
-			dev_err(dev, "can't request irq %i, err: %d\n",
-				gpiod_to_irq(nop->gpiod_vbus), err);
-			return err;
-		}
+		if (err)
+			return dev_err_probe(dev, err, "can't request irq %i\n",
+					     gpiod_to_irq(nop->gpiod_vbus));
+
 		nop->phy.otg->state = gpiod_get_value(nop->gpiod_vbus) ?
 			OTG_STATE_B_PERIPHERAL : OTG_STATE_B_IDLE;
 	}
@@ -302,10 +299,8 @@ static int usb_phy_generic_probe(struct platform_device *pdev)
 	nop->phy.shutdown	= usb_gen_phy_shutdown;
 
 	err = usb_add_phy_dev(&nop->phy);
-	if (err) {
-		dev_err(dev, "can't register transceiver, err: %d\n", err);
-		return err;
-	}
+	if (err)
+		return dev_err_probe(dev, err, "can't register transceiver\n");
 
 	platform_set_drvdata(pdev, nop);
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] usb: phy: generic: Convert to device property API
  2026-01-21 14:11 [PATCH 0/4] usb: phy: generic: Miscellaneous improvements Geert Uytterhoeven
                   ` (2 preceding siblings ...)
  2026-01-21 14:11 ` [PATCH 3/4] usb: phy: generic: Convert to dev_err_probe() Geert Uytterhoeven
@ 2026-01-21 14:11 ` Geert Uytterhoeven
  3 siblings, 0 replies; 5+ messages in thread
From: Geert Uytterhoeven @ 2026-01-21 14:11 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-usb, linux-renesas-soc, linux-kernel, Geert Uytterhoeven

Convert from OF properties to device properties, to make the driver more
generic and simpler.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/usb/phy/phy-generic.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
index 9f3a38b93f2649a8..de26b302334de974 100644
--- a/drivers/usb/phy/phy-generic.c
+++ b/drivers/usb/phy/phy-generic.c
@@ -20,7 +20,7 @@
 #include <linux/slab.h>
 #include <linux/clk.h>
 #include <linux/regulator/consumer.h>
-#include <linux/of.h>
+#include <linux/property.h>
 #include <linux/gpio/consumer.h>
 #include <linux/delay.h>
 
@@ -199,12 +199,7 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop)
 	int err = 0;
 	u32 clk_rate = 0;
 
-	if (dev->of_node) {
-		struct device_node *node = dev->of_node;
-
-		if (of_property_read_u32(node, "clock-frequency", &clk_rate))
-			clk_rate = 0;
-	}
+	device_property_read_u32(dev, "clock-frequency", &clk_rate);
 	nop->gpiod_reset = devm_gpiod_get_optional(dev, "reset",
 						   GPIOD_ASIS);
 	err = PTR_ERR_OR_ZERO(nop->gpiod_reset);
@@ -269,7 +264,6 @@ EXPORT_SYMBOL_GPL(usb_phy_gen_create_phy);
 static int usb_phy_generic_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *dn = dev->of_node;
 	struct usb_phy_generic	*nop;
 	int err;
 
@@ -305,7 +299,7 @@ static int usb_phy_generic_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, nop);
 
 	device_set_wakeup_capable(dev,
-				  of_property_read_bool(dn, "wakeup-source"));
+				  device_property_read_bool(dev, "wakeup-source"));
 
 	return 0;
 }
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-01-21 14:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-21 14:11 [PATCH 0/4] usb: phy: generic: Miscellaneous improvements Geert Uytterhoeven
2026-01-21 14:11 ` [PATCH 1/4] usb: phy: generic: Always use dev in usb_phy_generic_probe() Geert Uytterhoeven
2026-01-21 14:11 ` [PATCH 2/4] usb: phy: generic: Convert to devm_clk_get_optional() Geert Uytterhoeven
2026-01-21 14:11 ` [PATCH 3/4] usb: phy: generic: Convert to dev_err_probe() Geert Uytterhoeven
2026-01-21 14:11 ` [PATCH 4/4] usb: phy: generic: Convert to device property API Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®