ov534.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032
  1. /*
  2. * ov534 gspca driver
  3. *
  4. * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
  5. * Copyright (C) 2008 Jim Paris <jim@jtan.com>
  6. * Copyright (C) 2009 Jean-Francois Moine http://moinejf.free.fr
  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. * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr
  13. * PS3 Eye camera, brightness, contrast, hue, AWB control added
  14. * by Max Thrun <bear24rw@gmail.com>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. */
  30. #define MODULE_NAME "ov534"
  31. #include "gspca.h"
  32. #define OV534_REG_ADDRESS 0xf1 /* sensor address */
  33. #define OV534_REG_SUBADDR 0xf2
  34. #define OV534_REG_WRITE 0xf3
  35. #define OV534_REG_READ 0xf4
  36. #define OV534_REG_OPERATION 0xf5
  37. #define OV534_REG_STATUS 0xf6
  38. #define OV534_OP_WRITE_3 0x37
  39. #define OV534_OP_WRITE_2 0x33
  40. #define OV534_OP_READ_2 0xf9
  41. #define CTRL_TIMEOUT 500
  42. MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
  43. MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver");
  44. MODULE_LICENSE("GPL");
  45. /* specific webcam descriptor */
  46. struct sd {
  47. struct gspca_dev gspca_dev; /* !! must be the first item */
  48. __u32 last_pts;
  49. u16 last_fid;
  50. u8 frame_rate;
  51. u8 brightness;
  52. u8 contrast;
  53. u8 gain;
  54. u8 exposure;
  55. u8 redblc;
  56. u8 blueblc;
  57. u8 hue;
  58. u8 autogain;
  59. u8 awb;
  60. u8 sharpness;
  61. u8 hflip;
  62. u8 vflip;
  63. u8 sensor;
  64. #define SENSOR_OV772X 0
  65. #define SENSOR_OV965X 1
  66. };
  67. /* V4L2 controls supported by the driver */
  68. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
  69. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
  70. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
  71. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
  72. static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val);
  73. static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val);
  74. static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val);
  75. static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val);
  76. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
  77. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
  78. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
  79. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
  80. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
  81. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
  82. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
  83. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
  84. static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
  85. static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
  86. static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val);
  87. static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val);
  88. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
  89. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
  90. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
  91. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
  92. static struct ctrl sd_ctrls_ov772x[] = {
  93. { /* 0 */
  94. {
  95. .id = V4L2_CID_BRIGHTNESS,
  96. .type = V4L2_CTRL_TYPE_INTEGER,
  97. .name = "Brightness",
  98. .minimum = 0,
  99. .maximum = 255,
  100. .step = 1,
  101. #define BRIGHTNESS_DEF 20
  102. .default_value = BRIGHTNESS_DEF,
  103. },
  104. .set = sd_setbrightness,
  105. .get = sd_getbrightness,
  106. },
  107. { /* 1 */
  108. {
  109. .id = V4L2_CID_CONTRAST,
  110. .type = V4L2_CTRL_TYPE_INTEGER,
  111. .name = "Contrast",
  112. .minimum = 0,
  113. .maximum = 255,
  114. .step = 1,
  115. #define CONTRAST_DEF 37
  116. .default_value = CONTRAST_DEF,
  117. },
  118. .set = sd_setcontrast,
  119. .get = sd_getcontrast,
  120. },
  121. { /* 2 */
  122. {
  123. .id = V4L2_CID_GAIN,
  124. .type = V4L2_CTRL_TYPE_INTEGER,
  125. .name = "Main Gain",
  126. .minimum = 0,
  127. .maximum = 63,
  128. .step = 1,
  129. #define GAIN_DEF 20
  130. .default_value = GAIN_DEF,
  131. },
  132. .set = sd_setgain,
  133. .get = sd_getgain,
  134. },
  135. { /* 3 */
  136. {
  137. .id = V4L2_CID_EXPOSURE,
  138. .type = V4L2_CTRL_TYPE_INTEGER,
  139. .name = "Exposure",
  140. .minimum = 0,
  141. .maximum = 255,
  142. .step = 1,
  143. #define EXPO_DEF 120
  144. .default_value = EXPO_DEF,
  145. },
  146. .set = sd_setexposure,
  147. .get = sd_getexposure,
  148. },
  149. { /* 4 */
  150. {
  151. .id = V4L2_CID_RED_BALANCE,
  152. .type = V4L2_CTRL_TYPE_INTEGER,
  153. .name = "Red Balance",
  154. .minimum = 0,
  155. .maximum = 255,
  156. .step = 1,
  157. #define RED_BALANCE_DEF 128
  158. .default_value = RED_BALANCE_DEF,
  159. },
  160. .set = sd_setredblc,
  161. .get = sd_getredblc,
  162. },
  163. { /* 5 */
  164. {
  165. .id = V4L2_CID_BLUE_BALANCE,
  166. .type = V4L2_CTRL_TYPE_INTEGER,
  167. .name = "Blue Balance",
  168. .minimum = 0,
  169. .maximum = 255,
  170. .step = 1,
  171. #define BLUE_BALANCE_DEF 128
  172. .default_value = BLUE_BALANCE_DEF,
  173. },
  174. .set = sd_setblueblc,
  175. .get = sd_getblueblc,
  176. },
  177. { /* 6 */
  178. {
  179. .id = V4L2_CID_HUE,
  180. .type = V4L2_CTRL_TYPE_INTEGER,
  181. .name = "Hue",
  182. .minimum = 0,
  183. .maximum = 255,
  184. .step = 1,
  185. #define HUE_DEF 143
  186. .default_value = HUE_DEF,
  187. },
  188. .set = sd_sethue,
  189. .get = sd_gethue,
  190. },
  191. { /* 7 */
  192. {
  193. .id = V4L2_CID_AUTOGAIN,
  194. .type = V4L2_CTRL_TYPE_BOOLEAN,
  195. .name = "Autogain",
  196. .minimum = 0,
  197. .maximum = 1,
  198. .step = 1,
  199. #define AUTOGAIN_DEF 0
  200. .default_value = AUTOGAIN_DEF,
  201. },
  202. .set = sd_setautogain,
  203. .get = sd_getautogain,
  204. },
  205. #define AWB_IDX 8
  206. { /* 8 */
  207. {
  208. .id = V4L2_CID_AUTO_WHITE_BALANCE,
  209. .type = V4L2_CTRL_TYPE_BOOLEAN,
  210. .name = "Auto White Balance",
  211. .minimum = 0,
  212. .maximum = 1,
  213. .step = 1,
  214. #define AWB_DEF 0
  215. .default_value = AWB_DEF,
  216. },
  217. .set = sd_setawb,
  218. .get = sd_getawb,
  219. },
  220. { /* 9 */
  221. {
  222. .id = V4L2_CID_SHARPNESS,
  223. .type = V4L2_CTRL_TYPE_INTEGER,
  224. .name = "Sharpness",
  225. .minimum = 0,
  226. .maximum = 63,
  227. .step = 1,
  228. #define SHARPNESS_DEF 0
  229. .default_value = SHARPNESS_DEF,
  230. },
  231. .set = sd_setsharpness,
  232. .get = sd_getsharpness,
  233. },
  234. { /* 10 */
  235. {
  236. .id = V4L2_CID_HFLIP,
  237. .type = V4L2_CTRL_TYPE_BOOLEAN,
  238. .name = "HFlip",
  239. .minimum = 0,
  240. .maximum = 1,
  241. .step = 1,
  242. #define HFLIP_DEF 0
  243. .default_value = HFLIP_DEF,
  244. },
  245. .set = sd_sethflip,
  246. .get = sd_gethflip,
  247. },
  248. { /* 11 */
  249. {
  250. .id = V4L2_CID_VFLIP,
  251. .type = V4L2_CTRL_TYPE_BOOLEAN,
  252. .name = "VFlip",
  253. .minimum = 0,
  254. .maximum = 1,
  255. .step = 1,
  256. #define VFLIP_DEF 0
  257. .default_value = VFLIP_DEF,
  258. },
  259. .set = sd_setvflip,
  260. .get = sd_getvflip,
  261. },
  262. };
  263. static struct ctrl sd_ctrls_ov965x[] = {
  264. };
  265. static const struct v4l2_pix_format ov772x_mode[] = {
  266. {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
  267. .bytesperline = 320 * 2,
  268. .sizeimage = 320 * 240 * 2,
  269. .colorspace = V4L2_COLORSPACE_SRGB,
  270. .priv = 1},
  271. {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
  272. .bytesperline = 640 * 2,
  273. .sizeimage = 640 * 480 * 2,
  274. .colorspace = V4L2_COLORSPACE_SRGB,
  275. .priv = 0},
  276. };
  277. static const struct v4l2_pix_format ov965x_mode[] = {
  278. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  279. .bytesperline = 320,
  280. .sizeimage = 320 * 240 * 3 / 8 + 590,
  281. .colorspace = V4L2_COLORSPACE_JPEG,
  282. .priv = 4},
  283. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  284. .bytesperline = 640,
  285. .sizeimage = 640 * 480 * 3 / 8 + 590,
  286. .colorspace = V4L2_COLORSPACE_JPEG,
  287. .priv = 3},
  288. {800, 600, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  289. .bytesperline = 800,
  290. .sizeimage = 800 * 600 * 3 / 8 + 590,
  291. .colorspace = V4L2_COLORSPACE_JPEG,
  292. .priv = 2},
  293. {1024, 768, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  294. .bytesperline = 1024,
  295. .sizeimage = 1024 * 768 * 3 / 8 + 590,
  296. .colorspace = V4L2_COLORSPACE_JPEG,
  297. .priv = 1},
  298. {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  299. .bytesperline = 1280,
  300. .sizeimage = 1280 * 1024 * 3 / 8 + 590,
  301. .colorspace = V4L2_COLORSPACE_JPEG,
  302. .priv = 0},
  303. };
  304. static const u8 bridge_init_ov772x[][2] = {
  305. { 0xc2, 0x0c },
  306. { 0x88, 0xf8 },
  307. { 0xc3, 0x69 },
  308. { 0x89, 0xff },
  309. { 0x76, 0x03 },
  310. { 0x92, 0x01 },
  311. { 0x93, 0x18 },
  312. { 0x94, 0x10 },
  313. { 0x95, 0x10 },
  314. { 0xe2, 0x00 },
  315. { 0xe7, 0x3e },
  316. { 0x96, 0x00 },
  317. { 0x97, 0x20 },
  318. { 0x97, 0x20 },
  319. { 0x97, 0x20 },
  320. { 0x97, 0x0a },
  321. { 0x97, 0x3f },
  322. { 0x97, 0x4a },
  323. { 0x97, 0x20 },
  324. { 0x97, 0x15 },
  325. { 0x97, 0x0b },
  326. { 0x8e, 0x40 },
  327. { 0x1f, 0x81 },
  328. { 0x34, 0x05 },
  329. { 0xe3, 0x04 },
  330. { 0x88, 0x00 },
  331. { 0x89, 0x00 },
  332. { 0x76, 0x00 },
  333. { 0xe7, 0x2e },
  334. { 0x31, 0xf9 },
  335. { 0x25, 0x42 },
  336. { 0x21, 0xf0 },
  337. { 0x1c, 0x00 },
  338. { 0x1d, 0x40 },
  339. { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
  340. { 0x1d, 0x00 }, /* payload size */
  341. { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
  342. { 0x1d, 0x58 }, /* frame size */
  343. { 0x1d, 0x00 }, /* frame size */
  344. { 0x1c, 0x0a },
  345. { 0x1d, 0x08 }, /* turn on UVC header */
  346. { 0x1d, 0x0e }, /* .. */
  347. { 0x8d, 0x1c },
  348. { 0x8e, 0x80 },
  349. { 0xe5, 0x04 },
  350. { 0xc0, 0x50 },
  351. { 0xc1, 0x3c },
  352. { 0xc2, 0x0c },
  353. };
  354. static const u8 sensor_init_ov772x[][2] = {
  355. { 0x12, 0x80 },
  356. { 0x11, 0x01 },
  357. /*fixme: better have a delay?*/
  358. { 0x11, 0x01 },
  359. { 0x11, 0x01 },
  360. { 0x11, 0x01 },
  361. { 0x11, 0x01 },
  362. { 0x11, 0x01 },
  363. { 0x11, 0x01 },
  364. { 0x11, 0x01 },
  365. { 0x11, 0x01 },
  366. { 0x11, 0x01 },
  367. { 0x11, 0x01 },
  368. { 0x3d, 0x03 },
  369. { 0x17, 0x26 },
  370. { 0x18, 0xa0 },
  371. { 0x19, 0x07 },
  372. { 0x1a, 0xf0 },
  373. { 0x32, 0x00 },
  374. { 0x29, 0xa0 },
  375. { 0x2c, 0xf0 },
  376. { 0x65, 0x20 },
  377. { 0x11, 0x01 },
  378. { 0x42, 0x7f },
  379. { 0x63, 0xaa }, /* AWB - was e0 */
  380. { 0x64, 0xff },
  381. { 0x66, 0x00 },
  382. { 0x13, 0xf0 }, /* com8 */
  383. { 0x0d, 0x41 },
  384. { 0x0f, 0xc5 },
  385. { 0x14, 0x11 },
  386. { 0x22, 0x7f },
  387. { 0x23, 0x03 },
  388. { 0x24, 0x40 },
  389. { 0x25, 0x30 },
  390. { 0x26, 0xa1 },
  391. { 0x2a, 0x00 },
  392. { 0x2b, 0x00 },
  393. { 0x6b, 0xaa },
  394. { 0x13, 0xff }, /* AWB */
  395. { 0x90, 0x05 },
  396. { 0x91, 0x01 },
  397. { 0x92, 0x03 },
  398. { 0x93, 0x00 },
  399. { 0x94, 0x60 },
  400. { 0x95, 0x3c },
  401. { 0x96, 0x24 },
  402. { 0x97, 0x1e },
  403. { 0x98, 0x62 },
  404. { 0x99, 0x80 },
  405. { 0x9a, 0x1e },
  406. { 0x9b, 0x08 },
  407. { 0x9c, 0x20 },
  408. { 0x9e, 0x81 },
  409. { 0xa6, 0x04 },
  410. { 0x7e, 0x0c },
  411. { 0x7f, 0x16 },
  412. { 0x80, 0x2a },
  413. { 0x81, 0x4e },
  414. { 0x82, 0x61 },
  415. { 0x83, 0x6f },
  416. { 0x84, 0x7b },
  417. { 0x85, 0x86 },
  418. { 0x86, 0x8e },
  419. { 0x87, 0x97 },
  420. { 0x88, 0xa4 },
  421. { 0x89, 0xaf },
  422. { 0x8a, 0xc5 },
  423. { 0x8b, 0xd7 },
  424. { 0x8c, 0xe8 },
  425. { 0x8d, 0x20 },
  426. { 0x0c, 0x90 },
  427. { 0x2b, 0x00 },
  428. { 0x22, 0x7f },
  429. { 0x23, 0x03 },
  430. { 0x11, 0x01 },
  431. { 0x0c, 0xd0 },
  432. { 0x64, 0xff },
  433. { 0x0d, 0x41 },
  434. { 0x14, 0x41 },
  435. { 0x0e, 0xcd },
  436. { 0xac, 0xbf },
  437. { 0x8e, 0x00 }, /* De-noise threshold */
  438. { 0x0c, 0xd0 }
  439. };
  440. static const u8 bridge_start_ov772x_vga[][2] = {
  441. {0x1c, 0x00},
  442. {0x1d, 0x40},
  443. {0x1d, 0x02},
  444. {0x1d, 0x00},
  445. {0x1d, 0x02},
  446. {0x1d, 0x58},
  447. {0x1d, 0x00},
  448. {0xc0, 0x50},
  449. {0xc1, 0x3c},
  450. };
  451. static const u8 sensor_start_ov772x_vga[][2] = {
  452. {0x12, 0x00},
  453. {0x17, 0x26},
  454. {0x18, 0xa0},
  455. {0x19, 0x07},
  456. {0x1a, 0xf0},
  457. {0x29, 0xa0},
  458. {0x2c, 0xf0},
  459. {0x65, 0x20},
  460. };
  461. static const u8 bridge_start_ov772x_qvga[][2] = {
  462. {0x1c, 0x00},
  463. {0x1d, 0x40},
  464. {0x1d, 0x02},
  465. {0x1d, 0x00},
  466. {0x1d, 0x01},
  467. {0x1d, 0x4b},
  468. {0x1d, 0x00},
  469. {0xc0, 0x28},
  470. {0xc1, 0x1e},
  471. };
  472. static const u8 sensor_start_ov772x_qvga[][2] = {
  473. {0x12, 0x40},
  474. {0x17, 0x3f},
  475. {0x18, 0x50},
  476. {0x19, 0x03},
  477. {0x1a, 0x78},
  478. {0x29, 0x50},
  479. {0x2c, 0x78},
  480. {0x65, 0x2f},
  481. };
  482. static const u8 bridge_init_ov965x[][2] = {
  483. {0x88, 0xf8},
  484. {0x89, 0xff},
  485. {0x76, 0x03},
  486. {0x92, 0x03},
  487. {0x95, 0x10},
  488. {0xe2, 0x00},
  489. {0xe7, 0x3e},
  490. {0x8d, 0x1c},
  491. {0x8e, 0x00},
  492. {0x8f, 0x00},
  493. {0x1f, 0x00},
  494. {0xc3, 0xf9},
  495. {0x89, 0xff},
  496. {0x88, 0xf8},
  497. {0x76, 0x03},
  498. {0x92, 0x01},
  499. {0x93, 0x18},
  500. {0x1c, 0x0a},
  501. {0x1d, 0x48},
  502. {0xc0, 0x50},
  503. {0xc1, 0x3c},
  504. {0x34, 0x05},
  505. {0xc2, 0x0c},
  506. {0xc3, 0xf9},
  507. {0x34, 0x05},
  508. {0xe7, 0x2e},
  509. {0x31, 0xf9},
  510. {0x35, 0x02},
  511. {0xd9, 0x10},
  512. {0x25, 0x42},
  513. {0x94, 0x11},
  514. };
  515. static const u8 sensor_init_ov965x[][2] = {
  516. {0x12, 0x80}, /* com7 - SSCB reset */
  517. {0x00, 0x00}, /* gain */
  518. {0x01, 0x80}, /* blue */
  519. {0x02, 0x80}, /* red */
  520. {0x03, 0x1b}, /* vref */
  521. {0x04, 0x03}, /* com1 - exposure low bits */
  522. {0x0b, 0x57}, /* ver */
  523. {0x0e, 0x61}, /* com5 */
  524. {0x0f, 0x42}, /* com6 */
  525. {0x11, 0x00}, /* clkrc */
  526. {0x12, 0x02}, /* com7 - 15fps VGA YUYV */
  527. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  528. {0x14, 0x28}, /* com9 */
  529. {0x16, 0x24}, /* reg16 */
  530. {0x17, 0x1d}, /* hstart*/
  531. {0x18, 0xbd}, /* hstop */
  532. {0x19, 0x01}, /* vstrt */
  533. {0x1a, 0x81}, /* vstop*/
  534. {0x1e, 0x04}, /* mvfp */
  535. {0x24, 0x3c}, /* aew */
  536. {0x25, 0x36}, /* aeb */
  537. {0x26, 0x71}, /* vpt */
  538. {0x27, 0x08}, /* bbias */
  539. {0x28, 0x08}, /* gbbias */
  540. {0x29, 0x15}, /* gr com */
  541. {0x2a, 0x00}, /* exhch */
  542. {0x2b, 0x00}, /* exhcl */
  543. {0x2c, 0x08}, /* rbias */
  544. {0x32, 0xff}, /* href */
  545. {0x33, 0x00}, /* chlf */
  546. {0x34, 0x3f}, /* aref1 */
  547. {0x35, 0x00}, /* aref2 */
  548. {0x36, 0xf8}, /* aref3 */
  549. {0x38, 0x72}, /* adc2 */
  550. {0x39, 0x57}, /* aref4 */
  551. {0x3a, 0x80}, /* tslb - yuyv */
  552. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  553. {0x3d, 0x99}, /* com13 */
  554. {0x3f, 0xc1}, /* edge */
  555. {0x40, 0xc0}, /* com15 */
  556. {0x41, 0x40}, /* com16 */
  557. {0x42, 0xc0}, /* com17 */
  558. {0x43, 0x0a}, /* rsvd */
  559. {0x44, 0xf0},
  560. {0x45, 0x46},
  561. {0x46, 0x62},
  562. {0x47, 0x2a},
  563. {0x48, 0x3c},
  564. {0x4a, 0xfc},
  565. {0x4b, 0xfc},
  566. {0x4c, 0x7f},
  567. {0x4d, 0x7f},
  568. {0x4e, 0x7f},
  569. {0x4f, 0x98}, /* matrix */
  570. {0x50, 0x98},
  571. {0x51, 0x00},
  572. {0x52, 0x28},
  573. {0x53, 0x70},
  574. {0x54, 0x98},
  575. {0x58, 0x1a}, /* matrix coef sign */
  576. {0x59, 0x85}, /* AWB control */
  577. {0x5a, 0xa9},
  578. {0x5b, 0x64},
  579. {0x5c, 0x84},
  580. {0x5d, 0x53},
  581. {0x5e, 0x0e},
  582. {0x5f, 0xf0}, /* AWB blue limit */
  583. {0x60, 0xf0}, /* AWB red limit */
  584. {0x61, 0xf0}, /* AWB green limit */
  585. {0x62, 0x00}, /* lcc1 */
  586. {0x63, 0x00}, /* lcc2 */
  587. {0x64, 0x02}, /* lcc3 */
  588. {0x65, 0x16}, /* lcc4 */
  589. {0x66, 0x01}, /* lcc5 */
  590. {0x69, 0x02}, /* hv */
  591. {0x6b, 0x5a}, /* dbvl */
  592. {0x6c, 0x04},
  593. {0x6d, 0x55},
  594. {0x6e, 0x00},
  595. {0x6f, 0x9d},
  596. {0x70, 0x21}, /* dnsth */
  597. {0x71, 0x78},
  598. {0x72, 0x00}, /* poidx */
  599. {0x73, 0x01}, /* pckdv */
  600. {0x74, 0x3a}, /* xindx */
  601. {0x75, 0x35}, /* yindx */
  602. {0x76, 0x01},
  603. {0x77, 0x02},
  604. {0x7a, 0x12}, /* gamma curve */
  605. {0x7b, 0x08},
  606. {0x7c, 0x16},
  607. {0x7d, 0x30},
  608. {0x7e, 0x5e},
  609. {0x7f, 0x72},
  610. {0x80, 0x82},
  611. {0x81, 0x8e},
  612. {0x82, 0x9a},
  613. {0x83, 0xa4},
  614. {0x84, 0xac},
  615. {0x85, 0xb8},
  616. {0x86, 0xc3},
  617. {0x87, 0xd6},
  618. {0x88, 0xe6},
  619. {0x89, 0xf2},
  620. {0x8a, 0x03},
  621. {0x8c, 0x89}, /* com19 */
  622. {0x14, 0x28}, /* com9 */
  623. {0x90, 0x7d},
  624. {0x91, 0x7b},
  625. {0x9d, 0x03}, /* lcc6 */
  626. {0x9e, 0x04}, /* lcc7 */
  627. {0x9f, 0x7a},
  628. {0xa0, 0x79},
  629. {0xa1, 0x40}, /* aechm */
  630. {0xa4, 0x50}, /* com21 */
  631. {0xa5, 0x68}, /* com26 */
  632. {0xa6, 0x4a}, /* AWB green */
  633. {0xa8, 0xc1}, /* refa8 */
  634. {0xa9, 0xef}, /* refa9 */
  635. {0xaa, 0x92},
  636. {0xab, 0x04},
  637. {0xac, 0x80}, /* black level control */
  638. {0xad, 0x80},
  639. {0xae, 0x80},
  640. {0xaf, 0x80},
  641. {0xb2, 0xf2},
  642. {0xb3, 0x20},
  643. {0xb4, 0x20}, /* ctrlb4 */
  644. {0xb5, 0x00},
  645. {0xb6, 0xaf},
  646. {0xbb, 0xae},
  647. {0xbc, 0x7f}, /* ADC channel offsets */
  648. {0xdb, 0x7f},
  649. {0xbe, 0x7f},
  650. {0xbf, 0x7f},
  651. {0xc0, 0xe2},
  652. {0xc1, 0xc0},
  653. {0xc2, 0x01},
  654. {0xc3, 0x4e},
  655. {0xc6, 0x85},
  656. {0xc7, 0x80}, /* com24 */
  657. {0xc9, 0xe0},
  658. {0xca, 0xe8},
  659. {0xcb, 0xf0},
  660. {0xcc, 0xd8},
  661. {0xcd, 0xf1},
  662. {0x4f, 0x98},
  663. {0x50, 0x98},
  664. {0x51, 0x00},
  665. {0x52, 0x28},
  666. {0x53, 0x70},
  667. {0x54, 0x98},
  668. {0x58, 0x1a},
  669. {0xff, 0x41}, /* read 41, write ff 00 */
  670. {0x41, 0x40}, /* com16 */
  671. {0xc5, 0x03}, /* 60 Hz banding filter */
  672. {0x6a, 0x02}, /* 50 Hz banding filter */
  673. {0x12, 0x62}, /* com7 - 30fps VGA YUV */
  674. {0x36, 0xfa}, /* aref3 */
  675. {0x69, 0x0a}, /* hv */
  676. {0x8c, 0x89}, /* com22 */
  677. {0x14, 0x28}, /* com9 */
  678. {0x3e, 0x0c},
  679. {0x41, 0x40}, /* com16 */
  680. {0x72, 0x00},
  681. {0x73, 0x00},
  682. {0x74, 0x3a},
  683. {0x75, 0x35},
  684. {0x76, 0x01},
  685. {0xc7, 0x80},
  686. {0x03, 0x12}, /* vref */
  687. {0x17, 0x16}, /* hstart */
  688. {0x18, 0x02}, /* hstop */
  689. {0x19, 0x01}, /* vstrt */
  690. {0x1a, 0x3d}, /* vstop */
  691. {0x32, 0xff}, /* href */
  692. {0xc0, 0xaa},
  693. };
  694. static const u8 bridge_init_ov965x_2[][2] = {
  695. {0x94, 0xaa},
  696. {0xf1, 0x60},
  697. {0xe5, 0x04},
  698. {0xc0, 0x50},
  699. {0xc1, 0x3c},
  700. {0x8c, 0x00},
  701. {0x8d, 0x1c},
  702. {0x34, 0x05},
  703. {0xc2, 0x0c},
  704. {0xc3, 0xf9},
  705. {0xda, 0x01},
  706. {0x50, 0x00},
  707. {0x51, 0xa0},
  708. {0x52, 0x3c},
  709. {0x53, 0x00},
  710. {0x54, 0x00},
  711. {0x55, 0x00}, /* brightness */
  712. {0x57, 0x00}, /* contrast 2 */
  713. {0x5c, 0x00},
  714. {0x5a, 0xa0},
  715. {0x5b, 0x78},
  716. {0x35, 0x02},
  717. {0xd9, 0x10},
  718. {0x94, 0x11},
  719. };
  720. static const u8 sensor_init_ov965x_2[][2] = {
  721. {0x3b, 0xc4},
  722. {0x1e, 0x04}, /* mvfp */
  723. {0x13, 0xe0}, /* com8 */
  724. {0x00, 0x00}, /* gain */
  725. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  726. {0x11, 0x03}, /* clkrc */
  727. {0x6b, 0x5a}, /* dblv */
  728. {0x6a, 0x05},
  729. {0xc5, 0x07},
  730. {0xa2, 0x4b},
  731. {0xa3, 0x3e},
  732. {0x2d, 0x00},
  733. {0xff, 0x42}, /* read 42, write ff 00 */
  734. {0x42, 0xc0},
  735. {0x2d, 0x00},
  736. {0xff, 0x42}, /* read 42, write ff 00 */
  737. {0x42, 0xc1},
  738. {0x3f, 0x01},
  739. {0xff, 0x42}, /* read 42, write ff 00 */
  740. {0x42, 0xc1},
  741. {0x4f, 0x98},
  742. {0x50, 0x98},
  743. {0x51, 0x00},
  744. {0x52, 0x28},
  745. {0x53, 0x70},
  746. {0x54, 0x98},
  747. {0x58, 0x1a},
  748. {0xff, 0x41}, /* read 41, write ff 00 */
  749. {0x41, 0x40}, /* com16 */
  750. {0x56, 0x40},
  751. {0x55, 0x8f},
  752. {0x10, 0x25}, /* aech - exposure high bits */
  753. {0xff, 0x13}, /* read 13, write ff 00 */
  754. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  755. };
  756. static const u8 sensor_start_ov965x_1_vga[][2] = { /* same for qvga */
  757. {0x12, 0x62}, /* com7 - 30fps VGA YUV */
  758. {0x36, 0xfa}, /* aref3 */
  759. {0x69, 0x0a}, /* hv */
  760. {0x8c, 0x89}, /* com22 */
  761. {0x14, 0x28}, /* com9 */
  762. {0x3e, 0x0c}, /* com14 */
  763. {0x41, 0x40}, /* com16 */
  764. {0x72, 0x00},
  765. {0x73, 0x00},
  766. {0x74, 0x3a},
  767. {0x75, 0x35},
  768. {0x76, 0x01},
  769. {0xc7, 0x80}, /* com24 */
  770. {0x03, 0x12}, /* vref */
  771. {0x17, 0x16}, /* hstart */
  772. {0x18, 0x02}, /* hstop */
  773. {0x19, 0x01}, /* vstrt */
  774. {0x1a, 0x3d}, /* vstop */
  775. {0x32, 0xff}, /* href */
  776. {0xc0, 0xaa},
  777. };
  778. static const u8 sensor_start_ov965x_1_svga[][2] = {
  779. {0x12, 0x02}, /* com7 - YUYV - VGA 15 full resolution */
  780. {0x36, 0xf8}, /* aref3 */
  781. {0x69, 0x02}, /* hv */
  782. {0x8c, 0x0d}, /* com22 */
  783. {0x3e, 0x0c}, /* com14 */
  784. {0x41, 0x40}, /* com16 */
  785. {0x72, 0x00},
  786. {0x73, 0x01},
  787. {0x74, 0x3a},
  788. {0x75, 0x35},
  789. {0x76, 0x01},
  790. {0xc7, 0x80}, /* com24 */
  791. {0x03, 0x1b}, /* vref */
  792. {0x17, 0x1d}, /* hstart */
  793. {0x18, 0xbd}, /* hstop */
  794. {0x19, 0x01}, /* vstrt */
  795. {0x1a, 0x81}, /* vstop */
  796. {0x32, 0xff}, /* href */
  797. {0xc0, 0xe2},
  798. };
  799. static const u8 sensor_start_ov965x_1_xga[][2] = {
  800. {0x12, 0x02}, /* com7 */
  801. {0x36, 0xf8}, /* aref3 */
  802. {0x69, 0x02}, /* hv */
  803. {0x8c, 0x89}, /* com22 */
  804. {0x14, 0x28}, /* com9 */
  805. {0x3e, 0x0c}, /* com14 */
  806. {0x41, 0x40}, /* com16 */
  807. {0x72, 0x00},
  808. {0x73, 0x01},
  809. {0x74, 0x3a},
  810. {0x75, 0x35},
  811. {0x76, 0x01},
  812. {0xc7, 0x80}, /* com24 */
  813. {0x03, 0x1b}, /* vref */
  814. {0x17, 0x1d}, /* hstart */
  815. {0x18, 0xbd}, /* hstop */
  816. {0x19, 0x01}, /* vstrt */
  817. {0x1a, 0x81}, /* vstop */
  818. {0x32, 0xff}, /* href */
  819. {0xc0, 0xe2},
  820. };
  821. static const u8 sensor_start_ov965x_1_sxga[][2] = {
  822. {0x12, 0x02}, /* com7 */
  823. {0x36, 0xf8}, /* aref3 */
  824. {0x69, 0x02}, /* hv */
  825. {0x8c, 0x89}, /* com22 */
  826. {0x14, 0x28}, /* com9 */
  827. {0x3e, 0x0c}, /* com14 */
  828. {0x41, 0x40}, /* com16 */
  829. {0x72, 0x00},
  830. {0x73, 0x01},
  831. {0x74, 0x3a},
  832. {0x75, 0x35},
  833. {0x76, 0x01},
  834. {0xc7, 0x80}, /* com24 */
  835. {0x03, 0x1b}, /* vref */
  836. {0x17, 0x1d}, /* hstart */
  837. {0x18, 0x02}, /* hstop */
  838. {0x19, 0x01}, /* vstrt */
  839. {0x1a, 0x81}, /* vstop */
  840. {0x32, 0xff}, /* href */
  841. {0xc0, 0xe2},
  842. };
  843. static const u8 bridge_start_ov965x_qvga[][2] = {
  844. {0x94, 0xaa},
  845. {0xf1, 0x60},
  846. {0xe5, 0x04},
  847. {0xc0, 0x50},
  848. {0xc1, 0x3c},
  849. {0x8c, 0x00},
  850. {0x8d, 0x1c},
  851. {0x34, 0x05},
  852. {0xc2, 0x4c},
  853. {0xc3, 0xf9},
  854. {0xda, 0x00},
  855. {0x50, 0x00},
  856. {0x51, 0xa0},
  857. {0x52, 0x78},
  858. {0x53, 0x00},
  859. {0x54, 0x00},
  860. {0x55, 0x00},
  861. {0x57, 0x00},
  862. {0x5c, 0x00},
  863. {0x5a, 0x50},
  864. {0x5b, 0x3c},
  865. {0x35, 0x02},
  866. {0xd9, 0x10},
  867. {0x94, 0x11},
  868. };
  869. static const u8 bridge_start_ov965x_vga[][2] = {
  870. {0x94, 0xaa},
  871. {0xf1, 0x60},
  872. {0xe5, 0x04},
  873. {0xc0, 0x50},
  874. {0xc1, 0x3c},
  875. {0x8c, 0x00},
  876. {0x8d, 0x1c},
  877. {0x34, 0x05},
  878. {0xc2, 0x0c},
  879. {0xc3, 0xf9},
  880. {0xda, 0x01},
  881. {0x50, 0x00},
  882. {0x51, 0xa0},
  883. {0x52, 0x3c},
  884. {0x53, 0x00},
  885. {0x54, 0x00},
  886. {0x55, 0x00},
  887. {0x57, 0x00},
  888. {0x5c, 0x00},
  889. {0x5a, 0xa0},
  890. {0x5b, 0x78},
  891. {0x35, 0x02},
  892. {0xd9, 0x10},
  893. {0x94, 0x11},
  894. };
  895. static const u8 bridge_start_ov965x_svga[][2] = {
  896. {0x94, 0xaa},
  897. {0xf1, 0x60},
  898. {0xe5, 0x04},
  899. {0xc0, 0xa0},
  900. {0xc1, 0x80},
  901. {0x8c, 0x00},
  902. {0x8d, 0x1c},
  903. {0x34, 0x05},
  904. {0xc2, 0x4c},
  905. {0xc3, 0xf9},
  906. {0x50, 0x00},
  907. {0x51, 0x40},
  908. {0x52, 0x00},
  909. {0x53, 0x00},
  910. {0x54, 0x00},
  911. {0x55, 0x88},
  912. {0x57, 0x00},
  913. {0x5c, 0x00},
  914. {0x5a, 0xc8},
  915. {0x5b, 0x96},
  916. {0x35, 0x02},
  917. {0xd9, 0x10},
  918. {0xda, 0x00},
  919. {0x94, 0x11},
  920. };
  921. static const u8 bridge_start_ov965x_xga[][2] = {
  922. {0x94, 0xaa},
  923. {0xf1, 0x60},
  924. {0xe5, 0x04},
  925. {0xc0, 0xa0},
  926. {0xc1, 0x80},
  927. {0x8c, 0x00},
  928. {0x8d, 0x1c},
  929. {0x34, 0x05},
  930. {0xc2, 0x4c},
  931. {0xc3, 0xf9},
  932. {0x50, 0x00},
  933. {0x51, 0x40},
  934. {0x52, 0x00},
  935. {0x53, 0x00},
  936. {0x54, 0x00},
  937. {0x55, 0x88},
  938. {0x57, 0x00},
  939. {0x5c, 0x01},
  940. {0x5a, 0x00},
  941. {0x5b, 0xc0},
  942. {0x35, 0x02},
  943. {0xd9, 0x10},
  944. {0xda, 0x01},
  945. {0x94, 0x11},
  946. };
  947. static const u8 bridge_start_ov965x_sxga[][2] = {
  948. {0x94, 0xaa},
  949. {0xf1, 0x60},
  950. {0xe5, 0x04},
  951. {0xc0, 0xa0},
  952. {0xc1, 0x80},
  953. {0x8c, 0x00},
  954. {0x8d, 0x1c},
  955. {0x34, 0x05},
  956. {0xc2, 0x0c},
  957. {0xc3, 0xf9},
  958. {0xda, 0x00},
  959. {0x35, 0x02},
  960. {0xd9, 0x10},
  961. {0x94, 0x11},
  962. };
  963. static const u8 sensor_start_ov965x_2_qvga[][2] = {
  964. {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */
  965. {0x1e, 0x04}, /* mvfp */
  966. {0x13, 0xe0}, /* com8 */
  967. {0x00, 0x00},
  968. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  969. {0x11, 0x01}, /* clkrc */
  970. {0x6b, 0x5a}, /* dblv */
  971. {0x6a, 0x02}, /* 50 Hz banding filter */
  972. {0xc5, 0x03}, /* 60 Hz banding filter */
  973. {0xa2, 0x96}, /* bd50 */
  974. {0xa3, 0x7d}, /* bd60 */
  975. {0xff, 0x13}, /* read 13, write ff 00 */
  976. {0x13, 0xe7},
  977. {0x3a, 0x80}, /* tslb - yuyv */
  978. };
  979. static const u8 sensor_start_ov965x_2_vga[][2] = {
  980. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  981. {0x1e, 0x04}, /* mvfp */
  982. {0x13, 0xe0}, /* com8 */
  983. {0x00, 0x00},
  984. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  985. {0x11, 0x03}, /* clkrc */
  986. {0x6b, 0x5a}, /* dblv */
  987. {0x6a, 0x05}, /* 50 Hz banding filter */
  988. {0xc5, 0x07}, /* 60 Hz banding filter */
  989. {0xa2, 0x4b}, /* bd50 */
  990. {0xa3, 0x3e}, /* bd60 */
  991. {0x2d, 0x00}, /* advfl */
  992. };
  993. static const u8 sensor_start_ov965x_2_svga[][2] = { /* same for xga */
  994. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  995. {0x1e, 0x04}, /* mvfp */
  996. {0x13, 0xe0}, /* com8 */
  997. {0x00, 0x00},
  998. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  999. {0x11, 0x01}, /* clkrc */
  1000. {0x6b, 0x5a}, /* dblv */
  1001. {0x6a, 0x0c}, /* 50 Hz banding filter */
  1002. {0xc5, 0x0f}, /* 60 Hz banding filter */
  1003. {0xa2, 0x4e}, /* bd50 */
  1004. {0xa3, 0x41}, /* bd60 */
  1005. {0x2d, 0x00}, /* advfl */
  1006. };
  1007. static const u8 sensor_start_ov965x_2_sxga[][2] = {
  1008. {0x13, 0xe0}, /* com8 */
  1009. {0x00, 0x00},
  1010. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  1011. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  1012. {0x1e, 0x04}, /* mvfp */
  1013. {0x11, 0x01}, /* clkrc */
  1014. {0x6b, 0x5a}, /* dblv */
  1015. {0x6a, 0x0c}, /* 50 Hz banding filter */
  1016. {0xc5, 0x0f}, /* 60 Hz banding filter */
  1017. {0xa2, 0x4e}, /* bd50 */
  1018. {0xa3, 0x41}, /* bd60 */
  1019. {0x2d, 0x00}, /* advfl */
  1020. };
  1021. static const u8 sensor_start_ov965x_2[][2] = {
  1022. {0xff, 0x42}, /* read 42, write ff 00 */
  1023. {0x42, 0xc1}, /* com17 - 50 Hz filter */
  1024. };
  1025. static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
  1026. {
  1027. struct usb_device *udev = gspca_dev->dev;
  1028. int ret;
  1029. PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
  1030. gspca_dev->usb_buf[0] = val;
  1031. ret = usb_control_msg(udev,
  1032. usb_sndctrlpipe(udev, 0),
  1033. 0x01,
  1034. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1035. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  1036. if (ret < 0)
  1037. PDEBUG(D_ERR, "write failed");
  1038. }
  1039. static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
  1040. {
  1041. struct usb_device *udev = gspca_dev->dev;
  1042. int ret;
  1043. ret = usb_control_msg(udev,
  1044. usb_rcvctrlpipe(udev, 0),
  1045. 0x01,
  1046. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1047. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  1048. PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
  1049. if (ret < 0)
  1050. PDEBUG(D_ERR, "read failed");
  1051. return gspca_dev->usb_buf[0];
  1052. }
  1053. /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
  1054. * (direction and output)? */
  1055. static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
  1056. {
  1057. u8 data;
  1058. PDEBUG(D_CONF, "led status: %d", status);
  1059. data = ov534_reg_read(gspca_dev, 0x21);
  1060. data |= 0x80;
  1061. ov534_reg_write(gspca_dev, 0x21, data);
  1062. data = ov534_reg_read(gspca_dev, 0x23);
  1063. if (status)
  1064. data |= 0x80;
  1065. else
  1066. data &= ~0x80;
  1067. ov534_reg_write(gspca_dev, 0x23, data);
  1068. if (!status) {
  1069. data = ov534_reg_read(gspca_dev, 0x21);
  1070. data &= ~0x80;
  1071. ov534_reg_write(gspca_dev, 0x21, data);
  1072. }
  1073. }
  1074. static int sccb_check_status(struct gspca_dev *gspca_dev)
  1075. {
  1076. u8 data;
  1077. int i;
  1078. for (i = 0; i < 5; i++) {
  1079. data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
  1080. switch (data) {
  1081. case 0x00:
  1082. return 1;
  1083. case 0x04:
  1084. return 0;
  1085. case 0x03:
  1086. break;
  1087. default:
  1088. PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
  1089. data, i + 1);
  1090. }
  1091. }
  1092. return 0;
  1093. }
  1094. static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  1095. {
  1096. PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val);
  1097. ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
  1098. ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
  1099. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
  1100. if (!sccb_check_status(gspca_dev))
  1101. PDEBUG(D_ERR, "sccb_reg_write failed");
  1102. }
  1103. static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
  1104. {
  1105. ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
  1106. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
  1107. if (!sccb_check_status(gspca_dev))
  1108. PDEBUG(D_ERR, "sccb_reg_read failed 1");
  1109. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
  1110. if (!sccb_check_status(gspca_dev))
  1111. PDEBUG(D_ERR, "sccb_reg_read failed 2");
  1112. return ov534_reg_read(gspca_dev, OV534_REG_READ);
  1113. }
  1114. /* output a bridge sequence (reg - val) */
  1115. static void reg_w_array(struct gspca_dev *gspca_dev,
  1116. const u8 (*data)[2], int len)
  1117. {
  1118. while (--len >= 0) {
  1119. ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
  1120. data++;
  1121. }
  1122. }
  1123. /* output a sensor sequence (reg - val) */
  1124. static void sccb_w_array(struct gspca_dev *gspca_dev,
  1125. const u8 (*data)[2], int len)
  1126. {
  1127. while (--len >= 0) {
  1128. if ((*data)[0] != 0xff) {
  1129. sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
  1130. } else {
  1131. sccb_reg_read(gspca_dev, (*data)[1]);
  1132. sccb_reg_write(gspca_dev, 0xff, 0x00);
  1133. }
  1134. data++;
  1135. }
  1136. }
  1137. /* ov772x specific controls */
  1138. static void set_frame_rate(struct gspca_dev *gspca_dev)
  1139. {
  1140. struct sd *sd = (struct sd *) gspca_dev;
  1141. int i;
  1142. struct rate_s {
  1143. u8 fps;
  1144. u8 r11;
  1145. u8 r0d;
  1146. u8 re5;
  1147. };
  1148. const struct rate_s *r;
  1149. static const struct rate_s rate_0[] = { /* 640x480 */
  1150. {60, 0x01, 0xc1, 0x04},
  1151. {50, 0x01, 0x41, 0x02},
  1152. {40, 0x02, 0xc1, 0x04},
  1153. {30, 0x04, 0x81, 0x02},
  1154. {15, 0x03, 0x41, 0x04},
  1155. };
  1156. static const struct rate_s rate_1[] = { /* 320x240 */
  1157. {125, 0x02, 0x81, 0x02},
  1158. {100, 0x02, 0xc1, 0x04},
  1159. {75, 0x03, 0xc1, 0x04},
  1160. {60, 0x04, 0xc1, 0x04},
  1161. {50, 0x02, 0x41, 0x04},
  1162. {40, 0x03, 0x41, 0x04},
  1163. {30, 0x04, 0x41, 0x04},
  1164. };
  1165. if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) {
  1166. r = rate_0;
  1167. i = ARRAY_SIZE(rate_0);
  1168. } else {
  1169. r = rate_1;
  1170. i = ARRAY_SIZE(rate_1);
  1171. }
  1172. while (--i > 0) {
  1173. if (sd->frame_rate >= r->fps)
  1174. break;
  1175. r++;
  1176. }
  1177. sccb_reg_write(gspca_dev, 0x11, r->r11);
  1178. sccb_reg_write(gspca_dev, 0x0d, r->r0d);
  1179. ov534_reg_write(gspca_dev, 0xe5, r->re5);
  1180. PDEBUG(D_PROBE, "frame_rate: %d", r->fps);
  1181. }
  1182. static void setbrightness(struct gspca_dev *gspca_dev)
  1183. {
  1184. struct sd *sd = (struct sd *) gspca_dev;
  1185. sccb_reg_write(gspca_dev, 0x9B, sd->brightness);
  1186. }
  1187. static void setcontrast(struct gspca_dev *gspca_dev)
  1188. {
  1189. struct sd *sd = (struct sd *) gspca_dev;
  1190. sccb_reg_write(gspca_dev, 0x9C, sd->contrast);
  1191. }
  1192. static void setgain(struct gspca_dev *gspca_dev)
  1193. {
  1194. struct sd *sd = (struct sd *) gspca_dev;
  1195. u8 val;
  1196. val = sd->gain;
  1197. switch (val & 0x30) {
  1198. case 0x00:
  1199. val &= 0x0f;
  1200. break;
  1201. case 0x10:
  1202. val &= 0x0f;
  1203. val |= 0x30;
  1204. break;
  1205. case 0x20:
  1206. val &= 0x0f;
  1207. val |= 0x70;
  1208. break;
  1209. default:
  1210. /* case 0x30: */
  1211. val &= 0x0f;
  1212. val |= 0xf0;
  1213. break;
  1214. }
  1215. sccb_reg_write(gspca_dev, 0x00, val);
  1216. }
  1217. static void setexposure(struct gspca_dev *gspca_dev)
  1218. {
  1219. struct sd *sd = (struct sd *) gspca_dev;
  1220. u8 val;
  1221. val = sd->exposure;
  1222. sccb_reg_write(gspca_dev, 0x08, val >> 7);
  1223. sccb_reg_write(gspca_dev, 0x10, val << 1);
  1224. }
  1225. static void setredblc(struct gspca_dev *gspca_dev)
  1226. {
  1227. struct sd *sd = (struct sd *) gspca_dev;
  1228. sccb_reg_write(gspca_dev, 0x43, sd->redblc);
  1229. }
  1230. static void setblueblc(struct gspca_dev *gspca_dev)
  1231. {
  1232. struct sd *sd = (struct sd *) gspca_dev;
  1233. sccb_reg_write(gspca_dev, 0x42, sd->blueblc);
  1234. }
  1235. static void sethue(struct gspca_dev *gspca_dev)
  1236. {
  1237. struct sd *sd = (struct sd *) gspca_dev;
  1238. sccb_reg_write(gspca_dev, 0x01, sd->hue);
  1239. }
  1240. static void setautogain(struct gspca_dev *gspca_dev)
  1241. {
  1242. struct sd *sd = (struct sd *) gspca_dev;
  1243. if (sd->autogain) {
  1244. sccb_reg_write(gspca_dev, 0x13, 0xf7); /* AGC,AEC,AWB ON */
  1245. sccb_reg_write(gspca_dev, 0x64,
  1246. sccb_reg_read(gspca_dev, 0x64) | 0x03);
  1247. } else {
  1248. sccb_reg_write(gspca_dev, 0x13, 0xf0); /* AGC,AEC,AWB OFF */
  1249. sccb_reg_write(gspca_dev, 0x64,
  1250. sccb_reg_read(gspca_dev, 0x64) & 0xfc);
  1251. }
  1252. }
  1253. static void setawb(struct gspca_dev *gspca_dev)
  1254. {
  1255. struct sd *sd = (struct sd *) gspca_dev;
  1256. if (sd->awb)
  1257. sccb_reg_write(gspca_dev, 0x63, 0xe0); /* AWB on */
  1258. else
  1259. sccb_reg_write(gspca_dev, 0x63, 0xaa); /* AWB off */
  1260. }
  1261. static void setsharpness(struct gspca_dev *gspca_dev)
  1262. {
  1263. struct sd *sd = (struct sd *) gspca_dev;
  1264. u8 val;
  1265. val = sd->sharpness;
  1266. sccb_reg_write(gspca_dev, 0x91, val); /* vga noise */
  1267. sccb_reg_write(gspca_dev, 0x8e, val); /* qvga noise */
  1268. }
  1269. static void sethflip(struct gspca_dev *gspca_dev)
  1270. {
  1271. struct sd *sd = (struct sd *) gspca_dev;
  1272. if (sd->hflip == 0)
  1273. sccb_reg_write(gspca_dev, 0x0c,
  1274. sccb_reg_read(gspca_dev, 0x0c) | 0x40);
  1275. else
  1276. sccb_reg_write(gspca_dev, 0x0c,
  1277. sccb_reg_read(gspca_dev, 0x0c) & 0xbf);
  1278. }
  1279. static void setvflip(struct gspca_dev *gspca_dev)
  1280. {
  1281. struct sd *sd = (struct sd *) gspca_dev;
  1282. if (sd->vflip == 0)
  1283. sccb_reg_write(gspca_dev, 0x0c,
  1284. sccb_reg_read(gspca_dev, 0x0c) | 0x80);
  1285. else
  1286. sccb_reg_write(gspca_dev, 0x0c,
  1287. sccb_reg_read(gspca_dev, 0x0c) & 0x7f);
  1288. }
  1289. /* this function is called at probe time */
  1290. static int sd_config(struct gspca_dev *gspca_dev,
  1291. const struct usb_device_id *id)
  1292. {
  1293. struct sd *sd = (struct sd *) gspca_dev;
  1294. struct cam *cam;
  1295. sd->sensor = id->driver_info;
  1296. cam = &gspca_dev->cam;
  1297. if (sd->sensor == SENSOR_OV772X) {
  1298. cam->cam_mode = ov772x_mode;
  1299. cam->nmodes = ARRAY_SIZE(ov772x_mode);
  1300. cam->bulk = 1;
  1301. cam->bulk_size = 16384;
  1302. cam->bulk_nurbs = 2;
  1303. } else { /* ov965x */
  1304. cam->cam_mode = ov965x_mode;
  1305. cam->nmodes = ARRAY_SIZE(ov965x_mode);
  1306. }
  1307. sd->frame_rate = 30;
  1308. sd->brightness = BRIGHTNESS_DEF;
  1309. sd->contrast = CONTRAST_DEF;
  1310. sd->gain = GAIN_DEF;
  1311. sd->exposure = EXPO_DEF;
  1312. sd->redblc = RED_BALANCE_DEF;
  1313. sd->blueblc = BLUE_BALANCE_DEF;
  1314. sd->hue = HUE_DEF;
  1315. #if AUTOGAIN_DEF != 0
  1316. sd->autogain = AUTOGAIN_DEF;
  1317. #else
  1318. gspca_dev->ctrl_inac |= (1 << AWB_IDX);
  1319. #endif
  1320. #if AWB_DEF != 0
  1321. sd->awb = AWB_DEF
  1322. #endif
  1323. sd->sharpness = SHARPNESS_DEF;
  1324. #if HFLIP_DEF != 0
  1325. sd->hflip = HFLIP_DEF;
  1326. #endif
  1327. #if VFLIP_DEF != 0
  1328. sd->vflip = VFLIP_DEF;
  1329. #endif
  1330. return 0;
  1331. }
  1332. /* this function is called at probe and resume time */
  1333. static int sd_init(struct gspca_dev *gspca_dev)
  1334. {
  1335. struct sd *sd = (struct sd *) gspca_dev;
  1336. u16 sensor_id;
  1337. static const u8 sensor_addr[2] = {
  1338. 0x42, /* 0 SENSOR_OV772X */
  1339. 0x60, /* 1 SENSOR_OV965X */
  1340. };
  1341. /* reset bridge */
  1342. ov534_reg_write(gspca_dev, 0xe7, 0x3a);
  1343. ov534_reg_write(gspca_dev, 0xe0, 0x08);
  1344. msleep(100);
  1345. /* initialize the sensor address */
  1346. ov534_reg_write(gspca_dev, OV534_REG_ADDRESS,
  1347. sensor_addr[sd->sensor]);
  1348. /* reset sensor */
  1349. sccb_reg_write(gspca_dev, 0x12, 0x80);
  1350. msleep(10);
  1351. /* probe the sensor */
  1352. sccb_reg_read(gspca_dev, 0x0a);
  1353. sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
  1354. sccb_reg_read(gspca_dev, 0x0b);
  1355. sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
  1356. PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
  1357. /* initialize */
  1358. switch (sd->sensor) {
  1359. case SENSOR_OV772X:
  1360. reg_w_array(gspca_dev, bridge_init_ov772x,
  1361. ARRAY_SIZE(bridge_init_ov772x));
  1362. ov534_set_led(gspca_dev, 1);
  1363. sccb_w_array(gspca_dev, sensor_init_ov772x,
  1364. ARRAY_SIZE(sensor_init_ov772x));
  1365. ov534_reg_write(gspca_dev, 0xe0, 0x09);
  1366. ov534_set_led(gspca_dev, 0);
  1367. set_frame_rate(gspca_dev);
  1368. break;
  1369. default:
  1370. /* case SENSOR_OV965X: */
  1371. reg_w_array(gspca_dev, bridge_init_ov965x,
  1372. ARRAY_SIZE(bridge_init_ov965x));
  1373. sccb_w_array(gspca_dev, sensor_init_ov965x,
  1374. ARRAY_SIZE(sensor_init_ov965x));
  1375. reg_w_array(gspca_dev, bridge_init_ov965x_2,
  1376. ARRAY_SIZE(bridge_init_ov965x_2));
  1377. sccb_w_array(gspca_dev, sensor_init_ov965x_2,
  1378. ARRAY_SIZE(sensor_init_ov965x_2));
  1379. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1380. ov534_reg_write(gspca_dev, 0xe0, 0x01);
  1381. ov534_set_led(gspca_dev, 0);
  1382. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1383. }
  1384. return 0;
  1385. }
  1386. static int sd_start_ov772x(struct gspca_dev *gspca_dev)
  1387. {
  1388. int mode;
  1389. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  1390. if (mode != 0) { /* 320x240 */
  1391. reg_w_array(gspca_dev, bridge_start_ov772x_qvga,
  1392. ARRAY_SIZE(bridge_start_ov772x_qvga));
  1393. sccb_w_array(gspca_dev, sensor_start_ov772x_qvga,
  1394. ARRAY_SIZE(sensor_start_ov772x_qvga));
  1395. } else { /* 640x480 */
  1396. reg_w_array(gspca_dev, bridge_start_ov772x_vga,
  1397. ARRAY_SIZE(bridge_start_ov772x_vga));
  1398. sccb_w_array(gspca_dev, sensor_start_ov772x_vga,
  1399. ARRAY_SIZE(sensor_start_ov772x_vga));
  1400. }
  1401. set_frame_rate(gspca_dev);
  1402. setautogain(gspca_dev);
  1403. setawb(gspca_dev);
  1404. setgain(gspca_dev);
  1405. setredblc(gspca_dev);
  1406. setblueblc(gspca_dev);
  1407. sethue(gspca_dev);
  1408. setexposure(gspca_dev);
  1409. setbrightness(gspca_dev);
  1410. setcontrast(gspca_dev);
  1411. setsharpness(gspca_dev);
  1412. setvflip(gspca_dev);
  1413. sethflip(gspca_dev);
  1414. ov534_set_led(gspca_dev, 1);
  1415. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1416. return 0;
  1417. }
  1418. static int sd_start_ov965x(struct gspca_dev *gspca_dev)
  1419. {
  1420. int mode;
  1421. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  1422. switch (mode) {
  1423. default:
  1424. /* case 4: * 320x240 */
  1425. sccb_w_array(gspca_dev, sensor_start_ov965x_1_vga,
  1426. ARRAY_SIZE(sensor_start_ov965x_1_vga));
  1427. reg_w_array(gspca_dev, bridge_start_ov965x_qvga,
  1428. ARRAY_SIZE(bridge_start_ov965x_qvga));
  1429. sccb_w_array(gspca_dev, sensor_start_ov965x_2_qvga,
  1430. ARRAY_SIZE(sensor_start_ov965x_2_qvga));
  1431. break;
  1432. case 3: /* 640x480 */
  1433. sccb_w_array(gspca_dev, sensor_start_ov965x_1_vga,
  1434. ARRAY_SIZE(sensor_start_ov965x_1_vga));
  1435. reg_w_array(gspca_dev, bridge_start_ov965x_vga,
  1436. ARRAY_SIZE(bridge_start_ov965x_vga));
  1437. sccb_w_array(gspca_dev, sensor_start_ov965x_2_vga,
  1438. ARRAY_SIZE(sensor_start_ov965x_2_vga));
  1439. break;
  1440. case 2: /* 800x600 */
  1441. sccb_w_array(gspca_dev, sensor_start_ov965x_1_svga,
  1442. ARRAY_SIZE(sensor_start_ov965x_1_svga));
  1443. reg_w_array(gspca_dev, bridge_start_ov965x_svga,
  1444. ARRAY_SIZE(bridge_start_ov965x_svga));
  1445. sccb_w_array(gspca_dev, sensor_start_ov965x_2_svga,
  1446. ARRAY_SIZE(sensor_start_ov965x_2_svga));
  1447. break;
  1448. case 1: /* 1024x768 */
  1449. sccb_w_array(gspca_dev, sensor_start_ov965x_1_xga,
  1450. ARRAY_SIZE(sensor_start_ov965x_1_xga));
  1451. reg_w_array(gspca_dev, bridge_start_ov965x_xga,
  1452. ARRAY_SIZE(bridge_start_ov965x_xga));
  1453. sccb_w_array(gspca_dev, sensor_start_ov965x_2_svga,
  1454. ARRAY_SIZE(sensor_start_ov965x_2_svga));
  1455. break;
  1456. case 0: /* 1280x1024 */
  1457. sccb_w_array(gspca_dev, sensor_start_ov965x_1_sxga,
  1458. ARRAY_SIZE(sensor_start_ov965x_1_sxga));
  1459. reg_w_array(gspca_dev, bridge_start_ov965x_sxga,
  1460. ARRAY_SIZE(bridge_start_ov965x_sxga));
  1461. sccb_w_array(gspca_dev, sensor_start_ov965x_2_sxga,
  1462. ARRAY_SIZE(sensor_start_ov965x_2_sxga));
  1463. break;
  1464. }
  1465. sccb_w_array(gspca_dev, sensor_start_ov965x_2,
  1466. ARRAY_SIZE(sensor_start_ov965x_2));
  1467. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1468. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1469. ov534_set_led(gspca_dev, 1);
  1470. return 0;
  1471. }
  1472. static void sd_stopN_ov772x(struct gspca_dev *gspca_dev)
  1473. {
  1474. ov534_reg_write(gspca_dev, 0xe0, 0x09);
  1475. ov534_set_led(gspca_dev, 0);
  1476. }
  1477. static void sd_stopN_ov965x(struct gspca_dev *gspca_dev)
  1478. {
  1479. ov534_reg_write(gspca_dev, 0xe0, 0x01);
  1480. ov534_set_led(gspca_dev, 0);
  1481. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1482. }
  1483. /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
  1484. #define UVC_STREAM_EOH (1 << 7)
  1485. #define UVC_STREAM_ERR (1 << 6)
  1486. #define UVC_STREAM_STI (1 << 5)
  1487. #define UVC_STREAM_RES (1 << 4)
  1488. #define UVC_STREAM_SCR (1 << 3)
  1489. #define UVC_STREAM_PTS (1 << 2)
  1490. #define UVC_STREAM_EOF (1 << 1)
  1491. #define UVC_STREAM_FID (1 << 0)
  1492. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1493. u8 *data, int len)
  1494. {
  1495. struct sd *sd = (struct sd *) gspca_dev;
  1496. __u32 this_pts;
  1497. u16 this_fid;
  1498. int remaining_len = len;
  1499. int payload_len;
  1500. payload_len = gspca_dev->cam.bulk ? 2048 : 2040;
  1501. do {
  1502. len = min(remaining_len, payload_len);
  1503. /* Payloads are prefixed with a UVC-style header. We
  1504. consider a frame to start when the FID toggles, or the PTS
  1505. changes. A frame ends when EOF is set, and we've received
  1506. the correct number of bytes. */
  1507. /* Verify UVC header. Header length is always 12 */
  1508. if (data[0] != 12 || len < 12) {
  1509. PDEBUG(D_PACK, "bad header");
  1510. goto discard;
  1511. }
  1512. /* Check errors */
  1513. if (data[1] & UVC_STREAM_ERR) {
  1514. PDEBUG(D_PACK, "payload error");
  1515. goto discard;
  1516. }
  1517. /* Extract PTS and FID */
  1518. if (!(data[1] & UVC_STREAM_PTS)) {
  1519. PDEBUG(D_PACK, "PTS not present");
  1520. goto discard;
  1521. }
  1522. this_pts = (data[5] << 24) | (data[4] << 16)
  1523. | (data[3] << 8) | data[2];
  1524. this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
  1525. /* If PTS or FID has changed, start a new frame. */
  1526. if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
  1527. if (gspca_dev->last_packet_type == INTER_PACKET)
  1528. gspca_frame_add(gspca_dev, LAST_PACKET,
  1529. NULL, 0);
  1530. sd->last_pts = this_pts;
  1531. sd->last_fid = this_fid;
  1532. gspca_frame_add(gspca_dev, FIRST_PACKET,
  1533. data + 12, len - 12);
  1534. /* If this packet is marked as EOF, end the frame */
  1535. } else if (data[1] & UVC_STREAM_EOF) {
  1536. sd->last_pts = 0;
  1537. gspca_frame_add(gspca_dev, LAST_PACKET,
  1538. data + 12, len - 12);
  1539. } else {
  1540. /* Add the data from this payload */
  1541. gspca_frame_add(gspca_dev, INTER_PACKET,
  1542. data + 12, len - 12);
  1543. }
  1544. /* Done this payload */
  1545. goto scan_next;
  1546. discard:
  1547. /* Discard data until a new frame starts. */
  1548. gspca_dev->last_packet_type = DISCARD_PACKET;
  1549. scan_next:
  1550. remaining_len -= len;
  1551. data += len;
  1552. } while (remaining_len > 0);
  1553. }
  1554. /* ov772x controls */
  1555. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  1556. {
  1557. struct sd *sd = (struct sd *) gspca_dev;
  1558. sd->gain = val;
  1559. if (gspca_dev->streaming)
  1560. setgain(gspca_dev);
  1561. return 0;
  1562. }
  1563. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  1564. {
  1565. struct sd *sd = (struct sd *) gspca_dev;
  1566. *val = sd->gain;
  1567. return 0;
  1568. }
  1569. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  1570. {
  1571. struct sd *sd = (struct sd *) gspca_dev;
  1572. sd->exposure = val;
  1573. if (gspca_dev->streaming)
  1574. setexposure(gspca_dev);
  1575. return 0;
  1576. }
  1577. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  1578. {
  1579. struct sd *sd = (struct sd *) gspca_dev;
  1580. *val = sd->exposure;
  1581. return 0;
  1582. }
  1583. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1584. {
  1585. struct sd *sd = (struct sd *) gspca_dev;
  1586. sd->brightness = val;
  1587. if (gspca_dev->streaming)
  1588. setbrightness(gspca_dev);
  1589. return 0;
  1590. }
  1591. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1592. {
  1593. struct sd *sd = (struct sd *) gspca_dev;
  1594. *val = sd->brightness;
  1595. return 0;
  1596. }
  1597. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1598. {
  1599. struct sd *sd = (struct sd *) gspca_dev;
  1600. sd->contrast = val;
  1601. if (gspca_dev->streaming)
  1602. setcontrast(gspca_dev);
  1603. return 0;
  1604. }
  1605. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1606. {
  1607. struct sd *sd = (struct sd *) gspca_dev;
  1608. *val = sd->contrast;
  1609. return 0;
  1610. }
  1611. static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val)
  1612. {
  1613. struct sd *sd = (struct sd *) gspca_dev;
  1614. sd->redblc = val;
  1615. if (gspca_dev->streaming)
  1616. setredblc(gspca_dev);
  1617. return 0;
  1618. }
  1619. static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val)
  1620. {
  1621. struct sd *sd = (struct sd *) gspca_dev;
  1622. *val = sd->redblc;
  1623. return 0;
  1624. }
  1625. static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val)
  1626. {
  1627. struct sd *sd = (struct sd *) gspca_dev;
  1628. sd->blueblc = val;
  1629. if (gspca_dev->streaming)
  1630. setblueblc(gspca_dev);
  1631. return 0;
  1632. }
  1633. static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val)
  1634. {
  1635. struct sd *sd = (struct sd *) gspca_dev;
  1636. *val = sd->blueblc;
  1637. return 0;
  1638. }
  1639. static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
  1640. {
  1641. struct sd *sd = (struct sd *) gspca_dev;
  1642. sd->hue = val;
  1643. if (gspca_dev->streaming)
  1644. sethue(gspca_dev);
  1645. return 0;
  1646. }
  1647. static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
  1648. {
  1649. struct sd *sd = (struct sd *) gspca_dev;
  1650. *val = sd->hue;
  1651. return 0;
  1652. }
  1653. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1654. {
  1655. struct sd *sd = (struct sd *) gspca_dev;
  1656. sd->autogain = val;
  1657. /* the auto white balance control works only when auto gain is set */
  1658. if (val)
  1659. gspca_dev->ctrl_inac &= ~(1 << AWB_IDX);
  1660. else
  1661. gspca_dev->ctrl_inac |= (1 << AWB_IDX);
  1662. if (gspca_dev->streaming)
  1663. setautogain(gspca_dev);
  1664. return 0;
  1665. }
  1666. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1667. {
  1668. struct sd *sd = (struct sd *) gspca_dev;
  1669. *val = sd->autogain;
  1670. return 0;
  1671. }
  1672. static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
  1673. {
  1674. struct sd *sd = (struct sd *) gspca_dev;
  1675. sd->awb = val;
  1676. if (gspca_dev->streaming)
  1677. setawb(gspca_dev);
  1678. return 0;
  1679. }
  1680. static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
  1681. {
  1682. struct sd *sd = (struct sd *) gspca_dev;
  1683. *val = sd->awb;
  1684. return 0;
  1685. }
  1686. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  1687. {
  1688. struct sd *sd = (struct sd *) gspca_dev;
  1689. sd->sharpness = val;
  1690. if (gspca_dev->streaming)
  1691. setsharpness(gspca_dev);
  1692. return 0;
  1693. }
  1694. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  1695. {
  1696. struct sd *sd = (struct sd *) gspca_dev;
  1697. *val = sd->sharpness;
  1698. return 0;
  1699. }
  1700. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
  1701. {
  1702. struct sd *sd = (struct sd *) gspca_dev;
  1703. sd->hflip = val;
  1704. if (gspca_dev->streaming)
  1705. sethflip(gspca_dev);
  1706. return 0;
  1707. }
  1708. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
  1709. {
  1710. struct sd *sd = (struct sd *) gspca_dev;
  1711. *val = sd->hflip;
  1712. return 0;
  1713. }
  1714. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
  1715. {
  1716. struct sd *sd = (struct sd *) gspca_dev;
  1717. sd->vflip = val;
  1718. if (gspca_dev->streaming)
  1719. setvflip(gspca_dev);
  1720. return 0;
  1721. }
  1722. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
  1723. {
  1724. struct sd *sd = (struct sd *) gspca_dev;
  1725. *val = sd->vflip;
  1726. return 0;
  1727. }
  1728. /* get stream parameters (framerate) */
  1729. static int sd_get_streamparm(struct gspca_dev *gspca_dev,
  1730. struct v4l2_streamparm *parm)
  1731. {
  1732. struct v4l2_captureparm *cp = &parm->parm.capture;
  1733. struct v4l2_fract *tpf = &cp->timeperframe;
  1734. struct sd *sd = (struct sd *) gspca_dev;
  1735. if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1736. return -EINVAL;
  1737. cp->capability |= V4L2_CAP_TIMEPERFRAME;
  1738. tpf->numerator = 1;
  1739. tpf->denominator = sd->frame_rate;
  1740. return 0;
  1741. }
  1742. /* set stream parameters (framerate) */
  1743. static int sd_set_streamparm(struct gspca_dev *gspca_dev,
  1744. struct v4l2_streamparm *parm)
  1745. {
  1746. struct v4l2_captureparm *cp = &parm->parm.capture;
  1747. struct v4l2_fract *tpf = &cp->timeperframe;
  1748. struct sd *sd = (struct sd *) gspca_dev;
  1749. if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1750. return -EINVAL;
  1751. /* Set requested framerate */
  1752. sd->frame_rate = tpf->denominator / tpf->numerator;
  1753. if (gspca_dev->streaming && sd->sensor == SENSOR_OV772X)
  1754. set_frame_rate(gspca_dev);
  1755. /* Return the actual framerate */
  1756. tpf->numerator = 1;
  1757. tpf->denominator = sd->frame_rate;
  1758. return 0;
  1759. }
  1760. /* sub-driver description */
  1761. static const struct sd_desc sd_desc_ov772x = {
  1762. .name = MODULE_NAME,
  1763. .ctrls = sd_ctrls_ov772x,
  1764. .nctrls = ARRAY_SIZE(sd_ctrls_ov772x),
  1765. .config = sd_config,
  1766. .init = sd_init,
  1767. .start = sd_start_ov772x,
  1768. .stopN = sd_stopN_ov772x,
  1769. .pkt_scan = sd_pkt_scan,
  1770. .get_streamparm = sd_get_streamparm,
  1771. .set_streamparm = sd_set_streamparm,
  1772. };
  1773. static const struct sd_desc sd_desc_ov965x = {
  1774. .name = MODULE_NAME,
  1775. .ctrls = sd_ctrls_ov965x,
  1776. .nctrls = ARRAY_SIZE(sd_ctrls_ov965x),
  1777. .config = sd_config,
  1778. .init = sd_init,
  1779. .start = sd_start_ov965x,
  1780. .stopN = sd_stopN_ov965x,
  1781. .pkt_scan = sd_pkt_scan,
  1782. .get_streamparm = sd_get_streamparm,
  1783. .set_streamparm = sd_set_streamparm,
  1784. };
  1785. /* -- module initialisation -- */
  1786. static const __devinitdata struct usb_device_id device_table[] = {
  1787. {USB_DEVICE(0x06f8, 0x3003), .driver_info = SENSOR_OV965X},
  1788. {USB_DEVICE(0x1415, 0x2000), .driver_info = SENSOR_OV772X},
  1789. {}
  1790. };
  1791. MODULE_DEVICE_TABLE(usb, device_table);
  1792. /* -- device connect -- */
  1793. static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1794. {
  1795. return gspca_dev_probe(intf, id,
  1796. id->driver_info == SENSOR_OV772X
  1797. ? &sd_desc_ov772x
  1798. : &sd_desc_ov965x,
  1799. sizeof(struct sd),
  1800. THIS_MODULE);
  1801. }
  1802. static struct usb_driver sd_driver = {
  1803. .name = MODULE_NAME,
  1804. .id_table = device_table,
  1805. .probe = sd_probe,
  1806. .disconnect = gspca_disconnect,
  1807. #ifdef CONFIG_PM
  1808. .suspend = gspca_suspend,
  1809. .resume = gspca_resume,
  1810. #endif
  1811. };
  1812. /* -- module insert / remove -- */
  1813. static int __init sd_mod_init(void)
  1814. {
  1815. int ret;
  1816. ret = usb_register(&sd_driver);
  1817. if (ret < 0)
  1818. return ret;
  1819. PDEBUG(D_PROBE, "registered");
  1820. return 0;
  1821. }
  1822. static void __exit sd_mod_exit(void)
  1823. {
  1824. usb_deregister(&sd_driver);
  1825. PDEBUG(D_PROBE, "deregistered");
  1826. }
  1827. module_init(sd_mod_init);
  1828. module_exit(sd_mod_exit);