From patchwork Sun Sep 24 14:56:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 114130 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1644178qgf; Sun, 24 Sep 2017 08:00:54 -0700 (PDT) X-Received: by 10.98.26.201 with SMTP id a192mr4754257pfa.311.1506265254862; Sun, 24 Sep 2017 08:00:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506265254; cv=none; d=google.com; s=arc-20160816; b=D+pk6G4AH7DAePiyt09A/ma3+nM2oWx8reVHsf+VntoJrUy6/uEVTgCQGDolmh4Pq9 YPKqV1wv7S5rbaaeW8OznmpdD2vGgnWJydGVWbjR1W1GiDqgX08c1MQ9V3kFmpScFZ0P OLH1JxfxXrBA+ZXWYyRH00jZxmFNN39/OOWTl1aYYL5Y8Iao473OJ9bs3OKBA1tpGzBc ZljU0KZccFiD0S4ngbuTqABaPHk0ZsC/W0at9xwHCnFuyZQPLT4ipiSG+LwGgseWGbGY oH1ZCeL5/B/o3EhyEmn6z6IkDeQ26B0A+HDctwI8heS7XQ29f9bIAz1tLTr6WTMrmZdg wQbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=kGwfhHNs16L499QCaDMtlsmYNdt4BX9na+tY/K9pl9U=; b=HBF4RASlGchpf3SNluEEdQMtPKISsRTe6NK182oUiDVJqjpS0WtmTjV1R2dt536x8o SjFxM8UYJhe+ard+lgmwppC4T/wfQOqV8mP/h0R+2J37+5UhEYmLfV0MrHA9jFY7jl/M S/HjgZ4K0hwZD11WPj+RFfmGhm+V6sriR5ZB2xHwPUK2hRKIP6+pnntYnng4qXow6N5Q pzHG3vgUQbvt2sxkXmaouwOg3DnxP7slGjvH2DlNlEKePvsDIxz2nlOe/Hel9klkR2yV G6FJA0RYtn2elzJmreuBgkVzq5Jh8fTo3lyW/G/BtTSEw/YLTchoiOoYQkNomejr3xoM NRug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VOgpi8gK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s78si2644786pfa.117.2017.09.24.08.00.53; Sun, 24 Sep 2017 08:00:54 -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=@linaro.org header.s=google header.b=VOgpi8gK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752671AbdIXPAw (ORCPT + 26 others); Sun, 24 Sep 2017 11:00:52 -0400 Received: from mail-pg0-f51.google.com ([74.125.83.51]:45314 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752607AbdIXPAu (ORCPT ); Sun, 24 Sep 2017 11:00:50 -0400 Received: by mail-pg0-f51.google.com with SMTP id 188so2733256pgb.2 for ; Sun, 24 Sep 2017 08:00:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kGwfhHNs16L499QCaDMtlsmYNdt4BX9na+tY/K9pl9U=; b=VOgpi8gKmWrVBniz7fZ/OqH0SLtA7j8h5SeF241I5yAg6ntB6oVk7nD/fQxdc5uSUs +JJ9rfdgQoc/z45y/sGGNni9CYc848acAjwVwr8zTm/yzVpQh7edu24VDbOfWK5H3gmo IfVdPu114ABfhCivvSYylK+2RrGrznXZ8LhIY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kGwfhHNs16L499QCaDMtlsmYNdt4BX9na+tY/K9pl9U=; b=mTiFtBFlQ9o+l+HwWepj0rxUzqHW1dN7lnDw4+dHlWw85Ax3Wu/Goqns8EmnIUAorJ Yn5FDyaJwKbjnhE1I5MWL+8jmBYpzjLBInTIEaR0LDqRs2xb+FW7+WxCbNGgclsp7aS+ Kogk537qrCK17kq4/Ph2oDaciwTkFSZwCoxK+brQ7JmYcR3gccnFjjtYthU8WbHyAIkE lgJQA6Kglx4u3KpPE70ZlwGmGmBlDqtz6ChrkcKCEU8NUA+hWfyYIB5wB5sNMmdKTFUA 73BOvABtXTsYbHeesGGrQWokdqkpag7KvXPCbszkwpaVnQUkg/QZDaZ33Y9CICkh8s5U EB8Q== X-Gm-Message-State: AHPjjUhLx1nVrBS2Yi22bPgmTUcCZ6Tohieg6325basVxBR/nuqMiUlV xGpi0Np/PEkr/iJYXMui4KW55g== X-Google-Smtp-Source: AOwi7QAVJ4Th5OmZKuZAIAv7AYKoX/klo4w45fn08GZqa4xKL/r984+6CI9qrLeTfjfayRwrf4SquA== X-Received: by 10.99.51.15 with SMTP id z15mr4837618pgz.287.1506265249948; Sun, 24 Sep 2017 08:00:49 -0700 (PDT) Received: from genomnajs.saswifi.com ([104.153.224.168]) by smtp.gmail.com with ESMTPSA id n83sm7386805pfi.163.2017.09.24.08.00.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 24 Sep 2017 08:00:49 -0700 (PDT) From: Linus Walleij To: MyungJoo Ham , Chanwoo Choi Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, John Stultz , Mike Lockwood , Guenter Roeck , Linus Walleij Subject: [PATCH 5/8] extcon: gpio: Request reasonable interrupts Date: Sun, 24 Sep 2017 16:56:19 +0200 Message-Id: <20170924145622.4031-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170924145622.4031-1-linus.walleij@linaro.org> References: <20170924145622.4031-1-linus.walleij@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The only thing that makes sense is to request a falling edge interrupt if the line is active low and a rising edge interrupt if the line is active high, so just do that and get rid of the assignment from platform data. The GPIO descriptor knows if the line is active high or low. Also make irq a local variable in probe(), it's not used anywhere else. Signed-off-by: Linus Walleij --- drivers/extcon/extcon-gpio.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) -- 2.13.5 diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c index 86f3ec6d6014..6d9cb4ed11c2 100644 --- a/drivers/extcon/extcon-gpio.c +++ b/drivers/extcon/extcon-gpio.c @@ -30,26 +30,22 @@ /** * struct gpio_extcon_data - A simple GPIO-controlled extcon device state container. * @edev: Extcon device. - * @irq: Interrupt line for the external connector. * @work: Work fired by the interrupt. * @debounce_jiffies: Number of jiffies to wait for the GPIO to stabilize, from the debounce * value. * @gpiod: GPIO descriptor for this external connector. * @extcon_id: The unique id of specific external connector. * @debounce: Debounce time for GPIO IRQ in ms. - * @irq_flags: IRQ Flags (e.g., IRQF_TRIGGER_LOW). * @check_on_resume: Boolean describing whether to check the state of gpio * while resuming from sleep. */ struct gpio_extcon_data { struct extcon_dev *edev; - int irq; struct delayed_work work; unsigned long debounce_jiffies; struct gpio_desc *gpiod; unsigned int extcon_id; unsigned long debounce; - unsigned long irq_flags; bool check_on_resume; }; @@ -77,21 +73,34 @@ static int gpio_extcon_probe(struct platform_device *pdev) { struct gpio_extcon_data *data; struct device *dev = &pdev->dev; + unsigned long irq_flags; + int irq; int ret; data = devm_kzalloc(dev, sizeof(struct gpio_extcon_data), GFP_KERNEL); if (!data) return -ENOMEM; - if (!data->irq_flags || data->extcon_id > EXTCON_NONE) + if (data->extcon_id > EXTCON_NONE) return -EINVAL; data->gpiod = devm_gpiod_get(dev, "extcon", GPIOD_IN); if (IS_ERR(data->gpiod)) return PTR_ERR(data->gpiod); - data->irq = gpiod_to_irq(data->gpiod); - if (data->irq <= 0) - return data->irq; + irq = gpiod_to_irq(data->gpiod); + if (irq <= 0) + return irq; + + /* + * It is unlikely that this is an acknowledged interrupt that goes + * away after handling, what we are looking for are falling edges + * if the signal is active low, and rising edges if the signal is + * active high. + */ + if (gpiod_is_active_low(data->gpiod)) + irq_flags = IRQF_TRIGGER_FALLING; + else + irq_flags = IRQF_TRIGGER_RISING; /* Allocate the memory of extcon devie and register extcon device */ data->edev = devm_extcon_dev_allocate(dev, &data->extcon_id); @@ -110,8 +119,8 @@ static int gpio_extcon_probe(struct platform_device *pdev) * Request the interrupt of gpio to detect whether external connector * is attached or detached. */ - ret = devm_request_any_context_irq(dev, data->irq, - gpio_irq_handler, data->irq_flags, + ret = devm_request_any_context_irq(dev, irq, + gpio_irq_handler, irq_flags, pdev->name, data); if (ret < 0) return ret;