2 * Copyright (C) 2002 Benno Rice.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/param.h>
31 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/malloc.h>
37 #include <machine/bus.h>
40 #include <machine/resource.h>
42 #include <dev/ofw/openfirm.h>
44 #include <powerpc/powermac/maciovar.h>
46 struct pswitch_softc {
48 struct resource *sc_irq;
52 static int pswitch_probe(device_t);
53 static int pswitch_attach(device_t);
55 static int pswitch_intr(void *);
57 static device_method_t pswitch_methods[] = {
58 /* Device interface */
59 DEVMETHOD(device_probe, pswitch_probe),
60 DEVMETHOD(device_attach, pswitch_attach),
65 static driver_t pswitch_driver = {
68 sizeof(struct pswitch_softc)
71 static devclass_t pswitch_devclass;
73 DRIVER_MODULE(pswitch, macio, pswitch_driver, pswitch_devclass, 0, 0);
76 pswitch_probe(device_t dev)
78 char *type = macio_get_devtype(dev);
80 if (strcmp(type, "gpio") != 0)
83 device_set_desc(dev, "GPIO Programmer's Switch");
88 pswitch_attach(device_t dev)
90 struct pswitch_softc *sc;
91 phandle_t node, child;
95 sc = device_get_softc(dev);
96 node = macio_get_node(dev);
98 for (child = OF_child(node); child != 0; child = OF_peer(child)) {
99 if (OF_getprop(child, "device_type", type, 32) == -1)
102 if (strcmp(type, "programmer-switch") == 0)
107 device_printf(dev, "could not find correct node\n");
111 if (OF_getprop(child, "interrupts", irq, sizeof(irq)) == -1) {
112 device_printf(dev, "could not get interrupt\n");
117 sc->sc_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->sc_irqrid,
118 irq[0], irq[0], 1, RF_ACTIVE);
119 if (sc->sc_irq == NULL) {
120 device_printf(dev, "could not allocate interrupt\n");
124 if (bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_MISC,
125 pswitch_intr, NULL, dev, &sc->sc_ih) != 0) {
126 device_printf(dev, "could not setup interrupt\n");
127 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irqrid,
136 pswitch_intr(void *arg)
142 kdb_enter(KDB_WHY_POWERPC, device_get_nameunit(dev));
143 return (FILTER_HANDLED);