18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *		Connexant Cx11646 library
48c2ecf20Sopenharmony_ci *		Copyright (C) 2004 Michel Xhaard mxhaard@magic.fr
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#define MODULE_NAME "conex"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include "gspca.h"
148c2ecf20Sopenharmony_ci#define CONEX_CAM 1		/* special JPEG header */
158c2ecf20Sopenharmony_ci#include "jpeg.h"
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ciMODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
188c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("GSPCA USB Conexant Camera Driver");
198c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define QUALITY 50
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/* specific webcam descriptor */
248c2ecf20Sopenharmony_cistruct sd {
258c2ecf20Sopenharmony_ci	struct gspca_dev gspca_dev;	/* !! must be the first item */
268c2ecf20Sopenharmony_ci	struct v4l2_ctrl *brightness;
278c2ecf20Sopenharmony_ci	struct v4l2_ctrl *contrast;
288c2ecf20Sopenharmony_ci	struct v4l2_ctrl *sat;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	u8 jpeg_hdr[JPEG_HDR_SZ];
318c2ecf20Sopenharmony_ci};
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_cistatic const struct v4l2_pix_format vga_mode[] = {
348c2ecf20Sopenharmony_ci	{176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
358c2ecf20Sopenharmony_ci		.bytesperline = 176,
368c2ecf20Sopenharmony_ci		.sizeimage = 176 * 144 * 3 / 8 + 590,
378c2ecf20Sopenharmony_ci		.colorspace = V4L2_COLORSPACE_JPEG,
388c2ecf20Sopenharmony_ci		.priv = 3},
398c2ecf20Sopenharmony_ci	{320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
408c2ecf20Sopenharmony_ci		.bytesperline = 320,
418c2ecf20Sopenharmony_ci		.sizeimage = 320 * 240 * 3 / 8 + 590,
428c2ecf20Sopenharmony_ci		.colorspace = V4L2_COLORSPACE_JPEG,
438c2ecf20Sopenharmony_ci		.priv = 2},
448c2ecf20Sopenharmony_ci	{352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
458c2ecf20Sopenharmony_ci		.bytesperline = 352,
468c2ecf20Sopenharmony_ci		.sizeimage = 352 * 288 * 3 / 8 + 590,
478c2ecf20Sopenharmony_ci		.colorspace = V4L2_COLORSPACE_JPEG,
488c2ecf20Sopenharmony_ci		.priv = 1},
498c2ecf20Sopenharmony_ci	{640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
508c2ecf20Sopenharmony_ci		.bytesperline = 640,
518c2ecf20Sopenharmony_ci		.sizeimage = 640 * 480 * 3 / 8 + 590,
528c2ecf20Sopenharmony_ci		.colorspace = V4L2_COLORSPACE_JPEG,
538c2ecf20Sopenharmony_ci		.priv = 0},
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* the read bytes are found in gspca_dev->usb_buf */
578c2ecf20Sopenharmony_cistatic void reg_r(struct gspca_dev *gspca_dev,
588c2ecf20Sopenharmony_ci		  __u16 index,
598c2ecf20Sopenharmony_ci		  __u16 len)
608c2ecf20Sopenharmony_ci{
618c2ecf20Sopenharmony_ci	struct usb_device *dev = gspca_dev->dev;
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	if (len > USB_BUF_SZ) {
648c2ecf20Sopenharmony_ci		gspca_err(gspca_dev, "reg_r: buffer overflow\n");
658c2ecf20Sopenharmony_ci		return;
668c2ecf20Sopenharmony_ci	}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	usb_control_msg(dev,
698c2ecf20Sopenharmony_ci			usb_rcvctrlpipe(dev, 0),
708c2ecf20Sopenharmony_ci			0,
718c2ecf20Sopenharmony_ci			USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
728c2ecf20Sopenharmony_ci			0,
738c2ecf20Sopenharmony_ci			index, gspca_dev->usb_buf, len,
748c2ecf20Sopenharmony_ci			500);
758c2ecf20Sopenharmony_ci	gspca_dbg(gspca_dev, D_USBI, "reg read [%02x] -> %02x ..\n",
768c2ecf20Sopenharmony_ci		  index, gspca_dev->usb_buf[0]);
778c2ecf20Sopenharmony_ci}
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/* the bytes to write are in gspca_dev->usb_buf */
808c2ecf20Sopenharmony_cistatic void reg_w_val(struct gspca_dev *gspca_dev,
818c2ecf20Sopenharmony_ci			__u16 index,
828c2ecf20Sopenharmony_ci			__u8 val)
838c2ecf20Sopenharmony_ci{
848c2ecf20Sopenharmony_ci	struct usb_device *dev = gspca_dev->dev;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	gspca_dev->usb_buf[0] = val;
878c2ecf20Sopenharmony_ci	usb_control_msg(dev,
888c2ecf20Sopenharmony_ci			usb_sndctrlpipe(dev, 0),
898c2ecf20Sopenharmony_ci			0,
908c2ecf20Sopenharmony_ci			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
918c2ecf20Sopenharmony_ci			0,
928c2ecf20Sopenharmony_ci			index, gspca_dev->usb_buf, 1, 500);
938c2ecf20Sopenharmony_ci}
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistatic void reg_w(struct gspca_dev *gspca_dev,
968c2ecf20Sopenharmony_ci		  __u16 index,
978c2ecf20Sopenharmony_ci		  const __u8 *buffer,
988c2ecf20Sopenharmony_ci		  __u16 len)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	struct usb_device *dev = gspca_dev->dev;
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	if (len > USB_BUF_SZ) {
1038c2ecf20Sopenharmony_ci		gspca_err(gspca_dev, "reg_w: buffer overflow\n");
1048c2ecf20Sopenharmony_ci		return;
1058c2ecf20Sopenharmony_ci	}
1068c2ecf20Sopenharmony_ci	gspca_dbg(gspca_dev, D_USBO, "reg write [%02x] = %02x..\n",
1078c2ecf20Sopenharmony_ci		  index, *buffer);
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci	memcpy(gspca_dev->usb_buf, buffer, len);
1108c2ecf20Sopenharmony_ci	usb_control_msg(dev,
1118c2ecf20Sopenharmony_ci			usb_sndctrlpipe(dev, 0),
1128c2ecf20Sopenharmony_ci			0,
1138c2ecf20Sopenharmony_ci			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1148c2ecf20Sopenharmony_ci			0,
1158c2ecf20Sopenharmony_ci			index, gspca_dev->usb_buf, len, 500);
1168c2ecf20Sopenharmony_ci}
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_cistatic const __u8 cx_sensor_init[][4] = {
1198c2ecf20Sopenharmony_ci	{0x88, 0x11, 0x01, 0x01},
1208c2ecf20Sopenharmony_ci	{0x88, 0x12, 0x70, 0x01},
1218c2ecf20Sopenharmony_ci	{0x88, 0x0f, 0x00, 0x01},
1228c2ecf20Sopenharmony_ci	{0x88, 0x05, 0x01, 0x01},
1238c2ecf20Sopenharmony_ci	{}
1248c2ecf20Sopenharmony_ci};
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistatic const __u8 cx11646_fw1[][3] = {
1278c2ecf20Sopenharmony_ci	{0x00, 0x02, 0x00},
1288c2ecf20Sopenharmony_ci	{0x01, 0x43, 0x00},
1298c2ecf20Sopenharmony_ci	{0x02, 0xA7, 0x00},
1308c2ecf20Sopenharmony_ci	{0x03, 0x8B, 0x01},
1318c2ecf20Sopenharmony_ci	{0x04, 0xE9, 0x02},
1328c2ecf20Sopenharmony_ci	{0x05, 0x08, 0x04},
1338c2ecf20Sopenharmony_ci	{0x06, 0x08, 0x05},
1348c2ecf20Sopenharmony_ci	{0x07, 0x07, 0x06},
1358c2ecf20Sopenharmony_ci	{0x08, 0xE7, 0x06},
1368c2ecf20Sopenharmony_ci	{0x09, 0xC6, 0x07},
1378c2ecf20Sopenharmony_ci	{0x0A, 0x86, 0x08},
1388c2ecf20Sopenharmony_ci	{0x0B, 0x46, 0x09},
1398c2ecf20Sopenharmony_ci	{0x0C, 0x05, 0x0A},
1408c2ecf20Sopenharmony_ci	{0x0D, 0xA5, 0x0A},
1418c2ecf20Sopenharmony_ci	{0x0E, 0x45, 0x0B},
1428c2ecf20Sopenharmony_ci	{0x0F, 0xE5, 0x0B},
1438c2ecf20Sopenharmony_ci	{0x10, 0x85, 0x0C},
1448c2ecf20Sopenharmony_ci	{0x11, 0x25, 0x0D},
1458c2ecf20Sopenharmony_ci	{0x12, 0xC4, 0x0D},
1468c2ecf20Sopenharmony_ci	{0x13, 0x45, 0x0E},
1478c2ecf20Sopenharmony_ci	{0x14, 0xE4, 0x0E},
1488c2ecf20Sopenharmony_ci	{0x15, 0x64, 0x0F},
1498c2ecf20Sopenharmony_ci	{0x16, 0xE4, 0x0F},
1508c2ecf20Sopenharmony_ci	{0x17, 0x64, 0x10},
1518c2ecf20Sopenharmony_ci	{0x18, 0xE4, 0x10},
1528c2ecf20Sopenharmony_ci	{0x19, 0x64, 0x11},
1538c2ecf20Sopenharmony_ci	{0x1A, 0xE4, 0x11},
1548c2ecf20Sopenharmony_ci	{0x1B, 0x64, 0x12},
1558c2ecf20Sopenharmony_ci	{0x1C, 0xE3, 0x12},
1568c2ecf20Sopenharmony_ci	{0x1D, 0x44, 0x13},
1578c2ecf20Sopenharmony_ci	{0x1E, 0xC3, 0x13},
1588c2ecf20Sopenharmony_ci	{0x1F, 0x24, 0x14},
1598c2ecf20Sopenharmony_ci	{0x20, 0xA3, 0x14},
1608c2ecf20Sopenharmony_ci	{0x21, 0x04, 0x15},
1618c2ecf20Sopenharmony_ci	{0x22, 0x83, 0x15},
1628c2ecf20Sopenharmony_ci	{0x23, 0xE3, 0x15},
1638c2ecf20Sopenharmony_ci	{0x24, 0x43, 0x16},
1648c2ecf20Sopenharmony_ci	{0x25, 0xA4, 0x16},
1658c2ecf20Sopenharmony_ci	{0x26, 0x23, 0x17},
1668c2ecf20Sopenharmony_ci	{0x27, 0x83, 0x17},
1678c2ecf20Sopenharmony_ci	{0x28, 0xE3, 0x17},
1688c2ecf20Sopenharmony_ci	{0x29, 0x43, 0x18},
1698c2ecf20Sopenharmony_ci	{0x2A, 0xA3, 0x18},
1708c2ecf20Sopenharmony_ci	{0x2B, 0x03, 0x19},
1718c2ecf20Sopenharmony_ci	{0x2C, 0x63, 0x19},
1728c2ecf20Sopenharmony_ci	{0x2D, 0xC3, 0x19},
1738c2ecf20Sopenharmony_ci	{0x2E, 0x22, 0x1A},
1748c2ecf20Sopenharmony_ci	{0x2F, 0x63, 0x1A},
1758c2ecf20Sopenharmony_ci	{0x30, 0xC3, 0x1A},
1768c2ecf20Sopenharmony_ci	{0x31, 0x23, 0x1B},
1778c2ecf20Sopenharmony_ci	{0x32, 0x83, 0x1B},
1788c2ecf20Sopenharmony_ci	{0x33, 0xE2, 0x1B},
1798c2ecf20Sopenharmony_ci	{0x34, 0x23, 0x1C},
1808c2ecf20Sopenharmony_ci	{0x35, 0x83, 0x1C},
1818c2ecf20Sopenharmony_ci	{0x36, 0xE2, 0x1C},
1828c2ecf20Sopenharmony_ci	{0x37, 0x23, 0x1D},
1838c2ecf20Sopenharmony_ci	{0x38, 0x83, 0x1D},
1848c2ecf20Sopenharmony_ci	{0x39, 0xE2, 0x1D},
1858c2ecf20Sopenharmony_ci	{0x3A, 0x23, 0x1E},
1868c2ecf20Sopenharmony_ci	{0x3B, 0x82, 0x1E},
1878c2ecf20Sopenharmony_ci	{0x3C, 0xC3, 0x1E},
1888c2ecf20Sopenharmony_ci	{0x3D, 0x22, 0x1F},
1898c2ecf20Sopenharmony_ci	{0x3E, 0x63, 0x1F},
1908c2ecf20Sopenharmony_ci	{0x3F, 0xC1, 0x1F},
1918c2ecf20Sopenharmony_ci	{}
1928c2ecf20Sopenharmony_ci};
1938c2ecf20Sopenharmony_cistatic void cx11646_fw(struct gspca_dev*gspca_dev)
1948c2ecf20Sopenharmony_ci{
1958c2ecf20Sopenharmony_ci	int i = 0;
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x006a, 0x02);
1988c2ecf20Sopenharmony_ci	while (cx11646_fw1[i][1]) {
1998c2ecf20Sopenharmony_ci		reg_w(gspca_dev, 0x006b, cx11646_fw1[i], 3);
2008c2ecf20Sopenharmony_ci		i++;
2018c2ecf20Sopenharmony_ci	}
2028c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x006a, 0x00);
2038c2ecf20Sopenharmony_ci}
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_cistatic const __u8 cxsensor[] = {
2068c2ecf20Sopenharmony_ci	0x88, 0x12, 0x70, 0x01,
2078c2ecf20Sopenharmony_ci	0x88, 0x0d, 0x02, 0x01,
2088c2ecf20Sopenharmony_ci	0x88, 0x0f, 0x00, 0x01,
2098c2ecf20Sopenharmony_ci	0x88, 0x03, 0x71, 0x01, 0x88, 0x04, 0x00, 0x01,	/* 3 */
2108c2ecf20Sopenharmony_ci	0x88, 0x02, 0x10, 0x01,
2118c2ecf20Sopenharmony_ci	0x88, 0x00, 0xD4, 0x01, 0x88, 0x01, 0x01, 0x01,	/* 5 */
2128c2ecf20Sopenharmony_ci	0x88, 0x0B, 0x00, 0x01,
2138c2ecf20Sopenharmony_ci	0x88, 0x0A, 0x0A, 0x01,
2148c2ecf20Sopenharmony_ci	0x88, 0x00, 0x08, 0x01, 0x88, 0x01, 0x00, 0x01,	/* 8 */
2158c2ecf20Sopenharmony_ci	0x88, 0x05, 0x01, 0x01,
2168c2ecf20Sopenharmony_ci	0xA1, 0x18, 0x00, 0x01,
2178c2ecf20Sopenharmony_ci	0x00
2188c2ecf20Sopenharmony_ci};
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistatic const __u8 reg20[] = { 0x10, 0x42, 0x81, 0x19, 0xd3, 0xff, 0xa7, 0xff };
2218c2ecf20Sopenharmony_cistatic const __u8 reg28[] = { 0x87, 0x00, 0x87, 0x00, 0x8f, 0xff, 0xea, 0xff };
2228c2ecf20Sopenharmony_cistatic const __u8 reg10[] = { 0xb1, 0xb1 };
2238c2ecf20Sopenharmony_cistatic const __u8 reg71a[] = { 0x08, 0x18, 0x0a, 0x1e };	/* 640 */
2248c2ecf20Sopenharmony_cistatic const __u8 reg71b[] = { 0x04, 0x0c, 0x05, 0x0f };
2258c2ecf20Sopenharmony_ci	/* 352{0x04,0x0a,0x06,0x12}; //352{0x05,0x0e,0x06,0x11}; //352 */
2268c2ecf20Sopenharmony_cistatic const __u8 reg71c[] = { 0x02, 0x07, 0x03, 0x09 };
2278c2ecf20Sopenharmony_ci					/* 320{0x04,0x0c,0x05,0x0f}; //320 */
2288c2ecf20Sopenharmony_cistatic const __u8 reg71d[] = { 0x02, 0x07, 0x03, 0x09 };	/* 176 */
2298c2ecf20Sopenharmony_cistatic const __u8 reg7b[] = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff };
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_cistatic void cx_sensor(struct gspca_dev*gspca_dev)
2328c2ecf20Sopenharmony_ci{
2338c2ecf20Sopenharmony_ci	int i = 0;
2348c2ecf20Sopenharmony_ci	int length;
2358c2ecf20Sopenharmony_ci	const __u8 *ptsensor = cxsensor;
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0020, reg20, 8);
2388c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0028, reg28, 8);
2398c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0010, reg10, 2);
2408c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0092, 0x03);
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci	switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
2438c2ecf20Sopenharmony_ci	case 0:
2448c2ecf20Sopenharmony_ci		reg_w(gspca_dev, 0x0071, reg71a, 4);
2458c2ecf20Sopenharmony_ci		break;
2468c2ecf20Sopenharmony_ci	case 1:
2478c2ecf20Sopenharmony_ci		reg_w(gspca_dev, 0x0071, reg71b, 4);
2488c2ecf20Sopenharmony_ci		break;
2498c2ecf20Sopenharmony_ci	default:
2508c2ecf20Sopenharmony_ci/*	case 2: */
2518c2ecf20Sopenharmony_ci		reg_w(gspca_dev, 0x0071, reg71c, 4);
2528c2ecf20Sopenharmony_ci		break;
2538c2ecf20Sopenharmony_ci	case 3:
2548c2ecf20Sopenharmony_ci		reg_w(gspca_dev, 0x0071, reg71d, 4);
2558c2ecf20Sopenharmony_ci		break;
2568c2ecf20Sopenharmony_ci	}
2578c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x007b, reg7b, 6);
2588c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x00f8, 0x00);
2598c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0010, reg10, 2);
2608c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0098, 0x41);
2618c2ecf20Sopenharmony_ci	for (i = 0; i < 11; i++) {
2628c2ecf20Sopenharmony_ci		if (i == 3 || i == 5 || i == 8)
2638c2ecf20Sopenharmony_ci			length = 8;
2648c2ecf20Sopenharmony_ci		else
2658c2ecf20Sopenharmony_ci			length = 4;
2668c2ecf20Sopenharmony_ci		reg_w(gspca_dev, 0x00e5, ptsensor, length);
2678c2ecf20Sopenharmony_ci		if (length == 4)
2688c2ecf20Sopenharmony_ci			reg_r(gspca_dev, 0x00e8, 1);
2698c2ecf20Sopenharmony_ci		else
2708c2ecf20Sopenharmony_ci			reg_r(gspca_dev, 0x00e8, length);
2718c2ecf20Sopenharmony_ci		ptsensor += length;
2728c2ecf20Sopenharmony_ci	}
2738c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x00e7, 8);
2748c2ecf20Sopenharmony_ci}
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_cistatic const __u8 cx_inits_176[] = {
2778c2ecf20Sopenharmony_ci	0x33, 0x81, 0xB0, 0x00, 0x90, 0x00, 0x0A, 0x03,	/* 176x144 */
2788c2ecf20Sopenharmony_ci	0x00, 0x03, 0x03, 0x03, 0x1B, 0x05, 0x30, 0x03,
2798c2ecf20Sopenharmony_ci	0x65, 0x15, 0x18, 0x25, 0x03, 0x25, 0x08, 0x30,
2808c2ecf20Sopenharmony_ci	0x3B, 0x25, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00,
2818c2ecf20Sopenharmony_ci	0xDC, 0xFF, 0xEE, 0xFF, 0xC5, 0xFF, 0xBF, 0xFF,
2828c2ecf20Sopenharmony_ci	0xF7, 0xFF, 0x88, 0xFF, 0x66, 0x02, 0x28, 0x02,
2838c2ecf20Sopenharmony_ci	0x1E, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2848c2ecf20Sopenharmony_ci};
2858c2ecf20Sopenharmony_cistatic const __u8 cx_inits_320[] = {
2868c2ecf20Sopenharmony_ci	0x7f, 0x7f, 0x40, 0x01, 0xf0, 0x00, 0x02, 0x01,
2878c2ecf20Sopenharmony_ci	0x00, 0x01, 0x01, 0x01, 0x10, 0x00, 0x02, 0x01,
2888c2ecf20Sopenharmony_ci	0x65, 0x45, 0xfa, 0x4c, 0x2c, 0xdf, 0xb9, 0x81,
2898c2ecf20Sopenharmony_ci	0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
2908c2ecf20Sopenharmony_ci	0xe2, 0xff, 0xf1, 0xff, 0xc2, 0xff, 0xbc, 0xff,
2918c2ecf20Sopenharmony_ci	0xf5, 0xff, 0x6d, 0xff, 0xf6, 0x01, 0x43, 0x02,
2928c2ecf20Sopenharmony_ci	0xd3, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2938c2ecf20Sopenharmony_ci};
2948c2ecf20Sopenharmony_cistatic const __u8 cx_inits_352[] = {
2958c2ecf20Sopenharmony_ci	0x2e, 0x7c, 0x60, 0x01, 0x20, 0x01, 0x05, 0x03,
2968c2ecf20Sopenharmony_ci	0x00, 0x06, 0x03, 0x06, 0x1b, 0x10, 0x05, 0x3b,
2978c2ecf20Sopenharmony_ci	0x30, 0x25, 0x18, 0x25, 0x08, 0x30, 0x03, 0x25,
2988c2ecf20Sopenharmony_ci	0x3b, 0x30, 0x25, 0x1b, 0x10, 0x05, 0x00, 0x00,
2998c2ecf20Sopenharmony_ci	0xe3, 0xff, 0xf1, 0xff, 0xc2, 0xff, 0xbc, 0xff,
3008c2ecf20Sopenharmony_ci	0xf5, 0xff, 0x6b, 0xff, 0xee, 0x01, 0x43, 0x02,
3018c2ecf20Sopenharmony_ci	0xe4, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
3028c2ecf20Sopenharmony_ci};
3038c2ecf20Sopenharmony_cistatic const __u8 cx_inits_640[] = {
3048c2ecf20Sopenharmony_ci	0x7e, 0x7e, 0x80, 0x02, 0xe0, 0x01, 0x01, 0x01,
3058c2ecf20Sopenharmony_ci	0x00, 0x02, 0x01, 0x02, 0x10, 0x30, 0x01, 0x01,
3068c2ecf20Sopenharmony_ci	0x65, 0x45, 0xf7, 0x52, 0x2c, 0xdf, 0xb9, 0x81,
3078c2ecf20Sopenharmony_ci	0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
3088c2ecf20Sopenharmony_ci	0xe2, 0xff, 0xf1, 0xff, 0xc2, 0xff, 0xbc, 0xff,
3098c2ecf20Sopenharmony_ci	0xf6, 0xff, 0x7b, 0xff, 0x01, 0x02, 0x43, 0x02,
3108c2ecf20Sopenharmony_ci	0x77, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
3118c2ecf20Sopenharmony_ci};
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_cistatic void cx11646_initsize(struct gspca_dev *gspca_dev)
3148c2ecf20Sopenharmony_ci{
3158c2ecf20Sopenharmony_ci	const __u8 *cxinit;
3168c2ecf20Sopenharmony_ci	static const __u8 reg12[] = { 0x08, 0x05, 0x07, 0x04, 0x24 };
3178c2ecf20Sopenharmony_ci	static const __u8 reg17[] =
3188c2ecf20Sopenharmony_ci			{ 0x0a, 0x00, 0xf2, 0x01, 0x0f, 0x00, 0x97, 0x02 };
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci	switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
3218c2ecf20Sopenharmony_ci	case 0:
3228c2ecf20Sopenharmony_ci		cxinit = cx_inits_640;
3238c2ecf20Sopenharmony_ci		break;
3248c2ecf20Sopenharmony_ci	case 1:
3258c2ecf20Sopenharmony_ci		cxinit = cx_inits_352;
3268c2ecf20Sopenharmony_ci		break;
3278c2ecf20Sopenharmony_ci	default:
3288c2ecf20Sopenharmony_ci/*	case 2: */
3298c2ecf20Sopenharmony_ci		cxinit = cx_inits_320;
3308c2ecf20Sopenharmony_ci		break;
3318c2ecf20Sopenharmony_ci	case 3:
3328c2ecf20Sopenharmony_ci		cxinit = cx_inits_176;
3338c2ecf20Sopenharmony_ci		break;
3348c2ecf20Sopenharmony_ci	}
3358c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x009a, 0x01);
3368c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0010, 0x10);
3378c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0012, reg12, 5);
3388c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0017, reg17, 8);
3398c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x00c0, 0x00);
3408c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x00c1, 0x04);
3418c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x00c2, 0x04);
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0061, cxinit, 8);
3448c2ecf20Sopenharmony_ci	cxinit += 8;
3458c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x00ca, cxinit, 8);
3468c2ecf20Sopenharmony_ci	cxinit += 8;
3478c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x00d2, cxinit, 8);
3488c2ecf20Sopenharmony_ci	cxinit += 8;
3498c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x00da, cxinit, 6);
3508c2ecf20Sopenharmony_ci	cxinit += 8;
3518c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0041, cxinit, 8);
3528c2ecf20Sopenharmony_ci	cxinit += 8;
3538c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0049, cxinit, 8);
3548c2ecf20Sopenharmony_ci	cxinit += 8;
3558c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0051, cxinit, 2);
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0010, 1);
3588c2ecf20Sopenharmony_ci}
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_cistatic const __u8 cx_jpeg_init[][8] = {
3618c2ecf20Sopenharmony_ci	{0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00, 0x15},	/* 1 */
3628c2ecf20Sopenharmony_ci	{0x0f, 0x10, 0x12, 0x10, 0x0d, 0x15, 0x12, 0x11},
3638c2ecf20Sopenharmony_ci	{0x12, 0x18, 0x16, 0x15, 0x19, 0x20, 0x35, 0x22},
3648c2ecf20Sopenharmony_ci	{0x20, 0x1d, 0x1d, 0x20, 0x41, 0x2e, 0x31, 0x26},
3658c2ecf20Sopenharmony_ci	{0x35, 0x4d, 0x43, 0x51, 0x4f, 0x4b, 0x43, 0x4a},
3668c2ecf20Sopenharmony_ci	{0x49, 0x55, 0x5F, 0x79, 0x67, 0x55, 0x5A, 0x73},
3678c2ecf20Sopenharmony_ci	{0x5B, 0x49, 0x4A, 0x6A, 0x90, 0x6B, 0x73, 0x7D},
3688c2ecf20Sopenharmony_ci	{0x81, 0x88, 0x89, 0x88, 0x52, 0x66, 0x95, 0xA0},
3698c2ecf20Sopenharmony_ci	{0x94, 0x84, 0x9E, 0x79, 0x85, 0x88, 0x83, 0x01},
3708c2ecf20Sopenharmony_ci	{0x15, 0x0F, 0x10, 0x12, 0x10, 0x0D, 0x15, 0x12},
3718c2ecf20Sopenharmony_ci	{0x11, 0x12, 0x18, 0x16, 0x15, 0x19, 0x20, 0x35},
3728c2ecf20Sopenharmony_ci	{0x22, 0x20, 0x1D, 0x1D, 0x20, 0x41, 0x2E, 0x31},
3738c2ecf20Sopenharmony_ci	{0x26, 0x35, 0x4D, 0x43, 0x51, 0x4F, 0x4B, 0x43},
3748c2ecf20Sopenharmony_ci	{0x4A, 0x49, 0x55, 0x5F, 0x79, 0x67, 0x55, 0x5A},
3758c2ecf20Sopenharmony_ci	{0x73, 0x5B, 0x49, 0x4A, 0x6A, 0x90, 0x6B, 0x73},
3768c2ecf20Sopenharmony_ci	{0x7D, 0x81, 0x88, 0x89, 0x88, 0x52, 0x66, 0x95},
3778c2ecf20Sopenharmony_ci	{0xA0, 0x94, 0x84, 0x9E, 0x79, 0x85, 0x88, 0x83},
3788c2ecf20Sopenharmony_ci	{0xFF, 0xC4, 0x01, 0xA2, 0x00, 0x00, 0x01, 0x05},
3798c2ecf20Sopenharmony_ci	{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00},
3808c2ecf20Sopenharmony_ci	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02},
3818c2ecf20Sopenharmony_ci	{0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A},
3828c2ecf20Sopenharmony_ci	{0x0B, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01},
3838c2ecf20Sopenharmony_ci	{0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00},
3848c2ecf20Sopenharmony_ci	{0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05},
3858c2ecf20Sopenharmony_ci	{0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x10, 0x00},
3868c2ecf20Sopenharmony_ci	{0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05},
3878c2ecf20Sopenharmony_ci	{0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7D, 0x01},
3888c2ecf20Sopenharmony_ci	{0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21},
3898c2ecf20Sopenharmony_ci	{0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22},
3908c2ecf20Sopenharmony_ci	{0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23},
3918c2ecf20Sopenharmony_ci	{0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, 0x24},
3928c2ecf20Sopenharmony_ci	{0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17},
3938c2ecf20Sopenharmony_ci	{0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29},
3948c2ecf20Sopenharmony_ci	{0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A},
3958c2ecf20Sopenharmony_ci	{0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A},
3968c2ecf20Sopenharmony_ci	{0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A},
3978c2ecf20Sopenharmony_ci	{0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A},
3988c2ecf20Sopenharmony_ci	{0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A},
3998c2ecf20Sopenharmony_ci	{0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A},
4008c2ecf20Sopenharmony_ci	{0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99},
4018c2ecf20Sopenharmony_ci	{0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8},
4028c2ecf20Sopenharmony_ci	{0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7},
4038c2ecf20Sopenharmony_ci	{0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6},
4048c2ecf20Sopenharmony_ci	{0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5},
4058c2ecf20Sopenharmony_ci	{0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2, 0xE3},
4068c2ecf20Sopenharmony_ci	{0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF1},
4078c2ecf20Sopenharmony_ci	{0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9},
4088c2ecf20Sopenharmony_ci	{0xFA, 0x11, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04},
4098c2ecf20Sopenharmony_ci	{0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00, 0x01},
4108c2ecf20Sopenharmony_ci	{0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04},
4118c2ecf20Sopenharmony_ci	{0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07},
4128c2ecf20Sopenharmony_ci	{0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14},
4138c2ecf20Sopenharmony_ci	{0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33},
4148c2ecf20Sopenharmony_ci	{0x52, 0xF0, 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16},
4158c2ecf20Sopenharmony_ci	{0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19},
4168c2ecf20Sopenharmony_ci	{0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x35, 0x36},
4178c2ecf20Sopenharmony_ci	{0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46},
4188c2ecf20Sopenharmony_ci	{0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56},
4198c2ecf20Sopenharmony_ci	{0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66},
4208c2ecf20Sopenharmony_ci	{0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76},
4218c2ecf20Sopenharmony_ci	{0x77, 0x78, 0x79, 0x7A, 0x82, 0x83, 0x84, 0x85},
4228c2ecf20Sopenharmony_ci	{0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94},
4238c2ecf20Sopenharmony_ci	{0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3},
4248c2ecf20Sopenharmony_ci	{0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2},
4258c2ecf20Sopenharmony_ci	{0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA},
4268c2ecf20Sopenharmony_ci	{0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9},
4278c2ecf20Sopenharmony_ci	{0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8},
4288c2ecf20Sopenharmony_ci	{0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7},
4298c2ecf20Sopenharmony_ci	{0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6},
4308c2ecf20Sopenharmony_ci	{0xF7, 0xF8, 0xF9, 0xFA, 0xFF, 0x20, 0x00, 0x1F},
4318c2ecf20Sopenharmony_ci	{0x02, 0x0C, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00},
4328c2ecf20Sopenharmony_ci	{0x00, 0x00, 0x11, 0x00, 0x11, 0x22, 0x00, 0x22},
4338c2ecf20Sopenharmony_ci	{0x22, 0x11, 0x22, 0x22, 0x11, 0x33, 0x33, 0x11},
4348c2ecf20Sopenharmony_ci	{0x44, 0x66, 0x22, 0x55, 0x66, 0xFF, 0xDD, 0x00},
4358c2ecf20Sopenharmony_ci	{0x04, 0x00, 0x14, 0xFF, 0xC0, 0x00, 0x11, 0x08},
4368c2ecf20Sopenharmony_ci	{0x00, 0xF0, 0x01, 0x40, 0x03, 0x00, 0x21, 0x00},
4378c2ecf20Sopenharmony_ci	{0x01, 0x11, 0x01, 0x02, 0x11, 0x01, 0xFF, 0xDA},
4388c2ecf20Sopenharmony_ci	{0x00, 0x0C, 0x03, 0x00, 0x00, 0x01, 0x11, 0x02},
4398c2ecf20Sopenharmony_ci	{0x11, 0x00, 0x3F, 0x00, 0xFF, 0xD9, 0x00, 0x00}	/* 79 */
4408c2ecf20Sopenharmony_ci};
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_cistatic const __u8 cxjpeg_640[][8] = {
4448c2ecf20Sopenharmony_ci	{0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00, 0x10},	/* 1 */
4458c2ecf20Sopenharmony_ci	{0x0b, 0x0c, 0x0e, 0x0c, 0x0a, 0x10, 0x0e, 0x0d},
4468c2ecf20Sopenharmony_ci	{0x0e, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28, 0x1a},
4478c2ecf20Sopenharmony_ci	{0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25, 0x1d},
4488c2ecf20Sopenharmony_ci	{0x28, 0x3a, 0x33, 0x3D, 0x3C, 0x39, 0x33, 0x38},
4498c2ecf20Sopenharmony_ci	{0x37, 0x40, 0x48, 0x5C, 0x4E, 0x40, 0x44, 0x57},
4508c2ecf20Sopenharmony_ci	{0x45, 0x37, 0x38, 0x50, 0x6D, 0x51, 0x57, 0x5F},
4518c2ecf20Sopenharmony_ci	{0x62, 0x67, 0x68, 0x67, 0x3E, 0x4D, 0x71, 0x79},
4528c2ecf20Sopenharmony_ci	{0x70, 0x64, 0x78, 0x5C, 0x65, 0x67, 0x63, 0x01},
4538c2ecf20Sopenharmony_ci	{0x10, 0x0B, 0x0C, 0x0E, 0x0C, 0x0A, 0x10, 0x0E},
4548c2ecf20Sopenharmony_ci	{0x0D, 0x0E, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28},
4558c2ecf20Sopenharmony_ci	{0x1A, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25},
4568c2ecf20Sopenharmony_ci	{0x1D, 0x28, 0x3A, 0x33, 0x3D, 0x3C, 0x39, 0x33},
4578c2ecf20Sopenharmony_ci	{0x38, 0x37, 0x40, 0x48, 0x5C, 0x4E, 0x40, 0x44},
4588c2ecf20Sopenharmony_ci	{0x57, 0x45, 0x37, 0x38, 0x50, 0x6D, 0x51, 0x57},
4598c2ecf20Sopenharmony_ci	{0x5F, 0x62, 0x67, 0x68, 0x67, 0x3E, 0x4D, 0x71},
4608c2ecf20Sopenharmony_ci	{0x79, 0x70, 0x64, 0x78, 0x5C, 0x65, 0x67, 0x63},
4618c2ecf20Sopenharmony_ci	{0xFF, 0x20, 0x00, 0x1F, 0x00, 0x83, 0x00, 0x00},
4628c2ecf20Sopenharmony_ci	{0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00},
4638c2ecf20Sopenharmony_ci	{0x11, 0x22, 0x00, 0x22, 0x22, 0x11, 0x22, 0x22},
4648c2ecf20Sopenharmony_ci	{0x11, 0x33, 0x33, 0x11, 0x44, 0x66, 0x22, 0x55},
4658c2ecf20Sopenharmony_ci	{0x66, 0xFF, 0xDD, 0x00, 0x04, 0x00, 0x28, 0xFF},
4668c2ecf20Sopenharmony_ci	{0xC0, 0x00, 0x11, 0x08, 0x01, 0xE0, 0x02, 0x80},
4678c2ecf20Sopenharmony_ci	{0x03, 0x00, 0x21, 0x00, 0x01, 0x11, 0x01, 0x02},
4688c2ecf20Sopenharmony_ci	{0x11, 0x01, 0xFF, 0xDA, 0x00, 0x0C, 0x03, 0x00},
4698c2ecf20Sopenharmony_ci	{0x00, 0x01, 0x11, 0x02, 0x11, 0x00, 0x3F, 0x00},
4708c2ecf20Sopenharmony_ci	{0xFF, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}	/* 27 */
4718c2ecf20Sopenharmony_ci};
4728c2ecf20Sopenharmony_cistatic const __u8 cxjpeg_352[][8] = {
4738c2ecf20Sopenharmony_ci	{0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00, 0x0d},
4748c2ecf20Sopenharmony_ci	{0x09, 0x09, 0x0b, 0x09, 0x08, 0x0D, 0x0b, 0x0a},
4758c2ecf20Sopenharmony_ci	{0x0b, 0x0e, 0x0d, 0x0d, 0x0f, 0x13, 0x1f, 0x14},
4768c2ecf20Sopenharmony_ci	{0x13, 0x11, 0x11, 0x13, 0x26, 0x1b, 0x1d, 0x17},
4778c2ecf20Sopenharmony_ci	{0x1F, 0x2D, 0x28, 0x30, 0x2F, 0x2D, 0x28, 0x2C},
4788c2ecf20Sopenharmony_ci	{0x2B, 0x32, 0x38, 0x48, 0x3D, 0x32, 0x35, 0x44},
4798c2ecf20Sopenharmony_ci	{0x36, 0x2B, 0x2C, 0x3F, 0x55, 0x3F, 0x44, 0x4A},
4808c2ecf20Sopenharmony_ci	{0x4D, 0x50, 0x51, 0x50, 0x30, 0x3C, 0x58, 0x5F},
4818c2ecf20Sopenharmony_ci	{0x58, 0x4E, 0x5E, 0x48, 0x4F, 0x50, 0x4D, 0x01},
4828c2ecf20Sopenharmony_ci	{0x0D, 0x09, 0x09, 0x0B, 0x09, 0x08, 0x0D, 0x0B},
4838c2ecf20Sopenharmony_ci	{0x0A, 0x0B, 0x0E, 0x0D, 0x0D, 0x0F, 0x13, 0x1F},
4848c2ecf20Sopenharmony_ci	{0x14, 0x13, 0x11, 0x11, 0x13, 0x26, 0x1B, 0x1D},
4858c2ecf20Sopenharmony_ci	{0x17, 0x1F, 0x2D, 0x28, 0x30, 0x2F, 0x2D, 0x28},
4868c2ecf20Sopenharmony_ci	{0x2C, 0x2B, 0x32, 0x38, 0x48, 0x3D, 0x32, 0x35},
4878c2ecf20Sopenharmony_ci	{0x44, 0x36, 0x2B, 0x2C, 0x3F, 0x55, 0x3F, 0x44},
4888c2ecf20Sopenharmony_ci	{0x4A, 0x4D, 0x50, 0x51, 0x50, 0x30, 0x3C, 0x58},
4898c2ecf20Sopenharmony_ci	{0x5F, 0x58, 0x4E, 0x5E, 0x48, 0x4F, 0x50, 0x4D},
4908c2ecf20Sopenharmony_ci	{0xFF, 0x20, 0x00, 0x1F, 0x01, 0x83, 0x00, 0x00},
4918c2ecf20Sopenharmony_ci	{0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00},
4928c2ecf20Sopenharmony_ci	{0x11, 0x22, 0x00, 0x22, 0x22, 0x11, 0x22, 0x22},
4938c2ecf20Sopenharmony_ci	{0x11, 0x33, 0x33, 0x11, 0x44, 0x66, 0x22, 0x55},
4948c2ecf20Sopenharmony_ci	{0x66, 0xFF, 0xDD, 0x00, 0x04, 0x00, 0x16, 0xFF},
4958c2ecf20Sopenharmony_ci	{0xC0, 0x00, 0x11, 0x08, 0x01, 0x20, 0x01, 0x60},
4968c2ecf20Sopenharmony_ci	{0x03, 0x00, 0x21, 0x00, 0x01, 0x11, 0x01, 0x02},
4978c2ecf20Sopenharmony_ci	{0x11, 0x01, 0xFF, 0xDA, 0x00, 0x0C, 0x03, 0x00},
4988c2ecf20Sopenharmony_ci	{0x00, 0x01, 0x11, 0x02, 0x11, 0x00, 0x3F, 0x00},
4998c2ecf20Sopenharmony_ci	{0xFF, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
5008c2ecf20Sopenharmony_ci};
5018c2ecf20Sopenharmony_cistatic const __u8 cxjpeg_320[][8] = {
5028c2ecf20Sopenharmony_ci	{0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00, 0x05},
5038c2ecf20Sopenharmony_ci	{0x03, 0x04, 0x04, 0x04, 0x03, 0x05, 0x04, 0x04},
5048c2ecf20Sopenharmony_ci	{0x04, 0x05, 0x05, 0x05, 0x06, 0x07, 0x0c, 0x08},
5058c2ecf20Sopenharmony_ci	{0x07, 0x07, 0x07, 0x07, 0x0f, 0x0b, 0x0b, 0x09},
5068c2ecf20Sopenharmony_ci	{0x0C, 0x11, 0x0F, 0x12, 0x12, 0x11, 0x0f, 0x11},
5078c2ecf20Sopenharmony_ci	{0x11, 0x13, 0x16, 0x1C, 0x17, 0x13, 0x14, 0x1A},
5088c2ecf20Sopenharmony_ci	{0x15, 0x11, 0x11, 0x18, 0x21, 0x18, 0x1A, 0x1D},
5098c2ecf20Sopenharmony_ci	{0x1D, 0x1F, 0x1F, 0x1F, 0x13, 0x17, 0x22, 0x24},
5108c2ecf20Sopenharmony_ci	{0x22, 0x1E, 0x24, 0x1C, 0x1E, 0x1F, 0x1E, 0x01},
5118c2ecf20Sopenharmony_ci	{0x05, 0x03, 0x04, 0x04, 0x04, 0x03, 0x05, 0x04},
5128c2ecf20Sopenharmony_ci	{0x04, 0x04, 0x05, 0x05, 0x05, 0x06, 0x07, 0x0C},
5138c2ecf20Sopenharmony_ci	{0x08, 0x07, 0x07, 0x07, 0x07, 0x0F, 0x0B, 0x0B},
5148c2ecf20Sopenharmony_ci	{0x09, 0x0C, 0x11, 0x0F, 0x12, 0x12, 0x11, 0x0F},
5158c2ecf20Sopenharmony_ci	{0x11, 0x11, 0x13, 0x16, 0x1C, 0x17, 0x13, 0x14},
5168c2ecf20Sopenharmony_ci	{0x1A, 0x15, 0x11, 0x11, 0x18, 0x21, 0x18, 0x1A},
5178c2ecf20Sopenharmony_ci	{0x1D, 0x1D, 0x1F, 0x1F, 0x1F, 0x13, 0x17, 0x22},
5188c2ecf20Sopenharmony_ci	{0x24, 0x22, 0x1E, 0x24, 0x1C, 0x1E, 0x1F, 0x1E},
5198c2ecf20Sopenharmony_ci	{0xFF, 0x20, 0x00, 0x1F, 0x02, 0x0C, 0x00, 0x00},
5208c2ecf20Sopenharmony_ci	{0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00},
5218c2ecf20Sopenharmony_ci	{0x11, 0x22, 0x00, 0x22, 0x22, 0x11, 0x22, 0x22},
5228c2ecf20Sopenharmony_ci	{0x11, 0x33, 0x33, 0x11, 0x44, 0x66, 0x22, 0x55},
5238c2ecf20Sopenharmony_ci	{0x66, 0xFF, 0xDD, 0x00, 0x04, 0x00, 0x14, 0xFF},
5248c2ecf20Sopenharmony_ci	{0xC0, 0x00, 0x11, 0x08, 0x00, 0xF0, 0x01, 0x40},
5258c2ecf20Sopenharmony_ci	{0x03, 0x00, 0x21, 0x00, 0x01, 0x11, 0x01, 0x02},
5268c2ecf20Sopenharmony_ci	{0x11, 0x01, 0xFF, 0xDA, 0x00, 0x0C, 0x03, 0x00},
5278c2ecf20Sopenharmony_ci	{0x00, 0x01, 0x11, 0x02, 0x11, 0x00, 0x3F, 0x00},
5288c2ecf20Sopenharmony_ci	{0xFF, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}	/* 27 */
5298c2ecf20Sopenharmony_ci};
5308c2ecf20Sopenharmony_cistatic const __u8 cxjpeg_176[][8] = {
5318c2ecf20Sopenharmony_ci	{0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00, 0x0d},
5328c2ecf20Sopenharmony_ci	{0x09, 0x09, 0x0B, 0x09, 0x08, 0x0D, 0x0B, 0x0A},
5338c2ecf20Sopenharmony_ci	{0x0B, 0x0E, 0x0D, 0x0D, 0x0F, 0x13, 0x1F, 0x14},
5348c2ecf20Sopenharmony_ci	{0x13, 0x11, 0x11, 0x13, 0x26, 0x1B, 0x1D, 0x17},
5358c2ecf20Sopenharmony_ci	{0x1F, 0x2D, 0x28, 0x30, 0x2F, 0x2D, 0x28, 0x2C},
5368c2ecf20Sopenharmony_ci	{0x2B, 0x32, 0x38, 0x48, 0x3D, 0x32, 0x35, 0x44},
5378c2ecf20Sopenharmony_ci	{0x36, 0x2B, 0x2C, 0x3F, 0x55, 0x3F, 0x44, 0x4A},
5388c2ecf20Sopenharmony_ci	{0x4D, 0x50, 0x51, 0x50, 0x30, 0x3C, 0x58, 0x5F},
5398c2ecf20Sopenharmony_ci	{0x58, 0x4E, 0x5E, 0x48, 0x4F, 0x50, 0x4D, 0x01},
5408c2ecf20Sopenharmony_ci	{0x0D, 0x09, 0x09, 0x0B, 0x09, 0x08, 0x0D, 0x0B},
5418c2ecf20Sopenharmony_ci	{0x0A, 0x0B, 0x0E, 0x0D, 0x0D, 0x0F, 0x13, 0x1F},
5428c2ecf20Sopenharmony_ci	{0x14, 0x13, 0x11, 0x11, 0x13, 0x26, 0x1B, 0x1D},
5438c2ecf20Sopenharmony_ci	{0x17, 0x1F, 0x2D, 0x28, 0x30, 0x2F, 0x2D, 0x28},
5448c2ecf20Sopenharmony_ci	{0x2C, 0x2B, 0x32, 0x38, 0x48, 0x3D, 0x32, 0x35},
5458c2ecf20Sopenharmony_ci	{0x44, 0x36, 0x2B, 0x2C, 0x3F, 0x55, 0x3F, 0x44},
5468c2ecf20Sopenharmony_ci	{0x4A, 0x4D, 0x50, 0x51, 0x50, 0x30, 0x3C, 0x58},
5478c2ecf20Sopenharmony_ci	{0x5F, 0x58, 0x4E, 0x5E, 0x48, 0x4F, 0x50, 0x4D},
5488c2ecf20Sopenharmony_ci	{0xFF, 0x20, 0x00, 0x1F, 0x03, 0xA1, 0x00, 0x00},
5498c2ecf20Sopenharmony_ci	{0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00},
5508c2ecf20Sopenharmony_ci	{0x11, 0x22, 0x00, 0x22, 0x22, 0x11, 0x22, 0x22},
5518c2ecf20Sopenharmony_ci	{0x11, 0x33, 0x33, 0x11, 0x44, 0x66, 0x22, 0x55},
5528c2ecf20Sopenharmony_ci	{0x66, 0xFF, 0xDD, 0x00, 0x04, 0x00, 0x0B, 0xFF},
5538c2ecf20Sopenharmony_ci	{0xC0, 0x00, 0x11, 0x08, 0x00, 0x90, 0x00, 0xB0},
5548c2ecf20Sopenharmony_ci	{0x03, 0x00, 0x21, 0x00, 0x01, 0x11, 0x01, 0x02},
5558c2ecf20Sopenharmony_ci	{0x11, 0x01, 0xFF, 0xDA, 0x00, 0x0C, 0x03, 0x00},
5568c2ecf20Sopenharmony_ci	{0x00, 0x01, 0x11, 0x02, 0x11, 0x00, 0x3F, 0x00},
5578c2ecf20Sopenharmony_ci	{0xFF, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
5588c2ecf20Sopenharmony_ci};
5598c2ecf20Sopenharmony_ci/* 640 take with the zcx30x part */
5608c2ecf20Sopenharmony_cistatic const __u8 cxjpeg_qtable[][8] = {
5618c2ecf20Sopenharmony_ci	{0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84, 0x00, 0x08},
5628c2ecf20Sopenharmony_ci	{0x06, 0x06, 0x07, 0x06, 0x05, 0x08, 0x07, 0x07},
5638c2ecf20Sopenharmony_ci	{0x07, 0x09, 0x09, 0x08, 0x0a, 0x0c, 0x14, 0x0a},
5648c2ecf20Sopenharmony_ci	{0x0c, 0x0b, 0x0b, 0x0c, 0x19, 0x12, 0x13, 0x0f},
5658c2ecf20Sopenharmony_ci	{0x14, 0x1d, 0x1a, 0x1f, 0x1e, 0x1d, 0x1a, 0x1c},
5668c2ecf20Sopenharmony_ci	{0x1c, 0x20, 0x24, 0x2e, 0x27, 0x20, 0x22, 0x2c},
5678c2ecf20Sopenharmony_ci	{0x23, 0x1c, 0x1c, 0x28, 0x37, 0x29, 0x2c, 0x30},
5688c2ecf20Sopenharmony_ci	{0x31, 0x34, 0x34, 0x34, 0x1f, 0x27, 0x39, 0x3d},
5698c2ecf20Sopenharmony_ci	{0x38, 0x32, 0x3c, 0x2e, 0x33, 0x34, 0x32, 0x01},
5708c2ecf20Sopenharmony_ci	{0x09, 0x09, 0x09, 0x0c, 0x0b, 0x0c, 0x18, 0x0a},
5718c2ecf20Sopenharmony_ci	{0x0a, 0x18, 0x32, 0x21, 0x1c, 0x21, 0x32, 0x32},
5728c2ecf20Sopenharmony_ci	{0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32},
5738c2ecf20Sopenharmony_ci	{0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32},
5748c2ecf20Sopenharmony_ci	{0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32},
5758c2ecf20Sopenharmony_ci	{0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32},
5768c2ecf20Sopenharmony_ci	{0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32},
5778c2ecf20Sopenharmony_ci	{0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32},
5788c2ecf20Sopenharmony_ci	{0xFF, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}	/* 18 */
5798c2ecf20Sopenharmony_ci};
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_ci
5828c2ecf20Sopenharmony_cistatic void cx11646_jpegInit(struct gspca_dev*gspca_dev)
5838c2ecf20Sopenharmony_ci{
5848c2ecf20Sopenharmony_ci	int i;
5858c2ecf20Sopenharmony_ci	int length;
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x00c0, 0x01);
5888c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x00c3, 0x00);
5898c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x00c0, 0x00);
5908c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0001, 1);
5918c2ecf20Sopenharmony_ci	length = 8;
5928c2ecf20Sopenharmony_ci	for (i = 0; i < 79; i++) {
5938c2ecf20Sopenharmony_ci		if (i == 78)
5948c2ecf20Sopenharmony_ci			length = 6;
5958c2ecf20Sopenharmony_ci		reg_w(gspca_dev, 0x0008, cx_jpeg_init[i], length);
5968c2ecf20Sopenharmony_ci	}
5978c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0002, 1);
5988c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0055, 0x14);
5998c2ecf20Sopenharmony_ci}
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_cistatic const __u8 reg12[] = { 0x0a, 0x05, 0x07, 0x04, 0x19 };
6028c2ecf20Sopenharmony_cistatic const __u8 regE5_8[] =
6038c2ecf20Sopenharmony_ci		{ 0x88, 0x00, 0xd4, 0x01, 0x88, 0x01, 0x01, 0x01 };
6048c2ecf20Sopenharmony_cistatic const __u8 regE5a[] = { 0x88, 0x0a, 0x0c, 0x01 };
6058c2ecf20Sopenharmony_cistatic const __u8 regE5b[] = { 0x88, 0x0b, 0x12, 0x01 };
6068c2ecf20Sopenharmony_cistatic const __u8 regE5c[] = { 0x88, 0x05, 0x01, 0x01 };
6078c2ecf20Sopenharmony_cistatic const __u8 reg51[] = { 0x77, 0x03 };
6088c2ecf20Sopenharmony_ci#define reg70 0x03
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_cistatic void cx11646_jpeg(struct gspca_dev*gspca_dev)
6118c2ecf20Sopenharmony_ci{
6128c2ecf20Sopenharmony_ci	int i;
6138c2ecf20Sopenharmony_ci	int length;
6148c2ecf20Sopenharmony_ci	__u8 Reg55;
6158c2ecf20Sopenharmony_ci	int retry;
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x00c0, 0x01);
6188c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x00c3, 0x00);
6198c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x00c0, 0x00);
6208c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0001, 1);
6218c2ecf20Sopenharmony_ci	length = 8;
6228c2ecf20Sopenharmony_ci	switch (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv) {
6238c2ecf20Sopenharmony_ci	case 0:
6248c2ecf20Sopenharmony_ci		for (i = 0; i < 27; i++) {
6258c2ecf20Sopenharmony_ci			if (i == 26)
6268c2ecf20Sopenharmony_ci				length = 2;
6278c2ecf20Sopenharmony_ci			reg_w(gspca_dev, 0x0008, cxjpeg_640[i], length);
6288c2ecf20Sopenharmony_ci		}
6298c2ecf20Sopenharmony_ci		Reg55 = 0x28;
6308c2ecf20Sopenharmony_ci		break;
6318c2ecf20Sopenharmony_ci	case 1:
6328c2ecf20Sopenharmony_ci		for (i = 0; i < 27; i++) {
6338c2ecf20Sopenharmony_ci			if (i == 26)
6348c2ecf20Sopenharmony_ci				length = 2;
6358c2ecf20Sopenharmony_ci			reg_w(gspca_dev, 0x0008, cxjpeg_352[i], length);
6368c2ecf20Sopenharmony_ci		}
6378c2ecf20Sopenharmony_ci		Reg55 = 0x16;
6388c2ecf20Sopenharmony_ci		break;
6398c2ecf20Sopenharmony_ci	default:
6408c2ecf20Sopenharmony_ci/*	case 2: */
6418c2ecf20Sopenharmony_ci		for (i = 0; i < 27; i++) {
6428c2ecf20Sopenharmony_ci			if (i == 26)
6438c2ecf20Sopenharmony_ci				length = 2;
6448c2ecf20Sopenharmony_ci			reg_w(gspca_dev, 0x0008, cxjpeg_320[i], length);
6458c2ecf20Sopenharmony_ci		}
6468c2ecf20Sopenharmony_ci		Reg55 = 0x14;
6478c2ecf20Sopenharmony_ci		break;
6488c2ecf20Sopenharmony_ci	case 3:
6498c2ecf20Sopenharmony_ci		for (i = 0; i < 27; i++) {
6508c2ecf20Sopenharmony_ci			if (i == 26)
6518c2ecf20Sopenharmony_ci				length = 2;
6528c2ecf20Sopenharmony_ci			reg_w(gspca_dev, 0x0008, cxjpeg_176[i], length);
6538c2ecf20Sopenharmony_ci		}
6548c2ecf20Sopenharmony_ci		Reg55 = 0x0B;
6558c2ecf20Sopenharmony_ci		break;
6568c2ecf20Sopenharmony_ci	}
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0002, 1);
6598c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0055, Reg55);
6608c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0002, 1);
6618c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0010, reg10, 2);
6628c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0054, 0x02);
6638c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0054, 0x01);
6648c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0000, 0x94);
6658c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0053, 0xc0);
6668c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x00fc, 0xe1);
6678c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0000, 0x00);
6688c2ecf20Sopenharmony_ci	/* wait for completion */
6698c2ecf20Sopenharmony_ci	retry = 50;
6708c2ecf20Sopenharmony_ci	do {
6718c2ecf20Sopenharmony_ci		reg_r(gspca_dev, 0x0002, 1);
6728c2ecf20Sopenharmony_ci							/* 0x07 until 0x00 */
6738c2ecf20Sopenharmony_ci		if (gspca_dev->usb_buf[0] == 0x00)
6748c2ecf20Sopenharmony_ci			break;
6758c2ecf20Sopenharmony_ci		reg_w_val(gspca_dev, 0x0053, 0x00);
6768c2ecf20Sopenharmony_ci	} while (--retry);
6778c2ecf20Sopenharmony_ci	if (retry == 0)
6788c2ecf20Sopenharmony_ci		gspca_err(gspca_dev, "Damned Errors sending jpeg Table\n");
6798c2ecf20Sopenharmony_ci	/* send the qtable now */
6808c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0001, 1);		/* -> 0x18 */
6818c2ecf20Sopenharmony_ci	length = 8;
6828c2ecf20Sopenharmony_ci	for (i = 0; i < 18; i++) {
6838c2ecf20Sopenharmony_ci		if (i == 17)
6848c2ecf20Sopenharmony_ci			length = 2;
6858c2ecf20Sopenharmony_ci		reg_w(gspca_dev, 0x0008, cxjpeg_qtable[i], length);
6868c2ecf20Sopenharmony_ci
6878c2ecf20Sopenharmony_ci	}
6888c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0002, 1);	/* 0x00 */
6898c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0053, 1);	/* 0x00 */
6908c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0054, 0x02);
6918c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0054, 0x01);
6928c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0000, 0x94);
6938c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0053, 0xc0);
6948c2ecf20Sopenharmony_ci
6958c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0038, 1);		/* 0x40 */
6968c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0038, 1);		/* 0x40 */
6978c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x001f, 1);		/* 0x38 */
6988c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0012, reg12, 5);
6998c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x00e5, regE5_8, 8);
7008c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x00e8, 8);
7018c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x00e5, regE5a, 4);
7028c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x00e8, 1);		/* 0x00 */
7038c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x009a, 0x01);
7048c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x00e5, regE5b, 4);
7058c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x00e8, 1);		/* 0x00 */
7068c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x00e5, regE5c, 4);
7078c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x00e8, 1);		/* 0x00 */
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0051, reg51, 2);
7108c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0010, reg10, 2);
7118c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0070, reg70);
7128c2ecf20Sopenharmony_ci}
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_cistatic void cx11646_init1(struct gspca_dev *gspca_dev)
7158c2ecf20Sopenharmony_ci{
7168c2ecf20Sopenharmony_ci	int i = 0;
7178c2ecf20Sopenharmony_ci
7188c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0010, 0x00);
7198c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0053, 0x00);
7208c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0052, 0x00);
7218c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x009b, 0x2f);
7228c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x009c, 0x10);
7238c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0098, 1);
7248c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0098, 0x40);
7258c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0099, 1);
7268c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0099, 0x07);
7278c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0039, 0x40);
7288c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x003c, 0xff);
7298c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x003f, 0x1f);
7308c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x003d, 0x40);
7318c2ecf20Sopenharmony_ci/*	reg_w_val(gspca_dev, 0x003d, 0x60); */
7328c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0099, 1);			/* ->0x07 */
7338c2ecf20Sopenharmony_ci
7348c2ecf20Sopenharmony_ci	while (cx_sensor_init[i][0]) {
7358c2ecf20Sopenharmony_ci		reg_w_val(gspca_dev, 0x00e5, cx_sensor_init[i][0]);
7368c2ecf20Sopenharmony_ci		reg_r(gspca_dev, 0x00e8, 1);		/* -> 0x00 */
7378c2ecf20Sopenharmony_ci		if (i == 1) {
7388c2ecf20Sopenharmony_ci			reg_w_val(gspca_dev, 0x00ed, 0x01);
7398c2ecf20Sopenharmony_ci			reg_r(gspca_dev, 0x00ed, 1);	/* -> 0x01 */
7408c2ecf20Sopenharmony_ci		}
7418c2ecf20Sopenharmony_ci		i++;
7428c2ecf20Sopenharmony_ci	}
7438c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x00c3, 0x00);
7448c2ecf20Sopenharmony_ci}
7458c2ecf20Sopenharmony_ci
7468c2ecf20Sopenharmony_ci/* this function is called at probe time */
7478c2ecf20Sopenharmony_cistatic int sd_config(struct gspca_dev *gspca_dev,
7488c2ecf20Sopenharmony_ci			const struct usb_device_id *id)
7498c2ecf20Sopenharmony_ci{
7508c2ecf20Sopenharmony_ci	struct cam *cam;
7518c2ecf20Sopenharmony_ci
7528c2ecf20Sopenharmony_ci	cam = &gspca_dev->cam;
7538c2ecf20Sopenharmony_ci	cam->cam_mode = vga_mode;
7548c2ecf20Sopenharmony_ci	cam->nmodes = ARRAY_SIZE(vga_mode);
7558c2ecf20Sopenharmony_ci	return 0;
7568c2ecf20Sopenharmony_ci}
7578c2ecf20Sopenharmony_ci
7588c2ecf20Sopenharmony_ci/* this function is called at probe and resume time */
7598c2ecf20Sopenharmony_cistatic int sd_init(struct gspca_dev *gspca_dev)
7608c2ecf20Sopenharmony_ci{
7618c2ecf20Sopenharmony_ci	cx11646_init1(gspca_dev);
7628c2ecf20Sopenharmony_ci	cx11646_initsize(gspca_dev);
7638c2ecf20Sopenharmony_ci	cx11646_fw(gspca_dev);
7648c2ecf20Sopenharmony_ci	cx_sensor(gspca_dev);
7658c2ecf20Sopenharmony_ci	cx11646_jpegInit(gspca_dev);
7668c2ecf20Sopenharmony_ci	return 0;
7678c2ecf20Sopenharmony_ci}
7688c2ecf20Sopenharmony_ci
7698c2ecf20Sopenharmony_cistatic int sd_start(struct gspca_dev *gspca_dev)
7708c2ecf20Sopenharmony_ci{
7718c2ecf20Sopenharmony_ci	struct sd *sd = (struct sd *) gspca_dev;
7728c2ecf20Sopenharmony_ci
7738c2ecf20Sopenharmony_ci	/* create the JPEG header */
7748c2ecf20Sopenharmony_ci	jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
7758c2ecf20Sopenharmony_ci			gspca_dev->pixfmt.width,
7768c2ecf20Sopenharmony_ci			0x22);		/* JPEG 411 */
7778c2ecf20Sopenharmony_ci	jpeg_set_qual(sd->jpeg_hdr, QUALITY);
7788c2ecf20Sopenharmony_ci
7798c2ecf20Sopenharmony_ci	cx11646_initsize(gspca_dev);
7808c2ecf20Sopenharmony_ci	cx11646_fw(gspca_dev);
7818c2ecf20Sopenharmony_ci	cx_sensor(gspca_dev);
7828c2ecf20Sopenharmony_ci	cx11646_jpeg(gspca_dev);
7838c2ecf20Sopenharmony_ci	return 0;
7848c2ecf20Sopenharmony_ci}
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_ci/* called on streamoff with alt 0 and on disconnect */
7878c2ecf20Sopenharmony_cistatic void sd_stop0(struct gspca_dev *gspca_dev)
7888c2ecf20Sopenharmony_ci{
7898c2ecf20Sopenharmony_ci	int retry = 50;
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ci	if (!gspca_dev->present)
7928c2ecf20Sopenharmony_ci		return;
7938c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0000, 0x00);
7948c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0002, 1);
7958c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0053, 0x00);
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci	while (retry--) {
7988c2ecf20Sopenharmony_ci/*		reg_r(gspca_dev, 0x0002, 1);*/
7998c2ecf20Sopenharmony_ci		reg_r(gspca_dev, 0x0053, 1);
8008c2ecf20Sopenharmony_ci		if (gspca_dev->usb_buf[0] == 0)
8018c2ecf20Sopenharmony_ci			break;
8028c2ecf20Sopenharmony_ci	}
8038c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0000, 0x00);
8048c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0002, 1);
8058c2ecf20Sopenharmony_ci
8068c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0010, 0x00);
8078c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x0033, 1);
8088c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x00fc, 0xe0);
8098c2ecf20Sopenharmony_ci}
8108c2ecf20Sopenharmony_ci
8118c2ecf20Sopenharmony_cistatic void sd_pkt_scan(struct gspca_dev *gspca_dev,
8128c2ecf20Sopenharmony_ci			u8 *data,			/* isoc packet */
8138c2ecf20Sopenharmony_ci			int len)			/* iso packet length */
8148c2ecf20Sopenharmony_ci{
8158c2ecf20Sopenharmony_ci	struct sd *sd = (struct sd *) gspca_dev;
8168c2ecf20Sopenharmony_ci
8178c2ecf20Sopenharmony_ci	if (data[0] == 0xff && data[1] == 0xd8) {
8188c2ecf20Sopenharmony_ci
8198c2ecf20Sopenharmony_ci		/* start of frame */
8208c2ecf20Sopenharmony_ci		gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
8218c2ecf20Sopenharmony_ci
8228c2ecf20Sopenharmony_ci		/* put the JPEG header in the new frame */
8238c2ecf20Sopenharmony_ci		gspca_frame_add(gspca_dev, FIRST_PACKET,
8248c2ecf20Sopenharmony_ci				sd->jpeg_hdr, JPEG_HDR_SZ);
8258c2ecf20Sopenharmony_ci		data += 2;
8268c2ecf20Sopenharmony_ci		len -= 2;
8278c2ecf20Sopenharmony_ci	}
8288c2ecf20Sopenharmony_ci	gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
8298c2ecf20Sopenharmony_ci}
8308c2ecf20Sopenharmony_ci
8318c2ecf20Sopenharmony_cistatic void setbrightness(struct gspca_dev *gspca_dev, s32 val, s32 sat)
8328c2ecf20Sopenharmony_ci{
8338c2ecf20Sopenharmony_ci	__u8 regE5cbx[] = { 0x88, 0x00, 0xd4, 0x01, 0x88, 0x01, 0x01, 0x01 };
8348c2ecf20Sopenharmony_ci	__u8 reg51c[2];
8358c2ecf20Sopenharmony_ci
8368c2ecf20Sopenharmony_ci	regE5cbx[2] = val;
8378c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x00e5, regE5cbx, 8);
8388c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x00e8, 8);
8398c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x00e5, regE5c, 4);
8408c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x00e8, 1);		/* 0x00 */
8418c2ecf20Sopenharmony_ci
8428c2ecf20Sopenharmony_ci	reg51c[0] = 0x77;
8438c2ecf20Sopenharmony_ci	reg51c[1] = sat;
8448c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0051, reg51c, 2);
8458c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0010, reg10, 2);
8468c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0070, reg70);
8478c2ecf20Sopenharmony_ci}
8488c2ecf20Sopenharmony_ci
8498c2ecf20Sopenharmony_cistatic void setcontrast(struct gspca_dev *gspca_dev, s32 val, s32 sat)
8508c2ecf20Sopenharmony_ci{
8518c2ecf20Sopenharmony_ci	__u8 regE5acx[] = { 0x88, 0x0a, 0x0c, 0x01 };	/* seem MSB */
8528c2ecf20Sopenharmony_ci/*	__u8 regE5bcx[] = { 0x88, 0x0b, 0x12, 0x01};	 * LSB */
8538c2ecf20Sopenharmony_ci	__u8 reg51c[2];
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_ci	regE5acx[2] = val;
8568c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x00e5, regE5acx, 4);
8578c2ecf20Sopenharmony_ci	reg_r(gspca_dev, 0x00e8, 1);		/* 0x00 */
8588c2ecf20Sopenharmony_ci	reg51c[0] = 0x77;
8598c2ecf20Sopenharmony_ci	reg51c[1] = sat;
8608c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0051, reg51c, 2);
8618c2ecf20Sopenharmony_ci	reg_w(gspca_dev, 0x0010, reg10, 2);
8628c2ecf20Sopenharmony_ci	reg_w_val(gspca_dev, 0x0070, reg70);
8638c2ecf20Sopenharmony_ci}
8648c2ecf20Sopenharmony_ci
8658c2ecf20Sopenharmony_cistatic int sd_s_ctrl(struct v4l2_ctrl *ctrl)
8668c2ecf20Sopenharmony_ci{
8678c2ecf20Sopenharmony_ci	struct gspca_dev *gspca_dev =
8688c2ecf20Sopenharmony_ci		container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
8698c2ecf20Sopenharmony_ci	struct sd *sd = (struct sd *)gspca_dev;
8708c2ecf20Sopenharmony_ci
8718c2ecf20Sopenharmony_ci	gspca_dev->usb_err = 0;
8728c2ecf20Sopenharmony_ci
8738c2ecf20Sopenharmony_ci	if (!gspca_dev->streaming)
8748c2ecf20Sopenharmony_ci		return 0;
8758c2ecf20Sopenharmony_ci
8768c2ecf20Sopenharmony_ci	switch (ctrl->id) {
8778c2ecf20Sopenharmony_ci	case V4L2_CID_BRIGHTNESS:
8788c2ecf20Sopenharmony_ci		setbrightness(gspca_dev, ctrl->val, sd->sat->cur.val);
8798c2ecf20Sopenharmony_ci		break;
8808c2ecf20Sopenharmony_ci	case V4L2_CID_CONTRAST:
8818c2ecf20Sopenharmony_ci		setcontrast(gspca_dev, ctrl->val, sd->sat->cur.val);
8828c2ecf20Sopenharmony_ci		break;
8838c2ecf20Sopenharmony_ci	case V4L2_CID_SATURATION:
8848c2ecf20Sopenharmony_ci		setbrightness(gspca_dev, sd->brightness->cur.val, ctrl->val);
8858c2ecf20Sopenharmony_ci		setcontrast(gspca_dev, sd->contrast->cur.val, ctrl->val);
8868c2ecf20Sopenharmony_ci		break;
8878c2ecf20Sopenharmony_ci	}
8888c2ecf20Sopenharmony_ci	return gspca_dev->usb_err;
8898c2ecf20Sopenharmony_ci}
8908c2ecf20Sopenharmony_ci
8918c2ecf20Sopenharmony_cistatic const struct v4l2_ctrl_ops sd_ctrl_ops = {
8928c2ecf20Sopenharmony_ci	.s_ctrl = sd_s_ctrl,
8938c2ecf20Sopenharmony_ci};
8948c2ecf20Sopenharmony_ci
8958c2ecf20Sopenharmony_cistatic int sd_init_controls(struct gspca_dev *gspca_dev)
8968c2ecf20Sopenharmony_ci{
8978c2ecf20Sopenharmony_ci	struct sd *sd = (struct sd *)gspca_dev;
8988c2ecf20Sopenharmony_ci	struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
8998c2ecf20Sopenharmony_ci
9008c2ecf20Sopenharmony_ci	gspca_dev->vdev.ctrl_handler = hdl;
9018c2ecf20Sopenharmony_ci	v4l2_ctrl_handler_init(hdl, 3);
9028c2ecf20Sopenharmony_ci	sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
9038c2ecf20Sopenharmony_ci			V4L2_CID_BRIGHTNESS, 0, 255, 1, 0xd4);
9048c2ecf20Sopenharmony_ci	sd->contrast = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
9058c2ecf20Sopenharmony_ci			V4L2_CID_CONTRAST, 0x0a, 0x1f, 1, 0x0c);
9068c2ecf20Sopenharmony_ci	sd->sat = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
9078c2ecf20Sopenharmony_ci			V4L2_CID_SATURATION, 0, 7, 1, 3);
9088c2ecf20Sopenharmony_ci	if (hdl->error) {
9098c2ecf20Sopenharmony_ci		pr_err("Could not initialize controls\n");
9108c2ecf20Sopenharmony_ci		return hdl->error;
9118c2ecf20Sopenharmony_ci	}
9128c2ecf20Sopenharmony_ci	return 0;
9138c2ecf20Sopenharmony_ci}
9148c2ecf20Sopenharmony_ci
9158c2ecf20Sopenharmony_ci/* sub-driver description */
9168c2ecf20Sopenharmony_cistatic const struct sd_desc sd_desc = {
9178c2ecf20Sopenharmony_ci	.name = MODULE_NAME,
9188c2ecf20Sopenharmony_ci	.config = sd_config,
9198c2ecf20Sopenharmony_ci	.init = sd_init,
9208c2ecf20Sopenharmony_ci	.init_controls = sd_init_controls,
9218c2ecf20Sopenharmony_ci	.start = sd_start,
9228c2ecf20Sopenharmony_ci	.stop0 = sd_stop0,
9238c2ecf20Sopenharmony_ci	.pkt_scan = sd_pkt_scan,
9248c2ecf20Sopenharmony_ci};
9258c2ecf20Sopenharmony_ci
9268c2ecf20Sopenharmony_ci/* -- module initialisation -- */
9278c2ecf20Sopenharmony_cistatic const struct usb_device_id device_table[] = {
9288c2ecf20Sopenharmony_ci	{USB_DEVICE(0x0572, 0x0041)},
9298c2ecf20Sopenharmony_ci	{}
9308c2ecf20Sopenharmony_ci};
9318c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(usb, device_table);
9328c2ecf20Sopenharmony_ci
9338c2ecf20Sopenharmony_ci/* -- device connect -- */
9348c2ecf20Sopenharmony_cistatic int sd_probe(struct usb_interface *intf,
9358c2ecf20Sopenharmony_ci			const struct usb_device_id *id)
9368c2ecf20Sopenharmony_ci{
9378c2ecf20Sopenharmony_ci	return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
9388c2ecf20Sopenharmony_ci				THIS_MODULE);
9398c2ecf20Sopenharmony_ci}
9408c2ecf20Sopenharmony_ci
9418c2ecf20Sopenharmony_cistatic struct usb_driver sd_driver = {
9428c2ecf20Sopenharmony_ci	.name = MODULE_NAME,
9438c2ecf20Sopenharmony_ci	.id_table = device_table,
9448c2ecf20Sopenharmony_ci	.probe = sd_probe,
9458c2ecf20Sopenharmony_ci	.disconnect = gspca_disconnect,
9468c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
9478c2ecf20Sopenharmony_ci	.suspend = gspca_suspend,
9488c2ecf20Sopenharmony_ci	.resume = gspca_resume,
9498c2ecf20Sopenharmony_ci	.reset_resume = gspca_resume,
9508c2ecf20Sopenharmony_ci#endif
9518c2ecf20Sopenharmony_ci};
9528c2ecf20Sopenharmony_ci
9538c2ecf20Sopenharmony_cimodule_usb_driver(sd_driver);
954