From patchwork Wed May 25 09:00:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 68565 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1093791qge; Wed, 25 May 2016 02:00:19 -0700 (PDT) X-Received: by 10.98.97.67 with SMTP id v64mr4010908pfb.149.1464166819176; Wed, 25 May 2016 02:00:19 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 8si26494353pfc.245.2016.05.25.02.00.18; Wed, 25 May 2016 02:00:19 -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 S1752957AbcEYJAS (ORCPT + 4 others); Wed, 25 May 2016 05:00:18 -0400 Received: from mail-lb0-f174.google.com ([209.85.217.174]:34567 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752236AbcEYJAQ (ORCPT ); Wed, 25 May 2016 05:00:16 -0400 Received: by mail-lb0-f174.google.com with SMTP id sh2so13413880lbb.1 for ; Wed, 25 May 2016 02:00:15 -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; bh=VRuifdhMlQc9FtAkMu4KdV2mCUuB2Fr/OVeF+d0GuOs=; b=h9WaD/UHmYlpSbF2V2kchrOM6NpaRrsKSfNJP3/PggFAZvCZ/8Zk8kaqIMbI4cGpYK pvXnCAHKrkLj45JHNE5jpKa8VA14yIELZvBN5Oq9lbfNkbHVG88LxbQtXdK2t6XAd4is l4IWsKQ4+r0o2xl9EZDedIgd4+ie1JkWbNT94= 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; bh=VRuifdhMlQc9FtAkMu4KdV2mCUuB2Fr/OVeF+d0GuOs=; b=lAQZPz+FLUCIcHk79nRM1Ak60Te91hQ1m78bM/2raoBs2MpUcXA0RPaHNZg3UvzA76 uhTlHJdWjZXIJ9Uw+lfdjzZehdOIUMgRJS8vkQsRZwWXLVp2k7sQyTW+4bsTAJbwQPpS E/0ol3yn66h4oHJfUClgRrHRS1xYZBPog/j/S9PzjLrHQkSZEHiOvx9qAsXmGXd7zKYI yi2Z7huIgzud4tkobZrs5XI9Y5oTPB146zvMFHKlAZCnH7MCG8nyDq8Nt1KNcG4ajYGY yBIURtD4zymP+AiGjt6hbNfIxNvl7POJ9y3TSxI49CSRN124i8YO3Q82ZwRw+d2BeGI0 WWNA== X-Gm-Message-State: ALyK8tKYYMTMM+LAgXK5Z0T7UjHDLHMPjLk+KiyoA/2SVBxljrMLwbQTpd/qh8010Hl6/l9W X-Received: by 10.112.204.99 with SMTP id kx3mr802571lbc.31.1464166814780; Wed, 25 May 2016 02:00:14 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id z132sm1325646lff.46.2016.05.25.02.00.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 May 2016 02:00:12 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot Cc: Linus Walleij Subject: [PATCH] gpio: flush direction status in gpiochip_lock_as_irq() Date: Wed, 25 May 2016 11:00:10 +0200 Message-Id: <1464166810-32553-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.11 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org As irqchip and gpiochip functions are orthogonal, the IRQ set-up or something else can have changed the direction of the GPIO line from what the GPIO descriptor knows when we get into gpiochip_lock_as_irq(). Make sure to re-read the direction setting if we have the .get_direction() callback enabled for the chip. Else we get problems like this: iio iio:device2: interrupts on the rising edge gpio gpiochip2: (8012e080.gpio): gpiochip_lock_as_irq: tried to flag a GPIO set as output for IRQ gpio gpiochip2: (8012e080.gpio): unable to lock HW IRQ 0 for IRQ genirq: Failed to request resources for l3g4200d-trigger (irq 111) on irqchip nmk1-32-63 iio iio:device2: failed to request trigger IRQ. st-gyro-i2c: probe of 2-0068 failed with error -22 Fixes: 72d320006177 ("gpio: set up initial state from .get_direction()") Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) -- 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 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d407f904a31c..e901d2666b46 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2066,17 +2066,30 @@ EXPORT_SYMBOL_GPL(gpiod_to_irq); */ int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset) { - if (offset >= chip->ngpio) - return -EINVAL; + struct gpio_desc *desc; + + desc = gpiochip_get_desc(chip, offset); + if (IS_ERR(desc)) + return PTR_ERR(desc); + + /* Flush direction if something changed behind our back */ + if (chip->get_direction) { + int dir = chip->get_direction(chip, offset); + + if (dir) + clear_bit(FLAG_IS_OUT, &desc->flags); + else + set_bit(FLAG_IS_OUT, &desc->flags); + } - if (test_bit(FLAG_IS_OUT, &chip->gpiodev->descs[offset].flags)) { + if (test_bit(FLAG_IS_OUT, &desc->flags)) { chip_err(chip, "%s: tried to flag a GPIO set as output for IRQ\n", __func__); return -EIO; } - set_bit(FLAG_USED_AS_IRQ, &chip->gpiodev->descs[offset].flags); + set_bit(FLAG_USED_AS_IRQ, &desc->flags); return 0; } EXPORT_SYMBOL_GPL(gpiochip_lock_as_irq);