consinit.c revision 1.3
1/*	$NetBSD: consinit.c,v 1.3 2003/07/15 01:37:37 lukem 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 <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.3 2003/07/15 01:37:37 lukem Exp $");
31
32#include "opt_kgdb.h"
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/device.h>
37#include <machine/bus.h>
38
39#include <powerpc/ibm4xx/ibm405gp.h>
40
41#include "com.h"
42#if (NCOM > 0)
43#include <sys/termios.h>
44#include <dev/ic/comreg.h>
45#include <dev/ic/comvar.h>
46#endif
47
48#include <dev/cons.h>
49
50#ifndef CONSDEVNAME
51#define CONSDEVNAME "com"
52#endif
53
54#if (NCOM > 0)
55#ifndef CONADDR
56#define CONADDR IBM405GP_UART0_BASE
57#endif
58#ifndef CONSPEED
59#define CONSPEED B9600	/*  */
60// #define CONSPEED B115200	/* 9600 is too slow for my taste */
61#endif
62#ifndef CONMODE
63#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
64#endif
65int comcnmode = CONMODE;
66#endif /* NCOM */
67
68#ifdef KGDB
69#ifndef KGDB_DEVNAME
70#define KGDB_DEVNAME "com"
71#endif
72char kgdb_devname[] = KGDB_DEVNAME;
73
74#if (NCOM > 1)
75#ifndef KGDB_DEVADDR
76#define KGDB_DEVADDR  UART1_BASE
77#endif
78int comkgdbaddr = KGDB_DEVADDR;
79
80#ifndef KGDB_DEVRATE
81#define KGDB_DEVRATE CONSPEED
82#endif
83int comkgdbrate = KGDB_DEVRATE;
84
85#ifndef KGDB_DEVMODE
86#define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
87#endif
88int comkgdbmode = KGDB_DEVMODE;
89
90#endif /* NCOM */
91
92#endif /* KGDB */
93
94/*
95 * consinit:
96 * initialize the system console.
97 * XXX - shouldn't deal with this initted thing, but then,
98 * it shouldn't be called from initppc either.
99 */
100void
101consinit(void)
102{
103	static int initted = 0;
104#if (NCOM > 0)
105	bus_space_tag_t tag;
106#endif
107
108	if (initted)
109		return;
110	initted = 1;
111
112#if (NCOM > 0)
113	tag = ibm4xx_make_bus_space_tag(0, 0);
114
115	if (comcnattach(tag, CONADDR, CONSPEED, COM_FREQ*6,
116	    COM_TYPE_NORMAL, comcnmode))
117		panic("can't init serial console @%x", CONADDR);
118	else
119		return;
120#endif
121	panic("console device missing -- serial console not in kernel");
122	/* Of course, this is moot if there is no console... */
123}
124
125#ifdef KGDB
126void
127kgdb_port_init(void)
128{
129#if (NCOM > 0)
130	if(!strcmp(kgdb_devname, "com")) {
131		bus_space_tag_t tag = ibm4xx_make_bus_space_tag(0, 2);
132		com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ * 6,
133		    COM_TYPE_NORMAL, comkgdbmode);
134	}
135#endif
136}
137#endif
138