tx39power.c revision 1.9.8.2 1 1.9.8.2 nathanw /* $NetBSD: tx39power.c,v 1.9.8.2 2002/02/28 04:10:02 nathanw Exp $ */
2 1.9.8.2 nathanw
3 1.9.8.2 nathanw /*-
4 1.9.8.2 nathanw * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
5 1.9.8.2 nathanw * All rights reserved.
6 1.9.8.2 nathanw *
7 1.9.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.9.8.2 nathanw * by UCHIYAMA Yasushi.
9 1.9.8.2 nathanw *
10 1.9.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.9.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.9.8.2 nathanw * are met:
13 1.9.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.9.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.9.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.9.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.9.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.9.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.9.8.2 nathanw * must display the following acknowledgement:
20 1.9.8.2 nathanw * This product includes software developed by the NetBSD
21 1.9.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.9.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.9.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.9.8.2 nathanw * from this software without specific prior written permission.
25 1.9.8.2 nathanw *
26 1.9.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.9.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.9.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.9.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.9.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.9.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.9.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.9.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.9.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.9.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.9.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.9.8.2 nathanw */
38 1.9.8.2 nathanw
39 1.9.8.2 nathanw #include "opt_tx39power_debug.h"
40 1.9.8.2 nathanw #define TX39POWERDEBUG
41 1.9.8.2 nathanw
42 1.9.8.2 nathanw #include <sys/param.h>
43 1.9.8.2 nathanw #include <sys/systm.h>
44 1.9.8.2 nathanw #include <sys/device.h>
45 1.9.8.2 nathanw
46 1.9.8.2 nathanw #include <machine/bus.h>
47 1.9.8.2 nathanw #include <machine/intr.h>
48 1.9.8.2 nathanw #include <machine/config_hook.h>
49 1.9.8.2 nathanw
50 1.9.8.2 nathanw #include <hpcmips/tx/tx39var.h>
51 1.9.8.2 nathanw #include <hpcmips/tx/tx39icureg.h>
52 1.9.8.2 nathanw #include <hpcmips/tx/tx39powerreg.h>
53 1.9.8.2 nathanw
54 1.9.8.2 nathanw #ifdef TX39POWER_DEBUG
55 1.9.8.2 nathanw #define DPRINTF_ENABLE
56 1.9.8.2 nathanw #define DPRINTF_DEBUG tx39power_debug
57 1.9.8.2 nathanw #endif
58 1.9.8.2 nathanw #include <machine/debug.h>
59 1.9.8.2 nathanw
60 1.9.8.2 nathanw #ifdef TX39POWER_DEBUG
61 1.9.8.2 nathanw #define DUMP_REGS(x) __tx39power_dump(x)
62 1.9.8.2 nathanw #else
63 1.9.8.2 nathanw #define DUMP_REGS(x) ((void)0)
64 1.9.8.2 nathanw #endif
65 1.9.8.2 nathanw
66 1.9.8.2 nathanw #define ISSET(x, v) ((x) & (v))
67 1.9.8.2 nathanw #define ISSETPRINT(r, m) dbg_bitmask_print(r, TX39_POWERCTRL_##m, #m)
68 1.9.8.2 nathanw
69 1.9.8.2 nathanw int tx39power_match(struct device *, struct cfdata *, void *);
70 1.9.8.2 nathanw void tx39power_attach(struct device *, struct device *, void *);
71 1.9.8.2 nathanw
72 1.9.8.2 nathanw struct tx39power_softc {
73 1.9.8.2 nathanw struct device sc_dev;
74 1.9.8.2 nathanw tx_chipset_tag_t sc_tc;
75 1.9.8.2 nathanw
76 1.9.8.2 nathanw /* save interrupt status for resume */
77 1.9.8.2 nathanw txreg_t sc_icu_state[TX39_INTRSET_MAX + 1];
78 1.9.8.2 nathanw };
79 1.9.8.2 nathanw
80 1.9.8.2 nathanw struct cfattach tx39power_ca = {
81 1.9.8.2 nathanw sizeof(struct tx39power_softc), tx39power_match, tx39power_attach
82 1.9.8.2 nathanw };
83 1.9.8.2 nathanw
84 1.9.8.2 nathanw void tx39power_suspend_cpu(void); /* automatic hardware resume */
85 1.9.8.2 nathanw
86 1.9.8.2 nathanw static int tx39power_intr_p(void *);
87 1.9.8.2 nathanw static int tx39power_intr_n(void *);
88 1.9.8.2 nathanw static int tx39power_ok_intr_p(void *);
89 1.9.8.2 nathanw static int tx39power_ok_intr_n(void *);
90 1.9.8.2 nathanw static int tx39power_button_intr_p(void *);
91 1.9.8.2 nathanw static int tx39power_button_intr_n(void *);
92 1.9.8.2 nathanw #ifdef TX39POWER_DEBUG
93 1.9.8.2 nathanw static void __tx39power_dump(struct tx39power_softc *);
94 1.9.8.2 nathanw #endif
95 1.9.8.2 nathanw
96 1.9.8.2 nathanw int
97 1.9.8.2 nathanw tx39power_match(struct device *parent, struct cfdata *cf, void *aux)
98 1.9.8.2 nathanw {
99 1.9.8.2 nathanw return (ATTACH_FIRST);
100 1.9.8.2 nathanw }
101 1.9.8.2 nathanw
102 1.9.8.2 nathanw void
103 1.9.8.2 nathanw tx39power_attach(struct device *parent, struct device *self, void *aux)
104 1.9.8.2 nathanw {
105 1.9.8.2 nathanw struct txsim_attach_args *ta = aux;
106 1.9.8.2 nathanw struct tx39power_softc *sc = (void*)self;
107 1.9.8.2 nathanw tx_chipset_tag_t tc;
108 1.9.8.2 nathanw txreg_t reg;
109 1.9.8.2 nathanw
110 1.9.8.2 nathanw tc = sc->sc_tc = ta->ta_tc;
111 1.9.8.2 nathanw tx_conf_register_power(tc, self);
112 1.9.8.2 nathanw
113 1.9.8.2 nathanw printf("\n");
114 1.9.8.2 nathanw DUMP_REGS(sc);
115 1.9.8.2 nathanw
116 1.9.8.2 nathanw /* power button setting */
117 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
118 1.9.8.2 nathanw reg |= TX39_POWERCTRL_DBNCONBUTN;
119 1.9.8.2 nathanw tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
120 1.9.8.2 nathanw
121 1.9.8.2 nathanw /* enable stop timer */
122 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
123 1.9.8.2 nathanw reg &= ~(TX39_POWERCTRL_STPTIMERVAL_MASK <<
124 1.9.8.2 nathanw TX39_POWERCTRL_STPTIMERVAL_SHIFT);
125 1.9.8.2 nathanw reg = TX39_POWERCTRL_STPTIMERVAL_SET(reg,
126 1.9.8.2 nathanw TX39_POWERCTRL_STPTIMERVAL_MAX);
127 1.9.8.2 nathanw reg |= TX39_POWERCTRL_ENSTPTIMER;
128 1.9.8.2 nathanw tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
129 1.9.8.2 nathanw
130 1.9.8.2 nathanw /* install power event handler */
131 1.9.8.2 nathanw /* low priority */
132 1.9.8.2 nathanw tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSPWRINT),
133 1.9.8.2 nathanw IST_EDGE, IPL_CLOCK,
134 1.9.8.2 nathanw tx39power_intr_p, sc);
135 1.9.8.2 nathanw tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGPWRINT),
136 1.9.8.2 nathanw IST_EDGE, IPL_CLOCK,
137 1.9.8.2 nathanw tx39power_intr_n, sc);
138 1.9.8.2 nathanw /* high priority */
139 1.9.8.2 nathanw tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSPWROKINT),
140 1.9.8.2 nathanw IST_EDGE, IPL_CLOCK,
141 1.9.8.2 nathanw tx39power_ok_intr_p, sc);
142 1.9.8.2 nathanw tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGPWROKINT),
143 1.9.8.2 nathanw IST_EDGE, IPL_CLOCK,
144 1.9.8.2 nathanw tx39power_ok_intr_n, sc);
145 1.9.8.2 nathanw /* user driven event */
146 1.9.8.2 nathanw tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSONBUTNINT),
147 1.9.8.2 nathanw IST_EDGE, IPL_CLOCK,
148 1.9.8.2 nathanw tx39power_button_intr_p, sc);
149 1.9.8.2 nathanw tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGONBUTNINT),
150 1.9.8.2 nathanw IST_EDGE, IPL_CLOCK,
151 1.9.8.2 nathanw tx39power_button_intr_n, sc);
152 1.9.8.2 nathanw }
153 1.9.8.2 nathanw
154 1.9.8.2 nathanw void
155 1.9.8.2 nathanw tx39power_suspend_cpu() /* I assume already splhigh */
156 1.9.8.2 nathanw {
157 1.9.8.2 nathanw tx_chipset_tag_t tc = tx_conf_get_tag();
158 1.9.8.2 nathanw struct tx39power_softc *sc = tc->tc_powert;
159 1.9.8.2 nathanw txreg_t reg, *iregs = sc->sc_icu_state;
160 1.9.8.2 nathanw
161 1.9.8.2 nathanw printf ("%s: CPU sleep\n", sc->sc_dev.dv_xname);
162 1.9.8.2 nathanw __asm__ __volatile__(".set noreorder");
163 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
164 1.9.8.2 nathanw reg |= TX39_POWERCTRL_STOPCPU;
165 1.9.8.2 nathanw /* save interrupt state */
166 1.9.8.2 nathanw iregs[0] = tx_conf_read(tc, TX39_INTRENABLE6_REG);
167 1.9.8.2 nathanw iregs[1] = tx_conf_read(tc, TX39_INTRENABLE1_REG);
168 1.9.8.2 nathanw iregs[2] = tx_conf_read(tc, TX39_INTRENABLE2_REG);
169 1.9.8.2 nathanw iregs[3] = tx_conf_read(tc, TX39_INTRENABLE3_REG);
170 1.9.8.2 nathanw iregs[4] = tx_conf_read(tc, TX39_INTRENABLE4_REG);
171 1.9.8.2 nathanw iregs[5] = tx_conf_read(tc, TX39_INTRENABLE5_REG);
172 1.9.8.2 nathanw #ifdef TX392X
173 1.9.8.2 nathanw iregs[7] = tx_conf_read(tc, TX39_INTRENABLE7_REG);
174 1.9.8.2 nathanw iregs[8] = tx_conf_read(tc, TX39_INTRENABLE8_REG);
175 1.9.8.2 nathanw #endif
176 1.9.8.2 nathanw /* disable all interrupt (don't disable GLOBALEN) */
177 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE6_REG, TX39_INTRENABLE6_GLOBALEN);
178 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE1_REG, 0);
179 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE2_REG, 0);
180 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE3_REG, 0);
181 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE4_REG, 0);
182 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE5_REG, 0);
183 1.9.8.2 nathanw #ifdef TX392X
184 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE7_REG, 0);
185 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE8_REG, 0);
186 1.9.8.2 nathanw #endif
187 1.9.8.2 nathanw /* enable power button interrupt only */
188 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRCLEAR5_REG, TX39_INTRSTATUS5_NEGONBUTNINT);
189 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE5_REG, TX39_INTRSTATUS5_NEGONBUTNINT);
190 1.9.8.2 nathanw __asm__ __volatile__("sync");
191 1.9.8.2 nathanw
192 1.9.8.2 nathanw /* stop CPU clock */
193 1.9.8.2 nathanw tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
194 1.9.8.2 nathanw __asm__ __volatile__("sync");
195 1.9.8.2 nathanw /* wait until power button pressed */
196 1.9.8.2 nathanw /* clear interrupt */
197 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRCLEAR5_REG, TX39_INTRSTATUS5_NEGONBUTNINT);
198 1.9.8.2 nathanw #ifdef TX392X
199 1.9.8.2 nathanw /* Clear WARMSTART bit to reset vector(0xbfc00000) work correctly */
200 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
201 1.9.8.2 nathanw reg &= ~TX39_POWERCTRL_WARMSTART;
202 1.9.8.2 nathanw tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
203 1.9.8.2 nathanw #endif
204 1.9.8.2 nathanw
205 1.9.8.2 nathanw /* restore interrupt state */
206 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE6_REG, iregs[0]);
207 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE1_REG, iregs[1]);
208 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE2_REG, iregs[2]);
209 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE3_REG, iregs[3]);
210 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE4_REG, iregs[4]);
211 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE5_REG, iregs[5]);
212 1.9.8.2 nathanw #ifdef TX392X
213 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE7_REG, iregs[7]);
214 1.9.8.2 nathanw tx_conf_write(tc, TX39_INTRENABLE8_REG, iregs[8]);
215 1.9.8.2 nathanw #endif
216 1.9.8.2 nathanw __asm__ __volatile__(".set reorder");
217 1.9.8.2 nathanw
218 1.9.8.2 nathanw printf ("%s: CPU wakeup\n", sc->sc_dev.dv_xname);
219 1.9.8.2 nathanw }
220 1.9.8.2 nathanw
221 1.9.8.2 nathanw static int
222 1.9.8.2 nathanw tx39power_button_intr_p(void *arg)
223 1.9.8.2 nathanw {
224 1.9.8.2 nathanw config_hook_call(CONFIG_HOOK_BUTTONEVENT,
225 1.9.8.2 nathanw CONFIG_HOOK_BUTTONEVENT_POWER,
226 1.9.8.2 nathanw (void *)1 /* on */);
227 1.9.8.2 nathanw
228 1.9.8.2 nathanw return (0);
229 1.9.8.2 nathanw }
230 1.9.8.2 nathanw
231 1.9.8.2 nathanw static int
232 1.9.8.2 nathanw tx39power_button_intr_n(void *arg)
233 1.9.8.2 nathanw {
234 1.9.8.2 nathanw config_hook_call(CONFIG_HOOK_BUTTONEVENT,
235 1.9.8.2 nathanw CONFIG_HOOK_BUTTONEVENT_POWER,
236 1.9.8.2 nathanw (void *)0 /* off */);
237 1.9.8.2 nathanw DUMP_REGS(arg);
238 1.9.8.2 nathanw
239 1.9.8.2 nathanw return (0);
240 1.9.8.2 nathanw }
241 1.9.8.2 nathanw
242 1.9.8.2 nathanw int
243 1.9.8.2 nathanw tx39power_intr_p(void *arg)
244 1.9.8.2 nathanw {
245 1.9.8.2 nathanw /* low priority event */
246 1.9.8.2 nathanw printf("power_p\n");
247 1.9.8.2 nathanw DUMP_REGS(arg);
248 1.9.8.2 nathanw
249 1.9.8.2 nathanw return (0);
250 1.9.8.2 nathanw }
251 1.9.8.2 nathanw
252 1.9.8.2 nathanw static int
253 1.9.8.2 nathanw tx39power_intr_n(void *arg)
254 1.9.8.2 nathanw {
255 1.9.8.2 nathanw /* low priority event */
256 1.9.8.2 nathanw printf("power_n\n");
257 1.9.8.2 nathanw DUMP_REGS(arg);
258 1.9.8.2 nathanw
259 1.9.8.2 nathanw return (0);
260 1.9.8.2 nathanw }
261 1.9.8.2 nathanw
262 1.9.8.2 nathanw static int
263 1.9.8.2 nathanw tx39power_ok_intr_p(void *arg)
264 1.9.8.2 nathanw {
265 1.9.8.2 nathanw /* high priority event */
266 1.9.8.2 nathanw printf("power NG\n");
267 1.9.8.2 nathanw DUMP_REGS(arg);
268 1.9.8.2 nathanw config_hook_call(CONFIG_HOOK_PMEVENT,
269 1.9.8.2 nathanw CONFIG_HOOK_PMEVENT_SUSPENDREQ, NULL);
270 1.9.8.2 nathanw
271 1.9.8.2 nathanw return (0);
272 1.9.8.2 nathanw }
273 1.9.8.2 nathanw
274 1.9.8.2 nathanw static int
275 1.9.8.2 nathanw tx39power_ok_intr_n(void *arg)
276 1.9.8.2 nathanw {
277 1.9.8.2 nathanw /* high priority event */
278 1.9.8.2 nathanw printf("power OK\n");
279 1.9.8.2 nathanw DUMP_REGS(arg);
280 1.9.8.2 nathanw
281 1.9.8.2 nathanw return (0);
282 1.9.8.2 nathanw }
283 1.9.8.2 nathanw
284 1.9.8.2 nathanw #ifdef TX39POWER_DEBUG
285 1.9.8.2 nathanw static void
286 1.9.8.2 nathanw __tx39power_dump (struct tx39power_softc *sc)
287 1.9.8.2 nathanw {
288 1.9.8.2 nathanw tx_chipset_tag_t tc = sc->sc_tc;
289 1.9.8.2 nathanw txreg_t reg;
290 1.9.8.2 nathanw
291 1.9.8.2 nathanw reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
292 1.9.8.2 nathanw ISSETPRINT(reg, ONBUTN);
293 1.9.8.2 nathanw ISSETPRINT(reg, PWRINT);
294 1.9.8.2 nathanw ISSETPRINT(reg, PWROK);
295 1.9.8.2 nathanw #ifdef TX392X
296 1.9.8.2 nathanw ISSETPRINT(reg, PWROKNMI);
297 1.9.8.2 nathanw #endif /* TX392X */
298 1.9.8.2 nathanw ISSETPRINT(reg, SLOWBUS);
299 1.9.8.2 nathanw #ifdef TX391X
300 1.9.8.2 nathanw ISSETPRINT(reg, DIVMOD);
301 1.9.8.2 nathanw #endif /* TX391X */
302 1.9.8.2 nathanw ISSETPRINT(reg, ENSTPTIMER);
303 1.9.8.2 nathanw ISSETPRINT(reg, ENFORCESHUTDWN);
304 1.9.8.2 nathanw ISSETPRINT(reg, FORCESHUTDWN);
305 1.9.8.2 nathanw ISSETPRINT(reg, FORCESHUTDWNOCC);
306 1.9.8.2 nathanw ISSETPRINT(reg, SELC2MS);
307 1.9.8.2 nathanw #ifdef TX392X
308 1.9.8.2 nathanw ISSETPRINT(reg, WARMSTART);
309 1.9.8.2 nathanw #endif /* TX392X */
310 1.9.8.2 nathanw ISSETPRINT(reg, BPDBVCC3);
311 1.9.8.2 nathanw ISSETPRINT(reg, STOPCPU);
312 1.9.8.2 nathanw ISSETPRINT(reg, DBNCONBUTN);
313 1.9.8.2 nathanw ISSETPRINT(reg, COLDSTART);
314 1.9.8.2 nathanw ISSETPRINT(reg, PWRCS);
315 1.9.8.2 nathanw ISSETPRINT(reg, VCCON);
316 1.9.8.2 nathanw #ifdef TX391X
317 1.9.8.2 nathanw printf("VIDRF=%d ", TX39_POWERCTRL_VIDRF(reg));
318 1.9.8.2 nathanw #endif /* TX391X */
319 1.9.8.2 nathanw printf("STPTIMERVAL=%d ", TX39_POWERCTRL_STPTIMERVAL(reg));
320 1.9.8.2 nathanw printf("\n");
321 1.9.8.2 nathanw }
322 1.9.8.2 nathanw #endif /* TX39POWER_DEBUG */
323