Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1040531imm; Tue, 2 Oct 2018 01:28:02 -0700 (PDT) X-Google-Smtp-Source: ACcGV617jNuZlnZT4wDmc7oVwt1KY3iR8VYQc/5P7gYBLre5QWr+xgfo8j4ffXJs3BG8EuWSOIZU X-Received: by 2002:a63:d40c:: with SMTP id a12-v6mr13546315pgh.394.1538468882927; Tue, 02 Oct 2018 01:28:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538468882; cv=none; d=google.com; s=arc-20160816; b=xn1WHzv3veu0jHNmKTw8x2W2cmsrOJ4xG4CqXsJnyp/agabMK9vJFnjk3fT6EoAp2a c3XXRW/vOuJb5Q4bb7400NDpVK50dAdDEFG3jlgQMLaWsg2okWFD20SaVCFKVlSmEvfN OXPOXoq3vmwmrZ3jFBmtBY2vyA08pf9tY6DFNApjwiWcEOdh2nG+QfwAGhUen6h7NiPJ iQJ8gBd7GT0FvgPOhvaTzE7nrc9AsN7a7y6NpcTrb1cPKvHELIIsDG7LHxmvK5tNieRy Vds0IWf7iYevrFJhot3LZL1B24JSH1Oiqfo/q1I9p+GXR1FGJuwKnQnkOi44Lpqu2Bss 2O4w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mDcT737/quUU7Lv5/p9BcXm7XROdXOvHTo1MWEuta7M=; b=VHSDS+JUrbZi86tF9EH3BgY0DD3IT1nf6tu5B5VKqNpwaRF6MAL0Zx1m66EnEMH9Nw qKTr/MeUaBgrPOkDMiu0MRNk6XP5x+sY3iJNXiVhAxYbAgJRV0C9RClIgPx7qxvPwR94 zIO147bJX1aTEPut6Y014j26JzjpAyLinKyWwimsRqYFa4BU5no+u9r75Te6+59OyDWl f2pEh2rEKWNxbvT12/0qsM6o3qKYwFrYAwsAU+QjAaxP60BQ4izWCFqFsKTAm7ygPoRq IOuo9daM4Es0beyKhefnCbzMktlXONkWup9NFuI/Zsxu9G6gICtHXbyM3tPZaNSr/dcP qUeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="qNo6/epD"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p9-v6si16689327pll.298.2018.10.02.01.27.48; Tue, 02 Oct 2018 01:28:02 -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=@gmail.com header.s=20161025 header.b="qNo6/epD"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727628AbeJBPJp (ORCPT + 99 others); Tue, 2 Oct 2018 11:09:45 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:33447 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727383AbeJBPJp (ORCPT ); Tue, 2 Oct 2018 11:09:45 -0400 Received: by mail-lj1-f195.google.com with SMTP id z21-v6so975190ljz.0; Tue, 02 Oct 2018 01:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mDcT737/quUU7Lv5/p9BcXm7XROdXOvHTo1MWEuta7M=; b=qNo6/epD9zhT9i7eFl392ifXVFVIgpDQ3gEaS0KRaTKwRHDZX4EmYmRNOPcZZ5m8xK DKc+GmXVTnD3wnkuzXvQXILLrHh54aDMXOqtlqZg/BgRep7sno7JiynAvegud7NmobV/ HwgP+Y5xXcy/AK6GBVxtXUaCy1vsSLQzMrObVZNrvvL1Urhb1aGbLyV7LLbooI7wTjSJ P6p6Y9P0vo5whlzP1cFntFyYpZ2rklcUjPBf1LjbWRu5bnZJfl3Ow2QX1VeIt7Ebf+0S FNhughZh+SAYJe0rYNodiYnJ5w2QwhBdDWStIjsZ2PMBJPyXp1+o8LotaXibJoMaVTS+ Nq5g== 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:mime-version:content-transfer-encoding; bh=mDcT737/quUU7Lv5/p9BcXm7XROdXOvHTo1MWEuta7M=; b=pv6NYUnJmCdzsQrmJF95lJetrjlfl+/YcvB9gm+5oKhZz0im333ce435YgZTd7YTDv 74oC4otZphlzUubaFS0Q0+HMshBPuY68l9c5bswBNTBQ/BE33RnjFbMLtPRq125MLdAC byT492pT6vqZ7EopjbJ/voA7OlDeaLzAixUwhQmnusq6j107mF+lV2JB5TdLXdx63IfG 6riVRInyVBQndjCw9aO/GBqYDfJUCEPrHF3v+TctA0w2Svd07CFaP2YuYWKE8TdiumDK C9ughxxZ2ixaWICNIgHZmULq8rm0pps2A8niWpmNXnO3p1E1AtsWDVargcKc29mzocUc BgwQ== X-Gm-Message-State: ABuFfohBbhBp77XThqZ1gdbIAXgCQz8uUyBoXsWh3rN/RBLhKiANuga4 MkAj9sdtwLaVw94vicY3Pdk= X-Received: by 2002:a2e:6f0c:: with SMTP id k12-v6mr8918282ljc.66.1538468858362; Tue, 02 Oct 2018 01:27:38 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id p11-v6sm1493531lji.87.2018.10.02.01.27.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 01:27:37 -0700 (PDT) From: Ricardo Ribalda Delgado To: Linus Walleij , Timur Tabi , swboyd@chromium.org, linux-gpio@vger.kernel.org, LKML , Jeffrey Hugo Cc: Ricardo Ribalda Delgado Subject: [PATCH v3 3/3] gpiolib: Show correct direction from the beginning Date: Tue, 2 Oct 2018 10:27:31 +0200 Message-Id: <20181002082731.20141-3-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181002082731.20141-1-ricardo.ribalda@gmail.com> References: <20181002082731.20141-1-ricardo.ribalda@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current code assumes that the direction is input if direction_input function is set. This might not be the case on GPIOs with programmable direction. Signed-off-by: Ricardo Ribalda Delgado --- drivers/gpio/gpiolib.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6925196136ce..eaadbcb5c0f8 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1344,20 +1344,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, spin_unlock_irqrestore(&gpio_lock, flags); - for (i = 0; i < chip->ngpio; i++) { - 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. - */ - desc->flags = !chip->direction_input ? (1 << FLAG_IS_OUT) : 0; - } - #ifdef CONFIG_PINCTRL INIT_LIST_HEAD(&gdev->pin_ranges); #endif @@ -1374,6 +1360,25 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, if (status) goto err_remove_irqchip_mask; + for (i = 0; i < chip->ngpio; i++) { + 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. + */ + if (chip->get_direction && gpiochip_line_is_valid(chip, i)) + desc->flags = !chip->get_direction(chip, i) ? + (1 << FLAG_IS_OUT) : 0; + else + desc->flags = !chip->direction_input ? + (1 << FLAG_IS_OUT) : 0; + } + status = gpiochip_add_irqchip(chip, lock_key, request_key); if (status) goto err_remove_chip; -- 2.19.0