tx39.c revision 1.4 1 1.4 uch /* $NetBSD: tx39.c,v 1.4 1999/12/02 18:50:54 uch Exp $ */
2 1.1 uch
3 1.1 uch /*
4 1.1 uch * Copyright (c) 1999, by UCHIYAMA Yasushi
5 1.1 uch * All rights reserved.
6 1.1 uch *
7 1.1 uch * Redistribution and use in source and binary forms, with or without
8 1.1 uch * modification, are permitted provided that the following conditions
9 1.1 uch * are met:
10 1.1 uch * 1. Redistributions of source code must retain the above copyright
11 1.1 uch * notice, this list of conditions and the following disclaimer.
12 1.1 uch * 2. The name of the developer may NOT be used to endorse or promote products
13 1.1 uch * derived from this software without specific prior written permission.
14 1.1 uch *
15 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 1.1 uch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 1.1 uch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 1.1 uch * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.1 uch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.1 uch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 1.1 uch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 uch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.1 uch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.1 uch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.1 uch * SUCH DAMAGE.
26 1.1 uch *
27 1.1 uch */
28 1.1 uch
29 1.1 uch #include "opt_tx39_debug.h"
30 1.1 uch #include "cckbd.h"
31 1.1 uch
32 1.1 uch #include <sys/param.h>
33 1.1 uch #include <sys/systm.h>
34 1.1 uch #include <sys/device.h>
35 1.1 uch
36 1.1 uch #include <machine/locore.h> /* cpu_id */
37 1.1 uch #include <machine/bootinfo.h> /* bootinfo */
38 1.1 uch #include <machine/sysconf.h> /* platform */
39 1.1 uch
40 1.1 uch #include <machine/bus.h>
41 1.1 uch #include <machine/intr.h>
42 1.1 uch
43 1.1 uch #include <hpcmips/hpcmips/machdep.h> /* cpu_model */
44 1.1 uch #include <hpcmips/dev/biconsvar.h>
45 1.1 uch #include <hpcmips/dev/bicons.h>
46 1.1 uch
47 1.1 uch #include <hpcmips/tx/tx39biureg.h>
48 1.1 uch #include <hpcmips/tx/tx39reg.h>
49 1.1 uch #include <hpcmips/tx/tx39var.h>
50 1.1 uch #ifdef TX391X
51 1.1 uch #include <hpcmips/tx/tx3912videovar.h>
52 1.1 uch #endif
53 1.1 uch
54 1.1 uch #include <sys/termios.h>
55 1.1 uch #include <sys/ttydefaults.h>
56 1.1 uch #include <hpcmips/tx/tx39uartvar.h>
57 1.1 uch #ifndef CONSPEED
58 1.1 uch #define CONSPEED TTYDEF_SPEED
59 1.1 uch #endif
60 1.1 uch
61 1.1 uch #if NCCKBD > 0
62 1.1 uch #include <hpcmips/dev/cckbdvar.h>
63 1.1 uch #endif
64 1.1 uch
65 1.1 uch extern unsigned nullclkread __P((void));
66 1.1 uch extern unsigned (*clkread) __P((void));
67 1.1 uch
68 1.1 uch struct tx_chipset_tag tx_chipset;
69 1.1 uch
70 1.1 uch #ifdef TX39_DEBUG
71 1.1 uch u_int32_t tx39debugflag;
72 1.1 uch #endif
73 1.1 uch
74 1.1 uch void tx_init __P((void));
75 1.1 uch int tx39icu_intr __P((u_int32_t, u_int32_t, u_int32_t, u_int32_t));
76 1.1 uch int tx39_find_dram __P((u_int32_t, u_int32_t));
77 1.1 uch
78 1.1 uch /* TX39-specific initialization vector */
79 1.1 uch void tx_os_init __P((void));
80 1.1 uch void tx_bus_reset __P((void));
81 1.1 uch void tx_cons_init __P((void));
82 1.1 uch void tx_device_register __P((struct device *, void *));
83 1.1 uch void tx_fb_init __P((caddr_t*));
84 1.1 uch int tx_mem_init __P((caddr_t));
85 1.2 takemura void tx_reboot __P((int howto, char *bootstr));
86 1.1 uch int tx_intr __P((u_int32_t mask, u_int32_t pc, u_int32_t statusReg, u_int32_t causeReg));
87 1.1 uch
88 1.1 uch void
89 1.1 uch tx_init()
90 1.1 uch {
91 1.1 uch tx_chipset_tag_t tc;
92 1.1 uch int model, rev;
93 1.1 uch
94 1.1 uch tc = tx_conf_get_tag();
95 1.1 uch /*
96 1.1 uch * Platform Specific Function Hooks
97 1.1 uch */
98 1.1 uch platform.os_init = tx_os_init;
99 1.1 uch platform.bus_reset = tx_bus_reset;
100 1.1 uch platform.cons_init = tx_cons_init;
101 1.1 uch platform.device_register = tx_device_register;
102 1.1 uch platform.fb_init = tx_fb_init;
103 1.1 uch platform.mem_init = tx_mem_init;
104 1.2 takemura platform.reboot = tx_reboot;
105 1.1 uch
106 1.1 uch model = (cpu_id.cpu.cp_majrev << 4)| cpu_id.cpu.cp_minrev;
107 1.1 uch
108 1.1 uch switch (model) {
109 1.1 uch default:
110 1.1 uch /* Unknown TOSHIBA TX39-series */
111 1.1 uch sprintf(cpu_model, "Unknown TOSHIBA TX39-series %x.%x",
112 1.1 uch cpu_id.cpu.cp_majrev, cpu_id.cpu.cp_minrev);
113 1.1 uch break;
114 1.1 uch case TMPR3912:
115 1.1 uch sprintf(cpu_model, "TOSHIBA TMPR3912");
116 1.1 uch cpuspeed = 50; /* XXX Should calibrate XXX */
117 1.1 uch break;
118 1.1 uch case TMPR3922:
119 1.1 uch rev = tx_conf_read(tc, TX3922_REVISION_REG);
120 1.1 uch sprintf(cpu_model, "TOSHIBA TMPR3922 rev. %x.%x",
121 1.1 uch (rev >> 4) & 0xf, rev & 0xf);
122 1.1 uch cpuspeed = 100; /* XXX Should calibrate XXX */
123 1.1 uch break;
124 1.1 uch }
125 1.1 uch }
126 1.1 uch
127 1.1 uch void
128 1.1 uch tx_os_init()
129 1.1 uch {
130 1.1 uch /*
131 1.1 uch * Set up interrupt handling and I/O addresses.
132 1.1 uch */
133 1.1 uch mips_hardware_intr = tx39icu_intr;
134 1.1 uch
135 1.1 uch splvec.splbio = MIPS_SPL_2_4;
136 1.1 uch splvec.splnet = MIPS_SPL_2_4;
137 1.1 uch splvec.spltty = MIPS_SPL_2_4;
138 1.1 uch splvec.splimp = MIPS_SPL_2_4;
139 1.1 uch splvec.splclock = MIPS_SPL_2_4;
140 1.1 uch splvec.splstatclock = MIPS_SPL_2_4;
141 1.1 uch
142 1.1 uch /* no high resolution timer circuit; possibly never called */
143 1.1 uch clkread = nullclkread;
144 1.1 uch }
145 1.1 uch
146 1.1 uch void
147 1.1 uch tx_fb_init(kernend)
148 1.1 uch caddr_t *kernend;
149 1.1 uch {
150 1.1 uch #ifdef TX391X
151 1.1 uch tx_chipset_tag_t tc;
152 1.1 uch u_int32_t fb_start, fb_addr, fb_size, fb_line_bytes;
153 1.1 uch
154 1.1 uch /* Initialize to access TX39 configuration register */
155 1.1 uch tc = tx_conf_get_tag();
156 1.1 uch
157 1.1 uch fb_start = MIPS_KSEG0_TO_PHYS(*kernend);
158 1.1 uch tx3912video_init(tc, fb_start, bootinfo->fb_width,
159 1.1 uch bootinfo->fb_height, &fb_addr, &fb_size,
160 1.1 uch &fb_line_bytes);
161 1.1 uch
162 1.1 uch /* Set bootinfo for bicons */
163 1.1 uch bootinfo->fb_line_bytes = fb_line_bytes;
164 1.1 uch bootinfo->fb_addr = (unsigned char*)MIPS_PHYS_TO_KSEG1(fb_addr);
165 1.1 uch
166 1.1 uch /* Skip V-RAM area */
167 1.1 uch *kernend += fb_size;
168 1.1 uch #endif /* TX391X */
169 1.1 uch #ifdef TX392X
170 1.1 uch /*
171 1.1 uch * Plum V-RAM isn't accessible until pmap_bootstrap,
172 1.1 uch * at this time, bicons is disabled.
173 1.1 uch */
174 1.1 uch bootinfo->fb_addr = 0;
175 1.1 uch #endif /* TX392X */
176 1.1 uch }
177 1.1 uch
178 1.1 uch int
179 1.1 uch tx_mem_init(kernend)
180 1.1 uch caddr_t kernend; /* kseg0 */
181 1.1 uch {
182 1.1 uch u_int32_t startaddr, endaddr;
183 1.1 uch int npage, xpage, kpage;
184 1.1 uch
185 1.1 uch startaddr = MIPS_PHYS_TO_KSEG1(
186 1.1 uch (btoc((u_int32_t)kernend - MIPS_KSEG0_START)) << PGSHIFT);
187 1.1 uch endaddr = MIPS_PHYS_TO_KSEG1(TX39_SYSADDR_DRAMBANK0CS1 +
188 1.1 uch TX39_SYSADDR_DRAMBANK_LEN);
189 1.1 uch kpage = btoc(MIPS_KSEG1_TO_PHYS(startaddr));
190 1.1 uch /* D-RAM bank0 */
191 1.1 uch npage = tx39_find_dram(startaddr, endaddr);
192 1.1 uch
193 1.1 uch printf("DRAM bank0: %d pages (%dMByte) reserved %d pages\n", npage + 1,
194 1.1 uch ((npage + 1) * NBPG) / 0x100000, kpage + 1);
195 1.1 uch npage -= kpage; /* exclude kernel area */
196 1.1 uch /* Clear DRAM area */
197 1.1 uch memset((void*)startaddr, 0, npage * NBPG);
198 1.1 uch
199 1.1 uch /* D-RAM bank1 XXX find only. not usable yet */
200 1.1 uch startaddr = MIPS_PHYS_TO_KSEG1(TX39_SYSADDR_DRAMBANK1CS1);
201 1.1 uch endaddr = MIPS_PHYS_TO_KSEG1(TX39_SYSADDR_DRAMBANK1CS1 +
202 1.1 uch TX39_SYSADDR_DRAMBANK_LEN);
203 1.1 uch xpage = tx39_find_dram(startaddr, endaddr);
204 1.1 uch printf("DRAM bank1: %d pages (%dMByte) ...but not usable yet\n",
205 1.1 uch xpage + 1, ((xpage + 1) * NBPG) / 0x100000);
206 1.1 uch
207 1.1 uch /* Clear currently unused D-RAM area (For reboot Windows CE clearly)*/
208 1.1 uch memset((void*)startaddr, 0, npage * NBPG);
209 1.1 uch memset((void*)(KERNBASE + 0x400), 0, KERNTEXTOFF - KERNBASE - 0x800);
210 1.1 uch
211 1.1 uch return npage; /* Return bank0's memory only */
212 1.2 takemura }
213 1.2 takemura
214 1.2 takemura void
215 1.2 takemura tx_reboot(howto, bootstr)
216 1.2 takemura int howto;
217 1.2 takemura char *bootstr;
218 1.2 takemura {
219 1.2 takemura goto *(u_int32_t *)MIPS_RESET_EXC_VEC;
220 1.1 uch }
221 1.1 uch
222 1.1 uch int
223 1.1 uch tx39_find_dram(startaddr, endaddr)
224 1.1 uch u_int32_t startaddr; /* kseg1 */
225 1.1 uch u_int32_t endaddr; /* kseg1 */
226 1.1 uch {
227 1.1 uch #define DRAM_MAGIC0 0xac1dcafe
228 1.1 uch #define DRAM_MAGIC1 0x19700220
229 1.1 uch u_int32_t page;
230 1.1 uch int npage;
231 1.1 uch
232 1.1 uch page = startaddr;
233 1.1 uch ((volatile int *)page)[0] = DRAM_MAGIC0;
234 1.1 uch ((volatile int *)page)[4] = DRAM_MAGIC1;
235 1.1 uch page += NBPG;
236 1.1 uch for (npage = 0; page < endaddr; page += NBPG, npage++) {
237 1.1 uch if ((((volatile int *)page)[0] == DRAM_MAGIC0 &&
238 1.1 uch ((volatile int *)page)[4] == DRAM_MAGIC1)) {
239 1.1 uch return npage;
240 1.1 uch }
241 1.1 uch }
242 1.1 uch /* no memory in this bank */
243 1.1 uch return 0;
244 1.1 uch }
245 1.1 uch
246 1.1 uch void
247 1.1 uch tx_bus_reset()
248 1.1 uch {
249 1.1 uch /* hpcmips port don't use */
250 1.1 uch }
251 1.1 uch
252 1.1 uch void
253 1.1 uch tx_cons_init()
254 1.1 uch {
255 1.1 uch int slot;
256 1.1 uch
257 1.1 uch #ifdef SERIALCONSSLOT
258 1.1 uch slot = SERIALCONSSLOT;
259 1.1 uch #else
260 1.1 uch slot = TX39_UARTA;
261 1.1 uch #endif
262 1.1 uch if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
263 1.1 uch if(txcom_cnattach(slot, CONSPEED,
264 1.1 uch (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) {
265 1.1 uch panic("tx_cons_init: can't attach serial console.");
266 1.1 uch }
267 1.1 uch }
268 1.1 uch #if NCCKBD > 0
269 1.1 uch if(cckbd_cnattach(0, 0)) {
270 1.1 uch panic("tx_cons_init: can't init cckbd as console");
271 1.1 uch }
272 1.1 uch #endif
273 1.1 uch
274 1.1 uch }
275 1.1 uch
276 1.1 uch void
277 1.1 uch tx_device_register(dev, aux)
278 1.1 uch struct device *dev;
279 1.1 uch void *aux;
280 1.1 uch {
281 1.1 uch /* hpcmips port don't use */
282 1.1 uch }
283 1.1 uch
284 1.1 uch void
285 1.1 uch tx_conf_register_intr(t, intrt)
286 1.1 uch tx_chipset_tag_t t;
287 1.1 uch void *intrt;
288 1.1 uch {
289 1.1 uch if (tx_chipset.tc_intrt) {
290 1.1 uch panic("duplicate intrt");
291 1.1 uch }
292 1.1 uch
293 1.1 uch if (t != &tx_chipset) {
294 1.1 uch panic("bogus tx_chipset_tag");
295 1.1 uch }
296 1.1 uch
297 1.1 uch tx_chipset.tc_intrt = intrt;
298 1.1 uch }
299 1.1 uch
300 1.1 uch #ifdef TX39_PREFER_FUNCTION
301 1.1 uch tx_chipset_tag_t
302 1.1 uch tx_conf_get_tag()
303 1.1 uch {
304 1.1 uch return (tx_chipset_tag_t)&tx_chipset;
305 1.1 uch }
306 1.1 uch
307 1.1 uch txreg_t
308 1.1 uch tx_conf_read(t, reg)
309 1.1 uch tx_chipset_tag_t t;
310 1.1 uch int reg;
311 1.1 uch {
312 1.1 uch return *((txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg));
313 1.1 uch }
314 1.1 uch
315 1.1 uch void
316 1.1 uch tx_conf_write(t, reg, val)
317 1.1 uch tx_chipset_tag_t t;
318 1.1 uch int reg;
319 1.1 uch txreg_t val;
320 1.1 uch {
321 1.1 uch *((txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg)) = val;
322 1.1 uch }
323 1.1 uch #endif /* TX39_PREFER_FUNCTION */
324 1.1 uch
325 1.1 uch int
326 1.1 uch __is_set_print(reg, mask, name)
327 1.1 uch u_int32_t reg;
328 1.1 uch int mask;
329 1.1 uch char *name;
330 1.1 uch {
331 1.1 uch if (reg & mask) {
332 1.1 uch printf("%s ", name);
333 1.1 uch return 1;
334 1.1 uch }
335 1.1 uch return 0;
336 1.1 uch }
337