diff mbox series

[net-next,v1,4/4] net: usb: asix: suspend internal PHY if external is used

Message ID 20220310114434.3465481-4-o.rempel@pengutronix.de (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v1,1/4] net: usb: asix: unify ax88772_resume code | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter warning Series does not have a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 1 maintainers not CCed: linux@rempel-privat.de
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: Block comments use a trailing */ on a separate line
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Oleksij Rempel March 10, 2022, 11:44 a.m. UTC
In case external PHY is used, we need to take care of internal PHY.
Since there are no methods to disable this PHY from the MAC side, we
need to suspend it.
This we reduce electrical noise (PHY is continuing to send FLPs) and power
consumption by 0,22W.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/usb/asix.h         |  3 +++
 drivers/net/usb/asix_devices.c | 16 +++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

Comments

Andrew Lunn March 10, 2022, 7:19 p.m. UTC | #1
On Thu, Mar 10, 2022 at 12:44:34PM +0100, Oleksij Rempel wrote:
> In case external PHY is used, we need to take care of internal PHY.
> Since there are no methods to disable this PHY from the MAC side, we
> need to suspend it.
> This we reduce electrical noise (PHY is continuing to send FLPs) and power
> consumption by 0,22W.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/usb/asix.h         |  3 +++
>  drivers/net/usb/asix_devices.c | 16 +++++++++++++++-
>  2 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/usb/asix.h b/drivers/net/usb/asix.h
> index 072760d76a72..8a087205355d 100644
> --- a/drivers/net/usb/asix.h
> +++ b/drivers/net/usb/asix.h
> @@ -158,6 +158,8 @@
>  #define AX_EEPROM_MAGIC		0xdeadbeef
>  #define AX_EEPROM_LEN		0x200
>  
> +#define AX_INTERNAL_PHY_ADDR	0x10
> +
>  /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
>  struct asix_data {
>  	u8 multi_filter[AX_MCAST_FILTER_SIZE];
> @@ -183,6 +185,7 @@ struct asix_common_private {
>  	struct asix_rx_fixup_info rx_fixup_info;
>  	struct mii_bus *mdio;
>  	struct phy_device *phydev;
> +	struct phy_device *phydev_int;
>  	u16 phy_addr;
>  	bool embd_phy;
>  	u8 chipcode;
> diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
> index fb617eb551bb..2c63fbe32ca2 100644
> --- a/drivers/net/usb/asix_devices.c
> +++ b/drivers/net/usb/asix_devices.c
> @@ -679,6 +679,20 @@ static int ax88772_init_phy(struct usbnet *dev)
>  
>  	phy_attached_info(priv->phydev);
>  
> +	if (priv->embd_phy)
> +		return 0;

Minor nit pick: There appears to be some inconsistency with internal
and embedded. I think they are meant to mean the same thing? Maybe
replace internal with embedded in this patch?

The rest looks O.K.

    Andrew
Jakub Kicinski March 10, 2022, 8:43 p.m. UTC | #2
On Thu, 10 Mar 2022 12:44:34 +0100 Oleksij Rempel wrote:
> +	/* In case main PHY is not the embedded PHY, we need to take care of
> +	 * embedded PHY as well. */

Another nit would be to move the */ to the next line like checkpatch
wants us to.
diff mbox series

Patch

diff --git a/drivers/net/usb/asix.h b/drivers/net/usb/asix.h
index 072760d76a72..8a087205355d 100644
--- a/drivers/net/usb/asix.h
+++ b/drivers/net/usb/asix.h
@@ -158,6 +158,8 @@ 
 #define AX_EEPROM_MAGIC		0xdeadbeef
 #define AX_EEPROM_LEN		0x200
 
+#define AX_INTERNAL_PHY_ADDR	0x10
+
 /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
 struct asix_data {
 	u8 multi_filter[AX_MCAST_FILTER_SIZE];
@@ -183,6 +185,7 @@  struct asix_common_private {
 	struct asix_rx_fixup_info rx_fixup_info;
 	struct mii_bus *mdio;
 	struct phy_device *phydev;
+	struct phy_device *phydev_int;
 	u16 phy_addr;
 	bool embd_phy;
 	u8 chipcode;
diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index fb617eb551bb..2c63fbe32ca2 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -679,6 +679,20 @@  static int ax88772_init_phy(struct usbnet *dev)
 
 	phy_attached_info(priv->phydev);
 
+	if (priv->embd_phy)
+		return 0;
+
+	/* In case main PHY is not the embedded PHY, we need to take care of
+	 * embedded PHY as well. */
+	priv->phydev_int = mdiobus_get_phy(priv->mdio, AX_INTERNAL_PHY_ADDR);
+	if (!priv->phydev_int) {
+		netdev_err(dev->net, "Could not find internal PHY\n");
+		return -ENODEV;
+	}
+
+	priv->phydev_int->mac_managed_pm = 1;
+	phy_suspend(priv->phydev_int);
+
 	return 0;
 }
 
@@ -734,7 +748,7 @@  static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
 		return ret;
 
 	priv->phy_addr = ret;
-	priv->embd_phy = ((priv->phy_addr & 0x1f) == 0x10);
+	priv->embd_phy = ((priv->phy_addr & 0x1f) == AX_INTERNAL_PHY_ADDR);
 
 	ret = asix_read_cmd(dev, AX_CMD_STATMNGSTS_REG, 0, 0, 1,
 			    &priv->chipcode, 0);