1 /* $NetBSD: pckbc_pbus.c,v 1.3 2005/12/11 12:17:13 christos Exp $ */
4 * Copyright 2001 Wasabi Systems, Inc.
7 * Written by Simon Burge and Eduardo Horvath for Wasabi Systems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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
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.
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: pckbc_pbus.c,v 1.3 2005/12/11 12:17:13 christos Exp $");
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/device.h>
45 #include <sys/malloc.h>
47 #include <machine/intr.h>
48 #include <machine/walnut.h>
50 #include <arch/walnut/dev/pbusvar.h>
51 #include <powerpc/ibm4xx/dev/plbvar.h>
53 #include <dev/ic/i8042reg.h>
54 #include <dev/ic/pckbcvar.h>
56 struct pckbc_pbus_softc
{
57 struct pckbc_softc sc_pckbc
;
59 // XXX void *sc_ih[PCKBC_NSLOTS];
60 int sc_irq
[PCKBC_NSLOTS
];
65 static int pckbc_pbus_probe(device_t
, cfdata_t
, void *);
66 static void pckbc_pbus_attach(device_t
, device_t
, void *);
67 static void pckbc_pbus_intr_establish(struct pckbc_softc
*, pckbc_slot_t
);
69 CFATTACH_DECL_NEW(pckbc_pbus
, sizeof(struct pckbc_pbus_softc
),
70 pckbc_pbus_probe
, pckbc_pbus_attach
, NULL
, NULL
);
75 pckbc_pbus_probe(device_t parent
, cfdata_t cf
, void *aux
)
77 struct pbus_attach_args
*paa
= aux
;
79 /* match only pckbc devices */
80 if (strcmp(paa
->pb_name
, cf
->cf_name
) != 0)
83 return (pckbcfound
< 1);
86 struct pckbc_softc
*pckbc0
; /* XXX */
89 pckbc_pbus_attach(device_t parent
, device_t self
, void *aux
)
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
;
103 msc
->sc_irq
[PCKBC_KBD_SLOT
] = paa
->pb_irq
;
104 msc
->sc_irq
[PCKBC_AUX_SLOT
] = paa
->pb_irq
+ 1; /* XXX */
106 sc
->intr_establish
= pckbc_pbus_intr_establish
;
108 if (pckbc_is_console(iot
, addr
)) {
110 pckbc_console_attached
= 1;
111 /* t->t_cmdbyte was initialized by cnattach */
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");
117 t
= malloc(sizeof(struct pckbc_internal
), M_DEVBUF
, M_WAITOK
);
118 memset(t
, 0, sizeof(struct pckbc_internal
));
123 t
->t_cmdbyte
= KC8_CPU
; /* Enable ports */
131 /* Finish off the attach. */
140 pckbc_pbus_intr_establish(struct pckbc_softc
*sc
, pckbc_slot_t slot
)
142 struct pckbc_pbus_softc
*msc
= (void *)sc
;
143 int irq
= msc
->sc_irq
[slot
];
145 if (slot
> PCKBC_NSLOTS
) {
146 aprint_error("pckbc_pbus_intr_establish: attempt to establish "
147 "interrupt at slot %d\n", slot
);
151 intr_establish(irq
, IST_LEVEL
, IPL_SERIAL
, pckbcintr
, sc
);
152 aprint_normal_dev(sc
->sc_dv
, "%s slot interrupting at irq %d\n",
153 pckbc_slot_names
[slot
], irq
);