From patchwork Sun Nov 12 19:24:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 13453376 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0162AC4332F for ; Sun, 12 Nov 2023 19:25:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=CKC+bGZ74TZ5vUgn4c2CDYwh32YdSdxgLLW3kLXqV4k=; b=jP3vex8928r45y iGjVdchU5OI/h3rBlgz+KKFatU8ila7a8W3IWOQu1MpgRap2qmrk6TFG4PbZuMQIYOVUiiTPomHKo o1+KJotRqOQRbnu2PFIujI3FXbiXfJYFL+tsO+cUmrGM7HaV1M0GtX8I8/YUShQTjQ/dbIf9gdaHt 1FFUL7qvzdg3IeYkdF/8I3ggvSp+o/8KvUHDMwL1Ofj+XHS0yjqF56Z5fxZNZiFVYhhY8cHVsjKBM UOKvpwZyoO4LqhPaHo/aT1/Y33myofZEuw8FaJs2obNTV3qGHk51lX1ey3awqpacWFhfMHXqBHW8r XB+fb5Eowd2hs2ffvgRA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2G4n-00Ci4b-2q; Sun, 12 Nov 2023 19:24:57 +0000 Received: from mout.gmx.net ([212.227.15.18]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2G4l-00Ci44-13 for linux-arm-kernel@lists.infradead.org; Sun, 12 Nov 2023 19:24:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1699817087; x=1700421887; i=wahrenst@gmx.net; bh=bMwh/GFKRT3KTYXS4ogxMoKSBce3E3EizqgjsmyVGNo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=Bc0Yp2ucDMCvu3UVX4a9kVIhMigs9A8Qk5hEu2O4Wyuthy73WSoEDRVF25ZjhXzZ VY2ofeACT63ln+OncVfMTlWWlL/3mu5kNswyS+rwflSad1PYzTVsyj/v7KYF2b1dn zShyYJjxJm3x/elA9WNQU2Bu2T4pi7xARsFEWOLcO9xkUrpy2fiCR0uNtGJLjTncc LCV2rYCEMif5w0QFWRco8J0yF+e7VVTE/s5N4iR7EWUP3m/b7XhJDRkpRfuufIaxl 16QCU2e130vkTsXC/FB8aq3/QQEVgNeslVTE7OhqDbE9/j+cJozEOIZNYz+LuIRwM 1QWrK2/qwfv/PnpmOg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from stefanw-SCHENKER ([37.4.248.43]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MrhUE-1rh4WZ1SYG-00nlWV; Sun, 12 Nov 2023 20:24:47 +0100 From: Stefan Wahren To: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko , Shawn Guo , Sascha Hauer , kernel@pengutronix.de, Fabio Estevam Cc: linux-imx@nxp.com, linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, Stefan Wahren Subject: [PATCH] gpio: mxc: implement get_direction callback Date: Sun, 12 Nov 2023 20:24:28 +0100 Message-Id: <20231112192428.6832-1-wahrenst@gmx.net> X-Mail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8E9l3XXBTzEKWWEzeu49GmG1P2pvJcgh6+NkWbzdNkzR+3eyMzw 9STcLwHfaVRa0HA3YvZn3HlIzMmxAa/j6sfmgNsTmlESbe9Rvqdd7q+RYkPMTWvoiVS5NqIkX A2m00XAxEiU2lvpbzDY8Fsgx/r0Jx28cS5F0MuzqKmCt5wDDjYZFQkFF62auD4FA85hQB2qCT AJOwqQYStQR45REJ8r0FidTANNc= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231112_112455_668343_CCC87D19 X-CRM114-Status: GOOD ( 12.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org gpiolib's gpiod_get_direction() function returns an erro if .get_direction callback is not defined. The patch implements the callback for IMX platform which is useful for debugging and also the kernel docs about struct gpio_chip recommends it. Inspired by drivers/gpio/gpio-mxs.c Signed-off-by: Stefan Wahren --- drivers/gpio/gpio-mxc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) -- 2.34.1 diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c index 4cb455b2bdee..ad8a4c73d47b 100644 --- a/drivers/gpio/gpio-mxc.c +++ b/drivers/gpio/gpio-mxc.c @@ -418,6 +418,18 @@ static void mxc_update_irq_chained_handler(struct mxc_gpio_port *port, bool enab } } +static int mxc_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) +{ + struct mxc_gpio_port *port = gpiochip_get_data(gc); + u32 dir; + + dir = readl(port->base + GPIO_GDIR); + if (dir & BIT(offset)) + return GPIO_LINE_DIRECTION_OUT; + + return GPIO_LINE_DIRECTION_IN; +} + static int mxc_gpio_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -490,6 +502,7 @@ static int mxc_gpio_probe(struct platform_device *pdev) port->gc.request = mxc_gpio_request; port->gc.free = mxc_gpio_free; port->gc.to_irq = mxc_gpio_to_irq; + port->gc.get_direction = mxc_gpio_get_direction; port->gc.base = (pdev->id < 0) ? of_alias_get_id(np, "gpio") * 32 : pdev->id * 32;