[U-Boot,v2,1/3] net: designware: socfpga: adapt to Gen5

Message ID 20190111194506.12051-2-simon.k.r.goldschmidt@gmail.com
State Superseded, archived
Headers show
Series
  • arm: socpfpga: gen5 clean up ETH RST & PHY mode
Related show

Commit Message

Simon Goldschmidt Jan. 11, 2019, 7:45 p.m.
This driver was written for Arria10, but it applies to Gen5, too.

The main difference is that Gen5 has 2 MACs (Arria10 has 3) and the
syscon bits are encoded in the same register, thus an offset is needed.

This offset is already read from the devicetree, but for Arria10 it is
always 0, which is probably why it has been ignored. By using this
offset when writing the phy mode into the syscon regiter, we can use
this driver to set the phy mode for both of the MACs on Gen5.

Since the PHY mode bits in sysmgr are the same even for Stratix10,
let's drop the detection of the sub-mach by checking compatible
version and just use the same code for all FPGAs.

To work correctly, this driver depends on SYSCON and REGMAP, so select
those via Kconfig when it is enabeld.

Tested on socfpga_socrates (where the 2nd MAC is connected, so a shift
offset is required).

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
---

Changes in v2:
- remove detection of sub-mach via compatible version and handle
  all FPGAs the same
- select SYSCON and REGMAP via Kconfig

 drivers/net/Kconfig         |  2 +
 drivers/net/dwmac_socfpga.c | 87 ++++++++++++++-----------------------
 2 files changed, 35 insertions(+), 54 deletions(-)

Comments

Marek Vasut Jan. 11, 2019, 10:04 p.m. | #1
On 1/11/19 8:45 PM, Simon Goldschmidt wrote:
> This driver was written for Arria10, but it applies to Gen5, too.
> 
> The main difference is that Gen5 has 2 MACs (Arria10 has 3) and the
> syscon bits are encoded in the same register, thus an offset is needed.
> 
> This offset is already read from the devicetree, but for Arria10 it is
> always 0, which is probably why it has been ignored. By using this
> offset when writing the phy mode into the syscon regiter, we can use
> this driver to set the phy mode for both of the MACs on Gen5.
> 
> Since the PHY mode bits in sysmgr are the same even for Stratix10,
> let's drop the detection of the sub-mach by checking compatible
> version and just use the same code for all FPGAs.
> 
> To work correctly, this driver depends on SYSCON and REGMAP, so select
> those via Kconfig when it is enabeld.
> 
> Tested on socfpga_socrates (where the 2nd MAC is connected, so a shift
> offset is required).
> 
> Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

Acked-by: Marek Vasut <marex@denx.de>

Patch

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 7044c6adf3..b7c0b921e6 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -162,6 +162,8 @@  config ETH_DESIGNWARE
 	  provide the PHY (physical media interface).
 
 config ETH_DESIGNWARE_SOCFPGA
+	select REGMAP
+	select SYSCON
 	bool "Altera SoCFPGA extras for Synopsys Designware Ethernet MAC"
 	depends on DM_ETH && ETH_DESIGNWARE
 	help
diff --git a/drivers/net/dwmac_socfpga.c b/drivers/net/dwmac_socfpga.c
index 08fc9677c4..b7bf5dbe69 100644
--- a/drivers/net/dwmac_socfpga.c
+++ b/drivers/net/dwmac_socfpga.c
@@ -17,16 +17,10 @@ 
 
 #include <asm/arch/system_manager.h>
 
-enum dwmac_type {
-	DWMAC_SOCFPGA_GEN5 = 0,
-	DWMAC_SOCFPGA_ARRIA10,
-	DWMAC_SOCFPGA_STRATIX10,
-};
-
 struct dwmac_socfpga_platdata {
 	struct dw_eth_pdata	dw_eth_pdata;
-	enum dwmac_type		type;
 	void			*phy_intf;
+	u32			reg_shift;
 };
 
 static int dwmac_socfpga_ofdata_to_platdata(struct udevice *dev)
@@ -63,21 +57,7 @@  static int dwmac_socfpga_ofdata_to_platdata(struct udevice *dev)
 	}
 
 	pdata->phy_intf = range + args.args[0];
-
-	/*
-	 * Sadly, the Altera DT bindings don't have SoC-specific compatibles,
-	 * so we have to guesstimate which SoC we are running on from the
-	 * DWMAC version. Luckily, Altera at least updated the DWMAC with
-	 * each SoC.
-	 */
-	if (ofnode_device_is_compatible(dev->node, "snps,dwmac-3.70a"))
-		pdata->type = DWMAC_SOCFPGA_GEN5;
-
-	if (ofnode_device_is_compatible(dev->node, "snps,dwmac-3.72a"))
-		pdata->type = DWMAC_SOCFPGA_ARRIA10;
-
-	if (ofnode_device_is_compatible(dev->node, "snps,dwmac-3.74a"))
-		pdata->type = DWMAC_SOCFPGA_STRATIX10;
+	pdata->reg_shift = args.args[1];
 
 	return designware_eth_ofdata_to_platdata(dev);
 }
@@ -88,40 +68,39 @@  static int dwmac_socfpga_probe(struct udevice *dev)
 	struct eth_pdata *edata = &pdata->dw_eth_pdata.eth_pdata;
 	struct reset_ctl_bulk reset_bulk;
 	int ret;
-	u8 modereg;
-
-	if (pdata->type == DWMAC_SOCFPGA_ARRIA10) {
-		switch (edata->phy_interface) {
-		case PHY_INTERFACE_MODE_MII:
-		case PHY_INTERFACE_MODE_GMII:
-			modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII;
-			break;
-		case PHY_INTERFACE_MODE_RMII:
-			modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII;
-			break;
-		case PHY_INTERFACE_MODE_RGMII:
-			modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII;
-			break;
-		default:
-			dev_err(dev, "Unsupported PHY mode\n");
-			return -EINVAL;
-		}
-
-		ret = reset_get_bulk(dev, &reset_bulk);
-		if (ret) {
-			dev_err(dev, "Failed to get reset: %d\n", ret);
-			return ret;
-		}
-
-		reset_assert_bulk(&reset_bulk);
-
-		clrsetbits_le32(pdata->phy_intf,
-				SYSMGR_EMACGRP_CTRL_PHYSEL_MASK,
-				modereg);
-
-		reset_release_bulk(&reset_bulk);
+	u32 modereg;
+	u32 modemask;
+
+	switch (edata->phy_interface) {
+	case PHY_INTERFACE_MODE_MII:
+	case PHY_INTERFACE_MODE_GMII:
+		modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII;
+		break;
+	case PHY_INTERFACE_MODE_RMII:
+		modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII;
+		break;
+	case PHY_INTERFACE_MODE_RGMII:
+		modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII;
+		break;
+	default:
+		dev_err(dev, "Unsupported PHY mode\n");
+		return -EINVAL;
 	}
 
+	ret = reset_get_bulk(dev, &reset_bulk);
+	if (ret) {
+		dev_err(dev, "Failed to get reset: %d\n", ret);
+		return ret;
+	}
+
+	reset_assert_bulk(&reset_bulk);
+
+	modemask = SYSMGR_EMACGRP_CTRL_PHYSEL_MASK << pdata->reg_shift;
+	clrsetbits_le32(pdata->phy_intf, modemask,
+			modereg << pdata->reg_shift);
+
+	reset_release_bulk(&reset_bulk);
+
 	return designware_eth_probe(dev);
 }