xref: /netbsd/sys/dev/sun/sunms.c (revision bf9ec67e)
1 /*	$NetBSD: sunms.c,v 1.7 2001/12/11 17:27:25 pk Exp $	*/
2 
3 /*
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This software was developed by the Computer Systems Engineering group
8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9  * contributed to Berkeley.
10  *
11  * All advertising materials mentioning features or use of this software
12  * must display the following acknowledgement:
13  *	This product includes software developed by the University of
14  *	California, Lawrence Berkeley Laboratory.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  * 3. All advertising materials mentioning features or use of this software
25  *    must display the following acknowledgement:
26  *	This product includes software developed by the University of
27  *	California, Berkeley and its contributors.
28  * 4. Neither the name of the University nor the names of its contributors
29  *    may be used to endorse or promote products derived from this software
30  *    without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42  * SUCH DAMAGE.
43  *
44  *	@(#)ms.c	8.1 (Berkeley) 6/11/93
45  */
46 
47 /*
48  * Mouse driver (/dev/mouse)
49  */
50 
51 /*
52  * Zilog Z8530 Dual UART driver (mouse interface)
53  *
54  * This is the "slave" driver that will be attached to
55  * the "zsc" driver for a Sun mouse.
56  */
57 
58 #include <sys/cdefs.h>
59 __KERNEL_RCSID(0, "$NetBSD: sunms.c,v 1.7 2001/12/11 17:27:25 pk Exp $");
60 
61 #include <sys/param.h>
62 #include <sys/systm.h>
63 #include <sys/conf.h>
64 #include <sys/device.h>
65 #include <sys/ioctl.h>
66 #include <sys/kernel.h>
67 #include <sys/proc.h>
68 #include <sys/signal.h>
69 #include <sys/signalvar.h>
70 #include <sys/time.h>
71 #include <sys/select.h>
72 #include <sys/syslog.h>
73 #include <sys/fcntl.h>
74 #include <sys/tty.h>
75 
76 #include <machine/vuid_event.h>
77 
78 #include <sys/tty.h>
79 #include <dev/sun/event_var.h>
80 #include <dev/sun/msvar.h>
81 #include <dev/sun/kbd_ms_ttyvar.h>
82 
83 #include "ms.h"
84 #if NMS > 0
85 
86 #ifdef SUN_MS_BPS
87 int	sunms_bps = SUN_MS_BPS;
88 #else
89 int	sunms_bps = MS_DEFAULT_BPS;
90 #endif
91 
92 static int	sunms_match(struct device *, struct cfdata *, void *);
93 static void	sunms_attach(struct device *, struct device *, void *);
94 static int	sunmsiopen(struct device *, int mode);
95 int	sunmsinput(int, struct tty *);
96 
97 struct cfattach ms_ca = {
98 	sizeof(struct ms_softc), sunms_match, sunms_attach
99 };
100 
101 struct  linesw sunms_disc =
102 	{ "sunms", 8, ttylopen, ttylclose, ttyerrio, ttyerrio, nullioctl,
103 	  sunmsinput, ttstart, nullmodem, ttpoll };	/* 8- SUNMOUSEDISC */
104 
105 /*
106  * ms_match: how is this zs channel configured?
107  */
108 int
109 sunms_match(parent, cf, aux)
110 	struct device *parent;
111 	struct cfdata *cf;
112 	void   *aux;
113 {
114 	struct kbd_ms_tty_attach_args *args = aux;
115 
116 	if (sunms_bps == 0)
117 		return 0;
118 
119 	if (strcmp(args->kmta_name, "mouse") == 0)
120 		return (1);
121 
122 	return 0;
123 }
124 
125 void
126 sunms_attach(parent, self, aux)
127 	struct device *parent, *self;
128 	void   *aux;
129 
130 {
131 	struct ms_softc *ms = (void *) self;
132 	struct kbd_ms_tty_attach_args *args = aux;
133 	struct cfdata *cf;
134 	struct tty *tp = args->kmta_tp;
135 	int ms_unit;
136 
137 	cf = ms->ms_dev.dv_cfdata;
138 	ms_unit = ms->ms_dev.dv_unit;
139 	tp->t_sc  = ms;
140 	tp->t_dev = args->kmta_dev;
141 	ms->ms_cs = (struct zs_chanstate *)tp;
142         ms->ms_deviopen = sunmsiopen;
143         ms->ms_deviclose = NULL;
144 
145 	printf("\n");
146 
147 	/* Initialize the speed, etc. */
148 	if (ttyldisc_add(&sunms_disc, -1) == -1)
149 		panic("sunms_attach: sunms_disc");
150 	tp->t_linesw = &sunms_disc;
151 	tp->t_oflag &= ~OPOST;
152 
153 	/* Initialize translator. */
154 	ms->ms_byteno = -1;
155 }
156 
157 /*
158  * Internal open routine.  This really should be inside com.c
159  * But I'm putting it here until we have a generic internal open
160  * mechanism.
161  */
162 int
163 sunmsiopen(dev, flags)
164 	struct device *dev;
165 	int flags;
166 {
167 	struct ms_softc *ms = (void *) dev;
168 	struct tty *tp = (struct tty *)ms->ms_cs;
169 	struct proc *p = curproc;
170 	struct termios t;
171 	int maj;
172 	int error;
173 
174 	maj = major(tp->t_dev);
175 	if (p == NULL)
176 		p = &proc0;
177 
178 	/* Open the lower device */
179 	if ((error = (*cdevsw[maj].d_open)(tp->t_dev, O_NONBLOCK|flags,
180 					   0/* ignored? */, p)) != 0)
181 		return (error);
182 
183 	/* Now configure it for the console. */
184 	tp->t_ospeed = 0;
185 	t.c_ispeed = sunms_bps;
186 	t.c_ospeed = sunms_bps;
187 	t.c_cflag =  CLOCAL|CS8;
188 	(*tp->t_param)(tp, &t);
189 
190 	return (0);
191 }
192 
193 int
194 sunmsinput(c, tp)
195 	int c;
196 	struct tty *tp;
197 {
198 	struct ms_softc *ms = (struct ms_softc *)tp->t_sc;
199 
200 	if (c & TTY_ERRORMASK) c = -1;
201 	else c &= TTY_CHARMASK;
202 
203 	/* Pass this up to the "middle" layer. */
204 	ms_input(ms, c);
205 	return (0);
206 }
207 #endif
208