Home | History | Annotate | Line # | Download | only in dev
ms_kbc.c revision 1.10
      1 /*	$NetBSD: ms_kbc.c,v 1.10 2008/03/28 18:19:56 tsutsui 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/cdefs.h>
     31 __KERNEL_RCSID(0, "$NetBSD: ms_kbc.c,v 1.10 2008/03/28 18:19:56 tsutsui Exp $");
     32 
     33 #include <sys/param.h>
     34 #include <sys/device.h>
     35 #include <sys/systm.h>
     36 
     37 #include <dev/wscons/wsconsio.h>
     38 #include <dev/wscons/wsmousevar.h>
     39 
     40 #include <machine/cpu.h>
     41 #include <machine/bus.h>
     42 
     43 #include <news68k/dev/kbcreg.h>
     44 #include <news68k/dev/kbcvar.h>
     45 #include <news68k/dev/msvar.h>
     46 
     47 #include <news68k/news68k/isr.h>
     48 
     49 static int ms_kbc_match(device_t, cfdata_t, void *);
     50 static void ms_kbc_attach(device_t, device_t, void *);
     51 static void ms_kbc_init(struct ms_softc *);
     52 int ms_kbc_intr(void *);
     53 
     54 static int ms_kbc_enable(void *);
     55 static void ms_kbc_disable(void *);
     56 static int ms_kbc_ioctl(void *, u_long, void *, int, struct lwp *);
     57 
     58 CFATTACH_DECL_NEW(ms_kbc, sizeof(struct ms_softc),
     59     ms_kbc_match, ms_kbc_attach, NULL, NULL);
     60 
     61 struct wsmouse_accessops ms_kbc_accessops = {
     62 	ms_kbc_enable,
     63 	ms_kbc_ioctl,
     64 	ms_kbc_disable
     65 };
     66 
     67 static int
     68 ms_kbc_match(device_t parent, cfdata_t cf, void *aux)
     69 {
     70 	struct kbc_attach_args *ka = aux;
     71 
     72 	if (strcmp(ka->ka_name, "ms"))
     73 		return 0;
     74 
     75 	return 1;
     76 }
     77 
     78 static void
     79 ms_kbc_attach(device_t parent, device_t self, void *aux)
     80 {
     81 	struct ms_softc *sc = device_private(self);
     82 	struct kbc_attach_args *ka = aux;
     83 	struct wsmousedev_attach_args wsa;
     84 	int ipl;
     85 
     86 	aprint_normal("\n");
     87 
     88 	sc->sc_bt = ka->ka_bt;
     89 	sc->sc_bh = ka->ka_bh;
     90 	sc->sc_offset = KBC_MSREG_DATA;
     91 	ipl = ka->ka_ipl;
     92 
     93 	ms_kbc_init(sc);
     94 
     95 	isrlink_autovec(ms_kbc_intr, (void *)sc, ipl, IPL_TTY);
     96 
     97 	wsa.accessops = &ms_kbc_accessops;
     98 	wsa.accesscookie = sc;
     99 	sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint);
    100 }
    101 
    102 static void
    103 ms_kbc_init(struct ms_softc *sc)
    104 {
    105 	bus_space_tag_t bt = sc->sc_bt;
    106 	bus_space_handle_t bh = sc->sc_bh;
    107 
    108 	bus_space_write_1(bt, bh, KBC_MSREG_RESET, 0);
    109 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
    110 }
    111 
    112 int
    113 ms_kbc_intr(void *v)
    114 {
    115 	struct ms_softc *sc = v;
    116 	bus_space_tag_t bt = sc->sc_bt;
    117 	bus_space_handle_t bh = sc->sc_bh;
    118 	int handled = 0;
    119 
    120 	while (bus_space_read_1(bt, bh, KBC_MSREG_STAT) & KBCSTAT_MSRDY) {
    121 		ms_intr(sc);
    122 		handled = 1;
    123 	}
    124 	if (handled)
    125 		bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
    126 
    127 	return handled;
    128 }
    129 
    130 static int
    131 ms_kbc_enable(void *v)
    132 {
    133 	struct ms_softc *sc = v;
    134 	bus_space_tag_t bt = sc->sc_bt;
    135 	bus_space_handle_t bh = sc->sc_bh;
    136 
    137 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
    138 
    139 	return 0;
    140 }
    141 
    142 static void
    143 ms_kbc_disable(void *v)
    144 {
    145 	struct ms_softc *sc = v;
    146 	bus_space_tag_t bt = sc->sc_bt;
    147 	bus_space_handle_t bh = sc->sc_bh;
    148 
    149 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, 0);
    150 }
    151 
    152 static int
    153 ms_kbc_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
    154 {
    155 
    156 	return EPASSTHROUGH;
    157 }
    158