linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [1/2] USB: serial: mos7840: Adjust port settings for read and write registers
@ 2018-11-29  6:51 Jackychou
  0 siblings, 0 replies; 2+ messages in thread
From: Jackychou @ 2018-11-29  6:51 UTC (permalink / raw)
  To: johan; +Cc: gregkh, linux-usb, linux-kernel, louis, jackychou

From: JackyChou <jackychou@asix.com.tw>

In the read/write function, set port 2 independently in the 2-port case.

When setting the offset of port registers, the offset between port 1 and
other ports is different, so port 1 is set independently.
Then in the rest of ports, the port 2 between 2-ports case and 4-ports case
is different, so port 2 in 2-ports case is set independently.

Signed-off-by: JackyChou <jackychou@asix.com.tw>
---
 drivers/usb/serial/mos7840.c | 48 ++++++++++++------------------------
 1 file changed, 16 insertions(+), 32 deletions(-)

 			       MCS_WR_RTYPE, val, reg, NULL, 0,
@@ -332,15 +327,10 @@ static int mos7840_get_uart_reg(struct usb_serial_port
*port, __u16 reg,
 		return -ENOMEM;
 
 	/* Wval  is same as application number */
-	if (port->serial->num_ports == 4) {
+	if (port->serial->num_ports == 2 && port->port_number != 0)
+		Wval = ((__u16)port->port_number + 2) << 8;
+	else
 		Wval = ((__u16)port->port_number + 1) << 8;
-	} else {
-		if (port->port_number == 0) {
-			Wval = ((__u16)port->port_number + 1) << 8;
-		} else {
-			Wval = ((__u16)port->port_number + 2) << 8;
-		}
-	}
 	dev_dbg(&port->dev, "%s application number is %x\n", __func__,
Wval);
 	ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
 			      MCS_RD_RTYPE, Wval, reg, buf,
VENDOR_READ_LENGTH,
@@ -2132,22 +2122,16 @@ static int mos7840_port_probe(struct usb_serial_port
*port)
 		mos7840_port->SpRegOffset = 0x0;
 		mos7840_port->ControlRegOffset = 0x1;
 		mos7840_port->DcrRegOffset = 0x4;
-	} else if ((mos7840_port->port_num == 2) && (serial->num_ports ==
4)) {
-		mos7840_port->SpRegOffset = 0x8;
-		mos7840_port->ControlRegOffset = 0x9;
-		mos7840_port->DcrRegOffset = 0x16;
-	} else if ((mos7840_port->port_num == 2) && (serial->num_ports ==
2)) {
-		mos7840_port->SpRegOffset = 0xa;
-		mos7840_port->ControlRegOffset = 0xb;
-		mos7840_port->DcrRegOffset = 0x19;
-	} else if ((mos7840_port->port_num == 3) && (serial->num_ports ==
4)) {
-		mos7840_port->SpRegOffset = 0xa;
-		mos7840_port->ControlRegOffset = 0xb;
-		mos7840_port->DcrRegOffset = 0x19;
-	} else if ((mos7840_port->port_num == 4) && (serial->num_ports ==
4)) {
-		mos7840_port->SpRegOffset = 0xc;
-		mos7840_port->ControlRegOffset = 0xd;
-		mos7840_port->DcrRegOffset = 0x1c;
+	} else {
+		u8 port_offset;
+
+		if ((mos7840_port->port_num == 2) && (serial->num_ports ==
2))
+			port_offset = 1;
+		else
+			port_offset = mos7840_port->port_num - 2;
+		mos7840_port->SpRegOffset = 0x8 + (2 * port_offset);
+		mos7840_port->ControlRegOffset = 0x9 + (2 * port_offset);
+		mos7840_port->DcrRegOffset = 0x16 + (3 * port_offset);
 	}
 	mos7840_dump_serial_port(port, mos7840_port);
 	mos7840_set_port_private(port, mos7840_port);

diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 88828b4b8c44..92ab68ef08ab 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -298,15 +298,10 @@ static int mos7840_set_uart_reg(struct usb_serial_port
*port, __u16 reg,
 	val = val & 0x00ff;
 	/* For the UART control registers, the application number need
 	   to be Or'ed */
-	if (port->serial->num_ports == 4) {
+	if (port->serial->num_ports == 2 && port->port_number != 0)
+		val |= ((__u16)port->port_number + 2) << 8;
+	else
 		val |= ((__u16)port->port_number + 1) << 8;
-	} else {
-		if (port->port_number == 0) {
-			val |= ((__u16)port->port_number + 1) << 8;
-		} else {
-			val |= ((__u16)port->port_number + 2) << 8;
-		}
-	}
 	dev_dbg(&port->dev, "%s application number is %x\n", __func__, val);
 	return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,

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

* [1/2] USB: serial: mos7840: Adjust port settings for read and write registers
@ 2018-11-29 15:49 Johan Hovold
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hovold @ 2018-11-29 15:49 UTC (permalink / raw)
  To: JackyChou; +Cc: johan, gregkh, linux-usb, linux-kernel, louis

On Thu, Nov 29, 2018 at 02:51:36PM +0800, JackyChou wrote:
> 
> From: JackyChou <jackychou@asix.com.tw>
> 
> In the read/write function, set port 2 independently in the 2-port case.
> 
> When setting the offset of port registers, the offset between port 1 and
> other ports is different, so port 1 is set independently.
> Then in the rest of ports, the port 2 between 2-ports case and 4-ports case
> is different, so port 2 in 2-ports case is set independently.
> 
> Signed-off-by: JackyChou <jackychou@asix.com.tw>
> ---

Thanks for the update. Unfortunately the patches are still white-space
damaged. You may want to take a look at:

	Documentation/process/email-clients.rst

and verify if its your mail client or server that corrupts the patches.

Either way, try sending them to yourself first and run checkpatch on the
result.

Also, remember to include a changelog when you resend (here below the
cut-off, ---, line, and increase the patch revision (e.g. this is really
v4?).

Thanks,
Johan

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

end of thread, other threads:[~2018-11-29 15:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-29 15:49 [1/2] USB: serial: mos7840: Adjust port settings for read and write registers Johan Hovold
  -- strict thread matches above, loose matches on Subject: below --
2018-11-29  6:51 Jackychou

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).