Changeset View
Changeset View
Standalone View
Standalone View
sys/powerpc/powermac/pswitch.c
Show All 35 Lines | |||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/bus.h> | #include <sys/bus.h> | ||||
#include <machine/bus.h> | #include <machine/bus.h> | ||||
#include <sys/rman.h> | #include <sys/rman.h> | ||||
#include <machine/resource.h> | #include <machine/resource.h> | ||||
#include <dev/ofw/ofw_bus.h> | |||||
#include <dev/ofw/openfirm.h> | #include <dev/ofw/openfirm.h> | ||||
#include <powerpc/powermac/maciovar.h> | #include <powerpc/powermac/maciovar.h> | ||||
struct pswitch_softc { | struct pswitch_softc { | ||||
int sc_irqrid; | int sc_irq_rid; | ||||
struct resource *sc_irq; | struct resource *sc_irq; | ||||
void *sc_ih; | void *sc_ih; | ||||
jhibbits: do you need sc_dev? I don't see you using it anywhere. | |||||
}; | }; | ||||
static int pswitch_probe(device_t); | static int pswitch_probe(device_t); | ||||
static int pswitch_attach(device_t); | static int pswitch_attach(device_t); | ||||
static int pswitch_intr(void *); | static int pswitch_intr(void *); | ||||
static device_method_t pswitch_methods[] = { | static device_method_t pswitch_methods[] = { | ||||
/* Device interface */ | /* Device interface */ | ||||
DEVMETHOD(device_probe, pswitch_probe), | DEVMETHOD(device_probe, pswitch_probe), | ||||
DEVMETHOD(device_attach, pswitch_attach), | DEVMETHOD(device_attach, pswitch_attach), | ||||
{ 0, 0 } | { 0, 0 } | ||||
}; | }; | ||||
static driver_t pswitch_driver = { | static driver_t pswitch_driver = { | ||||
"pswitch", | "pswitch", | ||||
pswitch_methods, | pswitch_methods, | ||||
sizeof(struct pswitch_softc) | sizeof(struct pswitch_softc) | ||||
}; | }; | ||||
static devclass_t pswitch_devclass; | static devclass_t pswitch_devclass; | ||||
DRIVER_MODULE(pswitch, macio, pswitch_driver, pswitch_devclass, 0, 0); | EARLY_DRIVER_MODULE(pswitch, macgpio, pswitch_driver, pswitch_devclass, | ||||
0, 0, BUS_PASS_RESOURCE); | |||||
static int | static int | ||||
pswitch_probe(device_t dev) | pswitch_probe(device_t dev) | ||||
{ | { | ||||
char *type = macio_get_devtype(dev); | const char *type = ofw_bus_get_type(dev); | ||||
if (strcmp(type, "gpio") != 0) | if (strcmp(type, "programmer-switch") != 0) | ||||
return (ENXIO); | return (ENXIO); | ||||
device_set_desc(dev, "GPIO Programmer's Switch"); | device_set_desc(dev, "GPIO Programmer's Switch"); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
pswitch_attach(device_t dev) | pswitch_attach(device_t dev) | ||||
{ | { | ||||
struct pswitch_softc *sc; | struct pswitch_softc *sc; | ||||
phandle_t node, child; | |||||
char type[32]; | |||||
u_int irq[2]; | |||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
node = macio_get_node(dev); | |||||
for (child = OF_child(node); child != 0; child = OF_peer(child)) { | sc->sc_irq_rid = 0; | ||||
if (OF_getprop(child, "device_type", type, 32) == -1) | sc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, | ||||
continue; | &sc->sc_irq_rid, RF_ACTIVE); | ||||
if (strcmp(type, "programmer-switch") == 0) | |||||
break; | |||||
} | |||||
if (child == 0) { | |||||
device_printf(dev, "could not find correct node\n"); | |||||
return (ENXIO); | |||||
} | |||||
if (OF_getprop(child, "interrupts", irq, sizeof(irq)) == -1) { | |||||
device_printf(dev, "could not get interrupt\n"); | |||||
return (ENXIO); | |||||
} | |||||
sc->sc_irqrid = 0; | |||||
sc->sc_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->sc_irqrid, | |||||
irq[0], irq[0], 1, RF_ACTIVE); | |||||
if (sc->sc_irq == NULL) { | if (sc->sc_irq == NULL) { | ||||
device_printf(dev, "could not allocate interrupt\n"); | device_printf(dev, "could not allocate interrupt\n"); | ||||
return (ENXIO); | return (ENXIO); | ||||
} | } | ||||
if (bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_MISC, | if (bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_MISC | INTR_EXCL, | ||||
pswitch_intr, NULL, dev, &sc->sc_ih) != 0) { | pswitch_intr, NULL, dev, &sc->sc_ih) != 0) { | ||||
device_printf(dev, "could not setup interrupt\n"); | device_printf(dev, "could not setup interrupt\n"); | ||||
bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irqrid, | bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irq_rid, | ||||
sc->sc_irq); | sc->sc_irq); | ||||
return (ENXIO); | return (ENXIO); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
Show All 9 Lines |
do you need sc_dev? I don't see you using it anywhere.