consinit.c revision 1.4
11.4Sscw/*	$NetBSD: consinit.c,v 1.4 2003/07/25 11:44:21 scw Exp $	*/
21.1Sscw
31.1Sscw/*
41.1Sscw * Copyright (c) 1998
51.1Sscw *	Matthias Drochner.  All rights reserved.
61.1Sscw *
71.1Sscw * Redistribution and use in source and binary forms, with or without
81.1Sscw * modification, are permitted provided that the following conditions
91.1Sscw * are met:
101.1Sscw * 1. Redistributions of source code must retain the above copyright
111.1Sscw *    notice, this list of conditions and the following disclaimer.
121.1Sscw * 2. Redistributions in binary form must reproduce the above copyright
131.1Sscw *    notice, this list of conditions and the following disclaimer in the
141.1Sscw *    documentation and/or other materials provided with the distribution.
151.1Sscw *
161.1Sscw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
171.1Sscw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
181.1Sscw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
191.1Sscw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
201.1Sscw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
211.1Sscw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
221.1Sscw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
231.1Sscw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
241.1Sscw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
251.1Sscw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
261.1Sscw *
271.1Sscw */
281.3Slukem
291.3Slukem#include <sys/cdefs.h>
301.4Sscw__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.4 2003/07/25 11:44:21 scw Exp $");
311.1Sscw
321.1Sscw#include "opt_kgdb.h"
331.1Sscw
341.1Sscw#include <sys/param.h>
351.1Sscw#include <sys/systm.h>
361.1Sscw#include <sys/device.h>
371.1Sscw#include <machine/bus.h>
381.1Sscw
391.1Sscw#include <powerpc/ibm4xx/ibm405gp.h>
401.4Sscw#include <powerpc/ibm4xx/dev/opbvar.h>
411.1Sscw
421.1Sscw#include "com.h"
431.1Sscw#if (NCOM > 0)
441.1Sscw#include <sys/termios.h>
451.1Sscw#include <dev/ic/comreg.h>
461.1Sscw#include <dev/ic/comvar.h>
471.1Sscw#endif
481.1Sscw
491.1Sscw#include <dev/cons.h>
501.1Sscw
511.1Sscw#ifndef CONSDEVNAME
521.1Sscw#define CONSDEVNAME "com"
531.1Sscw#endif
541.1Sscw
551.1Sscw#if (NCOM > 0)
561.1Sscw#ifndef CONADDR
571.1Sscw#define CONADDR IBM405GP_UART0_BASE
581.1Sscw#endif
591.1Sscw#ifndef CONSPEED
601.1Sscw#define CONSPEED B9600	/*  */
611.1Sscw// #define CONSPEED B115200	/* 9600 is too slow for my taste */
621.1Sscw#endif
631.1Sscw#ifndef CONMODE
641.1Sscw#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
651.1Sscw#endif
661.1Sscwint comcnmode = CONMODE;
671.1Sscw#endif /* NCOM */
681.1Sscw
691.1Sscw#ifdef KGDB
701.1Sscw#ifndef KGDB_DEVNAME
711.1Sscw#define KGDB_DEVNAME "com"
721.1Sscw#endif
731.1Sscwchar kgdb_devname[] = KGDB_DEVNAME;
741.1Sscw
751.1Sscw#if (NCOM > 1)
761.1Sscw#ifndef KGDB_DEVADDR
771.1Sscw#define KGDB_DEVADDR  UART1_BASE
781.1Sscw#endif
791.1Sscwint comkgdbaddr = KGDB_DEVADDR;
801.1Sscw
811.1Sscw#ifndef KGDB_DEVRATE
821.1Sscw#define KGDB_DEVRATE CONSPEED
831.1Sscw#endif
841.1Sscwint comkgdbrate = KGDB_DEVRATE;
851.1Sscw
861.1Sscw#ifndef KGDB_DEVMODE
871.1Sscw#define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
881.1Sscw#endif
891.1Sscwint comkgdbmode = KGDB_DEVMODE;
901.1Sscw
911.1Sscw#endif /* NCOM */
921.1Sscw
931.1Sscw#endif /* KGDB */
941.1Sscw
951.1Sscw/*
961.1Sscw * consinit:
971.1Sscw * initialize the system console.
981.1Sscw * XXX - shouldn't deal with this initted thing, but then,
991.1Sscw * it shouldn't be called from initppc either.
1001.1Sscw */
1011.1Sscwvoid
1021.1Sscwconsinit(void)
1031.1Sscw{
1041.1Sscw	static int initted = 0;
1051.1Sscw#if (NCOM > 0)
1061.1Sscw	bus_space_tag_t tag;
1071.1Sscw#endif
1081.1Sscw
1091.1Sscw	if (initted)
1101.1Sscw		return;
1111.1Sscw	initted = 1;
1121.1Sscw
1131.1Sscw#if (NCOM > 0)
1141.4Sscw	/* We *know* the com-console attaches to opb */
1151.4Sscw	tag = opb_get_bus_space_tag();
1161.1Sscw
1171.1Sscw	if (comcnattach(tag, CONADDR, CONSPEED, COM_FREQ*6,
1181.2Sthorpej	    COM_TYPE_NORMAL, comcnmode))
1191.1Sscw		panic("can't init serial console @%x", CONADDR);
1201.1Sscw	else
1211.1Sscw#endif
1221.1Sscw	panic("console device missing -- serial console not in kernel");
1231.1Sscw	/* Of course, this is moot if there is no console... */
1241.1Sscw}
1251.1Sscw
1261.1Sscw#ifdef KGDB
1271.1Sscwvoid
1281.1Sscwkgdb_port_init(void)
1291.1Sscw{
1301.1Sscw#if (NCOM > 0)
1311.1Sscw	if(!strcmp(kgdb_devname, "com")) {
1321.4Sscw		bus_space_tag_t tag = opb_get_bus_space_tag();
1331.1Sscw		com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ * 6,
1341.2Sthorpej		    COM_TYPE_NORMAL, comkgdbmode);
1351.1Sscw	}
1361.1Sscw#endif
1371.1Sscw}
1381.1Sscw#endif
139