Skip to contentSkip to conversation

Add motorcomm 8531s set ds func and 8522 driver

PATCH Superseded Minda Chen 3 participants 8 messages May 8 – May 13

Subsystems (4)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
author
#1 lore raw

PATCH v3 1/3 net: phy: motorcomm: move mdio lock out from yt8531_set_ds()

In reply to Minda Chen

yt8531_set_ds() default set register with mdio lock and only called with YT8531 PHY. But new type YT8531s support RGMII and has the same pin strength setting with YT8531, YT8531s need to call yt8531_set_ds() setting pin drive strength. But YT8531s config init function yt8521_config_init() already get the mdio lock with phy_select_page(). If calling yt8521_config_init() with mdio lock will cause dead lock.

Need to get the lock before calling yt8531_get_ds() and move mdio lock out from it for YT8531s.

---
 drivers/net/phy/motorcomm.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/net/phy/motorcomm.c +14 -9
index 4d62f7b36212..c66804537aa2 100644
@@ -974,7 +974,8 @@ static u32 yt8531_get_ldo_vol(struct phy_device *phydev)
 {
 	u32 val;
 
-	val = ytphy_read_ext_with_lock(phydev, YT8521_CHIP_CONFIG_REG);
+	val = ytphy_read_ext(phydev, YT8521_CHIP_CONFIG_REG);
+
 	val = FIELD_GET(YT8531_RGMII_LDO_VOL_MASK, val);
 
 	return val <= YT8531_LDO_VOL_1V8 ? val : YT8531_LDO_VOL_1V8;
@@ -1010,10 +1011,11 @@ static int yt8531_set_ds(struct phy_device *phydev)
 		ds = YT8531_RGMII_RX_DS_DEFAULT;
 	}
 
-	ret = ytphy_modify_ext_with_lock(phydev,
-					 YTPHY_PAD_DRIVE_STRENGTH_REG,
-					 YT8531_RGMII_RXC_DS_MASK,
-					 FIELD_PREP(YT8531_RGMII_RXC_DS_MASK, ds));
+	ret = ytphy_modify_ext(phydev,
+			       YTPHY_PAD_DRIVE_STRENGTH_REG,
+			       YT8531_RGMII_RXC_DS_MASK,
+			       FIELD_PREP(YT8531_RGMII_RXC_DS_MASK, ds));
+
 	if (ret < 0)
 		return ret;
 
@@ -1033,10 +1035,11 @@ static int yt8531_set_ds(struct phy_device *phydev)
 	ds_field_low = FIELD_GET(GENMASK(1, 0), ds);
 	ds_field_low = FIELD_PREP(YT8531_RGMII_RXD_DS_LOW_MASK, ds_field_low);
 
-	ret = ytphy_modify_ext_with_lock(phydev,
-					 YTPHY_PAD_DRIVE_STRENGTH_REG,
-					 YT8531_RGMII_RXD_DS_LOW_MASK | YT8531_RGMII_RXD_DS_HI_MASK,
-					 ds_field_low | ds_field_hi);
+	ret = ytphy_modify_ext(phydev,
+			       YTPHY_PAD_DRIVE_STRENGTH_REG,
+			       YT8531_RGMII_RXD_DS_LOW_MASK | YT8531_RGMII_RXD_DS_HI_MASK,
+			       ds_field_low | ds_field_hi);
+
 	if (ret < 0)
 		return ret;
 
@@ -1826,7 +1829,9 @@ static int yt8531_config_init(struct phy_device *phydev)
 			return ret;
 	}
 
+	phy_lock_mdio_bus(phydev);
 	ret = yt8531_set_ds(phydev);
+	phy_unlock_mdio_bus(phydev);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
2.17.1
author
#6 lore raw

PATCH v3 3/3 net: phy: motorcomm: Add YT8522 100M RMII PHY support

In reply to Minda Chen

Add YT8522 100M RMII ethernet PHY base driver support, including PHY ID and base config init function.

---
 drivers/net/phy/motorcomm.c | 49 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)
drivers/net/phy/motorcomm.c +48 -1
index ebc24f51e626..13d57aba5487 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Motorcomm 8511/8521/8531/8531S/8821 PHY driver.
+ * Motorcomm 8511/8521/8522/8531/8531S/8821 PHY driver.
  *
  * Author: Peter Geis <[email protected]>
  * Author: Frank <[email protected]>
@@ -14,6 +14,7 @@
 
 #define PHY_ID_YT8511		0x0000010a
 #define PHY_ID_YT8521		0x0000011a
+#define PHY_ID_YT8522		0x4f51e928
 #define PHY_ID_YT8531		0x4f51e91b
 #define PHY_ID_YT8531S		0x4f51e91a
 #define PHY_ID_YT8821		0x4f51ea19
@@ -227,6 +228,13 @@
 #define YT8521_LED_100_ON_EN			BIT(5)
 #define YT8521_LED_10_ON_EN			BIT(4)
 
+#define YT8522_EXTREG_SLEEP_CONTROL		0x2027
+#define YT8522_EN_SLEEP_SW			15
+
+#define YT8522_EXTENDED_COMBO_CTRL		0x4000
+#define YT8522_RXDV_SEL				BIT(4)
+#define YT8522_RMII_EN				BIT(1)
+
 #define YTPHY_MISC_CONFIG_REG			0xA006
 #define YTPHY_MCR_FIBER_SPEED_MASK		BIT(0)
 #define YTPHY_MCR_FIBER_1000BX			(0x1 << 0)
@@ -1843,6 +1851,36 @@ static int yt8531_config_init(struct phy_device *phydev)
 	return 0;
 }
 
+static int yt8522_config_init(struct phy_device *phydev)
+{
+	struct device_node *node = phydev->mdio.dev.of_node;
+	int ret, val;
+
+	val = ytphy_read_ext_with_lock(phydev, YT8522_EXTENDED_COMBO_CTRL);
+	if (val < 0)
+		return val;
+
+	if (val & YT8522_RMII_EN) {
+		val |= YT8522_RXDV_SEL;
+		ret = ytphy_write_ext_with_lock(phydev,
+						YT8522_EXTENDED_COMBO_CTRL,
+						val);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (of_property_read_bool(node, "motorcomm,auto-sleep-disabled")) {
+		/* disable auto sleep */
+		ret = ytphy_modify_ext_with_lock(phydev,
+						 YT8522_EXTREG_SLEEP_CONTROL,
+						 YT8522_EN_SLEEP_SW, 0);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
 /**
  * yt8531_link_change_notify() - Adjust the tx clock direction according to
  * the current speed and dts config.
@@ -3052,6 +3090,14 @@ static struct phy_driver motorcomm_phy_drvs[] = {
 		.led_hw_control_set = yt8521_led_hw_control_set,
 		.led_hw_control_get = yt8521_led_hw_control_get,
 	},
+	{
+		PHY_ID_MATCH_EXACT(PHY_ID_YT8522),
+		.name		= "YT8522 100 Megabit Ethernet",
+		.config_aneg	= genphy_config_aneg,
+		.config_init	= yt8522_config_init,
+		.suspend	= genphy_suspend,
+		.resume		= genphy_resume,
+	},
 	{
 		PHY_ID_MATCH_EXACT(PHY_ID_YT8531),
 		.name		= "YT8531 Gigabit Ethernet",
@@ -3112,6 +3158,7 @@ MODULE_LICENSE("GPL");
 static const struct mdio_device_id __maybe_unused motorcomm_tbl[] = {
 	{ PHY_ID_MATCH_EXACT(PHY_ID_YT8511) },
 	{ PHY_ID_MATCH_EXACT(PHY_ID_YT8521) },
+	{ PHY_ID_MATCH_EXACT(PHY_ID_YT8522) },
 	{ PHY_ID_MATCH_EXACT(PHY_ID_YT8531) },
 	{ PHY_ID_MATCH_EXACT(PHY_ID_YT8531S) },
 	{ PHY_ID_MATCH_EXACT(PHY_ID_YT8821) },
Signature · 1 line
2.17.1

Minda Chen

author
#0 lore raw

v3 cover Add motorcomm 8531s set ds func and 8522 driver

This patch is for Starfive JHB100 EVB board. JHB100 contain 1 RGMII/RMII and 1 RMII synopsys GMAC cores. In the EVB board, RGMII interface connect with YT8531s Ethernet PHY. RMII interface connect with YT8522 ethernet PHY. So patch 1-2 is for RGMII interface patch 3 is RMII is for RMII interface.

JHB100 is a Starfive new RISC-V SoC for datacenter BMC (BaseBoard Managent Controller). Similar with Aspeed 27x0.

The JHB100 minimal system upstream is in progress:
https://patchwork.kernel.org/project/linux-riscv/cover/[email protected]/

The patch base net-next (base commit list below)

previous commit
v1: https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
v2:https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/

The change list:
v3:
1. change some commit message.
v2:
1. patch1 move mdio lock out from yt8531_set_ds().
2. patch2 changed to phy_interface_is_rgmii().

Minda Chen (3):
net: phy: motorcomm: move mdio lock out from yt8531_set_ds()
net: motorcomm: phy: set drive strength in YT8531s RGMII
net: phy: motorcomm: Add YT8522 100M RMII PHY support

 drivers/net/phy/motorcomm.c | 77 ++++++++++++++++++++++++++++++++-----
 1 file changed, 67 insertions(+), 10 deletions(-)

base-commit: 6a4c4656b0d2d4056a1f0c35442db4e8a5cf8021

Signature · 1 line
2.17.1
author
#3 lore raw

PATCH v3 2/3 net: motorcomm: phy: set drive strength in YT8531s RGMII

Set RXD and RX CLK pin drive strength while in YT8531s connect with RGMII.

---
 drivers/net/phy/motorcomm.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/phy/motorcomm.c +5 -0
index c66804537aa2..ebc24f51e626 100644
@@ -1698,6 +1698,11 @@ static int yt8521_config_init(struct phy_device *phydev)
 		if (ret < 0)
 			goto err_restore_page;
 	}
+
+	if (phydev->drv->phy_id == PHY_ID_YT8531S &&
+	    phy_interface_is_rgmii(phydev))
+		ret = yt8531_set_ds(phydev);
+
 err_restore_page:
 	return phy_restore_page(phydev, old_page, ret);
 }
Signature · 1 line
2.17.1
maintainer
#7 lore raw

Re: [net-next v3 3/3] net: phy: motorcomm: Add YT8522 100M RMII PHY support

In reply to Minda Chen
Quoted 29 lines · Minda Chen

Add YT8522 100M RMII ethernet PHY base driver support, including PHY ID and base config init function.

---
 drivers/net/phy/motorcomm.c | 49 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)
drivers/net/phy/motorcomm.c +2 -1
index ebc24f51e626..13d57aba5487 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Motorcomm 8511/8521/8531/8531S/8821 PHY driver.
+ * Motorcomm 8511/8521/8522/8531/8531S/8821 PHY driver.
  *
  * Author: Peter Geis <[email protected]>
  * Author: Frank <[email protected]>
@@ -14,6 +14,7 @@
 
 #define PHY_ID_YT8511		0x0000010a
 #define PHY_ID_YT8521		0x0000011a
+#define PHY_ID_YT8522		0x4f51e928
 #define PHY_ID_YT8531		0x4f51e91b
 #define PHY_ID_YT8531S		0x4f51e91a
 #define PHY_ID_YT8821		0x4f51ea19

drivers/net/phy/motorcomm.c line 232

Quoted 5 lines
drivers/net/phy/motorcomm.c +2 -0
@@ -227,6 +228,13 @@
 #define YT8521_LED_100_ON_EN			BIT(5)
 #define YT8521_LED_10_ON_EN			BIT(4)
 
+#define YT8522_EXTREG_SLEEP_CONTROL		0x2027
+#define YT8522_EN_SLEEP_SW			15

Sashiko noted that the above value looks unusual/inconsistent with other register dedinition. Should it be:

						BIT(15)

instead?

Otherwise using GENMASK() would possibly be more clear.

/P

Reviewed-by on v3 1/3
#2 lore raw

Re: [net-next v3 1/3] net: phy: motorcomm: move mdio lock out from yt8531_set_ds()

In reply to Minda Chen
Quoted 11 lines · Minda Chen

yt8531_set_ds() default set register with mdio lock and only called with YT8531 PHY. But new type YT8531s support RGMII and has the same pin strength setting with YT8531, YT8531s need to call yt8531_set_ds() setting pin drive strength. But YT8531s config init function yt8521_config_init() already get the mdio lock with phy_select_page(). If calling yt8521_config_init() with mdio lock will cause dead lock.

Need to get the lock before calling yt8531_get_ds() and move mdio lock out from it for YT8531s.

Maxime

Quoted 60 lines
---
  drivers/net/phy/motorcomm.c | 23 ++++++++++++++---------
  1 file changed, 14 insertions(+), 9 deletions(-)
drivers/net/phy/motorcomm.c +14 -9
index 4d62f7b36212..c66804537aa2 100644
@@ -974,7 +974,8 @@ static u32 yt8531_get_ldo_vol(struct phy_device *phydev)
  {
  	u32 val;
 
-	val = ytphy_read_ext_with_lock(phydev, YT8521_CHIP_CONFIG_REG);
+	val = ytphy_read_ext(phydev, YT8521_CHIP_CONFIG_REG);
+
  	val = FIELD_GET(YT8531_RGMII_LDO_VOL_MASK, val);
 
  	return val <= YT8531_LDO_VOL_1V8 ? val : YT8531_LDO_VOL_1V8;
@@ -1010,10 +1011,11 @@ static int yt8531_set_ds(struct phy_device *phydev)
  		ds = YT8531_RGMII_RX_DS_DEFAULT;
  	}
 
-	ret = ytphy_modify_ext_with_lock(phydev,
-					 YTPHY_PAD_DRIVE_STRENGTH_REG,
-					 YT8531_RGMII_RXC_DS_MASK,
-					 FIELD_PREP(YT8531_RGMII_RXC_DS_MASK, ds));
+	ret = ytphy_modify_ext(phydev,
+			       YTPHY_PAD_DRIVE_STRENGTH_REG,
+			       YT8531_RGMII_RXC_DS_MASK,
+			       FIELD_PREP(YT8531_RGMII_RXC_DS_MASK, ds));
+
  	if (ret < 0)
  		return ret;
 
@@ -1033,10 +1035,11 @@ static int yt8531_set_ds(struct phy_device *phydev)
  	ds_field_low = FIELD_GET(GENMASK(1, 0), ds);
  	ds_field_low = FIELD_PREP(YT8531_RGMII_RXD_DS_LOW_MASK, ds_field_low);
 
-	ret = ytphy_modify_ext_with_lock(phydev,
-					 YTPHY_PAD_DRIVE_STRENGTH_REG,
-					 YT8531_RGMII_RXD_DS_LOW_MASK | YT8531_RGMII_RXD_DS_HI_MASK,
-					 ds_field_low | ds_field_hi);
+	ret = ytphy_modify_ext(phydev,
+			       YTPHY_PAD_DRIVE_STRENGTH_REG,
+			       YT8531_RGMII_RXD_DS_LOW_MASK | YT8531_RGMII_RXD_DS_HI_MASK,
+			       ds_field_low | ds_field_hi);
+
  	if (ret < 0)
  		return ret;
 
@@ -1826,7 +1829,9 @@ static int yt8531_config_init(struct phy_device *phydev)
  			return ret;
  	}
 
+	phy_lock_mdio_bus(phydev);
  	ret = yt8531_set_ds(phydev);
+	phy_unlock_mdio_bus(phydev);
  	if (ret < 0)
  		return ret;
 
#4 lore raw

Re: [net-next v3 2/3] net: motorcomm: phy: set drive strength in YT8531s RGMII

In reply to Minda Chen
Quoted 13 lines · Minda Chen

Set RXD and RX CLK pin drive strength while in YT8531s connect with RGMII.

---
  drivers/net/phy/motorcomm.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/net/phy/motorcomm.c +0 -0
index c66804537aa2..ebc24f51e626 100644

drivers/net/phy/motorcomm.c static int yt8521_config_init(struct phy_device *phydev) · line 1704

Quoted 7 lines
drivers/net/phy/motorcomm.c +4 -0
@@ -1698,6 +1698,11 @@ static int yt8521_config_init(struct phy_device *phydev)
  		if (ret < 0)
  			goto err_restore_page;
  	}
+
+	if (phydev->drv->phy_id == PHY_ID_YT8531S &&
+	    phy_interface_is_rgmii(phydev))
+		ret = yt8531_set_ds(phydev);

Minor detail if you re-spin, there's already a check for the interface being RGMII a bit above in the same function, but it's written as :

	/* set rgmii delay mode */
	if (phydev->interface != PHY_INTERFACE_MODE_SGMII)
           ...

could be a good idea to change that check to a more explicit call to phy_interface_is_rgmii(), or even add the drive-strength configuration under the same block, provided the order of operation doesn't matter w.r.t the pll/auto-sleep configuration.

Maxime

Quoted 4 lines
drivers/net/phy/motorcomm.c +1 -0
+
  err_restore_page:
  	return phy_restore_page(phydev, old_page, ret);
  }
author
#5 lore raw

RE: [net-next v3 2/3] net: motorcomm: phy: set drive strength in YT8531s RGMII

Quoted 35 lines · Minda Chen

drivers/net/phy/motorcomm.c static int yt8521_config_init(struct phy_device

Quoted 13 lines

Set RXD and RX CLK pin drive strength while in YT8531s connect with RGMII.

---
  drivers/net/phy/motorcomm.c | 5 +++++
  1 file changed, 5 insertions(+)
drivers/net/phy/motorcomm.c +0 -0
index c66804537aa2..ebc24f51e626 100644
@@ -1698,6 +1698,11 @@ static int yt8521_config_init(struct phy_device

*phydev)

drivers/net/phy/motorcomm.c static int yt8521_config_init(struct phy_device *phydev) · line 1704

Quoted 7 lines
drivers/net/phy/motorcomm.c +4 -0
  		if (ret < 0)
  			goto err_restore_page;
  	}
+
+	if (phydev->drv->phy_id == PHY_ID_YT8531S &&
+	    phy_interface_is_rgmii(phydev))
+		ret = yt8531_set_ds(phydev);

Minor detail if you re-spin, there's already a check for the interface being RGMII a bit above in the same function, but it's written as :

	/* set rgmii delay mode */
	if (phydev->interface != PHY_INTERFACE_MODE_SGMII)
            ...
Quoted 7 lines

could be a good idea to change that check to a more explicit call to phy_interface_is_rgmii(), or even add the drive-strength configuration under the same block, provided the order of operation doesn't matter w.r.t the pll/auto-sleep configuration.

Maxime

+ if (phydev->drv->phy_id == PHY_ID_YT8531S &&

    (phydev->interface != PHY_INTERFACE_MODE_SGMII)

I just set it v1 like this. This function is used by YT8521 and YT8531s,I don’t know whether YT8521 contains
RGMII pin drive strength setting . Maybe need Frank confirm it.
And Andrew's review comment is using phy_interface_is_rgmii(phydev).

Quoted 4 lines
Quoted 4 lines
drivers/net/phy/motorcomm.c +1 -0
+
  err_restore_page:
  	return phy_restore_page(phydev, old_page, ret);
  }