Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / mac68k / dev / ite_compat.c
blob4275658e30753d2d66ac6dfd3d7489138823f95b
1 /* $NetBSD: ite_compat.c,v 1.9 2005/12/11 12:18:02 christos Exp $ */
3 /*
4 * Copyright (C) 2000 Scott Reynolds
5 * All rights reserved.
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.
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.
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.
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: ite_compat.c,v 1.9 2005/12/11 12:18:02 christos Exp $");
41 #include "ite.h"
42 #include "wsdisplay.h"
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/conf.h>
47 #include <sys/device.h>
48 #include <sys/ioctl.h>
49 #include <sys/ttycom.h>
51 #include <dev/cons.h>
53 #include <machine/cpu.h>
54 #include <machine/iteioctl.h>
56 dev_type_open(iteopen);
57 dev_type_close(iteclose);
58 dev_type_read(iteread);
59 dev_type_write(itewrite);
60 dev_type_ioctl(iteioctl);
61 dev_type_tty(itetty);
62 dev_type_poll(itepoll);
63 dev_type_kqfilter(itekqfilter);
65 const struct cdevsw ite_cdevsw = {
66 iteopen, iteclose, iteread, itewrite, iteioctl,
67 nostop, itetty, itepoll, nommap, itekqfilter, D_TTY
70 #if NWSDISPLAY > 0
71 extern const struct cdevsw wsdisplay_cdevsw;
72 #endif
74 void iteattach(int);
76 static int ite_initted = 0;
77 static int ite_bell_freq = 1880;
78 static int ite_bell_length = 10;
79 static int ite_bell_volume = 100;
82 /*ARGSUSED*/
83 void
84 iteattach(int n)
86 #if NWSDISPLAY > 0
87 int maj;
89 maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
90 KASSERT(maj != -1);
92 if (maj != major(cn_tab->cn_dev))
93 return;
95 ite_initted = 1;
96 #endif
100 * Tty handling functions
103 /*ARGSUSED*/
105 iteopen(dev_t dev, int mode, int devtype, struct lwp *l)
107 return ite_initted ? (0) : (ENXIO);
110 /*ARGSUSED*/
112 iteclose(dev_t dev, int flag, int mode, struct lwp *l)
114 return ite_initted ? (0) : (ENXIO);
117 /*ARGSUSED*/
119 iteread(dev_t dev, struct uio *uio, int flag)
121 return ite_initted ?
122 (*wsdisplay_cdevsw.d_read)(cn_tab->cn_dev, uio, flag) : (ENXIO);
125 /*ARGSUSED*/
127 itewrite(dev_t dev, struct uio *uio, int flag)
129 return ite_initted ?
130 (*wsdisplay_cdevsw.d_write)(cn_tab->cn_dev, uio, flag) : (ENXIO);
133 /*ARGSUSED*/
134 struct tty *
135 itetty(dev_t dev)
137 return ite_initted ? (*wsdisplay_cdevsw.d_tty)(cn_tab->cn_dev) : (NULL);
140 /*ARGSUSED*/
142 iteioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
144 if (!ite_initted)
145 return (ENXIO);
147 switch (cmd) {
148 case ITEIOC_RINGBELL:
149 return mac68k_ring_bell(ite_bell_freq,
150 ite_bell_length, ite_bell_volume);
151 case ITEIOC_SETBELL:
153 struct bellparams *bp = (void *)addr;
155 /* Do some sanity checks. */
156 if (bp->freq < 10 || bp->freq > 40000)
157 return (EINVAL);
158 if (bp->len < 0 || bp->len > 3600)
159 return (EINVAL);
160 if (bp->vol < 0 || bp->vol > 100)
161 return (EINVAL);
163 ite_bell_freq = bp->freq;
164 ite_bell_length = bp->len;
165 ite_bell_volume = bp->vol;
166 return (0);
168 case ITEIOC_GETBELL:
170 struct bellparams *bp = (void *)addr;
172 ite_bell_freq = bp->freq;
173 ite_bell_length = bp->len;
174 ite_bell_volume = bp->vol;
175 return (0);
177 default:
178 return ((*wsdisplay_cdevsw.d_ioctl)(cn_tab->cn_dev, cmd,
179 addr, flag, l));
182 return (ENOTTY);
185 /*ARGSUSED*/
187 itepoll(dev_t dev, int events, struct lwp *l)
189 return ite_initted ?
190 (*wsdisplay_cdevsw.d_poll)(cn_tab->cn_dev, events, l) : (ENXIO);
194 itekqfilter(dev_t dev, struct knote *kn)
196 return ite_initted ?
197 (*wsdisplay_cdevsw.d_kqfilter)(cn_tab->cn_dev, kn) : (ENXIO);