gl860-mi2020.c 30 KB

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