From: Stefan Wahren <wahrenst@gmx.net> To: Linus Walleij <linus.walleij@linaro.org>, Bartosz Golaszewski <brgl@bgdev.pl>, Andy Shevchenko <andy@kernel.org>, Shawn Guo <shawnguo@kernel.org>, Sascha Hauer <s.hauer@pengutronix.de>, kernel@pengutronix.de, Fabio Estevam <festevam@gmail.com> Cc: linux-imx@nxp.com, linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, Stefan Wahren <wahrenst@gmx.net> Subject: [PATCH] gpio: mxc: implement get_direction callback Date: Sun, 12 Nov 2023 20:24:28 +0100 [thread overview] Message-ID: <20231112192428.6832-1-wahrenst@gmx.net> (raw) 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 <wahrenst@gmx.net> --- drivers/gpio/gpio-mxc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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; -- 2.34.1
WARNING: multiple messages have this Message-ID (diff)
From: Stefan Wahren <wahrenst@gmx.net> To: Linus Walleij <linus.walleij@linaro.org>, Bartosz Golaszewski <brgl@bgdev.pl>, Andy Shevchenko <andy@kernel.org>, Shawn Guo <shawnguo@kernel.org>, Sascha Hauer <s.hauer@pengutronix.de>, kernel@pengutronix.de, Fabio Estevam <festevam@gmail.com> Cc: linux-imx@nxp.com, linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, Stefan Wahren <wahrenst@gmx.net> Subject: [PATCH] gpio: mxc: implement get_direction callback Date: Sun, 12 Nov 2023 20:24:28 +0100 [thread overview] Message-ID: <20231112192428.6832-1-wahrenst@gmx.net> (raw) 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 <wahrenst@gmx.net> --- drivers/gpio/gpio-mxc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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; -- 2.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2023-11-12 19:25 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-11-12 19:24 Stefan Wahren [this message] 2023-11-12 19:24 ` [PATCH] gpio: mxc: implement get_direction callback Stefan Wahren 2023-11-13 7:04 ` Sascha Hauer 2023-11-13 7:04 ` Sascha Hauer 2023-11-13 12:29 ` Stefan Wahren 2023-11-13 12:29 ` Stefan Wahren
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231112192428.6832-1-wahrenst@gmx.net \ --to=wahrenst@gmx.net \ --cc=andy@kernel.org \ --cc=brgl@bgdev.pl \ --cc=festevam@gmail.com \ --cc=kernel@pengutronix.de \ --cc=linus.walleij@linaro.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-gpio@vger.kernel.org \ --cc=linux-imx@nxp.com \ --cc=s.hauer@pengutronix.de \ --cc=shawnguo@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.