1 /* $NetBSD: dca.c,v 1.7 2011/02/08 20:20:14 rmind Exp $ */ 2 3 /* 4 * Copyright (c) 1988 University of Utah. 5 * Copyright (c) 1990, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * the Systems Programming Group of the University of Utah Computer 10 * Science Department. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)dca.c 8.1 (Berkeley) 6/10/93 37 */ 38 39 #ifdef DCACONSOLE 40 #include <sys/param.h> 41 #include <dev/cons.h> 42 43 #include <hp300/stand/common/dcareg.h> 44 #include <hp300/stand/common/consdefs.h> 45 #include <hp300/stand/common/samachdep.h> 46 47 /* If not using 4.4 devs */ 48 #ifndef dca_reset 49 #define dca_id dca_irid 50 #define dca_reset dca_id 51 #endif 52 53 struct dcadevice *dcacnaddr = 0; 54 55 #define DCACONSCODE 9 /* XXX */ 56 57 void 58 dcaprobe(struct consdev *cp) 59 { 60 struct dcadevice *dca; 61 62 dcacnaddr = (struct dcadevice *) sctoaddr(DCACONSCODE); 63 if (badaddr((char *)dcacnaddr)) { 64 cp->cn_pri = CN_DEAD; 65 return; 66 } 67 #ifdef FORCEDCACONSOLE 68 cp->cn_pri = CN_REMOTE; 69 #else 70 dca = dcacnaddr; 71 switch (dca->dca_id) { 72 case DCAID0: 73 case DCAID1: 74 cp->cn_pri = CN_NORMAL; 75 break; 76 case DCAREMID0: 77 case DCAREMID1: 78 cp->cn_pri = CN_REMOTE; 79 break; 80 default: 81 cp->cn_pri = CN_DEAD; 82 break; 83 } 84 85 #endif 86 curcons_scode = DCACONSCODE; 87 } 88 89 void 90 dcainit(struct consdev *cp) 91 { 92 struct dcadevice *dca = dcacnaddr; 93 94 dca->dca_reset = 0xFF; 95 DELAY(100); 96 dca->dca_ic = 0; 97 dca->dca_cfcr = CFCR_DLAB; 98 dca->dca_data = DCABRD(9600) & 0xFF; 99 dca->dca_ier = DCABRD(9600) >> 8; 100 dca->dca_cfcr = CFCR_8BITS; 101 dca->dca_fifo = 102 FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1; 103 dca->dca_mcr = MCR_DTR | MCR_RTS; 104 } 105 106 /* ARGSUSED */ 107 #ifndef SMALL 108 int 109 dcagetchar(dev_t dev) 110 { 111 struct dcadevice *dca = dcacnaddr; 112 short stat; 113 int c; 114 115 if (((stat = dca->dca_lsr) & LSR_RXRDY) == 0) 116 return 0; 117 c = dca->dca_data; 118 return c; 119 } 120 #else 121 int 122 dcagetchar(dev_t dev) 123 { 124 125 return 0; 126 } 127 #endif 128 129 /* ARGSUSED */ 130 void 131 dcaputchar(dev_t dev, int c) 132 { 133 struct dcadevice *dca = dcacnaddr; 134 int timo; 135 short stat; 136 137 /* wait a reasonable time for the transmitter to come ready */ 138 timo = 50000; 139 while (((stat = dca->dca_lsr) & LSR_TXRDY) == 0 && --timo) 140 ; 141 dca->dca_data = c; 142 /* wait for this transmission to complete */ 143 timo = 1000000; 144 while (((stat = dca->dca_lsr) & LSR_TXRDY) == 0 && --timo) 145 ; 146 } 147 #endif 148