162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * u_uvc.h
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Utility definitions for the uvc function
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (c) 2013-2014 Samsung Electronics Co., Ltd.
862306a36Sopenharmony_ci *		http://www.samsung.com
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci * Author: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com>
1162306a36Sopenharmony_ci */
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#ifndef U_UVC_H
1462306a36Sopenharmony_ci#define U_UVC_H
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#include <linux/mutex.h>
1762306a36Sopenharmony_ci#include <linux/usb/composite.h>
1862306a36Sopenharmony_ci#include <linux/usb/video.h>
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#define fi_to_f_uvc_opts(f)	container_of(f, struct f_uvc_opts, func_inst)
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_cistruct f_uvc_opts {
2362306a36Sopenharmony_ci	struct usb_function_instance			func_inst;
2462306a36Sopenharmony_ci	unsigned int					streaming_interval;
2562306a36Sopenharmony_ci	unsigned int					streaming_maxpacket;
2662306a36Sopenharmony_ci	unsigned int					streaming_maxburst;
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci	unsigned int					control_interface;
2962306a36Sopenharmony_ci	unsigned int					streaming_interface;
3062306a36Sopenharmony_ci	char						function_name[32];
3162306a36Sopenharmony_ci	unsigned int					last_unit_id;
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci	bool						enable_interrupt_ep;
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci	/*
3662306a36Sopenharmony_ci	 * Control descriptors array pointers for full-/high-speed and
3762306a36Sopenharmony_ci	 * super-speed. They point by default to the uvc_fs_control_cls and
3862306a36Sopenharmony_ci	 * uvc_ss_control_cls arrays respectively. Legacy gadgets must
3962306a36Sopenharmony_ci	 * override them in their gadget bind callback.
4062306a36Sopenharmony_ci	 */
4162306a36Sopenharmony_ci	const struct uvc_descriptor_header * const	*fs_control;
4262306a36Sopenharmony_ci	const struct uvc_descriptor_header * const	*ss_control;
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci	/*
4562306a36Sopenharmony_ci	 * Streaming descriptors array pointers for full-speed, high-speed and
4662306a36Sopenharmony_ci	 * super-speed. They will point to the uvc_[fhs]s_streaming_cls arrays
4762306a36Sopenharmony_ci	 * for configfs-based gadgets. Legacy gadgets must initialize them in
4862306a36Sopenharmony_ci	 * their gadget bind callback.
4962306a36Sopenharmony_ci	 */
5062306a36Sopenharmony_ci	const struct uvc_descriptor_header * const	*fs_streaming;
5162306a36Sopenharmony_ci	const struct uvc_descriptor_header * const	*hs_streaming;
5262306a36Sopenharmony_ci	const struct uvc_descriptor_header * const	*ss_streaming;
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci	/* Default control descriptors for configfs-based gadgets. */
5562306a36Sopenharmony_ci	struct uvc_camera_terminal_descriptor		uvc_camera_terminal;
5662306a36Sopenharmony_ci	struct uvc_processing_unit_descriptor		uvc_processing;
5762306a36Sopenharmony_ci	struct uvc_output_terminal_descriptor		uvc_output_terminal;
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	/*
6062306a36Sopenharmony_ci	 * Control descriptors pointers arrays for full-/high-speed and
6162306a36Sopenharmony_ci	 * super-speed. The first element is a configurable control header
6262306a36Sopenharmony_ci	 * descriptor, the other elements point to the fixed default control
6362306a36Sopenharmony_ci	 * descriptors. Used by configfs only, must not be touched by legacy
6462306a36Sopenharmony_ci	 * gadgets.
6562306a36Sopenharmony_ci	 */
6662306a36Sopenharmony_ci	struct uvc_descriptor_header			*uvc_fs_control_cls[5];
6762306a36Sopenharmony_ci	struct uvc_descriptor_header			*uvc_ss_control_cls[5];
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci	/*
7062306a36Sopenharmony_ci	 * Control descriptors for extension units. There could be any number
7162306a36Sopenharmony_ci	 * of these, including none at all.
7262306a36Sopenharmony_ci	 */
7362306a36Sopenharmony_ci	struct list_head				extension_units;
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci	/*
7662306a36Sopenharmony_ci	 * Streaming descriptors for full-speed, high-speed and super-speed.
7762306a36Sopenharmony_ci	 * Used by configfs only, must not be touched by legacy gadgets. The
7862306a36Sopenharmony_ci	 * arrays are allocated at runtime as the number of descriptors isn't
7962306a36Sopenharmony_ci	 * known in advance.
8062306a36Sopenharmony_ci	 */
8162306a36Sopenharmony_ci	struct uvc_descriptor_header			**uvc_fs_streaming_cls;
8262306a36Sopenharmony_ci	struct uvc_descriptor_header			**uvc_hs_streaming_cls;
8362306a36Sopenharmony_ci	struct uvc_descriptor_header			**uvc_ss_streaming_cls;
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci	/*
8662306a36Sopenharmony_ci	 * Indexes into the function's string descriptors allowing users to set
8762306a36Sopenharmony_ci	 * custom descriptions rather than the hard-coded defaults.
8862306a36Sopenharmony_ci	 */
8962306a36Sopenharmony_ci	u8						iad_index;
9062306a36Sopenharmony_ci	u8						vs0_index;
9162306a36Sopenharmony_ci	u8						vs1_index;
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci	/*
9462306a36Sopenharmony_ci	 * Read/write access to configfs attributes is handled by configfs.
9562306a36Sopenharmony_ci	 *
9662306a36Sopenharmony_ci	 * This lock protects the descriptors from concurrent access by
9762306a36Sopenharmony_ci	 * read/write and symlink creation/removal.
9862306a36Sopenharmony_ci	 */
9962306a36Sopenharmony_ci	struct mutex			lock;
10062306a36Sopenharmony_ci	int				refcnt;
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci	/*
10362306a36Sopenharmony_ci	 * Only for legacy gadget. Shall be NULL for configfs-composed gadgets,
10462306a36Sopenharmony_ci	 * which is guaranteed by alloc_inst implementation of f_uvc doing kzalloc.
10562306a36Sopenharmony_ci	 */
10662306a36Sopenharmony_ci	struct uvcg_streaming_header	*header;
10762306a36Sopenharmony_ci};
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci#endif /* U_UVC_H */
110