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