xref: /netbsd/sys/arch/news68k/dev/ms_hb.c (revision c4a72b64)
1 /*	$NetBSD: ms_hb.c,v 1.4 2002/10/02 04:40:08 thorpej 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/bus.h>
38 #include <machine/cpu.h>
39 
40 #include <news68k/dev/hbvar.h>
41 #include <news68k/dev/ms_hbreg.h>
42 #include <news68k/dev/msvar.h>
43 
44 #include <news68k/news68k/isr.h>
45 
46 #define MS_SIZE 0x10 /* XXX */
47 #define MS_IPL 5
48 
49 int ms_hb_match(struct device *, struct cfdata *, void *);
50 void ms_hb_attach(struct device *, struct device *, void *);
51 void ms_hb_init(struct ms_softc *);
52 int ms_hb_intr(void *);
53 
54 int ms_hb_enable(void *);
55 int ms_hb_ioctl(void *, u_long, caddr_t, int, struct proc *);
56 void ms_hb_disable(void *);
57 
58 CFATTACH_DECL(ms_hb, sizeof(struct ms_softc),
59     ms_hb_match, ms_hb_attach, NULL, NULL);
60 
61 struct wsmouse_accessops ms_hb_accessops = {
62 	ms_hb_enable,
63 	ms_hb_ioctl,
64 	ms_hb_disable
65 };
66 
67 int
68 ms_hb_match(parent, cf, aux)
69 	struct device *parent;
70 	struct cfdata *cf;
71 	void *aux;
72 {
73 	struct hb_attach_args *ha = aux;
74 	u_int addr;
75 
76 	if (strcmp(ha->ha_name, "ms"))
77 		return 0;
78 
79 	/* XXX no default address */
80 	if (ha->ha_address == -1)
81 		return 0;
82 
83 	addr = IIOV(ha->ha_address); /* XXX */
84 
85 	if (badaddr((void *)addr, 1))
86 		return 0;
87 
88 	return 1;
89 }
90 
91 void
92 ms_hb_attach(parent, self, aux)
93 	struct device *parent;
94 	struct device *self;
95 	void *aux;
96 {
97 	struct ms_softc *sc = (void *)self;
98 	struct hb_attach_args *ha = aux;
99 	bus_space_tag_t bt = ha->ha_bust;
100 	bus_space_handle_t bh;
101 	struct wsmousedev_attach_args wsa;
102 	int ipl;
103 
104 	if (bus_space_map(bt, ha->ha_address, MS_SIZE, 0, &bh) != 0) {
105 		printf("can't map device space\n");
106 		return;
107 	}
108 
109 	printf("\n");
110 
111 	sc->sc_bt = bt;
112 	sc->sc_bh = bh;
113 	sc->sc_offset = MS_REG_DATA;
114 	ipl = ha->ha_ipl;
115 	if (ipl == -1)
116 		ipl = MS_IPL;
117 
118 	ms_hb_init(sc);
119 
120 	isrlink_autovec(ms_hb_intr, (void *)sc, ipl, ISRPRI_TTY);
121 
122 	wsa.accessops = &ms_hb_accessops;
123 	wsa.accesscookie = sc;
124 	sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint);
125 }
126 
127 void
128 ms_hb_init(sc)
129 	struct ms_softc *sc;
130 {
131 	bus_space_tag_t bt = sc->sc_bt;
132 	bus_space_handle_t bh = sc->sc_bh;
133 
134 	bus_space_write_1(bt, bh, MS_REG_RESET, 0);
135 	bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
136 }
137 
138 int
139 ms_hb_intr(v)
140 	void *v;
141 {
142 	struct ms_softc *sc = v;
143 	bus_space_tag_t bt = sc->sc_bt;
144 	bus_space_handle_t bh = sc->sc_bh;
145 	int handled = 0;
146 
147 	while ((bus_space_read_1(bt, bh, MS_REG_STAT) & MSSTAT_RDY) != 0) {
148 		ms_intr(sc);
149 		handled = 1;
150 	}
151 	if (handled)
152 		bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
153 
154 	return handled;
155 }
156 
157 int
158 ms_hb_enable(v)
159 	void *v;
160 {
161 	struct ms_softc *sc = v;
162 	bus_space_tag_t bt = sc->sc_bt;
163 	bus_space_handle_t bh = sc->sc_bh;
164 
165 	bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
166 
167 	return 0;
168 }
169 
170 void
171 ms_hb_disable(v)
172 	void *v;
173 {
174 	struct ms_softc *sc = v;
175 	bus_space_tag_t bt = sc->sc_bt;
176 	bus_space_handle_t bh = sc->sc_bh;
177 
178 	bus_space_write_1(bt, bh, MS_REG_INTE, 0);
179 }
180 
181 int
182 ms_hb_ioctl(v, cmd, data, flag, p)
183 	void *v;
184 	u_long cmd;
185 	caddr_t data;
186 	int flag;
187 	struct proc *p;
188 {
189 	return EPASSTHROUGH;
190 }
191