All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: smsc911x: add power management functions
@ 2009-05-04 17:12 Daniel Mack
  2009-05-05  4:32 ` David Miller
  2009-05-05  8:37 ` Steve.Glendinning
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Mack @ 2009-05-04 17:12 UTC (permalink / raw)
  To: netdev; +Cc: Daniel Mack, Steve Glendinning

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 <steve.glendinning@smsc.com>
Signed-off-by: Daniel Mack <daniel@caiaq.de>
---
 drivers/net/smsc911x.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/drivers/net/smsc911x.c b/drivers/net/smsc911x.c
index eb7db03..77d164e 100644
--- a/drivers/net/smsc911x.c
+++ b/drivers/net/smsc911x.c
@@ -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 */
-- 
1.6.2.1


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

* Re: [PATCH] net: smsc911x: add power management functions
  2009-05-04 17:12 [PATCH] net: smsc911x: add power management functions Daniel Mack
@ 2009-05-05  4:32 ` David Miller
  2009-05-05  8:37 ` Steve.Glendinning
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2009-05-05  4:32 UTC (permalink / raw)
  To: daniel; +Cc: netdev, steve.glendinning

From: Daniel Mack <daniel@caiaq.de>
Date: Mon,  4 May 2009 19:12:02 +0200

> 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 <steve.glendinning@smsc.com>
> Signed-off-by: Daniel Mack <daniel@caiaq.de>

Steve, is this OK?

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

* Re: [PATCH] net: smsc911x: add power management functions
  2009-05-04 17:12 [PATCH] net: smsc911x: add power management functions Daniel Mack
  2009-05-05  4:32 ` David Miller
@ 2009-05-05  8:37 ` Steve.Glendinning
  2009-05-05  8:40   ` Daniel Mack
  1 sibling, 1 reply; 4+ messages in thread
From: Steve.Glendinning @ 2009-05-05  8:37 UTC (permalink / raw)
  To: Daniel Mack; +Cc: netdev, David Miller, Ian.Saturley

Daniel Mack <daniel@caiaq.de> wrote on 04/05/2009 18:12:02:

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

[....]

> +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;
> +}

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

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

* Re: [PATCH] net: smsc911x: add power management functions
  2009-05-05  8:37 ` Steve.Glendinning
@ 2009-05-05  8:40   ` Daniel Mack
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Mack @ 2009-05-05  8:40 UTC (permalink / raw)
  To: Steve.Glendinning; +Cc: netdev, David Miller, Ian.Saturley

On Tue, May 05, 2009 at 09:37:42AM +0100, Steve.Glendinning@smsc.com wrote:
> > 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.
> 
> [....]
> 
> > +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;
> > +}
> 
> 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.

> Other than that, the power saving logic looks fine.

Thanks for your review :)

Daniel


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

end of thread, other threads:[~2009-05-05  8:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-04 17:12 [PATCH] net: smsc911x: add power management functions Daniel Mack
2009-05-05  4:32 ` David Miller
2009-05-05  8:37 ` Steve.Glendinning
2009-05-05  8:40   ` Daniel Mack

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.