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.

what is the difference between "spi_master" and "spidev" on AM335x EVM?

I've got TI's AM335x EVM which has "spi_master" setup by default, like this...

root@am335x-evm:/sys# find /sys/ -name '*spi*'
/sys/devices/platform/omap/omap2_mcspi.1
/sys/devices/platform/omap/omap2_mcspi.1/spi_master
/sys/devices/platform/omap/omap2_mcspi.1/spi_master/spi1
/sys/devices/platform/omap/omap2_mcspi.2
/sys/devices/platform/omap/omap2_mcspi.2/spi_master
/sys/devices/platform/omap/omap2_mcspi.2/spi_master/spi2
/sys/bus/platform/devices/omap2_mcspi.1
/sys/bus/platform/devices/omap2_mcspi.2
/sys/bus/platform/drivers/omap2_mcspi
/sys/bus/platform/drivers/omap2_mcspi/omap2_mcspi.1
/sys/bus/platform/drivers/omap2_mcspi/omap2_mcspi.2
/sys/bus/spi
/sys/class/spi_master
/sys/class/spi_master/spi1
/sys/class/spi_master/spi2

I have an application that expects to access a custom device via spi found at /dev/spidev.

Can (or, how can) this spi_master be made to appear at /dev/spidev and be used as a character device for a non-flash memory application?

I do believe that I've got the pin-mux configured correctly (via uBoot, I'm not sure how to confirm) and have rebuilt the kernel and spidev.ko module.  I've gotten spidev to show up in /sys/class (previously, when building into kernel, not as a module) but I'm missing how to get any of these to show up in /dev.

The TI SDK document "sitara-linuxsdk-sdg-05.04.01.00.pdf" has proven very useful for getting different builds of the kernel and modules built.  I'm lost on the right combination of udev rules, mknod, spi_board_info, etc details to make this all come together.  Any thoughts would be most welcome.  Thanks

Shannon

  • Shannon,

    My understanding is that you want to change your board file in the kernel to add a spidev device.  Then you will get a spidev device node.  There have been some beaglebone based patches for this at https://groups.google.com/forum/#!topic/beagleboard/B3akyoyjwG4 and http://arago-project.org/git/?p=meta-ti.git;a=blob;f=recipes-kernel/linux/linux-ti33x-psp-3.2/beaglebone/0040-beaglebone-export-SPI2-as-spidev-when-no-capes-are-u.patch;h=4a004d7a407779334e8bef4fe7b73e583eb394bc;hb=d33058225df1156174db1131d964de1ef0ab3b48 which may help guide you.

    Chase

  • Hi Shannon,

    Does your problem solved? How? I meet the same trouble with you ?

    Please help,thanks!

  • zerong,

    I've been wrestling with this for a bit, but finally got it.  Ultimately, I used this advice: http://communistcode.co.uk/blog/blogPost.php?blogPostID=1 for guidance, though it is for the BeagleBone and NOT the TI's AM335x General Purpose EVM .   

    All edits to enable spidev  for TI's AM335x General Purpose EVM occur in this file:

    ti-sdk-am335x-evm-05.04.01.00/board-support/linux-3.2-psp04.06.00.07.sdk/arch/arm/mach-omap2/board-am335xevm.c

    edit this struct, be sure to get the "gen_purp_evm_dev_cfg[]" not the "low_cost_evm_dev_cfg[]"

    in code ------------------------------------------------------------------------------------
    static struct evm_dev_cfg gen_purp_evm_dev_cfg[] = {
    .....

    //take this out
    //    {spi0_init,    DEV_ON_DGHTR_BRD, PROFILE_2},

    .....

    //put this in
        {spi0_init, DEV_ON_BASEBOARD, PROFILE_0},
    ...

    };

    ---------------------------------------------------------------------------------------------

    in code -----------------------------------------------------------------

    static struct spi_board_info am335x_spi0_slave_info[] = { 
      {
        .modalias = "spidev",
        .max_speed_hz = 1000000,  // probably slower than you want, it is what we needed
        .irq = -1,
        .bus_num = 1, 
        .chip_select = 0,
        .mode = SPI_MODE_1  //appropriate for us, yours may be different
        },
    };

    ------------------------------------------------------------------------------

    in code  -----------------------------------------------------------

    static void spi0_init(int evm_id, int profile)
    {
        setup_pin_mux(spi0_pin_mux);         // this overrides anything in uboot mux.h that you might've used from TI's nifty PinMux utility
        spi_register_board_info(am335x_spi0_slave_info,
                ARRAY_SIZE(am335x_spi0_slave_info));
        return;
    }

    ------------------------------------------------------------------------------

    in code ------------------------------------------------------------------------------------------------
    static struct pinmux_config spi0_pin_mux[] = {
        {"spi0_sclk.spi0_sclk", OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT | AM33XX_PULL_UP | AM33XX_PULL_ENBL},
        {"spi0_d0.spi0_d0", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL | AM33XX_PULL_UP | AM33XX_INPUT_EN},
        {"spi0_d1.spi0_d1", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL | AM33XX_INPUT_EN},
        {"spi0_cs0.spi0_cs0", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL | AM33XX_PULL_UP | AM33XX_INPUT_EN},
        {NULL, 0},
    };

    -------------------------------------------------------------------------------------------------------

    I can't say that each setting is optimal, but this worked for me.

    good luck!

  • Chase,

    Thanks for your contribution.  I overlooked your response until now.  But, I got it working, as noted later in this thread.

    Shannon

  • Additionally, to clarify the original question of my thread...

    "am335x_spi0_slave_info[]" is just a name, having no real master/slave characteristics.

    I wasn't seeing the spi clock signal (as a master would provide) until I changed the pinmux for the signal to

    "{"spi0_sclk.spi0_sclk", OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT | AM33XX_PULL_UP | AM33XX_PULL_ENBL},"


    I'd welcome better info that others may be able to contribute.

  • Hi shannon,

    According to your guidance, I change  the corresponding  position  of kernel:

    root@am335x-evm:/sys# find /sys/ -name '*spi*'
    ./sys/devices/platform/omap/omap2_mcspi.1
    ./sys/devices/platform/omap/omap2_mcspi.1/spi_master
    ./sys/devices/platform/omap/omap2_mcspi.1/spi_master/spi1
    ./sys/devices/platform/omap/omap2_mcspi.1/spi1.0
    ./sys/devices/platform/omap/omap2_mcspi.2
    ./sys/devices/platform/omap/omap2_mcspi.2/spi_master
    ./sys/devices/platform/omap/omap2_mcspi.2/spi_master/spi2
    ./sys/bus/platform/devices/omap2_mcspi.1
    ./sys/bus/platform/devices/omap2_mcspi.2
    ./sys/bus/platform/drivers/omap2_mcspi
    ./sys/bus/platform/drivers/omap2_mcspi/omap2_mcspi.1
    ./sys/bus/platform/drivers/omap2_mcspi/omap2_mcspi.2
    ./sys/bus/spi
    ./sys/bus/spi/devices/spi1.0
    ./sys/class/spi_master
    ./sys/class/spi_master/spi1
    ./sys/class/spi_master/spi2

    but during test procedure, appear the following questions:

    root@am335x-evm:/opt# ./spidev_test -D /sys/bus/spi/devices/spi1.0
    can't open device: Is a directory
    Aborted
    root@am335x-evm:/opt# ./spidev_test -D /sys/devices/platform/omap/omap2_mcspi.1/spi1.0
    can't open device: Is a directory
    Aborted

    Do you  meet this problem?

    The compilation of the SPI driver is according to http://processors.wiki.ti.com/index.php/AM335x_McSPI_Driver%27s_Guide:

    Building into Kernel

      Device Drivers  ---> 
             [*] SPI support  ---> 
                <*>   McSPI driver for OMAP
    
    • Enable W25Q64 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)

    Is this process right?

    thank you,Looking forward to your help!


  • I don't recall if I hit that specific problem, but I did discover that I didn't understand the situation clearly enough to get creative with the naming of anything.  I kept every "spidev" part as "spidev".  I see that yours is coming out as just ..."spi"1.0. 

    Also, spidev_test is to be run against /dev/spidev#.#, where is appears as a read/write file.  Don't run the test to the nodes under /sys/...  Until you see the node under /dev/... the implementation isn't complete.

    Additionally, I disabled the SPI flash memory support.  I don't know how that impacts what you're trying to do.

    I'm not real clear on the whole situation myself.  I only indicated what I did to make /dev/spidev work for my situation.  I'd hope a more knowledgeable person would contribute.

  • Hi shannon,

     I also want to find spidev in the /dev directory, I had a lot of trying to  achieve it, but have no success.

    I don't know the problem is the driver code, or drive compiled process, it makes me very confused.

    Anyway, thank you all the same!

  • Hi all !!

    I have recognized the same problems ( same board and same sdk version ) .

    in the file board-am335xevm.c  inside /home/sitara/board-support/linux-3.2-psp04.06.00.07.sdk/arch/arm/mach-omap2  , the settings for the spi seem to be similar to yours,

    specially in

    static struct spi_board_info am335x_spi0_slave_info[] = {
        {
            .modalias      = "m25p80",
            .platform_data = &am335x_spi_flash,
            .irq           = -1,
            .max_speed_hz  = 24000000,
            .bus_num       = 1,
            .chip_select   = 0,
        },
    };

    static struct spi_board_info am335x_spi1_slave_info[] = {
        {
            .modalias      = "m25p80",
            .platform_data = &am335x_spi_flash,
            .irq           = -1,
            .max_speed_hz  = 12000000,
            .bus_num       = 2,
            .chip_select   = 0,
        },
    };

    with the exeption of modalias and platform data. the name "m25p80" instead of "spidev" couldn't be a big problem. About . platform_data?! I still need to compile kernel?

    Thanks in advance and sorry form my bad english! :P

    Marco

  • Marco,

    As I noted earlier, keeping the name "spidev" is important.  Now I understand better, that the Linux driver that exports this to for filesystem access - /dev/spidev - needs this .modalias to be "spidev".

    I think.  In any case, it didn't work for me until I changed the .modalias back to "spidev"

    good luck.

    Shannon

  • Thanks a lot Shannon! :)

    Forgive me for my trivial question , I'm a total beginner on this world ;)

    Now, i'm looking for the painful job: re-compile (cross compile) arago linux kernel! I hope to come back alive :D

    Best regards

    Marco