日期:2014-05-16  浏览次数:20779 次

.基于S3C2440 Linux2.30.4 SPI驱动移植全过程

原文地址:http://blog.163.com/joyrain_06/blog/static/1788253920113823524293/

一、环境

??? 硬件:s3c2440

?? ?内核:Linux2.30.4

??? 交叉编译工具:EABI4.3.3

??? 开发环境:rhel5.5

二、移植

? 1.修改arch/arm/mach-s3c2440/mach-mini2440.c文件:??
?

a.加入头文件

? #include <../mach-s3c2410/include/mach/spi.h>
? #include <linux/spi/spi.h>

? b.加入接口结构

/* SPI */
static struct spi_board_info s3c2410_spi0_board[] = {
??????? [0] = {
??????????????? .modalias = "spidev",
??????????????? .bus_num= 0,
??????????????? .chip_select= 0,
?????????????? /* s3c2410_spi0_platdata.num_cs */
??????????????? .irq = IRQ_EINT9,
??????????????? .max_speed_hz= 96*1000*1000,
??????? },
};

static struct s3c2410_spi_info s3c2410_spi0_platdata = {
??????? .pin_cs = S3C2410_GPG2,
??????? .num_cs = 1,
??????? .bus_num = 0,
??????? .gpio_setup=s3c24xx_spi_gpiocfg_bus0_gpe11_12_13,
};


c.加入设备

static struct platform_device *tq2440_devices[] __initdata = {
??????? &s3c_device_usb,
??????? &s3c_device_lcd,
??????? &s3c_device_wdt,
??????? &s3c_device_i2c0,
??????? &s3c_device_iis,
??????? &s3c_device_rtc,
#ifdef CONFIG_DM9000
??????? &s3c_device_dm9000,
#endif
??????? &s3c_device_usbgadget,
??????? &s3c_device_uda134x,

??????? &s3c_device_spi0,?????????????????//注意在结构体中的位置,否则会出现编译错误
??????? //&s3c_device_spi1, //for spi1
};

?

d.注册设备

static void __init tq2440_machine_init(void)
{
??????? s3c24xx_fb_set_platdata(&tq2440_fb_info);
??????? s3c_i2c0_set_platdata(NULL);

??????? platform_add_devices(tq2440_devices, ARRAY_SIZE(tq2440_devices));
??????? EmbedSky_machine_init();
??????? /*SPI*/
??????? s3c_device_spi0.dev.platform_data= &s3c2410_spi0_platdata;
??????? spi_register_board_info(s3c2410_spi0_board, ARRAY_SIZE(s3c2410_spi0_board));
??????? //s3c_device_spi1.dev.platform_data= &s3c2410_spi1_platdata; //for spi1
??????? //spi_register_board_info(s3c2410_spi1_board, ARRAY_SIZE(s3c2410_spi1_board)); //for spi1

??????? s3c2410_gpio_setpin(S3C2410_GPG12, 0);
??????? s3c2410_gpio_cfgpin(S3C2410_GPG12, S3C2410_GPIO_OUTPUT);
??????? s3c24xx_udc_set_platdata(&EmbedSky_udc_cfg);
}

2.修改Kconfig

打开arch/arm/plat-s3c24XX/Kconfig
找到
////////////

config S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13
bool
help
SPI GPIO configuration code for BUS0 when connected to
GPE11, GPE12 and GPE13.

config S3C24XX_SPI_BUS1_GPG5_GPG6_GPG7
bool
help
SPI GPIO configuration code for BUS 1 when connected to
GPG5, GPG6 and GPG7.

修改为
# SPI default pin configuration code

config S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13
??????? bool "S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13"
??????? help
????????? SPI GPIO configuration code for BUS0 when connected to
????????? GPE11, GPE12 and GPE13.

config S3C24XX_SPI_BUS1_GPG5_GPG6_GPG7
??????? bool "S3C24XX_SPI_BUS1_GPG5_GPG6_GPG7"
??????? help
????????? SPI GPIO configuration code for BUS 1 when connected to
????????? GPG5, GPG6 and GPG7.


3.编译内核

#make menuconfig


?System Type? --->?

? [*] S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13??????????????????????????????????