[PATCH 12/15] [POWERPC] Add mpc52xx_restart(), mpc52xx_halt(), mpc52xx_power_off().

Marian Balakowicz m8 at semihalf.com
Sun Oct 7 21:32:02 EST 2007


Add common MPC5200 helper routines: mpc52xx_restart(), mpc52xx_halt(),
mpc52xx_power_off().

This patch relies on Sascha Hauer's patch published in:
http://patchwork.ozlabs.org/linuxppc/patch?id=8910.

Signed-off-by: Marian Balakowicz <m8 at semihalf.com>
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---

 arch/powerpc/platforms/52xx/mpc52xx_common.c |   45 +++++++++++++++++++++++++++
 include/asm-powerpc/mpc52xx.h                |    7 ++++
 2 files changed, 52 insertions(+)

diff --git a/arch/powerpc/platforms/52xx/mpc52xx_common.c b/arch/powerpc/platforms/52xx/mpc52xx_common.c
index b1cd7b0..e7087d7 100644
--- a/arch/powerpc/platforms/52xx/mpc52xx_common.c
+++ b/arch/powerpc/platforms/52xx/mpc52xx_common.c
@@ -88,6 +88,14 @@ mpc52xx_find_ipb_freq(struct device_node *node)
 }
 EXPORT_SYMBOL(mpc52xx_find_ipb_freq);
 
+/*
+ * This variable is mapped in mpc52xx_setup_cpu() by a call to
+ * mpc52xx_find_and_map(), and used in mpc52xx_restart(). This is because
+ * mpc52xx_restart() can be called from interrupt context (e.g., watchdog
+ * interrupt handler), and mpc52xx_find_and_map() (ioremap() to be exact)
+ * can't be called from interrupt context.
+ */
+volatile struct mpc52xx_gpt *mpc52xx_gpt0 = NULL;
 
 void __init
 mpc52xx_setup_cpu(void)
@@ -95,6 +103,9 @@ mpc52xx_setup_cpu(void)
 	struct mpc52xx_cdm  __iomem *cdm;
 	struct mpc52xx_xlb  __iomem *xlb;
 
+	/* mpc52xx_gpt0 is mapped here and used in mpc52xx_restart */
+	mpc52xx_gpt0 = mpc52xx_find_and_map("mpc5200-gpt");
+
 	/* Map zones */
 	cdm = mpc52xx_find_and_map("mpc5200-cdm");
 	xlb = mpc52xx_find_and_map("mpc5200-xlb");
@@ -138,3 +149,37 @@ mpc52xx_declare_of_platform_devices(void)
 			"Error while probing of_platform bus\n");
 }
 
+void
+mpc52xx_restart(char *cmd)
+{
+	local_irq_disable();
+
+	/* Turn on the watchdog and wait for it to expire. It effectively
+	  does a reset */
+	if (mpc52xx_gpt0) {
+		out_be32(&mpc52xx_gpt0->mode, 0x00000000);
+		out_be32(&mpc52xx_gpt0->count, 0x000000ff);
+		out_be32(&mpc52xx_gpt0->mode, 0x00009004);
+	} else
+		printk("mpc52xx_restart: Can't access gpt. "
+			"Restart impossible, system halted\n");
+
+	while (1);
+}
+
+void
+mpc52xx_halt(void)
+{
+	local_irq_disable();
+
+	while (1);
+}
+
+void
+mpc52xx_power_off(void)
+{
+	/* By default we don't have any way of shut down.
+	   If a specific board wants to, it can set the power down
+	   code to any hardware implementation dependent code */
+	mpc52xx_halt();
+}
diff --git a/include/asm-powerpc/mpc52xx.h b/include/asm-powerpc/mpc52xx.h
index a431798..8dfb4de 100644
--- a/include/asm-powerpc/mpc52xx.h
+++ b/include/asm-powerpc/mpc52xx.h
@@ -104,6 +104,9 @@ struct mpc52xx_gpt {
 	u32 status;		/* GPTx + 0X0c */
 };
 
+/* Static instance of GPT0 */
+extern volatile struct mpc52xx_gpt *mpc52xx_gpt0;
+
 /* GPIO */
 struct mpc52xx_gpio {
 	u32 port_config;	/* GPIO + 0x00 */
@@ -257,6 +260,10 @@ extern unsigned int mpc52xx_get_irq(void);
 
 extern int __init mpc52xx_add_bridge(struct device_node *node);
 
+extern void mpc52xx_restart(char *cmd);
+extern void mpc52xx_halt(void);
+extern void mpc52xx_power_off(void);
+
 #endif /* __ASSEMBLY__ */
 
 #ifdef CONFIG_PM





More information about the Linuxppc-dev mailing list