diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-05-21 11:56:12 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-05-21 14:42:17 +0200 |
commit | 4778c7da3786cab7ee6c453fa19149e8b995bdf3 (patch) | |
tree | 72e51994a389ce6dc29bbc3e366b7bb9ac9b8b83 /drivers | |
parent | 9cbfe615f9a0784dc1186a9cc117bc40111d0db9 (diff) | |
download | barebox-4778c7da3786cab7ee6c453fa19149e8b995bdf3.tar.gz barebox-4778c7da3786cab7ee6c453fa19149e8b995bdf3.tar.xz |
net: phy: Support limiting phy speed in the devicetree
Even when both the ethernet controller and the phy support certain
features a board may have additional limitations. Allow specifying
it in the devicetree.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/phy/mdio_bus.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index ca016736d2..f526cfcd89 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -242,6 +242,39 @@ static struct file_operations phydev_ops = { .lseek = dev_lseek_default, }; +static void of_set_phy_supported(struct phy_device *phydev) +{ + struct device_node *node = phydev->dev.device_node; + u32 max_speed; + + if (!IS_ENABLED(CONFIG_OFDEVICE)) + return; + + if (!node) + return; + + if (!of_property_read_u32(node, "max-speed", &max_speed)) { + /* + * The default values for phydev->supported are provided by the PHY + * driver "features" member, we want to reset to sane defaults first + * before supporting higher speeds. + */ + phydev->supported &= PHY_DEFAULT_FEATURES; + + switch (max_speed) { + default: + return; + + case SPEED_1000: + phydev->supported |= PHY_1000BT_FEATURES; + case SPEED_100: + phydev->supported |= PHY_100BT_FEATURES; + case SPEED_10: + phydev->supported |= PHY_10BT_FEATURES; + } + } +} + static int mdio_bus_probe(struct device_d *_dev) { struct phy_device *dev = to_phy_device(_dev); @@ -275,7 +308,8 @@ static int mdio_bus_probe(struct device_d *_dev) * a controller will attach, and may modify one * or both of these values */ dev->supported = drv->features; - dev->advertising = drv->features; + of_set_phy_supported(dev); + dev->advertising = dev->supported; dev_add_param_int_ro(&dev->dev, "phy_addr", dev->addr, "%d"); dev_add_param_int_ro(&dev->dev, "phy_id", dev->phy_id, "0x%08x"); |