gl860-mi1320.c 18 KB

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