gl860-ov2640.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /* Subdriver for the GL860 chip with the OV2640 sensor
  2. * Author Olivier LORIN, from Malmostoso's logs
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /* Sensor : OV2640 */
  18. #include "gl860.h"
  19. static u8 dat_init1[] = "\x00\x41\x07\x6a\x06\x61\x0d\x6a" "\x10\x10\xc1\x01";
  20. static u8 dat_init2[] = {0x61}; /* expected */
  21. static u8 dat_init3[] = {0x51}; /* expected */
  22. static u8 dat_post[] =
  23. "\x00\x41\x07\x6a\x06\xef\x0d\x6a" "\x10\x10\xc1\x01";
  24. static u8 dat_640[] = "\xd0\x01\xd1\x08\xd2\xe0\xd3\x02\xd4\x10\xd5\x81";
  25. static u8 dat_800[] = "\xd0\x01\xd1\x10\xd2\x58\xd3\x02\xd4\x18\xd5\x21";
  26. static u8 dat_1280[] = "\xd0\x01\xd1\x18\xd2\xc0\xd3\x02\xd4\x28\xd5\x01";
  27. static u8 dat_1600[] = "\xd0\x01\xd1\x20\xd2\xb0\xd3\x02\xd4\x30\xd5\x41";
  28. static u8 c50[] = {0x50}; /* expected */
  29. static u8 c28[] = {0x28}; /* expected */
  30. static u8 ca8[] = {0xa8}; /* expected */
  31. static struct validx tbl_init_at_startup[] = {
  32. {0x0000, 0x0000}, {0x0010, 0x0010}, {0x0008, 0x00c0}, {0x0001, 0x00c1},
  33. {0x0001, 0x00c2}, {0x0020, 0x0006}, {0x006a, 0x000d},
  34. {0x0050, 0x0000}, {0x0041, 0x0000}, {0x006a, 0x0007}, {0x0061, 0x0006},
  35. {0x006a, 0x000d}, {0x0000, 0x00c0}, {0x0010, 0x0010}, {0x0001, 0x00c1},
  36. {0x0041, 0x00c2}, {0x0004, 0x00d8}, {0x0012, 0x0004}, {0x0000, 0x0058},
  37. {0x0041, 0x0000}, {0x0061, 0x0000},
  38. };
  39. static struct validx tbl_common[] = {
  40. {0x6000, 0x00ff}, {0x60ff, 0x002c}, {0x60df, 0x002e}, {0x6001, 0x00ff},
  41. {0x6080, 0x0012}, {0x6000, 0x0000}, {0x6000, 0x0045}, {0x6000, 0x0010},
  42. {0x6035, 0x003c}, {0x6000, 0x0011}, {0x6028, 0x0004}, {0x60e5, 0x0013},
  43. {0x6088, 0x0014}, {0x600c, 0x002c}, {0x6078, 0x0033}, {0x60f7, 0x003b},
  44. {0x6000, 0x003e}, {0x6011, 0x0043}, {0x6010, 0x0016}, {0x6082, 0x0039},
  45. {0x6088, 0x0035}, {0x600a, 0x0022}, {0x6040, 0x0037}, {0x6000, 0x0023},
  46. {0x60a0, 0x0034}, {0x601a, 0x0036}, {0x6002, 0x0006}, {0x60c0, 0x0007},
  47. {0x60b7, 0x000d}, {0x6001, 0x000e}, {0x6000, 0x004c}, {0x6081, 0x004a},
  48. {0x6099, 0x0021}, {0x6002, 0x0009}, {0x603e, 0x0024}, {0x6034, 0x0025},
  49. {0x6081, 0x0026}, {0x6000, 0x0000}, {0x6000, 0x0045}, {0x6000, 0x0010},
  50. {0x6000, 0x005c}, {0x6000, 0x0063}, {0x6000, 0x007c}, {0x6070, 0x0061},
  51. {0x6080, 0x0062}, {0x6080, 0x0020}, {0x6030, 0x0028}, {0x6000, 0x006c},
  52. {0x6000, 0x006e}, {0x6002, 0x0070}, {0x6094, 0x0071}, {0x60c1, 0x0073},
  53. {0x6034, 0x003d}, {0x6057, 0x005a}, {0x60bb, 0x004f}, {0x609c, 0x0050},
  54. {0x6080, 0x006d}, {0x6002, 0x0039}, {0x6033, 0x003a}, {0x60f1, 0x003b},
  55. {0x6031, 0x003c}, {0x6000, 0x00ff}, {0x6014, 0x00e0}, {0x60ff, 0x0076},
  56. {0x60a0, 0x0033}, {0x6020, 0x0042}, {0x6018, 0x0043}, {0x6000, 0x004c},
  57. {0x60d0, 0x0087}, {0x600f, 0x0088}, {0x6003, 0x00d7}, {0x6010, 0x00d9},
  58. {0x6005, 0x00da}, {0x6082, 0x00d3}, {0x60c0, 0x00f9}, {0x6006, 0x0044},
  59. {0x6007, 0x00d1}, {0x6002, 0x00d2}, {0x6000, 0x00d2}, {0x6011, 0x00d8},
  60. {0x6008, 0x00c8}, {0x6080, 0x00c9}, {0x6008, 0x007c}, {0x6020, 0x007d},
  61. {0x6020, 0x007d}, {0x6000, 0x0090}, {0x600e, 0x0091}, {0x601a, 0x0091},
  62. {0x6031, 0x0091}, {0x605a, 0x0091}, {0x6069, 0x0091}, {0x6075, 0x0091},
  63. {0x607e, 0x0091}, {0x6088, 0x0091}, {0x608f, 0x0091}, {0x6096, 0x0091},
  64. {0x60a3, 0x0091}, {0x60af, 0x0091}, {0x60c4, 0x0091}, {0x60d7, 0x0091},
  65. {0x60e8, 0x0091}, {0x6020, 0x0091}, {0x6000, 0x0092}, {0x6006, 0x0093},
  66. {0x60e3, 0x0093}, {0x6005, 0x0093}, {0x6005, 0x0093}, {0x6000, 0x0093},
  67. {0x6004, 0x0093}, {0x6000, 0x0093}, {0x6000, 0x0093}, {0x6000, 0x0093},
  68. {0x6000, 0x0093}, {0x6000, 0x0093}, {0x6000, 0x0093}, {0x6000, 0x0093},
  69. {0x6000, 0x0096}, {0x6008, 0x0097}, {0x6019, 0x0097}, {0x6002, 0x0097},
  70. {0x600c, 0x0097}, {0x6024, 0x0097}, {0x6030, 0x0097}, {0x6028, 0x0097},
  71. {0x6026, 0x0097}, {0x6002, 0x0097}, {0x6098, 0x0097}, {0x6080, 0x0097},
  72. {0x6000, 0x0097}, {0x6000, 0x0097}, {0x60ed, 0x00c3}, {0x609a, 0x00c4},
  73. {0x6000, 0x00a4}, {0x6011, 0x00c5}, {0x6051, 0x00c6}, {0x6010, 0x00c7},
  74. {0x6066, 0x00b6}, {0x60a5, 0x00b8}, {0x6064, 0x00b7}, {0x607c, 0x00b9},
  75. {0x60af, 0x00b3}, {0x6097, 0x00b4}, {0x60ff, 0x00b5}, {0x60c5, 0x00b0},
  76. {0x6094, 0x00b1}, {0x600f, 0x00b2}, {0x605c, 0x00c4}, {0x6000, 0x00a8},
  77. {0x60c8, 0x00c0}, {0x6096, 0x00c1}, {0x601d, 0x0086}, {0x6000, 0x0050},
  78. {0x6090, 0x0051}, {0x6018, 0x0052}, {0x6000, 0x0053}, {0x6000, 0x0054},
  79. {0x6088, 0x0055}, {0x6000, 0x0057}, {0x6090, 0x005a}, {0x6018, 0x005b},
  80. {0x6005, 0x005c}, {0x60ed, 0x00c3}, {0x6000, 0x007f}, {0x6005, 0x00da},
  81. {0x601f, 0x00e5}, {0x6067, 0x00e1}, {0x6000, 0x00e0}, {0x60ff, 0x00dd},
  82. {0x6000, 0x0005}, {0x6001, 0x00ff}, {0x6000, 0x0000}, {0x6000, 0x0045},
  83. {0x6000, 0x0010},
  84. };
  85. static struct validx tbl_sensor_settings_common1[] = {
  86. {0x0041, 0x0000}, {0x006a, 0x0007}, {0x00ef, 0x0006}, {0x006a, 0x000d},
  87. {0x0000, 0x00c0}, {0x0010, 0x0010}, {0x0001, 0x00c1}, {0x0041, 0x00c2},
  88. {0x0004, 0x00d8}, {0x0012, 0x0004}, {0x0000, 0x0058}, {0x0041, 0x0000},
  89. {50, 0xffff},
  90. {0x0061, 0x0000},
  91. {0xffff, 0xffff},
  92. {0x6000, 0x00ff}, {0x6000, 0x007c}, {0x6007, 0x007d},
  93. {30, 0xffff},
  94. {0x0040, 0x0000},
  95. };
  96. static struct validx tbl_sensor_settings_common2[] = {
  97. {0x6001, 0x00ff}, {0x6038, 0x000c},
  98. {10, 0xffff},
  99. {0x6000, 0x0011},
  100. /* backlight=31/64 */
  101. {0x6001, 0x00ff}, {0x603e, 0x0024}, {0x6034, 0x0025},
  102. /* bright=0/256 */
  103. {0x6000, 0x00ff}, {0x6009, 0x007c}, {0x6000, 0x007d},
  104. /* wbal=64/128 */
  105. {0x6000, 0x00ff}, {0x6003, 0x007c}, {0x6040, 0x007d},
  106. /* cntr=0/256 */
  107. {0x6000, 0x00ff}, {0x6007, 0x007c}, {0x6000, 0x007d},
  108. /* sat=128/256 */
  109. {0x6000, 0x00ff}, {0x6001, 0x007c}, {0x6080, 0x007d},
  110. /* sharpness=0/32 */
  111. {0x6000, 0x00ff}, {0x6001, 0x0092}, {0x60c0, 0x0093},
  112. /* hue=0/256 */
  113. {0x6000, 0x00ff}, {0x6002, 0x007c}, {0x6000, 0x007d},
  114. /* gam=32/64 */
  115. {0x6000, 0x00ff}, {0x6008, 0x007c}, {0x6020, 0x007d},
  116. /* image right up */
  117. {0xffff, 0xffff},
  118. {15, 0xffff},
  119. {0x6001, 0x00ff}, {0x6000, 0x8004},
  120. {0xffff, 0xffff},
  121. {0x60a8, 0x0004},
  122. {15, 0xffff},
  123. {0x6001, 0x00ff}, {0x6000, 0x8004},
  124. {0xffff, 0xffff},
  125. {0x60f8, 0x0004},
  126. /* image right up */
  127. {0xffff, 0xffff},
  128. /* backlight=31/64 */
  129. {0x6001, 0x00ff}, {0x603e, 0x0024}, {0x6034, 0x0025},
  130. };
  131. static struct validx tbl_640[] = {
  132. {0x6000, 0x00ff}, {0x60f1, 0x00dd}, {0x6004, 0x00e0}, {0x6067, 0x00e1},
  133. {0x6004, 0x00da}, {0x6000, 0x00ff}, {0x60f1, 0x00dd}, {0x6004, 0x00e0},
  134. {0x6001, 0x00ff}, {0x6000, 0x0012}, {0x6000, 0x0011}, {0x6011, 0x0017},
  135. {0x6075, 0x0018}, {0x6001, 0x0019}, {0x6097, 0x001a}, {0x6036, 0x0032},
  136. {0x60bb, 0x004f}, {0x6057, 0x005a}, {0x609c, 0x0050}, {0x6080, 0x006d},
  137. {0x6092, 0x0026}, {0x60ff, 0x0020}, {0x6000, 0x0027}, {0x6000, 0x00ff},
  138. {0x60c8, 0x00c0}, {0x6096, 0x00c1}, {0x6000, 0x008c}, {0x603d, 0x0086},
  139. {0x6089, 0x0050}, {0x6090, 0x0051}, {0x602c, 0x0052}, {0x6000, 0x0053},
  140. {0x6000, 0x0054}, {0x6088, 0x0055}, {0x6000, 0x0057}, {0x60a0, 0x005a},
  141. {0x6078, 0x005b}, {0x6000, 0x005c}, {0x6004, 0x00d3}, {0x6000, 0x00e0},
  142. {0x60ff, 0x00dd}, {0x60a1, 0x005a},
  143. };
  144. static struct validx tbl_800[] = {
  145. {0x6000, 0x00ff}, {0x60f1, 0x00dd}, {0x6004, 0x00e0}, {0x6067, 0x00e1},
  146. {0x6004, 0x00da}, {0x6000, 0x00ff}, {0x60f1, 0x00dd}, {0x6004, 0x00e0},
  147. {0x6001, 0x00ff}, {0x6040, 0x0012}, {0x6000, 0x0011}, {0x6011, 0x0017},
  148. {0x6043, 0x0018}, {0x6000, 0x0019}, {0x604b, 0x001a}, {0x6009, 0x0032},
  149. {0x60ca, 0x004f}, {0x60a8, 0x0050}, {0x6000, 0x006d}, {0x6038, 0x003d},
  150. {0x60c8, 0x0035}, {0x6000, 0x0022}, {0x6092, 0x0026}, {0x60ff, 0x0020},
  151. {0x6000, 0x0027}, {0x6000, 0x00ff}, {0x6064, 0x00c0}, {0x604b, 0x00c1},
  152. {0x6000, 0x008c}, {0x601d, 0x0086}, {0x6082, 0x00d3}, {0x6000, 0x00e0},
  153. {0x60ff, 0x00dd}, {0x6020, 0x008c}, {0x6001, 0x00ff}, {0x6044, 0x0018},
  154. };
  155. static struct validx tbl_big1[] = {
  156. {0x0002, 0x00c1}, {0x6000, 0x00ff}, {0x60f1, 0x00dd}, {0x6004, 0x00e0},
  157. {0x6001, 0x00ff}, {0x6000, 0x0012}, {0x6000, 0x0000}, {0x6000, 0x0045},
  158. {0x6000, 0x0010}, {0x6000, 0x0011}, {0x6011, 0x0017}, {0x6075, 0x0018},
  159. {0x6001, 0x0019}, {0x6097, 0x001a}, {0x6036, 0x0032}, {0x60bb, 0x004f},
  160. {0x609c, 0x0050}, {0x6057, 0x005a}, {0x6080, 0x006d}, {0x6043, 0x000f},
  161. {0x608f, 0x0003}, {0x6005, 0x007c}, {0x6081, 0x0026}, {0x6000, 0x00ff},
  162. {0x60c8, 0x00c0}, {0x6096, 0x00c1}, {0x6000, 0x008c},
  163. };
  164. static struct validx tbl_big2[] = {
  165. {0x603d, 0x0086}, {0x6000, 0x0050}, {0x6090, 0x0051}, {0x602c, 0x0052},
  166. {0x6000, 0x0053}, {0x6000, 0x0054}, {0x6088, 0x0055}, {0x6000, 0x0057},
  167. {0x6040, 0x005a}, {0x60f0, 0x005b}, {0x6001, 0x005c}, {0x6082, 0x00d3},
  168. {0x6000, 0x008e},
  169. };
  170. static struct validx tbl_big3[] = {
  171. {0x6004, 0x00da}, {0x6000, 0x00e0}, {0x6067, 0x00e1}, {0x60ff, 0x00dd},
  172. {0x6001, 0x00ff}, {0x6000, 0x00ff}, {0x60f1, 0x00dd}, {0x6004, 0x00e0},
  173. {0x6001, 0x00ff}, {0x6000, 0x0011}, {0x6000, 0x00ff}, {0x6010, 0x00c7},
  174. {0x6000, 0x0092}, {0x6006, 0x0093}, {0x60e3, 0x0093}, {0x6005, 0x0093},
  175. {0x6005, 0x0093}, {0x60ed, 0x00c3}, {0x6000, 0x00a4}, {0x60d0, 0x0087},
  176. {0x6003, 0x0096}, {0x600c, 0x0097}, {0x6024, 0x0097}, {0x6030, 0x0097},
  177. {0x6028, 0x0097}, {0x6026, 0x0097}, {0x6002, 0x0097}, {0x6001, 0x00ff},
  178. {0x6043, 0x000f}, {0x608f, 0x0003}, {0x6000, 0x002d}, {0x6000, 0x002e},
  179. {0x600a, 0x0022}, {0x6002, 0x0070}, {0x6008, 0x0014}, {0x6048, 0x0014},
  180. {0x6000, 0x00ff}, {0x6000, 0x00e0}, {0x60ff, 0x00dd},
  181. };
  182. static struct validx tbl_post_unset_alt[] = {
  183. {0x006a, 0x000d}, {0x6001, 0x00ff}, {0x6081, 0x0026}, {0x6000, 0x0000},
  184. {0x6000, 0x0045}, {0x6000, 0x0010}, {0x6068, 0x000d},
  185. {50, 0xffff},
  186. {0x0021, 0x0000},
  187. };
  188. static int ov2640_init_at_startup(struct gspca_dev *gspca_dev);
  189. static int ov2640_configure_alt(struct gspca_dev *gspca_dev);
  190. static int ov2640_init_pre_alt(struct gspca_dev *gspca_dev);
  191. static int ov2640_init_post_alt(struct gspca_dev *gspca_dev);
  192. static void ov2640_post_unset_alt(struct gspca_dev *gspca_dev);
  193. static int ov2640_camera_settings(struct gspca_dev *gspca_dev);
  194. /*==========================================================================*/
  195. void ov2640_init_settings(struct gspca_dev *gspca_dev)
  196. {
  197. struct sd *sd = (struct sd *) gspca_dev;
  198. sd->vcur.backlight = 32;
  199. sd->vcur.brightness = 0;
  200. sd->vcur.sharpness = 6;
  201. sd->vcur.contrast = 0;
  202. sd->vcur.gamma = 32;
  203. sd->vcur.hue = 0;
  204. sd->vcur.saturation = 128;
  205. sd->vcur.whitebal = 64;
  206. sd->vmax.backlight = 64;
  207. sd->vmax.brightness = 255;
  208. sd->vmax.sharpness = 31;
  209. sd->vmax.contrast = 255;
  210. sd->vmax.gamma = 64;
  211. sd->vmax.hue = 255 + 1;
  212. sd->vmax.saturation = 255;
  213. sd->vmax.whitebal = 128;
  214. sd->vmax.mirror = 0;
  215. sd->vmax.flip = 0;
  216. sd->vmax.AC50Hz = 0;
  217. sd->dev_camera_settings = ov2640_camera_settings;
  218. sd->dev_init_at_startup = ov2640_init_at_startup;
  219. sd->dev_configure_alt = ov2640_configure_alt;
  220. sd->dev_init_pre_alt = ov2640_init_pre_alt;
  221. sd->dev_post_unset_alt = ov2640_post_unset_alt;
  222. }
  223. /*==========================================================================*/
  224. static void common(struct gspca_dev *gspca_dev)
  225. {
  226. fetch_validx(gspca_dev, tbl_common, ARRAY_SIZE(tbl_common));
  227. }
  228. static int ov2640_init_at_startup(struct gspca_dev *gspca_dev)
  229. {
  230. fetch_validx(gspca_dev, tbl_init_at_startup,
  231. ARRAY_SIZE(tbl_init_at_startup));
  232. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, dat_init1);
  233. common(gspca_dev);
  234. ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0006, 1, dat_init2);
  235. ctrl_out(gspca_dev, 0x40, 1, 0x00ef, 0x0006, 0, NULL);
  236. ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0000, 1, dat_init3);
  237. ctrl_out(gspca_dev, 0x40, 1, 0x0051, 0x0000, 0, NULL);
  238. /* ctrl_out(gspca_dev, 0x40, 11, 0x0000, 0x0000, 0, NULL); */
  239. return 0;
  240. }
  241. static int ov2640_init_pre_alt(struct gspca_dev *gspca_dev)
  242. {
  243. struct sd *sd = (struct sd *) gspca_dev;
  244. sd->mirrorMask = 0;
  245. sd->vold.backlight = -1;
  246. sd->vold.brightness = -1;
  247. sd->vold.sharpness = -1;
  248. sd->vold.contrast = -1;
  249. sd->vold.saturation = -1;
  250. sd->vold.gamma = -1;
  251. sd->vold.hue = -1;
  252. sd->vold.whitebal = -1;
  253. ov2640_init_post_alt(gspca_dev);
  254. return 0;
  255. }
  256. static int ov2640_init_post_alt(struct gspca_dev *gspca_dev)
  257. {
  258. s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
  259. s32 n; /* reserved for FETCH functions */
  260. ctrl_out(gspca_dev, 0x40, 5, 0x0001, 0x0000, 0, NULL);
  261. n = fetch_validx(gspca_dev, tbl_sensor_settings_common1,
  262. ARRAY_SIZE(tbl_sensor_settings_common1));
  263. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, dat_post);
  264. common(gspca_dev);
  265. keep_on_fetching_validx(gspca_dev, tbl_sensor_settings_common1,
  266. ARRAY_SIZE(tbl_sensor_settings_common1), n);
  267. switch (reso) {
  268. case IMAGE_640:
  269. n = fetch_validx(gspca_dev, tbl_640, ARRAY_SIZE(tbl_640));
  270. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, dat_640);
  271. break;
  272. case IMAGE_800:
  273. n = fetch_validx(gspca_dev, tbl_800, ARRAY_SIZE(tbl_800));
  274. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 12, dat_800);
  275. break;
  276. case IMAGE_1600:
  277. case IMAGE_1280:
  278. n = fetch_validx(gspca_dev, tbl_big1, ARRAY_SIZE(tbl_big1));
  279. if (reso == IMAGE_1280) {
  280. n = fetch_validx(gspca_dev, tbl_big2,
  281. ARRAY_SIZE(tbl_big2));
  282. } else {
  283. ctrl_out(gspca_dev, 0x40, 1, 0x601d, 0x0086, 0, NULL);
  284. ctrl_out(gspca_dev, 0x40, 1, 0x6001, 0x00d7, 0, NULL);
  285. ctrl_out(gspca_dev, 0x40, 1, 0x6082, 0x00d3, 0, NULL);
  286. }
  287. n = fetch_validx(gspca_dev, tbl_big3, ARRAY_SIZE(tbl_big3));
  288. if (reso == IMAGE_1280) {
  289. ctrl_out(gspca_dev, 0x40, 1, 0x6001, 0x00ff, 0, NULL);
  290. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
  291. 12, dat_1280);
  292. } else {
  293. ctrl_out(gspca_dev, 0x40, 1, 0x6020, 0x008c, 0, NULL);
  294. ctrl_out(gspca_dev, 0x40, 1, 0x6001, 0x00ff, 0, NULL);
  295. ctrl_out(gspca_dev, 0x40, 1, 0x6076, 0x0018, 0, NULL);
  296. ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
  297. 12, dat_1600);
  298. }
  299. break;
  300. }
  301. n = fetch_validx(gspca_dev, tbl_sensor_settings_common2,
  302. ARRAY_SIZE(tbl_sensor_settings_common2));
  303. ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0000, 1, c50);
  304. keep_on_fetching_validx(gspca_dev, tbl_sensor_settings_common2,
  305. ARRAY_SIZE(tbl_sensor_settings_common2), n);
  306. ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x8004, 1, c28);
  307. keep_on_fetching_validx(gspca_dev, tbl_sensor_settings_common2,
  308. ARRAY_SIZE(tbl_sensor_settings_common2), n);
  309. ctrl_in(gspca_dev, 0xc0, 2, 0x6000, 0x8004, 1, ca8);
  310. keep_on_fetching_validx(gspca_dev, tbl_sensor_settings_common2,
  311. ARRAY_SIZE(tbl_sensor_settings_common2), n);
  312. ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0000, 1, c50);
  313. keep_on_fetching_validx(gspca_dev, tbl_sensor_settings_common2,
  314. ARRAY_SIZE(tbl_sensor_settings_common2), n);
  315. ov2640_camera_settings(gspca_dev);
  316. return 0;
  317. }
  318. static int ov2640_configure_alt(struct gspca_dev *gspca_dev)
  319. {
  320. s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
  321. switch (reso) {
  322. case IMAGE_640:
  323. gspca_dev->alt = 3 + 1;
  324. break;
  325. case IMAGE_800:
  326. case IMAGE_1280:
  327. case IMAGE_1600:
  328. gspca_dev->alt = 1 + 1;
  329. break;
  330. }
  331. return 0;
  332. }
  333. static int ov2640_camera_settings(struct gspca_dev *gspca_dev)
  334. {
  335. struct sd *sd = (struct sd *) gspca_dev;
  336. s32 backlight = sd->vcur.backlight;
  337. s32 bright = sd->vcur.brightness;
  338. s32 sharp = sd->vcur.sharpness;
  339. s32 gam = sd->vcur.gamma;
  340. s32 cntr = sd->vcur.contrast;
  341. s32 sat = sd->vcur.saturation;
  342. s32 hue = sd->vcur.hue;
  343. s32 wbal = sd->vcur.whitebal;
  344. if (backlight != sd->vold.backlight) {
  345. /* No sd->vold.backlight=backlight; (to be done again later) */
  346. if (backlight < 0 || backlight > sd->vmax.backlight)
  347. backlight = 0;
  348. ctrl_out(gspca_dev, 0x40, 1, 0x6001 , 0x00ff,
  349. 0, NULL);
  350. ctrl_out(gspca_dev, 0x40, 1, 0x601f + backlight , 0x0024,
  351. 0, NULL);
  352. ctrl_out(gspca_dev, 0x40, 1, 0x601f + backlight - 10, 0x0025,
  353. 0, NULL);
  354. }
  355. if (bright != sd->vold.brightness) {
  356. sd->vold.brightness = bright;
  357. if (bright < 0 || bright > sd->vmax.brightness)
  358. bright = 0;
  359. ctrl_out(gspca_dev, 0x40, 1, 0x6000 , 0x00ff, 0, NULL);
  360. ctrl_out(gspca_dev, 0x40, 1, 0x6009 , 0x007c, 0, NULL);
  361. ctrl_out(gspca_dev, 0x40, 1, 0x6000 + bright, 0x007d, 0, NULL);
  362. }
  363. if (wbal != sd->vold.whitebal) {
  364. sd->vold.whitebal = wbal;
  365. if (wbal < 0 || wbal > sd->vmax.whitebal)
  366. wbal = 0;
  367. ctrl_out(gspca_dev, 0x40, 1, 0x6000 , 0x00ff, 0, NULL);
  368. ctrl_out(gspca_dev, 0x40, 1, 0x6003 , 0x007c, 0, NULL);
  369. ctrl_out(gspca_dev, 0x40, 1, 0x6000 + wbal, 0x007d, 0, NULL);
  370. }
  371. if (cntr != sd->vold.contrast) {
  372. sd->vold.contrast = cntr;
  373. if (cntr < 0 || cntr > sd->vmax.contrast)
  374. cntr = 0;
  375. ctrl_out(gspca_dev, 0x40, 1, 0x6000 , 0x00ff, 0, NULL);
  376. ctrl_out(gspca_dev, 0x40, 1, 0x6007 , 0x007c, 0, NULL);
  377. ctrl_out(gspca_dev, 0x40, 1, 0x6000 + cntr, 0x007d, 0, NULL);
  378. }
  379. if (sat != sd->vold.saturation) {
  380. sd->vold.saturation = sat;
  381. if (sat < 0 || sat > sd->vmax.saturation)
  382. sat = 0;
  383. ctrl_out(gspca_dev, 0x40, 1, 0x6000 , 0x00ff, 0, NULL);
  384. ctrl_out(gspca_dev, 0x40, 1, 0x6001 , 0x007c, 0, NULL);
  385. ctrl_out(gspca_dev, 0x40, 1, 0x6000 + sat, 0x007d, 0, NULL);
  386. }
  387. if (sharp != sd->vold.sharpness) {
  388. sd->vold.sharpness = sharp;
  389. if (sharp < 0 || sharp > sd->vmax.sharpness)
  390. sharp = 0;
  391. ctrl_out(gspca_dev, 0x40, 1, 0x6000 , 0x00ff, 0, NULL);
  392. ctrl_out(gspca_dev, 0x40, 1, 0x6001 , 0x0092, 0, NULL);
  393. ctrl_out(gspca_dev, 0x40, 1, 0x60c0 + sharp, 0x0093, 0, NULL);
  394. }
  395. if (hue != sd->vold.hue) {
  396. sd->vold.hue = hue;
  397. if (hue < 0 || hue > sd->vmax.hue)
  398. hue = 0;
  399. ctrl_out(gspca_dev, 0x40, 1, 0x6000 , 0x00ff, 0, NULL);
  400. ctrl_out(gspca_dev, 0x40, 1, 0x6002 , 0x007c, 0, NULL);
  401. ctrl_out(gspca_dev, 0x40, 1, 0x6000 + hue * (hue < 255), 0x007d,
  402. 0, NULL);
  403. if (hue >= sd->vmax.hue)
  404. sd->swapRB = 1;
  405. else
  406. sd->swapRB = 0;
  407. }
  408. if (gam != sd->vold.gamma) {
  409. sd->vold.gamma = gam;
  410. if (gam < 0 || gam > sd->vmax.gamma)
  411. gam = 0;
  412. ctrl_out(gspca_dev, 0x40, 1, 0x6000 , 0x00ff, 0, NULL);
  413. ctrl_out(gspca_dev, 0x40, 1, 0x6008 , 0x007c, 0, NULL);
  414. ctrl_out(gspca_dev, 0x40, 1, 0x6000 + gam, 0x007d, 0, NULL);
  415. }
  416. if (backlight != sd->vold.backlight) {
  417. sd->vold.backlight = backlight;
  418. ctrl_out(gspca_dev, 0x40, 1, 0x6001 , 0x00ff,
  419. 0, NULL);
  420. ctrl_out(gspca_dev, 0x40, 1, 0x601f + backlight , 0x0024,
  421. 0, NULL);
  422. ctrl_out(gspca_dev, 0x40, 1, 0x601f + backlight - 10, 0x0025,
  423. 0, NULL);
  424. }
  425. return 0;
  426. }
  427. static void ov2640_post_unset_alt(struct gspca_dev *gspca_dev)
  428. {
  429. ctrl_out(gspca_dev, 0x40, 5, 0x0000, 0x0000, 0, NULL);
  430. msleep(20);
  431. fetch_validx(gspca_dev, tbl_post_unset_alt,
  432. ARRAY_SIZE(tbl_post_unset_alt));
  433. }