consinit.c revision 1.9
11.9Srin/*	$NetBSD: consinit.c,v 1.9 2021/03/29 13:59:15 rin 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.9Srin__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.9 2021/03/29 13:59:15 rin 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.8Sdyoung#include <sys/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.9Srin#include <powerpc/ibm4xx/dev/comopbvar.h>
481.1Sscw#endif
491.1Sscw
501.1Sscw#include <dev/cons.h>
511.1Sscw
521.1Sscw#ifndef CONSDEVNAME
531.1Sscw#define CONSDEVNAME "com"
541.1Sscw#endif
551.1Sscw
561.1Sscw#if (NCOM > 0)
571.1Sscw#ifndef CONADDR
581.1Sscw#define CONADDR IBM405GP_UART0_BASE
591.1Sscw#endif
601.1Sscw#ifndef CONSPEED
611.1Sscw#define CONSPEED B9600	/*  */
621.1Sscw// #define CONSPEED B115200	/* 9600 is too slow for my taste */
631.1Sscw#endif
641.1Sscw#ifndef CONMODE
651.1Sscw#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
661.1Sscw#endif
671.1Sscwint comcnmode = CONMODE;
681.1Sscw#endif /* NCOM */
691.1Sscw
701.1Sscw#ifdef KGDB
711.1Sscw#ifndef KGDB_DEVNAME
721.1Sscw#define KGDB_DEVNAME "com"
731.1Sscw#endif
741.1Sscwchar kgdb_devname[] = KGDB_DEVNAME;
751.1Sscw
761.1Sscw#if (NCOM > 1)
771.1Sscw#ifndef KGDB_DEVADDR
781.1Sscw#define KGDB_DEVADDR  UART1_BASE
791.1Sscw#endif
801.1Sscwint comkgdbaddr = KGDB_DEVADDR;
811.1Sscw
821.1Sscw#ifndef KGDB_DEVRATE
831.1Sscw#define KGDB_DEVRATE CONSPEED
841.1Sscw#endif
851.1Sscwint comkgdbrate = KGDB_DEVRATE;
861.1Sscw
871.1Sscw#ifndef KGDB_DEVMODE
881.1Sscw#define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
891.1Sscw#endif
901.1Sscwint comkgdbmode = KGDB_DEVMODE;
911.1Sscw
921.1Sscw#endif /* NCOM */
931.1Sscw
941.1Sscw#endif /* KGDB */
951.1Sscw
961.1Sscwvoid
971.1Sscwconsinit(void)
981.1Sscw{
991.1Sscw
1001.9Srin	com_opb_cnattach(COM_FREQ * 6, CONADDR, CONSPEED, comcnmode);
1011.1Sscw}
1021.1Sscw
1031.1Sscw#ifdef KGDB
1041.1Sscwvoid
1051.1Sscwkgdb_port_init(void)
1061.1Sscw{
1071.1Sscw#if (NCOM > 0)
1081.1Sscw	if(!strcmp(kgdb_devname, "com")) {
1091.4Sscw		bus_space_tag_t tag = opb_get_bus_space_tag();
1101.1Sscw		com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ * 6,
1111.2Sthorpej		    COM_TYPE_NORMAL, comkgdbmode);
1121.1Sscw	}
1131.1Sscw#endif
1141.1Sscw}
1151.1Sscw#endif
116