pckbc_ofisa.c revision 1.5
1/* $NetBSD: pckbc_ofisa.c,v 1.5 2002/09/27 20:39:35 thorpej Exp $ */
2
3/*
4 * Copyright (c) 1998
5 *	Matthias Drochner.  All rights reserved.
6 * Copyright (c) 2001
7 *	Matt Thomas.  All rights reserved.
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
20 *	by Matthias Drochner.
21 * 4. The name of the author may not be used to endorse or promote products
22 *    derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#include <sys/cdefs.h>
37__KERNEL_RCSID(0, "$NetBSD: pckbc_ofisa.c,v 1.5 2002/09/27 20:39:35 thorpej Exp $");
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/kernel.h>
42#include <sys/proc.h>
43#include <sys/device.h>
44#include <sys/malloc.h>
45#include <sys/errno.h>
46#include <sys/queue.h>
47#include <sys/lock.h>
48
49#include <machine/bus.h>
50
51#include <dev/isa/isareg.h>
52#include <dev/isa/isavar.h>
53
54#include <dev/ofw/openfirm.h>
55#include <dev/ofisa/ofisavar.h>
56
57#include <dev/ic/i8042reg.h>
58#include <dev/ic/pckbcvar.h>
59
60static int pckbc_ofisa_match (struct device *, struct cfdata *, void *);
61static void pckbc_ofisa_attach (struct device *, struct device *, void *);
62
63struct pckbc_ofisa_softc {
64	struct pckbc_softc sc_pckbc;
65
66	isa_chipset_tag_t sc_ic;
67	struct ofisa_intr_desc sc_intr[PCKBC_NSLOTS];
68};
69
70const struct cfattach pckbc_ofisa_ca = {
71	sizeof(struct pckbc_ofisa_softc), pckbc_ofisa_match, pckbc_ofisa_attach,
72};
73
74static void pckbc_ofisa_intr_establish (struct pckbc_softc *, pckbc_slot_t);
75
76static const char *const kb_compatible_strings[] = { "pnpPNP,303", NULL };
77static const char *const ms_compatible_strings[] = { "pnpPNP,f03", NULL };
78
79static int
80pckbc_ofisa_match(struct device *parent, struct cfdata *match, void *aux)
81{
82	struct ofisa_attach_args *aa = aux;
83	static const char *const compatible_strings[] = { "INTC,80c42", NULL };
84	int rv = 0;
85
86	if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1)
87		rv = 5;
88
89	return (rv);
90}
91
92static void
93pckbc_ofisa_attach(struct device *parent, struct device *self, void *aux)
94{
95	struct pckbc_ofisa_softc *osc = (void *)self;
96	struct pckbc_softc *sc = &osc->sc_pckbc;
97	struct ofisa_attach_args *aa = aux;
98	struct pckbc_internal *t;
99	bus_space_tag_t iot;
100	bus_space_handle_t ioh_d, ioh_c;
101	struct ofisa_reg_desc regs[2];
102	int phandle;
103	int n;
104
105	osc->sc_ic = aa->ic;
106	iot = aa->iot;
107
108	phandle = OF_child(aa->oba.oba_phandle);
109	while (phandle != 0) {
110		if (of_compatible(phandle, kb_compatible_strings) != -1) {
111			ofisa_intr_get(phandle, &osc->sc_intr[PCKBC_KBD_SLOT], 1);
112		} else if (of_compatible(phandle, ms_compatible_strings) != -1) {
113			ofisa_intr_get(phandle, &osc->sc_intr[PCKBC_AUX_SLOT], 1);
114		}
115		phandle = OF_peer(phandle);
116	}
117
118	sc->intr_establish = pckbc_ofisa_intr_establish;
119
120	if (pckbc_is_console(iot, IO_KBD)) {
121		t = &pckbc_consdata;
122		ioh_d = t->t_ioh_d;
123		ioh_c = t->t_ioh_c;
124		pckbc_console_attached = 1;
125		/* t->t_cmdbyte was initialized by cnattach */
126	} else {
127		n = ofisa_reg_get(aa->oba.oba_phandle, regs, 2);
128		if (n != 2 || regs[0].type != OFISA_REG_TYPE_IO || regs[1].type != OFISA_REG_TYPE_IO
129		    || bus_space_map(iot, regs[0].addr, regs[0].len, 0, &ioh_d)
130		    || bus_space_map(iot, regs[1].addr, regs[1].len, 0, &ioh_c))
131			panic("pckbc_attach: couldn't map");
132
133		t = malloc(sizeof(struct pckbc_internal), M_DEVBUF,
134		    M_WAITOK|M_ZERO);
135		t->t_iot = iot;
136		t->t_ioh_d = ioh_d;
137		t->t_ioh_c = ioh_c;
138		t->t_addr = regs[0].addr;
139		t->t_cmdbyte = KC8_CPU; /* Enable ports */
140		callout_init(&t->t_cleanup);
141	}
142
143	t->t_sc = sc;
144	sc->id = t;
145
146	printf("\n");
147
148	/* Finish off the attach. */
149	pckbc_attach(sc);
150}
151
152static void
153pckbc_ofisa_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot)
154{
155	struct pckbc_ofisa_softc *osc = (void *) sc;
156	void *rv;
157
158	rv = isa_intr_establish(osc->sc_ic, osc->sc_intr[slot].irq, osc->sc_intr[slot].share,
159	    IPL_TTY, pckbcintr, sc);
160	if (rv == NULL) {
161		printf("%s: unable to establish interrupt for %s slot\n",
162		    sc->sc_dv.dv_xname, pckbc_slot_names[slot]);
163	} else {
164		printf("%s: using irq %d for %s slot\n", sc->sc_dv.dv_xname,
165		    osc->sc_intr[slot].irq, pckbc_slot_names[slot]);
166	}
167}
168