1 /* $NetBSD: ite_compat.c,v 1.2 2000/02/14 07:01:46 scottr 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 47 #include <dev/cons.h> 48 49 #include <machine/cpu.h> 50 #include <machine/iteioctl.h> 51 52 cdev_decl(ite); 53 cdev_decl(wsdisplay); 54 void iteattach __P((int)); 55 56 static int ite_initted = 0; 57 static int ite_bell_freq = 1880; 58 static int ite_bell_length = 10; 59 static int ite_bell_volume = 100; 60 61 62 /*ARGSUSED*/ 63 void 64 iteattach(n) 65 int n; 66 { 67 #if NWSDISPLAY > 0 68 int maj; 69 70 for (maj = 0; maj < nchrdev; maj++) 71 if (cdevsw[maj].d_open == wsdisplayopen) 72 break; 73 KASSERT(maj < nchrdev); 74 75 if (maj != major(cn_tab->cn_dev)) 76 return; 77 78 cn_tab->cn_dev = cn_tab->cn_dev; 79 ite_initted = 1; 80 #endif 81 } 82 83 /* 84 * Tty handling functions 85 */ 86 87 /*ARGSUSED*/ 88 int 89 iteopen(dev, mode, devtype, p) 90 dev_t dev; 91 int mode; 92 int devtype; 93 struct proc *p; 94 { 95 return ite_initted ? 96 wsdisplayopen(cn_tab->cn_dev, mode, devtype, p) : (ENXIO); 97 } 98 99 /*ARGSUSED*/ 100 int 101 iteclose(dev, flag, mode, p) 102 dev_t dev; 103 int flag; 104 int mode; 105 struct proc *p; 106 { 107 return ite_initted ? 108 wsdisplayclose(cn_tab->cn_dev, flag, mode, p) : (ENXIO); 109 } 110 111 /*ARGSUSED*/ 112 int 113 iteread(dev, uio, flag) 114 dev_t dev; 115 struct uio *uio; 116 int flag; 117 { 118 return ite_initted ? 119 wsdisplayread(cn_tab->cn_dev, uio, flag) : (ENXIO); 120 } 121 122 /*ARGSUSED*/ 123 int 124 itewrite(dev, uio, flag) 125 dev_t dev; 126 struct uio *uio; 127 int flag; 128 { 129 return ite_initted ? 130 wsdisplaywrite(cn_tab->cn_dev, uio, flag) : (ENXIO); 131 } 132 133 /*ARGSUSED*/ 134 struct tty * 135 itetty(dev) 136 dev_t dev; 137 { 138 return ite_initted ? wsdisplaytty(cn_tab->cn_dev) : (NULL); 139 } 140 141 /*ARGSUSED*/ 142 void 143 itestop(struct tty *tp, int flag) 144 { 145 } 146 147 /*ARGSUSED*/ 148 int 149 iteioctl(dev, cmd, addr, flag, p) 150 dev_t dev; 151 u_long cmd; 152 caddr_t addr; 153 int flag; 154 struct proc *p; 155 { 156 if (!ite_initted) 157 return (ENXIO); 158 159 switch (cmd) { 160 case ITEIOC_RINGBELL: 161 return mac68k_ring_bell(ite_bell_freq, 162 ite_bell_length, ite_bell_volume); 163 case ITEIOC_SETBELL: 164 { 165 struct bellparams *bp = (void *)addr; 166 167 /* Do some sanity checks. */ 168 if (bp->freq < 10 || bp->freq > 40000) 169 return (EINVAL); 170 if (bp->len < 0 || bp->len > 3600) 171 return (EINVAL); 172 if (bp->vol < 0 || bp->vol > 100) 173 return (EINVAL); 174 175 ite_bell_freq = bp->freq; 176 ite_bell_length = bp->len; 177 ite_bell_volume = bp->vol; 178 return (0); 179 } 180 case ITEIOC_GETBELL: 181 { 182 struct bellparams *bp = (void *)addr; 183 184 ite_bell_freq = bp->freq; 185 ite_bell_length = bp->len; 186 ite_bell_volume = bp->vol; 187 return (0); 188 } 189 default: 190 return wsdisplayioctl(cn_tab->cn_dev, cmd, addr, flag, p); 191 } 192 193 return (ENOTTY); 194 } 195