162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/* (C) 1999-2003 Nemosoft Unv.
362306a36Sopenharmony_ci   (C) 2004-2006 Luc Saillard (luc@saillard.org)
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci   NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
662306a36Sopenharmony_ci   driver and thus may have bugs that are not present in the original version.
762306a36Sopenharmony_ci   Please send bug reports and support requests to <luc@saillard.org>.
862306a36Sopenharmony_ci   The decompression routines have been implemented by reverse-engineering the
962306a36Sopenharmony_ci   Nemosoft binary pwcx module. Caveat emptor.
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci*/
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#ifndef PWC_H
1462306a36Sopenharmony_ci#define PWC_H
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#include <linux/module.h>
1762306a36Sopenharmony_ci#include <linux/usb.h>
1862306a36Sopenharmony_ci#include <linux/spinlock.h>
1962306a36Sopenharmony_ci#include <linux/wait.h>
2062306a36Sopenharmony_ci#include <linux/mutex.h>
2162306a36Sopenharmony_ci#include <linux/mm.h>
2262306a36Sopenharmony_ci#include <linux/slab.h>
2362306a36Sopenharmony_ci#include <asm/errno.h>
2462306a36Sopenharmony_ci#include <linux/videodev2.h>
2562306a36Sopenharmony_ci#include <media/v4l2-common.h>
2662306a36Sopenharmony_ci#include <media/v4l2-device.h>
2762306a36Sopenharmony_ci#include <media/v4l2-ioctl.h>
2862306a36Sopenharmony_ci#include <media/v4l2-ctrls.h>
2962306a36Sopenharmony_ci#include <media/v4l2-fh.h>
3062306a36Sopenharmony_ci#include <media/v4l2-event.h>
3162306a36Sopenharmony_ci#include <media/videobuf2-v4l2.h>
3262306a36Sopenharmony_ci#include <media/videobuf2-vmalloc.h>
3362306a36Sopenharmony_ci#ifdef CONFIG_USB_PWC_INPUT_EVDEV
3462306a36Sopenharmony_ci#include <linux/input.h>
3562306a36Sopenharmony_ci#endif
3662306a36Sopenharmony_ci#include "pwc-dec1.h"
3762306a36Sopenharmony_ci#include "pwc-dec23.h"
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/* Version block */
4062306a36Sopenharmony_ci#define PWC_VERSION	"10.0.15"
4162306a36Sopenharmony_ci#define PWC_NAME	"pwc"
4262306a36Sopenharmony_ci#define PFX		PWC_NAME ": "
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci/* Trace certain actions in the driver */
4662306a36Sopenharmony_ci#define PWC_DEBUG_LEVEL_MODULE	BIT(0)
4762306a36Sopenharmony_ci#define PWC_DEBUG_LEVEL_PROBE	BIT(1)
4862306a36Sopenharmony_ci#define PWC_DEBUG_LEVEL_OPEN	BIT(2)
4962306a36Sopenharmony_ci#define PWC_DEBUG_LEVEL_READ	BIT(3)
5062306a36Sopenharmony_ci#define PWC_DEBUG_LEVEL_MEMORY	BIT(4)
5162306a36Sopenharmony_ci#define PWC_DEBUG_LEVEL_FLOW	BIT(5)
5262306a36Sopenharmony_ci#define PWC_DEBUG_LEVEL_SIZE	BIT(6)
5362306a36Sopenharmony_ci#define PWC_DEBUG_LEVEL_IOCTL	BIT(7)
5462306a36Sopenharmony_ci#define PWC_DEBUG_LEVEL_TRACE	BIT(8)
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#define PWC_DEBUG_MODULE(fmt, args...) PWC_DEBUG(MODULE, fmt, ##args)
5762306a36Sopenharmony_ci#define PWC_DEBUG_PROBE(fmt, args...) PWC_DEBUG(PROBE, fmt, ##args)
5862306a36Sopenharmony_ci#define PWC_DEBUG_OPEN(fmt, args...) PWC_DEBUG(OPEN, fmt, ##args)
5962306a36Sopenharmony_ci#define PWC_DEBUG_READ(fmt, args...) PWC_DEBUG(READ, fmt, ##args)
6062306a36Sopenharmony_ci#define PWC_DEBUG_MEMORY(fmt, args...) PWC_DEBUG(MEMORY, fmt, ##args)
6162306a36Sopenharmony_ci#define PWC_DEBUG_FLOW(fmt, args...) PWC_DEBUG(FLOW, fmt, ##args)
6262306a36Sopenharmony_ci#define PWC_DEBUG_SIZE(fmt, args...) PWC_DEBUG(SIZE, fmt, ##args)
6362306a36Sopenharmony_ci#define PWC_DEBUG_IOCTL(fmt, args...) PWC_DEBUG(IOCTL, fmt, ##args)
6462306a36Sopenharmony_ci#define PWC_DEBUG_TRACE(fmt, args...) PWC_DEBUG(TRACE, fmt, ##args)
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci#ifdef CONFIG_USB_PWC_DEBUG
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci#define PWC_DEBUG_LEVEL	(PWC_DEBUG_LEVEL_MODULE)
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci#define PWC_DEBUG(level, fmt, args...) do {\
7262306a36Sopenharmony_ci	if ((PWC_DEBUG_LEVEL_ ##level) & pwc_trace) \
7362306a36Sopenharmony_ci		printk(KERN_DEBUG PFX fmt, ##args); \
7462306a36Sopenharmony_ci	} while (0)
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci#define PWC_ERROR(fmt, args...) printk(KERN_ERR PFX fmt, ##args)
7762306a36Sopenharmony_ci#define PWC_WARNING(fmt, args...) printk(KERN_WARNING PFX fmt, ##args)
7862306a36Sopenharmony_ci#define PWC_INFO(fmt, args...) printk(KERN_INFO PFX fmt, ##args)
7962306a36Sopenharmony_ci#define PWC_TRACE(fmt, args...) PWC_DEBUG(TRACE, fmt, ##args)
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#else /* if ! CONFIG_USB_PWC_DEBUG */
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#define PWC_ERROR(fmt, args...) printk(KERN_ERR PFX fmt, ##args)
8462306a36Sopenharmony_ci#define PWC_WARNING(fmt, args...) printk(KERN_WARNING PFX fmt, ##args)
8562306a36Sopenharmony_ci#define PWC_INFO(fmt, args...) printk(KERN_INFO PFX fmt, ##args)
8662306a36Sopenharmony_ci#define PWC_TRACE(fmt, args...) do { } while(0)
8762306a36Sopenharmony_ci#define PWC_DEBUG(level, fmt, args...) do { } while(0)
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#define pwc_trace 0
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci#endif
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci/* Defines for ToUCam cameras */
9462306a36Sopenharmony_ci#define TOUCAM_HEADER_SIZE		8
9562306a36Sopenharmony_ci#define TOUCAM_TRAILER_SIZE		4
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci#define FEATURE_MOTOR_PANTILT		0x0001
9862306a36Sopenharmony_ci#define FEATURE_CODEC1			0x0002
9962306a36Sopenharmony_ci#define FEATURE_CODEC2			0x0004
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci#define MAX_WIDTH		640
10262306a36Sopenharmony_ci#define MAX_HEIGHT		480
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci/* Ignore errors in the first N frames, to allow for startup delays */
10562306a36Sopenharmony_ci#define FRAME_LOWMARK 5
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci/* Size and number of buffers for the ISO pipe. */
10862306a36Sopenharmony_ci#define MAX_ISO_BUFS		3
10962306a36Sopenharmony_ci#define ISO_FRAMES_PER_DESC	10
11062306a36Sopenharmony_ci#define ISO_MAX_FRAME_SIZE	960
11162306a36Sopenharmony_ci#define ISO_BUFFER_SIZE		(ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE)
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci/* Maximum size after decompression is 640x480 YUV data, 1.5 * 640 * 480 */
11462306a36Sopenharmony_ci#define PWC_FRAME_SIZE		(460800 + TOUCAM_HEADER_SIZE + TOUCAM_TRAILER_SIZE)
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci/* Absolute minimum and maximum number of buffers available for mmap() */
11762306a36Sopenharmony_ci#define MIN_FRAMES		2
11862306a36Sopenharmony_ci#define MAX_FRAMES		16
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci/* Some macros to quickly find the type of a webcam */
12162306a36Sopenharmony_ci#define DEVICE_USE_CODEC1(x) ((x)<675)
12262306a36Sopenharmony_ci#define DEVICE_USE_CODEC2(x) ((x)>=675 && (x)<700)
12362306a36Sopenharmony_ci#define DEVICE_USE_CODEC3(x) ((x)>=700)
12462306a36Sopenharmony_ci#define DEVICE_USE_CODEC23(x) ((x)>=675)
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci/* Request types: video */
12762306a36Sopenharmony_ci#define SET_LUM_CTL			0x01
12862306a36Sopenharmony_ci#define GET_LUM_CTL			0x02
12962306a36Sopenharmony_ci#define SET_CHROM_CTL			0x03
13062306a36Sopenharmony_ci#define GET_CHROM_CTL			0x04
13162306a36Sopenharmony_ci#define SET_STATUS_CTL			0x05
13262306a36Sopenharmony_ci#define GET_STATUS_CTL			0x06
13362306a36Sopenharmony_ci#define SET_EP_STREAM_CTL		0x07
13462306a36Sopenharmony_ci#define GET_EP_STREAM_CTL		0x08
13562306a36Sopenharmony_ci#define GET_XX_CTL			0x09
13662306a36Sopenharmony_ci#define SET_XX_CTL			0x0A
13762306a36Sopenharmony_ci#define GET_XY_CTL			0x0B
13862306a36Sopenharmony_ci#define SET_XY_CTL			0x0C
13962306a36Sopenharmony_ci#define SET_MPT_CTL			0x0D
14062306a36Sopenharmony_ci#define GET_MPT_CTL			0x0E
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci/* Selectors for the Luminance controls [GS]ET_LUM_CTL */
14362306a36Sopenharmony_ci#define AGC_MODE_FORMATTER			0x2000
14462306a36Sopenharmony_ci#define PRESET_AGC_FORMATTER			0x2100
14562306a36Sopenharmony_ci#define SHUTTER_MODE_FORMATTER			0x2200
14662306a36Sopenharmony_ci#define PRESET_SHUTTER_FORMATTER		0x2300
14762306a36Sopenharmony_ci#define PRESET_CONTOUR_FORMATTER		0x2400
14862306a36Sopenharmony_ci#define AUTO_CONTOUR_FORMATTER			0x2500
14962306a36Sopenharmony_ci#define BACK_LIGHT_COMPENSATION_FORMATTER	0x2600
15062306a36Sopenharmony_ci#define CONTRAST_FORMATTER			0x2700
15162306a36Sopenharmony_ci#define DYNAMIC_NOISE_CONTROL_FORMATTER		0x2800
15262306a36Sopenharmony_ci#define FLICKERLESS_MODE_FORMATTER		0x2900
15362306a36Sopenharmony_ci#define AE_CONTROL_SPEED			0x2A00
15462306a36Sopenharmony_ci#define BRIGHTNESS_FORMATTER			0x2B00
15562306a36Sopenharmony_ci#define GAMMA_FORMATTER				0x2C00
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci/* Selectors for the Chrominance controls [GS]ET_CHROM_CTL */
15862306a36Sopenharmony_ci#define WB_MODE_FORMATTER			0x1000
15962306a36Sopenharmony_ci#define AWB_CONTROL_SPEED_FORMATTER		0x1100
16062306a36Sopenharmony_ci#define AWB_CONTROL_DELAY_FORMATTER		0x1200
16162306a36Sopenharmony_ci#define PRESET_MANUAL_RED_GAIN_FORMATTER	0x1300
16262306a36Sopenharmony_ci#define PRESET_MANUAL_BLUE_GAIN_FORMATTER	0x1400
16362306a36Sopenharmony_ci#define COLOUR_MODE_FORMATTER			0x1500
16462306a36Sopenharmony_ci#define SATURATION_MODE_FORMATTER1		0x1600
16562306a36Sopenharmony_ci#define SATURATION_MODE_FORMATTER2		0x1700
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci/* Selectors for the Status controls [GS]ET_STATUS_CTL */
16862306a36Sopenharmony_ci#define SAVE_USER_DEFAULTS_FORMATTER		0x0200
16962306a36Sopenharmony_ci#define RESTORE_USER_DEFAULTS_FORMATTER		0x0300
17062306a36Sopenharmony_ci#define RESTORE_FACTORY_DEFAULTS_FORMATTER	0x0400
17162306a36Sopenharmony_ci#define READ_AGC_FORMATTER			0x0500
17262306a36Sopenharmony_ci#define READ_SHUTTER_FORMATTER			0x0600
17362306a36Sopenharmony_ci#define READ_RED_GAIN_FORMATTER			0x0700
17462306a36Sopenharmony_ci#define READ_BLUE_GAIN_FORMATTER		0x0800
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci/* Formatters for the motorized pan & tilt [GS]ET_MPT_CTL */
17762306a36Sopenharmony_ci#define PT_RELATIVE_CONTROL_FORMATTER		0x01
17862306a36Sopenharmony_ci#define PT_RESET_CONTROL_FORMATTER		0x02
17962306a36Sopenharmony_ci#define PT_STATUS_FORMATTER			0x03
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci/* Enumeration of image sizes */
18262306a36Sopenharmony_ci#define PSZ_SQCIF	0x00
18362306a36Sopenharmony_ci#define PSZ_QSIF	0x01
18462306a36Sopenharmony_ci#define PSZ_QCIF	0x02
18562306a36Sopenharmony_ci#define PSZ_SIF		0x03
18662306a36Sopenharmony_ci#define PSZ_CIF		0x04
18762306a36Sopenharmony_ci#define PSZ_VGA		0x05
18862306a36Sopenharmony_ci#define PSZ_MAX		6
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_cistruct pwc_raw_frame {
19162306a36Sopenharmony_ci	__le16 type;		/* type of the webcam */
19262306a36Sopenharmony_ci	__le16 vbandlength;	/* Size of 4 lines compressed (used by the
19362306a36Sopenharmony_ci				   decompressor) */
19462306a36Sopenharmony_ci	__u8   cmd[4];		/* the four byte of the command (in case of
19562306a36Sopenharmony_ci				   nala, only the first 3 bytes is filled) */
19662306a36Sopenharmony_ci	__u8   rawframe[];	/* frame_size = H / 4 * vbandlength */
19762306a36Sopenharmony_ci} __packed;
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci/* intermediate buffers with raw data from the USB cam */
20062306a36Sopenharmony_cistruct pwc_frame_buf
20162306a36Sopenharmony_ci{
20262306a36Sopenharmony_ci	/* common v4l buffer stuff -- must be first */
20362306a36Sopenharmony_ci	struct vb2_v4l2_buffer vb;
20462306a36Sopenharmony_ci	struct list_head list;
20562306a36Sopenharmony_ci	void *data;
20662306a36Sopenharmony_ci	int filled;		/* number of bytes filled */
20762306a36Sopenharmony_ci};
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_cistruct pwc_device
21062306a36Sopenharmony_ci{
21162306a36Sopenharmony_ci	struct video_device vdev;
21262306a36Sopenharmony_ci	struct v4l2_device v4l2_dev;
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ci	/* videobuf2 queue and queued buffers list */
21562306a36Sopenharmony_ci	struct vb2_queue vb_queue;
21662306a36Sopenharmony_ci	struct list_head queued_bufs;
21762306a36Sopenharmony_ci	spinlock_t queued_bufs_lock; /* Protects queued_bufs */
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci	/* If taking both locks vb_queue_lock must always be locked first! */
22062306a36Sopenharmony_ci	struct mutex v4l2_lock;      /* Protects everything else */
22162306a36Sopenharmony_ci	struct mutex vb_queue_lock;  /* Protects vb_queue and capt_file */
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci	/* Pointer to our usb_device, will be NULL after unplug */
22462306a36Sopenharmony_ci	struct usb_device *udev; /* Both mutexes most be hold when setting! */
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci	/* type of cam (645, 646, 675, 680, 690, 720, 730, 740, 750) */
22762306a36Sopenharmony_ci	int type;
22862306a36Sopenharmony_ci	int release;		/* release number */
22962306a36Sopenharmony_ci	int features;		/* feature bits */
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci	/*** Video data ***/
23262306a36Sopenharmony_ci	int vendpoint;		/* video isoc endpoint */
23362306a36Sopenharmony_ci	int vcinterface;	/* video control interface */
23462306a36Sopenharmony_ci	int valternate;		/* alternate interface needed */
23562306a36Sopenharmony_ci	int vframes;		/* frames-per-second */
23662306a36Sopenharmony_ci	int pixfmt;		/* pixelformat: V4L2_PIX_FMT_YUV420 or _PWCX */
23762306a36Sopenharmony_ci	int vframe_count;	/* received frames */
23862306a36Sopenharmony_ci	int vmax_packet_size;	/* USB maxpacket size */
23962306a36Sopenharmony_ci	int vlast_packet_size;	/* for frame synchronisation */
24062306a36Sopenharmony_ci	int visoc_errors;	/* number of contiguous ISOC errors */
24162306a36Sopenharmony_ci	int vbandlength;	/* compressed band length; 0 is uncompressed */
24262306a36Sopenharmony_ci	char vsync;		/* used by isoc handler */
24362306a36Sopenharmony_ci	char vmirror;		/* for ToUCaM series */
24462306a36Sopenharmony_ci	char power_save;	/* Do powersaving for this cam */
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_ci	unsigned char cmd_buf[13];
24762306a36Sopenharmony_ci	unsigned char *ctrl_buf;
24862306a36Sopenharmony_ci
24962306a36Sopenharmony_ci	struct urb *urbs[MAX_ISO_BUFS];
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ci	/*
25262306a36Sopenharmony_ci	 * Frame currently being filled, this only gets touched by the
25362306a36Sopenharmony_ci	 * isoc urb complete handler, and by stream start / stop since
25462306a36Sopenharmony_ci	 * start / stop touch it before / after starting / killing the urbs
25562306a36Sopenharmony_ci	 * no locking is needed around this
25662306a36Sopenharmony_ci	 */
25762306a36Sopenharmony_ci	struct pwc_frame_buf *fill_buf;
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci	int frame_header_size, frame_trailer_size;
26062306a36Sopenharmony_ci	int frame_size;
26162306a36Sopenharmony_ci	int frame_total_size;	/* including header & trailer */
26262306a36Sopenharmony_ci	int drop_frames;
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ci	union {	/* private data for decompression engine */
26562306a36Sopenharmony_ci		struct pwc_dec1_private dec1;
26662306a36Sopenharmony_ci		struct pwc_dec23_private dec23;
26762306a36Sopenharmony_ci	};
26862306a36Sopenharmony_ci
26962306a36Sopenharmony_ci	/*
27062306a36Sopenharmony_ci	 * We have an 'image' and a 'view', where 'image' is the fixed-size img
27162306a36Sopenharmony_ci	 * as delivered by the camera, and 'view' is the size requested by the
27262306a36Sopenharmony_ci	 * program. The camera image is centered in this viewport, laced with
27362306a36Sopenharmony_ci	 * a gray or black border. view_min <= image <= view <= view_max;
27462306a36Sopenharmony_ci	 */
27562306a36Sopenharmony_ci	int image_mask;				/* supported sizes */
27662306a36Sopenharmony_ci	int width, height;			/* current resolution */
27762306a36Sopenharmony_ci
27862306a36Sopenharmony_ci#ifdef CONFIG_USB_PWC_INPUT_EVDEV
27962306a36Sopenharmony_ci	struct input_dev *button_dev;	/* webcam snapshot button input */
28062306a36Sopenharmony_ci	char button_phys[64];
28162306a36Sopenharmony_ci#endif
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_ci	/* controls */
28462306a36Sopenharmony_ci	struct v4l2_ctrl_handler	ctrl_handler;
28562306a36Sopenharmony_ci	u16				saturation_fmt;
28662306a36Sopenharmony_ci	struct v4l2_ctrl		*brightness;
28762306a36Sopenharmony_ci	struct v4l2_ctrl		*contrast;
28862306a36Sopenharmony_ci	struct v4l2_ctrl		*saturation;
28962306a36Sopenharmony_ci	struct v4l2_ctrl		*gamma;
29062306a36Sopenharmony_ci	struct {
29162306a36Sopenharmony_ci		/* awb / red-blue balance cluster */
29262306a36Sopenharmony_ci		struct v4l2_ctrl	*auto_white_balance;
29362306a36Sopenharmony_ci		struct v4l2_ctrl	*red_balance;
29462306a36Sopenharmony_ci		struct v4l2_ctrl	*blue_balance;
29562306a36Sopenharmony_ci		/* usb ctrl transfers are slow, so we cache things */
29662306a36Sopenharmony_ci		int			color_bal_valid;
29762306a36Sopenharmony_ci		unsigned long		last_color_bal_update; /* In jiffies */
29862306a36Sopenharmony_ci		s32			last_red_balance;
29962306a36Sopenharmony_ci		s32			last_blue_balance;
30062306a36Sopenharmony_ci	};
30162306a36Sopenharmony_ci	struct {
30262306a36Sopenharmony_ci		/* autogain / gain cluster */
30362306a36Sopenharmony_ci		struct v4l2_ctrl	*autogain;
30462306a36Sopenharmony_ci		struct v4l2_ctrl	*gain;
30562306a36Sopenharmony_ci		int			gain_valid;
30662306a36Sopenharmony_ci		unsigned long		last_gain_update; /* In jiffies */
30762306a36Sopenharmony_ci		s32			last_gain;
30862306a36Sopenharmony_ci	};
30962306a36Sopenharmony_ci	struct {
31062306a36Sopenharmony_ci		/* exposure_auto / exposure cluster */
31162306a36Sopenharmony_ci		struct v4l2_ctrl	*exposure_auto;
31262306a36Sopenharmony_ci		struct v4l2_ctrl	*exposure;
31362306a36Sopenharmony_ci		int			exposure_valid;
31462306a36Sopenharmony_ci		unsigned long		last_exposure_update; /* In jiffies */
31562306a36Sopenharmony_ci		s32			last_exposure;
31662306a36Sopenharmony_ci	};
31762306a36Sopenharmony_ci	struct v4l2_ctrl		*colorfx;
31862306a36Sopenharmony_ci	struct {
31962306a36Sopenharmony_ci		/* autocontour/contour cluster */
32062306a36Sopenharmony_ci		struct v4l2_ctrl	*autocontour;
32162306a36Sopenharmony_ci		struct v4l2_ctrl	*contour;
32262306a36Sopenharmony_ci	};
32362306a36Sopenharmony_ci	struct v4l2_ctrl		*backlight;
32462306a36Sopenharmony_ci	struct v4l2_ctrl		*flicker;
32562306a36Sopenharmony_ci	struct v4l2_ctrl		*noise_reduction;
32662306a36Sopenharmony_ci	struct v4l2_ctrl		*save_user;
32762306a36Sopenharmony_ci	struct v4l2_ctrl		*restore_user;
32862306a36Sopenharmony_ci	struct v4l2_ctrl		*restore_factory;
32962306a36Sopenharmony_ci	struct v4l2_ctrl		*awb_speed;
33062306a36Sopenharmony_ci	struct v4l2_ctrl		*awb_delay;
33162306a36Sopenharmony_ci	struct {
33262306a36Sopenharmony_ci		/* motor control cluster */
33362306a36Sopenharmony_ci		struct v4l2_ctrl	*motor_pan;
33462306a36Sopenharmony_ci		struct v4l2_ctrl	*motor_tilt;
33562306a36Sopenharmony_ci		struct v4l2_ctrl	*motor_pan_reset;
33662306a36Sopenharmony_ci		struct v4l2_ctrl	*motor_tilt_reset;
33762306a36Sopenharmony_ci	};
33862306a36Sopenharmony_ci	/* CODEC3 models have both gain and exposure controlled by autogain */
33962306a36Sopenharmony_ci	struct v4l2_ctrl		*autogain_expo_cluster[3];
34062306a36Sopenharmony_ci};
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_ci/* Global variables */
34362306a36Sopenharmony_ci#ifdef CONFIG_USB_PWC_DEBUG
34462306a36Sopenharmony_ciextern int pwc_trace;
34562306a36Sopenharmony_ci#endif
34662306a36Sopenharmony_ci
34762306a36Sopenharmony_ci/** Functions in pwc-misc.c */
34862306a36Sopenharmony_ci/* sizes in pixels */
34962306a36Sopenharmony_ciextern const int pwc_image_sizes[PSZ_MAX][2];
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_ciint pwc_get_size(struct pwc_device *pdev, int width, int height);
35262306a36Sopenharmony_civoid pwc_construct(struct pwc_device *pdev);
35362306a36Sopenharmony_ci
35462306a36Sopenharmony_ci/** Functions in pwc-ctrl.c */
35562306a36Sopenharmony_ci/* Request a certain video mode. Returns < 0 if not possible */
35662306a36Sopenharmony_ciextern int pwc_set_video_mode(struct pwc_device *pdev, int width, int height,
35762306a36Sopenharmony_ci	int pixfmt, int frames, int *compression, int send_to_cam);
35862306a36Sopenharmony_ciextern unsigned int pwc_get_fps(struct pwc_device *pdev, unsigned int index, unsigned int size);
35962306a36Sopenharmony_ciextern int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value);
36062306a36Sopenharmony_ciextern int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor);
36162306a36Sopenharmony_ciextern int send_control_msg(struct pwc_device *pdev,
36262306a36Sopenharmony_ci			    u8 request, u16 value, void *buf, int buflen);
36362306a36Sopenharmony_ci
36462306a36Sopenharmony_ci/* Control get / set helpers */
36562306a36Sopenharmony_ciint pwc_get_u8_ctrl(struct pwc_device *pdev, u8 request, u16 value, int *data);
36662306a36Sopenharmony_ciint pwc_set_u8_ctrl(struct pwc_device *pdev, u8 request, u16 value, u8 data);
36762306a36Sopenharmony_ciint pwc_get_s8_ctrl(struct pwc_device *pdev, u8 request, u16 value, int *data);
36862306a36Sopenharmony_ci#define pwc_set_s8_ctrl pwc_set_u8_ctrl
36962306a36Sopenharmony_ciint pwc_get_u16_ctrl(struct pwc_device *pdev, u8 request, u16 value, int *dat);
37062306a36Sopenharmony_ciint pwc_set_u16_ctrl(struct pwc_device *pdev, u8 request, u16 value, u16 data);
37162306a36Sopenharmony_ciint pwc_button_ctrl(struct pwc_device *pdev, u16 value);
37262306a36Sopenharmony_ciint pwc_init_controls(struct pwc_device *pdev);
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_ci/* Power down or up the camera; not supported by all models */
37562306a36Sopenharmony_ciextern void pwc_camera_power(struct pwc_device *pdev, int power);
37662306a36Sopenharmony_ci
37762306a36Sopenharmony_ciextern const struct v4l2_ioctl_ops pwc_ioctl_ops;
37862306a36Sopenharmony_ci
37962306a36Sopenharmony_ci/** pwc-uncompress.c */
38062306a36Sopenharmony_ci/* Expand frame to image, possibly including decompression. Uses read_frame and fill_image */
38162306a36Sopenharmony_ciint pwc_decompress(struct pwc_device *pdev, struct pwc_frame_buf *fbuf);
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_ci#endif
384