Re: [RESEND PATCH v4 2/3] usb: serial: xr_serial: Add gpiochip support

From: Johan Hovold
Date: Thu Aug 06 2020 - 12:49:20 EST


On Sun, Jul 26, 2020 at 09:22:23PM +0530, Manivannan Sadhasivam wrote:
> On Wed, Jul 01, 2020 at 03:02:06PM +0200, Johan Hovold wrote:
> > On Sun, Jun 07, 2020 at 09:53:49PM +0530, Manivannan Sadhasivam wrote:
> > > Add gpiochip support for Maxlinear/Exar USB to serial converter
> > > for controlling the available gpios.
> > >
> > > Inspired from cp210x usb to serial converter driver.
> > >
> > > Cc: Linus Walleij <linus.walleij@xxxxxxxxxx>
> > > Cc: linux-gpio@xxxxxxxxxxxxxxx
> > > Reviewed-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
> > > Signed-off-by: Manivannan Sadhasivam <mani@xxxxxxxxxx>
> > > ---
> > > drivers/usb/serial/xr_serial.c | 209 ++++++++++++++++++++++++++++++++-
> > > 1 file changed, 208 insertions(+), 1 deletion(-)

> > > @@ -390,6 +408,13 @@ static void xr_set_flow_mode(struct tty_struct *tty,
> > > */
> > > gpio_mode &= ~UART_MODE_GPIO_MASK;
> > > if (cflag & CRTSCTS) {
> > > +#ifdef CONFIG_GPIOLIB
> > > + /* Check if the CTS/RTS pins are occupied */
> > > + if (port_priv->pin_status[GPIO_RTS] ||
> > > + port_priv->pin_status[GPIO_CTS])
> > > + return;
> > > +#endif
> >
> > You cannot just bail out as this could leave software flow enabled etc.
> >
> > You also need to claim these pins once at open or leave them be. We
> > don't want CRTSCTS to suddenly start toggling because a pin is released
> > by gpiolib.
> >
> > That is, determine who owns each pin at open() and keep it that way till
> > close() (by setting some flags at open).
> >
> > > +
> > > dev_dbg(&port->dev, "Enabling hardware flow ctrl\n");
> > > flow = UART_FLOW_MODE_HW;
> > > gpio_mode |= UART_MODE_RTS_CTS;
> > > @@ -497,6 +522,17 @@ static int xr_tiocmset_port(struct usb_serial_port *port,
> > > u8 gpio_set = 0;
> > > u8 gpio_clr = 0;
> > >
> > > +#ifdef CONFIG_GPIOLIB
> > > + /* Check if the RTS/DTR pins are occupied */
> > > + if (set & TIOCM_RTS || clear & TIOCM_RTS)
> > > + if (port_priv->pin_status[GPIO_RTS])
> > > + return -EBUSY;
> > > +
> > > + if (set & TIOCM_DTR || clear & TIOCM_DTR)
> > > + if (port_priv->pin_status[GPIO_DTR])
> > > + return -EBUSY;
> > > +#endif
> >
> > Same here. And perhaps just ignoring the pins managed by gpiolib is
> > better (cf. gpiolib and pinctrl being orthogonal).
>
> You mean, we can just make TX,RX,CTS,RTS pins controlled only by the serial
> driver and the rest only by gpiolib?

No, I think I just meant that you shouldn't return an error here for
signals whose pins happen to be muxed for a different function (gpio).

Johan