Home | History | Annotate | Line # | Download | only in walnut
      1 /*	$NetBSD: consinit.c,v 1.10 2021/03/30 05:18:37 rin 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.10 2021/03/30 05:18:37 rin Exp $");
     31 
     32 #include "opt_kgdb.h"
     33 
     34 #include <sys/param.h>
     35 #include <sys/bus.h>
     36 #include <sys/device.h>
     37 #include <sys/systm.h>
     38 
     39 #include <powerpc/ibm4xx/ibm405gp.h>
     40 
     41 #include "com.h"
     42 #if (NCOM > 0)
     43 #include <sys/termios.h>
     44 #include <dev/ic/comreg.h>
     45 #include <dev/ic/comvar.h>
     46 #include <powerpc/ibm4xx/dev/comopbvar.h>
     47 #endif
     48 
     49 #if (NCOM > 0)
     50 #ifndef CONADDR
     51 #define CONADDR IBM405GP_UART0_BASE
     52 #endif
     53 #ifndef CONSPEED
     54 #define CONSPEED B9600	/*  */
     55 // #define CONSPEED B115200	/* 9600 is too slow for my taste */
     56 #endif
     57 #ifndef CONMODE
     58 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
     59 #endif
     60 int comcnmode = CONMODE;
     61 #endif /* NCOM */
     62 
     63 #ifdef KGDB
     64 #ifndef KGDB_DEVNAME
     65 #define KGDB_DEVNAME "com"
     66 #endif
     67 char kgdb_devname[] = KGDB_DEVNAME;
     68 
     69 #if (NCOM > 1)
     70 #ifndef KGDB_DEVADDR
     71 #define KGDB_DEVADDR  UART1_BASE
     72 #endif
     73 int comkgdbaddr = KGDB_DEVADDR;
     74 
     75 #ifndef KGDB_DEVRATE
     76 #define KGDB_DEVRATE CONSPEED
     77 #endif
     78 int comkgdbrate = KGDB_DEVRATE;
     79 
     80 #ifndef KGDB_DEVMODE
     81 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
     82 #endif
     83 int comkgdbmode = KGDB_DEVMODE;
     84 
     85 #endif /* NCOM */
     86 
     87 #endif /* KGDB */
     88 
     89 void
     90 consinit(void)
     91 {
     92 
     93 	com_opb_cnattach(COM_FREQ * 6, CONADDR, CONSPEED, comcnmode);
     94 }
     95 
     96 #ifdef KGDB
     97 void
     98 kgdb_port_init(void)
     99 {
    100 #if (NCOM > 0)
    101 	if(!strcmp(kgdb_devname, "com")) {
    102 		bus_space_tag_t tag = opb_get_bus_space_tag();
    103 		com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ * 6,
    104 		    COM_TYPE_NORMAL, comkgdbmode);
    105 	}
    106 #endif
    107 }
    108 #endif
    109