Home | History | Annotate | Line # | Download | only in dev
pckbc_pbus.c revision 1.2
      1  1.2  lukem /*	$NetBSD: pckbc_pbus.c,v 1.2 2003/07/15 01:37:38 lukem Exp $	*/
      2  1.1    scw 
      3  1.1    scw /*
      4  1.1    scw  * Copyright 2001 Wasabi Systems, Inc.
      5  1.1    scw  * All rights reserved.
      6  1.1    scw  *
      7  1.1    scw  * Written by Simon Burge and Eduardo Horvath for Wasabi Systems, Inc.
      8  1.1    scw  *
      9  1.1    scw  * Redistribution and use in source and binary forms, with or without
     10  1.1    scw  * modification, are permitted provided that the following conditions
     11  1.1    scw  * are met:
     12  1.1    scw  * 1. Redistributions of source code must retain the above copyright
     13  1.1    scw  *    notice, this list of conditions and the following disclaimer.
     14  1.1    scw  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1    scw  *    notice, this list of conditions and the following disclaimer in the
     16  1.1    scw  *    documentation and/or other materials provided with the distribution.
     17  1.1    scw  * 3. All advertising materials mentioning features or use of this software
     18  1.1    scw  *    must display the following acknowledgement:
     19  1.1    scw  *      This product includes software developed for the NetBSD Project by
     20  1.1    scw  *      Wasabi Systems, Inc.
     21  1.1    scw  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1    scw  *    or promote products derived from this software without specific prior
     23  1.1    scw  *    written permission.
     24  1.1    scw  *
     25  1.1    scw  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1    scw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1    scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1    scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1    scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1    scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1    scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1    scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1    scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1    scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1    scw  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1    scw  */
     37  1.2  lukem 
     38  1.2  lukem #include <sys/cdefs.h>
     39  1.2  lukem __KERNEL_RCSID(0, "$NetBSD: pckbc_pbus.c,v 1.2 2003/07/15 01:37:38 lukem Exp $");
     40  1.1    scw 
     41  1.1    scw #include <sys/param.h>
     42  1.1    scw #include <sys/systm.h>
     43  1.1    scw #include <sys/kernel.h>
     44  1.1    scw #include <sys/device.h>
     45  1.1    scw #include <sys/malloc.h>
     46  1.1    scw 
     47  1.1    scw #include <machine/intr.h>
     48  1.1    scw #include <machine/walnut.h>
     49  1.1    scw 
     50  1.1    scw #include <arch/walnut/dev/pbusvar.h>
     51  1.1    scw #include <powerpc/ibm4xx/dev/plbvar.h>
     52  1.1    scw 
     53  1.1    scw #include <dev/ic/i8042reg.h>
     54  1.1    scw #include <dev/ic/pckbcvar.h>
     55  1.1    scw 
     56  1.1    scw struct pckbc_pbus_softc {
     57  1.1    scw 	struct pckbc_softc sc_pckbc;
     58  1.1    scw 
     59  1.1    scw 	// XXX void *sc_ih[PCKBC_NSLOTS];
     60  1.1    scw 	int sc_irq[PCKBC_NSLOTS];
     61  1.1    scw 
     62  1.1    scw };
     63  1.1    scw 
     64  1.1    scw 
     65  1.1    scw static int	pckbc_pbus_probe(struct device *, struct cfdata *, void *);
     66  1.1    scw static void	pckbc_pbus_attach(struct device *, struct device *, void *);
     67  1.1    scw static void	pckbc_pbus_intr_establish(struct pckbc_softc *, pckbc_slot_t);
     68  1.1    scw 
     69  1.1    scw CFATTACH_DECL(pckbc_pbus, sizeof(struct pckbc_pbus_softc),
     70  1.1    scw     pckbc_pbus_probe, pckbc_pbus_attach, NULL, NULL);
     71  1.1    scw 
     72  1.1    scw int pckbcfound = 0;
     73  1.1    scw 
     74  1.1    scw int
     75  1.1    scw pckbc_pbus_probe(struct device *parent, struct cfdata *cf, void *aux)
     76  1.1    scw {
     77  1.1    scw 	struct pbus_attach_args *paa = aux;
     78  1.1    scw 
     79  1.1    scw 	/* match only pckbc devices */
     80  1.1    scw 	if (strcmp(paa->pb_name, cf->cf_name) != 0)
     81  1.1    scw 		return 0;
     82  1.1    scw 
     83  1.1    scw 	return (pckbcfound < 1);
     84  1.1    scw }
     85  1.1    scw 
     86  1.1    scw struct pckbc_softc *pckbc0; /* XXX */
     87  1.1    scw 
     88  1.1    scw void
     89  1.1    scw pckbc_pbus_attach(struct device *parent, struct device *self, void *aux)
     90  1.1    scw {
     91  1.1    scw 	struct pckbc_pbus_softc *msc = (void *)self;
     92  1.1    scw 	struct pckbc_softc *sc = &msc->sc_pckbc;
     93  1.1    scw 	struct pbus_attach_args *paa = aux;
     94  1.1    scw 	struct pckbc_internal *t;
     95  1.1    scw 	bus_space_handle_t ioh_d, ioh_c;
     96  1.1    scw 	bus_space_tag_t iot = paa->pb_bt;
     97  1.1    scw 	u_long addr = paa->pb_addr;
     98  1.1    scw 
     99  1.1    scw 	/*
    100  1.1    scw 	 * Set up IRQs
    101  1.1    scw 	 */
    102  1.1    scw 	msc->sc_irq[PCKBC_KBD_SLOT] = paa->pb_irq;
    103  1.1    scw 	msc->sc_irq[PCKBC_AUX_SLOT] = paa->pb_irq + 1;	/* XXX */
    104  1.1    scw 
    105  1.1    scw 	sc->intr_establish = pckbc_pbus_intr_establish;
    106  1.1    scw 
    107  1.1    scw 	if (pckbc_is_console(iot, addr)) {
    108  1.1    scw 		t = &pckbc_consdata;
    109  1.1    scw 		pckbc_console_attached = 1;
    110  1.1    scw 		/* t->t_cmdbyte was initialized by cnattach */
    111  1.1    scw 	} else {
    112  1.1    scw 		if (bus_space_map(iot, addr + KEY_MOUSE_DATA, 1, 0, &ioh_d) ||
    113  1.1    scw 		    bus_space_map(iot, addr + KEY_MOUSE_CMD, 1, 0, &ioh_c))
    114  1.1    scw 			panic("pckbc_attach: couldn't map");
    115  1.1    scw 
    116  1.1    scw 		t = malloc(sizeof(struct pckbc_internal), M_DEVBUF, M_WAITOK);
    117  1.1    scw 		memset(t, 0, sizeof(struct pckbc_internal));
    118  1.1    scw 		t->t_iot = iot;
    119  1.1    scw 		t->t_ioh_d = ioh_d;
    120  1.1    scw 		t->t_ioh_c = ioh_c;
    121  1.1    scw 		t->t_addr = addr;
    122  1.1    scw 		t->t_cmdbyte = KC8_CPU; /* Enable ports */
    123  1.1    scw 	}
    124  1.1    scw 
    125  1.1    scw 	t->t_sc = sc;
    126  1.1    scw 	sc->id = t;
    127  1.1    scw 
    128  1.1    scw 	printf("\n");
    129  1.1    scw 
    130  1.1    scw 	/* Finish off the attach. */
    131  1.1    scw 	pckbc_attach(sc);
    132  1.1    scw 
    133  1.1    scw 	pckbcfound++;
    134  1.1    scw 
    135  1.1    scw 	return;
    136  1.1    scw }
    137  1.1    scw 
    138  1.1    scw static void
    139  1.1    scw pckbc_pbus_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot)
    140  1.1    scw {
    141  1.1    scw 	struct pckbc_pbus_softc *msc = (void *)sc;
    142  1.1    scw 	int irq = msc->sc_irq[slot];
    143  1.1    scw 
    144  1.1    scw 	if (slot > PCKBC_NSLOTS) {
    145  1.1    scw 		printf("pckbc_pbus_intr_establish: attempt to establish "
    146  1.1    scw 		    "interrupt at slot %d\n", slot);
    147  1.1    scw 		return;
    148  1.1    scw 	}
    149  1.1    scw 
    150  1.1    scw 	intr_establish(irq, IST_LEVEL, IPL_SERIAL, pckbcintr, sc);
    151  1.1    scw 	printf("%s: %s slot interrupting at irq %d\n", sc->sc_dv.dv_xname,
    152  1.1    scw 	    pckbc_slot_names[slot], irq);
    153  1.1    scw 
    154  1.1    scw }
    155