mini2440移植之SPI驱动

目标平台:mini2440

内核:linux2.6.32.2

1,修改arch/arm/mach-s3c2440/mach-mini2440.c文件,加入头文件:

#include <linux/spi/spi.h>
#include <../mach-s3c2410/include/mach/spi.h>
然后加入如下代码:
static struct spi_board_info s3c2410_spi0_board[] =
{
        [0] = {
                .modalias = "spidev",
                .bus_num = 0,
                .chip_select = 0,
                .irq = IRQ_EINT9,
                .max_speed_hz = 500 * 1000,
                }
};

static struct s3c2410_spi_info s3c2410_spi0_platdata = {
        .pin_cs = S3C2410_GPG(2),
        .num_cs = 1,
        .bus_num = 0,
        .gpio_setup = s3c24xx_spi_gpiocfg_bus0_gpe11_12_13,
};

static struct spi_board_info s3c2410_spi1_board[] =
{
        [0] = {
                .modalias = "spidev",
                .bus_num = 1,
                .chip_select = 0,
                .irq = IRQ_EINT2,
                .max_speed_hz = 500 * 1000,
                }
};


static struct s3c2410_spi_info s3c2410_spi1_platdata = {
        .pin_cs = S3C2410_GPG(3),
        .num_cs = 1,
        .bus_num = 1,
        .gpio_setup = s3c24xx_spi_gpiocfg_bus1_gpg5_6_7,
};
注意:这在2.6.29中可行,但是在2.6.32源代码中没有定义S3C2410_GPG2宏定义,要使用S3C2410_GPG(2)宏定义。移植过程中,尤其要注意,不同内核版本对结构体,函数等表示方法的变化

在mini2440_devices[]平台数组中添加如下代码:

static struct platform_device *mini2440_devices[] __initdata = {
        &s3c_device_usb,
        &s3c_device_lcd,
        &s3c_device_wdt,
        &s3c_device_i2c0,
        &s3c_device_iis,
        &s3c_device_rtc,
        &s3c_device_nand,//NAND
        &mini2440_device_eth,//DM9000
        &s3c_device_spi0,//spi
        &s3c_device_spi1,//spi
};
最后在mini2440_machine_init函数中加入如下代码:
static void __init mini2440_machine_init(void)
{
        s3c24xx_fb_set_platdata(&mini2440_fb_info);
        s3c_i2c0_set_platdata(NULL);

        platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
        //smdk_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;
        spi_register_board_info(s3c2410_spi1_board, ARRAY_SIZE(s3c2410_spi1_board));
}

最后需要修改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.
修改为

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.
最后我们配置编译文件:
make menuconfig
图1


图2


图3


图4


图5


编译内核

make zImage
将编译好的内核导入开发板,并且编译Linux Source自带的测试程序,在Documentation/spi下,修改spidev_test.c文件,将device name改为/dev/spidev1.0

将编译好的文件下载到开发板上,并且将开发板的SPI MOI和MIO短接,也就是让SPI自己发送自己接收,执行文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值