cloonam
Posts: 1
Joined: Wed Jun 05, 2019 11:06 pm

Cannot Use SPI frequency above 500 kHz

Wed Jun 05, 2019 11:10 pm

I am running Arch Linux ARM on a Raspberry Pi 2 Model B, and I am attempting to communicate with a TFT display. I am writing a kernel module to interface with the display using SPI, and it works, but I cannot get the SPI frequency to go above 500 kHz. I have successfully used higher frequencies in the user space when using the BCM2835 library, so I know it is possible.

Using the following command to parse the device tree,

Code: Select all

dtc -I fs /sys/firmware/devicetree/base | grep max-frequency
I can see that

Code: Select all

spi-max-frequency = <0x7735940>
which is hexadecimal for 150 MHz.

Code: Select all

hexdump /sys/class/spi_master/spi0/of_node/spi-max-frequency
gives me

Code: Select all

7307 4059
hexadecimal for the same number (just with the byte order reversed). In my kernel module, I do the following.

Code: Select all

struct spi_board_info spiBoardInfo = {
        .modalias = "spi",
        .max_speed_hz = 32000000,
        .bus_num = 0,
        .chip_select = 0,
        .mode = 0
    };

    master = spi_busnum_to_master(spiBoardInfo.bus_num);
    spiDevice = spi_new_device(master, &spiBoardInfo);
    spiDevice->bits_per_word = 8;
    ret = spi_setup(spiDevice);
    printk(KERN_INFO "TFT: device max speed %ld\n", spiDevice->max_speed_hz);
which prints out

Code: Select all

32000000
as expected (error checking code was removed above for brevity). To write to the slave, I use the following command

Code: Select all

spi_write(spiDevice, &data, sizeof(data));
(I have also tried using

Code: Select all

spi_sync_transfer()
and setting the speed there as well, to no avail). This command successfully writes the data, but at a speed of 500 kHz.

Does anyone know why I am being limited to this frequency?

Return to “Arch”