xref: /linux/drivers/usb/gadget/function/uvc_configfs.h (revision 79d2e1919a2728ef49d938eb20ebd5903c14dfb0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * uvc_configfs.h
4  *
5  * Configfs support for the uvc function.
6  *
7  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
8  *		http://www.samsung.com
9  *
10  * Author: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com>
11  */
12 #ifndef UVC_CONFIGFS_H
13 #define UVC_CONFIGFS_H
14 
15 #include <linux/configfs.h>
16 
17 #include "u_uvc.h"
18 
19 static inline struct f_uvc_opts *to_f_uvc_opts(struct config_item *item)
20 {
21 	return container_of(to_config_group(item), struct f_uvc_opts,
22 			    func_inst.group);
23 }
24 
25 #define UVCG_STREAMING_CONTROL_SIZE	1
26 
27 DECLARE_UVC_HEADER_DESCRIPTOR(1);
28 
29 struct uvcg_control_header {
30 	struct config_item		item;
31 	struct UVC_HEADER_DESCRIPTOR(1)	desc;
32 	unsigned			linked;
33 };
34 
35 static inline struct uvcg_control_header *to_uvcg_control_header(struct config_item *item)
36 {
37 	return container_of(item, struct uvcg_control_header, item);
38 }
39 
40 struct uvcg_color_matching {
41 	struct config_group group;
42 	struct uvc_color_matching_descriptor desc;
43 	unsigned int refcnt;
44 };
45 
46 #define to_uvcg_color_matching(group_ptr) \
47 container_of(group_ptr, struct uvcg_color_matching, group)
48 
49 enum uvcg_format_type {
50 	UVCG_UNCOMPRESSED = 0,
51 	UVCG_MJPEG,
52 	UVCG_FRAMEBASED,
53 };
54 
55 struct uvcg_format {
56 	struct config_group		group;
57 	enum uvcg_format_type		type;
58 	unsigned			linked;
59 	struct list_head		frames;
60 	unsigned			num_frames;
61 	__u8				bmaControls[UVCG_STREAMING_CONTROL_SIZE];
62 	struct uvcg_color_matching	*color_matching;
63 };
64 
65 struct uvcg_format_ptr {
66 	struct uvcg_format	*fmt;
67 	struct list_head	entry;
68 };
69 
70 static inline struct uvcg_format *to_uvcg_format(struct config_item *item)
71 {
72 	return container_of(to_config_group(item), struct uvcg_format, group);
73 }
74 
75 struct uvcg_streaming_header {
76 	struct config_item				item;
77 	struct uvc_input_header_descriptor		desc;
78 	unsigned					linked;
79 	struct list_head				formats;
80 	unsigned					num_fmt;
81 };
82 
83 static inline struct uvcg_streaming_header *to_uvcg_streaming_header(struct config_item *item)
84 {
85 	return container_of(item, struct uvcg_streaming_header, item);
86 }
87 
88 struct uvcg_frame_ptr {
89 	struct uvcg_frame	*frm;
90 	struct list_head	entry;
91 };
92 
93 struct uvcg_frame {
94 	struct config_item	item;
95 	enum uvcg_format_type	fmt_type;
96 	struct {
97 		u8	b_length;
98 		u8	b_descriptor_type;
99 		u8	b_descriptor_subtype;
100 		u8	b_frame_index;
101 		u8	bm_capabilities;
102 		u16	w_width;
103 		u16	w_height;
104 		u32	dw_min_bit_rate;
105 		u32	dw_max_bit_rate;
106 		u32	dw_max_video_frame_buffer_size;
107 		u32	dw_default_frame_interval;
108 		u8	b_frame_interval_type;
109 		u32     dw_bytes_perline;
110 	} __attribute__((packed)) frame;
111 	u32 *dw_frame_interval;
112 };
113 
114 static inline struct uvcg_frame *to_uvcg_frame(struct config_item *item)
115 {
116 	return container_of(item, struct uvcg_frame, item);
117 }
118 
119 /* -----------------------------------------------------------------------------
120  * streaming/uncompressed/<NAME>
121  */
122 
123 struct uvcg_uncompressed {
124 	struct uvcg_format		fmt;
125 	struct uvc_format_uncompressed	desc;
126 };
127 
128 static inline struct uvcg_uncompressed *to_uvcg_uncompressed(struct config_item *item)
129 {
130 	return container_of(to_uvcg_format(item), struct uvcg_uncompressed, fmt);
131 }
132 
133 /* -----------------------------------------------------------------------------
134  * streaming/mjpeg/<NAME>
135  */
136 
137 struct uvcg_mjpeg {
138 	struct uvcg_format		fmt;
139 	struct uvc_format_mjpeg		desc;
140 };
141 
142 static inline struct uvcg_mjpeg *to_uvcg_mjpeg(struct config_item *item)
143 {
144 	return container_of(to_uvcg_format(item), struct uvcg_mjpeg, fmt);
145 }
146 
147 /* -----------------------------------------------------------------------------
148  * streaming/framebased/<NAME>
149  */
150 
151 struct uvcg_framebased {
152 	struct uvcg_format              fmt;
153 	struct uvc_format_framebased    desc;
154 };
155 
156 static inline struct uvcg_framebased *to_uvcg_framebased(struct config_item *item)
157 {
158 	return container_of(to_uvcg_format(item), struct uvcg_framebased, fmt);
159 }
160 
161 /* -----------------------------------------------------------------------------
162  * control/extensions/<NAME>
163  */
164 
165 struct uvcg_extension_unit_descriptor {
166 	u8 bLength;
167 	u8 bDescriptorType;
168 	u8 bDescriptorSubType;
169 	u8 bUnitID;
170 	u8 guidExtensionCode[16];
171 	u8 bNumControls;
172 	u8 bNrInPins;
173 	u8 *baSourceID;
174 	u8 bControlSize;
175 	u8 *bmControls;
176 	u8 iExtension;
177 } __packed;
178 
179 struct uvcg_extension {
180 	struct config_item item;
181 	struct list_head list;
182 	u8 string_descriptor_index;
183 	struct uvcg_extension_unit_descriptor desc;
184 };
185 
186 static inline struct uvcg_extension *to_uvcg_extension(struct config_item *item)
187 {
188 	return container_of(item, struct uvcg_extension, item);
189 }
190 
191 int uvcg_attach_configfs(struct f_uvc_opts *opts);
192 
193 #endif /* UVC_CONFIGFS_H */
194