SPI Driver on Linux Side

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SPI Driver on Linux Side

Jump to solution
4,426 Views
bfac
NXP Employee
NXP Employee

Hello!

We would like to use the SPI interface from Linux side fro Vybrid inside the timesys Linux BSP.

The device we need to communicate with is a custom device, so we will use a custom made user-space driver to communicate over raw SPI (we already have that driver ready).

Our user-space driver is done such it communicated with /dev/spi -like interface, so it would be great to have a spi module that already creates that device structure.

BR,

Bruno

Labels (3)
0 Kudos
1 Solution
2,296 Views
helderhdw
Contributor III

Hello,

I resolved the dpsi driver, and DSPI works. I´m using the DSPI0, like following  code:

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

/*DSPI0*/

MVF600_PAD41_PTB19__DSPI0_PCS0,

MVF600_PAD42_PTB20__DSPI0_SIN,

MVF600_PAD43_PTB21__DSPI0_SOUT,

MVF600_PAD44_PTB22__DSPI0_SCK,

static int pcm052_spi_cs[] = {

        89,

};

static struct spi_mvf_chip at26df081a_chip_info = {

        .mode = SPI_MODE_0,

        .bits_per_word = 8,

        .void_write_data = 0,

        .dbr = 0,

        .pbr = 0,

        .br = 0,

        .pcssck = 0,

        .pasc = 0,

        .pdt = 0,

        .cssck = 0,

        .asc = 0,

        .dt = 0,

};

static const struct spi_mvf_master pcm052_qspi_data __initconst = {

        .bus_num = 0,

        .chipselect = pcm052_qspi_cs,

        .num_chipselect = ARRAY_SIZE(pcm052_qspi_cs),

        .cs_control = NULL,

};

static struct spi_board_info mvf_spi_board_info[] __initdata = {

        {

                // The modalias must be the same as spi device driver name

                //.modalias = "m25p80",

                .modalias = "spidev",

                .max_speed_hz = 16000000,

                .bus_num = 0,

                .chip_select = 0,

                //.platform_data = &at26df081a_platform_data,

                .controller_data = &at26df081a_chip_info

        },

};

static void spi_device_init(void)

{

        spi_register_board_info(mvf_spi_board_info,

                                ARRAY_SIZE(mvf_spi_board_info));

}

==== in pcm052_board_init function

        mvf_add_dspi(0, &pcm052_spi_data);

        //mvf_add_qspi(0, &pcm052_qspi_data);

        spi_device_init();

View solution in original post

0 Kudos
16 Replies
2,296 Views
vpa
Contributor II

Hi,

I try to use DSPI0 too. I follow this thread and this about change spi port.

I work on TWR-VF65GS10, so i modify the board file as above but i can't determine the chip select value.

In board file, chip select value is 134 but how can i determine this number ?

0 Kudos
2,296 Views
timesyssupport
Senior Contributor II

Hello Vincent,

The Linux kernel for the TWR-VF65GS10 has a working DSPI driver for DSPI0 - you should not need to change the chip select if you are using the reference hardware.

Regards,

Timesys Support

0 Kudos
2,296 Views
vpa
Contributor II

Yes, i understand that but if i want to change or add other DSPI, i need to know how to determine chip select.

Thanks for help.

0 Kudos
2,296 Views
timesyssupport
Senior Contributor II

Hello Vincent,

The chip select value corresponds to a GPIO pin - you can refer to the schematic for your hardware to determine the correct GPIO pin.

Regards,

Timesys Support

0 Kudos
2,296 Views
vpa
Contributor II

Hello,

In datasheet i can see some informations which i can't understand or translate to a correct pin number.

For example :

SPI0_PCS0 : - 364 MAP BGA = C13

                    - 176 LQFP = 167

                    - Pin name = PTB19

This is the same information on the schematics, no matches between reference and pin number.

Thanks.

0 Kudos
2,296 Views
timesyssupport
Senior Contributor II

Hello Bruno,

You will need to add a spidev entry to mvf_spi_board_info[] to the board definition file in your kernel, at arch/arm/mach-mvf/board-twr-vf700.c. You will also need to register the pin you are using as the chip select by adding it to mvf_vf600_spi_cs[] in this same file.

Thanks, and let me know if you have any questions.

Timesys Support

2,296 Views
bfac
NXP Employee
NXP Employee

heldercs, can you provide feed back on this topic?

0 Kudos
2,297 Views
helderhdw
Contributor III

Hello,

   I´m using phyCore-vybrid, and I made the suggested changes:

1) include "spidev" entry to mvf_spi_board_info[], at  arch/arm/mach-mvf/board-pcm052.c

static struct spi_board_info mvf_spi_board_info[] __initdata = {

        {

                /* The modalias must be the same as spi device driver name */

               .modalias = "spidev",

                .max_speed_hz = 50000000,

                .bus_num = 0,

                .chip_select = 0,

                .mode = SPI_MODE_0,

       },

};

2) register the chip select static int pcm052_spi_cs[] = { 41,}

3) and in ipcm052_board_init function, I included   "mvf_add_dspi(0, &pcm052_spi_data)",  and "spi_device_init()"

and I compiled the dspi driver like a MODULE, and started as show below. But segfalt occurred:

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

# modprobe spi_mvf_dspi

setup mode 0, 0 bits/w, 50000000 Hz max --> 0

Unable to handle kernel NULL pointer dereference at virtual address 00000000

pgd = 864d8000

[00000000] *pgd=864a4831, *pte=00000000, *ppte=00000000

Internal error: Oops: 17 [#1]

Modules linked in: spi_mvf_dspi(+)

CPU: 0    Not tainted  (3.0.15-ts-armv7l #79)

PC is at setup+0x178/0x1b0 [spi_mvf_dspi]

LR is at __kmalloc+0xf8/0x168

pc : [<7f000e54>]    lr : [<800be088>]    psr: a0000013

sp : 864ebd68  ip : 00000000  fp : 00000000

r10: 8640a768  r9 : 860d5a08  r8 : 00000000

r7 : 00000000  r6 : 864a2200  r5 : 00000000  r4 : 864b79c0

r3 : 804b2230  r2 : 00000000  r1 : ffffffe0  r0 : 864b79c0

Flags: NzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user

Control: 10c53c7d  Table: 864d8059  DAC: 00000015

Process modprobe (pid: 788, stack limit = 0x864ea2e8)

Stack: (0x864ebd68 to 0x864ec000)

bd60:                   7f000cdc 864a2200 8040fda8 8042dbe4 00000000 80248084

bd80: 8040fda8 8040fda8 00000000 02faf080 00000000 8021d560 86023938 864a2200

bda0: 860d6248 860d5a08 00000000 80248340 00000000 864a2200 860d6248 00000000

bdc0: 00000000 80248444 860d6248 8640a600 804a70f0 802484f0 804a70e8 860d6240

bde0: 8640a600 802485c4 860d621c 8640a740 8640a600 7f000bb0 00000000 8640a740

be00: 860d5a08 804ed638 860d5a3c 7f0012a0 00000000 7f003000 864ea000 8021f184

be20: 8021f16c 8021e174 00000000 860d5a08 7f0012a0 860d5a3c 864ad600 8021e318

be40: 00000000 7f0012a0 8021e28c 8021d184 860230f8 860d45d0 7f0012a0 7f0012a0

be60: 804a2a60 8021db58 7f00125c 804b8ebc 7f0012a0 7f0012a0 7f0012dc 864a6180

be80: 00000001 0000001c 864ea000 8021e594 8021f1ac 7f0012dc 7f0012dc 864a6180

bea0: 00000001 0000001c 864ea000 7f00300c 804b2d60 8002d428 8048c1dc ffffffff

bec0: 00000000 8048c1dc 00000000 80066da4 00000000 864b7400 888ed000 7f0012dc

bee0: 7f0012dc 864a6180 00000001 0000001c 7f001324 00000024 0000038f 800757f0

bf00: 7f0012e8 00000000 00003401 00000000 80074378 000a65d0 888ef4d4 888eed94

bf20: 014405eb 8044ddd8 00000000 00000000 00000000 00000000 00000000 00000000

bf40: 888ed000 00003354 888eeffc 888eeead 888efbfc 864dd700 0000142c 0000162c

bf60: 00000000 00000000 0000001e 0000001f 00000016 00000013 00000011 00000000

bf80: 864a30c0 00003354 000a65d0 000a6718 00000080 80032d84 864ea000 00000000

bfa0: 000a65a8 80032c00 00003354 000a65d0 000a6738 00003354 000a65d0 000a6690

bfc0: 00003354 000a65d0 000a6718 00000080 00000000 000a6718 000a5a24 000a65a8

bfe0: 7eff3b50 7eff3b40 00022670 2ac5bb40 600f0010 000a6738 87ffe821 87ffec21

[<7f000e54>] (setup+0x178/0x1b0 [spi_mvf_dspi]) from [<80248084>] (spi_setup+0xcc/0x104)

[<80248084>] (spi_setup+0xcc/0x104) from [<80248340>] (spi_add_device+0x94/0x124)

[<80248340>] (spi_add_device+0x94/0x124) from [<80248444>] (spi_new_device+0x74/0xac)

[<80248444>] (spi_new_device+0x74/0xac) from [<802484f0>] (spi_match_master_to_boardinfo+0x24/0x44)

[<802484f0>] (spi_match_master_to_boardinfo+0x24/0x44) from [<802485c4>] (spi_register_master+0xb4/0x118)

[<802485c4>] (spi_register_master+0xb4/0x118) from [<7f000bb0>] (spi_mvf_probe+0x29c/0x3c0 [spi_mvf_dspi])

[<7f000bb0>] (spi_mvf_probe+0x29c/0x3c0 [spi_mvf_dspi]) from [<8021f184>] (platform_drv_probe+0x18/0x1c)

[<8021f184>] (platform_drv_probe+0x18/0x1c) from [<8021e174>] (driver_probe_device+0x8c/0x1a4)

[<8021e174>] (driver_probe_device+0x8c/0x1a4) from [<8021e318>] (__driver_attach+0x8c/0x90)

[<8021e318>] (__driver_attach+0x8c/0x90) from [<8021d184>] (bus_for_each_dev+0x44/0x8c)

[<8021d184>] (bus_for_each_dev+0x44/0x8c) from [<8021db58>] (bus_add_driver+0x17c/0x24c)

[<8021db58>] (bus_add_driver+0x17c/0x24c) from [<8021e594>] (driver_register+0x78/0x148)

[<8021e594>] (driver_register+0x78/0x148) from [<7f00300c>] (spi_mvf_init+0xc/0x18 [spi_mvf_dspi])

[<7f00300c>] (spi_mvf_init+0xc/0x18 [spi_mvf_dspi]) from [<8002d428>] (do_one_initcall+0x10c/0x170)

[<8002d428>] (do_one_initcall+0x10c/0x170) from [<800757f0>] (sys_init_module+0x3d0/0x1a7c)

[<800757f0>] (sys_init_module+0x3d0/0x1a7c) from [<80032c00>] (ret_fast_syscall+0x0/0x30)

Code: e30810d0 eb42f450 e2504000 0a000004 (e5d53000)

---[ end trace e5ca59d17e94b3ab ]---

Segmentation fault

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

thanks,

Francisco

0 Kudos
2,297 Views
timesyssupport
Senior Contributor II

Hello Francisco,

Would you be able to send us the entire source file so we can review?

Thank you,

Timesys Support

0 Kudos
2,297 Views
helderhdw
Contributor III

Hello,

I resolved the dpsi driver, and DSPI works. I´m using the DSPI0, like following  code:

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

/*DSPI0*/

MVF600_PAD41_PTB19__DSPI0_PCS0,

MVF600_PAD42_PTB20__DSPI0_SIN,

MVF600_PAD43_PTB21__DSPI0_SOUT,

MVF600_PAD44_PTB22__DSPI0_SCK,

static int pcm052_spi_cs[] = {

        89,

};

static struct spi_mvf_chip at26df081a_chip_info = {

        .mode = SPI_MODE_0,

        .bits_per_word = 8,

        .void_write_data = 0,

        .dbr = 0,

        .pbr = 0,

        .br = 0,

        .pcssck = 0,

        .pasc = 0,

        .pdt = 0,

        .cssck = 0,

        .asc = 0,

        .dt = 0,

};

static const struct spi_mvf_master pcm052_qspi_data __initconst = {

        .bus_num = 0,

        .chipselect = pcm052_qspi_cs,

        .num_chipselect = ARRAY_SIZE(pcm052_qspi_cs),

        .cs_control = NULL,

};

static struct spi_board_info mvf_spi_board_info[] __initdata = {

        {

                // The modalias must be the same as spi device driver name

                //.modalias = "m25p80",

                .modalias = "spidev",

                .max_speed_hz = 16000000,

                .bus_num = 0,

                .chip_select = 0,

                //.platform_data = &at26df081a_platform_data,

                .controller_data = &at26df081a_chip_info

        },

};

static void spi_device_init(void)

{

        spi_register_board_info(mvf_spi_board_info,

                                ARRAY_SIZE(mvf_spi_board_info));

}

==== in pcm052_board_init function

        mvf_add_dspi(0, &pcm052_spi_data);

        //mvf_add_qspi(0, &pcm052_qspi_data);

        spi_device_init();

0 Kudos
2,297 Views
helderhdw
Contributor III

Hello,

Now I need the other help. I´m using the DSPI for chip 0 (DSPI0), like following  code:

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

/*DSPI0*/

MVF600_PAD41_PTB19__DSPI0_PCS0,

MVF600_PAD42_PTB20__DSPI0_SIN,

MVF600_PAD43_PTB21__DSPI0_SOUT,

MVF600_PAD44_PTB22__DSPI0_SCK,

static int pcm052_spi_cs[] = {

        89,

};

static struct spi_mvf_chip at26df081a_chip_info = {

        .mode = SPI_MODE_0,

        .bits_per_word = 8,

        .void_write_data = 0,

        .dbr = 0,

        .pbr = 0,

        .br = 0,

        .pcssck = 0,

        .pasc = 0,

        .pdt = 0,

        .cssck = 0,

        .asc = 0,

        .dt = 0,

};

static const struct spi_mvf_master pcm052_qspi_data __initconst = {

        .bus_num = 0,

        .chipselect = pcm052_qspi_cs,

        .num_chipselect = ARRAY_SIZE(pcm052_qspi_cs),

        .cs_control = NULL,

};

static struct spi_board_info mvf_spi_board_info[] __initdata = {

        {

                // The modalias must be the same as spi device driver name

                //.modalias = "m25p80",

                .modalias = "spidev",

                .max_speed_hz = 16000000,

                .bus_num = 0,

                .chip_select = 0,

                //.platform_data = &at26df081a_platform_data,

                .controller_data = &at26df081a_chip_info

        },

};

static void spi_device_init(void)

{

        spi_register_board_info(mvf_spi_board_info,

                                ARRAY_SIZE(mvf_spi_board_info));

}

==== in pcm052_board_init function

        mvf_add_dspi(0, &pcm052_spi_data);

        //mvf_add_qspi(0, &pcm052_qspi_data);

        spi_device_init();

===== in board-pcm052.c

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

and I like to use the other SPI pins (DSPI3), as show above:

        /*DSPI3*/

        MVF600_PAD89_PTD10__DSPI3_PCS0,

        MVF600_PAD90_PTD11__DSPI3_SIN,

        MVF600_PAD91_PTD12__DSPI3_SOUT,

        MVF600_PAD92_PTD13__DSPI3_SCK,

what procedure to change these SPI pins? 

regards,

Francisco

0 Kudos
2,297 Views
karina_valencia
NXP Apps Support
NXP Apps Support

HI Francisco,

can you  create  a new discussion with the new question please?

0 Kudos
2,297 Views
helderhdw
Contributor III

Hi Karina,

I created the new discussion.. https://community.freescale.com/message/361319#361319

thanks,

Franicsco

0 Kudos
2,297 Views
karina_valencia
NXP Apps Support
NXP Apps Support

Perfect, thanks.

0 Kudos
2,297 Views
karina_valencia
NXP Apps Support
NXP Apps Support

timesyssupport can you  continue with the follow up on this case?

0 Kudos
2,297 Views
karina_valencia
NXP Apps Support
NXP Apps Support

timesyssupport can you review this case and provide follow up?

0 Kudos