分类: LINUX
2009-08-14 01:54:04
struct platform_device {
const char * name;
u32 id;
struct device dev; //对应的设备
u32 num_resources; //资源的数量
struct resource * resource; //资源信息
};
与此对应的平台设备驱动程序由struct platform_driver描述:
struct platform_driver {
int (*probe)(struct platform_device *);
int (*remove)(struct platform_device *);
void (*shutdown)(struct platform_device *);
int (*suspend)(struct platform_device *, pm_message_t state);
int (*suspend_late)(struct platform_device *, pm_message_t state);
int (*resume_early)(struct platform_device *);
int (*resume)(struct platform_device *);
struct device_driver driver;
};
内核还提供了多平台设备的接口函数:
int platform_device_register(struct platform_device *pdev);
int platform_device_unregister(struct platform_device *pdev);
int platform_add_devices(struct platform_device **pdevs, int ndev);
int platform_driver_register(struct platform_driver *drv);
int platform_driver_unregister(struct platform_driver *drv);
还有一重要数据结构:
struct resource {
const char *name;
unsigned long start, end; //起始地址与终止地址
unsigned long flags;
struct resource *parent, *sibling, *child;
};
标志包括:
#define IORESOURCE_IO 0x00000100 //I/0资源
#define IORESOURCE_MEM 0x00000100 //内存资源
#define IORESOURCE_IRQ 0x00000100 //中断资源
#define IORESOURCE_DMA 0x00000100 //DMA资源
获取设备资源信息函数:
struct int platform_get_irq(struct platform_device *dev, unsigned int num);
//根据序号获取资源中的中断号。
struct resource * platform_get_resource(struct platform_device *dev, unsigned int type, unsigned int num); //根据资源类型和序号来获取指定的资源
struct resource * platform_get_resource_byname(struct platform_device *dev, unsigned int type, char *name); //根据名称和类别获取指定的资源
struct resource * platform_get_irq_byname(struct platform_device *dev, char *name); //根据名称获取资源的中断号
通过Platform机制开发发底层驱动的大致流程为: 定义 platform_device à 注册 platform_device à 定义 platform_driver à注册 platform_driver
S3C2440中集成的 i2C, IIS, RTC, 看门狗都归为平台设备.