tx39power.c revision 1.1 1 /* $NetBSD: tx39power.c,v 1.1 1999/11/20 19:56:36 uch Exp $ */
2
3 /*
4 * Copyright (c) 1999, 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 printf("\n ");
84 #ifdef TX39POWERDEBUG
85 reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
86 ISSETPRINT(reg, ONBUTN);
87 ISSETPRINT(reg, PWRINT);
88 ISSETPRINT(reg, PWROK);
89 #ifdef TX392X
90 ISSETPRINT(reg, PWROKNMI);
91 #endif /* TX392X */
92 ISSETPRINT(reg, SLOWBUS);
93 #ifdef TX391X
94 ISSETPRINT(reg, DIVMOD);
95 #endif /* TX391X */
96 ISSETPRINT(reg, ENSTPTIMER);
97 ISSETPRINT(reg, ENFORCESHUTDWN);
98 ISSETPRINT(reg, FORCESHUTDWN);
99 ISSETPRINT(reg, FORCESHUTDWNOCC);
100 ISSETPRINT(reg, SELC2MS);
101 #ifdef TX392X
102 ISSETPRINT(reg, WARMSTART);
103 #endif /* TX392X */
104 ISSETPRINT(reg, BPDBVCC3);
105 ISSETPRINT(reg, STOPCPU);
106 ISSETPRINT(reg, DBNCONBUTN);
107 ISSETPRINT(reg, COLDSTART);
108 ISSETPRINT(reg, PWRCS);
109 ISSETPRINT(reg, VCCON);
110 #ifdef TX391X
111 printf("VIDRF=%d ", TX39_POWERCTRL_VIDRF(reg));
112 #endif /* TX391X */
113 printf("STPTIMERVAL=%d ", TX39_POWERCTRL_STPTIMERVAL(reg));
114 printf("\n");
115 #endif /* TX39POWERDEBUG */
116 #ifdef DISABLE_SPI_AND_DOZE /* XXX test XXX */
117 /*
118 * Disable SPI module
119 */
120 reg = tx_conf_read(tc, TX39_SPICTRL_REG);
121 if (ISSET(reg, TX39_SPICTRL_ENSPI)) {
122 reg &= ~TX39_SPICTRL_ENSPI;
123 }
124 printf("SPI module disabled\n");
125
126 /*
127 * Disable Stop timer (Doze CPU mode)
128 */
129 reg = tx_conf_read(tc, TX39_POWERCTRL_REG);
130 printf("STPTIMER disabled.\n");
131 reg &= ~TX39_POWERCTRL_ENSTPTIMER;
132 tx_conf_write(tc, TX39_POWERCTRL_REG, reg);
133 #endif /* DISABLE_SPI_AND_DOZE */
134
135 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSPWRINT),
136 IST_EDGE, IPL_CLOCK,
137 tx39power_intr, sc);
138 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGPWRINT),
139 IST_EDGE, IPL_CLOCK,
140 tx39power_intr, sc);
141 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSPWROKINT),
142 IST_EDGE, IPL_CLOCK,
143 tx39power_ok_intr, sc);
144 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGPWROKINT),
145 IST_EDGE, IPL_CLOCK,
146 tx39power_ok_intr, sc);
147 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_POSONBUTNINT),
148 IST_EDGE, IPL_CLOCK,
149 tx39power_button_intr, sc);
150 tx_intr_establish(tc, MAKEINTR(5, TX39_INTRSTATUS5_NEGONBUTNINT),
151 IST_EDGE, IPL_CLOCK,
152 tx39power_button_intr, sc);
153
154 }
155
156 int
157 tx39power_button_intr(arg)
158 void *arg;
159 {
160 printf("power button\n");
161 return 0;
162 }
163
164 int
165 tx39power_intr(arg)
166 void *arg;
167 {
168 printf("power\n");
169 return 0;
170 }
171
172 int
173 tx39power_ok_intr(arg)
174 void *arg;
175 {
176 printf("power ok\n");
177 return 0;
178 }
179