18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * V 4 L 2 D R I V E R H E L P E R A P I 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Moved from videodev2.h 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Some commonly needed functions for drivers (v4l2-common.o module) 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci#ifndef _V4L2_DEV_H 118c2ecf20Sopenharmony_ci#define _V4L2_DEV_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/poll.h> 148c2ecf20Sopenharmony_ci#include <linux/fs.h> 158c2ecf20Sopenharmony_ci#include <linux/device.h> 168c2ecf20Sopenharmony_ci#include <linux/cdev.h> 178c2ecf20Sopenharmony_ci#include <linux/mutex.h> 188c2ecf20Sopenharmony_ci#include <linux/videodev2.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#include <media/media-entity.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define VIDEO_MAJOR 81 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/** 258c2ecf20Sopenharmony_ci * enum vfl_devnode_type - type of V4L2 device node 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * @VFL_TYPE_VIDEO: for video input/output devices 288c2ecf20Sopenharmony_ci * @VFL_TYPE_VBI: for vertical blank data (i.e. closed captions, teletext) 298c2ecf20Sopenharmony_ci * @VFL_TYPE_RADIO: for radio tuners 308c2ecf20Sopenharmony_ci * @VFL_TYPE_SUBDEV: for V4L2 subdevices 318c2ecf20Sopenharmony_ci * @VFL_TYPE_SDR: for Software Defined Radio tuners 328c2ecf20Sopenharmony_ci * @VFL_TYPE_TOUCH: for touch sensors 338c2ecf20Sopenharmony_ci * @VFL_TYPE_MAX: number of VFL types, must always be last in the enum 348c2ecf20Sopenharmony_ci */ 358c2ecf20Sopenharmony_cienum vfl_devnode_type { 368c2ecf20Sopenharmony_ci VFL_TYPE_VIDEO, 378c2ecf20Sopenharmony_ci VFL_TYPE_VBI, 388c2ecf20Sopenharmony_ci VFL_TYPE_RADIO, 398c2ecf20Sopenharmony_ci VFL_TYPE_SUBDEV, 408c2ecf20Sopenharmony_ci VFL_TYPE_SDR, 418c2ecf20Sopenharmony_ci VFL_TYPE_TOUCH, 428c2ecf20Sopenharmony_ci VFL_TYPE_MAX /* Shall be the last one */ 438c2ecf20Sopenharmony_ci}; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/** 468c2ecf20Sopenharmony_ci * enum vfl_direction - Identifies if a &struct video_device corresponds 478c2ecf20Sopenharmony_ci * to a receiver, a transmitter or a mem-to-mem device. 488c2ecf20Sopenharmony_ci * 498c2ecf20Sopenharmony_ci * @VFL_DIR_RX: device is a receiver. 508c2ecf20Sopenharmony_ci * @VFL_DIR_TX: device is a transmitter. 518c2ecf20Sopenharmony_ci * @VFL_DIR_M2M: device is a memory to memory device. 528c2ecf20Sopenharmony_ci * 538c2ecf20Sopenharmony_ci * Note: Ignored if &enum vfl_devnode_type is %VFL_TYPE_SUBDEV. 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_cienum vfl_devnode_direction { 568c2ecf20Sopenharmony_ci VFL_DIR_RX, 578c2ecf20Sopenharmony_ci VFL_DIR_TX, 588c2ecf20Sopenharmony_ci VFL_DIR_M2M, 598c2ecf20Sopenharmony_ci}; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistruct v4l2_ioctl_callbacks; 628c2ecf20Sopenharmony_cistruct video_device; 638c2ecf20Sopenharmony_cistruct v4l2_device; 648c2ecf20Sopenharmony_cistruct v4l2_ctrl_handler; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/** 678c2ecf20Sopenharmony_ci * enum v4l2_video_device_flags - Flags used by &struct video_device 688c2ecf20Sopenharmony_ci * 698c2ecf20Sopenharmony_ci * @V4L2_FL_REGISTERED: 708c2ecf20Sopenharmony_ci * indicates that a &struct video_device is registered. 718c2ecf20Sopenharmony_ci * Drivers can clear this flag if they want to block all future 728c2ecf20Sopenharmony_ci * device access. It is cleared by video_unregister_device. 738c2ecf20Sopenharmony_ci * @V4L2_FL_USES_V4L2_FH: 748c2ecf20Sopenharmony_ci * indicates that file->private_data points to &struct v4l2_fh. 758c2ecf20Sopenharmony_ci * This flag is set by the core when v4l2_fh_init() is called. 768c2ecf20Sopenharmony_ci * All new drivers should use it. 778c2ecf20Sopenharmony_ci * @V4L2_FL_QUIRK_INVERTED_CROP: 788c2ecf20Sopenharmony_ci * some old M2M drivers use g/s_crop/cropcap incorrectly: crop and 798c2ecf20Sopenharmony_ci * compose are swapped. If this flag is set, then the selection 808c2ecf20Sopenharmony_ci * targets are swapped in the g/s_crop/cropcap functions in v4l2-ioctl.c. 818c2ecf20Sopenharmony_ci * This allows those drivers to correctly implement the selection API, 828c2ecf20Sopenharmony_ci * but the old crop API will still work as expected in order to preserve 838c2ecf20Sopenharmony_ci * backwards compatibility. 848c2ecf20Sopenharmony_ci * Never set this flag for new drivers. 858c2ecf20Sopenharmony_ci * @V4L2_FL_SUBDEV_RO_DEVNODE: 868c2ecf20Sopenharmony_ci * indicates that the video device node is registered in read-only mode. 878c2ecf20Sopenharmony_ci * The flag only applies to device nodes registered for sub-devices, it is 888c2ecf20Sopenharmony_ci * set by the core when the sub-devices device nodes are registered with 898c2ecf20Sopenharmony_ci * v4l2_device_register_ro_subdev_nodes() and used by the sub-device ioctl 908c2ecf20Sopenharmony_ci * handler to restrict access to some ioctl calls. 918c2ecf20Sopenharmony_ci */ 928c2ecf20Sopenharmony_cienum v4l2_video_device_flags { 938c2ecf20Sopenharmony_ci V4L2_FL_REGISTERED = 0, 948c2ecf20Sopenharmony_ci V4L2_FL_USES_V4L2_FH = 1, 958c2ecf20Sopenharmony_ci V4L2_FL_QUIRK_INVERTED_CROP = 2, 968c2ecf20Sopenharmony_ci V4L2_FL_SUBDEV_RO_DEVNODE = 3, 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/* Priority helper functions */ 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci/** 1028c2ecf20Sopenharmony_ci * struct v4l2_prio_state - stores the priority states 1038c2ecf20Sopenharmony_ci * 1048c2ecf20Sopenharmony_ci * @prios: array with elements to store the array priorities 1058c2ecf20Sopenharmony_ci * 1068c2ecf20Sopenharmony_ci * 1078c2ecf20Sopenharmony_ci * .. note:: 1088c2ecf20Sopenharmony_ci * The size of @prios array matches the number of priority types defined 1098c2ecf20Sopenharmony_ci * by enum &v4l2_priority. 1108c2ecf20Sopenharmony_ci */ 1118c2ecf20Sopenharmony_cistruct v4l2_prio_state { 1128c2ecf20Sopenharmony_ci atomic_t prios[4]; 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/** 1168c2ecf20Sopenharmony_ci * v4l2_prio_init - initializes a struct v4l2_prio_state 1178c2ecf20Sopenharmony_ci * 1188c2ecf20Sopenharmony_ci * @global: pointer to &struct v4l2_prio_state 1198c2ecf20Sopenharmony_ci */ 1208c2ecf20Sopenharmony_civoid v4l2_prio_init(struct v4l2_prio_state *global); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/** 1238c2ecf20Sopenharmony_ci * v4l2_prio_change - changes the v4l2 file handler priority 1248c2ecf20Sopenharmony_ci * 1258c2ecf20Sopenharmony_ci * @global: pointer to the &struct v4l2_prio_state of the device node. 1268c2ecf20Sopenharmony_ci * @local: pointer to the desired priority, as defined by enum &v4l2_priority 1278c2ecf20Sopenharmony_ci * @new: Priority type requested, as defined by enum &v4l2_priority. 1288c2ecf20Sopenharmony_ci * 1298c2ecf20Sopenharmony_ci * .. note:: 1308c2ecf20Sopenharmony_ci * This function should be used only by the V4L2 core. 1318c2ecf20Sopenharmony_ci */ 1328c2ecf20Sopenharmony_ciint v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local, 1338c2ecf20Sopenharmony_ci enum v4l2_priority new); 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci/** 1368c2ecf20Sopenharmony_ci * v4l2_prio_open - Implements the priority logic for a file handler open 1378c2ecf20Sopenharmony_ci * 1388c2ecf20Sopenharmony_ci * @global: pointer to the &struct v4l2_prio_state of the device node. 1398c2ecf20Sopenharmony_ci * @local: pointer to the desired priority, as defined by enum &v4l2_priority 1408c2ecf20Sopenharmony_ci * 1418c2ecf20Sopenharmony_ci * .. note:: 1428c2ecf20Sopenharmony_ci * This function should be used only by the V4L2 core. 1438c2ecf20Sopenharmony_ci */ 1448c2ecf20Sopenharmony_civoid v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local); 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci/** 1478c2ecf20Sopenharmony_ci * v4l2_prio_close - Implements the priority logic for a file handler close 1488c2ecf20Sopenharmony_ci * 1498c2ecf20Sopenharmony_ci * @global: pointer to the &struct v4l2_prio_state of the device node. 1508c2ecf20Sopenharmony_ci * @local: priority to be released, as defined by enum &v4l2_priority 1518c2ecf20Sopenharmony_ci * 1528c2ecf20Sopenharmony_ci * .. note:: 1538c2ecf20Sopenharmony_ci * This function should be used only by the V4L2 core. 1548c2ecf20Sopenharmony_ci */ 1558c2ecf20Sopenharmony_civoid v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local); 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci/** 1588c2ecf20Sopenharmony_ci * v4l2_prio_max - Return the maximum priority, as stored at the @global array. 1598c2ecf20Sopenharmony_ci * 1608c2ecf20Sopenharmony_ci * @global: pointer to the &struct v4l2_prio_state of the device node. 1618c2ecf20Sopenharmony_ci * 1628c2ecf20Sopenharmony_ci * .. note:: 1638c2ecf20Sopenharmony_ci * This function should be used only by the V4L2 core. 1648c2ecf20Sopenharmony_ci */ 1658c2ecf20Sopenharmony_cienum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global); 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci/** 1688c2ecf20Sopenharmony_ci * v4l2_prio_check - Implements the priority logic for a file handler close 1698c2ecf20Sopenharmony_ci * 1708c2ecf20Sopenharmony_ci * @global: pointer to the &struct v4l2_prio_state of the device node. 1718c2ecf20Sopenharmony_ci * @local: desired priority, as defined by enum &v4l2_priority local 1728c2ecf20Sopenharmony_ci * 1738c2ecf20Sopenharmony_ci * .. note:: 1748c2ecf20Sopenharmony_ci * This function should be used only by the V4L2 core. 1758c2ecf20Sopenharmony_ci */ 1768c2ecf20Sopenharmony_ciint v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local); 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci/** 1798c2ecf20Sopenharmony_ci * struct v4l2_file_operations - fs operations used by a V4L2 device 1808c2ecf20Sopenharmony_ci * 1818c2ecf20Sopenharmony_ci * @owner: pointer to struct module 1828c2ecf20Sopenharmony_ci * @read: operations needed to implement the read() syscall 1838c2ecf20Sopenharmony_ci * @write: operations needed to implement the write() syscall 1848c2ecf20Sopenharmony_ci * @poll: operations needed to implement the poll() syscall 1858c2ecf20Sopenharmony_ci * @unlocked_ioctl: operations needed to implement the ioctl() syscall 1868c2ecf20Sopenharmony_ci * @compat_ioctl32: operations needed to implement the ioctl() syscall for 1878c2ecf20Sopenharmony_ci * the special case where the Kernel uses 64 bits instructions, but 1888c2ecf20Sopenharmony_ci * the userspace uses 32 bits. 1898c2ecf20Sopenharmony_ci * @get_unmapped_area: called by the mmap() syscall, used when %!CONFIG_MMU 1908c2ecf20Sopenharmony_ci * @mmap: operations needed to implement the mmap() syscall 1918c2ecf20Sopenharmony_ci * @open: operations needed to implement the open() syscall 1928c2ecf20Sopenharmony_ci * @release: operations needed to implement the release() syscall 1938c2ecf20Sopenharmony_ci * 1948c2ecf20Sopenharmony_ci * .. note:: 1958c2ecf20Sopenharmony_ci * 1968c2ecf20Sopenharmony_ci * Those operations are used to implemente the fs struct file_operations 1978c2ecf20Sopenharmony_ci * at the V4L2 drivers. The V4L2 core overrides the fs ops with some 1988c2ecf20Sopenharmony_ci * extra logic needed by the subsystem. 1998c2ecf20Sopenharmony_ci */ 2008c2ecf20Sopenharmony_cistruct v4l2_file_operations { 2018c2ecf20Sopenharmony_ci struct module *owner; 2028c2ecf20Sopenharmony_ci ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); 2038c2ecf20Sopenharmony_ci ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); 2048c2ecf20Sopenharmony_ci __poll_t (*poll) (struct file *, struct poll_table_struct *); 2058c2ecf20Sopenharmony_ci long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); 2068c2ecf20Sopenharmony_ci#ifdef CONFIG_COMPAT 2078c2ecf20Sopenharmony_ci long (*compat_ioctl32) (struct file *, unsigned int, unsigned long); 2088c2ecf20Sopenharmony_ci#endif 2098c2ecf20Sopenharmony_ci unsigned long (*get_unmapped_area) (struct file *, unsigned long, 2108c2ecf20Sopenharmony_ci unsigned long, unsigned long, unsigned long); 2118c2ecf20Sopenharmony_ci int (*mmap) (struct file *, struct vm_area_struct *); 2128c2ecf20Sopenharmony_ci int (*open) (struct file *); 2138c2ecf20Sopenharmony_ci int (*release) (struct file *); 2148c2ecf20Sopenharmony_ci}; 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci/* 2178c2ecf20Sopenharmony_ci * Newer version of video_device, handled by videodev2.c 2188c2ecf20Sopenharmony_ci * This version moves redundant code from video device code to 2198c2ecf20Sopenharmony_ci * the common handler 2208c2ecf20Sopenharmony_ci */ 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci/** 2238c2ecf20Sopenharmony_ci * struct video_device - Structure used to create and manage the V4L2 device 2248c2ecf20Sopenharmony_ci * nodes. 2258c2ecf20Sopenharmony_ci * 2268c2ecf20Sopenharmony_ci * @entity: &struct media_entity 2278c2ecf20Sopenharmony_ci * @intf_devnode: pointer to &struct media_intf_devnode 2288c2ecf20Sopenharmony_ci * @pipe: &struct media_pipeline 2298c2ecf20Sopenharmony_ci * @fops: pointer to &struct v4l2_file_operations for the video device 2308c2ecf20Sopenharmony_ci * @device_caps: device capabilities as used in v4l2_capabilities 2318c2ecf20Sopenharmony_ci * @dev: &struct device for the video device 2328c2ecf20Sopenharmony_ci * @cdev: character device 2338c2ecf20Sopenharmony_ci * @v4l2_dev: pointer to &struct v4l2_device parent 2348c2ecf20Sopenharmony_ci * @dev_parent: pointer to &struct device parent 2358c2ecf20Sopenharmony_ci * @ctrl_handler: Control handler associated with this device node. 2368c2ecf20Sopenharmony_ci * May be NULL. 2378c2ecf20Sopenharmony_ci * @queue: &struct vb2_queue associated with this device node. May be NULL. 2388c2ecf20Sopenharmony_ci * @prio: pointer to &struct v4l2_prio_state with device's Priority state. 2398c2ecf20Sopenharmony_ci * If NULL, then v4l2_dev->prio will be used. 2408c2ecf20Sopenharmony_ci * @name: video device name 2418c2ecf20Sopenharmony_ci * @vfl_type: V4L device type, as defined by &enum vfl_devnode_type 2428c2ecf20Sopenharmony_ci * @vfl_dir: V4L receiver, transmitter or m2m 2438c2ecf20Sopenharmony_ci * @minor: device node 'minor'. It is set to -1 if the registration failed 2448c2ecf20Sopenharmony_ci * @num: number of the video device node 2458c2ecf20Sopenharmony_ci * @flags: video device flags. Use bitops to set/clear/test flags. 2468c2ecf20Sopenharmony_ci * Contains a set of &enum v4l2_video_device_flags. 2478c2ecf20Sopenharmony_ci * @index: attribute to differentiate multiple indices on one physical device 2488c2ecf20Sopenharmony_ci * @fh_lock: Lock for all v4l2_fhs 2498c2ecf20Sopenharmony_ci * @fh_list: List of &struct v4l2_fh 2508c2ecf20Sopenharmony_ci * @dev_debug: Internal device debug flags, not for use by drivers 2518c2ecf20Sopenharmony_ci * @tvnorms: Supported tv norms 2528c2ecf20Sopenharmony_ci * 2538c2ecf20Sopenharmony_ci * @release: video device release() callback 2548c2ecf20Sopenharmony_ci * @ioctl_ops: pointer to &struct v4l2_ioctl_ops with ioctl callbacks 2558c2ecf20Sopenharmony_ci * 2568c2ecf20Sopenharmony_ci * @valid_ioctls: bitmap with the valid ioctls for this device 2578c2ecf20Sopenharmony_ci * @lock: pointer to &struct mutex serialization lock 2588c2ecf20Sopenharmony_ci * 2598c2ecf20Sopenharmony_ci * .. note:: 2608c2ecf20Sopenharmony_ci * Only set @dev_parent if that can't be deduced from @v4l2_dev. 2618c2ecf20Sopenharmony_ci */ 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_cistruct video_device 2648c2ecf20Sopenharmony_ci{ 2658c2ecf20Sopenharmony_ci#if defined(CONFIG_MEDIA_CONTROLLER) 2668c2ecf20Sopenharmony_ci struct media_entity entity; 2678c2ecf20Sopenharmony_ci struct media_intf_devnode *intf_devnode; 2688c2ecf20Sopenharmony_ci struct media_pipeline pipe; 2698c2ecf20Sopenharmony_ci#endif 2708c2ecf20Sopenharmony_ci const struct v4l2_file_operations *fops; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci u32 device_caps; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci /* sysfs */ 2758c2ecf20Sopenharmony_ci struct device dev; 2768c2ecf20Sopenharmony_ci struct cdev *cdev; 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci struct v4l2_device *v4l2_dev; 2798c2ecf20Sopenharmony_ci struct device *dev_parent; 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci struct v4l2_ctrl_handler *ctrl_handler; 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci struct vb2_queue *queue; 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci struct v4l2_prio_state *prio; 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci /* device info */ 2888c2ecf20Sopenharmony_ci char name[32]; 2898c2ecf20Sopenharmony_ci enum vfl_devnode_type vfl_type; 2908c2ecf20Sopenharmony_ci enum vfl_devnode_direction vfl_dir; 2918c2ecf20Sopenharmony_ci int minor; 2928c2ecf20Sopenharmony_ci u16 num; 2938c2ecf20Sopenharmony_ci unsigned long flags; 2948c2ecf20Sopenharmony_ci int index; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci /* V4L2 file handles */ 2978c2ecf20Sopenharmony_ci spinlock_t fh_lock; 2988c2ecf20Sopenharmony_ci struct list_head fh_list; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci int dev_debug; 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci v4l2_std_id tvnorms; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci /* callbacks */ 3058c2ecf20Sopenharmony_ci void (*release)(struct video_device *vdev); 3068c2ecf20Sopenharmony_ci const struct v4l2_ioctl_ops *ioctl_ops; 3078c2ecf20Sopenharmony_ci DECLARE_BITMAP(valid_ioctls, BASE_VIDIOC_PRIVATE); 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci struct mutex *lock; 3108c2ecf20Sopenharmony_ci}; 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci/** 3138c2ecf20Sopenharmony_ci * media_entity_to_video_device - Returns a &struct video_device from 3148c2ecf20Sopenharmony_ci * the &struct media_entity embedded on it. 3158c2ecf20Sopenharmony_ci * 3168c2ecf20Sopenharmony_ci * @__entity: pointer to &struct media_entity 3178c2ecf20Sopenharmony_ci */ 3188c2ecf20Sopenharmony_ci#define media_entity_to_video_device(__entity) \ 3198c2ecf20Sopenharmony_ci container_of(__entity, struct video_device, entity) 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci/** 3228c2ecf20Sopenharmony_ci * to_video_device - Returns a &struct video_device from the 3238c2ecf20Sopenharmony_ci * &struct device embedded on it. 3248c2ecf20Sopenharmony_ci * 3258c2ecf20Sopenharmony_ci * @cd: pointer to &struct device 3268c2ecf20Sopenharmony_ci */ 3278c2ecf20Sopenharmony_ci#define to_video_device(cd) container_of(cd, struct video_device, dev) 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci/** 3308c2ecf20Sopenharmony_ci * __video_register_device - register video4linux devices 3318c2ecf20Sopenharmony_ci * 3328c2ecf20Sopenharmony_ci * @vdev: struct video_device to register 3338c2ecf20Sopenharmony_ci * @type: type of device to register, as defined by &enum vfl_devnode_type 3348c2ecf20Sopenharmony_ci * @nr: which device node number is desired: 3358c2ecf20Sopenharmony_ci * (0 == /dev/video0, 1 == /dev/video1, ..., -1 == first free) 3368c2ecf20Sopenharmony_ci * @warn_if_nr_in_use: warn if the desired device node number 3378c2ecf20Sopenharmony_ci * was already in use and another number was chosen instead. 3388c2ecf20Sopenharmony_ci * @owner: module that owns the video device node 3398c2ecf20Sopenharmony_ci * 3408c2ecf20Sopenharmony_ci * The registration code assigns minor numbers and device node numbers 3418c2ecf20Sopenharmony_ci * based on the requested type and registers the new device node with 3428c2ecf20Sopenharmony_ci * the kernel. 3438c2ecf20Sopenharmony_ci * 3448c2ecf20Sopenharmony_ci * This function assumes that struct video_device was zeroed when it 3458c2ecf20Sopenharmony_ci * was allocated and does not contain any stale date. 3468c2ecf20Sopenharmony_ci * 3478c2ecf20Sopenharmony_ci * An error is returned if no free minor or device node number could be 3488c2ecf20Sopenharmony_ci * found, or if the registration of the device node failed. 3498c2ecf20Sopenharmony_ci * 3508c2ecf20Sopenharmony_ci * Returns 0 on success. 3518c2ecf20Sopenharmony_ci * 3528c2ecf20Sopenharmony_ci * .. note:: 3538c2ecf20Sopenharmony_ci * 3548c2ecf20Sopenharmony_ci * This function is meant to be used only inside the V4L2 core. 3558c2ecf20Sopenharmony_ci * Drivers should use video_register_device() or 3568c2ecf20Sopenharmony_ci * video_register_device_no_warn(). 3578c2ecf20Sopenharmony_ci */ 3588c2ecf20Sopenharmony_ciint __must_check __video_register_device(struct video_device *vdev, 3598c2ecf20Sopenharmony_ci enum vfl_devnode_type type, 3608c2ecf20Sopenharmony_ci int nr, int warn_if_nr_in_use, 3618c2ecf20Sopenharmony_ci struct module *owner); 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci/** 3648c2ecf20Sopenharmony_ci * video_register_device - register video4linux devices 3658c2ecf20Sopenharmony_ci * 3668c2ecf20Sopenharmony_ci * @vdev: struct video_device to register 3678c2ecf20Sopenharmony_ci * @type: type of device to register, as defined by &enum vfl_devnode_type 3688c2ecf20Sopenharmony_ci * @nr: which device node number is desired: 3698c2ecf20Sopenharmony_ci * (0 == /dev/video0, 1 == /dev/video1, ..., -1 == first free) 3708c2ecf20Sopenharmony_ci * 3718c2ecf20Sopenharmony_ci * Internally, it calls __video_register_device(). Please see its 3728c2ecf20Sopenharmony_ci * documentation for more details. 3738c2ecf20Sopenharmony_ci * 3748c2ecf20Sopenharmony_ci * .. note:: 3758c2ecf20Sopenharmony_ci * if video_register_device fails, the release() callback of 3768c2ecf20Sopenharmony_ci * &struct video_device structure is *not* called, so the caller 3778c2ecf20Sopenharmony_ci * is responsible for freeing any data. Usually that means that 3788c2ecf20Sopenharmony_ci * you video_device_release() should be called on failure. 3798c2ecf20Sopenharmony_ci */ 3808c2ecf20Sopenharmony_cistatic inline int __must_check video_register_device(struct video_device *vdev, 3818c2ecf20Sopenharmony_ci enum vfl_devnode_type type, 3828c2ecf20Sopenharmony_ci int nr) 3838c2ecf20Sopenharmony_ci{ 3848c2ecf20Sopenharmony_ci return __video_register_device(vdev, type, nr, 1, vdev->fops->owner); 3858c2ecf20Sopenharmony_ci} 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci/** 3888c2ecf20Sopenharmony_ci * video_register_device_no_warn - register video4linux devices 3898c2ecf20Sopenharmony_ci * 3908c2ecf20Sopenharmony_ci * @vdev: struct video_device to register 3918c2ecf20Sopenharmony_ci * @type: type of device to register, as defined by &enum vfl_devnode_type 3928c2ecf20Sopenharmony_ci * @nr: which device node number is desired: 3938c2ecf20Sopenharmony_ci * (0 == /dev/video0, 1 == /dev/video1, ..., -1 == first free) 3948c2ecf20Sopenharmony_ci * 3958c2ecf20Sopenharmony_ci * This function is identical to video_register_device() except that no 3968c2ecf20Sopenharmony_ci * warning is issued if the desired device node number was already in use. 3978c2ecf20Sopenharmony_ci * 3988c2ecf20Sopenharmony_ci * Internally, it calls __video_register_device(). Please see its 3998c2ecf20Sopenharmony_ci * documentation for more details. 4008c2ecf20Sopenharmony_ci * 4018c2ecf20Sopenharmony_ci * .. note:: 4028c2ecf20Sopenharmony_ci * if video_register_device fails, the release() callback of 4038c2ecf20Sopenharmony_ci * &struct video_device structure is *not* called, so the caller 4048c2ecf20Sopenharmony_ci * is responsible for freeing any data. Usually that means that 4058c2ecf20Sopenharmony_ci * you video_device_release() should be called on failure. 4068c2ecf20Sopenharmony_ci */ 4078c2ecf20Sopenharmony_cistatic inline int __must_check 4088c2ecf20Sopenharmony_civideo_register_device_no_warn(struct video_device *vdev, 4098c2ecf20Sopenharmony_ci enum vfl_devnode_type type, int nr) 4108c2ecf20Sopenharmony_ci{ 4118c2ecf20Sopenharmony_ci return __video_register_device(vdev, type, nr, 0, vdev->fops->owner); 4128c2ecf20Sopenharmony_ci} 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci/** 4158c2ecf20Sopenharmony_ci * video_unregister_device - Unregister video devices. 4168c2ecf20Sopenharmony_ci * 4178c2ecf20Sopenharmony_ci * @vdev: &struct video_device to register 4188c2ecf20Sopenharmony_ci * 4198c2ecf20Sopenharmony_ci * Does nothing if vdev == NULL or if video_is_registered() returns false. 4208c2ecf20Sopenharmony_ci */ 4218c2ecf20Sopenharmony_civoid video_unregister_device(struct video_device *vdev); 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci/** 4248c2ecf20Sopenharmony_ci * video_device_alloc - helper function to alloc &struct video_device 4258c2ecf20Sopenharmony_ci * 4268c2ecf20Sopenharmony_ci * Returns NULL if %-ENOMEM or a &struct video_device on success. 4278c2ecf20Sopenharmony_ci */ 4288c2ecf20Sopenharmony_cistruct video_device * __must_check video_device_alloc(void); 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci/** 4318c2ecf20Sopenharmony_ci * video_device_release - helper function to release &struct video_device 4328c2ecf20Sopenharmony_ci * 4338c2ecf20Sopenharmony_ci * @vdev: pointer to &struct video_device 4348c2ecf20Sopenharmony_ci * 4358c2ecf20Sopenharmony_ci * Can also be used for video_device->release\(\). 4368c2ecf20Sopenharmony_ci */ 4378c2ecf20Sopenharmony_civoid video_device_release(struct video_device *vdev); 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci/** 4408c2ecf20Sopenharmony_ci * video_device_release_empty - helper function to implement the 4418c2ecf20Sopenharmony_ci * video_device->release\(\) callback. 4428c2ecf20Sopenharmony_ci * 4438c2ecf20Sopenharmony_ci * @vdev: pointer to &struct video_device 4448c2ecf20Sopenharmony_ci * 4458c2ecf20Sopenharmony_ci * This release function does nothing. 4468c2ecf20Sopenharmony_ci * 4478c2ecf20Sopenharmony_ci * It should be used when the video_device is a static global struct. 4488c2ecf20Sopenharmony_ci * 4498c2ecf20Sopenharmony_ci * .. note:: 4508c2ecf20Sopenharmony_ci * Having a static video_device is a dubious construction at best. 4518c2ecf20Sopenharmony_ci */ 4528c2ecf20Sopenharmony_civoid video_device_release_empty(struct video_device *vdev); 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci/** 4558c2ecf20Sopenharmony_ci * v4l2_disable_ioctl- mark that a given command isn't implemented. 4568c2ecf20Sopenharmony_ci * shouldn't use core locking 4578c2ecf20Sopenharmony_ci * 4588c2ecf20Sopenharmony_ci * @vdev: pointer to &struct video_device 4598c2ecf20Sopenharmony_ci * @cmd: ioctl command 4608c2ecf20Sopenharmony_ci * 4618c2ecf20Sopenharmony_ci * This function allows drivers to provide just one v4l2_ioctl_ops struct, but 4628c2ecf20Sopenharmony_ci * disable ioctls based on the specific card that is actually found. 4638c2ecf20Sopenharmony_ci * 4648c2ecf20Sopenharmony_ci * .. note:: 4658c2ecf20Sopenharmony_ci * 4668c2ecf20Sopenharmony_ci * This must be called before video_register_device. 4678c2ecf20Sopenharmony_ci * See also the comments for determine_valid_ioctls(). 4688c2ecf20Sopenharmony_ci */ 4698c2ecf20Sopenharmony_cistatic inline void v4l2_disable_ioctl(struct video_device *vdev, 4708c2ecf20Sopenharmony_ci unsigned int cmd) 4718c2ecf20Sopenharmony_ci{ 4728c2ecf20Sopenharmony_ci if (_IOC_NR(cmd) < BASE_VIDIOC_PRIVATE) 4738c2ecf20Sopenharmony_ci set_bit(_IOC_NR(cmd), vdev->valid_ioctls); 4748c2ecf20Sopenharmony_ci} 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci/** 4778c2ecf20Sopenharmony_ci * video_get_drvdata - gets private data from &struct video_device. 4788c2ecf20Sopenharmony_ci * 4798c2ecf20Sopenharmony_ci * @vdev: pointer to &struct video_device 4808c2ecf20Sopenharmony_ci * 4818c2ecf20Sopenharmony_ci * returns a pointer to the private data 4828c2ecf20Sopenharmony_ci */ 4838c2ecf20Sopenharmony_cistatic inline void *video_get_drvdata(struct video_device *vdev) 4848c2ecf20Sopenharmony_ci{ 4858c2ecf20Sopenharmony_ci return dev_get_drvdata(&vdev->dev); 4868c2ecf20Sopenharmony_ci} 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci/** 4898c2ecf20Sopenharmony_ci * video_set_drvdata - sets private data from &struct video_device. 4908c2ecf20Sopenharmony_ci * 4918c2ecf20Sopenharmony_ci * @vdev: pointer to &struct video_device 4928c2ecf20Sopenharmony_ci * @data: private data pointer 4938c2ecf20Sopenharmony_ci */ 4948c2ecf20Sopenharmony_cistatic inline void video_set_drvdata(struct video_device *vdev, void *data) 4958c2ecf20Sopenharmony_ci{ 4968c2ecf20Sopenharmony_ci dev_set_drvdata(&vdev->dev, data); 4978c2ecf20Sopenharmony_ci} 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci/** 5008c2ecf20Sopenharmony_ci * video_devdata - gets &struct video_device from struct file. 5018c2ecf20Sopenharmony_ci * 5028c2ecf20Sopenharmony_ci * @file: pointer to struct file 5038c2ecf20Sopenharmony_ci */ 5048c2ecf20Sopenharmony_cistruct video_device *video_devdata(struct file *file); 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci/** 5078c2ecf20Sopenharmony_ci * video_drvdata - gets private data from &struct video_device using the 5088c2ecf20Sopenharmony_ci * struct file. 5098c2ecf20Sopenharmony_ci * 5108c2ecf20Sopenharmony_ci * @file: pointer to struct file 5118c2ecf20Sopenharmony_ci * 5128c2ecf20Sopenharmony_ci * This is function combines both video_get_drvdata() and video_devdata() 5138c2ecf20Sopenharmony_ci * as this is used very often. 5148c2ecf20Sopenharmony_ci */ 5158c2ecf20Sopenharmony_cistatic inline void *video_drvdata(struct file *file) 5168c2ecf20Sopenharmony_ci{ 5178c2ecf20Sopenharmony_ci return video_get_drvdata(video_devdata(file)); 5188c2ecf20Sopenharmony_ci} 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci/** 5218c2ecf20Sopenharmony_ci * video_device_node_name - returns the video device name 5228c2ecf20Sopenharmony_ci * 5238c2ecf20Sopenharmony_ci * @vdev: pointer to &struct video_device 5248c2ecf20Sopenharmony_ci * 5258c2ecf20Sopenharmony_ci * Returns the device name string 5268c2ecf20Sopenharmony_ci */ 5278c2ecf20Sopenharmony_cistatic inline const char *video_device_node_name(struct video_device *vdev) 5288c2ecf20Sopenharmony_ci{ 5298c2ecf20Sopenharmony_ci return dev_name(&vdev->dev); 5308c2ecf20Sopenharmony_ci} 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci/** 5338c2ecf20Sopenharmony_ci * video_is_registered - returns true if the &struct video_device is registered. 5348c2ecf20Sopenharmony_ci * 5358c2ecf20Sopenharmony_ci * 5368c2ecf20Sopenharmony_ci * @vdev: pointer to &struct video_device 5378c2ecf20Sopenharmony_ci */ 5388c2ecf20Sopenharmony_cistatic inline int video_is_registered(struct video_device *vdev) 5398c2ecf20Sopenharmony_ci{ 5408c2ecf20Sopenharmony_ci return test_bit(V4L2_FL_REGISTERED, &vdev->flags); 5418c2ecf20Sopenharmony_ci} 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci#endif /* _V4L2_DEV_H */ 544