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