1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * T613 subdriver
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2010 Jean-Francois Moine (http://moinejf.free.fr)
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun *Notes: * t613 + tas5130A
8*4882a593Smuzhiyun * * Focus to light do not balance well as in win.
9*4882a593Smuzhiyun * Quality in win is not good, but its kinda better.
10*4882a593Smuzhiyun * * Fix some "extraneous bytes", most of apps will show the image anyway
11*4882a593Smuzhiyun * * Gamma table, is there, but its really doing something?
12*4882a593Smuzhiyun * * 7~8 Fps, its ok, max on win its 10.
13*4882a593Smuzhiyun * Costantino Leandro
14*4882a593Smuzhiyun */
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #define MODULE_NAME "t613"
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun #include <linux/input.h>
21*4882a593Smuzhiyun #include <linux/slab.h>
22*4882a593Smuzhiyun #include "gspca.h"
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun MODULE_AUTHOR("Leandro Costantino <le_costantino@pixartargentina.com.ar>");
25*4882a593Smuzhiyun MODULE_DESCRIPTION("GSPCA/T613 (JPEG Compliance) USB Camera Driver");
26*4882a593Smuzhiyun MODULE_LICENSE("GPL");
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun struct sd {
29*4882a593Smuzhiyun struct gspca_dev gspca_dev; /* !! must be the first item */
30*4882a593Smuzhiyun struct v4l2_ctrl *freq;
31*4882a593Smuzhiyun struct { /* awb / color gains control cluster */
32*4882a593Smuzhiyun struct v4l2_ctrl *awb;
33*4882a593Smuzhiyun struct v4l2_ctrl *gain;
34*4882a593Smuzhiyun struct v4l2_ctrl *red_balance;
35*4882a593Smuzhiyun struct v4l2_ctrl *blue_balance;
36*4882a593Smuzhiyun };
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun u8 sensor;
39*4882a593Smuzhiyun u8 button_pressed;
40*4882a593Smuzhiyun };
41*4882a593Smuzhiyun enum sensors {
42*4882a593Smuzhiyun SENSOR_OM6802,
43*4882a593Smuzhiyun SENSOR_OTHER,
44*4882a593Smuzhiyun SENSOR_TAS5130A,
45*4882a593Smuzhiyun SENSOR_LT168G, /* must verify if this is the actual model */
46*4882a593Smuzhiyun };
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun static const struct v4l2_pix_format vga_mode_t16[] = {
49*4882a593Smuzhiyun {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
50*4882a593Smuzhiyun .bytesperline = 160,
51*4882a593Smuzhiyun .sizeimage = 160 * 120 * 4 / 8 + 590,
52*4882a593Smuzhiyun .colorspace = V4L2_COLORSPACE_JPEG,
53*4882a593Smuzhiyun .priv = 4},
54*4882a593Smuzhiyun #if 0 /* HDG: broken with my test cam, so lets disable it */
55*4882a593Smuzhiyun {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
56*4882a593Smuzhiyun .bytesperline = 176,
57*4882a593Smuzhiyun .sizeimage = 176 * 144 * 3 / 8 + 590,
58*4882a593Smuzhiyun .colorspace = V4L2_COLORSPACE_JPEG,
59*4882a593Smuzhiyun .priv = 3},
60*4882a593Smuzhiyun #endif
61*4882a593Smuzhiyun {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
62*4882a593Smuzhiyun .bytesperline = 320,
63*4882a593Smuzhiyun .sizeimage = 320 * 240 * 3 / 8 + 590,
64*4882a593Smuzhiyun .colorspace = V4L2_COLORSPACE_JPEG,
65*4882a593Smuzhiyun .priv = 2},
66*4882a593Smuzhiyun #if 0 /* HDG: broken with my test cam, so lets disable it */
67*4882a593Smuzhiyun {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
68*4882a593Smuzhiyun .bytesperline = 352,
69*4882a593Smuzhiyun .sizeimage = 352 * 288 * 3 / 8 + 590,
70*4882a593Smuzhiyun .colorspace = V4L2_COLORSPACE_JPEG,
71*4882a593Smuzhiyun .priv = 1},
72*4882a593Smuzhiyun #endif
73*4882a593Smuzhiyun {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
74*4882a593Smuzhiyun .bytesperline = 640,
75*4882a593Smuzhiyun .sizeimage = 640 * 480 * 3 / 8 + 590,
76*4882a593Smuzhiyun .colorspace = V4L2_COLORSPACE_JPEG,
77*4882a593Smuzhiyun .priv = 0},
78*4882a593Smuzhiyun };
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun /* sensor specific data */
81*4882a593Smuzhiyun struct additional_sensor_data {
82*4882a593Smuzhiyun const u8 n3[6];
83*4882a593Smuzhiyun const u8 *n4, n4sz;
84*4882a593Smuzhiyun const u8 reg80, reg8e;
85*4882a593Smuzhiyun const u8 nset8[6];
86*4882a593Smuzhiyun const u8 data1[10];
87*4882a593Smuzhiyun const u8 data2[9];
88*4882a593Smuzhiyun const u8 data3[9];
89*4882a593Smuzhiyun const u8 data5[6];
90*4882a593Smuzhiyun const u8 stream[4];
91*4882a593Smuzhiyun };
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun static const u8 n4_om6802[] = {
94*4882a593Smuzhiyun 0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c,
95*4882a593Smuzhiyun 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68,
96*4882a593Smuzhiyun 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1,
97*4882a593Smuzhiyun 0xa2, 0x60, 0xa5, 0x30, 0xa6, 0x3a, 0xa8, 0xe8,
98*4882a593Smuzhiyun 0xae, 0x05, 0xb1, 0x00, 0xbb, 0x04, 0xbc, 0x48,
99*4882a593Smuzhiyun 0xbe, 0x36, 0xc6, 0x88, 0xe9, 0x00, 0xc5, 0xc0,
100*4882a593Smuzhiyun 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68,
101*4882a593Smuzhiyun 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40,
102*4882a593Smuzhiyun 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46
103*4882a593Smuzhiyun };
104*4882a593Smuzhiyun static const u8 n4_other[] = {
105*4882a593Smuzhiyun 0x66, 0x00, 0x7f, 0x00, 0x80, 0xac, 0x81, 0x69,
106*4882a593Smuzhiyun 0x84, 0x40, 0x85, 0x70, 0x86, 0x20, 0x8a, 0x68,
107*4882a593Smuzhiyun 0x8b, 0x58, 0x8c, 0x88, 0x8d, 0xff, 0x8e, 0xb8,
108*4882a593Smuzhiyun 0x8f, 0x28, 0xa2, 0x60, 0xa5, 0x40, 0xa8, 0xa8,
109*4882a593Smuzhiyun 0xac, 0x84, 0xad, 0x84, 0xae, 0x24, 0xaf, 0x56,
110*4882a593Smuzhiyun 0xb0, 0x68, 0xb1, 0x00, 0xb2, 0x88, 0xbb, 0xc5,
111*4882a593Smuzhiyun 0xbc, 0x4a, 0xbe, 0x36, 0xc2, 0x88, 0xc5, 0xc0,
112*4882a593Smuzhiyun 0xc6, 0xda, 0xe9, 0x26, 0xeb, 0x00
113*4882a593Smuzhiyun };
114*4882a593Smuzhiyun static const u8 n4_tas5130a[] = {
115*4882a593Smuzhiyun 0x80, 0x3c, 0x81, 0x68, 0x83, 0xa0, 0x84, 0x20,
116*4882a593Smuzhiyun 0x8a, 0x68, 0x8b, 0x58, 0x8c, 0x88, 0x8e, 0xb4,
117*4882a593Smuzhiyun 0x8f, 0x24, 0xa1, 0xb1, 0xa2, 0x30, 0xa5, 0x10,
118*4882a593Smuzhiyun 0xa6, 0x4a, 0xae, 0x03, 0xb1, 0x44, 0xb2, 0x08,
119*4882a593Smuzhiyun 0xb7, 0x06, 0xb9, 0xe7, 0xbb, 0xc4, 0xbc, 0x4a,
120*4882a593Smuzhiyun 0xbe, 0x36, 0xbf, 0xff, 0xc2, 0x88, 0xc5, 0xc8,
121*4882a593Smuzhiyun 0xc6, 0xda
122*4882a593Smuzhiyun };
123*4882a593Smuzhiyun static const u8 n4_lt168g[] = {
124*4882a593Smuzhiyun 0x66, 0x01, 0x7f, 0x00, 0x80, 0x7c, 0x81, 0x28,
125*4882a593Smuzhiyun 0x83, 0x44, 0x84, 0x20, 0x86, 0x20, 0x8a, 0x70,
126*4882a593Smuzhiyun 0x8b, 0x58, 0x8c, 0x88, 0x8d, 0xa0, 0x8e, 0xb3,
127*4882a593Smuzhiyun 0x8f, 0x24, 0xa1, 0xb0, 0xa2, 0x38, 0xa5, 0x20,
128*4882a593Smuzhiyun 0xa6, 0x4a, 0xa8, 0xe8, 0xaf, 0x38, 0xb0, 0x68,
129*4882a593Smuzhiyun 0xb1, 0x44, 0xb2, 0x88, 0xbb, 0x86, 0xbd, 0x40,
130*4882a593Smuzhiyun 0xbe, 0x26, 0xc1, 0x05, 0xc2, 0x88, 0xc5, 0xc0,
131*4882a593Smuzhiyun 0xda, 0x8e, 0xdb, 0xca, 0xdc, 0xa8, 0xdd, 0x8c,
132*4882a593Smuzhiyun 0xde, 0x44, 0xdf, 0x0c, 0xe9, 0x80
133*4882a593Smuzhiyun };
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun static const struct additional_sensor_data sensor_data[] = {
136*4882a593Smuzhiyun [SENSOR_OM6802] = {
137*4882a593Smuzhiyun .n3 =
138*4882a593Smuzhiyun {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04},
139*4882a593Smuzhiyun .n4 = n4_om6802,
140*4882a593Smuzhiyun .n4sz = sizeof n4_om6802,
141*4882a593Smuzhiyun .reg80 = 0x3c,
142*4882a593Smuzhiyun .reg8e = 0x33,
143*4882a593Smuzhiyun .nset8 = {0xa8, 0xf0, 0xc6, 0x88, 0xc0, 0x00},
144*4882a593Smuzhiyun .data1 =
145*4882a593Smuzhiyun {0xc2, 0x28, 0x0f, 0x22, 0xcd, 0x27, 0x2c, 0x06,
146*4882a593Smuzhiyun 0xb3, 0xfc},
147*4882a593Smuzhiyun .data2 =
148*4882a593Smuzhiyun {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff,
149*4882a593Smuzhiyun 0xff},
150*4882a593Smuzhiyun .data3 =
151*4882a593Smuzhiyun {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff,
152*4882a593Smuzhiyun 0xff},
153*4882a593Smuzhiyun .data5 = /* this could be removed later */
154*4882a593Smuzhiyun {0x0c, 0x03, 0xab, 0x13, 0x81, 0x23},
155*4882a593Smuzhiyun .stream =
156*4882a593Smuzhiyun {0x0b, 0x04, 0x0a, 0x78},
157*4882a593Smuzhiyun },
158*4882a593Smuzhiyun [SENSOR_OTHER] = {
159*4882a593Smuzhiyun .n3 =
160*4882a593Smuzhiyun {0x61, 0xc2, 0x65, 0x88, 0x60, 0x00},
161*4882a593Smuzhiyun .n4 = n4_other,
162*4882a593Smuzhiyun .n4sz = sizeof n4_other,
163*4882a593Smuzhiyun .reg80 = 0xac,
164*4882a593Smuzhiyun .reg8e = 0xb8,
165*4882a593Smuzhiyun .nset8 = {0xa8, 0xa8, 0xc6, 0xda, 0xc0, 0x00},
166*4882a593Smuzhiyun .data1 =
167*4882a593Smuzhiyun {0xc1, 0x48, 0x04, 0x1b, 0xca, 0x2e, 0x33, 0x3a,
168*4882a593Smuzhiyun 0xe8, 0xfc},
169*4882a593Smuzhiyun .data2 =
170*4882a593Smuzhiyun {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96,
171*4882a593Smuzhiyun 0xd9},
172*4882a593Smuzhiyun .data3 =
173*4882a593Smuzhiyun {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96,
174*4882a593Smuzhiyun 0xd9},
175*4882a593Smuzhiyun .data5 =
176*4882a593Smuzhiyun {0x0c, 0x03, 0xab, 0x29, 0x81, 0x69},
177*4882a593Smuzhiyun .stream =
178*4882a593Smuzhiyun {0x0b, 0x04, 0x0a, 0x00},
179*4882a593Smuzhiyun },
180*4882a593Smuzhiyun [SENSOR_TAS5130A] = {
181*4882a593Smuzhiyun .n3 =
182*4882a593Smuzhiyun {0x61, 0xc2, 0x65, 0x0d, 0x60, 0x08},
183*4882a593Smuzhiyun .n4 = n4_tas5130a,
184*4882a593Smuzhiyun .n4sz = sizeof n4_tas5130a,
185*4882a593Smuzhiyun .reg80 = 0x3c,
186*4882a593Smuzhiyun .reg8e = 0xb4,
187*4882a593Smuzhiyun .nset8 = {0xa8, 0xf0, 0xc6, 0xda, 0xc0, 0x00},
188*4882a593Smuzhiyun .data1 =
189*4882a593Smuzhiyun {0xbb, 0x28, 0x10, 0x10, 0xbb, 0x28, 0x1e, 0x27,
190*4882a593Smuzhiyun 0xc8, 0xfc},
191*4882a593Smuzhiyun .data2 =
192*4882a593Smuzhiyun {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8,
193*4882a593Smuzhiyun 0xe0},
194*4882a593Smuzhiyun .data3 =
195*4882a593Smuzhiyun {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8,
196*4882a593Smuzhiyun 0xe0},
197*4882a593Smuzhiyun .data5 =
198*4882a593Smuzhiyun {0x0c, 0x03, 0xab, 0x10, 0x81, 0x20},
199*4882a593Smuzhiyun .stream =
200*4882a593Smuzhiyun {0x0b, 0x04, 0x0a, 0x40},
201*4882a593Smuzhiyun },
202*4882a593Smuzhiyun [SENSOR_LT168G] = {
203*4882a593Smuzhiyun .n3 = {0x61, 0xc2, 0x65, 0x68, 0x60, 0x00},
204*4882a593Smuzhiyun .n4 = n4_lt168g,
205*4882a593Smuzhiyun .n4sz = sizeof n4_lt168g,
206*4882a593Smuzhiyun .reg80 = 0x7c,
207*4882a593Smuzhiyun .reg8e = 0xb3,
208*4882a593Smuzhiyun .nset8 = {0xa8, 0xf0, 0xc6, 0xba, 0xc0, 0x00},
209*4882a593Smuzhiyun .data1 = {0xc0, 0x38, 0x08, 0x10, 0xc0, 0x30, 0x10, 0x40,
210*4882a593Smuzhiyun 0xb0, 0xf4},
211*4882a593Smuzhiyun .data2 = {0x40, 0x80, 0xc0, 0x50, 0xa0, 0xf0, 0x53, 0xa6,
212*4882a593Smuzhiyun 0xff},
213*4882a593Smuzhiyun .data3 = {0x40, 0x80, 0xc0, 0x50, 0xa0, 0xf0, 0x53, 0xa6,
214*4882a593Smuzhiyun 0xff},
215*4882a593Smuzhiyun .data5 = {0x0c, 0x03, 0xab, 0x4b, 0x81, 0x2b},
216*4882a593Smuzhiyun .stream = {0x0b, 0x04, 0x0a, 0x28},
217*4882a593Smuzhiyun },
218*4882a593Smuzhiyun };
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun #define MAX_EFFECTS 7
221*4882a593Smuzhiyun static const u8 effects_table[MAX_EFFECTS][6] = {
222*4882a593Smuzhiyun {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x00}, /* Normal */
223*4882a593Smuzhiyun {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x04}, /* Repujar */
224*4882a593Smuzhiyun {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x20}, /* Monochrome */
225*4882a593Smuzhiyun {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x80}, /* Sepia */
226*4882a593Smuzhiyun {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x02}, /* Croquis */
227*4882a593Smuzhiyun {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x10}, /* Sun Effect */
228*4882a593Smuzhiyun {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x40}, /* Negative */
229*4882a593Smuzhiyun };
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun #define GAMMA_MAX (15)
232*4882a593Smuzhiyun static const u8 gamma_table[GAMMA_MAX+1][17] = {
233*4882a593Smuzhiyun /* gamma table from cam1690.ini */
234*4882a593Smuzhiyun {0x00, 0x00, 0x01, 0x04, 0x08, 0x0e, 0x16, 0x21, /* 0 */
235*4882a593Smuzhiyun 0x2e, 0x3d, 0x50, 0x65, 0x7d, 0x99, 0xb8, 0xdb,
236*4882a593Smuzhiyun 0xff},
237*4882a593Smuzhiyun {0x00, 0x01, 0x03, 0x08, 0x0e, 0x16, 0x21, 0x2d, /* 1 */
238*4882a593Smuzhiyun 0x3c, 0x4d, 0x60, 0x75, 0x8d, 0xa6, 0xc2, 0xe1,
239*4882a593Smuzhiyun 0xff},
240*4882a593Smuzhiyun {0x00, 0x01, 0x05, 0x0b, 0x12, 0x1c, 0x28, 0x35, /* 2 */
241*4882a593Smuzhiyun 0x45, 0x56, 0x69, 0x7e, 0x95, 0xad, 0xc7, 0xe3,
242*4882a593Smuzhiyun 0xff},
243*4882a593Smuzhiyun {0x00, 0x02, 0x07, 0x0f, 0x18, 0x24, 0x30, 0x3f, /* 3 */
244*4882a593Smuzhiyun 0x4f, 0x61, 0x73, 0x88, 0x9d, 0xb4, 0xcd, 0xe6,
245*4882a593Smuzhiyun 0xff},
246*4882a593Smuzhiyun {0x00, 0x04, 0x0b, 0x15, 0x20, 0x2d, 0x3b, 0x4a, /* 4 */
247*4882a593Smuzhiyun 0x5b, 0x6c, 0x7f, 0x92, 0xa7, 0xbc, 0xd2, 0xe9,
248*4882a593Smuzhiyun 0xff},
249*4882a593Smuzhiyun {0x00, 0x07, 0x11, 0x15, 0x20, 0x2d, 0x48, 0x58, /* 5 */
250*4882a593Smuzhiyun 0x68, 0x79, 0x8b, 0x9d, 0xb0, 0xc4, 0xd7, 0xec,
251*4882a593Smuzhiyun 0xff},
252*4882a593Smuzhiyun {0x00, 0x0c, 0x1a, 0x29, 0x38, 0x47, 0x57, 0x67, /* 6 */
253*4882a593Smuzhiyun 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
254*4882a593Smuzhiyun 0xff},
255*4882a593Smuzhiyun {0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, /* 7 */
256*4882a593Smuzhiyun 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0,
257*4882a593Smuzhiyun 0xff},
258*4882a593Smuzhiyun {0x00, 0x15, 0x27, 0x38, 0x49, 0x59, 0x69, 0x79, /* 8 */
259*4882a593Smuzhiyun 0x88, 0x97, 0xa7, 0xb6, 0xc4, 0xd3, 0xe2, 0xf0,
260*4882a593Smuzhiyun 0xff},
261*4882a593Smuzhiyun {0x00, 0x1c, 0x30, 0x43, 0x54, 0x65, 0x75, 0x84, /* 9 */
262*4882a593Smuzhiyun 0x93, 0xa1, 0xb0, 0xbd, 0xca, 0xd8, 0xe5, 0xf2,
263*4882a593Smuzhiyun 0xff},
264*4882a593Smuzhiyun {0x00, 0x24, 0x3b, 0x4f, 0x60, 0x70, 0x80, 0x8e, /* 10 */
265*4882a593Smuzhiyun 0x9c, 0xaa, 0xb7, 0xc4, 0xd0, 0xdc, 0xe8, 0xf3,
266*4882a593Smuzhiyun 0xff},
267*4882a593Smuzhiyun {0x00, 0x2a, 0x3c, 0x5d, 0x6e, 0x7e, 0x8d, 0x9b, /* 11 */
268*4882a593Smuzhiyun 0xa8, 0xb4, 0xc0, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5,
269*4882a593Smuzhiyun 0xff},
270*4882a593Smuzhiyun {0x00, 0x3f, 0x5a, 0x6e, 0x7f, 0x8e, 0x9c, 0xa8, /* 12 */
271*4882a593Smuzhiyun 0xb4, 0xbf, 0xc9, 0xd3, 0xdc, 0xe5, 0xee, 0xf6,
272*4882a593Smuzhiyun 0xff},
273*4882a593Smuzhiyun {0x00, 0x54, 0x6f, 0x83, 0x93, 0xa0, 0xad, 0xb7, /* 13 */
274*4882a593Smuzhiyun 0xc2, 0xcb, 0xd4, 0xdc, 0xe4, 0xeb, 0xf2, 0xf9,
275*4882a593Smuzhiyun 0xff},
276*4882a593Smuzhiyun {0x00, 0x6e, 0x88, 0x9a, 0xa8, 0xb3, 0xbd, 0xc6, /* 14 */
277*4882a593Smuzhiyun 0xcf, 0xd6, 0xdd, 0xe3, 0xe9, 0xef, 0xf4, 0xfa,
278*4882a593Smuzhiyun 0xff},
279*4882a593Smuzhiyun {0x00, 0x93, 0xa8, 0xb7, 0xc1, 0xca, 0xd2, 0xd8, /* 15 */
280*4882a593Smuzhiyun 0xde, 0xe3, 0xe8, 0xed, 0xf1, 0xf5, 0xf8, 0xfc,
281*4882a593Smuzhiyun 0xff}
282*4882a593Smuzhiyun };
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun static const u8 tas5130a_sensor_init[][8] = {
285*4882a593Smuzhiyun {0x62, 0x08, 0x63, 0x70, 0x64, 0x1d, 0x60, 0x09},
286*4882a593Smuzhiyun {0x62, 0x20, 0x63, 0x01, 0x64, 0x02, 0x60, 0x09},
287*4882a593Smuzhiyun {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09},
288*4882a593Smuzhiyun };
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun static u8 sensor_reset[] = {0x61, 0x68, 0x62, 0xff, 0x60, 0x07};
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun /* read 1 byte */
reg_r(struct gspca_dev * gspca_dev,u16 index)293*4882a593Smuzhiyun static u8 reg_r(struct gspca_dev *gspca_dev,
294*4882a593Smuzhiyun u16 index)
295*4882a593Smuzhiyun {
296*4882a593Smuzhiyun usb_control_msg(gspca_dev->dev,
297*4882a593Smuzhiyun usb_rcvctrlpipe(gspca_dev->dev, 0),
298*4882a593Smuzhiyun 0, /* request */
299*4882a593Smuzhiyun USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
300*4882a593Smuzhiyun 0, /* value */
301*4882a593Smuzhiyun index,
302*4882a593Smuzhiyun gspca_dev->usb_buf, 1, 500);
303*4882a593Smuzhiyun return gspca_dev->usb_buf[0];
304*4882a593Smuzhiyun }
305*4882a593Smuzhiyun
reg_w(struct gspca_dev * gspca_dev,u16 index)306*4882a593Smuzhiyun static void reg_w(struct gspca_dev *gspca_dev,
307*4882a593Smuzhiyun u16 index)
308*4882a593Smuzhiyun {
309*4882a593Smuzhiyun usb_control_msg(gspca_dev->dev,
310*4882a593Smuzhiyun usb_sndctrlpipe(gspca_dev->dev, 0),
311*4882a593Smuzhiyun 0,
312*4882a593Smuzhiyun USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
313*4882a593Smuzhiyun 0, index,
314*4882a593Smuzhiyun NULL, 0, 500);
315*4882a593Smuzhiyun }
316*4882a593Smuzhiyun
reg_w_buf(struct gspca_dev * gspca_dev,const u8 * buffer,u16 len)317*4882a593Smuzhiyun static void reg_w_buf(struct gspca_dev *gspca_dev,
318*4882a593Smuzhiyun const u8 *buffer, u16 len)
319*4882a593Smuzhiyun {
320*4882a593Smuzhiyun if (len <= USB_BUF_SZ) {
321*4882a593Smuzhiyun memcpy(gspca_dev->usb_buf, buffer, len);
322*4882a593Smuzhiyun usb_control_msg(gspca_dev->dev,
323*4882a593Smuzhiyun usb_sndctrlpipe(gspca_dev->dev, 0),
324*4882a593Smuzhiyun 0,
325*4882a593Smuzhiyun USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
326*4882a593Smuzhiyun 0x01, 0,
327*4882a593Smuzhiyun gspca_dev->usb_buf, len, 500);
328*4882a593Smuzhiyun } else {
329*4882a593Smuzhiyun u8 *tmpbuf;
330*4882a593Smuzhiyun
331*4882a593Smuzhiyun tmpbuf = kmemdup(buffer, len, GFP_KERNEL);
332*4882a593Smuzhiyun if (!tmpbuf) {
333*4882a593Smuzhiyun pr_err("Out of memory\n");
334*4882a593Smuzhiyun return;
335*4882a593Smuzhiyun }
336*4882a593Smuzhiyun usb_control_msg(gspca_dev->dev,
337*4882a593Smuzhiyun usb_sndctrlpipe(gspca_dev->dev, 0),
338*4882a593Smuzhiyun 0,
339*4882a593Smuzhiyun USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
340*4882a593Smuzhiyun 0x01, 0,
341*4882a593Smuzhiyun tmpbuf, len, 500);
342*4882a593Smuzhiyun kfree(tmpbuf);
343*4882a593Smuzhiyun }
344*4882a593Smuzhiyun }
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun /* write values to consecutive registers */
reg_w_ixbuf(struct gspca_dev * gspca_dev,u8 reg,const u8 * buffer,u16 len)347*4882a593Smuzhiyun static void reg_w_ixbuf(struct gspca_dev *gspca_dev,
348*4882a593Smuzhiyun u8 reg,
349*4882a593Smuzhiyun const u8 *buffer, u16 len)
350*4882a593Smuzhiyun {
351*4882a593Smuzhiyun int i;
352*4882a593Smuzhiyun u8 *p, *tmpbuf;
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun if (len * 2 <= USB_BUF_SZ) {
355*4882a593Smuzhiyun p = tmpbuf = gspca_dev->usb_buf;
356*4882a593Smuzhiyun } else {
357*4882a593Smuzhiyun p = tmpbuf = kmalloc_array(len, 2, GFP_KERNEL);
358*4882a593Smuzhiyun if (!tmpbuf) {
359*4882a593Smuzhiyun pr_err("Out of memory\n");
360*4882a593Smuzhiyun return;
361*4882a593Smuzhiyun }
362*4882a593Smuzhiyun }
363*4882a593Smuzhiyun i = len;
364*4882a593Smuzhiyun while (--i >= 0) {
365*4882a593Smuzhiyun *p++ = reg++;
366*4882a593Smuzhiyun *p++ = *buffer++;
367*4882a593Smuzhiyun }
368*4882a593Smuzhiyun usb_control_msg(gspca_dev->dev,
369*4882a593Smuzhiyun usb_sndctrlpipe(gspca_dev->dev, 0),
370*4882a593Smuzhiyun 0,
371*4882a593Smuzhiyun USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
372*4882a593Smuzhiyun 0x01, 0,
373*4882a593Smuzhiyun tmpbuf, len * 2, 500);
374*4882a593Smuzhiyun if (len * 2 > USB_BUF_SZ)
375*4882a593Smuzhiyun kfree(tmpbuf);
376*4882a593Smuzhiyun }
377*4882a593Smuzhiyun
om6802_sensor_init(struct gspca_dev * gspca_dev)378*4882a593Smuzhiyun static void om6802_sensor_init(struct gspca_dev *gspca_dev)
379*4882a593Smuzhiyun {
380*4882a593Smuzhiyun int i;
381*4882a593Smuzhiyun const u8 *p;
382*4882a593Smuzhiyun u8 byte;
383*4882a593Smuzhiyun u8 val[6] = {0x62, 0, 0x64, 0, 0x60, 0x05};
384*4882a593Smuzhiyun static const u8 sensor_init[] = {
385*4882a593Smuzhiyun 0xdf, 0x6d,
386*4882a593Smuzhiyun 0xdd, 0x18,
387*4882a593Smuzhiyun 0x5a, 0xe0,
388*4882a593Smuzhiyun 0x5c, 0x07,
389*4882a593Smuzhiyun 0x5d, 0xb0,
390*4882a593Smuzhiyun 0x5e, 0x1e,
391*4882a593Smuzhiyun 0x60, 0x71,
392*4882a593Smuzhiyun 0xef, 0x00,
393*4882a593Smuzhiyun 0xe9, 0x00,
394*4882a593Smuzhiyun 0xea, 0x00,
395*4882a593Smuzhiyun 0x90, 0x24,
396*4882a593Smuzhiyun 0x91, 0xb2,
397*4882a593Smuzhiyun 0x82, 0x32,
398*4882a593Smuzhiyun 0xfd, 0x41,
399*4882a593Smuzhiyun 0x00 /* table end */
400*4882a593Smuzhiyun };
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
403*4882a593Smuzhiyun msleep(100);
404*4882a593Smuzhiyun i = 4;
405*4882a593Smuzhiyun while (--i > 0) {
406*4882a593Smuzhiyun byte = reg_r(gspca_dev, 0x0060);
407*4882a593Smuzhiyun if (!(byte & 0x01))
408*4882a593Smuzhiyun break;
409*4882a593Smuzhiyun msleep(100);
410*4882a593Smuzhiyun }
411*4882a593Smuzhiyun byte = reg_r(gspca_dev, 0x0063);
412*4882a593Smuzhiyun if (byte != 0x17) {
413*4882a593Smuzhiyun pr_err("Bad sensor reset %02x\n", byte);
414*4882a593Smuzhiyun /* continue? */
415*4882a593Smuzhiyun }
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun p = sensor_init;
418*4882a593Smuzhiyun while (*p != 0) {
419*4882a593Smuzhiyun val[1] = *p++;
420*4882a593Smuzhiyun val[3] = *p++;
421*4882a593Smuzhiyun if (*p == 0)
422*4882a593Smuzhiyun reg_w(gspca_dev, 0x3c80);
423*4882a593Smuzhiyun reg_w_buf(gspca_dev, val, sizeof val);
424*4882a593Smuzhiyun i = 4;
425*4882a593Smuzhiyun while (--i >= 0) {
426*4882a593Smuzhiyun msleep(15);
427*4882a593Smuzhiyun byte = reg_r(gspca_dev, 0x60);
428*4882a593Smuzhiyun if (!(byte & 0x01))
429*4882a593Smuzhiyun break;
430*4882a593Smuzhiyun }
431*4882a593Smuzhiyun }
432*4882a593Smuzhiyun msleep(15);
433*4882a593Smuzhiyun reg_w(gspca_dev, 0x3c80);
434*4882a593Smuzhiyun }
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun /* this function is called at probe time */
sd_config(struct gspca_dev * gspca_dev,const struct usb_device_id * id)437*4882a593Smuzhiyun static int sd_config(struct gspca_dev *gspca_dev,
438*4882a593Smuzhiyun const struct usb_device_id *id)
439*4882a593Smuzhiyun {
440*4882a593Smuzhiyun struct cam *cam = &gspca_dev->cam;
441*4882a593Smuzhiyun
442*4882a593Smuzhiyun cam->cam_mode = vga_mode_t16;
443*4882a593Smuzhiyun cam->nmodes = ARRAY_SIZE(vga_mode_t16);
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun return 0;
446*4882a593Smuzhiyun }
447*4882a593Smuzhiyun
setbrightness(struct gspca_dev * gspca_dev,s32 brightness)448*4882a593Smuzhiyun static void setbrightness(struct gspca_dev *gspca_dev, s32 brightness)
449*4882a593Smuzhiyun {
450*4882a593Smuzhiyun u8 set6[4] = { 0x8f, 0x24, 0xc3, 0x00 };
451*4882a593Smuzhiyun
452*4882a593Smuzhiyun if (brightness < 7) {
453*4882a593Smuzhiyun set6[1] = 0x26;
454*4882a593Smuzhiyun set6[3] = 0x70 - brightness * 0x10;
455*4882a593Smuzhiyun } else {
456*4882a593Smuzhiyun set6[3] = 0x00 + ((brightness - 7) * 0x10);
457*4882a593Smuzhiyun }
458*4882a593Smuzhiyun
459*4882a593Smuzhiyun reg_w_buf(gspca_dev, set6, sizeof set6);
460*4882a593Smuzhiyun }
461*4882a593Smuzhiyun
setcontrast(struct gspca_dev * gspca_dev,s32 contrast)462*4882a593Smuzhiyun static void setcontrast(struct gspca_dev *gspca_dev, s32 contrast)
463*4882a593Smuzhiyun {
464*4882a593Smuzhiyun u16 reg_to_write;
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun if (contrast < 7)
467*4882a593Smuzhiyun reg_to_write = 0x8ea9 - contrast * 0x200;
468*4882a593Smuzhiyun else
469*4882a593Smuzhiyun reg_to_write = 0x00a9 + (contrast - 7) * 0x200;
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun reg_w(gspca_dev, reg_to_write);
472*4882a593Smuzhiyun }
473*4882a593Smuzhiyun
setcolors(struct gspca_dev * gspca_dev,s32 val)474*4882a593Smuzhiyun static void setcolors(struct gspca_dev *gspca_dev, s32 val)
475*4882a593Smuzhiyun {
476*4882a593Smuzhiyun u16 reg_to_write;
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun reg_to_write = 0x80bb + val * 0x100; /* was 0xc0 */
479*4882a593Smuzhiyun reg_w(gspca_dev, reg_to_write);
480*4882a593Smuzhiyun }
481*4882a593Smuzhiyun
setgamma(struct gspca_dev * gspca_dev,s32 val)482*4882a593Smuzhiyun static void setgamma(struct gspca_dev *gspca_dev, s32 val)
483*4882a593Smuzhiyun {
484*4882a593Smuzhiyun gspca_dbg(gspca_dev, D_CONF, "Gamma: %d\n", val);
485*4882a593Smuzhiyun reg_w_ixbuf(gspca_dev, 0x90,
486*4882a593Smuzhiyun gamma_table[val], sizeof gamma_table[0]);
487*4882a593Smuzhiyun }
488*4882a593Smuzhiyun
setawb_n_RGB(struct gspca_dev * gspca_dev)489*4882a593Smuzhiyun static void setawb_n_RGB(struct gspca_dev *gspca_dev)
490*4882a593Smuzhiyun {
491*4882a593Smuzhiyun struct sd *sd = (struct sd *) gspca_dev;
492*4882a593Smuzhiyun u8 all_gain_reg[8] = {
493*4882a593Smuzhiyun 0x87, 0x00, 0x88, 0x00, 0x89, 0x00, 0x80, 0x00 };
494*4882a593Smuzhiyun s32 red_gain, blue_gain, green_gain;
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun green_gain = sd->gain->val;
497*4882a593Smuzhiyun
498*4882a593Smuzhiyun red_gain = green_gain + sd->red_balance->val;
499*4882a593Smuzhiyun if (red_gain > 0x40)
500*4882a593Smuzhiyun red_gain = 0x40;
501*4882a593Smuzhiyun else if (red_gain < 0x10)
502*4882a593Smuzhiyun red_gain = 0x10;
503*4882a593Smuzhiyun
504*4882a593Smuzhiyun blue_gain = green_gain + sd->blue_balance->val;
505*4882a593Smuzhiyun if (blue_gain > 0x40)
506*4882a593Smuzhiyun blue_gain = 0x40;
507*4882a593Smuzhiyun else if (blue_gain < 0x10)
508*4882a593Smuzhiyun blue_gain = 0x10;
509*4882a593Smuzhiyun
510*4882a593Smuzhiyun all_gain_reg[1] = red_gain;
511*4882a593Smuzhiyun all_gain_reg[3] = blue_gain;
512*4882a593Smuzhiyun all_gain_reg[5] = green_gain;
513*4882a593Smuzhiyun all_gain_reg[7] = sensor_data[sd->sensor].reg80;
514*4882a593Smuzhiyun if (!sd->awb->val)
515*4882a593Smuzhiyun all_gain_reg[7] &= ~0x04; /* AWB off */
516*4882a593Smuzhiyun
517*4882a593Smuzhiyun reg_w_buf(gspca_dev, all_gain_reg, sizeof all_gain_reg);
518*4882a593Smuzhiyun }
519*4882a593Smuzhiyun
setsharpness(struct gspca_dev * gspca_dev,s32 val)520*4882a593Smuzhiyun static void setsharpness(struct gspca_dev *gspca_dev, s32 val)
521*4882a593Smuzhiyun {
522*4882a593Smuzhiyun u16 reg_to_write;
523*4882a593Smuzhiyun
524*4882a593Smuzhiyun reg_to_write = 0x0aa6 + 0x1000 * val;
525*4882a593Smuzhiyun
526*4882a593Smuzhiyun reg_w(gspca_dev, reg_to_write);
527*4882a593Smuzhiyun }
528*4882a593Smuzhiyun
setfreq(struct gspca_dev * gspca_dev,s32 val)529*4882a593Smuzhiyun static void setfreq(struct gspca_dev *gspca_dev, s32 val)
530*4882a593Smuzhiyun {
531*4882a593Smuzhiyun struct sd *sd = (struct sd *) gspca_dev;
532*4882a593Smuzhiyun u8 reg66;
533*4882a593Smuzhiyun u8 freq[4] = { 0x66, 0x00, 0xa8, 0xe8 };
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun switch (sd->sensor) {
536*4882a593Smuzhiyun case SENSOR_LT168G:
537*4882a593Smuzhiyun if (val != 0)
538*4882a593Smuzhiyun freq[3] = 0xa8;
539*4882a593Smuzhiyun reg66 = 0x41;
540*4882a593Smuzhiyun break;
541*4882a593Smuzhiyun case SENSOR_OM6802:
542*4882a593Smuzhiyun reg66 = 0xca;
543*4882a593Smuzhiyun break;
544*4882a593Smuzhiyun default:
545*4882a593Smuzhiyun reg66 = 0x40;
546*4882a593Smuzhiyun break;
547*4882a593Smuzhiyun }
548*4882a593Smuzhiyun switch (val) {
549*4882a593Smuzhiyun case 0: /* no flicker */
550*4882a593Smuzhiyun freq[3] = 0xf0;
551*4882a593Smuzhiyun break;
552*4882a593Smuzhiyun case 2: /* 60Hz */
553*4882a593Smuzhiyun reg66 &= ~0x40;
554*4882a593Smuzhiyun break;
555*4882a593Smuzhiyun }
556*4882a593Smuzhiyun freq[1] = reg66;
557*4882a593Smuzhiyun
558*4882a593Smuzhiyun reg_w_buf(gspca_dev, freq, sizeof freq);
559*4882a593Smuzhiyun }
560*4882a593Smuzhiyun
561*4882a593Smuzhiyun /* this function is called at probe and resume time */
sd_init(struct gspca_dev * gspca_dev)562*4882a593Smuzhiyun static int sd_init(struct gspca_dev *gspca_dev)
563*4882a593Smuzhiyun {
564*4882a593Smuzhiyun /* some of this registers are not really needed, because
565*4882a593Smuzhiyun * they are overridden by setbrigthness, setcontrast, etc.,
566*4882a593Smuzhiyun * but won't hurt anyway, and can help someone with similar webcam
567*4882a593Smuzhiyun * to see the initial parameters.*/
568*4882a593Smuzhiyun struct sd *sd = (struct sd *) gspca_dev;
569*4882a593Smuzhiyun const struct additional_sensor_data *sensor;
570*4882a593Smuzhiyun int i;
571*4882a593Smuzhiyun u16 sensor_id;
572*4882a593Smuzhiyun u8 test_byte = 0;
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun static const u8 read_indexs[] =
575*4882a593Smuzhiyun { 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5,
576*4882a593Smuzhiyun 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00 };
577*4882a593Smuzhiyun static const u8 n1[] =
578*4882a593Smuzhiyun {0x08, 0x03, 0x09, 0x03, 0x12, 0x04};
579*4882a593Smuzhiyun static const u8 n2[] =
580*4882a593Smuzhiyun {0x08, 0x00};
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun sensor_id = (reg_r(gspca_dev, 0x06) << 8)
583*4882a593Smuzhiyun | reg_r(gspca_dev, 0x07);
584*4882a593Smuzhiyun switch (sensor_id & 0xff0f) {
585*4882a593Smuzhiyun case 0x0801:
586*4882a593Smuzhiyun gspca_dbg(gspca_dev, D_PROBE, "sensor tas5130a\n");
587*4882a593Smuzhiyun sd->sensor = SENSOR_TAS5130A;
588*4882a593Smuzhiyun break;
589*4882a593Smuzhiyun case 0x0802:
590*4882a593Smuzhiyun gspca_dbg(gspca_dev, D_PROBE, "sensor lt168g\n");
591*4882a593Smuzhiyun sd->sensor = SENSOR_LT168G;
592*4882a593Smuzhiyun break;
593*4882a593Smuzhiyun case 0x0803:
594*4882a593Smuzhiyun gspca_dbg(gspca_dev, D_PROBE, "sensor 'other'\n");
595*4882a593Smuzhiyun sd->sensor = SENSOR_OTHER;
596*4882a593Smuzhiyun break;
597*4882a593Smuzhiyun case 0x0807:
598*4882a593Smuzhiyun gspca_dbg(gspca_dev, D_PROBE, "sensor om6802\n");
599*4882a593Smuzhiyun sd->sensor = SENSOR_OM6802;
600*4882a593Smuzhiyun break;
601*4882a593Smuzhiyun default:
602*4882a593Smuzhiyun pr_err("unknown sensor %04x\n", sensor_id);
603*4882a593Smuzhiyun return -EINVAL;
604*4882a593Smuzhiyun }
605*4882a593Smuzhiyun
606*4882a593Smuzhiyun if (sd->sensor == SENSOR_OM6802) {
607*4882a593Smuzhiyun reg_w_buf(gspca_dev, n1, sizeof n1);
608*4882a593Smuzhiyun i = 5;
609*4882a593Smuzhiyun while (--i >= 0) {
610*4882a593Smuzhiyun reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
611*4882a593Smuzhiyun test_byte = reg_r(gspca_dev, 0x0063);
612*4882a593Smuzhiyun msleep(100);
613*4882a593Smuzhiyun if (test_byte == 0x17)
614*4882a593Smuzhiyun break; /* OK */
615*4882a593Smuzhiyun }
616*4882a593Smuzhiyun if (i < 0) {
617*4882a593Smuzhiyun pr_err("Bad sensor reset %02x\n", test_byte);
618*4882a593Smuzhiyun return -EIO;
619*4882a593Smuzhiyun }
620*4882a593Smuzhiyun reg_w_buf(gspca_dev, n2, sizeof n2);
621*4882a593Smuzhiyun }
622*4882a593Smuzhiyun
623*4882a593Smuzhiyun i = 0;
624*4882a593Smuzhiyun while (read_indexs[i] != 0x00) {
625*4882a593Smuzhiyun test_byte = reg_r(gspca_dev, read_indexs[i]);
626*4882a593Smuzhiyun gspca_dbg(gspca_dev, D_STREAM, "Reg 0x%02x = 0x%02x\n",
627*4882a593Smuzhiyun read_indexs[i], test_byte);
628*4882a593Smuzhiyun i++;
629*4882a593Smuzhiyun }
630*4882a593Smuzhiyun
631*4882a593Smuzhiyun sensor = &sensor_data[sd->sensor];
632*4882a593Smuzhiyun reg_w_buf(gspca_dev, sensor->n3, sizeof sensor->n3);
633*4882a593Smuzhiyun reg_w_buf(gspca_dev, sensor->n4, sensor->n4sz);
634*4882a593Smuzhiyun
635*4882a593Smuzhiyun if (sd->sensor == SENSOR_LT168G) {
636*4882a593Smuzhiyun test_byte = reg_r(gspca_dev, 0x80);
637*4882a593Smuzhiyun gspca_dbg(gspca_dev, D_STREAM, "Reg 0x%02x = 0x%02x\n", 0x80,
638*4882a593Smuzhiyun test_byte);
639*4882a593Smuzhiyun reg_w(gspca_dev, 0x6c80);
640*4882a593Smuzhiyun }
641*4882a593Smuzhiyun
642*4882a593Smuzhiyun reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
643*4882a593Smuzhiyun reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
644*4882a593Smuzhiyun reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
645*4882a593Smuzhiyun
646*4882a593Smuzhiyun reg_w(gspca_dev, (sensor->reg80 << 8) + 0x80);
647*4882a593Smuzhiyun reg_w(gspca_dev, (sensor->reg80 << 8) + 0x80);
648*4882a593Smuzhiyun reg_w(gspca_dev, (sensor->reg8e << 8) + 0x8e);
649*4882a593Smuzhiyun reg_w(gspca_dev, (0x20 << 8) + 0x87);
650*4882a593Smuzhiyun reg_w(gspca_dev, (0x20 << 8) + 0x88);
651*4882a593Smuzhiyun reg_w(gspca_dev, (0x20 << 8) + 0x89);
652*4882a593Smuzhiyun
653*4882a593Smuzhiyun reg_w_buf(gspca_dev, sensor->data5, sizeof sensor->data5);
654*4882a593Smuzhiyun reg_w_buf(gspca_dev, sensor->nset8, sizeof sensor->nset8);
655*4882a593Smuzhiyun reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
656*4882a593Smuzhiyun
657*4882a593Smuzhiyun if (sd->sensor == SENSOR_LT168G) {
658*4882a593Smuzhiyun test_byte = reg_r(gspca_dev, 0x80);
659*4882a593Smuzhiyun gspca_dbg(gspca_dev, D_STREAM, "Reg 0x%02x = 0x%02x\n", 0x80,
660*4882a593Smuzhiyun test_byte);
661*4882a593Smuzhiyun reg_w(gspca_dev, 0x6c80);
662*4882a593Smuzhiyun }
663*4882a593Smuzhiyun
664*4882a593Smuzhiyun reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
665*4882a593Smuzhiyun reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
666*4882a593Smuzhiyun reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
667*4882a593Smuzhiyun
668*4882a593Smuzhiyun return 0;
669*4882a593Smuzhiyun }
670*4882a593Smuzhiyun
setmirror(struct gspca_dev * gspca_dev,s32 val)671*4882a593Smuzhiyun static void setmirror(struct gspca_dev *gspca_dev, s32 val)
672*4882a593Smuzhiyun {
673*4882a593Smuzhiyun u8 hflipcmd[8] =
674*4882a593Smuzhiyun {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09};
675*4882a593Smuzhiyun
676*4882a593Smuzhiyun if (val)
677*4882a593Smuzhiyun hflipcmd[3] = 0x01;
678*4882a593Smuzhiyun
679*4882a593Smuzhiyun reg_w_buf(gspca_dev, hflipcmd, sizeof hflipcmd);
680*4882a593Smuzhiyun }
681*4882a593Smuzhiyun
seteffect(struct gspca_dev * gspca_dev,s32 val)682*4882a593Smuzhiyun static void seteffect(struct gspca_dev *gspca_dev, s32 val)
683*4882a593Smuzhiyun {
684*4882a593Smuzhiyun int idx = 0;
685*4882a593Smuzhiyun
686*4882a593Smuzhiyun switch (val) {
687*4882a593Smuzhiyun case V4L2_COLORFX_NONE:
688*4882a593Smuzhiyun break;
689*4882a593Smuzhiyun case V4L2_COLORFX_BW:
690*4882a593Smuzhiyun idx = 2;
691*4882a593Smuzhiyun break;
692*4882a593Smuzhiyun case V4L2_COLORFX_SEPIA:
693*4882a593Smuzhiyun idx = 3;
694*4882a593Smuzhiyun break;
695*4882a593Smuzhiyun case V4L2_COLORFX_SKETCH:
696*4882a593Smuzhiyun idx = 4;
697*4882a593Smuzhiyun break;
698*4882a593Smuzhiyun case V4L2_COLORFX_NEGATIVE:
699*4882a593Smuzhiyun idx = 6;
700*4882a593Smuzhiyun break;
701*4882a593Smuzhiyun default:
702*4882a593Smuzhiyun break;
703*4882a593Smuzhiyun }
704*4882a593Smuzhiyun
705*4882a593Smuzhiyun reg_w_buf(gspca_dev, effects_table[idx],
706*4882a593Smuzhiyun sizeof effects_table[0]);
707*4882a593Smuzhiyun
708*4882a593Smuzhiyun if (val == V4L2_COLORFX_SKETCH)
709*4882a593Smuzhiyun reg_w(gspca_dev, 0x4aa6);
710*4882a593Smuzhiyun else
711*4882a593Smuzhiyun reg_w(gspca_dev, 0xfaa6);
712*4882a593Smuzhiyun }
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun /* Is this really needed?
715*4882a593Smuzhiyun * i added some module parameters for test with some users */
poll_sensor(struct gspca_dev * gspca_dev)716*4882a593Smuzhiyun static void poll_sensor(struct gspca_dev *gspca_dev)
717*4882a593Smuzhiyun {
718*4882a593Smuzhiyun static const u8 poll1[] =
719*4882a593Smuzhiyun {0x67, 0x05, 0x68, 0x81, 0x69, 0x80, 0x6a, 0x82,
720*4882a593Smuzhiyun 0x6b, 0x68, 0x6c, 0x69, 0x72, 0xd9, 0x73, 0x34,
721*4882a593Smuzhiyun 0x74, 0x32, 0x75, 0x92, 0x76, 0x00, 0x09, 0x01,
722*4882a593Smuzhiyun 0x60, 0x14};
723*4882a593Smuzhiyun static const u8 poll2[] =
724*4882a593Smuzhiyun {0x67, 0x02, 0x68, 0x71, 0x69, 0x72, 0x72, 0xa9,
725*4882a593Smuzhiyun 0x73, 0x02, 0x73, 0x02, 0x60, 0x14};
726*4882a593Smuzhiyun static const u8 noise03[] = /* (some differences / ms-drv) */
727*4882a593Smuzhiyun {0xa6, 0x0a, 0xea, 0xcf, 0xbe, 0x26, 0xb1, 0x5f,
728*4882a593Smuzhiyun 0xa1, 0xb1, 0xda, 0x6b, 0xdb, 0x98, 0xdf, 0x0c,
729*4882a593Smuzhiyun 0xc2, 0x80, 0xc3, 0x10};
730*4882a593Smuzhiyun
731*4882a593Smuzhiyun gspca_dbg(gspca_dev, D_STREAM, "[Sensor requires polling]\n");
732*4882a593Smuzhiyun reg_w_buf(gspca_dev, poll1, sizeof poll1);
733*4882a593Smuzhiyun reg_w_buf(gspca_dev, poll2, sizeof poll2);
734*4882a593Smuzhiyun reg_w_buf(gspca_dev, noise03, sizeof noise03);
735*4882a593Smuzhiyun }
736*4882a593Smuzhiyun
sd_start(struct gspca_dev * gspca_dev)737*4882a593Smuzhiyun static int sd_start(struct gspca_dev *gspca_dev)
738*4882a593Smuzhiyun {
739*4882a593Smuzhiyun struct sd *sd = (struct sd *) gspca_dev;
740*4882a593Smuzhiyun const struct additional_sensor_data *sensor;
741*4882a593Smuzhiyun int i, mode;
742*4882a593Smuzhiyun u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
743*4882a593Smuzhiyun static const u8 t3[] =
744*4882a593Smuzhiyun { 0x07, 0x00, 0x88, 0x02, 0x06, 0x00, 0xe7, 0x01 };
745*4882a593Smuzhiyun
746*4882a593Smuzhiyun mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
747*4882a593Smuzhiyun switch (mode) {
748*4882a593Smuzhiyun case 0: /* 640x480 (0x00) */
749*4882a593Smuzhiyun break;
750*4882a593Smuzhiyun case 1: /* 352x288 */
751*4882a593Smuzhiyun t2[1] = 0x40;
752*4882a593Smuzhiyun break;
753*4882a593Smuzhiyun case 2: /* 320x240 */
754*4882a593Smuzhiyun t2[1] = 0x10;
755*4882a593Smuzhiyun break;
756*4882a593Smuzhiyun case 3: /* 176x144 */
757*4882a593Smuzhiyun t2[1] = 0x50;
758*4882a593Smuzhiyun break;
759*4882a593Smuzhiyun default:
760*4882a593Smuzhiyun /* case 4: * 160x120 */
761*4882a593Smuzhiyun t2[1] = 0x20;
762*4882a593Smuzhiyun break;
763*4882a593Smuzhiyun }
764*4882a593Smuzhiyun
765*4882a593Smuzhiyun switch (sd->sensor) {
766*4882a593Smuzhiyun case SENSOR_OM6802:
767*4882a593Smuzhiyun om6802_sensor_init(gspca_dev);
768*4882a593Smuzhiyun break;
769*4882a593Smuzhiyun case SENSOR_TAS5130A:
770*4882a593Smuzhiyun i = 0;
771*4882a593Smuzhiyun for (;;) {
772*4882a593Smuzhiyun reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
773*4882a593Smuzhiyun sizeof tas5130a_sensor_init[0]);
774*4882a593Smuzhiyun if (i >= ARRAY_SIZE(tas5130a_sensor_init) - 1)
775*4882a593Smuzhiyun break;
776*4882a593Smuzhiyun i++;
777*4882a593Smuzhiyun }
778*4882a593Smuzhiyun reg_w(gspca_dev, 0x3c80);
779*4882a593Smuzhiyun /* just in case and to keep sync with logs (for mine) */
780*4882a593Smuzhiyun reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
781*4882a593Smuzhiyun sizeof tas5130a_sensor_init[0]);
782*4882a593Smuzhiyun reg_w(gspca_dev, 0x3c80);
783*4882a593Smuzhiyun break;
784*4882a593Smuzhiyun }
785*4882a593Smuzhiyun sensor = &sensor_data[sd->sensor];
786*4882a593Smuzhiyun setfreq(gspca_dev, v4l2_ctrl_g_ctrl(sd->freq));
787*4882a593Smuzhiyun reg_r(gspca_dev, 0x0012);
788*4882a593Smuzhiyun reg_w_buf(gspca_dev, t2, sizeof t2);
789*4882a593Smuzhiyun reg_w_ixbuf(gspca_dev, 0xb3, t3, sizeof t3);
790*4882a593Smuzhiyun reg_w(gspca_dev, 0x0013);
791*4882a593Smuzhiyun msleep(15);
792*4882a593Smuzhiyun reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
793*4882a593Smuzhiyun reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
794*4882a593Smuzhiyun
795*4882a593Smuzhiyun if (sd->sensor == SENSOR_OM6802)
796*4882a593Smuzhiyun poll_sensor(gspca_dev);
797*4882a593Smuzhiyun
798*4882a593Smuzhiyun return 0;
799*4882a593Smuzhiyun }
800*4882a593Smuzhiyun
sd_stopN(struct gspca_dev * gspca_dev)801*4882a593Smuzhiyun static void sd_stopN(struct gspca_dev *gspca_dev)
802*4882a593Smuzhiyun {
803*4882a593Smuzhiyun struct sd *sd = (struct sd *) gspca_dev;
804*4882a593Smuzhiyun
805*4882a593Smuzhiyun reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
806*4882a593Smuzhiyun sizeof sensor_data[sd->sensor].stream);
807*4882a593Smuzhiyun reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
808*4882a593Smuzhiyun sizeof sensor_data[sd->sensor].stream);
809*4882a593Smuzhiyun if (sd->sensor == SENSOR_OM6802) {
810*4882a593Smuzhiyun msleep(20);
811*4882a593Smuzhiyun reg_w(gspca_dev, 0x0309);
812*4882a593Smuzhiyun }
813*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_INPUT)
814*4882a593Smuzhiyun /* If the last button state is pressed, release it now! */
815*4882a593Smuzhiyun if (sd->button_pressed) {
816*4882a593Smuzhiyun input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
817*4882a593Smuzhiyun input_sync(gspca_dev->input_dev);
818*4882a593Smuzhiyun sd->button_pressed = 0;
819*4882a593Smuzhiyun }
820*4882a593Smuzhiyun #endif
821*4882a593Smuzhiyun }
822*4882a593Smuzhiyun
sd_pkt_scan(struct gspca_dev * gspca_dev,u8 * data,int len)823*4882a593Smuzhiyun static void sd_pkt_scan(struct gspca_dev *gspca_dev,
824*4882a593Smuzhiyun u8 *data, /* isoc packet */
825*4882a593Smuzhiyun int len) /* iso packet length */
826*4882a593Smuzhiyun {
827*4882a593Smuzhiyun struct sd *sd __maybe_unused = (struct sd *) gspca_dev;
828*4882a593Smuzhiyun int pkt_type;
829*4882a593Smuzhiyun
830*4882a593Smuzhiyun if (data[0] == 0x5a) {
831*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_INPUT)
832*4882a593Smuzhiyun if (len > 20) {
833*4882a593Smuzhiyun u8 state = (data[20] & 0x80) ? 1 : 0;
834*4882a593Smuzhiyun if (sd->button_pressed != state) {
835*4882a593Smuzhiyun input_report_key(gspca_dev->input_dev,
836*4882a593Smuzhiyun KEY_CAMERA, state);
837*4882a593Smuzhiyun input_sync(gspca_dev->input_dev);
838*4882a593Smuzhiyun sd->button_pressed = state;
839*4882a593Smuzhiyun }
840*4882a593Smuzhiyun }
841*4882a593Smuzhiyun #endif
842*4882a593Smuzhiyun /* Control Packet, after this came the header again,
843*4882a593Smuzhiyun * but extra bytes came in the packet before this,
844*4882a593Smuzhiyun * sometimes an EOF arrives, sometimes not... */
845*4882a593Smuzhiyun return;
846*4882a593Smuzhiyun }
847*4882a593Smuzhiyun data += 2;
848*4882a593Smuzhiyun len -= 2;
849*4882a593Smuzhiyun if (data[0] == 0xff && data[1] == 0xd8)
850*4882a593Smuzhiyun pkt_type = FIRST_PACKET;
851*4882a593Smuzhiyun else if (data[len - 2] == 0xff && data[len - 1] == 0xd9)
852*4882a593Smuzhiyun pkt_type = LAST_PACKET;
853*4882a593Smuzhiyun else
854*4882a593Smuzhiyun pkt_type = INTER_PACKET;
855*4882a593Smuzhiyun gspca_frame_add(gspca_dev, pkt_type, data, len);
856*4882a593Smuzhiyun }
857*4882a593Smuzhiyun
sd_g_volatile_ctrl(struct v4l2_ctrl * ctrl)858*4882a593Smuzhiyun static int sd_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
859*4882a593Smuzhiyun {
860*4882a593Smuzhiyun struct gspca_dev *gspca_dev =
861*4882a593Smuzhiyun container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
862*4882a593Smuzhiyun struct sd *sd = (struct sd *)gspca_dev;
863*4882a593Smuzhiyun s32 red_gain, blue_gain, green_gain;
864*4882a593Smuzhiyun
865*4882a593Smuzhiyun gspca_dev->usb_err = 0;
866*4882a593Smuzhiyun
867*4882a593Smuzhiyun switch (ctrl->id) {
868*4882a593Smuzhiyun case V4L2_CID_AUTO_WHITE_BALANCE:
869*4882a593Smuzhiyun red_gain = reg_r(gspca_dev, 0x0087);
870*4882a593Smuzhiyun if (red_gain > 0x40)
871*4882a593Smuzhiyun red_gain = 0x40;
872*4882a593Smuzhiyun else if (red_gain < 0x10)
873*4882a593Smuzhiyun red_gain = 0x10;
874*4882a593Smuzhiyun
875*4882a593Smuzhiyun blue_gain = reg_r(gspca_dev, 0x0088);
876*4882a593Smuzhiyun if (blue_gain > 0x40)
877*4882a593Smuzhiyun blue_gain = 0x40;
878*4882a593Smuzhiyun else if (blue_gain < 0x10)
879*4882a593Smuzhiyun blue_gain = 0x10;
880*4882a593Smuzhiyun
881*4882a593Smuzhiyun green_gain = reg_r(gspca_dev, 0x0089);
882*4882a593Smuzhiyun if (green_gain > 0x40)
883*4882a593Smuzhiyun green_gain = 0x40;
884*4882a593Smuzhiyun else if (green_gain < 0x10)
885*4882a593Smuzhiyun green_gain = 0x10;
886*4882a593Smuzhiyun
887*4882a593Smuzhiyun sd->gain->val = green_gain;
888*4882a593Smuzhiyun sd->red_balance->val = red_gain - green_gain;
889*4882a593Smuzhiyun sd->blue_balance->val = blue_gain - green_gain;
890*4882a593Smuzhiyun break;
891*4882a593Smuzhiyun }
892*4882a593Smuzhiyun return 0;
893*4882a593Smuzhiyun }
894*4882a593Smuzhiyun
sd_s_ctrl(struct v4l2_ctrl * ctrl)895*4882a593Smuzhiyun static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
896*4882a593Smuzhiyun {
897*4882a593Smuzhiyun struct gspca_dev *gspca_dev =
898*4882a593Smuzhiyun container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
899*4882a593Smuzhiyun
900*4882a593Smuzhiyun gspca_dev->usb_err = 0;
901*4882a593Smuzhiyun
902*4882a593Smuzhiyun if (!gspca_dev->streaming)
903*4882a593Smuzhiyun return 0;
904*4882a593Smuzhiyun
905*4882a593Smuzhiyun switch (ctrl->id) {
906*4882a593Smuzhiyun case V4L2_CID_BRIGHTNESS:
907*4882a593Smuzhiyun setbrightness(gspca_dev, ctrl->val);
908*4882a593Smuzhiyun break;
909*4882a593Smuzhiyun case V4L2_CID_CONTRAST:
910*4882a593Smuzhiyun setcontrast(gspca_dev, ctrl->val);
911*4882a593Smuzhiyun break;
912*4882a593Smuzhiyun case V4L2_CID_SATURATION:
913*4882a593Smuzhiyun setcolors(gspca_dev, ctrl->val);
914*4882a593Smuzhiyun break;
915*4882a593Smuzhiyun case V4L2_CID_GAMMA:
916*4882a593Smuzhiyun setgamma(gspca_dev, ctrl->val);
917*4882a593Smuzhiyun break;
918*4882a593Smuzhiyun case V4L2_CID_HFLIP:
919*4882a593Smuzhiyun setmirror(gspca_dev, ctrl->val);
920*4882a593Smuzhiyun break;
921*4882a593Smuzhiyun case V4L2_CID_SHARPNESS:
922*4882a593Smuzhiyun setsharpness(gspca_dev, ctrl->val);
923*4882a593Smuzhiyun break;
924*4882a593Smuzhiyun case V4L2_CID_POWER_LINE_FREQUENCY:
925*4882a593Smuzhiyun setfreq(gspca_dev, ctrl->val);
926*4882a593Smuzhiyun break;
927*4882a593Smuzhiyun case V4L2_CID_BACKLIGHT_COMPENSATION:
928*4882a593Smuzhiyun reg_w(gspca_dev, ctrl->val ? 0xf48e : 0xb48e);
929*4882a593Smuzhiyun break;
930*4882a593Smuzhiyun case V4L2_CID_AUTO_WHITE_BALANCE:
931*4882a593Smuzhiyun setawb_n_RGB(gspca_dev);
932*4882a593Smuzhiyun break;
933*4882a593Smuzhiyun case V4L2_CID_COLORFX:
934*4882a593Smuzhiyun seteffect(gspca_dev, ctrl->val);
935*4882a593Smuzhiyun break;
936*4882a593Smuzhiyun }
937*4882a593Smuzhiyun return gspca_dev->usb_err;
938*4882a593Smuzhiyun }
939*4882a593Smuzhiyun
940*4882a593Smuzhiyun static const struct v4l2_ctrl_ops sd_ctrl_ops = {
941*4882a593Smuzhiyun .g_volatile_ctrl = sd_g_volatile_ctrl,
942*4882a593Smuzhiyun .s_ctrl = sd_s_ctrl,
943*4882a593Smuzhiyun };
944*4882a593Smuzhiyun
sd_init_controls(struct gspca_dev * gspca_dev)945*4882a593Smuzhiyun static int sd_init_controls(struct gspca_dev *gspca_dev)
946*4882a593Smuzhiyun {
947*4882a593Smuzhiyun struct sd *sd = (struct sd *)gspca_dev;
948*4882a593Smuzhiyun struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
949*4882a593Smuzhiyun
950*4882a593Smuzhiyun gspca_dev->vdev.ctrl_handler = hdl;
951*4882a593Smuzhiyun v4l2_ctrl_handler_init(hdl, 12);
952*4882a593Smuzhiyun v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
953*4882a593Smuzhiyun V4L2_CID_BRIGHTNESS, 0, 14, 1, 8);
954*4882a593Smuzhiyun v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
955*4882a593Smuzhiyun V4L2_CID_CONTRAST, 0, 0x0d, 1, 7);
956*4882a593Smuzhiyun v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
957*4882a593Smuzhiyun V4L2_CID_SATURATION, 0, 0xf, 1, 5);
958*4882a593Smuzhiyun v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
959*4882a593Smuzhiyun V4L2_CID_GAMMA, 0, GAMMA_MAX, 1, 10);
960*4882a593Smuzhiyun /* Activate lowlight, some apps don't bring up the
961*4882a593Smuzhiyun backlight_compensation control) */
962*4882a593Smuzhiyun v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
963*4882a593Smuzhiyun V4L2_CID_BACKLIGHT_COMPENSATION, 0, 1, 1, 1);
964*4882a593Smuzhiyun if (sd->sensor == SENSOR_TAS5130A)
965*4882a593Smuzhiyun v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
966*4882a593Smuzhiyun V4L2_CID_HFLIP, 0, 1, 1, 0);
967*4882a593Smuzhiyun sd->awb = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
968*4882a593Smuzhiyun V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
969*4882a593Smuzhiyun sd->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
970*4882a593Smuzhiyun V4L2_CID_GAIN, 0x10, 0x40, 1, 0x20);
971*4882a593Smuzhiyun sd->blue_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
972*4882a593Smuzhiyun V4L2_CID_BLUE_BALANCE, -0x30, 0x30, 1, 0);
973*4882a593Smuzhiyun sd->red_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
974*4882a593Smuzhiyun V4L2_CID_RED_BALANCE, -0x30, 0x30, 1, 0);
975*4882a593Smuzhiyun v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
976*4882a593Smuzhiyun V4L2_CID_SHARPNESS, 0, 15, 1, 6);
977*4882a593Smuzhiyun v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
978*4882a593Smuzhiyun V4L2_CID_COLORFX, V4L2_COLORFX_SKETCH,
979*4882a593Smuzhiyun ~((1 << V4L2_COLORFX_NONE) |
980*4882a593Smuzhiyun (1 << V4L2_COLORFX_BW) |
981*4882a593Smuzhiyun (1 << V4L2_COLORFX_SEPIA) |
982*4882a593Smuzhiyun (1 << V4L2_COLORFX_SKETCH) |
983*4882a593Smuzhiyun (1 << V4L2_COLORFX_NEGATIVE)),
984*4882a593Smuzhiyun V4L2_COLORFX_NONE);
985*4882a593Smuzhiyun sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
986*4882a593Smuzhiyun V4L2_CID_POWER_LINE_FREQUENCY,
987*4882a593Smuzhiyun V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 1,
988*4882a593Smuzhiyun V4L2_CID_POWER_LINE_FREQUENCY_50HZ);
989*4882a593Smuzhiyun
990*4882a593Smuzhiyun if (hdl->error) {
991*4882a593Smuzhiyun pr_err("Could not initialize controls\n");
992*4882a593Smuzhiyun return hdl->error;
993*4882a593Smuzhiyun }
994*4882a593Smuzhiyun
995*4882a593Smuzhiyun v4l2_ctrl_auto_cluster(4, &sd->awb, 0, true);
996*4882a593Smuzhiyun
997*4882a593Smuzhiyun return 0;
998*4882a593Smuzhiyun }
999*4882a593Smuzhiyun
1000*4882a593Smuzhiyun /* sub-driver description */
1001*4882a593Smuzhiyun static const struct sd_desc sd_desc = {
1002*4882a593Smuzhiyun .name = MODULE_NAME,
1003*4882a593Smuzhiyun .config = sd_config,
1004*4882a593Smuzhiyun .init = sd_init,
1005*4882a593Smuzhiyun .init_controls = sd_init_controls,
1006*4882a593Smuzhiyun .start = sd_start,
1007*4882a593Smuzhiyun .stopN = sd_stopN,
1008*4882a593Smuzhiyun .pkt_scan = sd_pkt_scan,
1009*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_INPUT)
1010*4882a593Smuzhiyun .other_input = 1,
1011*4882a593Smuzhiyun #endif
1012*4882a593Smuzhiyun };
1013*4882a593Smuzhiyun
1014*4882a593Smuzhiyun /* -- module initialisation -- */
1015*4882a593Smuzhiyun static const struct usb_device_id device_table[] = {
1016*4882a593Smuzhiyun {USB_DEVICE(0x17a1, 0x0128)},
1017*4882a593Smuzhiyun {}
1018*4882a593Smuzhiyun };
1019*4882a593Smuzhiyun MODULE_DEVICE_TABLE(usb, device_table);
1020*4882a593Smuzhiyun
1021*4882a593Smuzhiyun /* -- device connect -- */
sd_probe(struct usb_interface * intf,const struct usb_device_id * id)1022*4882a593Smuzhiyun static int sd_probe(struct usb_interface *intf,
1023*4882a593Smuzhiyun const struct usb_device_id *id)
1024*4882a593Smuzhiyun {
1025*4882a593Smuzhiyun return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1026*4882a593Smuzhiyun THIS_MODULE);
1027*4882a593Smuzhiyun }
1028*4882a593Smuzhiyun
1029*4882a593Smuzhiyun static struct usb_driver sd_driver = {
1030*4882a593Smuzhiyun .name = MODULE_NAME,
1031*4882a593Smuzhiyun .id_table = device_table,
1032*4882a593Smuzhiyun .probe = sd_probe,
1033*4882a593Smuzhiyun .disconnect = gspca_disconnect,
1034*4882a593Smuzhiyun #ifdef CONFIG_PM
1035*4882a593Smuzhiyun .suspend = gspca_suspend,
1036*4882a593Smuzhiyun .resume = gspca_resume,
1037*4882a593Smuzhiyun .reset_resume = gspca_resume,
1038*4882a593Smuzhiyun #endif
1039*4882a593Smuzhiyun };
1040*4882a593Smuzhiyun
1041*4882a593Smuzhiyun module_usb_driver(sd_driver);
1042