diff --git a/sys/arm/at91/at91_pit.c b/sys/arm/at91/at91_pit.c index 853dddcfa348..944c75ea2f9a 100644 --- a/sys/arm/at91/at91_pit.c +++ b/sys/arm/at91/at91_pit.c @@ -24,6 +24,8 @@ * SUCH DAMAGE. */ +#include "opt_platform.h" + #include __FBSDID("$FreeBSD$"); @@ -48,6 +50,12 @@ __FBSDID("$FreeBSD$"); #include #include +#ifdef FDT +#include +#include +#include +#endif + #ifndef PIT_PRESCALE #define PIT_PRESCALE (16) #endif @@ -83,6 +91,9 @@ at91_pit_delay(int us) uint64_t pit_freq; const uint64_t mhz = 1E6; + if (sc == NULL) + return; + last = PIT_PIV(RD4(sc, PIT_PIIR)); /* Max delay ~= 260s. @ 133Mhz */ @@ -111,7 +122,10 @@ static struct timecounter at91_pit_timecounter = { static int at91_pit_probe(device_t dev) { - +#ifdef FDT + if (!ofw_bus_is_compatible(dev, "atmel,at91sam9260-pit")) + return (ENXIO); +#endif device_set_desc(dev, "AT91SAM9 PIT"); return (0); } @@ -121,10 +135,8 @@ at91_pit_attach(device_t dev) { void *ih; int rid, err = 0; - struct at91_softc *at91_sc; struct resource *irq; - at91_sc = device_get_softc(device_get_parent(dev)); sc = device_get_softc(dev); sc->sc_dev = dev; @@ -158,22 +170,6 @@ at91_pit_attach(device_t dev) return (err); } -static device_method_t at91_pit_methods[] = { - DEVMETHOD(device_probe, at91_pit_probe), - DEVMETHOD(device_attach, at91_pit_attach), - DEVMETHOD_END -}; - -static driver_t at91_pit_driver = { - "at91_pit", - at91_pit_methods, - sizeof(struct pit_softc), -}; - -static devclass_t at91_pit_devclass; - -DRIVER_MODULE(at91_pit, atmelarm, at91_pit_driver, at91_pit_devclass, NULL, - NULL); static int pit_intr(void *arg) @@ -202,3 +198,25 @@ at91_pit_get_timecount(struct timecounter *tc) icnt = piir >> 20; /* Overflows */ return (timecount + PIT_PIV(piir) + PIT_PIV(RD4(sc, PIT_MR)) * icnt); } + +static device_method_t at91_pit_methods[] = { + DEVMETHOD(device_probe, at91_pit_probe), + DEVMETHOD(device_attach, at91_pit_attach), + DEVMETHOD_END +}; + +static driver_t at91_pit_driver = { + "at91_pit", + at91_pit_methods, + sizeof(struct pit_softc), +}; + +static devclass_t at91_pit_devclass; + +#ifdef FDT +DRIVER_MODULE(at91_pit, simplebus, at91_pit_driver, at91_pit_devclass, NULL, + NULL); +#else +DRIVER_MODULE(at91_pit, atmelarm, at91_pit_driver, at91_pit_devclass, NULL, + NULL); +#endif