gl860-ov9655.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /* @file gl860-ov9655.c
  2. * @author Olivier LORIN, from logs done by Simon (Sur3) and Almighurt
  3. * on dsd's weblog
  4. * @date 2009-08-27
  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 : OV9655 */
  20. #include "gl860.h"
  21. static struct validx tbl_init_at_startup[] = {
  22. {0x0000, 0x0000}, {0x0010, 0x0010}, {0x0008, 0x00c0}, {0x0001, 0x00c1},
  23. {0x0001, 0x00c2}, {0x0020, 0x0006}, {0x006a, 0x000d},
  24. {0x0040, 0x0000},
  25. };
  26. static struct validx tbl_commmon[] = {
  27. {0x0041, 0x0000}, {0x006a, 0x0007}, {0x0063, 0x0006}, {0x006a, 0x000d},
  28. {0x0000, 0x00c0}, {0x0010, 0x0010}, {0x0001, 0x00c1}, {0x0041, 0x00c2},
  29. {0x0004, 0x00d8}, {0x0012, 0x0004}, {0x0000, 0x0058}, {0x0040, 0x0000},
  30. {0x00f3, 0x0006}, {0x0058, 0x0000}, {0x0048, 0x0000}, {0x0061, 0x0000},
  31. };
  32. static s32 tbl_length[] = {12, 56, 52, 54, 56, 42, 32, 12};
  33. static u8 *tbl_640[] = {
  34. "\x00\x40\x07\x6a\x06\xf3\x0d\x6a" "\x10\x10\xc1\x01"
  35. ,
  36. "\x12\x80\x00\x00\x01\x98\x02\x80" "\x03\x12\x04\x03\x0b\x57\x0e\x61"
  37. "\x0f\x42\x11\x01\x12\x60\x13\x00" "\x14\x3a\x16\x24\x17\x14\x18\x00"
  38. "\x19\x01\x1a\x3d\x1e\x04\x24\x3c" "\x25\x36\x26\x72\x27\x08\x28\x08"
  39. "\x29\x15\x2a\x00\x2b\x00\x2c\x08"
  40. ,
  41. "\x32\xff\x33\x00\x34\x3d\x35\x00" "\x36\xfa\x38\x72\x39\x57\x3a\x00"
  42. "\x3b\x0c\x3d\x99\x3e\x0c\x3f\xc1" "\x40\xc0\x41\x00\x42\xc0\x43\x0a"
  43. "\x44\xf0\x45\x46\x46\x62\x47\x2a" "\x48\x3c\x4a\xee\x4b\xe7\x4c\xe7"
  44. "\x4d\xe7\x4e\xe7"
  45. ,
  46. "\x4f\x98\x50\x98\x51\x00\x52\x28" "\x53\x70\x54\x98\x58\x1a\x59\x85"
  47. "\x5a\xa9\x5b\x64\x5c\x84\x5d\x53" "\x5e\x0e\x5f\xf0\x60\xf0\x61\xf0"
  48. "\x62\x00\x63\x00\x64\x02\x65\x20" "\x66\x00\x69\x0a\x6b\x5a\x6c\x04"
  49. "\x6d\x55\x6e\x00\x6f\x9d"
  50. ,
  51. "\x70\x15\x71\x78\x72\x00\x73\x00" "\x74\x3a\x75\x35\x76\x01\x77\x02"
  52. "\x7a\x24\x7b\x04\x7c\x07\x7d\x10" "\x7e\x28\x7f\x36\x80\x44\x81\x52"
  53. "\x82\x60\x83\x6c\x84\x78\x85\x8c" "\x86\x9e\x87\xbb\x88\xd2\x89\xe5"
  54. "\x8a\x23\x8c\x8d\x90\x7c\x91\x7b"
  55. ,
  56. "\x9d\x02\x9e\x02\x9f\x74\xa0\x73" "\xa1\x40\xa4\x50\xa5\x68\xa6\x70"
  57. "\xa8\xc1\xa9\xef\xaa\x92\xab\x04" "\xac\x80\xad\x80\xae\x80\xaf\x80"
  58. "\xb2\xf2\xb3\x20\xb4\x20\xb5\x00" "\xb6\xaf"
  59. ,
  60. "\xbb\xae\xbc\x4f\xbd\x4e\xbe\x6a" "\xbf\x68\xc0\xaa\xc1\xc0\xc2\x01"
  61. "\xc3\x4e\xc6\x85\xc7\x81\xc9\xe0" "\xca\xe8\xcb\xf0\xcc\xd8\xcd\x93"
  62. ,
  63. "\xd0\x01\xd1\x08\xd2\xe0\xd3\x01" "\xd4\x10\xd5\x80"
  64. };
  65. static u8 *tbl_800[] = {
  66. "\x00\x40\x07\x6a\x06\xf3\x0d\x6a" "\x10\x10\xc1\x01"
  67. ,
  68. "\x12\x80\x00\x00\x01\x98\x02\x80" "\x03\x12\x04\x01\x0b\x57\x0e\x61"
  69. "\x0f\x42\x11\x00\x12\x00\x13\x00" "\x14\x3a\x16\x24\x17\x1b\x18\xbb"
  70. "\x19\x01\x1a\x81\x1e\x04\x24\x3c" "\x25\x36\x26\x72\x27\x08\x28\x08"
  71. "\x29\x15\x2a\x00\x2b\x00\x2c\x08"
  72. ,
  73. "\x32\xa4\x33\x00\x34\x3d\x35\x00" "\x36\xf8\x38\x72\x39\x57\x3a\x00"
  74. "\x3b\x0c\x3d\x99\x3e\x0c\x3f\xc2" "\x40\xc0\x41\x00\x42\xc0\x43\x0a"
  75. "\x44\xf0\x45\x46\x46\x62\x47\x2a" "\x48\x3c\x4a\xec\x4b\xe8\x4c\xe8"
  76. "\x4d\xe8\x4e\xe8"
  77. ,
  78. "\x4f\x98\x50\x98\x51\x00\x52\x28" "\x53\x70\x54\x98\x58\x1a\x59\x85"
  79. "\x5a\xa9\x5b\x64\x5c\x84\x5d\x53" "\x5e\x0e\x5f\xf0\x60\xf0\x61\xf0"
  80. "\x62\x00\x63\x00\x64\x02\x65\x20" "\x66\x00\x69\x02\x6b\x5a\x6c\x04"
  81. "\x6d\x55\x6e\x00\x6f\x9d"
  82. ,
  83. "\x70\x08\x71\x78\x72\x00\x73\x01" "\x74\x3a\x75\x35\x76\x01\x77\x02"
  84. "\x7a\x24\x7b\x04\x7c\x07\x7d\x10" "\x7e\x28\x7f\x36\x80\x44\x81\x52"
  85. "\x82\x60\x83\x6c\x84\x78\x85\x8c" "\x86\x9e\x87\xbb\x88\xd2\x89\xe5"
  86. "\x8a\x23\x8c\x0d\x90\x90\x91\x90"
  87. ,
  88. "\x9d\x02\x9e\x02\x9f\x94\xa0\x94" "\xa1\x01\xa4\x50\xa5\x68\xa6\x70"
  89. "\xa8\xc1\xa9\xef\xaa\x92\xab\x04" "\xac\x80\xad\x80\xae\x80\xaf\x80"
  90. "\xb2\xf2\xb3\x20\xb4\x20\xb5\x00" "\xb6\xaf"
  91. ,
  92. "\xbb\xae\xbc\x38\xbd\x39\xbe\x01" "\xbf\x01\xc0\xe2\xc1\xc0\xc2\x01"
  93. "\xc3\x4e\xc6\x85\xc7\x81\xc9\xe0" "\xca\xe8\xcb\xf0\xcc\xd8\xcd\x93"
  94. ,
  95. "\xd0\x21\xd1\x18\xd2\xe0\xd3\x01" "\xd4\x28\xd5\x00"
  96. };
  97. static u8 c04[] = {0x04};
  98. static u8 dat_post_1[] = "\x04\x00\x10\x20\xa1\x00\x00\x02";
  99. static u8 dat_post_2[] = "\x10\x10\xc1\x02";
  100. static u8 dat_post_3[] = "\x04\x00\x10\x7c\xa1\x00\x00\x04";
  101. static u8 dat_post_4[] = "\x10\x02\xc1\x06";
  102. static u8 dat_post_5[] = "\x04\x00\x10\x7b\xa1\x00\x00\x08";
  103. static u8 dat_post_6[] = "\x10\x10\xc1\x05";
  104. static u8 dat_post_7[] = "\x04\x00\x10\x7c\xa1\x00\x00\x08";
  105. static u8 dat_post_8[] = "\x04\x00\x10\x7c\xa1\x00\x00\x09";
  106. static struct validx tbl_init_post_alt[] = {
  107. {0x6032, 0x00ff}, {0x6032, 0x00ff}, {0x6032, 0x00ff}, {0x603c, 0x00ff},
  108. {0x6003, 0x00ff}, {0x6032, 0x00ff}, {0x6032, 0x00ff}, {0x6001, 0x00ff},
  109. {0x6000, 0x801e},
  110. {0xffff, 0xffff},
  111. {0x6004, 0x001e}, {0x6000, 0x801e},
  112. {0xffff, 0xffff},
  113. {0x6004, 0x001e}, {0x6012, 0x0003}, {0x6000, 0x801e},
  114. {0xffff, 0xffff},
  115. {0x6004, 0x001e}, {0x6000, 0x801e},
  116. {0xffff, 0xffff},
  117. {0x6004, 0x001e}, {0x6012, 0x0003},
  118. {0xffff, 0xffff},
  119. {0x6000, 0x801e},
  120. {0xffff, 0xffff},
  121. {0x6004, 0x001e}, {0x6000, 0x801e},
  122. {0xffff, 0xffff},
  123. {0x6004, 0x001e}, {0x6012, 0x0003}, {0x6000, 0x801e},
  124. {0xffff, 0xffff},
  125. {0x6004, 0x001e}, {0x6000, 0x801e},
  126. {0xffff, 0xffff},
  127. {0x6004, 0x001e}, {0x6012, 0x0003},
  128. {0xffff, 0xffff},
  129. {0x6000, 0x801e},
  130. {0xffff, 0xffff},
  131. {0x6004, 0x001e}, {0x6000, 0x801e},
  132. {0xffff, 0xffff},
  133. {0x6004, 0x001e}, {0x6012, 0x0003},
  134. };
  135. static int ov9655_init_at_startup(struct gspca_dev *gspca_dev);
  136. static int ov9655_configure_alt(struct gspca_dev *gspca_dev);
  137. static int ov9655_init_pre_alt(struct gspca_dev *gspca_dev);
  138. static int ov9655_init_post_alt(struct gspca_dev *gspca_dev);
  139. static void ov9655_post_unset_alt(struct gspca_dev *gspca_dev);
  140. static int ov9655_camera_settings(struct gspca_dev *gspca_dev);
  141. /*==========================================================================*/
  142. void ov9655_init_settings(struct gspca_dev *gspca_dev)
  143. {
  144. struct sd *sd = (struct sd *) gspca_dev;
  145. sd->vcur.backlight = 0;
  146. sd->vcur.brightness = 128;
  147. sd->vcur.sharpness = 0;
  148. sd->vcur.contrast = 0;
  149. sd->vcur.gamma = 0;
  150. sd->vcur.hue = 0;
  151. sd->vcur.saturation = 0;
  152. sd->vcur.whitebal = 0;
  153. sd->vmax.backlight = 0;
  154. sd->vmax.brightness = 255;
  155. sd->vmax.sharpness = 0;
  156. sd->vmax.contrast = 0;
  157. sd->vmax.gamma = 0;
  158. sd->vmax.hue = 0 + 1;
  159. sd->vmax.saturation = 0;
  160. sd->vmax.whitebal = 0;
  161. sd->vmax.mirror = 0;
  162. sd->vmax.flip = 0;
  163. sd->vmax.AC50Hz = 0;
  164. sd->dev_camera_settings = ov9655_camera_settings;
  165. sd->dev_init_at_startup = ov9655_init_at_startup;
  166. sd->dev_configure_alt = ov9655_configure_alt;
  167. sd->dev_init_pre_alt = ov9655_init_pre_alt;
  168. sd->dev_post_unset_alt = ov9655_post_unset_alt;
  169. }
  170. /*==========================================================================*/
  171. static int ov9655_init_at_startup(struct gspca_dev *gspca_dev)
  172. {
  173. fetch_validx(gspca_dev, tbl_init_at_startup,
  174. ARRAY_SIZE(tbl_init_at_startup));
  175. fetch_validx(gspca_dev, tbl_commmon, ARRAY_SIZE(tbl_commmon));
  176. /* ctrl_out(gspca_dev, 0x40, 11, 0x0000, 0x0000, 0, NULL);*/
  177. return 0;
  178. }
  179. static int ov9655_init_pre_alt(struct gspca_dev *gspca_dev)
  180. {
  181. struct sd *sd = (struct sd *) gspca_dev;
  182. sd->vold.brightness = -1;
  183. sd->vold.hue = -1;
  184. fetch_validx(gspca_dev, tbl_commmon, ARRAY_SIZE(tbl_commmon));
  185. ov9655_init_post_alt(gspca_dev);
  186. return 0;
  187. }
  188. static int ov9655_init_post_alt(struct gspca_dev *gspca_dev)
  189. {
  190. s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
  191. s32 n; /* reserved for FETCH macros */
  192. s32 i;
  193. u8 **tbl;
  194. ctrl_out(gspca_dev, 0x40, 5, 0x0001, 0x0000, 0, NULL);
  195. tbl = (reso == IMAGE_640) ? tbl_640 : tbl_800;
  196. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
  197. tbl_length[0], tbl[0]);
  198. for (i = 1; i < 7; i++)
  199. ctrl_out(gspca_dev, 0x40, 3, 0x6000, 0x0200,
  200. tbl_length[i], tbl[i]);
  201. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
  202. tbl_length[7], tbl[7]);
  203. n = fetch_validx(gspca_dev, tbl_init_post_alt,
  204. ARRAY_SIZE(tbl_init_post_alt));
  205. ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x801e, 1, c04);
  206. keep_on_fetching_validx(gspca_dev, tbl_init_post_alt,
  207. ARRAY_SIZE(tbl_init_post_alt), n);
  208. ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x801e, 1, c04);
  209. keep_on_fetching_validx(gspca_dev, tbl_init_post_alt,
  210. ARRAY_SIZE(tbl_init_post_alt), n);
  211. ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x801e, 1, c04);
  212. keep_on_fetching_validx(gspca_dev, tbl_init_post_alt,
  213. ARRAY_SIZE(tbl_init_post_alt), n);
  214. ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x801e, 1, c04);
  215. keep_on_fetching_validx(gspca_dev, tbl_init_post_alt,
  216. ARRAY_SIZE(tbl_init_post_alt), n);
  217. ctrl_out(gspca_dev, 0x40, 3, 0x6000, 0x0200, 8, dat_post_1);
  218. keep_on_fetching_validx(gspca_dev, tbl_init_post_alt,
  219. ARRAY_SIZE(tbl_init_post_alt), n);
  220. ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x801e, 1, c04);
  221. keep_on_fetching_validx(gspca_dev, tbl_init_post_alt,
  222. ARRAY_SIZE(tbl_init_post_alt), n);
  223. ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x801e, 1, c04);
  224. keep_on_fetching_validx(gspca_dev, tbl_init_post_alt,
  225. ARRAY_SIZE(tbl_init_post_alt), n);
  226. ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x801e, 1, c04);
  227. keep_on_fetching_validx(gspca_dev, tbl_init_post_alt,
  228. ARRAY_SIZE(tbl_init_post_alt), n);
  229. ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x801e, 1, c04);
  230. keep_on_fetching_validx(gspca_dev, tbl_init_post_alt,
  231. ARRAY_SIZE(tbl_init_post_alt), n);
  232. ctrl_out(gspca_dev, 0x40, 3, 0x6000, 0x0200, 8, dat_post_1);
  233. keep_on_fetching_validx(gspca_dev, tbl_init_post_alt,
  234. ARRAY_SIZE(tbl_init_post_alt), n);
  235. ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x801e, 1, c04);
  236. keep_on_fetching_validx(gspca_dev, tbl_init_post_alt,
  237. ARRAY_SIZE(tbl_init_post_alt), n);
  238. ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x801e, 1, c04);
  239. keep_on_fetching_validx(gspca_dev, tbl_init_post_alt,
  240. ARRAY_SIZE(tbl_init_post_alt), n);
  241. ctrl_out(gspca_dev, 0x40, 3, 0x6000, 0x0200, 8, dat_post_1);
  242. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 4, dat_post_2);
  243. ctrl_out(gspca_dev, 0x40, 3, 0x6000, 0x0200, 8, dat_post_3);
  244. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 4, dat_post_4);
  245. ctrl_out(gspca_dev, 0x40, 3, 0x6000, 0x0200, 8, dat_post_5);
  246. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 4, dat_post_6);
  247. ctrl_out(gspca_dev, 0x40, 3, 0x6000, 0x0200, 8, dat_post_7);
  248. ctrl_out(gspca_dev, 0x40, 3, 0x6000, 0x0200, 8, dat_post_8);
  249. ov9655_camera_settings(gspca_dev);
  250. return 0;
  251. }
  252. static int ov9655_configure_alt(struct gspca_dev *gspca_dev)
  253. {
  254. s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
  255. switch (reso) {
  256. case IMAGE_640:
  257. gspca_dev->alt = 1 + 1;
  258. break;
  259. default:
  260. gspca_dev->alt = 1 + 1;
  261. break;
  262. }
  263. return 0;
  264. }
  265. static int ov9655_camera_settings(struct gspca_dev *gspca_dev)
  266. {
  267. struct sd *sd = (struct sd *) gspca_dev;
  268. u8 dat_bright[] = "\x04\x00\x10\x7c\xa1\x00\x00\x70";
  269. s32 bright = sd->vcur.brightness;
  270. s32 hue = sd->vcur.hue;
  271. if (bright != sd->vold.brightness) {
  272. sd->vold.brightness = bright;
  273. if (bright < 0 || bright > sd->vmax.brightness)
  274. bright = 0;
  275. dat_bright[3] = bright;
  276. ctrl_out(gspca_dev, 0x40, 3, 0x6000, 0x0200, 8, dat_bright);
  277. }
  278. if (hue != sd->vold.hue) {
  279. sd->vold.hue = hue;
  280. sd->swapRB = (hue != 0);
  281. }
  282. return 0;
  283. }
  284. static void ov9655_post_unset_alt(struct gspca_dev *gspca_dev)
  285. {
  286. ctrl_out(gspca_dev, 0x40, 5, 0x0000, 0x0000, 0, NULL);
  287. ctrl_out(gspca_dev, 0x40, 1, 0x0061, 0x0000, 0, NULL);
  288. }