ov534.c 53 KB

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