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