xref: /OK3568_Linux_fs/kernel/drivers/media/usb/gspca/spca500.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * SPCA500 chip based cameras initialization data
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #define MODULE_NAME "spca500"
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include "gspca.h"
13*4882a593Smuzhiyun #include "jpeg.h"
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
16*4882a593Smuzhiyun MODULE_DESCRIPTION("GSPCA/SPCA500 USB Camera Driver");
17*4882a593Smuzhiyun MODULE_LICENSE("GPL");
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #define QUALITY 85
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun /* specific webcam descriptor */
22*4882a593Smuzhiyun struct sd {
23*4882a593Smuzhiyun 	struct gspca_dev gspca_dev;		/* !! must be the first item */
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun 	char subtype;
26*4882a593Smuzhiyun #define AgfaCl20 0
27*4882a593Smuzhiyun #define AiptekPocketDV 1
28*4882a593Smuzhiyun #define BenqDC1016 2
29*4882a593Smuzhiyun #define CreativePCCam300 3
30*4882a593Smuzhiyun #define DLinkDSC350 4
31*4882a593Smuzhiyun #define Gsmartmini 5
32*4882a593Smuzhiyun #define IntelPocketPCCamera 6
33*4882a593Smuzhiyun #define KodakEZ200 7
34*4882a593Smuzhiyun #define LogitechClickSmart310 8
35*4882a593Smuzhiyun #define LogitechClickSmart510 9
36*4882a593Smuzhiyun #define LogitechTraveler 10
37*4882a593Smuzhiyun #define MustekGsmart300 11
38*4882a593Smuzhiyun #define Optimedia 12
39*4882a593Smuzhiyun #define PalmPixDC85 13
40*4882a593Smuzhiyun #define ToptroIndus 14
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun 	u8 jpeg_hdr[JPEG_HDR_SZ];
43*4882a593Smuzhiyun };
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun static const struct v4l2_pix_format vga_mode[] = {
46*4882a593Smuzhiyun 	{320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
47*4882a593Smuzhiyun 		.bytesperline = 320,
48*4882a593Smuzhiyun 		.sizeimage = 320 * 240 * 3 / 8 + 590,
49*4882a593Smuzhiyun 		.colorspace = V4L2_COLORSPACE_JPEG,
50*4882a593Smuzhiyun 		.priv = 1},
51*4882a593Smuzhiyun 	{640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
52*4882a593Smuzhiyun 		.bytesperline = 640,
53*4882a593Smuzhiyun 		.sizeimage = 640 * 480 * 3 / 8 + 590,
54*4882a593Smuzhiyun 		.colorspace = V4L2_COLORSPACE_JPEG,
55*4882a593Smuzhiyun 		.priv = 0},
56*4882a593Smuzhiyun };
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun static const struct v4l2_pix_format sif_mode[] = {
59*4882a593Smuzhiyun 	{176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
60*4882a593Smuzhiyun 		.bytesperline = 176,
61*4882a593Smuzhiyun 		.sizeimage = 176 * 144 * 3 / 8 + 590,
62*4882a593Smuzhiyun 		.colorspace = V4L2_COLORSPACE_JPEG,
63*4882a593Smuzhiyun 		.priv = 1},
64*4882a593Smuzhiyun 	{352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
65*4882a593Smuzhiyun 		.bytesperline = 352,
66*4882a593Smuzhiyun 		.sizeimage = 352 * 288 * 3 / 8 + 590,
67*4882a593Smuzhiyun 		.colorspace = V4L2_COLORSPACE_JPEG,
68*4882a593Smuzhiyun 		.priv = 0},
69*4882a593Smuzhiyun };
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun /* Frame packet header offsets for the spca500 */
72*4882a593Smuzhiyun #define SPCA500_OFFSET_PADDINGLB 2
73*4882a593Smuzhiyun #define SPCA500_OFFSET_PADDINGHB 3
74*4882a593Smuzhiyun #define SPCA500_OFFSET_MODE      4
75*4882a593Smuzhiyun #define SPCA500_OFFSET_IMGWIDTH  5
76*4882a593Smuzhiyun #define SPCA500_OFFSET_IMGHEIGHT 6
77*4882a593Smuzhiyun #define SPCA500_OFFSET_IMGMODE   7
78*4882a593Smuzhiyun #define SPCA500_OFFSET_QTBLINDEX 8
79*4882a593Smuzhiyun #define SPCA500_OFFSET_FRAMSEQ   9
80*4882a593Smuzhiyun #define SPCA500_OFFSET_CDSPINFO  10
81*4882a593Smuzhiyun #define SPCA500_OFFSET_GPIO      11
82*4882a593Smuzhiyun #define SPCA500_OFFSET_AUGPIO    12
83*4882a593Smuzhiyun #define SPCA500_OFFSET_DATA      16
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun static const __u16 spca500_visual_defaults[][3] = {
87*4882a593Smuzhiyun 	{0x00, 0x0003, 0x816b},	/* SSI not active sync with vsync,
88*4882a593Smuzhiyun 				 * hue (H byte) = 0,
89*4882a593Smuzhiyun 				 * saturation/hue enable,
90*4882a593Smuzhiyun 				 * brightness/contrast enable.
91*4882a593Smuzhiyun 				 */
92*4882a593Smuzhiyun 	{0x00, 0x0000, 0x8167},	/* brightness = 0 */
93*4882a593Smuzhiyun 	{0x00, 0x0020, 0x8168},	/* contrast = 0 */
94*4882a593Smuzhiyun 	{0x00, 0x0003, 0x816b},	/* SSI not active sync with vsync,
95*4882a593Smuzhiyun 				 * hue (H byte) = 0, saturation/hue enable,
96*4882a593Smuzhiyun 				 * brightness/contrast enable.
97*4882a593Smuzhiyun 				 * was 0x0003, now 0x0000.
98*4882a593Smuzhiyun 				 */
99*4882a593Smuzhiyun 	{0x00, 0x0000, 0x816a},	/* hue (L byte) = 0 */
100*4882a593Smuzhiyun 	{0x00, 0x0020, 0x8169},	/* saturation = 0x20 */
101*4882a593Smuzhiyun 	{0x00, 0x0050, 0x8157},	/* edge gain high threshold */
102*4882a593Smuzhiyun 	{0x00, 0x0030, 0x8158},	/* edge gain low threshold */
103*4882a593Smuzhiyun 	{0x00, 0x0028, 0x8159},	/* edge bandwidth high threshold */
104*4882a593Smuzhiyun 	{0x00, 0x000a, 0x815a},	/* edge bandwidth low threshold */
105*4882a593Smuzhiyun 	{0x00, 0x0001, 0x8202},	/* clock rate compensation = 1/25 sec/frame */
106*4882a593Smuzhiyun 	{0x0c, 0x0004, 0x0000},
107*4882a593Smuzhiyun 	/* set interface */
108*4882a593Smuzhiyun 	{}
109*4882a593Smuzhiyun };
110*4882a593Smuzhiyun static const __u16 Clicksmart510_defaults[][3] = {
111*4882a593Smuzhiyun 	{0x00, 0x00, 0x8211},
112*4882a593Smuzhiyun 	{0x00, 0x01, 0x82c0},
113*4882a593Smuzhiyun 	{0x00, 0x10, 0x82cb},
114*4882a593Smuzhiyun 	{0x00, 0x0f, 0x800d},
115*4882a593Smuzhiyun 	{0x00, 0x82, 0x8225},
116*4882a593Smuzhiyun 	{0x00, 0x21, 0x8228},
117*4882a593Smuzhiyun 	{0x00, 0x00, 0x8203},
118*4882a593Smuzhiyun 	{0x00, 0x00, 0x8204},
119*4882a593Smuzhiyun 	{0x00, 0x08, 0x8205},
120*4882a593Smuzhiyun 	{0x00, 0xf8, 0x8206},
121*4882a593Smuzhiyun 	{0x00, 0x28, 0x8207},
122*4882a593Smuzhiyun 	{0x00, 0xa0, 0x8208},
123*4882a593Smuzhiyun 	{0x00, 0x08, 0x824a},
124*4882a593Smuzhiyun 	{0x00, 0x08, 0x8214},
125*4882a593Smuzhiyun 	{0x00, 0x80, 0x82c1},
126*4882a593Smuzhiyun 	{0x00, 0x00, 0x82c2},
127*4882a593Smuzhiyun 	{0x00, 0x00, 0x82ca},
128*4882a593Smuzhiyun 	{0x00, 0x80, 0x82c1},
129*4882a593Smuzhiyun 	{0x00, 0x04, 0x82c2},
130*4882a593Smuzhiyun 	{0x00, 0x00, 0x82ca},
131*4882a593Smuzhiyun 	{0x00, 0xfc, 0x8100},
132*4882a593Smuzhiyun 	{0x00, 0xfc, 0x8105},
133*4882a593Smuzhiyun 	{0x00, 0x30, 0x8101},
134*4882a593Smuzhiyun 	{0x00, 0x00, 0x8102},
135*4882a593Smuzhiyun 	{0x00, 0x00, 0x8103},
136*4882a593Smuzhiyun 	{0x00, 0x66, 0x8107},
137*4882a593Smuzhiyun 	{0x00, 0x00, 0x816b},
138*4882a593Smuzhiyun 	{0x00, 0x00, 0x8155},
139*4882a593Smuzhiyun 	{0x00, 0x01, 0x8156},
140*4882a593Smuzhiyun 	{0x00, 0x60, 0x8157},
141*4882a593Smuzhiyun 	{0x00, 0x40, 0x8158},
142*4882a593Smuzhiyun 	{0x00, 0x0a, 0x8159},
143*4882a593Smuzhiyun 	{0x00, 0x06, 0x815a},
144*4882a593Smuzhiyun 	{0x00, 0x00, 0x813f},
145*4882a593Smuzhiyun 	{0x00, 0x00, 0x8200},
146*4882a593Smuzhiyun 	{0x00, 0x19, 0x8201},
147*4882a593Smuzhiyun 	{0x00, 0x00, 0x82c1},
148*4882a593Smuzhiyun 	{0x00, 0xa0, 0x82c2},
149*4882a593Smuzhiyun 	{0x00, 0x00, 0x82ca},
150*4882a593Smuzhiyun 	{0x00, 0x00, 0x8117},
151*4882a593Smuzhiyun 	{0x00, 0x00, 0x8118},
152*4882a593Smuzhiyun 	{0x00, 0x65, 0x8119},
153*4882a593Smuzhiyun 	{0x00, 0x00, 0x811a},
154*4882a593Smuzhiyun 	{0x00, 0x00, 0x811b},
155*4882a593Smuzhiyun 	{0x00, 0x55, 0x811c},
156*4882a593Smuzhiyun 	{0x00, 0x65, 0x811d},
157*4882a593Smuzhiyun 	{0x00, 0x55, 0x811e},
158*4882a593Smuzhiyun 	{0x00, 0x16, 0x811f},
159*4882a593Smuzhiyun 	{0x00, 0x19, 0x8120},
160*4882a593Smuzhiyun 	{0x00, 0x80, 0x8103},
161*4882a593Smuzhiyun 	{0x00, 0x83, 0x816b},
162*4882a593Smuzhiyun 	{0x00, 0x25, 0x8168},
163*4882a593Smuzhiyun 	{0x00, 0x01, 0x820f},
164*4882a593Smuzhiyun 	{0x00, 0xff, 0x8115},
165*4882a593Smuzhiyun 	{0x00, 0x48, 0x8116},
166*4882a593Smuzhiyun 	{0x00, 0x50, 0x8151},
167*4882a593Smuzhiyun 	{0x00, 0x40, 0x8152},
168*4882a593Smuzhiyun 	{0x00, 0x78, 0x8153},
169*4882a593Smuzhiyun 	{0x00, 0x40, 0x8154},
170*4882a593Smuzhiyun 	{0x00, 0x00, 0x8167},
171*4882a593Smuzhiyun 	{0x00, 0x20, 0x8168},
172*4882a593Smuzhiyun 	{0x00, 0x00, 0x816a},
173*4882a593Smuzhiyun 	{0x00, 0x03, 0x816b},
174*4882a593Smuzhiyun 	{0x00, 0x20, 0x8169},
175*4882a593Smuzhiyun 	{0x00, 0x60, 0x8157},
176*4882a593Smuzhiyun 	{0x00, 0x00, 0x8190},
177*4882a593Smuzhiyun 	{0x00, 0x00, 0x81a1},
178*4882a593Smuzhiyun 	{0x00, 0x00, 0x81b2},
179*4882a593Smuzhiyun 	{0x00, 0x27, 0x8191},
180*4882a593Smuzhiyun 	{0x00, 0x27, 0x81a2},
181*4882a593Smuzhiyun 	{0x00, 0x27, 0x81b3},
182*4882a593Smuzhiyun 	{0x00, 0x4b, 0x8192},
183*4882a593Smuzhiyun 	{0x00, 0x4b, 0x81a3},
184*4882a593Smuzhiyun 	{0x00, 0x4b, 0x81b4},
185*4882a593Smuzhiyun 	{0x00, 0x66, 0x8193},
186*4882a593Smuzhiyun 	{0x00, 0x66, 0x81a4},
187*4882a593Smuzhiyun 	{0x00, 0x66, 0x81b5},
188*4882a593Smuzhiyun 	{0x00, 0x79, 0x8194},
189*4882a593Smuzhiyun 	{0x00, 0x79, 0x81a5},
190*4882a593Smuzhiyun 	{0x00, 0x79, 0x81b6},
191*4882a593Smuzhiyun 	{0x00, 0x8a, 0x8195},
192*4882a593Smuzhiyun 	{0x00, 0x8a, 0x81a6},
193*4882a593Smuzhiyun 	{0x00, 0x8a, 0x81b7},
194*4882a593Smuzhiyun 	{0x00, 0x9b, 0x8196},
195*4882a593Smuzhiyun 	{0x00, 0x9b, 0x81a7},
196*4882a593Smuzhiyun 	{0x00, 0x9b, 0x81b8},
197*4882a593Smuzhiyun 	{0x00, 0xa6, 0x8197},
198*4882a593Smuzhiyun 	{0x00, 0xa6, 0x81a8},
199*4882a593Smuzhiyun 	{0x00, 0xa6, 0x81b9},
200*4882a593Smuzhiyun 	{0x00, 0xb2, 0x8198},
201*4882a593Smuzhiyun 	{0x00, 0xb2, 0x81a9},
202*4882a593Smuzhiyun 	{0x00, 0xb2, 0x81ba},
203*4882a593Smuzhiyun 	{0x00, 0xbe, 0x8199},
204*4882a593Smuzhiyun 	{0x00, 0xbe, 0x81aa},
205*4882a593Smuzhiyun 	{0x00, 0xbe, 0x81bb},
206*4882a593Smuzhiyun 	{0x00, 0xc8, 0x819a},
207*4882a593Smuzhiyun 	{0x00, 0xc8, 0x81ab},
208*4882a593Smuzhiyun 	{0x00, 0xc8, 0x81bc},
209*4882a593Smuzhiyun 	{0x00, 0xd2, 0x819b},
210*4882a593Smuzhiyun 	{0x00, 0xd2, 0x81ac},
211*4882a593Smuzhiyun 	{0x00, 0xd2, 0x81bd},
212*4882a593Smuzhiyun 	{0x00, 0xdb, 0x819c},
213*4882a593Smuzhiyun 	{0x00, 0xdb, 0x81ad},
214*4882a593Smuzhiyun 	{0x00, 0xdb, 0x81be},
215*4882a593Smuzhiyun 	{0x00, 0xe4, 0x819d},
216*4882a593Smuzhiyun 	{0x00, 0xe4, 0x81ae},
217*4882a593Smuzhiyun 	{0x00, 0xe4, 0x81bf},
218*4882a593Smuzhiyun 	{0x00, 0xed, 0x819e},
219*4882a593Smuzhiyun 	{0x00, 0xed, 0x81af},
220*4882a593Smuzhiyun 	{0x00, 0xed, 0x81c0},
221*4882a593Smuzhiyun 	{0x00, 0xf7, 0x819f},
222*4882a593Smuzhiyun 	{0x00, 0xf7, 0x81b0},
223*4882a593Smuzhiyun 	{0x00, 0xf7, 0x81c1},
224*4882a593Smuzhiyun 	{0x00, 0xff, 0x81a0},
225*4882a593Smuzhiyun 	{0x00, 0xff, 0x81b1},
226*4882a593Smuzhiyun 	{0x00, 0xff, 0x81c2},
227*4882a593Smuzhiyun 	{0x00, 0x03, 0x8156},
228*4882a593Smuzhiyun 	{0x00, 0x00, 0x8211},
229*4882a593Smuzhiyun 	{0x00, 0x20, 0x8168},
230*4882a593Smuzhiyun 	{0x00, 0x01, 0x8202},
231*4882a593Smuzhiyun 	{0x00, 0x30, 0x8101},
232*4882a593Smuzhiyun 	{0x00, 0x00, 0x8111},
233*4882a593Smuzhiyun 	{0x00, 0x00, 0x8112},
234*4882a593Smuzhiyun 	{0x00, 0x00, 0x8113},
235*4882a593Smuzhiyun 	{0x00, 0x00, 0x8114},
236*4882a593Smuzhiyun 	{}
237*4882a593Smuzhiyun };
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun static const __u8 qtable_creative_pccam[2][64] = {
240*4882a593Smuzhiyun 	{				/* Q-table Y-components */
241*4882a593Smuzhiyun 	 0x05, 0x03, 0x03, 0x05, 0x07, 0x0c, 0x0f, 0x12,
242*4882a593Smuzhiyun 	 0x04, 0x04, 0x04, 0x06, 0x08, 0x11, 0x12, 0x11,
243*4882a593Smuzhiyun 	 0x04, 0x04, 0x05, 0x07, 0x0c, 0x11, 0x15, 0x11,
244*4882a593Smuzhiyun 	 0x04, 0x05, 0x07, 0x09, 0x0f, 0x1a, 0x18, 0x13,
245*4882a593Smuzhiyun 	 0x05, 0x07, 0x0b, 0x11, 0x14, 0x21, 0x1f, 0x17,
246*4882a593Smuzhiyun 	 0x07, 0x0b, 0x11, 0x13, 0x18, 0x1f, 0x22, 0x1c,
247*4882a593Smuzhiyun 	 0x0f, 0x13, 0x17, 0x1a, 0x1f, 0x24, 0x24, 0x1e,
248*4882a593Smuzhiyun 	 0x16, 0x1c, 0x1d, 0x1d, 0x22, 0x1e, 0x1f, 0x1e},
249*4882a593Smuzhiyun 	{				/* Q-table C-components */
250*4882a593Smuzhiyun 	 0x05, 0x05, 0x07, 0x0e, 0x1e, 0x1e, 0x1e, 0x1e,
251*4882a593Smuzhiyun 	 0x05, 0x06, 0x08, 0x14, 0x1e, 0x1e, 0x1e, 0x1e,
252*4882a593Smuzhiyun 	 0x07, 0x08, 0x11, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
253*4882a593Smuzhiyun 	 0x0e, 0x14, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
254*4882a593Smuzhiyun 	 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
255*4882a593Smuzhiyun 	 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
256*4882a593Smuzhiyun 	 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
257*4882a593Smuzhiyun 	 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e}
258*4882a593Smuzhiyun };
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun static const __u8 qtable_kodak_ez200[2][64] = {
261*4882a593Smuzhiyun 	{				/* Q-table Y-components */
262*4882a593Smuzhiyun 	 0x02, 0x01, 0x01, 0x02, 0x02, 0x04, 0x05, 0x06,
263*4882a593Smuzhiyun 	 0x01, 0x01, 0x01, 0x02, 0x03, 0x06, 0x06, 0x06,
264*4882a593Smuzhiyun 	 0x01, 0x01, 0x02, 0x02, 0x04, 0x06, 0x07, 0x06,
265*4882a593Smuzhiyun 	 0x01, 0x02, 0x02, 0x03, 0x05, 0x09, 0x08, 0x06,
266*4882a593Smuzhiyun 	 0x02, 0x02, 0x04, 0x06, 0x07, 0x0b, 0x0a, 0x08,
267*4882a593Smuzhiyun 	 0x02, 0x04, 0x06, 0x06, 0x08, 0x0a, 0x0b, 0x09,
268*4882a593Smuzhiyun 	 0x05, 0x06, 0x08, 0x09, 0x0a, 0x0c, 0x0c, 0x0a,
269*4882a593Smuzhiyun 	 0x07, 0x09, 0x0a, 0x0a, 0x0b, 0x0a, 0x0a, 0x0a},
270*4882a593Smuzhiyun 	{				/* Q-table C-components */
271*4882a593Smuzhiyun 	 0x02, 0x02, 0x02, 0x05, 0x0a, 0x0a, 0x0a, 0x0a,
272*4882a593Smuzhiyun 	 0x02, 0x02, 0x03, 0x07, 0x0a, 0x0a, 0x0a, 0x0a,
273*4882a593Smuzhiyun 	 0x02, 0x03, 0x06, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
274*4882a593Smuzhiyun 	 0x05, 0x07, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
275*4882a593Smuzhiyun 	 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
276*4882a593Smuzhiyun 	 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
277*4882a593Smuzhiyun 	 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
278*4882a593Smuzhiyun 	 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}
279*4882a593Smuzhiyun };
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun static const __u8 qtable_pocketdv[2][64] = {
282*4882a593Smuzhiyun 	{		/* Q-table Y-components start registers 0x8800 */
283*4882a593Smuzhiyun 	 0x06, 0x04, 0x04, 0x06, 0x0a, 0x10, 0x14, 0x18,
284*4882a593Smuzhiyun 	 0x05, 0x05, 0x06, 0x08, 0x0a, 0x17, 0x18, 0x16,
285*4882a593Smuzhiyun 	 0x06, 0x05, 0x06, 0x0a, 0x10, 0x17, 0x1c, 0x16,
286*4882a593Smuzhiyun 	 0x06, 0x07, 0x09, 0x0c, 0x14, 0x23, 0x20, 0x19,
287*4882a593Smuzhiyun 	 0x07, 0x09, 0x0f, 0x16, 0x1b, 0x2c, 0x29, 0x1f,
288*4882a593Smuzhiyun 	 0x0a, 0x0e, 0x16, 0x1a, 0x20, 0x2a, 0x2d, 0x25,
289*4882a593Smuzhiyun 	 0x14, 0x1a, 0x1f, 0x23, 0x29, 0x30, 0x30, 0x28,
290*4882a593Smuzhiyun 	 0x1d, 0x25, 0x26, 0x27, 0x2d, 0x28, 0x29, 0x28,
291*4882a593Smuzhiyun 	 },
292*4882a593Smuzhiyun 	{		/* Q-table C-components start registers 0x8840 */
293*4882a593Smuzhiyun 	 0x07, 0x07, 0x0a, 0x13, 0x28, 0x28, 0x28, 0x28,
294*4882a593Smuzhiyun 	 0x07, 0x08, 0x0a, 0x1a, 0x28, 0x28, 0x28, 0x28,
295*4882a593Smuzhiyun 	 0x0a, 0x0a, 0x16, 0x28, 0x28, 0x28, 0x28, 0x28,
296*4882a593Smuzhiyun 	 0x13, 0x1a, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
297*4882a593Smuzhiyun 	 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
298*4882a593Smuzhiyun 	 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
299*4882a593Smuzhiyun 	 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
300*4882a593Smuzhiyun 	 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28}
301*4882a593Smuzhiyun };
302*4882a593Smuzhiyun 
303*4882a593Smuzhiyun /* read 'len' bytes to gspca_dev->usb_buf */
reg_r(struct gspca_dev * gspca_dev,__u16 index,__u16 length)304*4882a593Smuzhiyun static void reg_r(struct gspca_dev *gspca_dev,
305*4882a593Smuzhiyun 		  __u16 index,
306*4882a593Smuzhiyun 		  __u16 length)
307*4882a593Smuzhiyun {
308*4882a593Smuzhiyun 	usb_control_msg(gspca_dev->dev,
309*4882a593Smuzhiyun 			usb_rcvctrlpipe(gspca_dev->dev, 0),
310*4882a593Smuzhiyun 			0,
311*4882a593Smuzhiyun 			USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
312*4882a593Smuzhiyun 			0,		/* value */
313*4882a593Smuzhiyun 			index, gspca_dev->usb_buf, length, 500);
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun 
reg_w(struct gspca_dev * gspca_dev,__u16 req,__u16 index,__u16 value)316*4882a593Smuzhiyun static int reg_w(struct gspca_dev *gspca_dev,
317*4882a593Smuzhiyun 		     __u16 req, __u16 index, __u16 value)
318*4882a593Smuzhiyun {
319*4882a593Smuzhiyun 	int ret;
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun 	gspca_dbg(gspca_dev, D_USBO, "reg write: [0x%02x] = 0x%02x\n",
322*4882a593Smuzhiyun 		  index, value);
323*4882a593Smuzhiyun 	ret = usb_control_msg(gspca_dev->dev,
324*4882a593Smuzhiyun 			usb_sndctrlpipe(gspca_dev->dev, 0),
325*4882a593Smuzhiyun 			req,
326*4882a593Smuzhiyun 			USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
327*4882a593Smuzhiyun 			value, index, NULL, 0, 500);
328*4882a593Smuzhiyun 	if (ret < 0)
329*4882a593Smuzhiyun 		pr_err("reg write: error %d\n", ret);
330*4882a593Smuzhiyun 	return ret;
331*4882a593Smuzhiyun }
332*4882a593Smuzhiyun 
333*4882a593Smuzhiyun /* returns: negative is error, pos or zero is data */
reg_r_12(struct gspca_dev * gspca_dev,__u16 req,__u16 index,__u16 length)334*4882a593Smuzhiyun static int reg_r_12(struct gspca_dev *gspca_dev,
335*4882a593Smuzhiyun 			__u16 req,	/* bRequest */
336*4882a593Smuzhiyun 			__u16 index,	/* wIndex */
337*4882a593Smuzhiyun 			__u16 length)	/* wLength (1 or 2 only) */
338*4882a593Smuzhiyun {
339*4882a593Smuzhiyun 	int ret;
340*4882a593Smuzhiyun 
341*4882a593Smuzhiyun 	gspca_dev->usb_buf[1] = 0;
342*4882a593Smuzhiyun 	ret = usb_control_msg(gspca_dev->dev,
343*4882a593Smuzhiyun 			usb_rcvctrlpipe(gspca_dev->dev, 0),
344*4882a593Smuzhiyun 			req,
345*4882a593Smuzhiyun 			USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
346*4882a593Smuzhiyun 			0,		/* value */
347*4882a593Smuzhiyun 			index,
348*4882a593Smuzhiyun 			gspca_dev->usb_buf, length,
349*4882a593Smuzhiyun 			500);		/* timeout */
350*4882a593Smuzhiyun 	if (ret < 0) {
351*4882a593Smuzhiyun 		pr_err("reg_r_12 err %d\n", ret);
352*4882a593Smuzhiyun 		return ret;
353*4882a593Smuzhiyun 	}
354*4882a593Smuzhiyun 	return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
355*4882a593Smuzhiyun }
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun /*
358*4882a593Smuzhiyun  * Simple function to wait for a given 8-bit value to be returned from
359*4882a593Smuzhiyun  * a reg_read call.
360*4882a593Smuzhiyun  * Returns: negative is error or timeout, zero is success.
361*4882a593Smuzhiyun  */
reg_r_wait(struct gspca_dev * gspca_dev,__u16 reg,__u16 index,__u16 value)362*4882a593Smuzhiyun static int reg_r_wait(struct gspca_dev *gspca_dev,
363*4882a593Smuzhiyun 			__u16 reg, __u16 index, __u16 value)
364*4882a593Smuzhiyun {
365*4882a593Smuzhiyun 	int ret, cnt = 20;
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun 	while (--cnt > 0) {
368*4882a593Smuzhiyun 		ret = reg_r_12(gspca_dev, reg, index, 1);
369*4882a593Smuzhiyun 		if (ret == value)
370*4882a593Smuzhiyun 			return 0;
371*4882a593Smuzhiyun 		msleep(50);
372*4882a593Smuzhiyun 	}
373*4882a593Smuzhiyun 	return -EIO;
374*4882a593Smuzhiyun }
375*4882a593Smuzhiyun 
write_vector(struct gspca_dev * gspca_dev,const __u16 data[][3])376*4882a593Smuzhiyun static int write_vector(struct gspca_dev *gspca_dev,
377*4882a593Smuzhiyun 			const __u16 data[][3])
378*4882a593Smuzhiyun {
379*4882a593Smuzhiyun 	int ret, i = 0;
380*4882a593Smuzhiyun 
381*4882a593Smuzhiyun 	while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) {
382*4882a593Smuzhiyun 		ret = reg_w(gspca_dev, data[i][0], data[i][2], data[i][1]);
383*4882a593Smuzhiyun 		if (ret < 0)
384*4882a593Smuzhiyun 			return ret;
385*4882a593Smuzhiyun 		i++;
386*4882a593Smuzhiyun 	}
387*4882a593Smuzhiyun 	return 0;
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun 
spca50x_setup_qtable(struct gspca_dev * gspca_dev,unsigned int request,unsigned int ybase,unsigned int cbase,const __u8 qtable[2][64])390*4882a593Smuzhiyun static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
391*4882a593Smuzhiyun 				unsigned int request,
392*4882a593Smuzhiyun 				unsigned int ybase,
393*4882a593Smuzhiyun 				unsigned int cbase,
394*4882a593Smuzhiyun 				const __u8 qtable[2][64])
395*4882a593Smuzhiyun {
396*4882a593Smuzhiyun 	int i, err;
397*4882a593Smuzhiyun 
398*4882a593Smuzhiyun 	/* loop over y components */
399*4882a593Smuzhiyun 	for (i = 0; i < 64; i++) {
400*4882a593Smuzhiyun 		err = reg_w(gspca_dev, request, ybase + i, qtable[0][i]);
401*4882a593Smuzhiyun 		if (err < 0)
402*4882a593Smuzhiyun 			return err;
403*4882a593Smuzhiyun 	}
404*4882a593Smuzhiyun 
405*4882a593Smuzhiyun 	/* loop over c components */
406*4882a593Smuzhiyun 	for (i = 0; i < 64; i++) {
407*4882a593Smuzhiyun 		err = reg_w(gspca_dev, request, cbase + i, qtable[1][i]);
408*4882a593Smuzhiyun 		if (err < 0)
409*4882a593Smuzhiyun 			return err;
410*4882a593Smuzhiyun 	}
411*4882a593Smuzhiyun 	return 0;
412*4882a593Smuzhiyun }
413*4882a593Smuzhiyun 
spca500_ping310(struct gspca_dev * gspca_dev)414*4882a593Smuzhiyun static void spca500_ping310(struct gspca_dev *gspca_dev)
415*4882a593Smuzhiyun {
416*4882a593Smuzhiyun 	reg_r(gspca_dev, 0x0d04, 2);
417*4882a593Smuzhiyun 	gspca_dbg(gspca_dev, D_STREAM, "ClickSmart310 ping 0x0d04 0x%02x 0x%02x\n",
418*4882a593Smuzhiyun 		  gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]);
419*4882a593Smuzhiyun }
420*4882a593Smuzhiyun 
spca500_clksmart310_init(struct gspca_dev * gspca_dev)421*4882a593Smuzhiyun static void spca500_clksmart310_init(struct gspca_dev *gspca_dev)
422*4882a593Smuzhiyun {
423*4882a593Smuzhiyun 	reg_r(gspca_dev, 0x0d05, 2);
424*4882a593Smuzhiyun 	gspca_dbg(gspca_dev, D_STREAM, "ClickSmart310 init 0x0d05 0x%02x 0x%02x\n",
425*4882a593Smuzhiyun 		  gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]);
426*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8167, 0x5a);
427*4882a593Smuzhiyun 	spca500_ping310(gspca_dev);
428*4882a593Smuzhiyun 
429*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8168, 0x22);
430*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x816a, 0xc0);
431*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x816b, 0x0b);
432*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8169, 0x25);
433*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8157, 0x5b);
434*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8158, 0x5b);
435*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x813f, 0x03);
436*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8151, 0x4a);
437*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8153, 0x78);
438*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x0d01, 0x04);
439*4882a593Smuzhiyun 						/* 00 for adjust shutter */
440*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x0d02, 0x01);
441*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8169, 0x25);
442*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x0d01, 0x02);
443*4882a593Smuzhiyun }
444*4882a593Smuzhiyun 
spca500_setmode(struct gspca_dev * gspca_dev,__u8 xmult,__u8 ymult)445*4882a593Smuzhiyun static void spca500_setmode(struct gspca_dev *gspca_dev,
446*4882a593Smuzhiyun 			__u8 xmult, __u8 ymult)
447*4882a593Smuzhiyun {
448*4882a593Smuzhiyun 	int mode;
449*4882a593Smuzhiyun 
450*4882a593Smuzhiyun 	/* set x multiplier */
451*4882a593Smuzhiyun 	reg_w(gspca_dev, 0, 0x8001, xmult);
452*4882a593Smuzhiyun 
453*4882a593Smuzhiyun 	/* set y multiplier */
454*4882a593Smuzhiyun 	reg_w(gspca_dev, 0, 0x8002, ymult);
455*4882a593Smuzhiyun 
456*4882a593Smuzhiyun 	/* use compressed mode, VGA, with mode specific subsample */
457*4882a593Smuzhiyun 	mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
458*4882a593Smuzhiyun 	reg_w(gspca_dev, 0, 0x8003, mode << 4);
459*4882a593Smuzhiyun }
460*4882a593Smuzhiyun 
spca500_full_reset(struct gspca_dev * gspca_dev)461*4882a593Smuzhiyun static int spca500_full_reset(struct gspca_dev *gspca_dev)
462*4882a593Smuzhiyun {
463*4882a593Smuzhiyun 	int err;
464*4882a593Smuzhiyun 
465*4882a593Smuzhiyun 	/* send the reset command */
466*4882a593Smuzhiyun 	err = reg_w(gspca_dev, 0xe0, 0x0001, 0x0000);
467*4882a593Smuzhiyun 	if (err < 0)
468*4882a593Smuzhiyun 		return err;
469*4882a593Smuzhiyun 
470*4882a593Smuzhiyun 	/* wait for the reset to complete */
471*4882a593Smuzhiyun 	err = reg_r_wait(gspca_dev, 0x06, 0x0000, 0x0000);
472*4882a593Smuzhiyun 	if (err < 0)
473*4882a593Smuzhiyun 		return err;
474*4882a593Smuzhiyun 	err = reg_w(gspca_dev, 0xe0, 0x0000, 0x0000);
475*4882a593Smuzhiyun 	if (err < 0)
476*4882a593Smuzhiyun 		return err;
477*4882a593Smuzhiyun 	err = reg_r_wait(gspca_dev, 0x06, 0, 0);
478*4882a593Smuzhiyun 	if (err < 0) {
479*4882a593Smuzhiyun 		gspca_err(gspca_dev, "reg_r_wait() failed\n");
480*4882a593Smuzhiyun 		return err;
481*4882a593Smuzhiyun 	}
482*4882a593Smuzhiyun 	/* all ok */
483*4882a593Smuzhiyun 	return 0;
484*4882a593Smuzhiyun }
485*4882a593Smuzhiyun 
486*4882a593Smuzhiyun /* Synchro the Bridge with sensor */
487*4882a593Smuzhiyun /* Maybe that will work on all spca500 chip */
488*4882a593Smuzhiyun /* because i only own a clicksmart310 try for that chip */
489*4882a593Smuzhiyun /* using spca50x_set_packet_size() cause an Ooops here */
490*4882a593Smuzhiyun /* usb_set_interface from kernel 2.6.x clear all the urb stuff */
491*4882a593Smuzhiyun /* up-port the same feature as in 2.4.x kernel */
spca500_synch310(struct gspca_dev * gspca_dev)492*4882a593Smuzhiyun static int spca500_synch310(struct gspca_dev *gspca_dev)
493*4882a593Smuzhiyun {
494*4882a593Smuzhiyun 	if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0) < 0) {
495*4882a593Smuzhiyun 		gspca_err(gspca_dev, "Set packet size: set interface error\n");
496*4882a593Smuzhiyun 		goto error;
497*4882a593Smuzhiyun 	}
498*4882a593Smuzhiyun 	spca500_ping310(gspca_dev);
499*4882a593Smuzhiyun 
500*4882a593Smuzhiyun 	reg_r(gspca_dev, 0x0d00, 1);
501*4882a593Smuzhiyun 
502*4882a593Smuzhiyun 	/* need alt setting here */
503*4882a593Smuzhiyun 	gspca_dbg(gspca_dev, D_PACK, "ClickSmart310 sync alt: %d\n",
504*4882a593Smuzhiyun 		  gspca_dev->alt);
505*4882a593Smuzhiyun 
506*4882a593Smuzhiyun 	/* Windoze use pipe with altsetting 6 why 7 here */
507*4882a593Smuzhiyun 	if (usb_set_interface(gspca_dev->dev,
508*4882a593Smuzhiyun 				gspca_dev->iface,
509*4882a593Smuzhiyun 				gspca_dev->alt) < 0) {
510*4882a593Smuzhiyun 		gspca_err(gspca_dev, "Set packet size: set interface error\n");
511*4882a593Smuzhiyun 		goto error;
512*4882a593Smuzhiyun 	}
513*4882a593Smuzhiyun 	return 0;
514*4882a593Smuzhiyun error:
515*4882a593Smuzhiyun 	return -EBUSY;
516*4882a593Smuzhiyun }
517*4882a593Smuzhiyun 
spca500_reinit(struct gspca_dev * gspca_dev)518*4882a593Smuzhiyun static void spca500_reinit(struct gspca_dev *gspca_dev)
519*4882a593Smuzhiyun {
520*4882a593Smuzhiyun 	int err;
521*4882a593Smuzhiyun 	__u8 Data;
522*4882a593Smuzhiyun 
523*4882a593Smuzhiyun 	/* some unknown command from Aiptek pocket dv and family300 */
524*4882a593Smuzhiyun 
525*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x0d01, 0x01);
526*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x0d03, 0x00);
527*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x0d02, 0x01);
528*4882a593Smuzhiyun 
529*4882a593Smuzhiyun 	/* enable drop packet */
530*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
531*4882a593Smuzhiyun 
532*4882a593Smuzhiyun 	err = spca50x_setup_qtable(gspca_dev, 0x00, 0x8800, 0x8840,
533*4882a593Smuzhiyun 				 qtable_pocketdv);
534*4882a593Smuzhiyun 	if (err < 0)
535*4882a593Smuzhiyun 		gspca_err(gspca_dev, "spca50x_setup_qtable failed on init\n");
536*4882a593Smuzhiyun 
537*4882a593Smuzhiyun 	/* set qtable index */
538*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8880, 2);
539*4882a593Smuzhiyun 	/* family cam Quicksmart stuff */
540*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x800a, 0x00);
541*4882a593Smuzhiyun 	/* Set agc transfer: synced between frames */
542*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x820f, 0x01);
543*4882a593Smuzhiyun 	/* Init SDRAM - needed for SDRAM access */
544*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x870a, 0x04);
545*4882a593Smuzhiyun 	/*Start init sequence or stream */
546*4882a593Smuzhiyun 	reg_w(gspca_dev, 0, 0x8003, 0x00);
547*4882a593Smuzhiyun 	/* switch to video camera mode */
548*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
549*4882a593Smuzhiyun 	msleep(2000);
550*4882a593Smuzhiyun 	if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0) {
551*4882a593Smuzhiyun 		reg_r(gspca_dev, 0x816b, 1);
552*4882a593Smuzhiyun 		Data = gspca_dev->usb_buf[0];
553*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x816b, Data);
554*4882a593Smuzhiyun 	}
555*4882a593Smuzhiyun }
556*4882a593Smuzhiyun 
557*4882a593Smuzhiyun /* this function is called at probe time */
sd_config(struct gspca_dev * gspca_dev,const struct usb_device_id * id)558*4882a593Smuzhiyun static int sd_config(struct gspca_dev *gspca_dev,
559*4882a593Smuzhiyun 			const struct usb_device_id *id)
560*4882a593Smuzhiyun {
561*4882a593Smuzhiyun 	struct sd *sd = (struct sd *) gspca_dev;
562*4882a593Smuzhiyun 	struct cam *cam;
563*4882a593Smuzhiyun 
564*4882a593Smuzhiyun 	cam = &gspca_dev->cam;
565*4882a593Smuzhiyun 	sd->subtype = id->driver_info;
566*4882a593Smuzhiyun 	if (sd->subtype != LogitechClickSmart310) {
567*4882a593Smuzhiyun 		cam->cam_mode = vga_mode;
568*4882a593Smuzhiyun 		cam->nmodes = ARRAY_SIZE(vga_mode);
569*4882a593Smuzhiyun 	} else {
570*4882a593Smuzhiyun 		cam->cam_mode = sif_mode;
571*4882a593Smuzhiyun 		cam->nmodes = ARRAY_SIZE(sif_mode);
572*4882a593Smuzhiyun 	}
573*4882a593Smuzhiyun 	return 0;
574*4882a593Smuzhiyun }
575*4882a593Smuzhiyun 
576*4882a593Smuzhiyun /* this function is called at probe and resume time */
sd_init(struct gspca_dev * gspca_dev)577*4882a593Smuzhiyun static int sd_init(struct gspca_dev *gspca_dev)
578*4882a593Smuzhiyun {
579*4882a593Smuzhiyun 	struct sd *sd = (struct sd *) gspca_dev;
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun 	/* initialisation of spca500 based cameras is deferred */
582*4882a593Smuzhiyun 	gspca_dbg(gspca_dev, D_STREAM, "SPCA500 init\n");
583*4882a593Smuzhiyun 	if (sd->subtype == LogitechClickSmart310)
584*4882a593Smuzhiyun 		spca500_clksmart310_init(gspca_dev);
585*4882a593Smuzhiyun /*	else
586*4882a593Smuzhiyun 		spca500_initialise(gspca_dev); */
587*4882a593Smuzhiyun 	gspca_dbg(gspca_dev, D_STREAM, "SPCA500 init done\n");
588*4882a593Smuzhiyun 	return 0;
589*4882a593Smuzhiyun }
590*4882a593Smuzhiyun 
sd_start(struct gspca_dev * gspca_dev)591*4882a593Smuzhiyun static int sd_start(struct gspca_dev *gspca_dev)
592*4882a593Smuzhiyun {
593*4882a593Smuzhiyun 	struct sd *sd = (struct sd *) gspca_dev;
594*4882a593Smuzhiyun 	int err;
595*4882a593Smuzhiyun 	__u8 Data;
596*4882a593Smuzhiyun 	__u8 xmult, ymult;
597*4882a593Smuzhiyun 
598*4882a593Smuzhiyun 	/* create the JPEG header */
599*4882a593Smuzhiyun 	jpeg_define(sd->jpeg_hdr, gspca_dev->pixfmt.height,
600*4882a593Smuzhiyun 			gspca_dev->pixfmt.width,
601*4882a593Smuzhiyun 			0x22);		/* JPEG 411 */
602*4882a593Smuzhiyun 	jpeg_set_qual(sd->jpeg_hdr, QUALITY);
603*4882a593Smuzhiyun 
604*4882a593Smuzhiyun 	if (sd->subtype == LogitechClickSmart310) {
605*4882a593Smuzhiyun 		xmult = 0x16;
606*4882a593Smuzhiyun 		ymult = 0x12;
607*4882a593Smuzhiyun 	} else {
608*4882a593Smuzhiyun 		xmult = 0x28;
609*4882a593Smuzhiyun 		ymult = 0x1e;
610*4882a593Smuzhiyun 	}
611*4882a593Smuzhiyun 
612*4882a593Smuzhiyun 	/* is there a sensor here ? */
613*4882a593Smuzhiyun 	reg_r(gspca_dev, 0x8a04, 1);
614*4882a593Smuzhiyun 	gspca_dbg(gspca_dev, D_STREAM, "Spca500 Sensor Address 0x%02x\n",
615*4882a593Smuzhiyun 		  gspca_dev->usb_buf[0]);
616*4882a593Smuzhiyun 	gspca_dbg(gspca_dev, D_STREAM, "Spca500 curr_mode: %d Xmult: 0x%02x, Ymult: 0x%02x",
617*4882a593Smuzhiyun 		  gspca_dev->curr_mode, xmult, ymult);
618*4882a593Smuzhiyun 
619*4882a593Smuzhiyun 	/* setup qtable */
620*4882a593Smuzhiyun 	switch (sd->subtype) {
621*4882a593Smuzhiyun 	case LogitechClickSmart310:
622*4882a593Smuzhiyun 		 spca500_setmode(gspca_dev, xmult, ymult);
623*4882a593Smuzhiyun 
624*4882a593Smuzhiyun 		/* enable drop packet */
625*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
626*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x8880, 3);
627*4882a593Smuzhiyun 		err = spca50x_setup_qtable(gspca_dev,
628*4882a593Smuzhiyun 					   0x00, 0x8800, 0x8840,
629*4882a593Smuzhiyun 					   qtable_creative_pccam);
630*4882a593Smuzhiyun 		if (err < 0)
631*4882a593Smuzhiyun 			gspca_err(gspca_dev, "spca50x_setup_qtable failed\n");
632*4882a593Smuzhiyun 		/* Init SDRAM - needed for SDRAM access */
633*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x870a, 0x04);
634*4882a593Smuzhiyun 
635*4882a593Smuzhiyun 		/* switch to video camera mode */
636*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
637*4882a593Smuzhiyun 		msleep(500);
638*4882a593Smuzhiyun 		if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
639*4882a593Smuzhiyun 			gspca_err(gspca_dev, "reg_r_wait() failed\n");
640*4882a593Smuzhiyun 
641*4882a593Smuzhiyun 		reg_r(gspca_dev, 0x816b, 1);
642*4882a593Smuzhiyun 		Data = gspca_dev->usb_buf[0];
643*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x816b, Data);
644*4882a593Smuzhiyun 
645*4882a593Smuzhiyun 		spca500_synch310(gspca_dev);
646*4882a593Smuzhiyun 
647*4882a593Smuzhiyun 		write_vector(gspca_dev, spca500_visual_defaults);
648*4882a593Smuzhiyun 		spca500_setmode(gspca_dev, xmult, ymult);
649*4882a593Smuzhiyun 		/* enable drop packet */
650*4882a593Smuzhiyun 		err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
651*4882a593Smuzhiyun 		if (err < 0)
652*4882a593Smuzhiyun 			gspca_err(gspca_dev, "failed to enable drop packet\n");
653*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x8880, 3);
654*4882a593Smuzhiyun 		err = spca50x_setup_qtable(gspca_dev,
655*4882a593Smuzhiyun 					   0x00, 0x8800, 0x8840,
656*4882a593Smuzhiyun 					   qtable_creative_pccam);
657*4882a593Smuzhiyun 		if (err < 0)
658*4882a593Smuzhiyun 			gspca_err(gspca_dev, "spca50x_setup_qtable failed\n");
659*4882a593Smuzhiyun 
660*4882a593Smuzhiyun 		/* Init SDRAM - needed for SDRAM access */
661*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x870a, 0x04);
662*4882a593Smuzhiyun 
663*4882a593Smuzhiyun 		/* switch to video camera mode */
664*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
665*4882a593Smuzhiyun 
666*4882a593Smuzhiyun 		if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
667*4882a593Smuzhiyun 			gspca_err(gspca_dev, "reg_r_wait() failed\n");
668*4882a593Smuzhiyun 
669*4882a593Smuzhiyun 		reg_r(gspca_dev, 0x816b, 1);
670*4882a593Smuzhiyun 		Data = gspca_dev->usb_buf[0];
671*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x816b, Data);
672*4882a593Smuzhiyun 		break;
673*4882a593Smuzhiyun 	case CreativePCCam300:		/* Creative PC-CAM 300 640x480 CCD */
674*4882a593Smuzhiyun 	case IntelPocketPCCamera:	/* FIXME: Temporary fix for
675*4882a593Smuzhiyun 					 *	Intel Pocket PC Camera
676*4882a593Smuzhiyun 					 *	- NWG (Sat 29th March 2003) */
677*4882a593Smuzhiyun 
678*4882a593Smuzhiyun 		/* do a full reset */
679*4882a593Smuzhiyun 		err = spca500_full_reset(gspca_dev);
680*4882a593Smuzhiyun 		if (err < 0)
681*4882a593Smuzhiyun 			gspca_err(gspca_dev, "spca500_full_reset failed\n");
682*4882a593Smuzhiyun 
683*4882a593Smuzhiyun 		/* enable drop packet */
684*4882a593Smuzhiyun 		err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
685*4882a593Smuzhiyun 		if (err < 0)
686*4882a593Smuzhiyun 			gspca_err(gspca_dev, "failed to enable drop packet\n");
687*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x8880, 3);
688*4882a593Smuzhiyun 		err = spca50x_setup_qtable(gspca_dev,
689*4882a593Smuzhiyun 					   0x00, 0x8800, 0x8840,
690*4882a593Smuzhiyun 					   qtable_creative_pccam);
691*4882a593Smuzhiyun 		if (err < 0)
692*4882a593Smuzhiyun 			gspca_err(gspca_dev, "spca50x_setup_qtable failed\n");
693*4882a593Smuzhiyun 
694*4882a593Smuzhiyun 		spca500_setmode(gspca_dev, xmult, ymult);
695*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x20, 0x0001, 0x0004);
696*4882a593Smuzhiyun 
697*4882a593Smuzhiyun 		/* switch to video camera mode */
698*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
699*4882a593Smuzhiyun 
700*4882a593Smuzhiyun 		if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
701*4882a593Smuzhiyun 			gspca_err(gspca_dev, "reg_r_wait() failed\n");
702*4882a593Smuzhiyun 
703*4882a593Smuzhiyun 		reg_r(gspca_dev, 0x816b, 1);
704*4882a593Smuzhiyun 		Data = gspca_dev->usb_buf[0];
705*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x816b, Data);
706*4882a593Smuzhiyun 
707*4882a593Smuzhiyun /*		write_vector(gspca_dev, spca500_visual_defaults); */
708*4882a593Smuzhiyun 		break;
709*4882a593Smuzhiyun 	case KodakEZ200:		/* Kodak EZ200 */
710*4882a593Smuzhiyun 
711*4882a593Smuzhiyun 		/* do a full reset */
712*4882a593Smuzhiyun 		err = spca500_full_reset(gspca_dev);
713*4882a593Smuzhiyun 		if (err < 0)
714*4882a593Smuzhiyun 			gspca_err(gspca_dev, "spca500_full_reset failed\n");
715*4882a593Smuzhiyun 		/* enable drop packet */
716*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
717*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x8880, 0);
718*4882a593Smuzhiyun 		err = spca50x_setup_qtable(gspca_dev,
719*4882a593Smuzhiyun 					   0x00, 0x8800, 0x8840,
720*4882a593Smuzhiyun 					   qtable_kodak_ez200);
721*4882a593Smuzhiyun 		if (err < 0)
722*4882a593Smuzhiyun 			gspca_err(gspca_dev, "spca50x_setup_qtable failed\n");
723*4882a593Smuzhiyun 		spca500_setmode(gspca_dev, xmult, ymult);
724*4882a593Smuzhiyun 
725*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x20, 0x0001, 0x0004);
726*4882a593Smuzhiyun 
727*4882a593Smuzhiyun 		/* switch to video camera mode */
728*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
729*4882a593Smuzhiyun 
730*4882a593Smuzhiyun 		if (reg_r_wait(gspca_dev, 0, 0x8000, 0x44) != 0)
731*4882a593Smuzhiyun 			gspca_err(gspca_dev, "reg_r_wait() failed\n");
732*4882a593Smuzhiyun 
733*4882a593Smuzhiyun 		reg_r(gspca_dev, 0x816b, 1);
734*4882a593Smuzhiyun 		Data = gspca_dev->usb_buf[0];
735*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x816b, Data);
736*4882a593Smuzhiyun 
737*4882a593Smuzhiyun /*		write_vector(gspca_dev, spca500_visual_defaults); */
738*4882a593Smuzhiyun 		break;
739*4882a593Smuzhiyun 
740*4882a593Smuzhiyun 	case BenqDC1016:
741*4882a593Smuzhiyun 	case DLinkDSC350:		/* FamilyCam 300 */
742*4882a593Smuzhiyun 	case AiptekPocketDV:		/* Aiptek PocketDV */
743*4882a593Smuzhiyun 	case Gsmartmini:		/*Mustek Gsmart Mini */
744*4882a593Smuzhiyun 	case MustekGsmart300:		/* Mustek Gsmart 300 */
745*4882a593Smuzhiyun 	case PalmPixDC85:
746*4882a593Smuzhiyun 	case Optimedia:
747*4882a593Smuzhiyun 	case ToptroIndus:
748*4882a593Smuzhiyun 	case AgfaCl20:
749*4882a593Smuzhiyun 		spca500_reinit(gspca_dev);
750*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x0d01, 0x01);
751*4882a593Smuzhiyun 		/* enable drop packet */
752*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
753*4882a593Smuzhiyun 
754*4882a593Smuzhiyun 		err = spca50x_setup_qtable(gspca_dev,
755*4882a593Smuzhiyun 				   0x00, 0x8800, 0x8840, qtable_pocketdv);
756*4882a593Smuzhiyun 		if (err < 0)
757*4882a593Smuzhiyun 			gspca_err(gspca_dev, "spca50x_setup_qtable failed\n");
758*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x8880, 2);
759*4882a593Smuzhiyun 
760*4882a593Smuzhiyun 		/* familycam Quicksmart pocketDV stuff */
761*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x800a, 0x00);
762*4882a593Smuzhiyun 		/* Set agc transfer: synced between frames */
763*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x820f, 0x01);
764*4882a593Smuzhiyun 		/* Init SDRAM - needed for SDRAM access */
765*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x870a, 0x04);
766*4882a593Smuzhiyun 
767*4882a593Smuzhiyun 		spca500_setmode(gspca_dev, xmult, ymult);
768*4882a593Smuzhiyun 		/* switch to video camera mode */
769*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
770*4882a593Smuzhiyun 
771*4882a593Smuzhiyun 		reg_r_wait(gspca_dev, 0, 0x8000, 0x44);
772*4882a593Smuzhiyun 
773*4882a593Smuzhiyun 		reg_r(gspca_dev, 0x816b, 1);
774*4882a593Smuzhiyun 		Data = gspca_dev->usb_buf[0];
775*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x816b, Data);
776*4882a593Smuzhiyun 		break;
777*4882a593Smuzhiyun 	case LogitechTraveler:
778*4882a593Smuzhiyun 	case LogitechClickSmart510:
779*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x02, 0x00, 0x00);
780*4882a593Smuzhiyun 		/* enable drop packet */
781*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
782*4882a593Smuzhiyun 
783*4882a593Smuzhiyun 		err = spca50x_setup_qtable(gspca_dev,
784*4882a593Smuzhiyun 					0x00, 0x8800,
785*4882a593Smuzhiyun 					0x8840, qtable_creative_pccam);
786*4882a593Smuzhiyun 		if (err < 0)
787*4882a593Smuzhiyun 			gspca_err(gspca_dev, "spca50x_setup_qtable failed\n");
788*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x8880, 3);
789*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x800a, 0x00);
790*4882a593Smuzhiyun 		/* Init SDRAM - needed for SDRAM access */
791*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x870a, 0x04);
792*4882a593Smuzhiyun 
793*4882a593Smuzhiyun 		spca500_setmode(gspca_dev, xmult, ymult);
794*4882a593Smuzhiyun 
795*4882a593Smuzhiyun 		/* switch to video camera mode */
796*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
797*4882a593Smuzhiyun 		reg_r_wait(gspca_dev, 0, 0x8000, 0x44);
798*4882a593Smuzhiyun 
799*4882a593Smuzhiyun 		reg_r(gspca_dev, 0x816b, 1);
800*4882a593Smuzhiyun 		Data = gspca_dev->usb_buf[0];
801*4882a593Smuzhiyun 		reg_w(gspca_dev, 0x00, 0x816b, Data);
802*4882a593Smuzhiyun 		write_vector(gspca_dev, Clicksmart510_defaults);
803*4882a593Smuzhiyun 		break;
804*4882a593Smuzhiyun 	}
805*4882a593Smuzhiyun 	return 0;
806*4882a593Smuzhiyun }
807*4882a593Smuzhiyun 
sd_stopN(struct gspca_dev * gspca_dev)808*4882a593Smuzhiyun static void sd_stopN(struct gspca_dev *gspca_dev)
809*4882a593Smuzhiyun {
810*4882a593Smuzhiyun 	reg_w(gspca_dev, 0, 0x8003, 0x00);
811*4882a593Smuzhiyun 
812*4882a593Smuzhiyun 	/* switch to video camera mode */
813*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8000, 0x0004);
814*4882a593Smuzhiyun 	reg_r(gspca_dev, 0x8000, 1);
815*4882a593Smuzhiyun 	gspca_dbg(gspca_dev, D_STREAM, "stop SPCA500 done reg8000: 0x%2x\n",
816*4882a593Smuzhiyun 		  gspca_dev->usb_buf[0]);
817*4882a593Smuzhiyun }
818*4882a593Smuzhiyun 
sd_pkt_scan(struct gspca_dev * gspca_dev,u8 * data,int len)819*4882a593Smuzhiyun static void sd_pkt_scan(struct gspca_dev *gspca_dev,
820*4882a593Smuzhiyun 			u8 *data,			/* isoc packet */
821*4882a593Smuzhiyun 			int len)			/* iso packet length */
822*4882a593Smuzhiyun {
823*4882a593Smuzhiyun 	struct sd *sd = (struct sd *) gspca_dev;
824*4882a593Smuzhiyun 	int i;
825*4882a593Smuzhiyun 	static __u8 ffd9[] = {0xff, 0xd9};
826*4882a593Smuzhiyun 
827*4882a593Smuzhiyun /* frames are jpeg 4.1.1 without 0xff escape */
828*4882a593Smuzhiyun 	if (data[0] == 0xff) {
829*4882a593Smuzhiyun 		if (data[1] != 0x01) {	/* drop packet */
830*4882a593Smuzhiyun /*			gspca_dev->last_packet_type = DISCARD_PACKET; */
831*4882a593Smuzhiyun 			return;
832*4882a593Smuzhiyun 		}
833*4882a593Smuzhiyun 		gspca_frame_add(gspca_dev, LAST_PACKET,
834*4882a593Smuzhiyun 					ffd9, 2);
835*4882a593Smuzhiyun 
836*4882a593Smuzhiyun 		/* put the JPEG header in the new frame */
837*4882a593Smuzhiyun 		gspca_frame_add(gspca_dev, FIRST_PACKET,
838*4882a593Smuzhiyun 			sd->jpeg_hdr, JPEG_HDR_SZ);
839*4882a593Smuzhiyun 
840*4882a593Smuzhiyun 		data += SPCA500_OFFSET_DATA;
841*4882a593Smuzhiyun 		len -= SPCA500_OFFSET_DATA;
842*4882a593Smuzhiyun 	} else {
843*4882a593Smuzhiyun 		data += 1;
844*4882a593Smuzhiyun 		len -= 1;
845*4882a593Smuzhiyun 	}
846*4882a593Smuzhiyun 
847*4882a593Smuzhiyun 	/* add 0x00 after 0xff */
848*4882a593Smuzhiyun 	i = 0;
849*4882a593Smuzhiyun 	do {
850*4882a593Smuzhiyun 		if (data[i] == 0xff) {
851*4882a593Smuzhiyun 			gspca_frame_add(gspca_dev, INTER_PACKET,
852*4882a593Smuzhiyun 					data, i + 1);
853*4882a593Smuzhiyun 			len -= i;
854*4882a593Smuzhiyun 			data += i;
855*4882a593Smuzhiyun 			*data = 0x00;
856*4882a593Smuzhiyun 			i = 0;
857*4882a593Smuzhiyun 		}
858*4882a593Smuzhiyun 		i++;
859*4882a593Smuzhiyun 	} while (i < len);
860*4882a593Smuzhiyun 	gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
861*4882a593Smuzhiyun }
862*4882a593Smuzhiyun 
setbrightness(struct gspca_dev * gspca_dev,s32 val)863*4882a593Smuzhiyun static void setbrightness(struct gspca_dev *gspca_dev, s32 val)
864*4882a593Smuzhiyun {
865*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8167,
866*4882a593Smuzhiyun 			(__u8) (val - 128));
867*4882a593Smuzhiyun }
868*4882a593Smuzhiyun 
setcontrast(struct gspca_dev * gspca_dev,s32 val)869*4882a593Smuzhiyun static void setcontrast(struct gspca_dev *gspca_dev, s32 val)
870*4882a593Smuzhiyun {
871*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8168, val);
872*4882a593Smuzhiyun }
873*4882a593Smuzhiyun 
setcolors(struct gspca_dev * gspca_dev,s32 val)874*4882a593Smuzhiyun static void setcolors(struct gspca_dev *gspca_dev, s32 val)
875*4882a593Smuzhiyun {
876*4882a593Smuzhiyun 	reg_w(gspca_dev, 0x00, 0x8169, val);
877*4882a593Smuzhiyun }
878*4882a593Smuzhiyun 
sd_s_ctrl(struct v4l2_ctrl * ctrl)879*4882a593Smuzhiyun static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
880*4882a593Smuzhiyun {
881*4882a593Smuzhiyun 	struct gspca_dev *gspca_dev =
882*4882a593Smuzhiyun 		container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
883*4882a593Smuzhiyun 
884*4882a593Smuzhiyun 	gspca_dev->usb_err = 0;
885*4882a593Smuzhiyun 
886*4882a593Smuzhiyun 	if (!gspca_dev->streaming)
887*4882a593Smuzhiyun 		return 0;
888*4882a593Smuzhiyun 
889*4882a593Smuzhiyun 	switch (ctrl->id) {
890*4882a593Smuzhiyun 	case V4L2_CID_BRIGHTNESS:
891*4882a593Smuzhiyun 		setbrightness(gspca_dev, ctrl->val);
892*4882a593Smuzhiyun 		break;
893*4882a593Smuzhiyun 	case V4L2_CID_CONTRAST:
894*4882a593Smuzhiyun 		setcontrast(gspca_dev, ctrl->val);
895*4882a593Smuzhiyun 		break;
896*4882a593Smuzhiyun 	case V4L2_CID_SATURATION:
897*4882a593Smuzhiyun 		setcolors(gspca_dev, ctrl->val);
898*4882a593Smuzhiyun 		break;
899*4882a593Smuzhiyun 	}
900*4882a593Smuzhiyun 	return gspca_dev->usb_err;
901*4882a593Smuzhiyun }
902*4882a593Smuzhiyun 
903*4882a593Smuzhiyun static const struct v4l2_ctrl_ops sd_ctrl_ops = {
904*4882a593Smuzhiyun 	.s_ctrl = sd_s_ctrl,
905*4882a593Smuzhiyun };
906*4882a593Smuzhiyun 
sd_init_controls(struct gspca_dev * gspca_dev)907*4882a593Smuzhiyun static int sd_init_controls(struct gspca_dev *gspca_dev)
908*4882a593Smuzhiyun {
909*4882a593Smuzhiyun 	struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
910*4882a593Smuzhiyun 
911*4882a593Smuzhiyun 	gspca_dev->vdev.ctrl_handler = hdl;
912*4882a593Smuzhiyun 	v4l2_ctrl_handler_init(hdl, 3);
913*4882a593Smuzhiyun 	v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
914*4882a593Smuzhiyun 			V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
915*4882a593Smuzhiyun 	v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
916*4882a593Smuzhiyun 			V4L2_CID_CONTRAST, 0, 63, 1, 31);
917*4882a593Smuzhiyun 	v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
918*4882a593Smuzhiyun 			V4L2_CID_SATURATION, 0, 63, 1, 31);
919*4882a593Smuzhiyun 
920*4882a593Smuzhiyun 	if (hdl->error) {
921*4882a593Smuzhiyun 		pr_err("Could not initialize controls\n");
922*4882a593Smuzhiyun 		return hdl->error;
923*4882a593Smuzhiyun 	}
924*4882a593Smuzhiyun 	return 0;
925*4882a593Smuzhiyun }
926*4882a593Smuzhiyun 
927*4882a593Smuzhiyun /* sub-driver description */
928*4882a593Smuzhiyun static const struct sd_desc sd_desc = {
929*4882a593Smuzhiyun 	.name = MODULE_NAME,
930*4882a593Smuzhiyun 	.config = sd_config,
931*4882a593Smuzhiyun 	.init = sd_init,
932*4882a593Smuzhiyun 	.init_controls = sd_init_controls,
933*4882a593Smuzhiyun 	.start = sd_start,
934*4882a593Smuzhiyun 	.stopN = sd_stopN,
935*4882a593Smuzhiyun 	.pkt_scan = sd_pkt_scan,
936*4882a593Smuzhiyun };
937*4882a593Smuzhiyun 
938*4882a593Smuzhiyun /* -- module initialisation -- */
939*4882a593Smuzhiyun static const struct usb_device_id device_table[] = {
940*4882a593Smuzhiyun 	{USB_DEVICE(0x040a, 0x0300), .driver_info = KodakEZ200},
941*4882a593Smuzhiyun 	{USB_DEVICE(0x041e, 0x400a), .driver_info = CreativePCCam300},
942*4882a593Smuzhiyun 	{USB_DEVICE(0x046d, 0x0890), .driver_info = LogitechTraveler},
943*4882a593Smuzhiyun 	{USB_DEVICE(0x046d, 0x0900), .driver_info = LogitechClickSmart310},
944*4882a593Smuzhiyun 	{USB_DEVICE(0x046d, 0x0901), .driver_info = LogitechClickSmart510},
945*4882a593Smuzhiyun 	{USB_DEVICE(0x04a5, 0x300c), .driver_info = BenqDC1016},
946*4882a593Smuzhiyun 	{USB_DEVICE(0x04fc, 0x7333), .driver_info = PalmPixDC85},
947*4882a593Smuzhiyun 	{USB_DEVICE(0x055f, 0xc200), .driver_info = MustekGsmart300},
948*4882a593Smuzhiyun 	{USB_DEVICE(0x055f, 0xc220), .driver_info = Gsmartmini},
949*4882a593Smuzhiyun 	{USB_DEVICE(0x06bd, 0x0404), .driver_info = AgfaCl20},
950*4882a593Smuzhiyun 	{USB_DEVICE(0x06be, 0x0800), .driver_info = Optimedia},
951*4882a593Smuzhiyun 	{USB_DEVICE(0x084d, 0x0003), .driver_info = DLinkDSC350},
952*4882a593Smuzhiyun 	{USB_DEVICE(0x08ca, 0x0103), .driver_info = AiptekPocketDV},
953*4882a593Smuzhiyun 	{USB_DEVICE(0x2899, 0x012c), .driver_info = ToptroIndus},
954*4882a593Smuzhiyun 	{USB_DEVICE(0x8086, 0x0630), .driver_info = IntelPocketPCCamera},
955*4882a593Smuzhiyun 	{}
956*4882a593Smuzhiyun };
957*4882a593Smuzhiyun MODULE_DEVICE_TABLE(usb, device_table);
958*4882a593Smuzhiyun 
959*4882a593Smuzhiyun /* -- device connect -- */
sd_probe(struct usb_interface * intf,const struct usb_device_id * id)960*4882a593Smuzhiyun static int sd_probe(struct usb_interface *intf,
961*4882a593Smuzhiyun 			const struct usb_device_id *id)
962*4882a593Smuzhiyun {
963*4882a593Smuzhiyun 	return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
964*4882a593Smuzhiyun 				THIS_MODULE);
965*4882a593Smuzhiyun }
966*4882a593Smuzhiyun 
967*4882a593Smuzhiyun static struct usb_driver sd_driver = {
968*4882a593Smuzhiyun 	.name = MODULE_NAME,
969*4882a593Smuzhiyun 	.id_table = device_table,
970*4882a593Smuzhiyun 	.probe = sd_probe,
971*4882a593Smuzhiyun 	.disconnect = gspca_disconnect,
972*4882a593Smuzhiyun #ifdef CONFIG_PM
973*4882a593Smuzhiyun 	.suspend = gspca_suspend,
974*4882a593Smuzhiyun 	.resume = gspca_resume,
975*4882a593Smuzhiyun 	.reset_resume = gspca_resume,
976*4882a593Smuzhiyun #endif
977*4882a593Smuzhiyun };
978*4882a593Smuzhiyun 
979*4882a593Smuzhiyun module_usb_driver(sd_driver);
980