PageRenderTime 61ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/kernel/linux-source-2.6.32/drivers/media/video/gspca/sonixj.c

https://bitbucket.org/ChuloChumo/sctp_thesis
C | 2401 lines | 1978 code | 186 blank | 237 comment | 143 complexity | c97592b92dbc18de8f8f1e9120f38c1f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Sonix sn9c102p sn9c105 sn9c120 (jpeg) library
  3. * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
  4. *
  5. * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #define MODULE_NAME "sonixj"
  22. #include "gspca.h"
  23. #include "jpeg.h"
  24. #define V4L2_CID_INFRARED (V4L2_CID_PRIVATE_BASE + 0)
  25. MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
  26. MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
  27. MODULE_LICENSE("GPL");
  28. /* specific webcam descriptor */
  29. struct sd {
  30. struct gspca_dev gspca_dev; /* !! must be the first item */
  31. atomic_t avg_lum;
  32. u32 exposure;
  33. u16 brightness;
  34. u8 contrast;
  35. u8 colors;
  36. u8 autogain;
  37. u8 blue;
  38. u8 red;
  39. u8 gamma;
  40. u8 vflip; /* ov7630/ov7648 only */
  41. u8 infrared; /* mt9v111 only */
  42. u8 freq; /* ov76xx only */
  43. u8 quality; /* image quality */
  44. #define QUALITY_MIN 60
  45. #define QUALITY_MAX 95
  46. #define QUALITY_DEF 80
  47. u8 jpegqual; /* webcam quality */
  48. u8 reg18;
  49. s8 ag_cnt;
  50. #define AG_CNT_START 13
  51. u8 bridge;
  52. #define BRIDGE_SN9C102P 0
  53. #define BRIDGE_SN9C105 1
  54. #define BRIDGE_SN9C110 2
  55. #define BRIDGE_SN9C120 3
  56. u8 sensor; /* Type of image sensor chip */
  57. #define SENSOR_HV7131R 0
  58. #define SENSOR_MI0360 1
  59. #define SENSOR_MO4000 2
  60. #define SENSOR_MT9V111 3
  61. #define SENSOR_OM6802 4
  62. #define SENSOR_OV7630 5
  63. #define SENSOR_OV7648 6
  64. #define SENSOR_OV7660 7
  65. #define SENSOR_SP80708 8
  66. u8 i2c_base;
  67. u8 *jpeg_hdr;
  68. };
  69. /* V4L2 controls supported by the driver */
  70. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  71. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  72. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  73. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  74. static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
  75. static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
  76. static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val);
  77. static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val);
  78. static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val);
  79. static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val);
  80. static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
  81. static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
  82. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
  83. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
  84. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
  85. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
  86. static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val);
  87. static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val);
  88. static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
  89. static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
  90. static struct ctrl sd_ctrls[] = {
  91. #define BRIGHTNESS_IDX 0
  92. {
  93. {
  94. .id = V4L2_CID_BRIGHTNESS,
  95. .type = V4L2_CTRL_TYPE_INTEGER,
  96. .name = "Brightness",
  97. .minimum = 0,
  98. #define BRIGHTNESS_MAX 0xffff
  99. .maximum = BRIGHTNESS_MAX,
  100. .step = 1,
  101. #define BRIGHTNESS_DEF 0x8000
  102. .default_value = BRIGHTNESS_DEF,
  103. },
  104. .set = sd_setbrightness,
  105. .get = sd_getbrightness,
  106. },
  107. #define CONTRAST_IDX 1
  108. {
  109. {
  110. .id = V4L2_CID_CONTRAST,
  111. .type = V4L2_CTRL_TYPE_INTEGER,
  112. .name = "Contrast",
  113. .minimum = 0,
  114. #define CONTRAST_MAX 127
  115. .maximum = CONTRAST_MAX,
  116. .step = 1,
  117. #define CONTRAST_DEF 63
  118. .default_value = CONTRAST_DEF,
  119. },
  120. .set = sd_setcontrast,
  121. .get = sd_getcontrast,
  122. },
  123. #define COLOR_IDX 2
  124. {
  125. {
  126. .id = V4L2_CID_SATURATION,
  127. .type = V4L2_CTRL_TYPE_INTEGER,
  128. .name = "Saturation",
  129. .minimum = 0,
  130. .maximum = 40,
  131. .step = 1,
  132. #define COLOR_DEF 25
  133. .default_value = COLOR_DEF,
  134. },
  135. .set = sd_setcolors,
  136. .get = sd_getcolors,
  137. },
  138. #define BLUE_BALANCE_IDX 3
  139. {
  140. {
  141. .id = V4L2_CID_BLUE_BALANCE,
  142. .type = V4L2_CTRL_TYPE_INTEGER,
  143. .name = "Blue Balance",
  144. .minimum = 24,
  145. .maximum = 40,
  146. .step = 1,
  147. #define BLUE_BALANCE_DEF 32
  148. .default_value = BLUE_BALANCE_DEF,
  149. },
  150. .set = sd_setblue_balance,
  151. .get = sd_getblue_balance,
  152. },
  153. #define RED_BALANCE_IDX 4
  154. {
  155. {
  156. .id = V4L2_CID_RED_BALANCE,
  157. .type = V4L2_CTRL_TYPE_INTEGER,
  158. .name = "Red Balance",
  159. .minimum = 24,
  160. .maximum = 40,
  161. .step = 1,
  162. #define RED_BALANCE_DEF 32
  163. .default_value = RED_BALANCE_DEF,
  164. },
  165. .set = sd_setred_balance,
  166. .get = sd_getred_balance,
  167. },
  168. #define GAMMA_IDX 5
  169. {
  170. {
  171. .id = V4L2_CID_GAMMA,
  172. .type = V4L2_CTRL_TYPE_INTEGER,
  173. .name = "Gamma",
  174. .minimum = 0,
  175. .maximum = 40,
  176. .step = 1,
  177. #define GAMMA_DEF 20
  178. .default_value = GAMMA_DEF,
  179. },
  180. .set = sd_setgamma,
  181. .get = sd_getgamma,
  182. },
  183. #define AUTOGAIN_IDX 6
  184. {
  185. {
  186. .id = V4L2_CID_AUTOGAIN,
  187. .type = V4L2_CTRL_TYPE_BOOLEAN,
  188. .name = "Auto Gain",
  189. .minimum = 0,
  190. .maximum = 1,
  191. .step = 1,
  192. #define AUTOGAIN_DEF 1
  193. .default_value = AUTOGAIN_DEF,
  194. },
  195. .set = sd_setautogain,
  196. .get = sd_getautogain,
  197. },
  198. /* ov7630/ov7648 only */
  199. #define VFLIP_IDX 7
  200. {
  201. {
  202. .id = V4L2_CID_VFLIP,
  203. .type = V4L2_CTRL_TYPE_BOOLEAN,
  204. .name = "Vflip",
  205. .minimum = 0,
  206. .maximum = 1,
  207. .step = 1,
  208. #define VFLIP_DEF 0
  209. .default_value = VFLIP_DEF,
  210. },
  211. .set = sd_setvflip,
  212. .get = sd_getvflip,
  213. },
  214. /* mt9v111 only */
  215. #define INFRARED_IDX 8
  216. {
  217. {
  218. .id = V4L2_CID_INFRARED,
  219. .type = V4L2_CTRL_TYPE_BOOLEAN,
  220. .name = "Infrared",
  221. .minimum = 0,
  222. .maximum = 1,
  223. .step = 1,
  224. #define INFRARED_DEF 0
  225. .default_value = INFRARED_DEF,
  226. },
  227. .set = sd_setinfrared,
  228. .get = sd_getinfrared,
  229. },
  230. /* ov7630/ov7648/ov7660 only */
  231. #define FREQ_IDX 9
  232. {
  233. {
  234. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  235. .type = V4L2_CTRL_TYPE_MENU,
  236. .name = "Light frequency filter",
  237. .minimum = 0,
  238. .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
  239. .step = 1,
  240. #define FREQ_DEF 2
  241. .default_value = FREQ_DEF,
  242. },
  243. .set = sd_setfreq,
  244. .get = sd_getfreq,
  245. },
  246. };
  247. /* table of the disabled controls */
  248. static __u32 ctrl_dis[] = {
  249. (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
  250. /* SENSOR_HV7131R 0 */
  251. (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
  252. /* SENSOR_MI0360 1 */
  253. (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
  254. /* SENSOR_MO4000 2 */
  255. (1 << VFLIP_IDX) | (1 << FREQ_IDX),
  256. /* SENSOR_MT9V111 3 */
  257. (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
  258. /* SENSOR_OM6802 4 */
  259. (1 << INFRARED_IDX),
  260. /* SENSOR_OV7630 5 */
  261. (1 << INFRARED_IDX),
  262. /* SENSOR_OV7648 6 */
  263. (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
  264. /* SENSOR_OV7660 7 */
  265. (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) |
  266. (1 << FREQ_IDX), /* SENSOR_SP80708 8 */
  267. };
  268. static const struct v4l2_pix_format vga_mode[] = {
  269. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  270. .bytesperline = 160,
  271. .sizeimage = 160 * 120 * 4 / 8 + 590,
  272. .colorspace = V4L2_COLORSPACE_JPEG,
  273. .priv = 2},
  274. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  275. .bytesperline = 320,
  276. .sizeimage = 320 * 240 * 3 / 8 + 590,
  277. .colorspace = V4L2_COLORSPACE_JPEG,
  278. .priv = 1},
  279. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  280. .bytesperline = 640,
  281. /* Note 3 / 8 is not large enough, not even 5 / 8 is ?! */
  282. .sizeimage = 640 * 480 * 3 / 4 + 590,
  283. .colorspace = V4L2_COLORSPACE_JPEG,
  284. .priv = 0},
  285. };
  286. /*Data from sn9c102p+hv7131r */
  287. static const u8 sn_hv7131[0x1c] = {
  288. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  289. 0x00, 0x03, 0x64, 0x00, 0x1a, 0x20, 0x20, 0x20,
  290. /* reg8 reg9 rega regb regc regd rege regf */
  291. 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10,
  292. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  293. 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
  294. /* reg18 reg19 reg1a reg1b */
  295. 0x0a, 0x00, 0x00, 0x00
  296. };
  297. static const u8 sn_mi0360[0x1c] = {
  298. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  299. 0x00, 0x61, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20,
  300. /* reg8 reg9 rega regb regc regd rege regf */
  301. 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10,
  302. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  303. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
  304. /* reg18 reg19 reg1a reg1b */
  305. 0x06, 0x00, 0x00, 0x00
  306. };
  307. static const u8 sn_mo4000[0x1c] = {
  308. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  309. 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
  310. /* reg8 reg9 rega regb regc regd rege regf */
  311. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  312. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  313. 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
  314. /* reg18 reg19 reg1a reg1b */
  315. 0x08, 0x00, 0x00, 0x00
  316. };
  317. static const u8 sn_mt9v111[0x1c] = {
  318. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  319. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  320. /* reg8 reg9 rega regb regc regd rege regf */
  321. 0x81, 0x5c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
  322. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  323. 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
  324. /* reg18 reg19 reg1a reg1b */
  325. 0x06, 0x00, 0x00, 0x00
  326. };
  327. static const u8 sn_om6802[0x1c] = {
  328. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  329. 0x00, 0x23, 0x72, 0x00, 0x1a, 0x34, 0x27, 0x20,
  330. /* reg8 reg9 rega regb regc regd rege regf */
  331. 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  332. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  333. 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
  334. /* reg18 reg19 reg1a reg1b */
  335. 0x05, 0x00, 0x00, 0x00
  336. };
  337. static const u8 sn_ov7630[0x1c] = {
  338. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  339. 0x00, 0x21, 0x40, 0x00, 0x1a, 0x20, 0x1f, 0x20,
  340. /* reg8 reg9 rega regb regc regd rege regf */
  341. 0xa1, 0x21, 0x76, 0x21, 0x00, 0x00, 0x00, 0x10,
  342. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  343. 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
  344. /* reg18 reg19 reg1a reg1b */
  345. 0x0b, 0x00, 0x00, 0x00
  346. };
  347. static const u8 sn_ov7648[0x1c] = {
  348. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  349. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  350. /* reg8 reg9 rega regb regc regd rege regf */
  351. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
  352. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  353. 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
  354. /* reg18 reg19 reg1a reg1b */
  355. 0x0b, 0x00, 0x00, 0x00
  356. };
  357. static const u8 sn_ov7660[0x1c] = {
  358. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  359. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  360. /* reg8 reg9 rega regb regc regd rege regf */
  361. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  362. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  363. 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
  364. /* reg18 reg19 reg1a reg1b */
  365. 0x07, 0x00, 0x00, 0x00
  366. };
  367. static const u8 sn_sp80708[0x1c] = {
  368. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  369. 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
  370. /* reg8 reg9 rega regb regc regd rege regf */
  371. 0x81, 0x18, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
  372. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  373. 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
  374. /* reg18 reg19 reg1a reg1b */
  375. 0x07, 0x00, 0x00, 0x00
  376. };
  377. /* sequence specific to the sensors - !! index = SENSOR_xxx */
  378. static const u8 *sn_tb[] = {
  379. sn_hv7131,
  380. sn_mi0360,
  381. sn_mo4000,
  382. sn_mt9v111,
  383. sn_om6802,
  384. sn_ov7630,
  385. sn_ov7648,
  386. sn_ov7660,
  387. sn_sp80708
  388. };
  389. /* default gamma table */
  390. static const u8 gamma_def[17] = {
  391. 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
  392. 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
  393. };
  394. /* gamma for sensors HV7131R and MT9V111 */
  395. static const u8 gamma_spec_1[17] = {
  396. 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
  397. 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
  398. };
  399. /* gamma for sensor SP80708 */
  400. static const u8 gamma_spec_2[17] = {
  401. 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
  402. 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
  403. };
  404. /* color matrix and offsets */
  405. static const u8 reg84[] = {
  406. 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
  407. 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
  408. 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
  409. 0x00, 0x00, 0x00 /* YUV offsets */
  410. };
  411. static const u8 hv7131r_sensor_init[][8] = {
  412. {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
  413. {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
  414. {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
  415. /* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  416. {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  417. {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
  418. /* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  419. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  420. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  421. {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
  422. {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
  423. {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
  424. {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
  425. {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
  426. {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
  427. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  428. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  429. {0xa1, 0x11, 0x21, 0xD0, 0x00, 0x00, 0x00, 0x10},
  430. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  431. {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
  432. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  433. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  434. {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
  435. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  436. {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
  437. {}
  438. };
  439. static const u8 mi0360_sensor_init[][8] = {
  440. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  441. {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
  442. {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  443. {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  444. {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
  445. {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
  446. {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
  447. {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  448. {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
  449. {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  450. {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  451. {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  452. {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  453. {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  454. {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  455. {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
  456. {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  457. {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  458. {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  459. {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  460. {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  461. {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  462. {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
  463. {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  464. {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  465. {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
  466. {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
  467. {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  468. {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  469. {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
  470. {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
  471. {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
  472. {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  473. {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  474. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  475. {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  476. {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
  477. {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
  478. {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
  479. {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
  480. {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
  481. {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  482. {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
  483. {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
  484. /* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
  485. /* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
  486. {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  487. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  488. {}
  489. };
  490. static const u8 mo4000_sensor_init[][8] = {
  491. {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
  492. {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
  493. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  494. {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  495. {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  496. {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
  497. {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
  498. {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
  499. {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  500. {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
  501. {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
  502. {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
  503. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  504. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  505. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  506. {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  507. {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
  508. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
  509. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  510. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  511. {}
  512. };
  513. static const u8 mt9v111_sensor_init[][8] = {
  514. {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
  515. /* delay 20 ms */
  516. {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  517. {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
  518. {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
  519. {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
  520. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
  521. {0xb1, 0x5c, 0x03, 0x01, 0xe1, 0x00, 0x00, 0x10},
  522. {0xb1, 0x5c, 0x04, 0x02, 0x81, 0x00, 0x00, 0x10},
  523. {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
  524. {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
  525. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
  526. {0xb1, 0x5c, 0x03, 0x01, 0xe6, 0x00, 0x00, 0x10},
  527. {0xb1, 0x5c, 0x04, 0x02, 0x86, 0x00, 0x00, 0x10},
  528. {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
  529. {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
  530. {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
  531. {0xb1, 0x5c, 0x0e, 0x00, 0x08, 0x00, 0x00, 0x10},
  532. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
  533. {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
  534. {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
  535. {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
  536. {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
  537. {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
  538. {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
  539. {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
  540. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
  541. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  542. /*******/
  543. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  544. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  545. {0xb1, 0x5c, 0x09, 0x01, 0x2c, 0x00, 0x00, 0x10},
  546. {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10}, /* green1 gain */
  547. {0xd1, 0x5c, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10}, /* red gain */
  548. /*******/
  549. {0xb1, 0x5c, 0x06, 0x00, 0x1e, 0x00, 0x00, 0x10}, /* vert blanking */
  550. {0xb1, 0x5c, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10}, /* horiz blanking */
  551. {0xd1, 0x5c, 0x2c, 0x00, 0xad, 0x00, 0xad, 0x10}, /* blue gain */
  552. {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
  553. {}
  554. };
  555. static const u8 om6802_sensor_init[][8] = {
  556. {0xa0, 0x34, 0x90, 0x05, 0x00, 0x00, 0x00, 0x10},
  557. {0xa0, 0x34, 0x49, 0x85, 0x00, 0x00, 0x00, 0x10},
  558. {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
  559. {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
  560. /* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
  561. {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
  562. /* white balance & auto-exposure */
  563. /* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
  564. * set color mode */
  565. /* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
  566. * max AGC value in AE */
  567. /* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
  568. * preset AGC */
  569. /* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
  570. * preset brightness */
  571. /* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
  572. * preset contrast */
  573. /* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
  574. * preset gamma */
  575. {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
  576. /* luminance mode (0x4f = AE) */
  577. {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
  578. /* preset shutter */
  579. /* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
  580. * auto frame rate */
  581. /* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
  582. /* {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10}, */
  583. /* {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10}, */
  584. /* {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10}, */
  585. /* {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10}, */
  586. {}
  587. };
  588. static const u8 ov7630_sensor_init[][8] = {
  589. {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
  590. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  591. /* win: delay 20ms */
  592. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  593. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  594. /* win: delay 20ms */
  595. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  596. /* win: i2c_r from 00 to 80 */
  597. {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
  598. {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
  599. /* HDG: 0x11 was 0x00 change to 0x01 for better exposure (15 fps instead of 30)
  600. 0x13 was 0xc0 change to 0xc3 for auto gain and exposure */
  601. {0xd1, 0x21, 0x11, 0x01, 0x48, 0xc3, 0x00, 0x10},
  602. {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
  603. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  604. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  605. {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
  606. {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
  607. {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
  608. {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
  609. {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
  610. {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
  611. {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  612. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
  613. {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
  614. {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
  615. {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
  616. {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
  617. {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
  618. {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
  619. {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
  620. {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
  621. {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
  622. {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
  623. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  624. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  625. /* */
  626. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  627. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  628. /*fixme: + 0x12, 0x04*/
  629. /* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
  630. * set by setvflip */
  631. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  632. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  633. {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
  634. /* */
  635. /* {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  636. /* {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  637. /* */
  638. {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
  639. /* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
  640. {}
  641. };
  642. static const u8 ov7648_sensor_init[][8] = {
  643. {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
  644. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
  645. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  646. {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
  647. {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
  648. {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
  649. {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
  650. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  651. {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
  652. {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
  653. {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
  654. {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
  655. {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
  656. {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
  657. {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
  658. {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
  659. {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
  660. {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
  661. {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
  662. {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
  663. {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
  664. {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
  665. /* {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
  666. /* {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
  667. /* {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, set by setfreq */
  668. /*...*/
  669. /* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
  670. /* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
  671. * set by setvflip */
  672. {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
  673. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  674. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  675. /* {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, * GAIN - def */
  676. /* {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10}, * B R - def: 80 */
  677. /*...*/
  678. {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
  679. /* {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  680. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  681. /* {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
  682. /* {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  683. /* {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10}, * B R - def: 80 */
  684. {}
  685. };
  686. static const u8 ov7660_sensor_init[][8] = {
  687. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
  688. /* (delay 20ms) */
  689. {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
  690. /* Outformat = rawRGB */
  691. {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
  692. {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
  693. /* GAIN BLUE RED VREF */
  694. {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
  695. /* COM 1 BAVE GEAVE AECHH */
  696. {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
  697. {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
  698. {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
  699. /* AECH CLKRC COM7 COM8 */
  700. {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
  701. {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
  702. /* HSTART HSTOP VSTRT VSTOP */
  703. {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
  704. {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
  705. {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
  706. /* BOS GBOS GROS ROS (BGGR offset) */
  707. /* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
  708. {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
  709. /* AEW AEB VPT BBIAS */
  710. {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
  711. /* GbBIAS RSVD EXHCH EXHCL */
  712. {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
  713. /* RBIAS ADVFL ASDVFH YAVE */
  714. {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
  715. /* HSYST HSYEN HREF */
  716. {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
  717. {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
  718. /* ADC ACOM OFON TSLB */
  719. {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
  720. /* COM11 COM12 COM13 COM14 */
  721. {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
  722. /* EDGE COM15 COM16 COM17 */
  723. {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
  724. {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
  725. {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  726. {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
  727. {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
  728. {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
  729. {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
  730. {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
  731. {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  732. {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
  733. /* LCC1 LCC2 LCC3 LCC4 */
  734. {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
  735. {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
  736. {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
  737. /* band gap reference [0:3] DBLV */
  738. {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
  739. {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
  740. {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
  741. {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
  742. {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
  743. {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
  744. {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
  745. {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
  746. {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
  747. {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
  748. {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
  749. /****** (some exchanges in the win trace) ******/
  750. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
  751. /* bits[3..0]reserved */
  752. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
  753. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  754. /* VREF vertical frame ctrl */
  755. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  756. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
  757. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
  758. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
  759. {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
  760. /* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
  761. /****** (some exchanges in the win trace) ******/
  762. {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
  763. {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
  764. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
  765. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
  766. /* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
  767. /****** (some exchanges in the win trace) ******/
  768. /******!! startsensor KO if changed !!****/
  769. {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
  770. {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
  771. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
  772. {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
  773. {}
  774. };
  775. static const u8 sp80708_sensor_init[][8] = {
  776. {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
  777. {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
  778. {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  779. {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
  780. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  781. {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
  782. {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
  783. {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
  784. {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
  785. {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
  786. {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
  787. {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
  788. {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
  789. {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
  790. {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
  791. {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
  792. {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
  793. {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
  794. {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
  795. {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
  796. {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
  797. {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
  798. {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
  799. {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
  800. {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
  801. {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
  802. {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
  803. {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
  804. {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
  805. {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
  806. {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
  807. {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
  808. {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
  809. {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
  810. {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
  811. {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
  812. {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
  813. {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
  814. {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
  815. {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
  816. {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
  817. {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
  818. {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
  819. {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
  820. {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
  821. {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
  822. {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
  823. {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
  824. {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
  825. {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
  826. {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
  827. {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
  828. {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
  829. {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
  830. {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
  831. {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
  832. {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
  833. {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
  834. {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
  835. {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
  836. {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
  837. {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
  838. {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
  839. {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
  840. {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
  841. {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
  842. {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
  843. {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
  844. {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
  845. {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
  846. {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
  847. /********/
  848. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  849. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  850. {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
  851. {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
  852. {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
  853. {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
  854. {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
  855. {}
  856. };
  857. /* read <len> bytes to gspca_dev->usb_buf */
  858. static void reg_r(struct gspca_dev *gspca_dev,
  859. u16 value, int len)
  860. {
  861. #ifdef GSPCA_DEBUG
  862. if (len > USB_BUF_SZ) {
  863. err("reg_r: buffer overflow");
  864. return;
  865. }
  866. #endif
  867. usb_control_msg(gspca_dev->dev,
  868. usb_rcvctrlpipe(gspca_dev->dev, 0),
  869. 0,
  870. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  871. value, 0,
  872. gspca_dev->usb_buf, len,
  873. 500);
  874. PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
  875. }
  876. static void reg_w1(struct gspca_dev *gspca_dev,
  877. u16 value,
  878. u8 data)
  879. {
  880. PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
  881. gspca_dev->usb_buf[0] = data;
  882. usb_control_msg(gspca_dev->dev,
  883. usb_sndctrlpipe(gspca_dev->dev, 0),
  884. 0x08,
  885. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  886. value,
  887. 0,
  888. gspca_dev->usb_buf, 1,
  889. 500);
  890. }
  891. static void reg_w(struct gspca_dev *gspca_dev,
  892. u16 value,
  893. const u8 *buffer,
  894. int len)
  895. {
  896. PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
  897. value, buffer[0], buffer[1]);
  898. #ifdef GSPCA_DEBUG
  899. if (len > USB_BUF_SZ) {
  900. err("reg_w: buffer overflow");
  901. return;
  902. }
  903. #endif
  904. memcpy(gspca_dev->usb_buf, buffer, len);
  905. usb_control_msg(gspca_dev->dev,
  906. usb_sndctrlpipe(gspca_dev->dev, 0),
  907. 0x08,
  908. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  909. value, 0,
  910. gspca_dev->usb_buf, len,
  911. 500);
  912. }
  913. /* I2C write 1 byte */
  914. static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  915. {
  916. struct sd *sd = (struct sd *) gspca_dev;
  917. PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
  918. gspca_dev->usb_buf[0] = 0x81 | (2 << 4); /* = a1 */
  919. gspca_dev->usb_buf[1] = sd->i2c_base;
  920. gspca_dev->usb_buf[2] = reg;
  921. gspca_dev->usb_buf[3] = val;
  922. gspca_dev->usb_buf[4] = 0;
  923. gspca_dev->usb_buf[5] = 0;
  924. gspca_dev->usb_buf[6] = 0;
  925. gspca_dev->usb_buf[7] = 0x10;
  926. usb_control_msg(gspca_dev->dev,
  927. usb_sndctrlpipe(gspca_dev->dev, 0),
  928. 0x08,
  929. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  930. 0x08, /* value = i2c */
  931. 0,
  932. gspca_dev->usb_buf, 8,
  933. 500);
  934. }
  935. /* I2C write 8 bytes */
  936. static void i2c_w8(struct gspca_dev *gspca_dev,
  937. const u8 *buffer)
  938. {
  939. memcpy(gspca_dev->usb_buf, buffer, 8);
  940. usb_control_msg(gspca_dev->dev,
  941. usb_sndctrlpipe(gspca_dev->dev, 0),
  942. 0x08,
  943. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  944. 0x08, 0, /* value, index */
  945. gspca_dev->usb_buf, 8,
  946. 500);
  947. msleep(2);
  948. }
  949. /* read 5 bytes in gspca_dev->usb_buf */
  950. static void i2c_r5(struct gspca_dev *gspca_dev, u8 reg)
  951. {
  952. struct sd *sd = (struct sd *) gspca_dev;
  953. u8 mode[8];
  954. mode[0] = 0x81 | 0x10;
  955. mode[1] = sd->i2c_base;
  956. mode[2] = reg;
  957. mode[3] = 0;
  958. mode[4] = 0;
  959. mode[5] = 0;
  960. mode[6] = 0;
  961. mode[7] = 0x10;
  962. i2c_w8(gspca_dev, mode);
  963. msleep(2);
  964. mode[0] = 0x81 | (5 << 4) | 0x02;
  965. mode[2] = 0;
  966. i2c_w8(gspca_dev, mode);
  967. msleep(2);
  968. reg_r(gspca_dev, 0x0a, 5);
  969. }
  970. static int hv7131r_probe(struct gspca_dev *gspca_dev)
  971. {
  972. i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
  973. msleep(10);
  974. reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
  975. msleep(10);
  976. i2c_r5(gspca_dev, 0); /* read sensor id */
  977. if (gspca_dev->usb_buf[0] == 0x02
  978. && gspca_dev->usb_buf[1] == 0x09
  979. && gspca_dev->usb_buf[2] == 0x01
  980. && gspca_dev->usb_buf[3] == 0x00
  981. && gspca_dev->usb_buf[4] == 0x00) {
  982. PDEBUG(D_PROBE, "Find Sensor sn9c102P HV7131R");
  983. return 0;
  984. }
  985. PDEBUG(D_PROBE, "Find Sensor 0x%02x 0x%02x 0x%02x",
  986. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
  987. gspca_dev->usb_buf[2]);
  988. PDEBUG(D_PROBE, "Sensor sn9c102P Not found");
  989. return -ENODEV;
  990. }
  991. static void mi0360_probe(struct gspca_dev *gspca_dev)
  992. {
  993. struct sd *sd = (struct sd *) gspca_dev;
  994. int i, j;
  995. u16 val = 0;
  996. static const u8 probe_tb[][4][8] = {
  997. { /* mi0360 */
  998. {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  999. {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1000. {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1001. {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
  1002. },
  1003. { /* mt9v111 */
  1004. {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
  1005. {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
  1006. {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1007. {}
  1008. },
  1009. };
  1010. for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
  1011. reg_w1(gspca_dev, 0x17, 0x62);
  1012. reg_w1(gspca_dev, 0x01, 0x08);
  1013. for (j = 0; j < 3; j++)
  1014. i2c_w8(gspca_dev, probe_tb[i][j]);
  1015. msleep(2);
  1016. reg_r(gspca_dev, 0x0a, 5);
  1017. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1018. if (probe_tb[i][3][0] != 0)
  1019. i2c_w8(gspca_dev, probe_tb[i][3]);
  1020. reg_w1(gspca_dev, 0x01, 0x29);
  1021. reg_w1(gspca_dev, 0x17, 0x42);
  1022. if (val != 0xffff)
  1023. break;
  1024. }
  1025. switch (val) {
  1026. case 0x823a:
  1027. PDEBUG(D_PROBE, "Sensor mt9v111");
  1028. sd->sensor = SENSOR_MT9V111;
  1029. sd->i2c_base = 0x5c;
  1030. break;
  1031. case 0x8243:
  1032. PDEBUG(D_PROBE, "Sensor mi0360");
  1033. break;
  1034. default:
  1035. PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
  1036. break;
  1037. }
  1038. }
  1039. static int configure_gpio(struct gspca_dev *gspca_dev,
  1040. const u8 *sn9c1xx)
  1041. {
  1042. struct sd *sd = (struct sd *) gspca_dev;
  1043. const u8 *reg9a;
  1044. static const u8 reg9a_def[] =
  1045. {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
  1046. static const u8 reg9a_spec[] =
  1047. {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
  1048. static const u8 regd4[] = {0x60, 0x00, 0x00};
  1049. reg_w1(gspca_dev, 0xf1, 0x00);
  1050. reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
  1051. /* configure gpio */
  1052. reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2);
  1053. reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
  1054. reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5); /* jfm len was 3 */
  1055. switch (sd->sensor) {
  1056. case SENSOR_OV7660:
  1057. case SENSOR_SP80708:
  1058. reg9a = reg9a_spec;
  1059. break;
  1060. default:
  1061. reg9a = reg9a_def;
  1062. break;
  1063. }
  1064. reg_w(gspca_dev, 0x9a, reg9a, 6);
  1065. reg_w(gspca_dev, 0xd4, regd4, sizeof regd4); /*fixme:jfm was 60 only*/
  1066. reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
  1067. switch (sd->sensor) {
  1068. case SENSOR_MT9V111:
  1069. reg_w1(gspca_dev, 0x01, 0x61);
  1070. reg_w1(gspca_dev, 0x17, 0x61);
  1071. reg_w1(gspca_dev, 0x01, 0x60);
  1072. reg_w1(gspca_dev, 0x01, 0x40);
  1073. break;
  1074. case SENSOR_OM6802:
  1075. reg_w1(gspca_dev, 0x02, 0x71);
  1076. reg_w1(gspca_dev, 0x01, 0x42);
  1077. reg_w1(gspca_dev, 0x17, 0x64);
  1078. reg_w1(gspca_dev, 0x01, 0x42);
  1079. break;
  1080. case SENSOR_OV7630:
  1081. reg_w1(gspca_dev, 0x01, 0x61);
  1082. reg_w1(gspca_dev, 0x17, 0xe2);
  1083. reg_w1(gspca_dev, 0x01, 0x60);
  1084. reg_w1(gspca_dev, 0x01, 0x40);
  1085. break;
  1086. case SENSOR_OV7648:
  1087. reg_w1(gspca_dev, 0x01, 0x63);
  1088. reg_w1(gspca_dev, 0x17, 0x20);
  1089. reg_w1(gspca_dev, 0x01, 0x62);
  1090. reg_w1(gspca_dev, 0x01, 0x42);
  1091. break;
  1092. case SENSOR_OV7660:
  1093. case SENSOR_SP80708:
  1094. reg_w1(gspca_dev, 0x01, 0x63);
  1095. reg_w1(gspca_dev, 0x17, 0x20);
  1096. reg_w1(gspca_dev, 0x01, 0x62);
  1097. reg_w1(gspca_dev, 0x01, 0x42);
  1098. msleep(100);
  1099. reg_w1(gspca_dev, 0x02, 0x62);
  1100. break;
  1101. /* case SENSOR_HV7131R: */
  1102. /* case SENSOR_MI0360: */
  1103. /* case SENSOR_MO4000: */
  1104. default:
  1105. reg_w1(gspca_dev, 0x01, 0x43);
  1106. reg_w1(gspca_dev, 0x17, 0x61);
  1107. reg_w1(gspca_dev, 0x01, 0x42);
  1108. if (sd->sensor == SENSOR_HV7131R) {
  1109. if (hv7131r_probe(gspca_dev) < 0)
  1110. return -ENODEV;
  1111. }
  1112. break;
  1113. }
  1114. return 0;
  1115. }
  1116. static void hv7131R_InitSensor(struct gspca_dev *gspca_dev)
  1117. {
  1118. int i = 0;
  1119. static const u8 SetSensorClk[] = /* 0x08 Mclk */
  1120. { 0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10 };
  1121. while (hv7131r_sensor_init[i][0]) {
  1122. i2c_w8(gspca_dev, hv7131r_sensor_init[i]);
  1123. i++;
  1124. }
  1125. i2c_w8(gspca_dev, SetSensorClk);
  1126. }
  1127. static void mi0360_InitSensor(struct gspca_dev *gspca_dev)
  1128. {
  1129. int i = 0;
  1130. while (mi0360_sensor_init[i][0]) {
  1131. i2c_w8(gspca_dev, mi0360_sensor_init[i]);
  1132. i++;
  1133. }
  1134. }
  1135. static void mo4000_InitSensor(struct gspca_dev *gspca_dev)
  1136. {
  1137. int i = 0;
  1138. while (mo4000_sensor_init[i][0]) {
  1139. i2c_w8(gspca_dev, mo4000_sensor_init[i]);
  1140. i++;
  1141. }
  1142. }
  1143. static void mt9v111_InitSensor(struct gspca_dev *gspca_dev)
  1144. {
  1145. int i = 0;
  1146. i2c_w8(gspca_dev, mt9v111_sensor_init[i]);
  1147. i++;
  1148. msleep(20);
  1149. while (mt9v111_sensor_init[i][0]) {
  1150. i2c_w8(gspca_dev, mt9v111_sensor_init[i]);
  1151. i++;
  1152. }
  1153. }
  1154. static void om6802_InitSensor(struct gspca_dev *gspca_dev)
  1155. {
  1156. int i = 0;
  1157. while (om6802_sensor_init[i][0]) {
  1158. i2c_w8(gspca_dev, om6802_sensor_init[i]);
  1159. i++;
  1160. }
  1161. }
  1162. static void ov7630_InitSensor(struct gspca_dev *gspca_dev)
  1163. {
  1164. int i = 0;
  1165. i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 76 01 */
  1166. i++;
  1167. i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 c8 (RGB+SRST) */
  1168. i++;
  1169. msleep(20);
  1170. i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 48 */
  1171. i++;
  1172. i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 c8 */
  1173. i++;
  1174. msleep(20);
  1175. i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 48 */
  1176. i++;
  1177. /*jfm:win i2c_r from 00 to 80*/
  1178. while (ov7630_sensor_init[i][0]) {
  1179. i2c_w8(gspca_dev, ov7630_sensor_init[i]);
  1180. i++;
  1181. }
  1182. }
  1183. static void ov7648_InitSensor(struct gspca_dev *gspca_dev)
  1184. {
  1185. int i = 0;
  1186. i2c_w8(gspca_dev, ov7648_sensor_init[i]);
  1187. i++;
  1188. /* win: dble reset */
  1189. i2c_w8(gspca_dev, ov7648_sensor_init[i]); /* reset */
  1190. i++;
  1191. msleep(20);
  1192. /* win: i2c reg read 00..7f */
  1193. while (ov7648_sensor_init[i][0]) {
  1194. i2c_w8(gspca_dev, ov7648_sensor_init[i]);
  1195. i++;
  1196. }
  1197. }
  1198. static void ov7660_InitSensor(struct gspca_dev *gspca_dev)
  1199. {
  1200. int i = 0;
  1201. i2c_w8(gspca_dev, ov7660_sensor_init[i]); /* reset SCCB */
  1202. i++;
  1203. msleep(20);
  1204. while (ov7660_sensor_init[i][0]) {
  1205. i2c_w8(gspca_dev, ov7660_sensor_init[i]);
  1206. i++;
  1207. }
  1208. }
  1209. static void sp80708_InitSensor(struct gspca_dev *gspca_dev)
  1210. {
  1211. int i = 0;
  1212. i2c_w8(gspca_dev, sp80708_sensor_init[i]); /* reset SCCB */
  1213. i++;
  1214. msleep(20);
  1215. while (sp80708_sensor_init[i][0]) {
  1216. i2c_w8(gspca_dev, sp80708_sensor_init[i]);
  1217. i++;
  1218. }
  1219. }
  1220. /* this function is called at probe time */
  1221. static int sd_config(struct gspca_dev *gspca_dev,
  1222. const struct usb_device_id *id)
  1223. {
  1224. struct sd *sd = (struct sd *) gspca_dev;
  1225. struct cam *cam;
  1226. cam = &gspca_dev->cam;
  1227. cam->cam_mode = vga_mode;
  1228. cam->nmodes = ARRAY_SIZE(vga_mode);
  1229. cam->npkt = 24; /* 24 packets per ISOC message */
  1230. sd->bridge = id->driver_info >> 16;
  1231. sd->sensor = id->driver_info >> 8;
  1232. sd->i2c_base = id->driver_info;
  1233. sd->brightness = BRIGHTNESS_DEF;
  1234. sd->contrast = CONTRAST_DEF;
  1235. sd->colors = COLOR_DEF;
  1236. sd->blue = BLUE_BALANCE_DEF;
  1237. sd->red = RED_BALANCE_DEF;
  1238. sd->gamma = GAMMA_DEF;
  1239. sd->autogain = AUTOGAIN_DEF;
  1240. sd->ag_cnt = -1;
  1241. sd->vflip = VFLIP_DEF;
  1242. sd->infrared = INFRARED_DEF;
  1243. sd->freq = FREQ_DEF;
  1244. sd->quality = QUALITY_DEF;
  1245. sd->jpegqual = 80;
  1246. gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
  1247. return 0;
  1248. }
  1249. /* this function is called at probe and resume time */
  1250. static int sd_init(struct gspca_dev *gspca_dev)
  1251. {
  1252. struct sd *sd = (struct sd *) gspca_dev;
  1253. u8 regGpio[] = { 0x29, 0x74 };
  1254. u8 regF1;
  1255. /* setup a selector by bridge */
  1256. reg_w1(gspca_dev, 0xf1, 0x01);
  1257. reg_r(gspca_dev, 0x00, 1);
  1258. reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]);
  1259. reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
  1260. regF1 = gspca_dev->usb_buf[0];
  1261. PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
  1262. switch (sd->bridge) {
  1263. case BRIDGE_SN9C102P:
  1264. if (regF1 != 0x11)
  1265. return -ENODEV;
  1266. reg_w1(gspca_dev, 0x02, regGpio[1]);
  1267. break;
  1268. case BRIDGE_SN9C105:
  1269. if (regF1 != 0x11)
  1270. return -ENODEV;
  1271. if (sd->sensor == SENSOR_MI0360)
  1272. mi0360_probe(gspca_dev);
  1273. reg_w(gspca_dev, 0x01, regGpio, 2);
  1274. break;
  1275. case BRIDGE_SN9C120:
  1276. if (regF1 != 0x12)
  1277. return -ENODEV;
  1278. if (sd->sensor == SENSOR_MI0360)
  1279. mi0360_probe(gspca_dev);
  1280. regGpio[1] = 0x70;
  1281. reg_w(gspca_dev, 0x01, regGpio, 2);
  1282. break;
  1283. default:
  1284. /* case BRIDGE_SN9C110: */
  1285. /* case BRIDGE_SN9C325: */
  1286. if (regF1 != 0x12)
  1287. return -ENODEV;
  1288. reg_w1(gspca_dev, 0x02, 0x62);
  1289. break;
  1290. }
  1291. reg_w1(gspca_dev, 0xf1, 0x01);
  1292. return 0;
  1293. }
  1294. static u32 setexposure(struct gspca_dev *gspca_dev,
  1295. u32 expo)
  1296. {
  1297. struct sd *sd = (struct sd *) gspca_dev;
  1298. switch (sd->sensor) {
  1299. case SENSOR_HV7131R: {
  1300. u8 Expodoit[] =
  1301. { 0xc1, 0x11, 0x25, 0x07, 0x27, 0xc0, 0x00, 0x16 };
  1302. Expodoit[3] = expo >> 16;
  1303. Expodoit[4] = expo >> 8;
  1304. Expodoit[5] = expo;
  1305. i2c_w8(gspca_dev, Expodoit);
  1306. break;
  1307. }
  1308. case SENSOR_MI0360: {
  1309. u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
  1310. { 0xb1, 0x5d, 0x09, 0x06, 0x35, 0x00, 0x00, 0x16 };
  1311. static const u8 doit[] = /* update sensor */
  1312. { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
  1313. static const u8 sensorgo[] = /* sensor on */
  1314. { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
  1315. if (expo > 0x0635)
  1316. expo = 0x0635;
  1317. else if (expo < 0x0001)
  1318. expo = 0x0001;
  1319. expoMi[3] = expo >> 8;
  1320. expoMi[4] = expo;
  1321. i2c_w8(gspca_dev, expoMi);
  1322. i2c_w8(gspca_dev, doit);
  1323. i2c_w8(gspca_dev, sensorgo);
  1324. break;
  1325. }
  1326. case SENSOR_MO4000: {
  1327. u8 expoMof[] =
  1328. { 0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10 };
  1329. u8 expoMo10[] =
  1330. { 0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10 };
  1331. static const u8 gainMo[] =
  1332. { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
  1333. if (expo > 0x1fff)
  1334. expo = 0x1fff;
  1335. else if (expo < 0x0001)
  1336. expo = 0x0001;
  1337. expoMof[3] = (expo & 0x03fc) >> 2;
  1338. i2c_w8(gspca_dev, expoMof);
  1339. expoMo10[3] = ((expo & 0x1c00) >> 10)
  1340. | ((expo & 0x0003) << 4);
  1341. i2c_w8(gspca_dev, expoMo10);
  1342. i2c_w8(gspca_dev, gainMo);
  1343. PDEBUG(D_FRAM, "set exposure %d",
  1344. ((expoMo10[3] & 0x07) << 10)
  1345. | (expoMof[3] << 2)
  1346. | ((expoMo10[3] & 0x30) >> 4));
  1347. break;
  1348. }
  1349. case SENSOR_MT9V111: {
  1350. u8 expo_c1[] =
  1351. { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1352. if (expo > 0x0280)
  1353. expo = 0x0280;
  1354. else if (expo < 0x0040)
  1355. expo = 0x0040;
  1356. expo_c1[3] = expo >> 8;
  1357. expo_c1[4] = expo;
  1358. i2c_w8(gspca_dev, expo_c1);
  1359. break;
  1360. }
  1361. case SENSOR_OM6802: {
  1362. u8 gainOm[] =
  1363. { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1364. if (expo > 0x03ff)
  1365. expo = 0x03ff;
  1366. if (expo < 0x0001)
  1367. expo = 0x0001;
  1368. gainOm[3] = expo >> 2;
  1369. i2c_w8(gspca_dev, gainOm);
  1370. reg_w1(gspca_dev, 0x96, (expo >> 5) & 0x1f);
  1371. PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
  1372. break;
  1373. }
  1374. }
  1375. return expo;
  1376. }
  1377. static void setbrightness(struct gspca_dev *gspca_dev)
  1378. {
  1379. struct sd *sd = (struct sd *) gspca_dev;
  1380. unsigned int expo;
  1381. u8 k2;
  1382. k2 = ((int) sd->brightness - 0x8000) >> 10;
  1383. switch (sd->sensor) {
  1384. case SENSOR_HV7131R:
  1385. expo = sd->brightness << 4;
  1386. if (expo > 0x002dc6c0)
  1387. expo = 0x002dc6c0;
  1388. else if (expo < 0x02a0)
  1389. expo = 0x02a0;
  1390. sd->exposure = setexposure(gspca_dev, expo);
  1391. break;
  1392. case SENSOR_MI0360:
  1393. case SENSOR_MO4000:
  1394. expo = sd->brightness >> 4;
  1395. sd->exposure = setexposure(gspca_dev, expo);
  1396. break;
  1397. case SENSOR_MT9V111:
  1398. expo = sd->brightness >> 8;
  1399. sd->exposure = setexposure(gspca_dev, expo);
  1400. break;
  1401. case SENSOR_OM6802:
  1402. expo = sd->brightness >> 6;
  1403. sd->exposure = setexposure(gspca_dev, expo);
  1404. k2 = sd->brightness >> 11;
  1405. break;
  1406. }
  1407. if (sd->sensor != SENSOR_MT9V111)
  1408. reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
  1409. }
  1410. static void setcontrast(struct gspca_dev *gspca_dev)
  1411. {
  1412. struct sd *sd = (struct sd *) gspca_dev;
  1413. u8 k2;
  1414. u8 contrast[6];
  1415. k2 = sd->contrast * 0x30 / (CONTRAST_MAX + 1) + 0x10; /* 10..40 */
  1416. contrast[0] = (k2 + 1) / 2; /* red */
  1417. contrast[1] = 0;
  1418. contrast[2] = k2; /* green */
  1419. contrast[3] = 0;
  1420. contrast[4] = (k2 + 1) / 5; /* blue */
  1421. contrast[5] = 0;
  1422. reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
  1423. }
  1424. static void setcolors(struct gspca_dev *gspca_dev)
  1425. {
  1426. struct sd *sd = (struct sd *) gspca_dev;
  1427. int i, v;
  1428. u8 reg8a[12]; /* U & V gains */
  1429. static s16 uv[6] = { /* same as reg84 in signed decimal */
  1430. -24, -38, 64, /* UR UG UB */
  1431. 62, -

Large files files are truncated, but you can click here to view the full file