1 /* $NetBSD: pckbc_jazzio.c,v 1.11 2004/03/24 17:06:58 drochner 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 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 __KERNEL_RCSID(0, "$NetBSD: pckbc_jazzio.c,v 1.11 2004/03/24 17:06:58 drochner Exp $"); 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/kernel.h> 35 #include <sys/proc.h> 36 #include <sys/device.h> 37 #include <sys/malloc.h> 38 #include <sys/errno.h> 39 #include <sys/queue.h> 40 #include <sys/lock.h> 41 42 #include <machine/autoconf.h> 43 #include <machine/bus.h> 44 #include <arc/jazz/pica.h> 45 #include <arc/jazz/jazziovar.h> 46 47 #include <dev/ic/i8042reg.h> 48 #include <dev/ic/pckbcvar.h> 49 #include <arc/jazz/pckbc_jazzioreg.h> 50 51 #define PMS_INTR 7 /* XXX - should be obtained from firmware */ 52 #define PICA_KBCMDP (PICA_SYS_KBD + JAZZIO_KBCMDP) 53 54 int pckbc_jazzio_match __P((struct device *, struct cfdata *, void *)); 55 void pckbc_jazzio_attach __P((struct device *, struct device *, void *)); 56 void pckbc_jazzio_intr_establish __P((struct pckbc_softc *, pckbc_slot_t)); 57 58 struct pckbc_jazzio_softc { 59 struct pckbc_softc sc_pckbc; 60 61 int sc_intr[PCKBC_NSLOTS]; 62 }; 63 64 CFATTACH_DECL(pckbc_jazzio, sizeof(struct pckbc_jazzio_softc), 65 pckbc_jazzio_match, pckbc_jazzio_attach, NULL, NULL); 66 67 int 68 pckbc_jazzio_match(parent, match, aux) 69 struct device *parent; 70 struct cfdata *match; 71 void *aux; 72 { 73 struct jazzio_attach_args *ja = aux; 74 bus_space_tag_t iot = ja->ja_bust; 75 bus_space_handle_t ioh_d, ioh_c; 76 bus_addr_t addr = ja->ja_addr; 77 int res, ok = 1; 78 79 if (strcmp(ja->ja_name, "I8742") != 0) 80 return (0); 81 82 if (pckbc_is_console(iot, addr) == 0) { 83 struct pckbc_internal t; 84 85 if (bus_space_map(iot, addr + KBDATAP, 1, 0, &ioh_d)) 86 return (0); 87 if (bus_space_map(iot, PICA_KBCMDP, 1, 0, &ioh_c)) { 88 bus_space_unmap(iot, ioh_d, 1); 89 return (0); 90 } 91 92 memset(&t, 0, sizeof(t)); 93 t.t_iot = iot; 94 t.t_ioh_d = ioh_d; 95 t.t_ioh_c = ioh_c; 96 97 /* flush KBC */ 98 (void) pckbc_poll_data1(&t, PCKBC_KBD_SLOT); 99 100 /* KBC selftest */ 101 if (pckbc_send_cmd(iot, ioh_c, KBC_SELFTEST) == 0) { 102 ok = 0; 103 goto out; 104 } 105 res = pckbc_poll_data1(&t, PCKBC_KBD_SLOT); 106 if (res != 0x55) { 107 printf("kbc selftest: %x\n", res); 108 ok = 0; 109 } 110 out: 111 bus_space_unmap(iot, ioh_d, 1); 112 bus_space_unmap(iot, ioh_c, 1); 113 } 114 115 return (ok); 116 } 117 118 void 119 pckbc_jazzio_attach(parent, self, aux) 120 struct device *parent, *self; 121 void *aux; 122 { 123 struct jazzio_attach_args *ja = aux; 124 struct pckbc_jazzio_softc *jsc = (void *)self; 125 struct pckbc_softc *sc = &jsc->sc_pckbc; 126 struct pckbc_internal *t; 127 bus_space_tag_t iot = ja->ja_bust; 128 bus_space_handle_t ioh_d, ioh_c; 129 bus_addr_t addr = ja->ja_addr; 130 131 sc->intr_establish = pckbc_jazzio_intr_establish; 132 133 /* 134 * To establish interrupt handler 135 * 136 * XXX handcrafting "aux" slot... 137 */ 138 jsc->sc_intr[PCKBC_KBD_SLOT] = ja->ja_intr; 139 jsc->sc_intr[PCKBC_AUX_SLOT] = PMS_INTR; /* XXX */ 140 141 if (pckbc_is_console(iot, addr)) { 142 t = &pckbc_consdata; 143 ioh_d = t->t_ioh_d; 144 ioh_c = t->t_ioh_c; 145 pckbc_console_attached = 1; 146 /* t->t_cmdbyte was initialized by cnattach */ 147 } else { 148 if (bus_space_map(iot, addr + KBDATAP, 1, 0, &ioh_d) || 149 bus_space_map(iot, PICA_KBCMDP, 1, 0, &ioh_c)) 150 panic("pckbc_attach: couldn't map"); 151 152 t = malloc(sizeof(struct pckbc_internal), M_DEVBUF, M_WAITOK); 153 bzero(t, sizeof(struct pckbc_internal)); 154 t->t_iot = iot; 155 t->t_ioh_d = ioh_d; 156 t->t_ioh_c = ioh_c; 157 t->t_addr = addr; 158 t->t_cmdbyte = KC8_CPU; /* Enable ports */ 159 callout_init(&t->t_cleanup); 160 } 161 162 t->t_sc = sc; 163 sc->id = t; 164 165 printf("\n"); 166 167 /* Finish off the attach. */ 168 pckbc_attach(sc); 169 } 170 171 void 172 pckbc_jazzio_intr_establish(sc, slot) 173 struct pckbc_softc *sc; 174 pckbc_slot_t slot; 175 { 176 struct pckbc_jazzio_softc *jsc = (void *) sc; 177 178 jazzio_intr_establish(jsc->sc_intr[slot], pckbcintr, sc); 179 } 180