pckbc_ofisa.c revision 1.6
11.6Sthorpej/* $NetBSD: pckbc_ofisa.c,v 1.6 2002/09/30 22:08:02 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 * 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.6Sthorpej__KERNEL_RCSID(0, "$NetBSD: pckbc_ofisa.c,v 1.6 2002/09/30 22:08:02 thorpej 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.6SthorpejCFATTACH_DECL(pckbc_ofisa, sizeof(struct pckbc_ofisa_softc),
711.6Sthorpej    pckbc_ofisa_match, pckbc_ofisa_attach, NULL, NULL)
721.1Smatt
731.1Smattstatic void pckbc_ofisa_intr_establish (struct pckbc_softc *, pckbc_slot_t);
741.1Smatt
751.4Syamtstatic const char *const kb_compatible_strings[] = { "pnpPNP,303", NULL };
761.4Syamtstatic const char *const ms_compatible_strings[] = { "pnpPNP,f03", NULL };
771.1Smatt
781.1Smattstatic int
791.1Smattpckbc_ofisa_match(struct device *parent, struct cfdata *match, void *aux)
801.1Smatt{
811.1Smatt	struct ofisa_attach_args *aa = aux;
821.4Syamt	static const char *const compatible_strings[] = { "INTC,80c42", NULL };
831.1Smatt	int rv = 0;
841.1Smatt
851.1Smatt	if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
861.1Smatt		rv = 5;
871.1Smatt
881.1Smatt	return (rv);
891.1Smatt}
901.1Smatt
911.1Smattstatic void
921.1Smattpckbc_ofisa_attach(struct device *parent, struct device *self, void *aux)
931.1Smatt{
941.1Smatt	struct pckbc_ofisa_softc *osc = (void *)self;
951.1Smatt	struct pckbc_softc *sc = &osc->sc_pckbc;
961.1Smatt	struct ofisa_attach_args *aa = aux;
971.1Smatt	struct pckbc_internal *t;
981.1Smatt	bus_space_tag_t iot;
991.1Smatt	bus_space_handle_t ioh_d, ioh_c;
1001.1Smatt	struct ofisa_reg_desc regs[2];
1011.1Smatt	int phandle;
1021.1Smatt	int n;
1031.1Smatt
1041.1Smatt	osc->sc_ic = aa->ic;
1051.1Smatt	iot = aa->iot;
1061.1Smatt
1071.1Smatt	phandle = OF_child(aa->oba.oba_phandle);
1081.1Smatt	while (phandle != 0) {
1091.1Smatt		if (of_compatible(phandle, kb_compatible_strings) != -1) {
1101.1Smatt			ofisa_intr_get(phandle, &osc->sc_intr[PCKBC_KBD_SLOT], 1);
1111.1Smatt		} else if (of_compatible(phandle, ms_compatible_strings) != -1) {
1121.1Smatt			ofisa_intr_get(phandle, &osc->sc_intr[PCKBC_AUX_SLOT], 1);
1131.1Smatt		}
1141.1Smatt		phandle = OF_peer(phandle);
1151.1Smatt	}
1161.1Smatt
1171.1Smatt	sc->intr_establish = pckbc_ofisa_intr_establish;
1181.1Smatt
1191.1Smatt	if (pckbc_is_console(iot, IO_KBD)) {
1201.1Smatt		t = &pckbc_consdata;
1211.1Smatt		ioh_d = t->t_ioh_d;
1221.1Smatt		ioh_c = t->t_ioh_c;
1231.1Smatt		pckbc_console_attached = 1;
1241.1Smatt		/* t->t_cmdbyte was initialized by cnattach */
1251.1Smatt	} else {
1261.1Smatt		n = ofisa_reg_get(aa->oba.oba_phandle, regs, 2);
1271.1Smatt		if (n != 2 || regs[0].type != OFISA_REG_TYPE_IO || regs[1].type != OFISA_REG_TYPE_IO
1281.1Smatt		    || bus_space_map(iot, regs[0].addr, regs[0].len, 0, &ioh_d)
1291.1Smatt		    || bus_space_map(iot, regs[1].addr, regs[1].len, 0, &ioh_c))
1301.1Smatt			panic("pckbc_attach: couldn't map");
1311.1Smatt
1321.3Stsutsui		t = malloc(sizeof(struct pckbc_internal), M_DEVBUF,
1331.3Stsutsui		    M_WAITOK|M_ZERO);
1341.1Smatt		t->t_iot = iot;
1351.1Smatt		t->t_ioh_d = ioh_d;
1361.1Smatt		t->t_ioh_c = ioh_c;
1371.1Smatt		t->t_addr = regs[0].addr;
1381.1Smatt		t->t_cmdbyte = KC8_CPU; /* Enable ports */
1391.1Smatt		callout_init(&t->t_cleanup);
1401.1Smatt	}
1411.1Smatt
1421.1Smatt	t->t_sc = sc;
1431.1Smatt	sc->id = t;
1441.1Smatt
1451.1Smatt	printf("\n");
1461.1Smatt
1471.1Smatt	/* Finish off the attach. */
1481.1Smatt	pckbc_attach(sc);
1491.1Smatt}
1501.1Smatt
1511.1Smattstatic void
1521.1Smattpckbc_ofisa_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot)
1531.1Smatt{
1541.1Smatt	struct pckbc_ofisa_softc *osc = (void *) sc;
1551.1Smatt	void *rv;
1561.1Smatt
1571.1Smatt	rv = isa_intr_establish(osc->sc_ic, osc->sc_intr[slot].irq, osc->sc_intr[slot].share,
1581.1Smatt	    IPL_TTY, pckbcintr, sc);
1591.1Smatt	if (rv == NULL) {
1601.1Smatt		printf("%s: unable to establish interrupt for %s slot\n",
1611.1Smatt		    sc->sc_dv.dv_xname, pckbc_slot_names[slot]);
1621.1Smatt	} else {
1631.1Smatt		printf("%s: using irq %d for %s slot\n", sc->sc_dv.dv_xname,
1641.1Smatt		    osc->sc_intr[slot].irq, pckbc_slot_names[slot]);
1651.1Smatt	}
1661.1Smatt}
167