Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6613890ybi; Mon, 8 Jul 2019 05:58:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3GcXzbFJlZf+7sXdh4CguyikIXMN4wFAboPjvHpjTamytGAn6pFRquN26Z0DxY0iIxXpW X-Received: by 2002:a65:530b:: with SMTP id m11mr18839377pgq.236.1562590688102; Mon, 08 Jul 2019 05:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562590688; cv=none; d=google.com; s=arc-20160816; b=smgSnhuREKJhp0iyBqcakRqWFV7GmqvowbpxlVJQ6tiiI4y+P+4hrWp7jIrA4WfSTT ekdGjI6x/l0nrwzAIUTYHf+8mlH71K1Xh2sKT5/dYAK8lfulisDOHWKAru2Cs+D/Dfwp s5NKpjo6IDOG4+kGQaDPbAa/Wq8HW7oYM8vwjy/YM7EHuuRsHRH6ANXz0vg79MT6qdbo jqkIJcKJ/RQNQoKtB++f+ZaBMbZ191PHyVfPch2XMCK0U6ywprZcnN/nFwmFikULEDPJ /z+YXBux1uimCWXmgwaKfgyEAPjVW15iUYyLUbrNtZojGfQ7r+Na97xhZ9Fr6KWJINzP H+6Q== 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=efd+BnPGvehL2A2UX02caz/Y1NvKnWaen2fuHX7MRzE=; b=YIm/TUBatWMfrDI0VivEfwOaI5+qsJWGxJFgnYxJw2uyF/s6teAe/LRQ8BbT3WizDp xy6VEYUkiMF3XDn7n3YY4nxbN9ol1duocmdb6Ay0TNFXJQ7I0PeP1VBaHaLAUz+IGLFd eLt/5QT92DOrLkVHEP/6TAKf24PRUWbNQ7leiMDOqkjDksJ2skMKoeOKebcIRDgMCcB3 uQUXPqkVjL27NnxSSPaXEGz4LO73zkYxCKUo/0m3e15RPklofHCp6WzytmkdOCIxXdPm HhPs8fIyTYIq59SrtIUtIy2hjJD3uzkiLFiflw+3JQbNRumGmbHpEwW6vra0eCtkZbkG Ylng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b="SBKlIJU/"; 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 q187si20234951pfb.51.2019.07.08.05.57.48; Mon, 08 Jul 2019 05:58:08 -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="SBKlIJU/"; 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 S1729134AbfGHIyp (ORCPT + 99 others); Mon, 8 Jul 2019 04:54:45 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:46537 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727636AbfGHIyp (ORCPT ); Mon, 8 Jul 2019 04:54:45 -0400 Received: by mail-ot1-f66.google.com with SMTP id z23so15376708ote.13 for ; Mon, 08 Jul 2019 01:54: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=efd+BnPGvehL2A2UX02caz/Y1NvKnWaen2fuHX7MRzE=; b=SBKlIJU/kRPxduwNsmhn4tfli4XHsNgkuvfs0vrliM2bO588TzaFFyJH5mpAvTSpyE vMNX4Bd77Rl3/PaXl+2+z4JVB7NPoSm4GhlWUjVRlavKIQpL2Cxrd/FBWWa1j55aw4da /QaiPrUGXrShadGQrBe86H0v+jTxpYgYb6ccgPiEacmVlt5b1e8v9q9rKiRW0dUtPMwT 0+XtYxiegFoER2tF+EwxhAwN0zyalL9YZrWD3dxmWJEgF864gq1gMwcHWrRSXfR1rdDs GAgOGW8Zf5t8AedaZCgZCJOOkkpuaUfNlSBafi8WRxtyWJjnJiKk2YQymWEe/jUuSyjM 3EVw== 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=efd+BnPGvehL2A2UX02caz/Y1NvKnWaen2fuHX7MRzE=; b=Gi7crQYUdPhJOiWDlzbKm4amliMYrU4nU2sxw+nGw+5Xkf/ugXL3dd+JoA1/xBSRiL O5wBNwHnaDr3Rt/htOUI61B8gK6VVFvbEYJ/N34+HI+keU3Inw6V9iCkQ9YzPOknwZA2 Rg/uPt7GlPR8/y3vvUXGaaD3vQCtEyRjdd9WNikmKI+IO+qr29068Y7CUuJR1BBeaQo8 4GTXEOLfjXtR/xy9dslZxlsHbpd7SKHN0EDA0bTPPDVOl6ogNKRU4Dgxzw+hOujB8ctI flgw9aW6WVwCuS8rOtPw+Mm2WGg2e2C07WiGWXYMBQi+kFjR0+F4h5lksJYOGImSlkYa t+bw== X-Gm-Message-State: APjAAAWnaECIZjzx+YPHqoJHzl9+5sDdvKLMcrhxTljFMnrh47mXiOhb QTxYswdXgP/n0hvl3FnZcMGWHZVuO0Wf7D1Zt0Rtkg== X-Received: by 2002:a05:6830:1681:: with SMTP id k1mr13388848otr.256.1562576084924; Mon, 08 Jul 2019 01:54:44 -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, 8 Jul 2019 10:54: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 > Tested-by: Bartosz Golaszewski Reviewed-by: Bartosz Golaszewski