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
to_f_uvc_opts(struct config_item * item)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
to_uvcg_control_header(struct config_item * item)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 enum uvcg_format_type {
41 UVCG_UNCOMPRESSED = 0,
42 UVCG_MJPEG,
43 };
44
45 struct uvcg_format {
46 struct config_group group;
47 enum uvcg_format_type type;
48 unsigned linked;
49 struct list_head frames;
50 unsigned num_frames;
51 __u8 bmaControls[UVCG_STREAMING_CONTROL_SIZE];
52 };
53
54 struct uvcg_format_ptr {
55 struct uvcg_format *fmt;
56 struct list_head entry;
57 };
58
to_uvcg_format(struct config_item * item)59 static inline struct uvcg_format *to_uvcg_format(struct config_item *item)
60 {
61 return container_of(to_config_group(item), struct uvcg_format, group);
62 }
63
64 struct uvcg_streaming_header {
65 struct config_item item;
66 struct uvc_input_header_descriptor desc;
67 unsigned linked;
68 struct list_head formats;
69 unsigned num_fmt;
70 };
71
to_uvcg_streaming_header(struct config_item * item)72 static inline struct uvcg_streaming_header *to_uvcg_streaming_header(struct config_item *item)
73 {
74 return container_of(item, struct uvcg_streaming_header, item);
75 }
76
77 struct uvcg_frame_ptr {
78 struct uvcg_frame *frm;
79 struct list_head entry;
80 };
81
82 struct uvcg_frame {
83 struct config_item item;
84 enum uvcg_format_type fmt_type;
85 struct {
86 u8 b_length;
87 u8 b_descriptor_type;
88 u8 b_descriptor_subtype;
89 u8 b_frame_index;
90 u8 bm_capabilities;
91 u16 w_width;
92 u16 w_height;
93 u32 dw_min_bit_rate;
94 u32 dw_max_bit_rate;
95 u32 dw_max_video_frame_buffer_size;
96 u32 dw_default_frame_interval;
97 u8 b_frame_interval_type;
98 } __attribute__((packed)) frame;
99 u32 *dw_frame_interval;
100 };
101
to_uvcg_frame(struct config_item * item)102 static inline struct uvcg_frame *to_uvcg_frame(struct config_item *item)
103 {
104 return container_of(item, struct uvcg_frame, item);
105 }
106
107 /* -----------------------------------------------------------------------------
108 * streaming/uncompressed/<NAME>
109 */
110
111 struct uvcg_uncompressed {
112 struct uvcg_format fmt;
113 struct uvc_format_uncompressed desc;
114 };
115
to_uvcg_uncompressed(struct config_item * item)116 static inline struct uvcg_uncompressed *to_uvcg_uncompressed(struct config_item *item)
117 {
118 return container_of(to_uvcg_format(item), struct uvcg_uncompressed, fmt);
119 }
120
121 /* -----------------------------------------------------------------------------
122 * streaming/mjpeg/<NAME>
123 */
124
125 struct uvcg_mjpeg {
126 struct uvcg_format fmt;
127 struct uvc_format_mjpeg desc;
128 };
129
to_uvcg_mjpeg(struct config_item * item)130 static inline struct uvcg_mjpeg *to_uvcg_mjpeg(struct config_item *item)
131 {
132 return container_of(to_uvcg_format(item), struct uvcg_mjpeg, fmt);
133 }
134
135 int uvcg_attach_configfs(struct f_uvc_opts *opts);
136
137 #endif /* UVC_CONFIGFS_H */
138