From patchwork Tue Apr 21 12:39:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 227377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B21EC54FD0 for ; Tue, 21 Apr 2020 12:40:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7812A2074F for ; Tue, 21 Apr 2020 12:40:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="vLKSrKHB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728739AbgDUMku (ORCPT ); Tue, 21 Apr 2020 08:40:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728874AbgDUMku (ORCPT ); Tue, 21 Apr 2020 08:40:50 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B88FDC061A41 for ; Tue, 21 Apr 2020 05:40:49 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id y24so3495436wma.4 for ; Tue, 21 Apr 2020 05:40:49 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=FufN8ACRAoxbxjTegJ+M/1R/ELgdwjuEiGq1TqIq1Lc=; b=vLKSrKHBC50HSMEdUg3fKqcwrRGVHBJu7KLH38rc0PcUh6NQ+hOhqV3S39seQRhw0f o33MVGiFdMGCo9284qpruQ2jhc/Ui+O3ieHQvF5mdpbf7MG9xow358kY8NNJkarcutuw Wh1Z8TXg1PshyCVx5EWPyG2Zz9drckRADrqb/2IvB/kAnXdHexjLejkNZrSh7jVaBHSy 9oqOfuTlKOJL+xJxIV1wPC2Iyutby492EpNZdi9gSi33CAbI5Ehed4bW5P1EJFyO9fSS BOvzWfpG3PGdtw9BbU4jS5fKPPYyts9IJt8sqR+9BpqZQ2H+YGQPo6Uh5UwprN+xCEpT 7rsw== 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=FufN8ACRAoxbxjTegJ+M/1R/ELgdwjuEiGq1TqIq1Lc=; b=SsJxM5e7TaIb8rgOzlBPzl+Q+3MTnc5kSzZ7JUE53lbMfOiboO9SHv0WOl4MmgtXA/ FDKssMgkoUkuUcNuuN5nmPbLgsD0MgBJkiRg5YeQDq9Y694Qwh5ta1uNNehxJKAsSbor tjSRP1VJ9gQV4DqzZiJL18X3njAg0Xpczo3mHefP4SFpsh1pQ+Ti875/8rhx1Ukvzmyk jjJC0EqhZSd/vxdCsJZXPKg/PPf5ec7qXTIPr24zixoyiHBIIdNLno0PjAkPkJsqG47e LLQMu/Biv/y09wl592BgU0LQQpqt0xp3qJpBt33aDPgPEScY8FMwibr+Y/pwJ6BVyE5d Gzeg== X-Gm-Message-State: AGi0PuZ4ffKQKpnlnxVwQoWapYnrzKvuutHizvJpSGDArms9FV5JKVWl zeV5XjOKqkbqI7wbplrbe3Se7pErXbg= X-Google-Smtp-Source: APiQypLDkm0AyICgP+rg7hysUAnYTbVKrjTvaL/62bezJ48PyKrWuUyqg3dDcSP1h71u3NvC3ObVjQ== X-Received: by 2002:a1c:4085:: with SMTP id n127mr5008186wma.163.1587472848215; Tue, 21 Apr 2020 05:40:48 -0700 (PDT) Received: from localhost.localdomain ([2.31.163.63]) by smtp.gmail.com with ESMTPSA id u3sm3408232wrt.93.2020.04.21.05.40.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 05:40:47 -0700 (PDT) From: Lee Jones To: stable@vger.kernel.org Cc: Timur Tabi , Stephen Boyd , Linus Walleij , Lee Jones Subject: [PATCH 4.14 03/24] Revert "gpio: set up initial state from .get_direction()" Date: Tue, 21 Apr 2020 13:39:56 +0100 Message-Id: <20200421124017.272694-4-lee.jones@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200421124017.272694-1-lee.jones@linaro.org> References: <20200421124017.272694-1-lee.jones@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Timur Tabi [ Upstream commit 1ca2a92b2a99323f666f1b669b7484df4bda05e4 ] This reverts commit 72d3200061776264941be1b5a9bb8e926b3b30a5. We cannot blindly query the direction of all GPIOs when the pins are first registered. The get_direction callback normally triggers a read/write to hardware, but we shouldn't be touching the hardware for an individual GPIO until after it's been properly claimed. Signed-off-by: Timur Tabi Reviewed-by: Stephen Boyd Signed-off-by: Linus Walleij Signed-off-by: Lee Jones --- drivers/gpio/gpiolib.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f0777a7a4305b..d5b42cc86d718 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1245,31 +1245,14 @@ 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. - */ - - 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); - } + /* 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