From patchwork Fri Jan 15 14:04:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1427064 X-Patchwork-Delegate: sjg@chromium.org 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; dmarc=pass (p=none dis=none) header.from=chromium.org 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=g+/e4aa7; 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 4DHNLc482Cz9sVr for ; Sat, 16 Jan 2021 01:08:07 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 019DE826E1; Fri, 15 Jan 2021 15:06:10 +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="g+/e4aa7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2036982667; Fri, 15 Jan 2021 15:05:49 +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.2 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-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) (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 C19698267A for ; Fri, 15 Jan 2021 15:05:38 +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-io1-xd2d.google.com with SMTP id d13so15058464ioy.4 for ; Fri, 15 Jan 2021 06:05:38 -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=FVvNLRZpeWjrRIdPViaShIj9rVU8z3HDQei/1Aa9sLI=; b=g+/e4aa7TPu1uxM9JnzOsQFA7jdancCd09HIuVeZmU0Id6tRyOaB4FNu2jIGIiexsk oZpbQ8wvbbH52aUk9PbD/SNOoVxknwwnE5Dh4S5+Bcr30S9RV/pXcN9WNgnwVlw1/aSm zQtQNjREftiXklDorC2nNdoN6BXbX6AIqAr6o= 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=FVvNLRZpeWjrRIdPViaShIj9rVU8z3HDQei/1Aa9sLI=; b=e+J52zReys7a/u/mxWz4qgzp06rUavSRQlPJwwX0idcCqD/Z/C2rUQt1gVIdB6GqK5 8kf7EkyNsEJmuipJYFWazeulpCxCdlGFeSLqYsfIVhkB7XA5HwRItydcR2NM2Ie+U3j4 dMKjlP/Lc9WdZuGE6lhPd2Pd96UvH8ChTQtDgAAVPO1yiMgWm9Ru8z3zPa4nS22n+g41 nx79Kb7cjpNsAJpjEyTRsB12COR1nqLiijZauoYOQOeGP4mHPXDpG9Y42NWlKNdqMXhZ r4ei4TZ4o6AkXLxSBKOplcEWfi9lQ4iMqSb1CQuKyM8RQaRmmN/9BTnyoHlAGl3qsksi 27mQ== X-Gm-Message-State: AOAM532iqyZ4O/a15n0VRrvA3z28o7GKik61CaW5Cb8eabsMPwcshWdA TpRI8ia0B8NJs99LwpB52aOOwr/LMURBrI/7 X-Google-Smtp-Source: ABdhPJzThqZhO0G43eqKs0nxxxFaHVojhBly1bdzsui5dsW5Eq0IBWekvKNOc0mRCo3pv2La7yAhDA== X-Received: by 2002:a05:6602:24cb:: with SMTP id h11mr8601876ioe.79.1610719537405; Fri, 15 Jan 2021 06:05:37 -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 1sm5664843ilv.37.2021.01.15.06.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 06:05:36 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Patrick Delaunay , Tom Rini , Simon Glass , Dario Binacchi , Heiko Schocher , Jean-Jacques Hiblot , Patrick Delaunay , Pratyush Yadav Subject: [PATCH 11/15] gpio: Replace direction_input() and direction_output() Date: Fri, 15 Jan 2021 07:04:56 -0700 Message-Id: <20210115140500.846307-12-sjg@chromium.org> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210115140500.846307-1-sjg@chromium.org> References: <20210115140500.846307-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 The new update_flags() method is more flexible since it allows the driver to see the full flags all at once. Use that in preference to these two functions. Add comments to that effect. Signed-off-by: Simon Glass Reviewed-by: Patrick Delaunay --- drivers/gpio/gpio-uclass.c | 15 ++++++--------- include/asm-generic/gpio.h | 26 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 05627ecdc30..68ed65d0899 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -512,13 +512,10 @@ int gpio_direction_input(unsigned gpio) int ret; ret = gpio_to_device(gpio, &desc); - if (ret) - return ret; - ret = check_reserved(&desc, "dir_input"); if (ret) return ret; - return gpio_get_ops(desc.dev)->direction_input(desc.dev, desc.offset); + return dm_gpio_clrset_flags(&desc, GPIOD_MASK_DIR, GPIOD_IS_IN); } /** @@ -533,17 +530,17 @@ int gpio_direction_input(unsigned gpio) int gpio_direction_output(unsigned gpio, int value) { struct gpio_desc desc; + ulong flags; int ret; ret = gpio_to_device(gpio, &desc); - if (ret) - return ret; - ret = check_reserved(&desc, "dir_output"); if (ret) return ret; - return gpio_get_ops(desc.dev)->direction_output(desc.dev, - desc.offset, value); + flags = GPIOD_IS_OUT; + if (value) + flags |= GPIOD_IS_OUT_ACTIVE; + return dm_gpio_clrset_flags(&desc, GPIOD_MASK_DIR, flags); } static int _gpio_get_value(const struct gpio_desc *desc) diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index 4a657b1bd2b..4628d937259 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h @@ -266,10 +266,32 @@ int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc, struct dm_gpio_ops { int (*request)(struct udevice *dev, unsigned offset, const char *label); int (*rfree)(struct udevice *dev, unsigned int offset); + + /** + * direction_input() - deprecated + * + * Equivalent to update_flags(...GPIOD_IS_IN) + */ int (*direction_input)(struct udevice *dev, unsigned offset); + + /** + * direction_output() - deprecated + * + * Equivalent to update_flags(...GPIOD_IS_OUT) with GPIOD_IS_OUT_ACTIVE + * also set if @value + */ int (*direction_output)(struct udevice *dev, unsigned offset, int value); + int (*get_value)(struct udevice *dev, unsigned offset); + + /** + * set_value() - Sets the GPIO value of an output + * + * If the driver provides an @update_flags() method then that is used + * in preference to this, with GPIOD_IS_OUT_ACTIVE set according to + * @value. + */ int (*set_value)(struct udevice *dev, unsigned offset, int value); /** * get_function() Get the GPIO function @@ -328,7 +350,9 @@ struct dm_gpio_ops { * uclass, so the driver always sees the value that should be set at the * pin (1=high, 0=low). * - * This method is optional. + * This method is required and should be implemented by new drivers. At + * some point, it will supersede direction_input() and + * direction_output(), which wil be removed. * * @dev: GPIO device * @offset: GPIO offset within that device