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