Home | History | Annotate | Line # | Download | only in lcboot
com.c revision 1.1.2.3
      1  1.1.2.3  skrll /*	$NetBSD: com.c,v 1.1.2.3 2004/09/21 13:16:12 skrll Exp $	*/
      2      1.1    igy 
      3      1.1    igy /*-
      4      1.1    igy  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
      5      1.1    igy  * All rights reserved.
      6      1.1    igy  *
      7      1.1    igy  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1    igy  * by Charles M. Hannum.
      9      1.1    igy  *
     10      1.1    igy  * Redistribution and use in source and binary forms, with or without
     11      1.1    igy  * modification, are permitted provided that the following conditions
     12      1.1    igy  * are met:
     13      1.1    igy  * 1. Redistributions of source code must retain the above copyright
     14      1.1    igy  *    notice, this list of conditions and the following disclaimer.
     15      1.1    igy  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1    igy  *    notice, this list of conditions and the following disclaimer in the
     17      1.1    igy  *    documentation and/or other materials provided with the distribution.
     18      1.1    igy  * 3. All advertising materials mentioning features or use of this software
     19      1.1    igy  *    must display the following acknowledgement:
     20      1.1    igy  *        This product includes software developed by the NetBSD
     21      1.1    igy  *        Foundation, Inc. and its contributors.
     22      1.1    igy  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1    igy  *    contributors may be used to endorse or promote products derived
     24      1.1    igy  *    from this software without specific prior written permission.
     25      1.1    igy  *
     26      1.1    igy  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1    igy  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1    igy  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1    igy  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1    igy  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1    igy  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1    igy  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1    igy  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1    igy  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1    igy  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1    igy  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1    igy  */
     38      1.1    igy 
     39      1.1    igy /*
     40      1.1    igy  * Copyright (c) 1991 The Regents of the University of California.
     41      1.1    igy  * All rights reserved.
     42      1.1    igy  *
     43      1.1    igy  * Redistribution and use in source and binary forms, with or without
     44      1.1    igy  * modification, are permitted provided that the following conditions
     45      1.1    igy  * are met:
     46      1.1    igy  * 1. Redistributions of source code must retain the above copyright
     47      1.1    igy  *    notice, this list of conditions and the following disclaimer.
     48      1.1    igy  * 2. Redistributions in binary form must reproduce the above copyright
     49      1.1    igy  *    notice, this list of conditions and the following disclaimer in the
     50      1.1    igy  *    documentation and/or other materials provided with the distribution.
     51  1.1.2.1  skrll  * 3. Neither the name of the University nor the names of its contributors
     52      1.1    igy  *    may be used to endorse or promote products derived from this software
     53      1.1    igy  *    without specific prior written permission.
     54      1.1    igy  *
     55      1.1    igy  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     56      1.1    igy  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     57      1.1    igy  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     58      1.1    igy  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     59      1.1    igy  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     60      1.1    igy  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     61      1.1    igy  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     62      1.1    igy  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     63      1.1    igy  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     64      1.1    igy  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     65      1.1    igy  * SUCH DAMAGE.
     66      1.1    igy  *
     67      1.1    igy  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     68      1.1    igy  */
     69      1.1    igy 
     70      1.1    igy #include <sys/param.h>
     71      1.1    igy 
     72      1.1    igy #include <lib/libsa/stand.h>
     73      1.1    igy 
     74      1.1    igy #include <hpcmips/vr/vripreg.h>
     75      1.1    igy #include <hpcmips/vr/cmureg.h>
     76      1.1    igy 
     77      1.1    igy #include <dev/ic/comreg.h>
     78      1.1    igy #include <dev/ic/ns16550reg.h>
     79      1.1    igy #include <dev/ic/st16650reg.h>
     80      1.1    igy #define com_lcr com_cfcr
     81      1.1    igy 
     82      1.1    igy #include "extern.h"
     83      1.1    igy 
     84      1.1    igy #if 0
     85      1.1    igy #define	VRCOM_FREQ	18432000	/* 18.432kHz */
     86      1.1    igy #endif
     87      1.1    igy 
     88      1.1    igy int
     89      1.1    igy iskey(void)
     90      1.1    igy {
     91      1.1    igy 	return ISSET(REGREAD_1(VR4181_SIU_ADDR, com_lsr), LSR_RXRDY);
     92      1.1    igy }
     93      1.1    igy 
     94      1.1    igy int
     95      1.1    igy getchar(void)
     96      1.1    igy {
     97      1.1    igy 	u_int8_t	stat;
     98      1.1    igy 	u_int8_t	c;
     99      1.1    igy 
    100      1.1    igy 	/* block until a character becomes available */
    101      1.1    igy 	while (!ISKEY)
    102      1.1    igy 		;
    103      1.1    igy 
    104      1.1    igy 	c = REGREAD_1(VR4181_SIU_ADDR, com_data);
    105      1.1    igy 	stat = REGREAD_1(VR4181_SIU_ADDR, com_iir);
    106      1.1    igy 
    107      1.1    igy 	return c;
    108      1.1    igy }
    109      1.1    igy 
    110      1.1    igy static void
    111      1.1    igy comcnputc(int c)
    112      1.1    igy {
    113      1.1    igy 	int	timo;
    114      1.1    igy 
    115      1.1    igy 	/* wait for any pending transmission to finish */
    116      1.1    igy 	timo = 150000;
    117      1.1    igy 	while (!ISSET(REGREAD_1(VR4181_SIU_ADDR, com_lsr), LSR_TXRDY)
    118      1.1    igy 	       && --timo)
    119      1.1    igy 		continue;
    120      1.1    igy 
    121      1.1    igy 	REGWRITE_1(VR4181_SIU_ADDR, com_data, c);
    122      1.1    igy 
    123      1.1    igy 	/* wait for this transmission to complete */
    124      1.1    igy 	timo = 1500000;
    125      1.1    igy 	while (!ISSET(REGREAD_1(VR4181_SIU_ADDR, com_lsr), LSR_TXRDY)
    126      1.1    igy 	       && --timo)
    127      1.1    igy 		continue;
    128      1.1    igy }
    129      1.1    igy 
    130      1.1    igy void
    131      1.1    igy putchar(int c)
    132      1.1    igy {
    133      1.1    igy 	if (c == '\n')
    134      1.1    igy 		comcnputc('\r');
    135      1.1    igy 	comcnputc(c);
    136      1.1    igy }
    137      1.1    igy 
    138      1.1    igy /*
    139      1.1    igy  * Initialize UART for use as console or KGDB line.
    140      1.1    igy  */
    141      1.1    igy void
    142      1.1    igy comcninit(void)
    143      1.1    igy {
    144      1.1    igy 	int		rate;
    145      1.1    igy 
    146      1.1    igy 	/* enable divisor latch access and set bit rate */
    147      1.1    igy 	REGWRITE_1(VR4181_SIU_ADDR, com_lcr, LCR_DLAB);
    148      1.1    igy 	rate = 10; /* 115200bps with VRCOM_FREQ */
    149      1.1    igy 	REGWRITE_1(VR4181_SIU_ADDR, com_dlbl, rate);
    150      1.1    igy 	REGWRITE_1(VR4181_SIU_ADDR, com_dlbh, rate >> 8);
    151      1.1    igy 
    152      1.1    igy 	/*
    153      1.1    igy 	 * disable divisor latch access and,
    154      1.1    igy 	 * set "8bit non-parity 1 stop bit"
    155      1.1    igy 	 */
    156      1.1    igy 	REGWRITE_1(VR4181_SIU_ADDR, com_lcr, LCR_8BITS);
    157      1.1    igy 
    158      1.1    igy 	/* disable all interrupt */
    159      1.1    igy 	REGWRITE_1(VR4181_SIU_ADDR, com_ier, 0);
    160      1.1    igy 
    161      1.1    igy 	/* enable FIFO */
    162      1.1    igy 	REGWRITE_1(VR4181_SIU_ADDR, com_fifo,
    163      1.1    igy 		   FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1);
    164      1.1    igy 
    165      1.1    igy 	/* set DTR and RTS low */
    166      1.1    igy 	REGWRITE_1(VR4181_SIU_ADDR, com_mcr, MCR_DTR | MCR_RTS);
    167      1.1    igy }
    168