1/* 2 * Copyright (C) 2002 Benno Rice. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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. 24 *
| 1/* 2 * Copyright (C) 2002 Benno Rice. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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. 24 *
|
33#include <sys/malloc.h> 34#include <sys/bus.h> 35#include <machine/bus.h> 36#include <sys/rman.h> 37 38#include <machine/resource.h> 39 40#include <dev/ofw/openfirm.h> 41 42#include <powerpc/powermac/maciovar.h> 43 44struct pswitch_softc { 45 int sc_irqrid; 46 struct resource *sc_irq; 47 void *sc_ih; 48}; 49 50static int pswitch_probe(device_t); 51static int pswitch_attach(device_t); 52 53static void pswitch_intr(void *); 54 55static device_method_t pswitch_methods[] = { 56 /* Device interface */ 57 DEVMETHOD(device_probe, pswitch_probe), 58 DEVMETHOD(device_attach, pswitch_attach), 59 60 { 0, 0 } 61}; 62 63static driver_t pswitch_driver = { 64 "pswitch", 65 pswitch_methods, 66 sizeof(struct pswitch_softc) 67}; 68 69static devclass_t pswitch_devclass; 70 71DRIVER_MODULE(pswitch, macio, pswitch_driver, pswitch_devclass, 0, 0); 72 73static int 74pswitch_probe(device_t dev) 75{ 76 char *type = macio_get_devtype(dev); 77 78 if (strcmp(type, "gpio") != 0) 79 return (ENXIO); 80 81 device_set_desc(dev, "GPIO Programmer's Switch"); 82 return (0); 83} 84 85static int 86pswitch_attach(device_t dev) 87{ 88 struct pswitch_softc *sc; 89 phandle_t node, child; 90 char type[32]; 91 u_int irq[2]; 92 93 sc = device_get_softc(dev); 94 node = macio_get_node(dev); 95 96 for (child = OF_child(node); child != 0; child = OF_peer(child)) { 97 if (OF_getprop(child, "device_type", type, 32) == -1) 98 continue; 99 100 if (strcmp(type, "programmer-switch") == 0) 101 break; 102 } 103 104 if (child == 0) { 105 device_printf(dev, "could not find correct node\n"); 106 return (ENXIO); 107 } 108 109 if (OF_getprop(child, "interrupts", irq, sizeof(irq)) == -1) { 110 device_printf(dev, "could not get interrupt\n"); 111 return (ENXIO); 112 } 113 114 sc->sc_irqrid = 0; 115 sc->sc_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->sc_irqrid, 116 irq[0], irq[0], 1, RF_ACTIVE); 117 if (sc->sc_irq == NULL) { 118 device_printf(dev, "could not allocate interrupt\n"); 119 return (ENXIO); 120 } 121 122 if (bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_MISC | INTR_FAST, 123 pswitch_intr, dev, &sc->sc_ih) != 0) { 124 device_printf(dev, "could not setup interrupt\n"); 125 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irqrid, 126 sc->sc_irq); 127 return (ENXIO); 128 } 129 130 return (0); 131} 132 133static void 134pswitch_intr(void *arg) 135{ 136 device_t dev; 137 138 dev = (device_t)arg; 139
| 35#include <sys/malloc.h> 36#include <sys/bus.h> 37#include <machine/bus.h> 38#include <sys/rman.h> 39 40#include <machine/resource.h> 41 42#include <dev/ofw/openfirm.h> 43 44#include <powerpc/powermac/maciovar.h> 45 46struct pswitch_softc { 47 int sc_irqrid; 48 struct resource *sc_irq; 49 void *sc_ih; 50}; 51 52static int pswitch_probe(device_t); 53static int pswitch_attach(device_t); 54 55static void pswitch_intr(void *); 56 57static device_method_t pswitch_methods[] = { 58 /* Device interface */ 59 DEVMETHOD(device_probe, pswitch_probe), 60 DEVMETHOD(device_attach, pswitch_attach), 61 62 { 0, 0 } 63}; 64 65static driver_t pswitch_driver = { 66 "pswitch", 67 pswitch_methods, 68 sizeof(struct pswitch_softc) 69}; 70 71static devclass_t pswitch_devclass; 72 73DRIVER_MODULE(pswitch, macio, pswitch_driver, pswitch_devclass, 0, 0); 74 75static int 76pswitch_probe(device_t dev) 77{ 78 char *type = macio_get_devtype(dev); 79 80 if (strcmp(type, "gpio") != 0) 81 return (ENXIO); 82 83 device_set_desc(dev, "GPIO Programmer's Switch"); 84 return (0); 85} 86 87static int 88pswitch_attach(device_t dev) 89{ 90 struct pswitch_softc *sc; 91 phandle_t node, child; 92 char type[32]; 93 u_int irq[2]; 94 95 sc = device_get_softc(dev); 96 node = macio_get_node(dev); 97 98 for (child = OF_child(node); child != 0; child = OF_peer(child)) { 99 if (OF_getprop(child, "device_type", type, 32) == -1) 100 continue; 101 102 if (strcmp(type, "programmer-switch") == 0) 103 break; 104 } 105 106 if (child == 0) { 107 device_printf(dev, "could not find correct node\n"); 108 return (ENXIO); 109 } 110 111 if (OF_getprop(child, "interrupts", irq, sizeof(irq)) == -1) { 112 device_printf(dev, "could not get interrupt\n"); 113 return (ENXIO); 114 } 115 116 sc->sc_irqrid = 0; 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"); 121 return (ENXIO); 122 } 123 124 if (bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_MISC | INTR_FAST, 125 pswitch_intr, 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, 128 sc->sc_irq); 129 return (ENXIO); 130 } 131 132 return (0); 133} 134 135static void 136pswitch_intr(void *arg) 137{ 138 device_t dev; 139 140 dev = (device_t)arg; 141
|