xref: /linux/drivers/usb/gadget/function/u_uvc.h (revision 06d07429858317ded2db7986113a9e0129cd599b)
12e759738SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
26d11ed76SAndrzej Pietrasiewicz /*
36d11ed76SAndrzej Pietrasiewicz  * u_uvc.h
46d11ed76SAndrzej Pietrasiewicz  *
56d11ed76SAndrzej Pietrasiewicz  * Utility definitions for the uvc function
66d11ed76SAndrzej Pietrasiewicz  *
76d11ed76SAndrzej Pietrasiewicz  * Copyright (c) 2013-2014 Samsung Electronics Co., Ltd.
86d11ed76SAndrzej Pietrasiewicz  *		http://www.samsung.com
96d11ed76SAndrzej Pietrasiewicz  *
101b4a3b51SAndrzej Pietrasiewicz  * Author: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com>
116d11ed76SAndrzej Pietrasiewicz  */
126d11ed76SAndrzej Pietrasiewicz 
136d11ed76SAndrzej Pietrasiewicz #ifndef U_UVC_H
146d11ed76SAndrzej Pietrasiewicz #define U_UVC_H
156d11ed76SAndrzej Pietrasiewicz 
16284eb166SLaurent Pinchart #include <linux/mutex.h>
176d11ed76SAndrzej Pietrasiewicz #include <linux/usb/composite.h>
1846919a23SAndrzej Pietrasiewicz #include <linux/usb/video.h>
196d11ed76SAndrzej Pietrasiewicz 
20bbea6de1SAndrzej Pietrasiewicz #define fi_to_f_uvc_opts(f)	container_of(f, struct f_uvc_opts, func_inst)
216d11ed76SAndrzej Pietrasiewicz 
226d11ed76SAndrzej Pietrasiewicz struct f_uvc_opts {
236d11ed76SAndrzej Pietrasiewicz 	struct usb_function_instance			func_inst;
246d11ed76SAndrzej Pietrasiewicz 	unsigned int					streaming_interval;
256d11ed76SAndrzej Pietrasiewicz 	unsigned int					streaming_maxpacket;
266d11ed76SAndrzej Pietrasiewicz 	unsigned int					streaming_maxburst;
2746919a23SAndrzej Pietrasiewicz 
28bf715448SLaurent Pinchart 	unsigned int					control_interface;
29bf715448SLaurent Pinchart 	unsigned int					streaming_interface;
30324e4f85SDan Vacura 	char						function_name[32];
310525210cSDaniel Scally 	unsigned int					last_unit_id;
32bf715448SLaurent Pinchart 
33a36afe78SDaniel Scally 	bool						enable_interrupt_ep;
34a36afe78SDaniel Scally 
3546919a23SAndrzej Pietrasiewicz 	/*
3646919a23SAndrzej Pietrasiewicz 	 * Control descriptors array pointers for full-/high-speed and
3746919a23SAndrzej Pietrasiewicz 	 * super-speed. They point by default to the uvc_fs_control_cls and
3846919a23SAndrzej Pietrasiewicz 	 * uvc_ss_control_cls arrays respectively. Legacy gadgets must
3946919a23SAndrzej Pietrasiewicz 	 * override them in their gadget bind callback.
4046919a23SAndrzej Pietrasiewicz 	 */
416d11ed76SAndrzej Pietrasiewicz 	const struct uvc_descriptor_header * const	*fs_control;
426d11ed76SAndrzej Pietrasiewicz 	const struct uvc_descriptor_header * const	*ss_control;
4346919a23SAndrzej Pietrasiewicz 
4446919a23SAndrzej Pietrasiewicz 	/*
4546919a23SAndrzej Pietrasiewicz 	 * Streaming descriptors array pointers for full-speed, high-speed and
4646919a23SAndrzej Pietrasiewicz 	 * super-speed. They will point to the uvc_[fhs]s_streaming_cls arrays
4746919a23SAndrzej Pietrasiewicz 	 * for configfs-based gadgets. Legacy gadgets must initialize them in
4846919a23SAndrzej Pietrasiewicz 	 * their gadget bind callback.
4946919a23SAndrzej Pietrasiewicz 	 */
506d11ed76SAndrzej Pietrasiewicz 	const struct uvc_descriptor_header * const	*fs_streaming;
516d11ed76SAndrzej Pietrasiewicz 	const struct uvc_descriptor_header * const	*hs_streaming;
526d11ed76SAndrzej Pietrasiewicz 	const struct uvc_descriptor_header * const	*ss_streaming;
5346919a23SAndrzej Pietrasiewicz 
5446919a23SAndrzej Pietrasiewicz 	/* Default control descriptors for configfs-based gadgets. */
5546919a23SAndrzej Pietrasiewicz 	struct uvc_camera_terminal_descriptor		uvc_camera_terminal;
5646919a23SAndrzej Pietrasiewicz 	struct uvc_processing_unit_descriptor		uvc_processing;
5746919a23SAndrzej Pietrasiewicz 	struct uvc_output_terminal_descriptor		uvc_output_terminal;
5846919a23SAndrzej Pietrasiewicz 
5946919a23SAndrzej Pietrasiewicz 	/*
6046919a23SAndrzej Pietrasiewicz 	 * Control descriptors pointers arrays for full-/high-speed and
6146919a23SAndrzej Pietrasiewicz 	 * super-speed. The first element is a configurable control header
6246919a23SAndrzej Pietrasiewicz 	 * descriptor, the other elements point to the fixed default control
6346919a23SAndrzej Pietrasiewicz 	 * descriptors. Used by configfs only, must not be touched by legacy
6446919a23SAndrzej Pietrasiewicz 	 * gadgets.
6546919a23SAndrzej Pietrasiewicz 	 */
6646919a23SAndrzej Pietrasiewicz 	struct uvc_descriptor_header			*uvc_fs_control_cls[5];
6746919a23SAndrzej Pietrasiewicz 	struct uvc_descriptor_header			*uvc_ss_control_cls[5];
6846919a23SAndrzej Pietrasiewicz 
6946919a23SAndrzej Pietrasiewicz 	/*
700525210cSDaniel Scally 	 * Control descriptors for extension units. There could be any number
710525210cSDaniel Scally 	 * of these, including none at all.
720525210cSDaniel Scally 	 */
730525210cSDaniel Scally 	struct list_head				extension_units;
740525210cSDaniel Scally 
750525210cSDaniel Scally 	/*
7646919a23SAndrzej Pietrasiewicz 	 * Streaming descriptors for full-speed, high-speed and super-speed.
7746919a23SAndrzej Pietrasiewicz 	 * Used by configfs only, must not be touched by legacy gadgets. The
7846919a23SAndrzej Pietrasiewicz 	 * arrays are allocated at runtime as the number of descriptors isn't
7946919a23SAndrzej Pietrasiewicz 	 * known in advance.
8046919a23SAndrzej Pietrasiewicz 	 */
8146919a23SAndrzej Pietrasiewicz 	struct uvc_descriptor_header			**uvc_fs_streaming_cls;
8246919a23SAndrzej Pietrasiewicz 	struct uvc_descriptor_header			**uvc_hs_streaming_cls;
8346919a23SAndrzej Pietrasiewicz 	struct uvc_descriptor_header			**uvc_ss_streaming_cls;
8446919a23SAndrzej Pietrasiewicz 
8546919a23SAndrzej Pietrasiewicz 	/*
86fe625755SDaniel Scally 	 * Indexes into the function's string descriptors allowing users to set
87fe625755SDaniel Scally 	 * custom descriptions rather than the hard-coded defaults.
88fe625755SDaniel Scally 	 */
89fe625755SDaniel Scally 	u8						iad_index;
90fe625755SDaniel Scally 	u8						vs0_index;
91fe625755SDaniel Scally 	u8						vs1_index;
92fe625755SDaniel Scally 
93fe625755SDaniel Scally 	/*
9446919a23SAndrzej Pietrasiewicz 	 * Read/write access to configfs attributes is handled by configfs.
9546919a23SAndrzej Pietrasiewicz 	 *
9646919a23SAndrzej Pietrasiewicz 	 * This lock protects the descriptors from concurrent access by
9746919a23SAndrzej Pietrasiewicz 	 * read/write and symlink creation/removal.
9846919a23SAndrzej Pietrasiewicz 	 */
9946919a23SAndrzej Pietrasiewicz 	struct mutex			lock;
10046919a23SAndrzej Pietrasiewicz 	int				refcnt;
101*f1fd91a0SAndrzej Pietrasiewicz 
102*f1fd91a0SAndrzej Pietrasiewicz 	/*
103*f1fd91a0SAndrzej Pietrasiewicz 	 * Only for legacy gadget. Shall be NULL for configfs-composed gadgets,
104*f1fd91a0SAndrzej Pietrasiewicz 	 * which is guaranteed by alloc_inst implementation of f_uvc doing kzalloc.
105*f1fd91a0SAndrzej Pietrasiewicz 	 */
106*f1fd91a0SAndrzej Pietrasiewicz 	struct uvcg_streaming_header	*header;
1076d11ed76SAndrzej Pietrasiewicz };
1086d11ed76SAndrzej Pietrasiewicz 
1096d11ed76SAndrzej Pietrasiewicz #endif /* U_UVC_H */
110