[PATH] physical abstraction layer suspend/resume functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All,
the patch attached adds the suspend/resume into the PAL (kernel 2.6.25.4).
The generic suspend/resume functions only program the MII control register bit 11 in order to put in power down the PHY device. If the MAC driver is able to wake-up the system (should_wakeup:1) the PHY device attached will not be turned-off.

I'm testing it on the stlinux kernel 2.6.23_17 (through the PM Linux framework), using an embedded MAC with the following PHYs:
ste100p, ste101p, sms lan 8700.

To use it:
- On PHY side:
drivers/net/phy/<phy_device.c> should have the suspend/resume (phy_driver structure) as the Generic driver does.

- On MAC:
 in the Ethernet driver,  something like this could be enough:

static int <device>_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{
       struct eth_driver_local *lp = netdev_priv(dev);
       u32 support = WAKE_MAGIC;
   ...
       if (wol->wolopts == 0)
               device_set_wakeup_enable(lp->device, 0);
       else
               device_set_wakeup_enable(lp->device, 1);
  ...
       lp->wolopts = wol->wolopts;
  ...

       return 0;
}


Regards,
Giuseppe
This patch adds the generic suspend and resume functions.
If the Ethernet driver is able to wake-on LAN, the PHY device
is not put in power save mode.

Signed-off-by: Giuseppe Cavallaro <peppe.cavallaro@xxxxxx>

diff -uprN linux-2.6.25.4/drivers/net/phy.orig/mdio_bus.c linux-2.6.25.4/drivers/net/phy/mdio_bus.c
--- linux-2.6.25.4/drivers/net/phy.orig/mdio_bus.c	2008-06-03 11:44:31.000000000 +0200
+++ linux-2.6.25.4/drivers/net/phy/mdio_bus.c	2008-06-03 11:44:54.000000000 +0200
@@ -143,9 +143,12 @@ static int mdio_bus_suspend(struct devic
 {
 	int ret = 0;
 	struct device_driver *drv = dev->driver;
+	struct phy_driver *phydrv = to_phy_driver(drv);
+	struct phy_device *phydev = to_phy_device(dev);
 
-	if (drv && drv->suspend)
-		ret = drv->suspend(dev, state);
+	if ((!device_may_wakeup(phydev->dev.parent)) && 
+		(phydrv && phydrv->suspend))
+			ret = phydrv->suspend(phydev);
 
 	return ret;
 }
@@ -154,9 +157,12 @@ static int mdio_bus_resume(struct device
 {
 	int ret = 0;
 	struct device_driver *drv = dev->driver;
+	struct phy_driver *phydrv = to_phy_driver(drv);
+	struct phy_device *phydev = to_phy_device(dev);
 
-	if (drv && drv->resume)
-		ret = drv->resume(dev);
+	if ((!device_may_wakeup(phydev->dev.parent)) && 
+		(phydrv && phydrv->resume))
+		ret = phydrv->resume(phydev);
 
 	return ret;
 }
diff -uprN linux-2.6.25.4/drivers/net/phy.orig/phy_device.c linux-2.6.25.4/drivers/net/phy/phy_device.c
--- linux-2.6.25.4/drivers/net/phy.orig/phy_device.c	2008-06-03 11:44:31.000000000 +0200
+++ linux-2.6.25.4/drivers/net/phy/phy_device.c	2008-06-03 11:54:18.000000000 +0200
@@ -627,6 +627,36 @@ static int genphy_config_init(struct phy
 	return 0;
 }
 
+int genphy_suspend(struct phy_device *phydev)
+{
+	int value;
+
+	spin_lock_bh(&phydev->lock);
+
+	value = phy_read(phydev, MII_BMCR);
+	phy_write(phydev, MII_BMCR, (value | BMCR_PDOWN));
+
+	spin_unlock_bh(&phydev->lock);
+
+	return 0;
+}
+EXPORT_SYMBOL(genphy_suspend);
+
+int genphy_resume(struct phy_device *phydev)
+{
+	int value;
+
+	spin_lock_bh(&phydev->lock);
+
+	value = phy_read(phydev, MII_BMCR);
+	phy_write(phydev, MII_BMCR, (value & ~BMCR_PDOWN));
+
+	spin_unlock_bh(&phydev->lock);
+
+	return 0;
+}
+
+EXPORT_SYMBOL(genphy_resume);
 
 /**
  * phy_probe - probe and init a PHY device
@@ -737,6 +767,8 @@ static struct phy_driver genphy_driver =
 	.features	= 0,
 	.config_aneg	= genphy_config_aneg,
 	.read_status	= genphy_read_status,
+	.suspend	= genphy_suspend,
+	.resume		= genphy_resume,
 	.driver		= {.owner= THIS_MODULE, },
 };
 

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux