* [PATCH 0/4] pps: add Intel Timed I/O PPS input support
@ 2026-12-02 17:21 KhaiWenTan
2026-12-02 17:21 ` [PATCH 1/4] pps: generators: synchronize sysfs and registration failure KhaiWenTan
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: KhaiWenTan @ 2026-12-02 17:21 UTC (permalink / raw)
To: Rodolfo Giometti, Greg Kroah-Hartman, Jonathan Corbet
Cc: Thomas Gleixner, Andy Shevchenko, david.zage, weifeng.voon,
hong.aun.looi, christopher.s.hall, khai.wen.tan, linux-kernel,
linux-doc
Intel Timed I/O (TIO) pins can either generate output edges at a
programmed time or capture input edges, both timestamped in the ART
clock domain. The existing pps_gen_tio driver supports generation only.
This series adds capture support as a PPS client, so an external PPS
signal on a TIO pin can be used as a regular /dev/ppsN source.
Patches 1-2 prepare the existing generator code:
- Patch 1 serializes the PPS generator sysfs callbacks with source
removal using the existing info lock, rejects opens and reports a
hangup after removal, and cleans up when cdev_device_add() fails.
- Patch 2 moves hrtimer_cancel() in pps_gen_tio out of the spinlocked
section, since the timer callback takes the same lock, and serializes
enable, disable and removal with a mutex.
Patch 3 moves ACPI enumeration and register ownership into a new shared
pps_tio platform driver. It creates "generator" and "client" auxiliary
devices, and pps_gen_tio becomes an auxiliary driver. The platform driver
name and the generator's user-visible behavior are unchanged. A new
driver_manages_enabled flag in struct pps_gen_source_info lets the
driver own the enabled state so the generator core cannot overwrite an
asynchronous missed-pulse failure.
Patch 4 adds the pps_tio_client driver. It registers a PPS source per
TIO device, polls the latched timestamp and event counter, converts the
ART timestamp to system time with get_device_system_crosststamp() and
reports the edge as a PPS assert or clear event. Capture is disabled by
default and is controlled per device through two new sysfs attributes,
capture_enable and capture_edge, documented in
Documentation/ABI/testing/sysfs-platform-intel-tio and in
Documentation/driver-api/pps.rst.
Generation and capture are mutually exclusive on a pin. Enabling one
while the other is active fails with -EBUSY. The hardware retains only
the most recent captured edge, so edges arriving between polls are lost;
the driver warns when the event counter shows this has happened.
Voon Weifeng (4):
pps: generators: synchronize sysfs and registration failure
pps: generators: cancel TIO timer outside spinlock
pps: generators: move TIO ownership to auxiliary parent
pps: clients: add Intel TIO PPS capture
.../ABI/testing/sysfs-platform-intel-tio | 24 ++
Documentation/ABI/testing/sysfs-pps-gen-tio | 1 +
Documentation/driver-api/pps.rst | 29 ++
MAINTAINERS | 1 +
drivers/pps/Kconfig | 5 +
drivers/pps/Makefile | 1 +
drivers/pps/clients/Kconfig | 10 +
drivers/pps/clients/Makefile | 1 +
drivers/pps/clients/pps_tio_client.c | 298 ++++++++++++++++++
drivers/pps/generators/Kconfig | 1 +
drivers/pps/generators/pps_gen.c | 27 +-
drivers/pps/generators/pps_gen_tio.c | 283 +++++++----------
drivers/pps/generators/sysfs.c | 27 +-
drivers/pps/pps_tio.c | 167 ++++++++++
drivers/pps/pps_tio.h | 57 ++++
include/linux/pps_gen_kernel.h | 2 +
16 files changed, 757 insertions(+), 177 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-tio
create mode 100644 drivers/pps/clients/pps_tio_client.c
create mode 100644 drivers/pps/pps_tio.c
create mode 100644 drivers/pps/pps_tio.h
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] pps: generators: synchronize sysfs and registration failure
2026-12-02 17:21 [PATCH 0/4] pps: add Intel Timed I/O PPS input support KhaiWenTan
@ 2026-12-02 17:21 ` KhaiWenTan
2026-12-02 17:21 ` [PATCH 2/4] pps: generators: cancel TIO timer outside spinlock KhaiWenTan
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: KhaiWenTan @ 2026-12-02 17:21 UTC (permalink / raw)
To: Rodolfo Giometti, Greg Kroah-Hartman, Jonathan Corbet
Cc: Thomas Gleixner, Andy Shevchenko, david.zage, weifeng.voon,
hong.aun.looi, christopher.s.hall, khai.wen.tan, linux-kernel,
linux-doc
From: Voon Weifeng <weifeng.voon@intel.com>
Serialize sysfs callbacks with ioctls and source removal using the
existing info lock. Reject opens and report a hangup after removal.
If cdev_device_add() fails after making the character device available,
stop the generator, invalidate its driver info and wake event readers
before releasing the device.
Fixes: 86b525bed275 ("drivers pps: add PPS generators support")
Signed-off-by: Voon Weifeng <weifeng.voon@intel.com>
Signed-off-by: KhaiWenTan <khai.wen.tan@linux.intel.com>
---
drivers/pps/generators/pps_gen.c | 20 ++++++++++++++++++--
drivers/pps/generators/sysfs.c | 27 +++++++++++++++++++++++----
2 files changed, 41 insertions(+), 6 deletions(-)
diff --git a/drivers/pps/generators/pps_gen.c b/drivers/pps/generators/pps_gen.c
index 474e17c36458..8f68061b8698 100644
--- a/drivers/pps/generators/pps_gen.c
+++ b/drivers/pps/generators/pps_gen.c
@@ -42,6 +42,8 @@ static __poll_t pps_gen_cdev_poll(struct file *file, poll_table *wait)
struct pps_gen_device *pps_gen = file->private_data;
poll_wait(file, &pps_gen->queue, wait);
+ if (!READ_ONCE(pps_gen->info))
+ return EPOLLHUP | EPOLLERR;
return EPOLLIN | EPOLLRDNORM;
}
@@ -134,10 +136,18 @@ static int pps_gen_cdev_open(struct inode *inode, struct file *file)
{
struct pps_gen_device *pps_gen = container_of(inode->i_cdev,
struct pps_gen_device, cdev);
+ int ret = 0;
get_device(&pps_gen->dev);
- file->private_data = pps_gen;
- return 0;
+ mutex_lock(&pps_gen->info_lock);
+ if (pps_gen->info)
+ file->private_data = pps_gen;
+ else
+ ret = -ENODEV;
+ mutex_unlock(&pps_gen->info_lock);
+ if (ret)
+ put_device(&pps_gen->dev);
+ return ret;
}
static int pps_gen_cdev_release(struct inode *inode, struct file *file)
@@ -209,6 +219,12 @@ static int pps_gen_register_cdev(struct pps_gen_device *pps_gen)
if (err) {
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)
+ pps_gen->info->enable(pps_gen, false);
+ WRITE_ONCE(pps_gen->info, NULL);
+ mutex_unlock(&pps_gen->info_lock);
+ wake_up_interruptible_all(&pps_gen->queue);
goto put_dev;
}
diff --git a/drivers/pps/generators/sysfs.c b/drivers/pps/generators/sysfs.c
index 6d6bc0006fea..43d833383fe9 100644
--- a/drivers/pps/generators/sysfs.c
+++ b/drivers/pps/generators/sysfs.c
@@ -18,8 +18,15 @@ static ssize_t system_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct pps_gen_device *pps_gen = dev_get_drvdata(dev);
+ ssize_t ret;
- return sysfs_emit(buf, "%d\n", pps_gen->info->use_system_clock);
+ mutex_lock(&pps_gen->info_lock);
+ if (pps_gen->info)
+ ret = sysfs_emit(buf, "%d\n", pps_gen->info->use_system_clock);
+ else
+ ret = -ENODEV;
+ mutex_unlock(&pps_gen->info_lock);
+ return ret;
}
static DEVICE_ATTR_RO(system);
@@ -30,7 +37,12 @@ static ssize_t time_show(struct device *dev, struct device_attribute *attr,
struct timespec64 time;
int ret;
- ret = pps_gen->info->get_time(pps_gen, &time);
+ mutex_lock(&pps_gen->info_lock);
+ if (pps_gen->info)
+ ret = pps_gen->info->get_time(pps_gen, &time);
+ else
+ ret = -ENODEV;
+ mutex_unlock(&pps_gen->info_lock);
if (ret)
return ret;
@@ -49,10 +61,17 @@ static ssize_t enable_store(struct device *dev, struct device_attribute *attr,
if (ret)
return ret;
- ret = pps_gen->info->enable(pps_gen, status);
+ mutex_lock(&pps_gen->info_lock);
+ if (pps_gen->info) {
+ ret = pps_gen->info->enable(pps_gen, status);
+ if (!ret)
+ pps_gen->enabled = status;
+ } else {
+ ret = -ENODEV;
+ }
+ mutex_unlock(&pps_gen->info_lock);
if (ret)
return ret;
- pps_gen->enabled = status;
return count;
}
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/4] pps: generators: cancel TIO timer outside spinlock
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 ` KhaiWenTan
2026-12-02 17:21 ` [PATCH 3/4] pps: generators: move TIO ownership to auxiliary parent KhaiWenTan
2026-12-02 17:21 ` [PATCH 4/4] pps: clients: add Intel TIO PPS capture KhaiWenTan
3 siblings, 0 replies; 5+ messages in thread
From: KhaiWenTan @ 2026-12-02 17:21 UTC (permalink / raw)
To: Rodolfo Giometti, Greg Kroah-Hartman, Jonathan Corbet
Cc: Thomas Gleixner, Andy Shevchenko, david.zage, weifeng.voon,
hong.aun.looi, christopher.s.hall, khai.wen.tan, linux-kernel,
linux-doc
From: Voon Weifeng <weifeng.voon@intel.com>
Move hrtimer_cancel() out of the spinlocked section. The timer
callback takes the same lock, so cancelling while holding it can
deadlock. Serialize enable, disable and removal with a mutex.
Fixes: c89755d1111f ("pps: generators: Add PPS Generator TIO Driver")
Signed-off-by: Voon Weifeng <weifeng.voon@intel.com>
Signed-off-by: KhaiWenTan <khai.wen.tan@linux.intel.com>
---
drivers/pps/generators/pps_gen_tio.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/drivers/pps/generators/pps_gen_tio.c b/drivers/pps/generators/pps_gen_tio.c
index c6d41fb2105f..9e3142041269 100644
--- a/drivers/pps/generators/pps_gen_tio.c
+++ b/drivers/pps/generators/pps_gen_tio.c
@@ -13,6 +13,7 @@
#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>
@@ -44,6 +45,7 @@ struct pps_tio {
struct hrtimer timer;
void __iomem *base;
u32 prev_count;
+ struct mutex mutex;
spinlock_t lock;
struct device *dev;
};
@@ -167,22 +169,31 @@ static enum hrtimer_restart hrtimer_callback(struct hrtimer *timer)
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);
+ unsigned long flags;
+ int ret = 0;
+ mutex_lock(&tio->mutex);
if (!timekeeping_clocksource_has_base(CSID_X86_ART)) {
dev_err_once(tio->dev, "PPS cannot be used as clock is not related to ART");
- return -ENODEV;
+ ret = -ENODEV;
+ goto out_mutex;
}
- guard(spinlock_irqsave)(&tio->lock);
+ if (!enable)
+ hrtimer_cancel(&tio->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) {
- hrtimer_cancel(&tio->timer);
pps_tio_disable(tio);
}
+ spin_unlock_irqrestore(&tio->lock, flags);
- return 0;
+out_mutex:
+ mutex_unlock(&tio->mutex);
+ return ret;
}
static int pps_tio_get_time(struct pps_gen_device *pps_gen,
@@ -206,6 +217,7 @@ static int pps_gen_tio_probe(struct platform_device *pdev)
tio = devm_kzalloc_obj(dev, *tio);
if (!tio)
return -ENOMEM;
+ mutex_init(&tio->mutex);
tio->gen_info.use_system_clock = true;
tio->gen_info.enable = pps_tio_gen_enable;
@@ -233,9 +245,14 @@ static int pps_gen_tio_probe(struct platform_device *pdev)
static void pps_gen_tio_remove(struct platform_device *pdev)
{
struct pps_tio *tio = platform_get_drvdata(pdev);
+ unsigned long flags;
+ mutex_lock(&tio->mutex);
hrtimer_cancel(&tio->timer);
+ spin_lock_irqsave(&tio->lock, flags);
pps_tio_disable(tio);
+ spin_unlock_irqrestore(&tio->lock, flags);
+ mutex_unlock(&tio->mutex);
pps_gen_unregister_source(tio->pps_gen);
}
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/4] pps: generators: move TIO ownership to auxiliary parent
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
2026-12-02 17:21 ` [PATCH 4/4] pps: clients: add Intel TIO PPS capture KhaiWenTan
3 siblings, 0 replies; 5+ messages in thread
From: KhaiWenTan @ 2026-12-02 17:21 UTC (permalink / raw)
To: Rodolfo Giometti, Greg Kroah-Hartman, Jonathan Corbet
Cc: Thomas Gleixner, Andy Shevchenko, david.zage, weifeng.voon,
hong.aun.looi, christopher.s.hall, khai.wen.tan, linux-kernel,
linux-doc
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 4/4] pps: clients: add Intel TIO PPS capture
2026-12-02 17:21 [PATCH 0/4] pps: add Intel Timed I/O PPS input support KhaiWenTan
` (2 preceding siblings ...)
2026-12-02 17:21 ` [PATCH 3/4] pps: generators: move TIO ownership to auxiliary parent KhaiWenTan
@ 2026-12-02 17:21 ` KhaiWenTan
3 siblings, 0 replies; 5+ messages in thread
From: KhaiWenTan @ 2026-12-02 17:21 UTC (permalink / raw)
To: Rodolfo Giometti, Greg Kroah-Hartman, Jonathan Corbet
Cc: Thomas Gleixner, Andy Shevchenko, david.zage, weifeng.voon,
hong.aun.looi, christopher.s.hall, khai.wen.tan, linux-kernel,
linux-doc
From: Voon Weifeng <weifeng.voon@intel.com>
Add an auxiliary PPS client for Intel Timed I/O hardware. The shared
TIO owner arbitrates the pin between capture and generation, so both
interfaces remain registered while only one role is active. Reject
requests to enable either role while the other owns the pin.
Poll the latched event timestamp and event count, convert the ART
timestamp to system time, and report the selected rising or falling
edge. Warn about overwritten events and conversion failures. Read an
initial counter baseline and retry inconsistent capture reads.
Keep capture disabled by default and document the per-device capture
enable and edge controls. The capture registers remain readable while
capture is disabled and retain their values when capture is enabled,
allowing the initial counter baseline to be read before enabling capture.
This builds on earlier Intel TIO work by Christopher Hall, Pandith N
and Subramanian Mohan.
Co-developed-by: Christopher Hall <christopher.s.hall@intel.com>
Signed-off-by: Christopher Hall <christopher.s.hall@intel.com>
Signed-off-by: Voon Weifeng <weifeng.voon@intel.com>
Signed-off-by: KhaiWenTan <khai.wen.tan@linux.intel.com>
---
.../ABI/testing/sysfs-platform-intel-tio | 24 ++
Documentation/ABI/testing/sysfs-pps-gen-tio | 1 +
Documentation/driver-api/pps.rst | 29 ++
MAINTAINERS | 1 +
drivers/pps/clients/Kconfig | 10 +
drivers/pps/clients/Makefile | 1 +
drivers/pps/clients/pps_tio_client.c | 298 ++++++++++++++++++
drivers/pps/generators/pps_gen_tio.c | 4 +-
drivers/pps/pps_tio.c | 14 +-
drivers/pps/pps_tio.h | 10 +
10 files changed, 390 insertions(+), 2 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-platform-intel-tio
create mode 100644 drivers/pps/clients/pps_tio_client.c
diff --git a/Documentation/ABI/testing/sysfs-platform-intel-tio b/Documentation/ABI/testing/sysfs-platform-intel-tio
new file mode 100644
index 000000000000..64e910f1a2f8
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-platform-intel-tio
@@ -0,0 +1,24 @@
+What: /sys/bus/platform/devices/INTC102[1-4]:*/capture_enable
+Date: November 2026
+Contact: "Tan Khai Wen" <khai.wen.tan@intel.com>
+Description:
+ Read or enable Intel Timed I/O PPS capture. This attribute is
+ present when the Intel TIO PPS client is bound.
+ It accepts a boolean value and reads back 0 or 1. Capture is
+ disabled initially.
+
+ Writing 1 fails with EBUSY while PPS generation is active, and
+ with ENODEV if the system clocksource is not based on ART.
+ It fails with EAGAIN if a system-time snapshot is unavailable
+ or the capture registers cannot be read consistently.
+ Disable capture before enabling PPS generation on the same pin.
+
+What: /sys/bus/platform/devices/INTC102[1-4]:*/capture_edge
+Date: November 2026
+Contact: "Tan Khai Wen" <khai.wen.tan@intel.com>
+Description:
+ Select the edge captured by the Intel Timed I/O PPS source.
+ The accepted values are "rising" and "falling". The default is
+ "rising". Writes fail with EBUSY while capture or generation
+ is active. The rising edge is reported as PPS assert, and the
+ falling edge as PPS clear.
diff --git a/Documentation/ABI/testing/sysfs-pps-gen-tio b/Documentation/ABI/testing/sysfs-pps-gen-tio
index 3c34ff17a335..c1489b8fa708 100644
--- a/Documentation/ABI/testing/sysfs-pps-gen-tio
+++ b/Documentation/ABI/testing/sysfs-pps-gen-tio
@@ -4,3 +4,4 @@ KernelVersion: 6.15
Contact: Subramanian Mohan<subramanian.mohan@intel.com>
Description:
Enable or disable PPS TIO generator output.
+ Enabling fails with EBUSY while PPS capture is active on the pin.
diff --git a/Documentation/driver-api/pps.rst b/Documentation/driver-api/pps.rst
index 598729f9cd27..f52fb669670b 100644
--- a/Documentation/driver-api/pps.rst
+++ b/Documentation/driver-api/pps.rst
@@ -309,3 +309,32 @@ Start generating PPS signal::
Stop generating PPS signal::
$echo 0 > /sys/class/pps-gen/pps-genx/enable
+
+Intel Timed I/O PPS capture
+---------------------------
+
+When CONFIG_PPS_CLIENT_TIO is enabled, the TIO client registers a PPS
+source. The hardware latches edges in the ART clock
+domain. The driver polls the capture register and converts each observed
+timestamp to system time. Capture is disabled initially.
+
+Generation and capture are mutually exclusive on each TIO pin. Stop the
+generator before enabling capture, and stop capture before enabling the
+generator. The platform device for a PPS source is available through the
+source's ``device`` symlink. To enable capture for ``pps0``::
+
+ $ echo 1 > /sys/class/pps/pps0/device/capture_enable
+
+To stop capture::
+
+ $ echo 0 > /sys/class/pps/pps0/device/capture_enable
+
+The captured edge defaults to rising and may be changed while the pin is
+idle::
+
+ $ echo falling > /sys/class/pps/pps0/device/capture_edge
+
+The hardware retains only the latest captured timestamp. Edges occurring
+between polls may therefore be lost. The driver reports a warning when the
+event counter indicates that this has happened, or when conversion to system
+time fails. Failed conversions are not reported as PPS events.
diff --git a/MAINTAINERS b/MAINTAINERS
index 84cb98ef4c49..cd8bc2060a8e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -22379,6 +22379,7 @@ M: Rodolfo Giometti <giometti@enneenne.com>
L: linuxpps@ml.enneenne.com (subscribers-only)
S: Maintained
W: http://wiki.enneenne.com/index.php/LinuxPPS_support
+F: Documentation/ABI/testing/sysfs-platform-intel-tio
F: Documentation/ABI/testing/sysfs-pps
F: Documentation/ABI/testing/sysfs-pps-gen
F: Documentation/ABI/testing/sysfs-pps-gen-tio
diff --git a/drivers/pps/clients/Kconfig b/drivers/pps/clients/Kconfig
index 4f3244e17aa1..24097e945b60 100644
--- a/drivers/pps/clients/Kconfig
+++ b/drivers/pps/clients/Kconfig
@@ -35,3 +35,13 @@ config PPS_CLIENT_GPIO
GPIO. To be useful you must also register a platform device
specifying the GPIO pin and other options, usually in your board
setup.
+
+config PPS_CLIENT_TIO
+ tristate "Intel TIO PPS client"
+ depends on X86 && CPU_SUP_INTEL
+ select PPS_TIO
+ help
+ Capture PPS edges using Intel Timed I/O. Capture is disabled
+ initially and can be enabled using the platform device's
+ capture_enable attribute. A pin cannot capture and generate
+ PPS signals at the same time.
diff --git a/drivers/pps/clients/Makefile b/drivers/pps/clients/Makefile
index 7a3807e57832..eebb7b2f4550 100644
--- a/drivers/pps/clients/Makefile
+++ b/drivers/pps/clients/Makefile
@@ -7,5 +7,6 @@ obj-$(CONFIG_PPS_CLIENT_KTIMER) += pps-ktimer.o
obj-$(CONFIG_PPS_CLIENT_LDISC) += pps-ldisc.o
obj-$(CONFIG_PPS_CLIENT_PARPORT) += pps_parport.o
obj-$(CONFIG_PPS_CLIENT_GPIO) += pps-gpio.o
+obj-$(CONFIG_PPS_CLIENT_TIO) += pps_tio_client.o
ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG
diff --git a/drivers/pps/clients/pps_tio_client.c b/drivers/pps/clients/pps_tio_client.c
new file mode 100644
index 000000000000..d28fad4a0291
--- /dev/null
+++ b/drivers/pps/clients/pps_tio_client.c
@@ -0,0 +1,298 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Intel Timed I/O PPS Capture Driver
+ *
+ * Copyright (C) 2026 Intel Corporation
+ */
+
+#include <linux/auxiliary_bus.h>
+#include <linux/hrtimer.h>
+#include <linux/module.h>
+#include <linux/pps_kernel.h>
+#include <linux/timekeeping.h>
+
+#include "../pps_tio.h"
+
+#define CAPTURE_INTERVAL_NS (100 * NSEC_PER_MSEC)
+
+struct pps_tio_client {
+ struct pps_tio *tio;
+ struct pps_device *pps;
+ struct hrtimer timer;
+ struct system_time_snapshot prev_snapshot;
+ u64 capture_count;
+ bool removing;
+};
+
+static int pps_tio_read_capture(struct pps_tio *tio, u64 *capture, u64 *count)
+{
+ u64 first_count, capture_count, next_count;
+ u32 low, high;
+ int retries;
+
+ for (retries = 0; retries < 3; retries++) {
+ first_count = hi_lo_readq(tio->base + TIOECCV);
+ low = readl(tio->base + TIOTCV);
+ capture_count = hi_lo_readq(tio->base + TIOECCV);
+ high = readl(tio->base + TIOTCV + sizeof(u32));
+ readl(tio->base + TIOTCV);
+ next_count = hi_lo_readq(tio->base + TIOECCV);
+ if (first_count == capture_count && capture_count == next_count) {
+ *capture = (u64)high << 32 | low;
+ *count = capture_count;
+ return 0;
+ }
+ }
+ return -EAGAIN;
+}
+
+static int pps_tio_capture_time(ktime_t *device,
+ struct system_counterval_t *system, void *ctx)
+{
+ u64 cycles = *(u64 *)ctx;
+
+ *device = cycles;
+ system->cycles = cycles;
+ system->cs_id = CSID_X86_ART;
+ return 0;
+}
+
+static enum hrtimer_restart pps_tio_capture_timer(struct hrtimer *timer)
+{
+ struct pps_tio_client *client = container_of(timer, struct pps_tio_client, timer);
+ struct system_device_crosststamp xts = { .clock_id = CLOCK_REALTIME };
+ struct pps_tio *tio = client->tio;
+ struct system_time_snapshot snapshot;
+ struct pps_event_time event;
+ u64 capture, count;
+ int ret;
+
+ spin_lock(&tio->lock);
+ if (tio->state != TIO_CAPTURING) {
+ spin_unlock(&tio->lock);
+ return HRTIMER_NORESTART;
+ }
+ ktime_get_snapshot_id(CLOCK_REALTIME, &snapshot);
+ ret = pps_tio_read_capture(tio, &capture, &count);
+ if (ret) {
+ dev_warn_ratelimited(tio->dev, "capture changed while reading\n");
+ goto restart;
+ }
+ if (count != client->capture_count) {
+ if (count - client->capture_count > 1)
+ dev_warn_ratelimited(tio->dev, "PPS capture events lost\n");
+ ret = get_device_system_crosststamp(pps_tio_capture_time, &capture,
+ &client->prev_snapshot, &xts);
+ if (!ret) {
+ event.ts_real = ktime_to_timespec64(xts.sys_systime);
+#ifdef CONFIG_NTP_PPS
+ event.ts_raw = ktime_to_timespec64(xts.sys_monoraw);
+#endif
+ pps_event(client->pps, &event, tio->capture_falling ?
+ PPS_CAPTURECLEAR : PPS_CAPTUREASSERT, NULL);
+ } else {
+ dev_warn_ratelimited(tio->dev, "capture timestamp conversion failed: %d\n",
+ ret);
+ }
+ }
+ client->capture_count = count;
+ if (snapshot.valid)
+ client->prev_snapshot = snapshot;
+restart:
+ hrtimer_forward_now(timer, ns_to_ktime(CAPTURE_INTERVAL_NS));
+ spin_unlock(&tio->lock);
+ return HRTIMER_RESTART;
+}
+
+static ssize_t capture_enable_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct pps_tio *tio = dev_get_drvdata(dev);
+ unsigned long flags;
+ bool enabled;
+
+ spin_lock_irqsave(&tio->lock, flags);
+ enabled = tio->state == TIO_CAPTURING;
+ spin_unlock_irqrestore(&tio->lock, flags);
+ return sysfs_emit(buf, "%d\n", enabled);
+}
+
+static ssize_t capture_enable_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct pps_tio *tio = dev_get_drvdata(dev);
+ struct pps_tio_client *client = tio->client;
+ unsigned long flags;
+ u64 capture;
+ bool enable;
+ int ret;
+
+ ret = kstrtobool(buf, &enable);
+ if (ret)
+ return ret;
+ mutex_lock(&tio->mutex);
+ if (tio->removing || client->removing) {
+ ret = -ENODEV;
+ goto out;
+ }
+ if (enable && !timekeeping_clocksource_has_base(CSID_X86_ART)) {
+ ret = -ENODEV;
+ goto out;
+ }
+ if (!enable)
+ hrtimer_cancel(&client->timer);
+ spin_lock_irqsave(&tio->lock, flags);
+ if (enable && tio->state == TIO_GENERATING) {
+ ret = -EBUSY;
+ } else if (enable && tio->state == TIO_IDLE) {
+ ktime_get_snapshot_id(CLOCK_REALTIME, &client->prev_snapshot);
+ if (!client->prev_snapshot.valid) {
+ ret = -EAGAIN;
+ } else {
+ ret = pps_tio_read_capture(tio, &capture, &client->capture_count);
+ if (!ret) {
+ pps_tio_configure(tio, TIO_CAPTURING);
+ hrtimer_start(&client->timer,
+ ns_to_ktime(CAPTURE_INTERVAL_NS),
+ HRTIMER_MODE_REL);
+ }
+ }
+ } else if (!enable && tio->state == TIO_CAPTURING) {
+ pps_tio_disable(tio);
+ }
+ spin_unlock_irqrestore(&tio->lock, flags);
+out:
+ mutex_unlock(&tio->mutex);
+ if (ret)
+ return ret;
+ return count;
+}
+static DEVICE_ATTR_RW(capture_enable);
+
+static ssize_t capture_edge_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct pps_tio *tio = dev_get_drvdata(dev);
+ unsigned long flags;
+ bool falling;
+
+ spin_lock_irqsave(&tio->lock, flags);
+ falling = tio->capture_falling;
+ spin_unlock_irqrestore(&tio->lock, flags);
+ return sysfs_emit(buf, "%s\n", falling ? "falling" : "rising");
+}
+
+static ssize_t capture_edge_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct pps_tio *tio = dev_get_drvdata(dev);
+ unsigned long flags;
+ bool falling;
+ int ret = 0;
+
+ if (sysfs_streq(buf, "rising"))
+ falling = false;
+ else if (sysfs_streq(buf, "falling"))
+ falling = true;
+ else
+ return -EINVAL;
+ mutex_lock(&tio->mutex);
+ spin_lock_irqsave(&tio->lock, flags);
+ if (tio->removing)
+ ret = -ENODEV;
+ else if (tio->state != TIO_IDLE)
+ ret = -EBUSY;
+ else
+ tio->capture_falling = falling;
+ spin_unlock_irqrestore(&tio->lock, flags);
+ mutex_unlock(&tio->mutex);
+ if (ret)
+ return ret;
+ return count;
+}
+static DEVICE_ATTR_RW(capture_edge);
+
+static struct attribute *pps_tio_attrs[] = {
+ &dev_attr_capture_enable.attr,
+ &dev_attr_capture_edge.attr,
+ NULL,
+};
+
+static const struct attribute_group pps_tio_group = {
+ .attrs = pps_tio_attrs,
+};
+
+static int pps_tio_client_probe(struct auxiliary_device *aux,
+ const struct auxiliary_device_id *id)
+{
+ struct pps_tio *tio = dev_get_platdata(&aux->dev);
+ struct pps_source_info info = {
+ .name = "intel_tio",
+ .mode = PPS_CAPTUREBOTH | PPS_CANWAIT | PPS_TSFMT_TSPEC,
+ .owner = THIS_MODULE,
+ .dev = tio->dev,
+ };
+ struct pps_tio_client *client;
+ int ret;
+
+ client = devm_kzalloc(&aux->dev, sizeof(*client), GFP_KERNEL);
+ if (!client)
+ return -ENOMEM;
+ client->tio = tio;
+ hrtimer_setup(&client->timer, pps_tio_capture_timer, CLOCK_MONOTONIC,
+ HRTIMER_MODE_REL);
+ dev_set_drvdata(&aux->dev, client);
+ client->pps = pps_register_source(&info, info.mode);
+ if (IS_ERR(client->pps))
+ return PTR_ERR(client->pps);
+
+ tio->client = client;
+ ret = device_add_group(tio->dev, &pps_tio_group);
+ if (ret) {
+ tio->client = NULL;
+ pps_unregister_source(client->pps);
+ return ret;
+ }
+ return 0;
+}
+
+static void pps_tio_client_remove(struct auxiliary_device *aux)
+{
+ struct pps_tio_client *client = dev_get_drvdata(&aux->dev);
+ struct pps_tio *tio = client->tio;
+ unsigned long flags;
+
+ device_remove_group(tio->dev, &pps_tio_group);
+ mutex_lock(&tio->mutex);
+ client->removing = true;
+ hrtimer_cancel(&client->timer);
+ spin_lock_irqsave(&tio->lock, flags);
+ if (tio->state == TIO_CAPTURING)
+ pps_tio_disable(tio);
+ spin_unlock_irqrestore(&tio->lock, flags);
+ tio->client = NULL;
+ mutex_unlock(&tio->mutex);
+ pps_unregister_source(client->pps);
+}
+
+static const struct auxiliary_device_id pps_tio_client_ids[] = {
+ { .name = "pps_tio.client" },
+ { }
+};
+MODULE_DEVICE_TABLE(auxiliary, pps_tio_client_ids);
+
+static struct auxiliary_driver pps_tio_client_driver = {
+ .name = "client",
+ .probe = pps_tio_client_probe,
+ .remove = pps_tio_client_remove,
+ .id_table = pps_tio_client_ids,
+};
+module_auxiliary_driver(pps_tio_client_driver);
+
+MODULE_AUTHOR("Christopher Hall <christopher.s.hall@intel.com>");
+MODULE_AUTHOR("Voon Weifeng <weifeng.voon@intel.com>");
+MODULE_DESCRIPTION("Intel Timed I/O PPS client");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("PPS_TIO");
diff --git a/drivers/pps/generators/pps_gen_tio.c b/drivers/pps/generators/pps_gen_tio.c
index 00361a23ddda..659da70a3a84 100644
--- a/drivers/pps/generators/pps_gen_tio.c
+++ b/drivers/pps/generators/pps_gen_tio.c
@@ -120,7 +120,9 @@ static int pps_tio_gen_enable(struct pps_gen_device *pps_gen, bool enable)
hrtimer_cancel(&gen->timer);
spin_lock_irqsave(&tio->lock, flags);
- if (enable && tio->state == TIO_IDLE) {
+ if (enable && tio->state == TIO_CAPTURING) {
+ ret = -EBUSY;
+ } else if (enable && tio->state == TIO_IDLE) {
gen->pps_gen = pps_gen;
gen->prev_count = 0;
pps_tio_configure(tio, TIO_GENERATING);
diff --git a/drivers/pps/pps_tio.c b/drivers/pps/pps_tio.c
index 6b2eda8de0f5..c1ddd57a7005 100644
--- a/drivers/pps/pps_tio.c
+++ b/drivers/pps/pps_tio.c
@@ -35,7 +35,11 @@ void pps_tio_configure(struct pps_tio *tio, enum tio_state state)
pps_tio_disable(tio);
ctrl = readl(tio->base + TIOCTL);
ctrl &= ~(TIOCTL_DIR | TIOCTL_EP);
- ctrl |= TIOCTL_EP_TOGGLE_EDGE;
+ if (state == TIO_GENERATING)
+ ctrl |= TIOCTL_EP_TOGGLE_EDGE;
+ else
+ ctrl |= TIOCTL_DIR | (tio->capture_falling ? TIOCTL_EP_FALLING_EDGE :
+ TIOCTL_EP_RISING_EDGE);
writel(ctrl, tio->base + TIOCTL);
writel(ctrl | TIOCTL_EN, tio->base + TIOCTL);
tio->state = state;
@@ -113,8 +117,15 @@ static int pps_tio_probe(struct platform_device *pdev)
ret = PTR_ERR(tio->generator);
goto free_id;
}
+ tio->capture = pps_tio_add_aux(tio, "client");
+ if (IS_ERR(tio->capture)) {
+ ret = PTR_ERR(tio->capture);
+ goto del_generator;
+ }
return 0;
+del_generator:
+ pps_tio_del_aux(tio->generator);
free_id:
ida_free(&pps_tio_ida, tio->id);
return ret;
@@ -127,6 +138,7 @@ static void pps_tio_remove(struct platform_device *pdev)
mutex_lock(&tio->mutex);
tio->removing = true;
mutex_unlock(&tio->mutex);
+ pps_tio_del_aux(tio->capture);
pps_tio_del_aux(tio->generator);
ida_free(&pps_tio_ida, tio->id);
}
diff --git a/drivers/pps/pps_tio.h b/drivers/pps/pps_tio.h
index c078db8787b0..3a68dd77c9b2 100644
--- a/drivers/pps/pps_tio.h
+++ b/drivers/pps/pps_tio.h
@@ -18,18 +18,25 @@
#define TIOCTL 0x00
#define TIOCOMPV 0x10
+#define TIOTCV 0x20
+#define TIOECCV 0x28
#define TIOEC 0x30
#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)
enum tio_state {
TIO_IDLE,
TIO_GENERATING,
+ TIO_CAPTURING,
};
+struct pps_tio_client;
+
struct pps_tio {
struct device *dev;
void __iomem *base;
@@ -37,7 +44,10 @@ struct pps_tio {
spinlock_t lock;
enum tio_state state;
bool removing;
+ bool capture_falling;
+ struct pps_tio_client *client;
struct auxiliary_device *generator;
+ struct auxiliary_device *capture;
int id;
};
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-02 9:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 3/4] pps: generators: move TIO ownership to auxiliary parent KhaiWenTan
2026-12-02 17:21 ` [PATCH 4/4] pps: clients: add Intel TIO PPS capture KhaiWenTan
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®