Home | History | Annotate | Line # | Download | only in jazz
pckbc_jazzio.c revision 1.1
      1 /* $NetBSD: pckbc_jazzio.c,v 1.1 2000/06/17 07:17:38 soda Exp $ */
      2 /* NetBSD: pckbc_isa.c,v 1.2 2000/03/23 07:01:35 thorpej Exp  */
      3 
      4 /*
      5  * Copyright (c) 1998
      6  *	Matthias Drochner.  All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed for the NetBSD Project
     19  *	by Matthias Drochner.
     20  * 4. The name of the author may not be used to endorse or promote products
     21  *    derived from this software without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/kernel.h>
     38 #include <sys/proc.h>
     39 #include <sys/device.h>
     40 #include <sys/malloc.h>
     41 #include <sys/errno.h>
     42 #include <sys/queue.h>
     43 #include <sys/lock.h>
     44 
     45 #include <machine/autoconf.h>
     46 #include <machine/bus.h>
     47 #include <arc/pica/pica.h>
     48 
     49 #include <dev/ic/i8042reg.h>
     50 #include <dev/ic/pckbcvar.h>
     51 #include <arc/jazz/pckbc_jazzioreg.h>
     52 
     53 #define PICA_KBCMDP	(PICA_SYS_KBD + JAZZIO_KBCMDP)
     54 
     55 int	pckbc_jazzio_match __P((struct device *, struct cfdata *, void *));
     56 void	pckbc_jazzio_attach __P((struct device *, struct device *, void *));
     57 void	pckbc_jazzio_intr_establish __P((struct pckbc_softc *, pckbc_slot_t));
     58 
     59 struct pckbc_jazzio_softc {
     60 	struct pckbc_softc sc_pckbc;
     61 
     62 	struct confargs *sc_ca[PCKBC_NSLOTS];
     63 };
     64 
     65 struct cfattach pckbc_jazzio_ca = {
     66 	sizeof(struct pckbc_jazzio_softc),
     67 	pckbc_jazzio_match, pckbc_jazzio_attach,
     68 };
     69 
     70 extern struct arc_bus_space pica_bus; /* XXX */
     71 
     72 int
     73 pckbc_jazzio_match(parent, match, aux)
     74 	struct device *parent;
     75 	struct cfdata *match;
     76 	void *aux;
     77 {
     78 	struct confargs *ca = aux;
     79 	bus_space_tag_t iot = &pica_bus;
     80 	bus_space_handle_t ioh_d, ioh_c;
     81 	bus_addr_t addr;
     82 	int res, ok = 1;
     83 
     84 	if(!BUS_MATCHNAME(ca, "pckbd"))
     85 		return(0);
     86 
     87 	addr = (bus_addr_t)BUS_CVTADDR(ca);
     88 	if (pckbc_is_console(iot, addr) == 0) {
     89 		if (bus_space_map(iot, addr + KBDATAP, 1, 0, &ioh_d))
     90 			return (0);
     91 		if (bus_space_map(iot, PICA_KBCMDP, 1, 0, &ioh_c)) {
     92 			bus_space_unmap(iot, ioh_d, 1);
     93 			return (0);
     94 		}
     95 
     96 		/* flush KBC */
     97 		(void) pckbc_poll_data1(iot, ioh_d, ioh_c, PCKBC_KBD_SLOT, 0);
     98 
     99 		/* KBC selftest */
    100 		if (pckbc_send_cmd(iot, ioh_c, KBC_SELFTEST) == 0) {
    101 			ok = 0;
    102 			goto out;
    103 		}
    104 		res = pckbc_poll_data1(iot, ioh_d, ioh_c, PCKBC_KBD_SLOT, 0);
    105 		if (res != 0x55) {
    106 			printf("kbc selftest: %x\n", res);
    107 			ok = 0;
    108 		}
    109  out:
    110 		bus_space_unmap(iot, ioh_d, 1);
    111 		bus_space_unmap(iot, ioh_c, 1);
    112 	}
    113 
    114 	return (ok);
    115 }
    116 
    117 void
    118 pckbc_jazzio_attach(parent, self, aux)
    119 	struct device *parent, *self;
    120 	void *aux;
    121 {
    122 	struct confargs *ca = aux;
    123 	struct pckbc_jazzio_softc *jsc = (void *)self;
    124 	struct pckbc_softc *sc = &jsc->sc_pckbc;
    125 	struct pckbc_internal *t;
    126 	bus_space_tag_t iot = &pica_bus;
    127 	bus_space_handle_t ioh_d, ioh_c;
    128 	bus_addr_t addr;
    129 	static struct confargs pms_ca = { "pms", 8, NULL, }; /* XXX */
    130 
    131 	sc->intr_establish = pckbc_jazzio_intr_establish;
    132 
    133 	/*
    134 	 * To establish interrupt handler
    135 	 *
    136 	 * XXX handcrafting "aux" slot...
    137 	 */
    138 	pms_ca.ca_bus = ca->ca_bus;
    139 	jsc->sc_ca[PCKBC_KBD_SLOT] = ca;
    140 	jsc->sc_ca[PCKBC_AUX_SLOT] = &pms_ca;
    141 
    142 	addr = (bus_addr_t)BUS_CVTADDR(ca);
    143 	if (pckbc_is_console(iot, addr)) {
    144 		t = &pckbc_consdata;
    145 		ioh_d = t->t_ioh_d;
    146 		ioh_c = t->t_ioh_c;
    147 		pckbc_console_attached = 1;
    148 		/* t->t_cmdbyte was initialized by cnattach */
    149 	} else {
    150 		if (bus_space_map(iot, addr + KBDATAP, 1, 0, &ioh_d) ||
    151 		    bus_space_map(iot, PICA_KBCMDP, 1, 0, &ioh_c))
    152 			panic("pckbc_attach: couldn't map");
    153 
    154 		t = malloc(sizeof(struct pckbc_internal), M_DEVBUF, M_WAITOK);
    155 		bzero(t, sizeof(struct pckbc_internal));
    156 		t->t_iot = iot;
    157 		t->t_ioh_d = ioh_d;
    158 		t->t_ioh_c = ioh_c;
    159 		t->t_addr = addr;
    160 		t->t_cmdbyte = KC8_CPU; /* Enable ports */
    161 		callout_init(&t->t_cleanup);
    162 	}
    163 
    164 	t->t_sc = sc;
    165 	sc->id = t;
    166 
    167 	printf("\n");
    168 
    169 	/* Finish off the attach. */
    170 	pckbc_attach(sc);
    171 }
    172 
    173 void
    174 pckbc_jazzio_intr_establish(sc, slot)
    175 	struct pckbc_softc *sc;
    176 	pckbc_slot_t slot;
    177 {
    178 	struct pckbc_jazzio_softc *jsc = (void *) sc;
    179 
    180 	BUS_INTR_ESTABLISH(jsc->sc_ca[slot], pckbcintr, sc);
    181 }
    182