From patchwork Mon Jan 24 20:38:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Fritz X-Patchwork-Id: 1583682 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlemail.com header.i=@googlemail.com header.a=rsa-sha256 header.s=20210112 header.b=oD8zbtq4; dkim-atps=neutral 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=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JjMTX3lxVz9s1l for ; Tue, 25 Jan 2022 07:46:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 04D4982A65; Mon, 24 Jan 2022 21:46:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=googlemail.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=googlemail.com header.i=@googlemail.com header.b="oD8zbtq4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 39AFB83035; Mon, 24 Jan 2022 21:38:08 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) (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 A5D2880FD6 for ; Mon, 24 Jan 2022 21:38:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=googlemail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=chf.fritz@googlemail.com Received: by mail-wm1-x336.google.com with SMTP id v123so23788891wme.2 for ; Mon, 24 Jan 2022 12:38:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=message-id:subject:from:reply-to:to:date:user-agent:mime-version :content-transfer-encoding; bh=HMSY3j1Pl4imi2xbvezH/MHN6U+EGsppQ5fm6+/8OLg=; b=oD8zbtq4JwaBxEw6jngXahfAfxSu7F4QMXf+ZwYHsu+CvcqC+lTn4DFxIAgOLkVKFn 7ISyJd81v9K7cXwHErqpZeZ40RRQz5rabZFQYP3uGMnmHfAQPrOxj+mACQN12VoXNVvt s2mdp+iP2SzTHHrQlN99C1MOy4giwxmtShOAvD09b8FnkgWE5Z4J2b1lzzoYUYfosdJD h51CS1PuXpV7OT3/OCB7ShP//IMllxZgUTrp3CUP2jjQ+6CxyeHEeDSZkqnYhMeS6KfN +l5cfXUMmptJsfjhKEhClbN6FtPpO4b8Q7Q+7sTFVbHU/vMc1D/HZ096JWgDdh2f88yl fahQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:reply-to:to:date :user-agent:mime-version:content-transfer-encoding; bh=HMSY3j1Pl4imi2xbvezH/MHN6U+EGsppQ5fm6+/8OLg=; b=r4+x0J0nzW3JTfcNGHKf3Y29k546MFiEYeL+m+iPfL9wpZ2hpjvmKlSb/rt4JuxA4X VytkDmOJ8rEKKgWXD43A9GuoQQA89/QUjpLHa3fbBvLpOalb214aga5IBGg14NuUOPE8 349MHh4ecD9UHdFOcn3SgyvUawSY8cJD8H/ian93BgCRiKeC6PbHw00Mg2OPO1xtkv5W x18Ahc7+RbmsMo6uLoZMLk7LsimwYfH6jgDfmPytlbs71BmCm07NbAfWSzlwwBXWRjii aQavcpBb6Ver/OBzLZfLPe8YrxD4bGOeQEZz6t2K8956wqFq46wW1NKdLiO7ZSwT+x+n vsnw== X-Gm-Message-State: AOAM533UX8F5fEQX5vtEopsgQwXAK6HMALXsr/X35HM8HxxNYnlNbJaA 7QncVgdFBfYVCqGV1KE1rqMDVawFTUc= X-Google-Smtp-Source: ABdhPJynweM8NPXrefU7TYd8fOjwmvtq30dGQClXVMgqOW6c53CWUyXMKx4iZU8QlTS1NRUiAMyIOA== X-Received: by 2002:a05:600c:3b0d:: with SMTP id m13mr85905wms.40.1643056685256; Mon, 24 Jan 2022 12:38:05 -0800 (PST) Received: from mars.fritz.box ([2a02:8070:bb0:8700:3e7c:3fff:fe20:2cae]) by smtp.gmail.com with ESMTPSA id z5sm466687wmp.10.2022.01.24.12.38.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 12:38:04 -0800 (PST) Message-ID: <1fe3fadd8f669058ad737c32b7af5d2c6ccb189e.camel@googlemail.com> Subject: [PATCH] gpio: rgpio2p: Enhance reading of GPIO pin value From: Christoph Fritz To: u-boot@lists.denx.de Date: Mon, 24 Jan 2022 21:38:04 +0100 User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 24 Jan 2022 21:46:17 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: chf.fritz@googlemail.com Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Add support for reading GPIO pin value when function is output. With this patch applied, gpio toggle command is working. Signed-off-by: Christoph Fritz Reviewed-by: Peng Fan --- drivers/gpio/imx_rgpio2p.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/imx_rgpio2p.c b/drivers/gpio/imx_rgpio2p.c index 0e2874ca95c..175e460aff5 100644 --- a/drivers/gpio/imx_rgpio2p.c +++ b/drivers/gpio/imx_rgpio2p.c @@ -39,6 +39,14 @@ static int imx_rgpio2p_is_output(struct gpio_regs *regs, int offset) return val & (1 << offset) ? 1 : 0; } +static int imx_rgpio2p_bank_get_direction(struct gpio_regs *regs, int offset) +{ + if ((readl(®s->gpio_pddr) >> offset) & 0x01) + return IMX_RGPIO2P_DIRECTION_OUT; + + return IMX_RGPIO2P_DIRECTION_IN; +} + static void imx_rgpio2p_bank_direction(struct gpio_regs *regs, int offset, enum imx_rgpio2p_direction direction) { @@ -67,7 +75,11 @@ static void imx_rgpio2p_bank_set_value(struct gpio_regs *regs, int offset, static int imx_rgpio2p_bank_get_value(struct gpio_regs *regs, int offset) { - return (readl(®s->gpio_pdir) >> offset) & 0x01; + if (imx_rgpio2p_bank_get_direction(regs, offset) == + IMX_RGPIO2P_DIRECTION_IN) + return (readl(®s->gpio_pdir) >> offset) & 0x01; + + return (readl(®s->gpio_pdor) >> offset) & 0x01; } static int imx_rgpio2p_direction_input(struct udevice *dev, unsigned offset)