* [PATCH] gpio: vf610: add get_direction() support
@ 2024-07-22 6:28 haibo.chen
2024-07-22 10:32 ` Stefan Wahren
0 siblings, 1 reply; 4+ messages in thread
From: haibo.chen @ 2024-07-22 6:28 UTC (permalink / raw)
To: linus.walleij, brgl; +Cc: linux-gpio, linux-kernel, haibo.chen, imx, wahrenst
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(+)
diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 07e5e6323e86..08ca8377b19c 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 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);
+ unsigned long 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++)
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] gpio: vf610: add get_direction() support
2024-07-22 6:28 [PATCH] gpio: vf610: add get_direction() support haibo.chen
@ 2024-07-22 10:32 ` Stefan Wahren
2024-07-23 2:45 ` Bough Chen
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Wahren @ 2024-07-22 10:32 UTC (permalink / raw)
To: haibo.chen, linus.walleij, brgl; +Cc: linux-gpio, linux-kernel, imx
Hi Haibo,
Am 22.07.24 um 08:28 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).
>
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
> ---
> drivers/gpio/gpio-vf610.c | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
> index 07e5e6323e86..08ca8377b19c 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 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);
> + unsigned long mask = BIT(gpio);
thanks for sending this patch. I'm fine with this patch, but could we
use u32 to make it clear about the range of the mask?
Regards
> +
> + 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++)
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] gpio: vf610: add get_direction() support
2024-07-22 10:32 ` Stefan Wahren
@ 2024-07-23 2:45 ` Bough Chen
2024-07-29 16:27 ` Stefan Wahren
0 siblings, 1 reply; 4+ messages in thread
From: Bough Chen @ 2024-07-23 2:45 UTC (permalink / raw)
To: Stefan Wahren, linus.walleij@linaro.org, brgl@bgdev.pl
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
imx@lists.linux.dev
> -----Original Message-----
> From: Stefan Wahren <wahrenst@gmx.net>
> Sent: 2024年7月22日 18:32
> 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] gpio: vf610: add get_direction() support
>
> Hi Haibo,
>
> Am 22.07.24 um 08:28 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).
> >
> > Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
> > ---
> > drivers/gpio/gpio-vf610.c | 19 +++++++++++++++++++
> > 1 file changed, 19 insertions(+)
> >
> > diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
> > index 07e5e6323e86..08ca8377b19c 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 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);
> > + unsigned long mask = BIT(gpio);
> thanks for sending this patch. I'm fine with this patch, but could we use u32 to
> make it clear about the range of the mask?
Yes, u32 seems more clear here, but I notice all other place use unsigned long, so I keep the same code style.
I go through the history of this driver, seems no specific explanation about the unsigned long.
If anyone know the reason, please comment.
Best Regards
Haibo Chen
>
> Regards
> > +
> > + 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++)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpio: vf610: add get_direction() support
2024-07-23 2:45 ` Bough Chen
@ 2024-07-29 16:27 ` Stefan Wahren
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Wahren @ 2024-07-29 16:27 UTC (permalink / raw)
To: Bough Chen, linus.walleij@linaro.org, brgl@bgdev.pl
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
imx@lists.linux.dev
Am 23.07.24 um 04:45 schrieb Bough Chen:
>> -----Original Message-----
>> From: Stefan Wahren <wahrenst@gmx.net>
>> Sent: 2024年7月22日 18:32
>> 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] gpio: vf610: add get_direction() support
>>
>> Hi Haibo,
>>
>> Am 22.07.24 um 08:28 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).
>>>
>>> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
>>> ---
>>> drivers/gpio/gpio-vf610.c | 19 +++++++++++++++++++
>>> 1 file changed, 19 insertions(+)
>>>
>>> diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
>>> index 07e5e6323e86..08ca8377b19c 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 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);
>>> + unsigned long mask = BIT(gpio);
>> thanks for sending this patch. I'm fine with this patch, but could we use u32 to
>> make it clear about the range of the mask?
> Yes, u32 seems more clear here, but I notice all other place use unsigned long, so I keep the same code style.
> I go through the history of this driver, seems no specific explanation about the unsigned long.
I understand, but i don't think there is a reason for using unsigned
long. So maybe this is a good opportunity to clean this up.
Regards
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-07-29 16:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-22 6:28 [PATCH] gpio: vf610: add get_direction() support haibo.chen
2024-07-22 10:32 ` Stefan Wahren
2024-07-23 2:45 ` Bough Chen
2024-07-29 16:27 ` Stefan Wahren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox