On Sun, Dec 12, 2021 at 03:18:21PM +0000, Visa Hankala wrote:
> Silicon Labs CP2108 USB device can implement up to four COM ports. Each
> port appears as a separate USB virtual COM interface under the device.
>
> Currently, uslcom(4) always uses the device's first interface, which is
> wrong when there are multiple ports. The following patch adjusts the
> driver to use the USB interface that the USB attachment code provides.
> This makes the different ports usable.
>
> dmesg before:
>
> uslcom0 at uhub0 port 3 configuration 1 interface 0 "Silicon Labs CP2108 Quad
> USB to UART Bridge Controller" rev 2.00/1.70 addr 2
> ucom0 at uslcom0 portno 0
> uslcom1 at uhub0 port 3 configuration 1 interface 1 "Silicon Labs CP2108 Quad
> USB to UART Bridge Controller" rev 2.00/1.70 addr 2
> ucom1 at uslcom1 portno 0
> uslcom2 at uhub0 port 3 configuration 1 interface 2 "Silicon Labs CP2108 Quad
> USB to UART Bridge Controller" rev 2.00/1.70 addr 2
> ucom2 at uslcom2 portno 0
> uslcom3 at uhub0 port 3 configuration 1 interface 3 "Silicon Labs CP2108 Quad
> USB to UART Bridge Controller" rev 2.00/1.70 addr 2
> ucom3 at uslcom3 portno 0
>
> dmesg after:
>
> uslcom0 at uhub0 port 3 configuration 1 interface 0 "Silicon Labs CP2108 Quad
> USB to UART Bridge Controller" rev 2.00/1.70 addr 2
> ucom0 at uslcom0 portno 0
> uslcom1 at uhub0 port 3 configuration 1 interface 1 "Silicon Labs CP2108 Quad
> USB to UART Bridge Controller" rev 2.00/1.70 addr 2
> ucom1 at uslcom1 portno 1
> uslcom2 at uhub0 port 3 configuration 1 interface 2 "Silicon Labs CP2108 Quad
> USB to UART Bridge Controller" rev 2.00/1.70 addr 2
> ucom2 at uslcom2 portno 2
> uslcom3 at uhub0 port 3 configuration 1 interface 3 "Silicon Labs CP2108 Quad
> USB to UART Bridge Controller" rev 2.00/1.70 addr 2
> ucom3 at uslcom3 portno 3
>
> OK?
tested without any problems on
uslcom0 at uhub2 port 2 configuration 1 interface 0 "Silicon Labs CP2102 USB to
UART Bridge Controller" rev 1.10/1.00 addr 3
ucom0 at uslcom0 portno 0
ok jsg@
>
> Index: share/man/man4/uslcom.4
> ===================================================================
> RCS file: src/share/man/man4/uslcom.4,v
> retrieving revision 1.15
> diff -u -p -r1.15 uslcom.4
> --- share/man/man4/uslcom.4 26 Apr 2019 06:02:10 -0000 1.15
> +++ share/man/man4/uslcom.4 12 Dec 2021 14:51:03 -0000
> @@ -26,12 +26,12 @@
> .Sh DESCRIPTION
> The
> .Nm
> -driver supports Silicon Laboratories CP2101/CP2102/CP2103/CP2104/CP2105
> +driver supports Silicon Laboratories
> CP2101/CP2102/CP2103/CP2104/CP2105/CP2108
> based serial adapters.
> .Pp
> The CP2101/CP2102/CP2103 devices only support a variety of baud rates
> up to 921600.
> -CP2104 and CP2105 devices support any baud rate up to 2 Mbps.
> +CP2104, CP2105 and CP2108 devices support any baud rate up to 2 Mbps.
> .Pp
> The following devices should work with the
> .Nm
> Index: sys/dev/usb/uslcom.c
> ===================================================================
> RCS file: src/sys/dev/usb/uslcom.c,v
> retrieving revision 1.42
> diff -u -p -r1.42 uslcom.c
> --- sys/dev/usb/uslcom.c 5 Jan 2020 00:54:13 -0000 1.42
> +++ sys/dev/usb/uslcom.c 12 Dec 2021 14:51:03 -0000
> @@ -38,7 +38,6 @@ int uslcomdebug = 0;
> #define DPRINTF(x) DPRINTFN(0, x)
>
> #define USLCOMBUFSZ 256
> -#define USLCOM_IFACE_NO 0
>
> #define USLCOM_SET_DATA_BITS(x) (x << 8)
>
> @@ -292,21 +291,11 @@ uslcom_attach(struct device *parent, str
> struct ucom_attach_args uca;
> usb_interface_descriptor_t *id;
> usb_endpoint_descriptor_t *ed;
> - usbd_status error;
> int i;
>
> bzero(&uca, sizeof(uca));
> sc->sc_udev = uaa->device;
> -
> - /* get the first interface handle */
> - error = usbd_device2interface_handle(sc->sc_udev, USLCOM_IFACE_NO,
> - &sc->sc_iface);
> - if (error != 0) {
> - printf("%s: could not get interface handle\n",
> - sc->sc_dev.dv_xname);
> - usbd_deactivate(sc->sc_udev);
> - return;
> - }
> + sc->sc_iface = uaa->iface;
>
> id = usbd_get_interface_descriptor(sc->sc_iface);
>
> @@ -334,6 +323,7 @@ uslcom_attach(struct device *parent, str
> return;
> }
>
> + uca.portno = id->bInterfaceNumber;
> uca.ibufsize = USLCOMBUFSZ;
> uca.obufsize = USLCOMBUFSZ;
> uca.ibufsizepad = USLCOMBUFSZ;
>
>