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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,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 6D09BC433EF for ; Sat, 11 Sep 2021 22:06:44 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D461B610C9 for ; Sat, 11 Sep 2021 22:06:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D461B610C9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 726E4838BC; Sun, 12 Sep 2021 00:06:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sholland.org 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=sholland.org header.i=@sholland.org header.b="HEV5GNWO"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="DwWyvQg4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2056B83885; Sun, 12 Sep 2021 00:06:11 +0200 (CEST) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1848C838A3 for ; Sun, 12 Sep 2021 00:06:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=samuel@sholland.org Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 616B35C00C8; Sat, 11 Sep 2021 18:06:01 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 11 Sep 2021 18:06:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=6pDdr1WQPVcBE Z0CWf/HwpGK+EnhUYfDquYwchpF1ms=; b=HEV5GNWOjYoP/zJvndFlU8P+MtWuC LQZziE4jww4TYQd09fb6wLQ6XdzCkJFz8GOtJrJsTsldHhwaXIOM/VcWlEx085HP +NbpX/OTJ1PudOkva1Ls50ehLHo7uBho5vztA+s+r5ARt/d33mVaE/676cJgu4BD PgpAWotxvr5KJ/Y6wewOdo5CpnKieCBWZfkCG8DX/rw7HvJUDZztY3H9VGg/BCPS axYI1T0477BQmtJzaDUsHFD2gfrM9qa29Ed56GX5h1o2Nkd0jqYlfAQ46hiLvPxb 4KMLGxoMM54R0AAKYCagVoryAGRIu+j/FR8T/EjSULYMyJLrEe9O/AqJA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=6pDdr1WQPVcBEZ0CWf/HwpGK+EnhUYfDquYwchpF1ms=; b=DwWyvQg4 CxBDrStHTmdWHfWcdimuqVfakKzsfj6pG+zbb/lWvsl04iVf87gyFiLWZhZwdiZm FGVjiBXmKTDGfTAdYyQa28Cfg3//o0+hlEFBeR2wVTxg7qeyjWL9ZGN05rH91Efb G1GNv4Xbci1mVBZjJdeaRNcuO3EDTQ0S69J8jQLq55z7IWuSYMnsC4MEKCax3Ltt J9z0vL/PsesrhcfwIXtekSiGmY3HePeLcFcKyEaRDSONQX6ZFpZ7fmkTx0wPPm/J /G+rxSleY3XL8Mb+DAvNMfGvsEo1AGXwkb20mFyfjO5Zcfdtri4dPCrqDjv1ARQb gl/fKdnGwz29jw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudeggedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 11 Sep 2021 18:06:00 -0400 (EDT) From: Samuel Holland To: u-boot@lists.denx.de Cc: Samuel Holland , Dario Binacchi , Jean-Jacques Hiblot , Patrick Delaunay , Pratyush Yadav , Simon Glass Subject: [PATCH 3/3] gpio: Factor out DT flag translation Date: Sat, 11 Sep 2021 17:05:53 -0500 Message-Id: <20210911220553.9427-4-samuel@sholland.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210911220553.9427-1-samuel@sholland.org> References: <20210911220553.9427-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.103.2 at phobos.denx.de X-Virus-Status: Clean The generic GPIO flags binding is shared across many drivers, some of which need their own xlate function. Factor out the flag translation code from gpio_xlate_offs_flags so it does not need to be duplicated. Signed-off-by: Samuel Holland --- drivers/gpio/gpio-uclass.c | 50 ++++++++++++++++++++++---------------- include/asm-generic/gpio.h | 8 ++++++ 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 6f2b1adfdec..b88b4290a45 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -185,6 +185,34 @@ int gpio_lookup_name(const char *name, struct udevice **devp, return 0; } +unsigned long gpio_flags_xlate(uint32_t arg) +{ + unsigned long flags = 0; + + if (arg & GPIO_ACTIVE_LOW) + flags |= GPIOD_ACTIVE_LOW; + + /* + * need to test 2 bits for gpio output binding: + * OPEN_DRAIN (0x6) = SINGLE_ENDED (0x2) | LINE_OPEN_DRAIN (0x4) + * OPEN_SOURCE (0x2) = SINGLE_ENDED (0x2) | LINE_OPEN_SOURCE (0x0) + */ + if (arg & GPIO_SINGLE_ENDED) { + if (arg & GPIO_LINE_OPEN_DRAIN) + flags |= GPIOD_OPEN_DRAIN; + else + flags |= GPIOD_OPEN_SOURCE; + } + + if (arg & GPIO_PULL_UP) + flags |= GPIOD_PULL_UP; + + if (arg & GPIO_PULL_DOWN) + flags |= GPIOD_PULL_DOWN; + + return flags; +} + int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc, struct ofnode_phandle_args *args) { @@ -200,27 +228,7 @@ int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc, if (args->args_count < 2) return 0; - desc->flags = 0; - if (args->args[1] & GPIO_ACTIVE_LOW) - desc->flags |= GPIOD_ACTIVE_LOW; - - /* - * need to test 2 bits for gpio output binding: - * OPEN_DRAIN (0x6) = SINGLE_ENDED (0x2) | LINE_OPEN_DRAIN (0x4) - * OPEN_SOURCE (0x2) = SINGLE_ENDED (0x2) | LINE_OPEN_SOURCE (0x0) - */ - if (args->args[1] & GPIO_SINGLE_ENDED) { - if (args->args[1] & GPIO_LINE_OPEN_DRAIN) - desc->flags |= GPIOD_OPEN_DRAIN; - else - desc->flags |= GPIOD_OPEN_SOURCE; - } - - if (args->args[1] & GPIO_PULL_UP) - desc->flags |= GPIOD_PULL_UP; - - if (args->args[1] & GPIO_PULL_DOWN) - desc->flags |= GPIOD_PULL_DOWN; + desc->flags = gpio_flags_xlate(args->args[1]); return 0; } diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index e33cde7abdd..911b11bc389 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h @@ -221,6 +221,14 @@ int gpio_requestf(unsigned gpio, const char *fmt, ...) struct fdtdec_phandle_args; +/** + * gpio_flags_xlate() - convert DT flags to internal flags + * + * This routine converts the GPIO_* flags from the generic DT binding to the + * GPIOD_* flags used internally. It can be called from driver xlate functions. + */ +unsigned long gpio_flags_xlate(uint32_t arg); + /** * gpio_xlate_offs_flags() - implementation for common use of dm_gpio_ops.xlate * -- 2.31.1