diff mbox series

[v2,1/8] phy: generic: add error trace to detect PHY issue in uclass

Message ID 20200218083836.6369-1-patrick.delaunay@st.com
State New
Headers show
Series [v2,1/8] phy: generic: add error trace to detect PHY issue in uclass | expand

Commit Message

Patrick Delaunay Feb. 18, 2020, 8:38 a.m. UTC
Add an error trace for PHY errors directly in generic phy
functions provided by PHY uclass.

Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
---

This patch is requested by Marek Vasut to avoid code duplication
in usb host serie for dwc2:

See http://patchwork.ozlabs.org/patch/1176048/#2297595
[U-Boot,RESEND,1/5] usb: host: dwc2: add phy support


Changes in v2:
- Rebase and add include dm/device_compat.h

 drivers/phy/phy-uclass.c | 41 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 36 insertions(+), 5 deletions(-)

Comments

Marek Vasut Feb. 18, 2020, 5:40 p.m. UTC | #1
On 2/18/20 9:38 AM, Patrick Delaunay wrote:
[...]
>  static inline struct phy_ops *phy_dev_ops(struct udevice *dev)
>  {
> @@ -109,56 +110,86 @@ int generic_phy_get_by_name(struct udevice *dev, const char *phy_name,
>  int generic_phy_init(struct phy *phy)
>  {
>  	struct phy_ops const *ops;
> +	int ret;
>  
>  	if (!phy)
>  		return 0;
>  	ops = phy_dev_ops(phy->dev);
>  
> -	return ops->init ? ops->init(phy) : 0;
> +	ret = ops->init ? ops->init(phy) : 0;

if (!ops->init)
   return 0;
ret = ops->init();
if (ret)
   dev_err...

return ret;

Please fix globally.

> +	if (ret)
> +		dev_err(phy->dev, "PHY: Failed to init %s: %d.\n",
> +			phy->dev->name, ret);
> +
> +	return ret;
[...]
Patrick Delaunay Feb. 21, 2020, 2:37 p.m. UTC | #2
Hi Marek,

> From: Marek Vasut <marex at denx.de>
> Sent: mardi 18 f?vrier 2020 18:40
> 
> On 2/18/20 9:38 AM, Patrick Delaunay wrote:
> [...]
> >  static inline struct phy_ops *phy_dev_ops(struct udevice *dev)  { @@
> > -109,56 +110,86 @@ int generic_phy_get_by_name(struct udevice *dev,
> > const char *phy_name,  int generic_phy_init(struct phy *phy)  {
> >  	struct phy_ops const *ops;
> > +	int ret;
> >
> >  	if (!phy)
> >  		return 0;
> >  	ops = phy_dev_ops(phy->dev);
> >
> > -	return ops->init ? ops->init(phy) : 0;
> > +	ret = ops->init ? ops->init(phy) : 0;
> 
> if (!ops->init)
>    return 0;
> ret = ops->init();
> if (ret)
>    dev_err...
> 
> return ret;
> 
> Please fix globally.

Yes it is more clear, I am the v3 serie
 
> > +	if (ret)
> > +		dev_err(phy->dev, "PHY: Failed to init %s: %d.\n",
> > +			phy->dev->name, ret);
> > +
> > +	return ret;
> [...]

Regards,

Patrick
diff mbox series

Patch

diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c
index e201a90c8c..f4a602fbd0 100644
--- a/drivers/phy/phy-uclass.c
+++ b/drivers/phy/phy-uclass.c
@@ -7,6 +7,7 @@ 
 #include <common.h>
 #include <dm.h>
 #include <generic-phy.h>
+#include <dm/device_compat.h>
 
 static inline struct phy_ops *phy_dev_ops(struct udevice *dev)
 {
@@ -109,56 +110,86 @@  int generic_phy_get_by_name(struct udevice *dev, const char *phy_name,
 int generic_phy_init(struct phy *phy)
 {
 	struct phy_ops const *ops;
+	int ret;
 
 	if (!phy)
 		return 0;
 	ops = phy_dev_ops(phy->dev);
 
-	return ops->init ? ops->init(phy) : 0;
+	ret = ops->init ? ops->init(phy) : 0;
+	if (ret)
+		dev_err(phy->dev, "PHY: Failed to init %s: %d.\n",
+			phy->dev->name, ret);
+
+	return ret;
 }
 
 int generic_phy_reset(struct phy *phy)
 {
 	struct phy_ops const *ops;
+	int ret;
 
 	if (!phy)
 		return 0;
 	ops = phy_dev_ops(phy->dev);
 
-	return ops->reset ? ops->reset(phy) : 0;
+	ret = ops->reset ? ops->reset(phy) : 0;
+	if (ret)
+		dev_err(phy->dev, "PHY: Failed to reset %s: %d.\n",
+			phy->dev->name, ret);
+
+	return ret;
 }
 
 int generic_phy_exit(struct phy *phy)
 {
 	struct phy_ops const *ops;
+	int ret;
 
 	if (!phy)
 		return 0;
 	ops = phy_dev_ops(phy->dev);
 
-	return ops->exit ? ops->exit(phy) : 0;
+	ret = ops->exit ? ops->exit(phy) : 0;
+	if (ret)
+		dev_err(phy->dev, "PHY: Failed to exit %s: %d.\n",
+			phy->dev->name, ret);
+
+	return ret;
 }
 
 int generic_phy_power_on(struct phy *phy)
 {
 	struct phy_ops const *ops;
+	int ret;
 
 	if (!phy)
 		return 0;
 	ops = phy_dev_ops(phy->dev);
 
-	return ops->power_on ? ops->power_on(phy) : 0;
+	ret = ops->power_on ? ops->power_on(phy) : 0;
+	if (ret)
+		dev_err(phy->dev, "PHY: Failed to power on %s: %d.\n",
+			phy->dev->name, ret);
+
+	return ret;
 }
 
 int generic_phy_power_off(struct phy *phy)
 {
 	struct phy_ops const *ops;
+	int ret;
 
 	if (!phy)
 		return 0;
 	ops = phy_dev_ops(phy->dev);
 
-	return ops->power_off ? ops->power_off(phy) : 0;
+	ret = ops->power_off ? ops->power_off(phy) : 0;
+	if (ret)
+		dev_err(phy->dev, "PHY: Failed to power off %s: %d.\n",
+			phy->dev->name, ret);
+
+	return ret;
 }
 
 UCLASS_DRIVER(phy) = {