1 /* $NetBSD: apci.c,v 1.2 1997/10/04 17:20:15 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 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) 1988 University of Utah. 41 * Copyright (c) 1990, 1993 42 * The Regents of the University of California. All rights reserved. 43 * 44 * This code is derived from software contributed to Berkeley by 45 * the Systems Programming Group of the University of Utah Computer 46 * Science Department. 47 * 48 * Redistribution and use in source and binary forms, with or without 49 * modification, are permitted provided that the following conditions 50 * are met: 51 * 1. Redistributions of source code must retain the above copyright 52 * notice, this list of conditions and the following disclaimer. 53 * 2. Redistributions in binary form must reproduce the above copyright 54 * notice, this list of conditions and the following disclaimer in the 55 * documentation and/or other materials provided with the distribution. 56 * 3. All advertising materials mentioning features or use of this software 57 * must display the following acknowledgement: 58 * This product includes software developed by the University of 59 * California, Berkeley and its contributors. 60 * 4. Neither the name of the University nor the names of its contributors 61 * may be used to endorse or promote products derived from this software 62 * without specific prior written permission. 63 * 64 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 65 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 66 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 67 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 68 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 69 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 70 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 71 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 72 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 73 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 74 * SUCH DAMAGE. 75 * 76 * @(#)dca.c 8.1 (Berkeley) 6/10/93 77 */ 78 79 #ifdef APCICONSOLE 80 #include <sys/param.h> 81 #include <dev/cons.h> 82 83 #include <hp300/dev/frodoreg.h> /* for APCI offsets */ 84 #include <hp300/dev/apcireg.h> /* for register map */ 85 #include <hp300/dev/dcareg.h> /* for register bits */ 86 87 #include <hp300/stand/common/consdefs.h> 88 #include <hp300/stand/common/samachdep.h> 89 90 struct apciregs *apcicnaddr = 0; 91 92 void 93 apciprobe(cp) 94 struct consdev *cp; 95 { 96 struct apciregs *apci = apcicnaddr = 97 (struct apciregs *)IIOV(FRODO_BASE + FRODO_APCI_OFFSET(1)); 98 struct dcadevice *dca = (struct dcadevice *)sctoaddr(9); 99 100 cp->cn_pri = CN_DEAD; 101 102 /* Only 400-series machines can have this. */ 103 switch (machineid) { 104 case HP_400: 105 case HP_425: 106 case HP_433: 107 break; 108 default: 109 return; 110 } 111 112 /* Make sure there's not a DCA in the way. */ 113 if (badaddr((caddr_t)dca) == 0) { 114 switch (dca->dca_id) { 115 case DCAID0: 116 case DCAID1: 117 case DCAREMID0: 118 case DCAREMID1: 119 return; 120 } 121 } 122 123 #ifdef FORCEAPCICONSOLE 124 cp->cn_pri = CN_REMOTE; 125 #else 126 cp->cn_pri = CN_NORMAL; 127 #endif 128 curcons_scode = -2; 129 } 130 131 void 132 apciinit(cp) 133 struct consdev *cp; 134 { 135 struct apciregs *apci = (struct apciregs *)apcicnaddr; 136 137 /* 138 * The only system on which this will happen is a 425e, 139 * which does not currently have a framebuffer console 140 * driver. We use the ROM's output method to let the 141 * operator know we're switching to the APCI. 142 */ 143 userom = 1; 144 printf("Switching to APCI console.\n"); 145 userom = 0; 146 147 apci->ap_cfcr = CFCR_DLAB; 148 apci->ap_data = APCIBRD(9600) & 0xff; 149 apci->ap_ier = (APCIBRD(9600) >> 8) & 0xff; 150 apci->ap_cfcr = CFCR_8BITS; 151 apci->ap_fifo = 152 FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1; 153 apci->ap_mcr = MCR_DTR | MCR_RTS; 154 } 155 156 /* ARGSUSED */ 157 #ifndef SMALL 158 int 159 apcigetchar(dev) 160 dev_t dev; 161 { 162 register struct apciregs *apci = apcicnaddr; 163 short stat; 164 int c; 165 166 if (((stat = apci->ap_lsr) & LSR_RXRDY) == 0) 167 return (0); 168 c = apci->ap_data; 169 return (c); 170 } 171 #else 172 int 173 apcigetchar(dev) 174 dev_t dev; 175 { 176 return (0); 177 } 178 #endif 179 180 /* ARGSUSED */ 181 void 182 apciputchar(dev, c) 183 dev_t dev; 184 int c; 185 { 186 struct apciregs *apci = apcicnaddr; 187 int timo; 188 short stat; 189 190 /* wait a reasonable time for the transmitter to come ready */ 191 timo = 50000; 192 while (((stat = apci->ap_lsr) & LSR_TXRDY) == 0 && --timo) 193 ; 194 apci->ap_data = c; 195 /* wait for this transmission to complete */ 196 timo = 1000000; 197 while (((stat = apci->ap_lsr) & LSR_TXRDY) == 0 && --timo) 198 ; 199 } 200 #endif 201