tx39.c revision 1.3 1 1.3 uch /* $NetBSD: tx39.c,v 1.3 1999/11/29 17:21:21 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 "fb.h"
31 1.1 uch #include "cckbd.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.1 uch
37 1.1 uch #include <machine/locore.h> /* cpu_id */
38 1.1 uch #include <machine/bootinfo.h> /* bootinfo */
39 1.1 uch #include <machine/sysconf.h> /* platform */
40 1.1 uch
41 1.1 uch #include <machine/bus.h>
42 1.1 uch #include <machine/intr.h>
43 1.1 uch
44 1.1 uch #include <hpcmips/hpcmips/machdep.h> /* cpu_model */
45 1.1 uch #include <hpcmips/dev/biconsvar.h>
46 1.1 uch #include <hpcmips/dev/bicons.h>
47 1.1 uch
48 1.1 uch #include <hpcmips/tx/tx39biureg.h>
49 1.1 uch #include <hpcmips/tx/tx39reg.h>
50 1.1 uch #include <hpcmips/tx/tx39var.h>
51 1.1 uch #ifdef TX391X
52 1.1 uch #include <hpcmips/tx/tx3912videovar.h>
53 1.1 uch #endif
54 1.1 uch
55 1.1 uch #include <sys/termios.h>
56 1.1 uch #include <sys/ttydefaults.h>
57 1.1 uch #include <hpcmips/tx/tx39uartvar.h>
58 1.1 uch #ifndef CONSPEED
59 1.1 uch #define CONSPEED TTYDEF_SPEED
60 1.1 uch #endif
61 1.1 uch
62 1.1 uch #if NCCKBD > 0
63 1.1 uch #include <hpcmips/dev/cckbdvar.h>
64 1.1 uch #endif
65 1.1 uch
66 1.1 uch extern unsigned nullclkread __P((void));
67 1.1 uch extern unsigned (*clkread) __P((void));
68 1.1 uch
69 1.1 uch struct tx_chipset_tag tx_chipset;
70 1.1 uch
71 1.1 uch #ifdef TX39_DEBUG
72 1.1 uch u_int32_t tx39debugflag;
73 1.1 uch #endif
74 1.1 uch
75 1.1 uch void tx_init __P((void));
76 1.1 uch int tx39icu_intr __P((u_int32_t, u_int32_t, u_int32_t, u_int32_t));
77 1.1 uch int tx39_find_dram __P((u_int32_t, u_int32_t));
78 1.1 uch
79 1.1 uch /* TX39-specific initialization vector */
80 1.1 uch void tx_os_init __P((void));
81 1.1 uch void tx_bus_reset __P((void));
82 1.1 uch void tx_cons_init __P((void));
83 1.1 uch void tx_device_register __P((struct device *, void *));
84 1.1 uch void tx_fb_init __P((caddr_t*));
85 1.1 uch int tx_mem_init __P((caddr_t));
86 1.2 takemura void tx_reboot __P((int howto, char *bootstr));
87 1.1 uch int tx_intr __P((u_int32_t mask, u_int32_t pc, u_int32_t statusReg, u_int32_t causeReg));
88 1.1 uch
89 1.1 uch void
90 1.1 uch tx_init()
91 1.1 uch {
92 1.1 uch tx_chipset_tag_t tc;
93 1.1 uch int model, rev;
94 1.1 uch
95 1.1 uch tc = tx_conf_get_tag();
96 1.1 uch /*
97 1.1 uch * Platform Specific Function Hooks
98 1.1 uch */
99 1.1 uch platform.os_init = tx_os_init;
100 1.1 uch platform.bus_reset = tx_bus_reset;
101 1.1 uch platform.cons_init = tx_cons_init;
102 1.1 uch platform.device_register = tx_device_register;
103 1.1 uch platform.fb_init = tx_fb_init;
104 1.1 uch platform.mem_init = tx_mem_init;
105 1.2 takemura platform.reboot = tx_reboot;
106 1.1 uch
107 1.1 uch model = (cpu_id.cpu.cp_majrev << 4)| cpu_id.cpu.cp_minrev;
108 1.1 uch
109 1.1 uch switch (model) {
110 1.1 uch default:
111 1.1 uch /* Unknown TOSHIBA TX39-series */
112 1.1 uch sprintf(cpu_model, "Unknown TOSHIBA TX39-series %x.%x",
113 1.1 uch cpu_id.cpu.cp_majrev, cpu_id.cpu.cp_minrev);
114 1.1 uch break;
115 1.1 uch case TMPR3912:
116 1.1 uch sprintf(cpu_model, "TOSHIBA TMPR3912");
117 1.1 uch cpuspeed = 50; /* XXX Should calibrate XXX */
118 1.1 uch break;
119 1.1 uch case TMPR3922:
120 1.1 uch rev = tx_conf_read(tc, TX3922_REVISION_REG);
121 1.1 uch sprintf(cpu_model, "TOSHIBA TMPR3922 rev. %x.%x",
122 1.1 uch (rev >> 4) & 0xf, rev & 0xf);
123 1.1 uch cpuspeed = 100; /* XXX Should calibrate XXX */
124 1.1 uch break;
125 1.1 uch }
126 1.1 uch }
127 1.1 uch
128 1.1 uch void
129 1.1 uch tx_os_init()
130 1.1 uch {
131 1.1 uch /*
132 1.1 uch * Set up interrupt handling and I/O addresses.
133 1.1 uch */
134 1.1 uch mips_hardware_intr = tx39icu_intr;
135 1.1 uch
136 1.1 uch splvec.splbio = MIPS_SPL_2_4;
137 1.1 uch splvec.splnet = MIPS_SPL_2_4;
138 1.1 uch splvec.spltty = MIPS_SPL_2_4;
139 1.1 uch splvec.splimp = MIPS_SPL_2_4;
140 1.1 uch splvec.splclock = MIPS_SPL_2_4;
141 1.1 uch splvec.splstatclock = MIPS_SPL_2_4;
142 1.1 uch
143 1.1 uch /* no high resolution timer circuit; possibly never called */
144 1.1 uch clkread = nullclkread;
145 1.1 uch }
146 1.1 uch
147 1.1 uch void
148 1.1 uch tx_fb_init(kernend)
149 1.1 uch caddr_t *kernend;
150 1.1 uch {
151 1.1 uch #ifdef TX391X
152 1.1 uch tx_chipset_tag_t tc;
153 1.1 uch u_int32_t fb_start, fb_addr, fb_size, fb_line_bytes;
154 1.1 uch
155 1.1 uch /* Initialize to access TX39 configuration register */
156 1.1 uch tc = tx_conf_get_tag();
157 1.1 uch
158 1.1 uch fb_start = MIPS_KSEG0_TO_PHYS(*kernend);
159 1.1 uch tx3912video_init(tc, fb_start, bootinfo->fb_width,
160 1.1 uch bootinfo->fb_height, &fb_addr, &fb_size,
161 1.1 uch &fb_line_bytes);
162 1.1 uch
163 1.1 uch /* Set bootinfo for bicons */
164 1.1 uch bootinfo->fb_line_bytes = fb_line_bytes;
165 1.1 uch bootinfo->fb_addr = (unsigned char*)MIPS_PHYS_TO_KSEG1(fb_addr);
166 1.1 uch
167 1.1 uch /* Skip V-RAM area */
168 1.1 uch *kernend += fb_size;
169 1.1 uch #endif /* TX391X */
170 1.1 uch #ifdef TX392X
171 1.1 uch /*
172 1.1 uch * Plum V-RAM isn't accessible until pmap_bootstrap,
173 1.1 uch * at this time, bicons is disabled.
174 1.1 uch */
175 1.1 uch bootinfo->fb_addr = 0;
176 1.1 uch #endif /* TX392X */
177 1.1 uch }
178 1.1 uch
179 1.1 uch int
180 1.1 uch tx_mem_init(kernend)
181 1.1 uch caddr_t kernend; /* kseg0 */
182 1.1 uch {
183 1.1 uch u_int32_t startaddr, endaddr;
184 1.1 uch int npage, xpage, kpage;
185 1.1 uch
186 1.1 uch startaddr = MIPS_PHYS_TO_KSEG1(
187 1.1 uch (btoc((u_int32_t)kernend - MIPS_KSEG0_START)) << PGSHIFT);
188 1.1 uch endaddr = MIPS_PHYS_TO_KSEG1(TX39_SYSADDR_DRAMBANK0CS1 +
189 1.1 uch TX39_SYSADDR_DRAMBANK_LEN);
190 1.1 uch kpage = btoc(MIPS_KSEG1_TO_PHYS(startaddr));
191 1.1 uch /* D-RAM bank0 */
192 1.1 uch npage = tx39_find_dram(startaddr, endaddr);
193 1.1 uch
194 1.1 uch printf("DRAM bank0: %d pages (%dMByte) reserved %d pages\n", npage + 1,
195 1.1 uch ((npage + 1) * NBPG) / 0x100000, kpage + 1);
196 1.1 uch npage -= kpage; /* exclude kernel area */
197 1.1 uch /* Clear DRAM area */
198 1.1 uch memset((void*)startaddr, 0, npage * NBPG);
199 1.1 uch
200 1.1 uch /* D-RAM bank1 XXX find only. not usable yet */
201 1.1 uch startaddr = MIPS_PHYS_TO_KSEG1(TX39_SYSADDR_DRAMBANK1CS1);
202 1.1 uch endaddr = MIPS_PHYS_TO_KSEG1(TX39_SYSADDR_DRAMBANK1CS1 +
203 1.1 uch TX39_SYSADDR_DRAMBANK_LEN);
204 1.1 uch xpage = tx39_find_dram(startaddr, endaddr);
205 1.1 uch printf("DRAM bank1: %d pages (%dMByte) ...but not usable yet\n",
206 1.1 uch xpage + 1, ((xpage + 1) * NBPG) / 0x100000);
207 1.1 uch
208 1.1 uch /* Clear currently unused D-RAM area (For reboot Windows CE clearly)*/
209 1.1 uch memset((void*)startaddr, 0, npage * NBPG);
210 1.1 uch memset((void*)(KERNBASE + 0x400), 0, KERNTEXTOFF - KERNBASE - 0x800);
211 1.1 uch
212 1.1 uch return npage; /* Return bank0's memory only */
213 1.2 takemura }
214 1.2 takemura
215 1.2 takemura void
216 1.2 takemura tx_reboot(howto, bootstr)
217 1.2 takemura int howto;
218 1.2 takemura char *bootstr;
219 1.2 takemura {
220 1.2 takemura goto *(u_int32_t *)MIPS_RESET_EXC_VEC;
221 1.1 uch }
222 1.1 uch
223 1.1 uch int
224 1.1 uch tx39_find_dram(startaddr, endaddr)
225 1.1 uch u_int32_t startaddr; /* kseg1 */
226 1.1 uch u_int32_t endaddr; /* kseg1 */
227 1.1 uch {
228 1.1 uch #define DRAM_MAGIC0 0xac1dcafe
229 1.1 uch #define DRAM_MAGIC1 0x19700220
230 1.1 uch u_int32_t page;
231 1.1 uch int npage;
232 1.1 uch
233 1.1 uch page = startaddr;
234 1.1 uch ((volatile int *)page)[0] = DRAM_MAGIC0;
235 1.1 uch ((volatile int *)page)[4] = DRAM_MAGIC1;
236 1.1 uch page += NBPG;
237 1.1 uch for (npage = 0; page < endaddr; page += NBPG, npage++) {
238 1.1 uch if ((((volatile int *)page)[0] == DRAM_MAGIC0 &&
239 1.1 uch ((volatile int *)page)[4] == DRAM_MAGIC1)) {
240 1.1 uch return npage;
241 1.1 uch }
242 1.1 uch }
243 1.1 uch /* no memory in this bank */
244 1.1 uch return 0;
245 1.1 uch }
246 1.1 uch
247 1.1 uch void
248 1.1 uch tx_bus_reset()
249 1.1 uch {
250 1.1 uch /* hpcmips port don't use */
251 1.1 uch }
252 1.1 uch
253 1.1 uch void
254 1.1 uch tx_cons_init()
255 1.1 uch {
256 1.1 uch int slot;
257 1.1 uch
258 1.1 uch #ifdef SERIALCONSSLOT
259 1.1 uch slot = SERIALCONSSLOT;
260 1.1 uch #else
261 1.1 uch slot = TX39_UARTA;
262 1.1 uch #endif
263 1.1 uch if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
264 1.1 uch if(txcom_cnattach(slot, CONSPEED,
265 1.1 uch (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) {
266 1.1 uch panic("tx_cons_init: can't attach serial console.");
267 1.1 uch }
268 1.1 uch }
269 1.1 uch #if NCCKBD > 0
270 1.1 uch if(cckbd_cnattach(0, 0)) {
271 1.1 uch panic("tx_cons_init: can't init cckbd as console");
272 1.1 uch }
273 1.1 uch #endif
274 1.1 uch
275 1.1 uch }
276 1.1 uch
277 1.1 uch void
278 1.1 uch tx_device_register(dev, aux)
279 1.1 uch struct device *dev;
280 1.1 uch void *aux;
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_conf_register_intr(t, intrt)
287 1.1 uch tx_chipset_tag_t t;
288 1.1 uch void *intrt;
289 1.1 uch {
290 1.1 uch if (tx_chipset.tc_intrt) {
291 1.1 uch panic("duplicate intrt");
292 1.1 uch }
293 1.1 uch
294 1.1 uch if (t != &tx_chipset) {
295 1.1 uch panic("bogus tx_chipset_tag");
296 1.1 uch }
297 1.1 uch
298 1.1 uch tx_chipset.tc_intrt = intrt;
299 1.1 uch }
300 1.1 uch
301 1.1 uch #ifdef TX39_PREFER_FUNCTION
302 1.1 uch tx_chipset_tag_t
303 1.1 uch tx_conf_get_tag()
304 1.1 uch {
305 1.1 uch return (tx_chipset_tag_t)&tx_chipset;
306 1.1 uch }
307 1.1 uch
308 1.1 uch txreg_t
309 1.1 uch tx_conf_read(t, reg)
310 1.1 uch tx_chipset_tag_t t;
311 1.1 uch int reg;
312 1.1 uch {
313 1.1 uch return *((txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg));
314 1.1 uch }
315 1.1 uch
316 1.1 uch void
317 1.1 uch tx_conf_write(t, reg, val)
318 1.1 uch tx_chipset_tag_t t;
319 1.1 uch int reg;
320 1.1 uch txreg_t val;
321 1.1 uch {
322 1.1 uch *((txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg)) = val;
323 1.1 uch }
324 1.1 uch #endif /* TX39_PREFER_FUNCTION */
325 1.1 uch
326 1.1 uch int
327 1.1 uch __is_set_print(reg, mask, name)
328 1.1 uch u_int32_t reg;
329 1.1 uch int mask;
330 1.1 uch char *name;
331 1.1 uch {
332 1.1 uch if (reg & mask) {
333 1.1 uch printf("%s ", name);
334 1.1 uch return 1;
335 1.1 uch }
336 1.1 uch return 0;
337 1.1 uch }
338