ov534.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046
  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. };
  779. static const u8 sensor_start_ov965x_1_svga[][2] = {
  780. {0x12, 0x02}, /* com7 - YUYV - VGA 15 full resolution */
  781. {0x36, 0xf8}, /* aref3 */
  782. {0x69, 0x02}, /* hv */
  783. {0x8c, 0x0d}, /* com22 */
  784. {0x3e, 0x0c}, /* com14 */
  785. {0x41, 0x40}, /* com16 */
  786. {0x72, 0x00},
  787. {0x73, 0x01},
  788. {0x74, 0x3a},
  789. {0x75, 0x35},
  790. {0x76, 0x01},
  791. {0xc7, 0x80}, /* com24 */
  792. {0x03, 0x1b}, /* vref */
  793. {0x17, 0x1d}, /* hstart */
  794. {0x18, 0xbd}, /* hstop */
  795. {0x19, 0x01}, /* vstrt */
  796. {0x1a, 0x81}, /* vstop */
  797. {0x32, 0xff}, /* href */
  798. {0xc0, 0xe2},
  799. {}
  800. };
  801. static const u8 sensor_start_ov965x_1_xga[][2] = {
  802. {0x12, 0x02}, /* com7 */
  803. {0x36, 0xf8}, /* aref3 */
  804. {0x69, 0x02}, /* hv */
  805. {0x8c, 0x89}, /* com22 */
  806. {0x14, 0x28}, /* com9 */
  807. {0x3e, 0x0c}, /* com14 */
  808. {0x41, 0x40}, /* com16 */
  809. {0x72, 0x00},
  810. {0x73, 0x01},
  811. {0x74, 0x3a},
  812. {0x75, 0x35},
  813. {0x76, 0x01},
  814. {0xc7, 0x80}, /* com24 */
  815. {0x03, 0x1b}, /* vref */
  816. {0x17, 0x1d}, /* hstart */
  817. {0x18, 0xbd}, /* hstop */
  818. {0x19, 0x01}, /* vstrt */
  819. {0x1a, 0x81}, /* vstop */
  820. {0x32, 0xff}, /* href */
  821. {0xc0, 0xe2},
  822. {}
  823. };
  824. static const u8 sensor_start_ov965x_1_sxga[][2] = {
  825. {0x12, 0x02}, /* com7 */
  826. {0x36, 0xf8}, /* aref3 */
  827. {0x69, 0x02}, /* hv */
  828. {0x8c, 0x89}, /* com22 */
  829. {0x14, 0x28}, /* com9 */
  830. {0x3e, 0x0c}, /* com14 */
  831. {0x41, 0x40}, /* com16 */
  832. {0x72, 0x00},
  833. {0x73, 0x01},
  834. {0x74, 0x3a},
  835. {0x75, 0x35},
  836. {0x76, 0x01},
  837. {0xc7, 0x80}, /* com24 */
  838. {0x03, 0x1b}, /* vref */
  839. {0x17, 0x1d}, /* hstart */
  840. {0x18, 0x02}, /* hstop */
  841. {0x19, 0x01}, /* vstrt */
  842. {0x1a, 0x81}, /* vstop */
  843. {0x32, 0xff}, /* href */
  844. {0xc0, 0xe2},
  845. {}
  846. };
  847. static const u8 bridge_start_ov965x_qvga[][2] = {
  848. {0x94, 0xaa},
  849. {0xf1, 0x60},
  850. {0xe5, 0x04},
  851. {0xc0, 0x50},
  852. {0xc1, 0x3c},
  853. {0x8c, 0x00},
  854. {0x8d, 0x1c},
  855. {0x34, 0x05},
  856. {0xc2, 0x4c},
  857. {0xc3, 0xf9},
  858. {0xda, 0x00},
  859. {0x50, 0x00},
  860. {0x51, 0xa0},
  861. {0x52, 0x78},
  862. {0x53, 0x00},
  863. {0x54, 0x00},
  864. {0x55, 0x00},
  865. {0x57, 0x00},
  866. {0x5c, 0x00},
  867. {0x5a, 0x50},
  868. {0x5b, 0x3c},
  869. {0x35, 0x02},
  870. {0xd9, 0x10},
  871. {0x94, 0x11},
  872. {}
  873. };
  874. static const u8 bridge_start_ov965x_vga[][2] = {
  875. {0x94, 0xaa},
  876. {0xf1, 0x60},
  877. {0xe5, 0x04},
  878. {0xc0, 0x50},
  879. {0xc1, 0x3c},
  880. {0x8c, 0x00},
  881. {0x8d, 0x1c},
  882. {0x34, 0x05},
  883. {0xc2, 0x0c},
  884. {0xc3, 0xf9},
  885. {0xda, 0x01},
  886. {0x50, 0x00},
  887. {0x51, 0xa0},
  888. {0x52, 0x3c},
  889. {0x53, 0x00},
  890. {0x54, 0x00},
  891. {0x55, 0x00},
  892. {0x57, 0x00},
  893. {0x5c, 0x00},
  894. {0x5a, 0xa0},
  895. {0x5b, 0x78},
  896. {0x35, 0x02},
  897. {0xd9, 0x10},
  898. {0x94, 0x11},
  899. {}
  900. };
  901. static const u8 bridge_start_ov965x_svga[][2] = {
  902. {0x94, 0xaa},
  903. {0xf1, 0x60},
  904. {0xe5, 0x04},
  905. {0xc0, 0xa0},
  906. {0xc1, 0x80},
  907. {0x8c, 0x00},
  908. {0x8d, 0x1c},
  909. {0x34, 0x05},
  910. {0xc2, 0x4c},
  911. {0xc3, 0xf9},
  912. {0x50, 0x00},
  913. {0x51, 0x40},
  914. {0x52, 0x00},
  915. {0x53, 0x00},
  916. {0x54, 0x00},
  917. {0x55, 0x88},
  918. {0x57, 0x00},
  919. {0x5c, 0x00},
  920. {0x5a, 0xc8},
  921. {0x5b, 0x96},
  922. {0x35, 0x02},
  923. {0xd9, 0x10},
  924. {0xda, 0x00},
  925. {0x94, 0x11},
  926. {}
  927. };
  928. static const u8 bridge_start_ov965x_xga[][2] = {
  929. {0x94, 0xaa},
  930. {0xf1, 0x60},
  931. {0xe5, 0x04},
  932. {0xc0, 0xa0},
  933. {0xc1, 0x80},
  934. {0x8c, 0x00},
  935. {0x8d, 0x1c},
  936. {0x34, 0x05},
  937. {0xc2, 0x4c},
  938. {0xc3, 0xf9},
  939. {0x50, 0x00},
  940. {0x51, 0x40},
  941. {0x52, 0x00},
  942. {0x53, 0x00},
  943. {0x54, 0x00},
  944. {0x55, 0x88},
  945. {0x57, 0x00},
  946. {0x5c, 0x01},
  947. {0x5a, 0x00},
  948. {0x5b, 0xc0},
  949. {0x35, 0x02},
  950. {0xd9, 0x10},
  951. {0xda, 0x01},
  952. {0x94, 0x11},
  953. {}
  954. };
  955. static const u8 bridge_start_ov965x_sxga[][2] = {
  956. {0x94, 0xaa},
  957. {0xf1, 0x60},
  958. {0xe5, 0x04},
  959. {0xc0, 0xa0},
  960. {0xc1, 0x80},
  961. {0x8c, 0x00},
  962. {0x8d, 0x1c},
  963. {0x34, 0x05},
  964. {0xc2, 0x0c},
  965. {0xc3, 0xf9},
  966. {0xda, 0x00},
  967. {0x35, 0x02},
  968. {0xd9, 0x10},
  969. {0x94, 0x11},
  970. {}
  971. };
  972. static const u8 sensor_start_ov965x_2_qvga[][2] = {
  973. {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */
  974. {0x1e, 0x04}, /* mvfp */
  975. {0x13, 0xe0}, /* com8 */
  976. {0x00, 0x00},
  977. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  978. {0x11, 0x01}, /* clkrc */
  979. {0x6b, 0x5a}, /* dblv */
  980. {0x6a, 0x02}, /* 50 Hz banding filter */
  981. {0xc5, 0x03}, /* 60 Hz banding filter */
  982. {0xa2, 0x96}, /* bd50 */
  983. {0xa3, 0x7d}, /* bd60 */
  984. {0xff, 0x13}, /* read 13, write ff 00 */
  985. {0x13, 0xe7},
  986. {0x3a, 0x80}, /* tslb - yuyv */
  987. {}
  988. };
  989. static const u8 sensor_start_ov965x_2_vga[][2] = {
  990. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  991. {0x1e, 0x04}, /* mvfp */
  992. {0x13, 0xe0}, /* com8 */
  993. {0x00, 0x00},
  994. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  995. {0x11, 0x03}, /* clkrc */
  996. {0x6b, 0x5a}, /* dblv */
  997. {0x6a, 0x05}, /* 50 Hz banding filter */
  998. {0xc5, 0x07}, /* 60 Hz banding filter */
  999. {0xa2, 0x4b}, /* bd50 */
  1000. {0xa3, 0x3e}, /* bd60 */
  1001. {0x2d, 0x00}, /* advfl */
  1002. {}
  1003. };
  1004. static const u8 sensor_start_ov965x_2_svga[][2] = { /* same for xga */
  1005. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  1006. {0x1e, 0x04}, /* mvfp */
  1007. {0x13, 0xe0}, /* com8 */
  1008. {0x00, 0x00},
  1009. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  1010. {0x11, 0x01}, /* clkrc */
  1011. {0x6b, 0x5a}, /* dblv */
  1012. {0x6a, 0x0c}, /* 50 Hz banding filter */
  1013. {0xc5, 0x0f}, /* 60 Hz banding filter */
  1014. {0xa2, 0x4e}, /* bd50 */
  1015. {0xa3, 0x41}, /* bd60 */
  1016. {0x2d, 0x00}, /* advfl */
  1017. {}
  1018. };
  1019. static const u8 sensor_start_ov965x_2_sxga[][2] = {
  1020. {0x13, 0xe0}, /* com8 */
  1021. {0x00, 0x00},
  1022. {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
  1023. {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
  1024. {0x1e, 0x04}, /* mvfp */
  1025. {0x11, 0x01}, /* clkrc */
  1026. {0x6b, 0x5a}, /* dblv */
  1027. {0x6a, 0x0c}, /* 50 Hz banding filter */
  1028. {0xc5, 0x0f}, /* 60 Hz banding filter */
  1029. {0xa2, 0x4e}, /* bd50 */
  1030. {0xa3, 0x41}, /* bd60 */
  1031. {0x2d, 0x00}, /* advfl */
  1032. {}
  1033. };
  1034. static const u8 sensor_start_ov965x_2[][2] = {
  1035. {0xff, 0x42}, /* read 42, write ff 00 */
  1036. {0x42, 0xc1}, /* com17 - 50 Hz filter */
  1037. {}
  1038. };
  1039. static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
  1040. {
  1041. struct usb_device *udev = gspca_dev->dev;
  1042. int ret;
  1043. PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
  1044. gspca_dev->usb_buf[0] = val;
  1045. ret = usb_control_msg(udev,
  1046. usb_sndctrlpipe(udev, 0),
  1047. 0x01,
  1048. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1049. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  1050. if (ret < 0)
  1051. PDEBUG(D_ERR, "write failed");
  1052. }
  1053. static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
  1054. {
  1055. struct usb_device *udev = gspca_dev->dev;
  1056. int ret;
  1057. ret = usb_control_msg(udev,
  1058. usb_rcvctrlpipe(udev, 0),
  1059. 0x01,
  1060. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1061. 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
  1062. PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
  1063. if (ret < 0)
  1064. PDEBUG(D_ERR, "read failed");
  1065. return gspca_dev->usb_buf[0];
  1066. }
  1067. /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
  1068. * (direction and output)? */
  1069. static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
  1070. {
  1071. u8 data;
  1072. PDEBUG(D_CONF, "led status: %d", status);
  1073. data = ov534_reg_read(gspca_dev, 0x21);
  1074. data |= 0x80;
  1075. ov534_reg_write(gspca_dev, 0x21, data);
  1076. data = ov534_reg_read(gspca_dev, 0x23);
  1077. if (status)
  1078. data |= 0x80;
  1079. else
  1080. data &= ~0x80;
  1081. ov534_reg_write(gspca_dev, 0x23, data);
  1082. if (!status) {
  1083. data = ov534_reg_read(gspca_dev, 0x21);
  1084. data &= ~0x80;
  1085. ov534_reg_write(gspca_dev, 0x21, data);
  1086. }
  1087. }
  1088. static int sccb_check_status(struct gspca_dev *gspca_dev)
  1089. {
  1090. u8 data;
  1091. int i;
  1092. for (i = 0; i < 5; i++) {
  1093. data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
  1094. switch (data) {
  1095. case 0x00:
  1096. return 1;
  1097. case 0x04:
  1098. return 0;
  1099. case 0x03:
  1100. break;
  1101. default:
  1102. PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
  1103. data, i + 1);
  1104. }
  1105. }
  1106. return 0;
  1107. }
  1108. static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  1109. {
  1110. PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val);
  1111. ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
  1112. ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
  1113. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
  1114. if (!sccb_check_status(gspca_dev))
  1115. PDEBUG(D_ERR, "sccb_reg_write failed");
  1116. }
  1117. static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
  1118. {
  1119. ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
  1120. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
  1121. if (!sccb_check_status(gspca_dev))
  1122. PDEBUG(D_ERR, "sccb_reg_read failed 1");
  1123. ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
  1124. if (!sccb_check_status(gspca_dev))
  1125. PDEBUG(D_ERR, "sccb_reg_read failed 2");
  1126. return ov534_reg_read(gspca_dev, OV534_REG_READ);
  1127. }
  1128. /* output a bridge sequence (reg - val) */
  1129. static void reg_w_array(struct gspca_dev *gspca_dev,
  1130. const u8 (*data)[2], int len)
  1131. {
  1132. while (--len >= 0) {
  1133. ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
  1134. data++;
  1135. }
  1136. }
  1137. /* output a sensor sequence (reg - val) */
  1138. static void sccb_w_array(struct gspca_dev *gspca_dev,
  1139. const u8 (*data)[2], int len)
  1140. {
  1141. while (--len >= 0) {
  1142. if ((*data)[0] != 0xff) {
  1143. sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
  1144. } else {
  1145. sccb_reg_read(gspca_dev, (*data)[1]);
  1146. sccb_reg_write(gspca_dev, 0xff, 0x00);
  1147. }
  1148. data++;
  1149. }
  1150. }
  1151. /* ov772x specific controls */
  1152. static void set_frame_rate(struct gspca_dev *gspca_dev)
  1153. {
  1154. struct sd *sd = (struct sd *) gspca_dev;
  1155. int i;
  1156. struct rate_s {
  1157. u8 fps;
  1158. u8 r11;
  1159. u8 r0d;
  1160. u8 re5;
  1161. };
  1162. const struct rate_s *r;
  1163. static const struct rate_s rate_0[] = { /* 640x480 */
  1164. {60, 0x01, 0xc1, 0x04},
  1165. {50, 0x01, 0x41, 0x02},
  1166. {40, 0x02, 0xc1, 0x04},
  1167. {30, 0x04, 0x81, 0x02},
  1168. {15, 0x03, 0x41, 0x04},
  1169. };
  1170. static const struct rate_s rate_1[] = { /* 320x240 */
  1171. {125, 0x02, 0x81, 0x02},
  1172. {100, 0x02, 0xc1, 0x04},
  1173. {75, 0x03, 0xc1, 0x04},
  1174. {60, 0x04, 0xc1, 0x04},
  1175. {50, 0x02, 0x41, 0x04},
  1176. {40, 0x03, 0x41, 0x04},
  1177. {30, 0x04, 0x41, 0x04},
  1178. };
  1179. if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) {
  1180. r = rate_0;
  1181. i = ARRAY_SIZE(rate_0);
  1182. } else {
  1183. r = rate_1;
  1184. i = ARRAY_SIZE(rate_1);
  1185. }
  1186. while (--i > 0) {
  1187. if (sd->frame_rate >= r->fps)
  1188. break;
  1189. r++;
  1190. }
  1191. sccb_reg_write(gspca_dev, 0x11, r->r11);
  1192. sccb_reg_write(gspca_dev, 0x0d, r->r0d);
  1193. ov534_reg_write(gspca_dev, 0xe5, r->re5);
  1194. PDEBUG(D_PROBE, "frame_rate: %d", r->fps);
  1195. }
  1196. static void setbrightness(struct gspca_dev *gspca_dev)
  1197. {
  1198. struct sd *sd = (struct sd *) gspca_dev;
  1199. sccb_reg_write(gspca_dev, 0x9B, sd->brightness);
  1200. }
  1201. static void setcontrast(struct gspca_dev *gspca_dev)
  1202. {
  1203. struct sd *sd = (struct sd *) gspca_dev;
  1204. sccb_reg_write(gspca_dev, 0x9C, sd->contrast);
  1205. }
  1206. static void setgain(struct gspca_dev *gspca_dev)
  1207. {
  1208. struct sd *sd = (struct sd *) gspca_dev;
  1209. u8 val;
  1210. val = sd->gain;
  1211. switch (val & 0x30) {
  1212. case 0x00:
  1213. val &= 0x0f;
  1214. break;
  1215. case 0x10:
  1216. val &= 0x0f;
  1217. val |= 0x30;
  1218. break;
  1219. case 0x20:
  1220. val &= 0x0f;
  1221. val |= 0x70;
  1222. break;
  1223. default:
  1224. /* case 0x30: */
  1225. val &= 0x0f;
  1226. val |= 0xf0;
  1227. break;
  1228. }
  1229. sccb_reg_write(gspca_dev, 0x00, val);
  1230. }
  1231. static void setexposure(struct gspca_dev *gspca_dev)
  1232. {
  1233. struct sd *sd = (struct sd *) gspca_dev;
  1234. u8 val;
  1235. val = sd->exposure;
  1236. sccb_reg_write(gspca_dev, 0x08, val >> 7);
  1237. sccb_reg_write(gspca_dev, 0x10, val << 1);
  1238. }
  1239. static void setredblc(struct gspca_dev *gspca_dev)
  1240. {
  1241. struct sd *sd = (struct sd *) gspca_dev;
  1242. sccb_reg_write(gspca_dev, 0x43, sd->redblc);
  1243. }
  1244. static void setblueblc(struct gspca_dev *gspca_dev)
  1245. {
  1246. struct sd *sd = (struct sd *) gspca_dev;
  1247. sccb_reg_write(gspca_dev, 0x42, sd->blueblc);
  1248. }
  1249. static void sethue(struct gspca_dev *gspca_dev)
  1250. {
  1251. struct sd *sd = (struct sd *) gspca_dev;
  1252. sccb_reg_write(gspca_dev, 0x01, sd->hue);
  1253. }
  1254. static void setautogain(struct gspca_dev *gspca_dev)
  1255. {
  1256. struct sd *sd = (struct sd *) gspca_dev;
  1257. if (sd->autogain) {
  1258. sccb_reg_write(gspca_dev, 0x13, 0xf7); /* AGC,AEC,AWB ON */
  1259. sccb_reg_write(gspca_dev, 0x64,
  1260. sccb_reg_read(gspca_dev, 0x64) | 0x03);
  1261. } else {
  1262. sccb_reg_write(gspca_dev, 0x13, 0xf0); /* AGC,AEC,AWB OFF */
  1263. sccb_reg_write(gspca_dev, 0x64,
  1264. sccb_reg_read(gspca_dev, 0x64) & 0xfc);
  1265. }
  1266. }
  1267. static void setawb(struct gspca_dev *gspca_dev)
  1268. {
  1269. struct sd *sd = (struct sd *) gspca_dev;
  1270. if (sd->awb)
  1271. sccb_reg_write(gspca_dev, 0x63, 0xe0); /* AWB on */
  1272. else
  1273. sccb_reg_write(gspca_dev, 0x63, 0xaa); /* AWB off */
  1274. }
  1275. static void setsharpness(struct gspca_dev *gspca_dev)
  1276. {
  1277. struct sd *sd = (struct sd *) gspca_dev;
  1278. u8 val;
  1279. val = sd->sharpness;
  1280. sccb_reg_write(gspca_dev, 0x91, val); /* vga noise */
  1281. sccb_reg_write(gspca_dev, 0x8e, val); /* qvga noise */
  1282. }
  1283. static void sethflip(struct gspca_dev *gspca_dev)
  1284. {
  1285. struct sd *sd = (struct sd *) gspca_dev;
  1286. if (sd->hflip == 0)
  1287. sccb_reg_write(gspca_dev, 0x0c,
  1288. sccb_reg_read(gspca_dev, 0x0c) | 0x40);
  1289. else
  1290. sccb_reg_write(gspca_dev, 0x0c,
  1291. sccb_reg_read(gspca_dev, 0x0c) & 0xbf);
  1292. }
  1293. static void setvflip(struct gspca_dev *gspca_dev)
  1294. {
  1295. struct sd *sd = (struct sd *) gspca_dev;
  1296. if (sd->vflip == 0)
  1297. sccb_reg_write(gspca_dev, 0x0c,
  1298. sccb_reg_read(gspca_dev, 0x0c) | 0x80);
  1299. else
  1300. sccb_reg_write(gspca_dev, 0x0c,
  1301. sccb_reg_read(gspca_dev, 0x0c) & 0x7f);
  1302. }
  1303. /* this function is called at probe time */
  1304. static int sd_config(struct gspca_dev *gspca_dev,
  1305. const struct usb_device_id *id)
  1306. {
  1307. struct sd *sd = (struct sd *) gspca_dev;
  1308. struct cam *cam;
  1309. sd->sensor = id->driver_info;
  1310. cam = &gspca_dev->cam;
  1311. if (sd->sensor == SENSOR_OV772X) {
  1312. cam->cam_mode = ov772x_mode;
  1313. cam->nmodes = ARRAY_SIZE(ov772x_mode);
  1314. cam->bulk = 1;
  1315. cam->bulk_size = 16384;
  1316. cam->bulk_nurbs = 2;
  1317. } else { /* ov965x */
  1318. cam->cam_mode = ov965x_mode;
  1319. cam->nmodes = ARRAY_SIZE(ov965x_mode);
  1320. }
  1321. sd->frame_rate = 30;
  1322. sd->brightness = BRIGHTNESS_DEF;
  1323. sd->contrast = CONTRAST_DEF;
  1324. sd->gain = GAIN_DEF;
  1325. sd->exposure = EXPO_DEF;
  1326. sd->redblc = RED_BALANCE_DEF;
  1327. sd->blueblc = BLUE_BALANCE_DEF;
  1328. sd->hue = HUE_DEF;
  1329. #if AUTOGAIN_DEF != 0
  1330. sd->autogain = AUTOGAIN_DEF;
  1331. #else
  1332. gspca_dev->ctrl_inac |= (1 << AWB_IDX);
  1333. #endif
  1334. #if AWB_DEF != 0
  1335. sd->awb = AWB_DEF
  1336. #endif
  1337. sd->sharpness = SHARPNESS_DEF;
  1338. #if HFLIP_DEF != 0
  1339. sd->hflip = HFLIP_DEF;
  1340. #endif
  1341. #if VFLIP_DEF != 0
  1342. sd->vflip = VFLIP_DEF;
  1343. #endif
  1344. return 0;
  1345. }
  1346. /* this function is called at probe and resume time */
  1347. static int sd_init(struct gspca_dev *gspca_dev)
  1348. {
  1349. struct sd *sd = (struct sd *) gspca_dev;
  1350. u16 sensor_id;
  1351. static const u8 sensor_addr[2] = {
  1352. 0x42, /* 0 SENSOR_OV772X */
  1353. 0x60, /* 1 SENSOR_OV965X */
  1354. };
  1355. /* reset bridge */
  1356. ov534_reg_write(gspca_dev, 0xe7, 0x3a);
  1357. ov534_reg_write(gspca_dev, 0xe0, 0x08);
  1358. msleep(100);
  1359. /* initialize the sensor address */
  1360. ov534_reg_write(gspca_dev, OV534_REG_ADDRESS,
  1361. sensor_addr[sd->sensor]);
  1362. /* reset sensor */
  1363. sccb_reg_write(gspca_dev, 0x12, 0x80);
  1364. msleep(10);
  1365. /* probe the sensor */
  1366. sccb_reg_read(gspca_dev, 0x0a);
  1367. sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
  1368. sccb_reg_read(gspca_dev, 0x0b);
  1369. sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
  1370. PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
  1371. /* initialize */
  1372. switch (sd->sensor) {
  1373. case SENSOR_OV772X:
  1374. reg_w_array(gspca_dev, bridge_init_ov772x,
  1375. ARRAY_SIZE(bridge_init_ov772x));
  1376. ov534_set_led(gspca_dev, 1);
  1377. sccb_w_array(gspca_dev, sensor_init_ov772x,
  1378. ARRAY_SIZE(sensor_init_ov772x));
  1379. ov534_reg_write(gspca_dev, 0xe0, 0x09);
  1380. ov534_set_led(gspca_dev, 0);
  1381. set_frame_rate(gspca_dev);
  1382. break;
  1383. default:
  1384. /* case SENSOR_OV965X: */
  1385. reg_w_array(gspca_dev, bridge_init_ov965x,
  1386. ARRAY_SIZE(bridge_init_ov965x));
  1387. sccb_w_array(gspca_dev, sensor_init_ov965x,
  1388. ARRAY_SIZE(sensor_init_ov965x));
  1389. reg_w_array(gspca_dev, bridge_init_ov965x_2,
  1390. ARRAY_SIZE(bridge_init_ov965x_2));
  1391. sccb_w_array(gspca_dev, sensor_init_ov965x_2,
  1392. ARRAY_SIZE(sensor_init_ov965x_2));
  1393. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1394. ov534_reg_write(gspca_dev, 0xe0, 0x01);
  1395. ov534_set_led(gspca_dev, 0);
  1396. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1397. }
  1398. return 0;
  1399. }
  1400. static int sd_start_ov772x(struct gspca_dev *gspca_dev)
  1401. {
  1402. int mode;
  1403. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  1404. if (mode != 0) { /* 320x240 */
  1405. reg_w_array(gspca_dev, bridge_start_ov772x_qvga,
  1406. ARRAY_SIZE(bridge_start_ov772x_qvga));
  1407. sccb_w_array(gspca_dev, sensor_start_ov772x_qvga,
  1408. ARRAY_SIZE(sensor_start_ov772x_qvga));
  1409. } else { /* 640x480 */
  1410. reg_w_array(gspca_dev, bridge_start_ov772x_vga,
  1411. ARRAY_SIZE(bridge_start_ov772x_vga));
  1412. sccb_w_array(gspca_dev, sensor_start_ov772x_vga,
  1413. ARRAY_SIZE(sensor_start_ov772x_vga));
  1414. }
  1415. set_frame_rate(gspca_dev);
  1416. setautogain(gspca_dev);
  1417. setawb(gspca_dev);
  1418. setgain(gspca_dev);
  1419. setredblc(gspca_dev);
  1420. setblueblc(gspca_dev);
  1421. sethue(gspca_dev);
  1422. setexposure(gspca_dev);
  1423. setbrightness(gspca_dev);
  1424. setcontrast(gspca_dev);
  1425. setsharpness(gspca_dev);
  1426. setvflip(gspca_dev);
  1427. sethflip(gspca_dev);
  1428. ov534_set_led(gspca_dev, 1);
  1429. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1430. return 0;
  1431. }
  1432. static int sd_start_ov965x(struct gspca_dev *gspca_dev)
  1433. {
  1434. int mode;
  1435. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  1436. switch (mode) {
  1437. default:
  1438. /* case 4: * 320x240 */
  1439. sccb_w_array(gspca_dev, sensor_start_ov965x_1_vga,
  1440. ARRAY_SIZE(sensor_start_ov965x_1_vga));
  1441. reg_w_array(gspca_dev, bridge_start_ov965x_qvga,
  1442. ARRAY_SIZE(bridge_start_ov965x_qvga));
  1443. sccb_w_array(gspca_dev, sensor_start_ov965x_2_qvga,
  1444. ARRAY_SIZE(sensor_start_ov965x_2_qvga));
  1445. break;
  1446. case 3: /* 640x480 */
  1447. sccb_w_array(gspca_dev, sensor_start_ov965x_1_vga,
  1448. ARRAY_SIZE(sensor_start_ov965x_1_vga));
  1449. reg_w_array(gspca_dev, bridge_start_ov965x_vga,
  1450. ARRAY_SIZE(bridge_start_ov965x_vga));
  1451. sccb_w_array(gspca_dev, sensor_start_ov965x_2_vga,
  1452. ARRAY_SIZE(sensor_start_ov965x_2_vga));
  1453. break;
  1454. case 2: /* 800x600 */
  1455. sccb_w_array(gspca_dev, sensor_start_ov965x_1_svga,
  1456. ARRAY_SIZE(sensor_start_ov965x_1_svga));
  1457. reg_w_array(gspca_dev, bridge_start_ov965x_svga,
  1458. ARRAY_SIZE(bridge_start_ov965x_svga));
  1459. sccb_w_array(gspca_dev, sensor_start_ov965x_2_svga,
  1460. ARRAY_SIZE(sensor_start_ov965x_2_svga));
  1461. break;
  1462. case 1: /* 1024x768 */
  1463. sccb_w_array(gspca_dev, sensor_start_ov965x_1_xga,
  1464. ARRAY_SIZE(sensor_start_ov965x_1_xga));
  1465. reg_w_array(gspca_dev, bridge_start_ov965x_xga,
  1466. ARRAY_SIZE(bridge_start_ov965x_xga));
  1467. sccb_w_array(gspca_dev, sensor_start_ov965x_2_svga,
  1468. ARRAY_SIZE(sensor_start_ov965x_2_svga));
  1469. break;
  1470. case 0: /* 1280x1024 */
  1471. sccb_w_array(gspca_dev, sensor_start_ov965x_1_sxga,
  1472. ARRAY_SIZE(sensor_start_ov965x_1_sxga));
  1473. reg_w_array(gspca_dev, bridge_start_ov965x_sxga,
  1474. ARRAY_SIZE(bridge_start_ov965x_sxga));
  1475. sccb_w_array(gspca_dev, sensor_start_ov965x_2_sxga,
  1476. ARRAY_SIZE(sensor_start_ov965x_2_sxga));
  1477. break;
  1478. }
  1479. sccb_w_array(gspca_dev, sensor_start_ov965x_2,
  1480. ARRAY_SIZE(sensor_start_ov965x_2));
  1481. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1482. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1483. ov534_set_led(gspca_dev, 1);
  1484. return 0;
  1485. }
  1486. static void sd_stopN_ov772x(struct gspca_dev *gspca_dev)
  1487. {
  1488. ov534_reg_write(gspca_dev, 0xe0, 0x09);
  1489. ov534_set_led(gspca_dev, 0);
  1490. }
  1491. static void sd_stopN_ov965x(struct gspca_dev *gspca_dev)
  1492. {
  1493. ov534_reg_write(gspca_dev, 0xe0, 0x01);
  1494. ov534_set_led(gspca_dev, 0);
  1495. ov534_reg_write(gspca_dev, 0xe0, 0x00);
  1496. }
  1497. /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
  1498. #define UVC_STREAM_EOH (1 << 7)
  1499. #define UVC_STREAM_ERR (1 << 6)
  1500. #define UVC_STREAM_STI (1 << 5)
  1501. #define UVC_STREAM_RES (1 << 4)
  1502. #define UVC_STREAM_SCR (1 << 3)
  1503. #define UVC_STREAM_PTS (1 << 2)
  1504. #define UVC_STREAM_EOF (1 << 1)
  1505. #define UVC_STREAM_FID (1 << 0)
  1506. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1507. u8 *data, int len)
  1508. {
  1509. struct sd *sd = (struct sd *) gspca_dev;
  1510. __u32 this_pts;
  1511. u16 this_fid;
  1512. int remaining_len = len;
  1513. int payload_len;
  1514. payload_len = gspca_dev->cam.bulk ? 2048 : 2040;
  1515. do {
  1516. len = min(remaining_len, payload_len);
  1517. /* Payloads are prefixed with a UVC-style header. We
  1518. consider a frame to start when the FID toggles, or the PTS
  1519. changes. A frame ends when EOF is set, and we've received
  1520. the correct number of bytes. */
  1521. /* Verify UVC header. Header length is always 12 */
  1522. if (data[0] != 12 || len < 12) {
  1523. PDEBUG(D_PACK, "bad header");
  1524. goto discard;
  1525. }
  1526. /* Check errors */
  1527. if (data[1] & UVC_STREAM_ERR) {
  1528. PDEBUG(D_PACK, "payload error");
  1529. goto discard;
  1530. }
  1531. /* Extract PTS and FID */
  1532. if (!(data[1] & UVC_STREAM_PTS)) {
  1533. PDEBUG(D_PACK, "PTS not present");
  1534. goto discard;
  1535. }
  1536. this_pts = (data[5] << 24) | (data[4] << 16)
  1537. | (data[3] << 8) | data[2];
  1538. this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
  1539. /* If PTS or FID has changed, start a new frame. */
  1540. if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
  1541. if (gspca_dev->last_packet_type == INTER_PACKET)
  1542. gspca_frame_add(gspca_dev, LAST_PACKET,
  1543. NULL, 0);
  1544. sd->last_pts = this_pts;
  1545. sd->last_fid = this_fid;
  1546. gspca_frame_add(gspca_dev, FIRST_PACKET,
  1547. data + 12, len - 12);
  1548. /* If this packet is marked as EOF, end the frame */
  1549. } else if (data[1] & UVC_STREAM_EOF) {
  1550. sd->last_pts = 0;
  1551. gspca_frame_add(gspca_dev, LAST_PACKET,
  1552. data + 12, len - 12);
  1553. } else {
  1554. /* Add the data from this payload */
  1555. gspca_frame_add(gspca_dev, INTER_PACKET,
  1556. data + 12, len - 12);
  1557. }
  1558. /* Done this payload */
  1559. goto scan_next;
  1560. discard:
  1561. /* Discard data until a new frame starts. */
  1562. gspca_dev->last_packet_type = DISCARD_PACKET;
  1563. scan_next:
  1564. remaining_len -= len;
  1565. data += len;
  1566. } while (remaining_len > 0);
  1567. }
  1568. /* ov772x controls */
  1569. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  1570. {
  1571. struct sd *sd = (struct sd *) gspca_dev;
  1572. sd->gain = val;
  1573. if (gspca_dev->streaming)
  1574. setgain(gspca_dev);
  1575. return 0;
  1576. }
  1577. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  1578. {
  1579. struct sd *sd = (struct sd *) gspca_dev;
  1580. *val = sd->gain;
  1581. return 0;
  1582. }
  1583. static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
  1584. {
  1585. struct sd *sd = (struct sd *) gspca_dev;
  1586. sd->exposure = val;
  1587. if (gspca_dev->streaming)
  1588. setexposure(gspca_dev);
  1589. return 0;
  1590. }
  1591. static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
  1592. {
  1593. struct sd *sd = (struct sd *) gspca_dev;
  1594. *val = sd->exposure;
  1595. return 0;
  1596. }
  1597. static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
  1598. {
  1599. struct sd *sd = (struct sd *) gspca_dev;
  1600. sd->brightness = val;
  1601. if (gspca_dev->streaming)
  1602. setbrightness(gspca_dev);
  1603. return 0;
  1604. }
  1605. static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
  1606. {
  1607. struct sd *sd = (struct sd *) gspca_dev;
  1608. *val = sd->brightness;
  1609. return 0;
  1610. }
  1611. static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
  1612. {
  1613. struct sd *sd = (struct sd *) gspca_dev;
  1614. sd->contrast = val;
  1615. if (gspca_dev->streaming)
  1616. setcontrast(gspca_dev);
  1617. return 0;
  1618. }
  1619. static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
  1620. {
  1621. struct sd *sd = (struct sd *) gspca_dev;
  1622. *val = sd->contrast;
  1623. return 0;
  1624. }
  1625. static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val)
  1626. {
  1627. struct sd *sd = (struct sd *) gspca_dev;
  1628. sd->redblc = val;
  1629. if (gspca_dev->streaming)
  1630. setredblc(gspca_dev);
  1631. return 0;
  1632. }
  1633. static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val)
  1634. {
  1635. struct sd *sd = (struct sd *) gspca_dev;
  1636. *val = sd->redblc;
  1637. return 0;
  1638. }
  1639. static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val)
  1640. {
  1641. struct sd *sd = (struct sd *) gspca_dev;
  1642. sd->blueblc = val;
  1643. if (gspca_dev->streaming)
  1644. setblueblc(gspca_dev);
  1645. return 0;
  1646. }
  1647. static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val)
  1648. {
  1649. struct sd *sd = (struct sd *) gspca_dev;
  1650. *val = sd->blueblc;
  1651. return 0;
  1652. }
  1653. static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
  1654. {
  1655. struct sd *sd = (struct sd *) gspca_dev;
  1656. sd->hue = val;
  1657. if (gspca_dev->streaming)
  1658. sethue(gspca_dev);
  1659. return 0;
  1660. }
  1661. static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
  1662. {
  1663. struct sd *sd = (struct sd *) gspca_dev;
  1664. *val = sd->hue;
  1665. return 0;
  1666. }
  1667. static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
  1668. {
  1669. struct sd *sd = (struct sd *) gspca_dev;
  1670. sd->autogain = val;
  1671. /* the auto white balance control works only when auto gain is set */
  1672. if (val)
  1673. gspca_dev->ctrl_inac &= ~(1 << AWB_IDX);
  1674. else
  1675. gspca_dev->ctrl_inac |= (1 << AWB_IDX);
  1676. if (gspca_dev->streaming)
  1677. setautogain(gspca_dev);
  1678. return 0;
  1679. }
  1680. static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
  1681. {
  1682. struct sd *sd = (struct sd *) gspca_dev;
  1683. *val = sd->autogain;
  1684. return 0;
  1685. }
  1686. static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
  1687. {
  1688. struct sd *sd = (struct sd *) gspca_dev;
  1689. sd->awb = val;
  1690. if (gspca_dev->streaming)
  1691. setawb(gspca_dev);
  1692. return 0;
  1693. }
  1694. static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
  1695. {
  1696. struct sd *sd = (struct sd *) gspca_dev;
  1697. *val = sd->awb;
  1698. return 0;
  1699. }
  1700. static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
  1701. {
  1702. struct sd *sd = (struct sd *) gspca_dev;
  1703. sd->sharpness = val;
  1704. if (gspca_dev->streaming)
  1705. setsharpness(gspca_dev);
  1706. return 0;
  1707. }
  1708. static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
  1709. {
  1710. struct sd *sd = (struct sd *) gspca_dev;
  1711. *val = sd->sharpness;
  1712. return 0;
  1713. }
  1714. static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
  1715. {
  1716. struct sd *sd = (struct sd *) gspca_dev;
  1717. sd->hflip = val;
  1718. if (gspca_dev->streaming)
  1719. sethflip(gspca_dev);
  1720. return 0;
  1721. }
  1722. static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
  1723. {
  1724. struct sd *sd = (struct sd *) gspca_dev;
  1725. *val = sd->hflip;
  1726. return 0;
  1727. }
  1728. static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
  1729. {
  1730. struct sd *sd = (struct sd *) gspca_dev;
  1731. sd->vflip = val;
  1732. if (gspca_dev->streaming)
  1733. setvflip(gspca_dev);
  1734. return 0;
  1735. }
  1736. static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
  1737. {
  1738. struct sd *sd = (struct sd *) gspca_dev;
  1739. *val = sd->vflip;
  1740. return 0;
  1741. }
  1742. /* get stream parameters (framerate) */
  1743. static int sd_get_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. cp->capability |= V4L2_CAP_TIMEPERFRAME;
  1752. tpf->numerator = 1;
  1753. tpf->denominator = sd->frame_rate;
  1754. return 0;
  1755. }
  1756. /* set stream parameters (framerate) */
  1757. static int sd_set_streamparm(struct gspca_dev *gspca_dev,
  1758. struct v4l2_streamparm *parm)
  1759. {
  1760. struct v4l2_captureparm *cp = &parm->parm.capture;
  1761. struct v4l2_fract *tpf = &cp->timeperframe;
  1762. struct sd *sd = (struct sd *) gspca_dev;
  1763. if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1764. return -EINVAL;
  1765. /* Set requested framerate */
  1766. sd->frame_rate = tpf->denominator / tpf->numerator;
  1767. if (gspca_dev->streaming && sd->sensor == SENSOR_OV772X)
  1768. set_frame_rate(gspca_dev);
  1769. /* Return the actual framerate */
  1770. tpf->numerator = 1;
  1771. tpf->denominator = sd->frame_rate;
  1772. return 0;
  1773. }
  1774. /* sub-driver description */
  1775. static const struct sd_desc sd_desc_ov772x = {
  1776. .name = MODULE_NAME,
  1777. .ctrls = sd_ctrls_ov772x,
  1778. .nctrls = ARRAY_SIZE(sd_ctrls_ov772x),
  1779. .config = sd_config,
  1780. .init = sd_init,
  1781. .start = sd_start_ov772x,
  1782. .stopN = sd_stopN_ov772x,
  1783. .pkt_scan = sd_pkt_scan,
  1784. .get_streamparm = sd_get_streamparm,
  1785. .set_streamparm = sd_set_streamparm,
  1786. };
  1787. static const struct sd_desc sd_desc_ov965x = {
  1788. .name = MODULE_NAME,
  1789. .ctrls = sd_ctrls_ov965x,
  1790. .nctrls = ARRAY_SIZE(sd_ctrls_ov965x),
  1791. .config = sd_config,
  1792. .init = sd_init,
  1793. .start = sd_start_ov965x,
  1794. .stopN = sd_stopN_ov965x,
  1795. .pkt_scan = sd_pkt_scan,
  1796. .get_streamparm = sd_get_streamparm,
  1797. .set_streamparm = sd_set_streamparm,
  1798. };
  1799. /* -- module initialisation -- */
  1800. static const __devinitdata struct usb_device_id device_table[] = {
  1801. {USB_DEVICE(0x06f8, 0x3003), .driver_info = SENSOR_OV965X},
  1802. {USB_DEVICE(0x1415, 0x2000), .driver_info = SENSOR_OV772X},
  1803. {}
  1804. };
  1805. MODULE_DEVICE_TABLE(usb, device_table);
  1806. /* -- device connect -- */
  1807. static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
  1808. {
  1809. return gspca_dev_probe(intf, id,
  1810. id->driver_info == SENSOR_OV772X
  1811. ? &sd_desc_ov772x
  1812. : &sd_desc_ov965x,
  1813. sizeof(struct sd),
  1814. THIS_MODULE);
  1815. }
  1816. static struct usb_driver sd_driver = {
  1817. .name = MODULE_NAME,
  1818. .id_table = device_table,
  1819. .probe = sd_probe,
  1820. .disconnect = gspca_disconnect,
  1821. #ifdef CONFIG_PM
  1822. .suspend = gspca_suspend,
  1823. .resume = gspca_resume,
  1824. #endif
  1825. };
  1826. /* -- module insert / remove -- */
  1827. static int __init sd_mod_init(void)
  1828. {
  1829. int ret;
  1830. ret = usb_register(&sd_driver);
  1831. if (ret < 0)
  1832. return ret;
  1833. PDEBUG(D_PROBE, "registered");
  1834. return 0;
  1835. }
  1836. static void __exit sd_mod_exit(void)
  1837. {
  1838. usb_deregister(&sd_driver);
  1839. PDEBUG(D_PROBE, "deregistered");
  1840. }
  1841. module_init(sd_mod_init);
  1842. module_exit(sd_mod_exit);