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-08-08 22:25:46 +00:00
|
|
|
* $Id: pps.c,v 1.19 1999/05/31 11:25:00 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
#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
|
|
|
|
1999-08-08 22:25:46 +00:00
|
|
|
#define PPS_NAME "pps" /* our official name */
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1999-08-08 22:25:46 +00:00
|
|
|
struct pps_data {
|
1999-04-25 08:58:10 +00:00
|
|
|
int pps_open;
|
1998-02-15 14:54:09 +00:00
|
|
|
struct ppb_device pps_dev;
|
1999-03-11 15:09:51 +00:00
|
|
|
struct pps_state pps;
|
1999-08-08 22:25:46 +00:00
|
|
|
};
|
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);
|
1999-08-08 22:25:46 +00:00
|
|
|
static void ppsintr(struct ppb_device *ppd);
|
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
|
1999-05-30 16:53:49 +00:00
|
|
|
static struct cdevsw pps_cdevsw = {
|
|
|
|
/* open */ ppsopen,
|
|
|
|
/* close */ ppsclose,
|
|
|
|
/* read */ noread,
|
|
|
|
/* write */ nowrite,
|
|
|
|
/* ioctl */ ppsioctl,
|
|
|
|
/* stop */ nostop,
|
|
|
|
/* reset */ noreset,
|
|
|
|
/* devtotty */ nodevtotty,
|
|
|
|
/* poll */ nopoll,
|
|
|
|
/* mmap */ nommap,
|
|
|
|
/* strategy */ nostrategy,
|
|
|
|
/* name */ PPS_NAME,
|
|
|
|
/* parms */ noparms,
|
|
|
|
/* maj */ CDEV_MAJOR,
|
|
|
|
/* dump */ nodump,
|
|
|
|
/* psize */ nopsize,
|
|
|
|
/* flags */ 0,
|
|
|
|
/* maxio */ 0,
|
|
|
|
/* bmaj */ -1
|
|
|
|
};
|
1998-02-13 13:00:02 +00:00
|
|
|
|
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;
|
1999-05-31 11:29:30 +00:00
|
|
|
static int once;
|
1999-08-08 22:25:46 +00:00
|
|
|
dev_t dev;
|
1999-05-31 11:29:30 +00:00
|
|
|
|
|
|
|
if (!once++)
|
|
|
|
cdevsw_add(&pps_cdevsw);
|
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
|
|
|
|
1999-08-08 22:25:46 +00:00
|
|
|
dev = make_dev(&pps_cdevsw, npps,
|
|
|
|
UID_ROOT, GID_WHEEL, 0644, PPS_NAME "%d", npps);
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1999-08-08 22:25:46 +00:00
|
|
|
dev->si_drv1 = sc;
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1999-08-08 22:25:46 +00:00
|
|
|
sc->pps_dev.id_unit = npps++;
|
1998-02-15 14:54:09 +00:00
|
|
|
sc->pps_dev.ppb = ppb;
|
1998-08-03 19:14:33 +00:00
|
|
|
sc->pps_dev.name = ppsdriver.name;
|
1999-08-08 22:25:46 +00:00
|
|
|
sc->pps_dev.bintr = ppsintr;
|
|
|
|
sc->pps_dev.drv1 = sc;
|
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
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
1999-08-08 22:25:46 +00:00
|
|
|
sc = dev->si_drv1;
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1999-04-25 08:58:10 +00:00
|
|
|
if (!sc->pps_open) {
|
|
|
|
if (ppb_request_bus(&sc->pps_dev, PPB_WAIT|PPB_INTR))
|
|
|
|
return (EINTR);
|
1998-02-13 13:00:02 +00:00
|
|
|
|
1999-04-25 08:58:10 +00:00
|
|
|
ppb_wctr(&sc->pps_dev, 0);
|
|
|
|
ppb_wctr(&sc->pps_dev, IRQENABLE);
|
|
|
|
sc->pps_open = 1;
|
|
|
|
}
|
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
|
|
|
{
|
1999-08-08 22:25:46 +00:00
|
|
|
struct pps_data *sc = dev->si_drv1;
|
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);
|
1999-04-25 08:58:10 +00:00
|
|
|
sc->pps_open = 0;
|
1998-02-13 13:00:02 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-08-08 22:25:46 +00:00
|
|
|
ppsintr(struct ppb_device *ppd)
|
1998-02-13 13:00:02 +00:00
|
|
|
{
|
1999-08-08 22:25:46 +00:00
|
|
|
struct pps_data *sc = ppd->drv1;
|
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
|
|
|
{
|
1999-08-08 22:25:46 +00:00
|
|
|
struct pps_data *sc = dev->si_drv1;
|
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
|
|
|
}
|
|
|
|
|