码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2018-02-11 12:26:46      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:resource   strong   font   linux2.6   dm8127   module   static   oar   span   

一、驱动程序结构

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为例)

标签:resource   strong   font   linux2.6   dm8127   module   static   oar   span   

原文地址:https://www.cnblogs.com/FarmPick/p/8440504.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!