Merge tag 'devprop-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[linux-block.git] / drivers / usb / gadget / function / uvc.h
CommitLineData
2e759738 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)
cdda479f
LP
7 */
8
9#ifndef _UVC_GADGET_H_
10#define _UVC_GADGET_H_
11
284eb166
LP
12#include <linux/list.h>
13#include <linux/mutex.h>
14#include <linux/spinlock.h>
3a83c16e 15#include <linux/usb/composite.h>
cdda479f 16#include <linux/videodev2.h>
b81ac439 17#include <linux/wait.h>
284eb166 18
b60f9aa1 19#include <media/v4l2-device.h>
284eb166
LP
20#include <media/v4l2-dev.h>
21#include <media/v4l2-fh.h>
cdda479f
LP
22
23#include "uvc_queue.h"
24
284eb166
LP
25struct usb_ep;
26struct usb_request;
27struct uvc_descriptor_header;
dc0f755b 28struct uvc_device;
284eb166 29
d396e47f
LP
30/* ------------------------------------------------------------------------
31 * Debugging, printing and logging
32 */
33
cdda479f
LP
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
5d9955f8 48extern unsigned int uvc_gadget_trace_param;
cdda479f
LP
49
50#define uvc_trace(flag, msg...) \
51 do { \
5d9955f8 52 if (uvc_gadget_trace_param & flag) \
cdda479f
LP
53 printk(KERN_DEBUG "uvcvideo: " msg); \
54 } while (0)
55
dc0f755b
LP
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)
e49107d8
PE
60#define uvcg_warn(f, fmt, args...) \
61 dev_warn(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
dc0f755b
LP
62#define uvcg_err(f, fmt, args...) \
63 dev_err(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
cdda479f
LP
64
65/* ------------------------------------------------------------------------
66 * Driver specific constants
67 */
68
cdda479f
LP
69#define UVC_MAX_REQUEST_SIZE 64
70#define UVC_MAX_EVENTS 4
71
fd03af27 72#define UVCG_REQUEST_HEADER_LEN 12
859c675d 73
cdda479f
LP
74/* ------------------------------------------------------------------------
75 * Structures
76 */
9973772d
MG
77struct uvc_request {
78 struct usb_request *req;
79 u8 *req_buffer;
80 struct uvc_video *video;
e81e7f9a 81 struct sg_table sgt;
859c675d 82 u8 header[UVCG_REQUEST_HEADER_LEN];
9973772d 83};
cdda479f 84
97f0117b 85struct uvc_video {
dc0f755b 86 struct uvc_device *uvc;
cdda479f
LP
87 struct usb_ep *ep;
88
43cd0023
MG
89 struct work_struct pump;
90
cdda479f
LP
91 /* Frame parameters */
92 u8 bpp;
93 u32 fcc;
94 unsigned int width;
95 unsigned int height;
96 unsigned int imagesize;
d8e96c4b 97 struct mutex mutex; /* protects frame parameters */
cdda479f 98
9973772d
MG
99 unsigned int uvc_num_requests;
100
cdda479f
LP
101 /* Requests */
102 unsigned int req_size;
9973772d 103 struct uvc_request *ureq;
cdda479f
LP
104 struct list_head req_free;
105 spinlock_t req_lock;
106
fc78941d
MG
107 unsigned int req_int_count;
108
cdda479f
LP
109 void (*encode) (struct usb_request *req, struct uvc_video *video,
110 struct uvc_buffer *buf);
111
112 /* Context data used by the completion handler */
113 __u32 payload_size;
114 __u32 max_payload_size;
115
116 struct uvc_video_queue queue;
117 unsigned int fid;
118};
119
97f0117b 120enum uvc_state {
cdda479f
LP
121 UVC_STATE_DISCONNECTED,
122 UVC_STATE_CONNECTED,
123 UVC_STATE_STREAMING,
124};
125
97f0117b 126struct uvc_device {
dbe98b30 127 struct video_device vdev;
b60f9aa1 128 struct v4l2_device v4l2_dev;
cdda479f
LP
129 enum uvc_state state;
130 struct usb_function func;
131 struct uvc_video video;
72ee48ee 132 bool func_connected;
b81ac439 133 wait_queue_head_t func_connected_queue;
cdda479f
LP
134
135 /* Descriptors */
136 struct {
fbcaba0e
BS
137 const struct uvc_descriptor_header * const *fs_control;
138 const struct uvc_descriptor_header * const *ss_control;
cdda479f
LP
139 const struct uvc_descriptor_header * const *fs_streaming;
140 const struct uvc_descriptor_header * const *hs_streaming;
fbcaba0e 141 const struct uvc_descriptor_header * const *ss_streaming;
cdda479f
LP
142 } desc;
143
144 unsigned int control_intf;
145 struct usb_ep *control_ep;
146 struct usb_request *control_req;
147 void *control_buf;
148
149 unsigned int streaming_intf;
150
151 /* Events */
152 unsigned int event_length;
153 unsigned int event_setup_out : 1;
154};
155
156static inline struct uvc_device *to_uvc(struct usb_function *f)
157{
158 return container_of(f, struct uvc_device, func);
159}
160
97f0117b 161struct uvc_file_handle {
cdda479f
LP
162 struct v4l2_fh vfh;
163 struct uvc_video *device;
72ee48ee 164 bool is_uvc_app_handle;
cdda479f
LP
165};
166
167#define to_uvc_file_handle(handle) \
168 container_of(handle, struct uvc_file_handle, vfh)
169
cdda479f
LP
170/* ------------------------------------------------------------------------
171 * Functions
172 */
173
41837c35 174extern void uvc_function_setup_continue(struct uvc_device *uvc);
cdda479f
LP
175extern void uvc_endpoint_stream(struct uvc_device *dev);
176
177extern void uvc_function_connect(struct uvc_device *uvc);
178extern void uvc_function_disconnect(struct uvc_device *uvc);
179
cdda479f 180#endif /* _UVC_GADGET_H_ */