Loading...
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * uvc_gadget.h -- USB Video Class Gadget driver
4 *
5 * Copyright (C) 2009-2010
6 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7 */
8
9#ifndef _UVC_GADGET_H_
10#define _UVC_GADGET_H_
11
12#include <linux/list.h>
13#include <linux/mutex.h>
14#include <linux/spinlock.h>
15#include <linux/usb/composite.h>
16#include <linux/videodev2.h>
17#include <linux/wait.h>
18
19#include <media/v4l2-device.h>
20#include <media/v4l2-dev.h>
21#include <media/v4l2-fh.h>
22
23#include "uvc_queue.h"
24
25struct usb_ep;
26struct usb_request;
27struct uvc_descriptor_header;
28struct uvc_device;
29
30/* ------------------------------------------------------------------------
31 * Debugging, printing and logging
32 */
33
34#define UVC_TRACE_PROBE (1 << 0)
35#define UVC_TRACE_DESCR (1 << 1)
36#define UVC_TRACE_CONTROL (1 << 2)
37#define UVC_TRACE_FORMAT (1 << 3)
38#define UVC_TRACE_CAPTURE (1 << 4)
39#define UVC_TRACE_CALLS (1 << 5)
40#define UVC_TRACE_IOCTL (1 << 6)
41#define UVC_TRACE_FRAME (1 << 7)
42#define UVC_TRACE_SUSPEND (1 << 8)
43#define UVC_TRACE_STATUS (1 << 9)
44
45#define UVC_WARN_MINMAX 0
46#define UVC_WARN_PROBE_DEF 1
47
48extern unsigned int uvc_gadget_trace_param;
49
50#define uvc_trace(flag, msg...) \
51 do { \
52 if (uvc_gadget_trace_param & flag) \
53 printk(KERN_DEBUG "uvcvideo: " msg); \
54 } while (0)
55
56#define uvcg_dbg(f, fmt, args...) \
57 dev_dbg(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
58#define uvcg_info(f, fmt, args...) \
59 dev_info(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
60#define uvcg_warn(f, fmt, args...) \
61 dev_warn(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
62#define uvcg_err(f, fmt, args...) \
63 dev_err(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
64
65/* ------------------------------------------------------------------------
66 * Driver specific constants
67 */
68
69#define UVC_MAX_REQUEST_SIZE 64
70#define UVC_MAX_EVENTS 4
71
72#define UVCG_REQUEST_HEADER_LEN 12
73
74/* ------------------------------------------------------------------------
75 * Structures
76 */
77struct uvc_request {
78 struct usb_request *req;
79 u8 *req_buffer;
80 struct uvc_video *video;
81 struct sg_table sgt;
82 u8 header[UVCG_REQUEST_HEADER_LEN];
83 struct uvc_buffer *last_buf;
84};
85
86struct uvc_video {
87 struct uvc_device *uvc;
88 struct usb_ep *ep;
89
90 struct work_struct pump;
91 struct workqueue_struct *async_wq;
92
93 /* Frame parameters */
94 u8 bpp;
95 u32 fcc;
96 unsigned int width;
97 unsigned int height;
98 unsigned int imagesize;
99 struct mutex mutex; /* protects frame parameters */
100
101 unsigned int uvc_num_requests;
102
103 /* Requests */
104 unsigned int req_size;
105 struct uvc_request *ureq;
106 struct list_head req_free;
107 spinlock_t req_lock;
108
109 unsigned int req_int_count;
110
111 void (*encode) (struct usb_request *req, struct uvc_video *video,
112 struct uvc_buffer *buf);
113
114 /* Context data used by the completion handler */
115 __u32 payload_size;
116 __u32 max_payload_size;
117
118 struct uvc_video_queue queue;
119 unsigned int fid;
120};
121
122enum uvc_state {
123 UVC_STATE_DISCONNECTED,
124 UVC_STATE_CONNECTED,
125 UVC_STATE_STREAMING,
126};
127
128struct uvc_device {
129 struct video_device vdev;
130 struct v4l2_device v4l2_dev;
131 enum uvc_state state;
132 struct usb_function func;
133 struct uvc_video video;
134 bool func_connected;
135 wait_queue_head_t func_connected_queue;
136
137 struct uvcg_streaming_header *header;
138
139 /* Descriptors */
140 struct {
141 const struct uvc_descriptor_header * const *fs_control;
142 const struct uvc_descriptor_header * const *ss_control;
143 const struct uvc_descriptor_header * const *fs_streaming;
144 const struct uvc_descriptor_header * const *hs_streaming;
145 const struct uvc_descriptor_header * const *ss_streaming;
146 } desc;
147
148 unsigned int control_intf;
149 struct usb_ep *control_ep;
150 struct usb_request *control_req;
151 void *control_buf;
152
153 unsigned int streaming_intf;
154
155 /* Events */
156 unsigned int event_length;
157 unsigned int event_setup_out : 1;
158};
159
160static inline struct uvc_device *to_uvc(struct usb_function *f)
161{
162 return container_of(f, struct uvc_device, func);
163}
164
165struct uvc_file_handle {
166 struct v4l2_fh vfh;
167 struct uvc_video *device;
168 bool is_uvc_app_handle;
169};
170
171#define to_uvc_file_handle(handle) \
172 container_of(handle, struct uvc_file_handle, vfh)
173
174/* ------------------------------------------------------------------------
175 * Functions
176 */
177
178extern void uvc_function_setup_continue(struct uvc_device *uvc);
179extern void uvc_endpoint_stream(struct uvc_device *dev);
180
181extern void uvc_function_connect(struct uvc_device *uvc);
182extern void uvc_function_disconnect(struct uvc_device *uvc);
183
184#endif /* _UVC_GADGET_H_ */
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * uvc_gadget.h -- USB Video Class Gadget driver
4 *
5 * Copyright (C) 2009-2010
6 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7 */
8
9#ifndef _UVC_GADGET_H_
10#define _UVC_GADGET_H_
11
12#include <linux/list.h>
13#include <linux/mutex.h>
14#include <linux/spinlock.h>
15#include <linux/usb/composite.h>
16#include <linux/videodev2.h>
17
18#include <media/v4l2-device.h>
19#include <media/v4l2-dev.h>
20#include <media/v4l2-fh.h>
21
22#include "uvc_queue.h"
23
24struct usb_ep;
25struct usb_request;
26struct uvc_descriptor_header;
27struct uvc_device;
28
29/* ------------------------------------------------------------------------
30 * Debugging, printing and logging
31 */
32
33#define UVC_TRACE_PROBE (1 << 0)
34#define UVC_TRACE_DESCR (1 << 1)
35#define UVC_TRACE_CONTROL (1 << 2)
36#define UVC_TRACE_FORMAT (1 << 3)
37#define UVC_TRACE_CAPTURE (1 << 4)
38#define UVC_TRACE_CALLS (1 << 5)
39#define UVC_TRACE_IOCTL (1 << 6)
40#define UVC_TRACE_FRAME (1 << 7)
41#define UVC_TRACE_SUSPEND (1 << 8)
42#define UVC_TRACE_STATUS (1 << 9)
43
44#define UVC_WARN_MINMAX 0
45#define UVC_WARN_PROBE_DEF 1
46
47extern unsigned int uvc_gadget_trace_param;
48
49#define uvc_trace(flag, msg...) \
50 do { \
51 if (uvc_gadget_trace_param & flag) \
52 printk(KERN_DEBUG "uvcvideo: " msg); \
53 } while (0)
54
55#define uvcg_dbg(f, fmt, args...) \
56 dev_dbg(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
57#define uvcg_info(f, fmt, args...) \
58 dev_info(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
59#define uvcg_warn(f, fmt, args...) \
60 dev_warn(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
61#define uvcg_err(f, fmt, args...) \
62 dev_err(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
63
64/* ------------------------------------------------------------------------
65 * Driver specific constants
66 */
67
68#define UVC_NUM_REQUESTS 4
69#define UVC_MAX_REQUEST_SIZE 64
70#define UVC_MAX_EVENTS 4
71
72/* ------------------------------------------------------------------------
73 * Structures
74 */
75
76struct uvc_video {
77 struct uvc_device *uvc;
78 struct usb_ep *ep;
79
80 /* Frame parameters */
81 u8 bpp;
82 u32 fcc;
83 unsigned int width;
84 unsigned int height;
85 unsigned int imagesize;
86 struct mutex mutex; /* protects frame parameters */
87
88 /* Requests */
89 unsigned int req_size;
90 struct usb_request *req[UVC_NUM_REQUESTS];
91 __u8 *req_buffer[UVC_NUM_REQUESTS];
92 struct list_head req_free;
93 spinlock_t req_lock;
94
95 void (*encode) (struct usb_request *req, struct uvc_video *video,
96 struct uvc_buffer *buf);
97
98 /* Context data used by the completion handler */
99 __u32 payload_size;
100 __u32 max_payload_size;
101
102 struct uvc_video_queue queue;
103 unsigned int fid;
104};
105
106enum uvc_state {
107 UVC_STATE_DISCONNECTED,
108 UVC_STATE_CONNECTED,
109 UVC_STATE_STREAMING,
110};
111
112struct uvc_device {
113 struct video_device vdev;
114 struct v4l2_device v4l2_dev;
115 enum uvc_state state;
116 struct usb_function func;
117 struct uvc_video video;
118
119 /* Descriptors */
120 struct {
121 const struct uvc_descriptor_header * const *fs_control;
122 const struct uvc_descriptor_header * const *ss_control;
123 const struct uvc_descriptor_header * const *fs_streaming;
124 const struct uvc_descriptor_header * const *hs_streaming;
125 const struct uvc_descriptor_header * const *ss_streaming;
126 } desc;
127
128 unsigned int control_intf;
129 struct usb_ep *control_ep;
130 struct usb_request *control_req;
131 void *control_buf;
132
133 unsigned int streaming_intf;
134
135 /* Events */
136 unsigned int event_length;
137 unsigned int event_setup_out : 1;
138};
139
140static inline struct uvc_device *to_uvc(struct usb_function *f)
141{
142 return container_of(f, struct uvc_device, func);
143}
144
145struct uvc_file_handle {
146 struct v4l2_fh vfh;
147 struct uvc_video *device;
148};
149
150#define to_uvc_file_handle(handle) \
151 container_of(handle, struct uvc_file_handle, vfh)
152
153/* ------------------------------------------------------------------------
154 * Functions
155 */
156
157extern void uvc_function_setup_continue(struct uvc_device *uvc);
158extern void uvc_endpoint_stream(struct uvc_device *dev);
159
160extern void uvc_function_connect(struct uvc_device *uvc);
161extern void uvc_function_disconnect(struct uvc_device *uvc);
162
163#endif /* _UVC_GADGET_H_ */