SPI IO configuration before SPIDEV is used

We do use an Apalis iMX6 board and TorizonCore.
The SPI is shared with the external MCU placed on the carrier board.
Apalis and MCU shares the control of one of the devices on the carrier board. The goal is:

  1. Before the full boot of Apalis: the control is given to MCU.
  2. After the boot and running the containers: control is given to Apalis.

I do have ability to synchronize the handover of the SPI (dedicated pin from MCU to Apalis) to prevent the bus collision between MCU and Apalis.

However I do have some question: what is a I/O configuration for SPI during initialization?
a) Does the iMX6 drive the MISO and SCK pins just after device tree or driver load by kernel?
b) Those are tristate (or pull-up/down) until the application uses spidev driver?

In other words: could I use those pins by external MCU before application using it is executed on Apalis? If no - then how could I initialize the SPI after the OS boots?

Thank you in advance for your answer!

Hi @marek.kucinski ,

Thank you for your patience.

We’re having a look and come back to you as soon as possible.

Have a great day.

Best Regards

Hi @marek.kucinski

Everything related to the pinctrl (e.g. muxing, drive strength, pull-ups/pull-downs, etc.) is applied as soon as the SPI Controller driver loads. This means the settings are applied before you access SPI from user space (e.g. via spidev). However, if you compile the driver (spi-imx.ko) as a module it would only be applied when you load the driver (with modprobe/insmod).

There is another problem. U-Boot will also configure some pins, so if U-Boot does the configuration you might still have a conflict. You can disable it entirely if you don’t need it in U-Boot but maybe rethink the HW design and use a proper multiplexer instead.


Hi Stefan,
thank you for the response.

I assume that initial state is inputs (for almost all GPIOs).

  1. Which part of initialization is done under U-boot and what is done by the driver? Is there a documentation regarding those activities?

You wrote:

U-Boot will also configure some pins

  1. You mean those configured in device tree?

  2. What is the state of output pins (i.e. MOSI/SCK/CS) after the load of the SPI driver but before the usage of the SPI device by the user application (so before any transfer):
    a) push-pull to a state defined by device-tree,
    b) tri-state (input),
    c) pull-up/down (defined by device tree)?

I agree the best way would be the hardware update - although I try to find a workaround for existing design.

Hi @marek.kucinski ,

Unfortunately, there is no documentation about this. You could try to read the source code of u-boot and linux to understand how the pin you’re interested in is handled.

Not directly, you should check the board file (from u-boot) to understand how u-boot handles each HW interface.

You can see here that the SPI node is disabled and it is not mentioned anywhere else inside u-boot, which means it will stay disabled.

The state of any pin referenced by the device tree node, should be the state define by its pinctrl.

Hope this helps

Best Regards

Hi @marek.kucinski,

Do you have any news on this topic?

Best regards,

Nope - as getting into uboot programming is not jump-start for us, we need to plan it into our schedule when other urgent tasks will be finished. When we will investigate your proposition, I will let you know back here.

Hi @marek.kucinski !

Let us know if you have any updates regarding this topic :slight_smile:

Best regards,