Waveshare UART Expansion HAT (sc16is7xx) with sysfs

bluecamel
bluecamel New Member Posts: 4

I'm trying to get a Waveshare UART Expansion HAT working and am having trouble.

My understanding is that I can use the sc16is7xx kernel module along with sysfs to enable and create tty devices. As far as I can tell (with the sc16is7xx module loaded), I need to run echo "sc16is7xx 0x48" > /sys/bus/pci/devices/*/i2c_designware.0/i2c-1/new_device, which should create the devices, but it doesn't. dmesg does show i2c i2c-1: new_device: Instantiated device sc16is7xx at 0x48 after running that command.

I'm not sure if this is related, but sudo mraa-i2c detect 0 shows the device but i2cdetect -y -r 0 doesn't:

$ sudo mraa-i2c detect 0
00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

$ sudo i2cdetect -y -r 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Thanks for any help!

Answers

  • DannyB
    DannyB New Member Posts: 3

    The MRAA i2c bus numbering is not the same as the system I2C bus numbering.
    https://github.com/AaeonCM/mraa/blob/b20089c2a99a854e3b95a8fb08f4ea9bacdccd7f/src/x86/up2_6000.c#L230

    The MRAA AAEON fork uses i2c-1 (well, whatever designware.4 gets assigned) as the default bus #0.

  • bluecamel
    bluecamel New Member Posts: 4

    Thanks, DannyB. I was able to find the right one through both MRAA and i2c-inspect, so I think that I'm using the right one. I still can't get it to create devices, though. I think that I must need to provide the IRQ pin somewhere, but I'm not sure how and it's difficult to find information on it.

  • DannyB
    DannyB New Member Posts: 3
    edited September 18

    Ah, okay, no.

    The message you are getting is deceptive. It is not actually probing anything.
    up-edge-garage# echo "helloworld 0x52" > /sys/bus/pci/devices/*/i2c_designware.0/i2c-1/new_device
    [252731.434759] i2c i2c-1: new_device: Instantiated device helloworld at 0x52

    Two problems:
    1. The driver you are using is meant really for ACPI or DT configs. It has no idea what chip you are really trying to probe.

    I believe you can workaround this by being explicit, and using the actual chip id.
    Try using sc16is752 instead of sc16is7xx

    1. You will still have to hack the driver module to get yourself an interrupt pin and recompile it. It doesn't support ACPI configs, and so there is no other way to get the pin in there.

    The last time i did this i was using a 762. The patch looked like the attached. Should not be hard to get it working for the 752 on the waveshare.

    On the other hand, if you don't care about whether it is a kernel driver, and just care that you get a TTY you can use, something like https://github.com/vogelchr/sc16is17xx_linux_i2c_spi should work - it will create you a userspace TTY that will function as well as the kernel one would :)

  • bluecamel
    bluecamel New Member Posts: 4

    Thanks, DannyB, for the advice. Unfortunately, neither of these paths has worked for me. Have you made either of these work with the 752?

  • bluecamel
    bluecamel New Member Posts: 4

    I'm not going to attempt to explain all that I ran into with the kernel driver, but I'll share what I see with the userspace driver.

    First, to confirm that the device is connected:

    $ sudo i2cdetect -y -r 4
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: 40 41 -- 43 -- -- -- -- 48 -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --
    

    So, it's showing up on i2c-4 as 0x48, which seems right. Then, I run:

    $ sudo ./sc16is7xx_demo -d /dev/i2c-4 -a 0x48
    [sudo] password for bluecamel:
    Virtual terminal is /dev/pts/2.
    ioctl(SPI_IOC_WR_MODE): Inappropriate ioctl for device
    Could not create sc16is7xx instance.
    

    Regardless, poking at the code, I don't see that it can create two ports. So, even if I get this working, I don't think it's very useful since I'll only have the one port. Is that right?