gl860-ov9655.c 12 KB

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