platform设备 函数解析

                         platform设备 函数解析          

                        

这些函数都在inlcude/linux/platform_device.h 和platform.c中

1. platform驱动结构体:

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 (*resume)(struct platform_device *);
    struct device_driver driver;
    const struct platform_device_id *id_table;
};

2. platform设备

struct platform_device {
    const char    * name;
    int        id;
    struct device    dev;
    u32        num_resources;
    struct resource    * resource;
    const struct platform_device_id    *id_entry;
    /* arch specific additions */
    struct pdev_archdata    archdata;
};

3. device结构体://include/linux/device.h

struct device {
    struct device        *parent;
    struct device_private    *p;
    struct kobject kobj;
    const char        *init_name; /* initial name of the device */
    struct device_type    *type;
    struct mutex        mutex;    /* mutex 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        *platform_data;    /* Platform specific data, devicecore 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 consistentallocations such descriptors. */
    struct device_dma_parameters *dma_parms;
    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;
#ifdef CONFIG_OF
    struct device_node    *of_node;
#endif
    dev_t            devt;    /* dev_t, creates the sysfs "dev" */
    spinlock_t        devres_lock;
    struct list_head    devres_head;
    struct klist_node    knode_class;
    struct class        *class;
    const struct attribute_group **groups;    /* optional groups */
    void    (*release)(struct device *dev);
};

4.device_driver结构体:
struct device_driver {
    const char        *name;
    struct bus_type        *bus;
    struct module        *owner;
    const char        *mod_name;    /* used for built-in modules */
    bool suppress_bind_attrs;    /* disables bind/unbind via sysfs */
#if defined(CONFIG_OF)
    const struct of_device_id    *of_match_table;
#endif
    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 struct attribute_group **groups;
    const struct dev_pm_ops *pm;
    struct driver_private  *p;
};

5. int platform_driver_register(struct platform_driver *)
   void platform_driver_unregister(struct platform_driver *) / 注册和注销一个platform驱动。

14. platform_driver_probe(struct platform_driver *drv,int (*probe)(struct platform_device *)) //注册一个platform_driver。当一个驱动注册[platform_driver_probe()]的时候, 功能上和使用platform_driver_register()是一样的,唯一的区别是它不能被以后其他的device probe了,也就是说这个driver只能和一个device绑定

6. int platform_device_register(struct platform_device *)
   void platform_device_unregister(struct platform_device *) /注册和注销一个platform设备

13. platform_add_devices(struct platform_device **devs, int num) //批量注册platform_device  num为注册的个数。注册的源放在devs中

7. to_platform_device(x)   container_of((x), struct platform_device, dev) //由设备结构体得到成platform设备结构体

8. platform_set_drvdata(_dev,data) //_dev为platform的dev,data为要设置的数据,多为一个结构体。 把这个data数据放到platorm_device->device->p->driver_data中

9. platform_get_drvdata(_dev)//和platform_set_drvdata功能相反,从platorm_device->device->p->driver_data中取数据.

10. platform_get_irq(struct platform_device *dev, unsigned int num) //从paltform_device中获取.resource字段中由flags为IORESOURCE_IRQ资源。 它的实现由  latform_get_resource(dev, IORESOURCE_IRQ, num) 完成。

11. resource *platform_get_resource (struct platform_device *dev,unsigned int type, unsigned int num) //获取platform_device中由type标志resource字段的数据。num为resource中的个数。

12. platform_get_device_id(pdev)  ((pdev)->id_entry)   //返回platform_device中id_entry字段的platform_device_id结构体













  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值