how to increase spidev bus speed

581 Views Asked by At

I want to communicate through SPI from an Up2 6000 and a microcontroller. On the Up2 I am using Ubuntu 20.04 with kernel 5.13 and the PREEMT_RT patch.

Linux up 5.13.0-rt1 #1 SMP PREEMPT_RT Thu Oct 13 12:09:18 CEST 2022 x86_64 x86_64 x86_64 GNU/Linux

Then my program to communicate through SPI sets the speed like this:

    int file_desctiptor = open("/dev/spidev1.0", O_RDWR);
    if (file_desctiptor < 0) {
        return -2;
    }

    // Set the spi mode
    if (ioctl(file_desctiptor, SPI_IOC_WR_MODE, SPI_MODE_1 | SPI_CS_HIGH) < 0) {
        close(file_desctiptor);
        return -3;
    }

    // Set the spi speed
    uint32_t speed{8000000};
    if (ioctl(file_desctiptor, SPI_IOC_WR_MAX_SPEED_HZ, &speed) < 0) {
        close(file_desctiptor);
        return -4;
    }

But on the oscilloscope I can see the speed of the SCLK signal is 1MHz. However, when I change the speed value for less than 1MHz I can notice the difference on the oscilloscope, so it must be a maximum set somewhere.

To enable spidev on the Up2 6000 I use ACPI overloads. I also modified the max speed here:

/*
 * This ASL can be used to declare a spidev device on SPI1 CS0
 */
DefinitionBlock ("", "SSDT", 5, "INTEL", "SPIDEV0", 0x00000001)
{
    External (_SB.PC00.SPI1, DeviceObj)

    Scope (\_SB.PC00.SPI1)
    {
        Device (TP0)
        {
            Name (_HID, "SPT0001")  // _HID: Hardware ID
            Name (_DDN, "SPI test device connected to CS0")  // _DDN: DOS Device Name
            Name (_CRS, ResourceTemplate ()  // _CRS: Current Resource Settings
            {
                SpiSerialBusV2 (0x0000, PolarityLow, FourWireMode, 0x08,
                    ControllerInitiated, 8000000, ClockPolarityLow,
                    ClockPhaseFirst, "\\_SB.PC00.SPI1",
                    0x00, ResourceConsumer, , Exclusive,
                    )
            })
        }
    }
}

But the speed is still 1MHz. Am I missing something else?

Edit: I have read back the speed using SPI_IOC_RD_MAX_SPEED_HZ and it is 8MHz but still on my logic analyzer I can see 1MHz.

I compiled my kernel with some logs to see what was happening in the drivers and I got this:

enter image description here

Apparently there are two instances of pxa2xx-spi driver, I suppose one is internal and we don't have much access (the first one with frequency 100MHz) and the other one is the one connected to the GPIO (so with frequency maximum limit of 990099 Hz).

Then, the SPT0001 ACPI module tries to modify this frequency to be 8MHz but as it is bigger than the one of the controller the driver does not set it. Finally, I try to open a file descriptor for SPI exchanges at 10MHz and again the driver refuses to open it because the controller has a smaller frequency.

Where is this frequency limit set? I tried compiling the kernel with different configurations but it didn't change. Is it something related to the hardware itself? Or perhaps another ACPI that I am missing?

0

There are 0 best solutions below