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