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