[U-Boot] [PATCH v2 2/5] net: sun8i_emac: Support RX/TX delay chains

Chen-Yu Tsai wens at csie.org
Sat Nov 25 05:08:29 UTC 2017


The EMAC syscon has configurable RX/TX delay chains for use with RGMII
PHYs.

This adds support for configuring them via device tree properties. The
property names and format were defined in Linux's dwmac-sun8i binding
that was merged at one point.

Signed-off-by: Chen-Yu Tsai <wens at csie.org>
---
 drivers/net/sun8i_emac.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c
index 3ccc6b0bb612..ea26450d34bc 100644
--- a/drivers/net/sun8i_emac.c
+++ b/drivers/net/sun8i_emac.c
@@ -14,6 +14,7 @@
 #include <asm/io.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/gpio.h>
+#include <bitfield.h>
 #include <common.h>
 #include <dm.h>
 #include <fdt_support.h>
@@ -56,6 +57,8 @@
 #define H3_EPHY_SELECT		BIT(15) /* 1: internal PHY, 0: external PHY */
 
 #define SC_RMII_EN		BIT(13)
+#define SC_TXDC_MASK		GENMASK(12, 10)
+#define SC_RXDC_MASK		GENMASK(9, 5)
 #define SC_EPIT			BIT(2) /* 1: RGMII, 0: MII */
 #define SC_ETCS_MASK		GENMASK(1, 0)
 #define SC_ETCS_EXT_GMII	0x1
@@ -125,6 +128,8 @@ struct emac_eth_dev {
 	u32 addr;
 	u32 tx_slot;
 	bool use_internal_phy;
+	u32 tx_delay;
+	u32 rx_delay;
 
 	enum emac_variant variant;
 	void *mac_reg;
@@ -290,6 +295,10 @@ static int sun8i_emac_set_syscon(struct emac_eth_dev *priv)
 	if (priv->variant == H3_EMAC || priv->variant == A64_EMAC)
 		reg &= ~SC_RMII_EN;
 
+	/* Configure RX/TX delay chains */
+	reg = bitfield_replace_by_mask(reg, SC_RXDC_MASK, priv->rx_delay);
+	reg = bitfield_replace_by_mask(reg, SC_TXDC_MASK, priv->tx_delay);
+
 	switch (priv->interface) {
 	case PHY_INTERFACE_MODE_MII:
 		/* default */
@@ -839,6 +848,19 @@ static int sun8i_emac_eth_ofdata_to_platdata(struct udevice *dev)
 	}
 #endif
 
+	/* Get RX/TX delays for RGMII */
+	priv->rx_delay = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev),
+					 "allwinner,rx-delay-ps", 0);
+	if (priv->rx_delay % 100 || priv->rx_delay > 3100)
+		debug("%s: invalid rx delay value\n", __func__);
+	priv->rx_delay /= 100;
+
+	priv->tx_delay = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev),
+					 "allwinner,tx-delay-ps", 0);
+	if (priv->tx_delay % 100 || priv->tx_delay > 800)
+		debug("%s: invalid tx delay value\n", __func__);
+	priv->tx_delay /= 100;
+
 	return 0;
 }
 
-- 
2.15.0



More information about the U-Boot mailing list