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=1796202533; b=Rmd+oz+0GaN+Sft6AIgtx/b4Omg+rH3OVcPk0UdaYVw3ORLLRBIQz8/j+1bbVfUtuMFF hNky/HSxOLuwh1ImGMOPYeovkffwgyyCVUU4JYmte6UDo71cMOKHwegYl3Oavo/cSoBcm iKmhjX4KexVQzVTdtCGZAUvkDB3xRRDZJMDRlYmSu5758XKQKxJC418i+zu8TaM0sAWHY kmXoO+qjkYiUM5Ez7KfZTryuhkglBYHxVmZCXcIuQRVGYbtLOvA+FSMH+OEE+dbbm5saD VRHTGwfEe5dyrShu2tFrqbQ4bLCTtiCGkhm5YCJyjz5xV1LxThStMvfSsG8WEiTJ+BQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796202533; 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=Z7TRgO7xCqDoOBRp5SmSzIh2WP1W4oxU/oSXLK71i5I=; b=2tKoOJoR8yhx+RztQxpzww8p3zYFSJpl8QuiYlPXiuNoW8qeBX+H9TIJMVtvmmaNaHJi lu/WUvSyOiaVbR8E4OjgvqhuhkfSC7oPo46MpTe+livpIiXy8F2BHdib36ZGRKKWgfqz5 cXry7Tiqn5TOrWvQ4XJ5tA/2vtF+kF4DQ4hv+fcAgQK7noFjo9Fn0NB17+6Sv4SZJuKGQ Rkklot6WvRzQxvvbPHMG44rNqia747kOd5gJ5b1b9HJ131Kd0lFbMA7GtAR2F2O18Abex WUE/ebsrqI58hvY10pDtqLt3xb633bhszqzJaSYG1HLke2pI74ygtAIJ7WYiBGQ5S4w== 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=W6o4GMKj; 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 5A5EA606A332; Wed, 2 Dec 2026 09:08:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5A5EA606A332 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=W6o4GMKj DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796202533; x=1827738533; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Z7TRgO7xCqDoOBRp5SmSzIh2WP1W4oxU/oSXLK71i5I=; b=W6o4GMKje6m1+HU6IL8aJsTROopBYOp+Cyz70UJ8R+GK9xmU9Hn+zQk/ 0Lw3RZPfpoa6IXVXBxa6eNcIUtUNxPsHuOaZWsubLakZmpwZKTvIt3ri9 EvXXHPhJyGzmMOBUiebglieOABX7iTTfT32eDbgSNH/1Lla/wPdYoiMZG Ji5Tqw8b3awJ20W6UsjfopNR1b5a5M/6xQ+6f/D5ib9hooLFaWNfsJwNQ 96blv1ksCEdJ5EwNLl7dgvjfPwBQ01Ktetk676bhrSYIL1V32yMaAj7Vn 3YKr1JMfEzOMrkNdyXn5xn4lvF7WwUGqhfOzqNkdm6pHNrAvo62dcmA1M g==; X-CSE-ConnectionGUID: FXsFFSPmQDaasUPGj9JqAQ== X-CSE-MsgGUID: Vwy7yzo1T8G5Hd56wj3gJQ== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5133627" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="5133627" 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:52 -0800 X-CSE-ConnectionGUID: itchf2KHTvCmwjXUA1RXcQ== X-CSE-MsgGUID: bavtKxdARSuwF740hoDftw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="13989199" Received: from faizal-nuc12wski7.png.intel.com ([10.107.255.69]) by fmviesa001.fm.intel.com with ESMTP; 02 Dec 2026 01:08:49 -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 4/4] pps: clients: add Intel TIO PPS capture Date: Thu, 3 Dec 2026 01:21:58 +0800 Message-ID: <20261202172254.1188109-5-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 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 Signed-off-by: Christopher Hall Signed-off-by: Voon Weifeng Signed-off-by: KhaiWenTan --- .../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" +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" +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 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 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 +#include +#include +#include +#include + +#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 "); +MODULE_AUTHOR("Voon Weifeng "); +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