ms_hb.c revision 1.1.2.2 1 1.1.2.2 bouyer /* $NetBSD: ms_hb.c,v 1.1.2.2 2001/02/11 19:11:17 bouyer Exp $ */
2 1.1.2.2 bouyer
3 1.1.2.2 bouyer /*-
4 1.1.2.2 bouyer * Copyright (c) 2001 Izumi Tsutsui. All rights reserved.
5 1.1.2.2 bouyer * Copyright (c) 2000 Tsubai Masanari. All rights reserved.
6 1.1.2.2 bouyer *
7 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
8 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
9 1.1.2.2 bouyer * are met:
10 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
11 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
12 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
14 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
15 1.1.2.2 bouyer * 3. The name of the author may not be used to endorse or promote products
16 1.1.2.2 bouyer * derived from this software without specific prior written permission.
17 1.1.2.2 bouyer *
18 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1.2.2 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1.2.2 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1.2.2 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1.2.2 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1.2.2 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1.2.2 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1.2.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 1.1.2.2 bouyer * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1.2.2 bouyer */
29 1.1.2.2 bouyer
30 1.1.2.2 bouyer #include <sys/param.h>
31 1.1.2.2 bouyer #include <sys/device.h>
32 1.1.2.2 bouyer #include <sys/systm.h>
33 1.1.2.2 bouyer
34 1.1.2.2 bouyer #include <dev/wscons/wsconsio.h>
35 1.1.2.2 bouyer #include <dev/wscons/wsmousevar.h>
36 1.1.2.2 bouyer
37 1.1.2.2 bouyer #include <machine/bus.h>
38 1.1.2.2 bouyer #include <machine/cpu.h>
39 1.1.2.2 bouyer
40 1.1.2.2 bouyer #include <news68k/dev/hbvar.h>
41 1.1.2.2 bouyer #include <news68k/dev/ms_hbreg.h>
42 1.1.2.2 bouyer #include <news68k/dev/msvar.h>
43 1.1.2.2 bouyer
44 1.1.2.2 bouyer #include <news68k/news68k/isr.h>
45 1.1.2.2 bouyer
46 1.1.2.2 bouyer #define MS_SIZE 0x10 /* XXX */
47 1.1.2.2 bouyer #define MS_IPL 5
48 1.1.2.2 bouyer
49 1.1.2.2 bouyer int ms_hb_match(struct device *, struct cfdata *, void *);
50 1.1.2.2 bouyer void ms_hb_attach(struct device *, struct device *, void *);
51 1.1.2.2 bouyer void ms_hb_init(struct ms_softc *);
52 1.1.2.2 bouyer int ms_hb_intr(void *);
53 1.1.2.2 bouyer
54 1.1.2.2 bouyer int ms_hb_enable(void *);
55 1.1.2.2 bouyer int ms_hb_ioctl(void *, u_long, caddr_t, int, struct proc *);
56 1.1.2.2 bouyer void ms_hb_disable(void *);
57 1.1.2.2 bouyer
58 1.1.2.2 bouyer struct cfattach ms_hb_ca = {
59 1.1.2.2 bouyer sizeof(struct ms_softc), ms_hb_match, ms_hb_attach
60 1.1.2.2 bouyer };
61 1.1.2.2 bouyer
62 1.1.2.2 bouyer struct wsmouse_accessops ms_hb_accessops = {
63 1.1.2.2 bouyer ms_hb_enable,
64 1.1.2.2 bouyer ms_hb_ioctl,
65 1.1.2.2 bouyer ms_hb_disable
66 1.1.2.2 bouyer };
67 1.1.2.2 bouyer
68 1.1.2.2 bouyer int
69 1.1.2.2 bouyer ms_hb_match(parent, cf, aux)
70 1.1.2.2 bouyer struct device *parent;
71 1.1.2.2 bouyer struct cfdata *cf;
72 1.1.2.2 bouyer void *aux;
73 1.1.2.2 bouyer {
74 1.1.2.2 bouyer struct hb_attach_args *ha = aux;
75 1.1.2.2 bouyer u_int addr;
76 1.1.2.2 bouyer
77 1.1.2.2 bouyer if (strcmp(ha->ha_name, "ms"))
78 1.1.2.2 bouyer return 0;
79 1.1.2.2 bouyer
80 1.1.2.2 bouyer /* XXX no default address */
81 1.1.2.2 bouyer if (ha->ha_address == -1)
82 1.1.2.2 bouyer return 0;
83 1.1.2.2 bouyer
84 1.1.2.2 bouyer addr = IIOV(ha->ha_address); /* XXX */
85 1.1.2.2 bouyer
86 1.1.2.2 bouyer if (badaddr((void *)addr, 1))
87 1.1.2.2 bouyer return 0;
88 1.1.2.2 bouyer
89 1.1.2.2 bouyer return 1;
90 1.1.2.2 bouyer }
91 1.1.2.2 bouyer
92 1.1.2.2 bouyer void
93 1.1.2.2 bouyer ms_hb_attach(parent, self, aux)
94 1.1.2.2 bouyer struct device *parent;
95 1.1.2.2 bouyer struct device *self;
96 1.1.2.2 bouyer void *aux;
97 1.1.2.2 bouyer {
98 1.1.2.2 bouyer struct ms_softc *sc = (void *)self;
99 1.1.2.2 bouyer struct hb_attach_args *ha = aux;
100 1.1.2.2 bouyer bus_space_tag_t bt = ha->ha_bust;
101 1.1.2.2 bouyer bus_space_handle_t bh;
102 1.1.2.2 bouyer struct wsmousedev_attach_args wsa;
103 1.1.2.2 bouyer int ipl;
104 1.1.2.2 bouyer
105 1.1.2.2 bouyer if (bus_space_map(bt, ha->ha_address, MS_SIZE, 0, &bh) != 0) {
106 1.1.2.2 bouyer printf("can't map device space\n");
107 1.1.2.2 bouyer return;
108 1.1.2.2 bouyer }
109 1.1.2.2 bouyer
110 1.1.2.2 bouyer printf("\n");
111 1.1.2.2 bouyer
112 1.1.2.2 bouyer sc->sc_bt = bt;
113 1.1.2.2 bouyer sc->sc_bh = bh;
114 1.1.2.2 bouyer sc->sc_offset = MS_REG_DATA;
115 1.1.2.2 bouyer ipl = ha->ha_ipl;
116 1.1.2.2 bouyer if (ipl == -1)
117 1.1.2.2 bouyer ipl = MS_IPL;
118 1.1.2.2 bouyer
119 1.1.2.2 bouyer ms_hb_init(sc);
120 1.1.2.2 bouyer
121 1.1.2.2 bouyer isrlink_autovec(ms_hb_intr, (void *)sc, ipl, ISRPRI_TTY);
122 1.1.2.2 bouyer
123 1.1.2.2 bouyer wsa.accessops = &ms_hb_accessops;
124 1.1.2.2 bouyer wsa.accesscookie = sc;
125 1.1.2.2 bouyer sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint);
126 1.1.2.2 bouyer }
127 1.1.2.2 bouyer
128 1.1.2.2 bouyer void
129 1.1.2.2 bouyer ms_hb_init(sc)
130 1.1.2.2 bouyer struct ms_softc *sc;
131 1.1.2.2 bouyer {
132 1.1.2.2 bouyer bus_space_tag_t bt = sc->sc_bt;
133 1.1.2.2 bouyer bus_space_handle_t bh = sc->sc_bh;
134 1.1.2.2 bouyer
135 1.1.2.2 bouyer bus_space_write_1(bt, bh, MS_REG_RESET, 0);
136 1.1.2.2 bouyer bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
137 1.1.2.2 bouyer }
138 1.1.2.2 bouyer
139 1.1.2.2 bouyer int
140 1.1.2.2 bouyer ms_hb_intr(v)
141 1.1.2.2 bouyer void *v;
142 1.1.2.2 bouyer {
143 1.1.2.2 bouyer struct ms_softc *sc = v;
144 1.1.2.2 bouyer bus_space_tag_t bt = sc->sc_bt;
145 1.1.2.2 bouyer bus_space_handle_t bh = sc->sc_bh;
146 1.1.2.2 bouyer int handled = 0;
147 1.1.2.2 bouyer
148 1.1.2.2 bouyer while ((bus_space_read_1(bt, bh, MS_REG_STAT) & MSSTAT_RDY) != 0) {
149 1.1.2.2 bouyer ms_intr(sc);
150 1.1.2.2 bouyer handled = 1;
151 1.1.2.2 bouyer }
152 1.1.2.2 bouyer if (handled)
153 1.1.2.2 bouyer bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
154 1.1.2.2 bouyer
155 1.1.2.2 bouyer return handled;
156 1.1.2.2 bouyer }
157 1.1.2.2 bouyer
158 1.1.2.2 bouyer int
159 1.1.2.2 bouyer ms_hb_enable(v)
160 1.1.2.2 bouyer void *v;
161 1.1.2.2 bouyer {
162 1.1.2.2 bouyer struct ms_softc *sc = v;
163 1.1.2.2 bouyer bus_space_tag_t bt = sc->sc_bt;
164 1.1.2.2 bouyer bus_space_handle_t bh = sc->sc_bh;
165 1.1.2.2 bouyer
166 1.1.2.2 bouyer bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
167 1.1.2.2 bouyer
168 1.1.2.2 bouyer return 0;
169 1.1.2.2 bouyer }
170 1.1.2.2 bouyer
171 1.1.2.2 bouyer void
172 1.1.2.2 bouyer ms_hb_disable(v)
173 1.1.2.2 bouyer void *v;
174 1.1.2.2 bouyer {
175 1.1.2.2 bouyer struct ms_softc *sc = v;
176 1.1.2.2 bouyer bus_space_tag_t bt = sc->sc_bt;
177 1.1.2.2 bouyer bus_space_handle_t bh = sc->sc_bh;
178 1.1.2.2 bouyer
179 1.1.2.2 bouyer bus_space_write_1(bt, bh, MS_REG_INTE, 0);
180 1.1.2.2 bouyer }
181 1.1.2.2 bouyer
182 1.1.2.2 bouyer int
183 1.1.2.2 bouyer ms_hb_ioctl(v, cmd, data, flag, p)
184 1.1.2.2 bouyer void *v;
185 1.1.2.2 bouyer u_long cmd;
186 1.1.2.2 bouyer caddr_t data;
187 1.1.2.2 bouyer int flag;
188 1.1.2.2 bouyer struct proc *p;
189 1.1.2.2 bouyer {
190 1.1.2.2 bouyer return -1;
191 1.1.2.2 bouyer }
192