Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2752406ybh; Mon, 5 Aug 2019 06:17:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqzigiPu8JWoF9CuZfsUP6Y6t7NakJ3HBkmKI3Isc6okD2ey/DZAxgot4U3g/BEfXwJsYwqd X-Received: by 2002:a63:550e:: with SMTP id j14mr28325240pgb.302.1565011075055; Mon, 05 Aug 2019 06:17:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565011075; cv=none; d=google.com; s=arc-20160816; b=iYZYY9ZB4wX4OsDGS69UTF3Sjd5exbXqq1sT8rIgbRTSZ0koT4pvM/lG+rvGZ63uvm ghpfn3Uee/oHrMoKnLQex4wsFqP06sUZtQw1Q5mG+5Dunly6b4aIArD5BXxaxYC19ZP1 ff9nTT6+wmO5D2KhXnPaTd3AmCm2eKn89LxujP1imcs98yBbWqBLQDBHb0N5CwCzXx2u +Y28jdRVXyECcZ6C8CBRBomiMnVlElhNZ+OtxJxjO2ePH9jdqUkJDNo8+81lpKct0XkC WlU/BwDnQVaDJIffS8x6htUJogdDI43CwLuMAPH0Z9cGOrH2Ck32fOv0UMeuQKrCwdIb g+rA== 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=vD6V1ZawYdYRTV/G/bECUN1/Iia+CVqkqOUkbcZjLOw=; b=CM4MM+pI9nA0Mclu+3EkWpXdZpCS1s6SwiY/BDWXnpqybbCIQFgndjRfgdGkYntO0b p0I3KD5zCq7zXb/0ahYxMb2reE/qusYKvkUijzsxkP3/DfsVSThXTKgl/99GYZnV9iPK 0ZkdaQ0sv9UDuhBo7SlLooiAM5tpWxckcDHPDSMkAc3Ssqs1K0ZEHo/BnVTUfRFlWkUa Dqb22vVaxTUNQhXZ0pnPm8TgQmRM0MkVYAEVsuNTpF/6Ibsq+F96wbq0ZNqIBd6RvpB3 nzw7NEdR4AakrjUAHcyGy+7qrHE0JOmdViL4KVUik8A9s60czT9XnKQK9waL/a2VUFmf 2teg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=s2Q6a7lX; 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 69si43839676pge.101.2019.08.05.06.17.39; Mon, 05 Aug 2019 06:17:55 -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=s2Q6a7lX; 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 S1729888AbfHENRH (ORCPT + 99 others); Mon, 5 Aug 2019 09:17:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:41838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729375AbfHENFl (ORCPT ); Mon, 5 Aug 2019 09:05:41 -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 6ECE12087B; Mon, 5 Aug 2019 13:05:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565010340; bh=9GKALGfakBMmmFRWnJvklXWYZ/z02A+qOIf/kJJ53Cs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s2Q6a7lXjG+HOEBBniboTqtSPuIYzEC9z5NlqBQLZZ6/HrT9zr0AVC2lxKQ3lgqzM XVfY703QhI0Q7S5tzv+9vbRZeK8Ks0y0UbGAGOB1NT86lCqNmlm5vHLI8Z6Ko0HkRN pmfWo56rUiSorMPa60e3XmyR1EXoRHQ6z7mjdAt8= 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.9 29/42] gpiolib: fix incorrect IRQ requesting of an active-low lineevent Date: Mon, 5 Aug 2019 15:02:55 +0200 Message-Id: <20190805124928.441011112@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190805124924.788666484@linuxfoundation.org> References: <20190805124924.788666484@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 @@ -817,9 +817,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;