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