platform设备驱动(Linux驱动4)

来源:互联网 发布:android 珍藏源码 编辑:程序博客网 时间:2024/05/20 00:51

说明:

  platform是Linux中总线的一种,与i2c,pci,isa一样.但是它并非实际存在,而是虚拟出来的,用于将soc中的外围器件挂接在这个总线中.
  linux中的驱动包括总线,设备,设备驱动三个实体,总线将设备和驱动绑定.platform总线的驱动是platform_driver,设备是platform_device.
  总线的match函数就是将驱动与设备的名字加以比较,相等认为匹配上了.

变量:

device_private{
..
void * driver_data;
}
device {
device_private *p;//设备的私有数据
void* platform_data;//平台设备数据
。。。
}
platform_device {
char *name;
u32 id;
struct device dev;
u32 num_resourecs;
struct resource *resource;
}
如果资源文件中的描述不够,可以在dev中的platform_data中自定义数据

    device_driver{        char * name;//描述驱动名称        struct module *owner;        ...    }     platform_driver{        probe        remove        shutdown        suspend        ...        struct device_driver driver;    }    bus_type{        name        dev_attrs        match        uevent        pm    }    resource{        start        end        name        flags        resourec *parent,*sibling,*child;    }    flags:IORESOURCE_IO,IORESORECE_MEM,IORESOURCE_DMA...

函数:

platform_driver_register(platform_driver*)
platform_driver_unregister(platform_driver*)
platform_get_resource(platform_device *dev,flags,num)
platform_set_drvdata(platform_device*pdev,void *);
platform_get_drvdata(platform_device *pdev);

用法

xx_probe(struct platform_device *dev)
{
register_chrdev_region
alloc_chrdev_region
cdev_init
cdev_add

}
xx_remove(struct platform_device *dev)
{
cdev_del();
unregister_chrdev_region();

}
platform_driver xx_driver={
.probe=xx_probe;
.remove=xx_remove
.driver={
.name=”xxdevice”
.owner=THIS_MODULE;
}
}
platform_device xx_device={
.name=”xxdevice”;
.id=-1;

}
xx_init()
{
platform_driver_register(&xx_driver);
}
xx_exit()
{
platform_driver_unregister(&xx_driver);
}

0 0