All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adam Ford <aford173@gmail.com>
To: u-boot@lists.denx.de
Cc: marex@denx.de, trini@konsulko.com, aford@beaconembedded.com,
	Adam Ford <aford173@gmail.com>
Subject: [PATCH V3] phy: nop-phy: Enable reset-gpios support
Date: Sat, 22 Jan 2022 12:02:02 -0600	[thread overview]
Message-ID: <20220122180202.13583-1-aford173@gmail.com> (raw)

Some usb-nop-xceiv devices use a gpio to put them in and
out of reset.  Add a reset function to put them into that
state.  This is similar to how Linux handles the
usb-nop-xceiv driver.

Signed-off-by: Adam Ford <aford173@gmail.com>
---
V3:  Encapsulate the nop_phy_ops reference to nop_phy_reset
     in an if-def so it doesn't appear when DM_GPIO is not
     enabled.

V2:  Only use the GPIO functions when DM_GPIO is enabled
     Add error handling so if the GPIO fails, it will shutdown
     the clocks and return with the error code.
     Call nop_phy_reset() instead of repeating the same code.

diff --git a/drivers/phy/nop-phy.c b/drivers/phy/nop-phy.c
index 9f12ebc062..eac00953d3 100644
--- a/drivers/phy/nop-phy.c
+++ b/drivers/phy/nop-phy.c
@@ -10,17 +10,47 @@
 #include <dm/device.h>
 #include <dm/device_compat.h>
 #include <generic-phy.h>
+#include <asm-generic/gpio.h>
 
 struct nop_phy_priv {
 	struct clk_bulk bulk;
+#if CONFIG_IS_ENABLED(DM_GPIO)
+	struct gpio_desc reset_gpio;
+#endif
 };
 
+#if CONFIG_IS_ENABLED(DM_GPIO)
+static int nop_phy_reset(struct phy *phy)
+{
+	struct nop_phy_priv *priv = dev_get_priv(phy->dev);
+
+	/* Return if there is no gpio since it's optional */
+	if (!dm_gpio_is_valid(&priv->reset_gpio))
+		return 0;
+
+	return dm_gpio_set_value(&priv->reset_gpio, false);
+}
+#endif
+
 static int nop_phy_init(struct phy *phy)
 {
 	struct nop_phy_priv *priv = dev_get_priv(phy->dev);
+	int ret = 0;
+
+	if (CONFIG_IS_ENABLED(CLK)) {
+		ret = clk_enable_bulk(&priv->bulk);
+		if (ret)
+			return ret;
+	}
 
-	if (CONFIG_IS_ENABLED(CLK))
-		return clk_enable_bulk(&priv->bulk);
+	if (CONFIG_IS_ENABLED(DM_GPIO)) {
+		ret = nop_phy_reset(phy);
+		if (ret) {
+			if (CONFIG_IS_ENABLED(CLK))
+				clk_disable_bulk(&priv->bulk);
+			return ret;
+		}
+	}
 
 	return 0;
 }
@@ -38,6 +68,12 @@ static int nop_phy_probe(struct udevice *dev)
 		}
 	}
 
+	ret = gpio_request_by_name(dev, "reset-gpios", 0,
+				   &priv->reset_gpio,
+				   GPIOD_IS_OUT);
+	if (ret != -ENOENT)
+		return ret;
+
 	return 0;
 }
 
@@ -49,6 +85,9 @@ static const struct udevice_id nop_phy_ids[] = {
 
 static struct phy_ops nop_phy_ops = {
 	.init = nop_phy_init,
+#if CONFIG_IS_ENABLED(DM_GPIO)
+	.reset = nop_phy_reset,
+#endif
 };
 
 U_BOOT_DRIVER(nop_phy) = {
-- 
2.32.0


             reply	other threads:[~2022-01-22 18:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-22 18:02 Adam Ford [this message]
2022-01-29 12:50 ` [PATCH V3] phy: nop-phy: Enable reset-gpios support Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220122180202.13583-1-aford173@gmail.com \
    --to=aford173@gmail.com \
    --cc=aford@beaconembedded.com \
    --cc=marex@denx.de \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.