pckbc_ofisa.c revision 1.11
11.11Sthorpej/* $NetBSD: pckbc_ofisa.c,v 1.11 2006/03/29 07:09:33 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.11Sthorpej__KERNEL_RCSID(0, "$NetBSD: pckbc_ofisa.c,v 1.11 2006/03/29 07:09:33 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.1Smatt#include <sys/lock.h>
421.1Smatt
431.1Smatt#include <machine/bus.h>
441.1Smatt
451.9Sperry#include <dev/isa/isareg.h>
461.1Smatt#include <dev/isa/isavar.h>
471.1Smatt
481.1Smatt#include <dev/ofw/openfirm.h>
491.1Smatt#include <dev/ofisa/ofisavar.h>
501.1Smatt
511.1Smatt#include <dev/ic/i8042reg.h>
521.1Smatt#include <dev/ic/pckbcvar.h>
531.1Smatt
541.1Smattstatic int pckbc_ofisa_match (struct device *, struct cfdata *, void *);
551.1Smattstatic void pckbc_ofisa_attach (struct device *, struct device *, void *);
561.1Smatt
571.1Smattstruct pckbc_ofisa_softc {
581.1Smatt	struct pckbc_softc sc_pckbc;
591.1Smatt
601.1Smatt	isa_chipset_tag_t sc_ic;
611.1Smatt	struct ofisa_intr_desc sc_intr[PCKBC_NSLOTS];
621.1Smatt};
631.1Smatt
641.6SthorpejCFATTACH_DECL(pckbc_ofisa, sizeof(struct pckbc_ofisa_softc),
651.7Sthorpej    pckbc_ofisa_match, pckbc_ofisa_attach, NULL, NULL);
661.1Smatt
671.1Smattstatic void pckbc_ofisa_intr_establish (struct pckbc_softc *, pckbc_slot_t);
681.1Smatt
691.4Syamtstatic const char *const kb_compatible_strings[] = { "pnpPNP,303", NULL };
701.4Syamtstatic const char *const ms_compatible_strings[] = { "pnpPNP,f03", NULL };
711.1Smatt
721.1Smattstatic int
731.1Smattpckbc_ofisa_match(struct device *parent, struct cfdata *match, void *aux)
741.1Smatt{
751.1Smatt	struct ofisa_attach_args *aa = aux;
761.4Syamt	static const char *const compatible_strings[] = { "INTC,80c42", NULL };
771.1Smatt	int rv = 0;
781.1Smatt
791.1Smatt	if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
801.1Smatt		rv = 5;
811.1Smatt
821.1Smatt	return (rv);
831.1Smatt}
841.1Smatt
851.1Smattstatic void
861.1Smattpckbc_ofisa_attach(struct device *parent, struct device *self, void *aux)
871.1Smatt{
881.11Sthorpej	struct pckbc_ofisa_softc *osc = device_private(self);
891.1Smatt	struct pckbc_softc *sc = &osc->sc_pckbc;
901.1Smatt	struct ofisa_attach_args *aa = aux;
911.1Smatt	struct pckbc_internal *t;
921.1Smatt	bus_space_tag_t iot;
931.1Smatt	bus_space_handle_t ioh_d, ioh_c;
941.1Smatt	struct ofisa_reg_desc regs[2];
951.1Smatt	int phandle;
961.1Smatt	int n;
971.1Smatt
981.1Smatt	osc->sc_ic = aa->ic;
991.1Smatt	iot = aa->iot;
1001.1Smatt
1011.1Smatt	phandle = OF_child(aa->oba.oba_phandle);
1021.1Smatt	while (phandle != 0) {
1031.1Smatt		if (of_compatible(phandle, kb_compatible_strings) != -1) {
1041.1Smatt			ofisa_intr_get(phandle, &osc->sc_intr[PCKBC_KBD_SLOT], 1);
1051.1Smatt		} else if (of_compatible(phandle, ms_compatible_strings) != -1) {
1061.1Smatt			ofisa_intr_get(phandle, &osc->sc_intr[PCKBC_AUX_SLOT], 1);
1071.1Smatt		}
1081.1Smatt		phandle = OF_peer(phandle);
1091.1Smatt	}
1101.1Smatt
1111.1Smatt	sc->intr_establish = pckbc_ofisa_intr_establish;
1121.1Smatt
1131.1Smatt	if (pckbc_is_console(iot, IO_KBD)) {
1141.1Smatt		t = &pckbc_consdata;
1151.1Smatt		ioh_d = t->t_ioh_d;
1161.1Smatt		ioh_c = t->t_ioh_c;
1171.1Smatt		pckbc_console_attached = 1;
1181.1Smatt		/* t->t_cmdbyte was initialized by cnattach */
1191.1Smatt	} else {
1201.1Smatt		n = ofisa_reg_get(aa->oba.oba_phandle, regs, 2);
1211.1Smatt		if (n != 2 || regs[0].type != OFISA_REG_TYPE_IO || regs[1].type != OFISA_REG_TYPE_IO
1221.1Smatt		    || bus_space_map(iot, regs[0].addr, regs[0].len, 0, &ioh_d)
1231.1Smatt		    || bus_space_map(iot, regs[1].addr, regs[1].len, 0, &ioh_c))
1241.1Smatt			panic("pckbc_attach: couldn't map");
1251.1Smatt
1261.3Stsutsui		t = malloc(sizeof(struct pckbc_internal), M_DEVBUF,
1271.3Stsutsui		    M_WAITOK|M_ZERO);
1281.1Smatt		t->t_iot = iot;
1291.1Smatt		t->t_ioh_d = ioh_d;
1301.1Smatt		t->t_ioh_c = ioh_c;
1311.1Smatt		t->t_addr = regs[0].addr;
1321.1Smatt		t->t_cmdbyte = KC8_CPU; /* Enable ports */
1331.1Smatt		callout_init(&t->t_cleanup);
1341.1Smatt	}
1351.1Smatt
1361.1Smatt	t->t_sc = sc;
1371.1Smatt	sc->id = t;
1381.1Smatt
1391.1Smatt	printf("\n");
1401.1Smatt
1411.1Smatt	/* Finish off the attach. */
1421.1Smatt	pckbc_attach(sc);
1431.1Smatt}
1441.1Smatt
1451.1Smattstatic void
1461.1Smattpckbc_ofisa_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot)
1471.1Smatt{
1481.1Smatt	struct pckbc_ofisa_softc *osc = (void *) sc;
1491.1Smatt	void *rv;
1501.1Smatt
1511.1Smatt	rv = isa_intr_establish(osc->sc_ic, osc->sc_intr[slot].irq, osc->sc_intr[slot].share,
1521.1Smatt	    IPL_TTY, pckbcintr, sc);
1531.1Smatt	if (rv == NULL) {
1541.1Smatt		printf("%s: unable to establish interrupt for %s slot\n",
1551.1Smatt		    sc->sc_dv.dv_xname, pckbc_slot_names[slot]);
1561.1Smatt	} else {
1571.1Smatt		printf("%s: using irq %d for %s slot\n", sc->sc_dv.dv_xname,
1581.1Smatt		    osc->sc_intr[slot].irq, pckbc_slot_names[slot]);
1591.1Smatt	}
1601.1Smatt}
161