1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * uvc_gadget.h -- USB Video Class Gadget driver
5 * Copyright (C) 2009-2010
6 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
10 #define _UVC_GADGET_H_
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>
18 #include <media/v4l2-device.h>
19 #include <media/v4l2-dev.h>
20 #include <media/v4l2-fh.h>
22 #include "uvc_queue.h"
26 struct uvc_descriptor_header
;
29 /* ------------------------------------------------------------------------
30 * Debugging, printing and logging
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)
44 #define UVC_WARN_MINMAX 0
45 #define UVC_WARN_PROBE_DEF 1
47 extern unsigned int uvc_gadget_trace_param
;
49 #define uvc_trace(flag, msg...) \
51 if (uvc_gadget_trace_param & flag) \
52 printk(KERN_DEBUG "uvcvideo: " msg); \
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)
64 /* ------------------------------------------------------------------------
65 * Driver specific constants
68 #define UVC_NUM_REQUESTS 4
69 #define UVC_MAX_REQUEST_SIZE 64
70 #define UVC_MAX_EVENTS 4
72 /* ------------------------------------------------------------------------
77 struct uvc_device
*uvc
;
80 struct work_struct pump
;
82 /* Frame parameters */
87 unsigned int imagesize
;
88 struct mutex mutex
; /* protects frame parameters */
91 unsigned int req_size
;
92 struct usb_request
*req
[UVC_NUM_REQUESTS
];
93 __u8
*req_buffer
[UVC_NUM_REQUESTS
];
94 struct list_head req_free
;
97 void (*encode
) (struct usb_request
*req
, struct uvc_video
*video
,
98 struct uvc_buffer
*buf
);
100 /* Context data used by the completion handler */
102 __u32 max_payload_size
;
104 struct uvc_video_queue queue
;
109 UVC_STATE_DISCONNECTED
,
115 struct video_device vdev
;
116 struct v4l2_device v4l2_dev
;
117 enum uvc_state state
;
118 struct usb_function func
;
119 struct uvc_video video
;
123 const struct uvc_descriptor_header
* const *fs_control
;
124 const struct uvc_descriptor_header
* const *ss_control
;
125 const struct uvc_descriptor_header
* const *fs_streaming
;
126 const struct uvc_descriptor_header
* const *hs_streaming
;
127 const struct uvc_descriptor_header
* const *ss_streaming
;
130 unsigned int control_intf
;
131 struct usb_ep
*control_ep
;
132 struct usb_request
*control_req
;
135 unsigned int streaming_intf
;
138 unsigned int event_length
;
139 unsigned int event_setup_out
: 1;
142 static inline struct uvc_device
*to_uvc(struct usb_function
*f
)
144 return container_of(f
, struct uvc_device
, func
);
147 struct uvc_file_handle
{
149 struct uvc_video
*device
;
152 #define to_uvc_file_handle(handle) \
153 container_of(handle, struct uvc_file_handle, vfh)
155 /* ------------------------------------------------------------------------
159 extern void uvc_function_setup_continue(struct uvc_device
*uvc
);
160 extern void uvc_endpoint_stream(struct uvc_device
*dev
);
162 extern void uvc_function_connect(struct uvc_device
*uvc
);
163 extern void uvc_function_disconnect(struct uvc_device
*uvc
);
165 #endif /* _UVC_GADGET_H_ */