xref: /netbsd-src/sys/arch/mac68k/dev/ite_compat.c (revision a68f9396b633362f45c880fc202c3c9152a1101b)
1 /*	$NetBSD: ite_compat.c,v 1.11 2014/03/16 05:20:24 dholland 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.11 2014/03/16 05:20:24 dholland 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 	.d_open = iteopen,
67 	.d_close = iteclose,
68 	.d_read = iteread,
69 	.d_write = itewrite,
70 	.d_ioctl = iteioctl,
71 	.d_stop = nostop,
72 	.d_tty = itetty,
73 	.d_poll = itepoll,
74 	.d_mmap = nommap,
75 	.d_kqfilter = itekqfilter,
76 	.d_flag = D_TTY
77 };
78 
79 #if NWSDISPLAY > 0
80 extern const struct cdevsw wsdisplay_cdevsw;
81 #endif
82 
83 void		iteattach(int);
84 
85 static int	ite_initted = 0;
86 static int	ite_bell_freq = 1880;
87 static int	ite_bell_length = 10;
88 static int	ite_bell_volume = 100;
89 
90 
91 /*ARGSUSED*/
92 void
93 iteattach(int n)
94 {
95 #if NWSDISPLAY > 0
96 	int maj;
97 
98 	maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
99 	KASSERT(maj != -1);
100 
101 	if (maj != major(cn_tab->cn_dev))
102 		return;
103 
104 	ite_initted = 1;
105 #endif
106 }
107 
108 /*
109  * Tty handling functions
110  */
111 
112 /*ARGSUSED*/
113 int
114 iteopen(dev_t dev, int mode, int devtype, struct lwp *l)
115 {
116 	return ite_initted ? (0) : (ENXIO);
117 }
118 
119 /*ARGSUSED*/
120 int
121 iteclose(dev_t dev, int flag, int mode, struct lwp *l)
122 {
123 	return ite_initted ? (0) : (ENXIO);
124 }
125 
126 /*ARGSUSED*/
127 int
128 iteread(dev_t dev, struct uio *uio, int flag)
129 {
130 	return ite_initted ?
131 	    (*wsdisplay_cdevsw.d_read)(cn_tab->cn_dev, uio, flag) : (ENXIO);
132 }
133 
134 /*ARGSUSED*/
135 int
136 itewrite(dev_t dev, struct uio *uio, int flag)
137 {
138 	return ite_initted ?
139 	    (*wsdisplay_cdevsw.d_write)(cn_tab->cn_dev, uio, flag) : (ENXIO);
140 }
141 
142 /*ARGSUSED*/
143 struct tty *
144 itetty(dev_t dev)
145 {
146 	return ite_initted ? (*wsdisplay_cdevsw.d_tty)(cn_tab->cn_dev) : (NULL);
147 }
148 
149 /*ARGSUSED*/
150 int
151 iteioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
152 {
153 	if (!ite_initted)
154 		return (ENXIO);
155 
156 	switch (cmd) {
157 	case ITEIOC_RINGBELL:
158 		return mac68k_ring_bell(ite_bell_freq,
159 		    ite_bell_length, ite_bell_volume);
160 	case ITEIOC_SETBELL:
161 		{
162 			struct bellparams *bp = (void *)addr;
163 
164 			/* Do some sanity checks. */
165 			if (bp->freq < 10 || bp->freq > 40000)
166 				return (EINVAL);
167 			if (bp->len < 0 || bp->len > 3600)
168 				return (EINVAL);
169 			if (bp->vol < 0 || bp->vol > 100)
170 				return (EINVAL);
171 
172 			ite_bell_freq = bp->freq;
173 			ite_bell_length = bp->len;
174 			ite_bell_volume = bp->vol;
175 			return (0);
176 		}
177 	case ITEIOC_GETBELL:
178 		{
179 			struct bellparams *bp = (void *)addr;
180 
181 			ite_bell_freq = bp->freq;
182 			ite_bell_length = bp->len;
183 			ite_bell_volume = bp->vol;
184 			return (0);
185 		}
186 	default:
187 		return ((*wsdisplay_cdevsw.d_ioctl)(cn_tab->cn_dev, cmd,
188 						    addr, flag, l));
189 	}
190 
191 	return (ENOTTY);
192 }
193 
194 /*ARGSUSED*/
195 int
196 itepoll(dev_t dev, int events, struct lwp *l)
197 {
198 	return ite_initted ?
199 	    (*wsdisplay_cdevsw.d_poll)(cn_tab->cn_dev, events, l) : (ENXIO);
200 }
201 
202 int
203 itekqfilter(dev_t dev, struct knote *kn)
204 {
205 	return ite_initted ?
206 	    (*wsdisplay_cdevsw.d_kqfilter)(cn_tab->cn_dev, kn) : (ENXIO);
207 }
208