Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add a 1PPS-over-GPIO driver, originally by Brad...
details: https://anonhg.NetBSD.org/src/rev/8531da5a9749
branches: trunk
changeset: 319201:8531da5a9749
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sun May 20 14:08:32 2018 +0000
description:
Add a 1PPS-over-GPIO driver, originally by Brad Spencer, with changes by
me to adapt to the new GPIO interrupt interface and support a wider variety
of GPIO pin configuations.
PR kern/51676
diffstat:
distrib/sets/lists/man/mi | 5 +-
distrib/sets/lists/modules/mi | 4 +-
etc/MAKEDEV.tmpl | 14 +-
share/man/man4/Makefile | 4 +-
share/man/man8/MAKEDEV.8 | 7 +-
sys/conf/majors | 3 +-
sys/dev/gpio/files.gpio | 7 +-
sys/dev/gpio/gpiopps.c | 540 ++++++++++++++++++++++++++++++++++++++++++
sys/modules/Makefile | 3 +-
9 files changed, 577 insertions(+), 10 deletions(-)
diffs (truncated from 743 to 300 lines):
diff -r 291c446f4cfe -r 8531da5a9749 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Sun May 20 12:08:46 2018 +0000
+++ b/distrib/sets/lists/man/mi Sun May 20 14:08:32 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1587 2018/05/19 14:15:39 thorpej Exp $
+# $NetBSD: mi,v 1.1588 2018/05/20 14:08:32 thorpej Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -1124,6 +1124,7 @@
./usr/share/man/cat4/gpiolock.0 man-sys-catman .cat
./usr/share/man/cat4/gpioow.0 man-sys-catman .cat
./usr/share/man/cat4/gpioirq.0 man-sys-catman .cat
+./usr/share/man/cat4/gpiopps.0 man-sys-catman .cat
./usr/share/man/cat4/gpiopwm.0 man-sys-catman .cat
./usr/share/man/cat4/gpiosim.0 man-sys-catman .cat
./usr/share/man/cat4/gre.0 man-sys-catman .cat
@@ -4265,6 +4266,7 @@
./usr/share/man/html4/gpiolock.html man-sys-htmlman html
./usr/share/man/html4/gpioow.html man-sys-htmlman html
./usr/share/man/html4/gpioirq.html man-sys-htmlman html
+./usr/share/man/html4/gpiopps.html man-sys-htmlman html
./usr/share/man/html4/gpiopwm.html man-sys-htmlman html
./usr/share/man/html4/gpiosim.html man-sys-htmlman html
./usr/share/man/html4/gre.html man-sys-htmlman html
@@ -7180,6 +7182,7 @@
./usr/share/man/man4/gpiolock.4 man-sys-man .man
./usr/share/man/man4/gpioow.4 man-sys-man .man
./usr/share/man/man4/gpioirq.4 man-sys-man .man
+./usr/share/man/man4/gpiopps.4 man-sys-man .man
./usr/share/man/man4/gpiopwm.4 man-sys-man .man
./usr/share/man/man4/gpiosim.4 man-sys-man .man
./usr/share/man/man4/gre.4 man-sys-man .man
diff -r 291c446f4cfe -r 8531da5a9749 distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi Sun May 20 12:08:46 2018 +0000
+++ b/distrib/sets/lists/modules/mi Sun May 20 14:08:32 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.115 2018/05/19 14:15:39 thorpej Exp $
+# $NetBSD: mi,v 1.116 2018/05/20 14:08:33 thorpej Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -136,6 +136,8 @@
./@MODULEDIR@/gpioirq/gpioirq.kmod base-kernel-modules kmod
./@MODULEDIR@/gpioow base-kernel-modules kmod
./@MODULEDIR@/gpioow/gpioow.kmod base-kernel-modules kmod
+./@MODULEDIR@/gpiopps base-kernel-modules kmod
+./@MODULEDIR@/gpiopps/gpiopps.kmod base-kernel-modules kmod
./@MODULEDIR@/gpiosim base-kernel-modules kmod
./@MODULEDIR@/gpiosim/gpiosim.kmod base-kernel-modules kmod
./@MODULEDIR@/hfs base-kernel-modules kmod
diff -r 291c446f4cfe -r 8531da5a9749 etc/MAKEDEV.tmpl
--- a/etc/MAKEDEV.tmpl Sun May 20 12:08:46 2018 +0000
+++ b/etc/MAKEDEV.tmpl Sun May 20 14:08:32 2018 +0000
@@ -1,5 +1,5 @@
#!/bin/sh -
-# $NetBSD: MAKEDEV.tmpl,v 1.189 2018/01/09 03:31:14 christos Exp $
+# $NetBSD: MAKEDEV.tmpl,v 1.190 2018/05/20 14:08:33 thorpej Exp $
#
# Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -242,6 +242,7 @@
# dtv* Digital TV interface
# fb* PMAX generic framebuffer pseudo-device
# fd file descriptors
+# gpiopps* 1PPS signals on GPIO pins
# grf* graphics frame buffer device
# hdaudio* High Definition audio control device
# hdmicec* HDMI CEC devices
@@ -829,6 +830,7 @@
makedev atabus0 atabus1 atabus2 atabus3 atabus4 atabus5 atabus6 atabus7
makedev tap tap0 tap1 tap2 tap3
makedev gpio gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7
+ makedev gpiopps0
makedev pad pad0 pad1 pad2 pad3
makedev bthub
makedev putter
@@ -866,6 +868,11 @@
lndev gpio0 gpio
;;
+gpiopps)
+ makedev gpiopps0
+ lndev gpiopps0 gpiopps
+ ;;
+
lua)
makedev lua0
lndev lua0 lua
@@ -1535,6 +1542,11 @@
mkdev gpio$unit c %gpio_chr% $unit 664 $g_gpio
;;
+gpiopps[0-9]*)
+ unit=${i#gpiopps}
+ mkdev gpiopps$unit c %gpiopps_chr% $unit 664 $g_gpio
+ ;;
+
lua[0-9]*)
unit=${i#lua}
mkdev lua$unit c %lua_chr% $unit 664
diff -r 291c446f4cfe -r 8531da5a9749 share/man/man4/Makefile
--- a/share/man/man4/Makefile Sun May 20 12:08:46 2018 +0000
+++ b/share/man/man4/Makefile Sun May 20 14:08:32 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.653 2018/05/19 14:15:39 thorpej Exp $
+# $NetBSD: Makefile,v 1.654 2018/05/20 14:08:33 thorpej Exp $
# @(#)Makefile 8.1 (Berkeley) 6/18/93
MAN= aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -26,7 +26,7 @@
fast_ipsec.4 fd.4 filemon.4 finsio.4 flash.4 fpa.4 fms.4 fss.4 \
fujbp.4 full.4 fxp.4 \
gcscaudio.4 gem.4 genfb.4 gentbi.4 geodeide.4 \
- glxtphy.4 gpib.4 gpio.4 gpioirq.4 gpiolock.4 gpiopwm.4 \
+ glxtphy.4 gpib.4 gpio.4 gpioirq.4 gpiolock.4 gpiopps.4 gpiopwm.4 \
gpiosim.4 gre.4 gphyter.4 gsip.4 \
hdaudio.4 hifn.4 hme.4 hpacel.4 hpqlb.4 hptide.4 hythygtemp.4 \
ibmcd.4 ibmhawk.4 ichsmb.4 icmp.4 icp.4 icsphy.4 iee.4 ieee80211.4 \
diff -r 291c446f4cfe -r 8531da5a9749 share/man/man8/MAKEDEV.8
--- a/share/man/man8/MAKEDEV.8 Sun May 20 12:08:46 2018 +0000
+++ b/share/man/man8/MAKEDEV.8 Sun May 20 14:08:32 2018 +0000
@@ -6,7 +6,7 @@
.\" *** DO NOT EDIT - any changes will be lost!!!
.\" *** ------------------------------------------------------------------
.\"
-.\" $NetBSD: MAKEDEV.8,v 1.47 2018/01/23 19:14:09 sevan Exp $
+.\" $NetBSD: MAKEDEV.8,v 1.48 2018/05/20 14:08:33 thorpej Exp $
.\"
.\" Copyright (c) 2001, 2003, 2007, 2008 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -35,7 +35,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd January 23, 2018
+.Dd May 11, 2018
.Dt MAKEDEV 8
.Os
.Sh NAME
@@ -736,6 +736,9 @@
PMAX generic framebuffer pseudo-device
. It Ar fd
File descriptors
+. It Ar gpiopps#
+1PPS signals on GPIO pins, see
+.Xr \&gpiopps 4
. It Ar grf#
Graphics frame buffer device, see
.Xr \&amiga/grf 4
diff -r 291c446f4cfe -r 8531da5a9749 sys/conf/majors
--- a/sys/conf/majors Sun May 20 12:08:46 2018 +0000
+++ b/sys/conf/majors Sun May 20 14:08:32 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: majors,v 1.78 2018/01/09 03:31:12 christos Exp $
+# $NetBSD: majors,v 1.79 2018/05/20 14:08:33 thorpej Exp $
#
# Device majors for Machine-Independent drivers.
#
@@ -77,3 +77,4 @@
device-major nvme char 341 nvme
device-major qemufwcfg char 342 qemufwcfg
device-major autofs char 343 autofs
+device-major gpiopps char 344 gpiopps
diff -r 291c446f4cfe -r 8531da5a9749 sys/dev/gpio/files.gpio
--- a/sys/dev/gpio/files.gpio Sun May 20 12:08:46 2018 +0000
+++ b/sys/dev/gpio/files.gpio Sun May 20 14:08:32 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.gpio,v 1.15 2018/05/19 14:15:39 thorpej Exp $
+# $NetBSD: files.gpio,v 1.16 2018/05/20 14:08:33 thorpej Exp $
define gpio {[offset = -1], [mask = 0], [flag = 0]}
@@ -44,3 +44,8 @@
device gpioirq: gpiobus
attach gpioirq at gpio
file dev/gpio/gpioirq.c gpioirq
+
+# GPIO PPS
+device gpiopps: gpiobus
+attach gpiopps at gpio
+file dev/gpio/gpiopps.c gpiopps
diff -r 291c446f4cfe -r 8531da5a9749 sys/dev/gpio/gpiopps.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/gpio/gpiopps.c Sun May 20 14:08:32 2018 +0000
@@ -0,0 +1,540 @@
+/* $NetBSD: gpiopps.c,v 1.1 2018/05/20 14:08:33 thorpej Exp $ */
+
+/*
+ * Copyright (c) 2016 Brad Spencer <brad%anduin.eldar.org@localhost>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: gpiopps.c,v 1.1 2018/05/20 14:08:33 thorpej Exp $");
+
+/*
+ * GPIO interface to the pps subsystem for ntp support.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bitops.h>
+#include <sys/device.h>
+#include <sys/module.h>
+#include <sys/conf.h>
+#include <sys/proc.h>
+#include <sys/ioctl.h>
+#include <sys/timepps.h>
+
+#include <sys/gpio.h>
+#include <dev/gpio/gpiovar.h>
+
+#define GPIOPPS_NPINS 2
+
+struct gpiopps_softc {
+ device_t sc_dev;
+ void * sc_gpio;
+ struct gpio_pinmap sc_map;
+ int _map[GPIOPPS_NPINS];
+ struct {
+ char sc_intrstr[128];
+ void * sc_ih;
+ int sc_irqmode;
+ } sc_intrs[GPIOPPS_NPINS];
+ int sc_assert_val;
+ int sc_npins;
+ struct pps_state sc_pps_state;
+ bool sc_functional;
+ bool sc_busy;
+};
+
+#define GPIOPPS_FLAGS_ASSERT_NEG_EDGE 0x01
+#define GPIOPPS_FLAGS_NO_DOUBLE_EDGE 0x02
+
+static int gpiopps_match(device_t, cfdata_t, void *);
+static void gpiopps_attach(device_t, device_t, void *);
+static int gpiopps_detach(device_t, int);
+
+CFATTACH_DECL_NEW(gpiopps, sizeof(struct gpiopps_softc),
+ gpiopps_match, gpiopps_attach,
+ gpiopps_detach, NULL /*activate*/);
+
+extern struct cfdriver gpiopps_cd;
+
+static dev_type_open(gpioppsopen);
+static dev_type_close(gpioppsclose);
+static dev_type_ioctl(gpioppsioctl);
+const struct cdevsw gpiopps_cdevsw = {
+ .d_open = gpioppsopen,
+ .d_close = gpioppsclose,
+ .d_read = noread,
+ .d_write = nowrite,
+ .d_ioctl = gpioppsioctl,
+ .d_stop = nostop,
+ .d_tty = notty,
+ .d_poll = nopoll,
+ .d_mmap = nommap,
+ .d_kqfilter = nokqfilter,
+ .d_discard = nodiscard,
+ .d_flag = D_OTHER
+};
+
+static int
+gpiopps_match(device_t parent, cfdata_t cf, void *aux)
+{
+ struct gpio_attach_args *ga = aux;
+ int bits;
+
+ if (strcmp(ga->ga_dvname, cf->cf_name))
+ return (0);
+
+ if (ga->ga_offset == -1)
+ return (0);
+
+ /* One or 2 pins (unspecified, assume 1) */
+ bits = gpio_npins(ga->ga_mask);
+ if (bits > 2)
+ return (0);
+
Home |
Main Index |
Thread Index |
Old Index