Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp88473imm; Thu, 4 Oct 2018 23:53:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV60k/L1xqKsdISUPGiqEuEirwouluaDW6f73Y0mzDb8znseO6o1r/XT/MCrTdIS69UXrlQp3 X-Received: by 2002:a63:3c46:: with SMTP id i6-v6mr8816193pgn.286.1538722422933; Thu, 04 Oct 2018 23:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538722422; cv=none; d=google.com; s=arc-20160816; b=B83IFrSlh+7djvICSe/rfYB18PPR5CnMuR6iagFWYyLOm3m/Yzs4UIlbJwKa9pNVuO s6adKZbEbTTNYPmRieYKZKR2li6pseeYiGczK6ihHwY+dfFw4sIy1/0cnwBgwn+V6lw7 /ppm0E6MRbW39TfL+PkHdPpaLYhcbiuqmqyHVZqx6oKG+DOzT1/zarTPp4J/qlzr6D4u kCcoUdVZB7EVqlNa8BR+DBaMkG1Yj4r1j+g64507H72bymZlm3sYUt1EP6Vlr6JVfUY8 RUpsU107Y9OkQ7ZDrg8UPbx583SWeJbJ2xYFgakrhB2AoM9bB4cda3qa1RvsErmvwHPH CIxA== 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=JDv7+lrfVHx6crNgWoKYdtCEXUNPEwDIMvB3Aq/NiOY=; b=rVvcrQsIUQio5eQNGRdrQLW00ouVoXOMdkR3L164zDBWstzQMWL9rbtDxIfSDvXoMV bfUBOwbgx1BkyGeeaUPcv5DD/p/BjoKw8w0Ya6jOP7Jjc4CWJqi2fAwti47ZFOh+nI5m 0+galTEU0QLU06hszrfSYUdmMnCK3/N5dhwy/Maz8EqGA937u0W+SllK7dUfNscXQQQm JiJFnssT4w5q5zC5BYO4pm4wH4g6c0zrI//YHUysYdk8idyOnFgkiyhfrOJcia1pV3WQ mYuFJjHu2dOy69g1IuSRiXFUYddQ/9pmt8aD6D8JeheITKWim37I3ZxJk85qVpJo+iwq WCpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="U3dF5Hd/"; 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 b41-v6si7667640pla.306.2018.10.04.23.53.27; Thu, 04 Oct 2018 23:53:42 -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="U3dF5Hd/"; 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 S1728037AbeJENu1 (ORCPT + 99 others); Fri, 5 Oct 2018 09:50:27 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:33116 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727025AbeJENu0 (ORCPT ); Fri, 5 Oct 2018 09:50:26 -0400 Received: by mail-lf1-f67.google.com with SMTP id o21-v6so8602605lfe.0; Thu, 04 Oct 2018 23:53:08 -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=JDv7+lrfVHx6crNgWoKYdtCEXUNPEwDIMvB3Aq/NiOY=; b=U3dF5Hd/6yXGlzsw+OcTsxfReqrXFy2yFJ4m7PNFNgqz8tkeIIinx6jtyS/YSYmWhI Z58awvvaAm41fqxDObeJCrZ3yyOYK7MumxMJ63HD/juPrXX+nYcS8xd46+KNp8K6oQdF SLPAbv+Q5UGX93RU6grtxZBn5pHR787GemwqZkgA4z0jNXpS09gWoyeqzxQTwYZ/zEVH NUP1pC5HR/4R0ut1XaiKx2LosCF/OHMauiG/y/IwYlZz0NBiqiONXh29Sx0roZxFgQeU J7xfzcmoetuIztvZhXowmnnhJ6a1qfQhZxZO6U0Y04Jav05Do2MqhlfmB5/gwVOfea8t UJgg== 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=JDv7+lrfVHx6crNgWoKYdtCEXUNPEwDIMvB3Aq/NiOY=; b=XdpcML8vGKau12Ukl9ozl5SwGcJR+mpiFsub8xbl+iCo1tyZ2GrQUBAV5HU2oVv4AE kN13BCzxgHboxWIHZQQ8cxQR3+uiXsvtf8LXqrCXvQ+hVdy87Y1K7S8al4QS+9ojuwGf +ca0wvCj1otV30yt64Rkj5/+uP2+wtwI5slWIGJak0tcWze95H1WXW8i302uHKkJN1kD j9ZpvMR808lF2amleRisiEez7lomD+uhxCQq5QFlnx7UrP3bK3blyA54yCw0gt0Mz8tE NuO0KS5X640tqoxB/NszY+Y7r/ugwjom1kRhCBbFCVoYpNR8tHJyBJtYGcw56rii3KG2 NpXw== X-Gm-Message-State: ABuFfoiYXYb+cBoozPOGC2Y4qu62m08HeMNC+BbmgrC5jA4YKb/YwCGd 3a6iKPFMQBMSD+KpQnonWKA= X-Received: by 2002:a19:ea57:: with SMTP id i84-v6mr5582566lfh.91.1538722387064; Thu, 04 Oct 2018 23:53:07 -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 t21-v6sm1608871ljg.32.2018.10.04.23.53.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Oct 2018 23:53:04 -0700 (PDT) From: Ricardo Ribalda Delgado To: Jeffrey Hugo , Linus Walleij , Timur Tabi , Stephen Boyd , linux-gpio , LKML Cc: Ricardo Ribalda Delgado Subject: [PATCH v5 3/3] gpiolib: Show correct direction from the beginning Date: Fri, 5 Oct 2018 08:53:00 +0200 Message-Id: <20181005065300.22882-3-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181005065300.22882-1-ricardo.ribalda@gmail.com> References: <20181005065300.22882-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 | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 907019b67a58..e016b22658ff 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1349,20 +1349,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 @@ -1391,6 +1377,19 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, if (status) goto err_remove_chip; + 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; + } + acpi_gpiochip_add(chip); machine_gpiochip_add(chip); -- 2.19.0