diff mbox series

[v2,2/2] gpio: vf610: add get_direction() support

Message ID 20240801093028.732338-3-haibo.chen@nxp.com
State New
Headers show
Series few small change for gpio-vf610 | expand

Commit Message

Bough Chen Aug. 1, 2024, 9:30 a.m. UTC
From: Haibo Chen <haibo.chen@nxp.com>

For IP which do not contain PDDR, currently use the pinmux API
pinctrl_gpio_direction_input() to config the output/input, pinmux
currently do not support get_direction(). So here add the GPIO
get_direction() support only for the IP which has Port Data
Direction Register (PDDR).

Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
---
 drivers/gpio/gpio-vf610.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Stefan Wahren Aug. 2, 2024, 1:22 p.m. UTC | #1
Hi Haibo,

Am 01.08.24 um 11:30 schrieb haibo.chen@nxp.com:
> From: Haibo Chen <haibo.chen@nxp.com>
>
> For IP which do not contain PDDR, currently use the pinmux API
> pinctrl_gpio_direction_input() to config the output/input, pinmux
> currently do not support get_direction(). So here add the GPIO
> get_direction() support only for the IP which has Port Data
> Direction Register (PDDR).
just a question about how things work:

fsl,imx7ulp-gpio and i.MX93 have PDDR, so GPIO get_direction is handled
in gpio-vf610 driver
fsl,vf610-gpio doesn't have PDDR, so all GPIO direction stuff is handled
in pinctrl-vf610 driver

Is this correct?

Best regards
Bough Chen Aug. 5, 2024, 2:08 a.m. UTC | #2
> -----Original Message-----
> From: Stefan Wahren <wahrenst@gmx.net>
> Sent: 2024年8月2日 21:22
> To: Bough Chen <haibo.chen@nxp.com>; linus.walleij@linaro.org;
> brgl@bgdev.pl
> Cc: linux-gpio@vger.kernel.org; linux-kernel@vger.kernel.org;
> imx@lists.linux.dev
> Subject: Re: [PATCH v2 2/2] gpio: vf610: add get_direction() support
> 
> Hi Haibo,
> 
> Am 01.08.24 um 11:30 schrieb haibo.chen@nxp.com:
> > From: Haibo Chen <haibo.chen@nxp.com>
> >
> > For IP which do not contain PDDR, currently use the pinmux API
> > pinctrl_gpio_direction_input() to config the output/input, pinmux
> > currently do not support get_direction(). So here add the GPIO
> > get_direction() support only for the IP which has Port Data Direction
> > Register (PDDR).
> just a question about how things work:
> 
> fsl,imx7ulp-gpio and i.MX93 have PDDR, so GPIO get_direction is handled in
> gpio-vf610 driver fsl,vf610-gpio doesn't have PDDR, so all GPIO direction stuff is
> handled in pinctrl-vf610 driver
> 
> Is this correct?

Yes, correct. vf610_pmx_gpio_set_direction() did that.

Best Regards
Haibo Chen

> 
> Best regards
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index db68d8541597..27eff741fe9a 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -151,6 +151,19 @@  static int vf610_gpio_direction_output(struct gpio_chip *chip, unsigned int gpio
 	return pinctrl_gpio_direction_output(chip, gpio);
 }
 
+static int vf610_gpio_get_direction(struct gpio_chip *gc, unsigned int gpio)
+{
+	struct vf610_gpio_port *port = gpiochip_get_data(gc);
+	u32 mask = BIT(gpio);
+
+	mask &= vf610_gpio_readl(port->gpio_base + GPIO_PDDR);
+
+	if (mask)
+		return GPIO_LINE_DIRECTION_OUT;
+
+	return GPIO_LINE_DIRECTION_IN;
+}
+
 static void vf610_gpio_irq_handler(struct irq_desc *desc)
 {
 	struct vf610_gpio_port *port =
@@ -362,6 +375,12 @@  static int vf610_gpio_probe(struct platform_device *pdev)
 	gc->get = vf610_gpio_get;
 	gc->direction_output = vf610_gpio_direction_output;
 	gc->set = vf610_gpio_set;
+	/*
+	 * only IP has Port Data Direction Register(PDDR) can
+	 * support get direction
+	 */
+	if (port->sdata->have_paddr)
+		gc->get_direction = vf610_gpio_get_direction;
 
 	/* Mask all GPIO interrupts */
 	for (i = 0; i < gc->ngpio; i++)