v4l2框架v4l2-device API分析

来源:互联网 发布:mac共享wifi 编辑:程序博客网 时间:2024/06/08 09:56

涉及到的结构体:

struct v4l2_device在v4l2框架中充当所有v4l2_subdev的父设备,管理着注册在其下的子设备

struct v4l2_device {/* dev->driver_data points to this struct.   Note: dev might be NULL if there is no parent device   as is the case with e.g. ISA devices. */struct device *dev;#if defined(CONFIG_MEDIA_CONTROLLER)struct media_device *mdev;#endif/* used to keep track of the registered subdevs */struct list_head subdevs;/* lock this struct; can be used by the driver as well if this   struct is embedded into a larger struct. */spinlock_t lock;/* unique device name, by default the driver name + bus ID */char name[V4L2_DEVICE_NAME_SIZE];/* notify callback called by some sub-devices. */void (*notify)(struct v4l2_subdev *sd,unsigned int notification, void *arg);/* The control handler. May be NULL. */struct v4l2_ctrl_handler *ctrl_handler;/* Device's priority state */struct v4l2_prio_state prio;/* BKL replacement mutex. Temporary solution only. */struct mutex ioctl_lock;/* Keep track of the references to this struct. */struct kref ref;/* Release function that is called when the ref count goes to 0. */void (*release)(struct v4l2_device *v4l2_dev);};

struct device 代表子设备,包含了子设备的相关属性和操作

struct device {struct device*parent;struct device_private*p;struct kobject kobj;const char*init_name; /* initial name of the device */const struct device_type *type;struct mutexmutex;/* 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, device   core doesn't touch it */struct dev_pm_infopower;struct dev_pm_domain*pm_domain;#ifdef CONFIG_NUMAintnuma_node;/* NUMA node this device is close to */#endifu64*dma_mask;/* dma mask (if dma'able device) */u64coherent_dma_mask;/* Like dma_mask, but for     alloc_coherent mappings as     not all hardware supports     64 bit addresses for consistent     allocations such descriptors. */struct device_dma_parameters *dma_parms;struct list_headdma_pools;/* dma pools (if dma'ble) */struct dma_coherent_mem*dma_mem; /* internal for coherent mem     override *//* arch specific additions */struct dev_archdataarchdata;struct device_node*of_node; /* associated device tree node */dev_tdevt;/* dev_t, creates the sysfs "dev" */u32id;/* device instance */spinlock_tdevres_lock;struct list_headdevres_head;struct klist_nodeknode_class;struct class*class;const struct attribute_group **groups;/* optional groups */void(*release)(struct device *dev);};
struct subdev:

struct v4l2_subdev {#if defined(CONFIG_MEDIA_CONTROLLER)struct media_entity entity;#endifstruct list_head list;struct module *owner;u32 flags;struct v4l2_device *v4l2_dev;const struct v4l2_subdev_ops *ops;/* Never call these internal ops from within a driver! */const struct v4l2_subdev_internal_ops *internal_ops;/* The control handler of this subdev. May be NULL. */struct v4l2_ctrl_handler *ctrl_handler;/* name must be unique */char name[V4L2_SUBDEV_NAME_SIZE];/* can be used to group similar subdevs, value is driver-specific */u32 grp_id;/* pointer to private data */void *dev_priv;void *host_priv;/* subdev device node */struct video_device *devnode;};



涉及到的api:

void v4l2_device_get(struct v4l2_device *v4l2_dev)

v4l2_dev的引用计数kref加一


int v4l2_device_put(struct v4l2_device *v4l2_dev)         

v4l2_dev的引用计数kref


int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)

对v4l2_dev中的链表、自旋锁、互斥体、优先状态等进行初始化,并把v4l2_dev->dev指向dev


int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,atomic_t *instance)

设置v4l2_dev->name


void v4l2_device_disconnect(struct v4l2_device *v4l2_dev)

把v4l2_dev从指向的dev上互相断开(指向NULL)


void v4l2_device_unregister(struct v4l2_device *v4l2_dev)

把v4l2_dev从指向的dev上互相断开,并把挂接在v4l2_dev链表上的v4l2_subdev设备一一卸载


int __must_check v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,struct v4l2_subdev *sd)

把v4l2_dev->v4l2_device指向v4l2_dev,并调用v4l2_dev->internal_ops(不会在driver中调用的ops)->registered注册v4l2_dev


void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)

把sd从挂接的v4l2_device链表上删除,并执行sd->unregistered,卸载


int __must_check v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)

为v4l2_dev链表上每个具有V4L2_SUBDEV_FL_HAS_DEVNODE标志的subdevs创建video_device节点