18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/* Subdriver for the GL860 chip with the MI2020 sensor
38c2ecf20Sopenharmony_ci * Author Olivier LORIN, from logs by Iceman/Soro2005 + Fret_saw/Hulkie/Tricid
48c2ecf20Sopenharmony_ci * with the help of Kytrix/BUGabundo/Blazercist.
58c2ecf20Sopenharmony_ci * Driver achieved thanks to a webcam gift by Kytrix.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci/* Sensor : MI2020 */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include "gl860.h"
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cistatic u8 dat_wbal1[] = {0x8c, 0xa2, 0x0c};
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistatic u8 dat_bright1[] = {0x8c, 0xa2, 0x06};
158c2ecf20Sopenharmony_cistatic u8 dat_bright3[] = {0x8c, 0xa1, 0x02};
168c2ecf20Sopenharmony_cistatic u8 dat_bright4[] = {0x90, 0x00, 0x0f};
178c2ecf20Sopenharmony_cistatic u8 dat_bright5[] = {0x8c, 0xa1, 0x03};
188c2ecf20Sopenharmony_cistatic u8 dat_bright6[] = {0x90, 0x00, 0x05};
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistatic u8 dat_hvflip1[] = {0x8c, 0x27, 0x19};
218c2ecf20Sopenharmony_cistatic u8 dat_hvflip3[] = {0x8c, 0x27, 0x3b};
228c2ecf20Sopenharmony_cistatic u8 dat_hvflip5[] = {0x8c, 0xa1, 0x03};
238c2ecf20Sopenharmony_cistatic u8 dat_hvflip6[] = {0x90, 0x00, 0x06};
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistatic struct idxdata tbl_middle_hvflip_low[] = {
268c2ecf20Sopenharmony_ci	{0x33, {0x90, 0x00, 0x06}},
278c2ecf20Sopenharmony_ci	{6, {0xff, 0xff, 0xff}},
288c2ecf20Sopenharmony_ci	{0x33, {0x90, 0x00, 0x06}},
298c2ecf20Sopenharmony_ci	{6, {0xff, 0xff, 0xff}},
308c2ecf20Sopenharmony_ci	{0x33, {0x90, 0x00, 0x06}},
318c2ecf20Sopenharmony_ci	{6, {0xff, 0xff, 0xff}},
328c2ecf20Sopenharmony_ci	{0x33, {0x90, 0x00, 0x06}},
338c2ecf20Sopenharmony_ci	{6, {0xff, 0xff, 0xff}},
348c2ecf20Sopenharmony_ci};
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistatic struct idxdata tbl_middle_hvflip_big[] = {
378c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x01}},
388c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x20}}, {0x33, {0x90, 0x00, 0x00}},
398c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa7, 0x02}}, {0x33, {0x90, 0x00, 0x00}},
408c2ecf20Sopenharmony_ci	{102, {0xff, 0xff, 0xff}},
418c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x02}},
428c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x20}}, {0x33, {0x90, 0x00, 0x72}},
438c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa7, 0x02}}, {0x33, {0x90, 0x00, 0x01}},
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic struct idxdata tbl_end_hvflip[] = {
478c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x02}}, {0x33, {0x90, 0x00, 0x1f}},
488c2ecf20Sopenharmony_ci	{6, {0xff, 0xff, 0xff}},
498c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x02}}, {0x33, {0x90, 0x00, 0x1f}},
508c2ecf20Sopenharmony_ci	{6, {0xff, 0xff, 0xff}},
518c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x02}}, {0x33, {0x90, 0x00, 0x1f}},
528c2ecf20Sopenharmony_ci	{6, {0xff, 0xff, 0xff}},
538c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x02}}, {0x33, {0x90, 0x00, 0x1f}},
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic u8 dat_freq1[] = { 0x8c, 0xa4, 0x04 };
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic u8 dat_multi5[] = { 0x8c, 0xa1, 0x03 };
598c2ecf20Sopenharmony_cistatic u8 dat_multi6[] = { 0x90, 0x00, 0x05 };
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistatic struct validx tbl_init_at_startup[] = {
628c2ecf20Sopenharmony_ci	{0x0000, 0x0000}, {0x0010, 0x0010}, {0x0008, 0x00c0}, {0x0001, 0x00c1},
638c2ecf20Sopenharmony_ci	{0x0001, 0x00c2}, {0x0020, 0x0006}, {0x006a, 0x000d},
648c2ecf20Sopenharmony_ci	{53, 0xffff},
658c2ecf20Sopenharmony_ci	{0x0040, 0x0000}, {0x0063, 0x0006},
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistatic struct validx tbl_common_0B[] = {
698c2ecf20Sopenharmony_ci	{0x0002, 0x0004}, {0x006a, 0x0007}, {0x00ef, 0x0006}, {0x006a, 0x000d},
708c2ecf20Sopenharmony_ci	{0x0000, 0x00c0}, {0x0010, 0x0010}, {0x0003, 0x00c1}, {0x0042, 0x00c2},
718c2ecf20Sopenharmony_ci	{0x0004, 0x00d8}, {0x0000, 0x0058}, {0x0041, 0x0000},
728c2ecf20Sopenharmony_ci};
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cistatic struct idxdata tbl_common_3B[] = {
758c2ecf20Sopenharmony_ci	{0x33, {0x86, 0x25, 0x01}}, {0x33, {0x86, 0x25, 0x00}},
768c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
778c2ecf20Sopenharmony_ci	{0x30, {0x1a, 0x0a, 0xcc}}, {0x32, {0x02, 0x00, 0x08}},
788c2ecf20Sopenharmony_ci	{0x33, {0xf4, 0x03, 0x1d}},
798c2ecf20Sopenharmony_ci	{6, {0xff, 0xff, 0xff}}, /* 12 */
808c2ecf20Sopenharmony_ci	{0x34, {0x1e, 0x8f, 0x09}}, {0x34, {0x1c, 0x01, 0x28}},
818c2ecf20Sopenharmony_ci	{0x34, {0x1e, 0x8f, 0x09}},
828c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}}, /* - */
838c2ecf20Sopenharmony_ci	{0x34, {0x1e, 0x8f, 0x09}}, {0x32, {0x14, 0x06, 0xe6}},
848c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x22, 0x23}}, {0x33, {0x90, 0x00, 0x00}},
858c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa2, 0x0f}}, {0x33, {0x90, 0x00, 0x0d}},
868c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa2, 0x10}}, {0x33, {0x90, 0x00, 0x0b}},
878c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa2, 0x11}}, {0x33, {0x90, 0x00, 0x07}},
888c2ecf20Sopenharmony_ci	{0x33, {0xf4, 0x03, 0x1d}}, {0x35, {0xa2, 0x00, 0xe2}},
898c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xab, 0x05}}, {0x33, {0x90, 0x00, 0x01}},
908c2ecf20Sopenharmony_ci	{0x32, {0x6e, 0x00, 0x86}}, {0x32, {0x70, 0x0f, 0xaa}},
918c2ecf20Sopenharmony_ci	{0x32, {0x72, 0x0f, 0xe4}}, {0x33, {0x8c, 0xa3, 0x4a}},
928c2ecf20Sopenharmony_ci	{0x33, {0x90, 0x00, 0x5a}}, {0x33, {0x8c, 0xa3, 0x4b}},
938c2ecf20Sopenharmony_ci	{0x33, {0x90, 0x00, 0xa6}}, {0x33, {0x8c, 0xa3, 0x61}},
948c2ecf20Sopenharmony_ci	{0x33, {0x90, 0x00, 0xc8}}, {0x33, {0x8c, 0xa3, 0x62}},
958c2ecf20Sopenharmony_ci	{0x33, {0x90, 0x00, 0xe1}}, {0x34, {0xce, 0x01, 0xa8}},
968c2ecf20Sopenharmony_ci	{0x34, {0xd0, 0x66, 0x33}}, {0x34, {0xd2, 0x31, 0x9a}},
978c2ecf20Sopenharmony_ci	{0x34, {0xd4, 0x94, 0x63}}, {0x34, {0xd6, 0x4b, 0x25}},
988c2ecf20Sopenharmony_ci	{0x34, {0xd8, 0x26, 0x70}}, {0x34, {0xda, 0x72, 0x4c}},
998c2ecf20Sopenharmony_ci	{0x34, {0xdc, 0xff, 0x04}}, {0x34, {0xde, 0x01, 0x5b}},
1008c2ecf20Sopenharmony_ci	{0x34, {0xe6, 0x01, 0x13}}, {0x34, {0xee, 0x0b, 0xf0}},
1018c2ecf20Sopenharmony_ci	{0x34, {0xf6, 0x0b, 0xa4}}, {0x35, {0x00, 0xf6, 0xe7}},
1028c2ecf20Sopenharmony_ci	{0x35, {0x08, 0x0d, 0xfd}}, {0x35, {0x10, 0x25, 0x63}},
1038c2ecf20Sopenharmony_ci	{0x35, {0x18, 0x35, 0x6c}}, {0x35, {0x20, 0x42, 0x7e}},
1048c2ecf20Sopenharmony_ci	{0x35, {0x28, 0x19, 0x44}}, {0x35, {0x30, 0x39, 0xd4}},
1058c2ecf20Sopenharmony_ci	{0x35, {0x38, 0xf5, 0xa8}}, {0x35, {0x4c, 0x07, 0x90}},
1068c2ecf20Sopenharmony_ci	{0x35, {0x44, 0x07, 0xb8}}, {0x35, {0x5c, 0x06, 0x88}},
1078c2ecf20Sopenharmony_ci	{0x35, {0x54, 0x07, 0xff}}, {0x34, {0xe0, 0x01, 0x52}},
1088c2ecf20Sopenharmony_ci	{0x34, {0xe8, 0x00, 0xcc}}, {0x34, {0xf0, 0x0d, 0x83}},
1098c2ecf20Sopenharmony_ci	{0x34, {0xf8, 0x0c, 0xb3}}, {0x35, {0x02, 0xfe, 0xba}},
1108c2ecf20Sopenharmony_ci	{0x35, {0x0a, 0x04, 0xe0}}, {0x35, {0x12, 0x1c, 0x63}},
1118c2ecf20Sopenharmony_ci	{0x35, {0x1a, 0x2b, 0x5a}}, {0x35, {0x22, 0x32, 0x5e}},
1128c2ecf20Sopenharmony_ci	{0x35, {0x2a, 0x0d, 0x28}}, {0x35, {0x32, 0x2c, 0x02}},
1138c2ecf20Sopenharmony_ci	{0x35, {0x3a, 0xf4, 0xfa}}, {0x35, {0x4e, 0x07, 0xef}},
1148c2ecf20Sopenharmony_ci	{0x35, {0x46, 0x07, 0x88}}, {0x35, {0x5e, 0x07, 0xc1}},
1158c2ecf20Sopenharmony_ci	{0x35, {0x56, 0x04, 0x64}}, {0x34, {0xe4, 0x01, 0x15}},
1168c2ecf20Sopenharmony_ci	{0x34, {0xec, 0x00, 0x82}}, {0x34, {0xf4, 0x0c, 0xce}},
1178c2ecf20Sopenharmony_ci	{0x34, {0xfc, 0x0c, 0xba}}, {0x35, {0x06, 0x1f, 0x02}},
1188c2ecf20Sopenharmony_ci	{0x35, {0x0e, 0x02, 0xe3}}, {0x35, {0x16, 0x1a, 0x50}},
1198c2ecf20Sopenharmony_ci	{0x35, {0x1e, 0x24, 0x39}}, {0x35, {0x26, 0x23, 0x4c}},
1208c2ecf20Sopenharmony_ci	{0x35, {0x2e, 0xf9, 0x1b}}, {0x35, {0x36, 0x23, 0x19}},
1218c2ecf20Sopenharmony_ci	{0x35, {0x3e, 0x12, 0x08}}, {0x35, {0x52, 0x07, 0x22}},
1228c2ecf20Sopenharmony_ci	{0x35, {0x4a, 0x03, 0xd3}}, {0x35, {0x62, 0x06, 0x54}},
1238c2ecf20Sopenharmony_ci	{0x35, {0x5a, 0x04, 0x5d}}, {0x34, {0xe2, 0x01, 0x04}},
1248c2ecf20Sopenharmony_ci	{0x34, {0xea, 0x00, 0xa0}}, {0x34, {0xf2, 0x0c, 0xbc}},
1258c2ecf20Sopenharmony_ci	{0x34, {0xfa, 0x0c, 0x5b}}, {0x35, {0x04, 0x17, 0xf2}},
1268c2ecf20Sopenharmony_ci	{0x35, {0x0c, 0x02, 0x08}}, {0x35, {0x14, 0x28, 0x43}},
1278c2ecf20Sopenharmony_ci	{0x35, {0x1c, 0x28, 0x62}}, {0x35, {0x24, 0x2b, 0x60}},
1288c2ecf20Sopenharmony_ci	{0x35, {0x2c, 0x07, 0x33}}, {0x35, {0x34, 0x1f, 0xb0}},
1298c2ecf20Sopenharmony_ci	{0x35, {0x3c, 0xed, 0xcd}}, {0x35, {0x50, 0x00, 0x06}},
1308c2ecf20Sopenharmony_ci	{0x35, {0x48, 0x07, 0xff}}, {0x35, {0x60, 0x05, 0x89}},
1318c2ecf20Sopenharmony_ci	{0x35, {0x58, 0x07, 0xff}}, {0x35, {0x40, 0x00, 0xa0}},
1328c2ecf20Sopenharmony_ci	{0x35, {0x42, 0x00, 0x00}}, {0x32, {0x10, 0x01, 0xfc}},
1338c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x18}}, {0x33, {0x90, 0x00, 0x3c}},
1348c2ecf20Sopenharmony_ci	{0x33, {0x78, 0x00, 0x00}},
1358c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
1368c2ecf20Sopenharmony_ci	{0x35, {0xb8, 0x1f, 0x20}}, {0x33, {0x8c, 0xa2, 0x06}},
1378c2ecf20Sopenharmony_ci	{0x33, {0x90, 0x00, 0x10}}, {0x33, {0x8c, 0xa2, 0x07}},
1388c2ecf20Sopenharmony_ci	{0x33, {0x90, 0x00, 0x08}}, {0x33, {0x8c, 0xa2, 0x42}},
1398c2ecf20Sopenharmony_ci	{0x33, {0x90, 0x00, 0x0b}}, {0x33, {0x8c, 0xa2, 0x4a}},
1408c2ecf20Sopenharmony_ci	{0x33, {0x90, 0x00, 0x8c}}, {0x35, {0xba, 0xfa, 0x08}},
1418c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa2, 0x02}}, {0x33, {0x90, 0x00, 0x22}},
1428c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa2, 0x03}}, {0x33, {0x90, 0x00, 0xbb}},
1438c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa4, 0x04}}, {0x33, {0x90, 0x00, 0x80}},
1448c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa7, 0x9d}}, {0x33, {0x90, 0x00, 0x00}},
1458c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa7, 0x9e}}, {0x33, {0x90, 0x00, 0x00}},
1468c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa2, 0x0c}}, {0x33, {0x90, 0x00, 0x17}},
1478c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa2, 0x15}}, {0x33, {0x90, 0x00, 0x04}},
1488c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa2, 0x14}}, {0x33, {0x90, 0x00, 0x20}},
1498c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x00}},
1508c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x17}}, {0x33, {0x90, 0x21, 0x11}},
1518c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x1b}}, {0x33, {0x90, 0x02, 0x4f}},
1528c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x25}}, {0x33, {0x90, 0x06, 0x0f}},
1538c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x39}}, {0x33, {0x90, 0x21, 0x11}},
1548c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x3d}}, {0x33, {0x90, 0x01, 0x20}},
1558c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x47}}, {0x33, {0x90, 0x09, 0x4c}},
1568c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x03}}, {0x33, {0x90, 0x02, 0x84}},
1578c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x05}}, {0x33, {0x90, 0x01, 0xe2}},
1588c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x07}}, {0x33, {0x90, 0x06, 0x40}},
1598c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x09}}, {0x33, {0x90, 0x04, 0xb0}},
1608c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x0d}}, {0x33, {0x90, 0x00, 0x00}},
1618c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x0f}}, {0x33, {0x90, 0x00, 0x00}},
1628c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x11}}, {0x33, {0x90, 0x04, 0xbd}},
1638c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x13}}, {0x33, {0x90, 0x06, 0x4d}},
1648c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x15}}, {0x33, {0x90, 0x00, 0x00}},
1658c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x17}}, {0x33, {0x90, 0x21, 0x11}},
1668c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x19}}, {0x33, {0x90, 0x04, 0x6c}},
1678c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x1b}}, {0x33, {0x90, 0x02, 0x4f}},
1688c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x1d}}, {0x33, {0x90, 0x01, 0x02}},
1698c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x1f}}, {0x33, {0x90, 0x02, 0x79}},
1708c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x21}}, {0x33, {0x90, 0x01, 0x55}},
1718c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x23}}, {0x33, {0x90, 0x02, 0x85}},
1728c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x25}}, {0x33, {0x90, 0x06, 0x0f}},
1738c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x27}}, {0x33, {0x90, 0x20, 0x20}},
1748c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x29}}, {0x33, {0x90, 0x20, 0x20}},
1758c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x2b}}, {0x33, {0x90, 0x10, 0x20}},
1768c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x2d}}, {0x33, {0x90, 0x20, 0x07}},
1778c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x2f}}, {0x33, {0x90, 0x00, 0x04}},
1788c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x31}}, {0x33, {0x90, 0x00, 0x04}},
1798c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x33}}, {0x33, {0x90, 0x04, 0xbb}},
1808c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x35}}, {0x33, {0x90, 0x06, 0x4b}},
1818c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x37}}, {0x33, {0x90, 0x00, 0x00}},
1828c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x39}}, {0x33, {0x90, 0x21, 0x11}},
1838c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x3b}}, {0x33, {0x90, 0x00, 0x24}},
1848c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x3d}}, {0x33, {0x90, 0x01, 0x20}},
1858c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x41}}, {0x33, {0x90, 0x01, 0x69}},
1868c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x45}}, {0x33, {0x90, 0x04, 0xed}},
1878c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x47}}, {0x33, {0x90, 0x09, 0x4c}},
1888c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x51}}, {0x33, {0x90, 0x00, 0x00}},
1898c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x53}}, {0x33, {0x90, 0x03, 0x20}},
1908c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x55}}, {0x33, {0x90, 0x00, 0x00}},
1918c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x57}}, {0x33, {0x90, 0x02, 0x58}},
1928c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x5f}}, {0x33, {0x90, 0x00, 0x00}},
1938c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x61}}, {0x33, {0x90, 0x06, 0x40}},
1948c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x63}}, {0x33, {0x90, 0x00, 0x00}},
1958c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x65}}, {0x33, {0x90, 0x04, 0xb0}},
1968c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x22, 0x2e}}, {0x33, {0x90, 0x00, 0xa1}},
1978c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa4, 0x08}}, {0x33, {0x90, 0x00, 0x1f}},
1988c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa4, 0x09}}, {0x33, {0x90, 0x00, 0x21}},
1998c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa4, 0x0a}}, {0x33, {0x90, 0x00, 0x25}},
2008c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa4, 0x0b}}, {0x33, {0x90, 0x00, 0x27}},
2018c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x24, 0x11}}, {0x33, {0x90, 0x00, 0xa1}},
2028c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x24, 0x13}}, {0x33, {0x90, 0x00, 0xc1}},
2038c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x24, 0x15}}, {0x33, {0x90, 0x00, 0x6a}},
2048c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x24, 0x17}}, {0x33, {0x90, 0x00, 0x80}},
2058c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x05}},
2068c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2078c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x06}},
2088c2ecf20Sopenharmony_ci	{3, {0xff, 0xff, 0xff}},
2098c2ecf20Sopenharmony_ci};
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_cistatic struct idxdata tbl_init_post_alt_low1[] = {
2128c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x15}}, {0x33, {0x90, 0x00, 0x25}},
2138c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x22, 0x2e}}, {0x33, {0x90, 0x00, 0x81}},
2148c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa4, 0x08}}, {0x33, {0x90, 0x00, 0x17}},
2158c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa4, 0x09}}, {0x33, {0x90, 0x00, 0x1a}},
2168c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa4, 0x0a}}, {0x33, {0x90, 0x00, 0x1d}},
2178c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa4, 0x0b}}, {0x33, {0x90, 0x00, 0x20}},
2188c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x24, 0x11}}, {0x33, {0x90, 0x00, 0x81}},
2198c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x24, 0x13}}, {0x33, {0x90, 0x00, 0x9b}},
2208c2ecf20Sopenharmony_ci};
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_cistatic struct idxdata tbl_init_post_alt_low2[] = {
2238c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x03}}, {0x33, {0x90, 0x03, 0x24}},
2248c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x05}}, {0x33, {0x90, 0x02, 0x58}},
2258c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x05}},
2268c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2278c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x06}},
2288c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2298c2ecf20Sopenharmony_ci};
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_cistatic struct idxdata tbl_init_post_alt_low3[] = {
2328c2ecf20Sopenharmony_ci	{0x34, {0x1e, 0x8f, 0x09}}, {0x34, {0x1c, 0x01, 0x28}},
2338c2ecf20Sopenharmony_ci	{0x34, {0x1e, 0x8f, 0x09}},
2348c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2358c2ecf20Sopenharmony_ci	{0x34, {0x1e, 0x8f, 0x09}}, {0x32, {0x14, 0x06, 0xe6}},
2368c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x20}}, {0x33, {0x90, 0x00, 0x00}},
2378c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x01}},
2388c2ecf20Sopenharmony_ci	{0x33, {0x2e, 0x01, 0x00}}, {0x34, {0x04, 0x00, 0x2a}},
2398c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa7, 0x02}}, {0x33, {0x90, 0x00, 0x00}},
2408c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x95}}, {0x33, {0x90, 0x01, 0x00}},
2418c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2428c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x20}}, {0x33, {0x90, 0x00, 0x72}},
2438c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x02}},
2448c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa7, 0x02}}, {0x33, {0x90, 0x00, 0x01}},
2458c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2468c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x20}}, {0x33, {0x90, 0x00, 0x00}},
2478c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x01}},
2488c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa7, 0x02}}, {0x33, {0x90, 0x00, 0x00}},
2498c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2508c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x05}},
2518c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2528c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x06}},
2538c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2548c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x05}},
2558c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2568c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x06}},
2578c2ecf20Sopenharmony_ci};
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_cistatic struct idxdata tbl_init_post_alt_big[] = {
2608c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x05}},
2618c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2628c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x06}},
2638c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2648c2ecf20Sopenharmony_ci	{0x34, {0x1e, 0x8f, 0x09}}, {0x34, {0x1c, 0x01, 0x28}},
2658c2ecf20Sopenharmony_ci	{0x34, {0x1e, 0x8f, 0x09}},
2668c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2678c2ecf20Sopenharmony_ci	{0x34, {0x1e, 0x8f, 0x09}}, {0x32, {0x14, 0x06, 0xe6}},
2688c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}},
2698c2ecf20Sopenharmony_ci	{0x33, {0x90, 0x00, 0x05}},
2708c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2718c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x06}},
2728c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2738c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x05}},
2748c2ecf20Sopenharmony_ci	{2, {0xff, 0xff, 0xff}},
2758c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x06}},
2768c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x20}}, {0x33, {0x90, 0x00, 0x72}},
2778c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x30}}, {0x33, {0x90, 0x00, 0x03}},
2788c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x31}}, {0x33, {0x90, 0x00, 0x02}},
2798c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x32}}, {0x33, {0x90, 0x00, 0x03}},
2808c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x34}}, {0x33, {0x90, 0x00, 0x03}},
2818c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x02}},
2828c2ecf20Sopenharmony_ci	{0x33, {0x2e, 0x01, 0x00}}, {0x34, {0x04, 0x00, 0x2a}},
2838c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa7, 0x02}}, {0x33, {0x90, 0x00, 0x01}},
2848c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0x27, 0x97}}, {0x33, {0x90, 0x01, 0x00}},
2858c2ecf20Sopenharmony_ci	{51, {0xff, 0xff, 0xff}},
2868c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x20}}, {0x33, {0x90, 0x00, 0x00}},
2878c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x01}},
2888c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa7, 0x02}}, {0x33, {0x90, 0x00, 0x00}},
2898c2ecf20Sopenharmony_ci	{51, {0xff, 0xff, 0xff}},
2908c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x20}}, {0x33, {0x90, 0x00, 0x72}},
2918c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x03}}, {0x33, {0x90, 0x00, 0x02}},
2928c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa7, 0x02}}, {0x33, {0x90, 0x00, 0x01}},
2938c2ecf20Sopenharmony_ci	{51, {0xff, 0xff, 0xff}},
2948c2ecf20Sopenharmony_ci};
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_cistatic struct idxdata tbl_init_post_alt_3B[] = {
2978c2ecf20Sopenharmony_ci	{0x32, {0x10, 0x01, 0xf8}}, {0x34, {0xce, 0x01, 0xa8}},
2988c2ecf20Sopenharmony_ci	{0x34, {0xd0, 0x66, 0x33}}, {0x34, {0xd2, 0x31, 0x9a}},
2998c2ecf20Sopenharmony_ci	{0x34, {0xd4, 0x94, 0x63}}, {0x34, {0xd6, 0x4b, 0x25}},
3008c2ecf20Sopenharmony_ci	{0x34, {0xd8, 0x26, 0x70}}, {0x34, {0xda, 0x72, 0x4c}},
3018c2ecf20Sopenharmony_ci	{0x34, {0xdc, 0xff, 0x04}}, {0x34, {0xde, 0x01, 0x5b}},
3028c2ecf20Sopenharmony_ci	{0x34, {0xe6, 0x01, 0x13}}, {0x34, {0xee, 0x0b, 0xf0}},
3038c2ecf20Sopenharmony_ci	{0x34, {0xf6, 0x0b, 0xa4}}, {0x35, {0x00, 0xf6, 0xe7}},
3048c2ecf20Sopenharmony_ci	{0x35, {0x08, 0x0d, 0xfd}}, {0x35, {0x10, 0x25, 0x63}},
3058c2ecf20Sopenharmony_ci	{0x35, {0x18, 0x35, 0x6c}}, {0x35, {0x20, 0x42, 0x7e}},
3068c2ecf20Sopenharmony_ci	{0x35, {0x28, 0x19, 0x44}}, {0x35, {0x30, 0x39, 0xd4}},
3078c2ecf20Sopenharmony_ci	{0x35, {0x38, 0xf5, 0xa8}}, {0x35, {0x4c, 0x07, 0x90}},
3088c2ecf20Sopenharmony_ci	{0x35, {0x44, 0x07, 0xb8}}, {0x35, {0x5c, 0x06, 0x88}},
3098c2ecf20Sopenharmony_ci	{0x35, {0x54, 0x07, 0xff}}, {0x34, {0xe0, 0x01, 0x52}},
3108c2ecf20Sopenharmony_ci	{0x34, {0xe8, 0x00, 0xcc}}, {0x34, {0xf0, 0x0d, 0x83}},
3118c2ecf20Sopenharmony_ci	{0x34, {0xf8, 0x0c, 0xb3}}, {0x35, {0x02, 0xfe, 0xba}},
3128c2ecf20Sopenharmony_ci	{0x35, {0x0a, 0x04, 0xe0}}, {0x35, {0x12, 0x1c, 0x63}},
3138c2ecf20Sopenharmony_ci	{0x35, {0x1a, 0x2b, 0x5a}}, {0x35, {0x22, 0x32, 0x5e}},
3148c2ecf20Sopenharmony_ci	{0x35, {0x2a, 0x0d, 0x28}}, {0x35, {0x32, 0x2c, 0x02}},
3158c2ecf20Sopenharmony_ci	{0x35, {0x3a, 0xf4, 0xfa}}, {0x35, {0x4e, 0x07, 0xef}},
3168c2ecf20Sopenharmony_ci	{0x35, {0x46, 0x07, 0x88}}, {0x35, {0x5e, 0x07, 0xc1}},
3178c2ecf20Sopenharmony_ci	{0x35, {0x56, 0x04, 0x64}}, {0x34, {0xe4, 0x01, 0x15}},
3188c2ecf20Sopenharmony_ci	{0x34, {0xec, 0x00, 0x82}}, {0x34, {0xf4, 0x0c, 0xce}},
3198c2ecf20Sopenharmony_ci	{0x34, {0xfc, 0x0c, 0xba}}, {0x35, {0x06, 0x1f, 0x02}},
3208c2ecf20Sopenharmony_ci	{0x35, {0x0e, 0x02, 0xe3}}, {0x35, {0x16, 0x1a, 0x50}},
3218c2ecf20Sopenharmony_ci	{0x35, {0x1e, 0x24, 0x39}}, {0x35, {0x26, 0x23, 0x4c}},
3228c2ecf20Sopenharmony_ci	{0x35, {0x2e, 0xf9, 0x1b}}, {0x35, {0x36, 0x23, 0x19}},
3238c2ecf20Sopenharmony_ci	{0x35, {0x3e, 0x12, 0x08}}, {0x35, {0x52, 0x07, 0x22}},
3248c2ecf20Sopenharmony_ci	{0x35, {0x4a, 0x03, 0xd3}}, {0x35, {0x62, 0x06, 0x54}},
3258c2ecf20Sopenharmony_ci	{0x35, {0x5a, 0x04, 0x5d}}, {0x34, {0xe2, 0x01, 0x04}},
3268c2ecf20Sopenharmony_ci	{0x34, {0xea, 0x00, 0xa0}}, {0x34, {0xf2, 0x0c, 0xbc}},
3278c2ecf20Sopenharmony_ci	{0x34, {0xfa, 0x0c, 0x5b}}, {0x35, {0x04, 0x17, 0xf2}},
3288c2ecf20Sopenharmony_ci	{0x35, {0x0c, 0x02, 0x08}}, {0x35, {0x14, 0x28, 0x43}},
3298c2ecf20Sopenharmony_ci	{0x35, {0x1c, 0x28, 0x62}}, {0x35, {0x24, 0x2b, 0x60}},
3308c2ecf20Sopenharmony_ci	{0x35, {0x2c, 0x07, 0x33}}, {0x35, {0x34, 0x1f, 0xb0}},
3318c2ecf20Sopenharmony_ci	{0x35, {0x3c, 0xed, 0xcd}}, {0x35, {0x50, 0x00, 0x06}},
3328c2ecf20Sopenharmony_ci	{0x35, {0x48, 0x07, 0xff}}, {0x35, {0x60, 0x05, 0x89}},
3338c2ecf20Sopenharmony_ci	{0x35, {0x58, 0x07, 0xff}}, {0x35, {0x40, 0x00, 0xa0}},
3348c2ecf20Sopenharmony_ci	{0x35, {0x42, 0x00, 0x00}}, {0x32, {0x10, 0x01, 0xfc}},
3358c2ecf20Sopenharmony_ci	{0x33, {0x8c, 0xa1, 0x18}}, {0x33, {0x90, 0x00, 0x3c}},
3368c2ecf20Sopenharmony_ci};
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_cistatic u8 *dat_640  = "\xd0\x02\xd1\x08\xd2\xe1\xd3\x02\xd4\x10\xd5\x81";
3398c2ecf20Sopenharmony_cistatic u8 *dat_800  = "\xd0\x02\xd1\x10\xd2\x57\xd3\x02\xd4\x18\xd5\x21";
3408c2ecf20Sopenharmony_cistatic u8 *dat_1280 = "\xd0\x02\xd1\x20\xd2\x01\xd3\x02\xd4\x28\xd5\x01";
3418c2ecf20Sopenharmony_cistatic u8 *dat_1600 = "\xd0\x02\xd1\x20\xd2\xaf\xd3\x02\xd4\x30\xd5\x41";
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_cistatic int  mi2020_init_at_startup(struct gspca_dev *gspca_dev);
3448c2ecf20Sopenharmony_cistatic int  mi2020_configure_alt(struct gspca_dev *gspca_dev);
3458c2ecf20Sopenharmony_cistatic int  mi2020_init_pre_alt(struct gspca_dev *gspca_dev);
3468c2ecf20Sopenharmony_cistatic int  mi2020_init_post_alt(struct gspca_dev *gspca_dev);
3478c2ecf20Sopenharmony_cistatic void mi2020_post_unset_alt(struct gspca_dev *gspca_dev);
3488c2ecf20Sopenharmony_cistatic int  mi2020_camera_settings(struct gspca_dev *gspca_dev);
3498c2ecf20Sopenharmony_ci/*==========================================================================*/
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_civoid mi2020_init_settings(struct gspca_dev *gspca_dev)
3528c2ecf20Sopenharmony_ci{
3538c2ecf20Sopenharmony_ci	struct sd *sd = (struct sd *) gspca_dev;
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	sd->vcur.backlight  =  0;
3568c2ecf20Sopenharmony_ci	sd->vcur.brightness = 70;
3578c2ecf20Sopenharmony_ci	sd->vcur.sharpness  = 20;
3588c2ecf20Sopenharmony_ci	sd->vcur.contrast   =  0;
3598c2ecf20Sopenharmony_ci	sd->vcur.gamma      =  0;
3608c2ecf20Sopenharmony_ci	sd->vcur.hue        =  0;
3618c2ecf20Sopenharmony_ci	sd->vcur.saturation = 60;
3628c2ecf20Sopenharmony_ci	sd->vcur.whitebal   =  0; /* 50, not done by hardware */
3638c2ecf20Sopenharmony_ci	sd->vcur.mirror = 0;
3648c2ecf20Sopenharmony_ci	sd->vcur.flip   = 0;
3658c2ecf20Sopenharmony_ci	sd->vcur.AC50Hz = 1;
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	sd->vmax.backlight  =  64;
3688c2ecf20Sopenharmony_ci	sd->vmax.brightness = 128;
3698c2ecf20Sopenharmony_ci	sd->vmax.sharpness  =  40;
3708c2ecf20Sopenharmony_ci	sd->vmax.contrast   =   3;
3718c2ecf20Sopenharmony_ci	sd->vmax.gamma      =   2;
3728c2ecf20Sopenharmony_ci	sd->vmax.hue        =   0 + 1; /* 200, not done by hardware */
3738c2ecf20Sopenharmony_ci	sd->vmax.saturation =   0;     /* 100, not done by hardware */
3748c2ecf20Sopenharmony_ci	sd->vmax.whitebal   =   2;     /* 100, not done by hardware */
3758c2ecf20Sopenharmony_ci	sd->vmax.mirror = 1;
3768c2ecf20Sopenharmony_ci	sd->vmax.flip   = 1;
3778c2ecf20Sopenharmony_ci	sd->vmax.AC50Hz = 1;
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	sd->dev_camera_settings = mi2020_camera_settings;
3808c2ecf20Sopenharmony_ci	sd->dev_init_at_startup = mi2020_init_at_startup;
3818c2ecf20Sopenharmony_ci	sd->dev_configure_alt   = mi2020_configure_alt;
3828c2ecf20Sopenharmony_ci	sd->dev_init_pre_alt    = mi2020_init_pre_alt;
3838c2ecf20Sopenharmony_ci	sd->dev_post_unset_alt  = mi2020_post_unset_alt;
3848c2ecf20Sopenharmony_ci}
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci/*==========================================================================*/
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_cistatic void common(struct gspca_dev *gspca_dev)
3898c2ecf20Sopenharmony_ci{
3908c2ecf20Sopenharmony_ci	fetch_validx(gspca_dev, tbl_common_0B, ARRAY_SIZE(tbl_common_0B));
3918c2ecf20Sopenharmony_ci	fetch_idxdata(gspca_dev, tbl_common_3B, ARRAY_SIZE(tbl_common_3B));
3928c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x0000, 0, NULL);
3938c2ecf20Sopenharmony_ci}
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_cistatic int mi2020_init_at_startup(struct gspca_dev *gspca_dev)
3968c2ecf20Sopenharmony_ci{
3978c2ecf20Sopenharmony_ci	u8 c;
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci	ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0004, 1, &c);
4008c2ecf20Sopenharmony_ci	ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0004, 1, &c);
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci	fetch_validx(gspca_dev, tbl_init_at_startup,
4038c2ecf20Sopenharmony_ci			ARRAY_SIZE(tbl_init_at_startup));
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40,  1, 0x7a00, 0x8030,  0, NULL);
4068c2ecf20Sopenharmony_ci	ctrl_in(gspca_dev, 0xc0,  2, 0x7a00, 0x8030,  1, &c);
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci	common(gspca_dev);
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	msleep(61);
4118c2ecf20Sopenharmony_ci/*	ctrl_out(gspca_dev, 0x40, 11, 0x0000, 0x0000,  0, NULL); */
4128c2ecf20Sopenharmony_ci/*	msleep(36); */
4138c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40,  1, 0x0001, 0x0000,  0, NULL);
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci	return 0;
4168c2ecf20Sopenharmony_ci}
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_cistatic int mi2020_init_pre_alt(struct gspca_dev *gspca_dev)
4198c2ecf20Sopenharmony_ci{
4208c2ecf20Sopenharmony_ci	struct sd *sd = (struct sd *) gspca_dev;
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	sd->mirrorMask =  0;
4238c2ecf20Sopenharmony_ci	sd->vold.hue   = -1;
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci	/* These controls need to be reset */
4268c2ecf20Sopenharmony_ci	sd->vold.brightness = -1;
4278c2ecf20Sopenharmony_ci	sd->vold.sharpness  = -1;
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci	/* If not different from default, they do not need to be set */
4308c2ecf20Sopenharmony_ci	sd->vold.contrast  = 0;
4318c2ecf20Sopenharmony_ci	sd->vold.gamma     = 0;
4328c2ecf20Sopenharmony_ci	sd->vold.backlight = 0;
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci	mi2020_init_post_alt(gspca_dev);
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	return 0;
4378c2ecf20Sopenharmony_ci}
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_cistatic int mi2020_init_post_alt(struct gspca_dev *gspca_dev)
4408c2ecf20Sopenharmony_ci{
4418c2ecf20Sopenharmony_ci	struct sd *sd = (struct sd *) gspca_dev;
4428c2ecf20Sopenharmony_ci	s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci	s32 mirror = (((sd->vcur.mirror > 0) ^ sd->mirrorMask) > 0);
4458c2ecf20Sopenharmony_ci	s32 flip   = (((sd->vcur.flip   > 0) ^ sd->mirrorMask) > 0);
4468c2ecf20Sopenharmony_ci	s32 freq   = (sd->vcur.AC50Hz  > 0);
4478c2ecf20Sopenharmony_ci	s32 wbal   = sd->vcur.whitebal;
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci	u8 dat_freq2[] = {0x90, 0x00, 0x80};
4508c2ecf20Sopenharmony_ci	u8 dat_multi1[] = {0x8c, 0xa7, 0x00};
4518c2ecf20Sopenharmony_ci	u8 dat_multi2[] = {0x90, 0x00, 0x00};
4528c2ecf20Sopenharmony_ci	u8 dat_multi3[] = {0x8c, 0xa7, 0x00};
4538c2ecf20Sopenharmony_ci	u8 dat_multi4[] = {0x90, 0x00, 0x00};
4548c2ecf20Sopenharmony_ci	u8 dat_hvflip2[] = {0x90, 0x04, 0x6c};
4558c2ecf20Sopenharmony_ci	u8 dat_hvflip4[] = {0x90, 0x00, 0x24};
4568c2ecf20Sopenharmony_ci	u8 dat_wbal2[] = {0x90, 0x00, 0x00};
4578c2ecf20Sopenharmony_ci	u8 c;
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ci	sd->nbIm = -1;
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci	dat_freq2[2] = freq ? 0xc0 : 0x80;
4628c2ecf20Sopenharmony_ci	dat_multi1[2] = 0x9d;
4638c2ecf20Sopenharmony_ci	dat_multi3[2] = dat_multi1[2] + 1;
4648c2ecf20Sopenharmony_ci	if (wbal == 0) {
4658c2ecf20Sopenharmony_ci		dat_multi4[2] = dat_multi2[2] = 0;
4668c2ecf20Sopenharmony_ci		dat_wbal2[2] = 0x17;
4678c2ecf20Sopenharmony_ci	} else if (wbal == 1) {
4688c2ecf20Sopenharmony_ci		dat_multi4[2] = dat_multi2[2] = 0;
4698c2ecf20Sopenharmony_ci		dat_wbal2[2] = 0x35;
4708c2ecf20Sopenharmony_ci	} else if (wbal == 2) {
4718c2ecf20Sopenharmony_ci		dat_multi4[2] = dat_multi2[2] = 0x20;
4728c2ecf20Sopenharmony_ci		dat_wbal2[2] = 0x17;
4738c2ecf20Sopenharmony_ci	}
4748c2ecf20Sopenharmony_ci	dat_hvflip2[2] = 0x6c + 2 * (1 - flip) + (1 - mirror);
4758c2ecf20Sopenharmony_ci	dat_hvflip4[2] = 0x24 + 2 * (1 - flip) + (1 - mirror);
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci	msleep(200);
4788c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 5, 0x0001, 0x0000, 0, NULL);
4798c2ecf20Sopenharmony_ci	msleep(2);
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci	common(gspca_dev);
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci	msleep(142);
4848c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40,  1, 0x0010, 0x0010,  0, NULL);
4858c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40,  1, 0x0003, 0x00c1,  0, NULL);
4868c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40,  1, 0x0042, 0x00c2,  0, NULL);
4878c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40,  1, 0x006a, 0x000d,  0, NULL);
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	switch (reso) {
4908c2ecf20Sopenharmony_ci	case IMAGE_640:
4918c2ecf20Sopenharmony_ci	case IMAGE_800:
4928c2ecf20Sopenharmony_ci		if (reso != IMAGE_800)
4938c2ecf20Sopenharmony_ci			ctrl_out(gspca_dev, 0x40,  3, 0x0000, 0x0200,
4948c2ecf20Sopenharmony_ci				12, dat_640);
4958c2ecf20Sopenharmony_ci		else
4968c2ecf20Sopenharmony_ci			ctrl_out(gspca_dev, 0x40,  3, 0x0000, 0x0200,
4978c2ecf20Sopenharmony_ci				12, dat_800);
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci		fetch_idxdata(gspca_dev, tbl_init_post_alt_low1,
5008c2ecf20Sopenharmony_ci					ARRAY_SIZE(tbl_init_post_alt_low1));
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci		if (reso == IMAGE_800)
5038c2ecf20Sopenharmony_ci			fetch_idxdata(gspca_dev, tbl_init_post_alt_low2,
5048c2ecf20Sopenharmony_ci					ARRAY_SIZE(tbl_init_post_alt_low2));
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ci		fetch_idxdata(gspca_dev, tbl_init_post_alt_low3,
5078c2ecf20Sopenharmony_ci				ARRAY_SIZE(tbl_init_post_alt_low3));
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 1, 0x0010, 0x0010, 0, NULL);
5108c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);
5118c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);
5128c2ecf20Sopenharmony_ci		msleep(120);
5138c2ecf20Sopenharmony_ci		break;
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ci	case IMAGE_1280:
5168c2ecf20Sopenharmony_ci	case IMAGE_1600:
5178c2ecf20Sopenharmony_ci		if (reso == IMAGE_1280) {
5188c2ecf20Sopenharmony_ci			ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
5198c2ecf20Sopenharmony_ci					12, dat_1280);
5208c2ecf20Sopenharmony_ci			ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
5218c2ecf20Sopenharmony_ci					3, "\x8c\x27\x07");
5228c2ecf20Sopenharmony_ci			ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
5238c2ecf20Sopenharmony_ci					3, "\x90\x05\x04");
5248c2ecf20Sopenharmony_ci			ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
5258c2ecf20Sopenharmony_ci					3, "\x8c\x27\x09");
5268c2ecf20Sopenharmony_ci			ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
5278c2ecf20Sopenharmony_ci					3, "\x90\x04\x02");
5288c2ecf20Sopenharmony_ci		} else {
5298c2ecf20Sopenharmony_ci			ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
5308c2ecf20Sopenharmony_ci					12, dat_1600);
5318c2ecf20Sopenharmony_ci			ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
5328c2ecf20Sopenharmony_ci					3, "\x8c\x27\x07");
5338c2ecf20Sopenharmony_ci			ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
5348c2ecf20Sopenharmony_ci					3, "\x90\x06\x40");
5358c2ecf20Sopenharmony_ci			ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
5368c2ecf20Sopenharmony_ci					3, "\x8c\x27\x09");
5378c2ecf20Sopenharmony_ci			ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
5388c2ecf20Sopenharmony_ci					3, "\x90\x04\xb0");
5398c2ecf20Sopenharmony_ci		}
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci		fetch_idxdata(gspca_dev, tbl_init_post_alt_big,
5428c2ecf20Sopenharmony_ci				ARRAY_SIZE(tbl_init_post_alt_big));
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0010, 0, NULL);
5458c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);
5468c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);
5478c2ecf20Sopenharmony_ci		msleep(1850);
5488c2ecf20Sopenharmony_ci	}
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 1, 0x0040, 0x0000, 0, NULL);
5518c2ecf20Sopenharmony_ci	msleep(40);
5528c2ecf20Sopenharmony_ci
5538c2ecf20Sopenharmony_ci	/* AC power frequency */
5548c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq1);
5558c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq2);
5568c2ecf20Sopenharmony_ci	msleep(33);
5578c2ecf20Sopenharmony_ci	/* light source */
5588c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
5598c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
5608c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
5618c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);
5628c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_wbal1);
5638c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_wbal2);
5648c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
5658c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
5668c2ecf20Sopenharmony_ci	msleep(7);
5678c2ecf20Sopenharmony_ci	ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0000, 1, &c);
5688c2ecf20Sopenharmony_ci
5698c2ecf20Sopenharmony_ci	fetch_idxdata(gspca_dev, tbl_init_post_alt_3B,
5708c2ecf20Sopenharmony_ci			ARRAY_SIZE(tbl_init_post_alt_3B));
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ci	/* hvflip */
5738c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip1);
5748c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip2);
5758c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip3);
5768c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip4);
5778c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip5);
5788c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip6);
5798c2ecf20Sopenharmony_ci	msleep(250);
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_ci	if (reso == IMAGE_640 || reso == IMAGE_800)
5828c2ecf20Sopenharmony_ci		fetch_idxdata(gspca_dev, tbl_middle_hvflip_low,
5838c2ecf20Sopenharmony_ci				ARRAY_SIZE(tbl_middle_hvflip_low));
5848c2ecf20Sopenharmony_ci	else
5858c2ecf20Sopenharmony_ci		fetch_idxdata(gspca_dev, tbl_middle_hvflip_big,
5868c2ecf20Sopenharmony_ci				ARRAY_SIZE(tbl_middle_hvflip_big));
5878c2ecf20Sopenharmony_ci
5888c2ecf20Sopenharmony_ci	fetch_idxdata(gspca_dev, tbl_end_hvflip,
5898c2ecf20Sopenharmony_ci			ARRAY_SIZE(tbl_end_hvflip));
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_ci	sd->nbIm = 0;
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci	sd->vold.mirror    = mirror;
5948c2ecf20Sopenharmony_ci	sd->vold.flip      = flip;
5958c2ecf20Sopenharmony_ci	sd->vold.AC50Hz    = freq;
5968c2ecf20Sopenharmony_ci	sd->vold.whitebal  = wbal;
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ci	mi2020_camera_settings(gspca_dev);
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci	return 0;
6018c2ecf20Sopenharmony_ci}
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_cistatic int mi2020_configure_alt(struct gspca_dev *gspca_dev)
6048c2ecf20Sopenharmony_ci{
6058c2ecf20Sopenharmony_ci	s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
6068c2ecf20Sopenharmony_ci
6078c2ecf20Sopenharmony_ci	switch (reso) {
6088c2ecf20Sopenharmony_ci	case IMAGE_640:
6098c2ecf20Sopenharmony_ci		gspca_dev->alt = 3 + 1;
6108c2ecf20Sopenharmony_ci		break;
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_ci	case IMAGE_800:
6138c2ecf20Sopenharmony_ci	case IMAGE_1280:
6148c2ecf20Sopenharmony_ci	case IMAGE_1600:
6158c2ecf20Sopenharmony_ci		gspca_dev->alt = 1 + 1;
6168c2ecf20Sopenharmony_ci		break;
6178c2ecf20Sopenharmony_ci	}
6188c2ecf20Sopenharmony_ci	return 0;
6198c2ecf20Sopenharmony_ci}
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_cistatic int mi2020_camera_settings(struct gspca_dev *gspca_dev)
6228c2ecf20Sopenharmony_ci{
6238c2ecf20Sopenharmony_ci	struct sd *sd = (struct sd *) gspca_dev;
6248c2ecf20Sopenharmony_ci	s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_ci	s32 backlight = sd->vcur.backlight;
6278c2ecf20Sopenharmony_ci	s32 bright =  sd->vcur.brightness;
6288c2ecf20Sopenharmony_ci	s32 sharp  =  sd->vcur.sharpness;
6298c2ecf20Sopenharmony_ci	s32 cntr   =  sd->vcur.contrast;
6308c2ecf20Sopenharmony_ci	s32 gam	   =  sd->vcur.gamma;
6318c2ecf20Sopenharmony_ci	s32 hue    = (sd->vcur.hue > 0);
6328c2ecf20Sopenharmony_ci	s32 mirror = (((sd->vcur.mirror > 0) ^ sd->mirrorMask) > 0);
6338c2ecf20Sopenharmony_ci	s32 flip   = (((sd->vcur.flip   > 0) ^ sd->mirrorMask) > 0);
6348c2ecf20Sopenharmony_ci	s32 freq   = (sd->vcur.AC50Hz > 0);
6358c2ecf20Sopenharmony_ci	s32 wbal   = sd->vcur.whitebal;
6368c2ecf20Sopenharmony_ci
6378c2ecf20Sopenharmony_ci	u8 dat_sharp[] = {0x6c, 0x00, 0x08};
6388c2ecf20Sopenharmony_ci	u8 dat_bright2[] = {0x90, 0x00, 0x00};
6398c2ecf20Sopenharmony_ci	u8 dat_freq2[] = {0x90, 0x00, 0x80};
6408c2ecf20Sopenharmony_ci	u8 dat_multi1[] = {0x8c, 0xa7, 0x00};
6418c2ecf20Sopenharmony_ci	u8 dat_multi2[] = {0x90, 0x00, 0x00};
6428c2ecf20Sopenharmony_ci	u8 dat_multi3[] = {0x8c, 0xa7, 0x00};
6438c2ecf20Sopenharmony_ci	u8 dat_multi4[] = {0x90, 0x00, 0x00};
6448c2ecf20Sopenharmony_ci	u8 dat_hvflip2[] = {0x90, 0x04, 0x6c};
6458c2ecf20Sopenharmony_ci	u8 dat_hvflip4[] = {0x90, 0x00, 0x24};
6468c2ecf20Sopenharmony_ci	u8 dat_wbal2[] = {0x90, 0x00, 0x00};
6478c2ecf20Sopenharmony_ci
6488c2ecf20Sopenharmony_ci	/* Less than 4 images received -> too early to set the settings */
6498c2ecf20Sopenharmony_ci	if (sd->nbIm < 4) {
6508c2ecf20Sopenharmony_ci		sd->waitSet = 1;
6518c2ecf20Sopenharmony_ci		return 0;
6528c2ecf20Sopenharmony_ci	}
6538c2ecf20Sopenharmony_ci	sd->waitSet = 0;
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_ci	if (freq != sd->vold.AC50Hz) {
6568c2ecf20Sopenharmony_ci		sd->vold.AC50Hz = freq;
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_ci		dat_freq2[2] = freq ? 0xc0 : 0x80;
6598c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq1);
6608c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq2);
6618c2ecf20Sopenharmony_ci		msleep(20);
6628c2ecf20Sopenharmony_ci	}
6638c2ecf20Sopenharmony_ci
6648c2ecf20Sopenharmony_ci	if (wbal != sd->vold.whitebal) {
6658c2ecf20Sopenharmony_ci		sd->vold.whitebal = wbal;
6668c2ecf20Sopenharmony_ci		if (wbal < 0 || wbal > sd->vmax.whitebal)
6678c2ecf20Sopenharmony_ci			wbal = 0;
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_ci		dat_multi1[2] = 0x9d;
6708c2ecf20Sopenharmony_ci		dat_multi3[2] = dat_multi1[2] + 1;
6718c2ecf20Sopenharmony_ci		if (wbal == 0) {
6728c2ecf20Sopenharmony_ci			dat_multi4[2] = dat_multi2[2] = 0;
6738c2ecf20Sopenharmony_ci			dat_wbal2[2] = 0x17;
6748c2ecf20Sopenharmony_ci		} else if (wbal == 1) {
6758c2ecf20Sopenharmony_ci			dat_multi4[2] = dat_multi2[2] = 0;
6768c2ecf20Sopenharmony_ci			dat_wbal2[2] = 0x35;
6778c2ecf20Sopenharmony_ci		} else if (wbal == 2) {
6788c2ecf20Sopenharmony_ci			dat_multi4[2] = dat_multi2[2] = 0x20;
6798c2ecf20Sopenharmony_ci			dat_wbal2[2] = 0x17;
6808c2ecf20Sopenharmony_ci		}
6818c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
6828c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
6838c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
6848c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);
6858c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_wbal1);
6868c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_wbal2);
6878c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
6888c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
6898c2ecf20Sopenharmony_ci	}
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_ci	if (mirror != sd->vold.mirror || flip != sd->vold.flip) {
6928c2ecf20Sopenharmony_ci		sd->vold.mirror = mirror;
6938c2ecf20Sopenharmony_ci		sd->vold.flip   = flip;
6948c2ecf20Sopenharmony_ci
6958c2ecf20Sopenharmony_ci		dat_hvflip2[2] = 0x6c + 2 * (1 - flip) + (1 - mirror);
6968c2ecf20Sopenharmony_ci		dat_hvflip4[2] = 0x24 + 2 * (1 - flip) + (1 - mirror);
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_ci		fetch_idxdata(gspca_dev, tbl_init_post_alt_3B,
6998c2ecf20Sopenharmony_ci				ARRAY_SIZE(tbl_init_post_alt_3B));
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip1);
7028c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip2);
7038c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip3);
7048c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip4);
7058c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip5);
7068c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip6);
7078c2ecf20Sopenharmony_ci		msleep(40);
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_ci		if (reso == IMAGE_640 || reso == IMAGE_800)
7108c2ecf20Sopenharmony_ci			fetch_idxdata(gspca_dev, tbl_middle_hvflip_low,
7118c2ecf20Sopenharmony_ci					ARRAY_SIZE(tbl_middle_hvflip_low));
7128c2ecf20Sopenharmony_ci		else
7138c2ecf20Sopenharmony_ci			fetch_idxdata(gspca_dev, tbl_middle_hvflip_big,
7148c2ecf20Sopenharmony_ci					ARRAY_SIZE(tbl_middle_hvflip_big));
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_ci		fetch_idxdata(gspca_dev, tbl_end_hvflip,
7178c2ecf20Sopenharmony_ci				ARRAY_SIZE(tbl_end_hvflip));
7188c2ecf20Sopenharmony_ci	}
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_ci	if (bright != sd->vold.brightness) {
7218c2ecf20Sopenharmony_ci		sd->vold.brightness = bright;
7228c2ecf20Sopenharmony_ci		if (bright < 0 || bright > sd->vmax.brightness)
7238c2ecf20Sopenharmony_ci			bright = 0;
7248c2ecf20Sopenharmony_ci
7258c2ecf20Sopenharmony_ci		dat_bright2[2] = bright;
7268c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright1);
7278c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright2);
7288c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright3);
7298c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright4);
7308c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright5);
7318c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright6);
7328c2ecf20Sopenharmony_ci	}
7338c2ecf20Sopenharmony_ci
7348c2ecf20Sopenharmony_ci	if (cntr != sd->vold.contrast || gam != sd->vold.gamma) {
7358c2ecf20Sopenharmony_ci		sd->vold.contrast = cntr;
7368c2ecf20Sopenharmony_ci		if (cntr < 0 || cntr > sd->vmax.contrast)
7378c2ecf20Sopenharmony_ci			cntr = 0;
7388c2ecf20Sopenharmony_ci		sd->vold.gamma = gam;
7398c2ecf20Sopenharmony_ci		if (gam < 0 || gam > sd->vmax.gamma)
7408c2ecf20Sopenharmony_ci			gam = 0;
7418c2ecf20Sopenharmony_ci
7428c2ecf20Sopenharmony_ci		dat_multi1[2] = 0x6d;
7438c2ecf20Sopenharmony_ci		dat_multi3[2] = dat_multi1[2] + 1;
7448c2ecf20Sopenharmony_ci		if (cntr == 0)
7458c2ecf20Sopenharmony_ci			cntr = 4;
7468c2ecf20Sopenharmony_ci		dat_multi4[2] = dat_multi2[2] = cntr * 0x10 + 2 - gam;
7478c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
7488c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
7498c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
7508c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);
7518c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
7528c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
7538c2ecf20Sopenharmony_ci	}
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_ci	if (backlight != sd->vold.backlight) {
7568c2ecf20Sopenharmony_ci		sd->vold.backlight = backlight;
7578c2ecf20Sopenharmony_ci		if (backlight < 0 || backlight > sd->vmax.backlight)
7588c2ecf20Sopenharmony_ci			backlight = 0;
7598c2ecf20Sopenharmony_ci
7608c2ecf20Sopenharmony_ci		dat_multi1[2] = 0x9d;
7618c2ecf20Sopenharmony_ci		dat_multi3[2] = dat_multi1[2] + 1;
7628c2ecf20Sopenharmony_ci		dat_multi4[2] = dat_multi2[2] = backlight;
7638c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
7648c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
7658c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
7668c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);
7678c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
7688c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
7698c2ecf20Sopenharmony_ci	}
7708c2ecf20Sopenharmony_ci
7718c2ecf20Sopenharmony_ci	if (sharp != sd->vold.sharpness) {
7728c2ecf20Sopenharmony_ci		sd->vold.sharpness = sharp;
7738c2ecf20Sopenharmony_ci		if (sharp < 0 || sharp > sd->vmax.sharpness)
7748c2ecf20Sopenharmony_ci			sharp = 0;
7758c2ecf20Sopenharmony_ci
7768c2ecf20Sopenharmony_ci		dat_sharp[1] = sharp;
7778c2ecf20Sopenharmony_ci		ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0032, 3, dat_sharp);
7788c2ecf20Sopenharmony_ci	}
7798c2ecf20Sopenharmony_ci
7808c2ecf20Sopenharmony_ci	if (hue != sd->vold.hue) {
7818c2ecf20Sopenharmony_ci		sd->swapRB = hue;
7828c2ecf20Sopenharmony_ci		sd->vold.hue = hue;
7838c2ecf20Sopenharmony_ci	}
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ci	return 0;
7868c2ecf20Sopenharmony_ci}
7878c2ecf20Sopenharmony_ci
7888c2ecf20Sopenharmony_cistatic void mi2020_post_unset_alt(struct gspca_dev *gspca_dev)
7898c2ecf20Sopenharmony_ci{
7908c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 5, 0x0000, 0x0000, 0, NULL);
7918c2ecf20Sopenharmony_ci	msleep(40);
7928c2ecf20Sopenharmony_ci	ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0000, 0, NULL);
7938c2ecf20Sopenharmony_ci}
794