Home | History | Annotate | Line # | Download | only in dev
ms_kbc.c revision 1.11
      1  1.11   tsutsui /*	$NetBSD: ms_kbc.c,v 1.11 2008/03/29 05:48:33 tsutsui Exp $	*/
      2   1.1   tsutsui 
      3   1.1   tsutsui /*-
      4   1.1   tsutsui  * Copyright (c) 2001 Izumi Tsutsui.  All rights reserved.
      5   1.1   tsutsui  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
      6   1.1   tsutsui  *
      7   1.1   tsutsui  * Redistribution and use in source and binary forms, with or without
      8   1.1   tsutsui  * modification, are permitted provided that the following conditions
      9   1.1   tsutsui  * are met:
     10   1.1   tsutsui  * 1. Redistributions of source code must retain the above copyright
     11   1.1   tsutsui  *    notice, this list of conditions and the following disclaimer.
     12   1.1   tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1   tsutsui  *    notice, this list of conditions and the following disclaimer in the
     14   1.1   tsutsui  *    documentation and/or other materials provided with the distribution.
     15   1.1   tsutsui  * 3. The name of the author may not be used to endorse or promote products
     16   1.1   tsutsui  *    derived from this software without specific prior written permission.
     17   1.1   tsutsui  *
     18   1.1   tsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19   1.1   tsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20   1.1   tsutsui  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21   1.1   tsutsui  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22   1.1   tsutsui  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23   1.1   tsutsui  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24   1.1   tsutsui  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25   1.1   tsutsui  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26   1.1   tsutsui  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     27   1.1   tsutsui  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28   1.1   tsutsui  */
     29   1.5     lukem 
     30   1.5     lukem #include <sys/cdefs.h>
     31  1.11   tsutsui __KERNEL_RCSID(0, "$NetBSD: ms_kbc.c,v 1.11 2008/03/29 05:48:33 tsutsui Exp $");
     32   1.1   tsutsui 
     33   1.1   tsutsui #include <sys/param.h>
     34   1.1   tsutsui #include <sys/device.h>
     35   1.1   tsutsui #include <sys/systm.h>
     36   1.1   tsutsui 
     37   1.1   tsutsui #include <dev/wscons/wsconsio.h>
     38   1.1   tsutsui #include <dev/wscons/wsmousevar.h>
     39   1.1   tsutsui 
     40   1.1   tsutsui #include <machine/cpu.h>
     41   1.1   tsutsui #include <machine/bus.h>
     42   1.1   tsutsui 
     43   1.1   tsutsui #include <news68k/dev/kbcreg.h>
     44   1.1   tsutsui #include <news68k/dev/kbcvar.h>
     45   1.1   tsutsui #include <news68k/dev/msvar.h>
     46   1.1   tsutsui 
     47   1.1   tsutsui #include <news68k/news68k/isr.h>
     48   1.1   tsutsui 
     49  1.10   tsutsui static int ms_kbc_match(device_t, cfdata_t, void *);
     50  1.10   tsutsui static void ms_kbc_attach(device_t, device_t, void *);
     51   1.6   tsutsui static void ms_kbc_init(struct ms_softc *);
     52   1.1   tsutsui int ms_kbc_intr(void *);
     53   1.1   tsutsui 
     54   1.6   tsutsui static int ms_kbc_enable(void *);
     55   1.6   tsutsui static void ms_kbc_disable(void *);
     56   1.9  christos static int ms_kbc_ioctl(void *, u_long, void *, int, struct lwp *);
     57   1.1   tsutsui 
     58  1.10   tsutsui CFATTACH_DECL_NEW(ms_kbc, sizeof(struct ms_softc),
     59   1.4   thorpej     ms_kbc_match, ms_kbc_attach, NULL, NULL);
     60   1.1   tsutsui 
     61   1.1   tsutsui struct wsmouse_accessops ms_kbc_accessops = {
     62   1.1   tsutsui 	ms_kbc_enable,
     63   1.1   tsutsui 	ms_kbc_ioctl,
     64   1.1   tsutsui 	ms_kbc_disable
     65   1.1   tsutsui };
     66   1.1   tsutsui 
     67   1.6   tsutsui static int
     68  1.10   tsutsui ms_kbc_match(device_t parent, cfdata_t cf, void *aux)
     69   1.1   tsutsui {
     70   1.1   tsutsui 	struct kbc_attach_args *ka = aux;
     71   1.1   tsutsui 
     72   1.1   tsutsui 	if (strcmp(ka->ka_name, "ms"))
     73   1.1   tsutsui 		return 0;
     74   1.1   tsutsui 
     75   1.1   tsutsui 	return 1;
     76   1.1   tsutsui }
     77   1.1   tsutsui 
     78   1.6   tsutsui static void
     79  1.10   tsutsui ms_kbc_attach(device_t parent, device_t self, void *aux)
     80   1.1   tsutsui {
     81  1.10   tsutsui 	struct ms_softc *sc = device_private(self);
     82   1.1   tsutsui 	struct kbc_attach_args *ka = aux;
     83   1.1   tsutsui 	struct wsmousedev_attach_args wsa;
     84   1.1   tsutsui 	int ipl;
     85   1.1   tsutsui 
     86  1.11   tsutsui 	sc->sc_dev = self;
     87  1.10   tsutsui 	aprint_normal("\n");
     88   1.1   tsutsui 
     89   1.1   tsutsui 	sc->sc_bt = ka->ka_bt;
     90   1.1   tsutsui 	sc->sc_bh = ka->ka_bh;
     91   1.1   tsutsui 	sc->sc_offset = KBC_MSREG_DATA;
     92   1.1   tsutsui 	ipl = ka->ka_ipl;
     93   1.1   tsutsui 
     94   1.1   tsutsui 	ms_kbc_init(sc);
     95   1.1   tsutsui 
     96   1.8   tsutsui 	isrlink_autovec(ms_kbc_intr, (void *)sc, ipl, IPL_TTY);
     97   1.1   tsutsui 
     98   1.1   tsutsui 	wsa.accessops = &ms_kbc_accessops;
     99   1.1   tsutsui 	wsa.accesscookie = sc;
    100   1.1   tsutsui 	sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint);
    101   1.1   tsutsui }
    102   1.1   tsutsui 
    103   1.6   tsutsui static void
    104   1.6   tsutsui ms_kbc_init(struct ms_softc *sc)
    105   1.1   tsutsui {
    106   1.1   tsutsui 	bus_space_tag_t bt = sc->sc_bt;
    107   1.1   tsutsui 	bus_space_handle_t bh = sc->sc_bh;
    108   1.1   tsutsui 
    109   1.1   tsutsui 	bus_space_write_1(bt, bh, KBC_MSREG_RESET, 0);
    110   1.1   tsutsui 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
    111   1.1   tsutsui }
    112   1.1   tsutsui 
    113   1.1   tsutsui int
    114   1.6   tsutsui ms_kbc_intr(void *v)
    115   1.1   tsutsui {
    116   1.1   tsutsui 	struct ms_softc *sc = v;
    117   1.1   tsutsui 	bus_space_tag_t bt = sc->sc_bt;
    118   1.1   tsutsui 	bus_space_handle_t bh = sc->sc_bh;
    119   1.1   tsutsui 	int handled = 0;
    120   1.1   tsutsui 
    121   1.1   tsutsui 	while (bus_space_read_1(bt, bh, KBC_MSREG_STAT) & KBCSTAT_MSRDY) {
    122   1.1   tsutsui 		ms_intr(sc);
    123   1.1   tsutsui 		handled = 1;
    124   1.1   tsutsui 	}
    125   1.1   tsutsui 	if (handled)
    126   1.1   tsutsui 		bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
    127   1.1   tsutsui 
    128   1.1   tsutsui 	return handled;
    129   1.1   tsutsui }
    130   1.1   tsutsui 
    131   1.6   tsutsui static int
    132   1.6   tsutsui ms_kbc_enable(void *v)
    133   1.1   tsutsui {
    134   1.1   tsutsui 	struct ms_softc *sc = v;
    135   1.1   tsutsui 	bus_space_tag_t bt = sc->sc_bt;
    136   1.1   tsutsui 	bus_space_handle_t bh = sc->sc_bh;
    137   1.1   tsutsui 
    138   1.1   tsutsui 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
    139   1.1   tsutsui 
    140   1.1   tsutsui 	return 0;
    141   1.1   tsutsui }
    142   1.1   tsutsui 
    143   1.6   tsutsui static void
    144   1.6   tsutsui ms_kbc_disable(void *v)
    145   1.1   tsutsui {
    146   1.1   tsutsui 	struct ms_softc *sc = v;
    147   1.1   tsutsui 	bus_space_tag_t bt = sc->sc_bt;
    148   1.1   tsutsui 	bus_space_handle_t bh = sc->sc_bh;
    149   1.1   tsutsui 
    150   1.1   tsutsui 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, 0);
    151   1.1   tsutsui }
    152   1.1   tsutsui 
    153   1.6   tsutsui static int
    154   1.9  christos ms_kbc_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
    155   1.1   tsutsui {
    156   1.6   tsutsui 
    157   1.2    atatat 	return EPASSTHROUGH;
    158   1.1   tsutsui }
    159