diff mbox series

[U-Boot,v3,06/11] drivers: net: aquantia: set MDI reversal based on DT property

Message ID 20191114162838.7150-7-alexandru.marginean@nxp.com
State Accepted
Commit 7552ee9a01b838b95a1d486355b40dfe1ed2ad2f
Delegated to: Joe Hershberger
Headers show
Series Add XFI, USXGMII net protocols, use them in Aquantia driver | expand

Commit Message

Alexandru Marginean Nov. 14, 2019, 4:28 p.m. UTC
MDI pins up to the RJ45 connector may be reversed on the board and the
default PHY configuration applied by firmware may or may not match that.
Add an optional DT property to configure MDI reversal for this case.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
---
 drivers/net/phy/aquantia.c | 39 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

Comments

Joe Hershberger Nov. 30, 2019, 12:35 a.m. UTC | #1
On Thu, Nov 14, 2019 at 10:34 AM Alex Marginean
<alexandru.marginean@nxp.com> wrote:
>
> MDI pins up to the RJ45 connector may be reversed on the board and the
> default PHY configuration applied by firmware may or may not match that.
> Add an optional DT property to configure MDI reversal for this case.
>
> Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
diff mbox series

Patch

diff --git a/drivers/net/phy/aquantia.c b/drivers/net/phy/aquantia.c
index 97f202afd4..06532c51d5 100644
--- a/drivers/net/phy/aquantia.c
+++ b/drivers/net/phy/aquantia.c
@@ -64,6 +64,13 @@ 
 #define UP_RUN_STALL_OVERRIDE BIT(6)
 #define UP_RUN_STALL BIT(0)
 
+#define AQUANTIA_PMA_RX_VENDOR_P1		0xe400
+#define  AQUANTIA_PMA_RX_VENDOR_P1_MDI_MSK	GENMASK(1, 0)
+/* MDI reversal configured through registers */
+#define  AQUANTIA_PMA_RX_VENDOR_P1_MDI_CFG	BIT(1)
+/* MDI reversal enabled */
+#define  AQUANTIA_PMA_RX_VENDOR_P1_MDI_REV	BIT(0)
+
 /*
  * global start rate, the protocol associated with this speed is used by default
  * on SI.
@@ -320,6 +327,36 @@  static int aquantia_set_proto(struct phy_device *phydev)
 	return 0;
 }
 
+static int aquantia_dts_config(struct phy_device *phydev)
+{
+#ifdef CONFIG_DM_ETH
+	ofnode node = phydev->node;
+	u32 prop;
+	u16 reg;
+
+	/* this code only works on gen2 and gen3 PHYs */
+	if (phydev->drv->data != AQUANTIA_GEN2 &&
+	    phydev->drv->data != AQUANTIA_GEN3)
+		return -ENOTSUPP;
+
+	if (!ofnode_valid(node))
+		return 0;
+
+	if (!ofnode_read_u32(node, "mdi-reversal", &prop)) {
+		debug("mdi-reversal = %d\n", (int)prop);
+		reg =  phy_read(phydev, MDIO_MMD_PMAPMD,
+				AQUANTIA_PMA_RX_VENDOR_P1);
+		reg &= ~AQUANTIA_PMA_RX_VENDOR_P1_MDI_MSK;
+		reg |= AQUANTIA_PMA_RX_VENDOR_P1_MDI_CFG;
+		reg |= prop ? AQUANTIA_PMA_RX_VENDOR_P1_MDI_REV : 0;
+		phy_write(phydev, MDIO_MMD_PMAPMD, AQUANTIA_PMA_RX_VENDOR_P1,
+			  reg);
+	}
+
+#endif
+	return 0;
+}
+
 static bool aquantia_link_is_up(struct phy_device *phydev)
 {
 	u16 reg, regmask;
@@ -400,6 +437,8 @@  int aquantia_config(struct phy_device *phydev)
 
 		/* configure protocol based on phydev->interface */
 		aquantia_set_proto(phydev);
+		/* apply custom configuration based on DT */
+		aquantia_dts_config(phydev);
 
 		/* wake PHY back up */
 		phy_write(phydev, MDIO_MMD_VEND1, AQUANTIA_VND1_GLOBAL_SC, 0);