NOTICE: The Processors Wiki will End-of-Life on January 15, 2021. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.

TI81XX PSP McSPI Driver User Guide

From Texas Instruments Wiki
Jump to: navigation, search
TIBanner.png
TI81XX PSP McSPI Driver User Guide
Linux PSP
IMPORTANT

TI81XX refers to TI816X, TI814X and TI813X.


Overview[edit]

Some of the features of an SPI interface are,

  • Serial interface
  • Synchronous
  • Master-slave configuration (driver supports only master mode)
  • Data Exchange - DMA/PIO (driver supports only PIO mode)

SPI H/W Architecture[edit]

NoteNote: This is just a reference block diagram, the actual SPI hardware might have more number of buses and also it might support more advanced features. For example, there are 4 McSPI controllers in TI814X and 1 in TI816X. Please refer the hardware TRM for the actual information. Information for TI814X is applicable for TI813X as well.

SPI HW Block Diagram.jpg


SPI Driver Architecture[edit]

Spi driver architecture.jpg

TI8168/TI8148 EVM does not contain a SPI based audio codec. The reference to 'SPI Codec' above are meant to serve as an example.


SPI Support[edit]

  • SPI could be disabled/enabled from the following location during menuconfig
  Device Drivers  ---> 
         [*] SPI support  ---> 
            <*>   McSPI driver for OMAP24xx/OMAP34xx/TI81XX
  • Enable W25X32 SPI flash support. This step is mandatory if for using root file-system on SPI flash.
Device Drivers  ---> 
  <*> Memory Technology Device (MTD) support  ---> 
         Self-contained MTD device drivers  ---> 
            <*> Support most SPI Flash chips (AT26DF, M25P, W25X, ...)
            [*]   Use FAST_READ OPCode allowing SPI CLK <= 50MHz (NEW)

Loadable Module Support[edit]

  • Incase if you want to build the drivers as modules, use <M> instead of <*> during menuconfig while selecting the drivers (as shown below). For more information on loadable modules refer Loadable Module HOWTO
  Device Drivers  ---> 
         [*] SPI support  ---> 
            <M>   McSPI driver for OMAP24xx/OMAP34xx/TI81XX
Device Drivers  ---> 
 <*> Memory Technology Device (MTD) support  ---> 
       Self-contained MTD device drivers  ---> 
          <M> Support most SPI Flash chips (AT26DF, M25P, W25X, ...)
          [*]   Use FAST_READ OPCode allowing SPI CLK <= 50MHz (NEW)
  • This step applies if the drivers are built as modules, all of the below commands are run from Linux command line,
    • Do "make modules" to build the McSPI driver and SPI Flash driver as module. The module should be present in "drivers/spi/omap2_mcspi.ko" and "drivers/mtd/devices/m25p80.ko".
    • Copy the ".ko" files to the target
    • In the target command prompt, load the driver using "insmod <module_name.ko>"
    • Following sequence should be used during insertion and removal of modules

Module insertion sequence

insmod omap2_mcspi.ko
insmod m25p80.ko

Module removal sequence'

rmmod m25p80.ko
rmmod omap2_mcspi.ko

Validating SPI Support[edit]

  • Use the MTD interface provided for SPI flash on the EVM to validate the SPI driver interface. The below step copies 8KiB from /dev/mtd1 partition (u-boot env) to /dev/mtd3 partition and reads the 8KiB image from /dev/mtd3 to a file and checks the md5sum. The md5sum of test.img and test1.img should be same.
cd /tmp
dd if=/dev/mtd1 of=test.img bs=8k count=1
md5sum test.img
flash_eraseall /dev/mtd3
cp test.img /dev/mtd3
dd if=/dev/mtd3 of=test1.img bs=8k count=1
md5sum test1.img 


Proc Interface[edit]

The /proc/mtd kernel interface is a status interface. A lot of useful information about the partitions created after inserting modules can be found in the /proc/mtd file.

  • Use /proc/mtd to get information on how many partitions are currently configured by the kernel's flash driver.
    target$ cat /proc/mtd

You should see output similar to:

    target$ cat /proc/mtd
  dev:    size   erasesize  name
  mtd0: 00020000 00020000 "U-Boot-min"
  mtd1: 00240000 00020000 "U-Boot"
  mtd2: 00020000 00020000 "U-Boot Env"
  mtd3: 00440000 00020000 "Kernel"
  mtd4: 0c820000 00020000 "File System"
  mtd5: 03120000 00020000 "Reserved"


Porting to custom hardware[edit]

  • drivers/spi/omap2_mcspi.c implements core SPI master functionality.
    • This file is generic hence should not modify it.
  • Board specific customizations are available in arch/arm/mach-omap2/board-ti8168evm.c and arch/arm/mach-omap2/board-ti8148evm.c
  • Modify device array ti8168_evm_spi_info (for TI816X) or TI8148_evm_spi_info (for TI814X) to change information on slaves connected to SPI. When adding new slave devices, ensure that num_chipselect member of the platform data is updated for the corresponding SPI master.
    • Each member is of type spi_board_info defined in include/linux/spi. Each element of the device array represents one slave device.
      • modalias used to match slave device to slave driver. Note that this is not the SPI master driver. Each slave needs to have its own driver. Example, SPI flash will have a MTD driver, SPI codec will have an ALSA driver etc.
      • platform_data used by slave driver
      • controller_data used by SPI master driver for slave specific information (of type omap2_mcspi_cs). This is used to take care of specific requirements for communicating with a given slave.
      • bus_num Bus number identifies the SPI controller instance to which the SPI slave is connected. Numbering starts with '1'. Hence should use 1 for the first SPI controller. Please check the EVM schematic to identify the bus number to which your SPI slave is connected. On TI816X and TI814X EVM, it is the first SPI controller to which the SPI flash is connected.
      • chip_select chip select number for this SPI slave (0 on TI81XX EVMs)
      • max_speed_hz SPI bus speed.
  • Ensure all pins required for SPI operation are muxed correctly (especially if using GPIO for CS)


Supporting SPI Flashes[edit]

  • To modify partition layout on SPI flash following structure has to be modified in arch/arm/mach-omap2/board-ti8168evm.c and arch/arm/mach-omap2/board-ti8148evm.c
struct mtd_partition ti816x_spi_partitions[] = { /* For TI8168 EVM */

                 (or)

struct mtd_partition ti8148_spi_partitions[] = {  /* For TI8148 EVM */

    /* All the partition sizes are listed in terms of NAND block size */
    {
        .name       = "U-Boot",
        .offset     = 0,    /* Offset = 0x0 */
        .size       = 64 * SZ_4K,
        .mask_flags = MTD_WRITEABLE,    /* force read-only */
    },
    {
        .name       = "U-Boot Env",
        .offset     = MTDPART_OFS_APPEND,   /* Offset = 0x40000 */
        .size       = 2 * SZ_4K,
    },
    {
        .name       = "Kernel",
        .offset     = MTDPART_OFS_APPEND,   /* Offset = 0x42000 */
        .size       = 640 * SZ_4K,
    },
    {
        .name       = "File System",
        .offset     = MTDPART_OFS_APPEND,   /* Offset = 0x2C2000 */
        .size       = MTDPART_SIZ_FULL,     /* size = 1.24 MiB */
    }
};

  • SPI Flash information is available in following structure in file arch/arm/mach-omap2/board-ti8168evm.c (for TI816X) and arch/arm/mach-omap2/board-ti8148evm.c (for TI814X). This structure should be modified to support a SPI flash. The example structure given here supports most of the SPI flashes, check drivers/mtd/devices/m25p80.c for support for the new SPI flash. The string constants .modalias and .type depend on device names provided in the slave driver (in our case m25p32.c). The .type string here selects W25X32 SPI flash, which has to be modified in case of new SPI flash.
struct spi_board_info __initdata ti816x_spi_slave_info[] = { /* For TI8168 EVM */

                          (or)

struct spi_board_info __initdata ti8148_spi_slave_info[] = { /* For TI8148 EVM */

    {
        .modalias   = "m25p80",
        .platform_data  = &ti816x_spi_flash,
        .irq        = -1,
        .max_speed_hz   = 75000000,
        .bus_num    = 1,
        .chip_select    = 0,
    },
};

const struct flash_platform_data ti816x_spi_flash = { /* For TI8168 EVM */
       
               (or)

const struct flash_platform_data ti8148_spi_flash = { /* For TI8148 EVM */

    .type       = "w25x32",
    .name       = "spi_flash",
    .parts      = ti816x_spi_partitions,
    .nr_parts   = ARRAY_SIZE(ti816x_spi_partitions),
};


  • Check if drivers/mtd/devices/m25p80.c support the new SPI flash. If it is not supported then the new SPI flash device information has to be added to the m25p_ids[] list.
E2e.jpg {{
  1. switchcategory:MultiCore=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article TI81XX PSP McSPI Driver User Guide here.

Keystone=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article TI81XX PSP McSPI Driver User Guide here.

C2000=For technical support on the C2000 please post your questions on The C2000 Forum. Please post only comments about the article TI81XX PSP McSPI Driver User Guide here. DaVinci=For technical support on DaVincoplease post your questions on The DaVinci Forum. Please post only comments about the article TI81XX PSP McSPI Driver User Guide here. MSP430=For technical support on MSP430 please post your questions on The MSP430 Forum. Please post only comments about the article TI81XX PSP McSPI Driver User Guide here. OMAP35x=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article TI81XX PSP McSPI Driver User Guide here. OMAPL1=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article TI81XX PSP McSPI Driver User Guide here. MAVRK=For technical support on MAVRK please post your questions on The MAVRK Toolbox Forum. Please post only comments about the article TI81XX PSP McSPI Driver User Guide here. For technical support please post your questions at http://e2e.ti.com. Please post only comments about the article TI81XX PSP McSPI Driver User Guide here.

}}

Hyperlink blue.png Links

Amplifiers & Linear
Audio
Broadband RF/IF & Digital Radio
Clocks & Timers
Data Converters

DLP & MEMS
High-Reliability
Interface
Logic
Power Management

Processors

Switches & Multiplexers
Temperature Sensors & Control ICs
Wireless Connectivity