From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 4C455C433F5 for ; Tue, 5 Apr 2022 10:29:51 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 220BC83AEF; Tue, 5 Apr 2022 12:29:49 +0200 (CEST) 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="Zp9VZ9Ay"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 534A7803F1; Tue, 5 Apr 2022 12:29:47 +0200 (CEST) Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) (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 0F66583AEF for ; Tue, 5 Apr 2022 12:29:32 +0200 (CEST) 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-ej1-x634.google.com with SMTP id bg10so25774061ejb.4 for ; Tue, 05 Apr 2022 03:29:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=message-id:subject:from:reply-to:to:cc:date:user-agent:mime-version :content-transfer-encoding; bh=OrXIcGPTqRccxSGsAYEzMFrEmUN1G0E4Cp/vaDhpszo=; b=Zp9VZ9Aye+C+Nt8AxXM2Gpd0YquXUzgR/47y24777sf0qgLaQc01g0LqNkX5je8ld4 cbctVHk0WrALE1o6cFWONmF9elLEJMn1zrlATGeWK7Fl0e86t8J+NxlcsIMHIsLgAUla M1sZqRdFRp0g8GzjjcdZxXoZZ6PfS9khvnF1XbIEOarKQd5kvivnciHmujoQZxh1OtpG dAyauo9oFbbfj1uYAC0dJoUCpB+hemTRC7GMw6sKdbKP+onWaRsM8+ZQzRbbeHGqXVEt jMHMv/w6YJXGWwKH78953EyJq11BD1gF5TxohQv9/y9KU/eVUIWtsCrVXPSKsF9u16XM f5dQ== 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:cc:date :user-agent:mime-version:content-transfer-encoding; bh=OrXIcGPTqRccxSGsAYEzMFrEmUN1G0E4Cp/vaDhpszo=; b=oUl/2kmhKT6+ugPySRHYO4fwm0+jiI889eV0S04armZaZREikjs79Ho05pJviYUdoK Q9kA1dfS+6amCiuF3fDgS41pCNPqHNXr9BRCWXzXdpKiCQvqMtcMRZM86BtRw6NhcJfs X4b4BpKys54lVzk0Iy+zIjbs8dUHzHmaj2E/x8czph7ynZ9v6v7UsfXghqTzk/sskDSI X8yyIHTeoGk8D8lRnaGn5dQOTDezM9xoWXhVQ0Ki09tf4331MjA1DsgPdKMaYDR3xZnD 6Yvy0VomhF4uO/WAwIKy3U4zRwgf0F5fxyvsRLicKIGbthRxTuZO17tXei4dipE4QzjO JIKQ== X-Gm-Message-State: AOAM532qfH1b8EnZcr9t4t35ZkoLJ6RyKyBnkCAiy7EDNzHtjO7rTMhj kv36Sbwm2wScQll5wdmEmGE= X-Google-Smtp-Source: ABdhPJx5ag+6/DXSzIT1wXOBtfGHJ64oXm8p0y68JF5D/whHX38r9huJa/Zfq7oQ/3uRFf0CEl5Cyw== X-Received: by 2002:a17:907:7da8:b0:6e0:5b94:5ed8 with SMTP id oz40-20020a1709077da800b006e05b945ed8mr2699586ejc.312.1649154571582; Tue, 05 Apr 2022 03:29:31 -0700 (PDT) Received: from mars.fritz.box ([2a02:8070:bb0:8700:3e7c:3fff:fe20:2cae]) by smtp.gmail.com with ESMTPSA id gw15-20020a170906f14f00b006e7eec47373sm2496577ejb.16.2022.04.05.03.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 03:29:31 -0700 (PDT) Message-ID: <9be9017e32432390c565202b1e61a81eb66a6b27.camel@googlemail.com> Subject: [RESEND PATCH] gpio: rgpio2p: Enhance reading of GPIO pin value From: Christoph Fritz To: Stefano Babic , Tom Rini Cc: u-boot , Peng Fan , Fabio Estevam Date: Tue, 05 Apr 2022 12:29:30 +0200 Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 Reviewed-by: Fabio Estevam --- 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) -- 2.30.2