]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/usb/gadget/function/uvc.h
USB: add SPDX identifiers to all remaining files in drivers/usb/
[mirror_ubuntu-jammy-kernel.git] / drivers / usb / gadget / function / uvc.h
CommitLineData
5fd54ace 1// SPDX-License-Identifier: GPL-2.0+
cdda479f
LP
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 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
cdda479f
LP
12 */
13
14#ifndef _UVC_GADGET_H_
15#define _UVC_GADGET_H_
16
17#include <linux/ioctl.h>
18#include <linux/types.h>
19#include <linux/usb/ch9.h>
20
21#define UVC_EVENT_FIRST (V4L2_EVENT_PRIVATE_START + 0)
22#define UVC_EVENT_CONNECT (V4L2_EVENT_PRIVATE_START + 0)
23#define UVC_EVENT_DISCONNECT (V4L2_EVENT_PRIVATE_START + 1)
24#define UVC_EVENT_STREAMON (V4L2_EVENT_PRIVATE_START + 2)
25#define UVC_EVENT_STREAMOFF (V4L2_EVENT_PRIVATE_START + 3)
26#define UVC_EVENT_SETUP (V4L2_EVENT_PRIVATE_START + 4)
27#define UVC_EVENT_DATA (V4L2_EVENT_PRIVATE_START + 5)
28#define UVC_EVENT_LAST (V4L2_EVENT_PRIVATE_START + 5)
29
97f0117b 30struct uvc_request_data {
6f6543f5 31 __s32 length;
cdda479f
LP
32 __u8 data[60];
33};
34
97f0117b 35struct uvc_event {
cdda479f
LP
36 union {
37 enum usb_device_speed speed;
38 struct usb_ctrlrequest req;
39 struct uvc_request_data data;
40 };
41};
42
43#define UVCIOC_SEND_RESPONSE _IOW('U', 1, struct uvc_request_data)
44
45#define UVC_INTF_CONTROL 0
46#define UVC_INTF_STREAMING 1
47
cdda479f
LP
48/* ------------------------------------------------------------------------
49 * Debugging, printing and logging
50 */
51
52#ifdef __KERNEL__
53
54#include <linux/usb.h> /* For usb_endpoint_* */
3a83c16e 55#include <linux/usb/composite.h>
cdda479f
LP
56#include <linux/usb/gadget.h>
57#include <linux/videodev2.h>
58#include <media/v4l2-fh.h>
b60f9aa1 59#include <media/v4l2-device.h>
cdda479f
LP
60
61#include "uvc_queue.h"
62
63#define UVC_TRACE_PROBE (1 << 0)
64#define UVC_TRACE_DESCR (1 << 1)
65#define UVC_TRACE_CONTROL (1 << 2)
66#define UVC_TRACE_FORMAT (1 << 3)
67#define UVC_TRACE_CAPTURE (1 << 4)
68#define UVC_TRACE_CALLS (1 << 5)
69#define UVC_TRACE_IOCTL (1 << 6)
70#define UVC_TRACE_FRAME (1 << 7)
71#define UVC_TRACE_SUSPEND (1 << 8)
72#define UVC_TRACE_STATUS (1 << 9)
73
74#define UVC_WARN_MINMAX 0
75#define UVC_WARN_PROBE_DEF 1
76
5d9955f8 77extern unsigned int uvc_gadget_trace_param;
cdda479f
LP
78
79#define uvc_trace(flag, msg...) \
80 do { \
5d9955f8 81 if (uvc_gadget_trace_param & flag) \
cdda479f
LP
82 printk(KERN_DEBUG "uvcvideo: " msg); \
83 } while (0)
84
85#define uvc_warn_once(dev, warn, msg...) \
86 do { \
87 if (!test_and_set_bit(warn, &dev->warnings)) \
88 printk(KERN_INFO "uvcvideo: " msg); \
89 } while (0)
90
91#define uvc_printk(level, msg...) \
92 printk(level "uvcvideo: " msg)
93
94/* ------------------------------------------------------------------------
95 * Driver specific constants
96 */
97
cdda479f
LP
98#define UVC_NUM_REQUESTS 4
99#define UVC_MAX_REQUEST_SIZE 64
100#define UVC_MAX_EVENTS 4
101
cdda479f
LP
102/* ------------------------------------------------------------------------
103 * Structures
104 */
105
97f0117b 106struct uvc_video {
cdda479f
LP
107 struct usb_ep *ep;
108
109 /* Frame parameters */
110 u8 bpp;
111 u32 fcc;
112 unsigned int width;
113 unsigned int height;
114 unsigned int imagesize;
d8e96c4b 115 struct mutex mutex; /* protects frame parameters */
cdda479f
LP
116
117 /* Requests */
118 unsigned int req_size;
119 struct usb_request *req[UVC_NUM_REQUESTS];
120 __u8 *req_buffer[UVC_NUM_REQUESTS];
121 struct list_head req_free;
122 spinlock_t req_lock;
123
124 void (*encode) (struct usb_request *req, struct uvc_video *video,
125 struct uvc_buffer *buf);
126
127 /* Context data used by the completion handler */
128 __u32 payload_size;
129 __u32 max_payload_size;
130
131 struct uvc_video_queue queue;
132 unsigned int fid;
133};
134
97f0117b 135enum uvc_state {
cdda479f
LP
136 UVC_STATE_DISCONNECTED,
137 UVC_STATE_CONNECTED,
138 UVC_STATE_STREAMING,
139};
140
97f0117b 141struct uvc_device {
dbe98b30 142 struct video_device vdev;
b60f9aa1 143 struct v4l2_device v4l2_dev;
cdda479f
LP
144 enum uvc_state state;
145 struct usb_function func;
146 struct uvc_video video;
147
148 /* Descriptors */
149 struct {
fbcaba0e
BS
150 const struct uvc_descriptor_header * const *fs_control;
151 const struct uvc_descriptor_header * const *ss_control;
cdda479f
LP
152 const struct uvc_descriptor_header * const *fs_streaming;
153 const struct uvc_descriptor_header * const *hs_streaming;
fbcaba0e 154 const struct uvc_descriptor_header * const *ss_streaming;
cdda479f
LP
155 } desc;
156
157 unsigned int control_intf;
158 struct usb_ep *control_ep;
159 struct usb_request *control_req;
160 void *control_buf;
161
162 unsigned int streaming_intf;
163
164 /* Events */
165 unsigned int event_length;
166 unsigned int event_setup_out : 1;
167};
168
169static inline struct uvc_device *to_uvc(struct usb_function *f)
170{
171 return container_of(f, struct uvc_device, func);
172}
173
97f0117b 174struct uvc_file_handle {
cdda479f
LP
175 struct v4l2_fh vfh;
176 struct uvc_video *device;
177};
178
179#define to_uvc_file_handle(handle) \
180 container_of(handle, struct uvc_file_handle, vfh)
181
cdda479f
LP
182/* ------------------------------------------------------------------------
183 * Functions
184 */
185
41837c35 186extern void uvc_function_setup_continue(struct uvc_device *uvc);
cdda479f
LP
187extern void uvc_endpoint_stream(struct uvc_device *dev);
188
189extern void uvc_function_connect(struct uvc_device *uvc);
190extern void uvc_function_disconnect(struct uvc_device *uvc);
191
192#endif /* __KERNEL__ */
193
194#endif /* _UVC_GADGET_H_ */
195