From patchwork Fri Sep 21 10:36:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 973136 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SdC4Sc3c"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42GqlD69CBz9sCD for ; Fri, 21 Sep 2018 20:36:24 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389689AbeIUQY0 (ORCPT ); Fri, 21 Sep 2018 12:24:26 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:46190 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727554AbeIUQY0 (ORCPT ); Fri, 21 Sep 2018 12:24:26 -0400 Received: by mail-ed1-f68.google.com with SMTP id k14-v6so10302012edr.13; Fri, 21 Sep 2018 03:36:09 -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; bh=6fncp2wBKiaAhFqes5VbfWoYDTuWvL2B06DeOxEt5SM=; b=SdC4Sc3c1H+O8OJTrSmV9MNm9SmoO/lrebyfMRX9FWmHF8czXdSYPIQZPJxb4SldoD CL1Wo7PGKxAzY+4RcBxmvfMXaov3brxpQ8ht+aQtzSrzfm1ANllzJuhV3HLXDPZEbegq 78QA/beyhhcYkbI0BL4IGU0pY/IWl3YW8s58aLDHyR7IiSPVNsCseAbJJJ8tdiW2we1c FmUPU4hVlquDneN3wfopugIW0iCz7T8WVoAwJdWfaSiPrw0cDTlJK1RwLVdGXIxiqGzt PQk91lBjqnWLybGEJCkGYtibZnUgrBwtPNnUf/HPvRKugiIjDtsetmuBtbs41i9A1ZuC scRg== 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; bh=6fncp2wBKiaAhFqes5VbfWoYDTuWvL2B06DeOxEt5SM=; b=IfJ/m2y6/6DpgOXfJbJdeyfjFZWifx8l62WEWs8n17piIWMsXwewXYw/RMzcOhl2V1 iyTDLkDXBsWbWX97pUDf6m2k1+xqGxU8uZzHsyf/UArddvJrkRJgr3V3/NONYk4h6V3J 1iiI+Q97I38To9sZbLA7S0og0nFOv+HUxYTLaSRmqdQDRFJyROIs0g259aR802iFSFGt DBgDblsjyz2UsG9buPq5D0GLTzmty/WnaRVbqU+4B3UZWeqNf9s86J9zPWWcEGcqCLHZ uEJnKFe4Ft4JOQE3SPLavu2iG84H083XkviqPKLQX+4Ji2AMJsEKG8lA1mT3+t/Y5UHU 8gVw== X-Gm-Message-State: APzg51C6uZ9PDeBYIOCLf8OgFh+zKQKtHoZb8FAkyrH0xF1JoYze0ubv PmTDfIN1FqyV1C+uyhFvwA0= X-Google-Smtp-Source: ANB0VdaMYaqVZYfnfcbwYllJrScMAXrUOTKp8YNY7WGqsdaa/s1BmCin6FP11AiWAEt5Wh2yp3BMpQ== X-Received: by 2002:a50:8345:: with SMTP id 63-v6mr10583836edh.5.1537526168721; Fri, 21 Sep 2018 03:36:08 -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 k28-v6sm1900871ede.11.2018.09.21.03.36.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 03:36:07 -0700 (PDT) From: Ricardo Ribalda Delgado To: Linus Walleij , Timur Tabi , swboyd@chromium.org, linux-gpio@vger.kernel.org, LKML Cc: Ricardo Ribalda Delgado Subject: [PATCH v2] gpiolib: Show correct direction from the beginning Date: Fri, 21 Sep 2018 12:36:04 +0200 Message-Id: <20180921103604.13361-2-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180921103604.13361-1-ricardo.ribalda@gmail.com> References: <20180921103604.13361-1-ricardo.ribalda@gmail.com> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@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 Reviewed-by: Stephen Boyd --- drivers/gpio/gpiolib.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 4b45de883ada..00c17f64d9ff 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1352,7 +1352,12 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, * 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 && 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; } #ifdef CONFIG_PINCTRL