1 /* $NetBSD: ms_hb.c,v 1.12 2008/03/29 05:48:33 tsutsui Exp $ */
4 * Copyright (c) 2001 Izumi Tsutsui. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Copyright (c) 2000 Tsubai Masanari. All rights reserved.
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. The name of the author may not be used to endorse or promote products
39 * derived from this software without specific prior written permission.
41 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
42 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
45 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 #include <sys/cdefs.h>
54 __KERNEL_RCSID(0, "$NetBSD: ms_hb.c,v 1.12 2008/03/29 05:48:33 tsutsui Exp $");
56 #include <sys/param.h>
57 #include <sys/device.h>
58 #include <sys/systm.h>
60 #include <dev/wscons/wsconsio.h>
61 #include <dev/wscons/wsmousevar.h>
63 #include <machine/bus.h>
64 #include <machine/cpu.h>
66 #include <news68k/dev/hbvar.h>
67 #include <news68k/dev/ms_hbreg.h>
68 #include <news68k/dev/msvar.h>
70 #include <news68k/news68k/isr.h>
72 #define MS_SIZE 0x10 /* XXX */
75 static int ms_hb_match(device_t
, cfdata_t
, void *);
76 static void ms_hb_attach(device_t
, device_t
, void *);
77 static void ms_hb_init(struct ms_softc
*);
78 int ms_hb_intr(void *);
80 static int ms_hb_enable(void *);
81 static int ms_hb_ioctl(void *, u_long
, void *, int, struct lwp
*);
82 static void ms_hb_disable(void *);
84 CFATTACH_DECL_NEW(ms_hb
, sizeof(struct ms_softc
),
85 ms_hb_match
, ms_hb_attach
, NULL
, NULL
);
87 struct wsmouse_accessops ms_hb_accessops
= {
94 ms_hb_match(device_t parent
, cfdata_t cf
, void *aux
)
96 struct hb_attach_args
*ha
= aux
;
99 if (strcmp(ha
->ha_name
, "ms"))
102 /* XXX no default address */
103 if (ha
->ha_address
== (u_int
)-1)
106 addr
= IIOV(ha
->ha_address
); /* XXX */
108 if (badaddr((void *)addr
, 1))
115 ms_hb_attach(device_t parent
, device_t self
, void *aux
)
117 struct ms_softc
*sc
= device_private(self
);
118 struct hb_attach_args
*ha
= aux
;
119 bus_space_tag_t bt
= ha
->ha_bust
;
120 bus_space_handle_t bh
;
121 struct wsmousedev_attach_args wsa
;
125 if (bus_space_map(bt
, ha
->ha_address
, MS_SIZE
, 0, &bh
) != 0) {
126 aprint_error(": can't map device space\n");
134 sc
->sc_offset
= MS_REG_DATA
;
141 isrlink_autovec(ms_hb_intr
, (void *)sc
, ipl
, IPL_TTY
);
143 wsa
.accessops
= &ms_hb_accessops
;
144 wsa
.accesscookie
= sc
;
145 sc
->sc_wsmousedev
= config_found(self
, &wsa
, wsmousedevprint
);
149 ms_hb_init(struct ms_softc
*sc
)
151 bus_space_tag_t bt
= sc
->sc_bt
;
152 bus_space_handle_t bh
= sc
->sc_bh
;
154 bus_space_write_1(bt
, bh
, MS_REG_RESET
, 0);
155 bus_space_write_1(bt
, bh
, MS_REG_INTE
, MS_INTE
);
161 struct ms_softc
*sc
= v
;
162 bus_space_tag_t bt
= sc
->sc_bt
;
163 bus_space_handle_t bh
= sc
->sc_bh
;
166 while ((bus_space_read_1(bt
, bh
, MS_REG_STAT
) & MSSTAT_RDY
) != 0) {
171 bus_space_write_1(bt
, bh
, MS_REG_INTE
, MS_INTE
);
177 ms_hb_enable(void *v
)
179 struct ms_softc
*sc
= v
;
180 bus_space_tag_t bt
= sc
->sc_bt
;
181 bus_space_handle_t bh
= sc
->sc_bh
;
183 bus_space_write_1(bt
, bh
, MS_REG_INTE
, MS_INTE
);
189 ms_hb_disable(void *v
)
191 struct ms_softc
*sc
= v
;
192 bus_space_tag_t bt
= sc
->sc_bt
;
193 bus_space_handle_t bh
= sc
->sc_bh
;
195 bus_space_write_1(bt
, bh
, MS_REG_INTE
, 0);
199 ms_hb_ioctl(void *v
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)