Home | History | Annotate | Line # | Download | only in dev
ite_compat.c revision 1.6
      1 /*	$NetBSD: ite_compat.c,v 1.6 2002/10/23 09:11:28 jdolecek 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 dev_type_kqfilter(itekqfilter);
     61 
     62 const struct cdevsw ite_cdevsw = {
     63 	iteopen, iteclose, iteread, itewrite, iteioctl,
     64 	nostop, itetty, itepoll, nommap, itekqfilter, D_TTY
     65 };
     66 
     67 #if NWSDISPLAY > 0
     68 extern const struct cdevsw wsdisplay_cdevsw;
     69 #endif
     70 
     71 void		iteattach __P((int));
     72 
     73 static int	ite_initted = 0;
     74 static int	ite_bell_freq = 1880;
     75 static int	ite_bell_length = 10;
     76 static int	ite_bell_volume = 100;
     77 
     78 
     79 /*ARGSUSED*/
     80 void
     81 iteattach(n)
     82 	int n;
     83 {
     84 #if NWSDISPLAY > 0
     85 	int maj;
     86 
     87 	maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
     88 	KASSERT(maj != -1);
     89 
     90 	if (maj != major(cn_tab->cn_dev))
     91 		return;
     92 
     93 	ite_initted = 1;
     94 #endif
     95 }
     96 
     97 /*
     98  * Tty handling functions
     99  */
    100 
    101 /*ARGSUSED*/
    102 int
    103 iteopen(dev, mode, devtype, p)
    104 	dev_t dev;
    105 	int mode;
    106 	int devtype;
    107 	struct proc *p;
    108 {
    109 	return ite_initted ? (0) : (ENXIO);
    110 }
    111 
    112 /*ARGSUSED*/
    113 int
    114 iteclose(dev, flag, mode, p)
    115 	dev_t dev;
    116 	int flag;
    117 	int mode;
    118 	struct proc *p;
    119 {
    120 	return ite_initted ? (0) : (ENXIO);
    121 }
    122 
    123 /*ARGSUSED*/
    124 int
    125 iteread(dev, uio, flag)
    126 	dev_t dev;
    127 	struct uio *uio;
    128 	int flag;
    129 {
    130 	return ite_initted ?
    131 	    (*wsdisplay_cdevsw.d_read)(cn_tab->cn_dev, uio, flag) : (ENXIO);
    132 }
    133 
    134 /*ARGSUSED*/
    135 int
    136 itewrite(dev, uio, flag)
    137 	dev_t dev;
    138 	struct uio *uio;
    139 	int flag;
    140 {
    141 	return ite_initted ?
    142 	    (*wsdisplay_cdevsw.d_write)(cn_tab->cn_dev, uio, flag) : (ENXIO);
    143 }
    144 
    145 /*ARGSUSED*/
    146 struct tty *
    147 itetty(dev)
    148 	dev_t dev;
    149 {
    150 	return ite_initted ? (*wsdisplay_cdevsw.d_tty)(cn_tab->cn_dev) : (NULL);
    151 }
    152 
    153 /*ARGSUSED*/
    154 int
    155 iteioctl(dev, cmd, addr, flag, p)
    156 	dev_t dev;
    157 	u_long cmd;
    158 	caddr_t addr;
    159 	int flag;
    160 	struct proc *p;
    161 {
    162 	if (!ite_initted)
    163 		return (ENXIO);
    164 
    165 	switch (cmd) {
    166 	case ITEIOC_RINGBELL:
    167 		return mac68k_ring_bell(ite_bell_freq,
    168 		    ite_bell_length, ite_bell_volume);
    169 	case ITEIOC_SETBELL:
    170 		{
    171 			struct bellparams *bp = (void *)addr;
    172 
    173 			/* Do some sanity checks. */
    174 			if (bp->freq < 10 || bp->freq > 40000)
    175 				return (EINVAL);
    176 			if (bp->len < 0 || bp->len > 3600)
    177 				return (EINVAL);
    178 			if (bp->vol < 0 || bp->vol > 100)
    179 				return (EINVAL);
    180 
    181 			ite_bell_freq = bp->freq;
    182 			ite_bell_length = bp->len;
    183 			ite_bell_volume = bp->vol;
    184 			return (0);
    185 		}
    186 	case ITEIOC_GETBELL:
    187 		{
    188 			struct bellparams *bp = (void *)addr;
    189 
    190 			ite_bell_freq = bp->freq;
    191 			ite_bell_length = bp->len;
    192 			ite_bell_volume = bp->vol;
    193 			return (0);
    194 		}
    195 	default:
    196 		return ((*wsdisplay_cdevsw.d_ioctl)(cn_tab->cn_dev, cmd,
    197 						    addr, flag, p));
    198 	}
    199 
    200 	return (ENOTTY);
    201 }
    202 
    203 /*ARGSUSED*/
    204 int
    205 itepoll(dev, events, p)
    206 	dev_t dev;
    207 	int events;
    208 	struct proc *p;
    209 {
    210 	return ite_initted ?
    211 	    (*wsdisplay_cdevsw.d_poll)(cn_tab->cn_dev, events, p) : (ENXIO);
    212 }
    213 
    214 int
    215 itekqfilter(dev, kn)
    216 	dev_t dev;
    217 	struct knote *kn;
    218 {
    219 	return ite_initted ?
    220 	    (*wsdisplay_cdevsw.d_kqfilter)(cn_tab->cn_dev, kn) : (ENXIO);
    221 }
    222