tx39.c revision 1.19 1 1.19 cgd /* $NetBSD: tx39.c,v 1.19 2000/07/27 17:29:05 cgd Exp $ */
2 1.1 uch
3 1.17 uch /*-
4 1.17 uch * Copyright (c) 1999, 2000 UCHIYAMA Yasushi. All rights reserved.
5 1.1 uch *
6 1.1 uch * Redistribution and use in source and binary forms, with or without
7 1.1 uch * modification, are permitted provided that the following conditions
8 1.1 uch * are met:
9 1.1 uch * 1. Redistributions of source code must retain the above copyright
10 1.1 uch * notice, this list of conditions and the following disclaimer.
11 1.16 uch * 2. Redistributions in binary form must reproduce the above copyright
12 1.16 uch * notice, this list of conditions and the following disclaimer in the
13 1.16 uch * documentation and/or other materials provided with the distribution.
14 1.17 uch * 3. The name of the author may not be used to endorse or promote products
15 1.17 uch * derived from this software without specific prior written permission.
16 1.1 uch *
17 1.16 uch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.16 uch * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.16 uch * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.16 uch * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.16 uch * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.16 uch * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.16 uch * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.16 uch * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.17 uch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 1.17 uch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 uch */
28 1.1 uch
29 1.1 uch #include "opt_tx39_debug.h"
30 1.5 uch #include "m38813c.h"
31 1.6 uch #include "tc5165buf.h"
32 1.1 uch
33 1.1 uch #include <sys/param.h>
34 1.1 uch #include <sys/systm.h>
35 1.1 uch #include <sys/device.h>
36 1.14 shin #include <sys/kcore.h>
37 1.1 uch
38 1.1 uch #include <machine/locore.h> /* cpu_id */
39 1.1 uch #include <machine/bootinfo.h> /* bootinfo */
40 1.1 uch #include <machine/sysconf.h> /* platform */
41 1.1 uch
42 1.6 uch #include <machine/platid.h>
43 1.6 uch #include <machine/platid_mask.h>
44 1.6 uch
45 1.1 uch #include <machine/bus.h>
46 1.1 uch #include <machine/intr.h>
47 1.1 uch
48 1.13 sato #include <hpcmips/hpcmips/machdep.h> /* cpu_name */
49 1.1 uch
50 1.1 uch #include <hpcmips/tx/tx39biureg.h>
51 1.1 uch #include <hpcmips/tx/tx39reg.h>
52 1.1 uch #include <hpcmips/tx/tx39var.h>
53 1.1 uch #ifdef TX391X
54 1.1 uch #include <hpcmips/tx/tx3912videovar.h>
55 1.1 uch #endif
56 1.1 uch
57 1.1 uch #include <sys/termios.h>
58 1.1 uch #include <sys/ttydefaults.h>
59 1.1 uch #include <hpcmips/tx/tx39uartvar.h>
60 1.1 uch #ifndef CONSPEED
61 1.1 uch #define CONSPEED TTYDEF_SPEED
62 1.1 uch #endif
63 1.1 uch
64 1.5 uch /* console keyboard */
65 1.5 uch #if NM38813C > 0
66 1.5 uch #include <hpcmips/dev/m38813cvar.h>
67 1.1 uch #endif
68 1.6 uch #if NTC5165BUF > 0
69 1.6 uch #include <hpcmips/dev/tc5165bufvar.h>
70 1.6 uch #endif
71 1.1 uch
72 1.1 uch extern unsigned nullclkread __P((void));
73 1.1 uch extern unsigned (*clkread) __P((void));
74 1.1 uch
75 1.1 uch struct tx_chipset_tag tx_chipset;
76 1.1 uch
77 1.1 uch #ifdef TX39_DEBUG
78 1.1 uch u_int32_t tx39debugflag;
79 1.1 uch #endif
80 1.1 uch
81 1.1 uch void tx_init __P((void));
82 1.1 uch int tx39icu_intr __P((u_int32_t, u_int32_t, u_int32_t, u_int32_t));
83 1.8 uch void tx39clock_cpuspeed __P((int*, int*));
84 1.1 uch
85 1.1 uch /* TX39-specific initialization vector */
86 1.1 uch void tx_os_init __P((void));
87 1.1 uch void tx_bus_reset __P((void));
88 1.1 uch void tx_cons_init __P((void));
89 1.1 uch void tx_device_register __P((struct device *, void *));
90 1.1 uch void tx_fb_init __P((caddr_t*));
91 1.14 shin void tx_mem_init __P((paddr_t));
92 1.14 shin void tx_find_dram __P((paddr_t, paddr_t));
93 1.2 takemura void tx_reboot __P((int howto, char *bootstr));
94 1.5 uch int tx_intr __P((u_int32_t mask, u_int32_t pc, u_int32_t statusReg,
95 1.5 uch u_int32_t causeReg));
96 1.1 uch
97 1.14 shin extern phys_ram_seg_t mem_clusters[];
98 1.14 shin extern int mem_cluster_cnt;
99 1.14 shin
100 1.1 uch void
101 1.1 uch tx_init()
102 1.1 uch {
103 1.1 uch tx_chipset_tag_t tc;
104 1.1 uch int model, rev;
105 1.8 uch int cpuclock;
106 1.1 uch
107 1.1 uch tc = tx_conf_get_tag();
108 1.1 uch /*
109 1.1 uch * Platform Specific Function Hooks
110 1.1 uch */
111 1.1 uch platform.os_init = tx_os_init;
112 1.1 uch platform.bus_reset = tx_bus_reset;
113 1.1 uch platform.cons_init = tx_cons_init;
114 1.1 uch platform.device_register = tx_device_register;
115 1.1 uch platform.fb_init = tx_fb_init;
116 1.1 uch platform.mem_init = tx_mem_init;
117 1.2 takemura platform.reboot = tx_reboot;
118 1.15 uch platform.iointr = tx39icu_intr;
119 1.1 uch
120 1.19 cgd model = MIPS_PRID_REV(cpu_id);
121 1.1 uch
122 1.1 uch switch (model) {
123 1.1 uch default:
124 1.1 uch /* Unknown TOSHIBA TX39-series */
125 1.19 cgd sprintf(cpu_name, "Unknown TOSHIBA TX39-series %x", model);
126 1.1 uch break;
127 1.1 uch case TMPR3912:
128 1.8 uch tx39clock_cpuspeed(&cpuclock, &cpuspeed);
129 1.8 uch
130 1.13 sato sprintf(cpu_name, "TOSHIBA TMPR3912 %d.%02d MHz",
131 1.8 uch cpuclock / 1000000, (cpuclock % 1000000) / 10000);
132 1.1 uch break;
133 1.1 uch case TMPR3922:
134 1.8 uch tx39clock_cpuspeed(&cpuclock, &cpuspeed);
135 1.1 uch rev = tx_conf_read(tc, TX3922_REVISION_REG);
136 1.8 uch
137 1.13 sato sprintf(cpu_name, "TOSHIBA TMPR3922 rev. %x.%x "
138 1.8 uch "%d.%02d MHz", (rev >> 4) & 0xf, rev & 0xf,
139 1.8 uch cpuclock / 1000000, (cpuclock % 1000000) / 10000);
140 1.1 uch break;
141 1.1 uch }
142 1.1 uch }
143 1.1 uch
144 1.1 uch void
145 1.1 uch tx_os_init()
146 1.1 uch {
147 1.1 uch /*
148 1.1 uch * Set up interrupt handling and I/O addresses.
149 1.1 uch */
150 1.1 uch
151 1.1 uch splvec.splbio = MIPS_SPL_2_4;
152 1.1 uch splvec.splnet = MIPS_SPL_2_4;
153 1.1 uch splvec.spltty = MIPS_SPL_2_4;
154 1.1 uch splvec.splimp = MIPS_SPL_2_4;
155 1.1 uch splvec.splclock = MIPS_SPL_2_4;
156 1.1 uch splvec.splstatclock = MIPS_SPL_2_4;
157 1.1 uch
158 1.1 uch /* no high resolution timer circuit; possibly never called */
159 1.1 uch clkread = nullclkread;
160 1.1 uch }
161 1.1 uch
162 1.1 uch void
163 1.1 uch tx_fb_init(kernend)
164 1.1 uch caddr_t *kernend;
165 1.1 uch {
166 1.1 uch #ifdef TX391X
167 1.16 uch paddr_t fb_end;
168 1.1 uch
169 1.16 uch fb_end = MIPS_KSEG0_TO_PHYS(mem_clusters[0].start +
170 1.16 uch mem_clusters[0].size - 1);
171 1.16 uch tx3912video_init(MIPS_KSEG0_TO_PHYS(*kernend), &fb_end);
172 1.16 uch
173 1.1 uch /* Skip V-RAM area */
174 1.16 uch *kernend = (caddr_t)MIPS_PHYS_TO_KSEG0(fb_end);
175 1.1 uch #endif /* TX391X */
176 1.1 uch #ifdef TX392X
177 1.1 uch /*
178 1.1 uch * Plum V-RAM isn't accessible until pmap_bootstrap,
179 1.7 uch * at this time, frame buffer device is disabled.
180 1.1 uch */
181 1.1 uch bootinfo->fb_addr = 0;
182 1.1 uch #endif /* TX392X */
183 1.1 uch }
184 1.1 uch
185 1.14 shin void
186 1.1 uch tx_mem_init(kernend)
187 1.14 shin paddr_t kernend;
188 1.1 uch {
189 1.14 shin mem_clusters[0].start = 0;
190 1.14 shin mem_clusters[0].size = kernend;
191 1.14 shin mem_cluster_cnt = 1;
192 1.14 shin /* search DRAM bank 0 */
193 1.14 shin tx_find_dram(kernend, 0x02000000);
194 1.1 uch
195 1.14 shin /* search DRAM bank 1 */
196 1.14 shin tx_find_dram(0x02000000, 0x04000000);
197 1.5 uch /*
198 1.5 uch * Clear currently unused D-RAM area
199 1.5 uch * (For reboot Windows CE clearly)
200 1.5 uch */
201 1.14 shin memset((void *)(KERNBASE + 0x400), 0, KERNTEXTOFF -
202 1.14 shin (KERNBASE + 0x800));
203 1.2 takemura }
204 1.2 takemura
205 1.2 takemura void
206 1.14 shin tx_find_dram(start, end)
207 1.14 shin paddr_t start, end;
208 1.2 takemura {
209 1.14 shin caddr_t page, startaddr, endaddr;
210 1.14 shin
211 1.14 shin startaddr = (void*)MIPS_PHYS_TO_KSEG1(start);
212 1.14 shin endaddr = (void*)MIPS_PHYS_TO_KSEG1(end);
213 1.1 uch
214 1.1 uch #define DRAM_MAGIC0 0xac1dcafe
215 1.1 uch #define DRAM_MAGIC1 0x19700220
216 1.1 uch
217 1.1 uch page = startaddr;
218 1.14 shin if (badaddr(page, 4))
219 1.14 shin return;
220 1.14 shin
221 1.17 uch *(volatile int *)(page + 0) = DRAM_MAGIC0;
222 1.17 uch *(volatile int *)(page + 4) = DRAM_MAGIC1;
223 1.14 shin wbflush();
224 1.14 shin
225 1.17 uch if (*(volatile int *)(page + 0) != DRAM_MAGIC0 ||
226 1.17 uch *(volatile int *)(page + 4) != DRAM_MAGIC1)
227 1.14 shin return;
228 1.14 shin
229 1.14 shin for (page += NBPG; page < endaddr; page += NBPG) {
230 1.14 shin if (badaddr(page, 4))
231 1.14 shin return;
232 1.14 shin
233 1.17 uch if (*(volatile int *)(page + 0) == DRAM_MAGIC0 &&
234 1.17 uch *(volatile int *)(page + 4) == DRAM_MAGIC1) {
235 1.17 uch goto memend_found;
236 1.1 uch }
237 1.1 uch }
238 1.14 shin
239 1.17 uch /* check for 32MByte memory */
240 1.17 uch page -= NBPG;
241 1.17 uch *(volatile int *)(page + 0) = DRAM_MAGIC0;
242 1.17 uch *(volatile int *)(page + 4) = DRAM_MAGIC1;
243 1.17 uch wbflush();
244 1.17 uch
245 1.17 uch if (*(volatile int *)(page + 0) != DRAM_MAGIC0 ||
246 1.17 uch *(volatile int *)(page + 4) != DRAM_MAGIC1)
247 1.17 uch return; /* no memory in this bank */
248 1.17 uch
249 1.17 uch memend_found:
250 1.17 uch mem_clusters[mem_cluster_cnt].start = start;
251 1.17 uch mem_clusters[mem_cluster_cnt].size = page - startaddr;
252 1.17 uch
253 1.17 uch /* skip kernel area */
254 1.17 uch if (mem_cluster_cnt == 1)
255 1.17 uch mem_clusters[mem_cluster_cnt].size -= start;
256 1.17 uch
257 1.17 uch mem_cluster_cnt++;
258 1.14 shin }
259 1.14 shin
260 1.14 shin void
261 1.14 shin tx_reboot(howto, bootstr)
262 1.14 shin int howto;
263 1.14 shin char *bootstr;
264 1.14 shin {
265 1.14 shin goto *(u_int32_t *)MIPS_RESET_EXC_VEC;
266 1.1 uch }
267 1.1 uch
268 1.1 uch void
269 1.1 uch tx_bus_reset()
270 1.1 uch {
271 1.1 uch /* hpcmips port don't use */
272 1.1 uch }
273 1.1 uch
274 1.1 uch void
275 1.1 uch tx_cons_init()
276 1.1 uch {
277 1.1 uch int slot;
278 1.6 uch #define CONSPLATIDMATCH(p) \
279 1.6 uch platid_match(&platid, &platid_mask_MACH_##p)
280 1.1 uch
281 1.1 uch #ifdef SERIALCONSSLOT
282 1.1 uch slot = SERIALCONSSLOT;
283 1.1 uch #else
284 1.1 uch slot = TX39_UARTA;
285 1.1 uch #endif
286 1.1 uch if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
287 1.1 uch if(txcom_cnattach(slot, CONSPEED,
288 1.5 uch (TTYDEF_CFLAG & ~(CSIZE | PARENB)) |
289 1.5 uch CS8)) {
290 1.1 uch panic("tx_cons_init: can't attach serial console.");
291 1.1 uch }
292 1.5 uch } else {
293 1.6 uch #if NM38813C > 0
294 1.6 uch if(CONSPLATIDMATCH(VICTOR_INTERLINK) &&
295 1.6 uch m38813c_cnattach(TX39_SYSADDR_CARD1)) {
296 1.10 uch goto panic;
297 1.6 uch }
298 1.6 uch #endif
299 1.6 uch #if NTC5165BUF > 0
300 1.10 uch if(CONSPLATIDMATCH(COMPAQ_C) &&
301 1.10 uch tc5165buf_cnattach(TX39_SYSADDR_CS3)) {
302 1.10 uch goto panic;
303 1.10 uch }
304 1.10 uch
305 1.6 uch if(CONSPLATIDMATCH(SHARP_TELIOS) &&
306 1.6 uch tc5165buf_cnattach(TX39_SYSADDR_CS1)) {
307 1.10 uch goto panic;
308 1.10 uch }
309 1.10 uch
310 1.10 uch if(CONSPLATIDMATCH(SHARP_MOBILON) &&
311 1.10 uch tc5165buf_cnattach(TX39_SYSADDR_MCS0)) {
312 1.10 uch goto panic;
313 1.5 uch }
314 1.5 uch #endif
315 1.1 uch }
316 1.10 uch
317 1.10 uch return;
318 1.10 uch panic:
319 1.10 uch panic("tx_cons_init: can't init console");
320 1.10 uch /* NOTREACHED */
321 1.1 uch }
322 1.1 uch
323 1.1 uch void
324 1.1 uch tx_device_register(dev, aux)
325 1.1 uch struct device *dev;
326 1.1 uch void *aux;
327 1.1 uch {
328 1.1 uch /* hpcmips port don't use */
329 1.1 uch }
330 1.1 uch
331 1.1 uch void
332 1.1 uch tx_conf_register_intr(t, intrt)
333 1.1 uch tx_chipset_tag_t t;
334 1.1 uch void *intrt;
335 1.1 uch {
336 1.1 uch if (tx_chipset.tc_intrt) {
337 1.1 uch panic("duplicate intrt");
338 1.1 uch }
339 1.1 uch
340 1.1 uch if (t != &tx_chipset) {
341 1.1 uch panic("bogus tx_chipset_tag");
342 1.1 uch }
343 1.1 uch
344 1.1 uch tx_chipset.tc_intrt = intrt;
345 1.1 uch }
346 1.1 uch
347 1.9 uch void
348 1.9 uch tx_conf_register_power(t, powert)
349 1.9 uch tx_chipset_tag_t t;
350 1.9 uch void *powert;
351 1.9 uch {
352 1.9 uch if (tx_chipset.tc_powert) {
353 1.9 uch panic("duplicate powert");
354 1.9 uch }
355 1.9 uch
356 1.9 uch if (t != &tx_chipset) {
357 1.9 uch panic("bogus tx_chipset_tag");
358 1.9 uch }
359 1.9 uch
360 1.9 uch tx_chipset.tc_powert = powert;
361 1.9 uch }
362 1.9 uch
363 1.9 uch void
364 1.9 uch tx_conf_register_clock(t, clockt)
365 1.9 uch tx_chipset_tag_t t;
366 1.9 uch void *clockt;
367 1.9 uch {
368 1.9 uch if (tx_chipset.tc_clockt) {
369 1.9 uch panic("duplicate clockt");
370 1.9 uch }
371 1.9 uch
372 1.9 uch if (t != &tx_chipset) {
373 1.9 uch panic("bogus tx_chipset_tag");
374 1.9 uch }
375 1.9 uch
376 1.9 uch tx_chipset.tc_clockt = clockt;
377 1.11 uch }
378 1.11 uch
379 1.11 uch void
380 1.11 uch tx_conf_register_sound(t, soundt)
381 1.11 uch tx_chipset_tag_t t;
382 1.11 uch void *soundt;
383 1.11 uch {
384 1.11 uch if (t != &tx_chipset) {
385 1.11 uch panic("bogus tx_chipset_tag");
386 1.11 uch }
387 1.11 uch
388 1.11 uch tx_chipset.tc_soundt = soundt;
389 1.12 uch }
390 1.12 uch
391 1.12 uch void
392 1.12 uch tx_conf_register_ioman(t, iomant)
393 1.12 uch tx_chipset_tag_t t;
394 1.12 uch void *iomant;
395 1.12 uch {
396 1.12 uch if (tx_chipset.tc_iomant) {
397 1.12 uch panic("duplicate iomant");
398 1.12 uch }
399 1.12 uch
400 1.12 uch if (t != &tx_chipset) {
401 1.12 uch panic("bogus tx_chipset_tag");
402 1.12 uch }
403 1.12 uch
404 1.12 uch tx_chipset.tc_iomant = iomant;
405 1.18 uch }
406 1.18 uch
407 1.18 uch void
408 1.18 uch tx_conf_register_video(t, videot)
409 1.18 uch tx_chipset_tag_t t;
410 1.18 uch void *videot;
411 1.18 uch {
412 1.18 uch if (t != &tx_chipset) {
413 1.18 uch panic("bogus tx_chipset_tag");
414 1.18 uch }
415 1.18 uch
416 1.18 uch tx_chipset.tc_videot = videot;
417 1.9 uch }
418 1.9 uch
419 1.1 uch #ifdef TX39_PREFER_FUNCTION
420 1.1 uch tx_chipset_tag_t
421 1.1 uch tx_conf_get_tag()
422 1.1 uch {
423 1.1 uch return (tx_chipset_tag_t)&tx_chipset;
424 1.1 uch }
425 1.1 uch
426 1.1 uch txreg_t
427 1.1 uch tx_conf_read(t, reg)
428 1.1 uch tx_chipset_tag_t t;
429 1.1 uch int reg;
430 1.1 uch {
431 1.8 uch return *((volatile txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg));
432 1.1 uch }
433 1.1 uch
434 1.1 uch void
435 1.1 uch tx_conf_write(t, reg, val)
436 1.1 uch tx_chipset_tag_t t;
437 1.1 uch int reg;
438 1.1 uch txreg_t val;
439 1.1 uch {
440 1.8 uch *((volatile txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg)) = val;
441 1.1 uch }
442 1.1 uch #endif /* TX39_PREFER_FUNCTION */
443 1.1 uch
444 1.1 uch int
445 1.1 uch __is_set_print(reg, mask, name)
446 1.1 uch u_int32_t reg;
447 1.1 uch int mask;
448 1.1 uch char *name;
449 1.1 uch {
450 1.9 uch const char onoff[2] = "_x";
451 1.9 uch int ret = reg & mask ? 1 : 0;
452 1.9 uch
453 1.9 uch printf("%s[%c] ", name, onoff[ret]);
454 1.9 uch
455 1.9 uch return ret;
456 1.1 uch }
457