tx39biu.c revision 1.5.8.2 1 1.5.8.2 nathanw /* $NetBSD: tx39biu.c,v 1.5.8.2 2002/02/28 04:10:01 nathanw Exp $ */
2 1.5.8.2 nathanw
3 1.5.8.2 nathanw /*-
4 1.5.8.2 nathanw * Copyright (c) 1999-2002 The NetBSD Foundation, Inc.
5 1.5.8.2 nathanw * All rights reserved.
6 1.5.8.2 nathanw *
7 1.5.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.5.8.2 nathanw * by UCHIYAMA Yasushi.
9 1.5.8.2 nathanw *
10 1.5.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.5.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.5.8.2 nathanw * are met:
13 1.5.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.5.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.5.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.5.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.5.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.5.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.5.8.2 nathanw * must display the following acknowledgement:
20 1.5.8.2 nathanw * This product includes software developed by the NetBSD
21 1.5.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.5.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.5.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.5.8.2 nathanw * from this software without specific prior written permission.
25 1.5.8.2 nathanw *
26 1.5.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.5.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.5.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.5.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.5.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.5.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.5.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.5.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.5.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.5.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.5.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.5.8.2 nathanw */
38 1.5.8.2 nathanw
39 1.5.8.2 nathanw #include "opt_tx39_watchdogtimer.h"
40 1.5.8.2 nathanw #include "opt_tx39biu_debug.h"
41 1.5.8.2 nathanw
42 1.5.8.2 nathanw #include <sys/param.h>
43 1.5.8.2 nathanw #include <sys/systm.h>
44 1.5.8.2 nathanw #include <sys/device.h>
45 1.5.8.2 nathanw
46 1.5.8.2 nathanw #include <machine/bus.h>
47 1.5.8.2 nathanw #include <machine/debug.h>
48 1.5.8.2 nathanw
49 1.5.8.2 nathanw #include <hpcmips/tx/tx39var.h>
50 1.5.8.2 nathanw #include <hpcmips/tx/tx39biureg.h>
51 1.5.8.2 nathanw #include <hpcmips/tx/txcsbusvar.h>
52 1.5.8.2 nathanw
53 1.5.8.2 nathanw #ifdef TX39BIU_DEBUG
54 1.5.8.2 nathanw #define DPRINTF_ENABLE
55 1.5.8.2 nathanw #define DPRINTF_DEBUG tx39biu_debug
56 1.5.8.2 nathanw #endif
57 1.5.8.2 nathanw #include <machine/debug.h>
58 1.5.8.2 nathanw
59 1.5.8.2 nathanw #define ISSET(x, s) ((x) & (1 << (s)))
60 1.5.8.2 nathanw #define ISSETPRINT(r, s, m) dbg_bitmask_print((u_int32_t)(r), \
61 1.5.8.2 nathanw TX39_MEMCONFIG ## s ## _ ##m, #m)
62 1.5.8.2 nathanw
63 1.5.8.2 nathanw int tx39biu_match(struct device *, struct cfdata *, void *);
64 1.5.8.2 nathanw void tx39biu_attach(struct device *, struct device *, void *);
65 1.5.8.2 nathanw void tx39biu_callback(struct device *);
66 1.5.8.2 nathanw int tx39biu_print(void *, const char *);
67 1.5.8.2 nathanw int tx39biu_intr(void *);
68 1.5.8.2 nathanw
69 1.5.8.2 nathanw static void *__sc; /* XXX */
70 1.5.8.2 nathanw #ifdef TX39BIU_DEBUG
71 1.5.8.2 nathanw void tx39biu_dump(tx_chipset_tag_t);
72 1.5.8.2 nathanw #endif
73 1.5.8.2 nathanw
74 1.5.8.2 nathanw struct tx39biu_softc {
75 1.5.8.2 nathanw struct device sc_dev;
76 1.5.8.2 nathanw tx_chipset_tag_t sc_tc;
77 1.5.8.2 nathanw };
78 1.5.8.2 nathanw
79 1.5.8.2 nathanw struct cfattach tx39biu_ca = {
80 1.5.8.2 nathanw sizeof(struct tx39biu_softc), tx39biu_match, tx39biu_attach
81 1.5.8.2 nathanw };
82 1.5.8.2 nathanw
83 1.5.8.2 nathanw int
84 1.5.8.2 nathanw tx39biu_match(parent, cf, aux)
85 1.5.8.2 nathanw struct device *parent;
86 1.5.8.2 nathanw struct cfdata *cf;
87 1.5.8.2 nathanw void *aux;
88 1.5.8.2 nathanw {
89 1.5.8.2 nathanw return (ATTACH_NORMAL);
90 1.5.8.2 nathanw }
91 1.5.8.2 nathanw
92 1.5.8.2 nathanw void
93 1.5.8.2 nathanw tx39biu_attach(parent, self, aux)
94 1.5.8.2 nathanw struct device *parent;
95 1.5.8.2 nathanw struct device *self;
96 1.5.8.2 nathanw void *aux;
97 1.5.8.2 nathanw {
98 1.5.8.2 nathanw struct txsim_attach_args *ta = aux;
99 1.5.8.2 nathanw struct tx39biu_softc *sc = (void*)self;
100 1.5.8.2 nathanw tx_chipset_tag_t tc;
101 1.5.8.2 nathanw #ifdef TX39_WATCHDOGTIMER
102 1.5.8.2 nathanw txreg_t reg;
103 1.5.8.2 nathanw #endif
104 1.5.8.2 nathanw
105 1.5.8.2 nathanw sc->sc_tc = tc = ta->ta_tc;
106 1.5.8.2 nathanw printf("\n");
107 1.5.8.2 nathanw #ifdef TX39BIU_DEBUG
108 1.5.8.2 nathanw tx39biu_dump(tc);
109 1.5.8.2 nathanw #endif
110 1.5.8.2 nathanw
111 1.5.8.2 nathanw #ifdef TX39_WATCHDOGTIMER
112 1.5.8.2 nathanw /*
113 1.5.8.2 nathanw * CLRWRBUSERRINT Bus error connected CPU HwInt0
114 1.5.8.2 nathanw */
115 1.5.8.2 nathanw reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
116 1.5.8.2 nathanw reg |= TX39_MEMCONFIG4_ENWATCH;
117 1.5.8.2 nathanw reg = TX39_MEMCONFIG4_WATCHTIMEVAL_SET(reg, 0xf);
118 1.5.8.2 nathanw tx_conf_write(tc, TX39_MEMCONFIG4_REG, reg);
119 1.5.8.2 nathanw
120 1.5.8.2 nathanw reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
121 1.5.8.2 nathanw if (reg & TX39_MEMCONFIG4_ENWATCH) {
122 1.5.8.2 nathanw int i;
123 1.5.8.2 nathanw i = TX39_MEMCONFIG4_WATCHTIMEVAL(reg);
124 1.5.8.2 nathanw i = (1000 * (i + 1) * 64) / 36864;
125 1.5.8.2 nathanw printf("WatchDogTimerRate: %dus\n", i);
126 1.5.8.2 nathanw }
127 1.5.8.2 nathanw #endif
128 1.5.8.2 nathanw __sc = sc;
129 1.5.8.2 nathanw
130 1.5.8.2 nathanw /* Clear watch dog timer interrupt */
131 1.5.8.2 nathanw tx39biu_intr(sc);
132 1.5.8.2 nathanw
133 1.5.8.2 nathanw /*
134 1.5.8.2 nathanw * Chip select virtual bridge
135 1.5.8.2 nathanw */
136 1.5.8.2 nathanw config_defer(self, tx39biu_callback);
137 1.5.8.2 nathanw }
138 1.5.8.2 nathanw
139 1.5.8.2 nathanw void
140 1.5.8.2 nathanw tx39biu_callback(self)
141 1.5.8.2 nathanw struct device *self;
142 1.5.8.2 nathanw {
143 1.5.8.2 nathanw struct tx39biu_softc *sc = (void*)self;
144 1.5.8.2 nathanw struct csbus_attach_args cba;
145 1.5.8.2 nathanw
146 1.5.8.2 nathanw cba.cba_busname = "txcsbus";
147 1.5.8.2 nathanw cba.cba_tc = sc->sc_tc;
148 1.5.8.2 nathanw config_found(self, &cba, tx39biu_print);
149 1.5.8.2 nathanw }
150 1.5.8.2 nathanw
151 1.5.8.2 nathanw int
152 1.5.8.2 nathanw tx39biu_print(aux, pnp)
153 1.5.8.2 nathanw void *aux;
154 1.5.8.2 nathanw const char *pnp;
155 1.5.8.2 nathanw {
156 1.5.8.2 nathanw return (pnp ? QUIET : UNCONF);
157 1.5.8.2 nathanw }
158 1.5.8.2 nathanw
159 1.5.8.2 nathanw int
160 1.5.8.2 nathanw tx39biu_intr(arg)
161 1.5.8.2 nathanw void *arg;
162 1.5.8.2 nathanw {
163 1.5.8.2 nathanw struct tx39biu_softc *sc = __sc;
164 1.5.8.2 nathanw tx_chipset_tag_t tc;
165 1.5.8.2 nathanw txreg_t reg;
166 1.5.8.2 nathanw
167 1.5.8.2 nathanw if (!sc) {
168 1.5.8.2 nathanw return (0);
169 1.5.8.2 nathanw }
170 1.5.8.2 nathanw tc = sc->sc_tc;
171 1.5.8.2 nathanw /* Clear interrupt */
172 1.5.8.2 nathanw reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
173 1.5.8.2 nathanw reg |= TX39_MEMCONFIG4_CLRWRBUSERRINT;
174 1.5.8.2 nathanw tx_conf_write(tc, TX39_MEMCONFIG4_REG, reg);
175 1.5.8.2 nathanw reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
176 1.5.8.2 nathanw reg &= ~TX39_MEMCONFIG4_CLRWRBUSERRINT;
177 1.5.8.2 nathanw tx_conf_write(tc, TX39_MEMCONFIG4_REG, reg);
178 1.5.8.2 nathanw
179 1.5.8.2 nathanw return (0);
180 1.5.8.2 nathanw }
181 1.5.8.2 nathanw
182 1.5.8.2 nathanw #ifdef TX39BIU_DEBUG
183 1.5.8.2 nathanw void
184 1.5.8.2 nathanw tx39biu_dump(tc)
185 1.5.8.2 nathanw tx_chipset_tag_t tc;
186 1.5.8.2 nathanw {
187 1.5.8.2 nathanw char *rowsel[] = {"18,17:9", "22,18,20,19,17:9", "20,22,21,19,17:9",
188 1.5.8.2 nathanw "22,23,21,19,17:9"};
189 1.5.8.2 nathanw char *colsel[] = {"22,20,18,8:1", "19,18,8:2", "21,20,18,8:2",
190 1.5.8.2 nathanw "23,22,20,18,8:2", "24,22,20,18,8:2",
191 1.5.8.2 nathanw "18,p,X,8:0","22,p,X,21,8:0", "18,p,X,21,8:1",
192 1.5.8.2 nathanw "22,p,X,23,21,8:1", "24,23,21,8:2"};
193 1.5.8.2 nathanw txreg_t reg;
194 1.5.8.2 nathanw int i;
195 1.5.8.2 nathanw /*
196 1.5.8.2 nathanw * Memory config 0 register
197 1.5.8.2 nathanw */
198 1.5.8.2 nathanw reg = tx_conf_read(tc, TX39_MEMCONFIG0_REG);
199 1.5.8.2 nathanw printf(" config0:");
200 1.5.8.2 nathanw ISSETPRINT(reg, 0, ENDCLKOUTTRI);
201 1.5.8.2 nathanw ISSETPRINT(reg, 0, DISDQMINIT);
202 1.5.8.2 nathanw ISSETPRINT(reg, 0, ENSDRAMPD);
203 1.5.8.2 nathanw ISSETPRINT(reg, 0, SHOWDINO);
204 1.5.8.2 nathanw ISSETPRINT(reg, 0, ENRMAP2);
205 1.5.8.2 nathanw ISSETPRINT(reg, 0, ENRMAP1);
206 1.5.8.2 nathanw ISSETPRINT(reg, 0, ENWRINPAGE);
207 1.5.8.2 nathanw ISSETPRINT(reg, 0, ENCS3USER);
208 1.5.8.2 nathanw ISSETPRINT(reg, 0, ENCS2USER);
209 1.5.8.2 nathanw ISSETPRINT(reg, 0, ENCS1USER);
210 1.5.8.2 nathanw ISSETPRINT(reg, 0, ENCS1DRAM);
211 1.5.8.2 nathanw ISSETPRINT(reg, 0, CS3SIZE);
212 1.5.8.2 nathanw ISSETPRINT(reg, 0, CS2SIZE);
213 1.5.8.2 nathanw ISSETPRINT(reg, 0, CS1SIZE);
214 1.5.8.2 nathanw ISSETPRINT(reg, 0, CS0SIZE);
215 1.5.8.2 nathanw printf("\n");
216 1.5.8.2 nathanw for (i = 0; i < 2; i++) {
217 1.5.8.2 nathanw int r, c;
218 1.5.8.2 nathanw printf(" BANK%d: ", i);
219 1.5.8.2 nathanw switch (i ? TX39_MEMCONFIG0_BANK1CONF(reg)
220 1.5.8.2 nathanw : TX39_MEMCONFIG0_BANK0CONF(reg)) {
221 1.5.8.2 nathanw case TX39_MEMCONFIG0_BANKCONF_16BITSDRAM:
222 1.5.8.2 nathanw printf("16bit SDRAM");
223 1.5.8.2 nathanw break;
224 1.5.8.2 nathanw case TX39_MEMCONFIG0_BANKCONF_8BITSDRAM:
225 1.5.8.2 nathanw printf("8bit SDRAM");
226 1.5.8.2 nathanw break;
227 1.5.8.2 nathanw case TX39_MEMCONFIG0_BANKCONF_32BITSDHDRAM:
228 1.5.8.2 nathanw printf("32bit DRAM/HDRAM");
229 1.5.8.2 nathanw break;
230 1.5.8.2 nathanw case TX39_MEMCONFIG0_BANKCONF_16BITSDHDRAM:
231 1.5.8.2 nathanw printf("16bit DRAM/HDRAM");
232 1.5.8.2 nathanw break;
233 1.5.8.2 nathanw }
234 1.5.8.2 nathanw if (i == 1) {
235 1.5.8.2 nathanw r = TX39_MEMCONFIG0_ROWSEL1(reg);
236 1.5.8.2 nathanw c = TX39_MEMCONFIG0_COLSEL1(reg);
237 1.5.8.2 nathanw } else {
238 1.5.8.2 nathanw r = TX39_MEMCONFIG0_ROWSEL0(reg);
239 1.5.8.2 nathanw c = TX39_MEMCONFIG0_COLSEL0(reg);
240 1.5.8.2 nathanw }
241 1.5.8.2 nathanw printf(" ROW %s COL %s\n", rowsel[r], colsel[c]);
242 1.5.8.2 nathanw }
243 1.5.8.2 nathanw
244 1.5.8.2 nathanw /*
245 1.5.8.2 nathanw * Memory config 3 register
246 1.5.8.2 nathanw */
247 1.5.8.2 nathanw printf(" config3:");
248 1.5.8.2 nathanw reg = tx_conf_read(tc, TX39_MEMCONFIG3_REG);
249 1.5.8.2 nathanw #ifdef TX391X
250 1.5.8.2 nathanw ISSETPRINT(reg, 3, ENMCS3PAGE);
251 1.5.8.2 nathanw ISSETPRINT(reg, 3, ENMCS2PAGE);
252 1.5.8.2 nathanw ISSETPRINT(reg, 3, ENMCS1PAGE);
253 1.5.8.2 nathanw ISSETPRINT(reg, 3, ENMCS0PAGE);
254 1.5.8.2 nathanw #endif /* TX391X */
255 1.5.8.2 nathanw ISSETPRINT(reg, 3, ENCS3PAGE);
256 1.5.8.2 nathanw ISSETPRINT(reg, 3, ENCS2PAGE);
257 1.5.8.2 nathanw ISSETPRINT(reg, 3, ENCS1PAGE);
258 1.5.8.2 nathanw ISSETPRINT(reg, 3, ENCS0PAGE);
259 1.5.8.2 nathanw ISSETPRINT(reg, 3, CARD2WAITEN);
260 1.5.8.2 nathanw ISSETPRINT(reg, 3, CARD1WAITEN);
261 1.5.8.2 nathanw ISSETPRINT(reg, 3, CARD2IOEN);
262 1.5.8.2 nathanw ISSETPRINT(reg, 3, CARD1IOEN);
263 1.5.8.2 nathanw #ifdef TX391X
264 1.5.8.2 nathanw ISSETPRINT(reg, 3, PORT8SEL);
265 1.5.8.2 nathanw #endif /* TX391X */
266 1.5.8.2 nathanw #ifdef TX392X
267 1.5.8.2 nathanw ISSETPRINT(reg, 3, CARD2_8SEL);
268 1.5.8.2 nathanw ISSETPRINT(reg, 3, CARD1_8SEL);
269 1.5.8.2 nathanw #endif /* TX392X */
270 1.5.8.2 nathanw
271 1.5.8.2 nathanw printf("\n");
272 1.5.8.2 nathanw
273 1.5.8.2 nathanw /*
274 1.5.8.2 nathanw * Memory config 4 register
275 1.5.8.2 nathanw */
276 1.5.8.2 nathanw reg = tx_conf_read(tc, TX39_MEMCONFIG4_REG);
277 1.5.8.2 nathanw printf(" config4:");
278 1.5.8.2 nathanw ISSETPRINT(reg, 4, ENBANK1HDRAM);
279 1.5.8.2 nathanw ISSETPRINT(reg, 4, ENBANK0HDRAM);
280 1.5.8.2 nathanw ISSETPRINT(reg, 4, ENARB);
281 1.5.8.2 nathanw ISSETPRINT(reg, 4, DISSNOOP);
282 1.5.8.2 nathanw ISSETPRINT(reg, 4, CLRWRBUSERRINT);
283 1.5.8.2 nathanw ISSETPRINT(reg, 4, ENBANK1OPT);
284 1.5.8.2 nathanw ISSETPRINT(reg, 4, ENBANK0OPT);
285 1.5.8.2 nathanw ISSETPRINT(reg, 4, ENWATCH);
286 1.5.8.2 nathanw ISSETPRINT(reg, 4, MEMPOWERDOWN);
287 1.5.8.2 nathanw ISSETPRINT(reg, 4, ENRFSH1);
288 1.5.8.2 nathanw ISSETPRINT(reg, 4, ENRFSH0);
289 1.5.8.2 nathanw if (reg & TX39_MEMCONFIG4_ENWATCH) {
290 1.5.8.2 nathanw i = TX39_MEMCONFIG4_WATCHTIMEVAL(reg);
291 1.5.8.2 nathanw i = (1000 * (i + 1) * 64) / 36864;
292 1.5.8.2 nathanw printf("WatchDogTimerRate: %dus", i);
293 1.5.8.2 nathanw }
294 1.5.8.2 nathanw printf("\n");
295 1.5.8.2 nathanw }
296 1.5.8.2 nathanw #endif /* TX39BIU_DEBUG */
297