Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1366737imm; Tue, 2 Oct 2018 07:10:08 -0700 (PDT) X-Google-Smtp-Source: ACcGV62xei4xGY5T2ob5rRonWFtEceGUIQZS8QCJ6is5cOSI85E/y+kHZONFyapL+m86x0ZWsuTU X-Received: by 2002:a17:902:6a2:: with SMTP id 31-v6mr16667658plh.1.1538489408513; Tue, 02 Oct 2018 07:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538489408; cv=none; d=google.com; s=arc-20160816; b=cWe2mBnm+P9+cCF+g6ifZ4VVNVJqNWA6SzexsIUxs8TuPC9LP/WAmr9R2UUi9aqRoS dhYS1S60cwVSsSo81g64PQJ4uFO9XuhjHsbQ084w5QuCTBqtRQqErsiF4LMY1V7iTGTt u4l8jplvGhL3sfQMh5YozwA4zUvogyzbuNgYuDonKb4vw4omqyWNzYrSy/EFdzNLvaDi Oinya09KKlCA8Z5vfxIoPPOm2e65WadaMqyPjBFHjsBIWZK6UBpf9dBYkJu35+pMWsFd mr+vYRpN6OigqfUnpV3GXXFLZK2+QiLQ1jFBSUYpRLZFqxn80koV6HUzirMOxLYIVkGA kEWA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=A8q4HRunLlkAco+4jlBx5T/JrGR3kj2TrYpY+ho239Q=; b=FsvyLCa29QZ29cuAFmGFb6Zmhy4Ay8A+D66S/cs3zBmsdp2AgWObUirQc4QAGm34t+ 0zU0Na4jbxdPi+LNHRTyBlyNg83sqMK1Hfd0AdCp5Q40b2c2trWIDnuspN+ixIQ0mR7A B6ErjQqJtL1jVFYF8/P+1ANR1w53x49H3IJBGwfV7vHTSnQS24xWC9EJEG6LhewRZ90O ploroSsRc2PplMaj10TeY9OdAkYD5OvnKhxqK41k1gcCNmEjWHdKcFvzUSCnofO86LRT BuzZXdBnzbwHTe3VP+mBMC/rkkCvQx8NK0zzoJn51YHFi1qzu3tqDR6jQXAT6M/WMz6j afWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kPK4aSJ3; 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 d21-v6si15728215plr.327.2018.10.02.07.09.53; Tue, 02 Oct 2018 07:10:08 -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=kPK4aSJ3; 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 S1729672AbeJBUwg (ORCPT + 99 others); Tue, 2 Oct 2018 16:52:36 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:45665 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729105AbeJBUwg (ORCPT ); Tue, 2 Oct 2018 16:52:36 -0400 Received: by mail-ed1-f66.google.com with SMTP id v18-v6so1126188edq.12; Tue, 02 Oct 2018 07:09:02 -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:mime-version :content-transfer-encoding; bh=A8q4HRunLlkAco+4jlBx5T/JrGR3kj2TrYpY+ho239Q=; b=kPK4aSJ3Gh7LiW332hwJCU8Fm2Xj+qHsXvOug3t1aH1JI0bLYgWk+Nb6v2XlrwQvzI rRq/vtVLPh8Z8esBwZO/pXZgSeQ/tj6hqWFXrr5VNm+KEZpXUT5+KGglUTHm2X3xnzx7 DBy7aThvrII5VEYMNFMM73ZLNO37f8wcrXoNK3YOlshjD5FEG4MOeqqfDO4ave5JjHFL Bz/fgAjKE7FFNjcF71xBtcp5eo34WRxiXzwJSG3Yyr0gbsO0nUgW9noLScrqokSMilvE pslgGys3F0Yz/gpVUj8UXludomroFVGaev27Dm14vHvQXklPoLsuzQr78xQt5hx8N28d IVlw== 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:mime-version :content-transfer-encoding; bh=A8q4HRunLlkAco+4jlBx5T/JrGR3kj2TrYpY+ho239Q=; b=HHJ8vVbh6C97GSN504SMH4sAewD0/ZVnbROCG4+ZvJ7W3sd5jNY9Kn8Tojivo+kvNv JLJOnOD8NaW+DbuAM0Cj54/v2VZ8kW7DpCu+EvknJphuL0R0M5lCE5wzHM8slId68CwJ H79evgMbLnTUbgwEVtwf3jZLrDo6MizvGIjZyHRd1R/Vwv/CXLEg/ptjLa4aSVoLuwzR Y9ySLkm0Ll/yzjOfhRLTk4sOpwei+s53W0kpm4cZg8xbj+cZ5iZKD56kTYotp4RzO599 s/Ge+fgFQ2MGRp3Ff440M4dZTUF/pevzV89yiIIASURDPRY6L7i0ar21DS6TbApyg9Su uEzw== X-Gm-Message-State: ABuFfog43d4DrmMaNKIu8VCtBJMd+d4M3BiFflMzWqy90Ye3pSLfrAG+ 1EHLO1C+rSj5OtJocEdbDlY= X-Received: by 2002:a50:aed4:: with SMTP id f20-v6mr24049387edd.271.1538489341385; Tue, 02 Oct 2018 07:09:01 -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 k5-v6sm2786621eja.44.2018.10.02.07.08.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 07:09:00 -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 v4 3/3] gpiolib: Show correct direction from the beginning Date: Tue, 2 Oct 2018 16:08:58 +0200 Message-Id: <20181002140858.16833-1-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 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 --- Changelog v4: timur@kernel.org: Remove REVISIT comment drivers/gpio/gpiolib.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6925196136ce..cad859fece65 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,19 @@ 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; + + 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