1 /* $NetBSD: dcm.c,v 1.2 1997/04/14 05:58:32 scottr 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. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the University of 23 * California, Berkeley and its contributors. 24 * 4. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * @(#)dcm.c 8.1 (Berkeley) 6/10/93 41 */ 42 43 #ifdef DCMCONSOLE 44 #include <sys/param.h> 45 #include <dev/cons.h> 46 47 #include <hp300/dev/dcmreg.h> 48 49 #include <hp300/stand/common/consdefs.h> 50 #include <hp300/stand/common/samachdep.h> 51 #include <hp300/stand/common/device.h> 52 53 struct dcmdevice *dcmcnaddr = NULL; 54 55 #define DCMCONUNIT 1 /* XXX */ 56 57 void 58 dcmprobe(cp) 59 struct consdev *cp; 60 { 61 extern struct hp_hw sc_table[]; 62 register struct hp_hw *hw; 63 register struct dcmdevice *dcm; 64 65 for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) 66 if (HW_ISDEV(hw, D_COMMDCM) && !badaddr((caddr_t)hw->hw_kva)) 67 break; 68 if (!HW_ISDEV(hw, D_COMMDCM)) { 69 cp->cn_pri = CN_DEAD; 70 return; 71 } 72 dcmcnaddr = (struct dcmdevice *) hw->hw_kva; 73 74 #ifdef FORCEDCMCONSOLE 75 cp->cn_pri = CN_REMOTE; 76 #else 77 dcm = dcmcnaddr; 78 switch (dcm->dcm_rsid) { 79 case DCMID: 80 cp->cn_pri = CN_NORMAL; 81 break; 82 case DCMID|DCMCON: 83 cp->cn_pri = CN_REMOTE; 84 break; 85 default: 86 cp->cn_pri = CN_DEAD; 87 break; 88 } 89 90 curcons_scode = hw->hw_sc; 91 #endif 92 } 93 94 void 95 dcminit(cp) 96 struct consdev *cp; 97 { 98 register struct dcmdevice *dcm = dcmcnaddr; 99 register int port = DCMCONUNIT; 100 101 dcm->dcm_ic = IC_ID; 102 while (dcm->dcm_thead[port].ptr != dcm->dcm_ttail[port].ptr) 103 ; 104 dcm->dcm_data[port].dcm_baud = BR_9600; 105 dcm->dcm_data[port].dcm_conf = LC_8BITS | LC_1STOP; 106 SEM_LOCK(dcm); 107 dcm->dcm_cmdtab[port].dcm_data |= CT_CON; 108 dcm->dcm_cr |= (1 << port); 109 SEM_UNLOCK(dcm); 110 DELAY(15000); 111 } 112 113 /* ARGSUSED */ 114 #ifndef SMALL 115 int 116 dcmgetchar(dev) 117 dev_t dev; 118 { 119 register struct dcmdevice *dcm = dcmcnaddr; 120 register struct dcmrfifo *fifo; 121 register struct dcmpreg *pp; 122 register unsigned head; 123 int c, stat, port; 124 125 port = DCMCONUNIT; 126 pp = dcm_preg(dcm, port); 127 head = pp->r_head & RX_MASK; 128 if (head == (pp->r_tail & RX_MASK)) 129 return(0); 130 fifo = &dcm->dcm_rfifos[3-port][head>>1]; 131 c = fifo->data_char; 132 stat = fifo->data_stat; 133 pp->r_head = (head + 2) & RX_MASK; 134 SEM_LOCK(dcm); 135 stat = dcm->dcm_iir; 136 SEM_UNLOCK(dcm); 137 return(c); 138 } 139 #else 140 int 141 dcmgetchar(dev) 142 dev_t dev; 143 { 144 return(0); 145 } 146 #endif 147 148 /* ARGSUSED */ 149 void 150 dcmputchar(dev, c) 151 dev_t dev; 152 register int c; 153 { 154 register struct dcmdevice *dcm = dcmcnaddr; 155 register struct dcmpreg *pp; 156 register int timo; 157 unsigned tail; 158 int port, stat; 159 160 port = DCMCONUNIT; 161 pp = dcm_preg(dcm, port); 162 tail = pp->t_tail & TX_MASK; 163 timo = 50000; 164 while (tail != (pp->t_head & TX_MASK) && --timo) 165 ; 166 dcm->dcm_tfifos[3-port][tail].data_char = c; 167 pp->t_tail = tail = (tail + 1) & TX_MASK; 168 SEM_LOCK(dcm); 169 dcm->dcm_cmdtab[port].dcm_data |= CT_TX; 170 dcm->dcm_cr |= (1 << port); 171 SEM_UNLOCK(dcm); 172 timo = 1000000; 173 while (tail != (pp->t_head & TX_MASK) && --timo) 174 ; 175 SEM_LOCK(dcm); 176 stat = dcm->dcm_iir; 177 SEM_UNLOCK(dcm); 178 } 179 #endif 180