How to spidev (and issue!)

Discussion of your EDM baseboard, your add-on boards or other peripherals for your wandboard.

How to spidev (and issue!)

Postby raulina » Fri May 06, 2016 10:34 am

Hi all!

I've been using an embedded for a couple of years for a project. I had to recompile the kernel to enable NFS support (first time I ever compiled a kernel) and it was easier than expected. Now I need to use the spi port and I had several problems. I was not able to found anything in the menuconfig to enable them, so after looking a bit in this forum (and in the freescale forum), I read about spidev, which was what I was looking for. After some attempts, I found a way to enable /dev/spidev0.0, but not /dev/spidev0.1, what I also wanted. As I didn't found a step-by-step tutorial about how to do it, I wanted to create a post to help people. I insist that I have almost no idea what I am doing, if something is wrong, tell me and I will change it. I followed this procedure:

1) First, download the basic support files from the wandboard website (http://wandboard.org/index.php/downloads), and unzip the file.

2) Check the file wandboard-sdk-($date)/doc/wand-dev.pdf
It will explain you how to set the cross-compiler.

3) After setting the two environment variables (export CROSS_COMPILE=($your_compiler) and exporT ARCH=arm), load the basic configuration for the wandboard compilation with:

cd wandboard-sdk-($date)/linux-($version)-wand/
make wandboard_defconfig


4) Edit the .config file:
gedit .config


Ensure than the following lines are enabled (I have these enabled, but I am not sure if all them are required):

Code: Select all
CONFIG_IMX_HAVE_PLATFORM_SPI_IMX=y
CONFIG_SPI=y
CONFIG_SPI_DEBUG=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_BITBANG=y
CONFIG_SPI_GPIO=y
CONFIG_SPI_IMX_VER_2_3=y
CONFIG_SPI_IMX=y
CONFIG_SPI_SPIDEV=y
CONFIG_SND_SPI=y
CONFIG_SND_SOC_I2C_AND_SPI=y


In a freescale forum I found that this should be also enable, but I didn't found this line even comented in my .config file:

Code: Select all
CONFIG_REGMAP_SPI=y


5) Edit the board-wand.c file:

gedit arch/arm/mach-mx6/board-wand.cc


6) Add to the header:

Code: Select all
#include <linux/spi/spi.h>


7) Look for the SPI section. It begins by:

Code: Select all
/****************************************************************************
 *                                                                         
 * SPI - while not used on the Wandboard, the pins are routed to baseboard
 *                                                                         
 ****************************************************************************/


Add these lines:

Code: Select all
static struct spi_board_info wbquad_spi_devices[] = {
    {
        .modalias = "spidev",
        .max_speed_hz = 20000000,
        .bus_num = 0,
        .chip_select = 0,
        .mode = SPI_MODE_0,
    },
    {
        .modalias = "spidev",
        .max_speed_hz = 20000000,
        .bus_num = 0,
        .chip_select = 1,
        .mode = SPI_MODE_0,
    }
};


and this line at the end:

Code: Select all
spi_register_board_info(wbquad_spi_devices, ARRAY_SIZE(wbquad_spi_devices));


So finally it looks like:

Code: Select all
/****************************************************************************
 *                                                                         
 * SPI - while not used on the Wandboard, the pins are routed to baseboard
 *                                                                         
 ****************************************************************************/

static const int wand_spi1_chipselect[] = { IMX_GPIO_NR(2, 30) };

/* platform device */
static const struct spi_imx_master wand_spi1_data = {
   .chipselect     = (int *)wand_spi1_chipselect,
   .num_chipselect = ARRAY_SIZE(wand_spi1_chipselect),
};

/* ------------------------------------------------------------------------ */

static const int wand_spi2_chipselect[] = { IMX_GPIO_NR(2, 26), IMX_GPIO_NR(2, 27) };

static const struct spi_imx_master wand_spi2_data = {
   .chipselect     = (int *)wand_spi2_chipselect,
   .num_chipselect = ARRAY_SIZE(wand_spi2_chipselect),
};

static struct spi_board_info wbquad_spi_devices[] = {
    {
        .modalias = "spidev",
        .max_speed_hz = 20000000,
        .bus_num = 0,
        .chip_select = 0,
        .mode = SPI_MODE_0,
    },
    {
        .modalias = "spidev",
        .max_speed_hz = 20000000,
        .bus_num = 0,
        .chip_select = 1,
        .mode = SPI_MODE_0,
    }
};

/* ------------------------------------------------------------------------ */

static void __init wand_init_spi(void) {
   IMX6_SETUP_PAD( EIM_D16__ECSPI1_SCLK );
   IMX6_SETUP_PAD( EIM_D17__ECSPI1_MISO );
   IMX6_SETUP_PAD( EIM_D18__ECSPI1_MOSI );
   IMX6_SETUP_PAD( EIM_EB2__GPIO_2_30 );

   IMX6_SETUP_PAD( EIM_CS0__ECSPI2_SCLK );
   IMX6_SETUP_PAD( EIM_CS1__ECSPI2_MOSI );
   IMX6_SETUP_PAD( EIM_OE__ECSPI2_MISO );
/* The choice of using gpios for chipselect is deliberate,
   there can be issues using the dedicated mux modes for cs.*/
   IMX6_SETUP_PAD( EIM_RW__GPIO_2_26 );
   IMX6_SETUP_PAD( EIM_LBA__GPIO_2_27 );
       
   imx6q_add_ecspi(0, &wand_spi1_data);
   imx6q_add_ecspi(1, &wand_spi2_data);
      
   spi_register_board_info(wbquad_spi_devices, ARRAY_SIZE(wbquad_spi_devices));
}



8) Compile the kernel and burn it to your sd card:

make -j4 uImage module
sudo dd if=arch/arm/boot/uImage of=/dev/($sdcard location) bs=1M seek=1M


========= THE PROBLEM ============

After all this, I can now see the device /dev/spidev0.0, which I can guess that it is enabled due to this piece of the code:

Code: Select all
    {
        .modalias = "spidev",
        .max_speed_hz = 20000000,
        .bus_num = 0,
        .chip_select = 0,
        .mode = SPI_MODE_0,
    },


But I expected than the same code that is just below this, which has the same code but .chip_select = 1, will create the /dev/spidev0.1 file. What did I do wrong? Why spidev0.1 is not showing?

Thank you very much

Edit: I tried to add this to the wiki, but I was not able to register.

UPDATE: It is also possible to enable spidev following this tutorial: http://blog.luisdearquer.es/index.php/2 ... wandboard/
raulina
 
Posts: 15
Joined: Thu May 05, 2016 3:23 pm

Re: How to spidev (and issue!)

Postby blue_z » Tue May 10, 2016 1:51 am

raulina wrote:if something is wrong, tell me and I will change it.
Okay.
raulina wrote:4) Edit the .config file:
Your step #4 is really bad advice.
You should use the kernel's 'make menuconfig' for this step, instead of directly editing the .config file.

raulina wrote:5) Edit the board-wand.c file:

gedit arch/arm/mach-mx6/board-wand.cc
Typos?
What kernel version is this?
Who today uses a board file when current kernels use Device Tree?

Have you read any of the Linux kernel documentation (in the source code) for SPI?

Regards
blue_z
 
Posts: 36
Joined: Sat Jun 13, 2015 12:12 am
Location: USA

Re: How to spidev (and issue!)

Postby Richard » Thu May 19, 2016 2:07 am

Hello:

For the device tree kernel, please add spidev node in imx6qdl-wandboard.dtsi as follows:

Code: Select all
&ecspi1 {
    fsl,spi-num-chipselects = <1>;
   cs-gpios = <&gpio2 30 0>; /* EIM_EB2 */
   pinctrl-names = "default";
   pinctrl-0 = <&pinctrl_ecspi1>;
   status = "okay";

        spidev@0 {
        compatible = "rohm,dh2228fv";
        spi-max-frequency = <10000000>;
        reg = <0>;
        };
};


and enable kernel configuration:
Code: Select all
Symbol: SPI_SPIDEV [=n]
  │ Type  : tristate
  │ Prompt: User mode SPI device driver support
  │   Location:
  │     -> Device Drivers
  │ (1)   -> SPI support (SPI [=y])


BR,

Richard
Richard
Site Admin
 
Posts: 137
Joined: Tue Dec 17, 2013 6:57 am

Re: How to spidev (and issue!)

Postby blue_z » Sun May 22, 2016 10:42 pm

Richard wrote:For the device tree kernel, please add spidev node in imx6qdl-wandboard.dtsi as follows:
That's not the ideal or preferred method of customizing a Device Tree.
You'd be better off consolidating all of your changes to the end of the top-level .dts file for your board.
Keep the SoC manufacturer's and board vendor's .dtsi files as generic as possible (i.e. unmodified) for maximum reuse capability and maintainability.
That's why you see non-essential peripherals disabled when first described in a SoC .dtsi file, only to be enabled later in a different (board-level) file.

Regards
blue_z
 
Posts: 36
Joined: Sat Jun 13, 2015 12:12 am
Location: USA


Return to Hardware and peripherals

Who is online

Users browsing this forum: No registered users and 18 guests

cron