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