1/* $NetBSD: pckbc_pbus.c,v 1.5 2020/11/21 15:42:20 thorpej Exp $ */ 2 3/* 4 * Copyright 2001 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Simon Burge and Eduardo Horvath for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38#include <sys/cdefs.h> 39__KERNEL_RCSID(0, "$NetBSD: pckbc_pbus.c,v 1.5 2020/11/21 15:42:20 thorpej Exp $"); 40 41#include <sys/param.h> 42#include <sys/systm.h> 43#include <sys/kernel.h> 44#include <sys/device.h> 45#include <sys/kmem.h> 46 47#include <machine/intr.h> 48#include <machine/walnut.h> 49 50#include <arch/walnut/dev/pbusvar.h> 51#include <powerpc/ibm4xx/dev/plbvar.h> 52 53#include <dev/ic/i8042reg.h> 54#include <dev/ic/pckbcvar.h> 55 56struct pckbc_pbus_softc { 57 struct pckbc_softc sc_pckbc; 58 59 // XXX void *sc_ih[PCKBC_NSLOTS]; 60 int sc_irq[PCKBC_NSLOTS]; 61 62}; 63 64 65static int pckbc_pbus_probe(device_t, cfdata_t, void *); 66static void pckbc_pbus_attach(device_t, device_t, void *); 67static void pckbc_pbus_intr_establish(struct pckbc_softc *, pckbc_slot_t); 68 69CFATTACH_DECL_NEW(pckbc_pbus, sizeof(struct pckbc_pbus_softc), 70 pckbc_pbus_probe, pckbc_pbus_attach, NULL, NULL); 71 72int pckbcfound = 0; 73 74int 75pckbc_pbus_probe(device_t parent, cfdata_t cf, void *aux) 76{ 77 struct pbus_attach_args *paa = aux; 78 79 /* match only pckbc devices */ 80 if (strcmp(paa->pb_name, cf->cf_name) != 0) 81 return 0; 82 83 return (pckbcfound < 1); 84} 85 86struct pckbc_softc *pckbc0; /* XXX */ 87 88void 89pckbc_pbus_attach(device_t parent, device_t self, void *aux) 90{ 91 struct pckbc_pbus_softc *msc = device_private(self); 92 struct pckbc_softc *sc = &msc->sc_pckbc; 93 struct pbus_attach_args *paa = aux; 94 struct pckbc_internal *t; 95 bus_space_handle_t ioh_d, ioh_c; 96 bus_space_tag_t iot = paa->pb_bt; 97 u_long addr = paa->pb_addr; 98 99 sc->sc_dv = self; 100 /* 101 * Set up IRQs 102 */ 103 msc->sc_irq[PCKBC_KBD_SLOT] = paa->pb_irq; 104 msc->sc_irq[PCKBC_AUX_SLOT] = paa->pb_irq + 1; /* XXX */ 105 106 sc->intr_establish = pckbc_pbus_intr_establish; 107 108 if (pckbc_is_console(iot, addr)) { 109 t = &pckbc_consdata; 110 pckbc_console_attached = 1; 111 /* t->t_cmdbyte was initialized by cnattach */ 112 } else { 113 if (bus_space_map(iot, addr + KEY_MOUSE_DATA, 1, 0, &ioh_d) || 114 bus_space_map(iot, addr + KEY_MOUSE_CMD, 1, 0, &ioh_c)) 115 panic("pckbc_attach: couldn't map"); 116 117 t = kmem_zalloc(sizeof(struct pckbc_internal), KM_SLEEP); 118 t->t_iot = iot; 119 t->t_ioh_d = ioh_d; 120 t->t_ioh_c = ioh_c; 121 t->t_addr = addr; 122 t->t_cmdbyte = KC8_CPU; /* Enable ports */ 123 } 124 125 t->t_sc = sc; 126 sc->id = t; 127 128 aprint_normal("\n"); 129 130 /* Finish off the attach. */ 131 pckbc_attach(sc); 132 133 pckbcfound++; 134 135 return; 136} 137 138static void 139pckbc_pbus_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot) 140{ 141 struct pckbc_pbus_softc *msc = (void *)sc; 142 int irq = msc->sc_irq[slot]; 143 144 if (slot > PCKBC_NSLOTS) { 145 aprint_error("pckbc_pbus_intr_establish: attempt to establish " 146 "interrupt at slot %d\n", slot); 147 return; 148 } 149 150 intr_establish(irq, IST_LEVEL, IPL_SERIAL, pckbcintr, sc); 151 aprint_normal_dev(sc->sc_dv, "%s slot interrupting at irq %d\n", 152 pckbc_slot_names[slot], irq); 153} 154