18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/* (C) 1999-2003 Nemosoft Unv.
38c2ecf20Sopenharmony_ci   (C) 2004-2006 Luc Saillard (luc@saillard.org)
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci   NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
68c2ecf20Sopenharmony_ci   driver and thus may have bugs that are not present in the original version.
78c2ecf20Sopenharmony_ci   Please send bug reports and support requests to <luc@saillard.org>.
88c2ecf20Sopenharmony_ci   The decompression routines have been implemented by reverse-engineering the
98c2ecf20Sopenharmony_ci   Nemosoft binary pwcx module. Caveat emptor.
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci*/
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#ifndef PWC_H
148c2ecf20Sopenharmony_ci#define PWC_H
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <linux/module.h>
178c2ecf20Sopenharmony_ci#include <linux/usb.h>
188c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
198c2ecf20Sopenharmony_ci#include <linux/wait.h>
208c2ecf20Sopenharmony_ci#include <linux/mutex.h>
218c2ecf20Sopenharmony_ci#include <linux/mm.h>
228c2ecf20Sopenharmony_ci#include <linux/slab.h>
238c2ecf20Sopenharmony_ci#include <asm/errno.h>
248c2ecf20Sopenharmony_ci#include <linux/videodev2.h>
258c2ecf20Sopenharmony_ci#include <media/v4l2-common.h>
268c2ecf20Sopenharmony_ci#include <media/v4l2-device.h>
278c2ecf20Sopenharmony_ci#include <media/v4l2-ioctl.h>
288c2ecf20Sopenharmony_ci#include <media/v4l2-ctrls.h>
298c2ecf20Sopenharmony_ci#include <media/v4l2-fh.h>
308c2ecf20Sopenharmony_ci#include <media/v4l2-event.h>
318c2ecf20Sopenharmony_ci#include <media/videobuf2-v4l2.h>
328c2ecf20Sopenharmony_ci#include <media/videobuf2-vmalloc.h>
338c2ecf20Sopenharmony_ci#ifdef CONFIG_USB_PWC_INPUT_EVDEV
348c2ecf20Sopenharmony_ci#include <linux/input.h>
358c2ecf20Sopenharmony_ci#endif
368c2ecf20Sopenharmony_ci#include "pwc-dec1.h"
378c2ecf20Sopenharmony_ci#include "pwc-dec23.h"
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* Version block */
408c2ecf20Sopenharmony_ci#define PWC_VERSION	"10.0.15"
418c2ecf20Sopenharmony_ci#define PWC_NAME	"pwc"
428c2ecf20Sopenharmony_ci#define PFX		PWC_NAME ": "
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* Trace certain actions in the driver */
468c2ecf20Sopenharmony_ci#define PWC_DEBUG_LEVEL_MODULE	BIT(0)
478c2ecf20Sopenharmony_ci#define PWC_DEBUG_LEVEL_PROBE	BIT(1)
488c2ecf20Sopenharmony_ci#define PWC_DEBUG_LEVEL_OPEN	BIT(2)
498c2ecf20Sopenharmony_ci#define PWC_DEBUG_LEVEL_READ	BIT(3)
508c2ecf20Sopenharmony_ci#define PWC_DEBUG_LEVEL_MEMORY	BIT(4)
518c2ecf20Sopenharmony_ci#define PWC_DEBUG_LEVEL_FLOW	BIT(5)
528c2ecf20Sopenharmony_ci#define PWC_DEBUG_LEVEL_SIZE	BIT(6)
538c2ecf20Sopenharmony_ci#define PWC_DEBUG_LEVEL_IOCTL	BIT(7)
548c2ecf20Sopenharmony_ci#define PWC_DEBUG_LEVEL_TRACE	BIT(8)
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define PWC_DEBUG_MODULE(fmt, args...) PWC_DEBUG(MODULE, fmt, ##args)
578c2ecf20Sopenharmony_ci#define PWC_DEBUG_PROBE(fmt, args...) PWC_DEBUG(PROBE, fmt, ##args)
588c2ecf20Sopenharmony_ci#define PWC_DEBUG_OPEN(fmt, args...) PWC_DEBUG(OPEN, fmt, ##args)
598c2ecf20Sopenharmony_ci#define PWC_DEBUG_READ(fmt, args...) PWC_DEBUG(READ, fmt, ##args)
608c2ecf20Sopenharmony_ci#define PWC_DEBUG_MEMORY(fmt, args...) PWC_DEBUG(MEMORY, fmt, ##args)
618c2ecf20Sopenharmony_ci#define PWC_DEBUG_FLOW(fmt, args...) PWC_DEBUG(FLOW, fmt, ##args)
628c2ecf20Sopenharmony_ci#define PWC_DEBUG_SIZE(fmt, args...) PWC_DEBUG(SIZE, fmt, ##args)
638c2ecf20Sopenharmony_ci#define PWC_DEBUG_IOCTL(fmt, args...) PWC_DEBUG(IOCTL, fmt, ##args)
648c2ecf20Sopenharmony_ci#define PWC_DEBUG_TRACE(fmt, args...) PWC_DEBUG(TRACE, fmt, ##args)
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#ifdef CONFIG_USB_PWC_DEBUG
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define PWC_DEBUG_LEVEL	(PWC_DEBUG_LEVEL_MODULE)
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define PWC_DEBUG(level, fmt, args...) do {\
728c2ecf20Sopenharmony_ci	if ((PWC_DEBUG_LEVEL_ ##level) & pwc_trace) \
738c2ecf20Sopenharmony_ci		printk(KERN_DEBUG PFX fmt, ##args); \
748c2ecf20Sopenharmony_ci	} while (0)
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#define PWC_ERROR(fmt, args...) printk(KERN_ERR PFX fmt, ##args)
778c2ecf20Sopenharmony_ci#define PWC_WARNING(fmt, args...) printk(KERN_WARNING PFX fmt, ##args)
788c2ecf20Sopenharmony_ci#define PWC_INFO(fmt, args...) printk(KERN_INFO PFX fmt, ##args)
798c2ecf20Sopenharmony_ci#define PWC_TRACE(fmt, args...) PWC_DEBUG(TRACE, fmt, ##args)
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#else /* if ! CONFIG_USB_PWC_DEBUG */
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define PWC_ERROR(fmt, args...) printk(KERN_ERR PFX fmt, ##args)
848c2ecf20Sopenharmony_ci#define PWC_WARNING(fmt, args...) printk(KERN_WARNING PFX fmt, ##args)
858c2ecf20Sopenharmony_ci#define PWC_INFO(fmt, args...) printk(KERN_INFO PFX fmt, ##args)
868c2ecf20Sopenharmony_ci#define PWC_TRACE(fmt, args...) do { } while(0)
878c2ecf20Sopenharmony_ci#define PWC_DEBUG(level, fmt, args...) do { } while(0)
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define pwc_trace 0
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#endif
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/* Defines for ToUCam cameras */
948c2ecf20Sopenharmony_ci#define TOUCAM_HEADER_SIZE		8
958c2ecf20Sopenharmony_ci#define TOUCAM_TRAILER_SIZE		4
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#define FEATURE_MOTOR_PANTILT		0x0001
988c2ecf20Sopenharmony_ci#define FEATURE_CODEC1			0x0002
998c2ecf20Sopenharmony_ci#define FEATURE_CODEC2			0x0004
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#define MAX_WIDTH		640
1028c2ecf20Sopenharmony_ci#define MAX_HEIGHT		480
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/* Ignore errors in the first N frames, to allow for startup delays */
1058c2ecf20Sopenharmony_ci#define FRAME_LOWMARK 5
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/* Size and number of buffers for the ISO pipe. */
1088c2ecf20Sopenharmony_ci#define MAX_ISO_BUFS		3
1098c2ecf20Sopenharmony_ci#define ISO_FRAMES_PER_DESC	10
1108c2ecf20Sopenharmony_ci#define ISO_MAX_FRAME_SIZE	960
1118c2ecf20Sopenharmony_ci#define ISO_BUFFER_SIZE		(ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE)
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/* Maximum size after decompression is 640x480 YUV data, 1.5 * 640 * 480 */
1148c2ecf20Sopenharmony_ci#define PWC_FRAME_SIZE		(460800 + TOUCAM_HEADER_SIZE + TOUCAM_TRAILER_SIZE)
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/* Absolute minimum and maximum number of buffers available for mmap() */
1178c2ecf20Sopenharmony_ci#define MIN_FRAMES		2
1188c2ecf20Sopenharmony_ci#define MAX_FRAMES		16
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/* Some macros to quickly find the type of a webcam */
1218c2ecf20Sopenharmony_ci#define DEVICE_USE_CODEC1(x) ((x)<675)
1228c2ecf20Sopenharmony_ci#define DEVICE_USE_CODEC2(x) ((x)>=675 && (x)<700)
1238c2ecf20Sopenharmony_ci#define DEVICE_USE_CODEC3(x) ((x)>=700)
1248c2ecf20Sopenharmony_ci#define DEVICE_USE_CODEC23(x) ((x)>=675)
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci/* Request types: video */
1278c2ecf20Sopenharmony_ci#define SET_LUM_CTL			0x01
1288c2ecf20Sopenharmony_ci#define GET_LUM_CTL			0x02
1298c2ecf20Sopenharmony_ci#define SET_CHROM_CTL			0x03
1308c2ecf20Sopenharmony_ci#define GET_CHROM_CTL			0x04
1318c2ecf20Sopenharmony_ci#define SET_STATUS_CTL			0x05
1328c2ecf20Sopenharmony_ci#define GET_STATUS_CTL			0x06
1338c2ecf20Sopenharmony_ci#define SET_EP_STREAM_CTL		0x07
1348c2ecf20Sopenharmony_ci#define GET_EP_STREAM_CTL		0x08
1358c2ecf20Sopenharmony_ci#define GET_XX_CTL			0x09
1368c2ecf20Sopenharmony_ci#define SET_XX_CTL			0x0A
1378c2ecf20Sopenharmony_ci#define GET_XY_CTL			0x0B
1388c2ecf20Sopenharmony_ci#define SET_XY_CTL			0x0C
1398c2ecf20Sopenharmony_ci#define SET_MPT_CTL			0x0D
1408c2ecf20Sopenharmony_ci#define GET_MPT_CTL			0x0E
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci/* Selectors for the Luminance controls [GS]ET_LUM_CTL */
1438c2ecf20Sopenharmony_ci#define AGC_MODE_FORMATTER			0x2000
1448c2ecf20Sopenharmony_ci#define PRESET_AGC_FORMATTER			0x2100
1458c2ecf20Sopenharmony_ci#define SHUTTER_MODE_FORMATTER			0x2200
1468c2ecf20Sopenharmony_ci#define PRESET_SHUTTER_FORMATTER		0x2300
1478c2ecf20Sopenharmony_ci#define PRESET_CONTOUR_FORMATTER		0x2400
1488c2ecf20Sopenharmony_ci#define AUTO_CONTOUR_FORMATTER			0x2500
1498c2ecf20Sopenharmony_ci#define BACK_LIGHT_COMPENSATION_FORMATTER	0x2600
1508c2ecf20Sopenharmony_ci#define CONTRAST_FORMATTER			0x2700
1518c2ecf20Sopenharmony_ci#define DYNAMIC_NOISE_CONTROL_FORMATTER		0x2800
1528c2ecf20Sopenharmony_ci#define FLICKERLESS_MODE_FORMATTER		0x2900
1538c2ecf20Sopenharmony_ci#define AE_CONTROL_SPEED			0x2A00
1548c2ecf20Sopenharmony_ci#define BRIGHTNESS_FORMATTER			0x2B00
1558c2ecf20Sopenharmony_ci#define GAMMA_FORMATTER				0x2C00
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci/* Selectors for the Chrominance controls [GS]ET_CHROM_CTL */
1588c2ecf20Sopenharmony_ci#define WB_MODE_FORMATTER			0x1000
1598c2ecf20Sopenharmony_ci#define AWB_CONTROL_SPEED_FORMATTER		0x1100
1608c2ecf20Sopenharmony_ci#define AWB_CONTROL_DELAY_FORMATTER		0x1200
1618c2ecf20Sopenharmony_ci#define PRESET_MANUAL_RED_GAIN_FORMATTER	0x1300
1628c2ecf20Sopenharmony_ci#define PRESET_MANUAL_BLUE_GAIN_FORMATTER	0x1400
1638c2ecf20Sopenharmony_ci#define COLOUR_MODE_FORMATTER			0x1500
1648c2ecf20Sopenharmony_ci#define SATURATION_MODE_FORMATTER1		0x1600
1658c2ecf20Sopenharmony_ci#define SATURATION_MODE_FORMATTER2		0x1700
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci/* Selectors for the Status controls [GS]ET_STATUS_CTL */
1688c2ecf20Sopenharmony_ci#define SAVE_USER_DEFAULTS_FORMATTER		0x0200
1698c2ecf20Sopenharmony_ci#define RESTORE_USER_DEFAULTS_FORMATTER		0x0300
1708c2ecf20Sopenharmony_ci#define RESTORE_FACTORY_DEFAULTS_FORMATTER	0x0400
1718c2ecf20Sopenharmony_ci#define READ_AGC_FORMATTER			0x0500
1728c2ecf20Sopenharmony_ci#define READ_SHUTTER_FORMATTER			0x0600
1738c2ecf20Sopenharmony_ci#define READ_RED_GAIN_FORMATTER			0x0700
1748c2ecf20Sopenharmony_ci#define READ_BLUE_GAIN_FORMATTER		0x0800
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci/* Formatters for the motorized pan & tilt [GS]ET_MPT_CTL */
1778c2ecf20Sopenharmony_ci#define PT_RELATIVE_CONTROL_FORMATTER		0x01
1788c2ecf20Sopenharmony_ci#define PT_RESET_CONTROL_FORMATTER		0x02
1798c2ecf20Sopenharmony_ci#define PT_STATUS_FORMATTER			0x03
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci/* Enumeration of image sizes */
1828c2ecf20Sopenharmony_ci#define PSZ_SQCIF	0x00
1838c2ecf20Sopenharmony_ci#define PSZ_QSIF	0x01
1848c2ecf20Sopenharmony_ci#define PSZ_QCIF	0x02
1858c2ecf20Sopenharmony_ci#define PSZ_SIF		0x03
1868c2ecf20Sopenharmony_ci#define PSZ_CIF		0x04
1878c2ecf20Sopenharmony_ci#define PSZ_VGA		0x05
1888c2ecf20Sopenharmony_ci#define PSZ_MAX		6
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_cistruct pwc_raw_frame {
1918c2ecf20Sopenharmony_ci	__le16 type;		/* type of the webcam */
1928c2ecf20Sopenharmony_ci	__le16 vbandlength;	/* Size of 4 lines compressed (used by the
1938c2ecf20Sopenharmony_ci				   decompressor) */
1948c2ecf20Sopenharmony_ci	__u8   cmd[4];		/* the four byte of the command (in case of
1958c2ecf20Sopenharmony_ci				   nala, only the first 3 bytes is filled) */
1968c2ecf20Sopenharmony_ci	__u8   rawframe[];	/* frame_size = H / 4 * vbandlength */
1978c2ecf20Sopenharmony_ci} __packed;
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci/* intermediate buffers with raw data from the USB cam */
2008c2ecf20Sopenharmony_cistruct pwc_frame_buf
2018c2ecf20Sopenharmony_ci{
2028c2ecf20Sopenharmony_ci	/* common v4l buffer stuff -- must be first */
2038c2ecf20Sopenharmony_ci	struct vb2_v4l2_buffer vb;
2048c2ecf20Sopenharmony_ci	struct list_head list;
2058c2ecf20Sopenharmony_ci	void *data;
2068c2ecf20Sopenharmony_ci	int filled;		/* number of bytes filled */
2078c2ecf20Sopenharmony_ci};
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_cistruct pwc_device
2108c2ecf20Sopenharmony_ci{
2118c2ecf20Sopenharmony_ci	struct video_device vdev;
2128c2ecf20Sopenharmony_ci	struct v4l2_device v4l2_dev;
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci	/* videobuf2 queue and queued buffers list */
2158c2ecf20Sopenharmony_ci	struct vb2_queue vb_queue;
2168c2ecf20Sopenharmony_ci	struct list_head queued_bufs;
2178c2ecf20Sopenharmony_ci	spinlock_t queued_bufs_lock; /* Protects queued_bufs */
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	/* If taking both locks vb_queue_lock must always be locked first! */
2208c2ecf20Sopenharmony_ci	struct mutex v4l2_lock;      /* Protects everything else */
2218c2ecf20Sopenharmony_ci	struct mutex vb_queue_lock;  /* Protects vb_queue and capt_file */
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci	/* Pointer to our usb_device, will be NULL after unplug */
2248c2ecf20Sopenharmony_ci	struct usb_device *udev; /* Both mutexes most be hold when setting! */
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci	/* type of cam (645, 646, 675, 680, 690, 720, 730, 740, 750) */
2278c2ecf20Sopenharmony_ci	int type;
2288c2ecf20Sopenharmony_ci	int release;		/* release number */
2298c2ecf20Sopenharmony_ci	int features;		/* feature bits */
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci	/*** Video data ***/
2328c2ecf20Sopenharmony_ci	int vendpoint;		/* video isoc endpoint */
2338c2ecf20Sopenharmony_ci	int vcinterface;	/* video control interface */
2348c2ecf20Sopenharmony_ci	int valternate;		/* alternate interface needed */
2358c2ecf20Sopenharmony_ci	int vframes;		/* frames-per-second */
2368c2ecf20Sopenharmony_ci	int pixfmt;		/* pixelformat: V4L2_PIX_FMT_YUV420 or _PWCX */
2378c2ecf20Sopenharmony_ci	int vframe_count;	/* received frames */
2388c2ecf20Sopenharmony_ci	int vmax_packet_size;	/* USB maxpacket size */
2398c2ecf20Sopenharmony_ci	int vlast_packet_size;	/* for frame synchronisation */
2408c2ecf20Sopenharmony_ci	int visoc_errors;	/* number of contiguous ISOC errors */
2418c2ecf20Sopenharmony_ci	int vbandlength;	/* compressed band length; 0 is uncompressed */
2428c2ecf20Sopenharmony_ci	char vsync;		/* used by isoc handler */
2438c2ecf20Sopenharmony_ci	char vmirror;		/* for ToUCaM series */
2448c2ecf20Sopenharmony_ci	char power_save;	/* Do powersaving for this cam */
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci	unsigned char cmd_buf[13];
2478c2ecf20Sopenharmony_ci	unsigned char *ctrl_buf;
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	struct urb *urbs[MAX_ISO_BUFS];
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci	/*
2528c2ecf20Sopenharmony_ci	 * Frame currently being filled, this only gets touched by the
2538c2ecf20Sopenharmony_ci	 * isoc urb complete handler, and by stream start / stop since
2548c2ecf20Sopenharmony_ci	 * start / stop touch it before / after starting / killing the urbs
2558c2ecf20Sopenharmony_ci	 * no locking is needed around this
2568c2ecf20Sopenharmony_ci	 */
2578c2ecf20Sopenharmony_ci	struct pwc_frame_buf *fill_buf;
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci	int frame_header_size, frame_trailer_size;
2608c2ecf20Sopenharmony_ci	int frame_size;
2618c2ecf20Sopenharmony_ci	int frame_total_size;	/* including header & trailer */
2628c2ecf20Sopenharmony_ci	int drop_frames;
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci	union {	/* private data for decompression engine */
2658c2ecf20Sopenharmony_ci		struct pwc_dec1_private dec1;
2668c2ecf20Sopenharmony_ci		struct pwc_dec23_private dec23;
2678c2ecf20Sopenharmony_ci	};
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci	/*
2708c2ecf20Sopenharmony_ci	 * We have an 'image' and a 'view', where 'image' is the fixed-size img
2718c2ecf20Sopenharmony_ci	 * as delivered by the camera, and 'view' is the size requested by the
2728c2ecf20Sopenharmony_ci	 * program. The camera image is centered in this viewport, laced with
2738c2ecf20Sopenharmony_ci	 * a gray or black border. view_min <= image <= view <= view_max;
2748c2ecf20Sopenharmony_ci	 */
2758c2ecf20Sopenharmony_ci	int image_mask;				/* supported sizes */
2768c2ecf20Sopenharmony_ci	int width, height;			/* current resolution */
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci#ifdef CONFIG_USB_PWC_INPUT_EVDEV
2798c2ecf20Sopenharmony_ci	struct input_dev *button_dev;	/* webcam snapshot button input */
2808c2ecf20Sopenharmony_ci	char button_phys[64];
2818c2ecf20Sopenharmony_ci#endif
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	/* controls */
2848c2ecf20Sopenharmony_ci	struct v4l2_ctrl_handler	ctrl_handler;
2858c2ecf20Sopenharmony_ci	u16				saturation_fmt;
2868c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*brightness;
2878c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*contrast;
2888c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*saturation;
2898c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*gamma;
2908c2ecf20Sopenharmony_ci	struct {
2918c2ecf20Sopenharmony_ci		/* awb / red-blue balance cluster */
2928c2ecf20Sopenharmony_ci		struct v4l2_ctrl	*auto_white_balance;
2938c2ecf20Sopenharmony_ci		struct v4l2_ctrl	*red_balance;
2948c2ecf20Sopenharmony_ci		struct v4l2_ctrl	*blue_balance;
2958c2ecf20Sopenharmony_ci		/* usb ctrl transfers are slow, so we cache things */
2968c2ecf20Sopenharmony_ci		int			color_bal_valid;
2978c2ecf20Sopenharmony_ci		unsigned long		last_color_bal_update; /* In jiffies */
2988c2ecf20Sopenharmony_ci		s32			last_red_balance;
2998c2ecf20Sopenharmony_ci		s32			last_blue_balance;
3008c2ecf20Sopenharmony_ci	};
3018c2ecf20Sopenharmony_ci	struct {
3028c2ecf20Sopenharmony_ci		/* autogain / gain cluster */
3038c2ecf20Sopenharmony_ci		struct v4l2_ctrl	*autogain;
3048c2ecf20Sopenharmony_ci		struct v4l2_ctrl	*gain;
3058c2ecf20Sopenharmony_ci		int			gain_valid;
3068c2ecf20Sopenharmony_ci		unsigned long		last_gain_update; /* In jiffies */
3078c2ecf20Sopenharmony_ci		s32			last_gain;
3088c2ecf20Sopenharmony_ci	};
3098c2ecf20Sopenharmony_ci	struct {
3108c2ecf20Sopenharmony_ci		/* exposure_auto / exposure cluster */
3118c2ecf20Sopenharmony_ci		struct v4l2_ctrl	*exposure_auto;
3128c2ecf20Sopenharmony_ci		struct v4l2_ctrl	*exposure;
3138c2ecf20Sopenharmony_ci		int			exposure_valid;
3148c2ecf20Sopenharmony_ci		unsigned long		last_exposure_update; /* In jiffies */
3158c2ecf20Sopenharmony_ci		s32			last_exposure;
3168c2ecf20Sopenharmony_ci	};
3178c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*colorfx;
3188c2ecf20Sopenharmony_ci	struct {
3198c2ecf20Sopenharmony_ci		/* autocontour/contour cluster */
3208c2ecf20Sopenharmony_ci		struct v4l2_ctrl	*autocontour;
3218c2ecf20Sopenharmony_ci		struct v4l2_ctrl	*contour;
3228c2ecf20Sopenharmony_ci	};
3238c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*backlight;
3248c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*flicker;
3258c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*noise_reduction;
3268c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*save_user;
3278c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*restore_user;
3288c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*restore_factory;
3298c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*awb_speed;
3308c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*awb_delay;
3318c2ecf20Sopenharmony_ci	struct {
3328c2ecf20Sopenharmony_ci		/* motor control cluster */
3338c2ecf20Sopenharmony_ci		struct v4l2_ctrl	*motor_pan;
3348c2ecf20Sopenharmony_ci		struct v4l2_ctrl	*motor_tilt;
3358c2ecf20Sopenharmony_ci		struct v4l2_ctrl	*motor_pan_reset;
3368c2ecf20Sopenharmony_ci		struct v4l2_ctrl	*motor_tilt_reset;
3378c2ecf20Sopenharmony_ci	};
3388c2ecf20Sopenharmony_ci	/* CODEC3 models have both gain and exposure controlled by autogain */
3398c2ecf20Sopenharmony_ci	struct v4l2_ctrl		*autogain_expo_cluster[3];
3408c2ecf20Sopenharmony_ci};
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci/* Global variables */
3438c2ecf20Sopenharmony_ci#ifdef CONFIG_USB_PWC_DEBUG
3448c2ecf20Sopenharmony_ciextern int pwc_trace;
3458c2ecf20Sopenharmony_ci#endif
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci/** Functions in pwc-misc.c */
3488c2ecf20Sopenharmony_ci/* sizes in pixels */
3498c2ecf20Sopenharmony_ciextern const int pwc_image_sizes[PSZ_MAX][2];
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ciint pwc_get_size(struct pwc_device *pdev, int width, int height);
3528c2ecf20Sopenharmony_civoid pwc_construct(struct pwc_device *pdev);
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci/** Functions in pwc-ctrl.c */
3558c2ecf20Sopenharmony_ci/* Request a certain video mode. Returns < 0 if not possible */
3568c2ecf20Sopenharmony_ciextern int pwc_set_video_mode(struct pwc_device *pdev, int width, int height,
3578c2ecf20Sopenharmony_ci	int pixfmt, int frames, int *compression, int send_to_cam);
3588c2ecf20Sopenharmony_ciextern unsigned int pwc_get_fps(struct pwc_device *pdev, unsigned int index, unsigned int size);
3598c2ecf20Sopenharmony_ciextern int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value);
3608c2ecf20Sopenharmony_ciextern int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor);
3618c2ecf20Sopenharmony_ciextern int send_control_msg(struct pwc_device *pdev,
3628c2ecf20Sopenharmony_ci			    u8 request, u16 value, void *buf, int buflen);
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci/* Control get / set helpers */
3658c2ecf20Sopenharmony_ciint pwc_get_u8_ctrl(struct pwc_device *pdev, u8 request, u16 value, int *data);
3668c2ecf20Sopenharmony_ciint pwc_set_u8_ctrl(struct pwc_device *pdev, u8 request, u16 value, u8 data);
3678c2ecf20Sopenharmony_ciint pwc_get_s8_ctrl(struct pwc_device *pdev, u8 request, u16 value, int *data);
3688c2ecf20Sopenharmony_ci#define pwc_set_s8_ctrl pwc_set_u8_ctrl
3698c2ecf20Sopenharmony_ciint pwc_get_u16_ctrl(struct pwc_device *pdev, u8 request, u16 value, int *dat);
3708c2ecf20Sopenharmony_ciint pwc_set_u16_ctrl(struct pwc_device *pdev, u8 request, u16 value, u16 data);
3718c2ecf20Sopenharmony_ciint pwc_button_ctrl(struct pwc_device *pdev, u16 value);
3728c2ecf20Sopenharmony_ciint pwc_init_controls(struct pwc_device *pdev);
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci/* Power down or up the camera; not supported by all models */
3758c2ecf20Sopenharmony_ciextern void pwc_camera_power(struct pwc_device *pdev, int power);
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ciextern const struct v4l2_ioctl_ops pwc_ioctl_ops;
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci/** pwc-uncompress.c */
3808c2ecf20Sopenharmony_ci/* Expand frame to image, possibly including decompression. Uses read_frame and fill_image */
3818c2ecf20Sopenharmony_ciint pwc_decompress(struct pwc_device *pdev, struct pwc_frame_buf *fbuf);
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci#endif
384