Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2761221ybh; Mon, 5 Aug 2019 06:26:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzIETy35VKFS2CrxmnweTSGBW7tgRQubbe7dH2q81BGU6jsHdzdabL7SxiVi2WL/fqAkD1z X-Received: by 2002:a17:902:7283:: with SMTP id d3mr54082579pll.93.1565011571124; Mon, 05 Aug 2019 06:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565011571; cv=none; d=google.com; s=arc-20160816; b=EpOqjglfg3K6oyb6yXIJzI7yaTpl+KGhDBq3GB8pOZA/KKwNrzIw5zjGgmgBybHbdB DpI6iJdCVxeZJdFH7RbQrZ0JsfdZZIDKpuvvLJtdb3mbg3qx2e3pHWEkmu1m6z2QqdwF SMB7lQNqLdWNuTbheZuhd1p5S3how6zQlS17IsnG20dmQVrVX2xg/Vw5+5Kd6qFbSChH z6LkC2M7erQqsl4CzHT7HdFZcLpcyddWil42504tbpoYO70Vl03EnBB2UeJpH60QLXf4 TLwZtvXcehxpvU9fxr/oUzpIPQo0BpniBX+Fh8kUzePW3JOyAyUMzOuHa7NshMQk6Cpc xGYw== 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=27ZW0Q00H6ZRN/i4CUjWXwlKtnICXxhpRTLT8ytLqxI=; b=uld644tu5gBtnjXx9CmJhvyU566WWVwaU4kHgWg8NRb3jHeNS+lfayYVHJ/VoWEiCN DmHYE7S20lc3qDfGK9xR4TkS6SBjHVhZ3e44SfD/KjiuXkZsAAZG2E0vajCPjExX3hTn NNyIljmJTITogwfRvMgUOXRJhgrB4kHQ+wf4SmakldLtXPwzJ1YSkCoreJHj10hof2Rc b2hnXdTmmvAaMtRL5raoUO9x3wcDqPqAceD3TV7IE4ZyboLoqCGwnXB5LcBVE52zbDG7 svRSmo+llAjFCtIjRp9BIeTX1p1qxTO2wf8XJk//HAKIIEmyUwDALzb34a1PWEYxlhZR HtHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WyRmJujD; 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 a5si7355593pgw.454.2019.08.05.06.25.55; Mon, 05 Aug 2019 06:26:11 -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=WyRmJujD; 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 S1730934AbfHENYG (ORCPT + 99 others); Mon, 5 Aug 2019 09:24:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:60792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730591AbfHENYA (ORCPT ); Mon, 5 Aug 2019 09:24:00 -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 763F0216B7; Mon, 5 Aug 2019 13:23:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565011440; bh=wra90LzLRw0kXU4CfV/vSwLk17BbzGfiImryB0Cfj80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WyRmJujDAj67S+Tm7Rvm1yjaiYRxt5dVWJiuAzxsCCEdS9wyDz9sBIFLxEAC6YVJk Rucms8BpxFUlTXRiusSp6pSlJRTdzo5tccVBQZ7qrnHOc6U9pPTffSJf/nfWeCZOKI Tc1xYssauu9NsSCajbMaHxO3iQ2+jj6stNA84wWA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Wu , Bartosz Golaszewski Subject: [PATCH 5.2 089/131] gpiolib: fix incorrect IRQ requesting of an active-low lineevent Date: Mon, 5 Aug 2019 15:02:56 +0200 Message-Id: <20190805124957.928851120@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190805124951.453337465@linuxfoundation.org> References: <20190805124951.453337465@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 @@ -956,9 +956,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; INIT_KFIFO(le->events);