This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/OMAP-L138: spidev error -22 EINVAL

Part Number: OMAP-L138
Other Parts Discussed in Thread: OMAPL138

Tool/software: Linux

Hello,

I am attempting to get SPI communication working on the new Processor SDK release of Linux for the OMAP-L138.  On the previous SDK, MCSDK_1_01_00_02, I was able to get SPI working after changing the board configuration files, some light driver edits, and configuring the kernel for SPI in the user space.  The user space software I wrote uses the spidev character device and ioctl calls.  

Upon switching to the new SDK with Kernel 4.9.28, things have changed quite a bit.  I modified the device tree, da850-lcdk.dts and configured the kernel for user space spi.  The edits to the device tree look like this:

&spi1 {
  status = "okay";
  spidev@0 {
    spi-max-frequency = <24000000>;
    reg = <0>;
    compatible = "rohm,dh2228fv";
    status = "okay";
  };
};

After this change, the device node /dev/spidev32766.0 appeared.  I modified my code to open this device and attempted to execute it.  The result was an error code -22, EINVAL.  The ioctl was returning an invalid argument error.  The section of my code that initiates the transfer is shown below:

struct spi_ioc_transfer tr = {
  .tx_buf = (unsigned long)tx,
  .rx_buf = (unsigned long)rx,
  .len = len,
  .delay_usecs = 1,
  .speed_hz = 10000,
  .bits_per_word = 8,
  .cs_change = 0,
};

ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);

where tx is a two character long buffer, len=2, rx=NULL, and fd is the file descriptor for /dev/spidev32766.0.  The return value in this case is -1, and perror shows "invalid argument".  

I am having a hard time figuring out what the invalid argument is, since this code worked without issue in the previous system.  It is also puzzling why the spidev bus number is so high, and not '1' as it was in the past.

Any insight that can be provided is greatly appreciated.

Jeff

  • Hi Jeff,

    Have you enabled:
    CONFIG_SPI_SPIDEV
    in tisdk_omapl138-lcdk_defconfig?

    Also you need to configure the spi pinmux in u-boot/board/davinci/da8xxevm/omapl138_lcdk.c.

    Best Regards,
    Yordan
  • Yordan,

    Thank you for your response. I have the following configs enabled in my .config file:
    CONFIG_REGMAP_SPI=y
    CONFIG_SPI=y
    CONFIG_SPI_MASTER=y
    CONFIG_SPI_BITBANG=y
    CONFIG_SPI_DAVINCI=y
    CONFIG_SPI_SPIDEV=y

    This was done through the "menuconfig" utility.

    As far as pinmuxing goes, I have not yet implemented that, but I was able to connect with the CCS debugger to manually set the pinmux registers. After setting the registers, I started and stopped the part to verify that the values were indeed set. This yielded no change in behaviour. In the past, I was able to set the pinmux during the linux kernel boot sequence by modifying the board files (arch/arm/mach-davinci/omapl138-lcdk.c ). Is it now the case that the pinmux can only be set in u-boot?

    As a side note, the reply, verify, and reject buttons are not working for me in Chromium Version 59.0.3071.109 on Ubuntu 16.04LTS. Firefox is working.

    Jeff
  • Hi,

    In the past, I was able to set the pinmux during the linux kernel boot sequence by modifying the board files (arch/arm/mach-davinci/omapl138-lcdk.c ). Is it now the case that the pinmux can only be set in u-boot?

    Yes, latest SDKs set pinmux only in u-boot.
    As for the SPIDEV issue, let me try this on my OMAP-L138 LCDK & I will report back the results.

    As a side note, the reply, verify, and reject buttons are not working for me in Chromium Version 59.0.3071.109 on Ubuntu 16.04LTS. Firefox is working.

    Clear the browser cache & restart it. This did it for me :)

    Best Regards,
    Yordan
  • Good to know about u-boot. I have resolved the spidev problem. It seems that the speed_hz parameter was out of bounds. Removing this from the structure allowed the peripheral to transmit.

    Clearing the cache worked! Thank you for you help!

    Jeff
  • Hi Jeff, 

    Thanks for updating the thread. 

    Best Regards, 
    Yordan