Hi shashikant,
It seems that there is something wrong with steps on simulation of GPIO to SPI, i.MX28's BSP is old version of linux, whose final version is 2.6.35. so steps below if for you reference.
1. positions of source code
linux/drivers/spi/spi_gpio.c
linux/include/linux/spi_gpio.h
linux/include/linux/spi_bitbang.h
2. data structure
struct spi_gpio_platform_data {
unsigned sck;
unsigned mosi;
unsigned miso;
u16 num_chipselect;
};
For the first three members, we need to use GPIO on the CPU to assign values. And the fourth member is the number of chip selections, For example, num_chipselect = 4, means that this SPI BUS allows 4 Slave Devices.
3. Customers can follow it to use it
(1)In mx28evk.c, add code at the beginning
**** Define GPIO, interface with linux gpio, the following pins are assumed, the customer can modify it according to the situation:
#include<linux/spi_gpio.h>
#include<linux/spi_bitbang.h>
#define GPIO_SPI_SCLK MXS_PIN_TO_GPIO(PINID_PWM2)
#define GPIO_SPI_MOSI MXS_PIN_TO_GPIO(PINID_PWM3)
#define GPIO_SPI_MISO MXS_PIN_TO_GPIO(PINID_PWM4)
#define GPIO_SPI_CS0 MXS_PIN_TO_GPIO(PINID_SPDIF)
static struct spi_gpio_platform_data gpio_spi_data = {
. sck = GPIO_SPI_SCLK,
. mosi = GPIO_SPI_MOSI,
. miso = GPIO_SPI_MISO,
. num_chipselect = 1,
}
*** Define GPIO SPI device
struct platform_device gpio_spi_device = {
.name = " spi_gpio",
.id = 5,
.dev = {
. platform_data = & gpio_spi_data,
},
};
*** In the existing spi_board_info definition, add the device connected by the customer to the GPIO SPI:
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
/ * The device connected to GPIO_SPI Bus --- customer modify it by himself * /
{
.modalias = "customer device name", /* Name of spi_driver for this device */
.max_speed_hz = 50000, /* max spi clock (SCK) speed in HZ */
.bus_num = 5, /* the same as spi controller ID */
.controller_data = (void *)GPIO_SPI_CS0, /* Used as chip select. */
.platform_data = &gpio_spi_device_data, /* customer define*/
} ,
};
*** Register GPIO SPI device, add in static void spi_device_init (void) function:
static void spi_device_init(void)
{
platform_device_register(gpio_spi_device);
spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
}
4. When compiling the kernel, select the spi gpio module
From linux / driver / spi / Kconfig & Makefile, you can know its position in the kernel configuration menu.
Hope above information is helpful for you!
Have a nice day!
B.R,
Weidong