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 };
53 
54 struct uvcg_format {
55 	struct config_group		group;
56 	enum uvcg_format_type		type;
57 	unsigned			linked;
58 	struct list_head		frames;
59 	unsigned			num_frames;
60 	__u8				bmaControls[UVCG_STREAMING_CONTROL_SIZE];
61 	struct uvcg_color_matching	*color_matching;
62 };
63 
64 struct uvcg_format_ptr {
65 	struct uvcg_format	*fmt;
66 	struct list_head	entry;
67 };
68 
69 static inline struct uvcg_format *to_uvcg_format(struct config_item *item)
70 {
71 	return container_of(to_config_group(item), struct uvcg_format, group);
72 }
73 
74 struct uvcg_streaming_header {
75 	struct config_item				item;
76 	struct uvc_input_header_descriptor		desc;
77 	unsigned					linked;
78 	struct list_head				formats;
79 	unsigned					num_fmt;
80 };
81 
82 static inline struct uvcg_streaming_header *to_uvcg_streaming_header(struct config_item *item)
83 {
84 	return container_of(item, struct uvcg_streaming_header, item);
85 }
86 
87 struct uvcg_frame_ptr {
88 	struct uvcg_frame	*frm;
89 	struct list_head	entry;
90 };
91 
92 struct uvcg_frame {
93 	struct config_item	item;
94 	enum uvcg_format_type	fmt_type;
95 	struct {
96 		u8	b_length;
97 		u8	b_descriptor_type;
98 		u8	b_descriptor_subtype;
99 		u8	b_frame_index;
100 		u8	bm_capabilities;
101 		u16	w_width;
102 		u16	w_height;
103 		u32	dw_min_bit_rate;
104 		u32	dw_max_bit_rate;
105 		u32	dw_max_video_frame_buffer_size;
106 		u32	dw_default_frame_interval;
107 		u8	b_frame_interval_type;
108 	} __attribute__((packed)) frame;
109 	u32 *dw_frame_interval;
110 };
111 
112 static inline struct uvcg_frame *to_uvcg_frame(struct config_item *item)
113 {
114 	return container_of(item, struct uvcg_frame, item);
115 }
116 
117 /* -----------------------------------------------------------------------------
118  * streaming/uncompressed/<NAME>
119  */
120 
121 struct uvcg_uncompressed {
122 	struct uvcg_format		fmt;
123 	struct uvc_format_uncompressed	desc;
124 };
125 
126 static inline struct uvcg_uncompressed *to_uvcg_uncompressed(struct config_item *item)
127 {
128 	return container_of(to_uvcg_format(item), struct uvcg_uncompressed, fmt);
129 }
130 
131 /* -----------------------------------------------------------------------------
132  * streaming/mjpeg/<NAME>
133  */
134 
135 struct uvcg_mjpeg {
136 	struct uvcg_format		fmt;
137 	struct uvc_format_mjpeg		desc;
138 };
139 
140 static inline struct uvcg_mjpeg *to_uvcg_mjpeg(struct config_item *item)
141 {
142 	return container_of(to_uvcg_format(item), struct uvcg_mjpeg, fmt);
143 }
144 
145 /* -----------------------------------------------------------------------------
146  * control/extensions/<NAME>
147  */
148 
149 struct uvcg_extension_unit_descriptor {
150 	u8 bLength;
151 	u8 bDescriptorType;
152 	u8 bDescriptorSubType;
153 	u8 bUnitID;
154 	u8 guidExtensionCode[16];
155 	u8 bNumControls;
156 	u8 bNrInPins;
157 	u8 *baSourceID;
158 	u8 bControlSize;
159 	u8 *bmControls;
160 	u8 iExtension;
161 } __packed;
162 
163 struct uvcg_extension {
164 	struct config_item item;
165 	struct list_head list;
166 	u8 string_descriptor_index;
167 	struct uvcg_extension_unit_descriptor desc;
168 };
169 
170 static inline struct uvcg_extension *to_uvcg_extension(struct config_item *item)
171 {
172 	return container_of(item, struct uvcg_extension, item);
173 }
174 
175 int uvcg_attach_configfs(struct f_uvc_opts *opts);
176 
177 #endif /* UVC_CONFIGFS_H */
178