From patchwork Thu Mar 5 18:53:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1249822 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; 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.a=rsa-sha256 header.s=20161025 header.b=EsSBTpYY; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48YKg24sJgz9sPF for ; Fri, 6 Mar 2020 05:54:38 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4521A812DC; Thu, 5 Mar 2020 19:54:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EsSBTpYY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3F271812AC; Thu, 5 Mar 2020 19:53:52 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D433C8126E for ; Thu, 5 Mar 2020 19:53:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf44.google.com with SMTP id u10so2917318qvi.2 for ; Thu, 05 Mar 2020 10:53:47 -0800 (PST) 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=8Wpq3O5bqo4+7kCxyuSGdUg8b1S/b2C2ry1eTlnMFIs=; b=EsSBTpYYsIPaImoBcB4gpwq32ZPhYUEGTktwrETWgfITEaAUzf1jPkFM8ioL7TR4WQ JkhtvHt7LWqSeYXeVxVGIiIueVoUdv//3+2CKGJkGzWZ6s+eQ3fiT7nGsigbkzd88+J9 ZbBmBtLv0uBUNlfTCB+gFLz7MF76j4QHRJMVqvK+9Ld2ttBSyEhjQHDj9OnxjvSJcgzn RKwPWdFGnt11frGuOG2VEUTWNE4NEvWJCQY/rFQAhYMFGiYHBkfT5qMUalgg0jVz37vM lTH7NP977TMwToi7ttFQjrF5Ce9OZ0d3T+fODcWCgnh9UdewlO+FbEIlgiCP/iXg93/q Xq7Q== 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=8Wpq3O5bqo4+7kCxyuSGdUg8b1S/b2C2ry1eTlnMFIs=; b=jugdc+bgW0H0iF5cB1YB5jo8G+hW4GoMQI4aKbDW+dFm51sJohzkDR7YIDOuAIvYBE DUpkfMuTqGGVM3/J6PUIJqBUcw+G7SxGras6zWPb0zVfEtKiRS9U/bqJb8HpecI0BGCf TdAP/jAgYYvOY6lMFcfcqxCCCqyTEERv2oexLwdVA95UpBkbUmCAXIo9eawjSo7jYlgA ZT+UABBpLFYkxXQhFgyX2+/EOBCSlqRPQ6zbSSpfWAk/GaVnMee6xOyJ5aUk9KerimyM 1azGBgfSiyK35W+rUsUpMS9BOmrGn+M/UAULAnsrQ3V7sTYwjl22H5Gz++ePum5cvJLr FQgA== X-Gm-Message-State: ANhLgQ2a6flOPhz2lms5HbOQ7dD+S69oPzHIg9S/Di6szWYFG5FIHOki SylyJGS9pm4M1Zeg6qPs/qCXcNsp X-Google-Smtp-Source: ADFU+vvetU/qTN+tY8RUL+I/G3WWO1FdVzunidFUsxQU33jfrV52SHV0cZSgFleSidriRnI69wxA3Q== X-Received: by 2002:a0c:f94f:: with SMTP id i15mr139951qvo.190.1583434426238; Thu, 05 Mar 2020 10:53:46 -0800 (PST) Received: from localhost.localdomain ([75.102.135.197]) by smtp.gmail.com with ESMTPSA id o16sm16263379qke.35.2020.03.05.10.53.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 10:53:45 -0800 (PST) From: Sean Anderson To: u-boot@lists.denx.de Cc: Simon Glass , Tom Rini , Sean Anderson Subject: [PATCH v1 5/8] gpio: dw: Return output value when direction is out Date: Thu, 5 Mar 2020 13:53:25 -0500 Message-Id: <20200305185328.951011-6-seanga2@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200305185328.951011-1-seanga2@gmail.com> References: <20200305185328.951011-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean dm_gpio_ops.get_value can be called when the gpio is either input or output. The current dw code always returns the input value, which is invalid if the direction is set to out. Signed-off-by: Sean Anderson --- This patch was previously submitted as part of https://patchwork.ozlabs.org/project/uboot/list/?series=161576 drivers/gpio/dwapb_gpio.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index 09abab5c39..058c5fbfbf 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -64,13 +64,6 @@ static int dwapb_gpio_direction_output(struct udevice *dev, unsigned pin, return 0; } -static int dwapb_gpio_get_value(struct udevice *dev, unsigned pin) -{ - struct gpio_dwapb_platdata *plat = dev_get_platdata(dev); - return !!(readl(plat->base + GPIO_EXT_PORT(plat->bank)) & (1 << pin)); -} - - static int dwapb_gpio_set_value(struct udevice *dev, unsigned pin, int val) { struct gpio_dwapb_platdata *plat = dev_get_platdata(dev); @@ -96,6 +89,18 @@ static int dwapb_gpio_get_function(struct udevice *dev, unsigned offset) return GPIOF_INPUT; } +static int dwapb_gpio_get_value(struct udevice *dev, unsigned pin) +{ + struct gpio_dwapb_platdata *plat = dev_get_platdata(dev); + u32 value; + + if (dwapb_gpio_get_function(dev, pin) == GPIOF_OUTPUT) + value = readl(plat->base + GPIO_SWPORT_DR(plat->bank)); + else + value = readl(plat->base + GPIO_EXT_PORT(plat->bank)); + return !!(value & BIT(pin)); +} + static const struct dm_gpio_ops gpio_dwapb_ops = { .direction_input = dwapb_gpio_direction_input, .direction_output = dwapb_gpio_direction_output,