【Linux高级驱动】平台设备驱动机制的编程流程与编译进内核

【平台设备驱动机制的编程流程】

 

 

【如何将驱动静态的编译进内核镜像】

1.添加资源(dev-led.c)

1.1:一般来说,系统习惯上将资源放在arch/arm/plat-samsung/目录中

    cp dev-led.c linux-2.6.35.5/arch/arm/plat-samsung
    cp led.h linux-2.6.35.5/arch/arm/plat-samsung/include/plat

1.2:修改dev-led.c文件

  #include<linux/init.h>
  #include<linux/module.h>
  #include<linux/platform_device.h>
  #include<linux/ioport.h>
  #include<plat/led.h>
  
  /*2.构建资源*/
  static struct resource fsled_resource[]={
          [0]={
                  .start  =S3C_PA_LED,
                  .end    =S3C_PA_LED+SZ_8-1,
                  .flags  =IORESOURCE_MEM,   //linux/ioport.h
          },
  };
 
  /*1.构建平台设备结构体*/
  struct platform_device fsled_device={
          .name                   ="fs-led",
          .id                     =-1,
          .num_resources          =ARRAY_SIZE(fsled_resource),
          .resource               =fsled_resource,
  };

 

1.3:进入linux-2.6.35.5/arch/arm/plat-samsung/目录,修改其中的Makefile
    vi Makefile
    在其中添加如下代码

obj-$(CONFIG_S3C_DEV_LED)       += dev-led.o //新添加的

 

1.4:修改linux-2.6.35.5/arch/arm/plat-samsung/目录下的Kconfig
    vi Kconfig
    在其中添加如下代码

config S3C_DEV_LED     //此处一点要跟上面的S3C_DEV_LED一样
         bool 
         help
           Compile in platform device definitions for LED code

 

1.5:修改linux-2.6.35.5/arch/arm/mach-s5pc100/目录下的Kconfig
    vi arch/arm/mach-s5pc100/Kconfig

config MACH_SMDKC100
          bool "SMDKC100"
          select CPU_S5PC100
          select S3C_DEV_FB
          select S3C_DEV_I2C1
          select S3C_DEV_HSMMC
          select S3C_DEV_HSMMC1
          select S3C_DEV_HSMMC2
          select S5PC100_SETUP_FB_24BPP
          select S5PC100_SETUP_I2C1
          select S5PC100_SETUP_SDHCI
          select S3C_DEV_LED   //新添加的代码

 

1.6 修改linux-2.6.35.5/arch/arm/mach-s5pc100/mach-smdkc100.c文件
    vi arch/arm/mach-s5pc100/mach-smdkc100.c
    修改下面的数组:

static struct platform_device *smdkc100_devices[] __initdata = {
         &s3c_device_i2c0,
         &s3c_device_i2c1,
         &s3c_device_fb,
         &s3c_device_hsmmc0,
         &s3c_device_hsmmc1,
         &s3c_device_hsmmc2,
         &smdkc100_lcd_powerdev,
         &s5pc100_device_iis0,
         &s5pc100_device_ac97,
 #ifdef  CONFIG_DM9000
         &s5pc100_device_dm9000,
 #endif
         &fsled_device,    //添加的选项,让系统完成初始化
 };

 

1.7 修改linux-2.6.35.5/arch/arm/plat-samsung/include/plat/devs.h
    vi arch/arm/plat-samsung/include/plat/devs.h
    在其中添加如下代码:

extern struct platform_device fsled_device;

 

2.添加驱动(led_drv.c)

2.1 cp led_drv.c linux-2.6.35.5/drivers/leds/目录

2.2 修改linux-2.6.35.5/drivers/leds/的Makefile
    vi linux-2.6.35.5/drivers/leds/Makefile
    在其中添加如下代码:

obj-$(CONFIG_LEDS_S5PC100)              += led_drv.o

 

2.3 修改linux-2.6.35.5/drivers/leds/的Kconfig
    vi linux-2.6.35.5/drivers/leds/Kconfig
    在其中添加如下代码:

config LEDS_S5PC100
          tristate "LED Support for farsight"
          depends on ARCH_S5PC100
          help
            this is a led drv by farsight

 

2.4 配置选项
    make menuconfig
        Device Drivers  --->
         [*] LED Support  --->
          <*>     LED Support for farsight


3.编译内核

    make zImage

 

@成鹏致远

(email:wwwlllll@126.com)

qq:552158509





posted @ 2014-06-22 15:34  Leo.cheng  阅读(641)  评论(0编辑  收藏  举报