Linux驱动开发(2)——设备注册

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kakascx/article/details/83088556

结构体platform_device

注册设备使用结构体platform_device,源码路径include/linux/platform_device.h

struct platform_device {
        const char      * name;//设备名称,在sys/devices显示
        int             id;//设备id,用于插入总线并且具有相同name的设备编号,如果只有一个设备那么为-1
        struct device   dev;
        u32             num_resources;
        struct resource * resource;

        const struct platform_device_id *id_entry;

        /* MFD cell pointer */
        struct mfd_cell *mfd_cell;

        /* arch specific additions */
        struct pdev_archdata    archdata;
};

操作流程

  1. 注册设备
    将设备结构体放到平台文件中,会自动注册设备,不用去调用注册设备的函数。平台文件路径根据架构选择,例如arch/arm/mach-exynos/mach-itop4412.c。在平台文件中加入设备的结构体,如
#ifdef CONFIG_HELLO_CTL
struct platform_device s3c_device_hello_ctl = {
        .name   = "hello_ctl",
        .id             =-1,
};
#endif

并加入内核链表中,

#ifdef CONFIG_HELLO_CTL
        &s3c_device_hello_ctl,
#endif

  1. 在Kconfig文件中添加设备注册的宏定义
    在/drivers/char/Kconfig文件中定义在/drivers/char/Kconfig文件中定义
  2. 配置menuconfig中的HELLO宏定义,生成新的.config文件
  3. make zImage生成新的zImage
  4. 注册完之后在虚拟平台总线下可以查到注册的设备ls /sys/devices/platform/

猜你喜欢

转载自blog.csdn.net/kakascx/article/details/83088556