PageRenderTime 62ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/media/video/gspca/sonixj.c

https://bitbucket.org/ndreys/linux-sunxi
C | 3115 lines | 2582 code | 218 blank | 315 comment | 197 complexity | a3e7656da81cae8cfe5226b4f8068b60 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * Sonix sn9c102p sn9c105 sn9c120 (jpeg) subdriver
  3. *
  4. * Copyright (C) 2009-2010 Jean-Fran??ois Moine <http://moinejf.free.fr>
  5. * Copyright (C) 2005 Michel Xhaard mxhaard@magic.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 <linux/input.h>
  23. #include "gspca.h"
  24. #include "jpeg.h"
  25. MODULE_AUTHOR("Jean-Fran??ois Moine <http://moinejf.free.fr>");
  26. MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
  27. MODULE_LICENSE("GPL");
  28. /* controls */
  29. enum e_ctrl {
  30. BRIGHTNESS,
  31. CONTRAST,
  32. COLORS,
  33. BLUE,
  34. RED,
  35. GAMMA,
  36. AUTOGAIN,
  37. HFLIP,
  38. VFLIP,
  39. SHARPNESS,
  40. ILLUM,
  41. FREQ,
  42. NCTRLS /* number of controls */
  43. };
  44. /* specific webcam descriptor */
  45. struct sd {
  46. struct gspca_dev gspca_dev; /* !! must be the first item */
  47. struct gspca_ctrl ctrls[NCTRLS];
  48. atomic_t avg_lum;
  49. u32 exposure;
  50. struct work_struct work;
  51. struct workqueue_struct *work_thread;
  52. u32 pktsz; /* (used by pkt_scan) */
  53. u16 npkt;
  54. s8 nchg;
  55. s8 short_mark;
  56. u8 quality; /* image quality */
  57. #define QUALITY_MIN 25
  58. #define QUALITY_MAX 90
  59. #define QUALITY_DEF 70
  60. u8 reg01;
  61. u8 reg17;
  62. u8 reg18;
  63. u8 flags;
  64. s8 ag_cnt;
  65. #define AG_CNT_START 13
  66. u8 bridge;
  67. #define BRIDGE_SN9C102P 0
  68. #define BRIDGE_SN9C105 1
  69. #define BRIDGE_SN9C110 2
  70. #define BRIDGE_SN9C120 3
  71. u8 sensor; /* Type of image sensor chip */
  72. u8 i2c_addr;
  73. u8 jpeg_hdr[JPEG_HDR_SZ];
  74. };
  75. enum sensors {
  76. SENSOR_ADCM1700,
  77. SENSOR_GC0307,
  78. SENSOR_HV7131R,
  79. SENSOR_MI0360,
  80. SENSOR_MI0360B,
  81. SENSOR_MO4000,
  82. SENSOR_MT9V111,
  83. SENSOR_OM6802,
  84. SENSOR_OV7630,
  85. SENSOR_OV7648,
  86. SENSOR_OV7660,
  87. SENSOR_PO1030,
  88. SENSOR_PO2030N,
  89. SENSOR_SOI768,
  90. SENSOR_SP80708,
  91. };
  92. static void qual_upd(struct work_struct *work);
  93. /* device flags */
  94. #define F_PDN_INV 0x01 /* inverse pin S_PWR_DN / sn_xxx tables */
  95. #define F_ILLUM 0x02 /* presence of illuminator */
  96. /* sn9c1xx definitions */
  97. /* register 0x01 */
  98. #define S_PWR_DN 0x01 /* sensor power down */
  99. #define S_PDN_INV 0x02 /* inverse pin S_PWR_DN */
  100. #define V_TX_EN 0x04 /* video transfer enable */
  101. #define LED 0x08 /* output to pin LED */
  102. #define SCL_SEL_OD 0x20 /* open-drain mode */
  103. #define SYS_SEL_48M 0x40 /* system clock 0: 24MHz, 1: 48MHz */
  104. /* register 0x17 */
  105. #define MCK_SIZE_MASK 0x1f /* sensor master clock */
  106. #define SEN_CLK_EN 0x20 /* enable sensor clock */
  107. #define DEF_EN 0x80 /* defect pixel by 0: soft, 1: hard */
  108. /* V4L2 controls supported by the driver */
  109. static void setbrightness(struct gspca_dev *gspca_dev);
  110. static void setcontrast(struct gspca_dev *gspca_dev);
  111. static void setcolors(struct gspca_dev *gspca_dev);
  112. static void setredblue(struct gspca_dev *gspca_dev);
  113. static void setgamma(struct gspca_dev *gspca_dev);
  114. static void setautogain(struct gspca_dev *gspca_dev);
  115. static void sethvflip(struct gspca_dev *gspca_dev);
  116. static void setsharpness(struct gspca_dev *gspca_dev);
  117. static void setillum(struct gspca_dev *gspca_dev);
  118. static void setfreq(struct gspca_dev *gspca_dev);
  119. static const struct ctrl sd_ctrls[NCTRLS] = {
  120. [BRIGHTNESS] = {
  121. {
  122. .id = V4L2_CID_BRIGHTNESS,
  123. .type = V4L2_CTRL_TYPE_INTEGER,
  124. .name = "Brightness",
  125. .minimum = 0,
  126. .maximum = 0xff,
  127. .step = 1,
  128. .default_value = 0x80,
  129. },
  130. .set_control = setbrightness
  131. },
  132. [CONTRAST] = {
  133. {
  134. .id = V4L2_CID_CONTRAST,
  135. .type = V4L2_CTRL_TYPE_INTEGER,
  136. .name = "Contrast",
  137. .minimum = 0,
  138. #define CONTRAST_MAX 127
  139. .maximum = CONTRAST_MAX,
  140. .step = 1,
  141. .default_value = 63,
  142. },
  143. .set_control = setcontrast
  144. },
  145. [COLORS] = {
  146. {
  147. .id = V4L2_CID_SATURATION,
  148. .type = V4L2_CTRL_TYPE_INTEGER,
  149. .name = "Saturation",
  150. .minimum = 0,
  151. .maximum = 40,
  152. .step = 1,
  153. #define COLORS_DEF 25
  154. .default_value = COLORS_DEF,
  155. },
  156. .set_control = setcolors
  157. },
  158. [BLUE] = {
  159. {
  160. .id = V4L2_CID_BLUE_BALANCE,
  161. .type = V4L2_CTRL_TYPE_INTEGER,
  162. .name = "Blue Balance",
  163. .minimum = 24,
  164. .maximum = 40,
  165. .step = 1,
  166. .default_value = 32,
  167. },
  168. .set_control = setredblue
  169. },
  170. [RED] = {
  171. {
  172. .id = V4L2_CID_RED_BALANCE,
  173. .type = V4L2_CTRL_TYPE_INTEGER,
  174. .name = "Red Balance",
  175. .minimum = 24,
  176. .maximum = 40,
  177. .step = 1,
  178. .default_value = 32,
  179. },
  180. .set_control = setredblue
  181. },
  182. [GAMMA] = {
  183. {
  184. .id = V4L2_CID_GAMMA,
  185. .type = V4L2_CTRL_TYPE_INTEGER,
  186. .name = "Gamma",
  187. .minimum = 0,
  188. .maximum = 40,
  189. .step = 1,
  190. #define GAMMA_DEF 20
  191. .default_value = GAMMA_DEF,
  192. },
  193. .set_control = setgamma
  194. },
  195. [AUTOGAIN] = {
  196. {
  197. .id = V4L2_CID_AUTOGAIN,
  198. .type = V4L2_CTRL_TYPE_BOOLEAN,
  199. .name = "Auto Gain",
  200. .minimum = 0,
  201. .maximum = 1,
  202. .step = 1,
  203. .default_value = 1
  204. },
  205. .set_control = setautogain
  206. },
  207. [HFLIP] = {
  208. {
  209. .id = V4L2_CID_HFLIP,
  210. .type = V4L2_CTRL_TYPE_BOOLEAN,
  211. .name = "Mirror",
  212. .minimum = 0,
  213. .maximum = 1,
  214. .step = 1,
  215. .default_value = 0,
  216. },
  217. .set_control = sethvflip
  218. },
  219. [VFLIP] = {
  220. {
  221. .id = V4L2_CID_VFLIP,
  222. .type = V4L2_CTRL_TYPE_BOOLEAN,
  223. .name = "Vflip",
  224. .minimum = 0,
  225. .maximum = 1,
  226. .step = 1,
  227. .default_value = 0,
  228. },
  229. .set_control = sethvflip
  230. },
  231. [SHARPNESS] = {
  232. {
  233. .id = V4L2_CID_SHARPNESS,
  234. .type = V4L2_CTRL_TYPE_INTEGER,
  235. .name = "Sharpness",
  236. .minimum = 0,
  237. .maximum = 255,
  238. .step = 1,
  239. .default_value = 90,
  240. },
  241. .set_control = setsharpness
  242. },
  243. [ILLUM] = {
  244. {
  245. .id = V4L2_CID_ILLUMINATORS_1,
  246. .type = V4L2_CTRL_TYPE_BOOLEAN,
  247. .name = "Illuminator / infrared",
  248. .minimum = 0,
  249. .maximum = 1,
  250. .step = 1,
  251. .default_value = 0,
  252. },
  253. .set_control = setillum
  254. },
  255. /* ov7630/ov7648/ov7660 only */
  256. [FREQ] = {
  257. {
  258. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  259. .type = V4L2_CTRL_TYPE_MENU,
  260. .name = "Light frequency filter",
  261. .minimum = 0,
  262. .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
  263. .step = 1,
  264. .default_value = 1,
  265. },
  266. .set_control = setfreq
  267. },
  268. };
  269. /* table of the disabled controls */
  270. static const __u32 ctrl_dis[] = {
  271. [SENSOR_ADCM1700] = (1 << AUTOGAIN) |
  272. (1 << HFLIP) |
  273. (1 << VFLIP) |
  274. (1 << FREQ),
  275. [SENSOR_GC0307] = (1 << HFLIP) |
  276. (1 << VFLIP) |
  277. (1 << FREQ),
  278. [SENSOR_HV7131R] = (1 << HFLIP) |
  279. (1 << FREQ),
  280. [SENSOR_MI0360] = (1 << HFLIP) |
  281. (1 << VFLIP) |
  282. (1 << FREQ),
  283. [SENSOR_MI0360B] = (1 << HFLIP) |
  284. (1 << VFLIP) |
  285. (1 << FREQ),
  286. [SENSOR_MO4000] = (1 << HFLIP) |
  287. (1 << VFLIP) |
  288. (1 << FREQ),
  289. [SENSOR_MT9V111] = (1 << HFLIP) |
  290. (1 << VFLIP) |
  291. (1 << FREQ),
  292. [SENSOR_OM6802] = (1 << HFLIP) |
  293. (1 << VFLIP) |
  294. (1 << FREQ),
  295. [SENSOR_OV7630] = (1 << HFLIP),
  296. [SENSOR_OV7648] = (1 << HFLIP),
  297. [SENSOR_OV7660] = (1 << AUTOGAIN) |
  298. (1 << HFLIP) |
  299. (1 << VFLIP),
  300. [SENSOR_PO1030] = (1 << AUTOGAIN) |
  301. (1 << HFLIP) |
  302. (1 << VFLIP) |
  303. (1 << FREQ),
  304. [SENSOR_PO2030N] = (1 << AUTOGAIN) |
  305. (1 << FREQ),
  306. [SENSOR_SOI768] = (1 << AUTOGAIN) |
  307. (1 << HFLIP) |
  308. (1 << VFLIP) |
  309. (1 << FREQ),
  310. [SENSOR_SP80708] = (1 << AUTOGAIN) |
  311. (1 << HFLIP) |
  312. (1 << VFLIP) |
  313. (1 << FREQ),
  314. };
  315. static const struct v4l2_pix_format cif_mode[] = {
  316. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  317. .bytesperline = 352,
  318. .sizeimage = 352 * 288 * 4 / 8 + 590,
  319. .colorspace = V4L2_COLORSPACE_JPEG,
  320. .priv = 0},
  321. };
  322. static const struct v4l2_pix_format vga_mode[] = {
  323. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  324. .bytesperline = 160,
  325. .sizeimage = 160 * 120 * 4 / 8 + 590,
  326. .colorspace = V4L2_COLORSPACE_JPEG,
  327. .priv = 2},
  328. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  329. .bytesperline = 320,
  330. .sizeimage = 320 * 240 * 3 / 8 + 590,
  331. .colorspace = V4L2_COLORSPACE_JPEG,
  332. .priv = 1},
  333. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  334. .bytesperline = 640,
  335. /* Note 3 / 8 is not large enough, not even 5 / 8 is ?! */
  336. .sizeimage = 640 * 480 * 3 / 4 + 590,
  337. .colorspace = V4L2_COLORSPACE_JPEG,
  338. .priv = 0},
  339. };
  340. static const u8 sn_adcm1700[0x1c] = {
  341. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  342. 0x00, 0x43, 0x60, 0x00, 0x1a, 0x00, 0x00, 0x00,
  343. /* reg8 reg9 rega regb regc regd rege regf */
  344. 0x80, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  345. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  346. 0x03, 0x00, 0x05, 0x01, 0x05, 0x16, 0x12, 0x42,
  347. /* reg18 reg19 reg1a reg1b */
  348. 0x06, 0x00, 0x00, 0x00
  349. };
  350. static const u8 sn_gc0307[0x1c] = {
  351. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  352. 0x00, 0x61, 0x62, 0x00, 0x1a, 0x00, 0x00, 0x00,
  353. /* reg8 reg9 rega regb regc regd rege regf */
  354. 0x80, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  355. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  356. 0x03, 0x00, 0x03, 0x01, 0x08, 0x28, 0x1e, 0x02,
  357. /* reg18 reg19 reg1a reg1b */
  358. 0x06, 0x00, 0x00, 0x00
  359. };
  360. static const u8 sn_hv7131[0x1c] = {
  361. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  362. 0x00, 0x03, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
  363. /* reg8 reg9 rega regb regc regd rege regf */
  364. 0x81, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  365. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  366. 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
  367. /* reg18 reg19 reg1a reg1b */
  368. 0x0a, 0x00, 0x00, 0x00
  369. };
  370. static const u8 sn_mi0360[0x1c] = {
  371. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  372. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  373. /* reg8 reg9 rega regb regc regd rege regf */
  374. 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  375. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  376. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
  377. /* reg18 reg19 reg1a reg1b */
  378. 0x06, 0x00, 0x00, 0x00
  379. };
  380. static const u8 sn_mi0360b[0x1c] = {
  381. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  382. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  383. /* reg8 reg9 rega regb regc regd rege regf */
  384. 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  385. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  386. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x40,
  387. /* reg18 reg19 reg1a reg1b */
  388. 0x06, 0x00, 0x00, 0x00
  389. };
  390. static const u8 sn_mo4000[0x1c] = {
  391. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  392. 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
  393. /* reg8 reg9 rega regb regc regd rege regf */
  394. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  395. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  396. 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
  397. /* reg18 reg19 reg1a reg1b */
  398. 0x08, 0x00, 0x00, 0x00
  399. };
  400. static const u8 sn_mt9v111[0x1c] = {
  401. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  402. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  403. /* reg8 reg9 rega regb regc regd rege regf */
  404. 0x81, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  405. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  406. 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
  407. /* reg18 reg19 reg1a reg1b */
  408. 0x06, 0x00, 0x00, 0x00
  409. };
  410. static const u8 sn_om6802[0x1c] = {
  411. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  412. 0x00, 0x23, 0x72, 0x00, 0x1a, 0x20, 0x20, 0x19,
  413. /* reg8 reg9 rega regb regc regd rege regf */
  414. 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  415. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  416. 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
  417. /* reg18 reg19 reg1a reg1b */
  418. 0x05, 0x00, 0x00, 0x00
  419. };
  420. static const u8 sn_ov7630[0x1c] = {
  421. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  422. 0x00, 0x21, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  423. /* reg8 reg9 rega regb regc regd rege regf */
  424. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  425. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  426. 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
  427. /* reg18 reg19 reg1a reg1b */
  428. 0x0b, 0x00, 0x00, 0x00
  429. };
  430. static const u8 sn_ov7648[0x1c] = {
  431. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  432. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  433. /* reg8 reg9 rega regb regc regd rege regf */
  434. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  435. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  436. 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
  437. /* reg18 reg19 reg1a reg1b */
  438. 0x0b, 0x00, 0x00, 0x00
  439. };
  440. static const u8 sn_ov7660[0x1c] = {
  441. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  442. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  443. /* reg8 reg9 rega regb regc regd rege regf */
  444. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  445. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  446. 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
  447. /* reg18 reg19 reg1a reg1b */
  448. 0x07, 0x00, 0x00, 0x00
  449. };
  450. static const u8 sn_po1030[0x1c] = {
  451. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  452. 0x00, 0x21, 0x62, 0x00, 0x1a, 0x20, 0x20, 0x20,
  453. /* reg8 reg9 rega regb regc regd rege regf */
  454. 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  455. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  456. 0x03, 0x00, 0x00, 0x06, 0x06, 0x28, 0x1e, 0x00,
  457. /* reg18 reg19 reg1a reg1b */
  458. 0x07, 0x00, 0x00, 0x00
  459. };
  460. static const u8 sn_po2030n[0x1c] = {
  461. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  462. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  463. /* reg8 reg9 rega regb regc regd rege regf */
  464. 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  465. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  466. 0x03, 0x00, 0x00, 0x01, 0x14, 0x28, 0x1e, 0x00,
  467. /* reg18 reg19 reg1a reg1b */
  468. 0x07, 0x00, 0x00, 0x00
  469. };
  470. static const u8 sn_soi768[0x1c] = {
  471. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  472. 0x00, 0x21, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  473. /* reg8 reg9 rega regb regc regd rege regf */
  474. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  475. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  476. 0x03, 0x00, 0x00, 0x01, 0x08, 0x28, 0x1e, 0x00,
  477. /* reg18 reg19 reg1a reg1b */
  478. 0x07, 0x00, 0x00, 0x00
  479. };
  480. static const u8 sn_sp80708[0x1c] = {
  481. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  482. 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
  483. /* reg8 reg9 rega regb regc regd rege regf */
  484. 0x81, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  485. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  486. 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
  487. /* reg18 reg19 reg1a reg1b */
  488. 0x07, 0x00, 0x00, 0x00
  489. };
  490. /* sequence specific to the sensors - !! index = SENSOR_xxx */
  491. static const u8 *sn_tb[] = {
  492. [SENSOR_ADCM1700] = sn_adcm1700,
  493. [SENSOR_GC0307] = sn_gc0307,
  494. [SENSOR_HV7131R] = sn_hv7131,
  495. [SENSOR_MI0360] = sn_mi0360,
  496. [SENSOR_MI0360B] = sn_mi0360b,
  497. [SENSOR_MO4000] = sn_mo4000,
  498. [SENSOR_MT9V111] = sn_mt9v111,
  499. [SENSOR_OM6802] = sn_om6802,
  500. [SENSOR_OV7630] = sn_ov7630,
  501. [SENSOR_OV7648] = sn_ov7648,
  502. [SENSOR_OV7660] = sn_ov7660,
  503. [SENSOR_PO1030] = sn_po1030,
  504. [SENSOR_PO2030N] = sn_po2030n,
  505. [SENSOR_SOI768] = sn_soi768,
  506. [SENSOR_SP80708] = sn_sp80708,
  507. };
  508. /* default gamma table */
  509. static const u8 gamma_def[17] = {
  510. 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
  511. 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
  512. };
  513. /* gamma for sensor ADCM1700 */
  514. static const u8 gamma_spec_0[17] = {
  515. 0x0f, 0x39, 0x5a, 0x74, 0x86, 0x95, 0xa6, 0xb4,
  516. 0xbd, 0xc4, 0xcc, 0xd4, 0xd5, 0xde, 0xe4, 0xed, 0xf5
  517. };
  518. /* gamma for sensors HV7131R and MT9V111 */
  519. static const u8 gamma_spec_1[17] = {
  520. 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
  521. 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
  522. };
  523. /* gamma for sensor GC0307 */
  524. static const u8 gamma_spec_2[17] = {
  525. 0x14, 0x37, 0x50, 0x6a, 0x7c, 0x8d, 0x9d, 0xab,
  526. 0xb5, 0xbf, 0xc2, 0xcb, 0xd1, 0xd6, 0xdb, 0xe1, 0xeb
  527. };
  528. /* gamma for sensor SP80708 */
  529. static const u8 gamma_spec_3[17] = {
  530. 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
  531. 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
  532. };
  533. /* color matrix and offsets */
  534. static const u8 reg84[] = {
  535. 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
  536. 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
  537. 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
  538. 0x00, 0x00, 0x00 /* YUV offsets */
  539. };
  540. #define DELAY 0xdd
  541. static const u8 adcm1700_sensor_init[][8] = {
  542. {0xa0, 0x51, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x10},
  543. {0xb0, 0x51, 0x04, 0x08, 0x00, 0x00, 0x00, 0x10}, /* reset */
  544. {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  545. {0xb0, 0x51, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  546. {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  547. {0xb0, 0x51, 0x0c, 0xe0, 0x2e, 0x00, 0x00, 0x10},
  548. {0xb0, 0x51, 0x10, 0x02, 0x02, 0x00, 0x00, 0x10},
  549. {0xb0, 0x51, 0x14, 0x0e, 0x0e, 0x00, 0x00, 0x10},
  550. {0xb0, 0x51, 0x1c, 0x00, 0x80, 0x00, 0x00, 0x10},
  551. {0xb0, 0x51, 0x20, 0x01, 0x00, 0x00, 0x00, 0x10},
  552. {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  553. {0xb0, 0x51, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10},
  554. {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  555. {0xb0, 0x51, 0x04, 0x01, 0x00, 0x00, 0x00, 0x10},
  556. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  557. {0xb0, 0x51, 0x14, 0x01, 0x00, 0x00, 0x00, 0x10},
  558. {0xb0, 0x51, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  559. {}
  560. };
  561. static const u8 adcm1700_sensor_param1[][8] = {
  562. {0xb0, 0x51, 0x26, 0xf9, 0x01, 0x00, 0x00, 0x10}, /* exposure? */
  563. {0xd0, 0x51, 0x1e, 0x8e, 0x8e, 0x8e, 0x8e, 0x10},
  564. {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
  565. {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
  566. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  567. {0xb0, 0x51, 0x32, 0x00, 0x72, 0x00, 0x00, 0x10},
  568. {0xd0, 0x51, 0x1e, 0xbe, 0xd7, 0xe8, 0xbe, 0x10}, /* exposure? */
  569. {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
  570. {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
  571. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  572. {0xb0, 0x51, 0x32, 0x00, 0xa2, 0x00, 0x00, 0x10},
  573. {}
  574. };
  575. static const u8 gc0307_sensor_init[][8] = {
  576. {0xa0, 0x21, 0x43, 0x00, 0x00, 0x00, 0x00, 0x10},
  577. {0xa0, 0x21, 0x44, 0xa2, 0x00, 0x00, 0x00, 0x10},
  578. {0xa0, 0x21, 0x01, 0x6a, 0x00, 0x00, 0x00, 0x10},
  579. {0xa0, 0x21, 0x02, 0x70, 0x00, 0x00, 0x00, 0x10},
  580. {0xa0, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  581. {0xa0, 0x21, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  582. {0xa0, 0x21, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
  583. {0xa0, 0x21, 0x11, 0x05, 0x00, 0x00, 0x00, 0x10},
  584. {0xa0, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  585. {0xa0, 0x21, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
  586. {0xa0, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10},
  587. {0xa0, 0x21, 0x08, 0x02, 0x00, 0x00, 0x00, 0x10},
  588. {0xa0, 0x21, 0x09, 0x01, 0x00, 0x00, 0x00, 0x10},
  589. {0xa0, 0x21, 0x0a, 0xe8, 0x00, 0x00, 0x00, 0x10},
  590. {0xa0, 0x21, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x10},
  591. {0xa0, 0x21, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x10},
  592. {0xa0, 0x21, 0x0d, 0x22, 0x00, 0x00, 0x00, 0x10},
  593. {0xa0, 0x21, 0x0e, 0x02, 0x00, 0x00, 0x00, 0x10},
  594. {0xa0, 0x21, 0x0f, 0xb2, 0x00, 0x00, 0x00, 0x10},
  595. {0xa0, 0x21, 0x12, 0x70, 0x00, 0x00, 0x00, 0x10},
  596. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 10ms*/
  597. {0xa0, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10},
  598. {0xa0, 0x21, 0x15, 0xb8, 0x00, 0x00, 0x00, 0x10},
  599. {0xa0, 0x21, 0x16, 0x13, 0x00, 0x00, 0x00, 0x10},
  600. {0xa0, 0x21, 0x17, 0x52, 0x00, 0x00, 0x00, 0x10},
  601. {0xa0, 0x21, 0x18, 0x50, 0x00, 0x00, 0x00, 0x10},
  602. {0xa0, 0x21, 0x1e, 0x0d, 0x00, 0x00, 0x00, 0x10},
  603. {0xa0, 0x21, 0x1f, 0x32, 0x00, 0x00, 0x00, 0x10},
  604. {0xa0, 0x21, 0x61, 0x90, 0x00, 0x00, 0x00, 0x10},
  605. {0xa0, 0x21, 0x63, 0x70, 0x00, 0x00, 0x00, 0x10},
  606. {0xa0, 0x21, 0x65, 0x98, 0x00, 0x00, 0x00, 0x10},
  607. {0xa0, 0x21, 0x67, 0x90, 0x00, 0x00, 0x00, 0x10},
  608. {0xa0, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  609. {0xa0, 0x21, 0x04, 0x96, 0x00, 0x00, 0x00, 0x10},
  610. {0xa0, 0x21, 0x45, 0x27, 0x00, 0x00, 0x00, 0x10},
  611. {0xa0, 0x21, 0x47, 0x2c, 0x00, 0x00, 0x00, 0x10},
  612. {0xa0, 0x21, 0x43, 0x47, 0x00, 0x00, 0x00, 0x10},
  613. {0xa0, 0x21, 0x44, 0xd8, 0x00, 0x00, 0x00, 0x10},
  614. {}
  615. };
  616. static const u8 gc0307_sensor_param1[][8] = {
  617. {0xa0, 0x21, 0x68, 0x13, 0x00, 0x00, 0x00, 0x10},
  618. {0xd0, 0x21, 0x61, 0x80, 0x00, 0x80, 0x00, 0x10},
  619. {0xc0, 0x21, 0x65, 0x80, 0x00, 0x80, 0x00, 0x10},
  620. {0xc0, 0x21, 0x63, 0xa0, 0x00, 0xa6, 0x00, 0x10},
  621. /*param3*/
  622. {0xa0, 0x21, 0x01, 0x6e, 0x00, 0x00, 0x00, 0x10},
  623. {0xa0, 0x21, 0x02, 0x88, 0x00, 0x00, 0x00, 0x10},
  624. {}
  625. };
  626. static const u8 hv7131r_sensor_init[][8] = {
  627. {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
  628. {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
  629. {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
  630. /* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  631. {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  632. {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
  633. /* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  634. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  635. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  636. {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
  637. {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
  638. {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
  639. {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
  640. {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
  641. {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
  642. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  643. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  644. {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
  645. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  646. {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
  647. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  648. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  649. {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
  650. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  651. {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
  652. {0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10},
  653. /* set sensor clock */
  654. {}
  655. };
  656. static const u8 mi0360_sensor_init[][8] = {
  657. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  658. {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
  659. {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  660. {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  661. {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
  662. {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
  663. {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
  664. {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  665. {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
  666. {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  667. {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  668. {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  669. {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  670. {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  671. {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  672. {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
  673. {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  674. {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  675. {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  676. {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  677. {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  678. {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  679. {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
  680. {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  681. {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  682. {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
  683. {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
  684. {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  685. {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  686. {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
  687. {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
  688. {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
  689. {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  690. {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  691. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  692. {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  693. {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
  694. {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
  695. {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
  696. {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
  697. {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
  698. {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  699. {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
  700. {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
  701. /* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
  702. /* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
  703. {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  704. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  705. {}
  706. };
  707. static const u8 mi0360b_sensor_init[][8] = {
  708. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  709. {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
  710. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
  711. {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  712. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
  713. {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  714. {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
  715. {0xd1, 0x5d, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  716. {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
  717. {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  718. {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
  719. {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  720. {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  721. {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  722. {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  723. {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  724. {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  725. {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
  726. {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  727. {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  728. {0xd1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  729. {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  730. {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  731. {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  732. {0xd1, 0x5d, 0x2f, 0xf7, 0xb0, 0x00, 0x04, 0x10},
  733. {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  734. {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  735. {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
  736. {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
  737. {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  738. {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  739. {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
  740. {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
  741. {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
  742. {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  743. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  744. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  745. {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  746. {0xd1, 0x5d, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10},
  747. {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10},
  748. {}
  749. };
  750. static const u8 mi0360b_sensor_param1[][8] = {
  751. {0xb1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  752. {0xb1, 0x5d, 0x06, 0x00, 0x53, 0x00, 0x00, 0x10},
  753. {0xb1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x00, 0x10},
  754. {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  755. {0xd1, 0x5d, 0x2b, 0x00, 0xd1, 0x01, 0xc9, 0x10},
  756. {0xd1, 0x5d, 0x2d, 0x00, 0xed, 0x00, 0xd1, 0x10},
  757. {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  758. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  759. {}
  760. };
  761. static const u8 mo4000_sensor_init[][8] = {
  762. {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
  763. {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
  764. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  765. {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  766. {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  767. {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
  768. {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
  769. {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
  770. {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  771. {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
  772. {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
  773. {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
  774. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  775. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  776. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  777. {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  778. {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
  779. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
  780. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  781. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  782. {}
  783. };
  784. static const u8 mt9v111_sensor_init[][8] = {
  785. {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
  786. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  787. {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  788. {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
  789. {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
  790. {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
  791. {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
  792. {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
  793. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
  794. {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
  795. {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
  796. {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
  797. {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
  798. {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
  799. {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
  800. {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
  801. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
  802. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  803. {}
  804. };
  805. static const u8 mt9v111_sensor_param1[][8] = {
  806. {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xad, 0x10}, /* G1 and B gains */
  807. {0xd1, 0x5c, 0x2d, 0x00, 0xad, 0x00, 0x33, 0x10}, /* R and G2 gains */
  808. {0xb1, 0x5c, 0x06, 0x00, 0x40, 0x00, 0x00, 0x10}, /* vert blanking */
  809. {0xb1, 0x5c, 0x05, 0x00, 0x09, 0x00, 0x00, 0x10}, /* horiz blanking */
  810. {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
  811. {}
  812. };
  813. static const u8 om6802_init0[2][8] = {
  814. /*fixme: variable*/
  815. {0xa0, 0x34, 0x29, 0x0e, 0x00, 0x00, 0x00, 0x10},
  816. {0xa0, 0x34, 0x23, 0xb0, 0x00, 0x00, 0x00, 0x10},
  817. };
  818. static const u8 om6802_sensor_init[][8] = {
  819. {0xa0, 0x34, 0xdf, 0x6d, 0x00, 0x00, 0x00, 0x10},
  820. /* factory mode */
  821. {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
  822. /* output raw RGB */
  823. {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
  824. /* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
  825. {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
  826. /* auto-exposure speed (0) / white balance mode (auto RGB) */
  827. /* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
  828. * set color mode */
  829. /* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
  830. * max AGC value in AE */
  831. /* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
  832. * preset AGC */
  833. /* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
  834. * preset brightness */
  835. /* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
  836. * preset contrast */
  837. /* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
  838. * preset gamma */
  839. {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
  840. /* luminance mode (0x4f -> AutoExpo on) */
  841. {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
  842. /* preset shutter */
  843. /* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
  844. * auto frame rate */
  845. /* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
  846. {0xa0, 0x34, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
  847. {}
  848. };
  849. static const u8 om6802_sensor_param1[][8] = {
  850. {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10},
  851. {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10},
  852. {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10},
  853. {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10},
  854. {}
  855. };
  856. static const u8 ov7630_sensor_init[][8] = {
  857. {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
  858. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  859. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  860. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  861. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  862. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  863. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  864. /* win: i2c_r from 00 to 80 */
  865. {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
  866. {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
  867. /* HDG: 0x11 was 0x00 change to 0x01 for better exposure (15 fps instead of 30)
  868. 0x13 was 0xc0 change to 0xc3 for auto gain and exposure */
  869. {0xd1, 0x21, 0x11, 0x01, 0x48, 0xc3, 0x00, 0x10},
  870. {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
  871. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  872. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  873. {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
  874. {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
  875. {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
  876. {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
  877. {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
  878. {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
  879. {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  880. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
  881. {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
  882. {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
  883. {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
  884. {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
  885. {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
  886. {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
  887. {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
  888. {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
  889. {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
  890. {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
  891. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  892. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  893. {}
  894. };
  895. static const u8 ov7630_sensor_param1[][8] = {
  896. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  897. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  898. /*fixme: + 0x12, 0x04*/
  899. /* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
  900. * set by setvflip */
  901. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  902. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  903. {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
  904. /* */
  905. /* {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  906. /* {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  907. /* */
  908. {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
  909. /* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
  910. {}
  911. };
  912. static const u8 ov7648_sensor_init[][8] = {
  913. {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
  914. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
  915. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  916. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  917. {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
  918. {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
  919. {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
  920. {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
  921. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  922. {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
  923. {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
  924. {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
  925. {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
  926. {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
  927. {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
  928. {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
  929. {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
  930. {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
  931. {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
  932. {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
  933. {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
  934. {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
  935. {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
  936. /* {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
  937. /* {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
  938. /* {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, set by setfreq */
  939. {}
  940. };
  941. static const u8 ov7648_sensor_param1[][8] = {
  942. /* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
  943. /* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
  944. * set by setvflip */
  945. {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
  946. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  947. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  948. /* {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, * GAIN - def */
  949. /* {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10}, * B R - def: 80 */
  950. /*...*/
  951. {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
  952. /* {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  953. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  954. /* {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
  955. /* {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  956. /* {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10}, * B R - def: 80 */
  957. {}
  958. };
  959. static const u8 ov7660_sensor_init[][8] = {
  960. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
  961. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  962. {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
  963. /* Outformat = rawRGB */
  964. {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
  965. {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
  966. /* GAIN BLUE RED VREF */
  967. {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
  968. /* COM 1 BAVE GEAVE AECHH */
  969. {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
  970. {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
  971. {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
  972. /* AECH CLKRC COM7 COM8 */
  973. {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
  974. {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
  975. /* HSTART HSTOP VSTRT VSTOP */
  976. {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
  977. {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
  978. {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
  979. /* BOS GBOS GROS ROS (BGGR offset) */
  980. /* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
  981. {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
  982. /* AEW AEB VPT BBIAS */
  983. {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
  984. /* GbBIAS RSVD EXHCH EXHCL */
  985. {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
  986. /* RBIAS ADVFL ASDVFH YAVE */
  987. {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
  988. /* HSYST HSYEN HREF */
  989. {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
  990. {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
  991. /* ADC ACOM OFON TSLB */
  992. {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
  993. /* COM11 COM12 COM13 COM14 */
  994. {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
  995. /* EDGE COM15 COM16 COM17 */
  996. {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
  997. {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
  998. {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  999. {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
  1000. {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
  1001. {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
  1002. {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
  1003. {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
  1004. {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  1005. {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
  1006. /* LCC1 LCC2 LCC3 LCC4 */
  1007. {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
  1008. {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
  1009. {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
  1010. /* band gap reference [0:3] DBLV */
  1011. {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
  1012. {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
  1013. {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
  1014. {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
  1015. {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
  1016. {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
  1017. {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
  1018. {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
  1019. {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
  1020. {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
  1021. /* not in all ms-win traces*/
  1022. {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
  1023. {}
  1024. };
  1025. static const u8 ov7660_sensor_param1[][8] = {
  1026. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
  1027. /* bits[3..0]reserved */
  1028. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
  1029. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  1030. /* VREF vertical frame ctrl */
  1031. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  1032. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
  1033. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
  1034. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
  1035. {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
  1036. /* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
  1037. /****** (some exchanges in the win trace) ******/
  1038. /*fixme:param2*/
  1039. {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
  1040. {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
  1041. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
  1042. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
  1043. /* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
  1044. /****** (some exchanges in the win trace) ******/
  1045. /******!! startsensor KO if changed !!****/
  1046. /*fixme: param3*/
  1047. {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
  1048. {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
  1049. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
  1050. {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
  1051. {}
  1052. };
  1053. static const u8 po1030_sensor_init[][8] = {
  1054. /* the sensor registers are described in m5602/m5602_po1030.h */
  1055. {0xa1, 0x6e, 0x3f, 0x20, 0x00, 0x00, 0x00, 0x10}, /* sensor reset */
  1056. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  1057. {0xa1, 0x6e, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1058. {0xa1, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x10},
  1059. {0xd1, 0x6e, 0x04, 0x02, 0xb1, 0x02, 0x39, 0x10},
  1060. {0xd1, 0x6e, 0x08, 0x00, 0x01, 0x00, 0x00, 0x10},
  1061. {0xd1, 0x6e, 0x0c, 0x02, 0x7f, 0x01, 0xe0, 0x10},
  1062. {0xd1, 0x6e, 0x12, 0x03, 0x02, 0x00, 0x03, 0x10},
  1063. {0xd1, 0x6e, 0x16, 0x85, 0x40, 0x4a, 0x40, 0x10}, /* r/g1/b/g2 gains */
  1064. {0xc1, 0x6e, 0x1a, 0x00, 0x80, 0x00, 0x00, 0x10},
  1065. {0xd1, 0x6e, 0x1d, 0x08, 0x03, 0x00, 0x00, 0x10},
  1066. {0xd1, 0x6e, 0x23, 0x00, 0xb0, 0x00, 0x94, 0x10},
  1067. {0xd1, 0x6e, 0x27, 0x58, 0x00, 0x00, 0x00, 0x10},
  1068. {0xb1, 0x6e, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
  1069. {0xd1, 0x6e, 0x2d, 0x14, 0x35, 0x61, 0x84, 0x10}, /* gamma corr */
  1070. {0xd1, 0x6e, 0x31, 0xa2, 0xbd, 0xd8, 0xff, 0x10},
  1071. {0xd1, 0x6e, 0x35, 0x06, 0x1e, 0x12, 0x02, 0x10}, /* color matrix */
  1072. {0xd1, 0x6e, 0x39, 0xaa, 0x53, 0x37, 0xd5, 0x10},
  1073. {0xa1, 0x6e, 0x3d, 0xf2, 0x00, 0x00, 0x00, 0x10},
  1074. {0xd1, 0x6e, 0x3e, 0x00, 0x00, 0x80, 0x03, 0x10},
  1075. {0xd1, 0x6e, 0x42, 0x03, 0x00, 0x00, 0x00, 0x10},
  1076. {0xc1, 0x6e, 0x46, 0x00, 0x80, 0x80, 0x00, 0x10},
  1077. {0xd1, 0x6e, 0x4b, 0x02, 0xef, 0x08, 0xcd, 0x10},
  1078. {0xd1, 0x6e, 0x4f, 0x00, 0xd0, 0x00, 0xa0, 0x10},
  1079. {0xd1, 0x6e, 0x53, 0x01, 0xaa, 0x01, 0x40, 0x10},
  1080. {0xd1, 0x6e, 0x5a, 0x50, 0x04, 0x30, 0x03, 0x10}, /* raw rgb bayer */
  1081. {0xa1, 0x6e, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x10},
  1082. {0xd1, 0x6e, 0x5f, 0x10, 0x40, 0xff, 0x00, 0x10},
  1083. {0xd1, 0x6e, 0x63, 0x40, 0x40, 0x00, 0x00, 0x10},
  1084. {0xd1, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x10},
  1085. {0xd1, 0x6e, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x10},
  1086. {0xd1, 0x6e, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1087. {0xc1, 0x6e, 0x73, 0x10, 0x80, 0xeb, 0x00, 0x10},
  1088. {}
  1089. };
  1090. static const u8 po1030_sensor_param1[][8] = {
  1091. /* from ms-win traces - these values change with auto gain/expo/wb.. */
  1092. {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
  1093. {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
  1094. /* mean values */
  1095. {0xc1, 0x6e, 0x1a, 0x02, 0xd4, 0xa4, 0x00, 0x10}, /* integlines */
  1096. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10}, /* global gain */
  1097. {0xc1, 0x6e, 0x16, 0x40, 0x40, 0x40, 0x00, 0x10}, /* r/g1/b gains */
  1098. {0xa1, 0x6e, 0x1d, 0x08, 0x00, 0x00, 0x00, 0x10}, /* control1 */
  1099. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10}, /* frameheight */
  1100. {0xa1, 0x6e, 0x07, 0xd5, 0x00, 0x00, 0x00, 0x10},
  1101. /* {0xc1, 0x6e, 0x16, 0x49, 0x40, 0x45, 0x00, 0x10}, */
  1102. {}
  1103. };
  1104. static const u8 po2030n_sensor_init[][8] = {
  1105. {0xa1, 0x6e, 0x1e, 0x1a, 0x00, 0x00, 0x00, 0x10},
  1106. {0xa1, 0x6e, 0x1f, 0x99, 0x00, 0x00, 0x00, 0x10},
  1107. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
  1108. {0xa1, 0x6e, 0x1e, 0x0a, 0x00, 0x00, 0x00, 0x10},
  1109. {0xa1, 0x6e, 0x1f, 0x19, 0x00, 0x00, 0x00, 0x10},
  1110. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
  1111. {0xa1, 0x6e, 0x20, 0x44, 0x00, 0x00, 0x00, 0x10},
  1112. {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
  1113. {0xa1, 0x6e, 0x05, 0x70, 0x00, 0x00, 0x00, 0x10},
  1114. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  1115. {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
  1116. {0xd1, 0x6e, 0x08, 0x00, 0xd0, 0x00, 0x08, 0x10},
  1117. {0xd1, 0x6e, 0x0c, 0x03, 0x50, 0x01, 0xe8, 0x10},
  1118. {0xd1, 0x6e, 0x1d, 0x20, 0x0a, 0x19, 0x44, 0x10},
  1119. {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
  1120. {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x00, 0x10},
  1121. {0xd1, 0x6e, 0x29, 0x00, 0x00, 0x00, 0x00, 0x10},
  1122. {0xd1, 0x6e, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1123. {0xd1, 0x6e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  1124. {0xd1, 0x6e, 0x35, 0x00, 0x00, 0x00, 0x00, 0x10},
  1125. {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x00, 0x00, 0x10},
  1126. {0xd1, 0x6e, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1127. {0xd1, 0x6e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x10},
  1128. {0xd1, 0x6e, 0x45, 0x00, 0x00, 0x00, 0x00, 0x10},
  1129. {0xd1, 0x6e, 0x49, 0x00, 0x00, 0x00, 0x00, 0x10},
  1130. {0xd1, 0x6e, 0x4d, 0x00, 0x00, 0x00, 0xed, 0x10},
  1131. {0xd1, 0x6e, 0x51, 0x17, 0x4a, 0x2f, 0xc0, 0x10},
  1132. {0xd1, 0x6e, 0x55, 0x00, 0x00, 0x00, 0x00, 0x10},
  1133. {0xd1, 0x6e, 0x59, 0x00, 0x00, 0x00, 0x00, 0x10},
  1134. {0xd1, 0x6e, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1135. {0xd1, 0x6e, 0x61, 0x00, 0x00, 0x00, 0x00, 0x10},
  1136. {0xd1, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x00, 0x10},
  1137. {0xd1, 0x6e, 0x69, 0x00, 0x00, 0x00, 0x00, 0x10},
  1138. {0xd1, 0x6e, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1139. {0xd1, 0x6e, 0x71, 0x00, 0x00, 0x00, 0x00, 0x10},
  1140. {0xd1, 0x6e, 0x75, 0x00, 0x00, 0x00, 0x00, 0x10},
  1141. {0xd1, 0x6e, 0x79, 0x00, 0x00, 0x00, 0x00, 0x10},
  1142. {0xd1, 0x6e, 0x7d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1143. {0xd1, 0x6e, 0x81, 0x00, 0x00, 0x00, 0x00, 0x10},
  1144. {0xd1, 0x6e, 0x85, 0x00, 0x00, 0x00, 0x08, 0x10},
  1145. {0xd1, 0x6e, 0x89, 0x01, 0xe8, 0x00, 0x01, 0x10},
  1146. {0xa1, 0x6e, 0x8d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1147. {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
  1148. {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x01, 0x10},
  1149. {0xd1, 0x6e, 0x29, 0xe6, 0x00, 0xbd, 0x03, 0x10},
  1150. {0xd1, 0x6e, 0x2d, 0x41, 0x38, 0x68, 0x40, 0x10},
  1151. {0xd1, 0x6e, 0x31, 0x2b, 0x00, 0x36, 0x00, 0x10},
  1152. {0xd1, 0x6e, 0x35, 0x30, 0x30, 0x08, 0x00, 0x10},
  1153. {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x33, 0x06, 0x10},
  1154. {0xb1, 0x6e, 0x3d, 0x06, 0x02, 0x00, 0x00, 0x10},
  1155. {}
  1156. };
  1157. static const u8 po2030n_sensor_param1[][8] = {
  1158. {0xa1, 0x6e, 0x1a, 0x01, 0x00, 0x00, 0x00, 0x10},
  1159. {DELAY, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 8ms */
  1160. {0xa1, 0x6e, 0x1b, 0xf4, 0x00, 0x00, 0x00, 0x10},
  1161. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
  1162. {0xd1, 0x6e, 0x16, 0x50, 0x40, 0x49, 0x40, 0x10},
  1163. /*param2*/
  1164. {0xa1, 0x6e, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1165. {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
  1166. {0xa1, 0x6e, 0x05, 0x6f, 0x00, 0x00, 0x00, 0x10},
  1167. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  1168. {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
  1169. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
  1170. {0xc1, 0x6e, 0x16, 0x52, 0x40, 0x48, 0x00, 0x10},
  1171. /*after start*/
  1172. {0xa1, 0x6e, 0x15, 0x0f, 0x00, 0x00, 0x00, 0x10},
  1173. {DELAY, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */
  1174. {0xa1, 0x6e, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x10},
  1175. {DELAY, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */
  1176. {0xa1, 0x6e, 0x1b, 0x53, 0x00, 0x00, 0x00, 0x10},
  1177. {}
  1178. };
  1179. static const u8 soi768_sensor_init[][8] = {
  1180. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
  1181. {DELAY, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 96ms */
  1182. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  1183. {0xa1, 0x21, 0x13, 0x80, 0x00, 0x00, 0x00, 0x10},
  1184. {0xa1, 0x21, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x10},
  1185. {0xa1, 0x21, 0x19, 0x00, 0x00, 0x00, 0x00, 0x10},
  1186. {}
  1187. };
  1188. static const u8 soi768_sensor_param1[][8] = {
  1189. {0xa1, 0x21, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10},
  1190. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1191. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
  1192. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1193. {0xb1, 0x21, 0x01, 0x7f, 0x7f, 0x00, 0x00, 0x10},
  1194. /* */
  1195. /* {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  1196. /* {0xa1, 0x21, 0x2d, 0x25, 0x00, 0x00, 0x00, 0x10}, */
  1197. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
  1198. /* {0xb1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  1199. {0xa1, 0x21, 0x02, 0x8d, 0x00, 0x00, 0x00, 0x10},
  1200. /* the next sequence should be used for auto gain */
  1201. {0xa1, 0x21, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10},
  1202. /* global gain ? : 07 - change with 0x15 at the end */
  1203. {0xa1, 0x21, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x10}, /* ???? : 063f */
  1204. {0xa1, 0x21, 0x04, 0x06, 0x00, 0x00, 0x00, 0x10},
  1205. {0xb1, 0x21, 0x2d, 0x00, 0x02, 0x00, 0x00, 0x10},
  1206. /* exposure ? : 0200 - change with 0x1e at the end */
  1207. {}
  1208. };
  1209. static const u8 sp80708_sensor_init[][8] = {
  1210. {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
  1211. {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
  1212. {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  1213. {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
  1214. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1215. {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
  1216. {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
  1217. {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
  1218. {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
  1219. {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
  1220. {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
  1221. {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
  1222. {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
  1223. {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
  1224. {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
  1225. {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
  1226. {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
  1227. {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
  1228. {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
  1229. {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
  1230. {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
  1231. {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
  1232. {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
  1233. {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
  1234. {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
  1235. {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
  1236. {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
  1237. {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
  1238. {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
  1239. {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
  1240. {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
  1241. {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
  1242. {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
  1243. {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
  1244. {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
  1245. {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
  1246. {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
  1247. {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
  1248. {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
  1249. {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
  1250. {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
  1251. {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
  1252. {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
  1253. {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
  1254. {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
  1255. {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
  1256. {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
  1257. {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
  1258. {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
  1259. {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
  1260. {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
  1261. {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
  1262. {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
  1263. {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
  1264. {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
  1265. {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
  1266. {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
  1267. {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
  1268. {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
  1269. {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
  1270. {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
  1271. {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1272. {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
  1273. {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
  1274. {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
  1275. {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
  1276. {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
  1277. {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
  1278. {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
  1279. {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
  1280. {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
  1281. {}
  1282. };
  1283. static const u8 sp80708_sensor_param1[][8] = {
  1284. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1285. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1286. {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
  1287. {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
  1288. {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
  1289. {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
  1290. {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
  1291. {}
  1292. };
  1293. static const u8 (*sensor_init[])[8] = {
  1294. [SENSOR_ADCM1700] = adcm1700_sensor_init,
  1295. [SENSOR_GC0307] = gc0307_sensor_init,
  1296. [SENSOR_HV7131R] = hv7131r_sensor_init,
  1297. [SENSOR_MI0360] = mi0360_sensor_init,
  1298. [SENSOR_MI0360B] = mi0360b_sensor_init,
  1299. [SENSOR_MO4000] = mo4000_sensor_init,
  1300. [SENSOR_MT9V111] = mt9v111_sensor_init,
  1301. [SENSOR_OM6802] = om6802_sensor_init,
  1302. [SENSOR_OV7630] = ov7630_sensor_init,
  1303. [SENSOR_OV7648] = ov7648_sensor_init,
  1304. [SENSOR_OV7660] = ov7660_sensor_init,
  1305. [SENSOR_PO1030] = po1030_sensor_init,
  1306. [SENSOR_PO2030N] = po2030n_sensor_init,
  1307. [SENSOR_SOI768] = soi768_sensor_init,
  1308. [SENSOR_SP80708] = sp80708_sensor_init,
  1309. };
  1310. /* read <len> bytes to gspca_dev->usb_buf */
  1311. static void reg_r(struct gspca_dev *gspca_dev,
  1312. u16 value, int len)
  1313. {
  1314. int ret;
  1315. if (gspca_dev->usb_err < 0)
  1316. return;
  1317. #ifdef GSPCA_DEBUG
  1318. if (len > USB_BUF_SZ) {
  1319. err("reg_r: buffer overflow");
  1320. return;
  1321. }
  1322. #endif
  1323. ret = usb_control_msg(gspca_dev->dev,
  1324. usb_rcvctrlpipe(gspca_dev->dev, 0),
  1325. 0,
  1326. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1327. value, 0,
  1328. gspca_dev->usb_buf, len,
  1329. 500);
  1330. PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
  1331. if (ret < 0) {
  1332. err("reg_r err %d", ret);
  1333. gspca_dev->usb_err = ret;
  1334. }
  1335. }
  1336. static void reg_w1(struct gspca_dev *gspca_dev,
  1337. u16 value,
  1338. u8 data)
  1339. {
  1340. int ret;
  1341. if (gspca_dev->usb_err < 0)
  1342. return;
  1343. PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
  1344. gspca_dev->usb_buf[0] = data;
  1345. ret = usb_control_msg(gspca_dev->dev,
  1346. usb_sndctrlpipe(gspca_dev->dev, 0),
  1347. 0x08,
  1348. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1349. value,
  1350. 0,
  1351. gspca_dev->usb_buf, 1,
  1352. 500);
  1353. if (ret < 0) {
  1354. err("reg_w1 err %d", ret);
  1355. gspca_dev->usb_err = ret;
  1356. }
  1357. }
  1358. static void reg_w(struct gspca_dev *gspca_dev,
  1359. u16 value,
  1360. const u8 *buffer,
  1361. int len)
  1362. {
  1363. int ret;
  1364. if (gspca_dev->usb_err < 0)
  1365. return;
  1366. PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
  1367. value, buffer[0], buffer[1]);
  1368. #ifdef GSPCA_DEBUG
  1369. if (len > USB_BUF_SZ) {
  1370. err("reg_w: buffer overflow");
  1371. return;
  1372. }
  1373. #endif
  1374. memcpy(gspca_dev->usb_buf, buffer, len);
  1375. ret = usb_control_msg(gspca_dev->dev,
  1376. usb_sndctrlpipe(gspca_dev->dev, 0),
  1377. 0x08,
  1378. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1379. value, 0,
  1380. gspca_dev->usb_buf, len,
  1381. 500);
  1382. if (ret < 0) {
  1383. err("reg_w err %d", ret);
  1384. gspca_dev->usb_err = ret;
  1385. }
  1386. }
  1387. /* I2C write 1 byte */
  1388. static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  1389. {
  1390. struct sd *sd = (struct sd *) gspca_dev;
  1391. int ret;
  1392. if (gspca_dev->usb_err < 0)
  1393. return;
  1394. PDEBUG(D_USBO, "i2c_w1 [%02x] = %02x", reg, val);
  1395. switch (sd->sensor) {
  1396. case SENSOR_ADCM1700:
  1397. case SENSOR_OM6802:
  1398. case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
  1399. gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
  1400. break;
  1401. default: /* i2c command = a1 (400 kHz) */
  1402. gspca_dev->usb_buf[0] = 0x81 | (2 << 4);
  1403. break;
  1404. }
  1405. gspca_dev->usb_buf[1] = sd->i2c_addr;
  1406. gspca_dev->usb_buf[2] = reg;
  1407. gspca_dev->usb_buf[3] = val;
  1408. gspca_dev->usb_buf[4] = 0;
  1409. gspca_dev->usb_buf[5] = 0;
  1410. gspca_dev->usb_buf[6] = 0;
  1411. gspca_dev->usb_buf[7] = 0x10;
  1412. ret = usb_control_msg(gspca_dev->dev,
  1413. usb_sndctrlpipe(gspca_dev->dev, 0),
  1414. 0x08,
  1415. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1416. 0x08, /* value = i2c */
  1417. 0,
  1418. gspca_dev->usb_buf, 8,
  1419. 500);
  1420. if (ret < 0) {
  1421. err("i2c_w1 err %d", ret);
  1422. gspca_dev->usb_err = ret;
  1423. }
  1424. }
  1425. /* I2C write 8 bytes */
  1426. static void i2c_w8(struct gspca_dev *gspca_dev,
  1427. const u8 *buffer)
  1428. {
  1429. int ret;
  1430. if (gspca_dev->usb_err < 0)
  1431. return;
  1432. PDEBUG(D_USBO, "i2c_w8 [%02x] = %02x ..",
  1433. buffer[2], buffer[3]);
  1434. memcpy(gspca_dev->usb_buf, buffer, 8);
  1435. ret = usb_control_msg(gspca_dev->dev,
  1436. usb_sndctrlpipe(gspca_dev->dev, 0),
  1437. 0x08,
  1438. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1439. 0x08, 0, /* value, index */
  1440. gspca_dev->usb_buf, 8,
  1441. 500);
  1442. msleep(2);
  1443. if (ret < 0) {
  1444. err("i2c_w8 err %d", ret);
  1445. gspca_dev->usb_err = ret;
  1446. }
  1447. }
  1448. /* sensor read 'len' (1..5) bytes in gspca_dev->usb_buf */
  1449. static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len)
  1450. {
  1451. struct sd *sd = (struct sd *) gspca_dev;
  1452. u8 mode[8];
  1453. switch (sd->sensor) {
  1454. case SENSOR_ADCM1700:
  1455. case SENSOR_OM6802:
  1456. case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
  1457. mode[0] = 0x80 | 0x10;
  1458. break;
  1459. default: /* i2c command = 91 (400 kHz) */
  1460. mode[0] = 0x81 | 0x10;
  1461. break;
  1462. }
  1463. mode[1] = sd->i2c_addr;
  1464. mode[2] = reg;
  1465. mode[3] = 0;
  1466. mode[4] = 0;
  1467. mode[5] = 0;
  1468. mode[6] = 0;
  1469. mode[7] = 0x10;
  1470. i2c_w8(gspca_dev, mode);
  1471. msleep(2);
  1472. mode[0] = (mode[0] & 0x81) | (len << 4) | 0x02;
  1473. mode[2] = 0;
  1474. i2c_w8(gspca_dev, mode);
  1475. msleep(2);
  1476. reg_r(gspca_dev, 0x0a, 5);
  1477. }
  1478. static void i2c_w_seq(struct gspca_dev *gspca_dev,
  1479. const u8 (*data)[8])
  1480. {
  1481. while ((*data)[0] != 0) {
  1482. if ((*data)[0] != DELAY)
  1483. i2c_w8(gspca_dev, *data);
  1484. else
  1485. msleep((*data)[1]);
  1486. data++;
  1487. }
  1488. }
  1489. /* check the ID of the hv7131 sensor */
  1490. /* this sequence is needed because it activates the sensor */
  1491. static void hv7131r_probe(struct gspca_dev *gspca_dev)
  1492. {
  1493. i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
  1494. msleep(10);
  1495. reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
  1496. msleep(10);
  1497. i2c_r(gspca_dev, 0, 5); /* read sensor id */
  1498. if (gspca_dev->usb_buf[0] == 0x02 /* chip ID (02 is R) */
  1499. && gspca_dev->usb_buf[1] == 0x09
  1500. && gspca_dev->usb_buf[2] == 0x01) {
  1501. PDEBUG(D_PROBE, "Sensor HV7131R found");
  1502. return;
  1503. }
  1504. warn("Erroneous HV7131R ID 0x%02x 0x%02x 0x%02x",
  1505. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
  1506. gspca_dev->usb_buf[2]);
  1507. }
  1508. static void mi0360_probe(struct gspca_dev *gspca_dev)
  1509. {
  1510. struct sd *sd = (struct sd *) gspca_dev;
  1511. int i, j;
  1512. u16 val = 0;
  1513. static const u8 probe_tb[][4][8] = {
  1514. { /* mi0360 */
  1515. {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  1516. {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1517. {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1518. {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
  1519. },
  1520. { /* mt9v111 */
  1521. {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
  1522. {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
  1523. {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1524. {}
  1525. },
  1526. };
  1527. for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
  1528. reg_w1(gspca_dev, 0x17, 0x62);
  1529. reg_w1(gspca_dev, 0x01, 0x08);
  1530. for (j = 0; j < 3; j++)
  1531. i2c_w8(gspca_dev, probe_tb[i][j]);
  1532. msleep(2);
  1533. reg_r(gspca_dev, 0x0a, 5);
  1534. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1535. if (probe_tb[i][3][0] != 0)
  1536. i2c_w8(gspca_dev, probe_tb[i][3]);
  1537. reg_w1(gspca_dev, 0x01, 0x29);
  1538. reg_w1(gspca_dev, 0x17, 0x42);
  1539. if (val != 0xffff)
  1540. break;
  1541. }
  1542. if (gspca_dev->usb_err < 0)
  1543. return;
  1544. switch (val) {
  1545. case 0x8221:
  1546. PDEBUG(D_PROBE, "Sensor mi0360b");
  1547. sd->sensor = SENSOR_MI0360B;
  1548. break;
  1549. case 0x823a:
  1550. PDEBUG(D_PROBE, "Sensor mt9v111");
  1551. sd->sensor = SENSOR_MT9V111;
  1552. break;
  1553. case 0x8243:
  1554. PDEBUG(D_PROBE, "Sensor mi0360");
  1555. break;
  1556. default:
  1557. PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
  1558. break;
  1559. }
  1560. }
  1561. static void ov7630_probe(struct gspca_dev *gspca_dev)
  1562. {
  1563. struct sd *sd = (struct sd *) gspca_dev;
  1564. u16 val;
  1565. /* check ov76xx */
  1566. reg_w1(gspca_dev, 0x17, 0x62);
  1567. reg_w1(gspca_dev, 0x01, 0x08);
  1568. sd->i2c_addr = 0x21;
  1569. i2c_r(gspca_dev, 0x0a, 2);
  1570. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1571. reg_w1(gspca_dev, 0x01, 0x29);
  1572. reg_w1(gspca_dev, 0x17, 0x42);
  1573. if (gspca_dev->usb_err < 0)
  1574. return;
  1575. if (val == 0x7628) { /* soi768 */
  1576. sd->sensor = SENSOR_SOI768;
  1577. /*fixme: only valid for 0c45:613e?*/
  1578. gspca_dev->cam.input_flags =
  1579. V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP;
  1580. PDEBUG(D_PROBE, "Sensor soi768");
  1581. return;
  1582. }
  1583. PDEBUG(D_PROBE, "Sensor ov%04x", val);
  1584. }
  1585. static void ov7648_probe(struct gspca_dev *gspca_dev)
  1586. {
  1587. struct sd *sd = (struct sd *) gspca_dev;
  1588. u16 val;
  1589. /* check ov76xx */
  1590. reg_w1(gspca_dev, 0x17, 0x62);
  1591. reg_w1(gspca_dev, 0x01, 0x08);
  1592. sd->i2c_addr = 0x21;
  1593. i2c_r(gspca_dev, 0x0a, 2);
  1594. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1595. reg_w1(gspca_dev, 0x01, 0x29);
  1596. reg_w1(gspca_dev, 0x17, 0x42);
  1597. if ((val & 0xff00) == 0x7600) { /* ov76xx */
  1598. PDEBUG(D_PROBE, "Sensor ov%04x", val);
  1599. return;
  1600. }
  1601. /* check po1030 */
  1602. reg_w1(gspca_dev, 0x17, 0x62);
  1603. reg_w1(gspca_dev, 0x01, 0x08);
  1604. sd->i2c_addr = 0x6e;
  1605. i2c_r(gspca_dev, 0x00, 2);
  1606. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1607. reg_w1(gspca_dev, 0x01, 0x29);
  1608. reg_w1(gspca_dev, 0x17, 0x42);
  1609. if (gspca_dev->usb_err < 0)
  1610. return;
  1611. if (val == 0x1030) { /* po1030 */
  1612. PDEBUG(D_PROBE, "Sensor po1030");
  1613. sd->sensor = SENSOR_PO1030;
  1614. return;
  1615. }
  1616. err("Unknown sensor %04x", val);
  1617. }
  1618. /* 0c45:6142 sensor may be po2030n, gc0305 or gc0307 */
  1619. static void po2030n_probe(struct gspca_dev *gspca_dev)
  1620. {
  1621. struct sd *sd = (struct sd *) gspca_dev;
  1622. u16 val;
  1623. /* check gc0307 */
  1624. reg_w1(gspca_dev, 0x17, 0x62);
  1625. reg_w1(gspca_dev, 0x01, 0x08);
  1626. reg_w1(gspca_dev, 0x02, 0x22);
  1627. sd->i2c_addr = 0x21;
  1628. i2c_r(gspca_dev, 0x00, 1);
  1629. val = gspca_dev->usb_buf[4];
  1630. reg_w1(gspca_dev, 0x01, 0x29); /* reset */
  1631. reg_w1(gspca_dev, 0x17, 0x42);
  1632. if (val == 0x99) { /* gc0307 (?) */
  1633. PDEBUG(D_PROBE, "Sensor gc0307");
  1634. sd->sensor = SENSOR_GC0307;
  1635. return;
  1636. }
  1637. /* check po2030n */
  1638. reg_w1(gspca_dev, 0x17, 0x62);
  1639. reg_w1(gspca_dev, 0x01, 0x0a);
  1640. sd->i2c_addr = 0x6e;
  1641. i2c_r(gspca_dev, 0x00, 2);
  1642. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1643. reg_w1(gspca_dev, 0x01, 0x29);
  1644. reg_w1(gspca_dev, 0x17, 0x42);
  1645. if (gspca_dev->usb_err < 0)
  1646. return;
  1647. if (val == 0x2030) {
  1648. PDEBUG(D_PROBE, "Sensor po2030n");
  1649. /* sd->sensor = SENSOR_PO2030N; */
  1650. } else {
  1651. err("Unknown sensor ID %04x", val);
  1652. }
  1653. }
  1654. /* this function is called at probe time */
  1655. static int sd_config(struct gspca_dev *gspca_dev,
  1656. const struct usb_device_id *id)
  1657. {
  1658. struct sd *sd = (struct sd *) gspca_dev;
  1659. struct cam *cam;
  1660. sd->bridge = id->driver_info >> 16;
  1661. sd->sensor = id->driver_info >> 8;
  1662. sd->flags = id->driver_info;
  1663. cam = &gspca_dev->cam;
  1664. if (sd->sensor == SENSOR_ADCM1700) {
  1665. cam->cam_mode = cif_mode;
  1666. cam->nmodes = ARRAY_SIZE(cif_mode);
  1667. } else {
  1668. cam->cam_mode = vga_mode;
  1669. cam->nmodes = ARRAY_SIZE(vga_mode);
  1670. }
  1671. cam->npkt = 24; /* 24 packets per ISOC message */
  1672. cam->ctrls = sd->ctrls;
  1673. sd->ag_cnt = -1;
  1674. sd->quality = QUALITY_DEF;
  1675. /* if USB 1.1, let some bandwidth for the audio device */
  1676. if (gspca_dev->audio && gspca_dev->dev->speed < USB_SPEED_HIGH)
  1677. gspca_dev->nbalt--;
  1678. INIT_WORK(&sd->work, qual_upd);
  1679. return 0;
  1680. }
  1681. /* this function is called at probe and resume time */
  1682. static int sd_init(struct gspca_dev *gspca_dev)
  1683. {
  1684. struct sd *sd = (struct sd *) gspca_dev;
  1685. const u8 *sn9c1xx;
  1686. u8 regGpio[] = { 0x29, 0x70 }; /* no audio */
  1687. u8 regF1;
  1688. /* setup a selector by bridge */
  1689. reg_w1(gspca_dev, 0xf1, 0x01);
  1690. reg_r(gspca_dev, 0x00, 1);
  1691. reg_w1(gspca_dev, 0xf1, 0x00);
  1692. reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
  1693. regF1 = gspca_dev->usb_buf[0];
  1694. if (gspca_dev->usb_err < 0)
  1695. return gspca_dev->usb_err;
  1696. PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
  1697. if (gspca_dev->audio)
  1698. regGpio[1] |= 0x04; /* with audio */
  1699. switch (sd->bridge) {
  1700. case BRIDGE_SN9C102P:
  1701. case BRIDGE_SN9C105:
  1702. if (regF1 != 0x11)
  1703. return -ENODEV;
  1704. break;
  1705. default:
  1706. /* case BRIDGE_SN9C110: */
  1707. /* case BRIDGE_SN9C120: */
  1708. if (regF1 != 0x12)
  1709. return -ENODEV;
  1710. }
  1711. switch (sd->sensor) {
  1712. case SENSOR_MI0360:
  1713. mi0360_probe(gspca_dev);
  1714. break;
  1715. case SENSOR_OV7630:
  1716. ov7630_probe(gspca_dev);
  1717. break;
  1718. case SENSOR_OV7648:
  1719. ov7648_probe(gspca_dev);
  1720. break;
  1721. case SENSOR_PO2030N:
  1722. po2030n_probe(gspca_dev);
  1723. break;
  1724. }
  1725. switch (sd->bridge) {
  1726. case BRIDGE_SN9C102P:
  1727. reg_w1(gspca_dev, 0x02, regGpio[1]);
  1728. break;
  1729. default:
  1730. reg_w(gspca_dev, 0x01, regGpio, 2);
  1731. break;
  1732. }
  1733. if (sd->sensor == SENSOR_OM6802)
  1734. sd->ctrls[SHARPNESS].def = 0x10;
  1735. /* Note we do not disable the sensor clock here (power saving mode),
  1736. as that also disables the button on the cam. */
  1737. reg_w1(gspca_dev, 0xf1, 0x00);
  1738. /* set the i2c address */
  1739. sn9c1xx = sn_tb[sd->sensor];
  1740. sd->i2c_addr = sn9c1xx[9];
  1741. gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
  1742. if (!(sd->flags & F_ILLUM))
  1743. gspca_dev->ctrl_dis |= (1 << ILLUM);
  1744. return gspca_dev->usb_err;
  1745. }
  1746. static u32 setexposure(struct gspca_dev *gspca_dev,
  1747. u32 expo)
  1748. {
  1749. struct sd *sd = (struct sd *) gspca_dev;
  1750. switch (sd->sensor) {
  1751. case SENSOR_GC0307: {
  1752. int a, b;
  1753. /* expo = 0..255 -> a = 19..43 */
  1754. a = 19 + expo * 25 / 256;
  1755. i2c_w1(gspca_dev, 0x68, a);
  1756. a -= 12;
  1757. b = a * a * 4; /* heuristic */
  1758. i2c_w1(gspca_dev, 0x03, b >> 8);
  1759. i2c_w1(gspca_dev, 0x04, b);
  1760. break;
  1761. }
  1762. case SENSOR_HV7131R: {
  1763. u8 Expodoit[] =
  1764. { 0xc1, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1765. Expodoit[3] = expo >> 16;
  1766. Expodoit[4] = expo >> 8;
  1767. Expodoit[5] = expo;
  1768. i2c_w8(gspca_dev, Expodoit);
  1769. break;
  1770. }
  1771. case SENSOR_MI0360:
  1772. case SENSOR_MI0360B: {
  1773. u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
  1774. { 0xb1, 0x5d, 0x09, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1775. static const u8 doit[] = /* update sensor */
  1776. { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
  1777. static const u8 sensorgo[] = /* sensor on */
  1778. { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
  1779. if (expo > 0x0635)
  1780. expo = 0x0635;
  1781. else if (expo < 0x0001)
  1782. expo = 0x0001;
  1783. expoMi[3] = expo >> 8;
  1784. expoMi[4] = expo;
  1785. i2c_w8(gspca_dev, expoMi);
  1786. i2c_w8(gspca_dev, doit);
  1787. i2c_w8(gspca_dev, sensorgo);
  1788. break;
  1789. }
  1790. case SENSOR_MO4000: {
  1791. u8 expoMof[] =
  1792. { 0xa1, 0x21, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1793. u8 expoMo10[] =
  1794. { 0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1795. static const u8 gainMo[] =
  1796. { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
  1797. if (expo > 0x1fff)
  1798. expo = 0x1fff;
  1799. else if (expo < 0x0001)
  1800. expo = 0x0001;
  1801. expoMof[3] = (expo & 0x03fc) >> 2;
  1802. i2c_w8(gspca_dev, expoMof);
  1803. expoMo10[3] = ((expo & 0x1c00) >> 10)
  1804. | ((expo & 0x0003) << 4);
  1805. i2c_w8(gspca_dev, expoMo10);
  1806. i2c_w8(gspca_dev, gainMo);
  1807. PDEBUG(D_FRAM, "set exposure %d",
  1808. ((expoMo10[3] & 0x07) << 10)
  1809. | (expoMof[3] << 2)
  1810. | ((expoMo10[3] & 0x30) >> 4));
  1811. break;
  1812. }
  1813. case SENSOR_MT9V111: {
  1814. u8 expo_c1[] =
  1815. { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1816. if (expo > 0x0390)
  1817. expo = 0x0390;
  1818. else if (expo < 0x0060)
  1819. expo = 0x0060;
  1820. expo_c1[3] = expo >> 8;
  1821. expo_c1[4] = expo;
  1822. i2c_w8(gspca_dev, expo_c1);
  1823. break;
  1824. }
  1825. case SENSOR_OM6802: {
  1826. u8 gainOm[] =
  1827. { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1828. /* preset AGC - works when AutoExpo = off */
  1829. if (expo > 0x03ff)
  1830. expo = 0x03ff;
  1831. if (expo < 0x0001)
  1832. expo = 0x0001;
  1833. gainOm[3] = expo >> 2;
  1834. i2c_w8(gspca_dev, gainOm);
  1835. reg_w1(gspca_dev, 0x96, expo >> 5);
  1836. PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
  1837. break;
  1838. }
  1839. }
  1840. return expo;
  1841. }
  1842. static void setbrightness(struct gspca_dev *gspca_dev)
  1843. {
  1844. struct sd *sd = (struct sd *) gspca_dev;
  1845. unsigned int expo;
  1846. int brightness;
  1847. u8 k2;
  1848. brightness = sd->ctrls[BRIGHTNESS].val;
  1849. k2 = (brightness - 0x80) >> 2;
  1850. switch (sd->sensor) {
  1851. case SENSOR_ADCM1700:
  1852. if (k2 > 0x1f)
  1853. k2 = 0; /* only positive Y offset */
  1854. break;
  1855. case SENSOR_HV7131R:
  1856. expo = brightness << 12;
  1857. if (expo > 0x002dc6c0)
  1858. expo = 0x002dc6c0;
  1859. else if (expo < 0x02a0)
  1860. expo = 0x02a0;
  1861. sd->exposure = setexposure(gspca_dev, expo);
  1862. break;
  1863. case SENSOR_MI0360:
  1864. case SENSOR_MO4000:
  1865. expo = brightness << 4;
  1866. sd->exposure = setexposure(gspca_dev, expo);
  1867. break;
  1868. case SENSOR_MI0360B:
  1869. expo = brightness << 2;
  1870. sd->exposure = setexposure(gspca_dev, expo);
  1871. break;
  1872. case SENSOR_GC0307:
  1873. expo = brightness;
  1874. sd->exposure = setexposure(gspca_dev, expo);
  1875. return; /* don't set the Y offset */
  1876. case SENSOR_MT9V111:
  1877. expo = brightness << 2;
  1878. sd->exposure = setexposure(gspca_dev, expo);
  1879. return; /* don't set the Y offset */
  1880. case SENSOR_OM6802:
  1881. expo = brightness << 2;
  1882. sd->exposure = setexposure(gspca_dev, expo);
  1883. k2 = brightness >> 3;
  1884. break;
  1885. }
  1886. reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
  1887. }
  1888. static void setcontrast(struct gspca_dev *gspca_dev)
  1889. {
  1890. struct sd *sd = (struct sd *) gspca_dev;
  1891. u8 k2;
  1892. u8 contrast[6];
  1893. k2 = sd->ctrls[CONTRAST].val * 0x30 / (CONTRAST_MAX + 1)
  1894. + 0x10; /* 10..40 */
  1895. contrast[0] = (k2 + 1) / 2; /* red */
  1896. contrast[1] = 0;
  1897. contrast[2] = k2; /* green */
  1898. contrast[3] = 0;
  1899. contrast[4] = (k2 + 1) / 5; /* blue */
  1900. contrast[5] = 0;
  1901. reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
  1902. }
  1903. static void setcolors(struct gspca_dev *gspca_dev)
  1904. {
  1905. struct sd *sd = (struct sd *) gspca_dev;
  1906. int i, v, colors;
  1907. const s16 *uv;
  1908. u8 reg8a[12]; /* U & V gains */
  1909. static const s16 uv_com[6] = { /* same as reg84 in signed decimal */
  1910. -24, -38, 64, /* UR UG UB */
  1911. 62, -51, -9 /* VR VG VB */
  1912. };
  1913. static const s16 uv_mi0360b[6] = {
  1914. -20, -38, 64, /* UR UG UB */
  1915. 60, -51, -9 /* VR VG VB */
  1916. };
  1917. colors = sd->ctrls[COLORS].val;
  1918. if (sd->sensor == SENSOR_MI0360B)
  1919. uv = uv_mi0360b;
  1920. else
  1921. uv = uv_com;
  1922. for (i = 0; i < 6; i++) {
  1923. v = uv[i] * colors / COLORS_DEF;
  1924. reg8a[i * 2] = v;
  1925. reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
  1926. }
  1927. reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
  1928. }
  1929. static void setredblue(struct gspca_dev *gspca_dev)
  1930. {
  1931. struct sd *sd = (struct sd *) gspca_dev;
  1932. reg_w1(gspca_dev, 0x05, sd->ctrls[RED].val);
  1933. /* reg_w1(gspca_dev, 0x07, 32); */
  1934. reg_w1(gspca_dev, 0x06, sd->ctrls[BLUE].val);
  1935. }
  1936. static void setgamma(struct gspca_dev *gspca_dev)
  1937. {
  1938. struct sd *sd = (struct sd *) gspca_dev;
  1939. int i, val;
  1940. u8 gamma[17];
  1941. const u8 *gamma_base;
  1942. static const u8 delta[17] = {
  1943. 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
  1944. 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
  1945. };
  1946. switch (sd->sensor) {
  1947. case SENSOR_ADCM1700:
  1948. gamma_base = gamma_spec_0;
  1949. break;
  1950. case SENSOR_HV7131R:
  1951. case SENSOR_MI0360B:
  1952. case SENSOR_MT9V111:
  1953. gamma_base = gamma_spec_1;
  1954. break;
  1955. case SENSOR_GC0307:
  1956. gamma_base = gamma_spec_2;
  1957. break;
  1958. case SENSOR_SP80708:
  1959. gamma_base = gamma_spec_3;
  1960. break;
  1961. default:
  1962. gamma_base = gamma_def;
  1963. break;
  1964. }
  1965. val = sd->ctrls[GAMMA].val;
  1966. for (i = 0; i < sizeof gamma; i++)
  1967. gamma[i] = gamma_base[i]
  1968. + delta[i] * (val - GAMMA_DEF) / 32;
  1969. reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
  1970. }
  1971. static void setautogain(struct gspca_dev *gspca_dev)
  1972. {
  1973. struct sd *sd = (struct sd *) gspca_dev;
  1974. if (gspca_dev->ctrl_dis & (1 << AUTOGAIN))
  1975. return;
  1976. switch (sd->sensor) {
  1977. case SENSOR_OV7630:
  1978. case SENSOR_OV7648: {
  1979. u8 comb;
  1980. if (sd->sensor == SENSOR_OV7630)
  1981. comb = 0xc0;
  1982. else
  1983. comb = 0xa0;
  1984. if (sd->ctrls[AUTOGAIN].val)
  1985. comb |= 0x03;
  1986. i2c_w1(&sd->gspca_dev, 0x13, comb);
  1987. return;
  1988. }
  1989. }
  1990. if (sd->ctrls[AUTOGAIN].val)
  1991. sd->ag_cnt = AG_CNT_START;
  1992. else
  1993. sd->ag_cnt = -1;
  1994. }
  1995. static void sethvflip(struct gspca_dev *gspca_dev)
  1996. {
  1997. struct sd *sd = (struct sd *) gspca_dev;
  1998. u8 comn;
  1999. switch (sd->sensor) {
  2000. case SENSOR_HV7131R:
  2001. comn = 0x18; /* clkdiv = 1, ablcen = 1 */
  2002. if (sd->ctrls[VFLIP].val)
  2003. comn |= 0x01;
  2004. i2c_w1(gspca_dev, 0x01, comn); /* sctra */
  2005. break;
  2006. case SENSOR_OV7630:
  2007. comn = 0x02;
  2008. if (!sd->ctrls[VFLIP].val)
  2009. comn |= 0x80;
  2010. i2c_w1(gspca_dev, 0x75, comn);
  2011. break;
  2012. case SENSOR_OV7648:
  2013. comn = 0x06;
  2014. if (sd->ctrls[VFLIP].val)
  2015. comn |= 0x80;
  2016. i2c_w1(gspca_dev, 0x75, comn);
  2017. break;
  2018. case SENSOR_PO2030N:
  2019. /* Reg. 0x1E: Timing Generator Control Register 2 (Tgcontrol2)
  2020. * (reset value: 0x0A)
  2021. * bit7: HM: Horizontal Mirror: 0: disable, 1: enable
  2022. * bit6: VM: Vertical Mirror: 0: disable, 1: enable
  2023. * bit5: ST: Shutter Selection: 0: electrical, 1: mechanical
  2024. * bit4: FT: Single Frame Transfer: 0: disable, 1: enable
  2025. * bit3-0: X
  2026. */
  2027. comn = 0x0a;
  2028. if (sd->ctrls[HFLIP].val)
  2029. comn |= 0x80;
  2030. if (sd->ctrls[VFLIP].val)
  2031. comn |= 0x40;
  2032. i2c_w1(&sd->gspca_dev, 0x1e, comn);
  2033. break;
  2034. }
  2035. }
  2036. static void setsharpness(struct gspca_dev *gspca_dev)
  2037. {
  2038. struct sd *sd = (struct sd *) gspca_dev;
  2039. reg_w1(gspca_dev, 0x99, sd->ctrls[SHARPNESS].val);
  2040. }
  2041. static void setillum(struct gspca_dev *gspca_dev)
  2042. {
  2043. struct sd *sd = (struct sd *) gspca_dev;
  2044. if (gspca_dev->ctrl_dis & (1 << ILLUM))
  2045. return;
  2046. switch (sd->sensor) {
  2047. case SENSOR_ADCM1700:
  2048. reg_w1(gspca_dev, 0x02, /* gpio */
  2049. sd->ctrls[ILLUM].val ? 0x64 : 0x60);
  2050. break;
  2051. case SENSOR_MT9V111:
  2052. reg_w1(gspca_dev, 0x02,
  2053. sd->ctrls[ILLUM].val ? 0x77 : 0x74);
  2054. /* should have been: */
  2055. /* 0x55 : 0x54); * 370i */
  2056. /* 0x66 : 0x64); * Clip */
  2057. break;
  2058. }
  2059. }
  2060. static void setfreq(struct gspca_dev *gspca_dev)
  2061. {
  2062. struct sd *sd = (struct sd *) gspca_dev;
  2063. if (gspca_dev->ctrl_dis & (1 << FREQ))
  2064. return;
  2065. if (sd->sensor == SENSOR_OV7660) {
  2066. u8 com8;
  2067. com8 = 0xdf; /* auto gain/wb/expo */
  2068. switch (sd->ctrls[FREQ].val) {
  2069. case 0: /* Banding filter disabled */
  2070. i2c_w1(gspca_dev, 0x13, com8 | 0x20);
  2071. break;
  2072. case 1: /* 50 hz */
  2073. i2c_w1(gspca_dev, 0x13, com8);
  2074. i2c_w1(gspca_dev, 0x3b, 0x0a);
  2075. break;
  2076. case 2: /* 60 hz */
  2077. i2c_w1(gspca_dev, 0x13, com8);
  2078. i2c_w1(gspca_dev, 0x3b, 0x02);
  2079. break;
  2080. }
  2081. } else {
  2082. u8 reg2a = 0, reg2b = 0, reg2d = 0;
  2083. /* Get reg2a / reg2d base values */
  2084. switch (sd->sensor) {
  2085. case SENSOR_OV7630:
  2086. reg2a = 0x08;
  2087. reg2d = 0x01;
  2088. break;
  2089. case SENSOR_OV7648:
  2090. reg2a = 0x11;
  2091. reg2d = 0x81;
  2092. break;
  2093. }
  2094. switch (sd->ctrls[FREQ].val) {
  2095. case 0: /* Banding filter disabled */
  2096. break;
  2097. case 1: /* 50 hz (filter on and framerate adj) */
  2098. reg2a |= 0x80;
  2099. reg2b = 0xac;
  2100. reg2d |= 0x04;
  2101. break;
  2102. case 2: /* 60 hz (filter on, no framerate adj) */
  2103. reg2a |= 0x80;
  2104. reg2d |= 0x04;
  2105. break;
  2106. }
  2107. i2c_w1(gspca_dev, 0x2a, reg2a);
  2108. i2c_w1(gspca_dev, 0x2b, reg2b);
  2109. i2c_w1(gspca_dev, 0x2d, reg2d);
  2110. }
  2111. }
  2112. static void setjpegqual(struct gspca_dev *gspca_dev)
  2113. {
  2114. struct sd *sd = (struct sd *) gspca_dev;
  2115. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  2116. #if USB_BUF_SZ < 64
  2117. #error "No room enough in usb_buf for quantization table"
  2118. #endif
  2119. memcpy(gspca_dev->usb_buf, &sd->jpeg_hdr[JPEG_QT0_OFFSET], 64);
  2120. usb_control_msg(gspca_dev->dev,
  2121. usb_sndctrlpipe(gspca_dev->dev, 0),
  2122. 0x08,
  2123. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  2124. 0x0100, 0,
  2125. gspca_dev->usb_buf, 64,
  2126. 500);
  2127. memcpy(gspca_dev->usb_buf, &sd->jpeg_hdr[JPEG_QT1_OFFSET], 64);
  2128. usb_control_msg(gspca_dev->dev,
  2129. usb_sndctrlpipe(gspca_dev->dev, 0),
  2130. 0x08,
  2131. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  2132. 0x0140, 0,
  2133. gspca_dev->usb_buf, 64,
  2134. 500);
  2135. sd->reg18 ^= 0x40;
  2136. reg_w1(gspca_dev, 0x18, sd->reg18);
  2137. }
  2138. /* JPEG quality update */
  2139. /* This function is executed from a work queue. */
  2140. static void qual_upd(struct work_struct *work)
  2141. {
  2142. struct sd *sd = container_of(work, struct sd, work);
  2143. struct gspca_dev *gspca_dev = &sd->gspca_dev;
  2144. mutex_lock(&gspca_dev->usb_lock);
  2145. PDEBUG(D_STREAM, "qual_upd %d%%", sd->quality);
  2146. setjpegqual(gspca_dev);
  2147. mutex_unlock(&gspca_dev->usb_lock);
  2148. }
  2149. /* -- start the camera -- */
  2150. static int sd_start(struct gspca_dev *gspca_dev)
  2151. {
  2152. struct sd *sd = (struct sd *) gspca_dev;
  2153. int i;
  2154. u8 reg01, reg17;
  2155. u8 reg0102[2];
  2156. const u8 *sn9c1xx;
  2157. const u8 (*init)[8];
  2158. const u8 *reg9a;
  2159. int mode;
  2160. static const u8 reg9a_def[] =
  2161. {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
  2162. static const u8 reg9a_spec[] =
  2163. {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
  2164. static const u8 regd4[] = {0x60, 0x00, 0x00};
  2165. static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
  2166. static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
  2167. static const u8 CA_adcm1700[] =
  2168. { 0x14, 0xec, 0x0a, 0xf6 };
  2169. static const u8 CA_po2030n[] =
  2170. { 0x1e, 0xe2, 0x14, 0xec };
  2171. static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
  2172. static const u8 CE_gc0307[] =
  2173. { 0x32, 0xce, 0x2d, 0xd3 };
  2174. static const u8 CE_ov76xx[] =
  2175. { 0x32, 0xdd, 0x32, 0xdd };
  2176. static const u8 CE_po2030n[] =
  2177. { 0x14, 0xe7, 0x1e, 0xdd };
  2178. /* create the JPEG header */
  2179. jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
  2180. 0x21); /* JPEG 422 */
  2181. /* initialize the bridge */
  2182. sn9c1xx = sn_tb[sd->sensor];
  2183. /* sensor clock already enabled in sd_init */
  2184. /* reg_w1(gspca_dev, 0xf1, 0x00); */
  2185. reg01 = sn9c1xx[1];
  2186. if (sd->flags & F_PDN_INV)
  2187. reg01 ^= S_PDN_INV; /* power down inverted */
  2188. reg_w1(gspca_dev, 0x01, reg01);
  2189. /* configure gpio */
  2190. reg0102[0] = reg01;
  2191. reg0102[1] = sn9c1xx[2];
  2192. if (gspca_dev->audio)
  2193. reg0102[1] |= 0x04; /* keep the audio connection */
  2194. reg_w(gspca_dev, 0x01, reg0102, 2);
  2195. reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
  2196. reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
  2197. switch (sd->sensor) {
  2198. case SENSOR_GC0307:
  2199. case SENSOR_OV7660:
  2200. case SENSOR_PO1030:
  2201. case SENSOR_PO2030N:
  2202. case SENSOR_SOI768:
  2203. case SENSOR_SP80708:
  2204. reg9a = reg9a_spec;
  2205. break;
  2206. default:
  2207. reg9a = reg9a_def;
  2208. break;
  2209. }
  2210. reg_w(gspca_dev, 0x9a, reg9a, 6);
  2211. reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
  2212. reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
  2213. reg17 = sn9c1xx[0x17];
  2214. switch (sd->sensor) {
  2215. case SENSOR_GC0307:
  2216. msleep(50); /*fixme: is it useful? */
  2217. break;
  2218. case SENSOR_OM6802:
  2219. msleep(10);
  2220. reg_w1(gspca_dev, 0x02, 0x73);
  2221. reg17 |= SEN_CLK_EN;
  2222. reg_w1(gspca_dev, 0x17, reg17);
  2223. reg_w1(gspca_dev, 0x01, 0x22);
  2224. msleep(100);
  2225. reg01 = SCL_SEL_OD | S_PDN_INV;
  2226. reg17 &= MCK_SIZE_MASK;
  2227. reg17 |= 0x04; /* clock / 4 */
  2228. break;
  2229. }
  2230. reg01 |= SYS_SEL_48M;
  2231. reg_w1(gspca_dev, 0x01, reg01);
  2232. reg17 |= SEN_CLK_EN;
  2233. reg_w1(gspca_dev, 0x17, reg17);
  2234. reg01 &= ~S_PWR_DN; /* sensor power on */
  2235. reg_w1(gspca_dev, 0x01, reg01);
  2236. reg01 &= ~SYS_SEL_48M;
  2237. reg_w1(gspca_dev, 0x01, reg01);
  2238. switch (sd->sensor) {
  2239. case SENSOR_HV7131R:
  2240. hv7131r_probe(gspca_dev); /*fixme: is it useful? */
  2241. break;
  2242. case SENSOR_OM6802:
  2243. msleep(10);
  2244. reg_w1(gspca_dev, 0x01, reg01);
  2245. i2c_w8(gspca_dev, om6802_init0[0]);
  2246. i2c_w8(gspca_dev, om6802_init0[1]);
  2247. msleep(15);
  2248. reg_w1(gspca_dev, 0x02, 0x71);
  2249. msleep(150);
  2250. break;
  2251. case SENSOR_SP80708:
  2252. msleep(100);
  2253. reg_w1(gspca_dev, 0x02, 0x62);
  2254. break;
  2255. }
  2256. /* initialize the sensor */
  2257. i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
  2258. reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
  2259. reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
  2260. reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
  2261. reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
  2262. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  2263. if (sd->sensor == SENSOR_ADCM1700) {
  2264. reg_w1(gspca_dev, 0xd2, 0x3a); /* AE_H_SIZE = 116 */
  2265. reg_w1(gspca_dev, 0xd3, 0x30); /* AE_V_SIZE = 96 */
  2266. } else {
  2267. reg_w1(gspca_dev, 0xd2, 0x6a); /* AE_H_SIZE = 212 */
  2268. reg_w1(gspca_dev, 0xd3, 0x50); /* AE_V_SIZE = 160 */
  2269. }
  2270. reg_w1(gspca_dev, 0xc6, 0x00);
  2271. reg_w1(gspca_dev, 0xc7, 0x00);
  2272. if (sd->sensor == SENSOR_ADCM1700) {
  2273. reg_w1(gspca_dev, 0xc8, 0x2c); /* AW_H_STOP = 352 */
  2274. reg_w1(gspca_dev, 0xc9, 0x24); /* AW_V_STOP = 288 */
  2275. } else {
  2276. reg_w1(gspca_dev, 0xc8, 0x50); /* AW_H_STOP = 640 */
  2277. reg_w1(gspca_dev, 0xc9, 0x3c); /* AW_V_STOP = 480 */
  2278. }
  2279. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  2280. switch (sd->sensor) {
  2281. case SENSOR_OM6802:
  2282. /* case SENSOR_OV7648: * fixme: sometimes */
  2283. break;
  2284. default:
  2285. reg17 |= DEF_EN;
  2286. break;
  2287. }
  2288. reg_w1(gspca_dev, 0x17, reg17);
  2289. reg_w1(gspca_dev, 0x05, 0x00); /* red */
  2290. reg_w1(gspca_dev, 0x07, 0x00); /* green */
  2291. reg_w1(gspca_dev, 0x06, 0x00); /* blue */
  2292. reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
  2293. setgamma(gspca_dev);
  2294. /*fixme: 8 times with all zeroes and 1 or 2 times with normal values */
  2295. for (i = 0; i < 8; i++)
  2296. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  2297. switch (sd->sensor) {
  2298. case SENSOR_ADCM1700:
  2299. case SENSOR_OV7660:
  2300. case SENSOR_SP80708:
  2301. reg_w1(gspca_dev, 0x9a, 0x05);
  2302. break;
  2303. case SENSOR_GC0307:
  2304. case SENSOR_MT9V111:
  2305. case SENSOR_MI0360B:
  2306. reg_w1(gspca_dev, 0x9a, 0x07);
  2307. break;
  2308. case SENSOR_OV7630:
  2309. case SENSOR_OV7648:
  2310. reg_w1(gspca_dev, 0x9a, 0x0a);
  2311. break;
  2312. case SENSOR_PO2030N:
  2313. case SENSOR_SOI768:
  2314. reg_w1(gspca_dev, 0x9a, 0x06);
  2315. break;
  2316. default:
  2317. reg_w1(gspca_dev, 0x9a, 0x08);
  2318. break;
  2319. }
  2320. setsharpness(gspca_dev);
  2321. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  2322. reg_w1(gspca_dev, 0x05, 0x20); /* red */
  2323. reg_w1(gspca_dev, 0x07, 0x20); /* green */
  2324. reg_w1(gspca_dev, 0x06, 0x20); /* blue */
  2325. init = NULL;
  2326. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  2327. reg01 |= SYS_SEL_48M | V_TX_EN;
  2328. reg17 &= ~MCK_SIZE_MASK;
  2329. reg17 |= 0x02; /* clock / 2 */
  2330. switch (sd->sensor) {
  2331. case SENSOR_ADCM1700:
  2332. init = adcm1700_sensor_param1;
  2333. break;
  2334. case SENSOR_GC0307:
  2335. init = gc0307_sensor_param1;
  2336. break;
  2337. case SENSOR_HV7131R:
  2338. case SENSOR_MI0360:
  2339. if (mode)
  2340. reg01 |= SYS_SEL_48M; /* 320x240: clk 48Mhz */
  2341. else
  2342. reg01 &= ~SYS_SEL_48M; /* 640x480: clk 24Mhz */
  2343. reg17 &= ~MCK_SIZE_MASK;
  2344. reg17 |= 0x01; /* clock / 1 */
  2345. break;
  2346. case SENSOR_MI0360B:
  2347. init = mi0360b_sensor_param1;
  2348. break;
  2349. case SENSOR_MO4000:
  2350. if (mode) { /* if 320x240 */
  2351. reg01 &= ~SYS_SEL_48M; /* clk 24Mz */
  2352. reg17 &= ~MCK_SIZE_MASK;
  2353. reg17 |= 0x01; /* clock / 1 */
  2354. }
  2355. break;
  2356. case SENSOR_MT9V111:
  2357. init = mt9v111_sensor_param1;
  2358. break;
  2359. case SENSOR_OM6802:
  2360. init = om6802_sensor_param1;
  2361. if (!mode) { /* if 640x480 */
  2362. reg17 &= ~MCK_SIZE_MASK;
  2363. reg17 |= 0x04; /* clock / 4 */
  2364. }
  2365. break;
  2366. case SENSOR_OV7630:
  2367. init = ov7630_sensor_param1;
  2368. break;
  2369. case SENSOR_OV7648:
  2370. init = ov7648_sensor_param1;
  2371. reg17 &= ~MCK_SIZE_MASK;
  2372. reg17 |= 0x01; /* clock / 1 */
  2373. break;
  2374. case SENSOR_OV7660:
  2375. init = ov7660_sensor_param1;
  2376. break;
  2377. case SENSOR_PO1030:
  2378. init = po1030_sensor_param1;
  2379. break;
  2380. case SENSOR_PO2030N:
  2381. init = po2030n_sensor_param1;
  2382. break;
  2383. case SENSOR_SOI768:
  2384. init = soi768_sensor_param1;
  2385. break;
  2386. case SENSOR_SP80708:
  2387. init = sp80708_sensor_param1;
  2388. break;
  2389. }
  2390. /* more sensor initialization - param1 */
  2391. if (init != NULL) {
  2392. i2c_w_seq(gspca_dev, init);
  2393. /* init = NULL; */
  2394. }
  2395. reg_w(gspca_dev, 0xc0, C0, 6);
  2396. switch (sd->sensor) {
  2397. case SENSOR_ADCM1700:
  2398. case SENSOR_GC0307:
  2399. case SENSOR_SOI768:
  2400. reg_w(gspca_dev, 0xca, CA_adcm1700, 4);
  2401. break;
  2402. case SENSOR_PO2030N:
  2403. reg_w(gspca_dev, 0xca, CA_po2030n, 4);
  2404. break;
  2405. default:
  2406. reg_w(gspca_dev, 0xca, CA, 4);
  2407. break;
  2408. }
  2409. switch (sd->sensor) {
  2410. case SENSOR_ADCM1700:
  2411. case SENSOR_OV7630:
  2412. case SENSOR_OV7648:
  2413. case SENSOR_OV7660:
  2414. case SENSOR_SOI768:
  2415. reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
  2416. break;
  2417. case SENSOR_GC0307:
  2418. reg_w(gspca_dev, 0xce, CE_gc0307, 4);
  2419. break;
  2420. case SENSOR_PO2030N:
  2421. reg_w(gspca_dev, 0xce, CE_po2030n, 4);
  2422. break;
  2423. default:
  2424. reg_w(gspca_dev, 0xce, CE, 4);
  2425. /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
  2426. break;
  2427. }
  2428. /* here change size mode 0 -> VGA; 1 -> CIF */
  2429. sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
  2430. reg_w1(gspca_dev, 0x18, sd->reg18);
  2431. setjpegqual(gspca_dev);
  2432. reg_w1(gspca_dev, 0x17, reg17);
  2433. reg_w1(gspca_dev, 0x01, reg01);
  2434. sd->reg01 = reg01;
  2435. sd->reg17 = reg17;
  2436. sethvflip(gspca_dev);
  2437. setbrightness(gspca_dev);
  2438. setcontrast(gspca_dev);
  2439. setcolors(gspca_dev);
  2440. setautogain(gspca_dev);
  2441. setfreq(gspca_dev);
  2442. sd->pktsz = sd->npkt = 0;
  2443. sd->nchg = sd->short_mark = 0;
  2444. sd->work_thread = create_singlethread_workqueue(MODULE_NAME);
  2445. return gspca_dev->usb_err;
  2446. }
  2447. static void sd_stopN(struct gspca_dev *gspca_dev)
  2448. {
  2449. struct sd *sd = (struct sd *) gspca_dev;
  2450. static const u8 stophv7131[] =
  2451. { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
  2452. static const u8 stopmi0360[] =
  2453. { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
  2454. static const u8 stopov7648[] =
  2455. { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
  2456. static const u8 stopsoi768[] =
  2457. { 0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10 };
  2458. u8 reg01;
  2459. u8 reg17;
  2460. reg01 = sd->reg01;
  2461. reg17 = sd->reg17 & ~SEN_CLK_EN;
  2462. switch (sd->sensor) {
  2463. case SENSOR_ADCM1700:
  2464. case SENSOR_GC0307:
  2465. case SENSOR_PO2030N:
  2466. case SENSOR_SP80708:
  2467. reg01 |= LED;
  2468. reg_w1(gspca_dev, 0x01, reg01);
  2469. reg01 &= ~(LED | V_TX_EN);
  2470. reg_w1(gspca_dev, 0x01, reg01);
  2471. /* reg_w1(gspca_dev, 0x02, 0x??); * LED off ? */
  2472. break;
  2473. case SENSOR_HV7131R:
  2474. reg01 &= ~V_TX_EN;
  2475. reg_w1(gspca_dev, 0x01, reg01);
  2476. i2c_w8(gspca_dev, stophv7131);
  2477. break;
  2478. case SENSOR_MI0360:
  2479. case SENSOR_MI0360B:
  2480. reg01 &= ~V_TX_EN;
  2481. reg_w1(gspca_dev, 0x01, reg01);
  2482. /* reg_w1(gspca_dev, 0x02, 0x40); * LED off ? */
  2483. i2c_w8(gspca_dev, stopmi0360);
  2484. break;
  2485. case SENSOR_MT9V111:
  2486. case SENSOR_OM6802:
  2487. case SENSOR_PO1030:
  2488. reg01 &= ~V_TX_EN;
  2489. reg_w1(gspca_dev, 0x01, reg01);
  2490. break;
  2491. case SENSOR_OV7630:
  2492. case SENSOR_OV7648:
  2493. reg01 &= ~V_TX_EN;
  2494. reg_w1(gspca_dev, 0x01, reg01);
  2495. i2c_w8(gspca_dev, stopov7648);
  2496. break;
  2497. case SENSOR_OV7660:
  2498. reg01 &= ~V_TX_EN;
  2499. reg_w1(gspca_dev, 0x01, reg01);
  2500. break;
  2501. case SENSOR_SOI768:
  2502. i2c_w8(gspca_dev, stopsoi768);
  2503. break;
  2504. }
  2505. reg01 |= SCL_SEL_OD;
  2506. reg_w1(gspca_dev, 0x01, reg01);
  2507. reg01 |= S_PWR_DN; /* sensor power down */
  2508. reg_w1(gspca_dev, 0x01, reg01);
  2509. reg_w1(gspca_dev, 0x17, reg17);
  2510. reg01 &= ~SYS_SEL_48M; /* clock 24MHz */
  2511. reg_w1(gspca_dev, 0x01, reg01);
  2512. reg01 |= LED;
  2513. reg_w1(gspca_dev, 0x01, reg01);
  2514. /* Don't disable sensor clock as that disables the button on the cam */
  2515. /* reg_w1(gspca_dev, 0xf1, 0x01); */
  2516. }
  2517. /* called on streamoff with alt==0 and on disconnect */
  2518. /* the usb_lock is held at entry - restore on exit */
  2519. static void sd_stop0(struct gspca_dev *gspca_dev)
  2520. {
  2521. struct sd *sd = (struct sd *) gspca_dev;
  2522. if (sd->work_thread != NULL) {
  2523. mutex_unlock(&gspca_dev->usb_lock);
  2524. destroy_workqueue(sd->work_thread);
  2525. mutex_lock(&gspca_dev->usb_lock);
  2526. sd->work_thread = NULL;
  2527. }
  2528. }
  2529. static void do_autogain(struct gspca_dev *gspca_dev)
  2530. {
  2531. struct sd *sd = (struct sd *) gspca_dev;
  2532. int delta;
  2533. int expotimes;
  2534. u8 luma_mean = 130;
  2535. u8 luma_delta = 20;
  2536. /* Thanks S., without your advice, autobright should not work :) */
  2537. if (sd->ag_cnt < 0)
  2538. return;
  2539. if (--sd->ag_cnt >= 0)
  2540. return;
  2541. sd->ag_cnt = AG_CNT_START;
  2542. delta = atomic_read(&sd->avg_lum);
  2543. PDEBUG(D_FRAM, "mean lum %d", delta);
  2544. if (delta < luma_mean - luma_delta ||
  2545. delta > luma_mean + luma_delta) {
  2546. switch (sd->sensor) {
  2547. case SENSOR_GC0307:
  2548. expotimes = sd->exposure;
  2549. expotimes += (luma_mean - delta) >> 6;
  2550. if (expotimes < 0)
  2551. expotimes = 0;
  2552. sd->exposure = setexposure(gspca_dev,
  2553. (unsigned int) expotimes);
  2554. break;
  2555. case SENSOR_HV7131R:
  2556. expotimes = sd->exposure >> 8;
  2557. expotimes += (luma_mean - delta) >> 4;
  2558. if (expotimes < 0)
  2559. expotimes = 0;
  2560. sd->exposure = setexposure(gspca_dev,
  2561. (unsigned int) (expotimes << 8));
  2562. break;
  2563. case SENSOR_OM6802:
  2564. case SENSOR_MT9V111:
  2565. expotimes = sd->exposure;
  2566. expotimes += (luma_mean - delta) >> 2;
  2567. if (expotimes < 0)
  2568. expotimes = 0;
  2569. sd->exposure = setexposure(gspca_dev,
  2570. (unsigned int) expotimes);
  2571. setredblue(gspca_dev);
  2572. break;
  2573. default:
  2574. /* case SENSOR_MO4000: */
  2575. /* case SENSOR_MI0360: */
  2576. /* case SENSOR_MI0360B: */
  2577. expotimes = sd->exposure;
  2578. expotimes += (luma_mean - delta) >> 6;
  2579. if (expotimes < 0)
  2580. expotimes = 0;
  2581. sd->exposure = setexposure(gspca_dev,
  2582. (unsigned int) expotimes);
  2583. setredblue(gspca_dev);
  2584. break;
  2585. }
  2586. }
  2587. }
  2588. /* set the average luminosity from an isoc marker */
  2589. static void set_lum(struct sd *sd,
  2590. u8 *data)
  2591. {
  2592. int avg_lum;
  2593. /* w0 w1 w2
  2594. * w3 w4 w5
  2595. * w6 w7 w8
  2596. */
  2597. avg_lum = (data[27] << 8) + data[28] /* w3 */
  2598. + (data[31] << 8) + data[32] /* w5 */
  2599. + (data[23] << 8) + data[24] /* w1 */
  2600. + (data[35] << 8) + data[36] /* w7 */
  2601. + (data[29] << 10) + (data[30] << 2); /* w4 * 4 */
  2602. avg_lum >>= 10;
  2603. atomic_set(&sd->avg_lum, avg_lum);
  2604. }
  2605. /* scan the URB packets */
  2606. /* This function is run at interrupt level. */
  2607. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  2608. u8 *data, /* isoc packet */
  2609. int len) /* iso packet length */
  2610. {
  2611. struct sd *sd = (struct sd *) gspca_dev;
  2612. int i, new_qual;
  2613. /*
  2614. * A frame ends on the marker
  2615. * ff ff 00 c4 c4 96 ..
  2616. * which is 62 bytes long and is followed by various information
  2617. * including statuses and luminosity.
  2618. *
  2619. * A marker may be splitted on two packets.
  2620. *
  2621. * The 6th byte of a marker contains the bits:
  2622. * 0x08: USB full
  2623. * 0xc0: frame sequence
  2624. * When the bit 'USB full' is set, the frame must be discarded;
  2625. * this is also the case when the 2 bytes before the marker are
  2626. * not the JPEG end of frame ('ff d9').
  2627. */
  2628. /*fixme: assumption about the following code:
  2629. * - there can be only one marker in a packet
  2630. */
  2631. /* skip the remaining bytes of a short marker */
  2632. i = sd->short_mark;
  2633. if (i != 0) {
  2634. sd->short_mark = 0;
  2635. if (i < 0 /* if 'ff' at end of previous packet */
  2636. && data[0] == 0xff
  2637. && data[1] == 0x00)
  2638. goto marker_found;
  2639. if (data[0] == 0xff && data[1] == 0xff) {
  2640. i = 0;
  2641. goto marker_found;
  2642. }
  2643. len -= i;
  2644. if (len <= 0)
  2645. return;
  2646. data += i;
  2647. }
  2648. /* count the packets and their size */
  2649. sd->npkt++;
  2650. sd->pktsz += len;
  2651. /* search backwards if there is a marker in the packet */
  2652. for (i = len - 1; --i >= 0; ) {
  2653. if (data[i] != 0xff) {
  2654. i--;
  2655. continue;
  2656. }
  2657. if (data[i + 1] == 0xff) {
  2658. /* (there may be 'ff ff' inside a marker) */
  2659. if (i + 2 >= len || data[i + 2] == 0x00)
  2660. goto marker_found;
  2661. }
  2662. }
  2663. /* no marker found */
  2664. /* add the JPEG header if first fragment */
  2665. if (data[len - 1] == 0xff)
  2666. sd->short_mark = -1;
  2667. if (gspca_dev->last_packet_type == LAST_PACKET)
  2668. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2669. sd->jpeg_hdr, JPEG_HDR_SZ);
  2670. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2671. return;
  2672. /* marker found */
  2673. /* if some error, discard the frame and decrease the quality */
  2674. marker_found:
  2675. new_qual = 0;
  2676. if (i > 2) {
  2677. if (data[i - 2] != 0xff || data[i - 1] != 0xd9) {
  2678. gspca_dev->last_packet_type = DISCARD_PACKET;
  2679. new_qual = -3;
  2680. }
  2681. } else if (i + 6 < len) {
  2682. if (data[i + 6] & 0x08) {
  2683. gspca_dev->last_packet_type = DISCARD_PACKET;
  2684. new_qual = -5;
  2685. }
  2686. }
  2687. gspca_frame_add(gspca_dev, LAST_PACKET, data, i);
  2688. /* compute the filling rate and a new JPEG quality */
  2689. if (new_qual == 0) {
  2690. int r;
  2691. r = (sd->pktsz * 100) /
  2692. (sd->npkt *
  2693. gspca_dev->urb[0]->iso_frame_desc[0].length);
  2694. if (r >= 85)
  2695. new_qual = -3;
  2696. else if (r < 75)
  2697. new_qual = 2;
  2698. }
  2699. if (new_qual != 0) {
  2700. sd->nchg += new_qual;
  2701. if (sd->nchg < -6 || sd->nchg >= 12) {
  2702. sd->nchg = 0;
  2703. new_qual += sd->quality;
  2704. if (new_qual < QUALITY_MIN)
  2705. new_qual = QUALITY_MIN;
  2706. else if (new_qual > QUALITY_MAX)
  2707. new_qual = QUALITY_MAX;
  2708. if (new_qual != sd->quality) {
  2709. sd->quality = new_qual;
  2710. queue_work(sd->work_thread, &sd->work);
  2711. }
  2712. }
  2713. } else {
  2714. sd->nchg = 0;
  2715. }
  2716. sd->pktsz = sd->npkt = 0;
  2717. /* if the marker is smaller than 62 bytes,
  2718. * memorize the number of bytes to skip in the next packet */
  2719. if (i + 62 > len) { /* no more usable data */
  2720. sd->short_mark = i + 62 - len;
  2721. return;
  2722. }
  2723. if (sd->ag_cnt >= 0)
  2724. set_lum(sd, data + i);
  2725. /* if more data, start a new frame */
  2726. i += 62;
  2727. if (i < len) {
  2728. data += i;
  2729. len -= i;
  2730. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2731. sd->jpeg_hdr, JPEG_HDR_SZ);
  2732. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2733. }
  2734. }
  2735. static int sd_get_jcomp(struct gspca_dev *gspca_dev,
  2736. struct v4l2_jpegcompression *jcomp)
  2737. {
  2738. struct sd *sd = (struct sd *) gspca_dev;
  2739. memset(jcomp, 0, sizeof *jcomp);
  2740. jcomp->quality = sd->quality;
  2741. jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
  2742. | V4L2_JPEG_MARKER_DQT;
  2743. return 0;
  2744. }
  2745. static int sd_querymenu(struct gspca_dev *gspca_dev,
  2746. struct v4l2_querymenu *menu)
  2747. {
  2748. switch (menu->id) {
  2749. case V4L2_CID_POWER_LINE_FREQUENCY:
  2750. switch (menu->index) {
  2751. case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
  2752. strcpy((char *) menu->name, "NoFliker");
  2753. return 0;
  2754. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  2755. strcpy((char *) menu->name, "50 Hz");
  2756. return 0;
  2757. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  2758. strcpy((char *) menu->name, "60 Hz");
  2759. return 0;
  2760. }
  2761. break;
  2762. }
  2763. return -EINVAL;
  2764. }
  2765. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  2766. static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
  2767. u8 *data, /* interrupt packet data */
  2768. int len) /* interrupt packet length */
  2769. {
  2770. int ret = -EINVAL;
  2771. if (len == 1 && data[0] == 1) {
  2772. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
  2773. input_sync(gspca_dev->input_dev);
  2774. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
  2775. input_sync(gspca_dev->input_dev);
  2776. ret = 0;
  2777. }
  2778. return ret;
  2779. }
  2780. #endif
  2781. /* sub-driver description */
  2782. static const struct sd_desc sd_desc = {
  2783. .name = MODULE_NAME,
  2784. .ctrls = sd_ctrls,
  2785. .nctrls = NCTRLS,
  2786. .config = sd_config,
  2787. .init = sd_init,
  2788. .start = sd_start,
  2789. .stopN = sd_stopN,
  2790. .stop0 = sd_stop0,
  2791. .pkt_scan = sd_pkt_scan,
  2792. .dq_callback = do_autogain,
  2793. .get_jcomp = sd_get_jcomp,
  2794. .querymenu = sd_querymenu,
  2795. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  2796. .int_pkt_scan = sd_int_pkt_scan,
  2797. #endif
  2798. };
  2799. /* -- module initialisation -- */
  2800. #define BS(bridge, sensor) \
  2801. .driver_info = (BRIDGE_ ## bridge << 16) \
  2802. | (SENSOR_ ## sensor << 8)
  2803. #define BSF(bridge, sensor, flags) \
  2804. .driver_info = (BRIDGE_ ## bridge << 16) \
  2805. | (SENSOR_ ## sensor << 8) \
  2806. | (flags)
  2807. static const struct usb_device_id device_table[] = {
  2808. {USB_DEVICE(0x0458, 0x7025), BS(SN9C120, MI0360)},
  2809. {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)},
  2810. {USB_DEVICE(0x045e, 0x00f5), BSF(SN9C105, OV7660, F_PDN_INV)},
  2811. {USB_DEVICE(0x045e, 0x00f7), BSF(SN9C105, OV7660, F_PDN_INV)},
  2812. {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)},
  2813. {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)},
  2814. {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)},
  2815. {USB_DEVICE(0x06f8, 0x3004), BS(SN9C105, OV7660)},
  2816. {USB_DEVICE(0x06f8, 0x3008), BS(SN9C105, OV7660)},
  2817. /* {USB_DEVICE(0x0c45, 0x603a), BS(SN9C102P, OV7648)}, */
  2818. {USB_DEVICE(0x0c45, 0x6040), BS(SN9C102P, HV7131R)},
  2819. /* {USB_DEVICE(0x0c45, 0x607a), BS(SN9C102P, OV7648)}, */
  2820. /* {USB_DEVICE(0x0c45, 0x607b), BS(SN9C102P, OV7660)}, */
  2821. {USB_DEVICE(0x0c45, 0x607c), BS(SN9C102P, HV7131R)},
  2822. /* {USB_DEVICE(0x0c45, 0x607e), BS(SN9C102P, OV7630)}, */
  2823. {USB_DEVICE(0x0c45, 0x60c0), BSF(SN9C105, MI0360, F_ILLUM)},
  2824. /* or MT9V111 */
  2825. /* {USB_DEVICE(0x0c45, 0x60c2), BS(SN9C105, P1030xC)}, */
  2826. /* {USB_DEVICE(0x0c45, 0x60c8), BS(SN9C105, OM6802)}, */
  2827. /* {USB_DEVICE(0x0c45, 0x60cc), BS(SN9C105, HV7131GP)}, */
  2828. {USB_DEVICE(0x0c45, 0x60ce), BS(SN9C105, SP80708)},
  2829. {USB_DEVICE(0x0c45, 0x60ec), BS(SN9C105, MO4000)},
  2830. /* {USB_DEVICE(0x0c45, 0x60ef), BS(SN9C105, ICM105C)}, */
  2831. /* {USB_DEVICE(0x0c45, 0x60fa), BS(SN9C105, OV7648)}, */
  2832. /* {USB_DEVICE(0x0c45, 0x60f2), BS(SN9C105, OV7660)}, */
  2833. {USB_DEVICE(0x0c45, 0x60fb), BS(SN9C105, OV7660)},
  2834. {USB_DEVICE(0x0c45, 0x60fc), BS(SN9C105, HV7131R)},
  2835. {USB_DEVICE(0x0c45, 0x60fe), BS(SN9C105, OV7630)},
  2836. {USB_DEVICE(0x0c45, 0x6100), BS(SN9C120, MI0360)}, /*sn9c128*/
  2837. {USB_DEVICE(0x0c45, 0x6102), BS(SN9C120, PO2030N)}, /* /GC0305*/
  2838. /* {USB_DEVICE(0x0c45, 0x6108), BS(SN9C120, OM6802)}, */
  2839. {USB_DEVICE(0x0c45, 0x610a), BS(SN9C120, OV7648)}, /*sn9c128*/
  2840. {USB_DEVICE(0x0c45, 0x610b), BS(SN9C120, OV7660)}, /*sn9c128*/
  2841. {USB_DEVICE(0x0c45, 0x610c), BS(SN9C120, HV7131R)}, /*sn9c128*/
  2842. {USB_DEVICE(0x0c45, 0x610e), BS(SN9C120, OV7630)}, /*sn9c128*/
  2843. /* {USB_DEVICE(0x0c45, 0x610f), BS(SN9C120, S5K53BEB)}, */
  2844. /* {USB_DEVICE(0x0c45, 0x6122), BS(SN9C110, ICM105C)}, */
  2845. /* {USB_DEVICE(0x0c45, 0x6123), BS(SN9C110, SanyoCCD)}, */
  2846. {USB_DEVICE(0x0c45, 0x6128), BS(SN9C120, OM6802)}, /*sn9c325?*/
  2847. /*bw600.inf:*/
  2848. {USB_DEVICE(0x0c45, 0x612a), BS(SN9C120, OV7648)}, /*sn9c325?*/
  2849. {USB_DEVICE(0x0c45, 0x612b), BS(SN9C110, ADCM1700)},
  2850. {USB_DEVICE(0x0c45, 0x612c), BS(SN9C110, MO4000)},
  2851. {USB_DEVICE(0x0c45, 0x612e), BS(SN9C110, OV7630)},
  2852. /* {USB_DEVICE(0x0c45, 0x612f), BS(SN9C110, ICM105C)}, */
  2853. {USB_DEVICE(0x0c45, 0x6130), BS(SN9C120, MI0360)},
  2854. /* or MT9V111 / MI0360B */
  2855. /* {USB_DEVICE(0x0c45, 0x6132), BS(SN9C120, OV7670)}, */
  2856. {USB_DEVICE(0x0c45, 0x6138), BS(SN9C120, MO4000)},
  2857. {USB_DEVICE(0x0c45, 0x613a), BS(SN9C120, OV7648)},
  2858. {USB_DEVICE(0x0c45, 0x613b), BS(SN9C120, OV7660)},
  2859. {USB_DEVICE(0x0c45, 0x613c), BS(SN9C120, HV7131R)},
  2860. {USB_DEVICE(0x0c45, 0x613e), BS(SN9C120, OV7630)},
  2861. {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, /*sn9c120b*/
  2862. /* or GC0305 / GC0307 */
  2863. {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/
  2864. {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/
  2865. {USB_DEVICE(0x0c45, 0x614a), BSF(SN9C120, ADCM1700, F_ILLUM)},
  2866. /* {USB_DEVICE(0x0c45, 0x614c), BS(SN9C120, GC0306)}, */ /*sn9c120b*/
  2867. {}
  2868. };
  2869. MODULE_DEVICE_TABLE(usb, device_table);
  2870. /* -- device connect -- */
  2871. static int sd_probe(struct usb_interface *intf,
  2872. const struct usb_device_id *id)
  2873. {
  2874. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  2875. THIS_MODULE);
  2876. }
  2877. static struct usb_driver sd_driver = {
  2878. .name = MODULE_NAME,
  2879. .id_table = device_table,
  2880. .probe = sd_probe,
  2881. .disconnect = gspca_disconnect,
  2882. #ifdef CONFIG_PM
  2883. .suspend = gspca_suspend,
  2884. .resume = gspca_resume,
  2885. #endif
  2886. };
  2887. /* -- module insert / remove -- */
  2888. static int __init sd_mod_init(void)
  2889. {
  2890. return usb_register(&sd_driver);
  2891. }
  2892. static void __exit sd_mod_exit(void)
  2893. {
  2894. usb_deregister(&sd_driver);
  2895. }
  2896. module_init(sd_mod_init);
  2897. module_exit(sd_mod_exit);