gl860-mi2020.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. /* Subdriver for the GL860 chip with the MI2020 sensor
  2. * Author Olivier LORIN, from Ice/Soro2005's logs(A), Fret_saw/Hulkie's
  3. * logs(B) and Tricid"s logs(C). With the help of Kytrix/BUGabundo/Blazercist.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* Sensor : MI2020 */
  19. #include "gl860.h"
  20. static u8 dat_bright1[] = {0x8c, 0xa2, 0x06};
  21. static u8 dat_bright3[] = {0x8c, 0xa1, 0x02};
  22. static u8 dat_bright4[] = {0x90, 0x00, 0x0f};
  23. static u8 dat_bright5[] = {0x8c, 0xa1, 0x03};
  24. static u8 dat_bright6[] = {0x90, 0x00, 0x05};
  25. static u8 dat_dummy1[] = {0x90, 0x00, 0x06};
  26. /*static u8 dummy2[] = {0x8c, 0xa1, 0x02};*/
  27. /*static u8 dummy3[] = {0x90, 0x00, 0x1f};*/
  28. static u8 dat_hvflip1[] = {0x8c, 0x27, 0x19};
  29. static u8 dat_hvflip3[] = {0x8c, 0x27, 0x3b};
  30. static u8 dat_hvflip5[] = {0x8c, 0xa1, 0x03};
  31. static u8 dat_hvflip6[] = {0x90, 0x00, 0x06};
  32. static u8 dat_freq1[] = { 0x8c, 0xa4, 0x04 };
  33. static u8 dat_multi5[] = { 0x8c, 0xa1, 0x03 };
  34. static u8 dat_multi6[] = { 0x90, 0x00, 0x05 };
  35. static struct validx tbl_common1[] = {
  36. {0x0000, 0x0000},
  37. {1, 0xffff}, /* msleep(35); */
  38. {0x006a, 0x0007}, {0x0063, 0x0006}, {0x006a, 0x000d}, {0x0000, 0x00c0},
  39. {0x0010, 0x0010}, {0x0003, 0x00c1}, {0x0042, 0x00c2}, {0x0004, 0x00d8},
  40. {0x0000, 0x0058}, {0x0002, 0x0004}, {0x0041, 0x0000},
  41. };
  42. static struct validx tbl_common2[] = {
  43. {0x006a, 0x0007},
  44. {35, 0xffff},
  45. {0x00ef, 0x0006},
  46. {35, 0xffff},
  47. {0x006a, 0x000d},
  48. {35, 0xffff},
  49. {0x0000, 0x00c0}, {0x0010, 0x0010}, {0x0003, 0x00c1}, {0x0042, 0x00c2},
  50. {0x0004, 0x00d8}, {0x0000, 0x0058}, {0x0041, 0x0000},
  51. };
  52. static struct idxdata tbl_common3[] = {
  53. {0x32, "\x02\x00\x08"}, {0x33, "\xf4\x03\x1d"},
  54. {6, "\xff\xff\xff"}, /* 12 */
  55. {0x34, "\x1e\x8f\x09"}, {0x34, "\x1c\x01\x28"}, {0x34, "\x1e\x8f\x09"},
  56. {2, "\xff\xff\xff"}, /* - */
  57. {0x34, "\x1e\x8f\x09"}, {0x32, "\x14\x06\xe6"}, {0x33, "\x8c\x22\x23"},
  58. {0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa2\x0f"}, {0x33, "\x90\x00\x0d"},
  59. {0x33, "\x8c\xa2\x10"}, {0x33, "\x90\x00\x0b"}, {0x33, "\x8c\xa2\x11"},
  60. {0x33, "\x90\x00\x07"}, {0x33, "\xf4\x03\x1d"}, {0x35, "\xa2\x00\xe2"},
  61. {0x33, "\x8c\xab\x05"}, {0x33, "\x90\x00\x01"}, {0x32, "\x6e\x00\x86"},
  62. {0x32, "\x70\x0f\xaa"}, {0x32, "\x72\x0f\xe4"}, {0x33, "\x8c\xa3\x4a"},
  63. {0x33, "\x90\x00\x5a"}, {0x33, "\x8c\xa3\x4b"}, {0x33, "\x90\x00\xa6"},
  64. {0x33, "\x8c\xa3\x61"}, {0x33, "\x90\x00\xc8"}, {0x33, "\x8c\xa3\x62"},
  65. {0x33, "\x90\x00\xe1"}, {0x34, "\xce\x01\xa8"}, {0x34, "\xd0\x66\x33"},
  66. {0x34, "\xd2\x31\x9a"}, {0x34, "\xd4\x94\x63"}, {0x34, "\xd6\x4b\x25"},
  67. {0x34, "\xd8\x26\x70"}, {0x34, "\xda\x72\x4c"}, {0x34, "\xdc\xff\x04"},
  68. {0x34, "\xde\x01\x5b"}, {0x34, "\xe6\x01\x13"}, {0x34, "\xee\x0b\xf0"},
  69. {0x34, "\xf6\x0b\xa4"}, {0x35, "\x00\xf6\xe7"}, {0x35, "\x08\x0d\xfd"},
  70. {0x35, "\x10\x25\x63"}, {0x35, "\x18\x35\x6c"}, {0x35, "\x20\x42\x7e"},
  71. {0x35, "\x28\x19\x44"}, {0x35, "\x30\x39\xd4"}, {0x35, "\x38\xf5\xa8"},
  72. {0x35, "\x4c\x07\x90"}, {0x35, "\x44\x07\xb8"}, {0x35, "\x5c\x06\x88"},
  73. {0x35, "\x54\x07\xff"}, {0x34, "\xe0\x01\x52"}, {0x34, "\xe8\x00\xcc"},
  74. {0x34, "\xf0\x0d\x83"}, {0x34, "\xf8\x0c\xb3"}, {0x35, "\x02\xfe\xba"},
  75. {0x35, "\x0a\x04\xe0"}, {0x35, "\x12\x1c\x63"}, {0x35, "\x1a\x2b\x5a"},
  76. {0x35, "\x22\x32\x5e"}, {0x35, "\x2a\x0d\x28"}, {0x35, "\x32\x2c\x02"},
  77. {0x35, "\x3a\xf4\xfa"}, {0x35, "\x4e\x07\xef"}, {0x35, "\x46\x07\x88"},
  78. {0x35, "\x5e\x07\xc1"}, {0x35, "\x56\x04\x64"}, {0x34, "\xe4\x01\x15"},
  79. {0x34, "\xec\x00\x82"}, {0x34, "\xf4\x0c\xce"}, {0x34, "\xfc\x0c\xba"},
  80. {0x35, "\x06\x1f\x02"}, {0x35, "\x0e\x02\xe3"}, {0x35, "\x16\x1a\x50"},
  81. {0x35, "\x1e\x24\x39"}, {0x35, "\x26\x23\x4c"}, {0x35, "\x2e\xf9\x1b"},
  82. {0x35, "\x36\x23\x19"}, {0x35, "\x3e\x12\x08"}, {0x35, "\x52\x07\x22"},
  83. {0x35, "\x4a\x03\xd3"}, {0x35, "\x62\x06\x54"}, {0x35, "\x5a\x04\x5d"},
  84. {0x34, "\xe2\x01\x04"}, {0x34, "\xea\x00\xa0"}, {0x34, "\xf2\x0c\xbc"},
  85. {0x34, "\xfa\x0c\x5b"}, {0x35, "\x04\x17\xf2"}, {0x35, "\x0c\x02\x08"},
  86. {0x35, "\x14\x28\x43"}, {0x35, "\x1c\x28\x62"}, {0x35, "\x24\x2b\x60"},
  87. {0x35, "\x2c\x07\x33"}, {0x35, "\x34\x1f\xb0"}, {0x35, "\x3c\xed\xcd"},
  88. {0x35, "\x50\x00\x06"}, {0x35, "\x48\x07\xff"}, {0x35, "\x60\x05\x89"},
  89. {0x35, "\x58\x07\xff"}, {0x35, "\x40\x00\xa0"}, {0x35, "\x42\x00\x00"},
  90. {0x32, "\x10\x01\xfc"}, {0x33, "\x8c\xa1\x18"}, {0x33, "\x90\x00\x3c"},
  91. {1, "\xff\xff\xff"},
  92. {0x33, "\x78\x00\x00"},
  93. {1, "\xff\xff\xff"},
  94. {0x35, "\xb8\x1f\x20"}, {0x33, "\x8c\xa2\x06"}, {0x33, "\x90\x00\x10"},
  95. {0x33, "\x8c\xa2\x07"}, {0x33, "\x90\x00\x08"}, {0x33, "\x8c\xa2\x42"},
  96. {0x33, "\x90\x00\x0b"}, {0x33, "\x8c\xa2\x4a"}, {0x33, "\x90\x00\x8c"},
  97. {0x35, "\xba\xfa\x08"}, {0x33, "\x8c\xa2\x02"}, {0x33, "\x90\x00\x22"},
  98. {0x33, "\x8c\xa2\x03"}, {0x33, "\x90\x00\xbb"},
  99. };
  100. static struct idxdata tbl_common4[] = {
  101. {0x33, "\x8c\x22\x2e"}, {0x33, "\x90\x00\xa0"}, {0x33, "\x8c\xa4\x08"},
  102. {0x33, "\x90\x00\x1f"}, {0x33, "\x8c\xa4\x09"}, {0x33, "\x90\x00\x21"},
  103. {0x33, "\x8c\xa4\x0a"}, {0x33, "\x90\x00\x25"}, {0x33, "\x8c\xa4\x0b"},
  104. {0x33, "\x90\x00\x27"}, {0x33, "\x8c\x24\x11"}, {0x33, "\x90\x00\xa0"},
  105. {0x33, "\x8c\x24\x13"}, {0x33, "\x90\x00\xc0"}, {0x33, "\x8c\x24\x15"},
  106. {0x33, "\x90\x00\xa0"}, {0x33, "\x8c\x24\x17"}, {0x33, "\x90\x00\xc0"},
  107. };
  108. static struct idxdata tbl_common5[] = {
  109. {0x33, "\x8c\xa4\x04"}, {0x33, "\x90\x00\x80"}, {0x33, "\x8c\xa7\x9d"},
  110. {0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa7\x9e"}, {0x33, "\x90\x00\x00"},
  111. {0x33, "\x8c\xa2\x0c"}, {0x33, "\x90\x00\x17"}, {0x33, "\x8c\xa2\x15"},
  112. {0x33, "\x90\x00\x04"}, {0x33, "\x8c\xa2\x14"}, {0x33, "\x90\x00\x20"},
  113. {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x17"},
  114. /* msleep(53); */
  115. {0x33, "\x90\x21\x11"}, {0x33, "\x8c\x27\x1b"}, {0x33, "\x90\x02\x4f"},
  116. {0x33, "\x8c\x27\x25"}, {0x33, "\x90\x06\x0f"}, {0x33, "\x8c\x27\x39"},
  117. {0x33, "\x90\x21\x11"}, {0x33, "\x8c\x27\x3d"}, {0x33, "\x90\x01\x20"},
  118. {0x33, "\x8c\x27\x47"}, {0x33, "\x90\x09\x4c"}, {0x33, "\x8c\x27\x03"},
  119. {0x33, "\x90\x02\x84"}, {0x33, "\x8c\x27\x05"}, {0x33, "\x90\x01\xe2"},
  120. {0x33, "\x8c\x27\x07"}, {0x33, "\x90\x06\x40"}, {0x33, "\x8c\x27\x09"},
  121. {0x33, "\x90\x04\xb0"}, {0x33, "\x8c\x27\x0d"}, {0x33, "\x90\x00\x00"},
  122. {0x33, "\x8c\x27\x0f"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x11"},
  123. {0x33, "\x90\x04\xbd"}, {0x33, "\x8c\x27\x13"}, {0x33, "\x90\x06\x4d"},
  124. {0x33, "\x8c\x27\x15"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x17"},
  125. {0x33, "\x90\x21\x11"}, {0x33, "\x8c\x27\x19"}, {0x33, "\x90\x04\x6c"},
  126. {0x33, "\x8c\x27\x1b"}, {0x33, "\x90\x02\x4f"}, {0x33, "\x8c\x27\x1d"},
  127. {0x33, "\x90\x01\x02"}, {0x33, "\x8c\x27\x1f"}, {0x33, "\x90\x02\x79"},
  128. {0x33, "\x8c\x27\x21"}, {0x33, "\x90\x01\x55"}, {0x33, "\x8c\x27\x23"},
  129. {0x33, "\x90\x02\x85"}, {0x33, "\x8c\x27\x25"}, {0x33, "\x90\x06\x0f"},
  130. {0x33, "\x8c\x27\x27"}, {0x33, "\x90\x20\x20"}, {0x33, "\x8c\x27\x29"},
  131. {0x33, "\x90\x20\x20"}, {0x33, "\x8c\x27\x2b"}, {0x33, "\x90\x10\x20"},
  132. {0x33, "\x8c\x27\x2d"}, {0x33, "\x90\x20\x07"}, {0x33, "\x8c\x27\x2f"},
  133. {0x33, "\x90\x00\x04"}, {0x33, "\x8c\x27\x31"}, {0x33, "\x90\x00\x04"},
  134. {0x33, "\x8c\x27\x33"}, {0x33, "\x90\x04\xbb"}, {0x33, "\x8c\x27\x35"},
  135. {0x33, "\x90\x06\x4b"}, {0x33, "\x8c\x27\x37"}, {0x33, "\x90\x00\x00"},
  136. {0x33, "\x8c\x27\x39"}, {0x33, "\x90\x21\x11"}, {0x33, "\x8c\x27\x3b"},
  137. {0x33, "\x90\x00\x24"}, {0x33, "\x8c\x27\x3d"}, {0x33, "\x90\x01\x20"},
  138. {0x33, "\x8c\x27\x41"}, {0x33, "\x90\x01\x69"}, {0x33, "\x8c\x27\x45"},
  139. {0x33, "\x90\x04\xed"}, {0x33, "\x8c\x27\x47"}, {0x33, "\x90\x09\x4c"},
  140. {0x33, "\x8c\x27\x51"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x53"},
  141. {0x33, "\x90\x03\x20"}, {0x33, "\x8c\x27\x55"}, {0x33, "\x90\x00\x00"},
  142. {0x33, "\x8c\x27\x57"}, {0x33, "\x90\x02\x58"}, {0x33, "\x8c\x27\x5f"},
  143. {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x61"}, {0x33, "\x90\x06\x40"},
  144. {0x33, "\x8c\x27\x63"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x65"},
  145. {0x33, "\x90\x04\xb0"}, {0x33, "\x8c\x22\x2e"}, {0x33, "\x90\x00\xa1"},
  146. {0x33, "\x8c\xa4\x08"}, {0x33, "\x90\x00\x1f"}, {0x33, "\x8c\xa4\x09"},
  147. {0x33, "\x90\x00\x21"}, {0x33, "\x8c\xa4\x0a"}, {0x33, "\x90\x00\x25"},
  148. {0x33, "\x8c\xa4\x0b"}, {0x33, "\x90\x00\x27"}, {0x33, "\x8c\x24\x11"},
  149. {0x33, "\x90\x00\xa1"}, {0x33, "\x8c\x24\x13"}, {0x33, "\x90\x00\xc1"},
  150. {0x33, "\x8c\x24\x15"},
  151. };
  152. static struct validx tbl_init_at_startup[] = {
  153. {0x0000, 0x0000},
  154. {53, 0xffff},
  155. {0x0010, 0x0010},
  156. {53, 0xffff},
  157. {0x0008, 0x00c0},
  158. {53, 0xffff},
  159. {0x0001, 0x00c1},
  160. {53, 0xffff},
  161. {0x0001, 0x00c2},
  162. {53, 0xffff},
  163. {0x0020, 0x0006},
  164. {53, 0xffff},
  165. {0x006a, 0x000d},
  166. {53, 0xffff},
  167. };
  168. static struct idxdata tbl_init_post_alt_low1[] = {
  169. {0x33, "\x8c\x27\x15"}, {0x33, "\x90\x00\x25"}, {0x33, "\x8c\x22\x2e"},
  170. {0x33, "\x90\x00\x81"}, {0x33, "\x8c\xa4\x08"}, {0x33, "\x90\x00\x17"},
  171. {0x33, "\x8c\xa4\x09"}, {0x33, "\x90\x00\x1a"}, {0x33, "\x8c\xa4\x0a"},
  172. {0x33, "\x90\x00\x1d"}, {0x33, "\x8c\xa4\x0b"}, {0x33, "\x90\x00\x20"},
  173. {0x33, "\x8c\x24\x11"}, {0x33, "\x90\x00\x81"}, {0x33, "\x8c\x24\x13"},
  174. {0x33, "\x90\x00\x9b"},
  175. };
  176. static struct idxdata tbl_init_post_alt_low2[] = {
  177. {0x33, "\x8c\x27\x03"}, {0x33, "\x90\x03\x24"}, {0x33, "\x8c\x27\x05"},
  178. {0x33, "\x90\x02\x58"}, {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},
  179. {2, "\xff\xff\xff"},
  180. {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},
  181. {2, "\xff\xff\xff"},
  182. };
  183. static struct idxdata tbl_init_post_alt_low3[] = {
  184. {0x34, "\x1e\x8f\x09"}, {0x34, "\x1c\x01\x28"}, {0x34, "\x1e\x8f\x09"},
  185. {2, "\xff\xff\xff"},
  186. {0x34, "\x1e\x8f\x09"}, {0x32, "\x14\x06\xe6"}, {0x33, "\x8c\xa1\x20"},
  187. {0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x01"},
  188. {0x33, "\x2e\x01\x00"}, {0x34, "\x04\x00\x2a"}, {0x33, "\x8c\xa7\x02"},
  189. {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x95"}, {0x33, "\x90\x01\x00"},
  190. {2, "\xff\xff\xff"},
  191. {0x33, "\x8c\xa1\x20"}, {0x33, "\x90\x00\x72"}, {0x33, "\x8c\xa1\x03"},
  192. {0x33, "\x90\x00\x02"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x01"},
  193. {2, "\xff\xff\xff"},
  194. {0x33, "\x8c\xa1\x20"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa1\x03"},
  195. {0x33, "\x90\x00\x01"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x00"},
  196. {2, "\xff\xff\xff"}, /* - * */
  197. {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},
  198. {2, "\xff\xff\xff"},
  199. {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},
  200. {2, "\xff\xff\xff"},
  201. {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},
  202. {2, "\xff\xff\xff"},
  203. {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},
  204. {1, "\xff\xff\xff"},
  205. };
  206. static struct idxdata tbl_init_post_alt_low4[] = {
  207. {0x32, "\x10\x01\xf8"}, {0x34, "\xce\x01\xa8"}, {0x34, "\xd0\x66\x33"},
  208. {0x34, "\xd2\x31\x9a"}, {0x34, "\xd4\x94\x63"}, {0x34, "\xd6\x4b\x25"},
  209. {0x34, "\xd8\x26\x70"}, {0x34, "\xda\x72\x4c"}, {0x34, "\xdc\xff\x04"},
  210. {0x34, "\xde\x01\x5b"}, {0x34, "\xe6\x01\x13"}, {0x34, "\xee\x0b\xf0"},
  211. {0x34, "\xf6\x0b\xa4"}, {0x35, "\x00\xf6\xe7"}, {0x35, "\x08\x0d\xfd"},
  212. {0x35, "\x10\x25\x63"}, {0x35, "\x18\x35\x6c"}, {0x35, "\x20\x42\x7e"},
  213. {0x35, "\x28\x19\x44"}, {0x35, "\x30\x39\xd4"}, {0x35, "\x38\xf5\xa8"},
  214. {0x35, "\x4c\x07\x90"}, {0x35, "\x44\x07\xb8"}, {0x35, "\x5c\x06\x88"},
  215. {0x35, "\x54\x07\xff"}, {0x34, "\xe0\x01\x52"}, {0x34, "\xe8\x00\xcc"},
  216. {0x34, "\xf0\x0d\x83"}, {0x34, "\xf8\x0c\xb3"}, {0x35, "\x02\xfe\xba"},
  217. {0x35, "\x0a\x04\xe0"}, {0x35, "\x12\x1c\x63"}, {0x35, "\x1a\x2b\x5a"},
  218. {0x35, "\x22\x32\x5e"}, {0x35, "\x2a\x0d\x28"}, {0x35, "\x32\x2c\x02"},
  219. {0x35, "\x3a\xf4\xfa"}, {0x35, "\x4e\x07\xef"}, {0x35, "\x46\x07\x88"},
  220. {0x35, "\x5e\x07\xc1"}, {0x35, "\x56\x04\x64"}, {0x34, "\xe4\x01\x15"},
  221. {0x34, "\xec\x00\x82"}, {0x34, "\xf4\x0c\xce"}, {0x34, "\xfc\x0c\xba"},
  222. {0x35, "\x06\x1f\x02"}, {0x35, "\x0e\x02\xe3"}, {0x35, "\x16\x1a\x50"},
  223. {0x35, "\x1e\x24\x39"}, {0x35, "\x26\x23\x4c"}, {0x35, "\x2e\xf9\x1b"},
  224. {0x35, "\x36\x23\x19"}, {0x35, "\x3e\x12\x08"}, {0x35, "\x52\x07\x22"},
  225. {0x35, "\x4a\x03\xd3"}, {0x35, "\x62\x06\x54"}, {0x35, "\x5a\x04\x5d"},
  226. {0x34, "\xe2\x01\x04"}, {0x34, "\xea\x00\xa0"}, {0x34, "\xf2\x0c\xbc"},
  227. {0x34, "\xfa\x0c\x5b"}, {0x35, "\x04\x17\xf2"}, {0x35, "\x0c\x02\x08"},
  228. {0x35, "\x14\x28\x43"}, {0x35, "\x1c\x28\x62"}, {0x35, "\x24\x2b\x60"},
  229. {0x35, "\x2c\x07\x33"}, {0x35, "\x34\x1f\xb0"}, {0x35, "\x3c\xed\xcd"},
  230. {0x35, "\x50\x00\x06"}, {0x35, "\x48\x07\xff"}, {0x35, "\x60\x05\x89"},
  231. {0x35, "\x58\x07\xff"}, {0x35, "\x40\x00\xa0"}, {0x35, "\x42\x00\x00"},
  232. {0x32, "\x10\x01\xfc"}, {0x33, "\x8c\xa1\x18"},
  233. /* Flip/Mirror h/v=1 */
  234. {0x33, "\x90\x00\x3c"}, {0x33, "\x8c\x27\x19"}, {0x33, "\x90\x04\x6c"},
  235. {0x33, "\x8c\x27\x3b"}, {0x33, "\x90\x00\x24"}, {0x33, "\x8c\xa1\x03"},
  236. {0x33, "\x90\x00\x06"},
  237. {130, "\xff\xff\xff"},
  238. {0x33, "\x90\x00\x06"}, {0x33, "\x90\x00\x06"}, {0x33, "\x90\x00\x06"},
  239. {0x33, "\x90\x00\x06"}, {0x33, "\x90\x00\x06"}, {0x33, "\x90\x00\x06"},
  240. {100, "\xff\xff\xff"},
  241. /* ?? */
  242. {0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"}, {0x33, "\x8c\xa1\x02"},
  243. {0x33, "\x90\x00\x1f"}, {0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"},
  244. {0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"},
  245. /* Brigthness=70 */
  246. {0x33, "\x8c\xa2\x06"}, {0x33, "\x90\x00\x46"}, {0x33, "\x8c\xa1\x02"},
  247. {0x33, "\x90\x00\x0f"}, {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},
  248. /* Sharpness=20 */
  249. {0x32, "\x6c\x14\x08"},
  250. };
  251. static struct idxdata tbl_init_post_alt_big1[] = {
  252. {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},
  253. {2, "\xff\xff\xff"},
  254. {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},
  255. {2, "\xff\xff\xff"},
  256. {0x34, "\x1e\x8f\x09"}, {0x34, "\x1c\x01\x28"}, {0x34, "\x1e\x8f\x09"},
  257. {0x34, "\x1e\x8f\x09"}, {0x32, "\x14\x06\xe6"}, {0x33, "\x8c\xa1\x03"},
  258. {0x33, "\x90\x00\x05"},
  259. {2, "\xff\xff\xff"},
  260. {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},
  261. {2, "\xff\xff\xff"},
  262. {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},
  263. {2, "\xff\xff\xff"},
  264. {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"}, {0x33, "\x8c\xa1\x20"},
  265. {0x33, "\x90\x00\x72"}, {0x33, "\x8c\xa1\x30"}, {0x33, "\x90\x00\x03"},
  266. {0x33, "\x8c\xa1\x31"}, {0x33, "\x90\x00\x02"}, {0x33, "\x8c\xa1\x32"},
  267. {0x33, "\x90\x00\x03"}, {0x33, "\x8c\xa1\x34"}, {0x33, "\x90\x00\x03"},
  268. {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x02"}, {0x33, "\x2e\x01\x00"},
  269. {0x34, "\x04\x00\x2a"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x01"},
  270. };
  271. static struct idxdata tbl_init_post_alt_big2[] = {
  272. {0x32, "\x10\x01\xf8"}, {0x34, "\xce\x01\xa8"}, {0x34, "\xd0\x66\x33"},
  273. {0x34, "\xd2\x31\x9a"}, {0x34, "\xd4\x94\x63"}, {0x34, "\xd6\x4b\x25"},
  274. {0x34, "\xd8\x26\x70"}, {0x34, "\xda\x72\x4c"}, {0x34, "\xdc\xff\x04"},
  275. {0x34, "\xde\x01\x5b"}, {0x34, "\xe6\x01\x13"}, {0x34, "\xee\x0b\xf0"},
  276. {0x34, "\xf6\x0b\xa4"}, {0x35, "\x00\xf6\xe7"}, {0x35, "\x08\x0d\xfd"},
  277. {0x35, "\x10\x25\x63"}, {0x35, "\x18\x35\x6c"}, {0x35, "\x20\x42\x7e"},
  278. {0x35, "\x28\x19\x44"}, {0x35, "\x30\x39\xd4"}, {0x35, "\x38\xf5\xa8"},
  279. {0x35, "\x4c\x07\x90"}, {0x35, "\x44\x07\xb8"}, {0x35, "\x5c\x06\x88"},
  280. {0x35, "\x54\x07\xff"}, {0x34, "\xe0\x01\x52"}, {0x34, "\xe8\x00\xcc"},
  281. {0x34, "\xf0\x0d\x83"}, {0x34, "\xf8\x0c\xb3"}, {0x35, "\x02\xfe\xba"},
  282. {0x35, "\x0a\x04\xe0"}, {0x35, "\x12\x1c\x63"}, {0x35, "\x1a\x2b\x5a"},
  283. {0x35, "\x22\x32\x5e"}, {0x35, "\x2a\x0d\x28"}, {0x35, "\x32\x2c\x02"},
  284. {0x35, "\x3a\xf4\xfa"}, {0x35, "\x4e\x07\xef"}, {0x35, "\x46\x07\x88"},
  285. {0x35, "\x5e\x07\xc1"}, {0x35, "\x56\x04\x64"}, {0x34, "\xe4\x01\x15"},
  286. {0x34, "\xec\x00\x82"}, {0x34, "\xf4\x0c\xce"}, {0x34, "\xfc\x0c\xba"},
  287. {0x35, "\x06\x1f\x02"}, {0x35, "\x0e\x02\xe3"}, {0x35, "\x16\x1a\x50"},
  288. {0x35, "\x1e\x24\x39"}, {0x35, "\x26\x23\x4c"}, {0x35, "\x2e\xf9\x1b"},
  289. {0x35, "\x36\x23\x19"}, {0x35, "\x3e\x12\x08"}, {0x35, "\x52\x07\x22"},
  290. {0x35, "\x4a\x03\xd3"}, {0x35, "\x62\x06\x54"}, {0x35, "\x5a\x04\x5d"},
  291. {0x34, "\xe2\x01\x04"}, {0x34, "\xea\x00\xa0"}, {0x34, "\xf2\x0c\xbc"},
  292. {0x34, "\xfa\x0c\x5b"}, {0x35, "\x04\x17\xf2"}, {0x35, "\x0c\x02\x08"},
  293. {0x35, "\x14\x28\x43"}, {0x35, "\x1c\x28\x62"}, {0x35, "\x24\x2b\x60"},
  294. {0x35, "\x2c\x07\x33"}, {0x35, "\x34\x1f\xb0"}, {0x35, "\x3c\xed\xcd"},
  295. {0x35, "\x50\x00\x06"}, {0x35, "\x48\x07\xff"}, {0x35, "\x60\x05\x89"},
  296. {0x35, "\x58\x07\xff"}, {0x35, "\x40\x00\xa0"}, {0x35, "\x42\x00\x00"},
  297. {0x32, "\x10\x01\xfc"}, {0x33, "\x8c\xa1\x18"}, {0x33, "\x90\x00\x3c"},
  298. };
  299. static struct idxdata tbl_init_post_alt_big3[] = {
  300. {0x33, "\x8c\xa1\x02"},
  301. {0x33, "\x90\x00\x1f"},
  302. {0x33, "\x8c\xa1\x02"},
  303. {0x33, "\x90\x00\x1f"},
  304. {0x33, "\x8c\xa1\x02"},
  305. {0x33, "\x90\x00\x1f"},
  306. {0x33, "\x8c\xa1\x02"},
  307. {0x33, "\x90\x00\x1f"},
  308. };
  309. static u8 *dat_640 = "\xd0\x02\xd1\x08\xd2\xe1\xd3\x02\xd4\x10\xd5\x81";
  310. static u8 *dat_800 = "\xd0\x02\xd1\x10\xd2\x57\xd3\x02\xd4\x18\xd5\x21";
  311. static u8 *dat_1280 = "\xd0\x02\xd1\x20\xd2\x01\xd3\x02\xd4\x28\xd5\x01";
  312. static u8 *dat_1600 = "\xd0\x02\xd1\x20\xd2\xaf\xd3\x02\xd4\x30\xd5\x41";
  313. static int mi2020_init_at_startup(struct gspca_dev *gspca_dev);
  314. static int mi2020_configure_alt(struct gspca_dev *gspca_dev);
  315. static int mi2020_init_pre_alt(struct gspca_dev *gspca_dev);
  316. static int mi2020_init_post_alt(struct gspca_dev *gspca_dev);
  317. static void mi2020_post_unset_alt(struct gspca_dev *gspca_dev);
  318. static int mi2020_camera_settings(struct gspca_dev *gspca_dev);
  319. /*==========================================================================*/
  320. void mi2020_init_settings(struct gspca_dev *gspca_dev)
  321. {
  322. struct sd *sd = (struct sd *) gspca_dev;
  323. sd->vcur.backlight = 0;
  324. sd->vcur.brightness = 70;
  325. sd->vcur.sharpness = 20;
  326. sd->vcur.contrast = 0;
  327. sd->vcur.gamma = 0;
  328. sd->vcur.hue = 0;
  329. sd->vcur.saturation = 60;
  330. sd->vcur.whitebal = 50;
  331. sd->vcur.mirror = 0;
  332. sd->vcur.flip = 0;
  333. sd->vcur.AC50Hz = 1;
  334. sd->vmax.backlight = 64;
  335. sd->vmax.brightness = 128;
  336. sd->vmax.sharpness = 40;
  337. sd->vmax.contrast = 3;
  338. sd->vmax.gamma = 2;
  339. sd->vmax.hue = 0 + 1; /* 200 */
  340. sd->vmax.saturation = 0; /* 100 */
  341. sd->vmax.whitebal = 0; /* 100 */
  342. sd->vmax.mirror = 1;
  343. sd->vmax.flip = 1;
  344. sd->vmax.AC50Hz = 1;
  345. if (_MI2020b_) {
  346. sd->vmax.contrast = 0;
  347. sd->vmax.gamma = 0;
  348. sd->vmax.backlight = 0;
  349. }
  350. sd->dev_camera_settings = mi2020_camera_settings;
  351. sd->dev_init_at_startup = mi2020_init_at_startup;
  352. sd->dev_configure_alt = mi2020_configure_alt;
  353. sd->dev_init_pre_alt = mi2020_init_pre_alt;
  354. sd->dev_post_unset_alt = mi2020_post_unset_alt;
  355. }
  356. /*==========================================================================*/
  357. static void common(struct gspca_dev *gspca_dev)
  358. {
  359. s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
  360. if (_MI2020b_) {
  361. fetch_validx(gspca_dev, tbl_common1, ARRAY_SIZE(tbl_common1));
  362. } else {
  363. if (_MI2020_)
  364. ctrl_out(gspca_dev, 0x40, 1, 0x0008, 0x0004, 0, NULL);
  365. else
  366. ctrl_out(gspca_dev, 0x40, 1, 0x0002, 0x0004, 0, NULL);
  367. msleep(35);
  368. fetch_validx(gspca_dev, tbl_common2, ARRAY_SIZE(tbl_common2));
  369. }
  370. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x86\x25\x01");
  371. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x86\x25\x00");
  372. msleep(2); /* - * */
  373. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0030, 3, "\x1a\x0a\xcc");
  374. if (reso == IMAGE_1600)
  375. msleep(2); /* 1600 */
  376. fetch_idxdata(gspca_dev, tbl_common3, ARRAY_SIZE(tbl_common3));
  377. if (_MI2020b_ || _MI2020_)
  378. fetch_idxdata(gspca_dev, tbl_common4,
  379. ARRAY_SIZE(tbl_common4));
  380. fetch_idxdata(gspca_dev, tbl_common5, ARRAY_SIZE(tbl_common5));
  381. if (_MI2020b_ || _MI2020_) {
  382. /* Different from fret */
  383. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x78");
  384. /* Same as fret */
  385. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\x24\x17");
  386. /* Different from fret */
  387. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x90");
  388. } else {
  389. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x6a");
  390. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\x24\x17");
  391. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x80");
  392. }
  393. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x03");
  394. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x05");
  395. msleep(2);
  396. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x03");
  397. if (reso == IMAGE_1600)
  398. msleep(14); /* 1600 */
  399. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x06");
  400. msleep(2);
  401. }
  402. static int mi2020_init_at_startup(struct gspca_dev *gspca_dev)
  403. {
  404. u8 c;
  405. ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0004, 1, &c);
  406. ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0004, 1, &c);
  407. fetch_validx(gspca_dev, tbl_init_at_startup,
  408. ARRAY_SIZE(tbl_init_at_startup));
  409. common(gspca_dev);
  410. return 0;
  411. }
  412. static int mi2020_init_pre_alt(struct gspca_dev *gspca_dev)
  413. {
  414. struct sd *sd = (struct sd *) gspca_dev;
  415. sd->mirrorMask = 0;
  416. sd->vold.backlight = -1;
  417. sd->vold.brightness = -1;
  418. sd->vold.sharpness = -1;
  419. sd->vold.contrast = -1;
  420. sd->vold.gamma = -1;
  421. sd->vold.hue = -1;
  422. sd->vold.mirror = -1;
  423. sd->vold.flip = -1;
  424. sd->vold.AC50Hz = -1;
  425. mi2020_init_post_alt(gspca_dev);
  426. return 0;
  427. }
  428. static int mi2020_init_post_alt(struct gspca_dev *gspca_dev)
  429. {
  430. struct sd *sd = (struct sd *) gspca_dev;
  431. s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
  432. s32 backlight = sd->vcur.backlight;
  433. s32 mirror = (((sd->vcur.mirror > 0) ^ sd->mirrorMask) > 0);
  434. s32 flip = (((sd->vcur.flip > 0) ^ sd->mirrorMask) > 0);
  435. s32 freq = (sd->vcur.AC50Hz > 0);
  436. u8 dat_freq2[] = {0x90, 0x00, 0x80};
  437. u8 dat_multi1[] = {0x8c, 0xa7, 0x00};
  438. u8 dat_multi2[] = {0x90, 0x00, 0x00};
  439. u8 dat_multi3[] = {0x8c, 0xa7, 0x00};
  440. u8 dat_multi4[] = {0x90, 0x00, 0x00};
  441. u8 dat_hvflip2[] = {0x90, 0x04, 0x6c};
  442. u8 dat_hvflip4[] = {0x90, 0x00, 0x24};
  443. u8 c;
  444. sd->nbIm = -1;
  445. dat_freq2[2] = freq ? 0xc0 : 0x80;
  446. dat_multi1[2] = 0x9d;
  447. dat_multi3[2] = dat_multi1[2] + 1;
  448. dat_multi4[2] = dat_multi2[2] = backlight;
  449. dat_hvflip2[2] = 0x6c + 2 * (1 - flip) + (1 - mirror);
  450. dat_hvflip4[2] = 0x24 + 2 * (1 - flip) + (1 - mirror);
  451. msleep(200);
  452. ctrl_out(gspca_dev, 0x40, 5, 0x0001, 0x0000, 0, NULL);
  453. msleep(3); /* 35 * */
  454. common(gspca_dev);
  455. ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x0000, 0, NULL);
  456. msleep(70);
  457. if (_MI2020b_)
  458. ctrl_out(gspca_dev, 0x40, 1, 0x0040, 0x0000, 0, NULL);
  459. ctrl_out(gspca_dev, 0x40, 1, 0x0010, 0x0010, 0, NULL);
  460. ctrl_out(gspca_dev, 0x40, 1, 0x0003, 0x00c1, 0, NULL);
  461. ctrl_out(gspca_dev, 0x40, 1, 0x0042, 0x00c2, 0, NULL);
  462. ctrl_out(gspca_dev, 0x40, 1, 0x006a, 0x000d, 0, NULL);
  463. switch (reso) {
  464. case IMAGE_640:
  465. case IMAGE_800:
  466. if (reso != IMAGE_800)
  467. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
  468. 12, dat_640);
  469. else
  470. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
  471. 12, dat_800);
  472. if (_MI2020c_)
  473. fetch_idxdata(gspca_dev, tbl_init_post_alt_low1,
  474. ARRAY_SIZE(tbl_init_post_alt_low1));
  475. if (reso == IMAGE_800)
  476. fetch_idxdata(gspca_dev, tbl_init_post_alt_low2,
  477. ARRAY_SIZE(tbl_init_post_alt_low2));
  478. fetch_idxdata(gspca_dev, tbl_init_post_alt_low3,
  479. ARRAY_SIZE(tbl_init_post_alt_low3));
  480. if (_MI2020b_) {
  481. ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0010, 0, NULL);
  482. ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);
  483. ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);
  484. msleep(150);
  485. } else if (_MI2020c_) {
  486. ctrl_out(gspca_dev, 0x40, 1, 0x0010, 0x0010, 0, NULL);
  487. ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);
  488. ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);
  489. msleep(120);
  490. ctrl_out(gspca_dev, 0x40, 1, 0x0040, 0x0000, 0, NULL);
  491. msleep(30);
  492. } else if (_MI2020_) {
  493. ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0010, 0, NULL);
  494. ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);
  495. ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);
  496. msleep(120);
  497. ctrl_out(gspca_dev, 0x40, 1, 0x0040, 0x0000, 0, NULL);
  498. msleep(30);
  499. }
  500. /* AC power frequency */
  501. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq1);
  502. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq2);
  503. msleep(20);
  504. /* backlight */
  505. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
  506. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
  507. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
  508. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);
  509. /* at init time but not after */
  510. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa2\x0c");
  511. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x17");
  512. /* finish the backlight */
  513. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
  514. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
  515. msleep(5);/* " */
  516. if (_MI2020c_) {
  517. fetch_idxdata(gspca_dev, tbl_init_post_alt_low4,
  518. ARRAY_SIZE(tbl_init_post_alt_low4));
  519. } else {
  520. ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0000, 1, &c);
  521. msleep(14); /* 0xd8 */
  522. /* flip/mirror */
  523. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  524. 3, dat_hvflip1);
  525. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  526. 3, dat_hvflip2);
  527. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  528. 3, dat_hvflip3);
  529. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  530. 3, dat_hvflip4);
  531. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  532. 3, dat_hvflip5);
  533. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  534. 3, dat_hvflip6);
  535. msleep(21);
  536. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  537. 3, dat_dummy1);
  538. msleep(5);
  539. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  540. 3, dat_dummy1);
  541. msleep(5);
  542. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  543. 3, dat_dummy1);
  544. msleep(5);
  545. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  546. 3, dat_dummy1);
  547. msleep(5);
  548. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  549. 3, dat_dummy1);
  550. msleep(5);
  551. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  552. 3, dat_dummy1);
  553. /* end of flip/mirror main part */
  554. msleep(246); /* 146 */
  555. sd->nbIm = 0;
  556. }
  557. break;
  558. case IMAGE_1280:
  559. case IMAGE_1600:
  560. if (reso == IMAGE_1280) {
  561. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
  562. 12, dat_1280);
  563. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  564. 3, "\x8c\x27\x07");
  565. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  566. 3, "\x90\x05\x04");
  567. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  568. 3, "\x8c\x27\x09");
  569. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  570. 3, "\x90\x04\x02");
  571. } else {
  572. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
  573. 12, dat_1600);
  574. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  575. 3, "\x8c\x27\x07");
  576. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  577. 3, "\x90\x06\x40");
  578. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  579. 3, "\x8c\x27\x09");
  580. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
  581. 3, "\x90\x04\xb0");
  582. }
  583. fetch_idxdata(gspca_dev, tbl_init_post_alt_big1,
  584. ARRAY_SIZE(tbl_init_post_alt_big1));
  585. if (reso == IMAGE_1600)
  586. msleep(13); /* 1600 */
  587. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\x27\x97");
  588. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x01\x00");
  589. msleep(53);
  590. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x20");
  591. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x00");
  592. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x03");
  593. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x01");
  594. if (reso == IMAGE_1600)
  595. msleep(13); /* 1600 */
  596. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa7\x02");
  597. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x00");
  598. msleep(53);
  599. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x20");
  600. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x72");
  601. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x03");
  602. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x02");
  603. if (reso == IMAGE_1600)
  604. msleep(13); /* 1600 */
  605. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa7\x02");
  606. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x01");
  607. msleep(53);
  608. if (_MI2020b_) {
  609. ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0010, 0, NULL);
  610. if (reso == IMAGE_1600)
  611. msleep(500); /* 1600 */
  612. ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);
  613. ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);
  614. msleep(1850);
  615. } else if (_MI2020c_ || _MI2020_) {
  616. ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0010, 0, NULL);
  617. ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);
  618. ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);
  619. msleep(1850);
  620. ctrl_out(gspca_dev, 0x40, 1, 0x0040, 0x0000, 0, NULL);
  621. msleep(30);
  622. }
  623. /* AC power frequency */
  624. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq1);
  625. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq2);
  626. msleep(20);
  627. /* backlight */
  628. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
  629. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
  630. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
  631. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);
  632. /* at init time but not after */
  633. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa2\x0c");
  634. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x17");
  635. /* finish the backlight */
  636. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
  637. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
  638. msleep(6); /* " */
  639. ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0000, 1, &c);
  640. msleep(14);
  641. if (_MI2020c_)
  642. fetch_idxdata(gspca_dev, tbl_init_post_alt_big2,
  643. ARRAY_SIZE(tbl_init_post_alt_big2));
  644. /* flip/mirror */
  645. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip1);
  646. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip2);
  647. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip3);
  648. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip4);
  649. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip5);
  650. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip6);
  651. /* end of flip/mirror main part */
  652. msleep(16);
  653. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x03");
  654. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x01");
  655. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x20");
  656. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x00");
  657. if (reso == IMAGE_1600)
  658. msleep(25); /* 1600 */
  659. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa7\x02");
  660. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x00");
  661. msleep(103);
  662. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x03");
  663. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x02");
  664. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x20");
  665. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x72");
  666. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa7\x02");
  667. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x01");
  668. sd->nbIm = 0;
  669. if (_MI2020c_)
  670. fetch_idxdata(gspca_dev, tbl_init_post_alt_big3,
  671. ARRAY_SIZE(tbl_init_post_alt_big3));
  672. }
  673. sd->vold.mirror = mirror;
  674. sd->vold.flip = flip;
  675. sd->vold.AC50Hz = freq;
  676. sd->vold.backlight = backlight;
  677. mi2020_camera_settings(gspca_dev);
  678. return 0;
  679. }
  680. static int mi2020_configure_alt(struct gspca_dev *gspca_dev)
  681. {
  682. s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
  683. switch (reso) {
  684. case IMAGE_640:
  685. gspca_dev->alt = 3 + 1;
  686. break;
  687. case IMAGE_800:
  688. case IMAGE_1280:
  689. case IMAGE_1600:
  690. gspca_dev->alt = 1 + 1;
  691. break;
  692. }
  693. return 0;
  694. }
  695. int mi2020_camera_settings(struct gspca_dev *gspca_dev)
  696. {
  697. struct sd *sd = (struct sd *) gspca_dev;
  698. s32 backlight = sd->vcur.backlight;
  699. s32 bright = sd->vcur.brightness;
  700. s32 sharp = sd->vcur.sharpness;
  701. s32 cntr = sd->vcur.contrast;
  702. s32 gam = sd->vcur.gamma;
  703. s32 hue = (sd->vcur.hue > 0);
  704. s32 mirror = (((sd->vcur.mirror > 0) ^ sd->mirrorMask) > 0);
  705. s32 flip = (((sd->vcur.flip > 0) ^ sd->mirrorMask) > 0);
  706. s32 freq = (sd->vcur.AC50Hz > 0);
  707. u8 dat_sharp[] = {0x6c, 0x00, 0x08};
  708. u8 dat_bright2[] = {0x90, 0x00, 0x00};
  709. u8 dat_freq2[] = {0x90, 0x00, 0x80};
  710. u8 dat_multi1[] = {0x8c, 0xa7, 0x00};
  711. u8 dat_multi2[] = {0x90, 0x00, 0x00};
  712. u8 dat_multi3[] = {0x8c, 0xa7, 0x00};
  713. u8 dat_multi4[] = {0x90, 0x00, 0x00};
  714. u8 dat_hvflip2[] = {0x90, 0x04, 0x6c};
  715. u8 dat_hvflip4[] = {0x90, 0x00, 0x24};
  716. /* Less than 4 images received -> too early to set the settings */
  717. if (sd->nbIm < 4) {
  718. sd->waitSet = 1;
  719. return 0;
  720. }
  721. sd->waitSet = 0;
  722. if (freq != sd->vold.AC50Hz) {
  723. sd->vold.AC50Hz = freq;
  724. dat_freq2[2] = freq ? 0xc0 : 0x80;
  725. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq1);
  726. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq2);
  727. msleep(20);
  728. }
  729. if (mirror != sd->vold.mirror || flip != sd->vold.flip) {
  730. sd->vold.mirror = mirror;
  731. sd->vold.flip = flip;
  732. dat_hvflip2[2] = 0x6c + 2 * (1 - flip) + (1 - mirror);
  733. dat_hvflip4[2] = 0x24 + 2 * (1 - flip) + (1 - mirror);
  734. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip1);
  735. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip2);
  736. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip3);
  737. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip4);
  738. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip5);
  739. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip6);
  740. msleep(130);
  741. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_dummy1);
  742. msleep(6);
  743. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_dummy1);
  744. msleep(6);
  745. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_dummy1);
  746. msleep(6);
  747. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_dummy1);
  748. msleep(6);
  749. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_dummy1);
  750. msleep(6);
  751. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_dummy1);
  752. msleep(6);
  753. /* Sometimes present, sometimes not, useful? */
  754. /* ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy2);
  755. * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy3);
  756. * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy2);
  757. * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy3);
  758. * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy2);
  759. * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy3);
  760. * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy2);
  761. * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy3);*/
  762. }
  763. if (backlight != sd->vold.backlight) {
  764. sd->vold.backlight = backlight;
  765. if (backlight < 0 || backlight > sd->vmax.backlight)
  766. backlight = 0;
  767. dat_multi1[2] = 0x9d;
  768. dat_multi3[2] = dat_multi1[2] + 1;
  769. dat_multi4[2] = dat_multi2[2] = backlight;
  770. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
  771. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
  772. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
  773. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);
  774. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
  775. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
  776. }
  777. if (gam != sd->vold.gamma) {
  778. sd->vold.gamma = gam;
  779. if (gam < 0 || gam > sd->vmax.gamma)
  780. gam = 0;
  781. dat_multi1[2] = 0x6d;
  782. dat_multi3[2] = dat_multi1[2] + 1;
  783. dat_multi4[2] = dat_multi2[2] = 0x40 + gam;
  784. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
  785. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
  786. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
  787. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);
  788. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
  789. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
  790. }
  791. if (cntr != sd->vold.contrast) {
  792. sd->vold.contrast = cntr;
  793. if (cntr < 0 || cntr > sd->vmax.contrast)
  794. cntr = 0;
  795. dat_multi1[2] = 0x6d;
  796. dat_multi3[2] = dat_multi1[2] + 1;
  797. dat_multi4[2] = dat_multi2[2] = 0x12 + 16 * cntr;
  798. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
  799. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
  800. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
  801. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);
  802. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
  803. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
  804. }
  805. if (bright != sd->vold.brightness) {
  806. sd->vold.brightness = bright;
  807. if (bright < 0 || bright > sd->vmax.brightness)
  808. bright = 0;
  809. dat_bright2[2] = bright;
  810. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright1);
  811. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright2);
  812. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright3);
  813. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright4);
  814. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright5);
  815. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright6);
  816. }
  817. if (sharp != sd->vold.sharpness) {
  818. sd->vold.sharpness = sharp;
  819. if (sharp < 0 || sharp > sd->vmax.sharpness)
  820. sharp = 0;
  821. dat_sharp[1] = sharp;
  822. ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0032, 3, dat_sharp);
  823. }
  824. if (hue != sd->vold.hue) {
  825. sd->swapRB = hue;
  826. sd->vold.hue = hue;
  827. }
  828. return 0;
  829. }
  830. static void mi2020_post_unset_alt(struct gspca_dev *gspca_dev)
  831. {
  832. ctrl_out(gspca_dev, 0x40, 5, 0x0000, 0x0000, 0, NULL);
  833. msleep(20);
  834. if (_MI2020c_ || _MI2020_)
  835. ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0000, 0, NULL);
  836. else
  837. ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x0000, 0, NULL);
  838. }