xref: /netbsd/sys/arch/news68k/dev/ms_kbc.c (revision bf9ec67e)
1 /*	$NetBSD: ms_kbc.c,v 1.2 2002/03/17 19:40:45 atatat Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 Izumi Tsutsui.  All rights reserved.
5  * Copyright (c) 2000 Tsubai Masanari.  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
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <sys/param.h>
31 #include <sys/device.h>
32 #include <sys/systm.h>
33 
34 #include <dev/wscons/wsconsio.h>
35 #include <dev/wscons/wsmousevar.h>
36 
37 #include <machine/cpu.h>
38 #include <machine/bus.h>
39 
40 #include <news68k/dev/kbcreg.h>
41 #include <news68k/dev/kbcvar.h>
42 #include <news68k/dev/msvar.h>
43 
44 #include <news68k/news68k/isr.h>
45 
46 int ms_kbc_match(struct device *, struct cfdata *, void *);
47 void ms_kbc_attach(struct device *, struct device *, void *);
48 void ms_kbc_init(struct ms_softc *);
49 int ms_kbc_intr(void *);
50 
51 int ms_kbc_enable(void *);
52 void ms_kbc_disable(void *);
53 int ms_kbc_ioctl(void *, u_long, caddr_t, int, struct proc *);
54 
55 struct cfattach ms_kbc_ca = {
56 	sizeof(struct ms_softc), ms_kbc_match, ms_kbc_attach
57 };
58 
59 struct wsmouse_accessops ms_kbc_accessops = {
60 	ms_kbc_enable,
61 	ms_kbc_ioctl,
62 	ms_kbc_disable
63 };
64 
65 int
66 ms_kbc_match(parent, cf, aux)
67 	struct device *parent;
68 	struct cfdata *cf;
69 	void *aux;
70 {
71 	struct kbc_attach_args *ka = aux;
72 
73 	if (strcmp(ka->ka_name, "ms"))
74 		return 0;
75 
76 	return 1;
77 }
78 
79 void
80 ms_kbc_attach(parent, self, aux)
81 	struct device *parent, *self;
82 	void *aux;
83 {
84 	struct ms_softc *sc = (void *)self;
85 	struct kbc_attach_args *ka = aux;
86 	struct wsmousedev_attach_args wsa;
87 	int ipl;
88 
89 	printf("\n");
90 
91 	sc->sc_bt = ka->ka_bt;
92 	sc->sc_bh = ka->ka_bh;
93 	sc->sc_offset = KBC_MSREG_DATA;
94 	ipl = ka->ka_ipl;
95 
96 	ms_kbc_init(sc);
97 
98 	isrlink_autovec(ms_kbc_intr, (void *)sc, ipl, ISRPRI_TTY);
99 
100 	wsa.accessops = &ms_kbc_accessops;
101 	wsa.accesscookie = sc;
102 	sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint);
103 }
104 
105 void
106 ms_kbc_init(sc)
107 	struct ms_softc *sc;
108 {
109 	bus_space_tag_t bt = sc->sc_bt;
110 	bus_space_handle_t bh = sc->sc_bh;
111 
112 	bus_space_write_1(bt, bh, KBC_MSREG_RESET, 0);
113 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
114 }
115 
116 int
117 ms_kbc_intr(v)
118 	void *v;
119 {
120 	struct ms_softc *sc = v;
121 	bus_space_tag_t bt = sc->sc_bt;
122 	bus_space_handle_t bh = sc->sc_bh;
123 	int handled = 0;
124 
125 	while (bus_space_read_1(bt, bh, KBC_MSREG_STAT) & KBCSTAT_MSRDY) {
126 		ms_intr(sc);
127 		handled = 1;
128 	}
129 	if (handled)
130 		bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
131 
132 	return handled;
133 }
134 
135 int
136 ms_kbc_enable(v)
137 	void *v;
138 {
139 	struct ms_softc *sc = v;
140 	bus_space_tag_t bt = sc->sc_bt;
141 	bus_space_handle_t bh = sc->sc_bh;
142 
143 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
144 
145 	return 0;
146 }
147 
148 void
149 ms_kbc_disable(v)
150 	void *v;
151 {
152 	struct ms_softc *sc = v;
153 	bus_space_tag_t bt = sc->sc_bt;
154 	bus_space_handle_t bh = sc->sc_bh;
155 
156 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, 0);
157 }
158 
159 int
160 ms_kbc_ioctl(v, cmd, data, flag, p)
161 	void *v;
162 	u_long cmd;
163 	caddr_t data;
164 	int flag;
165 	struct proc *p;
166 {
167 	return EPASSTHROUGH;
168 }
169