Linux Audio

Check our new training course

Embedded Linux training

Mar 31-Apr 8, 2025
Register
Loading...
v3.1
  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
 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
 30struct uvc_request_data
 31{
 32	unsigned int length;
 33	__u8 data[60];
 34};
 35
 36struct uvc_event
 37{
 38	union {
 39		enum usb_device_speed speed;
 40		struct usb_ctrlrequest req;
 41		struct uvc_request_data data;
 42	};
 43};
 44
 45#define UVCIOC_SEND_RESPONSE		_IOW('U', 1, struct uvc_request_data)
 46
 47#define UVC_INTF_CONTROL		0
 48#define UVC_INTF_STREAMING		1
 49
 50/* ------------------------------------------------------------------------
 51 * Debugging, printing and logging
 52 */
 53
 54#ifdef __KERNEL__
 55
 56#include <linux/usb.h>	/* For usb_endpoint_* */
 57#include <linux/usb/gadget.h>
 58#include <linux/videodev2.h>
 
 59#include <media/v4l2-fh.h>
 
 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
 77extern unsigned int uvc_gadget_trace_param;
 78
 79#define uvc_trace(flag, msg...) \
 80	do { \
 81		if (uvc_gadget_trace_param & flag) \
 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
 98#define DRIVER_VERSION				"0.1.0"
 99#define DRIVER_VERSION_NUMBER			KERNEL_VERSION(0, 1, 0)
100
101#define DMA_ADDR_INVALID			(~(dma_addr_t)0)
102
103#define UVC_NUM_REQUESTS			4
104#define UVC_MAX_REQUEST_SIZE			64
105#define UVC_MAX_EVENTS				4
106
107/* ------------------------------------------------------------------------
108 * Structures
109 */
110
111struct uvc_video
112{
113	struct usb_ep *ep;
114
115	/* Frame parameters */
116	u8 bpp;
117	u32 fcc;
118	unsigned int width;
119	unsigned int height;
120	unsigned int imagesize;
121
122	/* Requests */
123	unsigned int req_size;
124	struct usb_request *req[UVC_NUM_REQUESTS];
125	__u8 *req_buffer[UVC_NUM_REQUESTS];
126	struct list_head req_free;
127	spinlock_t req_lock;
128
129	void (*encode) (struct usb_request *req, struct uvc_video *video,
130			struct uvc_buffer *buf);
131
132	/* Context data used by the completion handler */
133	__u32 payload_size;
134	__u32 max_payload_size;
135
136	struct uvc_video_queue queue;
137	unsigned int fid;
138};
139
140enum uvc_state
141{
142	UVC_STATE_DISCONNECTED,
143	UVC_STATE_CONNECTED,
144	UVC_STATE_STREAMING,
145};
146
147struct uvc_device
148{
149	struct video_device *vdev;
 
150	enum uvc_state state;
151	struct usb_function func;
152	struct uvc_video video;
153
154	/* Descriptors */
155	struct {
156		const struct uvc_descriptor_header * const *control;
 
157		const struct uvc_descriptor_header * const *fs_streaming;
158		const struct uvc_descriptor_header * const *hs_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_endpoint_stream(struct uvc_device *dev);
192
193extern void uvc_function_connect(struct uvc_device *uvc);
194extern void uvc_function_disconnect(struct uvc_device *uvc);
195
196#endif /* __KERNEL__ */
197
198#endif /* _UVC_GADGET_H_ */
199
v3.15
  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/gadget.h>
 57#include <linux/videodev2.h>
 58#include <linux/version.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 DRIVER_VERSION				"0.1.0"
100#define DRIVER_VERSION_NUMBER			KERNEL_VERSION(0, 1, 0)
101
 
 
102#define UVC_NUM_REQUESTS			4
103#define UVC_MAX_REQUEST_SIZE			64
104#define UVC_MAX_EVENTS				4
105
106/* ------------------------------------------------------------------------
107 * Structures
108 */
109
110struct uvc_video
111{
112	struct usb_ep *ep;
113
114	/* Frame parameters */
115	u8 bpp;
116	u32 fcc;
117	unsigned int width;
118	unsigned int height;
119	unsigned int imagesize;
120
121	/* Requests */
122	unsigned int req_size;
123	struct usb_request *req[UVC_NUM_REQUESTS];
124	__u8 *req_buffer[UVC_NUM_REQUESTS];
125	struct list_head req_free;
126	spinlock_t req_lock;
127
128	void (*encode) (struct usb_request *req, struct uvc_video *video,
129			struct uvc_buffer *buf);
130
131	/* Context data used by the completion handler */
132	__u32 payload_size;
133	__u32 max_payload_size;
134
135	struct uvc_video_queue queue;
136	unsigned int fid;
137};
138
139enum uvc_state
140{
141	UVC_STATE_DISCONNECTED,
142	UVC_STATE_CONNECTED,
143	UVC_STATE_STREAMING,
144};
145
146struct uvc_device
147{
148	struct video_device *vdev;
149	struct v4l2_device v4l2_dev;
150	enum uvc_state state;
151	struct usb_function func;
152	struct uvc_video video;
153
154	/* Descriptors */
155	struct {
156		const struct uvc_descriptor_header * const *fs_control;
157		const struct uvc_descriptor_header * const *ss_control;
158		const struct uvc_descriptor_header * const *fs_streaming;
159		const struct uvc_descriptor_header * const *hs_streaming;
160		const struct uvc_descriptor_header * const *ss_streaming;
161	} desc;
162
163	unsigned int control_intf;
164	struct usb_ep *control_ep;
165	struct usb_request *control_req;
166	void *control_buf;
167
168	unsigned int streaming_intf;
169
170	/* Events */
171	unsigned int event_length;
172	unsigned int event_setup_out : 1;
173};
174
175static inline struct uvc_device *to_uvc(struct usb_function *f)
176{
177	return container_of(f, struct uvc_device, func);
178}
179
180struct uvc_file_handle
181{
182	struct v4l2_fh vfh;
183	struct uvc_video *device;
184};
185
186#define to_uvc_file_handle(handle) \
187	container_of(handle, struct uvc_file_handle, vfh)
188
189/* ------------------------------------------------------------------------
190 * Functions
191 */
192
193extern void uvc_function_setup_continue(struct uvc_device *uvc);
194extern void uvc_endpoint_stream(struct uvc_device *dev);
195
196extern void uvc_function_connect(struct uvc_device *uvc);
197extern void uvc_function_disconnect(struct uvc_device *uvc);
198
199#endif /* __KERNEL__ */
200
201#endif /* _UVC_GADGET_H_ */
202