From: Rodolfo Giometti <giometti@enneenne.com>
To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Greg KH <greg@kroah.com>,
corbet@lwn.net, Hall Christopher S <christopher.s.hall@intel.com>,
Mohan Subramanian <subramanian.mohan@intel.com>,
tglx@linutronix.de,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Dong Eddie <eddie.dong@intel.com>,
N Pandith <pandith.n@intel.com>,
T R Thejesh Reddy <thejesh.reddy.t.r@intel.com>,
Zage David <david.zage@intel.com>,
Chinnadurai Srinivasan <srinivasan.chinnadurai@intel.com>,
Randy Dunlap <rdunlap@infradead.org>,
Rodolfo Giometti <giometti@enneenne.com>
Subject: [V2 2/4] drivers pps/generators: add dummy PPS generator
Date: Thu, 31 Oct 2024 17:35:06 +0100 [thread overview]
Message-ID: <20241031163508.259522-3-giometti@enneenne.com> (raw)
In-Reply-To: <20241031163508.259522-1-giometti@enneenne.com>
This dummy PPS generator can be used for debugging and documentation
purposes.
Signed-off-by: Rodolfo Giometti <giometti@enneenne.com>
---
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
diff --git a/drivers/pps/generators/Kconfig b/drivers/pps/generators/Kconfig
index 5edbfdb8bd92..51c05b090d94 100644
--- a/drivers/pps/generators/Kconfig
+++ b/drivers/pps/generators/Kconfig
@@ -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
diff --git a/drivers/pps/generators/Makefile b/drivers/pps/generators/Makefile
index 034a78edfa26..dc1aa5a4688b 100644
--- a/drivers/pps/generators/Makefile
+++ b/drivers/pps/generators/Makefile
@@ -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
diff --git a/drivers/pps/generators/pps_gen-dummy.c b/drivers/pps/generators/pps_gen-dummy.c
new file mode 100644
index 000000000000..b284c200cbe5
--- /dev/null
+++ b/drivers/pps/generators/pps_gen-dummy.c
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * PPS dummy generator
+ *
+ * Copyright (C) 2024 Rodolfo Giometti <giometti@enneenne.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/time.h>
+#include <linux/timer.h>
+#include <linux/random.h>
+#include <linux/pps_gen_kernel.h>
+
+static struct pps_gen_device *pps_gen;
+static struct timer_list ktimer;
+
+static unsigned int get_random_delay(void)
+{
+ unsigned int delay = get_random_u8() & 0x0f;
+
+ return (delay + 1) * HZ;
+}
+
+/*
+ * The kernel timer
+ */
+
+static void pps_gen_ktimer_event(struct timer_list *unused)
+{
+ pps_gen_event(pps_gen, PPS_GEN_EVENT_MISSEDPULSE, NULL);
+}
+
+/*
+ * PPS Generator methods
+ */
+
+static int pps_gen_dummy_get_time(struct pps_gen_device *pps_gen,
+ struct timespec64 *time)
+{
+ struct system_time_snapshot snap;
+
+ ktime_get_snapshot(&snap);
+ *time = ktime_to_timespec64(snap.real);
+
+ return 0;
+}
+
+static int pps_gen_dummy_enable(struct pps_gen_device *pps_gen, bool enable)
+{
+ if (enable)
+ mod_timer(&ktimer, jiffies + get_random_delay());
+ else
+ del_timer_sync(&ktimer);
+
+ return 0;
+}
+
+/*
+ * The PPS info struct
+ */
+
+static struct pps_gen_source_info pps_gen_dummy_info = {
+ .use_system_clock = true,
+ .get_time = pps_gen_dummy_get_time,
+ .enable = pps_gen_dummy_enable,
+};
+
+/*
+ * Module staff
+ */
+
+static void __exit pps_gen_dummy_exit(void)
+{
+ del_timer_sync(&ktimer);
+ pps_gen_unregister_source(pps_gen);
+}
+
+static int __init pps_gen_dummy_init(void)
+{
+ pps_gen = pps_gen_register_source(&pps_gen_dummy_info);
+ if (IS_ERR(pps_gen))
+ return PTR_ERR(pps_gen);
+
+ timer_setup(&ktimer, pps_gen_ktimer_event, 0);
+
+ return 0;
+}
+
+module_init(pps_gen_dummy_init);
+module_exit(pps_gen_dummy_exit);
+
+MODULE_AUTHOR("Rodolfo Giometti <giometti@enneenne.com>");
+MODULE_DESCRIPTION("LinuxPPS dummy generator");
+MODULE_LICENSE("GPL");
--
2.34.1
next prev parent reply other threads:[~2024-10-31 16:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-31 16:35 [V2 0/4] Add PPS generators Rodolfo Giometti
2024-10-31 16:35 ` [V2 1/4] drivers pps: add PPS generators support Rodolfo Giometti
2024-10-31 17:08 ` Randy Dunlap
2024-10-31 16:35 ` Rodolfo Giometti [this message]
2024-10-31 16:35 ` [V2 3/4] Documentation pps.rst: add PPS generators documentation Rodolfo Giometti
2024-10-31 17:14 ` Randy Dunlap
2024-11-01 3:45 ` Bagas Sanjaya
2024-10-31 16:35 ` [V2 4/4] Documentation ABI: " Rodolfo Giometti
2024-11-01 8:17 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241031163508.259522-3-giometti@enneenne.com \
--to=giometti@enneenne.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=christopher.s.hall@intel.com \
--cc=corbet@lwn.net \
--cc=david.zage@intel.com \
--cc=eddie.dong@intel.com \
--cc=greg@kroah.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pandith.n@intel.com \
--cc=rdunlap@infradead.org \
--cc=srinivasan.chinnadurai@intel.com \
--cc=subramanian.mohan@intel.com \
--cc=tglx@linutronix.de \
--cc=thejesh.reddy.t.r@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®