linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] USB: serial: cp210x: provide gpio valid mask
@ 2021-04-09 15:52 Johan Hovold
  2021-04-09 15:52 ` [PATCH 1/2] " Johan Hovold
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Johan Hovold @ 2021-04-09 15:52 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Andy Shevchenko, Pho Tran, Hung.Nguyen, Tung.Pham, linux-usb,
	linux-kernel

Use the new GPIO valid-mask feature to inform gpiolib which pins are
available for use instead of handling that in a request callback.
    
This also allows user space to figure out which pins are available
through the chardev interface without having to request each pin in
turn.

Johan


Johan Hovold (2):
  USB: serial: cp210x: provide gpio valid mask
  USB: serial: cp210x: add gpio-configuration debug printk

 drivers/usb/serial/cp210x.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

-- 
2.26.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] USB: serial: cp210x: provide gpio valid mask
  2021-04-09 15:52 [PATCH 0/2] USB: serial: cp210x: provide gpio valid mask Johan Hovold
@ 2021-04-09 15:52 ` Johan Hovold
  2021-04-09 15:52 ` [PATCH 2/2] USB: serial: cp210x: add gpio-configuration debug printk Johan Hovold
  2021-04-09 16:23 ` [PATCH 0/2] USB: serial: cp210x: provide gpio valid mask Andy Shevchenko
  2 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2021-04-09 15:52 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Andy Shevchenko, Pho Tran, Hung.Nguyen, Tung.Pham, linux-usb,
	linux-kernel

Use the new GPIO valid-mask feature to inform gpiolib which pins are
available for use instead of handling that in a request callback.

This also allows user space to figure out which pins are available
through the chardev interface without having to request each pin in
turn.

Note that the return value when requesting an unavailable pin will now
be -EINVAL instead of -ENODEV.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/cp210x.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index a373cd63b3a4..ceb3a656a075 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -1410,17 +1410,6 @@ static void cp210x_break_ctl(struct tty_struct *tty, int break_state)
 }
 
 #ifdef CONFIG_GPIOLIB
-static int cp210x_gpio_request(struct gpio_chip *gc, unsigned int offset)
-{
-	struct usb_serial *serial = gpiochip_get_data(gc);
-	struct cp210x_serial_private *priv = usb_get_serial_data(serial);
-
-	if (priv->gpio_altfunc & BIT(offset))
-		return -ENODEV;
-
-	return 0;
-}
-
 static int cp210x_gpio_get(struct gpio_chip *gc, unsigned int gpio)
 {
 	struct usb_serial *serial = gpiochip_get_data(gc);
@@ -1549,6 +1538,18 @@ static int cp210x_gpio_set_config(struct gpio_chip *gc, unsigned int gpio,
 	return -ENOTSUPP;
 }
 
+static int cp210x_gpio_init_valid_mask(struct gpio_chip *gc,
+		unsigned long *valid_mask, unsigned int ngpios)
+{
+	struct usb_serial *serial = gpiochip_get_data(gc);
+	struct cp210x_serial_private *priv = usb_get_serial_data(serial);
+	unsigned long altfunc_mask = priv->gpio_altfunc;
+
+	bitmap_complement(valid_mask, &altfunc_mask, ngpios);
+
+	return 0;
+}
+
 /*
  * This function is for configuring GPIO using shared pins, where other signals
  * are made unavailable by configuring the use of GPIO. This is believed to be
@@ -1786,13 +1787,13 @@ static int cp210x_gpio_init(struct usb_serial *serial)
 		return result;
 
 	priv->gc.label = "cp210x";
-	priv->gc.request = cp210x_gpio_request;
 	priv->gc.get_direction = cp210x_gpio_direction_get;
 	priv->gc.direction_input = cp210x_gpio_direction_input;
 	priv->gc.direction_output = cp210x_gpio_direction_output;
 	priv->gc.get = cp210x_gpio_get;
 	priv->gc.set = cp210x_gpio_set;
 	priv->gc.set_config = cp210x_gpio_set_config;
+	priv->gc.init_valid_mask = cp210x_gpio_init_valid_mask;
 	priv->gc.owner = THIS_MODULE;
 	priv->gc.parent = &serial->interface->dev;
 	priv->gc.base = -1;
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] USB: serial: cp210x: add gpio-configuration debug printk
  2021-04-09 15:52 [PATCH 0/2] USB: serial: cp210x: provide gpio valid mask Johan Hovold
  2021-04-09 15:52 ` [PATCH 1/2] " Johan Hovold
@ 2021-04-09 15:52 ` Johan Hovold
  2021-04-09 16:22   ` Andy Shevchenko
  2021-04-09 16:23 ` [PATCH 0/2] USB: serial: cp210x: provide gpio valid mask Andy Shevchenko
  2 siblings, 1 reply; 7+ messages in thread
From: Johan Hovold @ 2021-04-09 15:52 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Andy Shevchenko, Pho Tran, Hung.Nguyen, Tung.Pham, linux-usb,
	linux-kernel

Add a debug printk to dump the GPIO configuration stored in EEPROM
during probe.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/cp210x.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index ceb3a656a075..ee595d1bea0a 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -1543,10 +1543,16 @@ static int cp210x_gpio_init_valid_mask(struct gpio_chip *gc,
 {
 	struct usb_serial *serial = gpiochip_get_data(gc);
 	struct cp210x_serial_private *priv = usb_get_serial_data(serial);
+	struct device *dev = &serial->interface->dev;
 	unsigned long altfunc_mask = priv->gpio_altfunc;
 
 	bitmap_complement(valid_mask, &altfunc_mask, ngpios);
 
+	if (bitmap_empty(valid_mask, ngpios))
+		dev_dbg(dev, "no pin configured for GPIO\n");
+	else
+		dev_dbg(dev, "GPIO.%*pbl configured for GPIO\n", ngpios,
+				valid_mask);
 	return 0;
 }
 
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] USB: serial: cp210x: add gpio-configuration debug printk
  2021-04-09 15:52 ` [PATCH 2/2] USB: serial: cp210x: add gpio-configuration debug printk Johan Hovold
@ 2021-04-09 16:22   ` Andy Shevchenko
  2021-04-09 16:32     ` Johan Hovold
  0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2021-04-09 16:22 UTC (permalink / raw)
  To: Johan Hovold, Bartosz Golaszewski
  Cc: Pho Tran, Hung.Nguyen, Tung.Pham, USB, Linux Kernel Mailing List

On Fri, Apr 9, 2021 at 6:52 PM Johan Hovold <johan@kernel.org> wrote:
>
> Add a debug printk to dump the GPIO configuration stored in EEPROM
> during probe.
>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/usb/serial/cp210x.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
> index ceb3a656a075..ee595d1bea0a 100644
> --- a/drivers/usb/serial/cp210x.c
> +++ b/drivers/usb/serial/cp210x.c
> @@ -1543,10 +1543,16 @@ static int cp210x_gpio_init_valid_mask(struct gpio_chip *gc,
>  {
>         struct usb_serial *serial = gpiochip_get_data(gc);
>         struct cp210x_serial_private *priv = usb_get_serial_data(serial);
> +       struct device *dev = &serial->interface->dev;
>         unsigned long altfunc_mask = priv->gpio_altfunc;
>
>         bitmap_complement(valid_mask, &altfunc_mask, ngpios);
>
> +       if (bitmap_empty(valid_mask, ngpios))
> +               dev_dbg(dev, "no pin configured for GPIO\n");

Shouldn't we drop the GPIO device completely in such a case?
Bart, wouldn't it be a good idea for GPIO library to do something like
this on driver's behalf?

> +       else
> +               dev_dbg(dev, "GPIO.%*pbl configured for GPIO\n", ngpios,
> +                               valid_mask);

A nit-pick:
I would change GPIO -> pin in the second message in the first occurrence.

>         return 0;
>  }
>
> --
> 2.26.3
>


-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] USB: serial: cp210x: provide gpio valid mask
  2021-04-09 15:52 [PATCH 0/2] USB: serial: cp210x: provide gpio valid mask Johan Hovold
  2021-04-09 15:52 ` [PATCH 1/2] " Johan Hovold
  2021-04-09 15:52 ` [PATCH 2/2] USB: serial: cp210x: add gpio-configuration debug printk Johan Hovold
@ 2021-04-09 16:23 ` Andy Shevchenko
  2021-04-12 10:00   ` Johan Hovold
  2 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2021-04-09 16:23 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Pho Tran, Hung.Nguyen, Tung.Pham, USB, Linux Kernel Mailing List

On Fri, Apr 9, 2021 at 6:52 PM Johan Hovold <johan@kernel.org> wrote:
>
> Use the new GPIO valid-mask feature to inform gpiolib which pins are
> available for use instead of handling that in a request callback.
>
> This also allows user space to figure out which pins are available
> through the chardev interface without having to request each pin in
> turn.

Thanks! I like the series.
Independently on reaction on my comments:
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Johan
>
>
> Johan Hovold (2):
>   USB: serial: cp210x: provide gpio valid mask
>   USB: serial: cp210x: add gpio-configuration debug printk
>
>  drivers/usb/serial/cp210x.c | 31 +++++++++++++++++++------------
>  1 file changed, 19 insertions(+), 12 deletions(-)
>
> --
> 2.26.3
>


-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] USB: serial: cp210x: add gpio-configuration debug printk
  2021-04-09 16:22   ` Andy Shevchenko
@ 2021-04-09 16:32     ` Johan Hovold
  0 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2021-04-09 16:32 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Bartosz Golaszewski, Pho Tran, Hung.Nguyen, Tung.Pham, USB,
	Linux Kernel Mailing List

On Fri, Apr 09, 2021 at 07:22:26PM +0300, Andy Shevchenko wrote:
> On Fri, Apr 9, 2021 at 6:52 PM Johan Hovold <johan@kernel.org> wrote:
> >
> > Add a debug printk to dump the GPIO configuration stored in EEPROM
> > during probe.
> >
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---
> >  drivers/usb/serial/cp210x.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
> > index ceb3a656a075..ee595d1bea0a 100644
> > --- a/drivers/usb/serial/cp210x.c
> > +++ b/drivers/usb/serial/cp210x.c
> > @@ -1543,10 +1543,16 @@ static int cp210x_gpio_init_valid_mask(struct gpio_chip *gc,
> >  {
> >         struct usb_serial *serial = gpiochip_get_data(gc);
> >         struct cp210x_serial_private *priv = usb_get_serial_data(serial);
> > +       struct device *dev = &serial->interface->dev;
> >         unsigned long altfunc_mask = priv->gpio_altfunc;
> >
> >         bitmap_complement(valid_mask, &altfunc_mask, ngpios);
> >
> > +       if (bitmap_empty(valid_mask, ngpios))
> > +               dev_dbg(dev, "no pin configured for GPIO\n");
> 
> Shouldn't we drop the GPIO device completely in such a case?

I considered it when we first added support for GPIOs to this driver but
decided not to. The reason being that we want to to tell user-space that
the device has gpio capability even if the GPIOs are currently muxed (in
EEPROM) for other functionality.

> Bart, wouldn't it be a good idea for GPIO library to do something like
> this on driver's behalf?

I'd say this is mostly useful for hotpluggable devices with EEPROM
configuration and is probably best handled by the drivers.

> > +       else
> > +               dev_dbg(dev, "GPIO.%*pbl configured for GPIO\n", ngpios,
> > +                               valid_mask);
> 
> A nit-pick:
> I would change GPIO -> pin in the second message in the first occurrence.

"GPIO.n" are the actual pin names from the datasheet (cf. ftdi_sio which
use "CBUSn" here). It's just a debug statement anyway.

Johan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] USB: serial: cp210x: provide gpio valid mask
  2021-04-09 16:23 ` [PATCH 0/2] USB: serial: cp210x: provide gpio valid mask Andy Shevchenko
@ 2021-04-12 10:00   ` Johan Hovold
  0 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2021-04-12 10:00 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Pho Tran, Hung.Nguyen, Tung.Pham, USB, Linux Kernel Mailing List

On Fri, Apr 09, 2021 at 07:23:11PM +0300, Andy Shevchenko wrote:
> On Fri, Apr 9, 2021 at 6:52 PM Johan Hovold <johan@kernel.org> wrote:
> >
> > Use the new GPIO valid-mask feature to inform gpiolib which pins are
> > available for use instead of handling that in a request callback.
> >
> > This also allows user space to figure out which pins are available
> > through the chardev interface without having to request each pin in
> > turn.
> 
> Thanks! I like the series.
> Independently on reaction on my comments:
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

Thanks for reviewing. Now applied.

Johan

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-04-12 10:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-09 15:52 [PATCH 0/2] USB: serial: cp210x: provide gpio valid mask Johan Hovold
2021-04-09 15:52 ` [PATCH 1/2] " Johan Hovold
2021-04-09 15:52 ` [PATCH 2/2] USB: serial: cp210x: add gpio-configuration debug printk Johan Hovold
2021-04-09 16:22   ` Andy Shevchenko
2021-04-09 16:32     ` Johan Hovold
2021-04-09 16:23 ` [PATCH 0/2] USB: serial: cp210x: provide gpio valid mask Andy Shevchenko
2021-04-12 10:00   ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).