diff options
author | Brandon Bergren <bdragon@FreeBSD.org> | 2021-04-05 17:04:12 +0000 |
---|---|---|
committer | Brandon Bergren <bdragon@FreeBSD.org> | 2021-04-05 17:04:12 +0000 |
commit | 0c9f52d4cebf18addbea45bd19abd910ba1ea43b (patch) | |
tree | e3e43bff364109cf4d6ed2e179a4a013fe8e5b5c /sys/powerpc | |
parent | f30f11f878fe2aa535cd286810d31c92793a3d95 (diff) | |
download | src-0c9f52d4cebf18addbea45bd19abd910ba1ea43b.tar.gz src-0c9f52d4cebf18addbea45bd19abd910ba1ea43b.zip |
powerpc: Fix programmer's switch driver and add to GENERIC
Older G4 and G3 models have a programmer's switch that can be used to
generate an interrupt to drop into the debugger.
This code hadn't been tested for a long time. It had been broken back
in 2005 in r153050.
Repair and modernize the code and add it to GENERIC.
Reviewed by: jhibbits (approved w/ removal of unused sc_dev var)
Sponsored by: Tag1 Consulting, Inc.
Differential Revision: https://reviews.freebsd.org/D29131
Diffstat (limited to 'sys/powerpc')
-rw-r--r-- | sys/powerpc/conf/GENERIC | 1 | ||||
-rw-r--r-- | sys/powerpc/powermac/pswitch.c | 46 |
2 files changed, 14 insertions, 33 deletions
diff --git a/sys/powerpc/conf/GENERIC b/sys/powerpc/conf/GENERIC index dc3484d7f614..7854e89d17b7 100644 --- a/sys/powerpc/conf/GENERIC +++ b/sys/powerpc/conf/GENERIC @@ -215,6 +215,7 @@ device smu # Apple System Management Unit device adm1030 # Apple G4 MDD fan controller device atibl # ATI-based backlight driver for PowerBooks/iBooks device nvbl # nVidia-based backlight driver for PowerBooks/iBooks +device pswitch # Macio programmer's switch # ADB support device adb diff --git a/sys/powerpc/powermac/pswitch.c b/sys/powerpc/powermac/pswitch.c index df47b5ae6d1f..e2da0f534188 100644 --- a/sys/powerpc/powermac/pswitch.c +++ b/sys/powerpc/powermac/pswitch.c @@ -41,14 +41,15 @@ #include <machine/resource.h> +#include <dev/ofw/ofw_bus.h> #include <dev/ofw/openfirm.h> #include <powerpc/powermac/maciovar.h> struct pswitch_softc { - int sc_irqrid; - struct resource *sc_irq; - void *sc_ih; + int sc_irq_rid; + struct resource *sc_irq; + void *sc_ih; }; static int pswitch_probe(device_t); @@ -71,14 +72,15 @@ static driver_t pswitch_driver = { 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 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); device_set_desc(dev, "GPIO Programmer's Switch"); @@ -89,43 +91,21 @@ static int pswitch_attach(device_t dev) { struct pswitch_softc *sc; - phandle_t node, child; - char type[32]; - u_int irq[2]; sc = device_get_softc(dev); - node = macio_get_node(dev); - for (child = OF_child(node); child != 0; child = OF_peer(child)) { - if (OF_getprop(child, "device_type", type, 32) == -1) - continue; - - 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); + sc->sc_irq_rid = 0; + sc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, + &sc->sc_irq_rid, RF_ACTIVE); if (sc->sc_irq == NULL) { device_printf(dev, "could not allocate interrupt\n"); 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) { 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); return (ENXIO); } |