1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * V 4 L 2 D R I V E R H E L P E R A P I
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Moved from videodev2.h
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Some commonly needed functions for drivers (v4l2-common.o module)
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun #ifndef _V4L2_DEV_H
11*4882a593Smuzhiyun #define _V4L2_DEV_H
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/poll.h>
14*4882a593Smuzhiyun #include <linux/fs.h>
15*4882a593Smuzhiyun #include <linux/device.h>
16*4882a593Smuzhiyun #include <linux/cdev.h>
17*4882a593Smuzhiyun #include <linux/mutex.h>
18*4882a593Smuzhiyun #include <linux/videodev2.h>
19*4882a593Smuzhiyun #include <linux/android_kabi.h>
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun #include <media/media-entity.h>
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #define VIDEO_MAJOR 81
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun /**
26*4882a593Smuzhiyun * enum vfl_devnode_type - type of V4L2 device node
27*4882a593Smuzhiyun *
28*4882a593Smuzhiyun * @VFL_TYPE_VIDEO: for video input/output devices
29*4882a593Smuzhiyun * @VFL_TYPE_VBI: for vertical blank data (i.e. closed captions, teletext)
30*4882a593Smuzhiyun * @VFL_TYPE_RADIO: for radio tuners
31*4882a593Smuzhiyun * @VFL_TYPE_SUBDEV: for V4L2 subdevices
32*4882a593Smuzhiyun * @VFL_TYPE_SDR: for Software Defined Radio tuners
33*4882a593Smuzhiyun * @VFL_TYPE_TOUCH: for touch sensors
34*4882a593Smuzhiyun * @VFL_TYPE_MAX: number of VFL types, must always be last in the enum
35*4882a593Smuzhiyun */
36*4882a593Smuzhiyun enum vfl_devnode_type {
37*4882a593Smuzhiyun VFL_TYPE_VIDEO,
38*4882a593Smuzhiyun VFL_TYPE_VBI,
39*4882a593Smuzhiyun VFL_TYPE_RADIO,
40*4882a593Smuzhiyun VFL_TYPE_SUBDEV,
41*4882a593Smuzhiyun VFL_TYPE_SDR,
42*4882a593Smuzhiyun VFL_TYPE_TOUCH,
43*4882a593Smuzhiyun VFL_TYPE_MAX /* Shall be the last one */
44*4882a593Smuzhiyun };
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun /**
47*4882a593Smuzhiyun * enum vfl_direction - Identifies if a &struct video_device corresponds
48*4882a593Smuzhiyun * to a receiver, a transmitter or a mem-to-mem device.
49*4882a593Smuzhiyun *
50*4882a593Smuzhiyun * @VFL_DIR_RX: device is a receiver.
51*4882a593Smuzhiyun * @VFL_DIR_TX: device is a transmitter.
52*4882a593Smuzhiyun * @VFL_DIR_M2M: device is a memory to memory device.
53*4882a593Smuzhiyun *
54*4882a593Smuzhiyun * Note: Ignored if &enum vfl_devnode_type is %VFL_TYPE_SUBDEV.
55*4882a593Smuzhiyun */
56*4882a593Smuzhiyun enum vfl_devnode_direction {
57*4882a593Smuzhiyun VFL_DIR_RX,
58*4882a593Smuzhiyun VFL_DIR_TX,
59*4882a593Smuzhiyun VFL_DIR_M2M,
60*4882a593Smuzhiyun };
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun struct v4l2_ioctl_callbacks;
63*4882a593Smuzhiyun struct video_device;
64*4882a593Smuzhiyun struct v4l2_device;
65*4882a593Smuzhiyun struct v4l2_ctrl_handler;
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun /**
68*4882a593Smuzhiyun * enum v4l2_video_device_flags - Flags used by &struct video_device
69*4882a593Smuzhiyun *
70*4882a593Smuzhiyun * @V4L2_FL_REGISTERED:
71*4882a593Smuzhiyun * indicates that a &struct video_device is registered.
72*4882a593Smuzhiyun * Drivers can clear this flag if they want to block all future
73*4882a593Smuzhiyun * device access. It is cleared by video_unregister_device.
74*4882a593Smuzhiyun * @V4L2_FL_USES_V4L2_FH:
75*4882a593Smuzhiyun * indicates that file->private_data points to &struct v4l2_fh.
76*4882a593Smuzhiyun * This flag is set by the core when v4l2_fh_init() is called.
77*4882a593Smuzhiyun * All new drivers should use it.
78*4882a593Smuzhiyun * @V4L2_FL_QUIRK_INVERTED_CROP:
79*4882a593Smuzhiyun * some old M2M drivers use g/s_crop/cropcap incorrectly: crop and
80*4882a593Smuzhiyun * compose are swapped. If this flag is set, then the selection
81*4882a593Smuzhiyun * targets are swapped in the g/s_crop/cropcap functions in v4l2-ioctl.c.
82*4882a593Smuzhiyun * This allows those drivers to correctly implement the selection API,
83*4882a593Smuzhiyun * but the old crop API will still work as expected in order to preserve
84*4882a593Smuzhiyun * backwards compatibility.
85*4882a593Smuzhiyun * Never set this flag for new drivers.
86*4882a593Smuzhiyun * @V4L2_FL_SUBDEV_RO_DEVNODE:
87*4882a593Smuzhiyun * indicates that the video device node is registered in read-only mode.
88*4882a593Smuzhiyun * The flag only applies to device nodes registered for sub-devices, it is
89*4882a593Smuzhiyun * set by the core when the sub-devices device nodes are registered with
90*4882a593Smuzhiyun * v4l2_device_register_ro_subdev_nodes() and used by the sub-device ioctl
91*4882a593Smuzhiyun * handler to restrict access to some ioctl calls.
92*4882a593Smuzhiyun */
93*4882a593Smuzhiyun enum v4l2_video_device_flags {
94*4882a593Smuzhiyun V4L2_FL_REGISTERED = 0,
95*4882a593Smuzhiyun V4L2_FL_USES_V4L2_FH = 1,
96*4882a593Smuzhiyun V4L2_FL_QUIRK_INVERTED_CROP = 2,
97*4882a593Smuzhiyun V4L2_FL_SUBDEV_RO_DEVNODE = 3,
98*4882a593Smuzhiyun };
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun /* Priority helper functions */
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun /**
103*4882a593Smuzhiyun * struct v4l2_prio_state - stores the priority states
104*4882a593Smuzhiyun *
105*4882a593Smuzhiyun * @prios: array with elements to store the array priorities
106*4882a593Smuzhiyun *
107*4882a593Smuzhiyun *
108*4882a593Smuzhiyun * .. note::
109*4882a593Smuzhiyun * The size of @prios array matches the number of priority types defined
110*4882a593Smuzhiyun * by enum &v4l2_priority.
111*4882a593Smuzhiyun */
112*4882a593Smuzhiyun struct v4l2_prio_state {
113*4882a593Smuzhiyun atomic_t prios[4];
114*4882a593Smuzhiyun };
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun /**
117*4882a593Smuzhiyun * v4l2_prio_init - initializes a struct v4l2_prio_state
118*4882a593Smuzhiyun *
119*4882a593Smuzhiyun * @global: pointer to &struct v4l2_prio_state
120*4882a593Smuzhiyun */
121*4882a593Smuzhiyun void v4l2_prio_init(struct v4l2_prio_state *global);
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun /**
124*4882a593Smuzhiyun * v4l2_prio_change - changes the v4l2 file handler priority
125*4882a593Smuzhiyun *
126*4882a593Smuzhiyun * @global: pointer to the &struct v4l2_prio_state of the device node.
127*4882a593Smuzhiyun * @local: pointer to the desired priority, as defined by enum &v4l2_priority
128*4882a593Smuzhiyun * @new: Priority type requested, as defined by enum &v4l2_priority.
129*4882a593Smuzhiyun *
130*4882a593Smuzhiyun * .. note::
131*4882a593Smuzhiyun * This function should be used only by the V4L2 core.
132*4882a593Smuzhiyun */
133*4882a593Smuzhiyun int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
134*4882a593Smuzhiyun enum v4l2_priority new);
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun /**
137*4882a593Smuzhiyun * v4l2_prio_open - Implements the priority logic for a file handler open
138*4882a593Smuzhiyun *
139*4882a593Smuzhiyun * @global: pointer to the &struct v4l2_prio_state of the device node.
140*4882a593Smuzhiyun * @local: pointer to the desired priority, as defined by enum &v4l2_priority
141*4882a593Smuzhiyun *
142*4882a593Smuzhiyun * .. note::
143*4882a593Smuzhiyun * This function should be used only by the V4L2 core.
144*4882a593Smuzhiyun */
145*4882a593Smuzhiyun void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun /**
148*4882a593Smuzhiyun * v4l2_prio_close - Implements the priority logic for a file handler close
149*4882a593Smuzhiyun *
150*4882a593Smuzhiyun * @global: pointer to the &struct v4l2_prio_state of the device node.
151*4882a593Smuzhiyun * @local: priority to be released, as defined by enum &v4l2_priority
152*4882a593Smuzhiyun *
153*4882a593Smuzhiyun * .. note::
154*4882a593Smuzhiyun * This function should be used only by the V4L2 core.
155*4882a593Smuzhiyun */
156*4882a593Smuzhiyun void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local);
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun /**
159*4882a593Smuzhiyun * v4l2_prio_max - Return the maximum priority, as stored at the @global array.
160*4882a593Smuzhiyun *
161*4882a593Smuzhiyun * @global: pointer to the &struct v4l2_prio_state of the device node.
162*4882a593Smuzhiyun *
163*4882a593Smuzhiyun * .. note::
164*4882a593Smuzhiyun * This function should be used only by the V4L2 core.
165*4882a593Smuzhiyun */
166*4882a593Smuzhiyun enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun /**
169*4882a593Smuzhiyun * v4l2_prio_check - Implements the priority logic for a file handler close
170*4882a593Smuzhiyun *
171*4882a593Smuzhiyun * @global: pointer to the &struct v4l2_prio_state of the device node.
172*4882a593Smuzhiyun * @local: desired priority, as defined by enum &v4l2_priority local
173*4882a593Smuzhiyun *
174*4882a593Smuzhiyun * .. note::
175*4882a593Smuzhiyun * This function should be used only by the V4L2 core.
176*4882a593Smuzhiyun */
177*4882a593Smuzhiyun int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun /**
180*4882a593Smuzhiyun * struct v4l2_file_operations - fs operations used by a V4L2 device
181*4882a593Smuzhiyun *
182*4882a593Smuzhiyun * @owner: pointer to struct module
183*4882a593Smuzhiyun * @read: operations needed to implement the read() syscall
184*4882a593Smuzhiyun * @write: operations needed to implement the write() syscall
185*4882a593Smuzhiyun * @poll: operations needed to implement the poll() syscall
186*4882a593Smuzhiyun * @unlocked_ioctl: operations needed to implement the ioctl() syscall
187*4882a593Smuzhiyun * @compat_ioctl32: operations needed to implement the ioctl() syscall for
188*4882a593Smuzhiyun * the special case where the Kernel uses 64 bits instructions, but
189*4882a593Smuzhiyun * the userspace uses 32 bits.
190*4882a593Smuzhiyun * @get_unmapped_area: called by the mmap() syscall, used when %!CONFIG_MMU
191*4882a593Smuzhiyun * @mmap: operations needed to implement the mmap() syscall
192*4882a593Smuzhiyun * @open: operations needed to implement the open() syscall
193*4882a593Smuzhiyun * @release: operations needed to implement the release() syscall
194*4882a593Smuzhiyun *
195*4882a593Smuzhiyun * .. note::
196*4882a593Smuzhiyun *
197*4882a593Smuzhiyun * Those operations are used to implemente the fs struct file_operations
198*4882a593Smuzhiyun * at the V4L2 drivers. The V4L2 core overrides the fs ops with some
199*4882a593Smuzhiyun * extra logic needed by the subsystem.
200*4882a593Smuzhiyun */
201*4882a593Smuzhiyun struct v4l2_file_operations {
202*4882a593Smuzhiyun struct module *owner;
203*4882a593Smuzhiyun ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
204*4882a593Smuzhiyun ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
205*4882a593Smuzhiyun __poll_t (*poll) (struct file *, struct poll_table_struct *);
206*4882a593Smuzhiyun long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
207*4882a593Smuzhiyun #ifdef CONFIG_COMPAT
208*4882a593Smuzhiyun long (*compat_ioctl32) (struct file *, unsigned int, unsigned long);
209*4882a593Smuzhiyun #endif
210*4882a593Smuzhiyun unsigned long (*get_unmapped_area) (struct file *, unsigned long,
211*4882a593Smuzhiyun unsigned long, unsigned long, unsigned long);
212*4882a593Smuzhiyun int (*mmap) (struct file *, struct vm_area_struct *);
213*4882a593Smuzhiyun int (*open) (struct file *);
214*4882a593Smuzhiyun int (*release) (struct file *);
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun ANDROID_KABI_RESERVE(1);
217*4882a593Smuzhiyun };
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun /*
220*4882a593Smuzhiyun * Newer version of video_device, handled by videodev2.c
221*4882a593Smuzhiyun * This version moves redundant code from video device code to
222*4882a593Smuzhiyun * the common handler
223*4882a593Smuzhiyun */
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun /**
226*4882a593Smuzhiyun * struct video_device - Structure used to create and manage the V4L2 device
227*4882a593Smuzhiyun * nodes.
228*4882a593Smuzhiyun *
229*4882a593Smuzhiyun * @entity: &struct media_entity
230*4882a593Smuzhiyun * @intf_devnode: pointer to &struct media_intf_devnode
231*4882a593Smuzhiyun * @pipe: &struct media_pipeline
232*4882a593Smuzhiyun * @fops: pointer to &struct v4l2_file_operations for the video device
233*4882a593Smuzhiyun * @device_caps: device capabilities as used in v4l2_capabilities
234*4882a593Smuzhiyun * @dev: &struct device for the video device
235*4882a593Smuzhiyun * @cdev: character device
236*4882a593Smuzhiyun * @v4l2_dev: pointer to &struct v4l2_device parent
237*4882a593Smuzhiyun * @dev_parent: pointer to &struct device parent
238*4882a593Smuzhiyun * @ctrl_handler: Control handler associated with this device node.
239*4882a593Smuzhiyun * May be NULL.
240*4882a593Smuzhiyun * @queue: &struct vb2_queue associated with this device node. May be NULL.
241*4882a593Smuzhiyun * @prio: pointer to &struct v4l2_prio_state with device's Priority state.
242*4882a593Smuzhiyun * If NULL, then v4l2_dev->prio will be used.
243*4882a593Smuzhiyun * @name: video device name
244*4882a593Smuzhiyun * @vfl_type: V4L device type, as defined by &enum vfl_devnode_type
245*4882a593Smuzhiyun * @vfl_dir: V4L receiver, transmitter or m2m
246*4882a593Smuzhiyun * @minor: device node 'minor'. It is set to -1 if the registration failed
247*4882a593Smuzhiyun * @num: number of the video device node
248*4882a593Smuzhiyun * @flags: video device flags. Use bitops to set/clear/test flags.
249*4882a593Smuzhiyun * Contains a set of &enum v4l2_video_device_flags.
250*4882a593Smuzhiyun * @index: attribute to differentiate multiple indices on one physical device
251*4882a593Smuzhiyun * @fh_lock: Lock for all v4l2_fhs
252*4882a593Smuzhiyun * @fh_list: List of &struct v4l2_fh
253*4882a593Smuzhiyun * @dev_debug: Internal device debug flags, not for use by drivers
254*4882a593Smuzhiyun * @tvnorms: Supported tv norms
255*4882a593Smuzhiyun *
256*4882a593Smuzhiyun * @release: video device release() callback
257*4882a593Smuzhiyun * @ioctl_ops: pointer to &struct v4l2_ioctl_ops with ioctl callbacks
258*4882a593Smuzhiyun *
259*4882a593Smuzhiyun * @valid_ioctls: bitmap with the valid ioctls for this device
260*4882a593Smuzhiyun * @lock: pointer to &struct mutex serialization lock
261*4882a593Smuzhiyun *
262*4882a593Smuzhiyun * .. note::
263*4882a593Smuzhiyun * Only set @dev_parent if that can't be deduced from @v4l2_dev.
264*4882a593Smuzhiyun */
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun struct video_device
267*4882a593Smuzhiyun {
268*4882a593Smuzhiyun #if defined(CONFIG_MEDIA_CONTROLLER)
269*4882a593Smuzhiyun struct media_entity entity;
270*4882a593Smuzhiyun struct media_intf_devnode *intf_devnode;
271*4882a593Smuzhiyun struct media_pipeline pipe;
272*4882a593Smuzhiyun #endif
273*4882a593Smuzhiyun const struct v4l2_file_operations *fops;
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun u32 device_caps;
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun /* sysfs */
278*4882a593Smuzhiyun struct device dev;
279*4882a593Smuzhiyun struct cdev *cdev;
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun struct v4l2_device *v4l2_dev;
282*4882a593Smuzhiyun struct device *dev_parent;
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun struct v4l2_ctrl_handler *ctrl_handler;
285*4882a593Smuzhiyun
286*4882a593Smuzhiyun struct vb2_queue *queue;
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun struct v4l2_prio_state *prio;
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun /* device info */
291*4882a593Smuzhiyun char name[32];
292*4882a593Smuzhiyun enum vfl_devnode_type vfl_type;
293*4882a593Smuzhiyun enum vfl_devnode_direction vfl_dir;
294*4882a593Smuzhiyun int minor;
295*4882a593Smuzhiyun u16 num;
296*4882a593Smuzhiyun unsigned long flags;
297*4882a593Smuzhiyun int index;
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun /* V4L2 file handles */
300*4882a593Smuzhiyun spinlock_t fh_lock;
301*4882a593Smuzhiyun struct list_head fh_list;
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun int dev_debug;
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun v4l2_std_id tvnorms;
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun /* callbacks */
308*4882a593Smuzhiyun void (*release)(struct video_device *vdev);
309*4882a593Smuzhiyun const struct v4l2_ioctl_ops *ioctl_ops;
310*4882a593Smuzhiyun DECLARE_BITMAP(valid_ioctls, BASE_VIDIOC_PRIVATE);
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun struct mutex *lock;
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun ANDROID_KABI_RESERVE(1);
315*4882a593Smuzhiyun ANDROID_KABI_RESERVE(2);
316*4882a593Smuzhiyun };
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun /**
319*4882a593Smuzhiyun * media_entity_to_video_device - Returns a &struct video_device from
320*4882a593Smuzhiyun * the &struct media_entity embedded on it.
321*4882a593Smuzhiyun *
322*4882a593Smuzhiyun * @__entity: pointer to &struct media_entity
323*4882a593Smuzhiyun */
324*4882a593Smuzhiyun #define media_entity_to_video_device(__entity) \
325*4882a593Smuzhiyun container_of(__entity, struct video_device, entity)
326*4882a593Smuzhiyun
327*4882a593Smuzhiyun /**
328*4882a593Smuzhiyun * to_video_device - Returns a &struct video_device from the
329*4882a593Smuzhiyun * &struct device embedded on it.
330*4882a593Smuzhiyun *
331*4882a593Smuzhiyun * @cd: pointer to &struct device
332*4882a593Smuzhiyun */
333*4882a593Smuzhiyun #define to_video_device(cd) container_of(cd, struct video_device, dev)
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun /**
336*4882a593Smuzhiyun * __video_register_device - register video4linux devices
337*4882a593Smuzhiyun *
338*4882a593Smuzhiyun * @vdev: struct video_device to register
339*4882a593Smuzhiyun * @type: type of device to register, as defined by &enum vfl_devnode_type
340*4882a593Smuzhiyun * @nr: which device node number is desired:
341*4882a593Smuzhiyun * (0 == /dev/video0, 1 == /dev/video1, ..., -1 == first free)
342*4882a593Smuzhiyun * @warn_if_nr_in_use: warn if the desired device node number
343*4882a593Smuzhiyun * was already in use and another number was chosen instead.
344*4882a593Smuzhiyun * @owner: module that owns the video device node
345*4882a593Smuzhiyun *
346*4882a593Smuzhiyun * The registration code assigns minor numbers and device node numbers
347*4882a593Smuzhiyun * based on the requested type and registers the new device node with
348*4882a593Smuzhiyun * the kernel.
349*4882a593Smuzhiyun *
350*4882a593Smuzhiyun * This function assumes that struct video_device was zeroed when it
351*4882a593Smuzhiyun * was allocated and does not contain any stale date.
352*4882a593Smuzhiyun *
353*4882a593Smuzhiyun * An error is returned if no free minor or device node number could be
354*4882a593Smuzhiyun * found, or if the registration of the device node failed.
355*4882a593Smuzhiyun *
356*4882a593Smuzhiyun * Returns 0 on success.
357*4882a593Smuzhiyun *
358*4882a593Smuzhiyun * .. note::
359*4882a593Smuzhiyun *
360*4882a593Smuzhiyun * This function is meant to be used only inside the V4L2 core.
361*4882a593Smuzhiyun * Drivers should use video_register_device() or
362*4882a593Smuzhiyun * video_register_device_no_warn().
363*4882a593Smuzhiyun */
364*4882a593Smuzhiyun int __must_check __video_register_device(struct video_device *vdev,
365*4882a593Smuzhiyun enum vfl_devnode_type type,
366*4882a593Smuzhiyun int nr, int warn_if_nr_in_use,
367*4882a593Smuzhiyun struct module *owner);
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun /**
370*4882a593Smuzhiyun * video_register_device - register video4linux devices
371*4882a593Smuzhiyun *
372*4882a593Smuzhiyun * @vdev: struct video_device to register
373*4882a593Smuzhiyun * @type: type of device to register, as defined by &enum vfl_devnode_type
374*4882a593Smuzhiyun * @nr: which device node number is desired:
375*4882a593Smuzhiyun * (0 == /dev/video0, 1 == /dev/video1, ..., -1 == first free)
376*4882a593Smuzhiyun *
377*4882a593Smuzhiyun * Internally, it calls __video_register_device(). Please see its
378*4882a593Smuzhiyun * documentation for more details.
379*4882a593Smuzhiyun *
380*4882a593Smuzhiyun * .. note::
381*4882a593Smuzhiyun * if video_register_device fails, the release() callback of
382*4882a593Smuzhiyun * &struct video_device structure is *not* called, so the caller
383*4882a593Smuzhiyun * is responsible for freeing any data. Usually that means that
384*4882a593Smuzhiyun * you video_device_release() should be called on failure.
385*4882a593Smuzhiyun */
video_register_device(struct video_device * vdev,enum vfl_devnode_type type,int nr)386*4882a593Smuzhiyun static inline int __must_check video_register_device(struct video_device *vdev,
387*4882a593Smuzhiyun enum vfl_devnode_type type,
388*4882a593Smuzhiyun int nr)
389*4882a593Smuzhiyun {
390*4882a593Smuzhiyun return __video_register_device(vdev, type, nr, 1, vdev->fops->owner);
391*4882a593Smuzhiyun }
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun /**
394*4882a593Smuzhiyun * video_register_device_no_warn - register video4linux devices
395*4882a593Smuzhiyun *
396*4882a593Smuzhiyun * @vdev: struct video_device to register
397*4882a593Smuzhiyun * @type: type of device to register, as defined by &enum vfl_devnode_type
398*4882a593Smuzhiyun * @nr: which device node number is desired:
399*4882a593Smuzhiyun * (0 == /dev/video0, 1 == /dev/video1, ..., -1 == first free)
400*4882a593Smuzhiyun *
401*4882a593Smuzhiyun * This function is identical to video_register_device() except that no
402*4882a593Smuzhiyun * warning is issued if the desired device node number was already in use.
403*4882a593Smuzhiyun *
404*4882a593Smuzhiyun * Internally, it calls __video_register_device(). Please see its
405*4882a593Smuzhiyun * documentation for more details.
406*4882a593Smuzhiyun *
407*4882a593Smuzhiyun * .. note::
408*4882a593Smuzhiyun * if video_register_device fails, the release() callback of
409*4882a593Smuzhiyun * &struct video_device structure is *not* called, so the caller
410*4882a593Smuzhiyun * is responsible for freeing any data. Usually that means that
411*4882a593Smuzhiyun * you video_device_release() should be called on failure.
412*4882a593Smuzhiyun */
413*4882a593Smuzhiyun static inline int __must_check
video_register_device_no_warn(struct video_device * vdev,enum vfl_devnode_type type,int nr)414*4882a593Smuzhiyun video_register_device_no_warn(struct video_device *vdev,
415*4882a593Smuzhiyun enum vfl_devnode_type type, int nr)
416*4882a593Smuzhiyun {
417*4882a593Smuzhiyun return __video_register_device(vdev, type, nr, 0, vdev->fops->owner);
418*4882a593Smuzhiyun }
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun /**
421*4882a593Smuzhiyun * video_unregister_device - Unregister video devices.
422*4882a593Smuzhiyun *
423*4882a593Smuzhiyun * @vdev: &struct video_device to register
424*4882a593Smuzhiyun *
425*4882a593Smuzhiyun * Does nothing if vdev == NULL or if video_is_registered() returns false.
426*4882a593Smuzhiyun */
427*4882a593Smuzhiyun void video_unregister_device(struct video_device *vdev);
428*4882a593Smuzhiyun
429*4882a593Smuzhiyun /**
430*4882a593Smuzhiyun * video_device_alloc - helper function to alloc &struct video_device
431*4882a593Smuzhiyun *
432*4882a593Smuzhiyun * Returns NULL if %-ENOMEM or a &struct video_device on success.
433*4882a593Smuzhiyun */
434*4882a593Smuzhiyun struct video_device * __must_check video_device_alloc(void);
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun /**
437*4882a593Smuzhiyun * video_device_release - helper function to release &struct video_device
438*4882a593Smuzhiyun *
439*4882a593Smuzhiyun * @vdev: pointer to &struct video_device
440*4882a593Smuzhiyun *
441*4882a593Smuzhiyun * Can also be used for video_device->release\(\).
442*4882a593Smuzhiyun */
443*4882a593Smuzhiyun void video_device_release(struct video_device *vdev);
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun /**
446*4882a593Smuzhiyun * video_device_release_empty - helper function to implement the
447*4882a593Smuzhiyun * video_device->release\(\) callback.
448*4882a593Smuzhiyun *
449*4882a593Smuzhiyun * @vdev: pointer to &struct video_device
450*4882a593Smuzhiyun *
451*4882a593Smuzhiyun * This release function does nothing.
452*4882a593Smuzhiyun *
453*4882a593Smuzhiyun * It should be used when the video_device is a static global struct.
454*4882a593Smuzhiyun *
455*4882a593Smuzhiyun * .. note::
456*4882a593Smuzhiyun * Having a static video_device is a dubious construction at best.
457*4882a593Smuzhiyun */
458*4882a593Smuzhiyun void video_device_release_empty(struct video_device *vdev);
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun /**
461*4882a593Smuzhiyun * v4l2_disable_ioctl- mark that a given command isn't implemented.
462*4882a593Smuzhiyun * shouldn't use core locking
463*4882a593Smuzhiyun *
464*4882a593Smuzhiyun * @vdev: pointer to &struct video_device
465*4882a593Smuzhiyun * @cmd: ioctl command
466*4882a593Smuzhiyun *
467*4882a593Smuzhiyun * This function allows drivers to provide just one v4l2_ioctl_ops struct, but
468*4882a593Smuzhiyun * disable ioctls based on the specific card that is actually found.
469*4882a593Smuzhiyun *
470*4882a593Smuzhiyun * .. note::
471*4882a593Smuzhiyun *
472*4882a593Smuzhiyun * This must be called before video_register_device.
473*4882a593Smuzhiyun * See also the comments for determine_valid_ioctls().
474*4882a593Smuzhiyun */
v4l2_disable_ioctl(struct video_device * vdev,unsigned int cmd)475*4882a593Smuzhiyun static inline void v4l2_disable_ioctl(struct video_device *vdev,
476*4882a593Smuzhiyun unsigned int cmd)
477*4882a593Smuzhiyun {
478*4882a593Smuzhiyun if (_IOC_NR(cmd) < BASE_VIDIOC_PRIVATE)
479*4882a593Smuzhiyun set_bit(_IOC_NR(cmd), vdev->valid_ioctls);
480*4882a593Smuzhiyun }
481*4882a593Smuzhiyun
482*4882a593Smuzhiyun /**
483*4882a593Smuzhiyun * video_get_drvdata - gets private data from &struct video_device.
484*4882a593Smuzhiyun *
485*4882a593Smuzhiyun * @vdev: pointer to &struct video_device
486*4882a593Smuzhiyun *
487*4882a593Smuzhiyun * returns a pointer to the private data
488*4882a593Smuzhiyun */
video_get_drvdata(struct video_device * vdev)489*4882a593Smuzhiyun static inline void *video_get_drvdata(struct video_device *vdev)
490*4882a593Smuzhiyun {
491*4882a593Smuzhiyun return dev_get_drvdata(&vdev->dev);
492*4882a593Smuzhiyun }
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun /**
495*4882a593Smuzhiyun * video_set_drvdata - sets private data from &struct video_device.
496*4882a593Smuzhiyun *
497*4882a593Smuzhiyun * @vdev: pointer to &struct video_device
498*4882a593Smuzhiyun * @data: private data pointer
499*4882a593Smuzhiyun */
video_set_drvdata(struct video_device * vdev,void * data)500*4882a593Smuzhiyun static inline void video_set_drvdata(struct video_device *vdev, void *data)
501*4882a593Smuzhiyun {
502*4882a593Smuzhiyun dev_set_drvdata(&vdev->dev, data);
503*4882a593Smuzhiyun }
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun /**
506*4882a593Smuzhiyun * video_devdata - gets &struct video_device from struct file.
507*4882a593Smuzhiyun *
508*4882a593Smuzhiyun * @file: pointer to struct file
509*4882a593Smuzhiyun */
510*4882a593Smuzhiyun struct video_device *video_devdata(struct file *file);
511*4882a593Smuzhiyun
512*4882a593Smuzhiyun /**
513*4882a593Smuzhiyun * video_drvdata - gets private data from &struct video_device using the
514*4882a593Smuzhiyun * struct file.
515*4882a593Smuzhiyun *
516*4882a593Smuzhiyun * @file: pointer to struct file
517*4882a593Smuzhiyun *
518*4882a593Smuzhiyun * This is function combines both video_get_drvdata() and video_devdata()
519*4882a593Smuzhiyun * as this is used very often.
520*4882a593Smuzhiyun */
video_drvdata(struct file * file)521*4882a593Smuzhiyun static inline void *video_drvdata(struct file *file)
522*4882a593Smuzhiyun {
523*4882a593Smuzhiyun return video_get_drvdata(video_devdata(file));
524*4882a593Smuzhiyun }
525*4882a593Smuzhiyun
526*4882a593Smuzhiyun /**
527*4882a593Smuzhiyun * video_device_node_name - returns the video device name
528*4882a593Smuzhiyun *
529*4882a593Smuzhiyun * @vdev: pointer to &struct video_device
530*4882a593Smuzhiyun *
531*4882a593Smuzhiyun * Returns the device name string
532*4882a593Smuzhiyun */
video_device_node_name(struct video_device * vdev)533*4882a593Smuzhiyun static inline const char *video_device_node_name(struct video_device *vdev)
534*4882a593Smuzhiyun {
535*4882a593Smuzhiyun return dev_name(&vdev->dev);
536*4882a593Smuzhiyun }
537*4882a593Smuzhiyun
538*4882a593Smuzhiyun /**
539*4882a593Smuzhiyun * video_is_registered - returns true if the &struct video_device is registered.
540*4882a593Smuzhiyun *
541*4882a593Smuzhiyun *
542*4882a593Smuzhiyun * @vdev: pointer to &struct video_device
543*4882a593Smuzhiyun */
video_is_registered(struct video_device * vdev)544*4882a593Smuzhiyun static inline int video_is_registered(struct video_device *vdev)
545*4882a593Smuzhiyun {
546*4882a593Smuzhiyun return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
547*4882a593Smuzhiyun }
548*4882a593Smuzhiyun
549*4882a593Smuzhiyun #endif /* _V4L2_DEV_H */
550