飞车青峰剃刀:关于s3c2410fb_driver

来源:百度文库 编辑:九乡新闻网 时间:2024/07/14 16:14:28

分析一下s3c2410fb_driver。static struct platform_driver s3c2410fb_driver = { .probe = s3c2410fb_probe, .remove = s3c2410fb_remove, .suspend = s3c2410fb_suspend, .resume = s3c2410fb_resume, .driver = { .name = "s3c2410-lcd", .owner = THIS_MODULE, },};
首先看一下这个结构体的原型也就是platform_driverstruct 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 (*probe)(struct platform_device *);
首先看括号,这里括号把成员变量分成两部分,一部分是(*probe)另一部分是(struct platform_device *)
很显然(*probe)是一个指针变量probe,那么(struct platform_device *)也是一个指针,并且是一个结构体类型(struct platform_device)的指针那么这个变量是指针并且有两个修饰,一个是前面的 int  一个是后面的(struct platform_device  *)这其实就是一个指向函数的指针变量,只不过是以个返回值是 int  参数是指向platform_device类型的指针
这里需要注意的是driver,driver是一个device_driver类型的结构体
那么来看看device_driver结构体的原型
struct device_driver { const char * name; struct bus_type * bus;
struct kobject kobj; struct klist klist_devices; struct klist_node knode_bus;
struct module * owner; const char * mod_name; /* used for built-in modules */ struct module_kobject * mkobj;
int (*probe) (struct device * dev); int (*remove) (struct device * dev); void (*shutdown) (struct device * dev); int (*suspend) (struct device * dev, pm_message_t state); int (*resume) (struct device * dev);};在这个结构体了找到了如下成员const char * name;
struct module * owner;
这两个成员就对应s3c2410fb_driver.driver.name;s3c2410fb_driver.driver.owner;另外需要说明一下name 对我们很重要
因为我们在前面定义了一个平台驱动s3c2410fb_driver
那么驱动就是通过name 来对应自己的设备的结构体

同时我们也可以找到一个关于设备的结构体struct platform_device s3c_device_lcd = { .name  = "s3c2410-lcd", .id  = -1, .num_resources  = ARRAY_SIZE(s3c_lcd_resource), .resource  = s3c_lcd_resource, .dev              = { .dma_mask = &s3c_device_lcd_dmamask, .coherent_dma_mask = 0xffffffffUL }};
在这个结构体里面也可以找到一个成员变量是.name   = "s3c2410-lcd",
那么这个变量就是为了和设备和驱动吻合而对应的。在来看看这个结构体的原型platform_device如下;struct platform_device { const char * name; u32 id; struct device dev; u32 num_resources; struct resource * resource;};再来看看这个成员dev这个变量是以个( device)结构类型的那么再来看看struct device
struct device如下;
struct device { struct klist klist_children; struct klist_node knode_parent; /* node in sibling list */ struct klist_node knode_driver; struct klist_node knode_bus; struct device *parent;
struct kobject kobj; char bus_id[BUS_ID_SIZE]; /* position on parent bus */ struct device_type *type; unsigned is_registered:1; unsigned uevent_suppress:1; struct device_attribute uevent_attr; struct device_attribute *devt_attr;
struct semaphore sem; /* semaphore to synchronize calls to * its driver. */
struct bus_type * bus; /* type of bus device is on */ struct device_driver *driver; /* which driver has allocated this   device */ void *driver_data; /* data private to the driver */ void *platform_data; /* Platform specific data, device   core doesn't touch it */ struct dev_pm_info power;
#ifdef CONFIG_NUMA int numa_node; /* NUMA node this device is close to */#endif u64 *dma_mask; /* dma mask (if dma'able device) */ u64 coherent_dma_mask;/* Like dma_mask, but for     alloc_coherent mappings as     not all hardware supports     64 bit addresses for consistent     allocations such descriptors. */
struct list_head dma_pools; /* dma pools (if dma'ble) */
struct dma_coherent_mem *dma_mem; /* internal for coherent mem     override */ /* arch specific additions */ struct dev_archdata archdata;
spinlock_t devres_lock; struct list_head devres_head;
/* class_device migration path */ struct list_head node; struct class *class; dev_t devt; /* dev_t, creates the sysfs "dev" */ struct attribute_group **groups; /* optional groups */
void (*release)(struct device * dev);};
这里详细描述了以个设备的信息
另外也对 resource如下 
Resources are tree-like, allowing  nesting etc.. 
struct resource { resource_size_t start; resource_size_t end; const char *name; unsigned long flags; struct resource *parent, *sibling, *child;};