Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2746599ybh; Mon, 5 Aug 2019 06:13:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxk29jmKz1XOY14FovyjiyvE3HPknQVtVBjGGdSoyC9DiqyVmggEC8GyByz7wvz1h659/n6 X-Received: by 2002:a62:f202:: with SMTP id m2mr75309165pfh.6.1565010790292; Mon, 05 Aug 2019 06:13:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565010790; cv=none; d=google.com; s=arc-20160816; b=o7bVy1V6oVP5ECGMLVGfWCiyKzKyc+Bi/N2sHr0kOiS2jeIs3+eLNtVjEAfnGTVwsc 0JXDOM25Z+iSoC+bEb17faW/t6Hd9b56pK6KSl5jqwGcWyF8/EzRIG65KR0luaAPH5ep XbaXS2m8UZEez3lx3/OTq4oVDPAfvipl14HGgvGLNdiWPdKSp6OZwRQaILJpy3TsvN4R SkQgv73uSfLhF/fe4DPgjiHuj5rapYhNrBSqwFRPhYCC26X586sBu+eguDlrYG3Rr0GB nKEShSkKk1B4qQgE5zqAvPf8s6DaMIKYZyXN5qTbAuZIYJAn+qw48Hn3BneDaOIquIdc mIuw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=as+SBxULZy15A6tDIW3fE80KrTZBYEKINe53klU4ar8=; b=i8DkSiOMkcoaqDlCwqdjPEY0lUCtLhgULz++hfPkY1aLWYlHIDHrXzGC83R8U/mOLW D4hsZ8NJFzu2+w9zTbhGPWY3N3Q9J7Z6ff2xkM2J8Sal9eA1HaLrtXVim02G6/ZPMoWj cIRHBAfbSglMtwVuowGp26XJN+h6sd4FD/z5YBxI717Laed2CxEuZ2/mBVgKg9cgtodg J+BqXqKG3ugMXHfKGEsrdC+pWJsUO9I0NzSeJtTZf+jg1ITMB8oEZ4U6+Cy7A50CEaeP w/yCpF8d4ItGAsmSDPFawJmd/2ZGjOxWTrGyWYhldiXu2QIrxWQpftEXZG6IStZAFzQO wBQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lZXVP2X4; 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 q16si44340036pgv.140.2019.08.05.06.12.54; Mon, 05 Aug 2019 06:13:10 -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=@kernel.org header.s=default header.b=lZXVP2X4; 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 S1730400AbfHENKr (ORCPT + 99 others); Mon, 5 Aug 2019 09:10:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:49808 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730384AbfHENKp (ORCPT ); Mon, 5 Aug 2019 09:10:45 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2369C2067D; Mon, 5 Aug 2019 13:10:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565010644; bh=Y9/KfZJ7BzQ/FNh0VbSKOYU/vLdjc7rLMhft54SUgeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZXVP2X41znGQg4rl9shZavVUSXPF061A3cxDM1VpkTKis95s4pF3Af38R4xkKvMz KVHuJ/b5aeRvAEUly/bpByW4MAKsI1l6y9pQAxX1vsGTqUEN0J/qfllsMKsWxFU9lk KTllO7TSMamFncVzR/qB9/iUybJhnDx92/Soiy54= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Wu , Bartosz Golaszewski Subject: [PATCH 4.19 48/74] gpiolib: fix incorrect IRQ requesting of an active-low lineevent Date: Mon, 5 Aug 2019 15:03:01 +0200 Message-Id: <20190805124939.780763795@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190805124935.819068648@linuxfoundation.org> References: <20190805124935.819068648@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Wu commit 223ecaf140b1dd1c1d2a1a1d96281efc5c906984 upstream. When a pin is active-low, logical trigger edge should be inverted to match the same interrupt opportunity. For example, a button pushed triggers falling edge in ACTIVE_HIGH case; in ACTIVE_LOW case, the button pushed triggers rising edge. For user space the 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, and drives level to be high when it is released. In user space we can do: req.handleflags = GPIOHANDLE_REQUEST_INPUT; req.eventflags = GPIOEVENT_REQUEST_FALLING_EDGE; while (1) { read(fd, &dat, sizeof(dat)); if (dat.id == 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 when released. For this inversion we add flag GPIOHANDLE_REQUEST_ACTIVE_LOW: req.handleflags = GPIOHANDLE_REQUEST_INPUT | GPIOHANDLE_REQUEST_ACTIVE_LOW; req.eventflags = 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 Tested-by: Bartosz Golaszewski Signed-off-by: Bartosz Golaszewski Signed-off-by: Greg Kroah-Hartman --- drivers/gpio/gpiolib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -946,9 +946,11 @@ static int lineevent_create(struct gpio_ } if (eflags & GPIOEVENT_REQUEST_RISING_EDGE) - irqflags |= IRQF_TRIGGER_RISING; + irqflags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? + IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; if (eflags & GPIOEVENT_REQUEST_FALLING_EDGE) - irqflags |= IRQF_TRIGGER_FALLING; + irqflags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? + IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING; irqflags |= IRQF_ONESHOT; irqflags |= IRQF_SHARED;