xref: /netbsd-src/sys/arch/mac68k/dev/ite_compat.c (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: ite_compat.c,v 1.10 2007/03/04 06:00:07 christos 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.10 2007/03/04 06:00:07 christos 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(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(int n)
85 {
86 #if NWSDISPLAY > 0
87 	int maj;
88 
89 	maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
90 	KASSERT(maj != -1);
91 
92 	if (maj != major(cn_tab->cn_dev))
93 		return;
94 
95 	ite_initted = 1;
96 #endif
97 }
98 
99 /*
100  * Tty handling functions
101  */
102 
103 /*ARGSUSED*/
104 int
105 iteopen(dev_t dev, int mode, int devtype, struct lwp *l)
106 {
107 	return ite_initted ? (0) : (ENXIO);
108 }
109 
110 /*ARGSUSED*/
111 int
112 iteclose(dev_t dev, int flag, int mode, struct lwp *l)
113 {
114 	return ite_initted ? (0) : (ENXIO);
115 }
116 
117 /*ARGSUSED*/
118 int
119 iteread(dev_t dev, struct uio *uio, int flag)
120 {
121 	return ite_initted ?
122 	    (*wsdisplay_cdevsw.d_read)(cn_tab->cn_dev, uio, flag) : (ENXIO);
123 }
124 
125 /*ARGSUSED*/
126 int
127 itewrite(dev_t dev, struct uio *uio, int flag)
128 {
129 	return ite_initted ?
130 	    (*wsdisplay_cdevsw.d_write)(cn_tab->cn_dev, uio, flag) : (ENXIO);
131 }
132 
133 /*ARGSUSED*/
134 struct tty *
135 itetty(dev_t dev)
136 {
137 	return ite_initted ? (*wsdisplay_cdevsw.d_tty)(cn_tab->cn_dev) : (NULL);
138 }
139 
140 /*ARGSUSED*/
141 int
142 iteioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
143 {
144 	if (!ite_initted)
145 		return (ENXIO);
146 
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:
152 		{
153 			struct bellparams *bp = (void *)addr;
154 
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);
162 
163 			ite_bell_freq = bp->freq;
164 			ite_bell_length = bp->len;
165 			ite_bell_volume = bp->vol;
166 			return (0);
167 		}
168 	case ITEIOC_GETBELL:
169 		{
170 			struct bellparams *bp = (void *)addr;
171 
172 			ite_bell_freq = bp->freq;
173 			ite_bell_length = bp->len;
174 			ite_bell_volume = bp->vol;
175 			return (0);
176 		}
177 	default:
178 		return ((*wsdisplay_cdevsw.d_ioctl)(cn_tab->cn_dev, cmd,
179 						    addr, flag, l));
180 	}
181 
182 	return (ENOTTY);
183 }
184 
185 /*ARGSUSED*/
186 int
187 itepoll(dev_t dev, int events, struct lwp *l)
188 {
189 	return ite_initted ?
190 	    (*wsdisplay_cdevsw.d_poll)(cn_tab->cn_dev, events, l) : (ENXIO);
191 }
192 
193 int
194 itekqfilter(dev_t dev, struct knote *kn)
195 {
196 	return ite_initted ?
197 	    (*wsdisplay_cdevsw.d_kqfilter)(cn_tab->cn_dev, kn) : (ENXIO);
198 }
199