···699699700700It is expected that once the CCF becomes available on all relevant701701architectures this API will be removed.702702+703703+video_device kAPI704704+^^^^^^^^^^^^^^^^^705705+706706+.. kernel-doc:: include/media/v4l2-dev.h
-34
drivers/media/v4l2-core/v4l2-dev.c
···812812 return 0;813813}814814815815-/**816816- * __video_register_device - register video4linux devices817817- * @vdev: video device structure we want to register818818- * @type: type of device to register819819- * @nr: which device node number (0 == /dev/video0, 1 == /dev/video1, ...820820- * -1 == first free)821821- * @warn_if_nr_in_use: warn if the desired device node number822822- * was already in use and another number was chosen instead.823823- * @owner: module that owns the video device node824824- *825825- * The registration code assigns minor numbers and device node numbers826826- * based on the requested type and registers the new device node with827827- * the kernel.828828- *829829- * This function assumes that struct video_device was zeroed when it830830- * was allocated and does not contain any stale date.831831- *832832- * An error is returned if no free minor or device node number could be833833- * found, or if the registration of the device node failed.834834- *835835- * Zero is returned on success.836836- *837837- * Valid types are838838- *839839- * %VFL_TYPE_GRABBER - A frame grabber840840- *841841- * %VFL_TYPE_VBI - Vertical blank data (undecoded)842842- *843843- * %VFL_TYPE_RADIO - A radio card844844- *845845- * %VFL_TYPE_SUBDEV - A subdevice846846- *847847- * %VFL_TYPE_SDR - Software Defined Radio848848- */849815int __video_register_device(struct video_device *vdev, int type, int nr,850816 int warn_if_nr_in_use, struct module *owner)851817{
+315-49
include/media/v4l2-dev.h
···47474848/* Priority helper functions */49495050+/**5151+ * struct v4l2_prio_state - stores the priority states5252+ *5353+ * @prios: array with elements to store the array priorities5454+ *5555+ *5656+ * .. note::5757+ * The size of @prios array matches the number of priority types defined5858+ * by :ref:`enum v4l2_priority <v4l2-priority>`.5959+ */5060struct v4l2_prio_state {5161 atomic_t prios[4];5262};53636464+/**6565+ * v4l2_prio_init - initializes a struct v4l2_prio_state6666+ *6767+ * @global: pointer to &struct v4l2_prio_state6868+ */5469void v4l2_prio_init(struct v4l2_prio_state *global);7070+7171+/**7272+ * v4l2_prio_change - changes the v4l2 file handler priority7373+ *7474+ * @global: pointer to the &struct v4l2_prio_state of the device node.7575+ * @local: pointer to the desired priority, as defined by :ref:`enum v4l2_priority <v4l2-priority>`7676+ * @new: Priority type requested, as defined by :ref:`enum v4l2_priority <v4l2-priority>`.7777+ *7878+ * .. note::7979+ * This function should be used only by the V4L2 core.8080+ */5581int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,5682 enum v4l2_priority new);8383+8484+/**8585+ * v4l2_prio_open - Implements the priority logic for a file handler open8686+ *8787+ * @global: pointer to the &struct v4l2_prio_state of the device node.8888+ * @local: pointer to the desired priority, as defined by :ref:`enum v4l2_priority <v4l2-priority>`8989+ *9090+ * .. note::9191+ * This function should be used only by the V4L2 core.9292+ */5793void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);9494+9595+/**9696+ * v4l2_prio_close - Implements the priority logic for a file handler close9797+ *9898+ * @global: pointer to the &struct v4l2_prio_state of the device node.9999+ * @local: priority to be released, as defined by :ref:`enum v4l2_priority <v4l2-priority>`100100+ *101101+ * .. note::102102+ * This function should be used only by the V4L2 core.103103+ */58104void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local);105105+106106+/**107107+ * v4l2_prio_max - Return the maximum priority, as stored at the @global array.108108+ *109109+ * @global: pointer to the &struct v4l2_prio_state of the device node.110110+ *111111+ * .. note::112112+ * This function should be used only by the V4L2 core.113113+ */59114enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);115115+116116+/**117117+ * v4l2_prio_close - Implements the priority logic for a file handler close118118+ *119119+ * @global: pointer to the &struct v4l2_prio_state of the device node.120120+ * @local: desired priority, as defined by :ref:`enum v4l2_priority <v4l2-priority>` local121121+ *122122+ * .. note::123123+ * This function should be used only by the V4L2 core.124124+ */60125int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);611266262-127127+/**128128+ * struct v4l2_file_operations - fs operations used by a V4L2 device129129+ *130130+ * @owner: pointer to struct module131131+ * @read: operations needed to implement the read() syscall132132+ * @write: operations needed to implement the write() syscall133133+ * @poll: operations needed to implement the poll() syscall134134+ * @unlocked_ioctl: operations needed to implement the ioctl() syscall135135+ * @compat_ioctl32: operations needed to implement the ioctl() syscall for136136+ * the special case where the Kernel uses 64 bits instructions, but137137+ * the userspace uses 32 bits.138138+ * @get_unmapped_area: called by the mmap() syscall, used when %!CONFIG_MMU139139+ * @mmap: operations needed to implement the mmap() syscall140140+ * @open: operations needed to implement the open() syscall141141+ * @release: operations needed to implement the release() syscall142142+ *143143+ * .. note::144144+ *145145+ * Those operations are used to implemente the fs struct file_operations146146+ * at the V4L2 drivers. The V4L2 core overrides the fs ops with some147147+ * extra logic needed by the subsystem.148148+ */63149struct v4l2_file_operations {64150 struct module *owner;65151 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);···16882 * the common handler16983 */170848585+/**8686+ * struct video_device - Structure used to create and manage the V4L2 device8787+ * nodes.8888+ *8989+ * @entity: &struct media_entity9090+ * @intf_devnode: pointer to &struct media_intf_devnode9191+ * @pipe: &struct media_pipeline9292+ * @fops: pointer to &struct v4l2_file_operations for the video device9393+ * @device_caps: device capabilities as used in v4l2_capabilities9494+ * @dev: &struct device for the video device9595+ * @cdev: character device9696+ * @v4l2_dev: pointer to &struct v4l2_device parent9797+ * @dev_parent: pointer to &struct device parent9898+ * @ctrl_handler: Control handler associated with this device node.9999+ * May be NULL.100100+ * @queue: &struct vb2_queue associated with this device node. May be NULL.101101+ * @prio: pointer to &struct v4l2_prio_state with device's Priority state.102102+ * If NULL, then v4l2_dev->prio will be used.103103+ * @name: video device name104104+ * @vfl_type: V4L device type105105+ * @vfl_dir: V4L receiver, transmitter or m2m106106+ * @minor: device node 'minor'. It is set to -1 if the registration failed107107+ * @num: number of the video device node108108+ * @flags: video device flags. Use bitops to set/clear/test flags109109+ * @index: attribute to differentiate multiple indices on one physical device110110+ * @fh_lock: Lock for all v4l2_fhs111111+ * @fh_list: List of &struct v4l2_fh112112+ * @dev_debug: Internal device debug flags, not for use by drivers113113+ * @tvnorms: Supported tv norms114114+ *115115+ * @release: video device release() callback116116+ * @ioctl_ops: pointer to &struct v4l2_ioctl_ops with ioctl callbacks117117+ *118118+ * @valid_ioctls: bitmap with the valid ioctls for this device119119+ * @disable_locking: bitmap with the ioctls that don't require locking120120+ * @lock: pointer to &struct mutex serialization lock121121+ *122122+ * .. note::123123+ * Only set @dev_parent if that can't be deduced from @v4l2_dev.124124+ */125125+171126struct video_device172127{173128#if defined(CONFIG_MEDIA_CONTROLLER)···21689 struct media_intf_devnode *intf_devnode;21790 struct media_pipeline pipe;21891#endif219219- /* device ops */22092 const struct v4l2_file_operations *fops;22193222222- /* device capabilities as used in v4l2_capabilities */22394 u32 device_caps;2249522596 /* sysfs */226226- struct device dev; /* v4l device */227227- struct cdev *cdev; /* character device */9797+ struct device dev;9898+ struct cdev *cdev;22899229229- struct v4l2_device *v4l2_dev; /* v4l2_device parent */230230- /* Only set parent if that can't be deduced from v4l2_dev */231231- struct device *dev_parent; /* device parent */100100+ struct v4l2_device *v4l2_dev;101101+ struct device *dev_parent;232102233233- /* Control handler associated with this device node. May be NULL. */234103 struct v4l2_ctrl_handler *ctrl_handler;235104236236- /* vb2_queue associated with this device node. May be NULL. */237105 struct vb2_queue *queue;238106239239- /* Priority state. If NULL, then v4l2_dev->prio will be used. */240107 struct v4l2_prio_state *prio;241108242109 /* device info */243110 char name[32];244244- int vfl_type; /* device type */245245- int vfl_dir; /* receiver, transmitter or m2m */246246- /* 'minor' is set to -1 if the registration failed */111111+ int vfl_type;112112+ int vfl_dir;247113 int minor;248114 u16 num;249249- /* use bitops to set/clear/test flags */250115 unsigned long flags;251251- /* attribute to differentiate multiple indices on one physical device */252116 int index;253117254118 /* V4L2 file handles */255255- spinlock_t fh_lock; /* Lock for all v4l2_fhs */256256- struct list_head fh_list; /* List of struct v4l2_fh */119119+ spinlock_t fh_lock;120120+ struct list_head fh_list;257121258258- /* Internal device debug flags, not for use by drivers */259122 int dev_debug;260123261261- /* Video standard vars */262262- v4l2_std_id tvnorms; /* Supported tv norms */124124+ v4l2_std_id tvnorms;263125264126 /* callbacks */265127 void (*release)(struct video_device *vdev);266266-267267- /* ioctl callbacks */268128 const struct v4l2_ioctl_ops *ioctl_ops;269129 DECLARE_BITMAP(valid_ioctls, BASE_VIDIOC_PRIVATE);270130271271- /* serialization lock */272131 DECLARE_BITMAP(disable_locking, BASE_VIDIOC_PRIVATE);273132 struct mutex *lock;274133};···264151/* dev to video-device */265152#define to_video_device(cd) container_of(cd, struct video_device, dev)266153154154+/**155155+ * __video_register_device - register video4linux devices156156+ *157157+ * @vdev: struct video_device to register158158+ * @type: type of device to register159159+ * @nr: which device node number is desired:160160+ * (0 == /dev/video0, 1 == /dev/video1, ..., -1 == first free)161161+ * @warn_if_nr_in_use: warn if the desired device node number162162+ * was already in use and another number was chosen instead.163163+ * @owner: module that owns the video device node164164+ *165165+ * The registration code assigns minor numbers and device node numbers166166+ * based on the requested type and registers the new device node with167167+ * the kernel.168168+ *169169+ * This function assumes that struct video_device was zeroed when it170170+ * was allocated and does not contain any stale date.171171+ *172172+ * An error is returned if no free minor or device node number could be173173+ * found, or if the registration of the device node failed.174174+ *175175+ * Returns 0 on success.176176+ *177177+ * Valid values for @type are:178178+ *179179+ * - %VFL_TYPE_GRABBER - A frame grabber180180+ * - %VFL_TYPE_VBI - Vertical blank data (undecoded)181181+ * - %VFL_TYPE_RADIO - A radio card182182+ * - %VFL_TYPE_SUBDEV - A subdevice183183+ * - %VFL_TYPE_SDR - Software Defined Radio184184+ *185185+ * .. note::186186+ *187187+ * This function is meant to be used only inside the V4L2 core.188188+ * Drivers should use video_register_device() or189189+ * video_register_device_no_warn().190190+ */267191int __must_check __video_register_device(struct video_device *vdev, int type,268192 int nr, int warn_if_nr_in_use, struct module *owner);269193270270-/* Register video devices. Note that if video_register_device fails,271271- the release() callback of the video_device structure is *not* called, so272272- the caller is responsible for freeing any data. Usually that means that273273- you call video_device_release() on failure. */194194+/**195195+ * video_register_device - register video4linux devices196196+ *197197+ * @vdev: struct video_device to register198198+ * @type: type of device to register199199+ * @nr: which device node number is desired:200200+ * (0 == /dev/video0, 1 == /dev/video1, ..., -1 == first free)201201+ *202202+ * Internally, it calls __video_register_device(). Please see its203203+ * documentation for more details.204204+ *205205+ * .. note::206206+ * if video_register_device fails, the release() callback of207207+ * &struct video_device structure is *not* called, so the caller208208+ * is responsible for freeing any data. Usually that means that209209+ * you video_device_release() should be called on failure.210210+ */274211static inline int __must_check video_register_device(struct video_device *vdev,275212 int type, int nr)276213{277214 return __video_register_device(vdev, type, nr, 1, vdev->fops->owner);278215}279216280280-/* Same as video_register_device, but no warning is issued if the desired281281- device node number was already in use. */217217+/**218218+ * video_register_device_no_warn - register video4linux devices219219+ *220220+ * @vdev: struct video_device to register221221+ * @type: type of device to register222222+ * @nr: which device node number is desired:223223+ * (0 == /dev/video0, 1 == /dev/video1, ..., -1 == first free)224224+ *225225+ * This function is identical to video_register_device() except that no226226+ * warning is issued if the desired device node number was already in use.227227+ *228228+ * Internally, it calls __video_register_device(). Please see its229229+ * documentation for more details.230230+ *231231+ * .. note::232232+ * if video_register_device fails, the release() callback of233233+ * &struct video_device structure is *not* called, so the caller234234+ * is responsible for freeing any data. Usually that means that235235+ * you video_device_release() should be called on failure.236236+ */282237static inline int __must_check video_register_device_no_warn(283238 struct video_device *vdev, int type, int nr)284239{285240 return __video_register_device(vdev, type, nr, 0, vdev->fops->owner);286241}287242288288-/* Unregister video devices. Will do nothing if vdev == NULL or289289- video_is_registered() returns false. */243243+/**244244+ * video_unregister_device - Unregister video devices.245245+ *246246+ * @vdev: &struct video_device to register247247+ *248248+ * Does nothing if vdev == NULL or if video_is_registered() returns false.249249+ */290250void video_unregister_device(struct video_device *vdev);291251292292-/* helper functions to alloc/release struct video_device, the293293- latter can also be used for video_device->release(). */252252+/**253253+ * video_device_alloc - helper function to alloc &struct video_device254254+ *255255+ * Returns NULL if %-ENOMEM or a &struct video_device on success.256256+ */294257struct video_device * __must_check video_device_alloc(void);295258296296-/* this release function frees the vdev pointer */259259+/**260260+ * video_device_release - helper function to release &struct video_device261261+ *262262+ * @vdev: pointer to &struct video_device263263+ *264264+ * Can also be used for video_device->release().265265+ */297266void video_device_release(struct video_device *vdev);298267299299-/* this release function does nothing, use when the video_device is a300300- static global struct. Note that having a static video_device is301301- a dubious construction at best. */268268+/**269269+ * video_device_release_empty - helper function to implement the270270+ * video_device->release() callback.271271+ *272272+ * @vdev: pointer to &struct video_device273273+ *274274+ * This release function does nothing.275275+ *276276+ * It should be used when the video_device is a static global struct.277277+ *278278+ * .. note::279279+ * Having a static video_device is a dubious construction at best.280280+ */302281void video_device_release_empty(struct video_device *vdev);303282304304-/* returns true if cmd is a known V4L2 ioctl */283283+/**284284+ * v4l2_is_known_ioctl - Checks if a given cmd is a known V4L ioctl285285+ *286286+ * @cmd: ioctl command287287+ *288288+ * returns true if cmd is a known V4L2 ioctl289289+ */305290bool v4l2_is_known_ioctl(unsigned int cmd);306291307307-/* mark that this command shouldn't use core locking */308308-static inline void v4l2_disable_ioctl_locking(struct video_device *vdev, unsigned int cmd)292292+/** v4l2_disable_ioctl_locking - mark that a given command293293+ * shouldn't use core locking294294+ *295295+ * @vdev: pointer to &struct video_device296296+ * @cmd: ioctl command297297+ */298298+static inline void v4l2_disable_ioctl_locking(struct video_device *vdev,299299+ unsigned int cmd)309300{310301 if (_IOC_NR(cmd) < BASE_VIDIOC_PRIVATE)311302 set_bit(_IOC_NR(cmd), vdev->disable_locking);312303}313304314314-/* Mark that this command isn't implemented. This must be called before315315- video_device_register. See also the comments in determine_valid_ioctls().316316- This function allows drivers to provide just one v4l2_ioctl_ops struct, but317317- disable ioctls based on the specific card that is actually found. */318318-static inline void v4l2_disable_ioctl(struct video_device *vdev, unsigned int cmd)305305+/**306306+ * v4l2_disable_ioctl- mark that a given command isn't implemented.307307+ * shouldn't use core locking308308+ *309309+ * @vdev: pointer to &struct video_device310310+ * @cmd: ioctl command311311+ *312312+ * This function allows drivers to provide just one v4l2_ioctl_ops struct, but313313+ * disable ioctls based on the specific card that is actually found.314314+ *315315+ * .. note::316316+ *317317+ * This must be called before video_register_device.318318+ * See also the comments for determine_valid_ioctls().319319+ */320320+static inline void v4l2_disable_ioctl(struct video_device *vdev,321321+ unsigned int cmd)319322{320323 if (_IOC_NR(cmd) < BASE_VIDIOC_PRIVATE)321324 set_bit(_IOC_NR(cmd), vdev->valid_ioctls);322325}323326324324-/* helper functions to access driver private data. */327327+/**328328+ * video_get_drvdata - gets private data from &struct video_device.329329+ *330330+ * @vdev: pointer to &struct video_device331331+ *332332+ * returns a pointer to the private data333333+ */325334static inline void *video_get_drvdata(struct video_device *vdev)326335{327336 return dev_get_drvdata(&vdev->dev);328337}329338339339+/**340340+ * video_set_drvdata - sets private data from &struct video_device.341341+ *342342+ * @vdev: pointer to &struct video_device343343+ * @data: private data pointer344344+ */330345static inline void video_set_drvdata(struct video_device *vdev, void *data)331346{332347 dev_set_drvdata(&vdev->dev, data);333348}334349350350+/**351351+ * video_devdata - gets &struct video_device from struct file.352352+ *353353+ * @file: pointer to struct file354354+ */335355struct video_device *video_devdata(struct file *file);336356337337-/* Combine video_get_drvdata and video_devdata as this is338338- used very often. */357357+/**358358+ * video_drvdata - gets private data from &struct video_device using the359359+ * struct file.360360+ *361361+ * @file: pointer to struct file362362+ *363363+ * This is function combines both video_get_drvdata() and video_devdata()364364+ * as this is used very often.365365+ */339366static inline void *video_drvdata(struct file *file)340367{341368 return video_get_drvdata(video_devdata(file));342369}343370371371+/**372372+ * video_device_node_name - returns the video device name373373+ *374374+ * @vdev: pointer to &struct video_device375375+ *376376+ * Returns the device name string377377+ */344378static inline const char *video_device_node_name(struct video_device *vdev)345379{346380 return dev_name(&vdev->dev);347381}348382383383+/**384384+ * video_is_registered - returns true if the &struct video_device is registered.385385+ *386386+ *387387+ * @vdev: pointer to &struct video_device388388+ */349389static inline int video_is_registered(struct video_device *vdev)350390{351391 return test_bit(V4L2_FL_REGISTERED, &vdev->flags);