Skip to contentSkip to conversation

Add PPS generators

PATCH Superseded Rodolfo Giometti 4 participants 9 messages Oct 31, 2024 – Nov 1, 2024

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Rodolfo Giometti

author maintainer
#0 lore raw

v2 cover Add PPS generators

PPS generators are special hardware which are able to produce PPS (Pulse Per Second) signals.

This patchset adds PPS generators class in order to have a well-defined interface for these devices.

Changelog:

V1 -> V2:
* new file Documentation/ABI/testing/sysfs-pps-gen added in MAINTAINERS
* date for the documentation ABI set to v6.13 which will be released on 2025-02
* removed documentation for non-existent sysfs "name" entry
* spelling and/or syntax errors fixed

RFC -> V1:
* char device reworked (get_device/set_device)
* dummy driver has been moved in a separate patch
* idr_ replaced with ida_* functions
* fixes in include/uapi/linux/pps_gen.h
* MAINTAINERS updated
* new ioctl PPS_GEN_USESYSTEMCLOCK added
* new ioctl PPS_GEN_FETCHEVENT added
* .compat_ioctl dropped
* WARN_ON() removed from pps_gen_cdev_release()
* not needed pr_*() calls removed or replaced with dev_*()
* more quite driver
* name attribute dropped
* white spaces removed

Rodolfo Giometti (4):
drivers pps: add PPS generators support drivers pps/generators: add dummy PPS generator Documentation pps.rst: add PPS generators documentation Documentation ABI: add PPS generators documentation

 Documentation/ABI/testing/sysfs-pps-gen       |  38 ++
 Documentation/driver-api/pps.rst              |  40 ++
 .../userspace-api/ioctl/ioctl-number.rst      |   1 +
 MAINTAINERS                                   |   2 +
 drivers/pps/Makefile                          |   3 +-
 drivers/pps/generators/Kconfig                |  22 +-
 drivers/pps/generators/Makefile               |   4 +
 drivers/pps/generators/pps_gen-dummy.c        |  96 +++++
 drivers/pps/generators/pps_gen.c              | 344 ++++++++++++++++++
 drivers/pps/generators/sysfs.c                |  75 ++++
 include/linux/pps_gen_kernel.h                |  78 ++++
 include/uapi/linux/pps_gen.h                  |  37 ++
 12 files changed, 738 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-pps-gen
 create mode 100644 drivers/pps/generators/pps_gen-dummy.c
 create mode 100644 drivers/pps/generators/pps_gen.c
 create mode 100644 drivers/pps/generators/sysfs.c
 create mode 100644 include/linux/pps_gen_kernel.h
 create mode 100644 include/uapi/linux/pps_gen.h
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v2 1/4 drivers pps: add PPS generators support

Sometimes one needs to be able not only to catch PPS signals but to produce them also. For example, running a distributed simulation, which requires computers' clock to be synchronized very tightly.

This patch adds PPS generators class in order to have a well-defined interface for these devices.

---
 .../userspace-api/ioctl/ioctl-number.rst      |   1 +
 MAINTAINERS                                   |   1 +
 drivers/pps/Makefile                          |   3 +-
 drivers/pps/generators/Kconfig                |  13 +-
 drivers/pps/generators/Makefile               |   3 +
 drivers/pps/generators/pps_gen.c              | 344 ++++++++++++++++++
 drivers/pps/generators/sysfs.c                |  75 ++++
 include/linux/pps_gen_kernel.h                |  78 ++++
 include/uapi/linux/pps_gen.h                  |  37 ++
 9 files changed, 553 insertions(+), 2 deletions(-)
 create mode 100644 drivers/pps/generators/pps_gen.c
 create mode 100644 drivers/pps/generators/sysfs.c
 create mode 100644 include/linux/pps_gen_kernel.h
 create mode 100644 include/uapi/linux/pps_gen.h
Documentation/userspace-api/ioctl/ioctl-number.rst +1 -0
index e4be1378ba26..e4f7f798f091 100644
@@ -283,6 +283,7 @@ Code  Seq#    Include File                                           Comments
 'p'   80-9F  linux/ppdev.h                                           user-space parport
                                                                      <mailto:[email protected]>
 'p'   A1-A5  linux/pps.h                                             LinuxPPS
+'p'   B1-B3  linux/pps-gen.h                                         LinuxPPS
                                                                      <mailto:[email protected]>
 'q'   00-1F  linux/serio.h
 'q'   80-FF  linux/telephony.h                                       Internet PhoneJACK, Internet LineJACK
MAINTAINERS +1 -0
index a097afd76ded..63871eb816eb 100644
@@ -18536,6 +18536,7 @@ F:	Documentation/devicetree/bindings/pps/pps-gpio.yaml
 F:	Documentation/driver-api/pps.rst
 F:	drivers/pps/
 F:	include/linux/pps*.h
+F:	include/uapi/linux/pps-gen.h
 F:	include/uapi/linux/pps.h
 
 PPTP DRIVER
drivers/pps/Makefile +2 -1
index ceaf65cc1f1d..0aea394d4e4d 100644
@@ -6,6 +6,7 @@
 pps_core-y			:= pps.o kapi.o sysfs.o
 pps_core-$(CONFIG_NTP_PPS)	+= kc.o
 obj-$(CONFIG_PPS)		:= pps_core.o
-obj-y				+= clients/ generators/
+obj-y				+= clients/
+obj-$(CONFIG_PPS_GENERATOR)	+= generators/
 
 ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG
drivers/pps/generators/Kconfig +12 -1
index d615e640fcad..5edbfdb8bd92 100644
@@ -3,7 +3,16 @@
 # PPS generators configuration
 #
 
-comment "PPS generators support"
+menuconfig PPS_GENERATOR
+	tristate "PPS generators support"
+	help
+	  PPS generators are special hardware which are able to produce PPS
+	  (Pulse Per Second) signals.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pps_gen_core.ko.
+
+if PPS_GENERATOR
 
 config PPS_GENERATOR_PARPORT
 	tristate "Parallel port PPS signal generator"
@@ -12,3 +21,5 @@ config PPS_GENERATOR_PARPORT
 	  If you say yes here you get support for a PPS signal generator which
 	  utilizes STROBE pin of a parallel port to send PPS signals. It uses
 	  parport abstraction layer and hrtimers to precisely control the signal.
+
+endif # PPS_GENERATOR
drivers/pps/generators/Makefile +3 -0
index 2589fd0f2481..034a78edfa26 100644
@@ -3,6 +3,9 @@
 # Makefile for PPS generators.
 #
 
+pps_gen_core-y			:= pps_gen.o sysfs.o
+obj-$(CONFIG_PPS_GENERATOR)	:= pps_gen_core.o
+
 obj-$(CONFIG_PPS_GENERATOR_PARPORT) += pps_gen_parport.o
 
 ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG
drivers/pps/generators/pps_gen.c new file +344 -0

344 lines not on this page · raw message

drivers/pps/generators/sysfs.c new file +75 -0

75 lines not on this page · raw message

include/linux/pps_gen_kernel.h new file +78 -0

78 lines not on this page · raw message

include/uapi/linux/pps_gen.h new file +37 -0
new file mode 100644
index 000000000000..60a5d0fcfa68
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * PPS generator API header
+ *
+ * Copyright (C) 2024 Rodolfo Giometti <[email protected]>
+ */
+
+#ifndef _PPS_GEN_H_
+#define _PPS_GEN_H_
+
+#include <linux/types.h>
+#include <linux/ioctl.h>
+
+/**
+ * struct pps_gen_event - the PPS generator events
+ * @event: the event type
+ * @sequence: the event sequence number
+ *
+ * Userspace can get the last PPS generator event by using the
+ * ioctl(pps_gen, PPS_GEN_FETCHEVENT, ...) syscall.
+ * The sequence field can be used to save the last event ID, while in the
+ * event field is stored the last event type. Currently known event is:
+ *
+ *     PPS_GEN_EVENT_MISSEDPULSE	: last pulse was not generated
+ */
+struct pps_gen_event {
+	unsigned int event;
+	unsigned int sequence;
+};
+
+#define PPS_GEN_EVENT_MISSEDPULSE	1
+
+#define PPS_GEN_SETENABLE		_IOW('p', 0xb1, unsigned int *)
+#define PPS_GEN_USESYSTEMCLOCK		_IOR('p', 0xb2, unsigned int *)
+#define PPS_GEN_FETCHEVENT		_IOR('p', 0xb3, struct pps_gen_event *)
+
+#endif /* _PPS_GEN_H_ */
Signature · 1 line
2.34.1
reviewer
#2 lore raw

Re: [V2 1/4] drivers pps: add PPS generators support

Quoted 32 lines · Rodolfo Giometti

Sometimes one needs to be able not only to catch PPS signals but to produce them also. For example, running a distributed simulation, which requires computers' clock to be synchronized very tightly.

This patch adds PPS generators class in order to have a well-defined interface for these devices.

---
 .../userspace-api/ioctl/ioctl-number.rst      |   1 +
 MAINTAINERS                                   |   1 +
 drivers/pps/Makefile                          |   3 +-
 drivers/pps/generators/Kconfig                |  13 +-
 drivers/pps/generators/Makefile               |   3 +
 drivers/pps/generators/pps_gen.c              | 344 ++++++++++++++++++
 drivers/pps/generators/sysfs.c                |  75 ++++
 include/linux/pps_gen_kernel.h                |  78 ++++
 include/uapi/linux/pps_gen.h                  |  37 ++
 9 files changed, 553 insertions(+), 2 deletions(-)
 create mode 100644 drivers/pps/generators/pps_gen.c
 create mode 100644 drivers/pps/generators/sysfs.c
 create mode 100644 include/linux/pps_gen_kernel.h
 create mode 100644 include/uapi/linux/pps_gen.h
drivers/pps/generators/Kconfig +0 -0
index d615e640fcad..5edbfdb8bd92 100644
@@ -3,7 +3,16 @@
 # PPS generators configuration
 #

drivers/pps/generators/Kconfig line 13

Quoted 10 lines
drivers/pps/generators/Kconfig +8 -1
 
-comment "PPS generators support"
+menuconfig PPS_GENERATOR
+	tristate "PPS generators support"
+	help
+	  PPS generators are special hardware which are able to produce PPS
+	  (Pulse Per Second) signals.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pps_gen_core.ko.

Drop the ".ko" suffix as you did for the dummy module and most of the kernel does.

Quoted 11 lines
drivers/pps/generators/Kconfig +4 -0
+
+if PPS_GENERATOR
 
 config PPS_GENERATOR_PARPORT
 	tristate "Parallel port PPS signal generator"
@@ -12,3 +21,5 @@ config PPS_GENERATOR_PARPORT
 	  If you say yes here you get support for a PPS signal generator which
 	  utilizes STROBE pin of a parallel port to send PPS signals. It uses
 	  parport abstraction layer and hrtimers to precisely control the signal.
+
+endif # PPS_GENERATOR
Signature · 1 line
~Randy
author maintainer
#3 lore raw

PATCH v2 2/4 drivers pps/generators: add dummy PPS generator

In reply to Rodolfo Giometti

This dummy PPS generator can be used for debugging and documentation purposes.

---
 drivers/pps/generators/Kconfig         |  9 +++
 drivers/pps/generators/Makefile        |  1 +
 drivers/pps/generators/pps_gen-dummy.c | 96 ++++++++++++++++++++++++++
 3 files changed, 106 insertions(+)
 create mode 100644 drivers/pps/generators/pps_gen-dummy.c
drivers/pps/generators/Kconfig +9 -0
index 5edbfdb8bd92..51c05b090d94 100644
@@ -14,6 +14,15 @@ menuconfig PPS_GENERATOR
 
 if PPS_GENERATOR
 
+config PPS_GENERATOR_DUMMY
+        tristate "Dummy PPS generator (Testing generator, use for debug)"
+        help
+          If you say yes here you get support for a PPS debugging generator
+          (which generates no PPS signal at all).
+
+          This driver can also be built as a module.  If so, the module
+          will be called pps_gen-dummy.
+
 config PPS_GENERATOR_PARPORT
 	tristate "Parallel port PPS signal generator"
 	depends on PARPORT && BROKEN
drivers/pps/generators/Makefile +1 -0
index 034a78edfa26..dc1aa5a4688b 100644
@@ -6,6 +6,7 @@
 pps_gen_core-y			:= pps_gen.o sysfs.o
 obj-$(CONFIG_PPS_GENERATOR)	:= pps_gen_core.o
 
+obj-$(CONFIG_PPS_GENERATOR_DUMMY)   += pps_gen-dummy.o
 obj-$(CONFIG_PPS_GENERATOR_PARPORT) += pps_gen_parport.o
 
 ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG
drivers/pps/generators/pps_gen-dummy.c new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#4 lore raw

PATCH v2 3/4 Documentation pps.rst: add PPS generators documentation

In reply to Rodolfo Giometti

This patch adds some examples about how to register a new PPS generator in the system, and how to manage it.

---
 Documentation/driver-api/pps.rst | 40 ++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
Documentation/driver-api/pps.rst +40 -0
index 78dded03e5d8..dffa06ed919f 100644
@@ -202,6 +202,46 @@ Sometimes one needs to be able not only to catch PPS signals but to produce
 them also. For example, running a distributed simulation, which requires
 computers' clock to be synchronized very tightly.
 
+To do so the class pps-gen has been added. PPS generators can be
+registered in the kernel by defining a struct pps_gen_source_info as
+follows::
+
+    static struct pps_gen_source_info pps_gen_dummy_info = {
+            .name                   = "dummy",
+            .use_system_clock       = true,
+            .get_time               = pps_gen_dummy_get_time,
+            .enable                 = pps_gen_dummy_enable,
+    };
+
+Where the use_system_clock states if the generator uses the system
+clock to generate its pulses, or from a peripheral device
+clock. Method get_time() is used to query the time stored into the
+generator clock, while the method enable() is used to enable or
+disable the PPS pulse generation.
+
+Then calling the function pps_gen_register_source() in your
+initialization routine as follows creates a new generator in the
+system::
+
+    pps_gen = pps_gen_register_source(&pps_gen_dummy_info);
+
+Generators SYSFS support
+------------------------
+
+If the SYSFS filesystem is enabled in the kernel it provides a new class::
+
+    $ ls /sys/class/pps-gen/
+    pps-gen0/  pps-gen1/  pps-gen2/
+
+Every directory is the ID of a PPS generator defined in the system and
+inside you find several files::
+
+    $ ls -F /sys/class/pps-gen/pps-gen0/
+    dev  enable  name  power/  subsystem@  system  time  uevent
+
+To enable the PPS signal generation you can use the command below::
+
+    $ echo 1 > /sys/class/pps-gen/pps-gen0/enable
 
 Parallel port generator
 ------------------------
Signature · 1 line
2.34.1
reviewer
#5 lore raw

Re: [V2 3/4] Documentation pps.rst: add PPS generators documentation

Quoted 19 lines · Rodolfo Giometti

This patch adds some examples about how to register a new PPS generator in the system, and how to manage it.

---
 Documentation/driver-api/pps.rst | 40 ++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
Documentation/driver-api/pps.rst +3 -0
index 78dded03e5d8..dffa06ed919f 100644
@@ -202,6 +202,46 @@ Sometimes one needs to be able not only to catch PPS signals but to produce
 them also. For example, running a distributed simulation, which requires
 computers' clock to be synchronized very tightly.
 
+To do so the class pps-gen has been added. PPS generators can be
+registered in the kernel by defining a struct pps_gen_source_info as
+follows::

Documentation/driver-api/pps.rst Sometimes one needs to be able not only to catch PPS signals but to produce · line 217

Quoted 10 lines
Documentation/driver-api/pps.rst +10 -0
+
+    static struct pps_gen_source_info pps_gen_dummy_info = {
+            .name                   = "dummy",
+            .use_system_clock       = true,
+            .get_time               = pps_gen_dummy_get_time,
+            .enable                 = pps_gen_dummy_enable,
+    };
+
+Where the use_system_clock states if the generator uses the system
+clock to generate its pulses, or from a peripheral device

or they are from a peripheral device

Quoted 30 lines
Documentation/driver-api/pps.rst +27 -0
+clock. Method get_time() is used to query the time stored into the
+generator clock, while the method enable() is used to enable or
+disable the PPS pulse generation.
+
+Then calling the function pps_gen_register_source() in your
+initialization routine as follows creates a new generator in the
+system::
+
+    pps_gen = pps_gen_register_source(&pps_gen_dummy_info);
+
+Generators SYSFS support
+------------------------
+
+If the SYSFS filesystem is enabled in the kernel it provides a new class::
+
+    $ ls /sys/class/pps-gen/
+    pps-gen0/  pps-gen1/  pps-gen2/
+
+Every directory is the ID of a PPS generator defined in the system and
+inside you find several files::
+
+    $ ls -F /sys/class/pps-gen/pps-gen0/
+    dev  enable  name  power/  subsystem@  system  time  uevent
+
+To enable the PPS signal generation you can use the command below::
+
+    $ echo 1 > /sys/class/pps-gen/pps-gen0/enable
 
 Parallel port generator
 ------------------------
Signature · 1 line
~Randy
#6 lore raw

Re: [V2 3/4] Documentation pps.rst: add PPS generators documentation

In reply to Rodolfo Giometti

Documentation/driver-api/pps.rst Sometimes one needs to be able not only to catch PPS signals but to produce · line 237

Quoted 2 lines · Rodolfo Giometti
Documentation/driver-api/pps.rst +2 -0
+Every directory is the ID of a PPS generator defined in the system and
+inside you find several files::

"inside of it ..."

Documentation/driver-api/pps.rst Sometimes one needs to be able not only to catch PPS signals but to produce · line 241

Quoted 4 lines
Documentation/driver-api/pps.rst +4 -0
+
+    $ ls -F /sys/class/pps-gen/pps-gen0/
+    dev  enable  name  power/  subsystem@  system  time  uevent
+

Thanks.

Signature · 1 line
An old man doll... just what I always wanted! - Clara
author maintainer
#7 lore raw

PATCH v2 4/4 Documentation ABI: add PPS generators documentation

In reply to Rodolfo Giometti

This patch adds the documentation for the ABI between the Linux kernel and userspace regarding the PPS generators.

---
 Documentation/ABI/testing/sysfs-pps-gen | 38 +++++++++++++++++++++++++
 MAINTAINERS                             |  1 +
 2 files changed, 39 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-pps-gen
Documentation/ABI/testing/sysfs-pps-gen new file +38 -0
new file mode 100644
index 000000000000..7effe495d062
@@ -0,0 +1,38 @@
+What:		/sys/class/pps-gen/
+Date:		February 2025
+Contact:	Rodolfo Giometti <[email protected]>
+Description:
+		The /sys/class/pps-gen/ directory contains files and
+		directories that provide a unified interface to the PPS
+		generators.
+
+What:		/sys/class/pps-gen/pps-genX/
+Date:		February 2025
+Contact:	Rodolfo Giometti <[email protected]>
+Description:
+		The /sys/class/pps-gen/pps-genX/ directory is related to X-th
+		PPS generator in the system. Each directory contain files to
+		manage and control its PPS generator.
+
+What:		/sys/class/pps-gen/pps-genX/enable
+Date:		February 2025
+Contact:	Rodolfo Giometti <[email protected]>
+Description:
+		This write-only file enables or disables generation of the
+		PPS signal.
+
+What:		/sys/class/pps-gen/pps-genX/system
+Date:		February 2025
+Contact:	Rodolfo Giometti <[email protected]>
+Description:
+		This read-only file returns "1" if the generator takes the
+		timing from the system clock, while it returns "0" if not
+		(i.e. from a peripheral device clock).
+
+What:		/sys/class/pps-gen/pps-genX/time
+Date:		February 2025
+Contact:	Rodolfo Giometti <[email protected]>
+Description:
+		This read-only file contains the current time stored into the
+		generator clock as two integers representing the current time
+		seconds and nanoseconds.
MAINTAINERS +1 -0
index 63871eb816eb..d0b628c973f7 100644
@@ -18532,6 +18532,7 @@ L:	[email protected] (subscribers-only)
 S:	Maintained
 W:	http://wiki.enneenne.com/index.php/LinuxPPS_support
 F:	Documentation/ABI/testing/sysfs-pps
+F:	Documentation/ABI/testing/sysfs-pps-gen
 F:	Documentation/devicetree/bindings/pps/pps-gpio.yaml
 F:	Documentation/driver-api/pps.rst
 F:	drivers/pps/
Signature · 1 line
2.34.1
#8 lore raw

Re: [V2 4/4] Documentation ABI: add PPS generators documentation

Quoted 2 lines · Rodolfo Giometti

This patch adds the documentation for the ABI between the Linux kernel and userspace regarding the PPS generators.

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+What:		/sys/class/pps-gen/
+Date:		February 2025

Don't you want to add KernelVersion? The date is hard to map to the actual version where it may appear first.

Quoted 1 line

+Contact: Rodolfo Giometti <[email protected]>

Ditto for all of them.

Signature · 2 lines
With Best Regards,
Andy Shevchenko