mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tim Harvey <tharvey@gateworks.com>
To: linuxpps@ml.enneenne.com, Rodolfo Giometti <giometti@enneenne.com>
Cc: linux-kernel@vger.kernel.org,
	Koen Vandeputte <koen.vandeputte@ncentric.com>
Subject: [PATCH] pps-gpio: use IRQ edge config when not capturing both edges
Date: Fri,  8 Sep 2017 12:53:34 -0700	[thread overview]
Message-ID: <1504900414-1514-1-git-send-email-tharvey@gateworks.com> (raw)

PPS signals with very short pulse-widths can be missed if their state
changes by the time the interrupt handler reads the GPIO pin state.

To avoid this in the case where we are only looking for one edge we can
use the edge configuration for the pin state but fall back to reading the
pin if both edges are being watched.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
 drivers/pps/clients/pps-gpio.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
index 333ad7d..0d2b807 100644
--- a/drivers/pps/clients/pps-gpio.c
+++ b/drivers/pps/clients/pps-gpio.c
@@ -61,7 +61,16 @@ static irqreturn_t pps_gpio_irq_handler(int irq, void *data)
 
 	info = data;
 
-	rising_edge = gpio_get_value(info->gpio_pin);
+	/*
+	 * if not capturing both assert/clear events use the IRQ state
+	 * otherwise read the gpio state from the pin (which could miss
+	 * assertions on very small pulse-widths due to interrupt latency
+	 * and CPU performance).
+	 */
+	if (!info->capture_clear)
+		rising_edge = !info->assert_falling_edge;
+	else
+		rising_edge = gpio_get_value(info->gpio_pin);
 	if ((rising_edge && !info->assert_falling_edge) ||
 			(!rising_edge && info->assert_falling_edge))
 		pps_event(info->pps, &ts, PPS_CAPTUREASSERT, NULL);
-- 
2.7.4

             reply	other threads:[~2017-09-08 19:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-08 19:53 Tim Harvey [this message]
2017-09-10 10:43 ` Rodolfo Giometti
2017-09-12 15:54   ` Tim Harvey
2017-09-12 16:22     ` Rodolfo Giometti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1504900414-1514-1-git-send-email-tharvey@gateworks.com \
    --to=tharvey@gateworks.com \
    --cc=giometti@enneenne.com \
    --cc=koen.vandeputte@ncentric.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxpps@ml.enneenne.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®