Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7256253ybi; Mon, 22 Jul 2019 09:46:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqwaKJlU34rvHdVmW7CdXetvbZfTsf1TjA/NmwXwPmYR5bmuN7l5LLgdzWf1fRUL6SNA3kTZ X-Received: by 2002:a63:188:: with SMTP id 130mr71324552pgb.231.1563813988199; Mon, 22 Jul 2019 09:46:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563813988; cv=none; d=google.com; s=arc-20160816; b=GrDpodTQgPYIk3u9Lt5pXRsRFAs6BMorQbWkJKvzy4Zgt3/6P0XOexhtZ1o6VhduQV psJJcdcbIqm2zHpLnHwFp1QRLrFJHH/GIqCcK1SX9WYy3hDCOA1i6JEUygOlGjp8i/sS GKgxGW+xBqDKvntzLSzp7i3v0To1EXg/9XDF2PZNjY8qgx+nhqn9hB680DCbUDEjag/4 oOhjaYX/PjlKHzXDMGeD5kpCholXdLvElUGYFPaeCjkxVBkrPxEwepf/DiijWzUry/GV AjOqUo6pYbKZxkfAn2JxeMrh3wU3UYgA8KzChfe2ezj6wGfww64pC02d4dBHfM4/6X8u R3Lw== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=g1UMNJz38FJKA8VfoTulETIw691BfDACZOimxcCXK/o=; b=O5fQEHvikmiR272TyfciFPLUpYTCvHO6YeEC/5ajjRNzzpBYzzFtc4Oce70dftRe4y isLc4ri6p6VsrejIlt8z5jgvf1KsKPhTVweQtblySp1ZOzIbN8LfDXaZWzOKRnyHMK8a G//xmkrtj6+PuvIt1FIoZJal2MXFHPi2Iz1PBRUO0KWjb/7b18g8NiAdoMiHdmLkdnOV 3uQYK4FHctf2ULIPo9Ly2qBlQjub+fgovNiV545jU1WzuhLFHUqvswOE6oVmhvt2JeZQ pX9AzCPO1VtNetUoRD82g+yUdB9lLt9zhm4gedi4iDJrCbsSzdvJT9gWYVUUkKojT7uX M2TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=fGNAYXME; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 73si15215669pgg.72.2019.07.22.09.46.11; Mon, 22 Jul 2019 09:46:28 -0700 (PDT) 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; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=fGNAYXME; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730660AbfGVNxq (ORCPT + 99 others); Mon, 22 Jul 2019 09:53:46 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:46307 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729750AbfGVNxq (ORCPT ); Mon, 22 Jul 2019 09:53:46 -0400 Received: by mail-oi1-f193.google.com with SMTP id 65so29589436oid.13 for ; Mon, 22 Jul 2019 06:53:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=g1UMNJz38FJKA8VfoTulETIw691BfDACZOimxcCXK/o=; b=fGNAYXMEMQLi61dS/BX669E7XdeJVBqAP/po6W0f/plWm3Ag7TmVrwhbmZteGpcd42 D08dufbOML0rLUeOodYQgaMv6jyBh3tRkFtbIrhsgt0Pje6GSJvRC6YIRDUmhOrSwonZ hlBbBHEI9nH4H80aLinD09Y8JniQTngsNyPoRegNf1LVnXJlUHGlTn0o03A7pO40X4vo TCR7+RH68UxHyyUDH0unVSP8nfWKTOneUMziMoYbIx9Yc2p89+n/4H7ehB1TOCq3BkS6 oM04WZJRb4UlHU+AIKfU0Fb76AB7ykQjASxlCvXNRYN5lJH790D8mZV1SO+IgWOEsk7P eV4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=g1UMNJz38FJKA8VfoTulETIw691BfDACZOimxcCXK/o=; b=BidUNyGWBKI9wCV2HkKnteoMVxKDmrf8rFvc7O9IwLGI4shjE8PTv7RRhEh6EqVZKJ goZ6uFE40WZ8D79ZHBrOql/PqQu96VKl1MG1eqlBpj5qrof/1jxpRDFO5/pOK5xtjImR 3dul6pa/pmyvHvFi9tl6mhsXj6WFAoOjX0wHu64M78grmRK7N32+wZYuOqS6Ot1xY17m nBVsxW2csFjD3JVl4CPwqqNjPpB7MLRkVk+SIQtXFxBZYr0snYE3QmfJWIaVaTpJ8R7q +5xwZnZ9ZVRSOXLbGIr8mZhNDCQz7opQC3vvl5NL7FfoaVpvJ9Ak6LlAKDNpLwrsh/in RQOA== X-Gm-Message-State: APjAAAXsGjaljGJfsu18eV5Y/9h/jzVX20KIPhpg3hShac/ziLZOuL1y re9KTVhHcyrgT9f7oOwftmIF1yvf7GjXoSGrk9cBEg== X-Received: by 2002:aca:450:: with SMTP id 77mr35802547oie.114.1563803625135; Mon, 22 Jul 2019 06:53:45 -0700 (PDT) MIME-Version: 1.0 References: <20190708052308.27802-1-michael.wu@vatics.com> In-Reply-To: <20190708052308.27802-1-michael.wu@vatics.com> From: Bartosz Golaszewski Date: Mon, 22 Jul 2019 15:53:34 +0200 Message-ID: Subject: Re: [PATCH v2] gpiolib: fix incorrect IRQ requesting of an active-low lineevent To: Michael Wu Cc: Linus Walleij , linux-gpio , LKML , morgan.chang@vatics.com, "Stable # 4 . 20+" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org pon., 8 lip 2019 o 07:23 Michael Wu napisa=C5=82(a)= : > > When a pin is active-low, logical trigger edge should be inverted to matc= h > the same interrupt opportunity. > > For example, a button pushed triggers falling edge in ACTIVE_HIGH case; i= n > ACTIVE_LOW case, the button pushed triggers rising edge. For user space t= he > IRQ requesting doesn't need to do any modification except to configuring > GPIOHANDLE_REQUEST_ACTIVE_LOW. > > For example, we want to catch the event when the button is pushed. The > button on the original board drives level to be low when it is pushed, an= d > drives level to be high when it is released. > > In user space we can do: > > req.handleflags =3D GPIOHANDLE_REQUEST_INPUT; > req.eventflags =3D GPIOEVENT_REQUEST_FALLING_EDGE; > > while (1) { > read(fd, &dat, sizeof(dat)); > if (dat.id =3D=3D GPIOEVENT_EVENT_FALLING_EDGE) > printf("button pushed\n"); > } > > Run the same logic on another board which the polarity of the button is > inverted; it drives level to be high when pushed, and level to be low whe= n > released. For this inversion we add flag GPIOHANDLE_REQUEST_ACTIVE_LOW: > > req.handleflags =3D GPIOHANDLE_REQUEST_INPUT | > GPIOHANDLE_REQUEST_ACTIVE_LOW; > req.eventflags =3D GPIOEVENT_REQUEST_FALLING_EDGE; > > At the result, there are no any events caught when the button is pushed. > By the way, button releasing will emit a "falling" event. The timing of > "falling" catching is not expected. > > Cc: stable@vger.kernel.org > Signed-off-by: Michael Wu > --- > Changes from v1: > - Correct undeclared 'IRQ_TRIGGER_RISING' > - Add an example to descibe the issue > --- > drivers/gpio/gpiolib.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > index e013d417a936..9c9597f929d7 100644 > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -956,9 +956,11 @@ static int lineevent_create(struct gpio_device *gdev= , void __user *ip) > } > > if (eflags & GPIOEVENT_REQUEST_RISING_EDGE) > - irqflags |=3D IRQF_TRIGGER_RISING; > + irqflags |=3D test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? > + IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; > if (eflags & GPIOEVENT_REQUEST_FALLING_EDGE) > - irqflags |=3D IRQF_TRIGGER_FALLING; > + irqflags |=3D test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? > + IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING; > irqflags |=3D IRQF_ONESHOT; > > INIT_KFIFO(le->events); > -- > 2.17.1 > Applied to fixes. Bart