1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * u_uvc.h
4  *
5  * Utility definitions for the uvc function
6  *
7  * Copyright (c) 2013-2014 Samsung Electronics Co., Ltd.
8  *		http://www.samsung.com
9  *
10  * Author: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com>
11  */
12 
13 #ifndef U_UVC_H
14 #define U_UVC_H
15 
16 #include <linux/mutex.h>
17 #include <linux/usb/composite.h>
18 #include <linux/usb/video.h>
19 
20 #define fi_to_f_uvc_opts(f)	container_of(f, struct f_uvc_opts, func_inst)
21 
22 struct f_uvc_opts {
23 	struct usb_function_instance			func_inst;
24 	unsigned int					streaming_interval;
25 	unsigned int					streaming_maxpacket;
26 	unsigned int					streaming_maxburst;
27 
28 	unsigned int					control_interface;
29 	unsigned int					streaming_interface;
30 	char						function_name[32];
31 
32 	bool						enable_interrupt_ep;
33 
34 	/*
35 	 * Control descriptors array pointers for full-/high-speed and
36 	 * super-speed. They point by default to the uvc_fs_control_cls and
37 	 * uvc_ss_control_cls arrays respectively. Legacy gadgets must
38 	 * override them in their gadget bind callback.
39 	 */
40 	const struct uvc_descriptor_header * const	*fs_control;
41 	const struct uvc_descriptor_header * const	*ss_control;
42 
43 	/*
44 	 * Streaming descriptors array pointers for full-speed, high-speed and
45 	 * super-speed. They will point to the uvc_[fhs]s_streaming_cls arrays
46 	 * for configfs-based gadgets. Legacy gadgets must initialize them in
47 	 * their gadget bind callback.
48 	 */
49 	const struct uvc_descriptor_header * const	*fs_streaming;
50 	const struct uvc_descriptor_header * const	*hs_streaming;
51 	const struct uvc_descriptor_header * const	*ss_streaming;
52 
53 	/* Default control descriptors for configfs-based gadgets. */
54 	struct uvc_camera_terminal_descriptor		uvc_camera_terminal;
55 	struct uvc_processing_unit_descriptor		uvc_processing;
56 	struct uvc_output_terminal_descriptor		uvc_output_terminal;
57 
58 	/*
59 	 * Control descriptors pointers arrays for full-/high-speed and
60 	 * super-speed. The first element is a configurable control header
61 	 * descriptor, the other elements point to the fixed default control
62 	 * descriptors. Used by configfs only, must not be touched by legacy
63 	 * gadgets.
64 	 */
65 	struct uvc_descriptor_header			*uvc_fs_control_cls[5];
66 	struct uvc_descriptor_header			*uvc_ss_control_cls[5];
67 
68 	/*
69 	 * Streaming descriptors for full-speed, high-speed and super-speed.
70 	 * Used by configfs only, must not be touched by legacy gadgets. The
71 	 * arrays are allocated at runtime as the number of descriptors isn't
72 	 * known in advance.
73 	 */
74 	struct uvc_descriptor_header			**uvc_fs_streaming_cls;
75 	struct uvc_descriptor_header			**uvc_hs_streaming_cls;
76 	struct uvc_descriptor_header			**uvc_ss_streaming_cls;
77 
78 	/*
79 	 * Read/write access to configfs attributes is handled by configfs.
80 	 *
81 	 * This lock protects the descriptors from concurrent access by
82 	 * read/write and symlink creation/removal.
83 	 */
84 	struct mutex			lock;
85 	int				refcnt;
86 };
87 
88 #endif /* U_UVC_H */
89