diff mbox series

[3/8] phy: nop-phy: add optional clk

Message ID 20201012062354.3743-4-peng.fan@nxp.com
State Changes Requested
Delegated to: Stefano Babic
Headers show
Series i.MX8MM: add host/gadget support | expand

Commit Message

Peng Fan Oct. 12, 2020, 6:23 a.m. UTC
Add optional clk for nop phy

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/phy/nop-phy.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

Comments

Marek Vasut Oct. 12, 2020, 8:52 a.m. UTC | #1
On 10/12/20 8:23 AM, Peng Fan wrote:
[...]
> +static int nop_phy_probe(struct udevice *dev)
> +{
> +	struct nop_phy_priv *priv = dev_get_priv(dev);
> +	int ret;
> +
> +	if (CONFIG_IS_ENABLED(CLK)) {
> +		ret = clk_get_by_name(dev, "main_clk", &priv->nop_clk);

So is this main_clk or nop_clk ?

Wouldn't it be better if the NOP PHY used the clk_bulk and enabled all
clock described in DT ?
Peng Fan Oct. 12, 2020, 9:12 a.m. UTC | #2
> Subject: Re: [PATCH 3/8] phy: nop-phy: add optional clk
> 
> On 10/12/20 8:23 AM, Peng Fan wrote:
> [...]
> > +static int nop_phy_probe(struct udevice *dev) {
> > +	struct nop_phy_priv *priv = dev_get_priv(dev);
> > +	int ret;
> > +
> > +	if (CONFIG_IS_ENABLED(CLK)) {
> > +		ret = clk_get_by_name(dev, "main_clk", &priv->nop_clk);
> 
> So is this main_clk or nop_clk ?
> 
> Wouldn't it be better if the NOP PHY used the clk_bulk and enabled all clock
> described in DT ?

Bulk seems better.

Thanks,
Peng.
diff mbox series

Patch

diff --git a/drivers/phy/nop-phy.c b/drivers/phy/nop-phy.c
index a5eed20f3f..a1afdef736 100644
--- a/drivers/phy/nop-phy.c
+++ b/drivers/phy/nop-phy.c
@@ -4,17 +4,49 @@ 
  * Written by Jean-Jacques Hiblot  <jjhiblot@ti.com>
  */
 
+#include <clk.h>
 #include <common.h>
 #include <dm.h>
 #include <dm/device.h>
 #include <generic-phy.h>
 
+struct nop_phy_priv {
+	struct clk nop_clk;
+};
+
+static int nop_phy_init(struct phy *phy)
+{
+	struct nop_phy_priv *priv = dev_get_priv(phy->dev);
+
+	if (!clk_valid(&priv->nop_clk))
+		return 0;
+
+	return clk_enable(&priv->nop_clk);
+}
+
+static int nop_phy_probe(struct udevice *dev)
+{
+	struct nop_phy_priv *priv = dev_get_priv(dev);
+	int ret;
+
+	if (CONFIG_IS_ENABLED(CLK)) {
+		ret = clk_get_by_name(dev, "main_clk", &priv->nop_clk);
+		if (ret < 0 && ret != -ENODATA) {
+			dev_err(dev, "Failed to get main_clk: %d\n", ret);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
 static const struct udevice_id nop_phy_ids[] = {
 	{ .compatible = "nop-phy" },
 	{ }
 };
 
 static struct phy_ops nop_phy_ops = {
+	.init = nop_phy_init,
 };
 
 U_BOOT_DRIVER(nop_phy) = {
@@ -22,4 +54,6 @@  U_BOOT_DRIVER(nop_phy) = {
 	.id	= UCLASS_PHY,
 	.of_match = nop_phy_ids,
 	.ops = &nop_phy_ops,
+	.probe = nop_phy_probe,
+	.priv_auto_alloc_size = sizeof(struct nop_phy_priv),
 };