ov534_9.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606
  1. /*
  2. * ov534-ov9xxx gspca driver
  3. *
  4. * Copyright (C) 2009-2011 Jean-Francois Moine http://moinejf.free.fr
  5. * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
  6. * Copyright (C) 2008 Jim Paris <jim@jtan.com>
  7. *
  8. * Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
  9. * USB protocol reverse engineered by Jim Paris <jim@jtan.com>
  10. * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  27. #define MODULE_NAME "ov534_9"
  28. #include "gspca.h"
  29. #define OV534_REG_ADDRESS 0xf1 /* sensor address */
  30. #define OV534_REG_SUBADDR 0xf2
  31. #define OV534_REG_WRITE 0xf3
  32. #define OV534_REG_READ 0xf4
  33. #define OV534_REG_OPERATION 0xf5
  34. #define OV534_REG_STATUS 0xf6
  35. #define OV534_OP_WRITE_3 0x37
  36. #define OV534_OP_WRITE_2 0x33
  37. #define OV534_OP_READ_2 0xf9
  38. #define CTRL_TIMEOUT 500
  39. MODULE_AUTHOR("Jean-Francois Moine <moinejf@free.fr>");
  40. MODULE_DESCRIPTION("GSPCA/OV534_9 USB Camera Driver");
  41. MODULE_LICENSE("GPL");
  42. /* controls */
  43. enum e_ctrl {
  44. BRIGHTNESS,
  45. CONTRAST,
  46. AUTOGAIN,
  47. EXPOSURE,
  48. SHARPNESS,
  49. SATUR,
  50. LIGHTFREQ,
  51. NCTRLS /* number of controls */
  52. };
  53. /* specific webcam descriptor */
  54. struct sd {
  55. struct gspca_dev gspca_dev; /* !! must be the first item */
  56. struct gspca_ctrl ctrls[NCTRLS];
  57. __u32 last_pts;
  58. u8 last_fid;
  59. u8 sensor;
  60. };
  61. enum sensors {
  62. SENSOR_OV965x, /* ov9657 */
  63. SENSOR_OV971x, /* ov9712 */
  64. SENSOR_OV562x, /* ov5621 */
  65. NSENSORS
  66. };
  67. /* V4L2 controls supported by the driver */
  68. static void setbrightness(struct gspca_dev *gspca_dev);
  69. static void setcontrast(struct gspca_dev *gspca_dev);
  70. static void setautogain(struct gspca_dev *gspca_dev);
  71. static void setexposure(struct gspca_dev *gspca_dev);
  72. static void setsharpness(struct gspca_dev *gspca_dev);
  73. static void setsatur(struct gspca_dev *gspca_dev);
  74. static void setlightfreq(struct gspca_dev *gspca_dev);
  75. static const struct ctrl sd_ctrls[NCTRLS] = {
  76. [BRIGHTNESS] = {
  77. {
  78. .id = V4L2_CID_BRIGHTNESS,
  79. .type = V4L2_CTRL_TYPE_INTEGER,
  80. .name = "Brightness",
  81. .minimum = 0,
  82. .maximum = 15,
  83. .step = 1,
  84. .default_value = 7
  85. },
  86. .set_control = setbrightness
  87. },
  88. [CONTRAST] = {
  89. {
  90. .id = V4L2_CID_CONTRAST,
  91. .type = V4L2_CTRL_TYPE_INTEGER,
  92. .name = "Contrast",
  93. .minimum = 0,
  94. .maximum = 15,
  95. .step = 1,
  96. .default_value = 3
  97. },
  98. .set_control = setcontrast
  99. },
  100. [AUTOGAIN] = {
  101. {
  102. .id = V4L2_CID_AUTOGAIN,
  103. .type = V4L2_CTRL_TYPE_BOOLEAN,
  104. .name = "Autogain",
  105. .minimum = 0,
  106. .maximum = 1,
  107. .step = 1,
  108. #define AUTOGAIN_DEF 1
  109. .default_value = AUTOGAIN_DEF,
  110. },
  111. .set_control = setautogain
  112. },
  113. [EXPOSURE] = {
  114. {
  115. .id = V4L2_CID_EXPOSURE,
  116. .type = V4L2_CTRL_TYPE_INTEGER,
  117. .name = "Exposure",
  118. .minimum = 0,
  119. .maximum = 3,
  120. .step = 1,
  121. .default_value = 0
  122. },
  123. .set_control = setexposure
  124. },
  125. [SHARPNESS] = {
  126. {
  127. .id = V4L2_CID_SHARPNESS,
  128. .type = V4L2_CTRL_TYPE_INTEGER,
  129. .name = "Sharpness",
  130. .minimum = -1, /* -1 = auto */
  131. .maximum = 4,
  132. .step = 1,
  133. .default_value = -1
  134. },
  135. .set_control = setsharpness
  136. },
  137. [SATUR] = {
  138. {
  139. .id = V4L2_CID_SATURATION,
  140. .type = V4L2_CTRL_TYPE_INTEGER,
  141. .name = "Saturation",
  142. .minimum = 0,
  143. .maximum = 4,
  144. .step = 1,
  145. .default_value = 2
  146. },
  147. .set_control = setsatur
  148. },
  149. [LIGHTFREQ] = {
  150. {
  151. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  152. .type = V4L2_CTRL_TYPE_MENU,
  153. .name = "Light frequency filter",
  154. .minimum = 0,
  155. .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
  156. .step = 1,
  157. .default_value = 0
  158. },
  159. .set_control = setlightfreq
  160. },
  161. };
  162. static const struct v4l2_pix_format ov965x_mode[] = {
  163. #define QVGA_MODE 0
  164. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  165. .bytesperline = 320,
  166. .sizeimage = 320 * 240 * 3 / 8 + 590,
  167. .colorspace = V4L2_COLORSPACE_JPEG},
  168. #define VGA_MODE 1
  169. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  170. .bytesperline = 640,
  171. .sizeimage = 640 * 480 * 3 / 8 + 590,
  172. .colorspace = V4L2_COLORSPACE_JPEG},
  173. #define SVGA_MODE 2
  174. {800, 600, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  175. .bytesperline = 800,
  176. .sizeimage = 800 * 600 * 3 / 8 + 590,
  177. .colorspace = V4L2_COLORSPACE_JPEG},
  178. #define XGA_MODE 3
  179. {1024, 768, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  180. .bytesperline = 1024,
  181. .sizeimage = 1024 * 768 * 3 / 8 + 590,
  182. .colorspace = V4L2_COLORSPACE_JPEG},
  183. #define SXGA_MODE 4
  184. {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  185. .bytesperline = 1280,
  186. .sizeimage = 1280 * 1024 * 3 / 8 + 590,
  187. .colorspace = V4L2_COLORSPACE_JPEG},
  188. };
  189. static const struct v4l2_pix_format ov971x_mode[] = {
  190. {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  191. .bytesperline = 640,
  192. .sizeimage = 640 * 480,
  193. .colorspace = V4L2_COLORSPACE_SRGB
  194. }
  195. };
  196. static const struct v4l2_pix_format ov562x_mode[] = {
  197. {2592, 1680, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  198. .bytesperline = 2592,
  199. .sizeimage = 2592 * 1680,
  200. .colorspace = V4L2_COLORSPACE_SRGB
  201. }
  202. };
  203. static const u8 bridge_init[][2] = {
  204. {0x88, 0xf8},
  205. {0x89, 0xff},
  206. {0x76, 0x03},
  207. {0x92, 0x03},
  208. {0x95, 0x10},
  209. {0xe2, 0x00},
  210. {0xe7, 0x3e},
  211. {0x8d, 0x1c},
  212. {0x8e, 0x00},
  213. {0x8f, 0x00},
  214. {0x1f, 0x00},
  215. {0xc3, 0xf9},
  216. {0x89, 0xff},
  217. {0x88, 0xf8},
  218. {0x76, 0x03},
  219. {0x92, 0x01},
  220. {0x93, 0x18},
  221. {0x1c, 0x0a},
  222. {0x1d, 0x48},
  223. {0xc0, 0x50},
  224. {0xc1, 0x3c},
  225. {0x34, 0x05},
  226. {0xc2, 0x0c},
  227. {0xc3, 0xf9},
  228. {0x34, 0x05},
  229. {0xe7, 0x2e},
  230. {0x31, 0xf9},
  231. {0x35, 0x02},
  232. {0xd9, 0x10},
  233. {0x25, 0x42},
  234. {0x94, 0x11},
  235. };
  236. static const u8 ov965x_init[][2] = {
  237. {0x12, 0x80}, /* com7 - SSCB reset */
  238. {0x00, 0x00}, /* gain */
  239. {0x01, 0x80}, /* blue */
  240. {0x02, 0x80}, /* red */
  241. {0x03, 0x1b}, /* vref */
  242. {0x04, 0x03}, /* com1 - exposure low bits */
  243. {0x0b, 0x57}, /* ver */
  244. {0x0e, 0x61}, /* com5 */
  245. {0x0f, 0x42}, /* com6 */
  246. {0x11, 0x00}, /* clkrc */
  247. {0x12, 0x02}, /* com7 - 15fps VGA YUYV */
  248. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  249. {0x14, 0x28}, /* com9 */
  250. {0x16, 0x24}, /* reg16 */
  251. {0x17, 0x1d}, /* hstart*/
  252. {0x18, 0xbd}, /* hstop */
  253. {0x19, 0x01}, /* vstrt */
  254. {0x1a, 0x81}, /* vstop*/
  255. {0x1e, 0x04}, /* mvfp */
  256. {0x24, 0x3c}, /* aew */
  257. {0x25, 0x36}, /* aeb */
  258. {0x26, 0x71}, /* vpt */
  259. {0x27, 0x08}, /* bbias */
  260. {0x28, 0x08}, /* gbbias */
  261. {0x29, 0x15}, /* gr com */
  262. {0x2a, 0x00}, /* exhch */
  263. {0x2b, 0x00}, /* exhcl */
  264. {0x2c, 0x08}, /* rbias */
  265. {0x32, 0xff}, /* href */
  266. {0x33, 0x00}, /* chlf */
  267. {0x34, 0x3f}, /* aref1 */
  268. {0x35, 0x00}, /* aref2 */
  269. {0x36, 0xf8}, /* aref3 */
  270. {0x38, 0x72}, /* adc2 */
  271. {0x39, 0x57}, /* aref4 */
  272. {0x3a, 0x80}, /* tslb - yuyv */
  273. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  274. {0x3d, 0x99}, /* com13 */
  275. {0x3f, 0xc1}, /* edge */
  276. {0x40, 0xc0}, /* com15 */
  277. {0x41, 0x40}, /* com16 */
  278. {0x42, 0xc0}, /* com17 */
  279. {0x43, 0x0a}, /* rsvd */
  280. {0x44, 0xf0},
  281. {0x45, 0x46},
  282. {0x46, 0x62},
  283. {0x47, 0x2a},
  284. {0x48, 0x3c},
  285. {0x4a, 0xfc},
  286. {0x4b, 0xfc},
  287. {0x4c, 0x7f},
  288. {0x4d, 0x7f},
  289. {0x4e, 0x7f},
  290. {0x4f, 0x98}, /* matrix */
  291. {0x50, 0x98},
  292. {0x51, 0x00},
  293. {0x52, 0x28},
  294. {0x53, 0x70},
  295. {0x54, 0x98},
  296. {0x58, 0x1a}, /* matrix coef sign */
  297. {0x59, 0x85}, /* AWB control */
  298. {0x5a, 0xa9},
  299. {0x5b, 0x64},
  300. {0x5c, 0x84},
  301. {0x5d, 0x53},
  302. {0x5e, 0x0e},
  303. {0x5f, 0xf0}, /* AWB blue limit */
  304. {0x60, 0xf0}, /* AWB red limit */
  305. {0x61, 0xf0}, /* AWB green limit */
  306. {0x62, 0x00}, /* lcc1 */
  307. {0x63, 0x00}, /* lcc2 */
  308. {0x64, 0x02}, /* lcc3 */
  309. {0x65, 0x16}, /* lcc4 */
  310. {0x66, 0x01}, /* lcc5 */
  311. {0x69, 0x02}, /* hv */
  312. {0x6b, 0x5a}, /* dbvl */
  313. {0x6c, 0x04},
  314. {0x6d, 0x55},
  315. {0x6e, 0x00},
  316. {0x6f, 0x9d},
  317. {0x70, 0x21}, /* dnsth */
  318. {0x71, 0x78},
  319. {0x72, 0x00}, /* poidx */
  320. {0x73, 0x01}, /* pckdv */
  321. {0x74, 0x3a}, /* xindx */
  322. {0x75, 0x35}, /* yindx */
  323. {0x76, 0x01},
  324. {0x77, 0x02},
  325. {0x7a, 0x12}, /* gamma curve */
  326. {0x7b, 0x08},
  327. {0x7c, 0x16},
  328. {0x7d, 0x30},
  329. {0x7e, 0x5e},
  330. {0x7f, 0x72},
  331. {0x80, 0x82},
  332. {0x81, 0x8e},
  333. {0x82, 0x9a},
  334. {0x83, 0xa4},
  335. {0x84, 0xac},
  336. {0x85, 0xb8},
  337. {0x86, 0xc3},
  338. {0x87, 0xd6},
  339. {0x88, 0xe6},
  340. {0x89, 0xf2},
  341. {0x8a, 0x03},
  342. {0x8c, 0x89}, /* com19 */
  343. {0x14, 0x28}, /* com9 */
  344. {0x90, 0x7d},
  345. {0x91, 0x7b},
  346. {0x9d, 0x03}, /* lcc6 */
  347. {0x9e, 0x04}, /* lcc7 */
  348. {0x9f, 0x7a},
  349. {0xa0, 0x79},
  350. {0xa1, 0x40}, /* aechm */
  351. {0xa4, 0x50}, /* com21 */
  352. {0xa5, 0x68}, /* com26 */
  353. {0xa6, 0x4a}, /* AWB green */
  354. {0xa8, 0xc1}, /* refa8 */
  355. {0xa9, 0xef}, /* refa9 */
  356. {0xaa, 0x92},
  357. {0xab, 0x04},
  358. {0xac, 0x80}, /* black level control */
  359. {0xad, 0x80},
  360. {0xae, 0x80},
  361. {0xaf, 0x80},
  362. {0xb2, 0xf2},
  363. {0xb3, 0x20},
  364. {0xb4, 0x20}, /* ctrlb4 */
  365. {0xb5, 0x00},
  366. {0xb6, 0xaf},
  367. {0xbb, 0xae},
  368. {0xbc, 0x7f}, /* ADC channel offsets */
  369. {0xdb, 0x7f},
  370. {0xbe, 0x7f},
  371. {0xbf, 0x7f},
  372. {0xc0, 0xe2},
  373. {0xc1, 0xc0},
  374. {0xc2, 0x01},
  375. {0xc3, 0x4e},
  376. {0xc6, 0x85},
  377. {0xc7, 0x80}, /* com24 */
  378. {0xc9, 0xe0},
  379. {0xca, 0xe8},
  380. {0xcb, 0xf0},
  381. {0xcc, 0xd8},
  382. {0xcd, 0xf1},
  383. {0x4f, 0x98}, /* matrix */
  384. {0x50, 0x98},
  385. {0x51, 0x00},
  386. {0x52, 0x28},
  387. {0x53, 0x70},
  388. {0x54, 0x98},
  389. {0x58, 0x1a},
  390. {0xff, 0x41}, /* read 41, write ff 00 */
  391. {0x41, 0x40}, /* com16 */
  392. {0xc5, 0x03}, /* 60 Hz banding filter */
  393. {0x6a, 0x02}, /* 50 Hz banding filter */
  394. {0x12, 0x62}, /* com7 - 30fps VGA YUV */
  395. {0x36, 0xfa}, /* aref3 */
  396. {0x69, 0x0a}, /* hv */
  397. {0x8c, 0x89}, /* com22 */
  398. {0x14, 0x28}, /* com9 */
  399. {0x3e, 0x0c},
  400. {0x41, 0x40}, /* com16 */
  401. {0x72, 0x00},
  402. {0x73, 0x00},
  403. {0x74, 0x3a},
  404. {0x75, 0x35},
  405. {0x76, 0x01},
  406. {0xc7, 0x80},
  407. {0x03, 0x12}, /* vref */
  408. {0x17, 0x16}, /* hstart */
  409. {0x18, 0x02}, /* hstop */
  410. {0x19, 0x01}, /* vstrt */
  411. {0x1a, 0x3d}, /* vstop */
  412. {0x32, 0xff}, /* href */
  413. {0xc0, 0xaa},
  414. };
  415. static const u8 bridge_init_2[][2] = {
  416. {0x94, 0xaa},
  417. {0xf1, 0x60},
  418. {0xe5, 0x04},
  419. {0xc0, 0x50},
  420. {0xc1, 0x3c},
  421. {0x8c, 0x00},
  422. {0x8d, 0x1c},
  423. {0x34, 0x05},
  424. {0xc2, 0x0c},
  425. {0xc3, 0xf9},
  426. {0xda, 0x01},
  427. {0x50, 0x00},
  428. {0x51, 0xa0},
  429. {0x52, 0x3c},
  430. {0x53, 0x00},
  431. {0x54, 0x00},
  432. {0x55, 0x00},
  433. {0x57, 0x00},
  434. {0x5c, 0x00},
  435. {0x5a, 0xa0},
  436. {0x5b, 0x78},
  437. {0x35, 0x02},
  438. {0xd9, 0x10},
  439. {0x94, 0x11},
  440. };
  441. static const u8 ov965x_init_2[][2] = {
  442. {0x3b, 0xc4},
  443. {0x1e, 0x04}, /* mvfp */
  444. {0x13, 0xe0}, /* com8 */
  445. {0x00, 0x00}, /* gain */
  446. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  447. {0x11, 0x03}, /* clkrc */
  448. {0x6b, 0x5a}, /* dblv */
  449. {0x6a, 0x05},
  450. {0xc5, 0x07},
  451. {0xa2, 0x4b},
  452. {0xa3, 0x3e},
  453. {0x2d, 0x00},
  454. {0xff, 0x42}, /* read 42, write ff 00 */
  455. {0x42, 0xc0}, /* com17 */
  456. {0x2d, 0x00},
  457. {0xff, 0x42}, /* read 42, write ff 00 */
  458. {0x42, 0xc1}, /* com17 */
  459. /* sharpness */
  460. {0x3f, 0x01},
  461. {0xff, 0x42}, /* read 42, write ff 00 */
  462. {0x42, 0xc1}, /* com17 */
  463. /* saturation */
  464. {0x4f, 0x98}, /* matrix */
  465. {0x50, 0x98},
  466. {0x51, 0x00},
  467. {0x52, 0x28},
  468. {0x53, 0x70},
  469. {0x54, 0x98},
  470. {0x58, 0x1a},
  471. {0xff, 0x41}, /* read 41, write ff 00 */
  472. {0x41, 0x40}, /* com16 */
  473. /* contrast */
  474. {0x56, 0x40},
  475. /* brightness */
  476. {0x55, 0x8f},
  477. /* expo */
  478. {0x10, 0x25}, /* aech - exposure high bits */
  479. {0xff, 0x13}, /* read 13, write ff 00 */
  480. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  481. };
  482. static const u8 ov971x_init[][2] = {
  483. {0x12, 0x80},
  484. {0x09, 0x10},
  485. {0x1e, 0x07},
  486. {0x5f, 0x18},
  487. {0x69, 0x04},
  488. {0x65, 0x2a},
  489. {0x68, 0x0a},
  490. {0x39, 0x28},
  491. {0x4d, 0x90},
  492. {0xc1, 0x80},
  493. {0x0c, 0x30},
  494. {0x6d, 0x02},
  495. {0x96, 0xf1},
  496. {0xbc, 0x68},
  497. {0x12, 0x00},
  498. {0x3b, 0x00},
  499. {0x97, 0x80},
  500. {0x17, 0x25},
  501. {0x18, 0xa2},
  502. {0x19, 0x01},
  503. {0x1a, 0xca},
  504. {0x03, 0x0a},
  505. {0x32, 0x07},
  506. {0x98, 0x40}, /*{0x98, 0x00},*/
  507. {0x99, 0xA0}, /*{0x99, 0x00},*/
  508. {0x9a, 0x01}, /*{0x9a, 0x00},*/
  509. {0x57, 0x00},
  510. {0x58, 0x78}, /*{0x58, 0xc8},*/
  511. {0x59, 0x50}, /*{0x59, 0xa0},*/
  512. {0x4c, 0x13},
  513. {0x4b, 0x36},
  514. {0x3d, 0x3c},
  515. {0x3e, 0x03},
  516. {0xbd, 0x50}, /*{0xbd, 0xa0},*/
  517. {0xbe, 0x78}, /*{0xbe, 0xc8},*/
  518. {0x4e, 0x55},
  519. {0x4f, 0x55},
  520. {0x50, 0x55},
  521. {0x51, 0x55},
  522. {0x24, 0x55},
  523. {0x25, 0x40},
  524. {0x26, 0xa1},
  525. {0x5c, 0x59},
  526. {0x5d, 0x00},
  527. {0x11, 0x00},
  528. {0x2a, 0x98},
  529. {0x2b, 0x06},
  530. {0x2d, 0x00},
  531. {0x2e, 0x00},
  532. {0x13, 0xa5},
  533. {0x14, 0x40},
  534. {0x4a, 0x00},
  535. {0x49, 0xce},
  536. {0x22, 0x03},
  537. {0x09, 0x00}
  538. };
  539. static const u8 ov965x_start_1_vga[][2] = { /* same for qvga */
  540. {0x12, 0x62}, /* com7 - 30fps VGA YUV */
  541. {0x36, 0xfa}, /* aref3 */
  542. {0x69, 0x0a}, /* hv */
  543. {0x8c, 0x89}, /* com22 */
  544. {0x14, 0x28}, /* com9 */
  545. {0x3e, 0x0c}, /* com14 */
  546. {0x41, 0x40}, /* com16 */
  547. {0x72, 0x00},
  548. {0x73, 0x00},
  549. {0x74, 0x3a},
  550. {0x75, 0x35},
  551. {0x76, 0x01},
  552. {0xc7, 0x80}, /* com24 */
  553. {0x03, 0x12}, /* vref */
  554. {0x17, 0x16}, /* hstart */
  555. {0x18, 0x02}, /* hstop */
  556. {0x19, 0x01}, /* vstrt */
  557. {0x1a, 0x3d}, /* vstop */
  558. {0x32, 0xff}, /* href */
  559. {0xc0, 0xaa},
  560. };
  561. static const u8 ov965x_start_1_svga[][2] = {
  562. {0x12, 0x02}, /* com7 - YUYV - VGA 15 full resolution */
  563. {0x36, 0xf8}, /* aref3 */
  564. {0x69, 0x02}, /* hv */
  565. {0x8c, 0x0d}, /* com22 */
  566. {0x3e, 0x0c}, /* com14 */
  567. {0x41, 0x40}, /* com16 */
  568. {0x72, 0x00},
  569. {0x73, 0x01},
  570. {0x74, 0x3a},
  571. {0x75, 0x35},
  572. {0x76, 0x01},
  573. {0xc7, 0x80}, /* com24 */
  574. {0x03, 0x1b}, /* vref */
  575. {0x17, 0x1d}, /* hstart */
  576. {0x18, 0xbd}, /* hstop */
  577. {0x19, 0x01}, /* vstrt */
  578. {0x1a, 0x81}, /* vstop */
  579. {0x32, 0xff}, /* href */
  580. {0xc0, 0xe2},
  581. };
  582. static const u8 ov965x_start_1_xga[][2] = {
  583. {0x12, 0x02}, /* com7 */
  584. {0x36, 0xf8}, /* aref3 */
  585. {0x69, 0x02}, /* hv */
  586. {0x8c, 0x89}, /* com22 */
  587. {0x14, 0x28}, /* com9 */
  588. {0x3e, 0x0c}, /* com14 */
  589. {0x41, 0x40}, /* com16 */
  590. {0x72, 0x00},
  591. {0x73, 0x01},
  592. {0x74, 0x3a},
  593. {0x75, 0x35},
  594. {0x76, 0x01},
  595. {0xc7, 0x80}, /* com24 */
  596. {0x03, 0x1b}, /* vref */
  597. {0x17, 0x1d}, /* hstart */
  598. {0x18, 0xbd}, /* hstop */
  599. {0x19, 0x01}, /* vstrt */
  600. {0x1a, 0x81}, /* vstop */
  601. {0x32, 0xff}, /* href */
  602. {0xc0, 0xe2},
  603. };
  604. static const u8 ov965x_start_1_sxga[][2] = {
  605. {0x12, 0x02}, /* com7 */
  606. {0x36, 0xf8}, /* aref3 */
  607. {0x69, 0x02}, /* hv */
  608. {0x8c, 0x89}, /* com22 */
  609. {0x14, 0x28}, /* com9 */
  610. {0x3e, 0x0c}, /* com14 */
  611. {0x41, 0x40}, /* com16 */
  612. {0x72, 0x00},
  613. {0x73, 0x01},
  614. {0x74, 0x3a},
  615. {0x75, 0x35},
  616. {0x76, 0x01},
  617. {0xc7, 0x80}, /* com24 */
  618. {0x03, 0x1b}, /* vref */
  619. {0x17, 0x1d}, /* hstart */
  620. {0x18, 0x02}, /* hstop */
  621. {0x19, 0x01}, /* vstrt */
  622. {0x1a, 0x81}, /* vstop */
  623. {0x32, 0xff}, /* href */
  624. {0xc0, 0xe2},
  625. };
  626. static const u8 bridge_start_qvga[][2] = {
  627. {0x94, 0xaa},
  628. {0xf1, 0x60},
  629. {0xe5, 0x04},
  630. {0xc0, 0x50},
  631. {0xc1, 0x3c},
  632. {0x8c, 0x00},
  633. {0x8d, 0x1c},
  634. {0x34, 0x05},
  635. {0xc2, 0x4c},
  636. {0xc3, 0xf9},
  637. {0xda, 0x00},
  638. {0x50, 0x00},
  639. {0x51, 0xa0},
  640. {0x52, 0x78},
  641. {0x53, 0x00},
  642. {0x54, 0x00},
  643. {0x55, 0x00},
  644. {0x57, 0x00},
  645. {0x5c, 0x00},
  646. {0x5a, 0x50},
  647. {0x5b, 0x3c},
  648. {0x35, 0x02},
  649. {0xd9, 0x10},
  650. {0x94, 0x11},
  651. };
  652. static const u8 bridge_start_vga[][2] = {
  653. {0x94, 0xaa},
  654. {0xf1, 0x60},
  655. {0xe5, 0x04},
  656. {0xc0, 0x50},
  657. {0xc1, 0x3c},
  658. {0x8c, 0x00},
  659. {0x8d, 0x1c},
  660. {0x34, 0x05},
  661. {0xc2, 0x0c},
  662. {0xc3, 0xf9},
  663. {0xda, 0x01},
  664. {0x50, 0x00},
  665. {0x51, 0xa0},
  666. {0x52, 0x3c},
  667. {0x53, 0x00},
  668. {0x54, 0x00},
  669. {0x55, 0x00},
  670. {0x57, 0x00},
  671. {0x5c, 0x00},
  672. {0x5a, 0xa0},
  673. {0x5b, 0x78},
  674. {0x35, 0x02},
  675. {0xd9, 0x10},
  676. {0x94, 0x11},
  677. };
  678. static const u8 bridge_start_svga[][2] = {
  679. {0x94, 0xaa},
  680. {0xf1, 0x60},
  681. {0xe5, 0x04},
  682. {0xc0, 0xa0},
  683. {0xc1, 0x80},
  684. {0x8c, 0x00},
  685. {0x8d, 0x1c},
  686. {0x34, 0x05},
  687. {0xc2, 0x4c},
  688. {0xc3, 0xf9},
  689. {0x50, 0x00},
  690. {0x51, 0x40},
  691. {0x52, 0x00},
  692. {0x53, 0x00},
  693. {0x54, 0x00},
  694. {0x55, 0x88},
  695. {0x57, 0x00},
  696. {0x5c, 0x00},
  697. {0x5a, 0xc8},
  698. {0x5b, 0x96},
  699. {0x35, 0x02},
  700. {0xd9, 0x10},
  701. {0xda, 0x00},
  702. {0x94, 0x11},
  703. };
  704. static const u8 bridge_start_xga[][2] = {
  705. {0x94, 0xaa},
  706. {0xf1, 0x60},
  707. {0xe5, 0x04},
  708. {0xc0, 0xa0},
  709. {0xc1, 0x80},
  710. {0x8c, 0x00},
  711. {0x8d, 0x1c},
  712. {0x34, 0x05},
  713. {0xc2, 0x4c},
  714. {0xc3, 0xf9},
  715. {0x50, 0x00},
  716. {0x51, 0x40},
  717. {0x52, 0x00},
  718. {0x53, 0x00},
  719. {0x54, 0x00},
  720. {0x55, 0x88},
  721. {0x57, 0x00},
  722. {0x5c, 0x01},
  723. {0x5a, 0x00},
  724. {0x5b, 0xc0},
  725. {0x35, 0x02},
  726. {0xd9, 0x10},
  727. {0xda, 0x01},
  728. {0x94, 0x11},
  729. };
  730. static const u8 bridge_start_sxga[][2] = {
  731. {0x94, 0xaa},
  732. {0xf1, 0x60},
  733. {0xe5, 0x04},
  734. {0xc0, 0xa0},
  735. {0xc1, 0x80},
  736. {0x8c, 0x00},
  737. {0x8d, 0x1c},
  738. {0x34, 0x05},
  739. {0xc2, 0x0c},
  740. {0xc3, 0xf9},
  741. {0xda, 0x00},
  742. {0x35, 0x02},
  743. {0xd9, 0x10},
  744. {0x94, 0x11},
  745. };
  746. static const u8 ov965x_start_2_qvga[][2] = {
  747. {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */
  748. {0x1e, 0x04}, /* mvfp */
  749. {0x13, 0xe0}, /* com8 */
  750. {0x00, 0x00},
  751. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  752. {0x11, 0x01}, /* clkrc */
  753. {0x6b, 0x5a}, /* dblv */
  754. {0x6a, 0x02}, /* 50 Hz banding filter */
  755. {0xc5, 0x03}, /* 60 Hz banding filter */
  756. {0xa2, 0x96}, /* bd50 */
  757. {0xa3, 0x7d}, /* bd60 */
  758. {0xff, 0x13}, /* read 13, write ff 00 */
  759. {0x13, 0xe7},
  760. {0x3a, 0x80}, /* tslb - yuyv */
  761. };
  762. static const u8 ov965x_start_2_vga[][2] = {
  763. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  764. {0x1e, 0x04}, /* mvfp */
  765. {0x13, 0xe0}, /* com8 */
  766. {0x00, 0x00},
  767. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  768. {0x11, 0x03}, /* clkrc */
  769. {0x6b, 0x5a}, /* dblv */
  770. {0x6a, 0x05}, /* 50 Hz banding filter */
  771. {0xc5, 0x07}, /* 60 Hz banding filter */
  772. {0xa2, 0x4b}, /* bd50 */
  773. {0xa3, 0x3e}, /* bd60 */
  774. {0x2d, 0x00}, /* advfl */
  775. };
  776. static const u8 ov965x_start_2_svga[][2] = { /* same for xga */
  777. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  778. {0x1e, 0x04}, /* mvfp */
  779. {0x13, 0xe0}, /* com8 */
  780. {0x00, 0x00},
  781. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  782. {0x11, 0x01}, /* clkrc */
  783. {0x6b, 0x5a}, /* dblv */
  784. {0x6a, 0x0c}, /* 50 Hz banding filter */
  785. {0xc5, 0x0f}, /* 60 Hz banding filter */
  786. {0xa2, 0x4e}, /* bd50 */
  787. {0xa3, 0x41}, /* bd60 */
  788. };
  789. static const u8 ov965x_start_2_sxga[][2] = {
  790. {0x13, 0xe0}, /* com8 */
  791. {0x00, 0x00},
  792. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  793. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  794. {0x1e, 0x04}, /* mvfp */
  795. {0x11, 0x01}, /* clkrc */
  796. {0x6b, 0x5a}, /* dblv */
  797. {0x6a, 0x0c}, /* 50 Hz banding filter */
  798. {0xc5, 0x0f}, /* 60 Hz banding filter */
  799. {0xa2, 0x4e}, /* bd50 */
  800. {0xa3, 0x41}, /* bd60 */
  801. };
  802. static const u8 ov562x_init[][2] = {
  803. {0x88, 0x20},
  804. {0x89, 0x0a},
  805. {0x8a, 0x90},
  806. {0x8b, 0x06},
  807. {0x8c, 0x01},
  808. {0x8d, 0x10},
  809. {0x1c, 0x00},
  810. {0x1d, 0x48},
  811. {0x1d, 0x00},
  812. {0x1d, 0xff},
  813. {0x1c, 0x0a},
  814. {0x1d, 0x2e},
  815. {0x1d, 0x1e},
  816. };
  817. static const u8 ov562x_init_2[][2] = {
  818. {0x12, 0x80},
  819. {0x11, 0x41},
  820. {0x13, 0x00},
  821. {0x10, 0x1e},
  822. {0x3b, 0x07},
  823. {0x5b, 0x40},
  824. {0x39, 0x07},
  825. {0x53, 0x02},
  826. {0x54, 0x60},
  827. {0x04, 0x20},
  828. {0x27, 0x04},
  829. {0x3d, 0x40},
  830. {0x36, 0x00},
  831. {0xc5, 0x04},
  832. {0x4e, 0x00},
  833. {0x4f, 0x93},
  834. {0x50, 0x7b},
  835. {0xca, 0x0c},
  836. {0xcb, 0x0f},
  837. {0x39, 0x07},
  838. {0x4a, 0x10},
  839. {0x3e, 0x0a},
  840. {0x3d, 0x00},
  841. {0x0c, 0x38},
  842. {0x38, 0x90},
  843. {0x46, 0x30},
  844. {0x4f, 0x93},
  845. {0x50, 0x7b},
  846. {0xab, 0x00},
  847. {0xca, 0x0c},
  848. {0xcb, 0x0f},
  849. {0x37, 0x02},
  850. {0x44, 0x48},
  851. {0x8d, 0x44},
  852. {0x2a, 0x00},
  853. {0x2b, 0x00},
  854. {0x32, 0x00},
  855. {0x38, 0x90},
  856. {0x53, 0x02},
  857. {0x54, 0x60},
  858. {0x12, 0x00},
  859. {0x17, 0x12},
  860. {0x18, 0xb4},
  861. {0x19, 0x0c},
  862. {0x1a, 0xf4},
  863. {0x03, 0x4a},
  864. {0x89, 0x20},
  865. {0x83, 0x80},
  866. {0xb7, 0x9d},
  867. {0xb6, 0x11},
  868. {0xb5, 0x55},
  869. {0xb4, 0x00},
  870. {0xa9, 0xf0},
  871. {0xa8, 0x0a},
  872. {0xb8, 0xf0},
  873. {0xb9, 0xf0},
  874. {0xba, 0xf0},
  875. {0x81, 0x07},
  876. {0x63, 0x44},
  877. {0x13, 0xc7},
  878. {0x14, 0x60},
  879. {0x33, 0x75},
  880. {0x2c, 0x00},
  881. {0x09, 0x00},
  882. {0x35, 0x30},
  883. {0x27, 0x04},
  884. {0x3c, 0x07},
  885. {0x3a, 0x0a},
  886. {0x3b, 0x07},
  887. {0x01, 0x40},
  888. {0x02, 0x40},
  889. {0x16, 0x40},
  890. {0x52, 0xb0},
  891. {0x51, 0x83},
  892. {0x21, 0xbb},
  893. {0x22, 0x10},
  894. {0x23, 0x03},
  895. {0x35, 0x38},
  896. {0x20, 0x90},
  897. {0x28, 0x30},
  898. {0x73, 0xe1},
  899. {0x6c, 0x00},
  900. {0x6d, 0x80},
  901. {0x6e, 0x00},
  902. {0x70, 0x04},
  903. {0x71, 0x00},
  904. {0x8d, 0x04},
  905. {0x64, 0x00},
  906. {0x65, 0x00},
  907. {0x66, 0x00},
  908. {0x67, 0x00},
  909. {0x68, 0x00},
  910. {0x69, 0x00},
  911. {0x6a, 0x00},
  912. {0x6b, 0x00},
  913. {0x71, 0x94},
  914. {0x74, 0x20},
  915. {0x80, 0x09},
  916. {0x85, 0xc0},
  917. };
  918. static void reg_w_i(struct gspca_dev *gspca_dev, u16 reg, u8 val)
  919. {
  920. struct usb_device *udev = gspca_dev->dev;
  921. int ret;
  922. if (gspca_dev->usb_err < 0)
  923. return;
  924. gspca_dev->usb_buf[0] = val;
  925. ret = usb_control_msg(udev,
  926. usb_sndctrlpipe(udev, 0),
  927. 0x01,
  928. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  929. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  930. if (ret < 0) {
  931. pr_err("reg_w failed %d\n", ret);
  932. gspca_dev->usb_err = ret;
  933. }
  934. }
  935. static void reg_w(struct gspca_dev *gspca_dev, u16 reg, u8 val)
  936. {
  937. PDEBUG(D_USBO, "reg_w [%04x] = %02x", reg, val);
  938. reg_w_i(gspca_dev, reg, val);
  939. }
  940. static u8 reg_r(struct gspca_dev *gspca_dev, u16 reg)
  941. {
  942. struct usb_device *udev = gspca_dev->dev;
  943. int ret;
  944. if (gspca_dev->usb_err < 0)
  945. return 0;
  946. ret = usb_control_msg(udev,
  947. usb_rcvctrlpipe(udev, 0),
  948. 0x01,
  949. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  950. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  951. PDEBUG(D_USBI, "reg_r [%04x] -> %02x", reg, gspca_dev->usb_buf[0]);
  952. if (ret < 0) {
  953. pr_err("reg_r err %d\n", ret);
  954. gspca_dev->usb_err = ret;
  955. }
  956. return gspca_dev->usb_buf[0];
  957. }
  958. static int sccb_check_status(struct gspca_dev *gspca_dev)
  959. {
  960. u8 data;
  961. int i;
  962. for (i = 0; i < 5; i++) {
  963. data = reg_r(gspca_dev, OV534_REG_STATUS);
  964. switch (data) {
  965. case 0x00:
  966. return 1;
  967. case 0x04:
  968. return 0;
  969. case 0x03:
  970. break;
  971. default:
  972. PDEBUG(D_USBI|D_USBO,
  973. "sccb status 0x%02x, attempt %d/5",
  974. data, i + 1);
  975. }
  976. }
  977. return 0;
  978. }
  979. static void sccb_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  980. {
  981. PDEBUG(D_USBO, "sccb_write [%02x] = %02x", reg, val);
  982. reg_w_i(gspca_dev, OV534_REG_SUBADDR, reg);
  983. reg_w_i(gspca_dev, OV534_REG_WRITE, val);
  984. reg_w_i(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
  985. if (!sccb_check_status(gspca_dev))
  986. pr_err("sccb_write failed\n");
  987. }
  988. static u8 sccb_read(struct gspca_dev *gspca_dev, u16 reg)
  989. {
  990. reg_w(gspca_dev, OV534_REG_SUBADDR, reg);
  991. reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
  992. if (!sccb_check_status(gspca_dev))
  993. pr_err("sccb_read failed 1\n");
  994. reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
  995. if (!sccb_check_status(gspca_dev))
  996. pr_err("sccb_read failed 2\n");
  997. return reg_r(gspca_dev, OV534_REG_READ);
  998. }
  999. /* output a bridge sequence (reg - val) */
  1000. static void reg_w_array(struct gspca_dev *gspca_dev,
  1001. const u8 (*data)[2], int len)
  1002. {
  1003. while (--len >= 0) {
  1004. reg_w(gspca_dev, (*data)[0], (*data)[1]);
  1005. data++;
  1006. }
  1007. }
  1008. /* output a sensor sequence (reg - val) */
  1009. static void sccb_w_array(struct gspca_dev *gspca_dev,
  1010. const u8 (*data)[2], int len)
  1011. {
  1012. while (--len >= 0) {
  1013. if ((*data)[0] != 0xff) {
  1014. sccb_write(gspca_dev, (*data)[0], (*data)[1]);
  1015. } else {
  1016. sccb_read(gspca_dev, (*data)[1]);
  1017. sccb_write(gspca_dev, 0xff, 0x00);
  1018. }
  1019. data++;
  1020. }
  1021. }
  1022. /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
  1023. * (direction and output)? */
  1024. static void set_led(struct gspca_dev *gspca_dev, int status)
  1025. {
  1026. u8 data;
  1027. PDEBUG(D_CONF, "led status: %d", status);
  1028. data = reg_r(gspca_dev, 0x21);
  1029. data |= 0x80;
  1030. reg_w(gspca_dev, 0x21, data);
  1031. data = reg_r(gspca_dev, 0x23);
  1032. if (status)
  1033. data |= 0x80;
  1034. else
  1035. data &= ~0x80;
  1036. reg_w(gspca_dev, 0x23, data);
  1037. if (!status) {
  1038. data = reg_r(gspca_dev, 0x21);
  1039. data &= ~0x80;
  1040. reg_w(gspca_dev, 0x21, data);
  1041. }
  1042. }
  1043. static void setbrightness(struct gspca_dev *gspca_dev)
  1044. {
  1045. struct sd *sd = (struct sd *) gspca_dev;
  1046. u8 val;
  1047. s8 sval;
  1048. if (gspca_dev->ctrl_dis & (1 << BRIGHTNESS))
  1049. return;
  1050. if (sd->sensor == SENSOR_OV562x) {
  1051. sval = sd->ctrls[BRIGHTNESS].val;
  1052. val = 0x76;
  1053. val += sval;
  1054. sccb_write(gspca_dev, 0x24, val);
  1055. val = 0x6a;
  1056. val += sval;
  1057. sccb_write(gspca_dev, 0x25, val);
  1058. if (sval < -40)
  1059. val = 0x71;
  1060. else if (sval < 20)
  1061. val = 0x94;
  1062. else
  1063. val = 0xe6;
  1064. sccb_write(gspca_dev, 0x26, val);
  1065. } else {
  1066. val = sd->ctrls[BRIGHTNESS].val;
  1067. if (val < 8)
  1068. val = 15 - val; /* f .. 8 */
  1069. else
  1070. val = val - 8; /* 0 .. 7 */
  1071. sccb_write(gspca_dev, 0x55, /* brtn - brightness adjustment */
  1072. 0x0f | (val << 4));
  1073. }
  1074. }
  1075. static void setcontrast(struct gspca_dev *gspca_dev)
  1076. {
  1077. struct sd *sd = (struct sd *) gspca_dev;
  1078. if (gspca_dev->ctrl_dis & (1 << CONTRAST))
  1079. return;
  1080. sccb_write(gspca_dev, 0x56, /* cnst1 - contrast 1 ctrl coeff */
  1081. sd->ctrls[CONTRAST].val << 4);
  1082. }
  1083. static void setautogain(struct gspca_dev *gspca_dev)
  1084. {
  1085. struct sd *sd = (struct sd *) gspca_dev;
  1086. u8 val;
  1087. if (gspca_dev->ctrl_dis & (1 << AUTOGAIN))
  1088. return;
  1089. /*fixme: should adjust agc/awb/aec by different controls */
  1090. val = sccb_read(gspca_dev, 0x13); /* com8 */
  1091. sccb_write(gspca_dev, 0xff, 0x00);
  1092. if (sd->ctrls[AUTOGAIN].val)
  1093. val |= 0x05; /* agc & aec */
  1094. else
  1095. val &= 0xfa;
  1096. sccb_write(gspca_dev, 0x13, val);
  1097. }
  1098. static void setexposure(struct gspca_dev *gspca_dev)
  1099. {
  1100. struct sd *sd = (struct sd *) gspca_dev;
  1101. u8 val;
  1102. static const u8 expo[4] = {0x00, 0x25, 0x38, 0x5e};
  1103. if (gspca_dev->ctrl_dis & (1 << EXPOSURE))
  1104. return;
  1105. sccb_write(gspca_dev, 0x10, /* aec[9:2] */
  1106. expo[sd->ctrls[EXPOSURE].val]);
  1107. val = sccb_read(gspca_dev, 0x13); /* com8 */
  1108. sccb_write(gspca_dev, 0xff, 0x00);
  1109. sccb_write(gspca_dev, 0x13, val);
  1110. val = sccb_read(gspca_dev, 0xa1); /* aech */
  1111. sccb_write(gspca_dev, 0xff, 0x00);
  1112. sccb_write(gspca_dev, 0xa1, val & 0xe0); /* aec[15:10] = 0 */
  1113. }
  1114. static void setsharpness(struct gspca_dev *gspca_dev)
  1115. {
  1116. struct sd *sd = (struct sd *) gspca_dev;
  1117. s8 val;
  1118. if (gspca_dev->ctrl_dis & (1 << SHARPNESS))
  1119. return;
  1120. val = sd->ctrls[SHARPNESS].val;
  1121. if (val < 0) { /* auto */
  1122. val = sccb_read(gspca_dev, 0x42); /* com17 */
  1123. sccb_write(gspca_dev, 0xff, 0x00);
  1124. sccb_write(gspca_dev, 0x42, val | 0x40);
  1125. /* Edge enhancement strength auto adjust */
  1126. return;
  1127. }
  1128. if (val != 0)
  1129. val = 1 << (val - 1);
  1130. sccb_write(gspca_dev, 0x3f, /* edge - edge enhance. factor */
  1131. val);
  1132. val = sccb_read(gspca_dev, 0x42); /* com17 */
  1133. sccb_write(gspca_dev, 0xff, 0x00);
  1134. sccb_write(gspca_dev, 0x42, val & 0xbf);
  1135. }
  1136. static void setsatur(struct gspca_dev *gspca_dev)
  1137. {
  1138. struct sd *sd = (struct sd *) gspca_dev;
  1139. u8 val1, val2, val3;
  1140. static const u8 matrix[5][2] = {
  1141. {0x14, 0x38},
  1142. {0x1e, 0x54},
  1143. {0x28, 0x70},
  1144. {0x32, 0x8c},
  1145. {0x48, 0x90}
  1146. };
  1147. if (gspca_dev->ctrl_dis & (1 << SATUR))
  1148. return;
  1149. val1 = matrix[sd->ctrls[SATUR].val][0];
  1150. val2 = matrix[sd->ctrls[SATUR].val][1];
  1151. val3 = val1 + val2;
  1152. sccb_write(gspca_dev, 0x4f, val3); /* matrix coeff */
  1153. sccb_write(gspca_dev, 0x50, val3);
  1154. sccb_write(gspca_dev, 0x51, 0x00);
  1155. sccb_write(gspca_dev, 0x52, val1);
  1156. sccb_write(gspca_dev, 0x53, val2);
  1157. sccb_write(gspca_dev, 0x54, val3);
  1158. sccb_write(gspca_dev, 0x58, 0x1a); /* mtxs - coeff signs */
  1159. val1 = sccb_read(gspca_dev, 0x41); /* com16 */
  1160. sccb_write(gspca_dev, 0xff, 0x00);
  1161. sccb_write(gspca_dev, 0x41, val1);
  1162. }
  1163. static void setlightfreq(struct gspca_dev *gspca_dev)
  1164. {
  1165. struct sd *sd = (struct sd *) gspca_dev;
  1166. u8 val;
  1167. if (gspca_dev->ctrl_dis & (1 << LIGHTFREQ))
  1168. return;
  1169. val = sccb_read(gspca_dev, 0x13); /* com8 */
  1170. sccb_write(gspca_dev, 0xff, 0x00);
  1171. if (sd->ctrls[LIGHTFREQ].val == 0) {
  1172. sccb_write(gspca_dev, 0x13, val & 0xdf);
  1173. return;
  1174. }
  1175. sccb_write(gspca_dev, 0x13, val | 0x20);
  1176. val = sccb_read(gspca_dev, 0x42); /* com17 */
  1177. sccb_write(gspca_dev, 0xff, 0x00);
  1178. if (sd->ctrls[LIGHTFREQ].val == 1)
  1179. val |= 0x01;
  1180. else
  1181. val &= 0xfe;
  1182. sccb_write(gspca_dev, 0x42, val);
  1183. }
  1184. /* this function is called at probe time */
  1185. static int sd_config(struct gspca_dev *gspca_dev,
  1186. const struct usb_device_id *id)
  1187. {
  1188. struct sd *sd = (struct sd *) gspca_dev;
  1189. gspca_dev->cam.ctrls = sd->ctrls;
  1190. #if AUTOGAIN_DEF != 0
  1191. gspca_dev->ctrl_inac |= (1 << EXPOSURE);
  1192. #endif
  1193. return 0;
  1194. }
  1195. /* this function is called at probe and resume time */
  1196. static int sd_init(struct gspca_dev *gspca_dev)
  1197. {
  1198. struct sd *sd = (struct sd *) gspca_dev;
  1199. u16 sensor_id;
  1200. /* reset bridge */
  1201. reg_w(gspca_dev, 0xe7, 0x3a);
  1202. reg_w(gspca_dev, 0xe0, 0x08);
  1203. msleep(100);
  1204. /* initialize the sensor address */
  1205. reg_w(gspca_dev, OV534_REG_ADDRESS, 0x60);
  1206. /* reset sensor */
  1207. sccb_write(gspca_dev, 0x12, 0x80);
  1208. msleep(10);
  1209. /* probe the sensor */
  1210. sccb_read(gspca_dev, 0x0a);
  1211. sensor_id = sccb_read(gspca_dev, 0x0a) << 8;
  1212. sccb_read(gspca_dev, 0x0b);
  1213. sensor_id |= sccb_read(gspca_dev, 0x0b);
  1214. PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
  1215. /* initialize */
  1216. if ((sensor_id & 0xfff0) == 0x9650) {
  1217. sd->sensor = SENSOR_OV965x;
  1218. gspca_dev->cam.cam_mode = ov965x_mode;
  1219. gspca_dev->cam.nmodes = ARRAY_SIZE(ov965x_mode);
  1220. reg_w_array(gspca_dev, bridge_init,
  1221. ARRAY_SIZE(bridge_init));
  1222. sccb_w_array(gspca_dev, ov965x_init,
  1223. ARRAY_SIZE(ov965x_init));
  1224. reg_w_array(gspca_dev, bridge_init_2,
  1225. ARRAY_SIZE(bridge_init_2));
  1226. sccb_w_array(gspca_dev, ov965x_init_2,
  1227. ARRAY_SIZE(ov965x_init_2));
  1228. reg_w(gspca_dev, 0xe0, 0x00);
  1229. reg_w(gspca_dev, 0xe0, 0x01);
  1230. set_led(gspca_dev, 0);
  1231. reg_w(gspca_dev, 0xe0, 0x00);
  1232. } else if ((sensor_id & 0xfff0) == 0x9710) {
  1233. const char *p;
  1234. int l;
  1235. sd->sensor = SENSOR_OV971x;
  1236. gspca_dev->cam.cam_mode = ov971x_mode;
  1237. gspca_dev->cam.nmodes = ARRAY_SIZE(ov971x_mode);
  1238. /* no control yet */
  1239. gspca_dev->ctrl_dis = (1 << NCTRLS) - 1;
  1240. gspca_dev->cam.bulk = 1;
  1241. gspca_dev->cam.bulk_size = 16384;
  1242. gspca_dev->cam.bulk_nurbs = 2;
  1243. sccb_w_array(gspca_dev, ov971x_init,
  1244. ARRAY_SIZE(ov971x_init));
  1245. /* set video format on bridge processor */
  1246. /* access bridge processor's video format registers at: 0x00 */
  1247. reg_w(gspca_dev, 0x1c, 0x00);
  1248. /*set register: 0x00 is 'RAW8', 0x40 is 'YUV422' (YUYV?)*/
  1249. reg_w(gspca_dev, 0x1d, 0x00);
  1250. /* Will W. specific stuff
  1251. * set VSYNC to
  1252. * output (0x1f) if first webcam
  1253. * input (0x17) if 2nd or 3rd webcam */
  1254. p = video_device_node_name(&gspca_dev->vdev);
  1255. l = strlen(p) - 1;
  1256. if (p[l] == '0')
  1257. reg_w(gspca_dev, 0x56, 0x1f);
  1258. else
  1259. reg_w(gspca_dev, 0x56, 0x17);
  1260. } else if ((sensor_id & 0xfff0) == 0x5620) {
  1261. sd->sensor = SENSOR_OV562x;
  1262. gspca_dev->ctrl_dis = (1 << CONTRAST) |
  1263. (1 << AUTOGAIN) |
  1264. (1 << EXPOSURE) |
  1265. (1 << SHARPNESS) |
  1266. (1 << SATUR) |
  1267. (1 << LIGHTFREQ);
  1268. sd->ctrls[BRIGHTNESS].min = -90;
  1269. sd->ctrls[BRIGHTNESS].max = 90;
  1270. sd->ctrls[BRIGHTNESS].def = 0;
  1271. gspca_dev->cam.cam_mode = ov562x_mode;
  1272. gspca_dev->cam.nmodes = ARRAY_SIZE(ov562x_mode);
  1273. reg_w_array(gspca_dev, ov562x_init,
  1274. ARRAY_SIZE(ov562x_init));
  1275. sccb_w_array(gspca_dev, ov562x_init_2,
  1276. ARRAY_SIZE(ov562x_init_2));
  1277. reg_w(gspca_dev, 0xe0, 0x00);
  1278. } else {
  1279. err("Unknown sensor %04x", sensor_id);
  1280. return -EINVAL;
  1281. }
  1282. return gspca_dev->usb_err;
  1283. }
  1284. static int sd_start(struct gspca_dev *gspca_dev)
  1285. {
  1286. struct sd *sd = (struct sd *) gspca_dev;
  1287. if (sd->sensor == SENSOR_OV971x)
  1288. return gspca_dev->usb_err;
  1289. else if (sd->sensor == SENSOR_OV562x) {
  1290. setbrightness(gspca_dev);
  1291. return gspca_dev->usb_err;
  1292. }
  1293. switch (gspca_dev->curr_mode) {
  1294. case QVGA_MODE: /* 320x240 */
  1295. sccb_w_array(gspca_dev, ov965x_start_1_vga,
  1296. ARRAY_SIZE(ov965x_start_1_vga));
  1297. reg_w_array(gspca_dev, bridge_start_qvga,
  1298. ARRAY_SIZE(bridge_start_qvga));
  1299. sccb_w_array(gspca_dev, ov965x_start_2_qvga,
  1300. ARRAY_SIZE(ov965x_start_2_qvga));
  1301. break;
  1302. case VGA_MODE: /* 640x480 */
  1303. sccb_w_array(gspca_dev, ov965x_start_1_vga,
  1304. ARRAY_SIZE(ov965x_start_1_vga));
  1305. reg_w_array(gspca_dev, bridge_start_vga,
  1306. ARRAY_SIZE(bridge_start_vga));
  1307. sccb_w_array(gspca_dev, ov965x_start_2_vga,
  1308. ARRAY_SIZE(ov965x_start_2_vga));
  1309. break;
  1310. case SVGA_MODE: /* 800x600 */
  1311. sccb_w_array(gspca_dev, ov965x_start_1_svga,
  1312. ARRAY_SIZE(ov965x_start_1_svga));
  1313. reg_w_array(gspca_dev, bridge_start_svga,
  1314. ARRAY_SIZE(bridge_start_svga));
  1315. sccb_w_array(gspca_dev, ov965x_start_2_svga,
  1316. ARRAY_SIZE(ov965x_start_2_svga));
  1317. break;
  1318. case XGA_MODE: /* 1024x768 */
  1319. sccb_w_array(gspca_dev, ov965x_start_1_xga,
  1320. ARRAY_SIZE(ov965x_start_1_xga));
  1321. reg_w_array(gspca_dev, bridge_start_xga,
  1322. ARRAY_SIZE(bridge_start_xga));
  1323. sccb_w_array(gspca_dev, ov965x_start_2_svga,
  1324. ARRAY_SIZE(ov965x_start_2_svga));
  1325. break;
  1326. default:
  1327. /* case SXGA_MODE: * 1280x1024 */
  1328. sccb_w_array(gspca_dev, ov965x_start_1_sxga,
  1329. ARRAY_SIZE(ov965x_start_1_sxga));
  1330. reg_w_array(gspca_dev, bridge_start_sxga,
  1331. ARRAY_SIZE(bridge_start_sxga));
  1332. sccb_w_array(gspca_dev, ov965x_start_2_sxga,
  1333. ARRAY_SIZE(ov965x_start_2_sxga));
  1334. break;
  1335. }
  1336. setlightfreq(gspca_dev);
  1337. setautogain(gspca_dev);
  1338. setbrightness(gspca_dev);
  1339. setcontrast(gspca_dev);
  1340. setexposure(gspca_dev);
  1341. setsharpness(gspca_dev);
  1342. setsatur(gspca_dev);
  1343. reg_w(gspca_dev, 0xe0, 0x00);
  1344. reg_w(gspca_dev, 0xe0, 0x00);
  1345. set_led(gspca_dev, 1);
  1346. return gspca_dev->usb_err;
  1347. }
  1348. static void sd_stopN(struct gspca_dev *gspca_dev)
  1349. {
  1350. reg_w(gspca_dev, 0xe0, 0x01);
  1351. set_led(gspca_dev, 0);
  1352. reg_w(gspca_dev, 0xe0, 0x00);
  1353. }
  1354. /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
  1355. #define UVC_STREAM_EOH (1 << 7)
  1356. #define UVC_STREAM_ERR (1 << 6)
  1357. #define UVC_STREAM_STI (1 << 5)
  1358. #define UVC_STREAM_RES (1 << 4)
  1359. #define UVC_STREAM_SCR (1 << 3)
  1360. #define UVC_STREAM_PTS (1 << 2)
  1361. #define UVC_STREAM_EOF (1 << 1)
  1362. #define UVC_STREAM_FID (1 << 0)
  1363. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1364. u8 *data, int len)
  1365. {
  1366. struct sd *sd = (struct sd *) gspca_dev;
  1367. __u32 this_pts;
  1368. u8 this_fid;
  1369. int remaining_len = len;
  1370. int payload_len;
  1371. payload_len = gspca_dev->cam.bulk ? 2048 : 2040;
  1372. do {
  1373. len = min(remaining_len, payload_len);
  1374. /* Payloads are prefixed with a UVC-style header. We
  1375. consider a frame to start when the FID toggles, or the PTS
  1376. changes. A frame ends when EOF is set, and we've received
  1377. the correct number of bytes. */
  1378. /* Verify UVC header. Header length is always 12 */
  1379. if (data[0] != 12 || len < 12) {
  1380. PDEBUG(D_PACK, "bad header");
  1381. goto discard;
  1382. }
  1383. /* Check errors */
  1384. if (data[1] & UVC_STREAM_ERR) {
  1385. PDEBUG(D_PACK, "payload error");
  1386. goto discard;
  1387. }
  1388. /* Extract PTS and FID */
  1389. if (!(data[1] & UVC_STREAM_PTS)) {
  1390. PDEBUG(D_PACK, "PTS not present");
  1391. goto discard;
  1392. }
  1393. this_pts = (data[5] << 24) | (data[4] << 16)
  1394. | (data[3] << 8) | data[2];
  1395. this_fid = data[1] & UVC_STREAM_FID;
  1396. /* If PTS or FID has changed, start a new frame. */
  1397. if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
  1398. if (gspca_dev->last_packet_type == INTER_PACKET)
  1399. gspca_frame_add(gspca_dev, LAST_PACKET,
  1400. NULL, 0);
  1401. sd->last_pts = this_pts;
  1402. sd->last_fid = this_fid;
  1403. gspca_frame_add(gspca_dev, FIRST_PACKET,
  1404. data + 12, len - 12);
  1405. /* If this packet is marked as EOF, end the frame */
  1406. } else if (data[1] & UVC_STREAM_EOF) {
  1407. sd->last_pts = 0;
  1408. gspca_frame_add(gspca_dev, LAST_PACKET,
  1409. data + 12, len - 12);
  1410. } else {
  1411. /* Add the data from this payload */
  1412. gspca_frame_add(gspca_dev, INTER_PACKET,
  1413. data + 12, len - 12);
  1414. }
  1415. /* Done this payload */
  1416. goto scan_next;
  1417. discard:
  1418. /* Discard data until a new frame starts. */
  1419. gspca_dev->last_packet_type = DISCARD_PACKET;
  1420. scan_next:
  1421. remaining_len -= len;
  1422. data += len;
  1423. } while (remaining_len > 0);
  1424. }
  1425. static int sd_querymenu(struct gspca_dev *gspca_dev,
  1426. struct v4l2_querymenu *menu)
  1427. {
  1428. switch (menu->id) {
  1429. case V4L2_CID_POWER_LINE_FREQUENCY:
  1430. switch (menu->index) {
  1431. case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
  1432. strcpy((char *) menu->name, "NoFliker");
  1433. return 0;
  1434. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  1435. strcpy((char *) menu->name, "50 Hz");
  1436. return 0;
  1437. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  1438. strcpy((char *) menu->name, "60 Hz");
  1439. return 0;
  1440. }
  1441. break;
  1442. }
  1443. return -EINVAL;
  1444. }
  1445. /* sub-driver description */
  1446. static const struct sd_desc sd_desc = {
  1447. .name = MODULE_NAME,
  1448. .ctrls = sd_ctrls,
  1449. .nctrls = NCTRLS,
  1450. .config = sd_config,
  1451. .init = sd_init,
  1452. .start = sd_start,
  1453. .stopN = sd_stopN,
  1454. .pkt_scan = sd_pkt_scan,
  1455. .querymenu = sd_querymenu,
  1456. };
  1457. /* -- module initialisation -- */
  1458. static const struct usb_device_id device_table[] = {
  1459. {USB_DEVICE(0x05a9, 0x8065)},
  1460. {USB_DEVICE(0x06f8, 0x3003)},
  1461. {USB_DEVICE(0x05a9, 0x1550)},
  1462. {}
  1463. };
  1464. MODULE_DEVICE_TABLE(usb, device_table);
  1465. /* -- device connect -- */
  1466. static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1467. {
  1468. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1469. THIS_MODULE);
  1470. }
  1471. static struct usb_driver sd_driver = {
  1472. .name = MODULE_NAME,
  1473. .id_table = device_table,
  1474. .probe = sd_probe,
  1475. .disconnect = gspca_disconnect,
  1476. #ifdef CONFIG_PM
  1477. .suspend = gspca_suspend,
  1478. .resume = gspca_resume,
  1479. #endif
  1480. };
  1481. module_usb_driver(sd_driver);