linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [2/2] USB: serial: pl2303: fix tranceiver suspend mode
@ 2019-04-02  8:19 Johan Hovold
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2019-04-02  8:19 UTC (permalink / raw)
  To: linux-usb; +Cc: Florian Zumbiehl, Charles Yeh, Johan Hovold

Add helper function to update register bits instead of overwriting the
entire control register when updating the flow-control settings.

This specifically avoids having the tranceiver suspend mode (bit 0)
depend on the flow control setting.

The tranceiver is currently configured at probe to be disabled during
suspend, but this was overridden when disabling flow control or enabling
xon/xoff.

Fixes: 715f9527c1c1 ("USB: flow control fix for pl2303")
Fixes: 7041d9c3f01b ("USB: serial: pl2303: add support for tx xon/xoff flow control")
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/pl2303.c | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index e7ccd06df802..55122ac84518 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -145,6 +145,8 @@ MODULE_DEVICE_TABLE(usb, id_table);
 #define UART_OVERRUN_ERROR		0x40
 #define UART_CTS			0x80
 
+#define PL2303_FLOWCTRL_MASK		0xf0
+
 static void pl2303_set_break(struct usb_serial_port *port, bool enable);
 
 enum pl2303_type {
@@ -176,7 +178,7 @@ static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = {
 	[TYPE_01] = {
 		.max_baud_rate		= 1228800,
 		.quirks			= PL2303_QUIRK_LEGACY,
-		.no_autoxonxoff		= 1,
+		.no_autoxonxoff		= true,
 	},
 	[TYPE_HX] = {
 		.max_baud_rate		= 12000000,
@@ -225,6 +227,29 @@ static int pl2303_vendor_write(struct usb_serial *serial, u16 value, u16 index)
 	return 0;
 }
 
+static int pl2303_update_reg(struct usb_serial *serial, u8 reg, u8 mask, u8 val)
+{
+	int ret = 0;
+	u8 *buf;
+
+	buf = kmalloc(1, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	ret = pl2303_vendor_read(serial, reg | 0x80, buf);
+	if (ret)
+		goto out_free;
+
+	*buf &= ~mask;
+	*buf |= val & mask;
+
+	ret = pl2303_vendor_write(serial, reg, *buf);
+out_free:
+	kfree(buf);
+
+	return ret;
+}
+
 static int pl2303_probe(struct usb_serial *serial,
 					const struct usb_device_id *id)
 {
@@ -694,13 +719,13 @@ static void pl2303_set_termios(struct tty_struct *tty,
 
 	if (C_CRTSCTS(tty)) {
 		if (spriv->quirks & PL2303_QUIRK_LEGACY)
-			pl2303_vendor_write(serial, 0x0, 0x41);
+			pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0x40);
 		else
-			pl2303_vendor_write(serial, 0x0, 0x61);
+			pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0x60);
 	} else if (pl2303_enable_xonxoff(tty, spriv->type)) {
-		pl2303_vendor_write(serial, 0x0, 0xc0);
+		pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0xc0);
 	} else {
-		pl2303_vendor_write(serial, 0x0, 0x0);
+		pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0);
 	}
 
 	kfree(buf);

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

* [2/2] USB: serial: pl2303: fix tranceiver suspend mode
@ 2019-04-02  8:22 Johan Hovold
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2019-04-02  8:22 UTC (permalink / raw)
  To: linux-usb; +Cc: Florian Zumbiehl, Charles Yeh, Johan Hovold

On Tue, Apr 02, 2019 at 10:19:31AM +0200, Johan Hovold wrote:
> Add helper function to update register bits instead of overwriting the
> entire control register when updating the flow-control settings.
> 
> This specifically avoids having the tranceiver suspend mode (bit 0)
> depend on the flow control setting.
> 
> The tranceiver is currently configured at probe to be disabled during
> suspend, but this was overridden when disabling flow control or enabling
> xon/xoff.
> 
> Fixes: 715f9527c1c1 ("USB: flow control fix for pl2303")
> Fixes: 7041d9c3f01b ("USB: serial: pl2303: add support for tx xon/xoff flow control")
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---

> @@ -176,7 +178,7 @@ static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = {
>  	[TYPE_01] = {
>  		.max_baud_rate		= 1228800,
>  		.quirks			= PL2303_QUIRK_LEGACY,
> -		.no_autoxonxoff		= 1,
> +		.no_autoxonxoff		= true,

This chunk was supposed to go in the first patch. I'll fix that up
before applying (or resending).

Johan

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

* [2/2] USB: serial: pl2303: fix tranceiver suspend mode
@ 2019-04-02 12:04 Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2019-04-02 12:04 UTC (permalink / raw)
  To: Johan Hovold; +Cc: linux-usb, Florian Zumbiehl, Charles Yeh

On Tue, Apr 02, 2019 at 10:22:06AM +0200, Johan Hovold wrote:
> On Tue, Apr 02, 2019 at 10:19:31AM +0200, Johan Hovold wrote:
> > Add helper function to update register bits instead of overwriting the
> > entire control register when updating the flow-control settings.
> > 
> > This specifically avoids having the tranceiver suspend mode (bit 0)
> > depend on the flow control setting.
> > 
> > The tranceiver is currently configured at probe to be disabled during
> > suspend, but this was overridden when disabling flow control or enabling
> > xon/xoff.
> > 
> > Fixes: 715f9527c1c1 ("USB: flow control fix for pl2303")
> > Fixes: 7041d9c3f01b ("USB: serial: pl2303: add support for tx xon/xoff flow control")
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---
> 
> > @@ -176,7 +178,7 @@ static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = {
> >  	[TYPE_01] = {
> >  		.max_baud_rate		= 1228800,
> >  		.quirks			= PL2303_QUIRK_LEGACY,
> > -		.no_autoxonxoff		= 1,
> > +		.no_autoxonxoff		= true,
> 
> This chunk was supposed to go in the first patch. I'll fix that up
> before applying (or resending).

With that fixup:

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

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

* [2/2] USB: serial: pl2303: fix tranceiver suspend mode
@ 2019-04-03  7:48 Johan Hovold
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2019-04-03  7:48 UTC (permalink / raw)
  To: Greg KH; +Cc: Johan Hovold, linux-usb, Florian Zumbiehl, Charles Yeh

On Tue, Apr 02, 2019 at 02:04:09PM +0200, Greg Kroah-Hartman wrote:
> On Tue, Apr 02, 2019 at 10:22:06AM +0200, Johan Hovold wrote:
> > On Tue, Apr 02, 2019 at 10:19:31AM +0200, Johan Hovold wrote:
> > > Add helper function to update register bits instead of overwriting the
> > > entire control register when updating the flow-control settings.
> > > 
> > > This specifically avoids having the tranceiver suspend mode (bit 0)
> > > depend on the flow control setting.
> > > 
> > > The tranceiver is currently configured at probe to be disabled during
> > > suspend, but this was overridden when disabling flow control or enabling
> > > xon/xoff.
> > > 
> > > Fixes: 715f9527c1c1 ("USB: flow control fix for pl2303")
> > > Fixes: 7041d9c3f01b ("USB: serial: pl2303: add support for tx xon/xoff flow control")
> > > Signed-off-by: Johan Hovold <johan@kernel.org>
> > > ---
> > 
> > > @@ -176,7 +178,7 @@ static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = {
> > >  	[TYPE_01] = {
> > >  		.max_baud_rate		= 1228800,
> > >  		.quirks			= PL2303_QUIRK_LEGACY,
> > > -		.no_autoxonxoff		= 1,
> > > +		.no_autoxonxoff		= true,
> > 
> > This chunk was supposed to go in the first patch. I'll fix that up
> > before applying (or resending).
> 
> With that fixup:
> 
> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Thanks for reviewing, now applied.

Johan

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

end of thread, other threads:[~2019-04-03  7:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-03  7:48 [2/2] USB: serial: pl2303: fix tranceiver suspend mode Johan Hovold
  -- strict thread matches above, loose matches on Subject: below --
2019-04-02 12:04 Greg Kroah-Hartman
2019-04-02  8:22 Johan Hovold
2019-04-02  8:19 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).