SPI驱动框架-1(DM8127 Linux2.6.37为例)

Posted 阳光农场皮卡

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SPI驱动框架-1(DM8127 Linux2.6.37为例)相关的知识,希望对你有一定的参考价值。

一、驱动程序结构

1、platform_device

文件:/arch/arm/mach-omap2/device.c

static struct omap2_mcspi_platform_config omap2_mcspi1_config = {
    .num_cs        = 4,
};

static struct resource omap2_mcspi1_resources[] = {
    {
        .start        = OMAP2_MCSPI1_BASE,
        .end        = OMAP2_MCSPI1_BASE + 0xff,
        .flags        = IORESOURCE_MEM,
    },
};

static struct platform_device omap2_mcspi1 = {
    .name        = "omap2_mcspi",
    .id        = 1,                              /* 用于platform_driver probe函数中识别不同的设备 */    
.num_resources
= ARRAY_SIZE(omap2_mcspi1_resources), .resource = omap2_mcspi1_resources, .dev = {   .platform_data = &omap2_mcspi1_config, }, };
static void omap_init_mcspi(void)
{
    if (cpu_is_omap44xx())
        omap4_mcspi_fixup();

    platform_device_register(&omap2_mcspi1);
}

2、dev_devices

文件:/arch/arm/mach-omap2/board-ti8148ipnc.c

static struct spi_board_info dm8127_spi1_board[] = {
   [0] = {
                .modalias = "spidev",
                .bus_num        = 1,
                .chip_select        = 0,
                .irq = -1,
                .max_speed_hz         = 20*1000*1000,
                .mode = SPI_MODE_0,
     },
};
void __init ti8148_spi_init(void)
{
     spi_register_board_info(dm8127_spi1_board,
        ARRAY_SIZE(dm8127_spi1_board));    
}

1、platform_driver

文件:/driver/spi/omap2_mcspi.c

static const struct dev_pm_ops omap2_mcspi_pm_ops = {
    .resume = omap2_mcspi_resume,
};

static struct platform_driver omap2_mcspi_driver = {
    .driver = {
        .name =        "omap2_mcspi",
        .owner =    THIS_MODULE,
        .pm =        &omap2_mcspi_pm_ops
    },
    .remove =    __exit_p(omap2_mcspi_remove),
};


static int __init omap2_mcspi_init(void)
{
    omap2_mcspi_wq = create_singlethread_workqueue(    /* 创建工作队列 */
    omap2_mcspi_driver.driver.name);
    if (omap2_mcspi_wq == NULL)
    return -1;
    return platform_driver_probe(&omap2_mcspi_driver, omap2_mcspi_probe);
}

 1、dev_driver

文件:/driver/spi/spidev.c

static struct spi_driver spidev_spi_driver = {
    .driver = {
        .name =        "spidev",
        .owner =    THIS_MODULE,
    },
    .probe =    spidev_probe,
    .remove =    __devexit_p(spidev_remove),

};

 









以上是关于SPI驱动框架-1(DM8127 Linux2.6.37为例)的主要内容,如果未能解决你的问题,请参考以下文章

DM9000驱动移植在mini2440(linux2.6.29)和FS4412(linux3.14.78)上的实现(deep dive)篇一

图像识别DM8127开发攻略——UBOOT的移植说明

图像识别DM8127开发攻略——KERNEL的移植说明

图像识别DM8127开发攻略——序

linux enc28j60网卡驱动移植(硬件spi和模拟spi)

Linux——Linux驱动之玩转SPI(上)Linux下SPI驱动框架简析及SPI设备驱动代码框架实现步骤