public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH, RFC] linkstation: implement standby
@ 2007-08-26  0:03 Guennadi Liakhovetski
  0 siblings, 0 replies; 7+ messages in thread
From: Guennadi Liakhovetski @ 2007-08-26  0:03 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Scott Wood, linux-pm

Implement suspend/resume for "mpc10x" compatible fsl host PCI controllers, 
use it for linkstation standby.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>

---

This requires patches from Scott Wood from this thread: 
http://ozlabs.org/pipermail/linuxppc-dev/2007-July/039109.html and my 
recent patch to implement wakeup from serial ports.

Thanks
Guennadi

 arch/powerpc/platforms/embedded6xx/linkstation.c |   57 +++++++++++++++++++++++
 arch/powerpc/sysdev/fsl_soc.c                    |   44 +++++++++++++++++
 arch/powerpc/sysdev/fsl_soc.h                    |    6 ++
 include/asm-powerpc/mpc6xx.h                     |    2
 4 files changed, 108 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/embedded6xx/linkstation.c b/arch/powerpc/platforms/embedded6xx/linkstation.c
index ab9e3f9..8ee0f0b 100644
--- a/arch/powerpc/platforms/embedded6xx/linkstation.c
+++ b/arch/powerpc/platforms/embedded6xx/linkstation.c
@@ -197,3 +197,60 @@ define_machine(linkstation){
 	.halt	 		= linkstation_halt,
 	.calibrate_decr 	= generic_calibrate_decr,
 };
+
+#ifdef CONFIG_PM
+
+#include <sysdev/fsl_soc.h>
+#include <asm/mpc6xx.h>
+
+static int ls_pm_valid(suspend_state_t state)
+{
+	switch (state) {
+	case PM_SUSPEND_STANDBY:
+		return 1;
+	default:
+		return 0;
+	}
+}
+
+static int ls_pm_enter(suspend_state_t state)
+{
+	char ier;
+	int ret = 0;
+	u64 tb;
+
+	if ((ret = mpc10x_suspend(state)) < 0)
+		return ret;
+
+	/* Get timebase */
+	tb = get_tb();
+
+	/* put CPU to sleep, re-enabling interrupts */
+	mpc6xx_enter_sleep();
+
+	local_irq_disable();
+
+	set_tb(tb >> 32, tb & 0xfffffffful);
+
+fail:
+	mpc10x_resume(state);
+
+	return ret;
+}
+
+static struct pm_ops ls_pm_ops = {
+	.valid		= ls_pm_valid,
+	.enter		= ls_pm_enter,
+};
+
+static int __init ls_pm_init(void)
+{
+	if (!machine_is(linkstation))
+		return 0;
+
+	pm_set_ops(&ls_pm_ops);
+	return 0;
+}
+
+device_initcall(ls_pm_init);
+#endif
diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index 727453d..c0d66df 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -1186,3 +1186,47 @@ err:
 arch_initcall(cpm_smc_uart_of_init);
 
 #endif /* CONFIG_8xx */
+
+#ifdef CONFIG_PM
+#include <linux/pci.h>
+#include <asm/pci-bridge.h>
+
+#define	MPC10X_LP_REF_EN	(1<<12)
+#define	MPC10X_PM		(1<<7)
+#define MPC10X_DOZE		(1<<5)
+#define	MPC10X_NAP		(1<<4)
+#define	MPC10X_SLEEP		(1<<3)
+
+int mpc10x_suspend(suspend_state_t state)
+{
+	struct pci_dev *bridge;
+	u16 pmcr1;
+
+	bridge = pci_find_slot(0, 0);
+	if (!bridge)
+		return -ENODEV;
+
+	pci_read_config_word(bridge, 0x70, &pmcr1);
+	pmcr1 &= ~(MPC10X_DOZE | MPC10X_NAP);
+	pmcr1 |= MPC10X_PM | MPC10X_SLEEP | MPC10X_LP_REF_EN;
+	pci_write_config_word(bridge, 0x70, pmcr1);
+
+	return 0;
+}
+
+int mpc10x_resume(suspend_state_t state)
+{
+	struct pci_dev *bridge;
+	u16 pmcr1;
+
+	bridge = pci_find_slot(0, 0);
+	if (!bridge)
+		return -ENODEV;
+
+	pci_read_config_word(bridge, 0x70, &pmcr1);
+	pmcr1 &= ~(MPC10X_PM | MPC10X_DOZE | MPC10X_SLEEP | MPC10X_NAP | MPC10X_LP_REF_EN);
+	pci_write_config_word(bridge, 0x70, pmcr1);
+
+	return 0;
+}
+#endif
diff --git a/arch/powerpc/sysdev/fsl_soc.h b/arch/powerpc/sysdev/fsl_soc.h
index 04e145b..bcb96cf 100644
--- a/arch/powerpc/sysdev/fsl_soc.h
+++ b/arch/powerpc/sysdev/fsl_soc.h
@@ -8,5 +8,11 @@ extern phys_addr_t get_immrbase(void);
 extern u32 get_brgfreq(void);
 extern u32 get_baudrate(void);
 
+#ifdef CONFIG_PM
+#include <linux/pm.h>
+extern int mpc10x_suspend(suspend_state_t state);
+extern int mpc10x_resume(suspend_state_t state);
+#endif
+
 #endif
 #endif
diff --git a/include/asm-powerpc/mpc6xx.h b/include/asm-powerpc/mpc6xx.h
index 01a33ed..be86967 100644
--- a/include/asm-powerpc/mpc6xx.h
+++ b/include/asm-powerpc/mpc6xx.h
@@ -1,6 +1,6 @@
 #ifndef __ASM_POWERPC_MPC6xx_H
 #define __ASM_POWERPC_MPC6xx_H
 
-void mpc6xx_enter_sleep(void);
+extern void mpc6xx_enter_sleep(void);
 
 #endif

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

* Re: [PATCH, RFC] linkstation: implement standby
       [not found] <Pine.LNX.4.60.0708260157330.3809@poirot.grange>
@ 2007-08-26  1:08 ` Stephen Rothwell
       [not found] ` <20070826110830.dfe6ea24.sfr@canb.auug.org.au>
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Stephen Rothwell @ 2007-08-26  1:08 UTC (permalink / raw)
  To: Guennadi Liakhovetski; +Cc: linuxppc-dev, linux-pm


[-- Attachment #1.1: Type: text/plain, Size: 620 bytes --]

On Sun, 26 Aug 2007 02:03:49 +0200 (CEST) Guennadi Liakhovetski <g.liakhovetski@gmx.de> wrote:
>
> +static int ls_pm_enter(suspend_state_t state)
> +{
> +	char ier;
> +	int ret = 0;
> +	u64 tb;
> +
> +	if ((ret = mpc10x_suspend(state)) < 0)
> +		return ret;
> +
> +	/* Get timebase */
> +	tb = get_tb();
> +
> +	/* put CPU to sleep, re-enabling interrupts */
> +	mpc6xx_enter_sleep();
> +
> +	local_irq_disable();
> +
> +	set_tb(tb >> 32, tb & 0xfffffffful);
> +
> +fail:

Unused label?

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

[-- Attachment #1.2: Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



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

* Re: [PATCH, RFC] linkstation: implement standby
       [not found] ` <20070826110830.dfe6ea24.sfr@canb.auug.org.au>
@ 2007-08-26 19:10   ` Guennadi Liakhovetski
  0 siblings, 0 replies; 7+ messages in thread
From: Guennadi Liakhovetski @ 2007-08-26 19:10 UTC (permalink / raw)
  To: Stephen Rothwell; +Cc: linuxppc-dev, linux-pm

On Sun, 26 Aug 2007, Stephen Rothwell wrote:

> On Sun, 26 Aug 2007 02:03:49 +0200 (CEST) Guennadi Liakhovetski <g.liakhovetski@gmx.de> wrote:
> >
> > +static int ls_pm_enter(suspend_state_t state)
> > +{
> > +	char ier;
> > +	int ret = 0;
> > +	u64 tb;
> > +
> > +	if ((ret = mpc10x_suspend(state)) < 0)
> > +		return ret;
> > +
> > +	/* Get timebase */
> > +	tb = get_tb();
> > +
> > +	/* put CPU to sleep, re-enabling interrupts */
> > +	mpc6xx_enter_sleep();
> > +
> > +	local_irq_disable();
> > +
> > +	set_tb(tb >> 32, tb & 0xfffffffful);
> > +
> > +fail:
> 
> Unused label?

Right, will fix in the next version, thanks.

Guennadi
---
Guennadi Liakhovetski

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

* Re: [PATCH, RFC] linkstation: implement standby
       [not found] <Pine.LNX.4.60.0708260157330.3809@poirot.grange>
  2007-08-26  1:08 ` [PATCH, RFC] linkstation: implement standby Stephen Rothwell
       [not found] ` <20070826110830.dfe6ea24.sfr@canb.auug.org.au>
@ 2007-08-27  0:44 ` Tony Breeds
  2007-08-27 10:03 ` Pavel Machek
  2007-08-27 11:32 ` Johannes Berg
  4 siblings, 0 replies; 7+ messages in thread
From: Tony Breeds @ 2007-08-27  0:44 UTC (permalink / raw)
  To: Guennadi Liakhovetski; +Cc: linuxppc-dev, linux-pm

On Sun, Aug 26, 2007 at 02:03:49AM +0200, Guennadi Liakhovetski wrote:
> Implement suspend/resume for "mpc10x" compatible fsl host PCI controllers, 
> use it for linkstation standby.

Hi Guennadi

<snip>

> +static int __init ls_pm_init(void)
> +{
> +	if (!machine_is(linkstation))
> +		return 0;

This should probably be -ENODEV.

<snip>

> +int mpc10x_suspend(suspend_state_t state)

You only seem to call this from ls_pm_enter() where you don't check the
return value, perhaps this should be void ?

> +{
> +	struct pci_dev *bridge;
> +	u16 pmcr1;
> +
> +	bridge = pci_find_slot(0, 0);
> +	if (!bridge)
> +		return -ENODEV;

I think you want pci_get_bus_and_slot() here instead of pci_find_slot(),
in fact I think it'd be cleaner, if you located the bridge in
ls_pm_enter() and passed it in.

> +int mpc10x_resume(suspend_state_t state)
> +{
> +	struct pci_dev *bridge;
> +	u16 pmcr1;
> +
> +	bridge = pci_find_slot(0, 0);
> +	if (!bridge)
> +		return -ENODEV;

Same comments ass mpc10x_suspend();

Yours Tony

  linux.conf.au        http://linux.conf.au/ || http://lca2008.linux.org.au/
  Jan 28 - Feb 02 2008 The Australian Linux Technical Conference!

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

* Re: [PATCH, RFC] linkstation: implement standby
       [not found] <Pine.LNX.4.60.0708260157330.3809@poirot.grange>
                   ` (2 preceding siblings ...)
  2007-08-27  0:44 ` Tony Breeds
@ 2007-08-27 10:03 ` Pavel Machek
  2007-08-27 11:32 ` Johannes Berg
  4 siblings, 0 replies; 7+ messages in thread
From: Pavel Machek @ 2007-08-27 10:03 UTC (permalink / raw)
  To: Guennadi Liakhovetski; +Cc: Scott Wood, linuxppc-dev, linux-pm

On Sun 2007-08-26 02:03:49, Guennadi Liakhovetski wrote:
> Implement suspend/resume for "mpc10x" compatible fsl host PCI controllers, 
> use it for linkstation standby.
> 
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>

Looks okay to me. I'm glad to see "standby" is present on non-i386
machines, too.
							Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [PATCH, RFC] linkstation: implement standby
       [not found] <Pine.LNX.4.60.0708260157330.3809@poirot.grange>
                   ` (3 preceding siblings ...)
  2007-08-27 10:03 ` Pavel Machek
@ 2007-08-27 11:32 ` Johannes Berg
       [not found]   ` <Pine.LNX.4.60.0708290015580.3552@poirot.grange>
  4 siblings, 1 reply; 7+ messages in thread
From: Johannes Berg @ 2007-08-27 11:32 UTC (permalink / raw)
  To: Guennadi Liakhovetski; +Cc: linuxppc-dev, linux-pm


[-- Attachment #1.1: Type: text/plain, Size: 158 bytes --]

On Sun, 2007-08-26 at 02:03 +0200, Guennadi Liakhovetski wrote:

> +#ifdef CONFIG_PM

some of those probably want to be CONFIG_PM_SLEEP now.

johannes

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



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

* Re: [PATCH, RFC] linkstation: implement standby
       [not found]   ` <Pine.LNX.4.60.0708290015580.3552@poirot.grange>
@ 2007-08-29 10:32     ` Johannes Berg
  0 siblings, 0 replies; 7+ messages in thread
From: Johannes Berg @ 2007-08-29 10:32 UTC (permalink / raw)
  To: Guennadi Liakhovetski
  Cc: Stephen Rothwell, Tony Breeds, linuxppc-dev, Scott Wood, linux-pm


[-- Attachment #1.1: Type: text/plain, Size: 462 bytes --]

On Wed, 2007-08-29 at 00:30 +0200, Guennadi Liakhovetski wrote:

> > > +#ifdef CONFIG_PM
> > 
> > some of those probably want to be CONFIG_PM_SLEEP now.
> 
> Well, I wasn't sure when PM can be used not meaning PM_SLEEP, so, I left 
> PM for now. Can certainly change, if it really matters.

You end up compiling more code than necessary if PM_SLEEP is disabled
but PM is enabled (i.e. runtime powermanagement enabled but no sleep
states)

johannes

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 190 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



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

end of thread, other threads:[~2007-08-29 10:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <Pine.LNX.4.60.0708260157330.3809@poirot.grange>
2007-08-26  1:08 ` [PATCH, RFC] linkstation: implement standby Stephen Rothwell
     [not found] ` <20070826110830.dfe6ea24.sfr@canb.auug.org.au>
2007-08-26 19:10   ` Guennadi Liakhovetski
2007-08-27  0:44 ` Tony Breeds
2007-08-27 10:03 ` Pavel Machek
2007-08-27 11:32 ` Johannes Berg
     [not found]   ` <Pine.LNX.4.60.0708290015580.3552@poirot.grange>
2007-08-29 10:32     ` Johannes Berg
2007-08-26  0:03 Guennadi Liakhovetski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox