Home | History | Annotate | Line # | Download | only in dev
ms_hb.c revision 1.5.2.1
      1  1.5.2.1    skrll /*	$NetBSD: ms_hb.c,v 1.5.2.1 2004/08/03 10:38:22 skrll 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.1  tsutsui 
     30  1.5.2.1    skrll #include <sys/cdefs.h>
     31  1.5.2.1    skrll __KERNEL_RCSID(0, "$NetBSD: ms_hb.c,v 1.5.2.1 2004/08/03 10:38:22 skrll Exp $");
     32  1.5.2.1    skrll 
     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/bus.h>
     41      1.1  tsutsui #include <machine/cpu.h>
     42      1.1  tsutsui 
     43      1.1  tsutsui #include <news68k/dev/hbvar.h>
     44      1.1  tsutsui #include <news68k/dev/ms_hbreg.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.1  tsutsui #define MS_SIZE 0x10 /* XXX */
     50      1.1  tsutsui #define MS_IPL 5
     51      1.1  tsutsui 
     52      1.1  tsutsui int ms_hb_match(struct device *, struct cfdata *, void *);
     53      1.1  tsutsui void ms_hb_attach(struct device *, struct device *, void *);
     54      1.1  tsutsui void ms_hb_init(struct ms_softc *);
     55      1.1  tsutsui int ms_hb_intr(void *);
     56      1.1  tsutsui 
     57      1.1  tsutsui int ms_hb_enable(void *);
     58      1.1  tsutsui int ms_hb_ioctl(void *, u_long, caddr_t, int, struct proc *);
     59      1.1  tsutsui void ms_hb_disable(void *);
     60      1.1  tsutsui 
     61      1.4  thorpej CFATTACH_DECL(ms_hb, sizeof(struct ms_softc),
     62      1.4  thorpej     ms_hb_match, ms_hb_attach, NULL, NULL);
     63      1.1  tsutsui 
     64      1.1  tsutsui struct wsmouse_accessops ms_hb_accessops = {
     65      1.1  tsutsui 	ms_hb_enable,
     66      1.1  tsutsui 	ms_hb_ioctl,
     67      1.1  tsutsui 	ms_hb_disable
     68      1.1  tsutsui };
     69      1.1  tsutsui 
     70      1.1  tsutsui int
     71      1.1  tsutsui ms_hb_match(parent, cf, aux)
     72      1.1  tsutsui 	struct device *parent;
     73      1.1  tsutsui 	struct cfdata *cf;
     74      1.1  tsutsui 	void *aux;
     75      1.1  tsutsui {
     76      1.1  tsutsui 	struct hb_attach_args *ha = aux;
     77      1.1  tsutsui 	u_int addr;
     78      1.1  tsutsui 
     79      1.1  tsutsui 	if (strcmp(ha->ha_name, "ms"))
     80      1.1  tsutsui 		return 0;
     81      1.1  tsutsui 
     82      1.1  tsutsui 	/* XXX no default address */
     83      1.5  tsutsui 	if (ha->ha_address == (u_int)-1)
     84      1.1  tsutsui 		return 0;
     85      1.1  tsutsui 
     86      1.1  tsutsui 	addr = IIOV(ha->ha_address); /* XXX */
     87      1.1  tsutsui 
     88      1.1  tsutsui 	if (badaddr((void *)addr, 1))
     89      1.1  tsutsui 		return 0;
     90      1.1  tsutsui 
     91      1.1  tsutsui 	return 1;
     92      1.1  tsutsui }
     93      1.1  tsutsui 
     94      1.1  tsutsui void
     95      1.1  tsutsui ms_hb_attach(parent, self, aux)
     96      1.1  tsutsui 	struct device *parent;
     97      1.1  tsutsui 	struct device *self;
     98      1.1  tsutsui 	void *aux;
     99      1.1  tsutsui {
    100      1.1  tsutsui 	struct ms_softc *sc = (void *)self;
    101      1.1  tsutsui 	struct hb_attach_args *ha = aux;
    102      1.1  tsutsui 	bus_space_tag_t bt = ha->ha_bust;
    103      1.1  tsutsui 	bus_space_handle_t bh;
    104      1.1  tsutsui 	struct wsmousedev_attach_args wsa;
    105      1.1  tsutsui 	int ipl;
    106      1.1  tsutsui 
    107      1.1  tsutsui 	if (bus_space_map(bt, ha->ha_address, MS_SIZE, 0, &bh) != 0) {
    108      1.1  tsutsui 		printf("can't map device space\n");
    109      1.1  tsutsui 		return;
    110      1.1  tsutsui 	}
    111      1.1  tsutsui 
    112      1.1  tsutsui 	printf("\n");
    113      1.1  tsutsui 
    114      1.1  tsutsui 	sc->sc_bt = bt;
    115      1.1  tsutsui 	sc->sc_bh = bh;
    116      1.1  tsutsui 	sc->sc_offset = MS_REG_DATA;
    117      1.1  tsutsui 	ipl = ha->ha_ipl;
    118      1.1  tsutsui 	if (ipl == -1)
    119      1.1  tsutsui 		ipl = MS_IPL;
    120      1.1  tsutsui 
    121      1.1  tsutsui 	ms_hb_init(sc);
    122      1.1  tsutsui 
    123      1.1  tsutsui 	isrlink_autovec(ms_hb_intr, (void *)sc, ipl, ISRPRI_TTY);
    124      1.1  tsutsui 
    125      1.1  tsutsui 	wsa.accessops = &ms_hb_accessops;
    126      1.1  tsutsui 	wsa.accesscookie = sc;
    127      1.1  tsutsui 	sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint);
    128      1.1  tsutsui }
    129      1.1  tsutsui 
    130      1.1  tsutsui void
    131      1.1  tsutsui ms_hb_init(sc)
    132      1.1  tsutsui 	struct ms_softc *sc;
    133      1.1  tsutsui {
    134      1.1  tsutsui 	bus_space_tag_t bt = sc->sc_bt;
    135      1.1  tsutsui 	bus_space_handle_t bh = sc->sc_bh;
    136      1.1  tsutsui 
    137      1.1  tsutsui 	bus_space_write_1(bt, bh, MS_REG_RESET, 0);
    138      1.1  tsutsui 	bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
    139      1.1  tsutsui }
    140      1.1  tsutsui 
    141      1.1  tsutsui int
    142      1.1  tsutsui ms_hb_intr(v)
    143      1.1  tsutsui 	void *v;
    144      1.1  tsutsui {
    145      1.1  tsutsui 	struct ms_softc *sc = v;
    146      1.1  tsutsui 	bus_space_tag_t bt = sc->sc_bt;
    147      1.1  tsutsui 	bus_space_handle_t bh = sc->sc_bh;
    148      1.1  tsutsui 	int handled = 0;
    149      1.1  tsutsui 
    150      1.1  tsutsui 	while ((bus_space_read_1(bt, bh, MS_REG_STAT) & MSSTAT_RDY) != 0) {
    151      1.1  tsutsui 		ms_intr(sc);
    152      1.1  tsutsui 		handled = 1;
    153      1.1  tsutsui 	}
    154      1.1  tsutsui 	if (handled)
    155      1.1  tsutsui 		bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
    156      1.1  tsutsui 
    157      1.1  tsutsui 	return handled;
    158      1.1  tsutsui }
    159      1.1  tsutsui 
    160      1.1  tsutsui int
    161      1.1  tsutsui ms_hb_enable(v)
    162      1.1  tsutsui 	void *v;
    163      1.1  tsutsui {
    164      1.1  tsutsui 	struct ms_softc *sc = v;
    165      1.1  tsutsui 	bus_space_tag_t bt = sc->sc_bt;
    166      1.1  tsutsui 	bus_space_handle_t bh = sc->sc_bh;
    167      1.1  tsutsui 
    168      1.1  tsutsui 	bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
    169      1.1  tsutsui 
    170      1.1  tsutsui 	return 0;
    171      1.1  tsutsui }
    172      1.1  tsutsui 
    173      1.1  tsutsui void
    174      1.1  tsutsui ms_hb_disable(v)
    175      1.1  tsutsui 	void *v;
    176      1.1  tsutsui {
    177      1.1  tsutsui 	struct ms_softc *sc = v;
    178      1.1  tsutsui 	bus_space_tag_t bt = sc->sc_bt;
    179      1.1  tsutsui 	bus_space_handle_t bh = sc->sc_bh;
    180      1.1  tsutsui 
    181      1.1  tsutsui 	bus_space_write_1(bt, bh, MS_REG_INTE, 0);
    182      1.1  tsutsui }
    183      1.1  tsutsui 
    184      1.1  tsutsui int
    185      1.1  tsutsui ms_hb_ioctl(v, cmd, data, flag, p)
    186      1.1  tsutsui 	void *v;
    187      1.1  tsutsui 	u_long cmd;
    188      1.1  tsutsui 	caddr_t data;
    189      1.1  tsutsui 	int flag;
    190      1.1  tsutsui 	struct proc *p;
    191      1.1  tsutsui {
    192      1.2   atatat 	return EPASSTHROUGH;
    193      1.1  tsutsui }
    194