Skip to contentSkip to conversation

lite5200b low power mode

RFC In review Domen Puncer 2 participants 7 messages Dec 22, 2006 – Feb 19, 2007

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

RFC 1/1 lite5200b low power mode

Hi!

I have managed to implement low power mode... well, to some degree, at least.

Short description:
patch u-boot, it's the return from wakeup code. pretty clean.

	address is saved at 0x0 (0xc000_0000)

patch linux with PM-platform_bus-and-late_suspend-early_resume.patch
didn't investigate too much, but it seems to broke mine.
patch linux with lite5200b_low_power.patch
ugly, with debugging, hacks and whatever

Boot Linux and 'echo mem > /sys/power/state'.
It won't work on PCI, possibly other devices, PSC0 and FEC seem to work ok for me.

It seems to work reliably (checksums match, so ram was in self-refresh) when called from boot scripts, but not so when from console prompt.

If someone's interested (or maybe wants to play with this during holiday? ;-) ), more info follow:

Intro
-----
lite5200b has low power mode, which turns off supply to MPC5200. It is controlled via "...QT1" microcontroller (PSC2_4 pin on mpc)

The cpu itself also supports a similar mode - deep sleep, where cpu is stopped but contents remain because it's static.

Vital for restore in both cases is putting sdram in self-refresh correctly. For deep sleep mpc5200b does that automatically (AN3045 says it's so for B rev., and tests confirm it).

self-refresh
------------
There are many ways of putting ram in self-refresh. Code can't be executed from SDRAM, but there are a few choices:
FLASH, SRAM (don't forget & ~_PAGE_GUARDED in mpc52xx_map_io), and instruction cache (prefetching via icbi or as described in g2 core reference manual didn't work for me. However, executing code surely did put it in cache).

Now, the sad part for me, is that I never actually managed to put it in SR. I've bugged Freescale, and they've been very helpfull, even tried my code on another project/kernel, and it worked.
Maybe I was doing something wrong, maybe something was accessing SDRAM (i flushed data cache, disabled interrupts).

The trick this patch uses, it to signal "low power" to "QT1", and after that put mpc5200b in deep sleep.
As I'm figuring out now, this isn't 100% ok either. I think it always worked right when called from boot scripts. Calling it from serial console is pretty much unpredictible.

deep sleep
----------
And a note about deep sleep.
I had code to put mpc in deep sleep in SRAM (so it should remain here on wakeup, to wake SDRAM). 1st stage wakeup code was interrupt handler (0x500), put in i-cache, by forcing an interrupt before sleeping.
It went to sleep, but on restore, I didn't get further than i-cached wakeup code. Jump back to SRAM failed :-(

Hopefully someone finds this useful.

I'd appreaciate any tips, ideas, patches etc. :-)

Domen

board/icecube/icecube.c +48 -0
index 4f056b2..741f1b5 100644
@@ -38,6 +38,52 @@ # else
 #include "mt48lc16m16a2-75.h"
 # endif
 #endif
+
+#ifdef CONFIG_LITE5200B
+/* u-boot part of low-power mode implementation */
+#define SAVED_ADDR 0x00000000
+void lite5200b_wakeup(void)
+{
+	unsigned char wakeup_pin;
+	void (*linux_wakeup)(void);
+
+	/* check PSC2_4, if it's down "QT" is signaling we have a wakeup
+	 * from low power mode */
+	*(vu_char *)MPC5XXX_WU_GPIO_ENABLE = 0x02;
+	__asm__ volatile ("sync");
+
+	wakeup_pin = *(vu_char *)MPC5XXX_WU_GPIO_DATA_I;
+	if (wakeup_pin & 0x02)
+		return;
+
+	/* acknowledge to "QT"
+	 * by holding pin at 1 for 10 uS */
+	*(vu_char *)MPC5XXX_WU_GPIO_DIR = 0x02;
+	__asm__ volatile ("sync");
+	*(vu_char *)MPC5XXX_WU_GPIO_DATA = 0x02;
+	__asm__ volatile ("sync");
+	udelay(10);
+
+	/* put ram out of self-refresh */
+	*(vu_long *)MPC5XXX_SDRAM_CTRL |= 0x80000000;	// mode_en
+	__asm__ volatile ("sync");
+	*(vu_long *)MPC5XXX_SDRAM_CTRL |= 0x50000000;	// cke ref_en
+	__asm__ volatile ("sync");
+	*(vu_long *)MPC5XXX_SDRAM_CTRL &= ~0x80000000;	// !mode_en
+	__asm__ volatile ("sync");
+	udelay(10); /* wait a bit */
+
+	/* jump back to linux kernel code */
+	linux_wakeup = *(unsigned long *)SAVED_ADDR;
+	printf("\n\nLooks like we just woke, transferring control to 0x%08lx\n",
+			linux_wakeup);
+	linux_wakeup();
+}
+#else
+#define lite5200b_wakeup
+#endif
+
+
 #ifndef CFG_RAMBOOT
 static void sdram_start (int hi_addr)
 {
@@ -204,6 +250,8 @@ #endif /* CFG_RAMBOOT */
 		__asm__ volatile ("sync");
 	}
 
+	lite5200b_wakeup();
+
 	return dramsize + dramsize2;
 }
 
include/mpc5xxx.h +1 -0
index 1d20d1d..c7eb090 100644
@@ -189,6 +189,7 @@ #define MPC5XXX_WU_GPIO_ENABLE  (MPC5XXX
 #define MPC5XXX_WU_GPIO_ODE     (MPC5XXX_WU_GPIO + 0x0004)
 #define MPC5XXX_WU_GPIO_DIR     (MPC5XXX_WU_GPIO + 0x0008)
 #define MPC5XXX_WU_GPIO_DATA    (MPC5XXX_WU_GPIO + 0x000c)
+#define MPC5XXX_WU_GPIO_DATA_I  (MPC5XXX_WU_GPIO + 0x0020)
 
 /* PCI registers */
 #define MPC5XXX_PCI_CMD		(MPC5XXX_PCI + 0x04)

commit 386415d88b1ae50304f9c61aa3e0db082fa90428

Author: David Brownell <[email protected]>
Date:   Sun Sep 3 13:16:45 2006 -0700

PM: platform_bus and late_suspend/early_resume

Teach platform_bus about the new suspend_late/resume_early PM calls, issued with IRQs off. Do we really need sysdev and friends any more, or can janitors start switching its users over to platform_device so we can do a minor code-ectomy?

drivers/base/platform.c +2 -28
@@ -505,36 +505,12 @@ static int platform_match(struct device 
 	return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);
 }
 
-static int platform_suspend(struct device *dev, pm_message_t mesg)
+static int platform_suspend(struct device * dev, pm_message_t state)
 {
 	int ret = 0;
 
 	if (dev->driver && dev->driver->suspend)
-		ret = dev->driver->suspend(dev, mesg);
-
-	return ret;
-}
-
-static int platform_suspend_late(struct device *dev, pm_message_t mesg)
-{
-	struct platform_driver *drv = to_platform_driver(dev->driver);
-	struct platform_device *pdev = container_of(dev, struct platform_device, dev);
-	int ret = 0;
-
-	if (dev->driver && drv->suspend_late)
-		ret = drv->suspend_late(pdev, mesg);
-
-	return ret;
-}
-
-static int platform_resume_early(struct device *dev)
-{
-	struct platform_driver *drv = to_platform_driver(dev->driver);
-	struct platform_device *pdev = container_of(dev, struct platform_device, dev);
-	int ret = 0;
-
-	if (dev->driver && drv->resume_early)
-		ret = drv->resume_early(pdev);
+		ret = dev->driver->suspend(dev, state);
 
 	return ret;
 }
@@ -555,8 +531,6 @@ struct bus_type platform_bus_type = {
 	.match		= platform_match,
 	.uevent		= platform_uevent,
 	.suspend	= platform_suspend,
-	.suspend_late	= platform_suspend_late,
-	.resume_early	= platform_resume_early,
 	.resume		= platform_resume,
 };
 EXPORT_SYMBOL_GPL(platform_bus_type);
drivers/base/power/resume.c +0 -0
drivers/i2c/busses/Kconfig +0 -0
drivers/i2c/busses/i2c-mpc.c +0 -0
drivers/ide/Kconfig +0 -0
drivers/ide/Makefile +0 -0
drivers/input/touchscreen/Kconfig +0 -0
drivers/input/touchscreen/Makefile +0 -0
drivers/mtd/maps/Kconfig +0 -0
drivers/mtd/maps/Makefile +0 -0
drivers/net/Kconfig +0 -0
drivers/net/Makefile +0 -0
drivers/serial/mpc52xx_uart.c +0 -0
drivers/video/Kconfig +0 -0
drivers/video/Makefile +0 -0
drivers/video/cfbcopyarea.c +0 -0
drivers/video/cfbfillrect.c +0 -0
drivers/video/cfbimgblt.c +0 -0
include/asm-ppc/mpc52xx.h +0 -0
include/linux/fb.h +0 -0
include/linux/ide.h +0 -0
include/linux/platform_device.h +0 -2
index 29cd6de..782090c 100644
@@ -49,8 +49,6 @@ struct platform_driver {
 	int (*remove)(struct platform_device *);
 	void (*shutdown)(struct platform_device *);
 	int (*suspend)(struct platform_device *, pm_message_t state);
-	int (*suspend_late)(struct platform_device *, pm_message_t state);
-	int (*resume_early)(struct platform_device *);
 	int (*resume)(struct platform_device *);
 	struct device_driver driver;
 };
kernel/power/main.c +0 -0
sound/Kconfig +0 -0
sound/Makefile +0 -0
arch/ppc/platforms/Makefile +4 -0
Index: work-powerpc.git/arch/ppc/platforms/Makefile
===================================================================
@@ -28,6 +28,10 @@ obj-$(CONFIG_SANDPOINT)		+= sandpoint.o
 obj-$(CONFIG_SBC82xx)		+= sbc82xx.o
 obj-$(CONFIG_SPRUCE)		+= spruce.o
 obj-$(CONFIG_LITE5200)		+= lite5200.o
+ifeq ($(CONFIG_LITE5200),y)
+obj-$(CONFIG_PM)		+= lite5200_pm.o
+obj-$(CONFIG_PM)		+= lite5200_sleep.o
+endif
 obj-$(CONFIG_MEDIA5200)		+= media5200.o
 obj-$(CONFIG_EV64360)		+= ev64360.o
 obj-$(CONFIG_MPC86XADS)		+= mpc866ads_setup.o
arch/ppc/platforms/lite5200_pm.c new file +141 -0

141 lines not on this page · raw message

arch/ppc/platforms/lite5200_sleep.S new file +490 -0

490 lines not on this page · raw message

arch/ppc/syslib/mpc52xx_pic.c +45 -0

54 lines not on this page · raw message

drivers/serial/mpc52xx_uart.c +2 -2
Index: work-powerpc.git/drivers/serial/mpc52xx_uart.c
===================================================================
@@ -285,7 +285,7 @@ mpc52xx_uart_set_termios(struct uart_por
 
 	/* Do our best to flush TX & RX, so we don't loose anything */
 	/* But we don't wait indefinitly ! */
-	j = 5000000;	/* Maximum wait */
+	j = 500000;	/* Maximum wait */
 	/* FIXME Can't receive chars since set_termios might be called at early
 	 * boot for the console, all stuff is not yet ready to receive at that
 	 * time and that just makes the kernel oops */
@@ -771,7 +771,7 @@ mpc52xx_uart_suspend(struct platform_dev
 {
 	struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev);
 
-	if (sport)
+	if (port)
 		uart_suspend_port(&mpc52xx_uart_driver, port);
 
 	return 0;
include/asm-ppc/mpc52xx.h +6 -0
Index: work-powerpc.git/include/asm-ppc/mpc52xx.h
===================================================================
@@ -142,6 +142,12 @@ enum ppc_sys_devices {
 #define MPC52xx_IRQ1			(MPC52xx_MAIN_IRQ_BASE + 1)
 #define MPC52xx_IRQ2			(MPC52xx_MAIN_IRQ_BASE + 2)
 #define MPC52xx_IRQ3			(MPC52xx_MAIN_IRQ_BASE + 3)
+/* see mpc5200b users manual, page 162 (7.2.4.11), and just count... */
+#define MPC52xx_LOINT_IRQ		(MPC52xx_MAIN_IRQ_BASE + 4)
+#define MPC52xx_RTC_PER_IRQ		(MPC52xx_MAIN_IRQ_BASE + 5)
+#define MPC52xx_RTC_STOP_IRQ		(MPC52xx_MAIN_IRQ_BASE + 6)
+#define MPC52xx_GPIO_IRQ		(MPC52xx_MAIN_IRQ_BASE + 7)
+#define MPC52xx_GPIO_WKUP_IRQ		(MPC52xx_MAIN_IRQ_BASE + 8)	/* == 13 */
 
 #define MPC52xx_SDMA_IRQ		(MPC52xx_PERP_IRQ_BASE + 0)
 #define MPC52xx_PSC1_IRQ		(MPC52xx_PERP_IRQ_BASE + 1)
drivers/net/fec_mpc52xx/fec.c +52 -2

66 lines not on this page · raw message

drivers/net/fec_mpc52xx/fec_phy.c +17 -0
Index: work-powerpc.git/drivers/net/fec_mpc52xx/fec_phy.c
===================================================================
@@ -521,6 +521,23 @@ int fec_mii_wait(struct net_device *dev)
 	return 0;
 }
 
+
+phy_cmd_t phy_cmd_powerdown[] =  { { mk_mii_write(0x00, 0x0800), NULL }, // power down
+				{ mk_mii_end, } };
+phy_cmd_t phy_cmd_sleep[] =  { { mk_mii_write(MII_LXT971_PCR, 0x00dc), NULL }, // sleep after 1 sec
+				{ mk_mii_write(0x14, 0xbbb2), NULL }, // disable leds
+				{ mk_mii_end, } };
+phy_cmd_t phy_cmd_wakeup[] =  { { mk_mii_write(MII_LXT971_PCR, 0x0084), NULL },
+				{ mk_mii_end, } };
+phy_cmd_t phy_cmd_poweron[] =  { { mk_mii_write(MII_BMCR, (BMCR_ANENABLE | BMCR_ANRESTART)), NULL },
+	  			{ mk_mii_end, } };
+
+void mpc52xx_fec_mii_suspend(struct net_device *dev)
+{
+	mii_do_cmd(dev, phy_cmd_powerdown);
+	printk(KERN_ALERT "%s: %i\n", __func__, __LINE__);
+}
+
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Dale Farnsworth");
 MODULE_DESCRIPTION("PHY driver for Motorola MPC52xx FEC");
kernel/power/main.c +38 -0
Index: work-powerpc.git/kernel/power/main.c
===================================================================
@@ -115,9 +115,26 @@ int suspend_enter(suspend_state_t state)
 		goto Done;
 	}
 	error = pm_ops->enter(state);
+	// zakaj za vraga se ne vrne sem? nima smisla, saj so vsi registri prav nastavljeni
+	*((volatile char *)0xc0000008) = 0x30;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
+
+	*((volatile long *)0xf0000620)   = 0x24;	// timer2 led, green
+	__asm__ __volatile__ ("sync");
+
+	*((volatile long *)0xf0000b10)   = 0x20000000;	// green
+	__asm__ __volatile__ ("sync");
+	*((volatile char *)0xc0000008)   = 0x31;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
 	device_power_up();
  Done:
+	*((volatile long *)0xf0000b10)   = 0x00000000;	// both
+	*((volatile char *)0xc0000008)   = 0x32;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
+	__asm__ __volatile__ ("sync");
 	local_irq_restore(flags);
+	*((volatile char *)0xc0000008)   = 0x33;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
 	return error;
 }
 
@@ -132,13 +149,27 @@ int suspend_enter(suspend_state_t state)
 
 static void suspend_finish(suspend_state_t state)
 {
+	*((volatile char *)0xc0000008)   = 0x40;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
 	device_resume();
+	*((volatile char *)0xc0000008)   = 0x41;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
 	resume_console();
+	*((volatile char *)0xc0000008)   = 0x42;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
 	thaw_processes();
+	*((volatile char *)0xc0000008)   = 0x43;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
 	enable_nonboot_cpus();
+	*((volatile char *)0xc0000008)   = 0x44;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
 	if (pm_ops && pm_ops->finish)
 		pm_ops->finish(state);
+	*((volatile char *)0xc0000008)   = 0x45;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
 	pm_restore_console();
+	*((volatile char *)0xc0000008)   = 0x46;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
 }
 
 
@@ -197,10 +228,17 @@ static int enter_state(suspend_state_t s
 	pr_debug("PM: Entering %s sleep\n", pm_states[state]);
 	error = suspend_enter(state);
 
+	*((volatile char *)0xc0000008)   = 0x35;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
 	pr_debug("PM: Finishing wakeup.\n");
+	*((volatile char *)0xc0000008)   = 0x36;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
 	suspend_finish(state);
+	*((volatile char *)0xc0000008)   = 0x37;
+	asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
  Unlock:
 	up(&pm_sem);
+	*((volatile char *)0xc0000008)   = 0x38;
 	return error;
 }
 
drivers/base/power/resume.c +4 -0
Index: work-powerpc.git/drivers/base/power/resume.c
===================================================================
@@ -70,10 +70,14 @@ static int resume_device_early(struct de
 void dpm_resume(void)
 {
 	down(&dpm_list_sem);
+	int foo = 0x50;
 	while(!list_empty(&dpm_off)) {
 		struct list_head * entry = dpm_off.next;
 		struct device * dev = to_device(entry);
 
+		*((volatile char *)0xc0000008)   = foo++;
+		asm volatile("dcbf 0,%0" : : "r" (0xc0000008) : "memory");
+
 		get_device(dev);
 		list_move_tail(entry, &dpm_active);
 
arch/ppc/syslib/mpc52xx_setup.c +5 -3
Index: work-powerpc.git/arch/ppc/syslib/mpc52xx_setup.c
===================================================================
@@ -86,8 +86,11 @@ mpc52xx_map_io(void)
 	/* Here we map the MBAR and the whole upper zone. MBAR is only
 	   64k but we can't map only 64k with BATs. Map the whole
 	   0xf0000000 range is ok and helps eventual lpb devices placed there */
+	/* Disable guarded bit, so we can execute code from SRAM.
+	 * Unfortunately, mappings are >= 2**17, so we "unguard" MBAR registers
+	 * too. This probably isn't a problem. */
 	io_block_mapping(
-		MPC52xx_MBAR_VIRT, MPC52xx_MBAR, 0x10000000, _PAGE_IO);
+		MPC52xx_MBAR_VIRT, MPC52xx_MBAR, 0x10000000, _PAGE_IO & ~_PAGE_GUARDED);
 }
 
 
@@ -217,8 +220,7 @@ mpc52xx_calibrate_decr(void)
 	tb_to_us = mulhwu_scale_factor(xlbfreq / divisor, 1000000);
 }
 
-void __init
-mpc52xx_setup_cpu(void)
+void mpc52xx_setup_cpu(void)
 {
 	struct mpc52xx_cdm  __iomem *cdm;
 	struct mpc52xx_xlb  __iomem *xlb;
arch/ppc/platforms/lite5200.c +2 -4
Index: work-powerpc.git/arch/ppc/platforms/lite5200.c
===================================================================
@@ -93,8 +93,7 @@ lite5200_map_irq(struct pci_dev *dev, un
 #endif
 #endif
 
-static void __init
-lite5200_setup_cpu(void)
+void lite5200_setup_cpu(void)
 {
 	struct mpc52xx_gpio __iomem *gpio;
 	struct mpc52xx_intr __iomem *intr;
@@ -149,8 +148,7 @@ unmap_regs:
 	if (intr) iounmap(intr);
 }
 
-static void __init
-lite5200_setup_arch(void)
+static void lite5200_setup_arch(void)
 {
 	/* CPU & Port mux setup */
 	mpc52xx_setup_cpu();	/* Generic */
arch/ppc/syslib/bestcomm/bestcomm.c +73 -2

87 lines not on this page · raw message

#1 lore raw
Quoted 17 lines · Domen Puncer

Hi!

I have managed to implement low power mode... well, to some degree, at least.

Short description:
patch u-boot, it's the return from wakeup code. pretty clean.

	address is saved at 0x0 (0xc000_0000)

patch linux with PM-platform_bus-and-late_suspend-early_resume.patch
didn't investigate too much, but it seems to broke mine.
patch linux with lite5200b_low_power.patch
ugly, with debugging, hacks and whatever

Boot Linux and 'echo mem > /sys/power/state'.
It won't work on PCI, possibly other devices, PSC0 and FEC seem to work ok for me.

Quoted 8 lines

It seems to work reliably (checksums match, so ram was in self-refresh) when called from boot scripts, but not so when from console prompt.

If someone's interested (or maybe wants to play with this during holiday? ;-) ), more info follow:

Well, I'll have a look, that looks interesting ;)

Sylvain

#2 lore raw

Re: [RFC PATCHES] lite5200b low power mode works

In reply to Domen Puncer
Quoted 4 lines · Domen Puncer

Hi!

I have managed to implement low power mode... well, to some degree, at least.

And now, I can't break it anymore, it works every time on my setup. :-)

How to use?
Patch u-boot, Linux. Run it. echo mem > /sys/power/state .

Patches in order they apply:
u-boot.patch
wakeup ram from self-refresh and jump to kernel wakeup code
fec_platform_fix
sdma_platform_fix
since these are platform drivers (.bus = ...), they need to have the proper structs so suspend_late will work
uart_sport_fix
a typo fix in suspend code
sram_executable
don't guard SRAM, since we execute some code from it
low_power_mode
"main" patch, with suspend, self-refresh and resume code
suspend_arch_code_non-init
call ppc_md.setup_arch() on resume
suspend_pic
suspend and resume pic
uart_smaller_delay
because 5 seconds delay is a bit long
suspend_bestcomm
save/restore SRAM and bestcomm registers
suspend_fec
fec suspend/resume

Update from previous patch:
the correct sequence for self-refresh seems to be:
mode_en = 1
soft_pre = 1
mode_en = 0, soft_pre = 0
ref_en = 1, cke = 0

Note the "mode_en = 0", I couldn't find it documented anywhere, and even in freescale's examples it's missing.

I'm planning on porting this to Grant/Sylvain's arch/powerpc mpc52xx tree soon.

Any comments are very appreaciated.

Domen

board/icecube/icecube.c +150 -0
index 4f056b2..3a52557 100644
@@ -38,6 +38,154 @@ # else
 #include "mt48lc16m16a2-75.h"
 # endif
 #endif
+
+#ifdef CONFIG_LITE5200B
+/* u-boot part of low-power mode implementation */
+#define SAVED_ADDR 0x00000000
+#define SDRAM_CONTROLW (SDRAM_CONTROL & ~0x50000000) /* !ref_en !cke */
+
+static void wakeup_sdram()
+{
+	long hi_addr_bit = 0x01000000;
+
+	/* unlock mode register */
+	*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROLW | 0x80000000;
+	__asm__ volatile ("sync");
+
+	/* precharge all banks */
+	*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROLW | 0x80000002;
+	__asm__ volatile ("sync");
+
+#if SDRAM_DDR
+	/* set mode register: extended mode */
+	*(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
+	__asm__ volatile ("sync");
+
+	/* set mode register: reset DLL */
+	*(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
+	__asm__ volatile ("sync");
+#endif
+
+	/* precharge all banks */
+	*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROLW | 0x80000002;
+	__asm__ volatile ("sync");
+
+	/* auto refresh */
+	*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROLW | 0x80000004;
+	__asm__ volatile ("sync");
+
+	/* set mode register */
+	*(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
+	__asm__ volatile ("sync");
+
+
+	/* the second bank too */
+	/* unlock mode register */
+	*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROLW | 0x80000000 | hi_addr_bit;
+	__asm__ volatile ("sync");
+
+	/* precharge all banks */
+	*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROLW | 0x80000002 | hi_addr_bit;
+	__asm__ volatile ("sync");
+
+#if SDRAM_DDR
+	/* set mode register: extended mode */
+	*(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
+	__asm__ volatile ("sync");
+
+	/* set mode register: reset DLL */
+	*(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
+	__asm__ volatile ("sync");
+#endif
+
+	/* precharge all banks */
+	*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROLW | 0x80000002 | hi_addr_bit;
+	__asm__ volatile ("sync");
+
+	/* auto refresh */
+	*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROLW | 0x80000004 | hi_addr_bit;
+	__asm__ volatile ("sync");
+
+	/* set mode register */
+	*(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
+	__asm__ volatile ("sync");
+
+
+	/* out of self refresh */
+	/* ref_en, cke, out of self refresh */
+	*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROLW | 0x80000000 | 0x50000000;
+	__asm__ volatile ("sync");
+
+	/* normal operation */
+	*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROLW | 0x50000000;
+	__asm__ volatile ("sync");
+
+	/* second bank too */
+	/* ref_en, cke, out of self refresh */
+	*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROLW | 0x80000000 | 0x50000000 | hi_addr_bit;
+	__asm__ volatile ("sync");
+
+	/* normal operation */
+	*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROLW | 0x50000000 | hi_addr_bit;
+	__asm__ volatile ("sync");
+}
+
+static void lite5200b_wakeup(void)
+{
+	unsigned char wakeup_pin;
+	void (*linux_wakeup)(void);
+
+	/* check PSC2_4, if it's down "QT" is signaling we have a wakeup
+	 * from low power mode */
+	*(vu_char *)MPC5XXX_WU_GPIO_ENABLE = 0x02;
+	__asm__ volatile ("sync");
+
+	wakeup_pin = *(vu_char *)MPC5XXX_WU_GPIO_DATA_I;
+	if (wakeup_pin & 0x02)
+		return;
+
+	/* acknowledge to "QT"
+	 * by holding pin at 1 for 10 uS */
+	*(vu_char *)MPC5XXX_WU_GPIO_DIR = 0x02;
+	__asm__ volatile ("sync");
+	*(vu_char *)MPC5XXX_WU_GPIO_DATA = 0x02;
+	__asm__ volatile ("sync");
+	udelay(10);
+
+	/* setup SDRAM chip selects */
+	/* 2 128 mb chips */
+	*(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001a;/* 128mb at 0x0 */
+	*(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x0800001a;/* 128mb at 0x08000000 */
+	__asm__ volatile ("sync");
+
+	/* setup config registers */
+	*(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
+	*(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
+	__asm__ volatile ("sync");
+
+	/* set tap delay */
+	*(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
+	__asm__ volatile ("sync");
+
+	*(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
+	__asm__ volatile ("sync");
+
+	wakeup_sdram(0);
+	wakeup_sdram(1);
+	udelay(10); /* wait a bit */
+
+	linux_wakeup = *(unsigned long *)SAVED_ADDR;
+
+	/* jump back to linux kernel code */
+	printf("\n\nLooks like we just woke, transferring control to 0x%08lx\n",
+			linux_wakeup);
+	linux_wakeup();
+}
+#else
+#define lite5200b_wakeup
+#endif
+
+
 #ifndef CFG_RAMBOOT
 static void sdram_start (int hi_addr)
 {
@@ -92,6 +240,8 @@ long int initdram (int board_type)
 	ulong dramsize2 = 0;
 	uint svr, pvr;
 
+	lite5200b_wakeup();
+
 #ifndef CFG_RAMBOOT
 	ulong test1, test2;
 
include/mpc5xxx.h +1 -0
index 1d20d1d..c7eb090 100644
@@ -189,6 +189,7 @@ #define MPC5XXX_WU_GPIO_ENABLE  (MPC5XXX
 #define MPC5XXX_WU_GPIO_ODE     (MPC5XXX_WU_GPIO + 0x0004)
 #define MPC5XXX_WU_GPIO_DIR     (MPC5XXX_WU_GPIO + 0x0008)
 #define MPC5XXX_WU_GPIO_DATA    (MPC5XXX_WU_GPIO + 0x000c)
+#define MPC5XXX_WU_GPIO_DATA_I  (MPC5XXX_WU_GPIO + 0x0020)
 
 /* PCI registers */
 #define MPC5XXX_PCI_CMD		(MPC5XXX_PCI + 0x04)
drivers/net/fec_mpc52xx/fec.c +11 -12
Index: work-powerpc.git/drivers/net/fec_mpc52xx/fec.c
===================================================================
@@ -553,10 +553,9 @@ static void fec_reinit(struct net_device
 /* ======================================================================== */
 
 static int __devinit
-mpc52xx_fec_probe(struct device *dev)
+mpc52xx_fec_probe(struct platform_device *pdev)
 {
 	int ret;
-	struct platform_device *pdev = to_platform_device(dev);
 	struct net_device *ndev;
 	struct fec_priv *priv = NULL;
 	struct resource *mem;
@@ -680,7 +679,7 @@ mpc52xx_fec_probe(struct device *dev)
 	fec_mii_init(ndev);
 
 	/* We're done ! */
-	dev_set_drvdata(dev, ndev);
+	platform_set_drvdata(pdev, ndev);
 
 	return 0;
 
@@ -707,12 +706,11 @@ probe_error:
 }
 
 static int
-mpc52xx_fec_remove(struct device *dev)
+mpc52xx_fec_remove(struct platform_device *pdev)
 {
-	struct net_device *ndev;
+	struct net_device *ndev = platform_get_drvdata(pdev);
 	struct fec_priv *priv;
 
-	ndev = (struct net_device *) dev_get_drvdata(dev);
 	if (!ndev)
 		return 0;
 	priv = (struct fec_priv *) ndev->priv;
@@ -729,19 +727,20 @@ mpc52xx_fec_remove(struct device *dev)
 
 	free_netdev(ndev);
 
-	dev_set_drvdata(dev, NULL);
+	platform_set_drvdata(pdev, NULL);
 	return 0;
 }
 
-static struct device_driver mpc52xx_fec_driver = {
-	.name	  = DRIVER_NAME,
-	.bus		= &platform_bus_type,
+static struct platform_driver mpc52xx_fec_driver = {
 	.probe		= mpc52xx_fec_probe,
 	.remove		= mpc52xx_fec_remove,
 #ifdef CONFIG_PM
 /*	.suspend	= mpc52xx_fec_suspend,	TODO */
 /*	.resume		= mpc52xx_fec_resume,	TODO */
 #endif
+	.driver	= {
+		.name	  = DRIVER_NAME,
+	},
 };
 
 /* ======================================================================== */
@@ -751,13 +750,13 @@ static struct device_driver mpc52xx_fec_
 static int __init
 mpc52xx_fec_init(void)
 {
-	return driver_register(&mpc52xx_fec_driver);
+	return platform_driver_register(&mpc52xx_fec_driver);
 }
 
 static void __exit
 mpc52xx_fec_exit(void)
 {
-	driver_unregister(&mpc52xx_fec_driver);
+	platform_driver_unregister(&mpc52xx_fec_driver);
 }
 
 
arch/ppc/syslib/bestcomm/bestcomm.c +8 -8
Index: work-powerpc.git/arch/ppc/syslib/bestcomm/bestcomm.c
===================================================================
@@ -264,9 +264,8 @@ void sdma_free(struct sdma *s)
 	kfree(s);
 }
 
-static int __devinit mpc52xx_sdma_probe(struct device *dev)
+static int __devinit mpc52xx_sdma_probe(struct platform_device *pdev)
 {
-	struct platform_device *pdev = to_platform_device(dev);
 	int task;
 	u32 *context;
 	u32 *fdt;
@@ -361,30 +360,31 @@ out:
 }
 
 
-static struct device_driver mpc52xx_sdma_driver = {
-	.owner	  = THIS_MODULE,
-	.name	  = DRIVER_NAME,
-	.bus	  = &platform_bus_type,
+static struct platform_driver mpc52xx_sdma_driver = {
 	.probe 	  = mpc52xx_sdma_probe,
 /*	.remove	  = mpc52xx_sdma_remove,	TODO */
 #ifdef CONFIG_PM
 /*	.suspend	= mpc52xx_sdma_suspend,	TODO */
 /*	.resume		= mpc52xx_sdma_resume,	TODO */
 #endif
+	.driver	= {
+		.owner	  = THIS_MODULE,
+		.name	  = DRIVER_NAME,
+	},
 };
 
 static int __init
 mpc52xx_sdma_init(void)
 {
 	printk(KERN_INFO "DMA: MPC52xx BestComm driver\n");
-	return driver_register(&mpc52xx_sdma_driver);
+	return platform_driver_register(&mpc52xx_sdma_driver);
 }
 
 #ifdef MODULE
 static void __exit
 mpc52xx_sdma_exit(void)
 {
-	driver_unregister(&mpc52xx_sdma_driver);
+	platform_driver_unregister(&mpc52xx_sdma_driver);
 }
 #endif
 
drivers/serial/mpc52xx_uart.c +1 -1
Index: work-powerpc.git/drivers/serial/mpc52xx_uart.c
===================================================================
@@ -771,7 +771,7 @@ mpc52xx_uart_suspend(struct platform_dev
 {
 	struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev);
 
-	if (sport)
+	if (port)
 		uart_suspend_port(&mpc52xx_uart_driver, port);
 
 	return 0;
arch/ppc/syslib/mpc52xx_setup.c +4 -1
Index: work-powerpc.git/arch/ppc/syslib/mpc52xx_setup.c
===================================================================
@@ -86,8 +86,11 @@ mpc52xx_map_io(void)
 	/* Here we map the MBAR and the whole upper zone. MBAR is only
 	   64k but we can't map only 64k with BATs. Map the whole
 	   0xf0000000 range is ok and helps eventual lpb devices placed there */
+	/* Disable guarded bit, so we can execute code from SRAM.
+	 * Unfortunately, mappings are >= 2**17, so we "unguard" MBAR registers
+	 * too. This probably isn't a problem. */
 	io_block_mapping(
-		MPC52xx_MBAR_VIRT, MPC52xx_MBAR, 0x10000000, _PAGE_IO);
+		MPC52xx_MBAR_VIRT, MPC52xx_MBAR, 0x10000000, _PAGE_IO & ~_PAGE_GUARDED);
 }
 
 
arch/ppc/platforms/Makefile +4 -0
Index: work-powerpc.git/arch/ppc/platforms/Makefile
===================================================================
@@ -28,6 +28,10 @@ obj-$(CONFIG_SANDPOINT)		+= sandpoint.o
 obj-$(CONFIG_SBC82xx)		+= sbc82xx.o
 obj-$(CONFIG_SPRUCE)		+= spruce.o
 obj-$(CONFIG_LITE5200)		+= lite5200.o
+ifeq ($(CONFIG_LITE5200),y)
+obj-$(CONFIG_PM)		+= lite5200_pm.o
+obj-$(CONFIG_PM)		+= lite5200_sleep.o
+endif
 obj-$(CONFIG_MEDIA5200)		+= media5200.o
 obj-$(CONFIG_EV64360)		+= ev64360.o
 obj-$(CONFIG_MPC86XADS)		+= mpc866ads_setup.o
arch/ppc/platforms/lite5200_pm.c new file +72 -0

72 lines not on this page · raw message

arch/ppc/platforms/lite5200_sleep.S new file +528 -0

528 lines not on this page · raw message

arch/ppc/syslib/mpc52xx_setup.c +1 -2
Index: work-powerpc.git/arch/ppc/syslib/mpc52xx_setup.c
===================================================================
@@ -220,8 +220,7 @@ mpc52xx_calibrate_decr(void)
 	tb_to_us = mulhwu_scale_factor(xlbfreq / divisor, 1000000);
 }
 
-void __init
-mpc52xx_setup_cpu(void)
+void mpc52xx_setup_cpu(void)
 {
 	struct mpc52xx_cdm  __iomem *cdm;
 	struct mpc52xx_xlb  __iomem *xlb;
arch/ppc/platforms/lite5200.c +2 -4
Index: work-powerpc.git/arch/ppc/platforms/lite5200.c
===================================================================
@@ -93,8 +93,7 @@ lite5200_map_irq(struct pci_dev *dev, un
 #endif
 #endif
 
-static void __init
-lite5200_setup_cpu(void)
+void lite5200_setup_cpu(void)
 {
 	struct mpc52xx_gpio __iomem *gpio;
 	struct mpc52xx_intr __iomem *intr;
@@ -149,8 +148,7 @@ unmap_regs:
 	if (intr) iounmap(intr);
 }
 
-static void __init
-lite5200_setup_arch(void)
+static void lite5200_setup_arch(void)
 {
 	/* CPU & Port mux setup */
 	mpc52xx_setup_cpu();	/* Generic */
arch/ppc/platforms/lite5200_pm.c +2 -0
Index: work-powerpc.git/arch/ppc/platforms/lite5200_pm.c
===================================================================
@@ -48,6 +48,8 @@ static int l5200_pm_enter(suspend_state_
 	gpio->port_config = gpio_saved_pc;
 	iounmap(gpio);
 
+	ppc_md.setup_arch();
+
 	return 0;
 }
 
arch/ppc/syslib/mpc52xx_pic.c +44 -0

47 lines not on this page · raw message

arch/ppc/platforms/lite5200_pm.c +7 -0
Index: work-powerpc.git/arch/ppc/platforms/lite5200_pm.c
===================================================================
@@ -23,6 +23,9 @@ static int l5200_pm_prepare(suspend_stat
 	return 0;
 }
 
+extern void mpc52xx_pic_suspend(void);
+extern void mpc52xx_pic_resume(void);
+
 static int l5200_pm_enter(suspend_state_t state)
 {
 	struct mpc52xx_gpio __iomem *gpio;
@@ -40,6 +43,8 @@ static int l5200_pm_enter(suspend_state_
 	gpio_saved_pc = gpio->port_config;
 	iounmap(gpio);
 
+	mpc52xx_pic_suspend();
+
 	if (state == PM_SUSPEND_MEM)
 		l5200_qt_sleep();
 
@@ -50,6 +55,8 @@ static int l5200_pm_enter(suspend_state_
 
 	ppc_md.setup_arch();
 
+	mpc52xx_pic_resume();
+
 	return 0;
 }
 
drivers/serial/mpc52xx_uart.c +1 -1
Index: work-powerpc.git/drivers/serial/mpc52xx_uart.c
===================================================================
@@ -285,7 +285,7 @@ mpc52xx_uart_set_termios(struct uart_por
 
 	/* Do our best to flush TX & RX, so we don't loose anything */
 	/* But we don't wait indefinitly ! */
-	j = 5000000;	/* Maximum wait */
+	j = 500000;	/* Maximum wait */
 	/* FIXME Can't receive chars since set_termios might be called at early
 	 * boot for the console, all stuff is not yet ready to receive at that
 	 * time and that just makes the kernel oops */
arch/ppc/syslib/bestcomm/bestcomm.c +75 -6

91 lines not on this page · raw message

drivers/net/fec_mpc52xx/fec.c +46 -5

60 lines not on this page · raw message

drivers/net/fec_mpc52xx/fec_phy.c +9 -0
Index: work-powerpc.git/drivers/net/fec_mpc52xx/fec_phy.c
===================================================================
@@ -521,6 +521,15 @@ int fec_mii_wait(struct net_device *dev)
 	return 0;
 }
 
+
+phy_cmd_t phy_cmd_powerdown[] =  { { mk_mii_write(0x00, 0x0800), NULL }, // power down
+				{ mk_mii_end, } };
+
+void mpc52xx_fec_mii_suspend(struct net_device *dev)
+{
+	mii_do_cmd(dev, phy_cmd_powerdown);
+}
+
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Dale Farnsworth");
 MODULE_DESCRIPTION("PHY driver for Motorola MPC52xx FEC");
#3 lore raw

Re: [RFC PATCHES] lite5200b low power mode works

Quoted 3 lines · Domen Puncer

I'm planning on porting this to Grant/Sylvain's arch/powerpc mpc52xx tree soon.

OK... and I've done that (mainline kernel + FEC/bestcomm patches)
+ some cleanups, fixes.

Any of you guys interested in having this in your tree?

Domen

#4 lore raw

Re: [RFC PATCHES] lite5200b low power mode works

Quoted 12 lines · Domen Puncer
Quoted 3 lines · Domen Puncer

I'm planning on porting this to Grant/Sylvain's arch/powerpc mpc52xx tree soon.

OK... and I've done that (mainline kernel + FEC/bestcomm patches)
+ some cleanups, fixes.

Any of you guys interested in having this in your tree?

Sure, feel free to post them.

Sylvain

#5 lore raw

Re: [RFC PATCHES] lite5200b low power mode works

Quoted 7 lines · Sylvain Munaut
Quoted 6 lines · Domen Puncer
Quoted 3 lines · Domen Puncer

I'm planning on porting this to Grant/Sylvain's arch/powerpc mpc52xx tree soon.

Quoted 7 lines
Quoted 6 lines

OK... and I've done that (mainline kernel + FEC/bestcomm patches)
+ some cleanups, fixes.

Any of you guys interested in having this in your tree?

Sure, feel free to post them.

It seems to be my lucky day. I just figured out what I was doing wrong with deep-sleep (aplicable to all mpc52xx), so I'll delay this a few days, and send patches implementing both mpc5200b and lite5200b "suspend to ram" modes.

Domen

Quoted 2 lines

Sylvain

#6 lore raw

Re: [RFC PATCHES] lite5200b low power mode works

Quoted 18 lines · Domen Puncer
Quoted 16 lines · Sylvain Munaut
Quoted 14 lines · Domen Puncer
Quoted 4 lines · Domen Puncer

I'm planning on porting this to Grant/Sylvain's arch/powerpc mpc52xx tree soon.

OK... and I've done that (mainline kernel + FEC/bestcomm patches)
+ some cleanups, fixes.

Any of you guys interested in having this in your tree?

Quoted 8 lines
Quoted 2 lines

Sure, feel free to post them.

It seems to be my lucky day. I just figured out what I was doing wrong with deep-sleep (aplicable to all mpc52xx), so I'll delay this a few days, and send patches implementing both mpc5200b and lite5200b "suspend to ram" modes.

Even better !

Sylvain