SPI on i.mx23

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

SPI on i.mx23

Jump to solution
4,099 Views
ajmorris
Contributor II

Hi all,

Firstly I apologise for what is most probably a stupid question.

Essentially i want to be able to interface with the SP Interface on the i.mx23 evk board. We are creating a custom breakout board for the 120-pin external connector to be able to connect to the SPI pins directly, however, i cannot figure out how to actually interface to these ports in the code itself. I have looked through the kernel source code, and located many references to SPI firmware/drivers, but nevertheless am still unsure of how to proceed. I was mostly looking for pre-defined functions for accessing the ports, or if they dont exist, just the hex addresses of the ports so i can write my own. If its relevant, the pins on the 120-pin connecter i am trying interface to, are 104, 108, 112 and 118.

Any help and/or insight anyone could give me would be great!

Thanks,

Andrew

0 Kudos
Reply
1 Solution
2,562 Views
fabio_estevam
NXP Employee
NXP Employee

Hi Andrew,

On a modern kernel (3.6-rc3), we use device tree to represent the board connections. You can see this patch I sent recently that adds support for mx28 spi flash as a reference:

http://git.linaro.org/gitweb?p=people/shawnguo/linux-2.6.git;a=commitdiff;h=5decb4b63ab25fa826e117f8...

You can do the same for your board. Take a look at arch/arm/boot/dts/imx23-evk.dts in kernel.org for a reference.

Regards,

Fabio Estevam

View solution in original post

0 Kudos
Reply
7 Replies
2,562 Views
ajmorris
Contributor II

Thanks alot for the info Yuji and Fabio. I should be well on the way to being able to implement the spi communication now.

0 Kudos
Reply
2,563 Views
fabio_estevam
NXP Employee
NXP Employee

Hi Andrew,

On a modern kernel (3.6-rc3), we use device tree to represent the board connections. You can see this patch I sent recently that adds support for mx28 spi flash as a reference:

http://git.linaro.org/gitweb?p=people/shawnguo/linux-2.6.git;a=commitdiff;h=5decb4b63ab25fa826e117f8...

You can do the same for your board. Take a look at arch/arm/boot/dts/imx23-evk.dts in kernel.org for a reference.

Regards,

Fabio Estevam

0 Kudos
Reply
2,562 Views
ajmorris
Contributor II

Hi Fabio,

I know its a long time since you responded, and probably wont see this again, but just wondering if its possible to actually compile a modern kernel for i.mx23... I downloaded some git source for a 3.7 tree, and attempted to compile it with imx patches using freescale's customised ltib package, however the ltib source that is provided is looking for a 2.6 tree so fails to compile.

Thanks,

Andrew

0 Kudos
Reply
2,562 Views
YS
Contributor IV

The mx23evk_pins.c is board support file which is specific to i.MX23 EVK.  Because you are dealing with your custom board, it may not 100% fit. In "official" way of Linux porting, you should define new board support package for your board, but it takes more steps (dealing with Kconfig file). I don't want to get too deep in this subject.

In quick and (little) dirty solution, you can modify mx23evk_pins.c to add your pin configuration. You may also have to modify mx23evk.c and device.c to define SPI device definition, resource, initialization code.

If you want to use two SPI ports, you also have to modify arch/arm/plat-mxs/device.c to define second SPI device (mxs-spi.1) instance.

2,562 Views
polestar
Contributor I

Hi,

I'm using imx28evk

I've added all the support I could think of for second SPI and nothing works for me.... Can you help??

  • I've edited my board info like this in mx28evk.c:


static struct spi_board_info spi_board_info[] __initdata = {

#if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE)

  {

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

  .modalias = "m25p80", /* Name of spi_driver for this device */

  .max_speed_hz = 20000000,     /* max spi clock (SCK) speed in HZ */

  .bus_num = 1, /* Framework bus number */

  .chip_select = 0, /* Framework chip select. */

  .platform_data = &mx28_spi_flash_data,

  },

#endif

  {

  .modalias = "spidev",

  .max_speed_hz = 20000000,

  .bus_num = 2,

  .chip_select = 0,

  .mode = SPI_MODE_0,

  },

};


  • in addition I've added support for SSP3 in device.c:


static struct mxs_spi_platform_data spi1_data = {

  .clk = "ssp.3",

  .slave_mode = 0,

};

static struct resource ssp3_resources[] = {

  {

  .start = SSP3_PHYS_ADDR,

  .end = SSP3_PHYS_ADDR + 0x2000 - 1,

  .flags = IORESOURCE_MEM,

  }, {

  .start = MXS_DMA_CHANNEL_AHB_APBH_SSP3,

  .end = MXS_DMA_CHANNEL_AHB_APBH_SSP3,

  .flags = IORESOURCE_DMA,

  }, {

  .start = IRQ_SSP3_DMA,

  .end = IRQ_SSP3_DMA,

  .flags = IORESOURCE_IRQ,

  }, {

  .start = IRQ_SSP3,

  .end = IRQ_SSP3,

  .flags = IORESOURCE_IRQ,

  },

};

static void __init mx28_init_spi1(void)

{

  struct platform_device *pdev;

  pdev = mxs_get_device("mxs-spi", 1);

  if (pdev == NULL || IS_ERR(pdev))

  return;

  pdev->resource = ssp3_resources;

  pdev->num_resources = ARRAY_SIZE(ssp3_resources);

  pdev->dev.platform_data = &spi1_data;

  mxs_add_device(pdev, 3);

}

  • and, of course, defined the SSP3 pins in mx28evk_pins.c:

#if defined(CONFIG_SPI_MXS) || defined(CONFIG_SPI_MXS_MODULE)

static struct pin_desc mx28evk_spi_pins[] = {

  {

  .name = "SSP2 MOSI",

  .id = PINID_SSP2_MOSI,

  .fun = PIN_FUN1,

  .strength = PAD_4MA,

  .voltage = PAD_3_3V,

  .drive = 1,

  },

  {

  .name = "SSP2 MISO",

  .id = PINID_SSP2_MISO,

  .fun = PIN_FUN1,

  .strength = PAD_4MA,

  .voltage = PAD_3_3V,

  .drive = 1,

  },

  {

  .name = "SSP2 SCK",

  .id = PINID_SSP2_SCK,

  .fun = PIN_FUN1,

  .strength = PAD_4MA,

  .voltage = PAD_3_3V,

  .drive = 1,

  },

  {

  .name = "SSP2 SS0",

  .id = PINID_SSP2_SS0,

  .fun = PIN_FUN1,

  .strength = PAD_8MA,

  .voltage = PAD_3_3V,

  .drive = 1,

  },

  {

  .name = "SSP3 MOSI",

  .id = PINID_SSP3_MOSI,

  .fun = PIN_FUN1,

  .strength = PAD_4MA,

  .voltage = PAD_3_3V,

  .drive = 1,

  },

  {

  .name = "SSP3 MISO",

  .id = PINID_SSP3_MISO,

  .fun = PIN_FUN1,

  .strength = PAD_4MA,

  .voltage = PAD_3_3V,

  .drive = 1,

  },

  {

  .name = "SSP3 SCK",

  .id = PINID_SSP3_SCK,

  .fun = PIN_FUN1,

  .strength = PAD_4MA,

  .voltage = PAD_3_3V,

  .drive = 1,

  },

  {

  .name = "SSP3 SS0",

  .id = PINID_SSP3_SS0,

  .fun = PIN_FUN1,

  .strength = PAD_8MA,

  .voltage = PAD_3_3V,

  .drive = 1,

  },

};

#endif

But still SPIDEV won't create the device driver...

The m25p80 is working fine though...

Thanks a lot for anyone's help with this.....

0 Kudos
Reply
2,562 Views
ajmorris
Contributor II

Hi Yuji,

Thankyou very much for your reply, this has helped a lot! However, the pin configuration in the kernel source code doesnt appear to have a full pin out for the 120-pin expansion port... There are some spi pinouts in there though, so hopefully i can use these definitions for the 4 out of 120 pins that i need.

0 Kudos
Reply
2,562 Views
YS
Contributor IV

Andrew,

You dont' have to feel sorry. Everybody feels powerless when they first seen Linux source code. I've also took same way when I tried to make SPI port works on my iMX28 project few months back. Because my experience is based on iMX28, I can't give you exact step-by-step instruction but I can give where you should look.

For iMX23 pin configuration, check out Linux Kernel source code arch/arm/mach-mx23/mx23evk_pins.c. There is built-in SPI pin configuration mx23evk_spi_pins[], which is chosen when CONFIG_SPI_MXS macro turns on. CONFIG_SPI_MXS is linked to Linux Kernel "make menuconfig" option, Device Drivers ---> SPI Support ---> Freescale MXS SPI/SSP controller. In same screen, you will also notice "User mode SPI device driver support". You should turn this ON too, if you want to control SPI bus from your program rather than built-in Linux device drivers (such as SPI flash rom driver).

Refer to Documentation/spi/spidev text file how to use usermode SPI driver from your program. There are few more steps you have to follow. Documentation/spi/spi-summary is also a good source of information.