1 /*	$NetBSD: hpcapm_machdep.c,v 1.3 2009/03/18 10:22:29 cegger Exp $	*/
2 
3 /*
4  * Copyright (c) 2000 Takemura Shin
5  * Copyright (c) 2000-2001 SATO Kazumi
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  */
30 
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: hpcapm_machdep.c,v 1.3 2009/03/18 10:22:29 cegger Exp $");
33 
34 #include <sys/param.h>
35 #include <sys/device.h>
36 #include <sys/kernel.h>
37 #include <sys/systm.h>
38 
39 #include <dev/hpc/apm/apmvar.h>
40 
41 #include <machine/bus.h>
42 #include <machine/autoconf.h>
43 #include <machine/config_hook.h>
44 #include <machine/platid.h>
45 #include <machine/platid_mask.h>
46 
47 #include "vrip_common.h"
48 #if NVRIP_COMMON > 0
49 #include <hpcmips/vr/vripvar.h>
50 #include <hpcmips/vr/vr_asm.h>
51 #endif
52 
53 #include "opt_tx39xx.h"
54 #ifdef TX39XX
55 #include <hpcmips/tx/tx39var.h>
56 #endif
57 
58 void
59 machine_standby(void)
60 {
61 #if NVRIP_COMMON > 0
62 	if (platid_match(&platid, &platid_mask_CPU_MIPS_VR_41XX)) {
63 		/*
64 		 * disable all interrupts except PIU interrupt
65 		 */
66 		vrip_intr_suspend();
67 		_spllower(~MIPS_INT_MASK_0);
68 
69 		/*
70 		 * STANDBY instruction puts the CPU into power saveing
71 		 * state until some interrupt occuer.
72 		 * It sleeps until you push the power button.
73 		 */
74 		__asm(".set noreorder");
75 		__asm(".word	" ___STRING(VR_OPCODE_STANDBY));
76 		__asm("nop");
77 		__asm("nop");
78 		__asm("nop");
79 		__asm("nop");
80 		__asm("nop");
81 		__asm(".set reorder");
82 
83 		splhigh();
84 		vrip_intr_resume();
85 		delay(1000); /* 1msec */
86 	}
87 #endif /* NVRIP_COMMON > 0 */
88 }
89 
90 void
91 machine_sleep(void)
92 {
93 #if NVRIP_COMMON > 0
94 	 if (platid_match(&platid, &platid_mask_CPU_MIPS_VR_41XX)) {
95 		 /*
96 		  * disable all interrupts except PIU interrupt
97 		  */
98 		 vrip_intr_suspend();
99 		 _spllower(~MIPS_INT_MASK_0);
100 
101 		 /*
102 		  * SUSPEND instruction puts the CPU into power saveing
103 		  * state until some interrupt occuer.
104 		  * It sleeps until you push the power button.
105 		  */
106 		 __asm(".set noreorder");
107 		 __asm(".word	" ___STRING(VR_OPCODE_SUSPEND));
108 		 __asm("nop");
109 		 __asm("nop");
110 		 __asm("nop");
111 		 __asm("nop");
112 		 __asm("nop");
113 		 __asm(".set reorder");
114 
115 		 splhigh();
116 		 vrip_intr_resume();
117 		 delay(1000); /* 1msec */
118 	 }
119 #endif /* NVRIP_COMMON > 0 */
120 #ifdef TX39XX
121 	 if (platid_match(&platid, &platid_mask_CPU_MIPS_TX)) {
122 		 tx39power_suspend_cpu();
123 	 }
124 #endif
125 }
126