pckbc_ofisa.c revision 1.18
11.18Sthorpej/* $NetBSD: pckbc_ofisa.c,v 1.18 2021/01/27 02:31:03 thorpej 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 * 181.1Smatt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 191.1Smatt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 201.1Smatt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 211.1Smatt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 221.1Smatt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 231.1Smatt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 241.1Smatt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 251.1Smatt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 261.1Smatt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 271.1Smatt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 281.1Smatt */ 291.1Smatt 301.2Slukem#include <sys/cdefs.h> 311.18Sthorpej__KERNEL_RCSID(0, "$NetBSD: pckbc_ofisa.c,v 1.18 2021/01/27 02:31:03 thorpej Exp $"); 321.2Slukem 331.1Smatt#include <sys/param.h> 341.1Smatt#include <sys/systm.h> 351.1Smatt#include <sys/kernel.h> 361.1Smatt#include <sys/proc.h> 371.1Smatt#include <sys/device.h> 381.9Sperry#include <sys/malloc.h> 391.1Smatt#include <sys/errno.h> 401.1Smatt#include <sys/queue.h> 411.13Sad#include <sys/bus.h> 421.1Smatt 431.9Sperry#include <dev/isa/isareg.h> 441.1Smatt#include <dev/isa/isavar.h> 451.1Smatt 461.1Smatt#include <dev/ofw/openfirm.h> 471.1Smatt#include <dev/ofisa/ofisavar.h> 481.1Smatt 491.1Smatt#include <dev/ic/i8042reg.h> 501.1Smatt#include <dev/ic/pckbcvar.h> 511.1Smatt 521.15Scubestatic int pckbc_ofisa_match (device_t, cfdata_t, void *); 531.15Scubestatic void pckbc_ofisa_attach (device_t, device_t, void *); 541.1Smatt 551.1Smattstruct pckbc_ofisa_softc { 561.1Smatt struct pckbc_softc sc_pckbc; 571.1Smatt 581.1Smatt isa_chipset_tag_t sc_ic; 591.1Smatt struct ofisa_intr_desc sc_intr[PCKBC_NSLOTS]; 601.1Smatt}; 611.1Smatt 621.15ScubeCFATTACH_DECL_NEW(pckbc_ofisa, sizeof(struct pckbc_ofisa_softc), 631.7Sthorpej pckbc_ofisa_match, pckbc_ofisa_attach, NULL, NULL); 641.1Smatt 651.1Smattstatic void pckbc_ofisa_intr_establish (struct pckbc_softc *, pckbc_slot_t); 661.1Smatt 671.16Sthorpejstatic const struct device_compatible_entry compat_data[] = { 681.16Sthorpej { .compat = "INTC,80c42" }, 691.18Sthorpej DEVICE_COMPAT_EOL 701.16Sthorpej}; 711.16Sthorpej 721.16Sthorpejstatic const struct device_compatible_entry port_compat_data[] = { 731.16Sthorpej { .compat = "pnpPNP,303", .value = PCKBC_KBD_SLOT }, 741.16Sthorpej { .compat = "pnpPNP,f03", .value = PCKBC_AUX_SLOT }, 751.18Sthorpej DEVICE_COMPAT_EOL 761.16Sthorpej}; 771.1Smatt 781.1Smattstatic int 791.15Scubepckbc_ofisa_match(device_t parent, cfdata_t match, void *aux) 801.1Smatt{ 811.1Smatt struct ofisa_attach_args *aa = aux; 821.1Smatt 831.16Sthorpej return of_match_compat_data(aa->oba.oba_phandle, compat_data) ? 5 : 0; 841.1Smatt} 851.1Smatt 861.1Smattstatic void 871.15Scubepckbc_ofisa_attach(device_t parent, device_t self, void *aux) 881.1Smatt{ 891.11Sthorpej struct pckbc_ofisa_softc *osc = device_private(self); 901.1Smatt struct pckbc_softc *sc = &osc->sc_pckbc; 911.1Smatt struct ofisa_attach_args *aa = aux; 921.16Sthorpej const struct device_compatible_entry *dce; 931.1Smatt struct pckbc_internal *t; 941.1Smatt bus_space_tag_t iot; 951.1Smatt bus_space_handle_t ioh_d, ioh_c; 961.1Smatt struct ofisa_reg_desc regs[2]; 971.1Smatt int phandle; 981.1Smatt int n; 991.1Smatt 1001.15Scube sc->sc_dv = self; 1011.1Smatt osc->sc_ic = aa->ic; 1021.1Smatt iot = aa->iot; 1031.1Smatt 1041.1Smatt phandle = OF_child(aa->oba.oba_phandle); 1051.1Smatt while (phandle != 0) { 1061.16Sthorpej dce = of_search_compatible(phandle, port_compat_data); 1071.16Sthorpej if (dce != NULL) { 1081.16Sthorpej ofisa_intr_get(phandle, &osc->sc_intr[dce->value], 1); 1091.1Smatt } 1101.1Smatt phandle = OF_peer(phandle); 1111.1Smatt } 1121.1Smatt 1131.1Smatt sc->intr_establish = pckbc_ofisa_intr_establish; 1141.1Smatt 1151.1Smatt if (pckbc_is_console(iot, IO_KBD)) { 1161.1Smatt t = &pckbc_consdata; 1171.1Smatt ioh_d = t->t_ioh_d; 1181.1Smatt ioh_c = t->t_ioh_c; 1191.1Smatt pckbc_console_attached = 1; 1201.1Smatt /* t->t_cmdbyte was initialized by cnattach */ 1211.1Smatt } else { 1221.1Smatt n = ofisa_reg_get(aa->oba.oba_phandle, regs, 2); 1231.1Smatt if (n != 2 || regs[0].type != OFISA_REG_TYPE_IO || regs[1].type != OFISA_REG_TYPE_IO 1241.1Smatt || bus_space_map(iot, regs[0].addr, regs[0].len, 0, &ioh_d) 1251.1Smatt || bus_space_map(iot, regs[1].addr, regs[1].len, 0, &ioh_c)) 1261.1Smatt panic("pckbc_attach: couldn't map"); 1271.1Smatt 1281.3Stsutsui t = malloc(sizeof(struct pckbc_internal), M_DEVBUF, 1291.3Stsutsui M_WAITOK|M_ZERO); 1301.1Smatt t->t_iot = iot; 1311.1Smatt t->t_ioh_d = ioh_d; 1321.1Smatt t->t_ioh_c = ioh_c; 1331.1Smatt t->t_addr = regs[0].addr; 1341.1Smatt t->t_cmdbyte = KC8_CPU; /* Enable ports */ 1351.12Sad callout_init(&t->t_cleanup, 0); 1361.1Smatt } 1371.1Smatt 1381.1Smatt t->t_sc = sc; 1391.1Smatt sc->id = t; 1401.1Smatt 1411.15Scube aprint_normal("\n"); 1421.1Smatt 1431.1Smatt /* Finish off the attach. */ 1441.1Smatt pckbc_attach(sc); 1451.1Smatt} 1461.1Smatt 1471.1Smattstatic void 1481.1Smattpckbc_ofisa_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot) 1491.1Smatt{ 1501.1Smatt struct pckbc_ofisa_softc *osc = (void *) sc; 1511.1Smatt void *rv; 1521.1Smatt 1531.1Smatt rv = isa_intr_establish(osc->sc_ic, osc->sc_intr[slot].irq, osc->sc_intr[slot].share, 1541.1Smatt IPL_TTY, pckbcintr, sc); 1551.1Smatt if (rv == NULL) { 1561.15Scube aprint_error_dev(sc->sc_dv, 1571.15Scube "unable to establish interrupt for %s slot\n", 1581.15Scube pckbc_slot_names[slot]); 1591.1Smatt } else { 1601.15Scube aprint_normal_dev(sc->sc_dv, "using irq %d for %s slot\n", 1611.1Smatt osc->sc_intr[slot].irq, pckbc_slot_names[slot]); 1621.1Smatt } 1631.1Smatt} 164