Skip to contentSkip to conversation

Winchiphead 340/1: full baud rate and status/control line support

PATCH In review Tollef Fog Heen 2 participants 4 messages Jan 4, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Winchiphead 340/1: full baud rate and status/control line support

Patch against current git (3c92ec8ae91ecf59d88c798301833d7cf83f2179)

From: Tollef Fog Heen <[email protected]>

* Implement support for all baud rates rather than just a hard coded set.
* Make it possible to control status and control lines

---
 Documentation/usb/usb-serial.txt |    2
 drivers/usb/serial/ch341.c       |  413 +++++++++++++++++++++++++++++++--------
 2 files changed, 340 insertions(+), 75 deletions(-)
Documentation/usb/usb-serial.txt +2 -0
index ff2c1ff..201ec84 100644
@@ -434,6 +434,8 @@ Winchiphead CH341 Driver
   The manufacturer's website: http://www.winchiphead.com/.
   For any questions or problems with this driver, please contact
   [email protected].
+  Extensions for universal baudrate settings and modem status/control have
+  been added by werner <at> cornelius-consult.de.
 
 
 Generic Serial driver
drivers/usb/serial/ch341.c +338 -75

550 lines not on this page · raw message

Signature · 2 lines
Tollef Fog Heen
UNIX is user friendly, it's just picky about who its friends are
#1 lore raw

drivers/usb/serial/ch341.c static int ch341_control_in(struct usb_device *dev, · line 140

Quoted 10 lines
drivers/usb/serial/ch341.c +10 -0
+	if (factor > 0xfff0) { /* Clamp */
+		factor = 0xfff0;
+		divisor = 0;
+	}
+
+	t1 = factor;
+	for (t2 = divisor; t2 <= CH341_BAUDBASE_DIVMAX; t2++)
+		t1 >>= 3;
+	baud = CH341_BAUDBASE_FACTOR / t1;
+

Same question as before: Can baud really become zero at this point ? Also for that matter what guarantees that t1 cannot become zero in this computation ?

drivers/usb/serial/ch341.c static int ch341_control_in(struct usb_device *dev, · line 142

Quoted 2 lines
drivers/usb/serial/ch341.c +2 -0
+	if (baud && tty)
+		tty_encode_baud_rate(tty, baud, baud);

The check for B0 (hangup) was done earlier (see set_termios). So if you can end up with a requested baud rate being turned into 0 you need to bump it up to 1. If not you don't need the test.

#2 lore raw

]] Alan Cox

| > +	if (factor > 0xfff0) { /* Clamp */
| > +		factor = 0xfff0;
| > +		divisor = 0;
| > +	}
| > +
| > +	t1 = factor;
| > +	for (t2 = divisor; t2 <= CH341_BAUDBASE_DIVMAX; t2++)
| > +		t1 >>= 3;
| > +	baud = CH341_BAUDBASE_FACTOR / t1;
| > +
| 
| Same question as before: Can baud really become zero at this point ? Also
| for that matter what guarantees that t1 cannot become zero in this
| computation ?

Nothing, that code is completely wrong. I've rewritten it now. Thanks for explaining.

| > +	if (baud && tty)
| > +		tty_encode_baud_rate(tty, baud, baud);
| 
| The check for B0 (hangup) was done earlier (see set_termios). So if you
| can end up with a requested baud rate being turned into 0 you need to
| bump it up to 1. If not you don't need the test.

Indeed, fixed as well. New patch incoming in a few minutes.

I've also added the mutex protecting set_handshake, but I feel less confident about whether that's the right approach, so feedback there is also appreciated.

Signature · 2 lines
Tollef Fog Heen
UNIX is user friendly, it's just picky about who its friends are
#3 lore raw

PATCH 1/1 Winchiphead 340/1: full baud rate and status/control line support

In reply to Tollef Fog Heen

Patch against current git (3c92ec8ae91ecf59d88c798301833d7cf83f2179)

From: Tollef Fog Heen <[email protected]>

* Implement support for all baud rates rather than just a hard coded set.
* Make it possible to control status and control lines
* Grab a bunch of #defines from FreeBSD to reduce the number of magic numbers in the file

---

 Documentation/usb/usb-serial.txt |    2
 drivers/usb/serial/ch341.c       |  501 ++++++++++++++++++++++++++++++++-------
 2 files changed, 419 insertions(+), 84 deletions(-)
Documentation/usb/usb-serial.txt +2 -0
index ff2c1ff..201ec84 100644
@@ -434,6 +434,8 @@ Winchiphead CH341 Driver
   The manufacturer's website: http://www.winchiphead.com/.
   For any questions or problems with this driver, please contact
   [email protected].
+  Extensions for universal baudrate settings and modem status/control have
+  been added by werner <at> cornelius-consult.de.
 
 
 Generic Serial driver
drivers/usb/serial/ch341.c +417 -84

661 lines not on this page · raw message

Signature · 2 lines
Tollef Fog Heen
UNIX is user friendly, it's just picky about who its friends are