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.

SPI1 device configuration in OMAPl138

Other Parts Discussed in Thread: OMAPL138, DA8XX

Hi 

I'm using custom board of OMAPl138 LCDK. i need to connect the SPI device with my board. I've expansion header for spi1 interface pins are 

SPI1_CLK, SPI1_SIMO, SPI1_SOMI and SPI1_SCSn_0. 

I enabled the following option in config files 

CONFIG_SPI=y

CONFIG_SPI_BITBANG=y
CONFIG_SPI_DAVINCI=y

CONFIG_SPI_SPIDEV=y 

and modification in board file  board-omapl138-hawk.c

ret = da8xx_register_spi(1, da830evm_spi_info,ARRAY_SIZE(da830evm_spi_info));

static struct spi_board_info da830evm_spi_info[] = {
{
.modalias = "my_spi",
.platform_data = &my_spi_pd,
.max_speed_hz = 12000000,
.bus_num = 2,
.chip_select = 0,
.mode = SPI_MODE_0,
},
};


static struct fpc1080_platform_data my_spi_pd = {
.irq_gpio = GPIO_TO_PIN(2, 6),
.reset_gpio = GPIO_TO_PIN(2, 4),
};

and i didn't made any changes for pin mux for SPI and configured for GPIO pins as below

ret = davinci_cfg_reg_list(da850_spi1_gpio_pins); 

static short da850_spi1_gpio_pins[] __initdata= {
DA850_GPIO2_4,
DA850_GPIO2_6,
-1
};

But i can't communicate with my SPI device what are steps i missed here? do i need to configure pin mux for SPI1 and let me know how to view the configured gpio and spi pins from file system kind of debug file system 

sys/kernel/debug or is there any other way to find the configured pins ?

Thanks 

Sangly kumar

  • Hi,

    I)

    If you want to do pinmux for any peripheral then,

    Three places need to affect,

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

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

    3) File: arch/arm/mach-davinci/board-omapl138-hawk.c

    II)

    You can take reference code from "board-da850-evm.c" or board-da850-sdi.c which they have already implemented.

    But i can't communicate with my SPI device what are steps i missed here? do i need to configure pin mux for SPI1 and let me know how to view the configured gpio and spi pins from file system kind of debug file system

    What is your SPI device?

    Did you probe your SPI clock signal on CRO?

    sys/kernel/debug or is there any other way to find the configured pins ?

    If you configured SPI properly then sysfs ll get created for testing the SPI.

    /sys/bus/spi/

    If sysfs is not get mounted then,

    mount -t sysfs sysfs /sys

  • Hi Mr.stalin 

         Actually i need the following pins for my SPI device,

    SPI PINs:-

    1. SPI1_CLK,

    2. SPI1_SOMI,

    3. SPI1_SIMO,

    4. SPI1_SCSn_0

    We don't have SPI1_ENAn at your expansion header. i have just 4 SPI pins mentioned above. 

    GPIO_PINs:-

    1. GPIO2_0,

    2. GPIO3_15,

    As  per your previous reply i modified the following files,

    /arch/arm/mach-davinci/da850.c

    /* I2C0 function */
    MUX_CFG(DA850, I2C0_SDA, 4, 12, 15, 2, false)
    MUX_CFG(DA850, I2C0_SCL, 4, 8, 15, 2, false)

    /* SPI1 function */
    + MUX_CFG(DA850, SPI1_CLK, 5, 8, 15, 1, true)
    + MUX_CFG(DA850, SPI1_SOMI, 5, 16, 15, 1, true)
    + MUX_CFG(DA850, SPI1_SIMO, 5, 20, 15, 1, true)
    + MUX_CFG(DA850, SPI1_SCS0, 5, 4, 15, 1, true)

    /* EMAC function */
    MUX_CFG(DA850, MII_TXEN, 2, 4, 15, 8, false)
    MUX_CFG(DA850, MII_TXCLK, 2, 8, 15, 8, false)

    /* GPIO function */
    + MUX_CFG(DA850, GPIO2_0, 6, 28, 15, 8, true)
    + MUX_CFG(DA850, GPIO3_15, 7, 0, 15, 8, true)

    /arch/arm/mach-davinci/include/mach/mux.h

    /* I2C0 function */
    DA850_I2C0_SDA,
    DA850_I2C0_SCL,

    /* SPI1 function */
    + DA850_SPI1_CLK,
    + DA850_SPI1_SOMI,
    + DA850_SPI1_SIMO,
    + DA850_SPI1_SCS0,

    /* EMAC function */
    DA850_MII_TXEN,
    DA850_MII_TXCLK,

    + DA850_GPIO2_0,
    + DA850_GPIO3_15,

    /arch/arm/mach-davinci/board-omapl138-hawk.c

    ret = davinci_cfg_reg_list(da850_spi1_gpio_pins); 

    static short da850_spi1_gpio_pins[] __initdata= {
    DA850_GPIO2_0,DA850_GPIO3_15,
    -1
    };

    ret = davinci_cfg_reg_list(da8xx_evm_spi_pins); 

    static short da8xx_evm_spi_pins[] __initdata = {
    DA850_SPI1_CLK,DA850_SPI1_SOMI,DA850_SPI1_SIMO,DA850_SPI1_SCS0,
    -1
    };

    ret = da8xx_register_spi(1, da830evm_spi_info,ARRAY_SIZE(da830evm_spi_info));
    if (ret)
    {
    pr_warning("da830_evm_init: spi 1 registration failed: %d\n",ret);
    return ret;
    }

    static struct spi_platform_data spi1_pd = {
    .irq_gpio      = GPIO_TO_PIN(2, 0),
    .reset_gpio  = GPIO_TO_PIN(3, 15),
    };

    static struct spi_board_info da830evm_spi_info[] = {
    {
    .modalias = "my_spi1",
    .platform_data = &spi1_pd,
    .mode = SPI_MODE_0,
    .max_speed_hz = 12000000,
    .bus_num = 1,
    .chip_select = 0,
    },
    };

    These are the changes i have done but still my spi driver and device not communicating with processor. But same device and driver working fine with AM335x processor.   

    Kindly let me know at where i missed and what i missed?

    I read the TRM and SPI1_ENAn is optional, so we left as NC in our board is this cause of SPI1 failure?
    Please check the da830evm_spi_info[] is this correct or i need to change the .bus_num or .chip_select to make it work properly ?

    My connection detail is

    SPI1_CS       --> CS

    SPI1_CLK     --> CLK

    SPI1_SOMI   --> MISO

    SPI1_SIMO   -->  MOSI

    I can see the spi under /sys/bus/spi

    root@omapl138-lcdk:/sys/bus/spi# ls -l
    drwxrwxrwx 2 root root 0 Apr 11 04:23 devices
    drwxrwxrwx 4 root root 0 Apr 11 04:23 drivers
    -rwxrwxrwx 1 root root 4096 Apr 11 04:23 drivers_autoprobe
    -rwxrwxrwx 1 root root 4096 Apr 11 04:23 drivers_probe
    -rwxrwxrwx 1 root root 4096 Apr 11 04:23 uevent

    root@omapl138-lcdk:/sys/bus/spi# ls -l
    drwxrwxrwx 2 root root 0 Apr 11 04:23 devices
    drwxrwxrwx 4 root root 0 Apr 11 04:23 drivers
    -rwxrwxrwx 1 root root 4096 Apr 11 04:23 drivers_autoprobe
    -rwxrwxrwx 1 root root 4096 Apr 11 04:23 drivers_probe
    -rwxrwxrwx 1 root root 4096 Apr 11 04:23 uevent

    root@omapl138-lcdk:/sys/bus/spi# ls -l drivers
    drwxr-xr-x 2 root root 0 Apr 11 04:22 my_spi1
    drwxr-xr-x 2 root root 0 Apr 11 04:22 spidev

    Thanks 

    Sangly

  • Hi,

    Titus said:

    What is your SPI device?

    What is your SPI1 device connected to the board?

    You have mentioned SPI device as "my_spi1"

  • Hi

    My connected SPI device is SPI 4 wire fingerprint sensor. 

    For your kind information sensor is working fine with AM335x (with same .max_speed_hz = 12000000) and micro controller. 

  • Hi,

    Thanks for your answer.

    My connected SPI device is SPI 4 wire fingerprint sensor.

    Do you have SPI driver for this FPS in linux?

    For your kind information sensor is working fine with AM335x (with same .max_speed_hz = 12000000) and micro controller.

    Okay, then,

    Can you please give me the AM335x platform data details used in AM335x board?

    I think that you may aware; The SPI1's platform data will pass the info of SPI1 devices to SPI1's driver

    the below SPI1 devices is SPI flash

    Sample SPI platform data init at board file

    static struct flash_platform_data spi_flash_data = {
        .name = "m25p80",
        .parts = spi_flash_partitions,
        .nr_parts = ARRAY_SIZE(spi_flash_partitions),
        .type = "m25p64",
    };

    static struct davinci_spi_config da850evm_spiflash_cfg = {
        .io_type    = SPI_IO_TYPE_DMA,
        .c2tdelay    = 8,
        .t2cdelay    = 8,
    };

    static struct spi_board_info da850evm_spi_info[] = {
        {
            .modalias        = "m25p80",
            .platform_data        = &spi_flash_data,
            .controller_data    = &da850evm_spiflash_cfg,
            .mode            = SPI_MODE_0,
            .max_speed_hz        = 30000000,
            .bus_num        = 1,
            .chip_select        = 0,
        },
    };

        ret = da8xx_register_spi(1, da850evm_spi_info,
                     ARRAY_SIZE(da850evm_spi_info));
        if (ret)
            pr_warning("da850_evm_init: spi 1 registration failed: %d\n",
                    ret);


    SPI1 driver located at "drivers/mtd/devices/m25p80.c"

    /*
     * board specific setup should have ensured the SPI clock used here
     * matches what the READ command supports, at least until this driver
     * understands FAST_READ (for clocks over 25 MHz).
     */
    static int __devinit m25p_probe(struct spi_device *spi)
    {
        const struct spi_device_id    *id = spi_get_device_id(spi);
        struct flash_platform_data    *data;
        struct m25p            *flash;
        struct flash_info        *info;
        unsigned            i;
        struct mtd_part_parser_data    ppdata;

    #ifdef CONFIG_MTD_OF_PARTS
        if (!of_device_is_available(spi->dev.of_node))
            return -ENODEV;
    #endif

        /* Platform data helps sort out which chip type we have, as
         * well as how this board partitions it.  If we don't have
         * a chip ID, try the JEDEC id commands; they'll work for most
         * newer chips, even if we don't recognize the particular chip.
         */
        data = spi->dev.platform_data;
        if (data && data->type) {
            const struct spi_device_id *plat_id;

            for (i = 0; i < ARRAY_SIZE(m25p_ids) - 1; i++) {
                plat_id = &m25p_ids[i];
                if (strcmp(data->type, plat_id->name))
                    continue;
                break;

    ..............

    ...............

    static struct spi_driver m25p80_driver = {
        .driver = {
            .name    = "m25p80",
            .owner    = THIS_MODULE,
        },
        .id_table    = m25p_ids,
        .probe    = m25p_probe,
        .remove    = __devexit_p(m25p_remove),

        /* REVISIT: many of these chips have deep power-down modes, which
         * should clearly be entered on suspend() to minimize power use.
         * And also when they're otherwise idle...
         */
    };

     

    In same way, You have SPI driver (If you have SPI driver for FPS,) for FPS and need to pass platform data's to the SPI1 driver of FPS from board file.

    static struct spi_board_info da830evm_spi_info[] = {
    {
    .modalias = "my_spi",
    .platform_data = &my_spi_pd,
    .max_speed_hz = 12000000,
    .bus_num = 2,
    .chip_select = 0,
    .mode = SPI_MODE_0,
    },
    };

  • HI

    My SPI device platform data is just two number of GPIO for reset and irq.

    Titusrathinaraj Stalin said:
    Can you please give me the AM335x platform data details used in AM335x board?

    static struct fpc1080_platform_data fpc1080_pd = {
    .irq_gpio = GPIO_TO_PIN(1, 2),
    .reset_gpio = GPIO_TO_PIN(1, 3),
    };

    static struct spi_board_info am335x_spi1_slave_info[] = {
    {
    .modalias = "fpc1080",
    .platform_data = &fpc1080_pd,
    .max_speed_hz = 12000000,
    .bus_num = 2,
    .chip_select = 0,
    .mode = SPI_MODE_0,
    },
    };

    Yes i've linux driver for my FPS device. 

    I'm passing the number of two GPIO as platform data

    static struct fpc1080_platform_data fpc1080_pd = {
    .irq_gpio = GPIO_TO_PIN(3, 15),
    .reset_gpio = GPIO_TO_PIN(2, 0),
    };

    static struct spi_board_info da830evm_spi_info[] = {
    {
    .modalias = "fpc1080",
    .platform_data = &fpc1080_pd,
    .mode = SPI_MODE_0,
    .max_speed_hz = 12000000,
    .bus_num = 1,
    .chip_select = 0,
    },
    };

    And i 've checked the SPI1 loop back by spi-dev module 

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

    Its working fine with my OMAPl138 custom board. I'm getting expected OP from the SPI hence SIMO, SOMI working fine. 

    Is the problem with CS? 

    And sensor also working fine with AM335x device. So the summery is 

    FPS working fine with AM335x

    SPI1 working fine with loop back test without CS as mentioned in above link

    If we connect the OMAP l138 SPI with my FPS not working. so there is change for problem in CS or CLK or some where else.

    Please give me some suggestion.

    Thanks 

    Sangly

  • Hi,

    Can you please try this,

    ret = davinci_cfg_reg_list(da850_spi1_gpio_pins); 

    static short da850_spi1_gpio_pins[] __initdata= {
    DA850_GPIO2_0,DA850_GPIO3_15,
    -1
    };

    ret = davinci_cfg_reg_list(da8xx_evm_spi_pins); 

    static short da8xx_evm_spi_pins[] __initdata = {
    DA850_SPI1_CLK,DA850_SPI1_SOMI,DA850_SPI1_SIMO,DA850_SPI1_SCS0,
    -1
    };

    ret = da8xx_register_spi(1, da850evm_spi_info,ARRAY_SIZE(da850evm_spi_info));
    if (ret)
    {
    pr_warning("da850_evm_init: spi 1 registration failed: %d\n",ret);
    return ret;
    }

    static struct spi_platform_data spi1_pd = {
    .irq_gpio      = GPIO_TO_PIN(2, 0),
    .reset_gpio  = GPIO_TO_PIN(3, 15),
    };

    static struct spi_board_info da850evm_spi_info[] = {
    {
    .modalias = "fpc1080",
    .platform_data = &spi1_pd,
    .mode = SPI_MODE_0,
    .max_speed_hz = 12000000,
    .bus_num = 1,
    .chip_select = 0,
    },
    };

     

    Why did use "my_spi1" instead  "fpc1080" ?

    If you use "my_spi1" then you need to use the same name in FPS linux driver.

  • HI 

      Sorry my modalias name and driver name is same

    board file:-

    static struct spi_board_info da830evm_spi_info[] = {
    {
    .modalias = "fpc1080",
    .platform_data = &fpc1080_pd,
    .mode = SPI_MODE_0,

    driver file:-

    .driver = {
    .name = "fpc1080",
    .bus = &spi_bus_type,
    .owner = THIS_MODULE,

    I can't find out the problem. 

  • Hi,

    Please provide correct details,

    Sangily said:

    static struct spi_board_info da830evm_spi_info[] = {
    {
    .modalias = "my_spi",
    .platform_data = &my_spi_pd,
    .max_speed_hz = 12000000,
    .bus_num = 2,
    .chip_select = 0,
    .mode = SPI_MODE_0,
    },
    };

    root@omapl138-lcdk:/sys/bus/spi# ls -l drivers
    drwxr-xr-x 2 root root 0 Apr 11 04:22 my_spi1
    drwxr-xr-x 2 root root 0 Apr 11 04:22 spidev

    Please answer these questions.

    Did you probe the clock of SPI1?

    Do you have SPI flash on your board?

    Do you have any other SPI slave devices connected to your board?

    I think that you are not using "CS" then remove/comment out ".chip_select = 0,"  or pass "NULL"

    Please Let us know the results.

  • Hi 

        My apologies for confusion. For the purpose privacy i replaced the original driver name with "my_spi1" and correct detail is 

    static struct spi_board_info da850evm_spi_info[] = {
    {
    .modalias = "fpc1080",
    .platform_data = &spi1_pd,
    .mode = SPI_MODE_0,
    .max_speed_hz = 12000000,
    .bus_num = 1,
    .chip_select = 0,
    },
    }; 

    driver file:-

    .driver = {
    .name = "fpc1080",
    .bus = &spi_bus_type,
    .owner = THIS_MODULE,

    Titusrathinaraj Stalin said:
    Do you have SPI flash on your board?

    No i don't have SPI flash on my board

    Titusrathinaraj Stalin said:
    Do you have any other SPI slave devices connected to your board?

    No this is the only one device(FPS) connected with board in SPI interface. 

    Titusrathinaraj Stalin said:
    I think that you are not using "CS" then remove/comment out ".chip_select = 0,"  or pass "NULL"

    I can't get your point clearly. But i'm connecting CS pin with my slave device.

    Could you clear me about "remove/comment out ".chip_select = 0,"

    Titusrathinaraj Stalin said:
    Did you probe the clock of SPI1?


    Yes, But my CRO not working properly but spi-dev loopback test working fine as mentioned in above link so i suspect that no problem in CLK, SIMO, and SOMI pins. 

    Thanks

    Sangly

  • Hi,

    Okay, I understood your privacy issues,

    Sorry for the misinterpretation of CS signal.

    I though that you left the CS signal simply.

    At which CS number did you used for SPI1 device.

    I think its is CS0, Correct me if I'm wrong.

    Did you connected/used CS0 signal to SPI for AM335x also with the same configuration?

    Could you please use clock freq "12000000" to "30000000" for OMAPL138

    I suspect that the AM335x board has 1GHz processor where as OMAPL138 has less (456MHz max).

    static struct spi_board_info da830evm_spi_info[] = {
    {
    .modalias = "fpc1080",
    .platform_data = &fpc1080_pd,
    .mode = SPI_MODE_0,
    .max_speed_hz = 30000000,
    .bus_num = 1,
    .chip_select = 0,
    },
    };

    Please let us know the results.

  • Hi, I did the same changes in mux.h, da850.c and board-omapl138-hawk.c.

    But my spi_boar_info is:
    static struct spi_board_info da830evm_spi_info[] = {
    {
        .modalias = "spidev",
        .mode = SPI_MODE_0,
        .max_speed_hz = 12000000,
        .bus_num = 1,
        .chip_select = 0,
    },
    };

    in /sys/bus/spi/drivers there is only spidev
    in /dev is spidev1.0
    But there is a lot of ttyXX(tty-ttyzf) and ptyXX(ptya0-zf). Why so many of them?

    Also there is problem with usb.
    If I start linux without usb flash ROM, then there is spidev1.0 in /dev, but is no sda1(my flash ROM).
    If I start it with flash ROM than there is no spidev and is sda1.
    But I can't understand how do they communicate.
    Thanks

  • No ideas?
    Can problem be in interrupts?

  • Hi,

    But there is a lot of ttyXX(tty-ttyzf) and ptyXX(ptya0-zf). Why so many of them?

    These are the pseudo terminals and normal terminals which used in linux

    Also there is problem with usb.
    If I start linux without usb flash ROM, then there is spidev1.0 in /dev, but is no sda1(my flash ROM).
    If I start it with flash ROM than there is no spidev and is sda1.

    What is your SDK ver?

    Have you configured your kernel for USB drivers in linux source through menuconfig?

    Are you able to test SPI device and Have you probed anytime on SPI clk to cross check pinmuxing of SPI?

  • SDK ver is 01.00.00

    No, usb is working from the box. There are picked up items in menuconfig in USB support:

    <*> Support for Host-side USB
    [*] USB announce new devices
    [*] USB device filesystem (DEPRECATED)
    [*] USB device class-devices (DEPRECATED)
    <*> OHCI HCD support
    <M>USB Mass Storage support
    [*] USB Mass Storage verbose debug

    I can't test SPI device because I use ramdisk and file with test program is on USB flash drive.

    Have you probed anytime on SPI clk to cross check pinmuxing of SPI

    Don't understand. SPI has no pins that can conflict with USB.

  • Hi Alex,

    Can you please create a new thread for this issue as posting on the same thread will get only less attention when compared to the new one. And as well, this thread seems to be a closed one.

    Thanks for your understanding,

  • Hi

          I tried .max_speed_hz = 30000000but no result still same problem. Do we need to configure anything in 

    "static struct davinci_spi_config" please let me know SPI is very important in my device. 

    Thanks

    Sangly

  • Hi Sangly,

    Please ensure that your USB section is working good after implementing the SPI interface on your board,

    Yes, But my CRO not working properly but spi-dev loopback test working fine as mentioned in above link so i suspect that no problem in CLK, SIMO, and SOMI pins.

     

    I suspect that the problem is due to CS of SPI interface, thats why the SPI loopback interface is worked,

  • Hi

       Sure i'll do, for our prototype demo we need SPI so i'm trying SPI now. 

    Still i can't find out the problem in SPI 

    Thanks

    Sangly

  • Hi,

    Typically, When you are doing SPI loopback test, We need to short the SOMI and SIMO pins and wont consider the CS at all,

    I presume that you are using OMAPL138 LCDK board which is released by TI and you are not testing SPI in your own board.