]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
of: extra: Introduce ofnode_phy_is_fixed_link() API
authorBin Meng <bmeng.cn@gmail.com>
Sun, 14 Mar 2021 12:14:46 +0000 (20:14 +0800)
committerPriyanka Jain <priyanka.jain@nxp.com>
Thu, 15 Apr 2021 08:52:17 +0000 (14:22 +0530)
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>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Priyanka Jain <priyanka.jain@nxp.com>
drivers/core/of_extra.c
include/dm/of_extra.h

index 653344529e6982cd245cae2b8d4a04185e31c2ec..7702beff97b09991e5864f9716d1b0120e122a94 100644 (file)
@@ -130,3 +130,26 @@ 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)
+{
+       ofnode node, subnode;
+       int len;
+
+       subnode = ofnode_find_subnode(eth_node, "fixed-link");
+       if (ofnode_valid(subnode)) {
+               /* new binding */
+               node = subnode;
+       } else if (ofnode_get_property(eth_node, "fixed-link", &len) &&
+                  len == (5 * sizeof(__be32))) {
+               /* old binding */
+               node = eth_node;
+       } else {
+               return false;
+       }
+
+       if (phy_node)
+               *phy_node = node;
+
+       return true;
+}
index fc4f97431967bf75a8916778a17b5e5a6994052c..f0d205491c16f7e76f6cbd01fb5c0bd165ac5fcb 100644 (file)
@@ -94,4 +94,24 @@ 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
+ *
+ * If both new and old bindings exist, the new one is preferred.
+ *
+ * @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