consinit.c revision 1.2
11.2Sthorpej/*	$NetBSD: consinit.c,v 1.2 2003/06/14 17:01:11 thorpej 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.1Sscw
291.1Sscw#include "opt_kgdb.h"
301.1Sscw
311.1Sscw#include <sys/param.h>
321.1Sscw#include <sys/systm.h>
331.1Sscw#include <sys/device.h>
341.1Sscw#include <machine/bus.h>
351.1Sscw
361.1Sscw#include <powerpc/ibm4xx/ibm405gp.h>
371.1Sscw
381.1Sscw#include "com.h"
391.1Sscw#if (NCOM > 0)
401.1Sscw#include <sys/termios.h>
411.1Sscw#include <dev/ic/comreg.h>
421.1Sscw#include <dev/ic/comvar.h>
431.1Sscw#endif
441.1Sscw
451.1Sscw#include <dev/cons.h>
461.1Sscw
471.1Sscw#ifndef CONSDEVNAME
481.1Sscw#define CONSDEVNAME "com"
491.1Sscw#endif
501.1Sscw
511.1Sscw#if (NCOM > 0)
521.1Sscw#ifndef CONADDR
531.1Sscw#define CONADDR IBM405GP_UART0_BASE
541.1Sscw#endif
551.1Sscw#ifndef CONSPEED
561.1Sscw#define CONSPEED B9600	/*  */
571.1Sscw// #define CONSPEED B115200	/* 9600 is too slow for my taste */
581.1Sscw#endif
591.1Sscw#ifndef CONMODE
601.1Sscw#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
611.1Sscw#endif
621.1Sscwint comcnmode = CONMODE;
631.1Sscw#endif /* NCOM */
641.1Sscw
651.1Sscw#ifdef KGDB
661.1Sscw#ifndef KGDB_DEVNAME
671.1Sscw#define KGDB_DEVNAME "com"
681.1Sscw#endif
691.1Sscwchar kgdb_devname[] = KGDB_DEVNAME;
701.1Sscw
711.1Sscw#if (NCOM > 1)
721.1Sscw#ifndef KGDB_DEVADDR
731.1Sscw#define KGDB_DEVADDR  UART1_BASE
741.1Sscw#endif
751.1Sscwint comkgdbaddr = KGDB_DEVADDR;
761.1Sscw
771.1Sscw#ifndef KGDB_DEVRATE
781.1Sscw#define KGDB_DEVRATE CONSPEED
791.1Sscw#endif
801.1Sscwint comkgdbrate = KGDB_DEVRATE;
811.1Sscw
821.1Sscw#ifndef KGDB_DEVMODE
831.1Sscw#define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
841.1Sscw#endif
851.1Sscwint comkgdbmode = KGDB_DEVMODE;
861.1Sscw
871.1Sscw#endif /* NCOM */
881.1Sscw
891.1Sscw#endif /* KGDB */
901.1Sscw
911.1Sscw/*
921.1Sscw * consinit:
931.1Sscw * initialize the system console.
941.1Sscw * XXX - shouldn't deal with this initted thing, but then,
951.1Sscw * it shouldn't be called from initppc either.
961.1Sscw */
971.1Sscwvoid
981.1Sscwconsinit(void)
991.1Sscw{
1001.1Sscw	static int initted = 0;
1011.1Sscw#if (NCOM > 0)
1021.1Sscw	bus_space_tag_t tag;
1031.1Sscw#endif
1041.1Sscw
1051.1Sscw	if (initted)
1061.1Sscw		return;
1071.1Sscw	initted = 1;
1081.1Sscw
1091.1Sscw#if (NCOM > 0)
1101.1Sscw	tag = ibm4xx_make_bus_space_tag(0, 0);
1111.1Sscw
1121.1Sscw	if (comcnattach(tag, CONADDR, CONSPEED, COM_FREQ*6,
1131.2Sthorpej	    COM_TYPE_NORMAL, comcnmode))
1141.1Sscw		panic("can't init serial console @%x", CONADDR);
1151.1Sscw	else
1161.1Sscw		return;
1171.1Sscw#endif
1181.1Sscw	panic("console device missing -- serial console not in kernel");
1191.1Sscw	/* Of course, this is moot if there is no console... */
1201.1Sscw}
1211.1Sscw
1221.1Sscw#ifdef KGDB
1231.1Sscwvoid
1241.1Sscwkgdb_port_init(void)
1251.1Sscw{
1261.1Sscw#if (NCOM > 0)
1271.1Sscw	if(!strcmp(kgdb_devname, "com")) {
1281.1Sscw		bus_space_tag_t tag = ibm4xx_make_bus_space_tag(0, 2);
1291.1Sscw		com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ * 6,
1301.2Sthorpej		    COM_TYPE_NORMAL, comkgdbmode);
1311.1Sscw	}
1321.1Sscw#endif
1331.1Sscw}
1341.1Sscw#endif
135