Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757042AbdIHTud (ORCPT ); Fri, 8 Sep 2017 15:50:33 -0400 Received: from mail-pg0-f51.google.com ([74.125.83.51]:34118 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757010AbdIHTub (ORCPT ); Fri, 8 Sep 2017 15:50:31 -0400 X-Google-Smtp-Source: ADKCNb5V7JiA0LdP24ULlMhMdUiOLh+8OaVC2bw+1Jm6PTw2u5BaF1PmzRHn4koGAdyRb7UAXnKc3Q== From: Tim Harvey To: linuxpps@ml.enneenne.com, Rodolfo Giometti Cc: linux-kernel@vger.kernel.org, Koen Vandeputte Subject: [PATCH] pps-gpio: use IRQ edge config when not capturing both edges Date: Fri, 8 Sep 2017 12:53:34 -0700 Message-Id: <1504900414-1514-1-git-send-email-tharvey@gateworks.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1337 Lines: 36 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 --- 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