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