From patchwork Wed Aug 28 13:09:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomas Paukrt X-Patchwork-Id: 1977868 X-Patchwork-Delegate: festevam@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=email.cz header.i=@email.cz header.a=rsa-sha256 header.s=szn20221014 header.b=p+HoD11c; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) 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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wv4Wx1y0Hz1yXd for ; Wed, 28 Aug 2024 23:10:05 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 21B5888800; Wed, 28 Aug 2024 15:10:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=email.cz 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; secure) header.d=email.cz header.i=@email.cz header.b="p+HoD11c"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B97A88884F; Wed, 28 Aug 2024 15:10:00 +0200 (CEST) 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mxe-1-afc.seznam.cz (mxe-1-afc.seznam.cz [IPv6:2a02:598:128:8a00::1000:afc]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8A500887B4 for ; Wed, 28 Aug 2024 15:09:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=email.cz Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=tomaspaukrt@email.cz Received: from email.seznam.cz by smtpc-mxe-85b96b7dcc-nmbd7 (smtpc-mxe-85b96b7dcc-nmbd7 [2a02:598:128:8a00::1000:afc]) id 756ad59b8b9e673175e45b83; Wed, 28 Aug 2024 15:09:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=email.cz; s=szn20221014; t=1724850592; bh=oYlB+eBcWaRlPM3rkWZdDcWELraGhWncZOhiATylKUQ=; h=Received:From:To:Cc:Subject:Date:Message-Id:Mime-Version:X-Mailer: Content-Type:Content-Transfer-Encoding; b=p+HoD11cCBT/mQoM8A4mNEPLNkbDERVBxhvSs/gHa6cUySUTo6eL15y02ISZjWrFh AT0Ry1FRXEfjuZn5rTFot8lgF0K+QNaR9nwfj6sSl40K2x7n0sCE82s7FxozGbAA0e l8RGwkxiOEsS5l7VWfKECIDfxle7qF2PovzgRYmNgIJXWpkK5CpfgdbF4eEa3tsRDP xMuXB+ETlseS5K7mWE0R1zQL2RatIaRJN4SkIj4Xf/HmVRi5Mp8BTh4W/utKR6AHz3 qq3fbGkr6MIgao16cwQ6mMJ5LSbhTTO1hdYDEXL0e/HbpWqzrdgR2g9fLBYH7BxhSr Mssxe/j2fFYtg== Received: from 215-143.ktuo.cz (215-143.ktuo.cz [82.144.143.215]) by email.seznam.cz (szn-UNKNOWN-unknown) with HTTP; Wed, 28 Aug 2024 15:09:48 +0200 (CEST) From: "Tomas Paukrt" To: Cc: , , , , , , , , Subject: =?utf-8?q?=5BPATCH_v4=5D_gpio=3A_mxc=5Fgpio=3A_fix_reading_state_of?= =?utf-8?q?_GPIO_pins_in_output_mode?= Date: Wed, 28 Aug 2024 15:09:48 +0200 (CEST) Message-Id: Mime-Version: 1.0 (szn-mime-2.1.61) X-Mailer: szn-UNKNOWN-unknown 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The PSR register works correctly for GPIO pins in input mode, but always returns 0 for GPIO pins in output mode unless the SION bit is set. The DR register should be used for GPIO pins in output mode to allow correct getting of previously set output value. Please note that the Linux gpio-mxc driver and the NXP U-Boot mxc_gpio driver already use the DR register for all GPIO pins in output mode: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=442b2494b17d1a4f0a14721580271eb23ebffd42 https://github.com/nxp-imx/uboot-imx/commit/4afc3f90943c6b117f79b66d2cd04e64f437b0c2 Signed-off-by: Tomas Paukrt Reviewed-by: Marek Vasut Reviewed-by: Fabio Estevam Tested-by: Fabio Estevam --- drivers/gpio/mxc_gpio.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c index cac6b32..28176e1 100644 --- a/drivers/gpio/mxc_gpio.c +++ b/drivers/gpio/mxc_gpio.c @@ -133,7 +133,10 @@ int gpio_get_value(unsigned gpio) regs = (struct gpio_regs *)gpio_ports[port]; - val = (readl(®s->gpio_psr) >> gpio) & 0x01; + if ((readl(®s->gpio_dir) >> gpio) & 0x01) + val = (readl(®s->gpio_dr) >> gpio) & 0x01; + else + val = (readl(®s->gpio_psr) >> gpio) & 0x01; return val; } @@ -210,7 +213,10 @@ static void mxc_gpio_bank_set_value(struct gpio_regs *regs, int offset, static int mxc_gpio_bank_get_value(struct gpio_regs *regs, int offset) { - return (readl(®s->gpio_psr) >> offset) & 0x01; + if ((readl(®s->gpio_dir) >> offset) & 0x01) + return (readl(®s->gpio_dr) >> offset) & 0x01; + else + return (readl(®s->gpio_psr) >> offset) & 0x01; } /* set GPIO pin 'gpio' as an input */