gl860-mi2020.c 30 KB

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