pckbc_ofisa.c revision 1.3
11.3Stsutsui/* $NetBSD: pckbc_ofisa.c,v 1.3 2002/01/14 13:32:46 tsutsui Exp $ */ 21.1Smatt 31.1Smatt/* 41.1Smatt * Copyright (c) 1998 51.1Smatt * Matthias Drochner. All rights reserved. 61.1Smatt * Copyright (c) 2001 71.1Smatt * Matt Thomas. All rights reserved. 81.1Smatt * 91.1Smatt * Redistribution and use in source and binary forms, with or without 101.1Smatt * modification, are permitted provided that the following conditions 111.1Smatt * are met: 121.1Smatt * 1. Redistributions of source code must retain the above copyright 131.1Smatt * notice, this list of conditions and the following disclaimer. 141.1Smatt * 2. Redistributions in binary form must reproduce the above copyright 151.1Smatt * notice, this list of conditions and the following disclaimer in the 161.1Smatt * documentation and/or other materials provided with the distribution. 171.1Smatt * 3. All advertising materials mentioning features or use of this software 181.1Smatt * must display the following acknowledgement: 191.1Smatt * This product includes software developed for the NetBSD Project 201.1Smatt * by Matthias Drochner. 211.1Smatt * 4. The name of the author may not be used to endorse or promote products 221.1Smatt * derived from this software without specific prior written permission. 231.1Smatt * 241.1Smatt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 251.1Smatt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 261.1Smatt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 271.1Smatt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 281.1Smatt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 291.1Smatt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 301.1Smatt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 311.1Smatt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 321.1Smatt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 331.1Smatt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 341.1Smatt */ 351.1Smatt 361.2Slukem#include <sys/cdefs.h> 371.3Stsutsui__KERNEL_RCSID(0, "$NetBSD: pckbc_ofisa.c,v 1.3 2002/01/14 13:32:46 tsutsui Exp $"); 381.2Slukem 391.1Smatt#include <sys/param.h> 401.1Smatt#include <sys/systm.h> 411.1Smatt#include <sys/kernel.h> 421.1Smatt#include <sys/proc.h> 431.1Smatt#include <sys/device.h> 441.1Smatt#include <sys/malloc.h> 451.1Smatt#include <sys/errno.h> 461.1Smatt#include <sys/queue.h> 471.1Smatt#include <sys/lock.h> 481.1Smatt 491.1Smatt#include <machine/bus.h> 501.1Smatt 511.1Smatt#include <dev/isa/isareg.h> 521.1Smatt#include <dev/isa/isavar.h> 531.1Smatt 541.1Smatt#include <dev/ofw/openfirm.h> 551.1Smatt#include <dev/ofisa/ofisavar.h> 561.1Smatt 571.1Smatt#include <dev/ic/i8042reg.h> 581.1Smatt#include <dev/ic/pckbcvar.h> 591.1Smatt 601.1Smattstatic int pckbc_ofisa_match (struct device *, struct cfdata *, void *); 611.1Smattstatic void pckbc_ofisa_attach (struct device *, struct device *, void *); 621.1Smatt 631.1Smattstruct pckbc_ofisa_softc { 641.1Smatt struct pckbc_softc sc_pckbc; 651.1Smatt 661.1Smatt isa_chipset_tag_t sc_ic; 671.1Smatt struct ofisa_intr_desc sc_intr[PCKBC_NSLOTS]; 681.1Smatt}; 691.1Smatt 701.1Smattstruct cfattach pckbc_ofisa_ca = { 711.1Smatt sizeof(struct pckbc_ofisa_softc), pckbc_ofisa_match, pckbc_ofisa_attach, 721.1Smatt}; 731.1Smatt 741.1Smattstatic void pckbc_ofisa_intr_establish (struct pckbc_softc *, pckbc_slot_t); 751.1Smatt 761.1Smattstatic const char *kb_compatible_strings[] = { "pnpPNP,303", NULL }; 771.1Smattstatic const char *ms_compatible_strings[] = { "pnpPNP,f03", NULL }; 781.1Smatt 791.1Smattstatic int 801.1Smattpckbc_ofisa_match(struct device *parent, struct cfdata *match, void *aux) 811.1Smatt{ 821.1Smatt struct ofisa_attach_args *aa = aux; 831.1Smatt static const char *compatible_strings[] = { "INTC,80c42", NULL }; 841.1Smatt int rv = 0; 851.1Smatt 861.1Smatt if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1) 871.1Smatt rv = 5; 881.1Smatt 891.1Smatt return (rv); 901.1Smatt} 911.1Smatt 921.1Smattstatic void 931.1Smattpckbc_ofisa_attach(struct device *parent, struct device *self, void *aux) 941.1Smatt{ 951.1Smatt struct pckbc_ofisa_softc *osc = (void *)self; 961.1Smatt struct pckbc_softc *sc = &osc->sc_pckbc; 971.1Smatt struct ofisa_attach_args *aa = aux; 981.1Smatt struct pckbc_internal *t; 991.1Smatt bus_space_tag_t iot; 1001.1Smatt bus_space_handle_t ioh_d, ioh_c; 1011.1Smatt struct ofisa_reg_desc regs[2]; 1021.1Smatt int phandle; 1031.1Smatt int n; 1041.1Smatt 1051.1Smatt osc->sc_ic = aa->ic; 1061.1Smatt iot = aa->iot; 1071.1Smatt 1081.1Smatt phandle = OF_child(aa->oba.oba_phandle); 1091.1Smatt while (phandle != 0) { 1101.1Smatt if (of_compatible(phandle, kb_compatible_strings) != -1) { 1111.1Smatt ofisa_intr_get(phandle, &osc->sc_intr[PCKBC_KBD_SLOT], 1); 1121.1Smatt } else if (of_compatible(phandle, ms_compatible_strings) != -1) { 1131.1Smatt ofisa_intr_get(phandle, &osc->sc_intr[PCKBC_AUX_SLOT], 1); 1141.1Smatt } 1151.1Smatt phandle = OF_peer(phandle); 1161.1Smatt } 1171.1Smatt 1181.1Smatt sc->intr_establish = pckbc_ofisa_intr_establish; 1191.1Smatt 1201.1Smatt if (pckbc_is_console(iot, IO_KBD)) { 1211.1Smatt t = &pckbc_consdata; 1221.1Smatt ioh_d = t->t_ioh_d; 1231.1Smatt ioh_c = t->t_ioh_c; 1241.1Smatt pckbc_console_attached = 1; 1251.1Smatt /* t->t_cmdbyte was initialized by cnattach */ 1261.1Smatt } else { 1271.1Smatt n = ofisa_reg_get(aa->oba.oba_phandle, regs, 2); 1281.1Smatt if (n != 2 || regs[0].type != OFISA_REG_TYPE_IO || regs[1].type != OFISA_REG_TYPE_IO 1291.1Smatt || bus_space_map(iot, regs[0].addr, regs[0].len, 0, &ioh_d) 1301.1Smatt || bus_space_map(iot, regs[1].addr, regs[1].len, 0, &ioh_c)) 1311.1Smatt panic("pckbc_attach: couldn't map"); 1321.1Smatt 1331.3Stsutsui t = malloc(sizeof(struct pckbc_internal), M_DEVBUF, 1341.3Stsutsui M_WAITOK|M_ZERO); 1351.1Smatt t->t_iot = iot; 1361.1Smatt t->t_ioh_d = ioh_d; 1371.1Smatt t->t_ioh_c = ioh_c; 1381.1Smatt t->t_addr = regs[0].addr; 1391.1Smatt t->t_cmdbyte = KC8_CPU; /* Enable ports */ 1401.1Smatt callout_init(&t->t_cleanup); 1411.1Smatt } 1421.1Smatt 1431.1Smatt t->t_sc = sc; 1441.1Smatt sc->id = t; 1451.1Smatt 1461.1Smatt printf("\n"); 1471.1Smatt 1481.1Smatt /* Finish off the attach. */ 1491.1Smatt pckbc_attach(sc); 1501.1Smatt} 1511.1Smatt 1521.1Smattstatic void 1531.1Smattpckbc_ofisa_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot) 1541.1Smatt{ 1551.1Smatt struct pckbc_ofisa_softc *osc = (void *) sc; 1561.1Smatt void *rv; 1571.1Smatt 1581.1Smatt rv = isa_intr_establish(osc->sc_ic, osc->sc_intr[slot].irq, osc->sc_intr[slot].share, 1591.1Smatt IPL_TTY, pckbcintr, sc); 1601.1Smatt if (rv == NULL) { 1611.1Smatt printf("%s: unable to establish interrupt for %s slot\n", 1621.1Smatt sc->sc_dv.dv_xname, pckbc_slot_names[slot]); 1631.1Smatt } else { 1641.1Smatt printf("%s: using irq %d for %s slot\n", sc->sc_dv.dv_xname, 1651.1Smatt osc->sc_intr[slot].irq, pckbc_slot_names[slot]); 1661.1Smatt } 1671.1Smatt} 168