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