Path: blob/master/drivers/media/video/gspca/gl860/gl860-mi2020.c
17885 views
/* Subdriver for the GL860 chip with the MI2020 sensor1* Author Olivier LORIN, from logs by Iceman/Soro2005 + Fret_saw/Hulkie/Tricid2* with the help of Kytrix/BUGabundo/Blazercist.3* Driver achieved thanks to a webcam gift by Kytrix.4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program. If not, see <http://www.gnu.org/licenses/>.17*/1819/* Sensor : MI2020 */2021#include "gl860.h"2223static u8 dat_wbal1[] = {0x8c, 0xa2, 0x0c};2425static u8 dat_bright1[] = {0x8c, 0xa2, 0x06};26static u8 dat_bright3[] = {0x8c, 0xa1, 0x02};27static u8 dat_bright4[] = {0x90, 0x00, 0x0f};28static u8 dat_bright5[] = {0x8c, 0xa1, 0x03};29static u8 dat_bright6[] = {0x90, 0x00, 0x05};3031static u8 dat_hvflip1[] = {0x8c, 0x27, 0x19};32static u8 dat_hvflip3[] = {0x8c, 0x27, 0x3b};33static u8 dat_hvflip5[] = {0x8c, 0xa1, 0x03};34static u8 dat_hvflip6[] = {0x90, 0x00, 0x06};3536static struct idxdata tbl_middle_hvflip_low[] = {37{0x33, "\x90\x00\x06"},38{6, "\xff\xff\xff"},39{0x33, "\x90\x00\x06"},40{6, "\xff\xff\xff"},41{0x33, "\x90\x00\x06"},42{6, "\xff\xff\xff"},43{0x33, "\x90\x00\x06"},44{6, "\xff\xff\xff"},45};4647static struct idxdata tbl_middle_hvflip_big[] = {48{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x01"}, {0x33, "\x8c\xa1\x20"},49{0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x00"},50{102, "\xff\xff\xff"},51{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x02"}, {0x33, "\x8c\xa1\x20"},52{0x33, "\x90\x00\x72"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x01"},53};5455static struct idxdata tbl_end_hvflip[] = {56{0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"},57{6, "\xff\xff\xff"},58{0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"},59{6, "\xff\xff\xff"},60{0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"},61{6, "\xff\xff\xff"},62{0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"},63};6465static u8 dat_freq1[] = { 0x8c, 0xa4, 0x04 };6667static u8 dat_multi5[] = { 0x8c, 0xa1, 0x03 };68static u8 dat_multi6[] = { 0x90, 0x00, 0x05 };6970static struct validx tbl_init_at_startup[] = {71{0x0000, 0x0000}, {0x0010, 0x0010}, {0x0008, 0x00c0}, {0x0001, 0x00c1},72{0x0001, 0x00c2}, {0x0020, 0x0006}, {0x006a, 0x000d},73{53, 0xffff},74{0x0040, 0x0000}, {0x0063, 0x0006},75};7677static struct validx tbl_common_0B[] = {78{0x0002, 0x0004}, {0x006a, 0x0007}, {0x00ef, 0x0006}, {0x006a, 0x000d},79{0x0000, 0x00c0}, {0x0010, 0x0010}, {0x0003, 0x00c1}, {0x0042, 0x00c2},80{0x0004, 0x00d8}, {0x0000, 0x0058}, {0x0041, 0x0000},81};8283static struct idxdata tbl_common_3B[] = {84{0x33, "\x86\x25\x01"}, {0x33, "\x86\x25\x00"},85{2, "\xff\xff\xff"},86{0x30, "\x1a\x0a\xcc"}, {0x32, "\x02\x00\x08"}, {0x33, "\xf4\x03\x1d"},87{6, "\xff\xff\xff"}, /* 12 */88{0x34, "\x1e\x8f\x09"}, {0x34, "\x1c\x01\x28"}, {0x34, "\x1e\x8f\x09"},89{2, "\xff\xff\xff"}, /* - */90{0x34, "\x1e\x8f\x09"}, {0x32, "\x14\x06\xe6"}, {0x33, "\x8c\x22\x23"},91{0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa2\x0f"}, {0x33, "\x90\x00\x0d"},92{0x33, "\x8c\xa2\x10"}, {0x33, "\x90\x00\x0b"}, {0x33, "\x8c\xa2\x11"},93{0x33, "\x90\x00\x07"}, {0x33, "\xf4\x03\x1d"}, {0x35, "\xa2\x00\xe2"},94{0x33, "\x8c\xab\x05"}, {0x33, "\x90\x00\x01"}, {0x32, "\x6e\x00\x86"},95{0x32, "\x70\x0f\xaa"}, {0x32, "\x72\x0f\xe4"}, {0x33, "\x8c\xa3\x4a"},96{0x33, "\x90\x00\x5a"}, {0x33, "\x8c\xa3\x4b"}, {0x33, "\x90\x00\xa6"},97{0x33, "\x8c\xa3\x61"}, {0x33, "\x90\x00\xc8"}, {0x33, "\x8c\xa3\x62"},98{0x33, "\x90\x00\xe1"}, {0x34, "\xce\x01\xa8"}, {0x34, "\xd0\x66\x33"},99{0x34, "\xd2\x31\x9a"}, {0x34, "\xd4\x94\x63"}, {0x34, "\xd6\x4b\x25"},100{0x34, "\xd8\x26\x70"}, {0x34, "\xda\x72\x4c"}, {0x34, "\xdc\xff\x04"},101{0x34, "\xde\x01\x5b"}, {0x34, "\xe6\x01\x13"}, {0x34, "\xee\x0b\xf0"},102{0x34, "\xf6\x0b\xa4"}, {0x35, "\x00\xf6\xe7"}, {0x35, "\x08\x0d\xfd"},103{0x35, "\x10\x25\x63"}, {0x35, "\x18\x35\x6c"}, {0x35, "\x20\x42\x7e"},104{0x35, "\x28\x19\x44"}, {0x35, "\x30\x39\xd4"}, {0x35, "\x38\xf5\xa8"},105{0x35, "\x4c\x07\x90"}, {0x35, "\x44\x07\xb8"}, {0x35, "\x5c\x06\x88"},106{0x35, "\x54\x07\xff"}, {0x34, "\xe0\x01\x52"}, {0x34, "\xe8\x00\xcc"},107{0x34, "\xf0\x0d\x83"}, {0x34, "\xf8\x0c\xb3"}, {0x35, "\x02\xfe\xba"},108{0x35, "\x0a\x04\xe0"}, {0x35, "\x12\x1c\x63"}, {0x35, "\x1a\x2b\x5a"},109{0x35, "\x22\x32\x5e"}, {0x35, "\x2a\x0d\x28"}, {0x35, "\x32\x2c\x02"},110{0x35, "\x3a\xf4\xfa"}, {0x35, "\x4e\x07\xef"}, {0x35, "\x46\x07\x88"},111{0x35, "\x5e\x07\xc1"}, {0x35, "\x56\x04\x64"}, {0x34, "\xe4\x01\x15"},112{0x34, "\xec\x00\x82"}, {0x34, "\xf4\x0c\xce"}, {0x34, "\xfc\x0c\xba"},113{0x35, "\x06\x1f\x02"}, {0x35, "\x0e\x02\xe3"}, {0x35, "\x16\x1a\x50"},114{0x35, "\x1e\x24\x39"}, {0x35, "\x26\x23\x4c"}, {0x35, "\x2e\xf9\x1b"},115{0x35, "\x36\x23\x19"}, {0x35, "\x3e\x12\x08"}, {0x35, "\x52\x07\x22"},116{0x35, "\x4a\x03\xd3"}, {0x35, "\x62\x06\x54"}, {0x35, "\x5a\x04\x5d"},117{0x34, "\xe2\x01\x04"}, {0x34, "\xea\x00\xa0"}, {0x34, "\xf2\x0c\xbc"},118{0x34, "\xfa\x0c\x5b"}, {0x35, "\x04\x17\xf2"}, {0x35, "\x0c\x02\x08"},119{0x35, "\x14\x28\x43"}, {0x35, "\x1c\x28\x62"}, {0x35, "\x24\x2b\x60"},120{0x35, "\x2c\x07\x33"}, {0x35, "\x34\x1f\xb0"}, {0x35, "\x3c\xed\xcd"},121{0x35, "\x50\x00\x06"}, {0x35, "\x48\x07\xff"}, {0x35, "\x60\x05\x89"},122{0x35, "\x58\x07\xff"}, {0x35, "\x40\x00\xa0"}, {0x35, "\x42\x00\x00"},123{0x32, "\x10\x01\xfc"}, {0x33, "\x8c\xa1\x18"}, {0x33, "\x90\x00\x3c"},124{0x33, "\x78\x00\x00"},125{2, "\xff\xff\xff"},126{0x35, "\xb8\x1f\x20"}, {0x33, "\x8c\xa2\x06"}, {0x33, "\x90\x00\x10"},127{0x33, "\x8c\xa2\x07"}, {0x33, "\x90\x00\x08"}, {0x33, "\x8c\xa2\x42"},128{0x33, "\x90\x00\x0b"}, {0x33, "\x8c\xa2\x4a"}, {0x33, "\x90\x00\x8c"},129{0x35, "\xba\xfa\x08"}, {0x33, "\x8c\xa2\x02"}, {0x33, "\x90\x00\x22"},130{0x33, "\x8c\xa2\x03"}, {0x33, "\x90\x00\xbb"}, {0x33, "\x8c\xa4\x04"},131{0x33, "\x90\x00\x80"}, {0x33, "\x8c\xa7\x9d"}, {0x33, "\x90\x00\x00"},132{0x33, "\x8c\xa7\x9e"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa2\x0c"},133{0x33, "\x90\x00\x17"}, {0x33, "\x8c\xa2\x15"}, {0x33, "\x90\x00\x04"},134{0x33, "\x8c\xa2\x14"}, {0x33, "\x90\x00\x20"}, {0x33, "\x8c\xa1\x03"},135{0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x17"}, {0x33, "\x90\x21\x11"},136{0x33, "\x8c\x27\x1b"}, {0x33, "\x90\x02\x4f"}, {0x33, "\x8c\x27\x25"},137{0x33, "\x90\x06\x0f"}, {0x33, "\x8c\x27\x39"}, {0x33, "\x90\x21\x11"},138{0x33, "\x8c\x27\x3d"}, {0x33, "\x90\x01\x20"}, {0x33, "\x8c\x27\x47"},139{0x33, "\x90\x09\x4c"}, {0x33, "\x8c\x27\x03"}, {0x33, "\x90\x02\x84"},140{0x33, "\x8c\x27\x05"}, {0x33, "\x90\x01\xe2"}, {0x33, "\x8c\x27\x07"},141{0x33, "\x90\x06\x40"}, {0x33, "\x8c\x27\x09"}, {0x33, "\x90\x04\xb0"},142{0x33, "\x8c\x27\x0d"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x0f"},143{0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x11"}, {0x33, "\x90\x04\xbd"},144{0x33, "\x8c\x27\x13"}, {0x33, "\x90\x06\x4d"}, {0x33, "\x8c\x27\x15"},145{0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x17"}, {0x33, "\x90\x21\x11"},146{0x33, "\x8c\x27\x19"}, {0x33, "\x90\x04\x6c"}, {0x33, "\x8c\x27\x1b"},147{0x33, "\x90\x02\x4f"}, {0x33, "\x8c\x27\x1d"}, {0x33, "\x90\x01\x02"},148{0x33, "\x8c\x27\x1f"}, {0x33, "\x90\x02\x79"}, {0x33, "\x8c\x27\x21"},149{0x33, "\x90\x01\x55"}, {0x33, "\x8c\x27\x23"}, {0x33, "\x90\x02\x85"},150{0x33, "\x8c\x27\x25"}, {0x33, "\x90\x06\x0f"}, {0x33, "\x8c\x27\x27"},151{0x33, "\x90\x20\x20"}, {0x33, "\x8c\x27\x29"}, {0x33, "\x90\x20\x20"},152{0x33, "\x8c\x27\x2b"}, {0x33, "\x90\x10\x20"}, {0x33, "\x8c\x27\x2d"},153{0x33, "\x90\x20\x07"}, {0x33, "\x8c\x27\x2f"}, {0x33, "\x90\x00\x04"},154{0x33, "\x8c\x27\x31"}, {0x33, "\x90\x00\x04"}, {0x33, "\x8c\x27\x33"},155{0x33, "\x90\x04\xbb"}, {0x33, "\x8c\x27\x35"}, {0x33, "\x90\x06\x4b"},156{0x33, "\x8c\x27\x37"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x39"},157{0x33, "\x90\x21\x11"}, {0x33, "\x8c\x27\x3b"}, {0x33, "\x90\x00\x24"},158{0x33, "\x8c\x27\x3d"}, {0x33, "\x90\x01\x20"}, {0x33, "\x8c\x27\x41"},159{0x33, "\x90\x01\x69"}, {0x33, "\x8c\x27\x45"}, {0x33, "\x90\x04\xed"},160{0x33, "\x8c\x27\x47"}, {0x33, "\x90\x09\x4c"}, {0x33, "\x8c\x27\x51"},161{0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x53"}, {0x33, "\x90\x03\x20"},162{0x33, "\x8c\x27\x55"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x57"},163{0x33, "\x90\x02\x58"}, {0x33, "\x8c\x27\x5f"}, {0x33, "\x90\x00\x00"},164{0x33, "\x8c\x27\x61"}, {0x33, "\x90\x06\x40"}, {0x33, "\x8c\x27\x63"},165{0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x65"}, {0x33, "\x90\x04\xb0"},166{0x33, "\x8c\x22\x2e"}, {0x33, "\x90\x00\xa1"}, {0x33, "\x8c\xa4\x08"},167{0x33, "\x90\x00\x1f"}, {0x33, "\x8c\xa4\x09"}, {0x33, "\x90\x00\x21"},168{0x33, "\x8c\xa4\x0a"}, {0x33, "\x90\x00\x25"}, {0x33, "\x8c\xa4\x0b"},169{0x33, "\x90\x00\x27"}, {0x33, "\x8c\x24\x11"}, {0x33, "\x90\x00\xa1"},170{0x33, "\x8c\x24\x13"}, {0x33, "\x90\x00\xc1"}, {0x33, "\x8c\x24\x15"},171{0x33, "\x90\x00\x6a"}, {0x33, "\x8c\x24\x17"}, {0x33, "\x90\x00\x80"},172{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},173{2, "\xff\xff\xff"},174{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},175{3, "\xff\xff\xff"},176};177178static struct idxdata tbl_init_post_alt_low1[] = {179{0x33, "\x8c\x27\x15"}, {0x33, "\x90\x00\x25"}, {0x33, "\x8c\x22\x2e"},180{0x33, "\x90\x00\x81"}, {0x33, "\x8c\xa4\x08"}, {0x33, "\x90\x00\x17"},181{0x33, "\x8c\xa4\x09"}, {0x33, "\x90\x00\x1a"}, {0x33, "\x8c\xa4\x0a"},182{0x33, "\x90\x00\x1d"}, {0x33, "\x8c\xa4\x0b"}, {0x33, "\x90\x00\x20"},183{0x33, "\x8c\x24\x11"}, {0x33, "\x90\x00\x81"}, {0x33, "\x8c\x24\x13"},184{0x33, "\x90\x00\x9b"},185};186187static struct idxdata tbl_init_post_alt_low2[] = {188{0x33, "\x8c\x27\x03"}, {0x33, "\x90\x03\x24"}, {0x33, "\x8c\x27\x05"},189{0x33, "\x90\x02\x58"}, {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},190{2, "\xff\xff\xff"},191{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},192{2, "\xff\xff\xff"},193};194195static struct idxdata tbl_init_post_alt_low3[] = {196{0x34, "\x1e\x8f\x09"}, {0x34, "\x1c\x01\x28"}, {0x34, "\x1e\x8f\x09"},197{2, "\xff\xff\xff"},198{0x34, "\x1e\x8f\x09"}, {0x32, "\x14\x06\xe6"}, {0x33, "\x8c\xa1\x20"},199{0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x01"},200{0x33, "\x2e\x01\x00"}, {0x34, "\x04\x00\x2a"}, {0x33, "\x8c\xa7\x02"},201{0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x95"}, {0x33, "\x90\x01\x00"},202{2, "\xff\xff\xff"},203{0x33, "\x8c\xa1\x20"}, {0x33, "\x90\x00\x72"}, {0x33, "\x8c\xa1\x03"},204{0x33, "\x90\x00\x02"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x01"},205{2, "\xff\xff\xff"},206{0x33, "\x8c\xa1\x20"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa1\x03"},207{0x33, "\x90\x00\x01"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x00"},208{2, "\xff\xff\xff"},209{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},210{2, "\xff\xff\xff"},211{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},212{2, "\xff\xff\xff"},213{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},214{2, "\xff\xff\xff"},215{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},216};217218static struct idxdata tbl_init_post_alt_big[] = {219{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},220{2, "\xff\xff\xff"},221{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},222{2, "\xff\xff\xff"},223{0x34, "\x1e\x8f\x09"}, {0x34, "\x1c\x01\x28"}, {0x34, "\x1e\x8f\x09"},224{2, "\xff\xff\xff"},225{0x34, "\x1e\x8f\x09"}, {0x32, "\x14\x06\xe6"}, {0x33, "\x8c\xa1\x03"},226{0x33, "\x90\x00\x05"},227{2, "\xff\xff\xff"},228{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},229{2, "\xff\xff\xff"},230{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},231{2, "\xff\xff\xff"},232{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"}, {0x33, "\x8c\xa1\x20"},233{0x33, "\x90\x00\x72"}, {0x33, "\x8c\xa1\x30"}, {0x33, "\x90\x00\x03"},234{0x33, "\x8c\xa1\x31"}, {0x33, "\x90\x00\x02"}, {0x33, "\x8c\xa1\x32"},235{0x33, "\x90\x00\x03"}, {0x33, "\x8c\xa1\x34"}, {0x33, "\x90\x00\x03"},236{0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x02"}, {0x33, "\x2e\x01\x00"},237{0x34, "\x04\x00\x2a"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x01"},238{0x33, "\x8c\x27\x97"}, {0x33, "\x90\x01\x00"},239{51, "\xff\xff\xff"},240{0x33, "\x8c\xa1\x20"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa1\x03"},241{0x33, "\x90\x00\x01"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x00"},242{51, "\xff\xff\xff"},243{0x33, "\x8c\xa1\x20"}, {0x33, "\x90\x00\x72"}, {0x33, "\x8c\xa1\x03"},244{0x33, "\x90\x00\x02"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x01"},245{51, "\xff\xff\xff"},246};247248static struct idxdata tbl_init_post_alt_3B[] = {249{0x32, "\x10\x01\xf8"}, {0x34, "\xce\x01\xa8"}, {0x34, "\xd0\x66\x33"},250{0x34, "\xd2\x31\x9a"}, {0x34, "\xd4\x94\x63"}, {0x34, "\xd6\x4b\x25"},251{0x34, "\xd8\x26\x70"}, {0x34, "\xda\x72\x4c"}, {0x34, "\xdc\xff\x04"},252{0x34, "\xde\x01\x5b"}, {0x34, "\xe6\x01\x13"}, {0x34, "\xee\x0b\xf0"},253{0x34, "\xf6\x0b\xa4"}, {0x35, "\x00\xf6\xe7"}, {0x35, "\x08\x0d\xfd"},254{0x35, "\x10\x25\x63"}, {0x35, "\x18\x35\x6c"}, {0x35, "\x20\x42\x7e"},255{0x35, "\x28\x19\x44"}, {0x35, "\x30\x39\xd4"}, {0x35, "\x38\xf5\xa8"},256{0x35, "\x4c\x07\x90"}, {0x35, "\x44\x07\xb8"}, {0x35, "\x5c\x06\x88"},257{0x35, "\x54\x07\xff"}, {0x34, "\xe0\x01\x52"}, {0x34, "\xe8\x00\xcc"},258{0x34, "\xf0\x0d\x83"}, {0x34, "\xf8\x0c\xb3"}, {0x35, "\x02\xfe\xba"},259{0x35, "\x0a\x04\xe0"}, {0x35, "\x12\x1c\x63"}, {0x35, "\x1a\x2b\x5a"},260{0x35, "\x22\x32\x5e"}, {0x35, "\x2a\x0d\x28"}, {0x35, "\x32\x2c\x02"},261{0x35, "\x3a\xf4\xfa"}, {0x35, "\x4e\x07\xef"}, {0x35, "\x46\x07\x88"},262{0x35, "\x5e\x07\xc1"}, {0x35, "\x56\x04\x64"}, {0x34, "\xe4\x01\x15"},263{0x34, "\xec\x00\x82"}, {0x34, "\xf4\x0c\xce"}, {0x34, "\xfc\x0c\xba"},264{0x35, "\x06\x1f\x02"}, {0x35, "\x0e\x02\xe3"}, {0x35, "\x16\x1a\x50"},265{0x35, "\x1e\x24\x39"}, {0x35, "\x26\x23\x4c"}, {0x35, "\x2e\xf9\x1b"},266{0x35, "\x36\x23\x19"}, {0x35, "\x3e\x12\x08"}, {0x35, "\x52\x07\x22"},267{0x35, "\x4a\x03\xd3"}, {0x35, "\x62\x06\x54"}, {0x35, "\x5a\x04\x5d"},268{0x34, "\xe2\x01\x04"}, {0x34, "\xea\x00\xa0"}, {0x34, "\xf2\x0c\xbc"},269{0x34, "\xfa\x0c\x5b"}, {0x35, "\x04\x17\xf2"}, {0x35, "\x0c\x02\x08"},270{0x35, "\x14\x28\x43"}, {0x35, "\x1c\x28\x62"}, {0x35, "\x24\x2b\x60"},271{0x35, "\x2c\x07\x33"}, {0x35, "\x34\x1f\xb0"}, {0x35, "\x3c\xed\xcd"},272{0x35, "\x50\x00\x06"}, {0x35, "\x48\x07\xff"}, {0x35, "\x60\x05\x89"},273{0x35, "\x58\x07\xff"}, {0x35, "\x40\x00\xa0"}, {0x35, "\x42\x00\x00"},274{0x32, "\x10\x01\xfc"}, {0x33, "\x8c\xa1\x18"}, {0x33, "\x90\x00\x3c"},275};276277static u8 *dat_640 = "\xd0\x02\xd1\x08\xd2\xe1\xd3\x02\xd4\x10\xd5\x81";278static u8 *dat_800 = "\xd0\x02\xd1\x10\xd2\x57\xd3\x02\xd4\x18\xd5\x21";279static u8 *dat_1280 = "\xd0\x02\xd1\x20\xd2\x01\xd3\x02\xd4\x28\xd5\x01";280static u8 *dat_1600 = "\xd0\x02\xd1\x20\xd2\xaf\xd3\x02\xd4\x30\xd5\x41";281282static int mi2020_init_at_startup(struct gspca_dev *gspca_dev);283static int mi2020_configure_alt(struct gspca_dev *gspca_dev);284static int mi2020_init_pre_alt(struct gspca_dev *gspca_dev);285static int mi2020_init_post_alt(struct gspca_dev *gspca_dev);286static void mi2020_post_unset_alt(struct gspca_dev *gspca_dev);287static int mi2020_camera_settings(struct gspca_dev *gspca_dev);288/*==========================================================================*/289290void mi2020_init_settings(struct gspca_dev *gspca_dev)291{292struct sd *sd = (struct sd *) gspca_dev;293294sd->vcur.backlight = 0;295sd->vcur.brightness = 70;296sd->vcur.sharpness = 20;297sd->vcur.contrast = 0;298sd->vcur.gamma = 0;299sd->vcur.hue = 0;300sd->vcur.saturation = 60;301sd->vcur.whitebal = 0; /* 50, not done by hardware */302sd->vcur.mirror = 0;303sd->vcur.flip = 0;304sd->vcur.AC50Hz = 1;305306sd->vmax.backlight = 64;307sd->vmax.brightness = 128;308sd->vmax.sharpness = 40;309sd->vmax.contrast = 3;310sd->vmax.gamma = 2;311sd->vmax.hue = 0 + 1; /* 200, not done by hardware */312sd->vmax.saturation = 0; /* 100, not done by hardware */313sd->vmax.whitebal = 2; /* 100, not done by hardware */314sd->vmax.mirror = 1;315sd->vmax.flip = 1;316sd->vmax.AC50Hz = 1;317318sd->dev_camera_settings = mi2020_camera_settings;319sd->dev_init_at_startup = mi2020_init_at_startup;320sd->dev_configure_alt = mi2020_configure_alt;321sd->dev_init_pre_alt = mi2020_init_pre_alt;322sd->dev_post_unset_alt = mi2020_post_unset_alt;323}324325/*==========================================================================*/326327static void common(struct gspca_dev *gspca_dev)328{329fetch_validx(gspca_dev, tbl_common_0B, ARRAY_SIZE(tbl_common_0B));330fetch_idxdata(gspca_dev, tbl_common_3B, ARRAY_SIZE(tbl_common_3B));331ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x0000, 0, NULL);332}333334static int mi2020_init_at_startup(struct gspca_dev *gspca_dev)335{336u8 c;337338ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0004, 1, &c);339ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0004, 1, &c);340341fetch_validx(gspca_dev, tbl_init_at_startup,342ARRAY_SIZE(tbl_init_at_startup));343344ctrl_out(gspca_dev, 0x40, 1, 0x7a00, 0x8030, 0, NULL);345ctrl_in(gspca_dev, 0xc0, 2, 0x7a00, 0x8030, 1, &c);346347common(gspca_dev);348349msleep(61);350/* ctrl_out(gspca_dev, 0x40, 11, 0x0000, 0x0000, 0, NULL); */351/* msleep(36); */352ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0000, 0, NULL);353354return 0;355}356357static int mi2020_init_pre_alt(struct gspca_dev *gspca_dev)358{359struct sd *sd = (struct sd *) gspca_dev;360361sd->mirrorMask = 0;362sd->vold.hue = -1;363364/* These controls need to be reset */365sd->vold.brightness = -1;366sd->vold.sharpness = -1;367368/* If not different from default, they do not need to be set */369sd->vold.contrast = 0;370sd->vold.gamma = 0;371sd->vold.backlight = 0;372373mi2020_init_post_alt(gspca_dev);374375return 0;376}377378static int mi2020_init_post_alt(struct gspca_dev *gspca_dev)379{380struct sd *sd = (struct sd *) gspca_dev;381s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;382383s32 mirror = (((sd->vcur.mirror > 0) ^ sd->mirrorMask) > 0);384s32 flip = (((sd->vcur.flip > 0) ^ sd->mirrorMask) > 0);385s32 freq = (sd->vcur.AC50Hz > 0);386s32 wbal = sd->vcur.whitebal;387388u8 dat_freq2[] = {0x90, 0x00, 0x80};389u8 dat_multi1[] = {0x8c, 0xa7, 0x00};390u8 dat_multi2[] = {0x90, 0x00, 0x00};391u8 dat_multi3[] = {0x8c, 0xa7, 0x00};392u8 dat_multi4[] = {0x90, 0x00, 0x00};393u8 dat_hvflip2[] = {0x90, 0x04, 0x6c};394u8 dat_hvflip4[] = {0x90, 0x00, 0x24};395u8 dat_wbal2[] = {0x90, 0x00, 0x00};396u8 c;397398sd->nbIm = -1;399400dat_freq2[2] = freq ? 0xc0 : 0x80;401dat_multi1[2] = 0x9d;402dat_multi3[2] = dat_multi1[2] + 1;403if (wbal == 0) {404dat_multi4[2] = dat_multi2[2] = 0;405dat_wbal2[2] = 0x17;406} else if (wbal == 1) {407dat_multi4[2] = dat_multi2[2] = 0;408dat_wbal2[2] = 0x35;409} else if (wbal == 2) {410dat_multi4[2] = dat_multi2[2] = 0x20;411dat_wbal2[2] = 0x17;412}413dat_hvflip2[2] = 0x6c + 2 * (1 - flip) + (1 - mirror);414dat_hvflip4[2] = 0x24 + 2 * (1 - flip) + (1 - mirror);415416msleep(200);417ctrl_out(gspca_dev, 0x40, 5, 0x0001, 0x0000, 0, NULL);418msleep(2);419420common(gspca_dev);421422msleep(142);423ctrl_out(gspca_dev, 0x40, 1, 0x0010, 0x0010, 0, NULL);424ctrl_out(gspca_dev, 0x40, 1, 0x0003, 0x00c1, 0, NULL);425ctrl_out(gspca_dev, 0x40, 1, 0x0042, 0x00c2, 0, NULL);426ctrl_out(gspca_dev, 0x40, 1, 0x006a, 0x000d, 0, NULL);427428switch (reso) {429case IMAGE_640:430case IMAGE_800:431if (reso != IMAGE_800)432ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,43312, dat_640);434else435ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,43612, dat_800);437438fetch_idxdata(gspca_dev, tbl_init_post_alt_low1,439ARRAY_SIZE(tbl_init_post_alt_low1));440441if (reso == IMAGE_800)442fetch_idxdata(gspca_dev, tbl_init_post_alt_low2,443ARRAY_SIZE(tbl_init_post_alt_low2));444445fetch_idxdata(gspca_dev, tbl_init_post_alt_low3,446ARRAY_SIZE(tbl_init_post_alt_low3));447448ctrl_out(gspca_dev, 0x40, 1, 0x0010, 0x0010, 0, NULL);449ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);450ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);451msleep(120);452break;453454case IMAGE_1280:455case IMAGE_1600:456if (reso == IMAGE_1280) {457ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,45812, dat_1280);459ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,4603, "\x8c\x27\x07");461ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,4623, "\x90\x05\x04");463ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,4643, "\x8c\x27\x09");465ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,4663, "\x90\x04\x02");467} else {468ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,46912, dat_1600);470ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,4713, "\x8c\x27\x07");472ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,4733, "\x90\x06\x40");474ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,4753, "\x8c\x27\x09");476ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,4773, "\x90\x04\xb0");478}479480fetch_idxdata(gspca_dev, tbl_init_post_alt_big,481ARRAY_SIZE(tbl_init_post_alt_big));482483ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0010, 0, NULL);484ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);485ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);486msleep(1850);487}488489ctrl_out(gspca_dev, 0x40, 1, 0x0040, 0x0000, 0, NULL);490msleep(40);491492/* AC power frequency */493ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq1);494ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq2);495msleep(33);496/* light source */497ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);498ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);499ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);500ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);501ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_wbal1);502ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_wbal2);503ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);504ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);505msleep(7);506ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0000, 1, &c);507508fetch_idxdata(gspca_dev, tbl_init_post_alt_3B,509ARRAY_SIZE(tbl_init_post_alt_3B));510511/* hvflip */512ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip1);513ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip2);514ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip3);515ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip4);516ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip5);517ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip6);518msleep(250);519520if (reso == IMAGE_640 || reso == IMAGE_800)521fetch_idxdata(gspca_dev, tbl_middle_hvflip_low,522ARRAY_SIZE(tbl_middle_hvflip_low));523else524fetch_idxdata(gspca_dev, tbl_middle_hvflip_big,525ARRAY_SIZE(tbl_middle_hvflip_big));526527fetch_idxdata(gspca_dev, tbl_end_hvflip,528ARRAY_SIZE(tbl_end_hvflip));529530sd->nbIm = 0;531532sd->vold.mirror = mirror;533sd->vold.flip = flip;534sd->vold.AC50Hz = freq;535sd->vold.whitebal = wbal;536537mi2020_camera_settings(gspca_dev);538539return 0;540}541542static int mi2020_configure_alt(struct gspca_dev *gspca_dev)543{544s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;545546switch (reso) {547case IMAGE_640:548gspca_dev->alt = 3 + 1;549break;550551case IMAGE_800:552case IMAGE_1280:553case IMAGE_1600:554gspca_dev->alt = 1 + 1;555break;556}557return 0;558}559560static int mi2020_camera_settings(struct gspca_dev *gspca_dev)561{562struct sd *sd = (struct sd *) gspca_dev;563s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;564565s32 backlight = sd->vcur.backlight;566s32 bright = sd->vcur.brightness;567s32 sharp = sd->vcur.sharpness;568s32 cntr = sd->vcur.contrast;569s32 gam = sd->vcur.gamma;570s32 hue = (sd->vcur.hue > 0);571s32 mirror = (((sd->vcur.mirror > 0) ^ sd->mirrorMask) > 0);572s32 flip = (((sd->vcur.flip > 0) ^ sd->mirrorMask) > 0);573s32 freq = (sd->vcur.AC50Hz > 0);574s32 wbal = sd->vcur.whitebal;575576u8 dat_sharp[] = {0x6c, 0x00, 0x08};577u8 dat_bright2[] = {0x90, 0x00, 0x00};578u8 dat_freq2[] = {0x90, 0x00, 0x80};579u8 dat_multi1[] = {0x8c, 0xa7, 0x00};580u8 dat_multi2[] = {0x90, 0x00, 0x00};581u8 dat_multi3[] = {0x8c, 0xa7, 0x00};582u8 dat_multi4[] = {0x90, 0x00, 0x00};583u8 dat_hvflip2[] = {0x90, 0x04, 0x6c};584u8 dat_hvflip4[] = {0x90, 0x00, 0x24};585u8 dat_wbal2[] = {0x90, 0x00, 0x00};586587/* Less than 4 images received -> too early to set the settings */588if (sd->nbIm < 4) {589sd->waitSet = 1;590return 0;591}592sd->waitSet = 0;593594if (freq != sd->vold.AC50Hz) {595sd->vold.AC50Hz = freq;596597dat_freq2[2] = freq ? 0xc0 : 0x80;598ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq1);599ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq2);600msleep(20);601}602603if (wbal != sd->vold.whitebal) {604sd->vold.whitebal = wbal;605if (wbal < 0 || wbal > sd->vmax.whitebal)606wbal = 0;607608dat_multi1[2] = 0x9d;609dat_multi3[2] = dat_multi1[2] + 1;610if (wbal == 0) {611dat_multi4[2] = dat_multi2[2] = 0;612dat_wbal2[2] = 0x17;613} else if (wbal == 1) {614dat_multi4[2] = dat_multi2[2] = 0;615dat_wbal2[2] = 0x35;616} else if (wbal == 2) {617dat_multi4[2] = dat_multi2[2] = 0x20;618dat_wbal2[2] = 0x17;619}620ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);621ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);622ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);623ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);624ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_wbal1);625ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_wbal2);626ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);627ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);628}629630if (mirror != sd->vold.mirror || flip != sd->vold.flip) {631sd->vold.mirror = mirror;632sd->vold.flip = flip;633634dat_hvflip2[2] = 0x6c + 2 * (1 - flip) + (1 - mirror);635dat_hvflip4[2] = 0x24 + 2 * (1 - flip) + (1 - mirror);636637fetch_idxdata(gspca_dev, tbl_init_post_alt_3B,638ARRAY_SIZE(tbl_init_post_alt_3B));639640ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip1);641ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip2);642ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip3);643ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip4);644ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip5);645ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip6);646msleep(40);647648if (reso == IMAGE_640 || reso == IMAGE_800)649fetch_idxdata(gspca_dev, tbl_middle_hvflip_low,650ARRAY_SIZE(tbl_middle_hvflip_low));651else652fetch_idxdata(gspca_dev, tbl_middle_hvflip_big,653ARRAY_SIZE(tbl_middle_hvflip_big));654655fetch_idxdata(gspca_dev, tbl_end_hvflip,656ARRAY_SIZE(tbl_end_hvflip));657}658659if (bright != sd->vold.brightness) {660sd->vold.brightness = bright;661if (bright < 0 || bright > sd->vmax.brightness)662bright = 0;663664dat_bright2[2] = bright;665ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright1);666ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright2);667ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright3);668ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright4);669ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright5);670ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright6);671}672673if (cntr != sd->vold.contrast || gam != sd->vold.gamma) {674sd->vold.contrast = cntr;675if (cntr < 0 || cntr > sd->vmax.contrast)676cntr = 0;677sd->vold.gamma = gam;678if (gam < 0 || gam > sd->vmax.gamma)679gam = 0;680681dat_multi1[2] = 0x6d;682dat_multi3[2] = dat_multi1[2] + 1;683if (cntr == 0)684cntr = 4;685dat_multi4[2] = dat_multi2[2] = cntr * 0x10 + 2 - gam;686ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);687ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);688ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);689ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);690ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);691ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);692}693694if (backlight != sd->vold.backlight) {695sd->vold.backlight = backlight;696if (backlight < 0 || backlight > sd->vmax.backlight)697backlight = 0;698699dat_multi1[2] = 0x9d;700dat_multi3[2] = dat_multi1[2] + 1;701dat_multi4[2] = dat_multi2[2] = backlight;702ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);703ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);704ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);705ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);706ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);707ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);708}709710if (sharp != sd->vold.sharpness) {711sd->vold.sharpness = sharp;712if (sharp < 0 || sharp > sd->vmax.sharpness)713sharp = 0;714715dat_sharp[1] = sharp;716ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0032, 3, dat_sharp);717}718719if (hue != sd->vold.hue) {720sd->swapRB = hue;721sd->vold.hue = hue;722}723724return 0;725}726727static void mi2020_post_unset_alt(struct gspca_dev *gspca_dev)728{729ctrl_out(gspca_dev, 0x40, 5, 0x0000, 0x0000, 0, NULL);730msleep(40);731ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0000, 0, NULL);732}733734735