Cleanup some of the newbus infrastructure.
[dragonfly.git] / sys / dev / misc / pps / pps.c
index 01d310c..f92b6cf 100644 (file)
@@ -7,7 +7,7 @@
  * ----------------------------------------------------------------------------
  *
  * $FreeBSD: src/sys/dev/ppbus/pps.c,v 1.24.2.1 2000/05/24 00:20:57 n_hibma Exp $
- * $DragonFly: src/sys/dev/misc/pps/pps.c,v 1.4 2003/07/21 07:57:41 dillon Exp $
+ * $DragonFly: src/sys/dev/misc/pps/pps.c,v 1.14 2005/10/28 03:25:50 dillon Exp $
  *
  * This driver implements a draft-mogul-pps-api-02.txt PPS source.
  *
@@ -16,6 +16,8 @@
  *
  */
 
+#include "use_pps.h"
+
 #include <sys/param.h>
 #include <sys/kernel.h>
 #include <sys/systm.h>
 #include <machine/resource.h>
 #include <sys/rman.h>
 
-#include <dev/ppbus/ppbconf.h>
+#include <bus/ppbus/ppbconf.h>
 #include "ppbus_if.h"
-#include <dev/ppbus/ppbio.h>
-#include "pps.h"
+#include <bus/ppbus/ppbio.h>
 
 #define PPS_NAME       "pps"           /* our official name */
 
@@ -64,7 +65,7 @@ static struct cdevsw pps_cdevsw = {
        /* maj */       CDEV_MAJOR,
        /* flags */     0,
        /* port */      NULL,
-       /* autoq */     0,
+       /* clone */     NULL,
 
        /* open */      ppsopen,
        /* close */     ppsclose,
@@ -78,27 +79,14 @@ static struct cdevsw pps_cdevsw = {
        /* psize */     nopsize
 };
 
-static void
-ppsidentify(driver_t *driver, device_t parent)
-{
-
-       BUS_ADD_CHILD(parent, 0, PPS_NAME, 0);
-}
-
 static int
 ppsprobe(device_t ppsdev)
 {
        struct pps_data *sc;
-       dev_t dev;
-       int unit;
 
        sc = DEVTOSOFTC(ppsdev);
        bzero(sc, sizeof(struct pps_data));
 
-       unit = device_get_unit(ppsdev);
-       dev = make_dev(&pps_cdevsw, unit,
-           UID_ROOT, GID_WHEEL, 0644, PPS_NAME "%d", unit);
-
        device_set_desc(ppsdev, "Pulse per second Timing Interface");
 
        sc->pps.ppscap = PPS_CAPTUREASSERT | PPS_ECHOASSERT;
@@ -107,24 +95,30 @@ ppsprobe(device_t ppsdev)
 }
 
 static int
-ppsattach(device_t dev)
+ppsattach(device_t ppsdev)
 {
-       struct pps_data *sc = DEVTOSOFTC(dev);
-       device_t ppbus = device_get_parent(dev);
-       int irq, zero = 0;
+       struct pps_data *sc = DEVTOSOFTC(ppsdev);
+       device_t ppbus = device_get_parent(ppsdev);
+       int irq;
+       int unit;
+       int zero = 0;
 
        /* retrieve the ppbus irq */
-       BUS_READ_IVAR(ppbus, dev, PPBUS_IVAR_IRQ, &irq);
+       BUS_READ_IVAR(ppbus, ppsdev, PPBUS_IVAR_IRQ, &irq);
 
        if (irq > 0) {
                /* declare our interrupt handler */
-               sc->intr_resource = bus_alloc_resource(dev, SYS_RES_IRQ,
+               sc->intr_resource = bus_alloc_resource(ppsdev, SYS_RES_IRQ,
                                       &zero, irq, irq, 1, RF_SHAREABLE);
        }
        /* interrupts seem mandatory */
        if (sc->intr_resource == 0)
                return (ENXIO);
 
+       unit = device_get_unit(ppsdev);
+       cdevsw_add(&pps_cdevsw, -1, unit);
+       make_dev(&pps_cdevsw, unit, UID_ROOT, GID_WHEEL, 0644,
+                   PPS_NAME "%d", unit);
        return (0);
 }
 
@@ -143,8 +137,8 @@ ppsopen(dev_t dev, int flags, int fmt, struct thread *td)
 
                /* attach the interrupt handler */
                if ((error = BUS_SETUP_INTR(ppbus, ppsdev, sc->intr_resource,
-                              INTR_TYPE_TTY, ppsintr, ppsdev,
-                              &sc->intr_cookie))) {
+                              0, ppsintr, ppsdev,
+                              &sc->intr_cookie, NULL))) {
                        ppb_release_bus(ppbus, ppsdev);
                        return (error);
                }
@@ -182,16 +176,14 @@ ppsintr(void *arg)
        device_t ppsdev = (device_t)arg;
        device_t ppbus = device_get_parent(ppsdev);
        struct pps_data *sc = DEVTOSOFTC(ppsdev);
-       struct timecounter *tc;
-       unsigned count;
+       sysclock_t count;
 
-       tc = timecounter;
-       count = timecounter->tc_get_timecount(tc);
+       count = sys_cputimer->count();
        if (!(ppb_rstr(ppbus) & nACK))
                return;
        if (sc->pps.ppsparam.mode & PPS_ECHOASSERT) 
                ppb_wctr(ppbus, IRQENABLE | AUTOFEED);
-       pps_event(&sc->pps, tc, count, PPS_CAPTUREASSERT);
+       pps_event(&sc->pps, count, PPS_CAPTUREASSERT);
        if (sc->pps.ppsparam.mode & PPS_ECHOASSERT) 
                ppb_wctr(ppbus, IRQENABLE);
 }
@@ -205,9 +197,13 @@ ppsioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct thread *td)
        return (pps_ioctl(cmd, data, &sc->pps));
 }
 
+/*
+ * Becuase pps is a static device under any attached ppbus, and not scanned
+ * by the ppbus, we need an identify function to create the device.
+ */
 static device_method_t pps_methods[] = {
        /* device interface */
-       DEVMETHOD(device_identify,      ppsidentify),
+       DEVMETHOD(device_identify,      bus_generic_identify),
        DEVMETHOD(device_probe,         ppsprobe),
        DEVMETHOD(device_attach,        ppsattach),