Wiki

This version (24 Sep 2020 05:35) was approved by cathy fang.The Previously approved version (27 Jul 2020 06:01) is available.Diff

SPI Driver

Introduction

This section describes the steps required to build and use the SPI bus on Linux using an ADSP-SC5xx board. The Serial Peripheral Interface (SPI) bus is a four wire master/slave full duplex synchronous bus. You can hook up multiple slave devices by utilizing chip select lines. The bus is composed of two data pins, one clock pin, and one chip select pin:

  • SCLK - Serial Peripheral Interface Clock Signal (generated by the master) (also referred to as SCK)
  • MOSI - Master Out Slave In data (output from the master)
  • MISO - Master In Slave Out (output from the slave)
  • CS - Chip Select (also referred to as Slave Select (SS))

It is not uncommon to use the bus with just one master and one slave, but it is certainly possible to use it as a real bus with many devices on it.

Each slave may operate at different clock frequencies as well as different clock polarities and clock phases with respect to the data. The permutations of polarities and phases are referred to as SPI modes. Below you can see the relationship between modes and the polarity/phase of the clock.

Mode Polarity Phase
SPI_MODE_0 0 0
SPI_MODE_1 0 1
SPI_MODE_2 1 0
SPI_MODE_3 1 1

Chip specifications won't always say “uses SPI mode X” in as many words, but their timing diagrams will make the CPOL and CPHA modes clear.

The figures below demonstrate the two basic transfer formats as defined by the CPHA bit. Two waveforms are shown for SPI_CLK—one for SPI_CTL.CPOL=0 and the other for SPI_CTL.CPOL=1.

Hardware Setup

An ADSP-SC5xx EZ-Board:

  • ADSP-SC589 Ezkit v1.1 and above, or,
  • ADSP-SC584 Ezkit v1.0 and above, or,
  • ADSP-SC573 Ezkit v1.2 (BOM 1.8) and above
  • ADSP-SC589 MINI v1.4 and above

Software Configuration

The following configuration should be done on top of the SC589-ezkit/SC584-ezkit/SC573-ezkit/SC589-mini default configuration.

Configure Linux Kernel

Enable SPI controller driver for ADSP-SC5xx

Device Drivers  --->
    [*] SPI support  --->
        <*>   SPI controller v3 for ADI

Enable SPI slave driver (for example spi flash w25q128)

Device Drivers  ---> 
    <*> Memory Technology Device (MTD) support  --->
        <*>   SPI-NOR device support  --->
        Self-contained MTD device drivers  --->
            <*> Support most SPI Flash chips (AT26DF, M25P, W25X, ...)

Enable spidev driver if you want to use user space API.

Device Drivers  ---> 
    [*] SPI support  --->
         <*>   User mode SPI device driver support
         

Configure Device tree

SPI slave node properties

SPI busses can be described with a node for the SPI master device and a set of child nodes for each SPI slave on the bus. Below is the child node for SPI flash of SPI master2 node.

flash: w25q32@0 {
        #address-cells = <1>;
        #size-cells = <1>;
        compatible = "winbond,w25q32";
        spi-max-frequency = <500000>;
        reg = <38>;
        spi-cpol;
        spi-cpha;
	spi-rx-bus-width = <4>;
        dma-mode;
}

SPI slave nodes must be children of the SPI master node and can contain the following properties. reg - (required) Chip select address of device. compatible - (required) Name of SPI device following generic names recommended practice spi-max-frequency - (required) Maximum SPI clocking speed of device in Hz spi-cpol - (optional) Empty property indicating device requires inverse clock polarity (CPOL) mode spi-cpha - (optional) Empty property indicating device requires shifted clock phase (CPHA) mode spi-cs-high - (optional) Empty property indicating device requires chip select active high spi-rx-bus-width - (optional) A value of 4 indicates to setup the SPI controller to receive data in Quad SPI mode. dma-mode - (optional) Empty property indicating device requires DMA mode transfer

spidev device node

If you want to use spidev, please add following SPI slave node to SPI master0 node. Only for ADSP-SC573 Ezkit:

spidev {
        #address-cells = <1>;
        #size-cells = <1>;
        compatible = "rohm,dh2228fv";
        spi-max-frequency = <5000000>;
        reg = <38>;
};

For other boards:

spidev {
        #address-cells = <1>;
        #size-cells = <1>;
        compatible = "rohm,dh2228fv";
        spi-max-frequency = <5000000>;
        reg = <44>;
};

Example

Add spidev_test program if you want to use user space SPI test utility.

$ vim build/conf/local.conf
IMAGE_INSTALL_append = " spidev_test"

Test example as:

# spidev_test -D /dev/spidev0.44 -b 8 -H -O 
spi mode: 0x3 
bits per word: 8 
max speed: 500000 Hz (500 KHz)
FF 80 00 00 3F FF 
40 00 00 00 02 00 
3F FF FF FF FF 80 
00 00 3F FF FF FF 
FF 80 00 00 3F FF 
DE AD BE 80 00 00 
30 0D

Back to Kernel Features and Device Drivers for ADSP-SC5xx Yocto Linux

resources/tools-software/linuxdsp/docs/linux-kernel-and-drivers/spi/spi.txt · Last modified: 24 Sep 2020 05:33 by cathy fang