Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] doc-rst: document v4l2-dev.h

Add documentation for v4l2-dev.h, and put it at v4l2-framework.rst,
where struct video_device is currently documented.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>

+320 -83
+5
Documentation/media/kapi/v4l2-framework.rst
··· 699 699 700 700 It is expected that once the CCF becomes available on all relevant 701 701 architectures this API will be removed. 702 + 703 + video_device kAPI 704 + ^^^^^^^^^^^^^^^^^ 705 + 706 + .. kernel-doc:: include/media/v4l2-dev.h
-34
drivers/media/v4l2-core/v4l2-dev.c
··· 812 812 return 0; 813 813 } 814 814 815 - /** 816 - * __video_register_device - register video4linux devices 817 - * @vdev: video device structure we want to register 818 - * @type: type of device to register 819 - * @nr: which device node number (0 == /dev/video0, 1 == /dev/video1, ... 820 - * -1 == first free) 821 - * @warn_if_nr_in_use: warn if the desired device node number 822 - * was already in use and another number was chosen instead. 823 - * @owner: module that owns the video device node 824 - * 825 - * The registration code assigns minor numbers and device node numbers 826 - * based on the requested type and registers the new device node with 827 - * the kernel. 828 - * 829 - * This function assumes that struct video_device was zeroed when it 830 - * was allocated and does not contain any stale date. 831 - * 832 - * An error is returned if no free minor or device node number could be 833 - * found, or if the registration of the device node failed. 834 - * 835 - * Zero is returned on success. 836 - * 837 - * Valid types are 838 - * 839 - * %VFL_TYPE_GRABBER - A frame grabber 840 - * 841 - * %VFL_TYPE_VBI - Vertical blank data (undecoded) 842 - * 843 - * %VFL_TYPE_RADIO - A radio card 844 - * 845 - * %VFL_TYPE_SUBDEV - A subdevice 846 - * 847 - * %VFL_TYPE_SDR - Software Defined Radio 848 - */ 849 815 int __video_register_device(struct video_device *vdev, int type, int nr, 850 816 int warn_if_nr_in_use, struct module *owner) 851 817 {
+315 -49
include/media/v4l2-dev.h
··· 47 47 48 48 /* Priority helper functions */ 49 49 50 + /** 51 + * struct v4l2_prio_state - stores the priority states 52 + * 53 + * @prios: array with elements to store the array priorities 54 + * 55 + * 56 + * .. note:: 57 + * The size of @prios array matches the number of priority types defined 58 + * by :ref:`enum v4l2_priority <v4l2-priority>`. 59 + */ 50 60 struct v4l2_prio_state { 51 61 atomic_t prios[4]; 52 62 }; 53 63 64 + /** 65 + * v4l2_prio_init - initializes a struct v4l2_prio_state 66 + * 67 + * @global: pointer to &struct v4l2_prio_state 68 + */ 54 69 void v4l2_prio_init(struct v4l2_prio_state *global); 70 + 71 + /** 72 + * v4l2_prio_change - changes the v4l2 file handler priority 73 + * 74 + * @global: pointer to the &struct v4l2_prio_state of the device node. 75 + * @local: pointer to the desired priority, as defined by :ref:`enum v4l2_priority <v4l2-priority>` 76 + * @new: Priority type requested, as defined by :ref:`enum v4l2_priority <v4l2-priority>`. 77 + * 78 + * .. note:: 79 + * This function should be used only by the V4L2 core. 80 + */ 55 81 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local, 56 82 enum v4l2_priority new); 83 + 84 + /** 85 + * v4l2_prio_open - Implements the priority logic for a file handler open 86 + * 87 + * @global: pointer to the &struct v4l2_prio_state of the device node. 88 + * @local: pointer to the desired priority, as defined by :ref:`enum v4l2_priority <v4l2-priority>` 89 + * 90 + * .. note:: 91 + * This function should be used only by the V4L2 core. 92 + */ 57 93 void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local); 94 + 95 + /** 96 + * v4l2_prio_close - Implements the priority logic for a file handler close 97 + * 98 + * @global: pointer to the &struct v4l2_prio_state of the device node. 99 + * @local: priority to be released, as defined by :ref:`enum v4l2_priority <v4l2-priority>` 100 + * 101 + * .. note:: 102 + * This function should be used only by the V4L2 core. 103 + */ 58 104 void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local); 105 + 106 + /** 107 + * v4l2_prio_max - Return the maximum priority, as stored at the @global array. 108 + * 109 + * @global: pointer to the &struct v4l2_prio_state of the device node. 110 + * 111 + * .. note:: 112 + * This function should be used only by the V4L2 core. 113 + */ 59 114 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global); 115 + 116 + /** 117 + * v4l2_prio_close - Implements the priority logic for a file handler close 118 + * 119 + * @global: pointer to the &struct v4l2_prio_state of the device node. 120 + * @local: desired priority, as defined by :ref:`enum v4l2_priority <v4l2-priority>` local 121 + * 122 + * .. note:: 123 + * This function should be used only by the V4L2 core. 124 + */ 60 125 int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local); 61 126 62 - 127 + /** 128 + * struct v4l2_file_operations - fs operations used by a V4L2 device 129 + * 130 + * @owner: pointer to struct module 131 + * @read: operations needed to implement the read() syscall 132 + * @write: operations needed to implement the write() syscall 133 + * @poll: operations needed to implement the poll() syscall 134 + * @unlocked_ioctl: operations needed to implement the ioctl() syscall 135 + * @compat_ioctl32: operations needed to implement the ioctl() syscall for 136 + * the special case where the Kernel uses 64 bits instructions, but 137 + * the userspace uses 32 bits. 138 + * @get_unmapped_area: called by the mmap() syscall, used when %!CONFIG_MMU 139 + * @mmap: operations needed to implement the mmap() syscall 140 + * @open: operations needed to implement the open() syscall 141 + * @release: operations needed to implement the release() syscall 142 + * 143 + * .. note:: 144 + * 145 + * Those operations are used to implemente the fs struct file_operations 146 + * at the V4L2 drivers. The V4L2 core overrides the fs ops with some 147 + * extra logic needed by the subsystem. 148 + */ 63 149 struct v4l2_file_operations { 64 150 struct module *owner; 65 151 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); ··· 168 82 * the common handler 169 83 */ 170 84 85 + /** 86 + * struct video_device - Structure used to create and manage the V4L2 device 87 + * nodes. 88 + * 89 + * @entity: &struct media_entity 90 + * @intf_devnode: pointer to &struct media_intf_devnode 91 + * @pipe: &struct media_pipeline 92 + * @fops: pointer to &struct v4l2_file_operations for the video device 93 + * @device_caps: device capabilities as used in v4l2_capabilities 94 + * @dev: &struct device for the video device 95 + * @cdev: character device 96 + * @v4l2_dev: pointer to &struct v4l2_device parent 97 + * @dev_parent: pointer to &struct device parent 98 + * @ctrl_handler: Control handler associated with this device node. 99 + * May be NULL. 100 + * @queue: &struct vb2_queue associated with this device node. May be NULL. 101 + * @prio: pointer to &struct v4l2_prio_state with device's Priority state. 102 + * If NULL, then v4l2_dev->prio will be used. 103 + * @name: video device name 104 + * @vfl_type: V4L device type 105 + * @vfl_dir: V4L receiver, transmitter or m2m 106 + * @minor: device node 'minor'. It is set to -1 if the registration failed 107 + * @num: number of the video device node 108 + * @flags: video device flags. Use bitops to set/clear/test flags 109 + * @index: attribute to differentiate multiple indices on one physical device 110 + * @fh_lock: Lock for all v4l2_fhs 111 + * @fh_list: List of &struct v4l2_fh 112 + * @dev_debug: Internal device debug flags, not for use by drivers 113 + * @tvnorms: Supported tv norms 114 + * 115 + * @release: video device release() callback 116 + * @ioctl_ops: pointer to &struct v4l2_ioctl_ops with ioctl callbacks 117 + * 118 + * @valid_ioctls: bitmap with the valid ioctls for this device 119 + * @disable_locking: bitmap with the ioctls that don't require locking 120 + * @lock: pointer to &struct mutex serialization lock 121 + * 122 + * .. note:: 123 + * Only set @dev_parent if that can't be deduced from @v4l2_dev. 124 + */ 125 + 171 126 struct video_device 172 127 { 173 128 #if defined(CONFIG_MEDIA_CONTROLLER) ··· 216 89 struct media_intf_devnode *intf_devnode; 217 90 struct media_pipeline pipe; 218 91 #endif 219 - /* device ops */ 220 92 const struct v4l2_file_operations *fops; 221 93 222 - /* device capabilities as used in v4l2_capabilities */ 223 94 u32 device_caps; 224 95 225 96 /* sysfs */ 226 - struct device dev; /* v4l device */ 227 - struct cdev *cdev; /* character device */ 97 + struct device dev; 98 + struct cdev *cdev; 228 99 229 - struct v4l2_device *v4l2_dev; /* v4l2_device parent */ 230 - /* Only set parent if that can't be deduced from v4l2_dev */ 231 - struct device *dev_parent; /* device parent */ 100 + struct v4l2_device *v4l2_dev; 101 + struct device *dev_parent; 232 102 233 - /* Control handler associated with this device node. May be NULL. */ 234 103 struct v4l2_ctrl_handler *ctrl_handler; 235 104 236 - /* vb2_queue associated with this device node. May be NULL. */ 237 105 struct vb2_queue *queue; 238 106 239 - /* Priority state. If NULL, then v4l2_dev->prio will be used. */ 240 107 struct v4l2_prio_state *prio; 241 108 242 109 /* device info */ 243 110 char name[32]; 244 - int vfl_type; /* device type */ 245 - int vfl_dir; /* receiver, transmitter or m2m */ 246 - /* 'minor' is set to -1 if the registration failed */ 111 + int vfl_type; 112 + int vfl_dir; 247 113 int minor; 248 114 u16 num; 249 - /* use bitops to set/clear/test flags */ 250 115 unsigned long flags; 251 - /* attribute to differentiate multiple indices on one physical device */ 252 116 int index; 253 117 254 118 /* V4L2 file handles */ 255 - spinlock_t fh_lock; /* Lock for all v4l2_fhs */ 256 - struct list_head fh_list; /* List of struct v4l2_fh */ 119 + spinlock_t fh_lock; 120 + struct list_head fh_list; 257 121 258 - /* Internal device debug flags, not for use by drivers */ 259 122 int dev_debug; 260 123 261 - /* Video standard vars */ 262 - v4l2_std_id tvnorms; /* Supported tv norms */ 124 + v4l2_std_id tvnorms; 263 125 264 126 /* callbacks */ 265 127 void (*release)(struct video_device *vdev); 266 - 267 - /* ioctl callbacks */ 268 128 const struct v4l2_ioctl_ops *ioctl_ops; 269 129 DECLARE_BITMAP(valid_ioctls, BASE_VIDIOC_PRIVATE); 270 130 271 - /* serialization lock */ 272 131 DECLARE_BITMAP(disable_locking, BASE_VIDIOC_PRIVATE); 273 132 struct mutex *lock; 274 133 }; ··· 264 151 /* dev to video-device */ 265 152 #define to_video_device(cd) container_of(cd, struct video_device, dev) 266 153 154 + /** 155 + * __video_register_device - register video4linux devices 156 + * 157 + * @vdev: struct video_device to register 158 + * @type: type of device to register 159 + * @nr: which device node number is desired: 160 + * (0 == /dev/video0, 1 == /dev/video1, ..., -1 == first free) 161 + * @warn_if_nr_in_use: warn if the desired device node number 162 + * was already in use and another number was chosen instead. 163 + * @owner: module that owns the video device node 164 + * 165 + * The registration code assigns minor numbers and device node numbers 166 + * based on the requested type and registers the new device node with 167 + * the kernel. 168 + * 169 + * This function assumes that struct video_device was zeroed when it 170 + * was allocated and does not contain any stale date. 171 + * 172 + * An error is returned if no free minor or device node number could be 173 + * found, or if the registration of the device node failed. 174 + * 175 + * Returns 0 on success. 176 + * 177 + * Valid values for @type are: 178 + * 179 + * - %VFL_TYPE_GRABBER - A frame grabber 180 + * - %VFL_TYPE_VBI - Vertical blank data (undecoded) 181 + * - %VFL_TYPE_RADIO - A radio card 182 + * - %VFL_TYPE_SUBDEV - A subdevice 183 + * - %VFL_TYPE_SDR - Software Defined Radio 184 + * 185 + * .. note:: 186 + * 187 + * This function is meant to be used only inside the V4L2 core. 188 + * Drivers should use video_register_device() or 189 + * video_register_device_no_warn(). 190 + */ 267 191 int __must_check __video_register_device(struct video_device *vdev, int type, 268 192 int nr, int warn_if_nr_in_use, struct module *owner); 269 193 270 - /* Register video devices. Note that if video_register_device fails, 271 - the release() callback of the video_device structure is *not* called, so 272 - the caller is responsible for freeing any data. Usually that means that 273 - you call video_device_release() on failure. */ 194 + /** 195 + * video_register_device - register video4linux devices 196 + * 197 + * @vdev: struct video_device to register 198 + * @type: type of device to register 199 + * @nr: which device node number is desired: 200 + * (0 == /dev/video0, 1 == /dev/video1, ..., -1 == first free) 201 + * 202 + * Internally, it calls __video_register_device(). Please see its 203 + * documentation for more details. 204 + * 205 + * .. note:: 206 + * if video_register_device fails, the release() callback of 207 + * &struct video_device structure is *not* called, so the caller 208 + * is responsible for freeing any data. Usually that means that 209 + * you video_device_release() should be called on failure. 210 + */ 274 211 static inline int __must_check video_register_device(struct video_device *vdev, 275 212 int type, int nr) 276 213 { 277 214 return __video_register_device(vdev, type, nr, 1, vdev->fops->owner); 278 215 } 279 216 280 - /* Same as video_register_device, but no warning is issued if the desired 281 - device node number was already in use. */ 217 + /** 218 + * video_register_device_no_warn - register video4linux devices 219 + * 220 + * @vdev: struct video_device to register 221 + * @type: type of device to register 222 + * @nr: which device node number is desired: 223 + * (0 == /dev/video0, 1 == /dev/video1, ..., -1 == first free) 224 + * 225 + * This function is identical to video_register_device() except that no 226 + * warning is issued if the desired device node number was already in use. 227 + * 228 + * Internally, it calls __video_register_device(). Please see its 229 + * documentation for more details. 230 + * 231 + * .. note:: 232 + * if video_register_device fails, the release() callback of 233 + * &struct video_device structure is *not* called, so the caller 234 + * is responsible for freeing any data. Usually that means that 235 + * you video_device_release() should be called on failure. 236 + */ 282 237 static inline int __must_check video_register_device_no_warn( 283 238 struct video_device *vdev, int type, int nr) 284 239 { 285 240 return __video_register_device(vdev, type, nr, 0, vdev->fops->owner); 286 241 } 287 242 288 - /* Unregister video devices. Will do nothing if vdev == NULL or 289 - video_is_registered() returns false. */ 243 + /** 244 + * video_unregister_device - Unregister video devices. 245 + * 246 + * @vdev: &struct video_device to register 247 + * 248 + * Does nothing if vdev == NULL or if video_is_registered() returns false. 249 + */ 290 250 void video_unregister_device(struct video_device *vdev); 291 251 292 - /* helper functions to alloc/release struct video_device, the 293 - latter can also be used for video_device->release(). */ 252 + /** 253 + * video_device_alloc - helper function to alloc &struct video_device 254 + * 255 + * Returns NULL if %-ENOMEM or a &struct video_device on success. 256 + */ 294 257 struct video_device * __must_check video_device_alloc(void); 295 258 296 - /* this release function frees the vdev pointer */ 259 + /** 260 + * video_device_release - helper function to release &struct video_device 261 + * 262 + * @vdev: pointer to &struct video_device 263 + * 264 + * Can also be used for video_device->release(). 265 + */ 297 266 void video_device_release(struct video_device *vdev); 298 267 299 - /* this release function does nothing, use when the video_device is a 300 - static global struct. Note that having a static video_device is 301 - a dubious construction at best. */ 268 + /** 269 + * video_device_release_empty - helper function to implement the 270 + * video_device->release() callback. 271 + * 272 + * @vdev: pointer to &struct video_device 273 + * 274 + * This release function does nothing. 275 + * 276 + * It should be used when the video_device is a static global struct. 277 + * 278 + * .. note:: 279 + * Having a static video_device is a dubious construction at best. 280 + */ 302 281 void video_device_release_empty(struct video_device *vdev); 303 282 304 - /* returns true if cmd is a known V4L2 ioctl */ 283 + /** 284 + * v4l2_is_known_ioctl - Checks if a given cmd is a known V4L ioctl 285 + * 286 + * @cmd: ioctl command 287 + * 288 + * returns true if cmd is a known V4L2 ioctl 289 + */ 305 290 bool v4l2_is_known_ioctl(unsigned int cmd); 306 291 307 - /* mark that this command shouldn't use core locking */ 308 - static inline void v4l2_disable_ioctl_locking(struct video_device *vdev, unsigned int cmd) 292 + /** v4l2_disable_ioctl_locking - mark that a given command 293 + * shouldn't use core locking 294 + * 295 + * @vdev: pointer to &struct video_device 296 + * @cmd: ioctl command 297 + */ 298 + static inline void v4l2_disable_ioctl_locking(struct video_device *vdev, 299 + unsigned int cmd) 309 300 { 310 301 if (_IOC_NR(cmd) < BASE_VIDIOC_PRIVATE) 311 302 set_bit(_IOC_NR(cmd), vdev->disable_locking); 312 303 } 313 304 314 - /* Mark that this command isn't implemented. This must be called before 315 - video_device_register. See also the comments in determine_valid_ioctls(). 316 - This function allows drivers to provide just one v4l2_ioctl_ops struct, but 317 - disable ioctls based on the specific card that is actually found. */ 318 - static inline void v4l2_disable_ioctl(struct video_device *vdev, unsigned int cmd) 305 + /** 306 + * v4l2_disable_ioctl- mark that a given command isn't implemented. 307 + * shouldn't use core locking 308 + * 309 + * @vdev: pointer to &struct video_device 310 + * @cmd: ioctl command 311 + * 312 + * This function allows drivers to provide just one v4l2_ioctl_ops struct, but 313 + * disable ioctls based on the specific card that is actually found. 314 + * 315 + * .. note:: 316 + * 317 + * This must be called before video_register_device. 318 + * See also the comments for determine_valid_ioctls(). 319 + */ 320 + static inline void v4l2_disable_ioctl(struct video_device *vdev, 321 + unsigned int cmd) 319 322 { 320 323 if (_IOC_NR(cmd) < BASE_VIDIOC_PRIVATE) 321 324 set_bit(_IOC_NR(cmd), vdev->valid_ioctls); 322 325 } 323 326 324 - /* helper functions to access driver private data. */ 327 + /** 328 + * video_get_drvdata - gets private data from &struct video_device. 329 + * 330 + * @vdev: pointer to &struct video_device 331 + * 332 + * returns a pointer to the private data 333 + */ 325 334 static inline void *video_get_drvdata(struct video_device *vdev) 326 335 { 327 336 return dev_get_drvdata(&vdev->dev); 328 337 } 329 338 339 + /** 340 + * video_set_drvdata - sets private data from &struct video_device. 341 + * 342 + * @vdev: pointer to &struct video_device 343 + * @data: private data pointer 344 + */ 330 345 static inline void video_set_drvdata(struct video_device *vdev, void *data) 331 346 { 332 347 dev_set_drvdata(&vdev->dev, data); 333 348 } 334 349 350 + /** 351 + * video_devdata - gets &struct video_device from struct file. 352 + * 353 + * @file: pointer to struct file 354 + */ 335 355 struct video_device *video_devdata(struct file *file); 336 356 337 - /* Combine video_get_drvdata and video_devdata as this is 338 - used very often. */ 357 + /** 358 + * video_drvdata - gets private data from &struct video_device using the 359 + * struct file. 360 + * 361 + * @file: pointer to struct file 362 + * 363 + * This is function combines both video_get_drvdata() and video_devdata() 364 + * as this is used very often. 365 + */ 339 366 static inline void *video_drvdata(struct file *file) 340 367 { 341 368 return video_get_drvdata(video_devdata(file)); 342 369 } 343 370 371 + /** 372 + * video_device_node_name - returns the video device name 373 + * 374 + * @vdev: pointer to &struct video_device 375 + * 376 + * Returns the device name string 377 + */ 344 378 static inline const char *video_device_node_name(struct video_device *vdev) 345 379 { 346 380 return dev_name(&vdev->dev); 347 381 } 348 382 383 + /** 384 + * video_is_registered - returns true if the &struct video_device is registered. 385 + * 386 + * 387 + * @vdev: pointer to &struct video_device 388 + */ 349 389 static inline int video_is_registered(struct video_device *vdev) 350 390 { 351 391 return test_bit(V4L2_FL_REGISTERED, &vdev->flags);