Linux Audio

Check our new training course

Loading...
v4.6
 
  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 <media/v4l2-fh.h>
 60#include <media/v4l2-device.h>
 61
 62#include "uvc_queue.h"
 63
 64#define UVC_TRACE_PROBE				(1 << 0)
 65#define UVC_TRACE_DESCR				(1 << 1)
 66#define UVC_TRACE_CONTROL			(1 << 2)
 67#define UVC_TRACE_FORMAT			(1 << 3)
 68#define UVC_TRACE_CAPTURE			(1 << 4)
 69#define UVC_TRACE_CALLS				(1 << 5)
 70#define UVC_TRACE_IOCTL				(1 << 6)
 71#define UVC_TRACE_FRAME				(1 << 7)
 72#define UVC_TRACE_SUSPEND			(1 << 8)
 73#define UVC_TRACE_STATUS			(1 << 9)
 74
 75#define UVC_WARN_MINMAX				0
 76#define UVC_WARN_PROBE_DEF			1
 77
 78extern unsigned int uvc_gadget_trace_param;
 79
 80#define uvc_trace(flag, msg...) \
 81	do { \
 82		if (uvc_gadget_trace_param & flag) \
 83			printk(KERN_DEBUG "uvcvideo: " msg); \
 84	} while (0)
 85
 86#define uvc_warn_once(dev, warn, msg...) \
 87	do { \
 88		if (!test_and_set_bit(warn, &dev->warnings)) \
 89			printk(KERN_INFO "uvcvideo: " msg); \
 90	} while (0)
 91
 92#define uvc_printk(level, msg...) \
 93	printk(level "uvcvideo: " msg)
 94
 95/* ------------------------------------------------------------------------
 96 * Driver specific constants
 97 */
 98
 99#define UVC_NUM_REQUESTS			4
100#define UVC_MAX_REQUEST_SIZE			64
101#define UVC_MAX_EVENTS				4
102
103/* ------------------------------------------------------------------------
104 * Structures
105 */
106
107struct uvc_video
108{
109	struct usb_ep *ep;
110
111	/* Frame parameters */
112	u8 bpp;
113	u32 fcc;
114	unsigned int width;
115	unsigned int height;
116	unsigned int imagesize;
117	struct mutex mutex;	/* protects frame parameters */
118
119	/* Requests */
120	unsigned int req_size;
121	struct usb_request *req[UVC_NUM_REQUESTS];
122	__u8 *req_buffer[UVC_NUM_REQUESTS];
123	struct list_head req_free;
124	spinlock_t req_lock;
125
126	void (*encode) (struct usb_request *req, struct uvc_video *video,
127			struct uvc_buffer *buf);
128
129	/* Context data used by the completion handler */
130	__u32 payload_size;
131	__u32 max_payload_size;
132
133	struct uvc_video_queue queue;
134	unsigned int fid;
135};
136
137enum uvc_state
138{
139	UVC_STATE_DISCONNECTED,
140	UVC_STATE_CONNECTED,
141	UVC_STATE_STREAMING,
142};
143
144struct uvc_device
145{
146	struct video_device vdev;
147	struct v4l2_device v4l2_dev;
148	enum uvc_state state;
149	struct usb_function func;
150	struct uvc_video video;
151
152	/* Descriptors */
153	struct {
154		const struct uvc_descriptor_header * const *fs_control;
155		const struct uvc_descriptor_header * const *ss_control;
156		const struct uvc_descriptor_header * const *fs_streaming;
157		const struct uvc_descriptor_header * const *hs_streaming;
158		const struct uvc_descriptor_header * const *ss_streaming;
159	} desc;
160
161	unsigned int control_intf;
162	struct usb_ep *control_ep;
163	struct usb_request *control_req;
164	void *control_buf;
165
166	unsigned int streaming_intf;
167
168	/* Events */
169	unsigned int event_length;
170	unsigned int event_setup_out : 1;
171};
172
173static inline struct uvc_device *to_uvc(struct usb_function *f)
174{
175	return container_of(f, struct uvc_device, func);
176}
177
178struct uvc_file_handle
179{
180	struct v4l2_fh vfh;
181	struct uvc_video *device;
182};
183
184#define to_uvc_file_handle(handle) \
185	container_of(handle, struct uvc_file_handle, vfh)
186
187/* ------------------------------------------------------------------------
188 * Functions
189 */
190
191extern void uvc_function_setup_continue(struct uvc_device *uvc);
192extern void uvc_endpoint_stream(struct uvc_device *dev);
193
194extern void uvc_function_connect(struct uvc_device *uvc);
195extern void uvc_function_disconnect(struct uvc_device *uvc);
196
197#endif /* __KERNEL__ */
198
199#endif /* _UVC_GADGET_H_ */
200
v5.4
  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_ */