xref: /openbmc/linux/drivers/media/usb/gspca/gl860/gl860-mi1320.c (revision 0c0d06cac63ee327ceaab4b5ffe2206574ab86bd)
1*0c0d06caSMauro Carvalho Chehab /* Subdriver for the GL860 chip with the MI1320 sensor
2*0c0d06caSMauro Carvalho Chehab  * Author Olivier LORIN from own logs
3*0c0d06caSMauro Carvalho Chehab  *
4*0c0d06caSMauro Carvalho Chehab  * This program is free software; you can redistribute it and/or modify
5*0c0d06caSMauro Carvalho Chehab  * it under the terms of the GNU General Public License as published by
6*0c0d06caSMauro Carvalho Chehab  * the Free Software Foundation; either version 2 of the License, or
7*0c0d06caSMauro Carvalho Chehab  * any later version.
8*0c0d06caSMauro Carvalho Chehab  *
9*0c0d06caSMauro Carvalho Chehab  * This program is distributed in the hope that it will be useful,
10*0c0d06caSMauro Carvalho Chehab  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*0c0d06caSMauro Carvalho Chehab  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*0c0d06caSMauro Carvalho Chehab  * GNU General Public License for more details.
13*0c0d06caSMauro Carvalho Chehab  *
14*0c0d06caSMauro Carvalho Chehab  * You should have received a copy of the GNU General Public License
15*0c0d06caSMauro Carvalho Chehab  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16*0c0d06caSMauro Carvalho Chehab  */
17*0c0d06caSMauro Carvalho Chehab 
18*0c0d06caSMauro Carvalho Chehab /* Sensor : MI1320 */
19*0c0d06caSMauro Carvalho Chehab 
20*0c0d06caSMauro Carvalho Chehab #include "gl860.h"
21*0c0d06caSMauro Carvalho Chehab 
22*0c0d06caSMauro Carvalho Chehab static struct validx tbl_common[] = {
23*0c0d06caSMauro Carvalho Chehab 	{0xba00, 0x00f0}, {0xba00, 0x00f1}, {0xba51, 0x0066}, {0xba02, 0x00f1},
24*0c0d06caSMauro Carvalho Chehab 	{0xba05, 0x0067}, {0xba05, 0x00f1}, {0xbaa0, 0x0065}, {0xba00, 0x00f1},
25*0c0d06caSMauro Carvalho Chehab 	{0xffff, 0xffff},
26*0c0d06caSMauro Carvalho Chehab 	{0xba00, 0x00f0}, {0xba02, 0x00f1}, {0xbafa, 0x0028}, {0xba02, 0x00f1},
27*0c0d06caSMauro Carvalho Chehab 	{0xba00, 0x00f0}, {0xba01, 0x00f1}, {0xbaf0, 0x0006}, {0xba0e, 0x00f1},
28*0c0d06caSMauro Carvalho Chehab 	{0xba70, 0x0006}, {0xba0e, 0x00f1},
29*0c0d06caSMauro Carvalho Chehab 	{0xffff, 0xffff},
30*0c0d06caSMauro Carvalho Chehab 	{0xba74, 0x0006}, {0xba0e, 0x00f1},
31*0c0d06caSMauro Carvalho Chehab 	{0xffff, 0xffff},
32*0c0d06caSMauro Carvalho Chehab 	{0x0061, 0x0000}, {0x0068, 0x000d},
33*0c0d06caSMauro Carvalho Chehab };
34*0c0d06caSMauro Carvalho Chehab 
35*0c0d06caSMauro Carvalho Chehab static struct validx tbl_init_at_startup[] = {
36*0c0d06caSMauro Carvalho Chehab 	{0x0000, 0x0000}, {0x0010, 0x0010},
37*0c0d06caSMauro Carvalho Chehab 	{35, 0xffff},
38*0c0d06caSMauro Carvalho Chehab 	{0x0008, 0x00c0}, {0x0001, 0x00c1}, {0x0001, 0x00c2}, {0x0020, 0x0006},
39*0c0d06caSMauro Carvalho Chehab 	{0x006a, 0x000d},
40*0c0d06caSMauro Carvalho Chehab };
41*0c0d06caSMauro Carvalho Chehab 
42*0c0d06caSMauro Carvalho Chehab static struct validx tbl_sensor_settings_common[] = {
43*0c0d06caSMauro Carvalho Chehab 	{0x0010, 0x0010}, {0x0003, 0x00c1}, {0x0042, 0x00c2}, {0x0040, 0x0000},
44*0c0d06caSMauro Carvalho Chehab 	{0x006a, 0x0007}, {0x006a, 0x000d}, {0x0063, 0x0006},
45*0c0d06caSMauro Carvalho Chehab };
46*0c0d06caSMauro Carvalho Chehab static struct validx tbl_sensor_settings_1280[] = {
47*0c0d06caSMauro Carvalho Chehab 	{0xba00, 0x00f0}, {0xba00, 0x00f1}, {0xba5a, 0x0066}, {0xba02, 0x00f1},
48*0c0d06caSMauro Carvalho Chehab 	{0xba05, 0x0067}, {0xba05, 0x00f1}, {0xba20, 0x0065}, {0xba00, 0x00f1},
49*0c0d06caSMauro Carvalho Chehab };
50*0c0d06caSMauro Carvalho Chehab static struct validx tbl_sensor_settings_800[] = {
51*0c0d06caSMauro Carvalho Chehab 	{0xba00, 0x00f0}, {0xba00, 0x00f1}, {0xba5a, 0x0066}, {0xba02, 0x00f1},
52*0c0d06caSMauro Carvalho Chehab 	{0xba05, 0x0067}, {0xba05, 0x00f1}, {0xba20, 0x0065}, {0xba00, 0x00f1},
53*0c0d06caSMauro Carvalho Chehab };
54*0c0d06caSMauro Carvalho Chehab static struct validx tbl_sensor_settings_640[] = {
55*0c0d06caSMauro Carvalho Chehab 	{0xba00, 0x00f0}, {0xba00, 0x00f1}, {0xbaa0, 0x0065}, {0xba00, 0x00f1},
56*0c0d06caSMauro Carvalho Chehab 	{0xba51, 0x0066}, {0xba02, 0x00f1}, {0xba05, 0x0067}, {0xba05, 0x00f1},
57*0c0d06caSMauro Carvalho Chehab 	{0xba20, 0x0065}, {0xba00, 0x00f1},
58*0c0d06caSMauro Carvalho Chehab };
59*0c0d06caSMauro Carvalho Chehab static struct validx tbl_post_unset_alt[] = {
60*0c0d06caSMauro Carvalho Chehab 	{0xba00, 0x00f0}, {0xba00, 0x00f1}, {0xbaa0, 0x0065}, {0xba00, 0x00f1},
61*0c0d06caSMauro Carvalho Chehab 	{0x0061, 0x0000}, {0x0068, 0x000d},
62*0c0d06caSMauro Carvalho Chehab };
63*0c0d06caSMauro Carvalho Chehab 
64*0c0d06caSMauro Carvalho Chehab static u8 *tbl_1280[] = {
65*0c0d06caSMauro Carvalho Chehab 	"\x0d\x80\xf1\x08\x03\x04\xf1\x00" "\x04\x05\xf1\x02\x05\x00\xf1\xf1"
66*0c0d06caSMauro Carvalho Chehab 	"\x06\x00\xf1\x0d\x20\x01\xf1\x00" "\x21\x84\xf1\x00\x0d\x00\xf1\x08"
67*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x01\x34\x00\xf1\x00" "\x9b\x43\xf1\x00\xa6\x05\xf1\x00"
68*0c0d06caSMauro Carvalho Chehab 	"\xa9\x04\xf1\x00\xa1\x05\xf1\x00" "\xa4\x04\xf1\x00\xae\x0a\xf1\x08"
69*0c0d06caSMauro Carvalho Chehab 	,
70*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x02\x3a\x05\xf1\xf1" "\x3c\x05\xf1\xf1\x59\x01\xf1\x47"
71*0c0d06caSMauro Carvalho Chehab 	"\x5a\x01\xf1\x88\x5c\x0a\xf1\x06" "\x5d\x0e\xf1\x0a\x64\x5e\xf1\x1c"
72*0c0d06caSMauro Carvalho Chehab 	"\xd2\x00\xf1\xcf\xcb\x00\xf1\x01"
73*0c0d06caSMauro Carvalho Chehab 	,
74*0c0d06caSMauro Carvalho Chehab 	"\xd3\x02\xd4\x28\xd5\x01\xd0\x02" "\xd1\x18\xd2\xc1"
75*0c0d06caSMauro Carvalho Chehab };
76*0c0d06caSMauro Carvalho Chehab 
77*0c0d06caSMauro Carvalho Chehab static u8 *tbl_800[] = {
78*0c0d06caSMauro Carvalho Chehab 	"\x0d\x80\xf1\x08\x03\x03\xf1\xc0" "\x04\x05\xf1\x02\x05\x00\xf1\xf1"
79*0c0d06caSMauro Carvalho Chehab 	"\x06\x00\xf1\x0d\x20\x01\xf1\x00" "\x21\x84\xf1\x00\x0d\x00\xf1\x08"
80*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x01\x34\x00\xf1\x00" "\x9b\x43\xf1\x00\xa6\x05\xf1\x00"
81*0c0d06caSMauro Carvalho Chehab 	"\xa9\x03\xf1\xc0\xa1\x03\xf1\x20" "\xa4\x02\xf1\x5a\xae\x0a\xf1\x08"
82*0c0d06caSMauro Carvalho Chehab 	,
83*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x02\x3a\x05\xf1\xf1" "\x3c\x05\xf1\xf1\x59\x01\xf1\x47"
84*0c0d06caSMauro Carvalho Chehab 	"\x5a\x01\xf1\x88\x5c\x0a\xf1\x06" "\x5d\x0e\xf1\x0a\x64\x5e\xf1\x1c"
85*0c0d06caSMauro Carvalho Chehab 	"\xd2\x00\xf1\xcf\xcb\x00\xf1\x01"
86*0c0d06caSMauro Carvalho Chehab 	,
87*0c0d06caSMauro Carvalho Chehab 	"\xd3\x02\xd4\x18\xd5\x21\xd0\x02" "\xd1\x10\xd2\x59"
88*0c0d06caSMauro Carvalho Chehab };
89*0c0d06caSMauro Carvalho Chehab 
90*0c0d06caSMauro Carvalho Chehab static u8 *tbl_640[] = {
91*0c0d06caSMauro Carvalho Chehab 	"\x0d\x80\xf1\x08\x03\x04\xf1\x04" "\x04\x05\xf1\x02\x07\x01\xf1\x7c"
92*0c0d06caSMauro Carvalho Chehab 	"\x08\x00\xf1\x0e\x21\x80\xf1\x00" "\x0d\x00\xf1\x08\xf0\x00\xf1\x01"
93*0c0d06caSMauro Carvalho Chehab 	"\x34\x10\xf1\x10\x3a\x43\xf1\x00" "\xa6\x05\xf1\x02\xa9\x04\xf1\x04"
94*0c0d06caSMauro Carvalho Chehab 	"\xa7\x02\xf1\x81\xaa\x01\xf1\xe2" "\xae\x0c\xf1\x09"
95*0c0d06caSMauro Carvalho Chehab 	,
96*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x02\x39\x03\xf1\xfc" "\x3b\x04\xf1\x04\x57\x01\xf1\xb6"
97*0c0d06caSMauro Carvalho Chehab 	"\x58\x02\xf1\x0d\x5c\x1f\xf1\x19" "\x5d\x24\xf1\x1e\x64\x5e\xf1\x1c"
98*0c0d06caSMauro Carvalho Chehab 	"\xd2\x00\xf1\x00\xcb\x00\xf1\x01"
99*0c0d06caSMauro Carvalho Chehab 	,
100*0c0d06caSMauro Carvalho Chehab 	"\xd3\x02\xd4\x10\xd5\x81\xd0\x02" "\xd1\x08\xd2\xe1"
101*0c0d06caSMauro Carvalho Chehab };
102*0c0d06caSMauro Carvalho Chehab 
103*0c0d06caSMauro Carvalho Chehab static s32 tbl_sat[] = {0x25, 0x1d, 0x15, 0x0d, 0x05, 0x4d, 0x55, 0x5d, 0x2d};
104*0c0d06caSMauro Carvalho Chehab static s32 tbl_bright[] = {0, 8, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70};
105*0c0d06caSMauro Carvalho Chehab static s32 tbl_backlight[] = {0x0e, 0x06, 0x02};
106*0c0d06caSMauro Carvalho Chehab 
107*0c0d06caSMauro Carvalho Chehab static s32 tbl_cntr1[] = {
108*0c0d06caSMauro Carvalho Chehab 	0x90, 0x98, 0xa0, 0xa8, 0xb0, 0xb8, 0xc0, 0xc8, 0xd0, 0xe0, 0xf0};
109*0c0d06caSMauro Carvalho Chehab static s32 tbl_cntr2[] = {
110*0c0d06caSMauro Carvalho Chehab 	0x70, 0x68, 0x60, 0x58, 0x50, 0x48, 0x40, 0x38, 0x30, 0x20, 0x10};
111*0c0d06caSMauro Carvalho Chehab 
112*0c0d06caSMauro Carvalho Chehab static u8 dat_wbalNL[] =
113*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x01\x05\x00\xf1\x06" "\x3b\x04\xf1\x2a\x47\x10\xf1\x10"
114*0c0d06caSMauro Carvalho Chehab 	"\x9d\x3c\xf1\xae\xaf\x10\xf1\x00" "\xf0\x00\xf1\x02\x2f\x91\xf1\x20"
115*0c0d06caSMauro Carvalho Chehab 	"\x9c\x91\xf1\x20\x37\x03\xf1\x00" "\x9d\xc5\xf1\x0f\xf0\x00\xf1\x00";
116*0c0d06caSMauro Carvalho Chehab 
117*0c0d06caSMauro Carvalho Chehab static u8 dat_wbalLL[] =
118*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x01\x05\x00\xf1\x0c" "\x3b\x04\xf1\x2a\x47\x40\xf1\x40"
119*0c0d06caSMauro Carvalho Chehab 	"\x9d\x20\xf1\xae\xaf\x10\xf1\x00" "\xf0\x00\xf1\x02\x2f\xd1\xf1\x00"
120*0c0d06caSMauro Carvalho Chehab 	"\x9c\xd1\xf1\x00\x37\x03\xf1\x00" "\x9d\xc5\xf1\x3f\xf0\x00\xf1\x00";
121*0c0d06caSMauro Carvalho Chehab 
122*0c0d06caSMauro Carvalho Chehab static u8 dat_wbalBL[] =
123*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x01\x05\x00\xf1\x06" "\x47\x10\xf1\x30\x9d\x3c\xf1\xae"
124*0c0d06caSMauro Carvalho Chehab 	"\xaf\x10\xf1\x00\xf0\x00\xf1\x02" "\x2f\x91\xf1\x20\x9c\x91\xf1\x20"
125*0c0d06caSMauro Carvalho Chehab 	"\x37\x03\xf1\x00\x9d\xc5\xf1\x2f" "\xf0\x00\xf1\x00";
126*0c0d06caSMauro Carvalho Chehab 
127*0c0d06caSMauro Carvalho Chehab static u8 dat_hvflip1[] = {0xf0, 0x00, 0xf1, 0x00};
128*0c0d06caSMauro Carvalho Chehab 
129*0c0d06caSMauro Carvalho Chehab static u8 dat_common00[] =
130*0c0d06caSMauro Carvalho Chehab 	"\x00\x01\x07\x6a\x06\x63\x0d\x6a" "\xc0\x00\x10\x10\xc1\x03\xc2\x42"
131*0c0d06caSMauro Carvalho Chehab 	"\xd8\x04\x58\x00\x04\x02";
132*0c0d06caSMauro Carvalho Chehab static u8 dat_common01[] =
133*0c0d06caSMauro Carvalho Chehab 	"\x0d\x00\xf1\x0b\x0d\x00\xf1\x08" "\x35\x00\xf1\x22\x68\x00\xf1\x5d"
134*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x01\x06\x70\xf1\x0e" "\xf0\x00\xf1\x02\xdd\x18\xf1\xe0";
135*0c0d06caSMauro Carvalho Chehab static u8 dat_common02[] =
136*0c0d06caSMauro Carvalho Chehab 	"\x05\x01\xf1\x84\x06\x00\xf1\x44" "\x07\x00\xf1\xbe\x08\x00\xf1\x1e"
137*0c0d06caSMauro Carvalho Chehab 	"\x20\x01\xf1\x03\x21\x84\xf1\x00" "\x22\x0d\xf1\x0f\x24\x80\xf1\x00"
138*0c0d06caSMauro Carvalho Chehab 	"\x34\x18\xf1\x2d\x35\x00\xf1\x22" "\x43\x83\xf1\x83\x59\x00\xf1\xff";
139*0c0d06caSMauro Carvalho Chehab static u8 dat_common03[] =
140*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x02\x39\x06\xf1\x8c" "\x3a\x06\xf1\x8c\x3b\x03\xf1\xda"
141*0c0d06caSMauro Carvalho Chehab 	"\x3c\x05\xf1\x30\x57\x01\xf1\x0c" "\x58\x01\xf1\x42\x59\x01\xf1\x0c"
142*0c0d06caSMauro Carvalho Chehab 	"\x5a\x01\xf1\x42\x5c\x13\xf1\x0e" "\x5d\x17\xf1\x12\x64\x1e\xf1\x1c";
143*0c0d06caSMauro Carvalho Chehab static u8 dat_common04[] =
144*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x02\x24\x5f\xf1\x20" "\x28\xea\xf1\x02\x5f\x41\xf1\x43";
145*0c0d06caSMauro Carvalho Chehab static u8 dat_common05[] =
146*0c0d06caSMauro Carvalho Chehab 	"\x02\x00\xf1\xee\x03\x29\xf1\x1a" "\x04\x02\xf1\xa4\x09\x00\xf1\x68"
147*0c0d06caSMauro Carvalho Chehab 	"\x0a\x00\xf1\x2a\x0b\x00\xf1\x04" "\x0c\x00\xf1\x93\x0d\x00\xf1\x82"
148*0c0d06caSMauro Carvalho Chehab 	"\x0e\x00\xf1\x40\x0f\x00\xf1\x5f" "\x10\x00\xf1\x4e\x11\x00\xf1\x5b";
149*0c0d06caSMauro Carvalho Chehab static u8 dat_common06[] =
150*0c0d06caSMauro Carvalho Chehab 	"\x15\x00\xf1\xc9\x16\x00\xf1\x5e" "\x17\x00\xf1\x9d\x18\x00\xf1\x06"
151*0c0d06caSMauro Carvalho Chehab 	"\x19\x00\xf1\x89\x1a\x00\xf1\x12" "\x1b\x00\xf1\xa1\x1c\x00\xf1\xe4"
152*0c0d06caSMauro Carvalho Chehab 	"\x1d\x00\xf1\x7a\x1e\x00\xf1\x64" "\xf6\x00\xf1\x5f";
153*0c0d06caSMauro Carvalho Chehab static u8 dat_common07[] =
154*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x01\x53\x09\xf1\x03" "\x54\x3d\xf1\x1c\x55\x99\xf1\x72"
155*0c0d06caSMauro Carvalho Chehab 	"\x56\xc1\xf1\xb1\x57\xd8\xf1\xce" "\x58\xe0\xf1\x00\xdc\x0a\xf1\x03"
156*0c0d06caSMauro Carvalho Chehab 	"\xdd\x45\xf1\x20\xde\xae\xf1\x82" "\xdf\xdc\xf1\xc9\xe0\xf6\xf1\xea"
157*0c0d06caSMauro Carvalho Chehab 	"\xe1\xff\xf1\x00";
158*0c0d06caSMauro Carvalho Chehab static u8 dat_common08[] =
159*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x01\x80\x00\xf1\x06" "\x81\xf6\xf1\x08\x82\xfb\xf1\xf7"
160*0c0d06caSMauro Carvalho Chehab 	"\x83\x00\xf1\xfe\xb6\x07\xf1\x03" "\xb7\x18\xf1\x0c\x84\xfb\xf1\x06"
161*0c0d06caSMauro Carvalho Chehab 	"\x85\xfb\xf1\xf9\x86\x00\xf1\xff" "\xb8\x07\xf1\x04\xb9\x16\xf1\x0a";
162*0c0d06caSMauro Carvalho Chehab static u8 dat_common09[] =
163*0c0d06caSMauro Carvalho Chehab 	"\x87\xfa\xf1\x05\x88\xfc\xf1\xf9" "\x89\x00\xf1\xff\xba\x06\xf1\x03"
164*0c0d06caSMauro Carvalho Chehab 	"\xbb\x17\xf1\x09\x8a\xe8\xf1\x14" "\x8b\xf7\xf1\xf0\x8c\xfd\xf1\xfa"
165*0c0d06caSMauro Carvalho Chehab 	"\x8d\x00\xf1\x00\xbc\x05\xf1\x01" "\xbd\x0c\xf1\x08\xbe\x00\xf1\x14";
166*0c0d06caSMauro Carvalho Chehab static u8 dat_common10[] =
167*0c0d06caSMauro Carvalho Chehab 	"\x8e\xea\xf1\x13\x8f\xf7\xf1\xf2" "\x90\xfd\xf1\xfa\x91\x00\xf1\x00"
168*0c0d06caSMauro Carvalho Chehab 	"\xbf\x05\xf1\x01\xc0\x0a\xf1\x08" "\xc1\x00\xf1\x0c\x92\xed\xf1\x0f"
169*0c0d06caSMauro Carvalho Chehab 	"\x93\xf9\xf1\xf4\x94\xfe\xf1\xfb" "\x95\x00\xf1\x00\xc2\x04\xf1\x01"
170*0c0d06caSMauro Carvalho Chehab 	"\xc3\x0a\xf1\x07\xc4\x00\xf1\x10";
171*0c0d06caSMauro Carvalho Chehab static u8 dat_common11[] =
172*0c0d06caSMauro Carvalho Chehab 	"\xf0\x00\xf1\x01\x05\x00\xf1\x06" "\x25\x00\xf1\x55\x34\x10\xf1\x10"
173*0c0d06caSMauro Carvalho Chehab 	"\x35\xf0\xf1\x10\x3a\x02\xf1\x03" "\x3b\x04\xf1\x2a\x9b\x43\xf1\x00"
174*0c0d06caSMauro Carvalho Chehab 	"\xa4\x03\xf1\xc0\xa7\x02\xf1\x81";
175*0c0d06caSMauro Carvalho Chehab 
176*0c0d06caSMauro Carvalho Chehab static int  mi1320_init_at_startup(struct gspca_dev *gspca_dev);
177*0c0d06caSMauro Carvalho Chehab static int  mi1320_configure_alt(struct gspca_dev *gspca_dev);
178*0c0d06caSMauro Carvalho Chehab static int  mi1320_init_pre_alt(struct gspca_dev *gspca_dev);
179*0c0d06caSMauro Carvalho Chehab static int  mi1320_init_post_alt(struct gspca_dev *gspca_dev);
180*0c0d06caSMauro Carvalho Chehab static void mi1320_post_unset_alt(struct gspca_dev *gspca_dev);
181*0c0d06caSMauro Carvalho Chehab static int  mi1320_sensor_settings(struct gspca_dev *gspca_dev);
182*0c0d06caSMauro Carvalho Chehab static int  mi1320_camera_settings(struct gspca_dev *gspca_dev);
183*0c0d06caSMauro Carvalho Chehab /*==========================================================================*/
184*0c0d06caSMauro Carvalho Chehab 
185*0c0d06caSMauro Carvalho Chehab void mi1320_init_settings(struct gspca_dev *gspca_dev)
186*0c0d06caSMauro Carvalho Chehab {
187*0c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
188*0c0d06caSMauro Carvalho Chehab 
189*0c0d06caSMauro Carvalho Chehab 	sd->vcur.backlight  =  0;
190*0c0d06caSMauro Carvalho Chehab 	sd->vcur.brightness =  0;
191*0c0d06caSMauro Carvalho Chehab 	sd->vcur.sharpness  =  6;
192*0c0d06caSMauro Carvalho Chehab 	sd->vcur.contrast   = 10;
193*0c0d06caSMauro Carvalho Chehab 	sd->vcur.gamma      = 20;
194*0c0d06caSMauro Carvalho Chehab 	sd->vcur.hue        =  0;
195*0c0d06caSMauro Carvalho Chehab 	sd->vcur.saturation =  6;
196*0c0d06caSMauro Carvalho Chehab 	sd->vcur.whitebal   =  0;
197*0c0d06caSMauro Carvalho Chehab 	sd->vcur.mirror     = 0;
198*0c0d06caSMauro Carvalho Chehab 	sd->vcur.flip       = 0;
199*0c0d06caSMauro Carvalho Chehab 	sd->vcur.AC50Hz     = 1;
200*0c0d06caSMauro Carvalho Chehab 
201*0c0d06caSMauro Carvalho Chehab 	sd->vmax.backlight  =  2;
202*0c0d06caSMauro Carvalho Chehab 	sd->vmax.brightness =  8;
203*0c0d06caSMauro Carvalho Chehab 	sd->vmax.sharpness  =  7;
204*0c0d06caSMauro Carvalho Chehab 	sd->vmax.contrast   =  0; /* 10 but not working with this driver */
205*0c0d06caSMauro Carvalho Chehab 	sd->vmax.gamma      = 40;
206*0c0d06caSMauro Carvalho Chehab 	sd->vmax.hue        =  5 + 1;
207*0c0d06caSMauro Carvalho Chehab 	sd->vmax.saturation =  8;
208*0c0d06caSMauro Carvalho Chehab 	sd->vmax.whitebal   =  2;
209*0c0d06caSMauro Carvalho Chehab 	sd->vmax.mirror     = 1;
210*0c0d06caSMauro Carvalho Chehab 	sd->vmax.flip       = 1;
211*0c0d06caSMauro Carvalho Chehab 	sd->vmax.AC50Hz     = 1;
212*0c0d06caSMauro Carvalho Chehab 
213*0c0d06caSMauro Carvalho Chehab 	sd->dev_camera_settings = mi1320_camera_settings;
214*0c0d06caSMauro Carvalho Chehab 	sd->dev_init_at_startup = mi1320_init_at_startup;
215*0c0d06caSMauro Carvalho Chehab 	sd->dev_configure_alt   = mi1320_configure_alt;
216*0c0d06caSMauro Carvalho Chehab 	sd->dev_init_pre_alt    = mi1320_init_pre_alt;
217*0c0d06caSMauro Carvalho Chehab 	sd->dev_post_unset_alt  = mi1320_post_unset_alt;
218*0c0d06caSMauro Carvalho Chehab }
219*0c0d06caSMauro Carvalho Chehab 
220*0c0d06caSMauro Carvalho Chehab /*==========================================================================*/
221*0c0d06caSMauro Carvalho Chehab 
222*0c0d06caSMauro Carvalho Chehab static void common(struct gspca_dev *gspca_dev)
223*0c0d06caSMauro Carvalho Chehab {
224*0c0d06caSMauro Carvalho Chehab 	s32 n; /* reserved for FETCH functions */
225*0c0d06caSMauro Carvalho Chehab 
226*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 22, dat_common00);
227*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x0000, 0, NULL);
228*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 32, dat_common01);
229*0c0d06caSMauro Carvalho Chehab 	n = fetch_validx(gspca_dev, tbl_common, ARRAY_SIZE(tbl_common));
230*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 48, dat_common02);
231*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 48, dat_common03);
232*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 16, dat_common04);
233*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 48, dat_common05);
234*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 44, dat_common06);
235*0c0d06caSMauro Carvalho Chehab 	keep_on_fetching_validx(gspca_dev, tbl_common,
236*0c0d06caSMauro Carvalho Chehab 					ARRAY_SIZE(tbl_common), n);
237*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 52, dat_common07);
238*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 48, dat_common08);
239*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 48, dat_common09);
240*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 56, dat_common10);
241*0c0d06caSMauro Carvalho Chehab 	keep_on_fetching_validx(gspca_dev, tbl_common,
242*0c0d06caSMauro Carvalho Chehab 					ARRAY_SIZE(tbl_common), n);
243*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 40, dat_common11);
244*0c0d06caSMauro Carvalho Chehab 	keep_on_fetching_validx(gspca_dev, tbl_common,
245*0c0d06caSMauro Carvalho Chehab 					ARRAY_SIZE(tbl_common), n);
246*0c0d06caSMauro Carvalho Chehab }
247*0c0d06caSMauro Carvalho Chehab 
248*0c0d06caSMauro Carvalho Chehab static int mi1320_init_at_startup(struct gspca_dev *gspca_dev)
249*0c0d06caSMauro Carvalho Chehab {
250*0c0d06caSMauro Carvalho Chehab 	fetch_validx(gspca_dev, tbl_init_at_startup,
251*0c0d06caSMauro Carvalho Chehab 				ARRAY_SIZE(tbl_init_at_startup));
252*0c0d06caSMauro Carvalho Chehab 
253*0c0d06caSMauro Carvalho Chehab 	common(gspca_dev);
254*0c0d06caSMauro Carvalho Chehab 
255*0c0d06caSMauro Carvalho Chehab /*	ctrl_out(gspca_dev, 0x40, 11, 0x0000, 0x0000, 0, NULL); */
256*0c0d06caSMauro Carvalho Chehab 
257*0c0d06caSMauro Carvalho Chehab 	return 0;
258*0c0d06caSMauro Carvalho Chehab }
259*0c0d06caSMauro Carvalho Chehab 
260*0c0d06caSMauro Carvalho Chehab static int mi1320_init_pre_alt(struct gspca_dev *gspca_dev)
261*0c0d06caSMauro Carvalho Chehab {
262*0c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
263*0c0d06caSMauro Carvalho Chehab 
264*0c0d06caSMauro Carvalho Chehab 	sd->mirrorMask = 0;
265*0c0d06caSMauro Carvalho Chehab 
266*0c0d06caSMauro Carvalho Chehab 	sd->vold.backlight  = -1;
267*0c0d06caSMauro Carvalho Chehab 	sd->vold.brightness = -1;
268*0c0d06caSMauro Carvalho Chehab 	sd->vold.sharpness  = -1;
269*0c0d06caSMauro Carvalho Chehab 	sd->vold.contrast   = -1;
270*0c0d06caSMauro Carvalho Chehab 	sd->vold.saturation = -1;
271*0c0d06caSMauro Carvalho Chehab 	sd->vold.gamma    = -1;
272*0c0d06caSMauro Carvalho Chehab 	sd->vold.hue      = -1;
273*0c0d06caSMauro Carvalho Chehab 	sd->vold.whitebal = -1;
274*0c0d06caSMauro Carvalho Chehab 	sd->vold.mirror   = -1;
275*0c0d06caSMauro Carvalho Chehab 	sd->vold.flip     = -1;
276*0c0d06caSMauro Carvalho Chehab 	sd->vold.AC50Hz   = -1;
277*0c0d06caSMauro Carvalho Chehab 
278*0c0d06caSMauro Carvalho Chehab 	common(gspca_dev);
279*0c0d06caSMauro Carvalho Chehab 
280*0c0d06caSMauro Carvalho Chehab 	mi1320_sensor_settings(gspca_dev);
281*0c0d06caSMauro Carvalho Chehab 
282*0c0d06caSMauro Carvalho Chehab 	mi1320_init_post_alt(gspca_dev);
283*0c0d06caSMauro Carvalho Chehab 
284*0c0d06caSMauro Carvalho Chehab 	return 0;
285*0c0d06caSMauro Carvalho Chehab }
286*0c0d06caSMauro Carvalho Chehab 
287*0c0d06caSMauro Carvalho Chehab static int mi1320_init_post_alt(struct gspca_dev *gspca_dev)
288*0c0d06caSMauro Carvalho Chehab {
289*0c0d06caSMauro Carvalho Chehab 	mi1320_camera_settings(gspca_dev);
290*0c0d06caSMauro Carvalho Chehab 
291*0c0d06caSMauro Carvalho Chehab 	return 0;
292*0c0d06caSMauro Carvalho Chehab }
293*0c0d06caSMauro Carvalho Chehab 
294*0c0d06caSMauro Carvalho Chehab static int mi1320_sensor_settings(struct gspca_dev *gspca_dev)
295*0c0d06caSMauro Carvalho Chehab {
296*0c0d06caSMauro Carvalho Chehab 	s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
297*0c0d06caSMauro Carvalho Chehab 
298*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 5, 0x0001, 0x0000, 0, NULL);
299*0c0d06caSMauro Carvalho Chehab 
300*0c0d06caSMauro Carvalho Chehab 	fetch_validx(gspca_dev, tbl_sensor_settings_common,
301*0c0d06caSMauro Carvalho Chehab 				ARRAY_SIZE(tbl_sensor_settings_common));
302*0c0d06caSMauro Carvalho Chehab 
303*0c0d06caSMauro Carvalho Chehab 	switch (reso) {
304*0c0d06caSMauro Carvalho Chehab 	case IMAGE_1280:
305*0c0d06caSMauro Carvalho Chehab 		fetch_validx(gspca_dev, tbl_sensor_settings_1280,
306*0c0d06caSMauro Carvalho Chehab 					ARRAY_SIZE(tbl_sensor_settings_1280));
307*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 64, tbl_1280[0]);
308*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 40, tbl_1280[1]);
309*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, tbl_1280[2]);
310*0c0d06caSMauro Carvalho Chehab 		break;
311*0c0d06caSMauro Carvalho Chehab 
312*0c0d06caSMauro Carvalho Chehab 	case IMAGE_800:
313*0c0d06caSMauro Carvalho Chehab 		fetch_validx(gspca_dev, tbl_sensor_settings_800,
314*0c0d06caSMauro Carvalho Chehab 					ARRAY_SIZE(tbl_sensor_settings_800));
315*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 64, tbl_800[0]);
316*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 40, tbl_800[1]);
317*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, tbl_800[2]);
318*0c0d06caSMauro Carvalho Chehab 		break;
319*0c0d06caSMauro Carvalho Chehab 
320*0c0d06caSMauro Carvalho Chehab 	default:
321*0c0d06caSMauro Carvalho Chehab 		fetch_validx(gspca_dev, tbl_sensor_settings_640,
322*0c0d06caSMauro Carvalho Chehab 					ARRAY_SIZE(tbl_sensor_settings_640));
323*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 60, tbl_640[0]);
324*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 40, tbl_640[1]);
325*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, tbl_640[2]);
326*0c0d06caSMauro Carvalho Chehab 		break;
327*0c0d06caSMauro Carvalho Chehab 	}
328*0c0d06caSMauro Carvalho Chehab 	return 0;
329*0c0d06caSMauro Carvalho Chehab }
330*0c0d06caSMauro Carvalho Chehab 
331*0c0d06caSMauro Carvalho Chehab static int mi1320_configure_alt(struct gspca_dev *gspca_dev)
332*0c0d06caSMauro Carvalho Chehab {
333*0c0d06caSMauro Carvalho Chehab 	s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
334*0c0d06caSMauro Carvalho Chehab 
335*0c0d06caSMauro Carvalho Chehab 	switch (reso) {
336*0c0d06caSMauro Carvalho Chehab 	case IMAGE_640:
337*0c0d06caSMauro Carvalho Chehab 		gspca_dev->alt = 3 + 1;
338*0c0d06caSMauro Carvalho Chehab 		break;
339*0c0d06caSMauro Carvalho Chehab 
340*0c0d06caSMauro Carvalho Chehab 	case IMAGE_800:
341*0c0d06caSMauro Carvalho Chehab 	case IMAGE_1280:
342*0c0d06caSMauro Carvalho Chehab 		gspca_dev->alt = 1 + 1;
343*0c0d06caSMauro Carvalho Chehab 		break;
344*0c0d06caSMauro Carvalho Chehab 	}
345*0c0d06caSMauro Carvalho Chehab 	return 0;
346*0c0d06caSMauro Carvalho Chehab }
347*0c0d06caSMauro Carvalho Chehab 
348*0c0d06caSMauro Carvalho Chehab static int mi1320_camera_settings(struct gspca_dev *gspca_dev)
349*0c0d06caSMauro Carvalho Chehab {
350*0c0d06caSMauro Carvalho Chehab 	struct sd *sd = (struct sd *) gspca_dev;
351*0c0d06caSMauro Carvalho Chehab 
352*0c0d06caSMauro Carvalho Chehab 	s32 backlight = sd->vcur.backlight;
353*0c0d06caSMauro Carvalho Chehab 	s32 bright = sd->vcur.brightness;
354*0c0d06caSMauro Carvalho Chehab 	s32 sharp  = sd->vcur.sharpness;
355*0c0d06caSMauro Carvalho Chehab 	s32 cntr   = sd->vcur.contrast;
356*0c0d06caSMauro Carvalho Chehab 	s32 gam	   = sd->vcur.gamma;
357*0c0d06caSMauro Carvalho Chehab 	s32 hue    = sd->vcur.hue;
358*0c0d06caSMauro Carvalho Chehab 	s32 sat	   = sd->vcur.saturation;
359*0c0d06caSMauro Carvalho Chehab 	s32 wbal   = sd->vcur.whitebal;
360*0c0d06caSMauro Carvalho Chehab 	s32 mirror = (((sd->vcur.mirror > 0) ^ sd->mirrorMask) > 0);
361*0c0d06caSMauro Carvalho Chehab 	s32 flip   = (((sd->vcur.flip   > 0) ^ sd->mirrorMask) > 0);
362*0c0d06caSMauro Carvalho Chehab 	s32 freq   = (sd->vcur.AC50Hz > 0);
363*0c0d06caSMauro Carvalho Chehab 	s32 i;
364*0c0d06caSMauro Carvalho Chehab 
365*0c0d06caSMauro Carvalho Chehab 	if (freq != sd->vold.AC50Hz) {
366*0c0d06caSMauro Carvalho Chehab 		sd->vold.AC50Hz = freq;
367*0c0d06caSMauro Carvalho Chehab 
368*0c0d06caSMauro Carvalho Chehab 		freq = 2 * (freq == 0);
369*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
370*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba02, 0x00f1, 0, NULL);
371*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00       , 0x005b, 0, NULL);
372*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba01 + freq, 0x00f1, 0, NULL);
373*0c0d06caSMauro Carvalho Chehab 	}
374*0c0d06caSMauro Carvalho Chehab 
375*0c0d06caSMauro Carvalho Chehab 	if (wbal != sd->vold.whitebal) {
376*0c0d06caSMauro Carvalho Chehab 		sd->vold.whitebal = wbal;
377*0c0d06caSMauro Carvalho Chehab 		if (wbal < 0 || wbal > sd->vmax.whitebal)
378*0c0d06caSMauro Carvalho Chehab 			wbal = 0;
379*0c0d06caSMauro Carvalho Chehab 
380*0c0d06caSMauro Carvalho Chehab 		for (i = 0; i < 2; i++) {
381*0c0d06caSMauro Carvalho Chehab 			if (wbal == 0) { /* Normal light */
382*0c0d06caSMauro Carvalho Chehab 				ctrl_out(gspca_dev, 0x40, 1,
383*0c0d06caSMauro Carvalho Chehab 						0x0010, 0x0010, 0, NULL);
384*0c0d06caSMauro Carvalho Chehab 				ctrl_out(gspca_dev, 0x40, 1,
385*0c0d06caSMauro Carvalho Chehab 						0x0003, 0x00c1, 0, NULL);
386*0c0d06caSMauro Carvalho Chehab 				ctrl_out(gspca_dev, 0x40, 1,
387*0c0d06caSMauro Carvalho Chehab 						0x0042, 0x00c2, 0, NULL);
388*0c0d06caSMauro Carvalho Chehab 				ctrl_out(gspca_dev, 0x40, 3,
389*0c0d06caSMauro Carvalho Chehab 						0xba00, 0x0200, 48, dat_wbalNL);
390*0c0d06caSMauro Carvalho Chehab 			}
391*0c0d06caSMauro Carvalho Chehab 
392*0c0d06caSMauro Carvalho Chehab 			if (wbal == 1) { /* Low light */
393*0c0d06caSMauro Carvalho Chehab 				ctrl_out(gspca_dev, 0x40, 1,
394*0c0d06caSMauro Carvalho Chehab 						0x0010, 0x0010, 0, NULL);
395*0c0d06caSMauro Carvalho Chehab 				ctrl_out(gspca_dev, 0x40, 1,
396*0c0d06caSMauro Carvalho Chehab 						0x0004, 0x00c1, 0, NULL);
397*0c0d06caSMauro Carvalho Chehab 				ctrl_out(gspca_dev, 0x40, 1,
398*0c0d06caSMauro Carvalho Chehab 						0x0043, 0x00c2, 0, NULL);
399*0c0d06caSMauro Carvalho Chehab 				ctrl_out(gspca_dev, 0x40, 3,
400*0c0d06caSMauro Carvalho Chehab 						0xba00, 0x0200, 48, dat_wbalLL);
401*0c0d06caSMauro Carvalho Chehab 			}
402*0c0d06caSMauro Carvalho Chehab 
403*0c0d06caSMauro Carvalho Chehab 			if (wbal == 2) { /* Back light */
404*0c0d06caSMauro Carvalho Chehab 				ctrl_out(gspca_dev, 0x40, 1,
405*0c0d06caSMauro Carvalho Chehab 						0x0010, 0x0010, 0, NULL);
406*0c0d06caSMauro Carvalho Chehab 				ctrl_out(gspca_dev, 0x40, 1,
407*0c0d06caSMauro Carvalho Chehab 						0x0003, 0x00c1, 0, NULL);
408*0c0d06caSMauro Carvalho Chehab 				ctrl_out(gspca_dev, 0x40, 1,
409*0c0d06caSMauro Carvalho Chehab 						0x0042, 0x00c2, 0, NULL);
410*0c0d06caSMauro Carvalho Chehab 				ctrl_out(gspca_dev, 0x40, 3,
411*0c0d06caSMauro Carvalho Chehab 						0xba00, 0x0200, 44, dat_wbalBL);
412*0c0d06caSMauro Carvalho Chehab 			}
413*0c0d06caSMauro Carvalho Chehab 		}
414*0c0d06caSMauro Carvalho Chehab 	}
415*0c0d06caSMauro Carvalho Chehab 
416*0c0d06caSMauro Carvalho Chehab 	if (bright != sd->vold.brightness) {
417*0c0d06caSMauro Carvalho Chehab 		sd->vold.brightness = bright;
418*0c0d06caSMauro Carvalho Chehab 		if (bright < 0 || bright > sd->vmax.brightness)
419*0c0d06caSMauro Carvalho Chehab 			bright = 0;
420*0c0d06caSMauro Carvalho Chehab 
421*0c0d06caSMauro Carvalho Chehab 		bright = tbl_bright[bright];
422*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
423*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
424*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00 + bright, 0x0034, 0, NULL);
425*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00 + bright, 0x00f1, 0, NULL);
426*0c0d06caSMauro Carvalho Chehab 	}
427*0c0d06caSMauro Carvalho Chehab 
428*0c0d06caSMauro Carvalho Chehab 	if (sat != sd->vold.saturation) {
429*0c0d06caSMauro Carvalho Chehab 		sd->vold.saturation = sat;
430*0c0d06caSMauro Carvalho Chehab 		if (sat < 0 || sat > sd->vmax.saturation)
431*0c0d06caSMauro Carvalho Chehab 			sat = 0;
432*0c0d06caSMauro Carvalho Chehab 
433*0c0d06caSMauro Carvalho Chehab 		sat = tbl_sat[sat];
434*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
435*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
436*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00      , 0x0025, 0, NULL);
437*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00 + sat, 0x00f1, 0, NULL);
438*0c0d06caSMauro Carvalho Chehab 	}
439*0c0d06caSMauro Carvalho Chehab 
440*0c0d06caSMauro Carvalho Chehab 	if (sharp != sd->vold.sharpness) {
441*0c0d06caSMauro Carvalho Chehab 		sd->vold.sharpness = sharp;
442*0c0d06caSMauro Carvalho Chehab 		if (sharp < 0 || sharp > sd->vmax.sharpness)
443*0c0d06caSMauro Carvalho Chehab 			sharp = 0;
444*0c0d06caSMauro Carvalho Chehab 
445*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
446*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
447*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00        , 0x0005, 0, NULL);
448*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00 + sharp, 0x00f1, 0, NULL);
449*0c0d06caSMauro Carvalho Chehab 	}
450*0c0d06caSMauro Carvalho Chehab 
451*0c0d06caSMauro Carvalho Chehab 	if (hue != sd->vold.hue) {
452*0c0d06caSMauro Carvalho Chehab 		/* 0=normal  1=NB  2="sepia"  3=negative  4=other  5=other2 */
453*0c0d06caSMauro Carvalho Chehab 		if (hue < 0 || hue > sd->vmax.hue)
454*0c0d06caSMauro Carvalho Chehab 			hue = 0;
455*0c0d06caSMauro Carvalho Chehab 		if (hue == sd->vmax.hue)
456*0c0d06caSMauro Carvalho Chehab 			sd->swapRB = 1;
457*0c0d06caSMauro Carvalho Chehab 		else
458*0c0d06caSMauro Carvalho Chehab 			sd->swapRB = 0;
459*0c0d06caSMauro Carvalho Chehab 
460*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
461*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
462*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba70, 0x00e2, 0, NULL);
463*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00 + hue * (hue < 6), 0x00f1,
464*0c0d06caSMauro Carvalho Chehab 							0, NULL);
465*0c0d06caSMauro Carvalho Chehab 	}
466*0c0d06caSMauro Carvalho Chehab 
467*0c0d06caSMauro Carvalho Chehab 	if (backlight != sd->vold.backlight) {
468*0c0d06caSMauro Carvalho Chehab 		sd->vold.backlight = backlight;
469*0c0d06caSMauro Carvalho Chehab 		if (backlight < 0 || backlight > sd->vmax.backlight)
470*0c0d06caSMauro Carvalho Chehab 			backlight = 0;
471*0c0d06caSMauro Carvalho Chehab 
472*0c0d06caSMauro Carvalho Chehab 		backlight = tbl_backlight[backlight];
473*0c0d06caSMauro Carvalho Chehab 		for (i = 0; i < 2; i++) {
474*0c0d06caSMauro Carvalho Chehab 			ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
475*0c0d06caSMauro Carvalho Chehab 			ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
476*0c0d06caSMauro Carvalho Chehab 			ctrl_out(gspca_dev, 0x40, 1, 0xba74, 0x0006, 0, NULL);
477*0c0d06caSMauro Carvalho Chehab 			ctrl_out(gspca_dev, 0x40, 1, 0xba80 + backlight, 0x00f1,
478*0c0d06caSMauro Carvalho Chehab 								0, NULL);
479*0c0d06caSMauro Carvalho Chehab 		}
480*0c0d06caSMauro Carvalho Chehab 	}
481*0c0d06caSMauro Carvalho Chehab 
482*0c0d06caSMauro Carvalho Chehab 	if (hue != sd->vold.hue) {
483*0c0d06caSMauro Carvalho Chehab 		sd->vold.hue = hue;
484*0c0d06caSMauro Carvalho Chehab 
485*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
486*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
487*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba70, 0x00e2, 0, NULL);
488*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00 + hue * (hue < 6), 0x00f1,
489*0c0d06caSMauro Carvalho Chehab 							0, NULL);
490*0c0d06caSMauro Carvalho Chehab 	}
491*0c0d06caSMauro Carvalho Chehab 
492*0c0d06caSMauro Carvalho Chehab 	if (mirror != sd->vold.mirror || flip != sd->vold.flip) {
493*0c0d06caSMauro Carvalho Chehab 		u8 dat_hvflip2[4] = {0x20, 0x01, 0xf1, 0x00};
494*0c0d06caSMauro Carvalho Chehab 		sd->vold.mirror = mirror;
495*0c0d06caSMauro Carvalho Chehab 		sd->vold.flip = flip;
496*0c0d06caSMauro Carvalho Chehab 
497*0c0d06caSMauro Carvalho Chehab 		dat_hvflip2[3] = flip + 2 * mirror;
498*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 4, dat_hvflip1);
499*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 4, dat_hvflip2);
500*0c0d06caSMauro Carvalho Chehab 	}
501*0c0d06caSMauro Carvalho Chehab 
502*0c0d06caSMauro Carvalho Chehab 	if (gam != sd->vold.gamma) {
503*0c0d06caSMauro Carvalho Chehab 		sd->vold.gamma = gam;
504*0c0d06caSMauro Carvalho Chehab 		if (gam < 0 || gam > sd->vmax.gamma)
505*0c0d06caSMauro Carvalho Chehab 			gam = 0;
506*0c0d06caSMauro Carvalho Chehab 
507*0c0d06caSMauro Carvalho Chehab 		gam = 2 * gam;
508*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
509*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
510*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba04      , 0x003b, 0, NULL);
511*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba02 + gam, 0x00f1, 0, NULL);
512*0c0d06caSMauro Carvalho Chehab 	}
513*0c0d06caSMauro Carvalho Chehab 
514*0c0d06caSMauro Carvalho Chehab 	if (cntr != sd->vold.contrast) {
515*0c0d06caSMauro Carvalho Chehab 		sd->vold.contrast = cntr;
516*0c0d06caSMauro Carvalho Chehab 		if (cntr < 0 || cntr > sd->vmax.contrast)
517*0c0d06caSMauro Carvalho Chehab 			cntr = 0;
518*0c0d06caSMauro Carvalho Chehab 
519*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
520*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
521*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00 + tbl_cntr1[cntr], 0x0035,
522*0c0d06caSMauro Carvalho Chehab 							0, NULL);
523*0c0d06caSMauro Carvalho Chehab 		ctrl_out(gspca_dev, 0x40, 1, 0xba00 + tbl_cntr2[cntr], 0x00f1,
524*0c0d06caSMauro Carvalho Chehab 							0, NULL);
525*0c0d06caSMauro Carvalho Chehab 	}
526*0c0d06caSMauro Carvalho Chehab 
527*0c0d06caSMauro Carvalho Chehab 	return 0;
528*0c0d06caSMauro Carvalho Chehab }
529*0c0d06caSMauro Carvalho Chehab 
530*0c0d06caSMauro Carvalho Chehab static void mi1320_post_unset_alt(struct gspca_dev *gspca_dev)
531*0c0d06caSMauro Carvalho Chehab {
532*0c0d06caSMauro Carvalho Chehab 	ctrl_out(gspca_dev, 0x40, 5, 0x0000, 0x0000, 0, NULL);
533*0c0d06caSMauro Carvalho Chehab 
534*0c0d06caSMauro Carvalho Chehab 	fetch_validx(gspca_dev, tbl_post_unset_alt,
535*0c0d06caSMauro Carvalho Chehab 				ARRAY_SIZE(tbl_post_unset_alt));
536*0c0d06caSMauro Carvalho Chehab }
537