Skip to contentSkip to conversation

net: smsc911x: add power management functions

PATCH In review Daniel Mack 3 participants 4 messages May 4, 2009 – May 5, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: smsc911x: add power management functions

This adds a power management implementation for smsc911x.c which assumes the chips remains powered during suspend. The device is put in its D1 power saving mode.

Cc Steve Glendinning <[email protected]>
---
 drivers/net/smsc911x.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
drivers/net/smsc911x.c +46 -0
index eb7db03..77d164e 100644
@@ -2096,12 +2096,58 @@ out_0:
 	return retval;
 }
 
+#ifdef CONFIG_PM
+/* This implementation assumes the devices remains powered on its VDDVARIO
+ * pins during suspend. */
+
+static int smsc911x_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	struct net_device *dev = platform_get_drvdata(pdev);
+	struct smsc911x_data *pdata = netdev_priv(dev);
+
+	/* enable wake on LAN, energy detection and the external PME
+	 * signal. */
+	smsc911x_reg_write(pdata, PMT_CTRL,
+		PMT_CTRL_PM_MODE_D1_ | PMT_CTRL_WOL_EN_ |
+		PMT_CTRL_ED_EN_ | PMT_CTRL_PME_EN_);
+
+	return 0;
+}
+
+static int smsc911x_resume(struct platform_device *pdev)
+{
+	struct net_device *dev = platform_get_drvdata(pdev);
+	struct smsc911x_data *pdata = netdev_priv(dev);
+	unsigned int to = 100;
+
+	/* Note 3.11 from the datasheet:
+	 * 	"When the LAN9220 is in a power saving state, a write of any
+	 * 	 data to the BYTE_TEST register will wake-up the device."
+	 */
+	smsc911x_reg_write(pdata, BYTE_TEST, 0);
+
+	/* poll the READY bit in PMT_CTRL. Any other access to the device is
+	 * forbidden while this bit isn't set. Try for 100ms and return -EIO
+	 * if it failed. */
+	while (!(smsc911x_reg_read(pdata, PMT_CTRL) & PMT_CTRL_READY_) && to--)
+		udelay(1000);
+
+	return (to == 0) ? -EIO : 0;
+}
+
+#else
+#define smsc911x_suspend	NULL
+#define smsc911x_resume		NULL
+#endif
+
 static struct platform_driver smsc911x_driver = {
 	.probe = smsc911x_drv_probe,
 	.remove = smsc911x_drv_remove,
 	.driver = {
 		.name = SMSC_CHIPNAME,
 	},
+	.suspend = smsc911x_suspend,
+	.resume = smsc911x_resume,
 };
 
 /* Entry point for loading the module */
Signature · 1 line
1.6.2.1
#2 lore raw
In reply to Daniel Mack

Daniel Mack <[email protected]> wrote on 04/05/2009 18:12:02:

Quoted 3 lines

This adds a power management implementation for smsc911x.c which assumes the chips remains powered during suspend. The device is put in its D1 power saving mode.

[....]

Quoted 6 lines
drivers/net/smsc911x.c +6 -0
+static int smsc911x_resume(struct platform_device *pdev)
+{
+   struct net_device *dev = platform_get_drvdata(pdev);
+   struct smsc911x_data *pdata = netdev_priv(dev);
+   unsigned int to = 100;
+

drivers/net/smsc911x.c out_0:

Quoted 10 lines
drivers/net/smsc911x.c +10 -0
+   /* Note 3.11 from the datasheet:
+    *    "When the LAN9220 is in a power saving state, a write of any
+    *     data to the BYTE_TEST register will wake-up the device."
+    */
+   smsc911x_reg_write(pdata, BYTE_TEST, 0);
+
+   /* poll the READY bit in PMT_CTRL. Any other access to the device is
+    * forbidden while this bit isn't set. Try for 100ms and return -EIO
+    * if it failed. */
+   while (!(smsc911x_reg_read(pdata, PMT_CTRL) & PMT_CTRL_READY_) && 

to--)

drivers/net/smsc911x.c out_0: · line 2136

Quoted 4 lines
drivers/net/smsc911x.c +4 -0
+      udelay(1000);
+
+   return (to == 0) ? -EIO : 0;
+}

to-- should be --to, otherwise it'll end up as -1 when the loop times out (and the error code return below won't work). Roel Kluin recently fixed many instances of this.

Other than that, the power saving logic looks fine.

Steve

#3 lore raw
Quoted 23 lines · On Tue, May 05, 2009 at 09:37:42AM +0100, [email protected] wrote:
Quoted 3 lines

This adds a power management implementation for smsc911x.c which assumes the chips remains powered during suspend. The device is put in its D1 power saving mode.

[....]

Quoted 6 lines
drivers/net/smsc911x.c +6 -0
+static int smsc911x_resume(struct platform_device *pdev)
+{
+   struct net_device *dev = platform_get_drvdata(pdev);
+   struct smsc911x_data *pdata = netdev_priv(dev);
+   unsigned int to = 100;
+

drivers/net/smsc911x.c out_0:

Quoted 10 lines
drivers/net/smsc911x.c +10 -0
+   /* Note 3.11 from the datasheet:
+    *    "When the LAN9220 is in a power saving state, a write of any
+    *     data to the BYTE_TEST register will wake-up the device."
+    */
+   smsc911x_reg_write(pdata, BYTE_TEST, 0);
+
+   /* poll the READY bit in PMT_CTRL. Any other access to the device is
+    * forbidden while this bit isn't set. Try for 100ms and return -EIO
+    * if it failed. */
+   while (!(smsc911x_reg_read(pdata, PMT_CTRL) & PMT_CTRL_READY_) && 

to--)

Quoted 8 lines

drivers/net/smsc911x.c out_0: · line 2136

Quoted 4 lines
drivers/net/smsc911x.c +4 -0
+      udelay(1000);
+
+   return (to == 0) ? -EIO : 0;
+}

to-- should be --to, otherwise it'll end up as -1 when the loop times out (and the error code return below won't work). Roel Kluin recently fixed many instances of this.

Yep, that's been pointed out by Enrik Berkhan already. David Miller offered to fix that on the fly when commiting.

Quoted 1 line

Other than that, the power saving logic looks fine.

Thanks for your review :)

Daniel