Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7cdbc6f7 authored by Andreas Oetken's avatar Andreas Oetken Committed by David S. Miller
Browse files

altera tse: add support for fixed-links.



Add support for fixed-links in configurations without PHY.
(e.g. connection to a switch, SGMII point to point, SFPs)

Check: Documentation/devicetree/bindings/net/fixed-link.txt.
Signed-off-by: default avatarAndreas Oetken <ennoerlangen@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0e03fd3e
Loading
Loading
Loading
Loading
+29 −8
Original line number Original line Diff line number Diff line
@@ -777,6 +777,8 @@ static int init_phy(struct net_device *dev)
	struct altera_tse_private *priv = netdev_priv(dev);
	struct altera_tse_private *priv = netdev_priv(dev);
	struct phy_device *phydev;
	struct phy_device *phydev;
	struct device_node *phynode;
	struct device_node *phynode;
	bool fixed_link = false;
	int rc = 0;


	/* Avoid init phy in case of no phy present */
	/* Avoid init phy in case of no phy present */
	if (!priv->phy_iface)
	if (!priv->phy_iface)
@@ -789,13 +791,32 @@ static int init_phy(struct net_device *dev)
	phynode = of_parse_phandle(priv->device->of_node, "phy-handle", 0);
	phynode = of_parse_phandle(priv->device->of_node, "phy-handle", 0);


	if (!phynode) {
	if (!phynode) {
		/* check if a fixed-link is defined in device-tree */
		if (of_phy_is_fixed_link(priv->device->of_node)) {
			rc = of_phy_register_fixed_link(priv->device->of_node);
			if (rc < 0) {
				netdev_err(dev, "cannot register fixed PHY\n");
				return rc;
			}

			/* In the case of a fixed PHY, the DT node associated
			 * to the PHY is the Ethernet MAC DT node.
			 */
			phynode = of_node_get(priv->device->of_node);
			fixed_link = true;

			netdev_dbg(dev, "fixed-link detected\n");
			phydev = of_phy_connect(dev, phynode,
						&altera_tse_adjust_link,
						0, priv->phy_iface);
		} else {
			netdev_dbg(dev, "no phy-handle found\n");
			netdev_dbg(dev, "no phy-handle found\n");
			if (!priv->mdio) {
			if (!priv->mdio) {
			netdev_err(dev,
				netdev_err(dev, "No phy-handle nor local mdio specified\n");
				   "No phy-handle nor local mdio specified\n");
				return -ENODEV;
				return -ENODEV;
			}
			}
			phydev = connect_local_phy(dev);
			phydev = connect_local_phy(dev);
		}
	} else {
	} else {
		netdev_dbg(dev, "phy-handle found\n");
		netdev_dbg(dev, "phy-handle found\n");
		phydev = of_phy_connect(dev, phynode,
		phydev = of_phy_connect(dev, phynode,
@@ -819,10 +840,10 @@ static int init_phy(struct net_device *dev)
	/* Broken HW is sometimes missing the pull-up resistor on the
	/* Broken HW is sometimes missing the pull-up resistor on the
	 * MDIO line, which results in reads to non-existent devices returning
	 * MDIO line, which results in reads to non-existent devices returning
	 * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent
	 * 0 rather than 0xffff. Catch this here and treat 0 as a non-existent
	 * device as well.
	 * device as well. If a fixed-link is used the phy_id is always 0.
	 * Note: phydev->phy_id is the result of reading the UID PHY registers.
	 * Note: phydev->phy_id is the result of reading the UID PHY registers.
	 */
	 */
	if (phydev->phy_id == 0) {
	if ((phydev->phy_id == 0) && !fixed_link) {
		netdev_err(dev, "Bad PHY UID 0x%08x\n", phydev->phy_id);
		netdev_err(dev, "Bad PHY UID 0x%08x\n", phydev->phy_id);
		phy_disconnect(phydev);
		phy_disconnect(phydev);
		return -ENODEV;
		return -ENODEV;