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