1 /* $NetBSD: ite_compat.c,v 1.5 2002/09/06 13:18:43 gehenna Exp $ */ 2 3 /* 4 * Copyright (C) 2000 Scott Reynolds 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 /* 31 * The main thing to realize about this emulator is that the old console 32 * emulator was largely compatible with the DEC VT-220. Since the 33 * wsdiplay driver has a more complete emulation of that terminal, it's 34 * reasonable to pass virtually everything up to that driver without 35 * modification. 36 */ 37 38 #include "ite.h" 39 #include "wsdisplay.h" 40 41 #include <sys/param.h> 42 #include <sys/systm.h> 43 #include <sys/conf.h> 44 #include <sys/device.h> 45 #include <sys/ioctl.h> 46 #include <sys/ttycom.h> 47 48 #include <dev/cons.h> 49 50 #include <machine/cpu.h> 51 #include <machine/iteioctl.h> 52 53 dev_type_open(iteopen); 54 dev_type_close(iteclose); 55 dev_type_read(iteread); 56 dev_type_write(itewrite); 57 dev_type_ioctl(iteioctl); 58 dev_type_tty(itetty); 59 dev_type_poll(itepoll); 60 61 const struct cdevsw ite_cdevsw = { 62 iteopen, iteclose, iteread, itewrite, iteioctl, 63 nostop, itetty, itepoll, nommap, D_TTY 64 }; 65 66 #if NWSDISPLAY > 0 67 extern const struct cdevsw wsdisplay_cdevsw; 68 #endif 69 70 void iteattach __P((int)); 71 72 static int ite_initted = 0; 73 static int ite_bell_freq = 1880; 74 static int ite_bell_length = 10; 75 static int ite_bell_volume = 100; 76 77 78 /*ARGSUSED*/ 79 void 80 iteattach(n) 81 int n; 82 { 83 #if NWSDISPLAY > 0 84 int maj; 85 86 maj = cdevsw_lookup_major(&wsdisplay_cdevsw); 87 KASSERT(maj != -1); 88 89 if (maj != major(cn_tab->cn_dev)) 90 return; 91 92 ite_initted = 1; 93 #endif 94 } 95 96 /* 97 * Tty handling functions 98 */ 99 100 /*ARGSUSED*/ 101 int 102 iteopen(dev, mode, devtype, p) 103 dev_t dev; 104 int mode; 105 int devtype; 106 struct proc *p; 107 { 108 return ite_initted ? (0) : (ENXIO); 109 } 110 111 /*ARGSUSED*/ 112 int 113 iteclose(dev, flag, mode, p) 114 dev_t dev; 115 int flag; 116 int mode; 117 struct proc *p; 118 { 119 return ite_initted ? (0) : (ENXIO); 120 } 121 122 /*ARGSUSED*/ 123 int 124 iteread(dev, uio, flag) 125 dev_t dev; 126 struct uio *uio; 127 int flag; 128 { 129 return ite_initted ? 130 (*wsdisplay_cdevsw.d_read)(cn_tab->cn_dev, uio, flag) : (ENXIO); 131 } 132 133 /*ARGSUSED*/ 134 int 135 itewrite(dev, uio, flag) 136 dev_t dev; 137 struct uio *uio; 138 int flag; 139 { 140 return ite_initted ? 141 (*wsdisplay_cdevsw.d_write)(cn_tab->cn_dev, uio, flag) : (ENXIO); 142 } 143 144 /*ARGSUSED*/ 145 struct tty * 146 itetty(dev) 147 dev_t dev; 148 { 149 return ite_initted ? (*wsdisplay_cdevsw.d_tty)(cn_tab->cn_dev) : (NULL); 150 } 151 152 /*ARGSUSED*/ 153 int 154 iteioctl(dev, cmd, addr, flag, p) 155 dev_t dev; 156 u_long cmd; 157 caddr_t addr; 158 int flag; 159 struct proc *p; 160 { 161 if (!ite_initted) 162 return (ENXIO); 163 164 switch (cmd) { 165 case ITEIOC_RINGBELL: 166 return mac68k_ring_bell(ite_bell_freq, 167 ite_bell_length, ite_bell_volume); 168 case ITEIOC_SETBELL: 169 { 170 struct bellparams *bp = (void *)addr; 171 172 /* Do some sanity checks. */ 173 if (bp->freq < 10 || bp->freq > 40000) 174 return (EINVAL); 175 if (bp->len < 0 || bp->len > 3600) 176 return (EINVAL); 177 if (bp->vol < 0 || bp->vol > 100) 178 return (EINVAL); 179 180 ite_bell_freq = bp->freq; 181 ite_bell_length = bp->len; 182 ite_bell_volume = bp->vol; 183 return (0); 184 } 185 case ITEIOC_GETBELL: 186 { 187 struct bellparams *bp = (void *)addr; 188 189 ite_bell_freq = bp->freq; 190 ite_bell_length = bp->len; 191 ite_bell_volume = bp->vol; 192 return (0); 193 } 194 default: 195 return ((*wsdisplay_cdevsw.d_ioctl)(cn_tab->cn_dev, cmd, 196 addr, flag, p)); 197 } 198 199 return (ENOTTY); 200 } 201 202 /*ARGSUSED*/ 203 int 204 itepoll(dev, events, p) 205 dev_t dev; 206 int events; 207 struct proc *p; 208 { 209 return ite_initted ? 210 (*wsdisplay_cdevsw.d_poll)(cn_tab->cn_dev, events, p) : (ENXIO); 211 } 212