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