gl860-mi1320.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* Subdriver for the GL860 chip with the MI1320 sensor
  3. * Author Olivier LORIN from own logs
  4. */
  5. /* Sensor : MI1320 */
  6. #include "gl860.h"
  7. static struct validx tbl_common[] = {
  8. {0xba00, 0x00f0}, {0xba00, 0x00f1}, {0xba51, 0x0066}, {0xba02, 0x00f1},
  9. {0xba05, 0x0067}, {0xba05, 0x00f1}, {0xbaa0, 0x0065}, {0xba00, 0x00f1},
  10. {0xffff, 0xffff},
  11. {0xba00, 0x00f0}, {0xba02, 0x00f1}, {0xbafa, 0x0028}, {0xba02, 0x00f1},
  12. {0xba00, 0x00f0}, {0xba01, 0x00f1}, {0xbaf0, 0x0006}, {0xba0e, 0x00f1},
  13. {0xba70, 0x0006}, {0xba0e, 0x00f1},
  14. {0xffff, 0xffff},
  15. {0xba74, 0x0006}, {0xba0e, 0x00f1},
  16. {0xffff, 0xffff},
  17. {0x0061, 0x0000}, {0x0068, 0x000d},
  18. };
  19. static struct validx tbl_init_at_startup[] = {
  20. {0x0000, 0x0000}, {0x0010, 0x0010},
  21. {35, 0xffff},
  22. {0x0008, 0x00c0}, {0x0001, 0x00c1}, {0x0001, 0x00c2}, {0x0020, 0x0006},
  23. {0x006a, 0x000d},
  24. };
  25. static struct validx tbl_sensor_settings_common[] = {
  26. {0x0010, 0x0010}, {0x0003, 0x00c1}, {0x0042, 0x00c2}, {0x0040, 0x0000},
  27. {0x006a, 0x0007}, {0x006a, 0x000d}, {0x0063, 0x0006},
  28. };
  29. static struct validx tbl_sensor_settings_1280[] = {
  30. {0xba00, 0x00f0}, {0xba00, 0x00f1}, {0xba5a, 0x0066}, {0xba02, 0x00f1},
  31. {0xba05, 0x0067}, {0xba05, 0x00f1}, {0xba20, 0x0065}, {0xba00, 0x00f1},
  32. };
  33. static struct validx tbl_sensor_settings_800[] = {
  34. {0xba00, 0x00f0}, {0xba00, 0x00f1}, {0xba5a, 0x0066}, {0xba02, 0x00f1},
  35. {0xba05, 0x0067}, {0xba05, 0x00f1}, {0xba20, 0x0065}, {0xba00, 0x00f1},
  36. };
  37. static struct validx tbl_sensor_settings_640[] = {
  38. {0xba00, 0x00f0}, {0xba00, 0x00f1}, {0xbaa0, 0x0065}, {0xba00, 0x00f1},
  39. {0xba51, 0x0066}, {0xba02, 0x00f1}, {0xba05, 0x0067}, {0xba05, 0x00f1},
  40. {0xba20, 0x0065}, {0xba00, 0x00f1},
  41. };
  42. static struct validx tbl_post_unset_alt[] = {
  43. {0xba00, 0x00f0}, {0xba00, 0x00f1}, {0xbaa0, 0x0065}, {0xba00, 0x00f1},
  44. {0x0061, 0x0000}, {0x0068, 0x000d},
  45. };
  46. static u8 *tbl_1280[] = {
  47. (u8[]){
  48. 0x0d, 0x80, 0xf1, 0x08, 0x03, 0x04, 0xf1, 0x00,
  49. 0x04, 0x05, 0xf1, 0x02, 0x05, 0x00, 0xf1, 0xf1,
  50. 0x06, 0x00, 0xf1, 0x0d, 0x20, 0x01, 0xf1, 0x00,
  51. 0x21, 0x84, 0xf1, 0x00, 0x0d, 0x00, 0xf1, 0x08,
  52. 0xf0, 0x00, 0xf1, 0x01, 0x34, 0x00, 0xf1, 0x00,
  53. 0x9b, 0x43, 0xf1, 0x00, 0xa6, 0x05, 0xf1, 0x00,
  54. 0xa9, 0x04, 0xf1, 0x00, 0xa1, 0x05, 0xf1, 0x00,
  55. 0xa4, 0x04, 0xf1, 0x00, 0xae, 0x0a, 0xf1, 0x08
  56. }, (u8[]){
  57. 0xf0, 0x00, 0xf1, 0x02, 0x3a, 0x05, 0xf1, 0xf1,
  58. 0x3c, 0x05, 0xf1, 0xf1, 0x59, 0x01, 0xf1, 0x47,
  59. 0x5a, 0x01, 0xf1, 0x88, 0x5c, 0x0a, 0xf1, 0x06,
  60. 0x5d, 0x0e, 0xf1, 0x0a, 0x64, 0x5e, 0xf1, 0x1c,
  61. 0xd2, 0x00, 0xf1, 0xcf, 0xcb, 0x00, 0xf1, 0x01
  62. }, (u8[]){
  63. 0xd3, 0x02, 0xd4, 0x28, 0xd5, 0x01, 0xd0, 0x02,
  64. 0xd1, 0x18, 0xd2, 0xc1
  65. }
  66. };
  67. static u8 *tbl_800[] = {
  68. (u8[]){
  69. 0x0d, 0x80, 0xf1, 0x08, 0x03, 0x03, 0xf1, 0xc0,
  70. 0x04, 0x05, 0xf1, 0x02, 0x05, 0x00, 0xf1, 0xf1,
  71. 0x06, 0x00, 0xf1, 0x0d, 0x20, 0x01, 0xf1, 0x00,
  72. 0x21, 0x84, 0xf1, 0x00, 0x0d, 0x00, 0xf1, 0x08,
  73. 0xf0, 0x00, 0xf1, 0x01, 0x34, 0x00, 0xf1, 0x00,
  74. 0x9b, 0x43, 0xf1, 0x00, 0xa6, 0x05, 0xf1, 0x00,
  75. 0xa9, 0x03, 0xf1, 0xc0, 0xa1, 0x03, 0xf1, 0x20,
  76. 0xa4, 0x02, 0xf1, 0x5a, 0xae, 0x0a, 0xf1, 0x08
  77. }, (u8[]){
  78. 0xf0, 0x00, 0xf1, 0x02, 0x3a, 0x05, 0xf1, 0xf1,
  79. 0x3c, 0x05, 0xf1, 0xf1, 0x59, 0x01, 0xf1, 0x47,
  80. 0x5a, 0x01, 0xf1, 0x88, 0x5c, 0x0a, 0xf1, 0x06,
  81. 0x5d, 0x0e, 0xf1, 0x0a, 0x64, 0x5e, 0xf1, 0x1c,
  82. 0xd2, 0x00, 0xf1, 0xcf, 0xcb, 0x00, 0xf1, 0x01
  83. }, (u8[]){
  84. 0xd3, 0x02, 0xd4, 0x18, 0xd5, 0x21, 0xd0, 0x02,
  85. 0xd1, 0x10, 0xd2, 0x59
  86. }
  87. };
  88. static u8 *tbl_640[] = {
  89. (u8[]){
  90. 0x0d, 0x80, 0xf1, 0x08, 0x03, 0x04, 0xf1, 0x04,
  91. 0x04, 0x05, 0xf1, 0x02, 0x07, 0x01, 0xf1, 0x7c,
  92. 0x08, 0x00, 0xf1, 0x0e, 0x21, 0x80, 0xf1, 0x00,
  93. 0x0d, 0x00, 0xf1, 0x08, 0xf0, 0x00, 0xf1, 0x01,
  94. 0x34, 0x10, 0xf1, 0x10, 0x3a, 0x43, 0xf1, 0x00,
  95. 0xa6, 0x05, 0xf1, 0x02, 0xa9, 0x04, 0xf1, 0x04,
  96. 0xa7, 0x02, 0xf1, 0x81, 0xaa, 0x01, 0xf1, 0xe2,
  97. 0xae, 0x0c, 0xf1, 0x09
  98. }, (u8[]){
  99. 0xf0, 0x00, 0xf1, 0x02, 0x39, 0x03, 0xf1, 0xfc,
  100. 0x3b, 0x04, 0xf1, 0x04, 0x57, 0x01, 0xf1, 0xb6,
  101. 0x58, 0x02, 0xf1, 0x0d, 0x5c, 0x1f, 0xf1, 0x19,
  102. 0x5d, 0x24, 0xf1, 0x1e, 0x64, 0x5e, 0xf1, 0x1c,
  103. 0xd2, 0x00, 0xf1, 0x00, 0xcb, 0x00, 0xf1, 0x01
  104. }, (u8[]){
  105. 0xd3, 0x02, 0xd4, 0x10, 0xd5, 0x81, 0xd0, 0x02,
  106. 0xd1, 0x08, 0xd2, 0xe1
  107. }
  108. };
  109. static s32 tbl_sat[] = {0x25, 0x1d, 0x15, 0x0d, 0x05, 0x4d, 0x55, 0x5d, 0x2d};
  110. static s32 tbl_bright[] = {0, 8, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70};
  111. static s32 tbl_backlight[] = {0x0e, 0x06, 0x02};
  112. static s32 tbl_cntr1[] = {
  113. 0x90, 0x98, 0xa0, 0xa8, 0xb0, 0xb8, 0xc0, 0xc8, 0xd0, 0xe0, 0xf0};
  114. static s32 tbl_cntr2[] = {
  115. 0x70, 0x68, 0x60, 0x58, 0x50, 0x48, 0x40, 0x38, 0x30, 0x20, 0x10};
  116. static u8 dat_wbalNL[] =
  117. "\xf0\x00\xf1\x01\x05\x00\xf1\x06" "\x3b\x04\xf1\x2a\x47\x10\xf1\x10"
  118. "\x9d\x3c\xf1\xae\xaf\x10\xf1\x00" "\xf0\x00\xf1\x02\x2f\x91\xf1\x20"
  119. "\x9c\x91\xf1\x20\x37\x03\xf1\x00" "\x9d\xc5\xf1\x0f\xf0\x00\xf1\x00";
  120. static u8 dat_wbalLL[] =
  121. "\xf0\x00\xf1\x01\x05\x00\xf1\x0c" "\x3b\x04\xf1\x2a\x47\x40\xf1\x40"
  122. "\x9d\x20\xf1\xae\xaf\x10\xf1\x00" "\xf0\x00\xf1\x02\x2f\xd1\xf1\x00"
  123. "\x9c\xd1\xf1\x00\x37\x03\xf1\x00" "\x9d\xc5\xf1\x3f\xf0\x00\xf1\x00";
  124. static u8 dat_wbalBL[] =
  125. "\xf0\x00\xf1\x01\x05\x00\xf1\x06" "\x47\x10\xf1\x30\x9d\x3c\xf1\xae"
  126. "\xaf\x10\xf1\x00\xf0\x00\xf1\x02" "\x2f\x91\xf1\x20\x9c\x91\xf1\x20"
  127. "\x37\x03\xf1\x00\x9d\xc5\xf1\x2f" "\xf0\x00\xf1\x00";
  128. static u8 dat_hvflip1[] = {0xf0, 0x00, 0xf1, 0x00};
  129. static u8 dat_common00[] =
  130. "\x00\x01\x07\x6a\x06\x63\x0d\x6a" "\xc0\x00\x10\x10\xc1\x03\xc2\x42"
  131. "\xd8\x04\x58\x00\x04\x02";
  132. static u8 dat_common01[] =
  133. "\x0d\x00\xf1\x0b\x0d\x00\xf1\x08" "\x35\x00\xf1\x22\x68\x00\xf1\x5d"
  134. "\xf0\x00\xf1\x01\x06\x70\xf1\x0e" "\xf0\x00\xf1\x02\xdd\x18\xf1\xe0";
  135. static u8 dat_common02[] =
  136. "\x05\x01\xf1\x84\x06\x00\xf1\x44" "\x07\x00\xf1\xbe\x08\x00\xf1\x1e"
  137. "\x20\x01\xf1\x03\x21\x84\xf1\x00" "\x22\x0d\xf1\x0f\x24\x80\xf1\x00"
  138. "\x34\x18\xf1\x2d\x35\x00\xf1\x22" "\x43\x83\xf1\x83\x59\x00\xf1\xff";
  139. static u8 dat_common03[] =
  140. "\xf0\x00\xf1\x02\x39\x06\xf1\x8c" "\x3a\x06\xf1\x8c\x3b\x03\xf1\xda"
  141. "\x3c\x05\xf1\x30\x57\x01\xf1\x0c" "\x58\x01\xf1\x42\x59\x01\xf1\x0c"
  142. "\x5a\x01\xf1\x42\x5c\x13\xf1\x0e" "\x5d\x17\xf1\x12\x64\x1e\xf1\x1c";
  143. static u8 dat_common04[] =
  144. "\xf0\x00\xf1\x02\x24\x5f\xf1\x20" "\x28\xea\xf1\x02\x5f\x41\xf1\x43";
  145. static u8 dat_common05[] =
  146. "\x02\x00\xf1\xee\x03\x29\xf1\x1a" "\x04\x02\xf1\xa4\x09\x00\xf1\x68"
  147. "\x0a\x00\xf1\x2a\x0b\x00\xf1\x04" "\x0c\x00\xf1\x93\x0d\x00\xf1\x82"
  148. "\x0e\x00\xf1\x40\x0f\x00\xf1\x5f" "\x10\x00\xf1\x4e\x11\x00\xf1\x5b";
  149. static u8 dat_common06[] =
  150. "\x15\x00\xf1\xc9\x16\x00\xf1\x5e" "\x17\x00\xf1\x9d\x18\x00\xf1\x06"
  151. "\x19\x00\xf1\x89\x1a\x00\xf1\x12" "\x1b\x00\xf1\xa1\x1c\x00\xf1\xe4"
  152. "\x1d\x00\xf1\x7a\x1e\x00\xf1\x64" "\xf6\x00\xf1\x5f";
  153. static u8 dat_common07[] =
  154. "\xf0\x00\xf1\x01\x53\x09\xf1\x03" "\x54\x3d\xf1\x1c\x55\x99\xf1\x72"
  155. "\x56\xc1\xf1\xb1\x57\xd8\xf1\xce" "\x58\xe0\xf1\x00\xdc\x0a\xf1\x03"
  156. "\xdd\x45\xf1\x20\xde\xae\xf1\x82" "\xdf\xdc\xf1\xc9\xe0\xf6\xf1\xea"
  157. "\xe1\xff\xf1\x00";
  158. static u8 dat_common08[] =
  159. "\xf0\x00\xf1\x01\x80\x00\xf1\x06" "\x81\xf6\xf1\x08\x82\xfb\xf1\xf7"
  160. "\x83\x00\xf1\xfe\xb6\x07\xf1\x03" "\xb7\x18\xf1\x0c\x84\xfb\xf1\x06"
  161. "\x85\xfb\xf1\xf9\x86\x00\xf1\xff" "\xb8\x07\xf1\x04\xb9\x16\xf1\x0a";
  162. static u8 dat_common09[] =
  163. "\x87\xfa\xf1\x05\x88\xfc\xf1\xf9" "\x89\x00\xf1\xff\xba\x06\xf1\x03"
  164. "\xbb\x17\xf1\x09\x8a\xe8\xf1\x14" "\x8b\xf7\xf1\xf0\x8c\xfd\xf1\xfa"
  165. "\x8d\x00\xf1\x00\xbc\x05\xf1\x01" "\xbd\x0c\xf1\x08\xbe\x00\xf1\x14";
  166. static u8 dat_common10[] =
  167. "\x8e\xea\xf1\x13\x8f\xf7\xf1\xf2" "\x90\xfd\xf1\xfa\x91\x00\xf1\x00"
  168. "\xbf\x05\xf1\x01\xc0\x0a\xf1\x08" "\xc1\x00\xf1\x0c\x92\xed\xf1\x0f"
  169. "\x93\xf9\xf1\xf4\x94\xfe\xf1\xfb" "\x95\x00\xf1\x00\xc2\x04\xf1\x01"
  170. "\xc3\x0a\xf1\x07\xc4\x00\xf1\x10";
  171. static u8 dat_common11[] =
  172. "\xf0\x00\xf1\x01\x05\x00\xf1\x06" "\x25\x00\xf1\x55\x34\x10\xf1\x10"
  173. "\x35\xf0\xf1\x10\x3a\x02\xf1\x03" "\x3b\x04\xf1\x2a\x9b\x43\xf1\x00"
  174. "\xa4\x03\xf1\xc0\xa7\x02\xf1\x81";
  175. static int mi1320_init_at_startup(struct gspca_dev *gspca_dev);
  176. static int mi1320_configure_alt(struct gspca_dev *gspca_dev);
  177. static int mi1320_init_pre_alt(struct gspca_dev *gspca_dev);
  178. static int mi1320_init_post_alt(struct gspca_dev *gspca_dev);
  179. static void mi1320_post_unset_alt(struct gspca_dev *gspca_dev);
  180. static int mi1320_sensor_settings(struct gspca_dev *gspca_dev);
  181. static int mi1320_camera_settings(struct gspca_dev *gspca_dev);
  182. /*==========================================================================*/
  183. void mi1320_init_settings(struct gspca_dev *gspca_dev)
  184. {
  185. struct sd *sd = (struct sd *) gspca_dev;
  186. sd->vcur.backlight = 0;
  187. sd->vcur.brightness = 0;
  188. sd->vcur.sharpness = 6;
  189. sd->vcur.contrast = 10;
  190. sd->vcur.gamma = 20;
  191. sd->vcur.hue = 0;
  192. sd->vcur.saturation = 6;
  193. sd->vcur.whitebal = 0;
  194. sd->vcur.mirror = 0;
  195. sd->vcur.flip = 0;
  196. sd->vcur.AC50Hz = 1;
  197. sd->vmax.backlight = 2;
  198. sd->vmax.brightness = 8;
  199. sd->vmax.sharpness = 7;
  200. sd->vmax.contrast = 0; /* 10 but not working with this driver */
  201. sd->vmax.gamma = 40;
  202. sd->vmax.hue = 5 + 1;
  203. sd->vmax.saturation = 8;
  204. sd->vmax.whitebal = 2;
  205. sd->vmax.mirror = 1;
  206. sd->vmax.flip = 1;
  207. sd->vmax.AC50Hz = 1;
  208. sd->dev_camera_settings = mi1320_camera_settings;
  209. sd->dev_init_at_startup = mi1320_init_at_startup;
  210. sd->dev_configure_alt = mi1320_configure_alt;
  211. sd->dev_init_pre_alt = mi1320_init_pre_alt;
  212. sd->dev_post_unset_alt = mi1320_post_unset_alt;
  213. }
  214. /*==========================================================================*/
  215. static void common(struct gspca_dev *gspca_dev)
  216. {
  217. s32 n; /* reserved for FETCH functions */
  218. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 22, dat_common00);
  219. ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x0000, 0, NULL);
  220. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 32, dat_common01);
  221. n = fetch_validx(gspca_dev, tbl_common, ARRAY_SIZE(tbl_common));
  222. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 48, dat_common02);
  223. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 48, dat_common03);
  224. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 16, dat_common04);
  225. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 48, dat_common05);
  226. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 44, dat_common06);
  227. keep_on_fetching_validx(gspca_dev, tbl_common,
  228. ARRAY_SIZE(tbl_common), n);
  229. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 52, dat_common07);
  230. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 48, dat_common08);
  231. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 48, dat_common09);
  232. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 56, dat_common10);
  233. keep_on_fetching_validx(gspca_dev, tbl_common,
  234. ARRAY_SIZE(tbl_common), n);
  235. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 40, dat_common11);
  236. keep_on_fetching_validx(gspca_dev, tbl_common,
  237. ARRAY_SIZE(tbl_common), n);
  238. }
  239. static int mi1320_init_at_startup(struct gspca_dev *gspca_dev)
  240. {
  241. fetch_validx(gspca_dev, tbl_init_at_startup,
  242. ARRAY_SIZE(tbl_init_at_startup));
  243. common(gspca_dev);
  244. /* ctrl_out(gspca_dev, 0x40, 11, 0x0000, 0x0000, 0, NULL); */
  245. return 0;
  246. }
  247. static int mi1320_init_pre_alt(struct gspca_dev *gspca_dev)
  248. {
  249. struct sd *sd = (struct sd *) gspca_dev;
  250. sd->mirrorMask = 0;
  251. sd->vold.backlight = -1;
  252. sd->vold.brightness = -1;
  253. sd->vold.sharpness = -1;
  254. sd->vold.contrast = -1;
  255. sd->vold.saturation = -1;
  256. sd->vold.gamma = -1;
  257. sd->vold.hue = -1;
  258. sd->vold.whitebal = -1;
  259. sd->vold.mirror = -1;
  260. sd->vold.flip = -1;
  261. sd->vold.AC50Hz = -1;
  262. common(gspca_dev);
  263. mi1320_sensor_settings(gspca_dev);
  264. mi1320_init_post_alt(gspca_dev);
  265. return 0;
  266. }
  267. static int mi1320_init_post_alt(struct gspca_dev *gspca_dev)
  268. {
  269. mi1320_camera_settings(gspca_dev);
  270. return 0;
  271. }
  272. static int mi1320_sensor_settings(struct gspca_dev *gspca_dev)
  273. {
  274. s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
  275. ctrl_out(gspca_dev, 0x40, 5, 0x0001, 0x0000, 0, NULL);
  276. fetch_validx(gspca_dev, tbl_sensor_settings_common,
  277. ARRAY_SIZE(tbl_sensor_settings_common));
  278. switch (reso) {
  279. case IMAGE_1280:
  280. fetch_validx(gspca_dev, tbl_sensor_settings_1280,
  281. ARRAY_SIZE(tbl_sensor_settings_1280));
  282. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 64, tbl_1280[0]);
  283. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 40, tbl_1280[1]);
  284. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, tbl_1280[2]);
  285. break;
  286. case IMAGE_800:
  287. fetch_validx(gspca_dev, tbl_sensor_settings_800,
  288. ARRAY_SIZE(tbl_sensor_settings_800));
  289. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 64, tbl_800[0]);
  290. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 40, tbl_800[1]);
  291. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, tbl_800[2]);
  292. break;
  293. default:
  294. fetch_validx(gspca_dev, tbl_sensor_settings_640,
  295. ARRAY_SIZE(tbl_sensor_settings_640));
  296. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 60, tbl_640[0]);
  297. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 40, tbl_640[1]);
  298. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, tbl_640[2]);
  299. break;
  300. }
  301. return 0;
  302. }
  303. static int mi1320_configure_alt(struct gspca_dev *gspca_dev)
  304. {
  305. s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
  306. switch (reso) {
  307. case IMAGE_640:
  308. gspca_dev->alt = 3 + 1;
  309. break;
  310. case IMAGE_800:
  311. case IMAGE_1280:
  312. gspca_dev->alt = 1 + 1;
  313. break;
  314. }
  315. return 0;
  316. }
  317. static int mi1320_camera_settings(struct gspca_dev *gspca_dev)
  318. {
  319. struct sd *sd = (struct sd *) gspca_dev;
  320. s32 backlight = sd->vcur.backlight;
  321. s32 bright = sd->vcur.brightness;
  322. s32 sharp = sd->vcur.sharpness;
  323. s32 cntr = sd->vcur.contrast;
  324. s32 gam = sd->vcur.gamma;
  325. s32 hue = sd->vcur.hue;
  326. s32 sat = sd->vcur.saturation;
  327. s32 wbal = sd->vcur.whitebal;
  328. s32 mirror = (((sd->vcur.mirror > 0) ^ sd->mirrorMask) > 0);
  329. s32 flip = (((sd->vcur.flip > 0) ^ sd->mirrorMask) > 0);
  330. s32 freq = (sd->vcur.AC50Hz > 0);
  331. s32 i;
  332. if (freq != sd->vold.AC50Hz) {
  333. sd->vold.AC50Hz = freq;
  334. freq = 2 * (freq == 0);
  335. ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
  336. ctrl_out(gspca_dev, 0x40, 1, 0xba02, 0x00f1, 0, NULL);
  337. ctrl_out(gspca_dev, 0x40, 1, 0xba00 , 0x005b, 0, NULL);
  338. ctrl_out(gspca_dev, 0x40, 1, 0xba01 + freq, 0x00f1, 0, NULL);
  339. }
  340. if (wbal != sd->vold.whitebal) {
  341. sd->vold.whitebal = wbal;
  342. if (wbal < 0 || wbal > sd->vmax.whitebal)
  343. wbal = 0;
  344. for (i = 0; i < 2; i++) {
  345. if (wbal == 0) { /* Normal light */
  346. ctrl_out(gspca_dev, 0x40, 1,
  347. 0x0010, 0x0010, 0, NULL);
  348. ctrl_out(gspca_dev, 0x40, 1,
  349. 0x0003, 0x00c1, 0, NULL);
  350. ctrl_out(gspca_dev, 0x40, 1,
  351. 0x0042, 0x00c2, 0, NULL);
  352. ctrl_out(gspca_dev, 0x40, 3,
  353. 0xba00, 0x0200, 48, dat_wbalNL);
  354. }
  355. if (wbal == 1) { /* Low light */
  356. ctrl_out(gspca_dev, 0x40, 1,
  357. 0x0010, 0x0010, 0, NULL);
  358. ctrl_out(gspca_dev, 0x40, 1,
  359. 0x0004, 0x00c1, 0, NULL);
  360. ctrl_out(gspca_dev, 0x40, 1,
  361. 0x0043, 0x00c2, 0, NULL);
  362. ctrl_out(gspca_dev, 0x40, 3,
  363. 0xba00, 0x0200, 48, dat_wbalLL);
  364. }
  365. if (wbal == 2) { /* Back light */
  366. ctrl_out(gspca_dev, 0x40, 1,
  367. 0x0010, 0x0010, 0, NULL);
  368. ctrl_out(gspca_dev, 0x40, 1,
  369. 0x0003, 0x00c1, 0, NULL);
  370. ctrl_out(gspca_dev, 0x40, 1,
  371. 0x0042, 0x00c2, 0, NULL);
  372. ctrl_out(gspca_dev, 0x40, 3,
  373. 0xba00, 0x0200, 44, dat_wbalBL);
  374. }
  375. }
  376. }
  377. if (bright != sd->vold.brightness) {
  378. sd->vold.brightness = bright;
  379. if (bright < 0 || bright > sd->vmax.brightness)
  380. bright = 0;
  381. bright = tbl_bright[bright];
  382. ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
  383. ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
  384. ctrl_out(gspca_dev, 0x40, 1, 0xba00 + bright, 0x0034, 0, NULL);
  385. ctrl_out(gspca_dev, 0x40, 1, 0xba00 + bright, 0x00f1, 0, NULL);
  386. }
  387. if (sat != sd->vold.saturation) {
  388. sd->vold.saturation = sat;
  389. if (sat < 0 || sat > sd->vmax.saturation)
  390. sat = 0;
  391. sat = tbl_sat[sat];
  392. ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
  393. ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
  394. ctrl_out(gspca_dev, 0x40, 1, 0xba00 , 0x0025, 0, NULL);
  395. ctrl_out(gspca_dev, 0x40, 1, 0xba00 + sat, 0x00f1, 0, NULL);
  396. }
  397. if (sharp != sd->vold.sharpness) {
  398. sd->vold.sharpness = sharp;
  399. if (sharp < 0 || sharp > sd->vmax.sharpness)
  400. sharp = 0;
  401. ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
  402. ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
  403. ctrl_out(gspca_dev, 0x40, 1, 0xba00 , 0x0005, 0, NULL);
  404. ctrl_out(gspca_dev, 0x40, 1, 0xba00 + sharp, 0x00f1, 0, NULL);
  405. }
  406. if (hue != sd->vold.hue) {
  407. /* 0=normal 1=NB 2="sepia" 3=negative 4=other 5=other2 */
  408. if (hue < 0 || hue > sd->vmax.hue)
  409. hue = 0;
  410. if (hue == sd->vmax.hue)
  411. sd->swapRB = 1;
  412. else
  413. sd->swapRB = 0;
  414. ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
  415. ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
  416. ctrl_out(gspca_dev, 0x40, 1, 0xba70, 0x00e2, 0, NULL);
  417. ctrl_out(gspca_dev, 0x40, 1, 0xba00 + hue * (hue < 6), 0x00f1,
  418. 0, NULL);
  419. }
  420. if (backlight != sd->vold.backlight) {
  421. sd->vold.backlight = backlight;
  422. if (backlight < 0 || backlight > sd->vmax.backlight)
  423. backlight = 0;
  424. backlight = tbl_backlight[backlight];
  425. for (i = 0; i < 2; i++) {
  426. ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
  427. ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
  428. ctrl_out(gspca_dev, 0x40, 1, 0xba74, 0x0006, 0, NULL);
  429. ctrl_out(gspca_dev, 0x40, 1, 0xba80 + backlight, 0x00f1,
  430. 0, NULL);
  431. }
  432. }
  433. if (hue != sd->vold.hue) {
  434. sd->vold.hue = hue;
  435. ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
  436. ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
  437. ctrl_out(gspca_dev, 0x40, 1, 0xba70, 0x00e2, 0, NULL);
  438. ctrl_out(gspca_dev, 0x40, 1, 0xba00 + hue * (hue < 6), 0x00f1,
  439. 0, NULL);
  440. }
  441. if (mirror != sd->vold.mirror || flip != sd->vold.flip) {
  442. u8 dat_hvflip2[4] = {0x20, 0x01, 0xf1, 0x00};
  443. sd->vold.mirror = mirror;
  444. sd->vold.flip = flip;
  445. dat_hvflip2[3] = flip + 2 * mirror;
  446. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 4, dat_hvflip1);
  447. ctrl_out(gspca_dev, 0x40, 3, 0xba00, 0x0200, 4, dat_hvflip2);
  448. }
  449. if (gam != sd->vold.gamma) {
  450. sd->vold.gamma = gam;
  451. if (gam < 0 || gam > sd->vmax.gamma)
  452. gam = 0;
  453. gam = 2 * gam;
  454. ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
  455. ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
  456. ctrl_out(gspca_dev, 0x40, 1, 0xba04 , 0x003b, 0, NULL);
  457. ctrl_out(gspca_dev, 0x40, 1, 0xba02 + gam, 0x00f1, 0, NULL);
  458. }
  459. if (cntr != sd->vold.contrast) {
  460. sd->vold.contrast = cntr;
  461. if (cntr < 0 || cntr > sd->vmax.contrast)
  462. cntr = 0;
  463. ctrl_out(gspca_dev, 0x40, 1, 0xba00, 0x00f0, 0, NULL);
  464. ctrl_out(gspca_dev, 0x40, 1, 0xba01, 0x00f1, 0, NULL);
  465. ctrl_out(gspca_dev, 0x40, 1, 0xba00 + tbl_cntr1[cntr], 0x0035,
  466. 0, NULL);
  467. ctrl_out(gspca_dev, 0x40, 1, 0xba00 + tbl_cntr2[cntr], 0x00f1,
  468. 0, NULL);
  469. }
  470. return 0;
  471. }
  472. static void mi1320_post_unset_alt(struct gspca_dev *gspca_dev)
  473. {
  474. ctrl_out(gspca_dev, 0x40, 5, 0x0000, 0x0000, 0, NULL);
  475. fetch_validx(gspca_dev, tbl_post_unset_alt,
  476. ARRAY_SIZE(tbl_post_unset_alt));
  477. }