diff mbox series

[06/20] of: extra: Introduce ofnode_phy_is_fixed_link() API

Message ID 20210302153451.19440-7-bmeng.cn@gmail.com
State Superseded
Delegated to: Priyanka Jain
Headers show
Series ppc: qemu: Add eTSEC support | expand

Commit Message

Bin Meng March 2, 2021, 3:34 p.m. UTC
Introduce a helper API ofnode_phy_is_fixed_link() to detect whether
the ethernet controller connects to a fixed-link pseudo-PHY device.

Note there are two ways to describe a fixed PHY attached to an
Ethernet device:

- the new DT binding, where 'fixed-link' is a sub-node of the
  Ethernet device
- the old DT binding, where 'fixed-link' is a property with 5
  cells encoding various information about the fixed PHY

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 drivers/core/of_extra.c | 26 ++++++++++++++++++++++++++
 include/dm/of_extra.h   | 18 ++++++++++++++++++
 2 files changed, 44 insertions(+)

Comments

Simon Glass March 5, 2021, 4:08 a.m. UTC | #1
+Joe Hershberger

On Tue, 2 Mar 2021 at 10:35, Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Introduce a helper API ofnode_phy_is_fixed_link() to detect whether
> the ethernet controller connects to a fixed-link pseudo-PHY device.
>
> Note there are two ways to describe a fixed PHY attached to an
> Ethernet device:
>
> - the new DT binding, where 'fixed-link' is a sub-node of the
>   Ethernet device
> - the old DT binding, where 'fixed-link' is a property with 5
>   cells encoding various information about the fixed PHY
>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> ---
>
>  drivers/core/of_extra.c | 26 ++++++++++++++++++++++++++
>  include/dm/of_extra.h   | 18 ++++++++++++++++++
>  2 files changed, 44 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

Is the binding in U-Boot?
Bin Meng March 9, 2021, 2:41 a.m. UTC | #2
Hi Simon,

On Fri, Mar 5, 2021 at 12:08 PM Simon Glass <sjg@chromium.org> wrote:
>
> +Joe Hershberger
>
> On Tue, 2 Mar 2021 at 10:35, Bin Meng <bmeng.cn@gmail.com> wrote:
> >
> > Introduce a helper API ofnode_phy_is_fixed_link() to detect whether
> > the ethernet controller connects to a fixed-link pseudo-PHY device.
> >
> > Note there are two ways to describe a fixed PHY attached to an
> > Ethernet device:
> >
> > - the new DT binding, where 'fixed-link' is a sub-node of the
> >   Ethernet device
> > - the old DT binding, where 'fixed-link' is a property with 5
> >   cells encoding various information about the fixed PHY
> >
> > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> > ---
> >
> >  drivers/core/of_extra.c | 26 ++++++++++++++++++++++++++
> >  include/dm/of_extra.h   | 18 ++++++++++++++++++
> >  2 files changed, 44 insertions(+)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> Is the binding in U-Boot?

Yes, in patch 5:

dt-bindings: net: Add the old DT bindings for "fixed-link"
http://patchwork.ozlabs.org/project/uboot/patch/20210302153451.19440-6-bmeng.cn@gmail.com/

Regards,
Bin
diff mbox series

Patch

diff --git a/drivers/core/of_extra.c b/drivers/core/of_extra.c
index 653344529e..a16f9a8dc1 100644
--- a/drivers/core/of_extra.c
+++ b/drivers/core/of_extra.c
@@ -130,3 +130,29 @@  int ofnode_decode_memory_region(ofnode config_node, const char *mem_type,
 
 	return 0;
 }
+
+bool ofnode_phy_is_fixed_link(ofnode eth_node, ofnode *phy_node)
+{
+	bool found = false;
+	ofnode node, subnode;
+	int len;
+
+	/* new binding */
+	subnode = ofnode_find_subnode(eth_node, "fixed-link");
+	if (ofnode_valid(subnode)) {
+		node = subnode;
+		found = true;
+	}
+
+	/* old binding */
+	if (ofnode_get_property(eth_node, "fixed-link", &len) &&
+	    len == (5 * sizeof(__be32))) {
+		node = eth_node;
+		found = true;
+	}
+
+	if (found && phy_node)
+		*phy_node = node;
+
+	return found;
+}
diff --git a/include/dm/of_extra.h b/include/dm/of_extra.h
index ca15df21b0..3641f68fe3 100644
--- a/include/dm/of_extra.h
+++ b/include/dm/of_extra.h
@@ -86,4 +86,22 @@  int ofnode_decode_memory_region(ofnode config_node, const char *mem_type,
 				const char *suffix, fdt_addr_t *basep,
 				fdt_size_t *sizep);
 
+/**
+ * ofnode_phy_is_fixed_link() - Detect fixed-link pseudo-PHY device
+ *
+ * This function detects whether the ethernet controller connects to a
+ * fixed-link pseudo-PHY device.
+ *
+ * This function supports the following two DT bindings:
+ * - the new DT binding, where 'fixed-link' is a sub-node of the
+ *   Ethernet device
+ * - the old DT binding, where 'fixed-link' is a property with 5
+ *   cells encoding various information about the fixed PHY
+ *
+ * @param eth_node	ofnode containing the fixed-link subnode/property
+ * @param phy_node	if fixed-link PHY detected, containing the PHY ofnode
+ * @return true if a fixed-link pseudo-PHY device exists, false otherwise
+ */
+bool ofnode_phy_is_fixed_link(ofnode eth_node, ofnode *phy_node);
+
 #endif