[PATCH 2/2] net: fec: probe phy_mode from devicetree

Sascha Hauer s.hauer at pengutronix.de
Tue Mar 26 05:15:16 EDT 2013


This allows to parse the phy mode from the devicetree.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/net/fec_imx.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index 37d88cd..1a85d15 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -26,6 +26,7 @@
 #include <linux/phy.h>
 #include <linux/clk.h>
 #include <linux/err.h>
+#include <of_net.h>
 
 #include <asm/mmu.h>
 
@@ -628,6 +629,25 @@ static int fec_alloc_receive_packets(struct fec_priv *fec, int count, int size)
 	return 0;
 }
 
+#ifdef CONFIG_OFDEVICE
+static int fec_probe_dt(struct device_d *dev, struct fec_priv *fec)
+{
+	int ret;
+
+	ret = of_get_phy_mode(dev->device_node);
+	if (ret < 0)
+		fec->interface = PHY_INTERFACE_MODE_MII;
+	else
+		fec->interface = ret;
+
+	return 0;
+}
+#else
+static int fec_probe_dt(struct device_d *dev, struct fec_priv *fec)
+{
+	return -ENODEV;
+}
+#endif
 static int fec_probe(struct device_d *dev)
 {
         struct fec_platform_data *pdata = (struct fec_platform_data *)dev->platform_data;
@@ -685,7 +705,9 @@ static int fec_probe(struct device_d *dev)
 
 	fec_alloc_receive_packets(fec, FEC_RBD_NUM, FEC_MAX_PKT_SIZE);
 
-	if (pdata) {
+	if (dev->device_node) {
+		ret = fec_probe_dt(dev, fec);
+	} else if (pdata) {
 		fec->interface = pdata->xcv_type;
 		fec->phy_init = pdata->phy_init;
 		fec->phy_addr = pdata->phy_addr;
@@ -694,6 +716,9 @@ static int fec_probe(struct device_d *dev)
 		fec->phy_addr = -1;
 	}
 
+	if (ret)
+		goto err_free;
+
 	fec_init(edev);
 
 	fec->miibus.read = fec_miibus_read;
-- 
1.8.2.rc2




More information about the barebox mailing list