[PATCH rtems-libbsd v2 1/2] freebsd/cgem: Add phy address to read it from device tree

Padmarao Begari padmarao.begari at microchip.com
Fri Mar 3 15:53:46 UTC 2023


Read the phy address from the device tree and use it to
find the phy device if not found then search in the
range of 0 to 31.
---
 freebsd/sys/dev/cadence/if_cgem.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/freebsd/sys/dev/cadence/if_cgem.c b/freebsd/sys/dev/cadence/if_cgem.c
index 689c3611..0aab0771 100644
--- a/freebsd/sys/dev/cadence/if_cgem.c
+++ b/freebsd/sys/dev/cadence/if_cgem.c
@@ -1217,6 +1217,27 @@ cgem_intr(void *arg)
 	CGEM_UNLOCK(sc);
 }
 
+#ifdef __rtems__
+static int
+cgem_get_phyaddr(phandle_t node)
+{
+	phandle_t phy_node;
+	pcell_t phy_handle, phy_reg;
+
+	if (OF_getencprop(node, "phy-handle", (void *)&phy_handle,
+		sizeof(phy_handle)) <= 0)
+		return (MII_PHY_ANY);
+
+	phy_node = OF_node_from_xref(phy_handle);
+
+	if (OF_getencprop(phy_node, "reg", (void *)&phy_reg,
+		sizeof(phy_reg)) <= 0)
+		return (MII_PHY_ANY);
+
+	return (phy_reg);
+}
+#endif /* __rtems__ */
+
 /* Reset hardware. */
 static void
 cgem_reset(struct cgem_softc *sc)
@@ -2091,10 +2112,19 @@ cgem_attach(device_t dev)
 	cgem_reset(sc);
 	CGEM_UNLOCK(sc);
 
+#ifdef __rtems__
+	int phy_addr = cgem_get_phyaddr(node);
+#endif /* __rtems__ */
+
 	/* Attach phy to mii bus. */
 	err = mii_attach(dev, &sc->miibus, ifp,
 			 cgem_ifmedia_upd, cgem_ifmedia_sts,
+#ifdef __rtems__
+			 BMSR_DEFCAPMASK, phy_addr, MII_OFFSET_ANY, 0);
+#else /* __rtems__ */
 			 BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);
+#endif /* __rtems__ */
+
 	if (err) {
 		device_printf(dev, "attaching PHYs failed\n");
 		cgem_detach(dev);
-- 
2.25.1



More information about the devel mailing list