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.

SPI interface for FRAM in TMS320DM365



Hello all,

In my project i am currently using custom board TMS320DM365 with ipnc_rdk Version5.0
We have external RAMTRON FM25V02 256Kbit FRAM interfaced to DM365 through SPI2.

I want to do read write operation with the FRAM.
In the board, only spi0 was enabled.

I did the following modifications in the kernel:

In arch/arm/mach-davinci/board-dm368-ipnc.c file:

struct davinci_eeprom_info davinci_spi2_micron_info = {
        .eeprom_size = 262144,
        .page_size = 262144,,
        .page_mask = 0x3FFFF,
        .chip_sel = SCS0_SELECT,
        .parts = NULL,
        .nr_parts = 0,
        .commit_delay = 3,
};
struct davinci_spi_config_t davinci_spi2_micron_spi_cfg = {
        .wdelay         = 0,
        .odd_parity     = 0,
        .parity_enable  = 0,
        .wait_enable    = 0,
        .lsb_first      = /*1,*/0,
        .timer_disable  = 0,
        .clk_high       = 1,//0,
        .phase_in       = 0,
        .clk_internal   = 1,
        .loop_back      = 0,
        .cs_hold        = 1,
        .intr_level     = 0,
        .pin_op_modes   = /*SPI_OPMODE_3PIN,*/SPI_OPMODE_SPISCS_4PIN,
#ifndef CONFIG_SPI_INTERRUPT
        .poll_mode      = 1,
#endif
};

static struct spi_board_info dm3xx_spi2_board_info[] = {
        [0] = {
                .modalias = "spidev",
                .platform_data = &davinci_spi2_micron_info,
                .controller_data = &davinci_spi2_micron_spi_cfg,
                .mode = SPI_MODE_0,
                .irq = 0,
                .max_speed_hz = 14 * 1000 * 1000 /* max sample rate at 3V */ ,
                .bus_num = 2,
                .chip_select = 0,
        },
};

 dm365_init_spi2(BIT(0), dm3xx_spi2_board_info,
                        ARRAY_SIZE(dm3xx_spi2_board_info));

In arch/arm/mach-davinci/dm365.c file:

static u64 dm365_spi2_dma_mask = DMA_BIT_MASK(32);

static u8 chsel[1] = {33};

static struct davinci_spi_platform_data dm365_spi2_pdata = {
        .version = SPI_VERSION_1,
        .num_chipselect = 1,
        .chip_sel = chsel,
        .clk_name = "SPICLK",
};

static struct resource dm365_spi2_resources[] = {
        {
                .start = 0x01c67800,
                .end   = 0x01c67fff,
                .flags = IORESOURCE_MEM,
        },

        {
                .start = IRQ_DM365_SPIINT0_0,
                  .end = IRQ_DM365_SPIINT0_0,
                .flags = IORESOURCE_IRQ,
        },
        /*//disable dma for spi currently
        {
                .start = 17,
                .flags = IORESOURCE_DMA,
        },
        {
                .start = 16,
                .flags = IORESOURCE_DMA,
        },
        {
                .start = EVENTQ_3,
                .flags = IORESOURCE_DMA,
        },
        */
};

static struct platform_device dm365_spi2_device = {
        .name = "spi_davinci",
        .id = 2,
        .dev = {
                .dma_mask = &dm365_spi2_dma_mask,
                .coherent_dma_mask = DMA_BIT_MASK(32),
                .platform_data = &dm365_spi2_pdata,
        },
        .num_resources = ARRAY_SIZE(dm365_spi2_resources),
        .resource = dm365_spi2_resources,
};

void __init dm365_init_spi2(unsigned chipselect_mask,
                struct spi_board_info *info, unsigned len)
{
        davinci_cfg_reg(DM365_SPI2_SCLK);
        davinci_cfg_reg(DM365_SPI2_SDI);
        davinci_cfg_reg(DM365_SPI2_SDO);

        /* not all slaves will be wired up */
        if (chipselect_mask & BIT(0))
                davinci_cfg_reg(DM365_SPI2_SDENA0);
        if (chipselect_mask & BIT(1))
                davinci_cfg_reg(DM365_SPI2_SDENA1);

        spi_register_board_info(info, len);

        platform_device_register(&dm365_spi2_device);
}


After doing these modifications, I was able to find /dev/spi2.0 and  open this

device.But read and write wont happen. It hangs at ioctl function call.

When i probed for SPI2_CS(which is active low enabled), is still high.And also spi2 clock is not coming.

in arch/arm/mach-davinci/dm365.c file, SPI2 is muxed as follows:

MUX_CFG(DM365,  SPI2_SCLK,      4,   10,    3,    1,     false)
MUX_CFG(DM365,  SPI2_SDI,       4,   6,     3,    1,     false)
MUX_CFG(DM365,  SPI2_SDO,       4,   8,     3,    1,     false)
MUX_CFG(DM365,  SPI2_SDENA0,    4,   12,    3,    1,     false)
MUX_CFG(DM365,  SPI2_SDENA1,    4,   8,     3,    2,     false)

Are the SPI2 mux configurations okay?

please let me know what should be done. Is the modifications done by me correct?
Am i in the proper direction?

Also i found RAMTRON FRAM driver from the below link:


http://code.google.com/p/nixduino/source/browse/drivers/mtd/spi/ramtron.c?r=e0987e251ff0eff25a55bf8db13a41f5849f59f7

How to use this driver? How to make ramtron driver available in make menuconfig?
I am doing the spi driver for the first time.
Plaese suggest me the options.

Regards,
Arpitha

  • Hi,

    I tried to do loop back test on spi2.0.. I made the following changes

    static struct spi_board_info dm3xx_spi2_board_info[] = {
            [0] = {
                    .modalias = "spidev",
                    //.platform_data = &davinci_spi2_micron_info,
                    //.controller_data = &davinci_spi2_micron_spi_cfg,
                    .platform_data = NULL,
                    .controller_data = NULL,
                    .mode = SPI_MODE_0,
                    .irq = 0,
                    //.max_speed_hz = 14 * 1000 * 1000 /* max sample rate at 3V */ ,
                    .max_speed_hz = 2 * 1000 * 1000 /* max sample rate at 3V */ ,
                    .bus_num = 2,
                    .chip_select = 0,
            },
    };

    Also i changed the mux configurations as per this document http://www.ti.com/lit/ug/sprufg5a/sprufg5a.pdf

    Previously mux configurations were:

    MUX_CFG(DM365,        SPI2_SDI,       4,   6,     3,    1,     false)
    MUX_CFG(DM365,        SPI2_SDO,       4,   8,     3,    1,     false)

    And now it is

    MUX_CFG(DM365,  SPI2_SDI,       4,   8,     3,    1,     false)
    MUX_CFG(DM365,  SPI2_SDO,       4,   6,     3,    1,     false)

    So when i do ./spidev_test -D /dev/spidev2.0 -l  It prints the following statements

    spi mode: 32
    bits per word: 8
    max speed: 500000 Hz (500 KHz)

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

    Why is it hanging? Can anyone please help me ?

    Thanks and Regards,

    Arpitha

  • Hi,

    Have you ever probed the SPI clock through CRO when you configured the SPI in loopback mode?

    mean while, I'm checking your pinmux details & update the results,

    Also i found RAMTRON FRAM driver from the below link:

    http://code.google.com/p/nixduino/source/browse/drivers/mtd/spi/ramtron.c?r=e0987e251ff0eff25a55bf8db13a41f5849f59f7

    How to use this driver? How to make ramtron driver available in make menuconfig?

    Actually, It may not tested by TI & it can be done at user's risk,

    To add the FRAM support,

    Share your Makefile & Kconfig file from "linux-source/drivers/mtd/spi/" locations,

  • Hi Titus,

    Even with loopback mode, spi clock is not coming.

    Please let me know if anything else has to be modified

    Also find the Makefile and Kconfig files from ipnc_psp_03_21_00_04/kernel/drivers/spi folder in the following path

    6114.MakefileAndKconfig.zip

    Thanks and Regards,

    Arpitha

  • Hi,

    Refer the below e2e post as like you but it is OMAPL13x

    http://e2e.ti.com/support/dsp/omap_applications_processors/f/42/t/329624.aspx

    1) File: arch/arm/mach-davinci/dm365.c

    2) File: arch/arm/mach-davinci/include/mach/mux.h

    3) File: arch/arm/mach-davinci/board-dm365-evm.c

    For SPI loopback testing,

    #include <linux/spi/spi.h>

    static struct spi_board_info dm365_evm_spi_info[] __initconst = {
        {
            .modalias = "spidev",
            .max_speed_hz    = 10 * 1000 * 1000,
            .bus_num    = 2,     /* mention your SPI bus no */
    //        .chip_select    = 0,    /* give your CS no if any */
            .mode        = SPI_MODE_0,
        },
    };

    I hope that you are using the below line in init fn.


    //use the below line in init fn.
        dm365_init_spi0(BIT(0), dm365_evm_spi_info,
                ARRAY_SIZE(dm365_evm_spi_info));

    Please try this for SPI loopback & let me know the status,

    Also i found RAMTRON FRAM driver from the below link:

    http://code.google.com/p/nixduino/source/browse/drivers/mtd/spi/ramtron.c?r=e0987e251ff0eff25a55bf8db13a41f5849f59f7

    How to use this driver? How to make ramtron driver available in make menuconfig?

    Sorry, I have not noticed clearly,

    This is u-boot driver implementation code & not for linux, so not possible.

    Just google for linux driver implementation,

    Previously mux configurations were:

    MUX_CFG(DM365,        SPI2_SDI,       4,   6,     3,    1,     false)
    MUX_CFG(DM365,        SPI2_SDO,       4,   8,     3,    1,     false)

    And now it is

    MUX_CFG(DM365,  SPI2_SDI,       4,   8,     3,    1,     false)
    MUX_CFG(DM365,  SPI2_SDO,       4,   6,     3,    1,     false)

    Why do you have changed this?

    I think that you dont need to change and if SPI2 is pinmuxed already.

    6, 8 are the offsets of PINMUX4 for SPI2

    3 - is the default (no worries)

    1 - is used to choose the functionality of peripheral whether this pin is GPIO or SPI

    http://e2e.ti.com/support/dsp/omap_applications_processors/f/42/p/325699/1134825.aspx#1134825

    Are you using any CS (chip select) signal for SPI device?

  • Hi,

    1. For loopback testing,

    I modified spi_board_info strucure as suggested by you

    static struct spi_board_info dm3xx_spi2_board_info[] = {
            [0] = {
                    .modalias = "spidev",
                    .platform_data = NULL,
                    .controller_data = NULL,
                    .mode = SPI_MODE_0,
                    //.irq = 0,
                    .max_speed_hz = 10* 1000 * 1000 /* max sample rate at 3V */ ,
                    .bus_num = 2,
                    //.chip_select = 0,
            },
    };

    Also the below function is there in the init function

    dm365_init_spi2(BIT(0), dm3xx_spi2_board_info,
                            ARRAY_SIZE(dm3xx_spi2_board_info));

    Still it hangs at the same function

    2. Regarding MUX configuration

    Previously mux configurations were:

    MUX_CFG(DM365,        SPI2_SDI,       4,   6,     3,    1,     false)
    MUX_CFG(DM365,        SPI2_SDO,       4,   8,     3,    1,     false)

    And now it is

    MUX_CFG(DM365,  SPI2_SDI,       4,   8,     3,    1,     false)
    MUX_CFG(DM365,  SPI2_SDO,       4,   6,     3,    1,     false)

    Please see the following table (http://www.ti.com/lit/ug/sprufg5a/sprufg5a.pdf  table83 )

     

    the bit num is 8 for SPI2_SOMI (SDI) and not 6

    similarly, the bit num is 6 for for SPI2_SIMO (SDO) and not 8

    So i modified the MUX configurations. This is fine right?

    3.

    Are you using any CS (chip select) signal for SPI device?


    I didnt get this completely. We are using SPI2_SCS[0].

    Also SPI2 can communicate with either FRAM or ADC or DTS depending upon the 2 GPIO pins (GPIO 23 and GPIO 24)

    00/01-> ADC
     10-> FRAM
     11-> DTS

    Since in loopback test,  spi will not communicate with none of the slave devices, i need not worry about the above GPIO setting rite?

    4.  /sys/bus/spi. I got the following

    root@10:/sys/bus/spi# ls
    devices            drivers_autoprobe  uevent
    drivers            drivers_probe

    root@10:/sys/bus/spi# ls devices/
    spi2.0

    root@10:/sys/bus/spi# ls  drivers
    spidev

    Are these okay?

    Thanks and Regards,

    Arpitha

  • Hi,

    For SPI loopback, Manual Shorting the SDI & SDO is required.

    http://communistcode.co.uk/blog/blogPost.php?blogPostID=1

    static struct davinci_spi_platform_data dm365_spi2_pdata = {
            .version = SPI_VERSION_1,
            .num_chipselect = 1,
            .chip_sel = chsel,
            .clk_name = "SPICLK",
    };

    Arpitha said:

    I didnt get this completely. We are using SPI2_SCS[0].


    1) Try to change the CS signal to '0' ( .num_chipselect)

        CLK("spi_davinci.2", NULL, &spi2_clk),

    static struct clk spi2_clk = {
        .name        = "spi2",
        .parent        = &pll1_sysclk4,
        .lpsc        = DM365_LPSC_SPI2,
    };

    2) Try to change the SPI clock name to " spi2 " or spi_davinci.2

    static struct platform_device dm365_spi2_device = {
            .name = "spi_davinci",
            .id = 2,
            .dev = {
                    .dma_mask = &dm365_spi2_dma_mask,
                    .coherent_dma_mask = DMA_BIT_MASK(32),
                    .platform_data = &dm365_spi2_pdata,
            },
            .num_resources = ARRAY_SIZE(dm365_spi2_resources),
            .resource = dm365_spi2_resources,
    };

    3) Have you tried to enable SPI DMA, your configuration seems to be the DMA disabled partially.

    Why do you have disabled the SPI DMA?

    the bit num is 8 for SPI2_SOMI (SDI) and not 6

    similarly, the bit num is 6 for for SPI2_SIMO (SDO) and not 8

    So i modified the MUX configurations. This is fine right?

    Perfect.

    Can you please attach your dm365.c , board file (board-dm365-evm.c,) and bootup logs,

    Are you using any other SPI devices on the board?

    spi0?

    If it so, then Try to disable spi0 completely and use the spi0's DMA resources to SPI2 for testing purpose.

  • HI Titus,

    Thanks for the reply.

    I shall change CS signal and the spi clock name and check.

    Can you please tell me how to enable spi dma? Sorry for asking such simple questions. I dont know how to do it.

    I am not using any other spi devices. spi0 was enabled. I have disabled it by commenting the below line

    //dm365_init_spi0(BIT(0), dm3xx_spi_board_info,
                            ARRAY_SIZE(dm3xx_spi_board_info));

    Will this commenting disable spi0 completely? Anything else has to be done? why because after commenting, i can still see /dev/spi0, however opening /dev/spi0 is not possible.

    Find the attched dm365.c, board-dm368-ipnc.c and bootLog.log

    7144.dm365.c

    1884.board-dm368-ipnc.c

    0804.bootLog.log

    Thanks and Regards,

    Arpitha

  • Hi,

    I forgot to ask you that,

    Do you have enabled linux driver support for FRAM?

    PFA of modified the dm365.c & board file.

    8507.7144.dm365.c

    6560.1884.board-dm368-ipnc.c

    Sorry I don't have a board to test,

    Let me know the status.

  • Hi Titus,

    Thanks for the files!!

    I used the modified files shared by you, unfortunately there is no progress. It still hangs at the ioctl call. I tried with both EVENTQ_2 and EVENTQ_3.. No use

    And spi_clk is also not coming.

    I really dont know how to move further.

    And i have not yet enabled the driver support or FRAM..

    Thanks,

    Arpitha

  • Hi,

    I presume that you have SPI2 device which is connected to FRAM,

    I'm suspecting that not possible to test SPIDEV loopback because of hardware routing to FRAM,

    Already, I have tested SPIDEV loopback mode in my EVM which is sit on expander port (it wont connect to any SPI device) since loopback is required h/w routing(SDO <-> SDI), Thats why it hangs at ioctl but I'm not sure.

    How about the SPI h/w design?

    What about SPI FRAM schematic ? ie what is your ref design for that or own?

    The recommended way is that need to enable FRAM support in linux and pass the pdata to the driver,

  • Hi Titus,

    How about internal loopback test mentioned in this document (http://www.ti.com/lit/ug/sprufh1b/sprufh1b.pdf ) in section 2.10?

    Please see spi interface attachment

    Depending on the device select pins, spi communicates with FRAM/ADC/DTS

    Also can you give some inputs for enabling the FRAM support in linux?

    Regards,

    Arpitha

  • Hi,

    How about internal loopback test mentioned in this document (http://www.ti.com/lit/ug/sprufh1b/sprufh1b.pdf ) in section 2.10?

    This is internal loop back test and not h/w loop back,

    You have to configure the SPI as a master then enable loop back mode through "LOOPBACK" bit of SPIGCR1 reg.

    To achieve this, You may have to write a driver. (Refer : drivers/spi/spi-davinci.c)

    The below link one is for external h/w loopback.

    http://communistcode.co.uk/blog/blogPost.php?blogPostID=1

    drivers/spi/spidev.c

    This is the h/w loopback test with all platform changes but the above internal loopback wont look into the platform

    code changes.

    Do you have any TI's DM3xx EVM with you?

    Also can you give some inputs for enabling the FRAM support in linux?

    I have searched in internet and not finding any linux driver support,

    Try to enable in u-boot & try to access the memory to confirm that h/w works perfect.

    Just contact your FRAM supplier to know the avail linux support,

  • HI

       I also encounter the same question,i use the DM365 with dvsdk4.02,when i set the spi1 with spidev,and

    can find the spidev1.0,but  when i do ./spidev_test -D /dev/spidev1.0 -l  It prints the following statements too

    spi mode: 32
    bits per word: 8
    max speed: 500000 Hz (500 KHz)

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

    Thanks and Regards

      WW

  • HI  

      Have you solved the problem about hanging up?This problem troubles me for several days。i think we may encounter the same question。

     Regards,

     WW

  • Hi Titus,

    Sorry for the delay in response.

    Yes, we do have an EVM board.. Its appro OV9715 DM365 IPNC

    Now i shall enable spi in uboot and check.

    Thank you

    Regards,

    Arpitha

  • Hi WEI WANG,

    I am not able solve this issue yet

    Right now i am trying to enable spi from uboot and check

    Let me know if you are able to solve this issue
    .

    Regards,

    Arpitha

  • Hi Arpitha,

    I have found your problem on setting up the pinmux for SPI2 in dm365.c file,

    Actually, The SPI2 is pinmuxed with GPIO, RGB interface(VENC),,

    But, You have pinmuxed the both GPIO and SPI2 interfaces.

    MUX_CFG(DM365,  SPI2_SCLK,      4,   10,    3,    1,     false)
    MUX_CFG(DM365,  SPI2_SDI,       4,   8,     3,    1,     false)
    MUX_CFG(DM365,  SPI2_SDO,       4,   6,     3,    1,     false)
    MUX_CFG(DM365,  SPI2_SDENA0,    4,   12,    3,    1,     false)
    MUX_CFG(DM365,  SPI2_SDENA1,    4,   8,     3,    2,     false)

    .......

    MUX_CFG(DM365,    GPIO30,        4,   6,     3,      0,     false)
    MUX_CFG(DM365,    GPIO31,        4,   8,     3,      0,     false)
    MUX_CFG(DM365,    GPIO32,        4,   10,    3,      0,     false)
    MUX_CFG(DM365,    GPIO33,        4,   12,    3,      0,     false)

    PFA of modified the dm365.c file and let us know the results.

    7870.7144.dm365.c

    So, You can try again the SPI loopback (not internal) test with previous configurations (try with my prev files also)

    In Parallel, Try the FRAM on u-boot too.

    Hi Wei Wang,

    Please check yours pinmux settings too.

  • Hi Arpitha,

    I hope that the above GPIO pinmux defns may not be initialized and It is just defined in dm365.c but we have to uncomment it out the GPIO definitions to avoid confusions and please ensure that you have not initialized the GPIO anywhere.

    Also, Please ensure that you have not used RGB video interface  (R0, G1)on your board which is pinmuxed with SPI2.

    I have tried to enable the SPI on my board for SPI loopback testing.

    Initially, I met a problem like below,

    root@omapl138-lcdk:/# ./a.out
    spi mode: 0
    bits per word:spi_davinci spi_davinci.0: SPI data transfer error
     8
    max speed: 500000 Hz (500 KHz)
    can't send spi message: Input/output error
    Aborted
    root@omapl138-lcdk:/#

    After I corrected pinmux settings, then the logs like below.

    root@omapl138-lcdk:/# ./a.out
    spi mode: 0
    bits per word: 8
    max speed: 500000 Hz (500 KHz)

    FF FF FF FF FF FF
    FF FF FF FF FF FF
    FF FF FF FF FF FF
    FF FF FF FF FF FF
    FF FF FF FF FF FF
    FF FF FF FF FF FF
    FF FF
    root@omapl138-lcdk:/#

    After you short the SDO & SDI pins then you will get the hard-coded data (instead 0xFF) which is written in "spidev_test.c"

  • Hi Titus,

    I used the latest modified dm365.c file shared by you.

    Hanging continues. No luck

    And also i was not getting any error like you mentioned "can't send spi message: Input/output error Aborted

     

    Thanks and Regards,

    Arpitha

  • Hi,

    I have edited the my last reply,

    Please have a look at it and confirm that you are device is not conflicting with GPIO & VENC - RGB interface(R0,G1)

  • HI Arpitha

     i'm WangWei, i am not solve the problem too(i use the SPI1). Can you tell me how to enable spi from uboot and check. i think my pinmux is ok.

    Regards,

    ww

     

  • Titus,

    I checked in dm365.c file for RGB video interface  (R0, G1), The R0,G1 pins are not multiplexed. Do i need to check in any other files?

    Also with the latest files shared by you, I was getting the below error

    arch/arm/mach-davinci/board-dm368-ipnc.c:814: error: void value not ignored as it ought to be

    So, i had to comment out the following

    *ret = */dm365_init_spi2(BIT(0), dm365_spi2_info,
                            ARRAY_SIZE(dm365_spi2_info));
            /*if (ret)
                    pr_warning("########### dm365_evm_init: spi 2 registration failed: %d\n",
                                    ret);
            else
                    pr_warning("########### dm365_evm_init: spi 2 registration success: %d\n",
                                    ret);*/

     

    But with the latest uImage, kernel is not booting. Please see the attached log 3058.bootlog.txt

     

    Hi WangWei,

    For enabling the spi in uboot, check whether CONFIG_DAVINCI_SPI and  CONFIG_CMD_SPI  are defined in your board configuration file i.e, “u-boot/include/configs/*.h” . If not defined, define it and also check whether cmd_spi.c file is present in “uboot/common/ “

    Once u have this file and CONFIG_DAVINCI_SPI,  CONFIG_CMD_SPI defined, generate a new uboot and use it.. you will get sspi command in uboot

    Regards,

    Arpitha

  • Hi WangWei,

    What is your spi slave device? If ts is a flash device then u have to enable sf command in uboot and not sspi.

    For enabling sf command, you need to define CONFIG_SPI_FLASH and CONFIG_CMD_SF in your board configuration file and check for cmd_sf.c in uboot/common/ folder


    Regards,

    Arpitha

  • hi Arpitha,

         Now, i want to use the spi1 communicating with dm6437,after i want to use it with tochscreen, Firstly, i want to make it useful. i use the loopback test to test if the spi1 and the driver is ok. but until now ,the test is still hanging up .i have no idea about  how to solve it.

    Regards,

    ww

  • WangWei,

    In my project,  i am using spi2 for communicating with FRAM. I am not sure how to go about with the touch screen.

    sorry for late reply.

    I will let you if i make any progress.

    Regards,

    Arpitha