gl860-ov9655.c 11 KB

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