Skip to contentSkip to conversation

usb: serial: add support for CH348

PATCH Superseded Corentin Labbe 3 participants 10 messages Jun 28, 2023 – Apr 10, 2024

Subsystems (2)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v6 cover usb: serial: add support for CH348

Hello

The CH348 is an octo serial to USB adapter.
The following patch adds a driver for supporting it.
Since there is no public datasheet, unfortunatly it remains some magic values.

It was tested with a large range of baud from 1200 to 1500000 and used with success in one of our kernel CI testlab.

Regards

Changes since v1:
- use a data structure for encoding/decoding messages.
- check if needed endpoints exists
- fix URB leak in ch348_allocate_status_read error case
- test for maximum baud rate as stated by datasheet

Changes since v2:
- specify ch348_rxbuf data length
- Use correct speed_t dwDTERate instead of __le32
- test for maximum baud rate supported according to datasheet
- Use a define for CH348_TX_HDRSIZE

Changes since v3
- Fixed all reported problem from https://lore.kernel.org/lkml/Y5NDwEakGJbmB6+b@Red/T/#mb6234d0427cfdabf412190565e215995a41482dd
Mostly reworked the endpoint mux to be the same than mx_uport

Changes since v4:
- The V4 was sent against stable and next have ch348_set_termios ktermios parameter const that I forgot to change

Changes since v5:
- Fixed all reported problem from https://lore.kernel.org/lkml/[email protected]/T/#m044aab24dfb652ea34aa06f8ef704da9d6a2e036
- Major change is dropping of all status handling which was unused.
It will be probably necessary to bring it back when using GPIO.
This will be done when I will finish my next devboard.

Corentin Labbe (2):
usb: serial: add support for CH348
usb: serial: add myself as maintainer of CH348

 MAINTAINERS                 |   5 +
 drivers/usb/serial/Kconfig  |   9 +
 drivers/usb/serial/Makefile |   1 +
 drivers/usb/serial/ch348.c  | 491 ++++++++++++++++++++++++++++++++++++
 4 files changed, 506 insertions(+)
 create mode 100644 drivers/usb/serial/ch348.c
Signature · 1 line
2.39.3
#1 lore raw

PATCH v6 1/2 usb: serial: add support for CH348

The CH348 is an USB octo port serial adapter.
The device multiplexes all 8 ports in the same pair of Bulk endpoints. Since there is no public datasheet, unfortunately it remains some magic values

---
 drivers/usb/serial/Kconfig  |   9 +
 drivers/usb/serial/Makefile |   1 +
 drivers/usb/serial/ch348.c  | 491 ++++++++++++++++++++++++++++++++++++
 3 files changed, 501 insertions(+)
 create mode 100644 drivers/usb/serial/ch348.c
drivers/usb/serial/Kconfig +9 -0
index ef8d1c73c754..1e1842656b54 100644
@@ -112,6 +112,15 @@ config USB_SERIAL_CH341
 	  To compile this driver as a module, choose M here: the
 	  module will be called ch341.
 
+config USB_SERIAL_CH348
+	tristate "USB Winchiphead CH348 Octo Port Serial Driver"
+	help
+	  Say Y here if you want to use a Winchiphead CH348 octo port
+	  USB to serial adapter.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ch348.
+
 config USB_SERIAL_WHITEHEAT
 	tristate "USB ConnectTech WhiteHEAT Serial Driver"
 	select USB_EZUSB_FX2
drivers/usb/serial/Makefile +1 -0
index c7bb1a88173e..d16ff59fde68 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_USB_SERIAL_AIRCABLE)		+= aircable.o
 obj-$(CONFIG_USB_SERIAL_ARK3116)		+= ark3116.o
 obj-$(CONFIG_USB_SERIAL_BELKIN)			+= belkin_sa.o
 obj-$(CONFIG_USB_SERIAL_CH341)			+= ch341.o
+obj-$(CONFIG_USB_SERIAL_CH348)			+= ch348.o
 obj-$(CONFIG_USB_SERIAL_CP210X)			+= cp210x.o
 obj-$(CONFIG_USB_SERIAL_CYBERJACK)		+= cyberjack.o
 obj-$(CONFIG_USB_SERIAL_CYPRESS_M8)		+= cypress_m8.o
drivers/usb/serial/ch348.c new file +491 -0

491 lines not on this page · raw message

Signature · 1 line
2.39.3
#2 lore raw

PATCH v6 2/2 usb: serial: add myself as maintainer of CH348

In reply to Corentin Labbe

Since I did the driver and have hardware to test, set myself as maintainer of it.

---
 MAINTAINERS | 5 +++++
 1 file changed, 5 insertions(+)
MAINTAINERS +5 -0
index 342cb79a9ac5..e95b51594bac 100644
@@ -22044,6 +22044,11 @@ F:	Documentation/usb/usb-serial.rst
 F:	drivers/usb/serial/
 F:	include/linux/usb/serial.h
 
+USB SERIAL DRIVER FOR CH348
+M:	Corentin Labbe <[email protected]>
+S:	Maintained
+F:	drivers/usb/serial/ch348.c
+
 USB SMSC75XX ETHERNET DRIVER
 M:	Steve Glendinning <[email protected]>
 L:	[email protected]
Signature · 1 line
2.39.3
Tested-by Reviewed-by on the v6 series
#3 lore raw
In reply to Corentin Labbe

Thank you

Quoted 48 lines · Corentin Labbe

Hello

The CH348 is an octo serial to USB adapter.
The following patch adds a driver for supporting it.
Since there is no public datasheet, unfortunatly it remains some magic values.

It was tested with a large range of baud from 1200 to 1500000 and used with success in one of our kernel CI testlab.

Regards

Changes since v1:
- use a data structure for encoding/decoding messages.
- check if needed endpoints exists
- fix URB leak in ch348_allocate_status_read error case
- test for maximum baud rate as stated by datasheet

Changes since v2:
- specify ch348_rxbuf data length
- Use correct speed_t dwDTERate instead of __le32
- test for maximum baud rate supported according to datasheet
- Use a define for CH348_TX_HDRSIZE

Changes since v3
- Fixed all reported problem from https://lore.kernel.org/lkml/Y5NDwEakGJbmB6+b@Red/T/#mb6234d0427cfdabf412190565e215995a41482dd
Mostly reworked the endpoint mux to be the same than mx_uport

Changes since v4:
- The V4 was sent against stable and next have ch348_set_termios ktermios parameter const that I forgot to change

Changes since v5:
- Fixed all reported problem from https://lore.kernel.org/lkml/[email protected]/T/#m044aab24dfb652ea34aa06f8ef704da9d6a2e036
- Major change is dropping of all status handling which was unused.
It will be probably necessary to bring it back when using GPIO.
This will be done when I will finish my next devboard.

Corentin Labbe (2):
usb: serial: add support for CH348
usb: serial: add myself as maintainer of CH348

  MAINTAINERS                 |   5 +
  drivers/usb/serial/Kconfig  |   9 +
  drivers/usb/serial/Makefile |   1 +
  drivers/usb/serial/ch348.c  | 491 ++++++++++++++++++++++++++++++++++++
  4 files changed, 506 insertions(+)

create mode 100644 drivers/usb/serial/ch348.c

Signature · 2 lines
David Heidelberg
Consultant Software Engineer
#4 lore raw
In reply to Corentin Labbe

Hello Johan,

Any chance to get CH348 into 6.5?

I want to highlight that from all serials I have around this is the only one which support 1500000 baud (needed for Rockchip devices).

Thank you!
David

Quoted 48 lines · Corentin Labbe

Hello

The CH348 is an octo serial to USB adapter.
The following patch adds a driver for supporting it.
Since there is no public datasheet, unfortunatly it remains some magic values.

It was tested with a large range of baud from 1200 to 1500000 and used with success in one of our kernel CI testlab.

Regards

Changes since v1:
- use a data structure for encoding/decoding messages.
- check if needed endpoints exists
- fix URB leak in ch348_allocate_status_read error case
- test for maximum baud rate as stated by datasheet

Changes since v2:
- specify ch348_rxbuf data length
- Use correct speed_t dwDTERate instead of __le32
- test for maximum baud rate supported according to datasheet
- Use a define for CH348_TX_HDRSIZE

Changes since v3
- Fixed all reported problem from https://lore.kernel.org/lkml/Y5NDwEakGJbmB6+b@Red/T/#mb6234d0427cfdabf412190565e215995a41482dd
Mostly reworked the endpoint mux to be the same than mx_uport

Changes since v4:
- The V4 was sent against stable and next have ch348_set_termios ktermios parameter const that I forgot to change

Changes since v5:
- Fixed all reported problem from https://lore.kernel.org/lkml/[email protected]/T/#m044aab24dfb652ea34aa06f8ef704da9d6a2e036
- Major change is dropping of all status handling which was unused.
It will be probably necessary to bring it back when using GPIO.
This will be done when I will finish my next devboard.

Corentin Labbe (2):
usb: serial: add support for CH348
usb: serial: add myself as maintainer of CH348

  MAINTAINERS                 |   5 +
  drivers/usb/serial/Kconfig  |   9 +
  drivers/usb/serial/Makefile |   1 +
  drivers/usb/serial/ch348.c  | 491 ++++++++++++++++++++++++++++++++++++
  4 files changed, 506 insertions(+)

create mode 100644 drivers/usb/serial/ch348.c

Signature · 2 lines
David Heidelberg
Certified Linux Magician
#5 lore raw
In reply to Corentin Labbe
Quoted 6 lines · On Mittwoch, 28. Juni 2023 15:38:32 CEST Corentin Labbe wrote:

Hello

The CH348 is an octo serial to USB adapter.
The following patch adds a driver for supporting it.
Since there is no public datasheet, unfortunatly it remains some magic values.

Quoted 6 lines

It was tested with a large range of baud from 1200 to 1500000 and used with success in one of our kernel CI testlab.

Regards

[...]

Hello,

thank you for your work on this. I recently made myself a CH348 board and used this patchset with a small test application[1] to see how it performs. Specifically, I ran this on an RK3566 single board computer, connecting one serial adapter to the other, with the test as follows:

./serialtest /dev/ttyUSB0 9600 # UART0 of 1st CH348 board ./serialtest /dev/ttyUSB8 9600 # UART0 of 2nd CH348 board

One problem I've noticed is that writes to the tty fd never seem to block. On two CH340 adapters I have, they do seem to block, whereas here, you can see from the statistics at the end that magnitudes more bytes were written than read, with seemingly most of them being discarded. From my reading of the termios parameters I set, this shouldn't be the case, right?

You can see from the error percentage that it gets less bad as you increase the serial baudrate; I've tested up to 6 mbaud like this. I assume that's because less written bytes get discarded.

Any ideas on whether I'm relying on weird driver behaviour with the blocking here or if this driver actually has a defect whereby it never signals to userspace that less bytes were written than have been submitted?

Kind regards,
Nicolas Frattaroli

[1]: https://github.com/CounterPillow/serialtest

#6 lore raw

Hello Corentin, light reminder about this patchset and Nicolas question :)

Thank you
David

Quoted 48 lines · Nicolas Frattaroli
Quoted 6 lines · On Mittwoch, 28. Juni 2023 15:38:32 CEST Corentin Labbe wrote:

Hello

The CH348 is an octo serial to USB adapter.
The following patch adds a driver for supporting it.
Since there is no public datasheet, unfortunatly it remains some magic values.

Quoted 6 lines

It was tested with a large range of baud from 1200 to 1500000 and used with success in one of our kernel CI testlab.

Regards

[...]

Hello,

thank you for your work on this. I recently made myself a CH348 board and used this patchset with a small test application[1] to see how it performs. Specifically, I ran this on an RK3566 single board computer, connecting one serial adapter to the other, with the test as follows:

./serialtest /dev/ttyUSB0 9600 # UART0 of 1st CH348 board ./serialtest /dev/ttyUSB8 9600 # UART0 of 2nd CH348 board

One problem I've noticed is that writes to the tty fd never seem to block. On two CH340 adapters I have, they do seem to block, whereas here, you can see from the statistics at the end that magnitudes more bytes were written than read, with seemingly most of them being discarded. From my reading of the termios parameters I set, this shouldn't be the case, right?

You can see from the error percentage that it gets less bad as you increase the serial baudrate; I've tested up to 6 mbaud like this. I assume that's because less written bytes get discarded.

Any ideas on whether I'm relying on weird driver behaviour with the blocking here or if this driver actually has a defect whereby it never signals to userspace that less bytes were written than have been submitted?

Kind regards,
Nicolas Frattaroli

[1]: https://github.com/CounterPillow/serialtest

Signature · 2 lines
David Heidelberg
Certified Linux Magician
#7 lore raw
In reply to Nicolas Frattaroli
Quoted 43 lines · Nicolas Frattaroli
Quoted 6 lines · On Mittwoch, 28. Juni 2023 15:38:32 CEST Corentin Labbe wrote:

Hello

The CH348 is an octo serial to USB adapter.
The following patch adds a driver for supporting it.
Since there is no public datasheet, unfortunatly it remains some magic values.

Quoted 6 lines

It was tested with a large range of baud from 1200 to 1500000 and used with success in one of our kernel CI testlab.

Regards

[...]

Hello,

thank you for your work on this. I recently made myself a CH348 board and used this patchset with a small test application[1] to see how it performs. Specifically, I ran this on an RK3566 single board computer, connecting one serial adapter to the other, with the test as follows:

./serialtest /dev/ttyUSB0 9600 # UART0 of 1st CH348 board ./serialtest /dev/ttyUSB8 9600 # UART0 of 2nd CH348 board

One problem I've noticed is that writes to the tty fd never seem to block. On two CH340 adapters I have, they do seem to block, whereas here, you can see from the statistics at the end that magnitudes more bytes were written than read, with seemingly most of them being discarded. From my reading of the termios parameters I set, this shouldn't be the case, right?

You can see from the error percentage that it gets less bad as you increase the serial baudrate; I've tested up to 6 mbaud like this. I assume that's because less written bytes get discarded.

Any ideas on whether I'm relying on weird driver behaviour with the blocking here or if this driver actually has a defect whereby it never signals to userspace that less bytes were written than have been submitted?

Quoted 5 lines

Kind regards,
Nicolas Frattaroli

[1]: https://github.com/CounterPillow/serialtest

Hello

Sorry for the very long delay of the answer.
I have reproduced the problem on my board.
My reproducer is https://github.com/montjoie/lava-tests/blob/master/test2a2.py

This problem seems to be here since the v1 of my patchset. The vendor driver seems to work so it is not an hardware problem.

I have no clue at the moment, it is hard to diff with vendor driver since it create tty directly and do not use usbserial.

Regards

#8 lore raw

Hello Corentin,

is there chance you find some time to upstream this?
In the worst case I would try to find some time to look into this, so it would have chance to get merged.

Thanks
David

Quoted 60 lines · Corentin LABBE
Quoted 42 lines · Nicolas Frattaroli
Quoted 6 lines · On Mittwoch, 28. Juni 2023 15:38:32 CEST Corentin Labbe wrote:

Hello

The CH348 is an octo serial to USB adapter.
The following patch adds a driver for supporting it.
Since there is no public datasheet, unfortunatly it remains some magic values.

Quoted 6 lines

It was tested with a large range of baud from 1200 to 1500000 and used with success in one of our kernel CI testlab.

Regards

[...]

Hello,

thank you for your work on this. I recently made myself a CH348 board and used this patchset with a small test application[1] to see how it performs. Specifically, I ran this on an RK3566 single board computer, connecting one serial adapter to the other, with the test as follows:

./serialtest /dev/ttyUSB0 9600 # UART0 of 1st CH348 board ./serialtest /dev/ttyUSB8 9600 # UART0 of 2nd CH348 board

One problem I've noticed is that writes to the tty fd never seem to block. On two CH340 adapters I have, they do seem to block, whereas here, you can see from the statistics at the end that magnitudes more bytes were written than read, with seemingly most of them being discarded. From my reading of the termios parameters I set, this shouldn't be the case, right?

You can see from the error percentage that it gets less bad as you increase the serial baudrate; I've tested up to 6 mbaud like this. I assume that's because less written bytes get discarded.

Any ideas on whether I'm relying on weird driver behaviour with the blocking here or if this driver actually has a defect whereby it never signals to userspace that less bytes were written than have been submitted?

Quoted 5 lines

Kind regards,
Nicolas Frattaroli

[1]: https://github.com/CounterPillow/serialtest

Hello

Sorry for the very long delay of the answer.
I have reproduced the problem on my board.
My reproducer is https://github.com/montjoie/lava-tests/blob/master/test2a2.py

This problem seems to be here since the v1 of my patchset. The vendor driver seems to work so it is not an hardware problem.

I have no clue at the moment, it is hard to diff with vendor driver since it create tty directly and do not use usbserial.

Regards

Signature · 1 line
David Heidelberg
#9 lore raw
Quoted 6 lines · David Heidelberg

Hello Corentin,

is there chance you find some time to upstream this?
In the worst case I would try to find some time to look into this, so it would have chance to get merged.

Hello

Martin Blumenstingl worked a lot on fixing issues
You can see it at https://github.com/xdarklight/ch348/commits/main/

Currently I finish to test it to be able to do a v7.

We have an IRC channel to speak about it libera:#ch348

Regards