xref: /netbsd-src/sys/arch/evbppc/walnut/consinit.c (revision d710132b4b8ce7f7cccaaf660cb16aa16b4077a0)
1 /*	$NetBSD: consinit.c,v 1.2 2003/06/14 17:01:11 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 1998
5  *	Matthias Drochner.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #include "opt_kgdb.h"
30 
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/device.h>
34 #include <machine/bus.h>
35 
36 #include <powerpc/ibm4xx/ibm405gp.h>
37 
38 #include "com.h"
39 #if (NCOM > 0)
40 #include <sys/termios.h>
41 #include <dev/ic/comreg.h>
42 #include <dev/ic/comvar.h>
43 #endif
44 
45 #include <dev/cons.h>
46 
47 #ifndef CONSDEVNAME
48 #define CONSDEVNAME "com"
49 #endif
50 
51 #if (NCOM > 0)
52 #ifndef CONADDR
53 #define CONADDR IBM405GP_UART0_BASE
54 #endif
55 #ifndef CONSPEED
56 #define CONSPEED B9600	/*  */
57 // #define CONSPEED B115200	/* 9600 is too slow for my taste */
58 #endif
59 #ifndef CONMODE
60 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
61 #endif
62 int comcnmode = CONMODE;
63 #endif /* NCOM */
64 
65 #ifdef KGDB
66 #ifndef KGDB_DEVNAME
67 #define KGDB_DEVNAME "com"
68 #endif
69 char kgdb_devname[] = KGDB_DEVNAME;
70 
71 #if (NCOM > 1)
72 #ifndef KGDB_DEVADDR
73 #define KGDB_DEVADDR  UART1_BASE
74 #endif
75 int comkgdbaddr = KGDB_DEVADDR;
76 
77 #ifndef KGDB_DEVRATE
78 #define KGDB_DEVRATE CONSPEED
79 #endif
80 int comkgdbrate = KGDB_DEVRATE;
81 
82 #ifndef KGDB_DEVMODE
83 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
84 #endif
85 int comkgdbmode = KGDB_DEVMODE;
86 
87 #endif /* NCOM */
88 
89 #endif /* KGDB */
90 
91 /*
92  * consinit:
93  * initialize the system console.
94  * XXX - shouldn't deal with this initted thing, but then,
95  * it shouldn't be called from initppc either.
96  */
97 void
98 consinit(void)
99 {
100 	static int initted = 0;
101 #if (NCOM > 0)
102 	bus_space_tag_t tag;
103 #endif
104 
105 	if (initted)
106 		return;
107 	initted = 1;
108 
109 #if (NCOM > 0)
110 	tag = ibm4xx_make_bus_space_tag(0, 0);
111 
112 	if (comcnattach(tag, CONADDR, CONSPEED, COM_FREQ*6,
113 	    COM_TYPE_NORMAL, comcnmode))
114 		panic("can't init serial console @%x", CONADDR);
115 	else
116 		return;
117 #endif
118 	panic("console device missing -- serial console not in kernel");
119 	/* Of course, this is moot if there is no console... */
120 }
121 
122 #ifdef KGDB
123 void
124 kgdb_port_init(void)
125 {
126 #if (NCOM > 0)
127 	if(!strcmp(kgdb_devname, "com")) {
128 		bus_space_tag_t tag = ibm4xx_make_bus_space_tag(0, 2);
129 		com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ * 6,
130 		    COM_TYPE_NORMAL, comkgdbmode);
131 	}
132 #endif
133 }
134 #endif
135