From patchwork Thu Apr 28 12:35:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 66894 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp187951qge; Thu, 28 Apr 2016 05:35:34 -0700 (PDT) X-Received: by 10.98.18.80 with SMTP id a77mr19895713pfj.27.1461846933942; Thu, 28 Apr 2016 05:35:33 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 191si10145242pfc.127.2016.04.28.05.35.33; Thu, 28 Apr 2016 05:35:33 -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 S1752016AbcD1Mfd (ORCPT + 4 others); Thu, 28 Apr 2016 08:35:33 -0400 Received: from mail-lf0-f43.google.com ([209.85.215.43]:36705 "EHLO mail-lf0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751571AbcD1Mfc (ORCPT ); Thu, 28 Apr 2016 08:35:32 -0400 Received: by mail-lf0-f43.google.com with SMTP id u64so82338285lff.3 for ; Thu, 28 Apr 2016 05:35:32 -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=0ajlBlAg/trXMDp1Osa2qFAQHg/BNH7DH9yHPLI3btw=; b=E9dOugfZqEYMy0gHAu8RItfn+8v6MVqRJF/FT4dVYRbJjFVsiAdZwi1U9nXLrC/auL 5Yr2Pq+ljsVmg0T7qP1Lnr84OWvEGbdKAv1/4CPK18gb+gLTSVz6nYeX/Z6B205wyW8N oDeP0n42F7XpkzEVkVAnnBYTGtapdhltSdE8w= 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=0ajlBlAg/trXMDp1Osa2qFAQHg/BNH7DH9yHPLI3btw=; b=PfV87+d/3o/8Fh0NlCJ9dKh/1yfnNdA0hAne7G7kMUDNfOlPZgW9cIIidFaLHW4Ypn RLIJMbZsIQtv9LJCQkLt6m89lB+lGi1zR5W7xIx9asxbKu/TJQ+Dobbu/EofFx5Rc94g /pMM75dc6Ydv4DqR9863l48zRWQZWn0N82RU6GFM2qpJ8pHz4Ee+pMlrDMR+Bipu01wS EIcI2h9d6CsgRUkZT9ZnGmfHLx0NJKg72McYbJJKGJcHNRZf94zrc0mtuIp04smwgcWz rzHelneNe6PVxluLMttfOXzl5Gu01itC+afiOucGjWqsMPEfMXmXoHBY6Wg0x+l1uQi+ tnGw== X-Gm-Message-State: AOPr4FV66GSYH4Z392iZ3KO8y+1J5kOm0w6PpBWUDA8nyOWIPnbCMp+9Yelz+kBQgGDegrKL X-Received: by 10.25.145.136 with SMTP id t130mr5971582lfd.4.1461846931021; Thu, 28 Apr 2016 05:35:31 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id n13sm653010lfb.28.2016.04.28.05.35.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Apr 2016 05:35:30 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org, Alexandre Courbot Cc: Linus Walleij Subject: [PATCH] gpio: set up initial state from .get_direction() Date: Thu, 28 Apr 2016 14:35:27 +0200 Message-Id: <1461846927-30734-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 If the gpiochip supports the .get_direction() callback, then the initial state of the descriptor flags should be set up as output accordingly. Also put in comments explaining what is going on. Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 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 f72dfb6094a7..d2246f58abbc 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -755,14 +755,31 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) struct gpio_desc *desc = &gdev->descs[i]; desc->gdev = gdev; - - /* REVISIT: most hardware initializes GPIOs as inputs (often - * with pullups enabled) so power usage is minimized. Linux - * code should set the gpio direction first thing; but until - * it does, and in case chip->get_direction is not set, we may - * expose the wrong direction in sysfs. + /* + * REVISIT: most hardware initializes GPIOs as inputs + * (often with pullups enabled) so power usage is + * minimized. Linux code should set the gpio direction + * first thing; but until it does, and in case + * chip->get_direction is not set, we may expose the + * wrong direction in sysfs. */ - desc->flags = !chip->direction_input ? (1 << FLAG_IS_OUT) : 0; + + if (chip->get_direction) { + /* + * If we have .get_direction, set up the initial + * direction flag from the hardware. + */ + int dir = chip->get_direction(chip, i); + + if (!dir) + set_bit(FLAG_IS_OUT, &desc->flags); + } else if (!chip->direction_input) { + /* + * If the chip lacks the .direction_input callback + * we logically assume all lines are outputs. + */ + set_bit(FLAG_IS_OUT, &desc->flags); + } } spin_unlock_irqrestore(&gpio_lock, flags);