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
This commit is contained in:
parent
f30f11f878
commit
0c9f52d4ce
@ -215,6 +215,7 @@ device smu # Apple System Management Unit
|
|||||||
device adm1030 # Apple G4 MDD fan controller
|
device adm1030 # Apple G4 MDD fan controller
|
||||||
device atibl # ATI-based backlight driver for PowerBooks/iBooks
|
device atibl # ATI-based backlight driver for PowerBooks/iBooks
|
||||||
device nvbl # nVidia-based backlight driver for PowerBooks/iBooks
|
device nvbl # nVidia-based backlight driver for PowerBooks/iBooks
|
||||||
|
device pswitch # Macio programmer's switch
|
||||||
|
|
||||||
# ADB support
|
# ADB support
|
||||||
device adb
|
device adb
|
||||||
|
@ -41,12 +41,13 @@
|
|||||||
|
|
||||||
#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;
|
||||||
};
|
};
|
||||||
@ -71,14 +72,15 @@ static driver_t pswitch_driver = {
|
|||||||
|
|
||||||
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");
|
||||||
@ -89,43 +91,21 @@ 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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user