From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.19 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796202529; b=kHzht0A/qzirn/qzL2UgMflemNaTdj8+q/Xm8nBQGQz6gzlnNZS/gtlYpKngTetXYC49 PvWgGjVR6cI1vYBo8iA38eehvFIQcE3vbxJ9B+CZIaBr9rOM9jI3oGknfyUVRXLHn6Oqf w4yjeQ3WoyyI+7nReo161dhZK7VYeukYNN0qqDzXpmyjmmDT/zpP8Dj0BGEvgoNRkjZsm guPG7+26rl9DrUSGZshQzYcGpLC0dbruEs0qwzCICfkpayZYv/ST0+MUVsei8sqjBbqRa vpRd+x1++auCzjrlbnx89qijoORCs6fvmYci2pE7ydi8wfD6XELpgg+4Ziqo4VKewVw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796202529; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=odoYGGto9FB7m5WzrXdwqga29YkkRb/6i0+8TRNfXe8=; b=qY9hJS7y+E0aCBloBOSZro/KexBmDx6gsnLuJCFskpZP3YBlexuBLIqafD7u06joJkwD QO98pIyAOqNTuxdDFgZZKPnZUNJpzOKxX4i2w6ECjlmzN5eEILsAql00pNl8HJBTJBTcx jL+bGaPk0t3jDE9qKbhHOmkD257kS4GOmBqILTmQQhydpTwmKK3tZ/PYyM7EJ3otxI3Ed CsHm5lBZKNZetGuJnfgZ+/SNgiDaY/ajAb/HO3O5I89m9IlT104IXINSMUNSdBSAOgyrz D9L9vLEi1Odi8u2XC99otcTjX3RXhD3lIShhkeqEGodd4+MGSZAqdBuaum17lvvFRyQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b="GzX3WNd/"; arc=none smtp.remote-ip=192.198.163.19 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37A69606A322; Wed, 2 Dec 2026 09:08:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 37A69606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=GzX3WNd/ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796202530; x=1827738530; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=odoYGGto9FB7m5WzrXdwqga29YkkRb/6i0+8TRNfXe8=; b=GzX3WNd/Rip/HYnBJEK4fYYFXXbWL4gAwE9LhX7RI/gSVdsvXSy825b9 NbehJJTodkPd6LVL+fXNNVFUBYKGuZveec3mxpV9BTMXgVKkEOiSzURiK r9q76uA9pqIHJRN1l6T7cfmS3lekZIREXGPK1HHDeMvTGYvcMVQuf9OvF qh+597oiP1RWmy8kOl6NiJILGZRjtwOJLurXFDwU7KZIq4HlVe22Oc6u1 Sq91rxizin6iwj6clic8KdeUt0Z0Oz4QYvEyNTw8mOcc9cca72FPK7F52 ni7vqF8y8aEBjxUWKmp+I6ouQAfSbWJDjftNwr+I7k2tvpp87qFch/6Yc A==; X-CSE-ConnectionGUID: yJQVtax1SJCFoF8F5HS8jg== X-CSE-MsgGUID: QTQ4e2/7T3Oy0fp57yLkNA== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5133617" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="5133617" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 01:08:49 -0800 X-CSE-ConnectionGUID: qZZ8dC2UR1WtC7YK/6ixHw== X-CSE-MsgGUID: lCoTLemBR/iCU4NXftMrAw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="13989193" Received: from faizal-nuc12wski7.png.intel.com ([10.107.255.69]) by fmviesa001.fm.intel.com with ESMTP; 02 Dec 2026 01:08:46 -0800 From: KhaiWenTan To: Rodolfo Giometti , Greg Kroah-Hartman , Jonathan Corbet Cc: Thomas Gleixner , Andy Shevchenko , 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 Message-ID: <20261202172254.1188109-4-khai.wen.tan@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261202172254.1188109-1-khai.wen.tan@linux.intel.com> References: <20261202172254.1188109-1-khai.wen.tan@linux.intel.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Voon Weifeng 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 Signed-off-by: KhaiWenTan --- 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 -#include -#include +#include #include #include #include -#include #include -#include -#include #include #include #include -#include - -#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 "); MODULE_AUTHOR("Lakshmi Sowjanya D "); @@ -282,3 +209,4 @@ MODULE_AUTHOR("Thejesh Reddy T R "); MODULE_AUTHOR("Subramanian Mohan "); 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 +#include +#include +#include +#include + +#include + +#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 "); +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 +#include +#include +#include +#include +#include +#include + +#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