Home | History | Annotate | Line # | Download | only in dev
      1  1.5  thorpej /*	$NetBSD: pckbc_pbus.c,v 1.5 2020/11/21 15:42:20 thorpej 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.5  thorpej __KERNEL_RCSID(0, "$NetBSD: pckbc_pbus.c,v 1.5 2020/11/21 15:42:20 thorpej 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.5  thorpej #include <sys/kmem.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.4     cube static int	pckbc_pbus_probe(device_t, cfdata_t, void *);
     66  1.4     cube static void	pckbc_pbus_attach(device_t, device_t, void *);
     67  1.1      scw static void	pckbc_pbus_intr_establish(struct pckbc_softc *, pckbc_slot_t);
     68  1.1      scw 
     69  1.4     cube CFATTACH_DECL_NEW(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.4     cube pckbc_pbus_probe(device_t parent, cfdata_t 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.4     cube pckbc_pbus_attach(device_t parent, device_t self, void *aux)
     90  1.1      scw {
     91  1.4     cube 	struct pckbc_pbus_softc *msc = device_private(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.4     cube 
     99  1.4     cube 	sc->sc_dv = self;
    100  1.1      scw 	/*
    101  1.1      scw 	 * Set up IRQs
    102  1.1      scw 	 */
    103  1.1      scw 	msc->sc_irq[PCKBC_KBD_SLOT] = paa->pb_irq;
    104  1.1      scw 	msc->sc_irq[PCKBC_AUX_SLOT] = paa->pb_irq + 1;	/* XXX */
    105  1.1      scw 
    106  1.1      scw 	sc->intr_establish = pckbc_pbus_intr_establish;
    107  1.1      scw 
    108  1.1      scw 	if (pckbc_is_console(iot, addr)) {
    109  1.1      scw 		t = &pckbc_consdata;
    110  1.1      scw 		pckbc_console_attached = 1;
    111  1.1      scw 		/* t->t_cmdbyte was initialized by cnattach */
    112  1.1      scw 	} else {
    113  1.1      scw 		if (bus_space_map(iot, addr + KEY_MOUSE_DATA, 1, 0, &ioh_d) ||
    114  1.1      scw 		    bus_space_map(iot, addr + KEY_MOUSE_CMD, 1, 0, &ioh_c))
    115  1.1      scw 			panic("pckbc_attach: couldn't map");
    116  1.1      scw 
    117  1.5  thorpej 		t = kmem_zalloc(sizeof(struct pckbc_internal), KM_SLEEP);
    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.4     cube 	aprint_normal("\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.4     cube 		aprint_error("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.4     cube 	aprint_normal_dev(sc->sc_dv, "%s slot interrupting at irq %d\n",
    152  1.1      scw 	    pckbc_slot_names[slot], irq);
    153  1.1      scw }
    154