mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: KhaiWenTan <khai.wen.tan@linux.intel.com>
To: Rodolfo Giometti <giometti@enneenne.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jonathan Corbet <corbet@lwn.net>
Cc: Thomas Gleixner <tglx@kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	david.zage@intel.com, weifeng.voon@intel.com,
	hong.aun.looi@intel.com, christopher.s.hall@intel.com,
	khai.wen.tan@intel.com, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org
Subject: [PATCH 3/4] pps: generators: move TIO ownership to auxiliary parent
Date: Thu,  3 Dec 2026 01:21:57 +0800	[thread overview]
Message-ID: <20261202172254.1188109-4-khai.wen.tan@linux.intel.com> (raw)
In-Reply-To: <20261202172254.1188109-1-khai.wen.tan@linux.intel.com>

From: Voon Weifeng <weifeng.voon@intel.com>

Move ACPI enumeration and register ownership to a shared TIO
platform driver, then convert the existing generator to an auxiliary
driver. Preserve the existing generator-facing names and behavior.

Let TIO manage its enabled state so the generator core cannot overwrite
an asynchronous missed-pulse failure.

Keep the migration generator-only; the PPS client and capture-specific
register configuration are added in a later patch.

Signed-off-by: Voon Weifeng <weifeng.voon@intel.com>
Signed-off-by: KhaiWenTan <khai.wen.tan@linux.intel.com>
---
 drivers/pps/Kconfig                  |   5 +
 drivers/pps/Makefile                 |   1 +
 drivers/pps/generators/Kconfig       |   1 +
 drivers/pps/generators/pps_gen.c     |   9 +-
 drivers/pps/generators/pps_gen_tio.c | 264 ++++++++++-----------------
 drivers/pps/generators/sysfs.c       |   4 +-
 drivers/pps/pps_tio.c                | 155 ++++++++++++++++
 drivers/pps/pps_tio.h                |  47 +++++
 include/linux/pps_gen_kernel.h       |   2 +
 9 files changed, 314 insertions(+), 174 deletions(-)
 create mode 100644 drivers/pps/pps_tio.c
 create mode 100644 drivers/pps/pps_tio.h

diff --git a/drivers/pps/Kconfig b/drivers/pps/Kconfig
index e1651d51cfc9..86b54239351f 100644
--- a/drivers/pps/Kconfig
+++ b/drivers/pps/Kconfig
@@ -38,6 +38,11 @@ config NTP_PPS
 
 	  It doesn't work on tickless systems at the moment.
 
+config PPS_TIO
+	tristate
+	depends on X86 && CPU_SUP_INTEL
+	select AUXILIARY_BUS
+
 source "drivers/pps/clients/Kconfig"
 
 source "drivers/pps/generators/Kconfig"
diff --git a/drivers/pps/Makefile b/drivers/pps/Makefile
index 0aea394d4e4d..d0b9d9385f00 100644
--- a/drivers/pps/Makefile
+++ b/drivers/pps/Makefile
@@ -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-$(CONFIG_PPS_TIO)		+= pps_tio.o
 obj-y				+= clients/
 obj-$(CONFIG_PPS_GENERATOR)	+= generators/
 
diff --git a/drivers/pps/generators/Kconfig b/drivers/pps/generators/Kconfig
index 4ef02b3f2576..328260bacd8b 100644
--- a/drivers/pps/generators/Kconfig
+++ b/drivers/pps/generators/Kconfig
@@ -26,6 +26,7 @@ config PPS_GENERATOR_DUMMY
 config PPS_GENERATOR_TIO
 	tristate "TIO PPS signal generator"
 	depends on X86 && CPU_SUP_INTEL
+	select PPS_TIO
 	help
 	  If you say yes here you get support for a PPS TIO signal generator
 	  which generates a pulse at a prescribed time based on the system clock.
diff --git a/drivers/pps/generators/pps_gen.c b/drivers/pps/generators/pps_gen.c
index 8f68061b8698..be4f699cb4ca 100644
--- a/drivers/pps/generators/pps_gen.c
+++ b/drivers/pps/generators/pps_gen.c
@@ -78,7 +78,8 @@ static long pps_gen_cdev_ioctl(struct file *file,
 			ret = pps_gen->info->enable(pps_gen, status);
 			if (ret)
 				return ret;
-			pps_gen->enabled = status;
+			if (!pps_gen->info->driver_manages_enabled)
+				WRITE_ONCE(pps_gen->enabled, !!status);
 		}
 
 		break;
@@ -220,7 +221,7 @@ static int pps_gen_register_cdev(struct pps_gen_device *pps_gen)
 		pr_err("failed to add char device %d:%d\n",
 				MAJOR(pps_gen_devt), pps_gen->id);
 		mutex_lock(&pps_gen->info_lock);
-		if (pps_gen->enabled)
+		if (READ_ONCE(pps_gen->enabled))
 			pps_gen->info->enable(pps_gen, false);
 		WRITE_ONCE(pps_gen->info, NULL);
 		mutex_unlock(&pps_gen->info_lock);
@@ -253,9 +254,9 @@ static void pps_gen_unregister_cdev(struct pps_gen_device *pps_gen)
 	 * after this point, so stop it here for good.
 	 */
 	scoped_guard(mutex, &pps_gen->info_lock) {
-		if (pps_gen->enabled) {
+		if (READ_ONCE(pps_gen->enabled)) {
 			pps_gen->info->enable(pps_gen, false);
-			pps_gen->enabled = false;
+			WRITE_ONCE(pps_gen->enabled, false);
 		}
 		WRITE_ONCE(pps_gen->info, NULL);
 	}
diff --git a/drivers/pps/generators/pps_gen_tio.c b/drivers/pps/generators/pps_gen_tio.c
index 9e3142041269..00361a23ddda 100644
--- a/drivers/pps/generators/pps_gen_tio.c
+++ b/drivers/pps/generators/pps_gen_tio.c
@@ -5,193 +5,134 @@
  * Copyright (C) 2024 Intel Corporation
  */
 
-#include <linux/bitfield.h>
-#include <linux/bits.h>
-#include <linux/cleanup.h>
+#include <linux/auxiliary_bus.h>
 #include <linux/container_of.h>
 #include <linux/device.h>
 #include <linux/hrtimer.h>
-#include <linux/io-64-nonatomic-hi-lo.h>
 #include <linux/module.h>
-#include <linux/mutex.h>
-#include <linux/platform_device.h>
 #include <linux/pps_gen_kernel.h>
 #include <linux/timekeeping.h>
 #include <linux/types.h>
 
-#include <asm/cpu_device_id.h>
-
-#define TIOCTL			0x00
-#define TIOCOMPV		0x10
-#define TIOEC			0x30
-
-/* Control Register */
-#define TIOCTL_EN			BIT(0)
-#define TIOCTL_DIR			BIT(1)
-#define TIOCTL_EP			GENMASK(3, 2)
-#define TIOCTL_EP_RISING_EDGE		FIELD_PREP(TIOCTL_EP, 0)
-#define TIOCTL_EP_FALLING_EDGE		FIELD_PREP(TIOCTL_EP, 1)
-#define TIOCTL_EP_TOGGLE_EDGE		FIELD_PREP(TIOCTL_EP, 2)
+#include "../pps_tio.h"
 
 /* Safety time to set hrtimer early */
-#define SAFE_TIME_NS			(10 * NSEC_PER_MSEC)
+#define SAFE_TIME_NS		(10 * NSEC_PER_MSEC)
 
-#define MAGIC_CONST			(NSEC_PER_SEC - SAFE_TIME_NS)
-#define ART_HW_DELAY_CYCLES		2
+#define MAGIC_CONST		(NSEC_PER_SEC - SAFE_TIME_NS)
+#define ART_HW_DELAY_CYCLES	2
 
-struct pps_tio {
+struct pps_tio_generator {
+	struct pps_tio *tio;
 	struct pps_gen_source_info gen_info;
 	struct pps_gen_device *pps_gen;
 	struct hrtimer timer;
-	void __iomem *base;
 	u32 prev_count;
-	struct mutex mutex;
-	spinlock_t lock;
-	struct device *dev;
+	bool removing;
 };
 
-static inline u32 pps_tio_read(u32 offset, struct pps_tio *tio)
-{
-	return readl(tio->base + offset);
-}
-
-static inline void pps_ctl_write(u32 value, struct pps_tio *tio)
-{
-	writel(value, tio->base + TIOCTL);
-}
-
-/*
- * For COMPV register, It's safer to write
- * higher 32-bit followed by lower 32-bit
- */
-static inline void pps_compv_write(u64 value, struct pps_tio *tio)
-{
-	hi_lo_writeq(value, tio->base + TIOCOMPV);
-}
-
-static inline ktime_t first_event(struct pps_tio *tio)
+static inline ktime_t first_event(struct pps_tio_generator *gen)
 {
 	return ktime_set(ktime_get_real_seconds() + 1, MAGIC_CONST);
 }
 
-static u32 pps_tio_disable(struct pps_tio *tio)
-{
-	u32 ctrl;
-
-	ctrl = pps_tio_read(TIOCTL, tio);
-	pps_compv_write(0, tio);
-
-	ctrl &= ~TIOCTL_EN;
-	pps_ctl_write(ctrl, tio);
-	tio->pps_gen->enabled = false;
-	tio->prev_count = 0;
-	return ctrl;
-}
-
-static void pps_tio_enable(struct pps_tio *tio)
-{
-	u32 ctrl;
-
-	ctrl = pps_tio_read(TIOCTL, tio);
-	ctrl |= TIOCTL_EN;
-	pps_ctl_write(ctrl, tio);
-	tio->pps_gen->enabled = true;
-}
-
-static void pps_tio_direction_output(struct pps_tio *tio)
-{
-	u32 ctrl;
-
-	ctrl = pps_tio_disable(tio);
-
-	/*
-	 * We enable the device, be sure that the
-	 * 'compare' value is invalid
-	 */
-	pps_compv_write(0, tio);
-
-	ctrl &= ~(TIOCTL_DIR | TIOCTL_EP);
-	ctrl |= TIOCTL_EP_TOGGLE_EDGE;
-	pps_ctl_write(ctrl, tio);
-	pps_tio_enable(tio);
-}
-
-static bool pps_generate_next_pulse(ktime_t expires, struct pps_tio *tio)
+static bool pps_generate_next_pulse(ktime_t expires,
+				    struct pps_tio_generator *gen)
 {
 	u64 art;
 
 	if (!ktime_real_to_base_clock(expires, CSID_X86_ART, &art)) {
-		pps_tio_disable(tio);
+		pps_tio_disable(gen->tio);
+		WRITE_ONCE(gen->pps_gen->enabled, false);
+		gen->prev_count = 0;
 		return false;
 	}
 
-	pps_compv_write(art - ART_HW_DELAY_CYCLES, tio);
+	/* Write the COMPV upper 32 bits before the lower 32 bits. */
+	hi_lo_writeq(art - ART_HW_DELAY_CYCLES, gen->tio->base + TIOCOMPV);
 	return true;
 }
 
-static enum hrtimer_restart hrtimer_callback(struct hrtimer *timer)
+static enum hrtimer_restart pps_tio_gen_timer(struct hrtimer *timer)
 {
+	struct pps_tio_generator *gen = container_of(timer,
+						     struct pps_tio_generator, timer);
+	struct pps_tio *tio = gen->tio;
 	ktime_t expires, now;
 	u32 event_count;
-	struct pps_tio *tio = container_of(timer, struct pps_tio, timer);
 
-	guard(spinlock)(&tio->lock);
+	spin_lock(&tio->lock);
+	if (tio->state != TIO_GENERATING)
+		goto stop;
 
-	/*
-	 * Check if any event is missed.
-	 * If an event is missed, TIO will be disabled.
-	 */
-	event_count = pps_tio_read(TIOEC, tio);
-	if (tio->prev_count && tio->prev_count == event_count)
+	/* Disable TIO if the event count indicates a missed pulse. */
+	event_count = readl(tio->base + TIOEC);
+	if (gen->prev_count && gen->prev_count == event_count)
 		goto err;
-	tio->prev_count = event_count;
+	gen->prev_count = event_count;
 
 	expires = hrtimer_get_expires(timer);
-
 	now = ktime_get_real();
 	if (now - expires >= SAFE_TIME_NS)
 		goto err;
 
-	tio->pps_gen->enabled = pps_generate_next_pulse(expires + SAFE_TIME_NS, tio);
-	if (!tio->pps_gen->enabled)
+	if (!pps_generate_next_pulse(expires + SAFE_TIME_NS, gen)) {
+		spin_unlock(&tio->lock);
 		return HRTIMER_NORESTART;
+	}
 
 	hrtimer_forward(timer, now, NSEC_PER_SEC / 2);
+	spin_unlock(&tio->lock);
 	return HRTIMER_RESTART;
 
 err:
 	dev_err(tio->dev, "Event missed, Disabling Timed I/O");
 	pps_tio_disable(tio);
-	pps_gen_event(tio->pps_gen, PPS_GEN_EVENT_MISSEDPULSE, NULL);
+	gen->prev_count = 0;
+	WRITE_ONCE(gen->pps_gen->enabled, false);
+	pps_gen_event(gen->pps_gen, PPS_GEN_EVENT_MISSEDPULSE, NULL);
+stop:
+	spin_unlock(&tio->lock);
 	return HRTIMER_NORESTART;
 }
 
 static int pps_tio_gen_enable(struct pps_gen_device *pps_gen, bool enable)
 {
-	struct pps_tio *tio = container_of(pps_gen->info, struct pps_tio, gen_info);
+	struct pps_tio_generator *gen = container_of(pps_gen->info,
+						      struct pps_tio_generator,
+						      gen_info);
+	struct pps_tio *tio = gen->tio;
 	unsigned long flags;
 	int ret = 0;
 
 	mutex_lock(&tio->mutex);
+	if (tio->removing || gen->removing) {
+		ret = -ENODEV;
+		goto out;
+	}
 	if (!timekeeping_clocksource_has_base(CSID_X86_ART)) {
-		dev_err_once(tio->dev, "PPS cannot be used as clock is not related to ART");
+		dev_err_once(tio->dev,
+			     "PPS cannot be used as clock is not related to ART");
 		ret = -ENODEV;
-		goto out_mutex;
+		goto out;
 	}
-
 	if (!enable)
-		hrtimer_cancel(&tio->timer);
+		hrtimer_cancel(&gen->timer);
 
 	spin_lock_irqsave(&tio->lock, flags);
-	if (enable && !pps_gen->enabled) {
-		pps_tio_direction_output(tio);
-		hrtimer_start(&tio->timer, first_event(tio), HRTIMER_MODE_ABS);
-	} else if (!enable && pps_gen->enabled) {
+	if (enable && tio->state == TIO_IDLE) {
+		gen->pps_gen = pps_gen;
+		gen->prev_count = 0;
+		pps_tio_configure(tio, TIO_GENERATING);
+		WRITE_ONCE(pps_gen->enabled, true);
+		hrtimer_start(&gen->timer, first_event(gen), HRTIMER_MODE_ABS);
+	} else if (!enable && tio->state == TIO_GENERATING) {
 		pps_tio_disable(tio);
+		gen->prev_count = 0;
+		WRITE_ONCE(pps_gen->enabled, false);
 	}
 	spin_unlock_irqrestore(&tio->lock, flags);
-
-out_mutex:
+out:
 	mutex_unlock(&tio->mutex);
 	return ret;
 }
@@ -203,77 +144,63 @@ static int pps_tio_get_time(struct pps_gen_device *pps_gen,
 	return 0;
 }
 
-static int pps_gen_tio_probe(struct platform_device *pdev)
+static int pps_gen_tio_probe(struct auxiliary_device *aux,
+			     const struct auxiliary_device_id *id)
 {
-	struct device *dev = &pdev->dev;
-	struct pps_tio *tio;
-
-	if (!(cpu_feature_enabled(X86_FEATURE_TSC_KNOWN_FREQ) &&
-	      cpu_feature_enabled(X86_FEATURE_ART))) {
-		dev_warn(dev, "TSC/ART is not enabled");
-		return -ENODEV;
-	}
+	struct pps_tio_generator *gen;
 
-	tio = devm_kzalloc_obj(dev, *tio);
-	if (!tio)
+	gen = devm_kzalloc_obj(&aux->dev, *gen);
+	if (!gen)
 		return -ENOMEM;
-	mutex_init(&tio->mutex);
-
-	tio->gen_info.use_system_clock = true;
-	tio->gen_info.enable = pps_tio_gen_enable;
-	tio->gen_info.get_time = pps_tio_get_time;
-	tio->gen_info.owner = THIS_MODULE;
-
-	tio->pps_gen = pps_gen_register_source(&tio->gen_info);
-	if (IS_ERR(tio->pps_gen))
-		return PTR_ERR(tio->pps_gen);
-
-	tio->dev = dev;
-	tio->base = devm_platform_ioremap_resource(pdev, 0);
-	if (IS_ERR(tio->base))
-		return PTR_ERR(tio->base);
-
-	pps_tio_disable(tio);
-	hrtimer_setup(&tio->timer, hrtimer_callback, CLOCK_REALTIME,
+	gen->tio = dev_get_platdata(&aux->dev);
+	gen->gen_info.use_system_clock = true;
+	gen->gen_info.driver_manages_enabled = true;
+	gen->gen_info.enable = pps_tio_gen_enable;
+	gen->gen_info.get_time = pps_tio_get_time;
+	gen->gen_info.owner = THIS_MODULE;
+	gen->gen_info.parent = gen->tio->dev;
+	hrtimer_setup(&gen->timer, pps_tio_gen_timer, CLOCK_REALTIME,
 		      HRTIMER_MODE_ABS);
-	spin_lock_init(&tio->lock);
-	platform_set_drvdata(pdev, tio);
+	dev_set_drvdata(&aux->dev, gen);
 
+	gen->pps_gen = pps_gen_register_source(&gen->gen_info);
+	if (IS_ERR(gen->pps_gen))
+		return PTR_ERR(gen->pps_gen);
 	return 0;
 }
 
-static void pps_gen_tio_remove(struct platform_device *pdev)
+static void pps_gen_tio_remove(struct auxiliary_device *aux)
 {
-	struct pps_tio *tio = platform_get_drvdata(pdev);
+	struct pps_tio_generator *gen = dev_get_drvdata(&aux->dev);
+	struct pps_tio *tio = gen->tio;
 	unsigned long flags;
 
 	mutex_lock(&tio->mutex);
-	hrtimer_cancel(&tio->timer);
+	gen->removing = true;
+	hrtimer_cancel(&gen->timer);
 	spin_lock_irqsave(&tio->lock, flags);
-	pps_tio_disable(tio);
+	if (tio->state == TIO_GENERATING) {
+		pps_tio_disable(tio);
+		WRITE_ONCE(gen->pps_gen->enabled, false);
+	}
 	spin_unlock_irqrestore(&tio->lock, flags);
 	mutex_unlock(&tio->mutex);
-	pps_gen_unregister_source(tio->pps_gen);
+	pps_gen_unregister_source(gen->pps_gen);
 }
 
-static const struct acpi_device_id intel_pmc_tio_acpi_match[] = {
-	{ "INTC1021" },
-	{ "INTC1022" },
-	{ "INTC1023" },
-	{ "INTC1024" },
-	{}
+static const struct auxiliary_device_id pps_gen_tio_id[] = {
+	{ .name = "pps_tio.generator" },
+	{ }
 };
-MODULE_DEVICE_TABLE(acpi, intel_pmc_tio_acpi_match);
+MODULE_DEVICE_TABLE(auxiliary, pps_gen_tio_id);
 
-static struct platform_driver pps_gen_tio_driver = {
-	.probe          = pps_gen_tio_probe,
-	.remove         = pps_gen_tio_remove,
-	.driver         = {
-		.name                   = "intel-pps-gen-tio",
-		.acpi_match_table       = intel_pmc_tio_acpi_match,
-	},
+static struct auxiliary_driver pps_gen_tio_driver = {
+	.name = "generator",
+	.probe = pps_gen_tio_probe,
+	.remove = pps_gen_tio_remove,
+	.id_table = pps_gen_tio_id,
 };
-module_platform_driver(pps_gen_tio_driver);
+module_auxiliary_driver(pps_gen_tio_driver);
 
 MODULE_AUTHOR("Christopher Hall <christopher.s.hall@intel.com>");
 MODULE_AUTHOR("Lakshmi Sowjanya D <lakshmi.sowjanya.d@intel.com>");
@@ -282,3 +209,4 @@ MODULE_AUTHOR("Thejesh Reddy T R <thejesh.reddy.t.r@intel.com>");
 MODULE_AUTHOR("Subramanian Mohan <subramanian.mohan@intel.com>");
 MODULE_DESCRIPTION("Intel PMC Time-Aware IO Generator Driver");
 MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("PPS_TIO");
diff --git a/drivers/pps/generators/sysfs.c b/drivers/pps/generators/sysfs.c
index 43d833383fe9..ee82ff435f26 100644
--- a/drivers/pps/generators/sysfs.c
+++ b/drivers/pps/generators/sysfs.c
@@ -64,8 +64,8 @@ static ssize_t enable_store(struct device *dev, struct device_attribute *attr,
 	mutex_lock(&pps_gen->info_lock);
 	if (pps_gen->info) {
 		ret = pps_gen->info->enable(pps_gen, status);
-		if (!ret)
-			pps_gen->enabled = status;
+		if (!ret && !pps_gen->info->driver_manages_enabled)
+			WRITE_ONCE(pps_gen->enabled, status);
 	} else {
 		ret = -ENODEV;
 	}
diff --git a/drivers/pps/pps_tio.c b/drivers/pps/pps_tio.c
new file mode 100644
index 000000000000..6b2eda8de0f5
--- /dev/null
+++ b/drivers/pps/pps_tio.c
@@ -0,0 +1,155 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Intel Timed I/O PPS Hardware Driver
+ *
+ * Copyright (C) 2026 Intel Corporation
+ */
+
+#include <linux/acpi.h>
+#include <linux/auxiliary_bus.h>
+#include <linux/idr.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+#include <asm/cpu_device_id.h>
+
+#include "pps_tio.h"
+
+static DEFINE_IDA(pps_tio_ida);
+
+void pps_tio_disable(struct pps_tio *tio)
+{
+	u32 ctrl = readl(tio->base + TIOCTL);
+
+	hi_lo_writeq(0, tio->base + TIOCOMPV);
+	writel(ctrl & ~TIOCTL_EN, tio->base + TIOCTL);
+	tio->state = TIO_IDLE;
+}
+EXPORT_SYMBOL_NS_GPL(pps_tio_disable, "PPS_TIO");
+
+void pps_tio_configure(struct pps_tio *tio, enum tio_state state)
+{
+	u32 ctrl;
+
+	/* Clear the compare value before enabling the device. */
+	pps_tio_disable(tio);
+	ctrl = readl(tio->base + TIOCTL);
+	ctrl &= ~(TIOCTL_DIR | TIOCTL_EP);
+	ctrl |= TIOCTL_EP_TOGGLE_EDGE;
+	writel(ctrl, tio->base + TIOCTL);
+	writel(ctrl | TIOCTL_EN, tio->base + TIOCTL);
+	tio->state = state;
+}
+EXPORT_SYMBOL_NS_GPL(pps_tio_configure, "PPS_TIO");
+
+static void pps_tio_aux_release(struct device *dev)
+{
+	struct auxiliary_device *aux = container_of(dev, struct auxiliary_device, dev);
+
+	kfree(aux);
+}
+
+static struct auxiliary_device *pps_tio_add_aux(struct pps_tio *tio,
+						const char *name)
+{
+	struct auxiliary_device *aux;
+	int ret;
+
+	aux = kzalloc_obj(*aux);
+	if (!aux)
+		return ERR_PTR(-ENOMEM);
+
+	aux->name = name;
+	aux->id = tio->id;
+	aux->dev.parent = tio->dev;
+	aux->dev.platform_data = tio;
+	aux->dev.release = pps_tio_aux_release;
+	ret = auxiliary_device_init(aux);
+	if (ret) {
+		kfree(aux);
+		return ERR_PTR(ret);
+	}
+	ret = auxiliary_device_add(aux);
+	if (ret) {
+		auxiliary_device_uninit(aux);
+		return ERR_PTR(ret);
+	}
+	return aux;
+}
+
+static void pps_tio_del_aux(struct auxiliary_device *aux)
+{
+	auxiliary_device_delete(aux);
+	auxiliary_device_uninit(aux);
+}
+
+static int pps_tio_probe(struct platform_device *pdev)
+{
+	struct pps_tio *tio;
+	int ret;
+
+	if (!(cpu_feature_enabled(X86_FEATURE_TSC_KNOWN_FREQ) &&
+	      cpu_feature_enabled(X86_FEATURE_ART)))
+		return dev_err_probe(&pdev->dev, -ENODEV, "TSC/ART is not enabled\n");
+
+	tio = devm_kzalloc(&pdev->dev, sizeof(*tio), GFP_KERNEL);
+	if (!tio)
+		return -ENOMEM;
+	tio->dev = &pdev->dev;
+	tio->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(tio->base))
+		return PTR_ERR(tio->base);
+	mutex_init(&tio->mutex);
+	spin_lock_init(&tio->lock);
+	platform_set_drvdata(pdev, tio);
+	pps_tio_disable(tio);
+
+	ret = ida_alloc(&pps_tio_ida, GFP_KERNEL);
+	if (ret < 0)
+		return ret;
+	tio->id = ret;
+	tio->generator = pps_tio_add_aux(tio, "generator");
+	if (IS_ERR(tio->generator)) {
+		ret = PTR_ERR(tio->generator);
+		goto free_id;
+	}
+	return 0;
+
+free_id:
+	ida_free(&pps_tio_ida, tio->id);
+	return ret;
+}
+
+static void pps_tio_remove(struct platform_device *pdev)
+{
+	struct pps_tio *tio = platform_get_drvdata(pdev);
+
+	mutex_lock(&tio->mutex);
+	tio->removing = true;
+	mutex_unlock(&tio->mutex);
+	pps_tio_del_aux(tio->generator);
+	ida_free(&pps_tio_ida, tio->id);
+}
+
+static const struct acpi_device_id pps_tio_acpi_match[] = {
+	{ "INTC1021" },
+	{ "INTC1022" },
+	{ "INTC1023" },
+	{ "INTC1024" },
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, pps_tio_acpi_match);
+
+static struct platform_driver pps_tio_driver = {
+	.probe = pps_tio_probe,
+	.remove = pps_tio_remove,
+	.driver = {
+		.name = "intel-pps-gen-tio",
+		.acpi_match_table = pps_tio_acpi_match,
+	},
+};
+module_platform_driver(pps_tio_driver);
+
+MODULE_AUTHOR("Voon Weifeng <weifeng.voon@intel.com>");
+MODULE_DESCRIPTION("Intel Timed I/O PPS hardware driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/pps/pps_tio.h b/drivers/pps/pps_tio.h
new file mode 100644
index 000000000000..c078db8787b0
--- /dev/null
+++ b/drivers/pps/pps_tio.h
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Intel Timed I/O PPS Shared Definitions
+ *
+ * Copyright (C) 2026 Intel Corporation
+ */
+
+#ifndef _PPS_TIO_H
+#define _PPS_TIO_H
+
+#include <linux/auxiliary_bus.h>
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+#include <linux/device.h>
+#include <linux/io-64-nonatomic-hi-lo.h>
+#include <linux/mutex.h>
+#include <linux/spinlock.h>
+
+#define TIOCTL			0x00
+#define TIOCOMPV		0x10
+#define TIOEC			0x30
+
+#define TIOCTL_EN		BIT(0)
+#define TIOCTL_DIR		BIT(1)
+#define TIOCTL_EP		GENMASK(3, 2)
+#define TIOCTL_EP_TOGGLE_EDGE	FIELD_PREP(TIOCTL_EP, 2)
+
+enum tio_state {
+	TIO_IDLE,
+	TIO_GENERATING,
+};
+
+struct pps_tio {
+	struct device *dev;
+	void __iomem *base;
+	struct mutex mutex;
+	spinlock_t lock;
+	enum tio_state state;
+	bool removing;
+	struct auxiliary_device *generator;
+	int id;
+};
+
+void pps_tio_disable(struct pps_tio *tio);
+void pps_tio_configure(struct pps_tio *tio, enum tio_state state);
+
+#endif
diff --git a/include/linux/pps_gen_kernel.h b/include/linux/pps_gen_kernel.h
index c4d22b1af118..3579ccb451f4 100644
--- a/include/linux/pps_gen_kernel.h
+++ b/include/linux/pps_gen_kernel.h
@@ -24,6 +24,7 @@ struct pps_gen_device;
 /**
  * struct pps_gen_source_info - the specific PPS generator info
  * @use_system_clock: true, if the system clock is used to generate pulses
+ * @driver_manages_enabled: driver updates enabled on enable and state changes
  * @get_time: query the time stored into the generator clock
  * @enable: enable/disable the PPS pulses generation
  *
@@ -32,6 +33,7 @@ struct pps_gen_device;
  */
 struct pps_gen_source_info {
 	bool use_system_clock;
+	bool driver_manages_enabled;
 
 	int (*get_time)(struct pps_gen_device *pps_gen,
 					struct timespec64 *time);
-- 
2.43.0


  parent reply	other threads:[~2026-12-02  9:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 17:21 [PATCH 0/4] pps: add Intel Timed I/O PPS input support KhaiWenTan
2026-12-02 17:21 ` [PATCH 1/4] pps: generators: synchronize sysfs and registration failure KhaiWenTan
2026-12-02 17:21 ` [PATCH 2/4] pps: generators: cancel TIO timer outside spinlock KhaiWenTan
2026-12-02 17:21 ` KhaiWenTan [this message]
2026-12-02 17:21 ` [PATCH 4/4] pps: clients: add Intel TIO PPS capture KhaiWenTan

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=20261202172254.1188109-4-khai.wen.tan@linux.intel.com \
    --to=khai.wen.tan@linux.intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=christopher.s.hall@intel.com \
    --cc=corbet@lwn.net \
    --cc=david.zage@intel.com \
    --cc=giometti@enneenne.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hong.aun.looi@intel.com \
    --cc=khai.wen.tan@intel.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@kernel.org \
    --cc=weifeng.voon@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®