linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] net: phy: tja11xx: add support for master-slave configuration
@ 2020-04-15 12:34 Oleksij Rempel
  2020-04-15 12:56 ` Oleksij Rempel
  0 siblings, 1 reply; 2+ messages in thread
From: Oleksij Rempel @ 2020-04-15 12:34 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Florian Fainelli, Heiner Kallweit,
	Jakub Kicinski, Jonathan Corbet, Michal Kubecek
  Cc: Oleksij Rempel, David Jander, kernel, linux-kernel, netdev,
	Russell King, mkl, Marek Vasut

The TJA11xx PHYs have a vendor specific Master/Slave configuration bit,
which is not compatible with IEEE 803.2-2018 spec for 100Base-T1
devices. So, provide a custom config_ange call back to solve this
problem.

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

diff --git a/drivers/net/phy/nxp-tja11xx.c b/drivers/net/phy/nxp-tja11xx.c
index 2bde9386baf1f..0042ee453cbd4 100644
--- a/drivers/net/phy/nxp-tja11xx.c
+++ b/drivers/net/phy/nxp-tja11xx.c
@@ -30,6 +30,7 @@
 #define MII_ECTRL_WAKE_REQUEST		BIT(0)
 
 #define MII_CFG1			18
+#define MII_CFG1_MASTER_SLAVE		BIT(15)
 #define MII_CFG1_AUTO_OP		BIT(14)
 #define MII_CFG1_SLEEP_CONFIRM		BIT(6)
 #define MII_CFG1_LED_MODE_MASK		GENMASK(5, 4)
@@ -177,6 +178,31 @@ static int tja11xx_soft_reset(struct phy_device *phydev)
 	return genphy_soft_reset(phydev);
 }
 
+static int tja11xx_config_aneg(struct phy_device *phydev)
+{
+	u16 ctl = 0;
+	int ret;
+
+	switch (phydev->master_slave) {
+	case PORT_MODE_MASTER:
+		ctl |= MII_CFG1_MASTER_SLAVE;
+		break;
+	case PORT_MODE_SLAVE:
+		break;
+	case PORT_MODE_UNKNOWN:
+		return 0;
+	default:
+		phydev_warn(phydev, "Unsupported Master/Slave mode\n");
+		return -ENOTSUPP;
+	}
+
+	ret = phy_modify_changed(phydev, MII_CFG1, MII_CFG1_MASTER_SLAVE, ctl);
+	if (ret < 0)
+		return ret;
+
+	return __genphy_config_aneg(phydev, ret);
+}
+
 static int tja11xx_config_init(struct phy_device *phydev)
 {
 	int ret;
@@ -245,6 +271,15 @@ static int tja11xx_read_status(struct phy_device *phydev)
 
 		if (!(ret & MII_COMMSTAT_LINK_UP))
 			phydev->link = 0;
+
+		ret = phy_read(phydev, MII_CFG1);
+		if (ret < 0)
+			return ret;
+
+		if (ret & MII_CFG1_MASTER_SLAVE)
+			phydev->master_slave = PORT_MODE_MASTER;
+		else
+			phydev->master_slave = PORT_MODE_SLAVE;
 	}
 
 	return 0;
@@ -514,6 +549,7 @@ static struct phy_driver tja11xx_driver[] = {
 		.features       = PHY_BASIC_T1_FEATURES,
 		.probe		= tja11xx_probe,
 		.soft_reset	= tja11xx_soft_reset,
+		.config_aneg	= tja11xx_config_aneg,
 		.config_init	= tja11xx_config_init,
 		.read_status	= tja11xx_read_status,
 		.suspend	= genphy_suspend,
@@ -529,6 +565,7 @@ static struct phy_driver tja11xx_driver[] = {
 		.features       = PHY_BASIC_T1_FEATURES,
 		.probe		= tja11xx_probe,
 		.soft_reset	= tja11xx_soft_reset,
+		.config_aneg	= tja11xx_config_aneg,
 		.config_init	= tja11xx_config_init,
 		.read_status	= tja11xx_read_status,
 		.suspend	= genphy_suspend,
@@ -543,6 +580,7 @@ static struct phy_driver tja11xx_driver[] = {
 		.features       = PHY_BASIC_T1_FEATURES,
 		.probe		= tja1102_p0_probe,
 		.soft_reset	= tja11xx_soft_reset,
+		.config_aneg	= tja11xx_config_aneg,
 		.config_init	= tja11xx_config_init,
 		.read_status	= tja11xx_read_status,
 		.match_phy_device = tja1102_p0_match_phy_device,
@@ -561,6 +599,7 @@ static struct phy_driver tja11xx_driver[] = {
 		.features       = PHY_BASIC_T1_FEATURES,
 		/* currently no probe for Port 1 is need */
 		.soft_reset	= tja11xx_soft_reset,
+		.config_aneg	= tja11xx_config_aneg,
 		.config_init	= tja11xx_config_init,
 		.read_status	= tja11xx_read_status,
 		.match_phy_device = tja1102_p1_match_phy_device,
-- 
2.26.0.rc2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] net: phy: tja11xx: add support for master-slave configuration
  2020-04-15 12:34 [PATCH v1] net: phy: tja11xx: add support for master-slave configuration Oleksij Rempel
@ 2020-04-15 12:56 ` Oleksij Rempel
  0 siblings, 0 replies; 2+ messages in thread
From: Oleksij Rempel @ 2020-04-15 12:56 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Florian Fainelli, Heiner Kallweit,
	Jakub Kicinski, Jonathan Corbet, Michal Kubecek
  Cc: David Jander, kernel, linux-kernel, netdev, Russell King, mkl,
	Marek Vasut

[-- Attachment #1: Type: text/plain, Size: 4050 bytes --]

This is the followup patch to the:
ethtool: provide UAPI for PHY master/slave configuration.

On Wed, Apr 15, 2020 at 02:34:47PM +0200, Oleksij Rempel wrote:
> The TJA11xx PHYs have a vendor specific Master/Slave configuration bit,
> which is not compatible with IEEE 803.2-2018 spec for 100Base-T1
> devices. So, provide a custom config_ange call back to solve this
> problem.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/phy/nxp-tja11xx.c | 39 +++++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
> 
> diff --git a/drivers/net/phy/nxp-tja11xx.c b/drivers/net/phy/nxp-tja11xx.c
> index 2bde9386baf1f..0042ee453cbd4 100644
> --- a/drivers/net/phy/nxp-tja11xx.c
> +++ b/drivers/net/phy/nxp-tja11xx.c
> @@ -30,6 +30,7 @@
>  #define MII_ECTRL_WAKE_REQUEST		BIT(0)
>  
>  #define MII_CFG1			18
> +#define MII_CFG1_MASTER_SLAVE		BIT(15)
>  #define MII_CFG1_AUTO_OP		BIT(14)
>  #define MII_CFG1_SLEEP_CONFIRM		BIT(6)
>  #define MII_CFG1_LED_MODE_MASK		GENMASK(5, 4)
> @@ -177,6 +178,31 @@ static int tja11xx_soft_reset(struct phy_device *phydev)
>  	return genphy_soft_reset(phydev);
>  }
>  
> +static int tja11xx_config_aneg(struct phy_device *phydev)
> +{
> +	u16 ctl = 0;
> +	int ret;
> +
> +	switch (phydev->master_slave) {
> +	case PORT_MODE_MASTER:
> +		ctl |= MII_CFG1_MASTER_SLAVE;
> +		break;
> +	case PORT_MODE_SLAVE:
> +		break;
> +	case PORT_MODE_UNKNOWN:
> +		return 0;
> +	default:
> +		phydev_warn(phydev, "Unsupported Master/Slave mode\n");
> +		return -ENOTSUPP;
> +	}
> +
> +	ret = phy_modify_changed(phydev, MII_CFG1, MII_CFG1_MASTER_SLAVE, ctl);
> +	if (ret < 0)
> +		return ret;
> +
> +	return __genphy_config_aneg(phydev, ret);
> +}
> +
>  static int tja11xx_config_init(struct phy_device *phydev)
>  {
>  	int ret;
> @@ -245,6 +271,15 @@ static int tja11xx_read_status(struct phy_device *phydev)
>  
>  		if (!(ret & MII_COMMSTAT_LINK_UP))
>  			phydev->link = 0;
> +
> +		ret = phy_read(phydev, MII_CFG1);
> +		if (ret < 0)
> +			return ret;
> +
> +		if (ret & MII_CFG1_MASTER_SLAVE)
> +			phydev->master_slave = PORT_MODE_MASTER;
> +		else
> +			phydev->master_slave = PORT_MODE_SLAVE;
>  	}
>  
>  	return 0;
> @@ -514,6 +549,7 @@ static struct phy_driver tja11xx_driver[] = {
>  		.features       = PHY_BASIC_T1_FEATURES,
>  		.probe		= tja11xx_probe,
>  		.soft_reset	= tja11xx_soft_reset,
> +		.config_aneg	= tja11xx_config_aneg,
>  		.config_init	= tja11xx_config_init,
>  		.read_status	= tja11xx_read_status,
>  		.suspend	= genphy_suspend,
> @@ -529,6 +565,7 @@ static struct phy_driver tja11xx_driver[] = {
>  		.features       = PHY_BASIC_T1_FEATURES,
>  		.probe		= tja11xx_probe,
>  		.soft_reset	= tja11xx_soft_reset,
> +		.config_aneg	= tja11xx_config_aneg,
>  		.config_init	= tja11xx_config_init,
>  		.read_status	= tja11xx_read_status,
>  		.suspend	= genphy_suspend,
> @@ -543,6 +580,7 @@ static struct phy_driver tja11xx_driver[] = {
>  		.features       = PHY_BASIC_T1_FEATURES,
>  		.probe		= tja1102_p0_probe,
>  		.soft_reset	= tja11xx_soft_reset,
> +		.config_aneg	= tja11xx_config_aneg,
>  		.config_init	= tja11xx_config_init,
>  		.read_status	= tja11xx_read_status,
>  		.match_phy_device = tja1102_p0_match_phy_device,
> @@ -561,6 +599,7 @@ static struct phy_driver tja11xx_driver[] = {
>  		.features       = PHY_BASIC_T1_FEATURES,
>  		/* currently no probe for Port 1 is need */
>  		.soft_reset	= tja11xx_soft_reset,
> +		.config_aneg	= tja11xx_config_aneg,
>  		.config_init	= tja11xx_config_init,
>  		.read_status	= tja11xx_read_status,
>  		.match_phy_device = tja1102_p1_match_phy_device,
> -- 
> 2.26.0.rc2
> 
> 

-- 
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 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-15 12:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-15 12:34 [PATCH v1] net: phy: tja11xx: add support for master-slave configuration Oleksij Rempel
2020-04-15 12:56 ` Oleksij Rempel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).