[parisc-linux-cvs] enable soft-power switch on 715 (Gecko) machines

Helge Deller deller@gmx.de
Fri, 30 Nov 2001 03:47:56 +0100


--------------Boundary-00=_WFELLHI5VROYKYPOXJ96
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

On Friday 30 November 2001 03:36, Helge Deller wrote:
> CVSROOT:	/var/cvs
> Module name:	linux
> Changes by:	deller	01/11/29 19:36:04
>
> Modified files:
> 	.              : Makefile
> 	arch/parisc/kernel: power.c
>
> Log message:
> - kernel version 2.4.16-pa4
> - enable soft-power switch on 715 (Gecko) machines
>
> Still experimental, but now it works for c3000 and 715/64 !



--------------Boundary-00=_WFELLHI5VROYKYPOXJ96
Content-Type: text/plain;
  charset="iso-8859-1";
  name="diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="diff"

Index: Makefile
===================================================================
RCS file: /var/cvs/linux/Makefile,v
retrieving revision 1.208
diff -u -p -r1.208 Makefile
--- Makefile	2001/11/29 23:22:16	1.208
+++ Makefile	2001/11/30 02:30:54
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 4
 SUBLEVEL = 16
-EXTRAVERSION = -pa3
+EXTRAVERSION = -pa4
 
 KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 
Index: arch/parisc/kernel/power.c
===================================================================
RCS file: /var/cvs/linux/arch/parisc/kernel/power.c,v
retrieving revision 1.1
diff -u -p -r1.1 power.c
--- arch/parisc/kernel/power.c	2001/11/29 20:00:47	1.1
+++ arch/parisc/kernel/power.c	2001/11/30 02:30:54
@@ -10,7 +10,6 @@
  * Status: EXPERIMENTAL
  *  
  * TODO:
- * - make it work on my 715/64 (Gecko-style) machine,
  * - use tasklets instead of calling it from the timer-interrupt function
  * - ....
  */
@@ -35,7 +34,32 @@
 //#define POWERSWITCH_DISABLED
 
 
+/* local time-counter for shutdown */
+static int shutdown_timer;
 
+
+/* this will go to processor.h or any other place... */
+/* taken from PCXL ERS pg 82 */
+#define MFCPU_X(rDiagReg, t_ch, t_th, code) \
+	(0x14000000 + ((rDiagReg)<<21) + ((t_ch)<<16) + ((code)<<5) + ((t_th)<<0) )
+	
+#define MFCPU_C(dr, gr)		MFCPU_X(dr, gr,  0, 0x30)	/* for dr0 and dr8 only ! */
+#define MFCPU_T(dr, gr)		MFCPU_X(dr,  0, gr, 0xa0)	/* all dr except dr0 and dr8 */
+	
+#define __getDIAG(dr) ( { 			\
+        register unsigned long __res asm("r28");\
+	__asm__ __volatile__ (			\
+		".word %0"			\
+		: 				\
+		: "i" (MFCPU_T(dr,28))		\
+		: "memory"			\
+	);					\
+	__res;					\
+} )
+
+
+
+
 static void deferred_poweroff(void *dummy)
 {
 	kill_proc(1, SIGINT, 0);
@@ -67,29 +91,37 @@ static void poweroff(void)
 void (*check_soft_power)(struct pt_regs *regs);
 
 
+
+/* check, give feedback and start shutdown after one second */
+static void process_shutdown(void)
+{
+	if (shutdown_timer == 0)
+		printk(KERN_INFO "Shutdown requested...\n");
+
+	shutdown_timer++;
+	
+	/* wait until the button was pressed for 1 second */
+	if (shutdown_timer == HZ) {
+		printk(KERN_INFO "Shutting down...\n");
+		poweroff();
+	}
+}
+
+
 /*
  * On gecko style machines (e.g. 712/xx and 715/xx) 
  * the power switch status is stored in Bit 0 ("the highest bit")
  * of CPU diagnose register 25.
  * 
- * FIXME: doesn't work yet,
- * I assume HPUX does some strange things (e.g. copy cr23 to cr25 ?)
  */
 static void check_soft_power_gecko(struct pt_regs *regs)
 {
-#if 0
-	static int x;
-
-	x++;
-	/* reduce the amount of stupid printk()s */
-	if (x & 0x3f)
-		return;
-
-	if (mfctl(23) & 0x80000000) 
-		printk("SWITCH_ON\n") ;
-	else
-		printk("SWITCH_OFF!!\n");
-#endif
+	if (__getDIAG(25) & 0x80000000) {
+		/* power switch button not pressed or released again */
+		shutdown_timer = 0;
+	} else {
+		process_shutdown();
+	}
 }
 
 
@@ -104,18 +136,14 @@ static unsigned long soft_power_reg;
 static void check_soft_power_polling(struct pt_regs *regs)
 {
         unsigned long current_status;
-	static int timer;
 
 	current_status = gsc_readl(soft_power_reg);
 	if (current_status & 0x1) {
 		/* power switch button not pressed */
-		timer = 0;
+		shutdown_timer = 0;
 	} else {
 		gsc_writel(soft_power_reg, current_status & ~0x1);
-		timer++;
-		/* wait until the button was pressed for 1 second */
-		if (timer == HZ)
-			poweroff();
+		process_shutdown();
 	}
 }
 

--------------Boundary-00=_WFELLHI5VROYKYPOXJ96--