Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0+ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *	uvc_gadget.h  --  USB Video Class Gadget driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *	Copyright (C) 2009-2010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	    Laurent Pinchart (laurent.pinchart@ideasonboard.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #ifndef _UVC_GADGET_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define _UVC_GADGET_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/pm_qos.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/usb/composite.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/videodev2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <media/v4l2-device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <media/v4l2-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <media/v4l2-fh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "uvc_queue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) struct usb_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) struct usb_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) struct uvc_descriptor_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) struct uvc_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /* ------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * Debugging, printing and logging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define UVC_TRACE_PROBE				(1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define UVC_TRACE_DESCR				(1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define UVC_TRACE_CONTROL			(1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define UVC_TRACE_FORMAT			(1 << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define UVC_TRACE_CAPTURE			(1 << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define UVC_TRACE_CALLS				(1 << 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define UVC_TRACE_IOCTL				(1 << 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define UVC_TRACE_FRAME				(1 << 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define UVC_TRACE_SUSPEND			(1 << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define UVC_TRACE_STATUS			(1 << 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define UVC_WARN_MINMAX				0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define UVC_WARN_PROBE_DEF			1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) extern unsigned int uvc_gadget_trace_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define uvc_trace(flag, msg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		if (uvc_gadget_trace_param & flag) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			printk(KERN_DEBUG "uvcvideo: " msg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define uvcg_dbg(f, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	dev_dbg(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define uvcg_info(f, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	dev_info(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define uvcg_warn(f, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	dev_warn(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define uvcg_err(f, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	dev_err(&(f)->config->cdev->gadget->dev, "%s: " fmt, (f)->name, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) /* ------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * Driver specific constants
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define UVC_MAX_REQUEST_SIZE			64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #define UVC_MAX_EVENTS				4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) /* ------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * Structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) struct uvc_request {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct usb_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	u8 *req_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct uvc_video *video;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #if defined(CONFIG_ARCH_ROCKCHIP) && defined(CONFIG_NO_GKI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct completion req_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) struct uvc_video {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct uvc_device *uvc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct usb_ep *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct work_struct pump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	/* Frame parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	u8 bpp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	u32 fcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	unsigned int width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	unsigned int height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	unsigned int imagesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct mutex mutex;	/* protects frame parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	unsigned int uvc_num_requests;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	/* Requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	unsigned int req_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct uvc_request *ureq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct list_head req_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	spinlock_t req_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	void (*encode) (struct usb_request *req, struct uvc_video *video,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			struct uvc_buffer *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	/* Context data used by the completion handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	__u32 payload_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	__u32 max_payload_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct uvc_video_queue queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	unsigned int fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) enum uvc_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	UVC_STATE_DISCONNECTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	UVC_STATE_CONNECTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	UVC_STATE_STREAMING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct uvc_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct video_device vdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct v4l2_device v4l2_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	enum uvc_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	struct usb_function func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct uvc_video video;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	bool func_connected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	wait_queue_head_t func_connected_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	/* for creating and issuing QoS requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct pm_qos_request pm_qos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/* Descriptors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		const struct uvc_descriptor_header * const *fs_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		const struct uvc_descriptor_header * const *ss_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		const struct uvc_descriptor_header * const *fs_streaming;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		const struct uvc_descriptor_header * const *hs_streaming;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		const struct uvc_descriptor_header * const *ss_streaming;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	} desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	unsigned int control_intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct usb_ep *control_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct usb_request *control_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	void *control_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	unsigned int streaming_intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	/* Events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	unsigned int event_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	unsigned int event_setup_out : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	unsigned int event_suspend : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static inline struct uvc_device *to_uvc(struct usb_function *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	return container_of(f, struct uvc_device, func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct uvc_file_handle {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct v4l2_fh vfh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	struct uvc_video *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	bool is_uvc_app_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) #define to_uvc_file_handle(handle) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	container_of(handle, struct uvc_file_handle, vfh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* ------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  * Functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) extern void uvc_function_setup_continue(struct uvc_device *uvc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) extern void uvc_endpoint_stream(struct uvc_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) extern void uvc_function_connect(struct uvc_device *uvc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) extern void uvc_function_disconnect(struct uvc_device *uvc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) #endif /* _UVC_GADGET_H_ */