diff mbox series

[net-next,v1,1/1] net: phy: microchip: lan937x: add support for 100BaseTX PHY

Message ID 20240704135850.3939342-1-o.rempel@pengutronix.de (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v1,1/1] net: phy: microchip: lan937x: add support for 100BaseTX PHY | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 839 this patch: 839
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 846 this patch: 846
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 846 this patch: 846
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 104 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-07-05--06-00 (tests: 695)

Commit Message

Oleksij Rempel July 4, 2024, 1:58 p.m. UTC
Add support of 100BaseTX PHY build in to LAN9371 and LAN9372 switches.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/phy/microchip_t1.c | 74 ++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

Comments

Florian Fainelli July 4, 2024, 2:21 p.m. UTC | #1
On 7/4/2024 2:58 PM, Oleksij Rempel wrote:
> Add support of 100BaseTX PHY build in to LAN9371 and LAN9372 switches.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>

Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Michal Kubiak July 4, 2024, 3:37 p.m. UTC | #2
On Thu, Jul 04, 2024 at 03:58:50PM +0200, Oleksij Rempel wrote:
> Add support of 100BaseTX PHY build in to LAN9371 and LAN9372 switches.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/phy/microchip_t1.c | 74 ++++++++++++++++++++++++++++++++++
>  1 file changed, 74 insertions(+)
> 
> diff --git a/drivers/net/phy/microchip_t1.c b/drivers/net/phy/microchip_t1.c
> index a35528497a576..c7ca0d04b9e1b 100644
> --- a/drivers/net/phy/microchip_t1.c
> +++ b/drivers/net/phy/microchip_t1.c
> @@ -12,6 +12,7 @@
>  
>  #define PHY_ID_LAN87XX				0x0007c150
>  #define PHY_ID_LAN937X				0x0007c180
> +#define PHY_ID_LAN937X_TX			0x0007c190
>  
>  /* External Register Control Register */
>  #define LAN87XX_EXT_REG_CTL                     (0x14)
> @@ -94,6 +95,10 @@
>  /* SQI defines */
>  #define LAN87XX_MAX_SQI			0x07
>  
> +#define LAN937X_MODE_CTRL_STATUS_REG	0x11
> +#define LAN937X_AUTOMDIX_EN		BIT(7)
> +#define LAN937X_MDI_MODE		BIT(6)
> +
>  #define DRIVER_AUTHOR	"Nisar Sayed <nisar.sayed@microchip.com>"
>  #define DRIVER_DESC	"Microchip LAN87XX/LAN937x T1 PHY driver"
>  
> @@ -860,6 +865,66 @@ static int lan87xx_get_sqi_max(struct phy_device *phydev)
>  	return LAN87XX_MAX_SQI;
>  }
>  
> +static int lan937x_tx_read_status(struct phy_device *phydev)
> +{
> +	int ret;
> +
> +	ret = genphy_read_status(phydev);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = phy_read(phydev, LAN937X_MODE_CTRL_STATUS_REG);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (ret & LAN937X_AUTOMDIX_EN) {
> +		phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
> +		/* MDI/MDIX status is unknown */
> +		phydev->mdix = ETH_TP_MDI_INVALID;
> +	} else if (ret & LAN937X_MDI_MODE) {
> +		phydev->mdix_ctrl = ETH_TP_MDI_X;
> +		phydev->mdix = ETH_TP_MDI_X;
> +	} else {
> +		phydev->mdix_ctrl = ETH_TP_MDI;
> +		phydev->mdix = ETH_TP_MDI;
> +	}
> +
> +	return 0;
> +}
> +
> +static int lan937x_tx_config_mdix(struct phy_device *phydev, u8 ctrl)
> +{
> +	u16 val;
> +
> +	switch (ctrl) {
> +	case ETH_TP_MDI:
> +		val = 0;
> +		break;
> +	case ETH_TP_MDI_X:
> +		val = LAN937X_MDI_MODE;
> +		break;
> +	case ETH_TP_MDI_AUTO:
> +		val = LAN937X_AUTOMDIX_EN;
> +		break;
> +	default:
> +		return 0;
> +	}
> +
> +	return phy_modify(phydev, LAN937X_MODE_CTRL_STATUS_REG,
> +			  LAN937X_AUTOMDIX_EN | LAN937X_MDI_MODE, val);
> +}
> +
> +static int lan937x_tx_config_aneg(struct phy_device *phydev)
> +{
> +	int ret;
> +
> +	ret = genphy_config_aneg(phydev);
> +	if (ret)
> +		return ret;
> +
> +	return lan937x_tx_config_mdix(phydev, phydev->mdix_ctrl);
> +}
> +
>  static struct phy_driver microchip_t1_phy_driver[] = {
>  	{
>  		PHY_ID_MATCH_MODEL(PHY_ID_LAN87XX),
> @@ -894,6 +959,14 @@ static struct phy_driver microchip_t1_phy_driver[] = {
>  		.get_sqi_max	= lan87xx_get_sqi_max,
>  		.cable_test_start = lan87xx_cable_test_start,
>  		.cable_test_get_status = lan87xx_cable_test_get_status,
> +	},
> +	{
> +		PHY_ID_MATCH_MODEL(PHY_ID_LAN937X_TX),
> +		.name		= "Microchip LAN937x TX",
> +		.suspend	= genphy_suspend,
> +		.resume		= genphy_resume,
> +		.config_aneg	= lan937x_tx_config_aneg,
> +		.read_status	= lan937x_tx_read_status,
>  	}
>  };
>  
> @@ -902,6 +975,7 @@ module_phy_driver(microchip_t1_phy_driver);
>  static struct mdio_device_id __maybe_unused microchip_t1_tbl[] = {
>  	{ PHY_ID_MATCH_MODEL(PHY_ID_LAN87XX) },
>  	{ PHY_ID_MATCH_MODEL(PHY_ID_LAN937X) },
> +	{ PHY_ID_MATCH_MODEL(PHY_ID_LAN937X_TX) },
>  	{ }
>  };
>  
> -- 
> 2.39.2
> 
> 

The patch looks OK.

Thanks,
Reviewed-by: Michal Kubiak <michal.kubiak@intel.com>
Oleksij Rempel July 4, 2024, 7:04 p.m. UTC | #3
Hi Woojung,

On Thu, Jul 04, 2024 at 03:44:52PM +0000, Woojung.Huh@microchip.com wrote:
> Hi Oleksij,
> 
> We use phy/microchip_t1.c for T1 phy. Can you please put the case in different phy driver file?

Which file would you suggest?

Regards,
Oleksij
Woojung Huh July 4, 2024, 8:02 p.m. UTC | #4
Hi Oleksij,

phy/microchip.c would be a file for this 100Base-TX PHY of LAN937x.

Thanks.
Woojung

> -----Original Message-----
> From: Oleksij Rempel <o.rempel@pengutronix.de>
> Sent: Thursday, July 4, 2024 3:05 PM
> To: Woojung Huh - C21699 <Woojung.Huh@microchip.com>
> Cc: davem@davemloft.net; andrew@lunn.ch; edumazet@google.com;
> f.fainelli@gmail.com; kuba@kernel.org; pabeni@redhat.com; Arun Ramadoss
> - I17769 <Arun.Ramadoss@microchip.com>; hkallweit1@gmail.com;
> linux@armlinux.org.uk; Yuiko Oshino - C18177
> <Yuiko.Oshino@microchip.com>; UNGLinuxDriver
> <UNGLinuxDriver@microchip.com>; linux-kernel@vger.kernel.org;
> kernel@pengutronix.de; netdev@vger.kernel.org
> Subject: Re: [PATCH net-next v1 1/1] net: phy: microchip: lan937x: add
> support for 100BaseTX PHY
> 
> EXTERNAL EMAIL: Do not click links or open attachments unless you know
> the content is safe
> 
> Hi Woojung,
> 
> On Thu, Jul 04, 2024 at 03:44:52PM +0000, Woojung.Huh@microchip.com
> wrote:
> > Hi Oleksij,
> >
> > We use phy/microchip_t1.c for T1 phy. Can you please put the case in
> different phy driver file?
> 
> Which file would you suggest?
> 
> Regards,
> Oleksij
> --
> Pengutronix e.K.                           |
> |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/
> |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0
> |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555
> |
Oleksij Rempel July 5, 2024, 6:29 a.m. UTC | #5
On Thu, Jul 04, 2024 at 08:02:00PM +0000, Woojung.Huh@microchip.com wrote:
> Hi Oleksij,
> 
> phy/microchip.c would be a file for this 100Base-TX PHY of LAN937x.

Thx!

Are there any diagnostic features in this? I was not able to find
anything in the register manual, MDIX status, no cable testing or
counters. Do I hold it wrong? How about the T1 PHY? Are there anything
beside cable testing and SQI?

Regards,
Oleksij
diff mbox series

Patch

diff --git a/drivers/net/phy/microchip_t1.c b/drivers/net/phy/microchip_t1.c
index a35528497a576..c7ca0d04b9e1b 100644
--- a/drivers/net/phy/microchip_t1.c
+++ b/drivers/net/phy/microchip_t1.c
@@ -12,6 +12,7 @@ 
 
 #define PHY_ID_LAN87XX				0x0007c150
 #define PHY_ID_LAN937X				0x0007c180
+#define PHY_ID_LAN937X_TX			0x0007c190
 
 /* External Register Control Register */
 #define LAN87XX_EXT_REG_CTL                     (0x14)
@@ -94,6 +95,10 @@ 
 /* SQI defines */
 #define LAN87XX_MAX_SQI			0x07
 
+#define LAN937X_MODE_CTRL_STATUS_REG	0x11
+#define LAN937X_AUTOMDIX_EN		BIT(7)
+#define LAN937X_MDI_MODE		BIT(6)
+
 #define DRIVER_AUTHOR	"Nisar Sayed <nisar.sayed@microchip.com>"
 #define DRIVER_DESC	"Microchip LAN87XX/LAN937x T1 PHY driver"
 
@@ -860,6 +865,66 @@  static int lan87xx_get_sqi_max(struct phy_device *phydev)
 	return LAN87XX_MAX_SQI;
 }
 
+static int lan937x_tx_read_status(struct phy_device *phydev)
+{
+	int ret;
+
+	ret = genphy_read_status(phydev);
+	if (ret < 0)
+		return ret;
+
+	ret = phy_read(phydev, LAN937X_MODE_CTRL_STATUS_REG);
+	if (ret < 0)
+		return ret;
+
+	if (ret & LAN937X_AUTOMDIX_EN) {
+		phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
+		/* MDI/MDIX status is unknown */
+		phydev->mdix = ETH_TP_MDI_INVALID;
+	} else if (ret & LAN937X_MDI_MODE) {
+		phydev->mdix_ctrl = ETH_TP_MDI_X;
+		phydev->mdix = ETH_TP_MDI_X;
+	} else {
+		phydev->mdix_ctrl = ETH_TP_MDI;
+		phydev->mdix = ETH_TP_MDI;
+	}
+
+	return 0;
+}
+
+static int lan937x_tx_config_mdix(struct phy_device *phydev, u8 ctrl)
+{
+	u16 val;
+
+	switch (ctrl) {
+	case ETH_TP_MDI:
+		val = 0;
+		break;
+	case ETH_TP_MDI_X:
+		val = LAN937X_MDI_MODE;
+		break;
+	case ETH_TP_MDI_AUTO:
+		val = LAN937X_AUTOMDIX_EN;
+		break;
+	default:
+		return 0;
+	}
+
+	return phy_modify(phydev, LAN937X_MODE_CTRL_STATUS_REG,
+			  LAN937X_AUTOMDIX_EN | LAN937X_MDI_MODE, val);
+}
+
+static int lan937x_tx_config_aneg(struct phy_device *phydev)
+{
+	int ret;
+
+	ret = genphy_config_aneg(phydev);
+	if (ret)
+		return ret;
+
+	return lan937x_tx_config_mdix(phydev, phydev->mdix_ctrl);
+}
+
 static struct phy_driver microchip_t1_phy_driver[] = {
 	{
 		PHY_ID_MATCH_MODEL(PHY_ID_LAN87XX),
@@ -894,6 +959,14 @@  static struct phy_driver microchip_t1_phy_driver[] = {
 		.get_sqi_max	= lan87xx_get_sqi_max,
 		.cable_test_start = lan87xx_cable_test_start,
 		.cable_test_get_status = lan87xx_cable_test_get_status,
+	},
+	{
+		PHY_ID_MATCH_MODEL(PHY_ID_LAN937X_TX),
+		.name		= "Microchip LAN937x TX",
+		.suspend	= genphy_suspend,
+		.resume		= genphy_resume,
+		.config_aneg	= lan937x_tx_config_aneg,
+		.read_status	= lan937x_tx_read_status,
 	}
 };
 
@@ -902,6 +975,7 @@  module_phy_driver(microchip_t1_phy_driver);
 static struct mdio_device_id __maybe_unused microchip_t1_tbl[] = {
 	{ PHY_ID_MATCH_MODEL(PHY_ID_LAN87XX) },
 	{ PHY_ID_MATCH_MODEL(PHY_ID_LAN937X) },
+	{ PHY_ID_MATCH_MODEL(PHY_ID_LAN937X_TX) },
 	{ }
 };