1998-02-13 13:00:02 +00:00
|
|
|
/*
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
* "THE BEER-WARE LICENSE" (Revision 42):
|
|
|
|
* <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
|
|
|
|
* can do whatever you want with this stuff. If we meet some day, and you think
|
|
|
|
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*
|
1999-03-13 16:22:18 +00:00
|
|
|
* $Id: pps.c,v 1.14 1999/03/11 15:09:51 phk Exp $
|
1998-06-12 23:15:53 +00:00
|
|
|
*
|
|
|
|
* This driver implements a draft-mogul-pps-api-02.txt PPS source.
|
|
|
|
*
|
|
|
|
* The input pin is pin#10
|
|
|
|
* The echo output pin is pin#14
|
1998-02-13 13:00:02 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
#include "opt_devfs.h"
|
|
|
|
|
1998-02-13 13:00:02 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
1998-06-07 19:44:22 +00:00
|
|
|
#include <sys/timepps.h>
|
1998-02-13 13:00:02 +00:00
|
|
|
#ifdef DEVFS
|
|
|
|
#include <sys/devfsext.h>
|
1998-02-15 14:54:09 +00:00
|
|
|
#endif
|
1998-02-13 13:00:02 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
|
|
|
#include <dev/ppbus/ppbconf.h>
|
1998-02-13 17:35:33 +00:00
|
|
|
#include "pps.h"
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1998-06-07 19:44:22 +00:00
|
|
|
#define PPS_NAME "lppps" /* our official name */
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
static struct pps_data {
|
|
|
|
int pps_unit;
|
|
|
|
struct ppb_device pps_dev;
|
1999-03-11 15:09:51 +00:00
|
|
|
struct pps_state pps;
|
1998-02-13 17:35:33 +00:00
|
|
|
} *softc[NPPS];
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
static int npps;
|
1998-02-13 13:00:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make ourselves visible as a ppbus driver
|
|
|
|
*/
|
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
static struct ppb_device *ppsprobe(struct ppb_data *ppb);
|
|
|
|
static int ppsattach(struct ppb_device *dev);
|
|
|
|
static void ppsintr(int unit);
|
|
|
|
static void pps_drvinit(void *unused);
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
static struct ppb_driver ppsdriver = {
|
|
|
|
ppsprobe, ppsattach, PPS_NAME
|
1998-02-13 13:00:02 +00:00
|
|
|
};
|
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
DATA_SET(ppbdriver_set, ppsdriver);
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
static d_open_t ppsopen;
|
|
|
|
static d_close_t ppsclose;
|
1998-06-07 19:44:22 +00:00
|
|
|
static d_ioctl_t ppsioctl;
|
1998-02-13 13:00:02 +00:00
|
|
|
|
|
|
|
#define CDEV_MAJOR 89
|
1998-02-15 14:54:09 +00:00
|
|
|
static struct cdevsw pps_cdevsw =
|
1998-06-07 19:44:22 +00:00
|
|
|
{ ppsopen, ppsclose, noread, nowrite,
|
|
|
|
ppsioctl, nullstop, nullreset, nodevtotty,
|
1998-02-13 17:35:33 +00:00
|
|
|
seltrue, nommap, nostrat, PPS_NAME,
|
1998-02-13 13:00:02 +00:00
|
|
|
NULL, -1 };
|
|
|
|
|
1999-03-11 15:09:51 +00:00
|
|
|
|
1998-02-13 13:00:02 +00:00
|
|
|
static struct ppb_device *
|
1998-02-15 14:54:09 +00:00
|
|
|
ppsprobe(struct ppb_data *ppb)
|
1998-02-13 13:00:02 +00:00
|
|
|
{
|
1998-02-15 14:54:09 +00:00
|
|
|
struct pps_data *sc;
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
sc = (struct pps_data *) malloc(sizeof(struct pps_data),
|
1998-02-13 13:00:02 +00:00
|
|
|
M_TEMP, M_NOWAIT);
|
|
|
|
if (!sc) {
|
1998-02-13 17:35:33 +00:00
|
|
|
printf(PPS_NAME ": cannot malloc!\n");
|
1998-02-13 13:00:02 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1998-02-15 14:54:09 +00:00
|
|
|
bzero(sc, sizeof(struct pps_data));
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
softc[npps] = sc;
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
sc->pps_unit = npps++;
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
sc->pps_dev.id_unit = sc->pps_unit;
|
|
|
|
sc->pps_dev.ppb = ppb;
|
1998-08-03 19:14:33 +00:00
|
|
|
sc->pps_dev.name = ppsdriver.name;
|
1998-02-15 14:54:09 +00:00
|
|
|
sc->pps_dev.intr = ppsintr;
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1999-03-11 15:09:51 +00:00
|
|
|
sc->pps.ppscap = PPS_CAPTUREASSERT | PPS_ECHOASSERT;
|
|
|
|
pps_init(&sc->pps);
|
1998-02-15 14:54:09 +00:00
|
|
|
return (&sc->pps_dev);
|
1998-02-13 13:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1998-02-15 14:54:09 +00:00
|
|
|
ppsattach(struct ppb_device *dev)
|
1998-02-13 13:00:02 +00:00
|
|
|
{
|
1999-03-11 15:09:51 +00:00
|
|
|
dev_t devt;
|
|
|
|
|
1998-02-13 13:00:02 +00:00
|
|
|
/*
|
|
|
|
* Report ourselves
|
|
|
|
*/
|
1998-02-13 17:35:33 +00:00
|
|
|
printf(PPS_NAME "%d: <Pulse per second Timing Interface> on ppbus %d\n",
|
1998-02-13 13:00:02 +00:00
|
|
|
dev->id_unit, dev->ppb->ppb_link->adapter_unit);
|
|
|
|
|
|
|
|
#ifdef DEVFS
|
1998-02-15 14:54:09 +00:00
|
|
|
devfs_add_devswf(&pps_cdevsw,
|
1998-02-13 13:00:02 +00:00
|
|
|
dev->id_unit, DV_CHR,
|
1998-02-13 17:35:33 +00:00
|
|
|
UID_ROOT, GID_WHEEL, 0600, PPS_NAME "%d", dev->id_unit);
|
1998-02-13 13:00:02 +00:00
|
|
|
#endif
|
1999-03-13 16:22:18 +00:00
|
|
|
devt = makedev(CDEV_MAJOR, 0);
|
|
|
|
cdevsw_add(&devt, &pps_cdevsw, NULL);
|
1998-02-13 13:00:02 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1998-02-15 14:54:09 +00:00
|
|
|
ppsopen(dev_t dev, int flags, int fmt, struct proc *p)
|
1998-02-13 13:00:02 +00:00
|
|
|
{
|
1998-02-15 14:54:09 +00:00
|
|
|
struct pps_data *sc;
|
1998-02-13 13:00:02 +00:00
|
|
|
u_int unit = minor(dev);
|
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
if ((unit >= npps))
|
1998-02-13 13:00:02 +00:00
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
sc = softc[unit];
|
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
if (ppb_request_bus(&sc->pps_dev, PPB_WAIT|PPB_INTR))
|
1998-02-13 13:00:02 +00:00
|
|
|
return (EINTR);
|
|
|
|
|
1999-01-30 15:35:39 +00:00
|
|
|
ppb_wctr(&sc->pps_dev, 0);
|
1998-06-07 19:44:22 +00:00
|
|
|
ppb_wctr(&sc->pps_dev, IRQENABLE);
|
1998-02-13 13:00:02 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1998-02-15 14:54:09 +00:00
|
|
|
ppsclose(dev_t dev, int flags, int fmt, struct proc *p)
|
1998-02-13 13:00:02 +00:00
|
|
|
{
|
1998-02-15 14:54:09 +00:00
|
|
|
struct pps_data *sc = softc[minor(dev)];
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1999-03-11 15:09:51 +00:00
|
|
|
sc->pps.ppsparam.mode = 0; /* PHK ??? */
|
1999-01-30 15:35:39 +00:00
|
|
|
|
|
|
|
ppb_wdtr(&sc->pps_dev, 0);
|
|
|
|
ppb_wctr(&sc->pps_dev, 0);
|
|
|
|
|
1998-02-15 14:54:09 +00:00
|
|
|
ppb_release_bus(&sc->pps_dev);
|
1998-02-13 13:00:02 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-02-15 14:54:09 +00:00
|
|
|
ppsintr(int unit)
|
1998-02-13 13:00:02 +00:00
|
|
|
{
|
1998-02-15 14:54:09 +00:00
|
|
|
struct pps_data *sc = softc[unit];
|
1999-03-11 15:09:51 +00:00
|
|
|
struct timecounter *tc;
|
|
|
|
unsigned count;
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1999-03-11 15:09:51 +00:00
|
|
|
tc = timecounter;
|
|
|
|
count = timecounter->tc_get_timecount(tc);
|
1998-02-15 14:54:09 +00:00
|
|
|
if (!(ppb_rstr(&sc->pps_dev) & nACK))
|
1998-02-13 13:00:02 +00:00
|
|
|
return;
|
1999-03-11 15:09:51 +00:00
|
|
|
if (sc->pps.ppsparam.mode & PPS_ECHOASSERT)
|
1998-06-07 19:44:22 +00:00
|
|
|
ppb_wctr(&sc->pps_dev, IRQENABLE | AUTOFEED);
|
1999-03-11 15:09:51 +00:00
|
|
|
pps_event(&sc->pps, tc, count, PPS_CAPTUREASSERT);
|
|
|
|
if (sc->pps.ppsparam.mode & PPS_ECHOASSERT)
|
1998-06-07 19:44:22 +00:00
|
|
|
ppb_wctr(&sc->pps_dev, IRQENABLE);
|
1998-02-13 13:00:02 +00:00
|
|
|
}
|
|
|
|
|
1998-06-07 19:44:22 +00:00
|
|
|
static int
|
1998-06-08 02:43:12 +00:00
|
|
|
ppsioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
|
1998-02-13 13:00:02 +00:00
|
|
|
{
|
1998-02-15 14:54:09 +00:00
|
|
|
struct pps_data *sc = softc[minor(dev)];
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1999-03-11 15:09:51 +00:00
|
|
|
return (pps_ioctl(cmd, data, &sc->pps));
|
1998-02-13 13:00:02 +00:00
|
|
|
}
|
|
|
|
|