consinit.c revision 1.10
11.10Srin/*	$NetBSD: consinit.c,v 1.10 2021/03/30 05:18:37 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.10Srin__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.10 2021/03/30 05:18:37 rin Exp $");
311.1Sscw
321.1Sscw#include "opt_kgdb.h"
331.1Sscw
341.1Sscw#include <sys/param.h>
351.10Srin#include <sys/bus.h>
361.10Srin#include <sys/device.h>
371.1Sscw#include <sys/systm.h>
381.1Sscw
391.1Sscw#include <powerpc/ibm4xx/ibm405gp.h>
401.1Sscw
411.1Sscw#include "com.h"
421.1Sscw#if (NCOM > 0)
431.1Sscw#include <sys/termios.h>
441.1Sscw#include <dev/ic/comreg.h>
451.1Sscw#include <dev/ic/comvar.h>
461.9Srin#include <powerpc/ibm4xx/dev/comopbvar.h>
471.1Sscw#endif
481.1Sscw
491.1Sscw#if (NCOM > 0)
501.1Sscw#ifndef CONADDR
511.1Sscw#define CONADDR IBM405GP_UART0_BASE
521.1Sscw#endif
531.1Sscw#ifndef CONSPEED
541.1Sscw#define CONSPEED B9600	/*  */
551.1Sscw// #define CONSPEED B115200	/* 9600 is too slow for my taste */
561.1Sscw#endif
571.1Sscw#ifndef CONMODE
581.1Sscw#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
591.1Sscw#endif
601.1Sscwint comcnmode = CONMODE;
611.1Sscw#endif /* NCOM */
621.1Sscw
631.1Sscw#ifdef KGDB
641.1Sscw#ifndef KGDB_DEVNAME
651.1Sscw#define KGDB_DEVNAME "com"
661.1Sscw#endif
671.1Sscwchar kgdb_devname[] = KGDB_DEVNAME;
681.1Sscw
691.1Sscw#if (NCOM > 1)
701.1Sscw#ifndef KGDB_DEVADDR
711.1Sscw#define KGDB_DEVADDR  UART1_BASE
721.1Sscw#endif
731.1Sscwint comkgdbaddr = KGDB_DEVADDR;
741.1Sscw
751.1Sscw#ifndef KGDB_DEVRATE
761.1Sscw#define KGDB_DEVRATE CONSPEED
771.1Sscw#endif
781.1Sscwint comkgdbrate = KGDB_DEVRATE;
791.1Sscw
801.1Sscw#ifndef KGDB_DEVMODE
811.1Sscw#define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
821.1Sscw#endif
831.1Sscwint comkgdbmode = KGDB_DEVMODE;
841.1Sscw
851.1Sscw#endif /* NCOM */
861.1Sscw
871.1Sscw#endif /* KGDB */
881.1Sscw
891.1Sscwvoid
901.1Sscwconsinit(void)
911.1Sscw{
921.1Sscw
931.9Srin	com_opb_cnattach(COM_FREQ * 6, CONADDR, CONSPEED, comcnmode);
941.1Sscw}
951.1Sscw
961.1Sscw#ifdef KGDB
971.1Sscwvoid
981.1Sscwkgdb_port_init(void)
991.1Sscw{
1001.1Sscw#if (NCOM > 0)
1011.1Sscw	if(!strcmp(kgdb_devname, "com")) {
1021.4Sscw		bus_space_tag_t tag = opb_get_bus_space_tag();
1031.1Sscw		com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ * 6,
1041.2Sthorpej		    COM_TYPE_NORMAL, comkgdbmode);
1051.1Sscw	}
1061.1Sscw#endif
1071.1Sscw}
1081.1Sscw#endif
109