Home | History | Annotate | Line # | Download | only in dev
ms_hb.c revision 1.12.4.1
      1 /*	$NetBSD: ms_hb.c,v 1.12.4.1 2008/05/16 02:22:57 yamt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001 Izumi Tsutsui.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      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.
     14  *
     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.
     25  */
     26 
     27 /*-
     28  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
     29  *
     30  * Redistribution and use in source and binary forms, with or without
     31  * modification, are permitted provided that the following conditions
     32  * are met:
     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.
     40  *
     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.
     51  */
     52 
     53 #include <sys/cdefs.h>
     54 __KERNEL_RCSID(0, "$NetBSD: ms_hb.c,v 1.12.4.1 2008/05/16 02:22:57 yamt Exp $");
     55 
     56 #include <sys/param.h>
     57 #include <sys/device.h>
     58 #include <sys/systm.h>
     59 
     60 #include <dev/wscons/wsconsio.h>
     61 #include <dev/wscons/wsmousevar.h>
     62 
     63 #include <machine/bus.h>
     64 #include <machine/cpu.h>
     65 
     66 #include <news68k/dev/hbvar.h>
     67 #include <news68k/dev/ms_hbreg.h>
     68 #include <news68k/dev/msvar.h>
     69 
     70 #include <news68k/news68k/isr.h>
     71 
     72 #define MS_SIZE 0x10 /* XXX */
     73 #define MS_IPL 5
     74 
     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 *);
     79 
     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 *);
     83 
     84 CFATTACH_DECL_NEW(ms_hb, sizeof(struct ms_softc),
     85     ms_hb_match, ms_hb_attach, NULL, NULL);
     86 
     87 struct wsmouse_accessops ms_hb_accessops = {
     88 	ms_hb_enable,
     89 	ms_hb_ioctl,
     90 	ms_hb_disable
     91 };
     92 
     93 static int
     94 ms_hb_match(device_t parent, cfdata_t cf, void *aux)
     95 {
     96 	struct hb_attach_args *ha = aux;
     97 	u_int addr;
     98 
     99 	if (strcmp(ha->ha_name, "ms"))
    100 		return 0;
    101 
    102 	/* XXX no default address */
    103 	if (ha->ha_address == (u_int)-1)
    104 		return 0;
    105 
    106 	addr = IIOV(ha->ha_address); /* XXX */
    107 
    108 	if (badaddr((void *)addr, 1))
    109 		return 0;
    110 
    111 	return 1;
    112 }
    113 
    114 static void
    115 ms_hb_attach(device_t parent, device_t self, void *aux)
    116 {
    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;
    122 	int ipl;
    123 
    124 	sc->sc_dev = self;
    125 	if (bus_space_map(bt, ha->ha_address, MS_SIZE, 0, &bh) != 0) {
    126 		aprint_error(": can't map device space\n");
    127 		return;
    128 	}
    129 
    130 	aprint_normal("\n");
    131 
    132 	sc->sc_bt = bt;
    133 	sc->sc_bh = bh;
    134 	sc->sc_offset = MS_REG_DATA;
    135 	ipl = ha->ha_ipl;
    136 	if (ipl == -1)
    137 		ipl = MS_IPL;
    138 
    139 	ms_hb_init(sc);
    140 
    141 	isrlink_autovec(ms_hb_intr, (void *)sc, ipl, IPL_TTY);
    142 
    143 	wsa.accessops = &ms_hb_accessops;
    144 	wsa.accesscookie = sc;
    145 	sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint);
    146 }
    147 
    148 static void
    149 ms_hb_init(struct ms_softc *sc)
    150 {
    151 	bus_space_tag_t bt = sc->sc_bt;
    152 	bus_space_handle_t bh = sc->sc_bh;
    153 
    154 	bus_space_write_1(bt, bh, MS_REG_RESET, 0);
    155 	bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
    156 }
    157 
    158 int
    159 ms_hb_intr(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 	int handled = 0;
    165 
    166 	while ((bus_space_read_1(bt, bh, MS_REG_STAT) & MSSTAT_RDY) != 0) {
    167 		ms_intr(sc);
    168 		handled = 1;
    169 	}
    170 	if (handled)
    171 		bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
    172 
    173 	return handled;
    174 }
    175 
    176 static int
    177 ms_hb_enable(void *v)
    178 {
    179 	struct ms_softc *sc = v;
    180 	bus_space_tag_t bt = sc->sc_bt;
    181 	bus_space_handle_t bh = sc->sc_bh;
    182 
    183 	bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
    184 
    185 	return 0;
    186 }
    187 
    188 static void
    189 ms_hb_disable(void *v)
    190 {
    191 	struct ms_softc *sc = v;
    192 	bus_space_tag_t bt = sc->sc_bt;
    193 	bus_space_handle_t bh = sc->sc_bh;
    194 
    195 	bus_space_write_1(bt, bh, MS_REG_INTE, 0);
    196 }
    197 
    198 static int
    199 ms_hb_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
    200 {
    201 
    202 	return EPASSTHROUGH;
    203 }
    204