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