From patchwork Fri Feb 5 04:22:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1436415 X-Patchwork-Delegate: trini@ti.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=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=OXWIqL8V; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4DX2NN67zBz9sXL for ; Fri, 5 Feb 2021 15:23:32 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CEBC582A5B; Fri, 5 Feb 2021 05:22:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="OXWIqL8V"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E44EC829FD; Fri, 5 Feb 2021 05:22:27 +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.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) (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 4490682A18 for ; Fri, 5 Feb 2021 05:22:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x12a.google.com with SMTP id y17so4690943ili.12 for ; Thu, 04 Feb 2021 20:22:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rURGbvoEfkH+BuzHl+U2w9Q5tbuRnwYbr6oHxAI3ShY=; b=OXWIqL8VCx32hLRJl+GowqoyjtLe+c1yvVW8Lch8hh+vz4nbqIvsbp4Fs1Cr55oCiX Rpz3XqlEO2RGuwBoWlJ0hIA4L4lynTXEdMXFO2fBFUpyQ3u1fglzqOGmpZYrB9MwngzW 8qEkN6CF8vpRxiqP+eYOFbjhXk/SSKgi0JrUo= 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=rURGbvoEfkH+BuzHl+U2w9Q5tbuRnwYbr6oHxAI3ShY=; b=s+FjmIQ9iBO5q5puZIoDd+Jfq8hvkBa4eo/XbryjhVRRvFnRwC31ajVpcBXcNQlm/6 CdOvkVcPCxXa5r2vJFzutXzL99SzJazHNIywV23FDH0ksqls3j3cnQh6wJmkK9/CkAf3 AW8H1YHsywy+qOpwGI/UVH7KAqRRS6u/vLlbwuoqKYy11nF3Zk88R/6zgT9mOrJEKq0B vqmOvuAcRsNCM9k4LMVYyuOAUW8c4x9pfEvUcxO66UdER5Tk0z8xrYrHwRcv3O5K8aJ9 k/pVzF7dxnUhEGiXRc6uiOCI6xbftLopdhVC7MLAzhUGp241b/PLwRe6u5QHoD0HXjAy PlFw== X-Gm-Message-State: AOAM5324Sda0/hp5Ra9cWC5YiK26H0UcV0Oxlh5DqImUabDoWum5N0tB vNVnhCoJ0dB2TTVkWvwTrPoQj6BgyP0nHRLF X-Google-Smtp-Source: ABdhPJyiHZYyQyPp8oJX/tcx3OAVWue5SyvGsyQfaQ8g/pIqJMNxgVD13O8SvZOb5MecCSONyXbYrg== X-Received: by 2002:a05:6e02:1787:: with SMTP id y7mr2173289ilu.233.1612498939859; Thu, 04 Feb 2021 20:22:19 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id d2sm3641404ilr.66.2021.02.04.20.22.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 20:22:19 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Kory Maincent , Patrick Delaunay , Tom Rini , Pratyush Yadav , Patrick Delaunay , Simon Glass Subject: [PATCH v4 08/16] gpio: sandbox: Fully separate pin value from output value Date: Thu, 4 Feb 2021 21:22:01 -0700 Message-Id: <20210205042210.2949365-9-sjg@chromium.org> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog In-Reply-To: <20210205042210.2949365-1-sjg@chromium.org> References: <20210205042210.2949365-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.3 at phobos.denx.de X-Virus-Status: Clean At present we have the concept of a pin's external value. This is what is used when getting the value of a pin. But we still set the GPIOD_IS_OUT_ACTIVE flag when changing the value. This is not actually correct, since if the pin changes from output to input, the external value need not change. Adjust the logic for this difference. Signed-off-by: Simon Glass Reviewed-by: Patrick Delaunay --- (no changes since v1) drivers/gpio/sandbox.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c index 4d73b954b26..912c333e560 100644 --- a/drivers/gpio/sandbox.c +++ b/drivers/gpio/sandbox.c @@ -85,7 +85,7 @@ int sandbox_gpio_get_value(struct udevice *dev, unsigned offset) int sandbox_gpio_set_value(struct udevice *dev, unsigned offset, int value) { - set_gpio_flag(dev, offset, GPIOD_IS_OUT_ACTIVE | GPIOD_EXT_HIGH, value); + set_gpio_flag(dev, offset, GPIOD_EXT_HIGH, value); return 0; } @@ -141,10 +141,19 @@ static int sb_gpio_direction_input(struct udevice *dev, unsigned offset) static int sb_gpio_direction_output(struct udevice *dev, unsigned offset, int value) { + int ret; + debug("%s: offset:%u, value = %d\n", __func__, offset, value); - return sandbox_gpio_set_direction(dev, offset, 1) | - sandbox_gpio_set_value(dev, offset, value); + ret = sandbox_gpio_set_direction(dev, offset, 1); + if (ret) + return ret; + ret = set_gpio_flag(dev, offset, GPIOD_IS_OUT_ACTIVE | GPIOD_EXT_HIGH, + value); + if (ret) + return ret; + + return 0; } /* read GPIO IN value of port 'offset' */ @@ -158,6 +167,8 @@ static int sb_gpio_get_value(struct udevice *dev, unsigned offset) /* write GPIO OUT value to port 'offset' */ static int sb_gpio_set_value(struct udevice *dev, unsigned offset, int value) { + int ret; + debug("%s: offset:%u, value = %d\n", __func__, offset, value); if (!sandbox_gpio_get_direction(dev, offset)) { @@ -166,7 +177,12 @@ static int sb_gpio_set_value(struct udevice *dev, unsigned offset, int value) return -1; } - return sandbox_gpio_set_value(dev, offset, value); + ret = set_gpio_flag(dev, offset, GPIOD_IS_OUT_ACTIVE | GPIOD_EXT_HIGH, + value); + if (ret) + return ret; + + return 0; } static int sb_gpio_get_function(struct udevice *dev, unsigned offset)