Porting plptools to Haiku

I opened a new ticket! Making sure you're not a bot!

Any help you can offer would be great, no matter how small - thank you!

I haven’t tried using kernel syslog, but I can do that. I’m a little busy over the next couple of days, but I can get to it over the weekend and do some testing.

Most of my tests have been with the FTDI FT232R, but I also have a Prolific PL2303TA and Prolific PL2303RA. I have a CH340, too, but for some reason I couldn’t get it to work on Haiku.

1 Like

When you’ll have time, try to connect all your USB / serial adapters, and run the listusb -vcommand to gather every USB information about them.

Regarding the CH340, the most probable is that it’s not in the list of supported vendor or product IDs.

1 Like

Here we go. Don’t know why the CH340 didn’t work last time I tried it, but it was fine this time.

FTDI FT232R

[Device /dev/bus/usb/0/2]
    Class .................. 0x00 (Defined at Interface level) ()
    Subclass ............... 0x00 (Defined at Interface level) ()
    Protocol ............... 0x00 (Defined at Interface level) ()
    Max Endpoint 0 Packet .. 8
    USB Version ............ 2.0
    Vendor ID .............. 0x0403 (Future Technology Devices International, Ltd)
    Product ID ............. 0x6001 (FT232 Serial (UART) IC)
    Product Version ........ 0x0600
    Manufacturer String .... "FTDI"
    Product String ......... "FT232R USB UART"
    Serial Number .......... "AQ02EREY"
    [Configuration 0]
        Configuration String . ""
        [Interface 0]
            [Alternate 0 active]
                Class .............. 0xff Vendor Specific Class ()
                Subclass ........... 0xff Vendor Specific Class (Vendor Specific Subclass)
                Protocol ........... 0xff Vendor Specific Class (Vendor Specific Subclass, Vendor Specific Protocol)
                Interface String ... "FT232R USB UART"
                [Endpoint 0]
                    MaxPacketSize .... 1x 64 bytes
                    Interval ......... 0
                    Type ............. Bulk
                    Direction ........ Input
                [Endpoint 1]
                    MaxPacketSize .... 1x 64 bytes
                    Interval ......... 0
                    Type ............. Bulk
                    Direction ........ Output

Prolific PL2023TA

[Device /dev/bus/usb/0/2]  
   Class .................. 0x00 (Defined at Interface level) ()  
   Subclass ............... 0x00 (Defined at Interface level) ()  
   Protocol ............... 0x00 (Defined at Interface level) ()  
   Max Endpoint 0 Packet .. 64  
   USB Version ............ 2.0  
   Vendor ID .............. 0x067b (Prolific Technology, Inc.)  
   Product ID ............. 0x2303 (PL2303 Serial Port / Mobile Phone Data Cable)  
   Product Version ........ 0x0300  
   Manufacturer String .... "Prolific Technology Inc."  
   Product String ......... "USB-Serial Controller"  
   Serial Number .......... ""  
   [Configuration 0]  
       Configuration String . ""  
       [Interface 0]  
           [Alternate 0 active]  
               Class .............. 0xff Vendor Specific Class ()  
               Subclass ........... 0x00 Vendor Specific Class ()  
               Protocol ........... 0x00 Vendor Specific Class ()  
               Interface String ... ""  
               [Endpoint 0]  
                   MaxPacketSize .... 1x 10 bytes  
                   Interval ......... 1  
                   Type ............. Interrupt  
                   Direction ........ Input  
               [Endpoint 1]  
                   MaxPacketSize .... 1x 64 bytes  
                   Interval ......... 0  
                   Type ............. Bulk  
                   Direction ........ Output  
               [Endpoint 2]  
                   MaxPacketSize .... 1x 64 bytes  
                   Interval ......... 0  
                   Type ............. Bulk  
                   Direction ........ Input

Prolific PL2023RA

[Device /dev/bus/usb/0/2]  
   Class .................. 0x00 (Defined at Interface level) ()  
   Subclass ............... 0x00 (Defined at Interface level) ()  
   Protocol ............... 0x00 (Defined at Interface level) ()  
   Max Endpoint 0 Packet .. 64  
   USB Version ............ 1.16  
   Vendor ID .............. 0x067b (Prolific Technology, Inc.)  
   Product ID ............. 0x2303 (PL2303 Serial Port / Mobile Phone Data Cable)  
   Product Version ........ 0x0400  
   Manufacturer String .... "Prolific Technology Inc. "  
   Product String ......... "USB-Serial Controller D"  
   Serial Number .......... ""  
   [Configuration 0]  
       Configuration String . ""  
       [Interface 0]  
           [Alternate 0 active]  
               Class .............. 0xff Vendor Specific Class ()  
               Subclass ........... 0x00 Vendor Specific Class ()  
               Protocol ........... 0x00 Vendor Specific Class ()  
               Interface String ... ""  
               [Endpoint 0]  
                   MaxPacketSize .... 1x 10 bytes  
                   Interval ......... 1  
                   Type ............. Interrupt  
                   Direction ........ Input  
               [Endpoint 1]  
                   MaxPacketSize .... 1x 64 bytes  
                   Interval ......... 0  
                   Type ............. Bulk  
                   Direction ........ Output  
               [Endpoint 2]  
                   MaxPacketSize .... 1x 64 bytes  
                   Interval ......... 0  
                   Type ............. Bulk  
                   Direction ........ Input

CH340

[Device /dev/bus/usb/0/2]  
   Class .................. 0xff Vendor Specific Class ()  
   Subclass ............... 0x00 Vendor Specific Class ()  
   Protocol ............... 0x00 Vendor Specific Class ()  
   Max Endpoint 0 Packet .. 8  
   USB Version ............ 1.16  
   Vendor ID .............. 0x1a86 (QinHeng Electronics)  
   Product ID ............. 0x7523 (CH340 serial converter)  
   Product Version ........ 0x0254  
   Manufacturer String .... ""  
   Product String ......... "USB2.0-Ser!"  
   Serial Number .......... ""  
   [Configuration 0]  
       Configuration String . ""  
       [Interface 0]  
           [Alternate 0 active]  
               Class .............. 0xff Vendor Specific Class ()  
               Subclass ........... 0x01 (Unknown) (255:1:0)  
               Protocol ........... 0x02 (Unknown) (255:1:2)  
               Interface String ... ""  
               [Endpoint 0]  
                   MaxPacketSize .... 1x 32 bytes  
                   Interval ......... 0  
                   Type ............. Bulk  
                   Direction ........ Input  
               [Endpoint 1]  
                   MaxPacketSize .... 1x 32 bytes  
                   Interval ......... 0  
                   Type ............. Bulk  
                   Direction ........ Output  
               [Endpoint 2]  
                   MaxPacketSize .... 1x 8 bytes  
                   Interval ......... 1  
                   Type ............. Interrupt  
                   Direction ........ Input

Thanks.

Turns out my USB serial adapter is also a CH340.

I’ve yet to install the PCI card, si don’t know yet if I’ll be able to start working on usb_serial driver code or if I’ll have first to make this card recognized by the haiku pc_serial driver…

PCI serial card installed, alas not recognized by haiku pc_serial.driver.
Will try to see how to add support for it, looks like just an issue of adding it to the list of PCI devices supported by the driver…

2 Likes

Out of interest, is there a good guide for getting started with Haiku driver development? At the very least it would be great to try out any code that you manage to get working.

Can you share the output of listdev -v and the PCI enumeration in the syslog for that card?

I would expect that it shows up as a standard PCI communication device and is matched by the existing generic rules in the driver:

https://cgit.haiku-os.org/haiku/tree/src/add-ons/kernel/drivers/ports/pc_serial/Driver.cpp#n131

But there are a few known special cases there already, and we may need more.

Also note that you may need to disable serial output from the kernel debugger to make sure the serial port is available for the pc_serial driver. If the lernel decides to use the serial port for debug logs, pc_serial will ignore it to avoid conflicts.

device Communication controller (Serial controller, 16850) [7|0|5]
  vendor 1c00: Nanjing Qinheng Microelectronics Co., Ltd.
  device 3253: CH352/CH382 PCI/PCIe Dual Port Serial Adapter

Which match PCI_serial_16850, which is supposed to be supported as a generic 16850 Serial Port.

Here the kernel PCI enumaration detail about this card:

KERN: PCI: [dom 0, bus  4] bus   4, device  0, function  0: vendor 1c00, device 3253, revision 10
KERN: PCI:   class_base 07, class_function 00, class_api 05
KERN: PCI:   vendor 1c00: Nanjing Qinheng Microelectronics Co., Ltd.
KERN: PCI:   device 3253: CH352/CH382 PCI/PCIe Dual Port Serial Adapter
KERN: PCI:   info: Communication controller (Serial controller, 16850)
KERN: PCI:   line_size 10, latency 00, header_type 00, BIST 00
KERN: PCI:   ROM base host a0900000, pci a0900000, size 00008000
KERN: PCI:   cardbus_CIS 00000000, subsystem_id 3253, subsystem_vendor_id 1c00
KERN: PCI:   interrupt_line 10, interrupt_pin 01, min_grant 00, max_latency 00
KERN: PCI:   base reg 0: host 00004000, pci 00004000, size 00000100, flags 01
KERN: PCI:   base reg 1: host a0908000, pci a0908000, size 00008000, flags 08
KERN: PCI:   base reg 2: host 00004100, pci 00004100, size 00000004, flags 01
KERN: PCI:   base reg 3: host 00000000, pci 00000000, size 00000000, flags 00
KERN: PCI:   base reg 4: host 00000000, pci 00000000, size 00000000, flags 00
KERN: PCI:   base reg 5: host 00000000, pci 00000000, size 00000000, flags 00
KERN: PCI:   Capabilities: PM, MSI, PCIe
KERN: PCI:   Extended capabilities: Advanced Error Reporting

It’s a dual ports PCIe card, low profile.

And here the kernel syslog lines from pc_serial driver:

KERN: pc_serial: Generic 16550 Serial Port added
KERN: pc_serial: scanning PCI bus (alt)...
KERN: pc_serial: found PCI device 12 [7|0|5] 1c00:3253 as Generic 16850 Serial Port
KERN: pc_serial: irq line 16, pin 1
KERN: pc_serial: regs at 0x00004000 len 0x100
KERN: pc_serial: regs at 0x00004100 len 0x4
KERN: loaded driver /boot/system/add-ons/kernel/drivers/dev/ports/pc_serial

But only /dev/ports/pc_serial0 published, which match the first device found, the “Generic 16550 Serial Port” , which is a port present on the motherboard but, due to its position, is useable for me has it conflicts with the GPU card right above.

serial_debug_output is explicitly set to false in my /boot/home/config/settings/kernel/drivers/kernel file.
It’s the only parameter, beside load_symbols true defined in it, everything else is commented-out lines.

KERN: pc_serial: regs at 0x00004000 len 0x100
KERN: pc_serial: regs at 0x00004100 len 0x4

The driver looks for a register block of size 8, because of the port_constraints set in the sSupportedDevices array: { 8, 8, 8 } (these are the minimal allowed size of the register area, the max size, and the offset between separate UARTs if the card supports multiple ports).

Maybe you can try changing that to { 8, 256, 8 }, matching the size of your register bar size. It may have the unwanted consequence of trying to add 32 serial ports, in that case maybe a better option is: { 8, 256, 256 }

This card appears to have a specific setup in Linux, but it seems to just disable autoprobing of the UART type, which we don’t do. They force driving it as a 16550A instead of a 16850, but in our driver we don’t currently make that distinction (I think it would mainly allow larger buffer sizes?).