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