Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp304018ybl; Thu, 30 Jan 2020 22:42:07 -0800 (PST) X-Google-Smtp-Source: APXvYqzSowzibeSzq3HwUbL7q7GHZsLxpZlOb1NuFlI5OKpAAOQQATyRiTOWr9TmGj5wJf6ztojL X-Received: by 2002:aca:1a05:: with SMTP id a5mr5544933oia.97.1580452927632; Thu, 30 Jan 2020 22:42:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580452927; cv=none; d=google.com; s=arc-20160816; b=cgeoAxJtxAOt/zxeiXZ5DWVHr7hIeiJIJiqJc4YgFnTcUDi8xhB3vbZT6Gugc/QunF Edir4UfvcViSnitdgx6+BnouY2J4eJ8DNQF0C7uEvTZL1I+oOxjFkD4PpTwckgqEUvaB wnBJmHOZ0uyq48zXKwhiUXdWUpVsmkSTNTXOZnZvny+FBYk959Njrmt5hfpQioKox0o2 PNmC6rNCfr7ss1PQOtpRcQX97WTBGNDlqjDKdAieYs9DV1b09qcS8HttaeUE0oI4Xv3L VGGbtZsB4E2WGbcUyV+/O1OwTgXjrKgFG0uJyl4l1N8/FvKQzrYjO9U+B/n+pXG0jFfq V3QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=uADdPAhorC7tfDp1+Je1/kwDIpEV6CdGiwCRcillu9U=; b=YyWdR5mS46joLgB4Y+HityYpUfqRWOWm9ScmlZviChV0IGMmxP42DHWg9puDAtUz33 +5aIGHReJHv6IW4NwQroiYt8yluoSnxCcSXHJMPZmaH2GSF6Oe4TvlzHSNk+y0eAAO3W yRcZRztdL5mjk4dz9426i6nJAbSJzqHHoQk17+uFnnkR+aEVs0WWIliP4eNbsA0oplTC K9Jggj3F/qzdPYEGIMF4qenhUMYh8fHN7f1YOkRH6o3vMFUlWgbZqRG0QdEV96YBOhwm xm6KGclI48uT2le+U8LjtuC2CIMqRQ0dfnSoZDql+fZpRu6MsF8N+1BW4Sq9J2XLn2Je 6AnA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l10si2255241oth.243.2020.01.30.22.41.56; Thu, 30 Jan 2020 22:42:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728145AbgAaGky (ORCPT + 99 others); Fri, 31 Jan 2020 01:40:54 -0500 Received: from mga02.intel.com ([134.134.136.20]:64027 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728109AbgAaGkt (ORCPT ); Fri, 31 Jan 2020 01:40:49 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Jan 2020 22:40:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,384,1574150400"; d="scan'208";a="309925513" Received: from wtczc53028gn.jf.intel.com (HELO localhost.localdomain) ([10.54.87.17]) by orsmga001.jf.intel.com with ESMTP; 30 Jan 2020 22:40:49 -0800 From: christopher.s.hall@intel.com To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, hpa@zytor.com, mingo@redhat.com, x86@kernel.org, jacob.e.keller@intel.com, richardcochran@gmail.com, davem@davemloft.net, sean.v.kelley@intel.com Cc: Christopher Hall Subject: [Intel PMC TGPIO Driver 3/5] drivers/ptp: Add user-space input polling interface Date: Wed, 11 Dec 2019 13:48:50 -0800 Message-Id: <20191211214852.26317-4-christopher.s.hall@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191211214852.26317-1-christopher.s.hall@intel.com> References: <20191211214852.26317-1-christopher.s.hall@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christopher Hall The Intel PMC Time-Aware GPIO controller doesn't implement interrupts to notify software that an input event has occurred. To solve this problem, implement a user-space polling interface allowing the application to check for input events. The API returns an event count and time. This interface (EVENT_COUNT_TSTAMP2) is *reused* from the output frequency adjustment API. The event count delta indicates that one or more events have occurred and how many events may have been missed. For periodic input use cases, polling is fairly efficient. Using PPS input, as an example, polling 3x per second is more than sufficient to capture rising and falling edge timestamps. Generalizing, the poll period should be: poll_period = (nominal_input_period / (1 + freq_offset)) / 2 Where freq_offset = - 1; A flag that indicates a pin isn't capable of generating interrupts is added. Software should not expect notification through the read() interface on pins marked as such. If all pins are marked as poll only, the read interface is marked 'defunct' and immediately returns an error because no interrupt would ever occur to exit the wait state. Signed-off-by: Christopher Hall --- drivers/ptp/ptp_clock.c | 13 +++++++++++++ include/uapi/linux/ptp_clock.h | 1 + 2 files changed, 14 insertions(+) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index b84f16bbd6f2..518dc911ec40 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -190,6 +190,17 @@ static void ptp_aux_kworker(struct kthread_work *work) kthread_queue_delayed_work(ptp->kworker, &ptp->aux_work, delay); } +static bool check_for_readability(struct ptp_pin_desc *pin_desc, size_t size) +{ + int i; + unsigned int flags = PTP_PINDESC_INPUTPOLL; + + for (i = 0; i < size && flags != 0; ++i) + flags &= pin_desc[i].flags; + + return flags == 0; +} + /* public interface */ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, @@ -213,6 +224,8 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, goto no_slot; } + ptp->defunct = !check_for_readability(info->pin_config, info->n_pins); + ptp->clock.ops = ptp_clock_ops; ptp->info = info; ptp->devid = MKDEV(major, index); diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h index ecb4c4e49205..d5bd6504480c 100644 --- a/include/uapi/linux/ptp_clock.h +++ b/include/uapi/linux/ptp_clock.h @@ -38,6 +38,7 @@ * Bits of the ptp_pin_desc.flags field: */ #define PTP_PINDESC_EVTCNTVALID (1<<0) +#define PTP_PINDESC_INPUTPOLL (1<<1) /* * flag fields valid for the new PTP_EXTTS_REQUEST2 ioctl. -- 2.21.0