tx39power.c revision 1.4 1 /* $NetBSD: tx39power.c,v 1.4 2000/01/03 18:24:04 uch Exp $ */
2
3 /*
4 * Copyright (c) 1999, 2000 by UCHIYAMA Yasushi
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. The name of the developer may NOT be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28 #include "opt_tx39_debug.h"
29 #include "opt_tx39powerdebug.h"
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/device.h>
34
35 #include <machine/bus.h>
36 #include <machine/intr.h>
37
38 #include <hpcmips/tx/tx39var.h>
39 #include <hpcmips/tx/tx39icureg.h>
40 #include <hpcmips/tx/tx39powerreg.h>
41 #include <hpcmips/tx/tx39spireg.h>
42
43 #define ISSET(x, v) ((x) & (v))
44 #define ISSETPRINT(r, m) __is_set_print(r, TX39_POWERCTRL_##m, #m)
45
46 int tx39power_match __P((struct device*, struct cfdata*, void*));
47 void tx39power_attach __P((struct device*, struct device*, void*));
48
49 int tx39power_intr __P((void*));
50 int tx39power_ok_intr __P((void*));
51 int tx39power_button_intr __P((void*));
52
53 struct tx39power_softc {
54 struct device sc_dev;
55 tx_chipset_tag_t sc_tc;
56 };
57
58 struct cfattach tx39power_ca = {
59 sizeof(struct tx39power_softc), tx39power_match, tx39power_attach
60 };
61
62 int
63 tx39power_match(parent, cf, aux)
64 struct device *parent;
65 struct cfdata *cf;
66 void *aux;
67 {
68 return 2; /* 1st attach group of txsim */
69 }
70
71 void
72 tx39power_attach(parent, self, aux)
73 struct device *parent;
74 struct device *self;
75 void *aux;
76 {
77 struct txsim_attach_args *ta = aux;
78 struct tx39power_softc *sc = (void*)self;
79 tx_chipset_tag_t tc;
80 txreg_t reg;
81
82 tc = sc->sc_tc = ta->ta_tc;
83 tx_conf_register_power(tc, self);
84
85 printf("\n");
86 #ifdef TX39POWERDEBUG
87 reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
88 ISSETPRINT(reg, ONBUTN);
89 ISSETPRINT(reg, PWRINT);
90 ISSETPRINT(reg, PWROK);
91 #ifdef TX392X
92 ISSETPRINT(reg, PWROKNMI);
93 #endif /* TX392X */
94 ISSETPRINT(reg, SLOWBUS);
95 #ifdef TX391X
96 ISSETPRINT(reg, DIVMOD);
97 #endif /* TX391X */
98 ISSETPRINT(reg, ENSTPTIMER);
99 ISSETPRINT(reg, ENFORCESHUTDWN);
100 ISSETPRINT(reg, FORCESHUTDWN);
101 ISSETPRINT(reg, FORCESHUTDWNOCC);
102 ISSETPRINT(reg, SELC2MS);
103 #ifdef TX392X
104 ISSETPRINT(reg, WARMSTART);
105 #endif /* TX392X */
106 ISSETPRINT(reg, BPDBVCC3);
107 ISSETPRINT(reg, STOPCPU);
108 ISSETPRINT(reg, DBNCONBUTN);
109 ISSETPRINT(reg, COLDSTART);
110 ISSETPRINT(reg, PWRCS);
111 ISSETPRINT(reg, VCCON);
112 #ifdef TX391X
113 printf("VIDRF=%d ", TX39_POWERCTRL_VIDRF(reg));
114 #endif /* TX391X */
115 printf("STPTIMERVAL=%d ", TX39_POWERCTRL_STPTIMERVAL(reg));
116 printf("\n");
117 #endif /* TX39POWERDEBUG */
118 #ifdef DISABLE_SPI_AND_DOZE /* XXX test XXX */
119 /*
120 * Disable SPI module
121 */
122 reg = tx_conf_read(tc, TX39_SPICTRL_REG);
123 if (ISSET(reg, TX39_SPICTRL_ENSPI)) {
124 reg &= ~TX39_SPICTRL_ENSPI;
125 }
126 printf("SPI module disabled\n");
127
128 /*
129 * Disable Stop timer (Doze CPU mode)
130 */
131 reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
132 printf("STPTIMER disabled.\n");
133 reg &= ~TX39_POWERCTRL_ENSTPTIMER;
134 tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
135 #endif /* DISABLE_SPI_AND_DOZE */
136
137 /*
138 * enable stop timer
139 */
140 reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
141
142 reg &= ~(TX39_POWERCTRL_STPTIMERVAL_MASK <<
143 TX39_POWERCTRL_STPTIMERVAL_SHIFT);
144 reg = TX39_POWERCTRL_STPTIMERVAL_SET(reg, 1);
145
146 reg |= TX39_POWERCTRL_ENSTPTIMER;
147 tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
148
149 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSPWRINT),
150 IST_EDGE, IPL_CLOCK,
151 tx39power_intr, sc);
152 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGPWRINT),
153 IST_EDGE, IPL_CLOCK,
154 tx39power_intr, sc);
155 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSPWROKINT),
156 IST_EDGE, IPL_CLOCK,
157 tx39power_ok_intr, sc);
158 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGPWROKINT),
159 IST_EDGE, IPL_CLOCK,
160 tx39power_ok_intr, sc);
161 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSONBUTNINT),
162 IST_EDGE, IPL_CLOCK,
163 tx39power_button_intr, sc);
164 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGONBUTNINT),
165 IST_EDGE, IPL_CLOCK,
166 tx39power_button_intr, sc);
167
168 }
169
170 int
171 tx39power_button_intr(arg)
172 void *arg;
173 {
174 printf("power button\n");
175 return 0;
176 }
177
178 int
179 tx39power_intr(arg)
180 void *arg;
181 {
182 printf("power\n");
183 return 0;
184 }
185
186 int
187 tx39power_ok_intr(arg)
188 void *arg;
189 {
190 printf("power ok\n");
191 return 0;
192 }
193