From patchwork Wed Jun 22 21:25:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 70697 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp112321qgy; Wed, 22 Jun 2016 14:26:08 -0700 (PDT) X-Received: by 10.98.201.210 with SMTP id l79mr9245501pfk.87.1466630768380; Wed, 22 Jun 2016 14:26:08 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wi2si2032839pab.52.2016.06.22.14.26.08; Wed, 22 Jun 2016 14:26:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752675AbcFVV0H (ORCPT + 4 others); Wed, 22 Jun 2016 17:26:07 -0400 Received: from mail-lf0-f53.google.com ([209.85.215.53]:33792 "EHLO mail-lf0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752636AbcFVV0F (ORCPT ); Wed, 22 Jun 2016 17:26:05 -0400 Received: by mail-lf0-f53.google.com with SMTP id h129so83121360lfh.1 for ; Wed, 22 Jun 2016 14:26:05 -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:mime-version :content-transfer-encoding; bh=cMiwryv5T0TUwOG6iutSgRDOv5YbiVATPDgLrw+8cBo=; b=PCM5gJxozH5MTcnQCW5YnQwjkF8bvz7sieGrFvjrq+zS7JXnu62Qs07HOn1OrAbLL6 KfLL4RRTy03FjzG5mLIuY68CrWuuDj7rlUGcgLjm8NQrKlx06RZ8NN7vfeZe/jBajPU5 ZJgilWChFaOxl6X8nakQjA1JxNQvCgmbOKVr0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cMiwryv5T0TUwOG6iutSgRDOv5YbiVATPDgLrw+8cBo=; b=X6YkaQo8zujSQmMn5mRTrgH4zrd6KC08MWm5SmQzxuWJIpt1TJusDMgAh+tGy2Wa6I ea1HKEV9gBb1TVpEMevGMsckdYj4CySMcPkHeRPchE4IE1+5aJbZ6biD+NSo4J60Bqcj ylQWzrO3l1bL1Wd9+wSpdYUmkciFYDEEsxFaFUphp3ZYjcWmLnosy3WrkQHNnzD01vEs vsbL1KRgBY7aIcv3UkH4CLXeSWnqwykWnqamVAcTxpkYk81FzxUB7q2yydsX2Do97/8f W45HsZJs2i68VzHRYE/XTmx9mfPBJF6A/N7AxdAS5kyF6fx7j2wd1BB5PixgESLxv2ux 1NYg== X-Gm-Message-State: ALyK8tIJowXXCSWUwRuhJg/WEKuZlpguUEOAWr7G0siFZIUNd4aznScl0kqnDFbVZhNpEdbd X-Received: by 10.25.162.135 with SMTP id l129mr11398089lfe.175.1466630763246; Wed, 22 Jun 2016 14:26:03 -0700 (PDT) Received: from localhost.localdomain.localdomain (c-cc7c71d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.124.204]) by smtp.gmail.com with ESMTPSA id 42sm211163lfw.42.2016.06.22.14.26.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Jun 2016 14:26:02 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot Cc: Linus Walleij , =?UTF-8?q?Bj=C3=B6rn=20Andersson?= Subject: [PATCH v2] gpio: convince line to become input in irq helper Date: Wed, 22 Jun 2016 23:25:58 +0200 Message-Id: <1466630758-26231-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.11 MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The generic IRQ helper library just checks if the IRQ line is set as input before activating it for interrupts. As we recently started to check things better with .get_dir() it turns out that it's good to try to convince the line to become an input before attempting to lock it as IRQ. Cc: Björn Andersson Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Propagate the error from .direction_input() so we can rely on it being used. --- drivers/gpio/gpiolib.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) -- 2.4.11 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Bjorn Andersson diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 5a21a6acf8af..b195ec406ff4 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1505,6 +1505,25 @@ static int gpiochip_irq_reqres(struct irq_data *d) if (!try_module_get(chip->gpiodev->owner)) return -ENODEV; + /* + * If it is possible to switch this GPIO to an input + * this is a good time to do it. + */ + if (chip->direction_input) { + struct gpio_desc *desc; + int ret; + + desc = gpiochip_get_desc(chip, d->hwirq); + if (IS_ERR(desc)) + return PTR_ERR(desc); + + ret = chip->direction_input(chip, d->hwirq); + if (ret) + return ret; + + clear_bit(FLAG_IS_OUT, &desc->flags); + } + if (gpiochip_lock_as_irq(chip, d->hwirq)) { chip_err(chip, "unable to lock HW IRQ %lu for IRQ\n",