summaryrefslogtreecommitdiffstats
path: root/drivers/net/fec_mxc.c
diff options
context:
space:
mode:
authorMartyn Welch <martyn@welchs.me.uk>2018-12-11 11:34:45 +0000
committerStefano Babic <sbabic@denx.de>2019-01-28 12:47:15 +0100
commit774ec60b74a7b8d356a2ec6249936b097631a726 (patch)
treec5e2836885dd10de91775d7b34721cc1d32a80ea /drivers/net/fec_mxc.c
parentb2ca8907d92434300e081e0f23ec589a2de1be9f (diff)
downloadu-boot-774ec60b74a7b8d356a2ec6249936b097631a726.tar.gz
u-boot-774ec60b74a7b8d356a2ec6249936b097631a726.tar.xz
u-boot-774ec60b74a7b8d356a2ec6249936b097631a726.zip
Enable FEC driver to retrieve PHY address from device tree
Currently if we have more than one phy on the MDIO bus, we do not have a good mechanism for determining which should be used at runtime. Enable the FEC driver to determine the address for the PHY from the device tree. Signed-off-by: Martyn Welch <martyn.welch@collabora.com> Reviewed-by: Lukasz Majewski <lukma@denx.de>
Diffstat (limited to 'drivers/net/fec_mxc.c')
-rw-r--r--drivers/net/fec_mxc.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c
index 32fb34b793..1a59026a62 100644
--- a/drivers/net/fec_mxc.c
+++ b/drivers/net/fec_mxc.c
@@ -1264,11 +1264,32 @@ static const struct eth_ops fecmxc_ops = {
.read_rom_hwaddr = fecmxc_read_rom_hwaddr,
};
+static int device_get_phy_addr(struct udevice *dev)
+{
+ struct ofnode_phandle_args phandle_args;
+ int reg;
+
+ if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
+ &phandle_args)) {
+ debug("Failed to find phy-handle");
+ return -ENODEV;
+ }
+
+ reg = ofnode_read_u32_default(phandle_args.node, "reg", 0);
+
+ return reg;
+}
+
static int fec_phy_init(struct fec_priv *priv, struct udevice *dev)
{
struct phy_device *phydev;
+ int addr;
int mask = 0xffffffff;
+ addr = device_get_phy_addr(dev);
+ if (addr >= 0)
+ mask = 1 << addr;
+
#ifdef CONFIG_FEC_MXC_PHYADDR
mask = 1 << CONFIG_FEC_MXC_PHYADDR;
#endif