ov519.c 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548
  1. /**
  2. * OV519 driver
  3. *
  4. * Copyright (C) 2008 Jean-Francois Moine (http://moinejf.free.fr)
  5. * Copyright (C) 2009 Hans de Goede <hdegoede@redhat.com>
  6. *
  7. * This module is adapted from the ov51x-jpeg package, which itself
  8. * was adapted from the ov511 driver.
  9. *
  10. * Original copyright for the ov511 driver is:
  11. *
  12. * Copyright (c) 1999-2006 Mark W. McClelland
  13. * Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach
  14. * Many improvements by Bret Wallach <bwallac1@san.rr.com>
  15. * Color fixes by by Orion Sky Lawlor <olawlor@acm.org> (2/26/2000)
  16. * OV7620 fixes by Charl P. Botha <cpbotha@ieee.org>
  17. * Changes by Claudio Matsuoka <claudio@conectiva.com>
  18. *
  19. * ov51x-jpeg original copyright is:
  20. *
  21. * Copyright (c) 2004-2007 Romain Beauxis <toots@rastageeks.org>
  22. * Support for OV7670 sensors was contributed by Sam Skipsey <aoanla@yahoo.com>
  23. *
  24. * This program is free software; you can redistribute it and/or modify
  25. * it under the terms of the GNU General Public License as published by
  26. * the Free Software Foundation; either version 2 of the License, or
  27. * any later version.
  28. *
  29. * This program is distributed in the hope that it will be useful,
  30. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. * GNU General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU General Public License
  35. * along with this program; if not, write to the Free Software
  36. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  37. *
  38. */
  39. #define MODULE_NAME "ov519"
  40. #include <linux/input.h>
  41. #include "gspca.h"
  42. /* The jpeg_hdr is used by w996Xcf only */
  43. /* The CONEX_CAM define for jpeg.h needs renaming, now its used here too */
  44. #define CONEX_CAM
  45. #include "jpeg.h"
  46. MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
  47. MODULE_DESCRIPTION("OV519 USB Camera Driver");
  48. MODULE_LICENSE("GPL");
  49. /* global parameters */
  50. static int frame_rate;
  51. /* Number of times to retry a failed I2C transaction. Increase this if you
  52. * are getting "Failed to read sensor ID..." */
  53. static int i2c_detect_tries = 10;
  54. /* controls */
  55. enum e_ctrl {
  56. BRIGHTNESS,
  57. CONTRAST,
  58. COLORS,
  59. HFLIP,
  60. VFLIP,
  61. AUTOBRIGHT,
  62. FREQ,
  63. NCTRL /* number of controls */
  64. };
  65. /* ov519 device descriptor */
  66. struct sd {
  67. struct gspca_dev gspca_dev; /* !! must be the first item */
  68. struct gspca_ctrl ctrls[NCTRL];
  69. u8 packet_nr;
  70. char bridge;
  71. #define BRIDGE_OV511 0
  72. #define BRIDGE_OV511PLUS 1
  73. #define BRIDGE_OV518 2
  74. #define BRIDGE_OV518PLUS 3
  75. #define BRIDGE_OV519 4
  76. #define BRIDGE_OVFX2 5
  77. #define BRIDGE_W9968CF 6
  78. #define BRIDGE_MASK 7
  79. char invert_led;
  80. #define BRIDGE_INVERT_LED 8
  81. char snapshot_pressed;
  82. char snapshot_needs_reset;
  83. /* Determined by sensor type */
  84. u8 sif;
  85. u8 quality;
  86. #define QUALITY_MIN 50
  87. #define QUALITY_MAX 70
  88. #define QUALITY_DEF 50
  89. u8 stopped; /* Streaming is temporarily paused */
  90. u8 first_frame;
  91. u8 frame_rate; /* current Framerate */
  92. u8 clockdiv; /* clockdiv override */
  93. s8 sensor; /* Type of image sensor chip (SEN_*) */
  94. u8 sensor_addr;
  95. u16 sensor_width;
  96. u16 sensor_height;
  97. s16 sensor_reg_cache[256];
  98. u8 jpeg_hdr[JPEG_HDR_SZ];
  99. };
  100. enum sensors {
  101. SEN_OV2610,
  102. SEN_OV3610,
  103. SEN_OV6620,
  104. SEN_OV6630,
  105. SEN_OV66308AF,
  106. SEN_OV7610,
  107. SEN_OV7620,
  108. SEN_OV7620AE,
  109. SEN_OV7640,
  110. SEN_OV7648,
  111. SEN_OV7670,
  112. SEN_OV76BE,
  113. SEN_OV8610,
  114. };
  115. /* Note this is a bit of a hack, but the w9968cf driver needs the code for all
  116. the ov sensors which is already present here. When we have the time we
  117. really should move the sensor drivers to v4l2 sub drivers. */
  118. #include "w996Xcf.c"
  119. /* V4L2 controls supported by the driver */
  120. static void setbrightness(struct gspca_dev *gspca_dev);
  121. static void setcontrast(struct gspca_dev *gspca_dev);
  122. static void setcolors(struct gspca_dev *gspca_dev);
  123. static void sethvflip(struct gspca_dev *gspca_dev);
  124. static void setautobright(struct gspca_dev *gspca_dev);
  125. static void setfreq(struct gspca_dev *gspca_dev);
  126. static void setfreq_i(struct sd *sd);
  127. static const struct ctrl sd_ctrls[] = {
  128. [BRIGHTNESS] = {
  129. {
  130. .id = V4L2_CID_BRIGHTNESS,
  131. .type = V4L2_CTRL_TYPE_INTEGER,
  132. .name = "Brightness",
  133. .minimum = 0,
  134. .maximum = 255,
  135. .step = 1,
  136. .default_value = 127,
  137. },
  138. .set_control = setbrightness,
  139. },
  140. [CONTRAST] = {
  141. {
  142. .id = V4L2_CID_CONTRAST,
  143. .type = V4L2_CTRL_TYPE_INTEGER,
  144. .name = "Contrast",
  145. .minimum = 0,
  146. .maximum = 255,
  147. .step = 1,
  148. .default_value = 127,
  149. },
  150. .set_control = setcontrast,
  151. },
  152. [COLORS] = {
  153. {
  154. .id = V4L2_CID_SATURATION,
  155. .type = V4L2_CTRL_TYPE_INTEGER,
  156. .name = "Color",
  157. .minimum = 0,
  158. .maximum = 255,
  159. .step = 1,
  160. .default_value = 127,
  161. },
  162. .set_control = setcolors,
  163. },
  164. /* The flip controls work with ov7670 only */
  165. [HFLIP] = {
  166. {
  167. .id = V4L2_CID_HFLIP,
  168. .type = V4L2_CTRL_TYPE_BOOLEAN,
  169. .name = "Mirror",
  170. .minimum = 0,
  171. .maximum = 1,
  172. .step = 1,
  173. .default_value = 0,
  174. },
  175. .set_control = sethvflip,
  176. },
  177. [VFLIP] = {
  178. {
  179. .id = V4L2_CID_VFLIP,
  180. .type = V4L2_CTRL_TYPE_BOOLEAN,
  181. .name = "Vflip",
  182. .minimum = 0,
  183. .maximum = 1,
  184. .step = 1,
  185. .default_value = 0,
  186. },
  187. .set_control = sethvflip,
  188. },
  189. [AUTOBRIGHT] = {
  190. {
  191. .id = V4L2_CID_AUTOBRIGHTNESS,
  192. .type = V4L2_CTRL_TYPE_BOOLEAN,
  193. .name = "Auto Brightness",
  194. .minimum = 0,
  195. .maximum = 1,
  196. .step = 1,
  197. .default_value = 1,
  198. },
  199. .set_control = setautobright,
  200. },
  201. [FREQ] = {
  202. {
  203. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  204. .type = V4L2_CTRL_TYPE_MENU,
  205. .name = "Light frequency filter",
  206. .minimum = 0,
  207. .maximum = 2, /* 0: no flicker, 1: 50Hz, 2:60Hz, 3: auto */
  208. .step = 1,
  209. .default_value = 0,
  210. },
  211. .set_control = setfreq,
  212. },
  213. };
  214. /* table of the disabled controls */
  215. static const unsigned ctrl_dis[] = {
  216. [SEN_OV2610] = (1 << NCTRL) - 1, /* no control */
  217. [SEN_OV3610] = (1 << NCTRL) - 1, /* no control */
  218. [SEN_OV6620] = (1 << HFLIP) |
  219. (1 << VFLIP),
  220. [SEN_OV6630] = (1 << HFLIP) |
  221. (1 << VFLIP),
  222. [SEN_OV66308AF] = (1 << HFLIP) |
  223. (1 << VFLIP),
  224. [SEN_OV7610] = (1 << HFLIP) |
  225. (1 << VFLIP),
  226. [SEN_OV7620] = (1 << HFLIP) |
  227. (1 << VFLIP),
  228. [SEN_OV7620AE] = (1 << HFLIP) |
  229. (1 << VFLIP),
  230. [SEN_OV7640] = (1 << HFLIP) |
  231. (1 << VFLIP) |
  232. (1 << AUTOBRIGHT) |
  233. (1 << CONTRAST),
  234. [SEN_OV7648] = (1 << HFLIP) |
  235. (1 << VFLIP) |
  236. (1 << AUTOBRIGHT) |
  237. (1 << CONTRAST),
  238. [SEN_OV7670] = (1 << COLORS) |
  239. (1 << AUTOBRIGHT),
  240. [SEN_OV76BE] = (1 << HFLIP) |
  241. (1 << VFLIP),
  242. [SEN_OV8610] = (1 << HFLIP) |
  243. (1 << VFLIP) |
  244. (1 << FREQ),
  245. };
  246. static const struct v4l2_pix_format ov519_vga_mode[] = {
  247. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  248. .bytesperline = 320,
  249. .sizeimage = 320 * 240 * 3 / 8 + 590,
  250. .colorspace = V4L2_COLORSPACE_JPEG,
  251. .priv = 1},
  252. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  253. .bytesperline = 640,
  254. .sizeimage = 640 * 480 * 3 / 8 + 590,
  255. .colorspace = V4L2_COLORSPACE_JPEG,
  256. .priv = 0},
  257. };
  258. static const struct v4l2_pix_format ov519_sif_mode[] = {
  259. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  260. .bytesperline = 160,
  261. .sizeimage = 160 * 120 * 3 / 8 + 590,
  262. .colorspace = V4L2_COLORSPACE_JPEG,
  263. .priv = 3},
  264. {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  265. .bytesperline = 176,
  266. .sizeimage = 176 * 144 * 3 / 8 + 590,
  267. .colorspace = V4L2_COLORSPACE_JPEG,
  268. .priv = 1},
  269. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  270. .bytesperline = 320,
  271. .sizeimage = 320 * 240 * 3 / 8 + 590,
  272. .colorspace = V4L2_COLORSPACE_JPEG,
  273. .priv = 2},
  274. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  275. .bytesperline = 352,
  276. .sizeimage = 352 * 288 * 3 / 8 + 590,
  277. .colorspace = V4L2_COLORSPACE_JPEG,
  278. .priv = 0},
  279. };
  280. /* Note some of the sizeimage values for the ov511 / ov518 may seem
  281. larger then necessary, however they need to be this big as the ov511 /
  282. ov518 always fills the entire isoc frame, using 0 padding bytes when
  283. it doesn't have any data. So with low framerates the amount of data
  284. transfered can become quite large (libv4l will remove all the 0 padding
  285. in userspace). */
  286. static const struct v4l2_pix_format ov518_vga_mode[] = {
  287. {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
  288. .bytesperline = 320,
  289. .sizeimage = 320 * 240 * 3,
  290. .colorspace = V4L2_COLORSPACE_JPEG,
  291. .priv = 1},
  292. {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
  293. .bytesperline = 640,
  294. .sizeimage = 640 * 480 * 2,
  295. .colorspace = V4L2_COLORSPACE_JPEG,
  296. .priv = 0},
  297. };
  298. static const struct v4l2_pix_format ov518_sif_mode[] = {
  299. {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
  300. .bytesperline = 160,
  301. .sizeimage = 70000,
  302. .colorspace = V4L2_COLORSPACE_JPEG,
  303. .priv = 3},
  304. {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
  305. .bytesperline = 176,
  306. .sizeimage = 70000,
  307. .colorspace = V4L2_COLORSPACE_JPEG,
  308. .priv = 1},
  309. {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
  310. .bytesperline = 320,
  311. .sizeimage = 320 * 240 * 3,
  312. .colorspace = V4L2_COLORSPACE_JPEG,
  313. .priv = 2},
  314. {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
  315. .bytesperline = 352,
  316. .sizeimage = 352 * 288 * 3,
  317. .colorspace = V4L2_COLORSPACE_JPEG,
  318. .priv = 0},
  319. };
  320. static const struct v4l2_pix_format ov511_vga_mode[] = {
  321. {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
  322. .bytesperline = 320,
  323. .sizeimage = 320 * 240 * 3,
  324. .colorspace = V4L2_COLORSPACE_JPEG,
  325. .priv = 1},
  326. {640, 480, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
  327. .bytesperline = 640,
  328. .sizeimage = 640 * 480 * 2,
  329. .colorspace = V4L2_COLORSPACE_JPEG,
  330. .priv = 0},
  331. };
  332. static const struct v4l2_pix_format ov511_sif_mode[] = {
  333. {160, 120, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
  334. .bytesperline = 160,
  335. .sizeimage = 70000,
  336. .colorspace = V4L2_COLORSPACE_JPEG,
  337. .priv = 3},
  338. {176, 144, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
  339. .bytesperline = 176,
  340. .sizeimage = 70000,
  341. .colorspace = V4L2_COLORSPACE_JPEG,
  342. .priv = 1},
  343. {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
  344. .bytesperline = 320,
  345. .sizeimage = 320 * 240 * 3,
  346. .colorspace = V4L2_COLORSPACE_JPEG,
  347. .priv = 2},
  348. {352, 288, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
  349. .bytesperline = 352,
  350. .sizeimage = 352 * 288 * 3,
  351. .colorspace = V4L2_COLORSPACE_JPEG,
  352. .priv = 0},
  353. };
  354. static const struct v4l2_pix_format ovfx2_vga_mode[] = {
  355. {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  356. .bytesperline = 320,
  357. .sizeimage = 320 * 240,
  358. .colorspace = V4L2_COLORSPACE_SRGB,
  359. .priv = 1},
  360. {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  361. .bytesperline = 640,
  362. .sizeimage = 640 * 480,
  363. .colorspace = V4L2_COLORSPACE_SRGB,
  364. .priv = 0},
  365. };
  366. static const struct v4l2_pix_format ovfx2_cif_mode[] = {
  367. {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  368. .bytesperline = 160,
  369. .sizeimage = 160 * 120,
  370. .colorspace = V4L2_COLORSPACE_SRGB,
  371. .priv = 3},
  372. {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  373. .bytesperline = 176,
  374. .sizeimage = 176 * 144,
  375. .colorspace = V4L2_COLORSPACE_SRGB,
  376. .priv = 1},
  377. {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  378. .bytesperline = 320,
  379. .sizeimage = 320 * 240,
  380. .colorspace = V4L2_COLORSPACE_SRGB,
  381. .priv = 2},
  382. {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  383. .bytesperline = 352,
  384. .sizeimage = 352 * 288,
  385. .colorspace = V4L2_COLORSPACE_SRGB,
  386. .priv = 0},
  387. };
  388. static const struct v4l2_pix_format ovfx2_ov2610_mode[] = {
  389. {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  390. .bytesperline = 1600,
  391. .sizeimage = 1600 * 1200,
  392. .colorspace = V4L2_COLORSPACE_SRGB},
  393. };
  394. static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
  395. {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  396. .bytesperline = 640,
  397. .sizeimage = 640 * 480,
  398. .colorspace = V4L2_COLORSPACE_SRGB,
  399. .priv = 1},
  400. {800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  401. .bytesperline = 800,
  402. .sizeimage = 800 * 600,
  403. .colorspace = V4L2_COLORSPACE_SRGB,
  404. .priv = 1},
  405. {1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  406. .bytesperline = 1024,
  407. .sizeimage = 1024 * 768,
  408. .colorspace = V4L2_COLORSPACE_SRGB,
  409. .priv = 1},
  410. {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  411. .bytesperline = 1600,
  412. .sizeimage = 1600 * 1200,
  413. .colorspace = V4L2_COLORSPACE_SRGB,
  414. .priv = 0},
  415. {2048, 1536, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
  416. .bytesperline = 2048,
  417. .sizeimage = 2048 * 1536,
  418. .colorspace = V4L2_COLORSPACE_SRGB,
  419. .priv = 0},
  420. };
  421. /* Registers common to OV511 / OV518 */
  422. #define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
  423. #define R51x_SYS_RESET 0x50
  424. /* Reset type flags */
  425. #define OV511_RESET_OMNICE 0x08
  426. #define R51x_SYS_INIT 0x53
  427. #define R51x_SYS_SNAP 0x52
  428. #define R51x_SYS_CUST_ID 0x5f
  429. #define R51x_COMP_LUT_BEGIN 0x80
  430. /* OV511 Camera interface register numbers */
  431. #define R511_CAM_DELAY 0x10
  432. #define R511_CAM_EDGE 0x11
  433. #define R511_CAM_PXCNT 0x12
  434. #define R511_CAM_LNCNT 0x13
  435. #define R511_CAM_PXDIV 0x14
  436. #define R511_CAM_LNDIV 0x15
  437. #define R511_CAM_UV_EN 0x16
  438. #define R511_CAM_LINE_MODE 0x17
  439. #define R511_CAM_OPTS 0x18
  440. #define R511_SNAP_FRAME 0x19
  441. #define R511_SNAP_PXCNT 0x1a
  442. #define R511_SNAP_LNCNT 0x1b
  443. #define R511_SNAP_PXDIV 0x1c
  444. #define R511_SNAP_LNDIV 0x1d
  445. #define R511_SNAP_UV_EN 0x1e
  446. #define R511_SNAP_UV_EN 0x1e
  447. #define R511_SNAP_OPTS 0x1f
  448. #define R511_DRAM_FLOW_CTL 0x20
  449. #define R511_FIFO_OPTS 0x31
  450. #define R511_I2C_CTL 0x40
  451. #define R511_SYS_LED_CTL 0x55 /* OV511+ only */
  452. #define R511_COMP_EN 0x78
  453. #define R511_COMP_LUT_EN 0x79
  454. /* OV518 Camera interface register numbers */
  455. #define R518_GPIO_OUT 0x56 /* OV518(+) only */
  456. #define R518_GPIO_CTL 0x57 /* OV518(+) only */
  457. /* OV519 Camera interface register numbers */
  458. #define OV519_R10_H_SIZE 0x10
  459. #define OV519_R11_V_SIZE 0x11
  460. #define OV519_R12_X_OFFSETL 0x12
  461. #define OV519_R13_X_OFFSETH 0x13
  462. #define OV519_R14_Y_OFFSETL 0x14
  463. #define OV519_R15_Y_OFFSETH 0x15
  464. #define OV519_R16_DIVIDER 0x16
  465. #define OV519_R20_DFR 0x20
  466. #define OV519_R25_FORMAT 0x25
  467. /* OV519 System Controller register numbers */
  468. #define OV519_R51_RESET1 0x51
  469. #define OV519_R54_EN_CLK1 0x54
  470. #define OV519_GPIO_DATA_OUT0 0x71
  471. #define OV519_GPIO_IO_CTRL0 0x72
  472. /*#define OV511_ENDPOINT_ADDRESS 1 * Isoc endpoint number */
  473. /*
  474. * The FX2 chip does not give us a zero length read at end of frame.
  475. * It does, however, give a short read at the end of a frame, if
  476. * necessary, rather than run two frames together.
  477. *
  478. * By choosing the right bulk transfer size, we are guaranteed to always
  479. * get a short read for the last read of each frame. Frame sizes are
  480. * always a composite number (width * height, or a multiple) so if we
  481. * choose a prime number, we are guaranteed that the last read of a
  482. * frame will be short.
  483. *
  484. * But it isn't that easy: the 2.6 kernel requires a multiple of 4KB,
  485. * otherwise EOVERFLOW "babbling" errors occur. I have not been able
  486. * to figure out why. [PMiller]
  487. *
  488. * The constant (13 * 4096) is the largest "prime enough" number less than 64KB.
  489. *
  490. * It isn't enough to know the number of bytes per frame, in case we
  491. * have data dropouts or buffer overruns (even though the FX2 double
  492. * buffers, there are some pretty strict real time constraints for
  493. * isochronous transfer for larger frame sizes).
  494. */
  495. #define OVFX2_BULK_SIZE (13 * 4096)
  496. /* I2C registers */
  497. #define R51x_I2C_W_SID 0x41
  498. #define R51x_I2C_SADDR_3 0x42
  499. #define R51x_I2C_SADDR_2 0x43
  500. #define R51x_I2C_R_SID 0x44
  501. #define R51x_I2C_DATA 0x45
  502. #define R518_I2C_CTL 0x47 /* OV518(+) only */
  503. #define OVFX2_I2C_ADDR 0x00
  504. /* I2C ADDRESSES */
  505. #define OV7xx0_SID 0x42
  506. #define OV_HIRES_SID 0x60 /* OV9xxx / OV2xxx / OV3xxx */
  507. #define OV8xx0_SID 0xa0
  508. #define OV6xx0_SID 0xc0
  509. /* OV7610 registers */
  510. #define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
  511. #define OV7610_REG_BLUE 0x01 /* blue channel balance */
  512. #define OV7610_REG_RED 0x02 /* red channel balance */
  513. #define OV7610_REG_SAT 0x03 /* saturation */
  514. #define OV8610_REG_HUE 0x04 /* 04 reserved */
  515. #define OV7610_REG_CNT 0x05 /* Y contrast */
  516. #define OV7610_REG_BRT 0x06 /* Y brightness */
  517. #define OV7610_REG_COM_C 0x14 /* misc common regs */
  518. #define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
  519. #define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
  520. #define OV7610_REG_COM_I 0x29 /* misc settings */
  521. /* OV7670 registers */
  522. #define OV7670_R00_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
  523. #define OV7670_R01_BLUE 0x01 /* blue gain */
  524. #define OV7670_R02_RED 0x02 /* red gain */
  525. #define OV7670_R03_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
  526. #define OV7670_R04_COM1 0x04 /* Control 1 */
  527. /*#define OV7670_R07_AECHH 0x07 * AEC MS 5 bits */
  528. #define OV7670_R0C_COM3 0x0c /* Control 3 */
  529. #define OV7670_R0D_COM4 0x0d /* Control 4 */
  530. #define OV7670_R0E_COM5 0x0e /* All "reserved" */
  531. #define OV7670_R0F_COM6 0x0f /* Control 6 */
  532. #define OV7670_R10_AECH 0x10 /* More bits of AEC value */
  533. #define OV7670_R11_CLKRC 0x11 /* Clock control */
  534. #define OV7670_R12_COM7 0x12 /* Control 7 */
  535. #define OV7670_COM7_FMT_VGA 0x00
  536. /*#define OV7670_COM7_YUV 0x00 * YUV */
  537. #define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
  538. #define OV7670_COM7_FMT_MASK 0x38
  539. #define OV7670_COM7_RESET 0x80 /* Register reset */
  540. #define OV7670_R13_COM8 0x13 /* Control 8 */
  541. #define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
  542. #define OV7670_COM8_AWB 0x02 /* White balance enable */
  543. #define OV7670_COM8_AGC 0x04 /* Auto gain enable */
  544. #define OV7670_COM8_BFILT 0x20 /* Band filter enable */
  545. #define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
  546. #define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
  547. #define OV7670_R14_COM9 0x14 /* Control 9 - gain ceiling */
  548. #define OV7670_R15_COM10 0x15 /* Control 10 */
  549. #define OV7670_R17_HSTART 0x17 /* Horiz start high bits */
  550. #define OV7670_R18_HSTOP 0x18 /* Horiz stop high bits */
  551. #define OV7670_R19_VSTART 0x19 /* Vert start high bits */
  552. #define OV7670_R1A_VSTOP 0x1a /* Vert stop high bits */
  553. #define OV7670_R1E_MVFP 0x1e /* Mirror / vflip */
  554. #define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
  555. #define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
  556. #define OV7670_R24_AEW 0x24 /* AGC upper limit */
  557. #define OV7670_R25_AEB 0x25 /* AGC lower limit */
  558. #define OV7670_R26_VPT 0x26 /* AGC/AEC fast mode op region */
  559. #define OV7670_R32_HREF 0x32 /* HREF pieces */
  560. #define OV7670_R3A_TSLB 0x3a /* lots of stuff */
  561. #define OV7670_R3B_COM11 0x3b /* Control 11 */
  562. #define OV7670_COM11_EXP 0x02
  563. #define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
  564. #define OV7670_R3C_COM12 0x3c /* Control 12 */
  565. #define OV7670_R3D_COM13 0x3d /* Control 13 */
  566. #define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
  567. #define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
  568. #define OV7670_R3E_COM14 0x3e /* Control 14 */
  569. #define OV7670_R3F_EDGE 0x3f /* Edge enhancement factor */
  570. #define OV7670_R40_COM15 0x40 /* Control 15 */
  571. /*#define OV7670_COM15_R00FF 0xc0 * 00 to FF */
  572. #define OV7670_R41_COM16 0x41 /* Control 16 */
  573. #define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
  574. #define OV7670_R55_BRIGHT 0x55 /* Brightness */
  575. #define OV7670_R56_CONTRAS 0x56 /* Contrast control */
  576. #define OV7670_R69_GFIX 0x69 /* Fix gain control */
  577. /*#define OV7670_R8C_RGB444 0x8c * RGB 444 control */
  578. #define OV7670_R9F_HAECC1 0x9f /* Hist AEC/AGC control 1 */
  579. #define OV7670_RA0_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
  580. #define OV7670_RA5_BD50MAX 0xa5 /* 50hz banding step limit */
  581. #define OV7670_RA6_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
  582. #define OV7670_RA7_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
  583. #define OV7670_RA8_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
  584. #define OV7670_RA9_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
  585. #define OV7670_RAA_HAECC7 0xaa /* Hist AEC/AGC control 7 */
  586. #define OV7670_RAB_BD60MAX 0xab /* 60hz banding step limit */
  587. struct ov_regvals {
  588. u8 reg;
  589. u8 val;
  590. };
  591. struct ov_i2c_regvals {
  592. u8 reg;
  593. u8 val;
  594. };
  595. /* Settings for OV2610 camera chip */
  596. static const struct ov_i2c_regvals norm_2610[] = {
  597. { 0x12, 0x80 }, /* reset */
  598. };
  599. static const struct ov_i2c_regvals norm_3620b[] = {
  600. /*
  601. * From the datasheet: "Note that after writing to register COMH
  602. * (0x12) to change the sensor mode, registers related to the
  603. * sensor’s cropping window will be reset back to their default
  604. * values."
  605. *
  606. * "wait 4096 external clock ... to make sure the sensor is
  607. * stable and ready to access registers" i.e. 160us at 24MHz
  608. */
  609. { 0x12, 0x80 }, /* COMH reset */
  610. { 0x12, 0x00 }, /* QXGA, master */
  611. /*
  612. * 11 CLKRC "Clock Rate Control"
  613. * [7] internal frequency doublers: on
  614. * [6] video port mode: master
  615. * [5:0] clock divider: 1
  616. */
  617. { 0x11, 0x80 },
  618. /*
  619. * 13 COMI "Common Control I"
  620. * = 192 (0xC0) 11000000
  621. * COMI[7] "AEC speed selection"
  622. * = 1 (0x01) 1....... "Faster AEC correction"
  623. * COMI[6] "AEC speed step selection"
  624. * = 1 (0x01) .1...... "Big steps, fast"
  625. * COMI[5] "Banding filter on off"
  626. * = 0 (0x00) ..0..... "Off"
  627. * COMI[4] "Banding filter option"
  628. * = 0 (0x00) ...0.... "Main clock is 48 MHz and
  629. * the PLL is ON"
  630. * COMI[3] "Reserved"
  631. * = 0 (0x00) ....0...
  632. * COMI[2] "AGC auto manual control selection"
  633. * = 0 (0x00) .....0.. "Manual"
  634. * COMI[1] "AWB auto manual control selection"
  635. * = 0 (0x00) ......0. "Manual"
  636. * COMI[0] "Exposure control"
  637. * = 0 (0x00) .......0 "Manual"
  638. */
  639. { 0x13, 0xc0 },
  640. /*
  641. * 09 COMC "Common Control C"
  642. * = 8 (0x08) 00001000
  643. * COMC[7:5] "Reserved"
  644. * = 0 (0x00) 000.....
  645. * COMC[4] "Sleep Mode Enable"
  646. * = 0 (0x00) ...0.... "Normal mode"
  647. * COMC[3:2] "Sensor sampling reset timing selection"
  648. * = 2 (0x02) ....10.. "Longer reset time"
  649. * COMC[1:0] "Output drive current select"
  650. * = 0 (0x00) ......00 "Weakest"
  651. */
  652. { 0x09, 0x08 },
  653. /*
  654. * 0C COMD "Common Control D"
  655. * = 8 (0x08) 00001000
  656. * COMD[7] "Reserved"
  657. * = 0 (0x00) 0.......
  658. * COMD[6] "Swap MSB and LSB at the output port"
  659. * = 0 (0x00) .0...... "False"
  660. * COMD[5:3] "Reserved"
  661. * = 1 (0x01) ..001...
  662. * COMD[2] "Output Average On Off"
  663. * = 0 (0x00) .....0.. "Output Normal"
  664. * COMD[1] "Sensor precharge voltage selection"
  665. * = 0 (0x00) ......0. "Selects internal
  666. * reference precharge
  667. * voltage"
  668. * COMD[0] "Snapshot option"
  669. * = 0 (0x00) .......0 "Enable live video output
  670. * after snapshot sequence"
  671. */
  672. { 0x0c, 0x08 },
  673. /*
  674. * 0D COME "Common Control E"
  675. * = 161 (0xA1) 10100001
  676. * COME[7] "Output average option"
  677. * = 1 (0x01) 1....... "Output average of 4 pixels"
  678. * COME[6] "Anti-blooming control"
  679. * = 0 (0x00) .0...... "Off"
  680. * COME[5:3] "Reserved"
  681. * = 4 (0x04) ..100...
  682. * COME[2] "Clock output power down pin status"
  683. * = 0 (0x00) .....0.. "Tri-state data output pin
  684. * on power down"
  685. * COME[1] "Data output pin status selection at power down"
  686. * = 0 (0x00) ......0. "Tri-state VSYNC, PCLK,
  687. * HREF, and CHSYNC pins on
  688. * power down"
  689. * COME[0] "Auto zero circuit select"
  690. * = 1 (0x01) .......1 "On"
  691. */
  692. { 0x0d, 0xa1 },
  693. /*
  694. * 0E COMF "Common Control F"
  695. * = 112 (0x70) 01110000
  696. * COMF[7] "System clock selection"
  697. * = 0 (0x00) 0....... "Use 24 MHz system clock"
  698. * COMF[6:4] "Reserved"
  699. * = 7 (0x07) .111....
  700. * COMF[3] "Manual auto negative offset canceling selection"
  701. * = 0 (0x00) ....0... "Auto detect negative
  702. * offset and cancel it"
  703. * COMF[2:0] "Reserved"
  704. * = 0 (0x00) .....000
  705. */
  706. { 0x0e, 0x70 },
  707. /*
  708. * 0F COMG "Common Control G"
  709. * = 66 (0x42) 01000010
  710. * COMG[7] "Optical black output selection"
  711. * = 0 (0x00) 0....... "Disable"
  712. * COMG[6] "Black level calibrate selection"
  713. * = 1 (0x01) .1...... "Use optical black pixels
  714. * to calibrate"
  715. * COMG[5:4] "Reserved"
  716. * = 0 (0x00) ..00....
  717. * COMG[3] "Channel offset adjustment"
  718. * = 0 (0x00) ....0... "Disable offset adjustment"
  719. * COMG[2] "ADC black level calibration option"
  720. * = 0 (0x00) .....0.. "Use B/G line and G/R
  721. * line to calibrate each
  722. * channel's black level"
  723. * COMG[1] "Reserved"
  724. * = 1 (0x01) ......1.
  725. * COMG[0] "ADC black level calibration enable"
  726. * = 0 (0x00) .......0 "Disable"
  727. */
  728. { 0x0f, 0x42 },
  729. /*
  730. * 14 COMJ "Common Control J"
  731. * = 198 (0xC6) 11000110
  732. * COMJ[7:6] "AGC gain ceiling"
  733. * = 3 (0x03) 11...... "8x"
  734. * COMJ[5:4] "Reserved"
  735. * = 0 (0x00) ..00....
  736. * COMJ[3] "Auto banding filter"
  737. * = 0 (0x00) ....0... "Banding filter is always
  738. * on off depending on
  739. * COMI[5] setting"
  740. * COMJ[2] "VSYNC drop option"
  741. * = 1 (0x01) .....1.. "SYNC is dropped if frame
  742. * data is dropped"
  743. * COMJ[1] "Frame data drop"
  744. * = 1 (0x01) ......1. "Drop frame data if
  745. * exposure is not within
  746. * tolerance. In AEC mode,
  747. * data is normally dropped
  748. * when data is out of
  749. * range."
  750. * COMJ[0] "Reserved"
  751. * = 0 (0x00) .......0
  752. */
  753. { 0x14, 0xc6 },
  754. /*
  755. * 15 COMK "Common Control K"
  756. * = 2 (0x02) 00000010
  757. * COMK[7] "CHSYNC pin output swap"
  758. * = 0 (0x00) 0....... "CHSYNC"
  759. * COMK[6] "HREF pin output swap"
  760. * = 0 (0x00) .0...... "HREF"
  761. * COMK[5] "PCLK output selection"
  762. * = 0 (0x00) ..0..... "PCLK always output"
  763. * COMK[4] "PCLK edge selection"
  764. * = 0 (0x00) ...0.... "Data valid on falling edge"
  765. * COMK[3] "HREF output polarity"
  766. * = 0 (0x00) ....0... "positive"
  767. * COMK[2] "Reserved"
  768. * = 0 (0x00) .....0..
  769. * COMK[1] "VSYNC polarity"
  770. * = 1 (0x01) ......1. "negative"
  771. * COMK[0] "HSYNC polarity"
  772. * = 0 (0x00) .......0 "positive"
  773. */
  774. { 0x15, 0x02 },
  775. /*
  776. * 33 CHLF "Current Control"
  777. * = 9 (0x09) 00001001
  778. * CHLF[7:6] "Sensor current control"
  779. * = 0 (0x00) 00......
  780. * CHLF[5] "Sensor current range control"
  781. * = 0 (0x00) ..0..... "normal range"
  782. * CHLF[4] "Sensor current"
  783. * = 0 (0x00) ...0.... "normal current"
  784. * CHLF[3] "Sensor buffer current control"
  785. * = 1 (0x01) ....1... "half current"
  786. * CHLF[2] "Column buffer current control"
  787. * = 0 (0x00) .....0.. "normal current"
  788. * CHLF[1] "Analog DSP current control"
  789. * = 0 (0x00) ......0. "normal current"
  790. * CHLF[1] "ADC current control"
  791. * = 0 (0x00) ......0. "normal current"
  792. */
  793. { 0x33, 0x09 },
  794. /*
  795. * 34 VBLM "Blooming Control"
  796. * = 80 (0x50) 01010000
  797. * VBLM[7] "Hard soft reset switch"
  798. * = 0 (0x00) 0....... "Hard reset"
  799. * VBLM[6:4] "Blooming voltage selection"
  800. * = 5 (0x05) .101....
  801. * VBLM[3:0] "Sensor current control"
  802. * = 0 (0x00) ....0000
  803. */
  804. { 0x34, 0x50 },
  805. /*
  806. * 36 VCHG "Sensor Precharge Voltage Control"
  807. * = 0 (0x00) 00000000
  808. * VCHG[7] "Reserved"
  809. * = 0 (0x00) 0.......
  810. * VCHG[6:4] "Sensor precharge voltage control"
  811. * = 0 (0x00) .000....
  812. * VCHG[3:0] "Sensor array common reference"
  813. * = 0 (0x00) ....0000
  814. */
  815. { 0x36, 0x00 },
  816. /*
  817. * 37 ADC "ADC Reference Control"
  818. * = 4 (0x04) 00000100
  819. * ADC[7:4] "Reserved"
  820. * = 0 (0x00) 0000....
  821. * ADC[3] "ADC input signal range"
  822. * = 0 (0x00) ....0... "Input signal 1.0x"
  823. * ADC[2:0] "ADC range control"
  824. * = 4 (0x04) .....100
  825. */
  826. { 0x37, 0x04 },
  827. /*
  828. * 38 ACOM "Analog Common Ground"
  829. * = 82 (0x52) 01010010
  830. * ACOM[7] "Analog gain control"
  831. * = 0 (0x00) 0....... "Gain 1x"
  832. * ACOM[6] "Analog black level calibration"
  833. * = 1 (0x01) .1...... "On"
  834. * ACOM[5:0] "Reserved"
  835. * = 18 (0x12) ..010010
  836. */
  837. { 0x38, 0x52 },
  838. /*
  839. * 3A FREFA "Internal Reference Adjustment"
  840. * = 0 (0x00) 00000000
  841. * FREFA[7:0] "Range"
  842. * = 0 (0x00) 00000000
  843. */
  844. { 0x3a, 0x00 },
  845. /*
  846. * 3C FVOPT "Internal Reference Adjustment"
  847. * = 31 (0x1F) 00011111
  848. * FVOPT[7:0] "Range"
  849. * = 31 (0x1F) 00011111
  850. */
  851. { 0x3c, 0x1f },
  852. /*
  853. * 44 Undocumented = 0 (0x00) 00000000
  854. * 44[7:0] "It's a secret"
  855. * = 0 (0x00) 00000000
  856. */
  857. { 0x44, 0x00 },
  858. /*
  859. * 40 Undocumented = 0 (0x00) 00000000
  860. * 40[7:0] "It's a secret"
  861. * = 0 (0x00) 00000000
  862. */
  863. { 0x40, 0x00 },
  864. /*
  865. * 41 Undocumented = 0 (0x00) 00000000
  866. * 41[7:0] "It's a secret"
  867. * = 0 (0x00) 00000000
  868. */
  869. { 0x41, 0x00 },
  870. /*
  871. * 42 Undocumented = 0 (0x00) 00000000
  872. * 42[7:0] "It's a secret"
  873. * = 0 (0x00) 00000000
  874. */
  875. { 0x42, 0x00 },
  876. /*
  877. * 43 Undocumented = 0 (0x00) 00000000
  878. * 43[7:0] "It's a secret"
  879. * = 0 (0x00) 00000000
  880. */
  881. { 0x43, 0x00 },
  882. /*
  883. * 45 Undocumented = 128 (0x80) 10000000
  884. * 45[7:0] "It's a secret"
  885. * = 128 (0x80) 10000000
  886. */
  887. { 0x45, 0x80 },
  888. /*
  889. * 48 Undocumented = 192 (0xC0) 11000000
  890. * 48[7:0] "It's a secret"
  891. * = 192 (0xC0) 11000000
  892. */
  893. { 0x48, 0xc0 },
  894. /*
  895. * 49 Undocumented = 25 (0x19) 00011001
  896. * 49[7:0] "It's a secret"
  897. * = 25 (0x19) 00011001
  898. */
  899. { 0x49, 0x19 },
  900. /*
  901. * 4B Undocumented = 128 (0x80) 10000000
  902. * 4B[7:0] "It's a secret"
  903. * = 128 (0x80) 10000000
  904. */
  905. { 0x4b, 0x80 },
  906. /*
  907. * 4D Undocumented = 196 (0xC4) 11000100
  908. * 4D[7:0] "It's a secret"
  909. * = 196 (0xC4) 11000100
  910. */
  911. { 0x4d, 0xc4 },
  912. /*
  913. * 35 VREF "Reference Voltage Control"
  914. * = 76 (0x4c) 01001100
  915. * VREF[7:5] "Column high reference control"
  916. * = 2 (0x02) 010..... "higher voltage"
  917. * VREF[4:2] "Column low reference control"
  918. * = 3 (0x03) ...011.. "Highest voltage"
  919. * VREF[1:0] "Reserved"
  920. * = 0 (0x00) ......00
  921. */
  922. { 0x35, 0x4c },
  923. /*
  924. * 3D Undocumented = 0 (0x00) 00000000
  925. * 3D[7:0] "It's a secret"
  926. * = 0 (0x00) 00000000
  927. */
  928. { 0x3d, 0x00 },
  929. /*
  930. * 3E Undocumented = 0 (0x00) 00000000
  931. * 3E[7:0] "It's a secret"
  932. * = 0 (0x00) 00000000
  933. */
  934. { 0x3e, 0x00 },
  935. /*
  936. * 3B FREFB "Internal Reference Adjustment"
  937. * = 24 (0x18) 00011000
  938. * FREFB[7:0] "Range"
  939. * = 24 (0x18) 00011000
  940. */
  941. { 0x3b, 0x18 },
  942. /*
  943. * 33 CHLF "Current Control"
  944. * = 25 (0x19) 00011001
  945. * CHLF[7:6] "Sensor current control"
  946. * = 0 (0x00) 00......
  947. * CHLF[5] "Sensor current range control"
  948. * = 0 (0x00) ..0..... "normal range"
  949. * CHLF[4] "Sensor current"
  950. * = 1 (0x01) ...1.... "double current"
  951. * CHLF[3] "Sensor buffer current control"
  952. * = 1 (0x01) ....1... "half current"
  953. * CHLF[2] "Column buffer current control"
  954. * = 0 (0x00) .....0.. "normal current"
  955. * CHLF[1] "Analog DSP current control"
  956. * = 0 (0x00) ......0. "normal current"
  957. * CHLF[1] "ADC current control"
  958. * = 0 (0x00) ......0. "normal current"
  959. */
  960. { 0x33, 0x19 },
  961. /*
  962. * 34 VBLM "Blooming Control"
  963. * = 90 (0x5A) 01011010
  964. * VBLM[7] "Hard soft reset switch"
  965. * = 0 (0x00) 0....... "Hard reset"
  966. * VBLM[6:4] "Blooming voltage selection"
  967. * = 5 (0x05) .101....
  968. * VBLM[3:0] "Sensor current control"
  969. * = 10 (0x0A) ....1010
  970. */
  971. { 0x34, 0x5a },
  972. /*
  973. * 3B FREFB "Internal Reference Adjustment"
  974. * = 0 (0x00) 00000000
  975. * FREFB[7:0] "Range"
  976. * = 0 (0x00) 00000000
  977. */
  978. { 0x3b, 0x00 },
  979. /*
  980. * 33 CHLF "Current Control"
  981. * = 9 (0x09) 00001001
  982. * CHLF[7:6] "Sensor current control"
  983. * = 0 (0x00) 00......
  984. * CHLF[5] "Sensor current range control"
  985. * = 0 (0x00) ..0..... "normal range"
  986. * CHLF[4] "Sensor current"
  987. * = 0 (0x00) ...0.... "normal current"
  988. * CHLF[3] "Sensor buffer current control"
  989. * = 1 (0x01) ....1... "half current"
  990. * CHLF[2] "Column buffer current control"
  991. * = 0 (0x00) .....0.. "normal current"
  992. * CHLF[1] "Analog DSP current control"
  993. * = 0 (0x00) ......0. "normal current"
  994. * CHLF[1] "ADC current control"
  995. * = 0 (0x00) ......0. "normal current"
  996. */
  997. { 0x33, 0x09 },
  998. /*
  999. * 34 VBLM "Blooming Control"
  1000. * = 80 (0x50) 01010000
  1001. * VBLM[7] "Hard soft reset switch"
  1002. * = 0 (0x00) 0....... "Hard reset"
  1003. * VBLM[6:4] "Blooming voltage selection"
  1004. * = 5 (0x05) .101....
  1005. * VBLM[3:0] "Sensor current control"
  1006. * = 0 (0x00) ....0000
  1007. */
  1008. { 0x34, 0x50 },
  1009. /*
  1010. * 12 COMH "Common Control H"
  1011. * = 64 (0x40) 01000000
  1012. * COMH[7] "SRST"
  1013. * = 0 (0x00) 0....... "No-op"
  1014. * COMH[6:4] "Resolution selection"
  1015. * = 4 (0x04) .100.... "XGA"
  1016. * COMH[3] "Master slave selection"
  1017. * = 0 (0x00) ....0... "Master mode"
  1018. * COMH[2] "Internal B/R channel option"
  1019. * = 0 (0x00) .....0.. "B/R use same channel"
  1020. * COMH[1] "Color bar test pattern"
  1021. * = 0 (0x00) ......0. "Off"
  1022. * COMH[0] "Reserved"
  1023. * = 0 (0x00) .......0
  1024. */
  1025. { 0x12, 0x40 },
  1026. /*
  1027. * 17 HREFST "Horizontal window start"
  1028. * = 31 (0x1F) 00011111
  1029. * HREFST[7:0] "Horizontal window start, 8 MSBs"
  1030. * = 31 (0x1F) 00011111
  1031. */
  1032. { 0x17, 0x1f },
  1033. /*
  1034. * 18 HREFEND "Horizontal window end"
  1035. * = 95 (0x5F) 01011111
  1036. * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
  1037. * = 95 (0x5F) 01011111
  1038. */
  1039. { 0x18, 0x5f },
  1040. /*
  1041. * 19 VSTRT "Vertical window start"
  1042. * = 0 (0x00) 00000000
  1043. * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
  1044. * = 0 (0x00) 00000000
  1045. */
  1046. { 0x19, 0x00 },
  1047. /*
  1048. * 1A VEND "Vertical window end"
  1049. * = 96 (0x60) 01100000
  1050. * VEND[7:0] "Vertical Window End, 8 MSBs"
  1051. * = 96 (0x60) 01100000
  1052. */
  1053. { 0x1a, 0x60 },
  1054. /*
  1055. * 32 COMM "Common Control M"
  1056. * = 18 (0x12) 00010010
  1057. * COMM[7:6] "Pixel clock divide option"
  1058. * = 0 (0x00) 00...... "/1"
  1059. * COMM[5:3] "Horizontal window end position, 3 LSBs"
  1060. * = 2 (0x02) ..010...
  1061. * COMM[2:0] "Horizontal window start position, 3 LSBs"
  1062. * = 2 (0x02) .....010
  1063. */
  1064. { 0x32, 0x12 },
  1065. /*
  1066. * 03 COMA "Common Control A"
  1067. * = 74 (0x4A) 01001010
  1068. * COMA[7:4] "AWB Update Threshold"
  1069. * = 4 (0x04) 0100....
  1070. * COMA[3:2] "Vertical window end line control 2 LSBs"
  1071. * = 2 (0x02) ....10..
  1072. * COMA[1:0] "Vertical window start line control 2 LSBs"
  1073. * = 2 (0x02) ......10
  1074. */
  1075. { 0x03, 0x4a },
  1076. /*
  1077. * 11 CLKRC "Clock Rate Control"
  1078. * = 128 (0x80) 10000000
  1079. * CLKRC[7] "Internal frequency doublers on off seclection"
  1080. * = 1 (0x01) 1....... "On"
  1081. * CLKRC[6] "Digital video master slave selection"
  1082. * = 0 (0x00) .0...... "Master mode, sensor
  1083. * provides PCLK"
  1084. * CLKRC[5:0] "Clock divider { CLK = PCLK/(1+CLKRC[5:0]) }"
  1085. * = 0 (0x00) ..000000
  1086. */
  1087. { 0x11, 0x80 },
  1088. /*
  1089. * 12 COMH "Common Control H"
  1090. * = 0 (0x00) 00000000
  1091. * COMH[7] "SRST"
  1092. * = 0 (0x00) 0....... "No-op"
  1093. * COMH[6:4] "Resolution selection"
  1094. * = 0 (0x00) .000.... "QXGA"
  1095. * COMH[3] "Master slave selection"
  1096. * = 0 (0x00) ....0... "Master mode"
  1097. * COMH[2] "Internal B/R channel option"
  1098. * = 0 (0x00) .....0.. "B/R use same channel"
  1099. * COMH[1] "Color bar test pattern"
  1100. * = 0 (0x00) ......0. "Off"
  1101. * COMH[0] "Reserved"
  1102. * = 0 (0x00) .......0
  1103. */
  1104. { 0x12, 0x00 },
  1105. /*
  1106. * 12 COMH "Common Control H"
  1107. * = 64 (0x40) 01000000
  1108. * COMH[7] "SRST"
  1109. * = 0 (0x00) 0....... "No-op"
  1110. * COMH[6:4] "Resolution selection"
  1111. * = 4 (0x04) .100.... "XGA"
  1112. * COMH[3] "Master slave selection"
  1113. * = 0 (0x00) ....0... "Master mode"
  1114. * COMH[2] "Internal B/R channel option"
  1115. * = 0 (0x00) .....0.. "B/R use same channel"
  1116. * COMH[1] "Color bar test pattern"
  1117. * = 0 (0x00) ......0. "Off"
  1118. * COMH[0] "Reserved"
  1119. * = 0 (0x00) .......0
  1120. */
  1121. { 0x12, 0x40 },
  1122. /*
  1123. * 17 HREFST "Horizontal window start"
  1124. * = 31 (0x1F) 00011111
  1125. * HREFST[7:0] "Horizontal window start, 8 MSBs"
  1126. * = 31 (0x1F) 00011111
  1127. */
  1128. { 0x17, 0x1f },
  1129. /*
  1130. * 18 HREFEND "Horizontal window end"
  1131. * = 95 (0x5F) 01011111
  1132. * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
  1133. * = 95 (0x5F) 01011111
  1134. */
  1135. { 0x18, 0x5f },
  1136. /*
  1137. * 19 VSTRT "Vertical window start"
  1138. * = 0 (0x00) 00000000
  1139. * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
  1140. * = 0 (0x00) 00000000
  1141. */
  1142. { 0x19, 0x00 },
  1143. /*
  1144. * 1A VEND "Vertical window end"
  1145. * = 96 (0x60) 01100000
  1146. * VEND[7:0] "Vertical Window End, 8 MSBs"
  1147. * = 96 (0x60) 01100000
  1148. */
  1149. { 0x1a, 0x60 },
  1150. /*
  1151. * 32 COMM "Common Control M"
  1152. * = 18 (0x12) 00010010
  1153. * COMM[7:6] "Pixel clock divide option"
  1154. * = 0 (0x00) 00...... "/1"
  1155. * COMM[5:3] "Horizontal window end position, 3 LSBs"
  1156. * = 2 (0x02) ..010...
  1157. * COMM[2:0] "Horizontal window start position, 3 LSBs"
  1158. * = 2 (0x02) .....010
  1159. */
  1160. { 0x32, 0x12 },
  1161. /*
  1162. * 03 COMA "Common Control A"
  1163. * = 74 (0x4A) 01001010
  1164. * COMA[7:4] "AWB Update Threshold"
  1165. * = 4 (0x04) 0100....
  1166. * COMA[3:2] "Vertical window end line control 2 LSBs"
  1167. * = 2 (0x02) ....10..
  1168. * COMA[1:0] "Vertical window start line control 2 LSBs"
  1169. * = 2 (0x02) ......10
  1170. */
  1171. { 0x03, 0x4a },
  1172. /*
  1173. * 02 RED "Red Gain Control"
  1174. * = 175 (0xAF) 10101111
  1175. * RED[7] "Action"
  1176. * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
  1177. * RED[6:0] "Value"
  1178. * = 47 (0x2F) .0101111
  1179. */
  1180. { 0x02, 0xaf },
  1181. /*
  1182. * 2D ADDVSL "VSYNC Pulse Width"
  1183. * = 210 (0xD2) 11010010
  1184. * ADDVSL[7:0] "VSYNC pulse width, LSB"
  1185. * = 210 (0xD2) 11010010
  1186. */
  1187. { 0x2d, 0xd2 },
  1188. /*
  1189. * 00 GAIN = 24 (0x18) 00011000
  1190. * GAIN[7:6] "Reserved"
  1191. * = 0 (0x00) 00......
  1192. * GAIN[5] "Double"
  1193. * = 0 (0x00) ..0..... "False"
  1194. * GAIN[4] "Double"
  1195. * = 1 (0x01) ...1.... "True"
  1196. * GAIN[3:0] "Range"
  1197. * = 8 (0x08) ....1000
  1198. */
  1199. { 0x00, 0x18 },
  1200. /*
  1201. * 01 BLUE "Blue Gain Control"
  1202. * = 240 (0xF0) 11110000
  1203. * BLUE[7] "Action"
  1204. * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
  1205. * BLUE[6:0] "Value"
  1206. * = 112 (0x70) .1110000
  1207. */
  1208. { 0x01, 0xf0 },
  1209. /*
  1210. * 10 AEC "Automatic Exposure Control"
  1211. * = 10 (0x0A) 00001010
  1212. * AEC[7:0] "Automatic Exposure Control, 8 MSBs"
  1213. * = 10 (0x0A) 00001010
  1214. */
  1215. { 0x10, 0x0a },
  1216. { 0xe1, 0x67 },
  1217. { 0xe3, 0x03 },
  1218. { 0xe4, 0x26 },
  1219. { 0xe5, 0x3e },
  1220. { 0xf8, 0x01 },
  1221. { 0xff, 0x01 },
  1222. };
  1223. static const struct ov_i2c_regvals norm_6x20[] = {
  1224. { 0x12, 0x80 }, /* reset */
  1225. { 0x11, 0x01 },
  1226. { 0x03, 0x60 },
  1227. { 0x05, 0x7f }, /* For when autoadjust is off */
  1228. { 0x07, 0xa8 },
  1229. /* The ratio of 0x0c and 0x0d controls the white point */
  1230. { 0x0c, 0x24 },
  1231. { 0x0d, 0x24 },
  1232. { 0x0f, 0x15 }, /* COMS */
  1233. { 0x10, 0x75 }, /* AEC Exposure time */
  1234. { 0x12, 0x24 }, /* Enable AGC */
  1235. { 0x14, 0x04 },
  1236. /* 0x16: 0x06 helps frame stability with moving objects */
  1237. { 0x16, 0x06 },
  1238. /* { 0x20, 0x30 }, * Aperture correction enable */
  1239. { 0x26, 0xb2 }, /* BLC enable */
  1240. /* 0x28: 0x05 Selects RGB format if RGB on */
  1241. { 0x28, 0x05 },
  1242. { 0x2a, 0x04 }, /* Disable framerate adjust */
  1243. /* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
  1244. { 0x2d, 0x85 },
  1245. { 0x33, 0xa0 }, /* Color Processing Parameter */
  1246. { 0x34, 0xd2 }, /* Max A/D range */
  1247. { 0x38, 0x8b },
  1248. { 0x39, 0x40 },
  1249. { 0x3c, 0x39 }, /* Enable AEC mode changing */
  1250. { 0x3c, 0x3c }, /* Change AEC mode */
  1251. { 0x3c, 0x24 }, /* Disable AEC mode changing */
  1252. { 0x3d, 0x80 },
  1253. /* These next two registers (0x4a, 0x4b) are undocumented.
  1254. * They control the color balance */
  1255. { 0x4a, 0x80 },
  1256. { 0x4b, 0x80 },
  1257. { 0x4d, 0xd2 }, /* This reduces noise a bit */
  1258. { 0x4e, 0xc1 },
  1259. { 0x4f, 0x04 },
  1260. /* Do 50-53 have any effect? */
  1261. /* Toggle 0x12[2] off and on here? */
  1262. };
  1263. static const struct ov_i2c_regvals norm_6x30[] = {
  1264. { 0x12, 0x80 }, /* Reset */
  1265. { 0x00, 0x1f }, /* Gain */
  1266. { 0x01, 0x99 }, /* Blue gain */
  1267. { 0x02, 0x7c }, /* Red gain */
  1268. { 0x03, 0xc0 }, /* Saturation */
  1269. { 0x05, 0x0a }, /* Contrast */
  1270. { 0x06, 0x95 }, /* Brightness */
  1271. { 0x07, 0x2d }, /* Sharpness */
  1272. { 0x0c, 0x20 },
  1273. { 0x0d, 0x20 },
  1274. { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */
  1275. { 0x0f, 0x05 },
  1276. { 0x10, 0x9a },
  1277. { 0x11, 0x00 }, /* Pixel clock = fastest */
  1278. { 0x12, 0x24 }, /* Enable AGC and AWB */
  1279. { 0x13, 0x21 },
  1280. { 0x14, 0x80 },
  1281. { 0x15, 0x01 },
  1282. { 0x16, 0x03 },
  1283. { 0x17, 0x38 },
  1284. { 0x18, 0xea },
  1285. { 0x19, 0x04 },
  1286. { 0x1a, 0x93 },
  1287. { 0x1b, 0x00 },
  1288. { 0x1e, 0xc4 },
  1289. { 0x1f, 0x04 },
  1290. { 0x20, 0x20 },
  1291. { 0x21, 0x10 },
  1292. { 0x22, 0x88 },
  1293. { 0x23, 0xc0 }, /* Crystal circuit power level */
  1294. { 0x25, 0x9a }, /* Increase AEC black ratio */
  1295. { 0x26, 0xb2 }, /* BLC enable */
  1296. { 0x27, 0xa2 },
  1297. { 0x28, 0x00 },
  1298. { 0x29, 0x00 },
  1299. { 0x2a, 0x84 }, /* 60 Hz power */
  1300. { 0x2b, 0xa8 }, /* 60 Hz power */
  1301. { 0x2c, 0xa0 },
  1302. { 0x2d, 0x95 }, /* Enable auto-brightness */
  1303. { 0x2e, 0x88 },
  1304. { 0x33, 0x26 },
  1305. { 0x34, 0x03 },
  1306. { 0x36, 0x8f },
  1307. { 0x37, 0x80 },
  1308. { 0x38, 0x83 },
  1309. { 0x39, 0x80 },
  1310. { 0x3a, 0x0f },
  1311. { 0x3b, 0x3c },
  1312. { 0x3c, 0x1a },
  1313. { 0x3d, 0x80 },
  1314. { 0x3e, 0x80 },
  1315. { 0x3f, 0x0e },
  1316. { 0x40, 0x00 }, /* White bal */
  1317. { 0x41, 0x00 }, /* White bal */
  1318. { 0x42, 0x80 },
  1319. { 0x43, 0x3f }, /* White bal */
  1320. { 0x44, 0x80 },
  1321. { 0x45, 0x20 },
  1322. { 0x46, 0x20 },
  1323. { 0x47, 0x80 },
  1324. { 0x48, 0x7f },
  1325. { 0x49, 0x00 },
  1326. { 0x4a, 0x00 },
  1327. { 0x4b, 0x80 },
  1328. { 0x4c, 0xd0 },
  1329. { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
  1330. { 0x4e, 0x40 },
  1331. { 0x4f, 0x07 }, /* UV avg., col. killer: max */
  1332. { 0x50, 0xff },
  1333. { 0x54, 0x23 }, /* Max AGC gain: 18dB */
  1334. { 0x55, 0xff },
  1335. { 0x56, 0x12 },
  1336. { 0x57, 0x81 },
  1337. { 0x58, 0x75 },
  1338. { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
  1339. { 0x5a, 0x2c },
  1340. { 0x5b, 0x0f }, /* AWB chrominance levels */
  1341. { 0x5c, 0x10 },
  1342. { 0x3d, 0x80 },
  1343. { 0x27, 0xa6 },
  1344. { 0x12, 0x20 }, /* Toggle AWB */
  1345. { 0x12, 0x24 },
  1346. };
  1347. /* Lawrence Glaister <lg@jfm.bc.ca> reports:
  1348. *
  1349. * Register 0x0f in the 7610 has the following effects:
  1350. *
  1351. * 0x85 (AEC method 1): Best overall, good contrast range
  1352. * 0x45 (AEC method 2): Very overexposed
  1353. * 0xa5 (spec sheet default): Ok, but the black level is
  1354. * shifted resulting in loss of contrast
  1355. * 0x05 (old driver setting): very overexposed, too much
  1356. * contrast
  1357. */
  1358. static const struct ov_i2c_regvals norm_7610[] = {
  1359. { 0x10, 0xff },
  1360. { 0x16, 0x06 },
  1361. { 0x28, 0x24 },
  1362. { 0x2b, 0xac },
  1363. { 0x12, 0x00 },
  1364. { 0x38, 0x81 },
  1365. { 0x28, 0x24 }, /* 0c */
  1366. { 0x0f, 0x85 }, /* lg's setting */
  1367. { 0x15, 0x01 },
  1368. { 0x20, 0x1c },
  1369. { 0x23, 0x2a },
  1370. { 0x24, 0x10 },
  1371. { 0x25, 0x8a },
  1372. { 0x26, 0xa2 },
  1373. { 0x27, 0xc2 },
  1374. { 0x2a, 0x04 },
  1375. { 0x2c, 0xfe },
  1376. { 0x2d, 0x93 },
  1377. { 0x30, 0x71 },
  1378. { 0x31, 0x60 },
  1379. { 0x32, 0x26 },
  1380. { 0x33, 0x20 },
  1381. { 0x34, 0x48 },
  1382. { 0x12, 0x24 },
  1383. { 0x11, 0x01 },
  1384. { 0x0c, 0x24 },
  1385. { 0x0d, 0x24 },
  1386. };
  1387. static const struct ov_i2c_regvals norm_7620[] = {
  1388. { 0x12, 0x80 }, /* reset */
  1389. { 0x00, 0x00 }, /* gain */
  1390. { 0x01, 0x80 }, /* blue gain */
  1391. { 0x02, 0x80 }, /* red gain */
  1392. { 0x03, 0xc0 }, /* OV7670_R03_VREF */
  1393. { 0x06, 0x60 },
  1394. { 0x07, 0x00 },
  1395. { 0x0c, 0x24 },
  1396. { 0x0c, 0x24 },
  1397. { 0x0d, 0x24 },
  1398. { 0x11, 0x01 },
  1399. { 0x12, 0x24 },
  1400. { 0x13, 0x01 },
  1401. { 0x14, 0x84 },
  1402. { 0x15, 0x01 },
  1403. { 0x16, 0x03 },
  1404. { 0x17, 0x2f },
  1405. { 0x18, 0xcf },
  1406. { 0x19, 0x06 },
  1407. { 0x1a, 0xf5 },
  1408. { 0x1b, 0x00 },
  1409. { 0x20, 0x18 },
  1410. { 0x21, 0x80 },
  1411. { 0x22, 0x80 },
  1412. { 0x23, 0x00 },
  1413. { 0x26, 0xa2 },
  1414. { 0x27, 0xea },
  1415. { 0x28, 0x22 }, /* Was 0x20, bit1 enables a 2x gain which we need */
  1416. { 0x29, 0x00 },
  1417. { 0x2a, 0x10 },
  1418. { 0x2b, 0x00 },
  1419. { 0x2c, 0x88 },
  1420. { 0x2d, 0x91 },
  1421. { 0x2e, 0x80 },
  1422. { 0x2f, 0x44 },
  1423. { 0x60, 0x27 },
  1424. { 0x61, 0x02 },
  1425. { 0x62, 0x5f },
  1426. { 0x63, 0xd5 },
  1427. { 0x64, 0x57 },
  1428. { 0x65, 0x83 },
  1429. { 0x66, 0x55 },
  1430. { 0x67, 0x92 },
  1431. { 0x68, 0xcf },
  1432. { 0x69, 0x76 },
  1433. { 0x6a, 0x22 },
  1434. { 0x6b, 0x00 },
  1435. { 0x6c, 0x02 },
  1436. { 0x6d, 0x44 },
  1437. { 0x6e, 0x80 },
  1438. { 0x6f, 0x1d },
  1439. { 0x70, 0x8b },
  1440. { 0x71, 0x00 },
  1441. { 0x72, 0x14 },
  1442. { 0x73, 0x54 },
  1443. { 0x74, 0x00 },
  1444. { 0x75, 0x8e },
  1445. { 0x76, 0x00 },
  1446. { 0x77, 0xff },
  1447. { 0x78, 0x80 },
  1448. { 0x79, 0x80 },
  1449. { 0x7a, 0x80 },
  1450. { 0x7b, 0xe2 },
  1451. { 0x7c, 0x00 },
  1452. };
  1453. /* 7640 and 7648. The defaults should be OK for most registers. */
  1454. static const struct ov_i2c_regvals norm_7640[] = {
  1455. { 0x12, 0x80 },
  1456. { 0x12, 0x14 },
  1457. };
  1458. /* 7670. Defaults taken from OmniVision provided data,
  1459. * as provided by Jonathan Corbet of OLPC */
  1460. static const struct ov_i2c_regvals norm_7670[] = {
  1461. { OV7670_R12_COM7, OV7670_COM7_RESET },
  1462. { OV7670_R3A_TSLB, 0x04 }, /* OV */
  1463. { OV7670_R12_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
  1464. { OV7670_R11_CLKRC, 0x01 },
  1465. /*
  1466. * Set the hardware window. These values from OV don't entirely
  1467. * make sense - hstop is less than hstart. But they work...
  1468. */
  1469. { OV7670_R17_HSTART, 0x13 },
  1470. { OV7670_R18_HSTOP, 0x01 },
  1471. { OV7670_R32_HREF, 0xb6 },
  1472. { OV7670_R19_VSTART, 0x02 },
  1473. { OV7670_R1A_VSTOP, 0x7a },
  1474. { OV7670_R03_VREF, 0x0a },
  1475. { OV7670_R0C_COM3, 0x00 },
  1476. { OV7670_R3E_COM14, 0x00 },
  1477. /* Mystery scaling numbers */
  1478. { 0x70, 0x3a },
  1479. { 0x71, 0x35 },
  1480. { 0x72, 0x11 },
  1481. { 0x73, 0xf0 },
  1482. { 0xa2, 0x02 },
  1483. /* { OV7670_R15_COM10, 0x0 }, */
  1484. /* Gamma curve values */
  1485. { 0x7a, 0x20 },
  1486. { 0x7b, 0x10 },
  1487. { 0x7c, 0x1e },
  1488. { 0x7d, 0x35 },
  1489. { 0x7e, 0x5a },
  1490. { 0x7f, 0x69 },
  1491. { 0x80, 0x76 },
  1492. { 0x81, 0x80 },
  1493. { 0x82, 0x88 },
  1494. { 0x83, 0x8f },
  1495. { 0x84, 0x96 },
  1496. { 0x85, 0xa3 },
  1497. { 0x86, 0xaf },
  1498. { 0x87, 0xc4 },
  1499. { 0x88, 0xd7 },
  1500. { 0x89, 0xe8 },
  1501. /* AGC and AEC parameters. Note we start by disabling those features,
  1502. then turn them only after tweaking the values. */
  1503. { OV7670_R13_COM8, OV7670_COM8_FASTAEC
  1504. | OV7670_COM8_AECSTEP
  1505. | OV7670_COM8_BFILT },
  1506. { OV7670_R00_GAIN, 0x00 },
  1507. { OV7670_R10_AECH, 0x00 },
  1508. { OV7670_R0D_COM4, 0x40 }, /* magic reserved bit */
  1509. { OV7670_R14_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
  1510. { OV7670_RA5_BD50MAX, 0x05 },
  1511. { OV7670_RAB_BD60MAX, 0x07 },
  1512. { OV7670_R24_AEW, 0x95 },
  1513. { OV7670_R25_AEB, 0x33 },
  1514. { OV7670_R26_VPT, 0xe3 },
  1515. { OV7670_R9F_HAECC1, 0x78 },
  1516. { OV7670_RA0_HAECC2, 0x68 },
  1517. { 0xa1, 0x03 }, /* magic */
  1518. { OV7670_RA6_HAECC3, 0xd8 },
  1519. { OV7670_RA7_HAECC4, 0xd8 },
  1520. { OV7670_RA8_HAECC5, 0xf0 },
  1521. { OV7670_RA9_HAECC6, 0x90 },
  1522. { OV7670_RAA_HAECC7, 0x94 },
  1523. { OV7670_R13_COM8, OV7670_COM8_FASTAEC
  1524. | OV7670_COM8_AECSTEP
  1525. | OV7670_COM8_BFILT
  1526. | OV7670_COM8_AGC
  1527. | OV7670_COM8_AEC },
  1528. /* Almost all of these are magic "reserved" values. */
  1529. { OV7670_R0E_COM5, 0x61 },
  1530. { OV7670_R0F_COM6, 0x4b },
  1531. { 0x16, 0x02 },
  1532. { OV7670_R1E_MVFP, 0x07 },
  1533. { 0x21, 0x02 },
  1534. { 0x22, 0x91 },
  1535. { 0x29, 0x07 },
  1536. { 0x33, 0x0b },
  1537. { 0x35, 0x0b },
  1538. { 0x37, 0x1d },
  1539. { 0x38, 0x71 },
  1540. { 0x39, 0x2a },
  1541. { OV7670_R3C_COM12, 0x78 },
  1542. { 0x4d, 0x40 },
  1543. { 0x4e, 0x20 },
  1544. { OV7670_R69_GFIX, 0x00 },
  1545. { 0x6b, 0x4a },
  1546. { 0x74, 0x10 },
  1547. { 0x8d, 0x4f },
  1548. { 0x8e, 0x00 },
  1549. { 0x8f, 0x00 },
  1550. { 0x90, 0x00 },
  1551. { 0x91, 0x00 },
  1552. { 0x96, 0x00 },
  1553. { 0x9a, 0x00 },
  1554. { 0xb0, 0x84 },
  1555. { 0xb1, 0x0c },
  1556. { 0xb2, 0x0e },
  1557. { 0xb3, 0x82 },
  1558. { 0xb8, 0x0a },
  1559. /* More reserved magic, some of which tweaks white balance */
  1560. { 0x43, 0x0a },
  1561. { 0x44, 0xf0 },
  1562. { 0x45, 0x34 },
  1563. { 0x46, 0x58 },
  1564. { 0x47, 0x28 },
  1565. { 0x48, 0x3a },
  1566. { 0x59, 0x88 },
  1567. { 0x5a, 0x88 },
  1568. { 0x5b, 0x44 },
  1569. { 0x5c, 0x67 },
  1570. { 0x5d, 0x49 },
  1571. { 0x5e, 0x0e },
  1572. { 0x6c, 0x0a },
  1573. { 0x6d, 0x55 },
  1574. { 0x6e, 0x11 },
  1575. { 0x6f, 0x9f },
  1576. /* "9e for advance AWB" */
  1577. { 0x6a, 0x40 },
  1578. { OV7670_R01_BLUE, 0x40 },
  1579. { OV7670_R02_RED, 0x60 },
  1580. { OV7670_R13_COM8, OV7670_COM8_FASTAEC
  1581. | OV7670_COM8_AECSTEP
  1582. | OV7670_COM8_BFILT
  1583. | OV7670_COM8_AGC
  1584. | OV7670_COM8_AEC
  1585. | OV7670_COM8_AWB },
  1586. /* Matrix coefficients */
  1587. { 0x4f, 0x80 },
  1588. { 0x50, 0x80 },
  1589. { 0x51, 0x00 },
  1590. { 0x52, 0x22 },
  1591. { 0x53, 0x5e },
  1592. { 0x54, 0x80 },
  1593. { 0x58, 0x9e },
  1594. { OV7670_R41_COM16, OV7670_COM16_AWBGAIN },
  1595. { OV7670_R3F_EDGE, 0x00 },
  1596. { 0x75, 0x05 },
  1597. { 0x76, 0xe1 },
  1598. { 0x4c, 0x00 },
  1599. { 0x77, 0x01 },
  1600. { OV7670_R3D_COM13, OV7670_COM13_GAMMA
  1601. | OV7670_COM13_UVSAT
  1602. | 2}, /* was 3 */
  1603. { 0x4b, 0x09 },
  1604. { 0xc9, 0x60 },
  1605. { OV7670_R41_COM16, 0x38 },
  1606. { 0x56, 0x40 },
  1607. { 0x34, 0x11 },
  1608. { OV7670_R3B_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
  1609. { 0xa4, 0x88 },
  1610. { 0x96, 0x00 },
  1611. { 0x97, 0x30 },
  1612. { 0x98, 0x20 },
  1613. { 0x99, 0x30 },
  1614. { 0x9a, 0x84 },
  1615. { 0x9b, 0x29 },
  1616. { 0x9c, 0x03 },
  1617. { 0x9d, 0x4c },
  1618. { 0x9e, 0x3f },
  1619. { 0x78, 0x04 },
  1620. /* Extra-weird stuff. Some sort of multiplexor register */
  1621. { 0x79, 0x01 },
  1622. { 0xc8, 0xf0 },
  1623. { 0x79, 0x0f },
  1624. { 0xc8, 0x00 },
  1625. { 0x79, 0x10 },
  1626. { 0xc8, 0x7e },
  1627. { 0x79, 0x0a },
  1628. { 0xc8, 0x80 },
  1629. { 0x79, 0x0b },
  1630. { 0xc8, 0x01 },
  1631. { 0x79, 0x0c },
  1632. { 0xc8, 0x0f },
  1633. { 0x79, 0x0d },
  1634. { 0xc8, 0x20 },
  1635. { 0x79, 0x09 },
  1636. { 0xc8, 0x80 },
  1637. { 0x79, 0x02 },
  1638. { 0xc8, 0xc0 },
  1639. { 0x79, 0x03 },
  1640. { 0xc8, 0x40 },
  1641. { 0x79, 0x05 },
  1642. { 0xc8, 0x30 },
  1643. { 0x79, 0x26 },
  1644. };
  1645. static const struct ov_i2c_regvals norm_8610[] = {
  1646. { 0x12, 0x80 },
  1647. { 0x00, 0x00 },
  1648. { 0x01, 0x80 },
  1649. { 0x02, 0x80 },
  1650. { 0x03, 0xc0 },
  1651. { 0x04, 0x30 },
  1652. { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
  1653. { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
  1654. { 0x0a, 0x86 },
  1655. { 0x0b, 0xb0 },
  1656. { 0x0c, 0x20 },
  1657. { 0x0d, 0x20 },
  1658. { 0x11, 0x01 },
  1659. { 0x12, 0x25 },
  1660. { 0x13, 0x01 },
  1661. { 0x14, 0x04 },
  1662. { 0x15, 0x01 }, /* Lin and Win think different about UV order */
  1663. { 0x16, 0x03 },
  1664. { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
  1665. { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
  1666. { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
  1667. { 0x1a, 0xf5 },
  1668. { 0x1b, 0x00 },
  1669. { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
  1670. { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
  1671. { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
  1672. { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
  1673. { 0x26, 0xa2 },
  1674. { 0x27, 0xea },
  1675. { 0x28, 0x00 },
  1676. { 0x29, 0x00 },
  1677. { 0x2a, 0x80 },
  1678. { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
  1679. { 0x2c, 0xac },
  1680. { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
  1681. { 0x2e, 0x80 },
  1682. { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
  1683. { 0x4c, 0x00 },
  1684. { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
  1685. { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
  1686. { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
  1687. { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
  1688. { 0x63, 0xff },
  1689. { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
  1690. * maybe thats wrong */
  1691. { 0x65, 0x00 },
  1692. { 0x66, 0x55 },
  1693. { 0x67, 0xb0 },
  1694. { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
  1695. { 0x69, 0x02 },
  1696. { 0x6a, 0x22 },
  1697. { 0x6b, 0x00 },
  1698. { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
  1699. * deleting bit7 colors the first images red */
  1700. { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
  1701. { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
  1702. { 0x6f, 0x01 },
  1703. { 0x70, 0x8b },
  1704. { 0x71, 0x00 },
  1705. { 0x72, 0x14 },
  1706. { 0x73, 0x54 },
  1707. { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
  1708. { 0x75, 0x0e },
  1709. { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
  1710. { 0x77, 0xff },
  1711. { 0x78, 0x80 },
  1712. { 0x79, 0x80 },
  1713. { 0x7a, 0x80 },
  1714. { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
  1715. { 0x7c, 0x00 },
  1716. { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
  1717. { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
  1718. { 0x7f, 0xfb },
  1719. { 0x80, 0x28 },
  1720. { 0x81, 0x00 },
  1721. { 0x82, 0x23 },
  1722. { 0x83, 0x0b },
  1723. { 0x84, 0x00 },
  1724. { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
  1725. { 0x86, 0xc9 },
  1726. { 0x87, 0x00 },
  1727. { 0x88, 0x00 },
  1728. { 0x89, 0x01 },
  1729. { 0x12, 0x20 },
  1730. { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
  1731. };
  1732. static unsigned char ov7670_abs_to_sm(unsigned char v)
  1733. {
  1734. if (v > 127)
  1735. return v & 0x7f;
  1736. return (128 - v) | 0x80;
  1737. }
  1738. /* Write a OV519 register */
  1739. static int reg_w(struct sd *sd, u16 index, u16 value)
  1740. {
  1741. int ret, req = 0;
  1742. switch (sd->bridge) {
  1743. case BRIDGE_OV511:
  1744. case BRIDGE_OV511PLUS:
  1745. req = 2;
  1746. break;
  1747. case BRIDGE_OVFX2:
  1748. req = 0x0a;
  1749. /* fall through */
  1750. case BRIDGE_W9968CF:
  1751. ret = usb_control_msg(sd->gspca_dev.dev,
  1752. usb_sndctrlpipe(sd->gspca_dev.dev, 0),
  1753. req,
  1754. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1755. value, index, NULL, 0, 500);
  1756. goto leave;
  1757. default:
  1758. req = 1;
  1759. }
  1760. sd->gspca_dev.usb_buf[0] = value;
  1761. ret = usb_control_msg(sd->gspca_dev.dev,
  1762. usb_sndctrlpipe(sd->gspca_dev.dev, 0),
  1763. req,
  1764. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1765. 0, index,
  1766. sd->gspca_dev.usb_buf, 1, 500);
  1767. leave:
  1768. if (ret < 0) {
  1769. err("Write reg 0x%04x -> [0x%02x] failed",
  1770. value, index);
  1771. return ret;
  1772. }
  1773. PDEBUG(D_USBO, "Write reg 0x%04x -> [0x%02x]", value, index);
  1774. return 0;
  1775. }
  1776. /* Read from a OV519 register, note not valid for the w9968cf!! */
  1777. /* returns: negative is error, pos or zero is data */
  1778. static int reg_r(struct sd *sd, u16 index)
  1779. {
  1780. int ret;
  1781. int req;
  1782. switch (sd->bridge) {
  1783. case BRIDGE_OV511:
  1784. case BRIDGE_OV511PLUS:
  1785. req = 3;
  1786. break;
  1787. case BRIDGE_OVFX2:
  1788. req = 0x0b;
  1789. break;
  1790. default:
  1791. req = 1;
  1792. }
  1793. ret = usb_control_msg(sd->gspca_dev.dev,
  1794. usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
  1795. req,
  1796. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1797. 0, index, sd->gspca_dev.usb_buf, 1, 500);
  1798. if (ret >= 0) {
  1799. ret = sd->gspca_dev.usb_buf[0];
  1800. PDEBUG(D_USBI, "Read reg [0x%02X] -> 0x%04X", index, ret);
  1801. } else
  1802. err("Read reg [0x%02x] failed", index);
  1803. return ret;
  1804. }
  1805. /* Read 8 values from a OV519 register */
  1806. static int reg_r8(struct sd *sd,
  1807. u16 index)
  1808. {
  1809. int ret;
  1810. ret = usb_control_msg(sd->gspca_dev.dev,
  1811. usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
  1812. 1, /* REQ_IO */
  1813. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1814. 0, index, sd->gspca_dev.usb_buf, 8, 500);
  1815. if (ret >= 0)
  1816. ret = sd->gspca_dev.usb_buf[0];
  1817. else
  1818. err("Read reg 8 [0x%02x] failed", index);
  1819. return ret;
  1820. }
  1821. /*
  1822. * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
  1823. * the same position as 1's in "mask" are cleared and set to "value". Bits
  1824. * that are in the same position as 0's in "mask" are preserved, regardless
  1825. * of their respective state in "value".
  1826. */
  1827. static int reg_w_mask(struct sd *sd,
  1828. u16 index,
  1829. u8 value,
  1830. u8 mask)
  1831. {
  1832. int ret;
  1833. u8 oldval;
  1834. if (mask != 0xff) {
  1835. value &= mask; /* Enforce mask on value */
  1836. ret = reg_r(sd, index);
  1837. if (ret < 0)
  1838. return ret;
  1839. oldval = ret & ~mask; /* Clear the masked bits */
  1840. value |= oldval; /* Set the desired bits */
  1841. }
  1842. return reg_w(sd, index, value);
  1843. }
  1844. /*
  1845. * Writes multiple (n) byte value to a single register. Only valid with certain
  1846. * registers (0x30 and 0xc4 - 0xce).
  1847. */
  1848. static int ov518_reg_w32(struct sd *sd, u16 index, u32 value, int n)
  1849. {
  1850. int ret;
  1851. *((__le32 *) sd->gspca_dev.usb_buf) = __cpu_to_le32(value);
  1852. ret = usb_control_msg(sd->gspca_dev.dev,
  1853. usb_sndctrlpipe(sd->gspca_dev.dev, 0),
  1854. 1 /* REG_IO */,
  1855. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  1856. 0, index,
  1857. sd->gspca_dev.usb_buf, n, 500);
  1858. if (ret < 0) {
  1859. err("Write reg32 [%02x] %08x failed", index, value);
  1860. return ret;
  1861. }
  1862. return 0;
  1863. }
  1864. static int ov511_i2c_w(struct sd *sd, u8 reg, u8 value)
  1865. {
  1866. int rc, retries;
  1867. PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
  1868. /* Three byte write cycle */
  1869. for (retries = 6; ; ) {
  1870. /* Select camera register */
  1871. rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
  1872. if (rc < 0)
  1873. return rc;
  1874. /* Write "value" to I2C data port of OV511 */
  1875. rc = reg_w(sd, R51x_I2C_DATA, value);
  1876. if (rc < 0)
  1877. return rc;
  1878. /* Initiate 3-byte write cycle */
  1879. rc = reg_w(sd, R511_I2C_CTL, 0x01);
  1880. if (rc < 0)
  1881. return rc;
  1882. do {
  1883. rc = reg_r(sd, R511_I2C_CTL);
  1884. } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
  1885. if (rc < 0)
  1886. return rc;
  1887. if ((rc & 2) == 0) /* Ack? */
  1888. break;
  1889. if (--retries < 0) {
  1890. PDEBUG(D_USBO, "i2c write retries exhausted");
  1891. return -1;
  1892. }
  1893. }
  1894. return 0;
  1895. }
  1896. static int ov511_i2c_r(struct sd *sd, u8 reg)
  1897. {
  1898. int rc, value, retries;
  1899. /* Two byte write cycle */
  1900. for (retries = 6; ; ) {
  1901. /* Select camera register */
  1902. rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
  1903. if (rc < 0)
  1904. return rc;
  1905. /* Initiate 2-byte write cycle */
  1906. rc = reg_w(sd, R511_I2C_CTL, 0x03);
  1907. if (rc < 0)
  1908. return rc;
  1909. do {
  1910. rc = reg_r(sd, R511_I2C_CTL);
  1911. } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
  1912. if (rc < 0)
  1913. return rc;
  1914. if ((rc & 2) == 0) /* Ack? */
  1915. break;
  1916. /* I2C abort */
  1917. reg_w(sd, R511_I2C_CTL, 0x10);
  1918. if (--retries < 0) {
  1919. PDEBUG(D_USBI, "i2c write retries exhausted");
  1920. return -1;
  1921. }
  1922. }
  1923. /* Two byte read cycle */
  1924. for (retries = 6; ; ) {
  1925. /* Initiate 2-byte read cycle */
  1926. rc = reg_w(sd, R511_I2C_CTL, 0x05);
  1927. if (rc < 0)
  1928. return rc;
  1929. do {
  1930. rc = reg_r(sd, R511_I2C_CTL);
  1931. } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
  1932. if (rc < 0)
  1933. return rc;
  1934. if ((rc & 2) == 0) /* Ack? */
  1935. break;
  1936. /* I2C abort */
  1937. rc = reg_w(sd, R511_I2C_CTL, 0x10);
  1938. if (rc < 0)
  1939. return rc;
  1940. if (--retries < 0) {
  1941. PDEBUG(D_USBI, "i2c read retries exhausted");
  1942. return -1;
  1943. }
  1944. }
  1945. value = reg_r(sd, R51x_I2C_DATA);
  1946. PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
  1947. /* This is needed to make i2c_w() work */
  1948. rc = reg_w(sd, R511_I2C_CTL, 0x05);
  1949. if (rc < 0)
  1950. return rc;
  1951. return value;
  1952. }
  1953. /*
  1954. * The OV518 I2C I/O procedure is different, hence, this function.
  1955. * This is normally only called from i2c_w(). Note that this function
  1956. * always succeeds regardless of whether the sensor is present and working.
  1957. */
  1958. static int ov518_i2c_w(struct sd *sd,
  1959. u8 reg,
  1960. u8 value)
  1961. {
  1962. int rc;
  1963. PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
  1964. /* Select camera register */
  1965. rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
  1966. if (rc < 0)
  1967. return rc;
  1968. /* Write "value" to I2C data port of OV511 */
  1969. rc = reg_w(sd, R51x_I2C_DATA, value);
  1970. if (rc < 0)
  1971. return rc;
  1972. /* Initiate 3-byte write cycle */
  1973. rc = reg_w(sd, R518_I2C_CTL, 0x01);
  1974. if (rc < 0)
  1975. return rc;
  1976. /* wait for write complete */
  1977. msleep(4);
  1978. return reg_r8(sd, R518_I2C_CTL);
  1979. }
  1980. /*
  1981. * returns: negative is error, pos or zero is data
  1982. *
  1983. * The OV518 I2C I/O procedure is different, hence, this function.
  1984. * This is normally only called from i2c_r(). Note that this function
  1985. * always succeeds regardless of whether the sensor is present and working.
  1986. */
  1987. static int ov518_i2c_r(struct sd *sd, u8 reg)
  1988. {
  1989. int rc, value;
  1990. /* Select camera register */
  1991. rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
  1992. if (rc < 0)
  1993. return rc;
  1994. /* Initiate 2-byte write cycle */
  1995. rc = reg_w(sd, R518_I2C_CTL, 0x03);
  1996. if (rc < 0)
  1997. return rc;
  1998. /* Initiate 2-byte read cycle */
  1999. rc = reg_w(sd, R518_I2C_CTL, 0x05);
  2000. if (rc < 0)
  2001. return rc;
  2002. value = reg_r(sd, R51x_I2C_DATA);
  2003. PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
  2004. return value;
  2005. }
  2006. static int ovfx2_i2c_w(struct sd *sd, u8 reg, u8 value)
  2007. {
  2008. int ret;
  2009. ret = usb_control_msg(sd->gspca_dev.dev,
  2010. usb_sndctrlpipe(sd->gspca_dev.dev, 0),
  2011. 0x02,
  2012. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  2013. (u16) value, (u16) reg, NULL, 0, 500);
  2014. if (ret < 0) {
  2015. err("i2c 0x%02x -> [0x%02x] failed", value, reg);
  2016. return ret;
  2017. }
  2018. PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
  2019. return 0;
  2020. }
  2021. static int ovfx2_i2c_r(struct sd *sd, u8 reg)
  2022. {
  2023. int ret;
  2024. ret = usb_control_msg(sd->gspca_dev.dev,
  2025. usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
  2026. 0x03,
  2027. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  2028. 0, (u16) reg, sd->gspca_dev.usb_buf, 1, 500);
  2029. if (ret >= 0) {
  2030. ret = sd->gspca_dev.usb_buf[0];
  2031. PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, ret);
  2032. } else
  2033. err("i2c read [0x%02x] failed", reg);
  2034. return ret;
  2035. }
  2036. static int i2c_w(struct sd *sd, u8 reg, u8 value)
  2037. {
  2038. int ret = -1;
  2039. if (sd->sensor_reg_cache[reg] == value)
  2040. return 0;
  2041. switch (sd->bridge) {
  2042. case BRIDGE_OV511:
  2043. case BRIDGE_OV511PLUS:
  2044. ret = ov511_i2c_w(sd, reg, value);
  2045. break;
  2046. case BRIDGE_OV518:
  2047. case BRIDGE_OV518PLUS:
  2048. case BRIDGE_OV519:
  2049. ret = ov518_i2c_w(sd, reg, value);
  2050. break;
  2051. case BRIDGE_OVFX2:
  2052. ret = ovfx2_i2c_w(sd, reg, value);
  2053. break;
  2054. case BRIDGE_W9968CF:
  2055. ret = w9968cf_i2c_w(sd, reg, value);
  2056. break;
  2057. }
  2058. if (ret >= 0) {
  2059. /* Up on sensor reset empty the register cache */
  2060. if (reg == 0x12 && (value & 0x80))
  2061. memset(sd->sensor_reg_cache, -1,
  2062. sizeof(sd->sensor_reg_cache));
  2063. else
  2064. sd->sensor_reg_cache[reg] = value;
  2065. }
  2066. return ret;
  2067. }
  2068. static int i2c_r(struct sd *sd, u8 reg)
  2069. {
  2070. int ret = -1;
  2071. if (sd->sensor_reg_cache[reg] != -1)
  2072. return sd->sensor_reg_cache[reg];
  2073. switch (sd->bridge) {
  2074. case BRIDGE_OV511:
  2075. case BRIDGE_OV511PLUS:
  2076. ret = ov511_i2c_r(sd, reg);
  2077. break;
  2078. case BRIDGE_OV518:
  2079. case BRIDGE_OV518PLUS:
  2080. case BRIDGE_OV519:
  2081. ret = ov518_i2c_r(sd, reg);
  2082. break;
  2083. case BRIDGE_OVFX2:
  2084. ret = ovfx2_i2c_r(sd, reg);
  2085. break;
  2086. case BRIDGE_W9968CF:
  2087. ret = w9968cf_i2c_r(sd, reg);
  2088. break;
  2089. }
  2090. if (ret >= 0)
  2091. sd->sensor_reg_cache[reg] = ret;
  2092. return ret;
  2093. }
  2094. /* Writes bits at positions specified by mask to an I2C reg. Bits that are in
  2095. * the same position as 1's in "mask" are cleared and set to "value". Bits
  2096. * that are in the same position as 0's in "mask" are preserved, regardless
  2097. * of their respective state in "value".
  2098. */
  2099. static int i2c_w_mask(struct sd *sd,
  2100. u8 reg,
  2101. u8 value,
  2102. u8 mask)
  2103. {
  2104. int rc;
  2105. u8 oldval;
  2106. value &= mask; /* Enforce mask on value */
  2107. rc = i2c_r(sd, reg);
  2108. if (rc < 0)
  2109. return rc;
  2110. oldval = rc & ~mask; /* Clear the masked bits */
  2111. value |= oldval; /* Set the desired bits */
  2112. return i2c_w(sd, reg, value);
  2113. }
  2114. /* Temporarily stops OV511 from functioning. Must do this before changing
  2115. * registers while the camera is streaming */
  2116. static inline int ov51x_stop(struct sd *sd)
  2117. {
  2118. PDEBUG(D_STREAM, "stopping");
  2119. sd->stopped = 1;
  2120. switch (sd->bridge) {
  2121. case BRIDGE_OV511:
  2122. case BRIDGE_OV511PLUS:
  2123. return reg_w(sd, R51x_SYS_RESET, 0x3d);
  2124. case BRIDGE_OV518:
  2125. case BRIDGE_OV518PLUS:
  2126. return reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a);
  2127. case BRIDGE_OV519:
  2128. return reg_w(sd, OV519_R51_RESET1, 0x0f);
  2129. case BRIDGE_OVFX2:
  2130. return reg_w_mask(sd, 0x0f, 0x00, 0x02);
  2131. case BRIDGE_W9968CF:
  2132. return reg_w(sd, 0x3c, 0x0a05); /* stop USB transfer */
  2133. }
  2134. return 0;
  2135. }
  2136. /* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
  2137. * actually stopped (for performance). */
  2138. static inline int ov51x_restart(struct sd *sd)
  2139. {
  2140. int rc;
  2141. PDEBUG(D_STREAM, "restarting");
  2142. if (!sd->stopped)
  2143. return 0;
  2144. sd->stopped = 0;
  2145. /* Reinitialize the stream */
  2146. switch (sd->bridge) {
  2147. case BRIDGE_OV511:
  2148. case BRIDGE_OV511PLUS:
  2149. return reg_w(sd, R51x_SYS_RESET, 0x00);
  2150. case BRIDGE_OV518:
  2151. case BRIDGE_OV518PLUS:
  2152. rc = reg_w(sd, 0x2f, 0x80);
  2153. if (rc < 0)
  2154. return rc;
  2155. return reg_w(sd, R51x_SYS_RESET, 0x00);
  2156. case BRIDGE_OV519:
  2157. return reg_w(sd, OV519_R51_RESET1, 0x00);
  2158. case BRIDGE_OVFX2:
  2159. return reg_w_mask(sd, 0x0f, 0x02, 0x02);
  2160. case BRIDGE_W9968CF:
  2161. return reg_w(sd, 0x3c, 0x8a05); /* USB FIFO enable */
  2162. }
  2163. return 0;
  2164. }
  2165. static int ov51x_set_slave_ids(struct sd *sd, u8 slave);
  2166. /* This does an initial reset of an OmniVision sensor and ensures that I2C
  2167. * is synchronized. Returns <0 on failure.
  2168. */
  2169. static int init_ov_sensor(struct sd *sd, u8 slave)
  2170. {
  2171. int i;
  2172. if (ov51x_set_slave_ids(sd, slave) < 0)
  2173. return -EIO;
  2174. /* Reset the sensor */
  2175. if (i2c_w(sd, 0x12, 0x80) < 0)
  2176. return -EIO;
  2177. /* Wait for it to initialize */
  2178. msleep(150);
  2179. for (i = 0; i < i2c_detect_tries; i++) {
  2180. if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
  2181. i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
  2182. PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
  2183. return 0;
  2184. }
  2185. /* Reset the sensor */
  2186. if (i2c_w(sd, 0x12, 0x80) < 0)
  2187. return -EIO;
  2188. /* Wait for it to initialize */
  2189. msleep(150);
  2190. /* Dummy read to sync I2C */
  2191. if (i2c_r(sd, 0x00) < 0)
  2192. return -EIO;
  2193. }
  2194. return -EIO;
  2195. }
  2196. /* Set the read and write slave IDs. The "slave" argument is the write slave,
  2197. * and the read slave will be set to (slave + 1).
  2198. * This should not be called from outside the i2c I/O functions.
  2199. * Sets I2C read and write slave IDs. Returns <0 for error
  2200. */
  2201. static int ov51x_set_slave_ids(struct sd *sd,
  2202. u8 slave)
  2203. {
  2204. int rc;
  2205. switch (sd->bridge) {
  2206. case BRIDGE_OVFX2:
  2207. return reg_w(sd, OVFX2_I2C_ADDR, slave);
  2208. case BRIDGE_W9968CF:
  2209. sd->sensor_addr = slave;
  2210. return 0;
  2211. }
  2212. rc = reg_w(sd, R51x_I2C_W_SID, slave);
  2213. if (rc < 0)
  2214. return rc;
  2215. return reg_w(sd, R51x_I2C_R_SID, slave + 1);
  2216. }
  2217. static int write_regvals(struct sd *sd,
  2218. const struct ov_regvals *regvals,
  2219. int n)
  2220. {
  2221. int rc;
  2222. while (--n >= 0) {
  2223. rc = reg_w(sd, regvals->reg, regvals->val);
  2224. if (rc < 0)
  2225. return rc;
  2226. regvals++;
  2227. }
  2228. return 0;
  2229. }
  2230. static int write_i2c_regvals(struct sd *sd,
  2231. const struct ov_i2c_regvals *regvals,
  2232. int n)
  2233. {
  2234. int rc;
  2235. while (--n >= 0) {
  2236. rc = i2c_w(sd, regvals->reg, regvals->val);
  2237. if (rc < 0)
  2238. return rc;
  2239. regvals++;
  2240. }
  2241. return 0;
  2242. }
  2243. /****************************************************************************
  2244. *
  2245. * OV511 and sensor configuration
  2246. *
  2247. ***************************************************************************/
  2248. /* This initializes the OV2x10 / OV3610 / OV3620 */
  2249. static int ov_hires_configure(struct sd *sd)
  2250. {
  2251. int high, low;
  2252. if (sd->bridge != BRIDGE_OVFX2) {
  2253. err("error hires sensors only supported with ovfx2");
  2254. return -1;
  2255. }
  2256. PDEBUG(D_PROBE, "starting ov hires configuration");
  2257. /* Detect sensor (sub)type */
  2258. high = i2c_r(sd, 0x0a);
  2259. low = i2c_r(sd, 0x0b);
  2260. /* info("%x, %x", high, low); */
  2261. if (high == 0x96 && low == 0x40) {
  2262. PDEBUG(D_PROBE, "Sensor is an OV2610");
  2263. sd->sensor = SEN_OV2610;
  2264. } else if (high == 0x36 && (low & 0x0f) == 0x00) {
  2265. PDEBUG(D_PROBE, "Sensor is an OV3610");
  2266. sd->sensor = SEN_OV3610;
  2267. } else {
  2268. err("Error unknown sensor type: 0x%02x%02x",
  2269. high, low);
  2270. return -1;
  2271. }
  2272. /* Set sensor-specific vars */
  2273. return 0;
  2274. }
  2275. /* This initializes the OV8110, OV8610 sensor. The OV8110 uses
  2276. * the same register settings as the OV8610, since they are very similar.
  2277. */
  2278. static int ov8xx0_configure(struct sd *sd)
  2279. {
  2280. int rc;
  2281. PDEBUG(D_PROBE, "starting ov8xx0 configuration");
  2282. /* Detect sensor (sub)type */
  2283. rc = i2c_r(sd, OV7610_REG_COM_I);
  2284. if (rc < 0) {
  2285. PDEBUG(D_ERR, "Error detecting sensor type");
  2286. return -1;
  2287. }
  2288. if ((rc & 3) == 1) {
  2289. sd->sensor = SEN_OV8610;
  2290. } else {
  2291. err("Unknown image sensor version: %d", rc & 3);
  2292. return -1;
  2293. }
  2294. /* Set sensor-specific vars */
  2295. return 0;
  2296. }
  2297. /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
  2298. * the same register settings as the OV7610, since they are very similar.
  2299. */
  2300. static int ov7xx0_configure(struct sd *sd)
  2301. {
  2302. int rc, high, low;
  2303. PDEBUG(D_PROBE, "starting OV7xx0 configuration");
  2304. /* Detect sensor (sub)type */
  2305. rc = i2c_r(sd, OV7610_REG_COM_I);
  2306. /* add OV7670 here
  2307. * it appears to be wrongly detected as a 7610 by default */
  2308. if (rc < 0) {
  2309. PDEBUG(D_ERR, "Error detecting sensor type");
  2310. return -1;
  2311. }
  2312. if ((rc & 3) == 3) {
  2313. /* quick hack to make OV7670s work */
  2314. high = i2c_r(sd, 0x0a);
  2315. low = i2c_r(sd, 0x0b);
  2316. /* info("%x, %x", high, low); */
  2317. if (high == 0x76 && low == 0x73) {
  2318. PDEBUG(D_PROBE, "Sensor is an OV7670");
  2319. sd->sensor = SEN_OV7670;
  2320. } else {
  2321. PDEBUG(D_PROBE, "Sensor is an OV7610");
  2322. sd->sensor = SEN_OV7610;
  2323. }
  2324. } else if ((rc & 3) == 1) {
  2325. /* I don't know what's different about the 76BE yet. */
  2326. if (i2c_r(sd, 0x15) & 1) {
  2327. PDEBUG(D_PROBE, "Sensor is an OV7620AE");
  2328. sd->sensor = SEN_OV7620AE;
  2329. } else {
  2330. PDEBUG(D_PROBE, "Sensor is an OV76BE");
  2331. sd->sensor = SEN_OV76BE;
  2332. }
  2333. } else if ((rc & 3) == 0) {
  2334. /* try to read product id registers */
  2335. high = i2c_r(sd, 0x0a);
  2336. if (high < 0) {
  2337. PDEBUG(D_ERR, "Error detecting camera chip PID");
  2338. return high;
  2339. }
  2340. low = i2c_r(sd, 0x0b);
  2341. if (low < 0) {
  2342. PDEBUG(D_ERR, "Error detecting camera chip VER");
  2343. return low;
  2344. }
  2345. if (high == 0x76) {
  2346. switch (low) {
  2347. case 0x30:
  2348. err("Sensor is an OV7630/OV7635");
  2349. err("7630 is not supported by this driver");
  2350. return -1;
  2351. case 0x40:
  2352. PDEBUG(D_PROBE, "Sensor is an OV7645");
  2353. sd->sensor = SEN_OV7640; /* FIXME */
  2354. break;
  2355. case 0x45:
  2356. PDEBUG(D_PROBE, "Sensor is an OV7645B");
  2357. sd->sensor = SEN_OV7640; /* FIXME */
  2358. break;
  2359. case 0x48:
  2360. PDEBUG(D_PROBE, "Sensor is an OV7648");
  2361. sd->sensor = SEN_OV7648;
  2362. break;
  2363. default:
  2364. PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
  2365. return -1;
  2366. }
  2367. } else {
  2368. PDEBUG(D_PROBE, "Sensor is an OV7620");
  2369. sd->sensor = SEN_OV7620;
  2370. }
  2371. } else {
  2372. err("Unknown image sensor version: %d", rc & 3);
  2373. return -1;
  2374. }
  2375. /* Set sensor-specific vars */
  2376. return 0;
  2377. }
  2378. /* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
  2379. static int ov6xx0_configure(struct sd *sd)
  2380. {
  2381. int rc;
  2382. PDEBUG(D_PROBE, "starting OV6xx0 configuration");
  2383. /* Detect sensor (sub)type */
  2384. rc = i2c_r(sd, OV7610_REG_COM_I);
  2385. if (rc < 0) {
  2386. PDEBUG(D_ERR, "Error detecting sensor type");
  2387. return -1;
  2388. }
  2389. /* Ugh. The first two bits are the version bits, but
  2390. * the entire register value must be used. I guess OVT
  2391. * underestimated how many variants they would make. */
  2392. switch (rc) {
  2393. case 0x00:
  2394. sd->sensor = SEN_OV6630;
  2395. warn("WARNING: Sensor is an OV66308. Your camera may have");
  2396. warn("been misdetected in previous driver versions.");
  2397. break;
  2398. case 0x01:
  2399. sd->sensor = SEN_OV6620;
  2400. PDEBUG(D_PROBE, "Sensor is an OV6620");
  2401. break;
  2402. case 0x02:
  2403. sd->sensor = SEN_OV6630;
  2404. PDEBUG(D_PROBE, "Sensor is an OV66308AE");
  2405. break;
  2406. case 0x03:
  2407. sd->sensor = SEN_OV66308AF;
  2408. PDEBUG(D_PROBE, "Sensor is an OV66308AF");
  2409. break;
  2410. case 0x90:
  2411. sd->sensor = SEN_OV6630;
  2412. warn("WARNING: Sensor is an OV66307. Your camera may have");
  2413. warn("been misdetected in previous driver versions.");
  2414. break;
  2415. default:
  2416. err("FATAL: Unknown sensor version: 0x%02x", rc);
  2417. return -1;
  2418. }
  2419. /* Set sensor-specific vars */
  2420. sd->sif = 1;
  2421. return 0;
  2422. }
  2423. /* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
  2424. static void ov51x_led_control(struct sd *sd, int on)
  2425. {
  2426. if (sd->invert_led)
  2427. on = !on;
  2428. switch (sd->bridge) {
  2429. /* OV511 has no LED control */
  2430. case BRIDGE_OV511PLUS:
  2431. reg_w(sd, R511_SYS_LED_CTL, on ? 1 : 0);
  2432. break;
  2433. case BRIDGE_OV518:
  2434. case BRIDGE_OV518PLUS:
  2435. reg_w_mask(sd, R518_GPIO_OUT, on ? 0x02 : 0x00, 0x02);
  2436. break;
  2437. case BRIDGE_OV519:
  2438. reg_w_mask(sd, OV519_GPIO_DATA_OUT0, !on, 1); /* 0 / 1 */
  2439. break;
  2440. }
  2441. }
  2442. static void sd_reset_snapshot(struct gspca_dev *gspca_dev)
  2443. {
  2444. struct sd *sd = (struct sd *) gspca_dev;
  2445. if (!sd->snapshot_needs_reset)
  2446. return;
  2447. /* Note it is important that we clear sd->snapshot_needs_reset,
  2448. before actually clearing the snapshot state in the bridge
  2449. otherwise we might race with the pkt_scan interrupt handler */
  2450. sd->snapshot_needs_reset = 0;
  2451. switch (sd->bridge) {
  2452. case BRIDGE_OV511:
  2453. case BRIDGE_OV511PLUS:
  2454. reg_w(sd, R51x_SYS_SNAP, 0x02);
  2455. reg_w(sd, R51x_SYS_SNAP, 0x00);
  2456. break;
  2457. case BRIDGE_OV518:
  2458. case BRIDGE_OV518PLUS:
  2459. reg_w(sd, R51x_SYS_SNAP, 0x02); /* Reset */
  2460. reg_w(sd, R51x_SYS_SNAP, 0x01); /* Enable */
  2461. break;
  2462. case BRIDGE_OV519:
  2463. reg_w(sd, R51x_SYS_RESET, 0x40);
  2464. reg_w(sd, R51x_SYS_RESET, 0x00);
  2465. break;
  2466. }
  2467. }
  2468. static int ov51x_upload_quan_tables(struct sd *sd)
  2469. {
  2470. const unsigned char yQuanTable511[] = {
  2471. 0, 1, 1, 2, 2, 3, 3, 4,
  2472. 1, 1, 1, 2, 2, 3, 4, 4,
  2473. 1, 1, 2, 2, 3, 4, 4, 4,
  2474. 2, 2, 2, 3, 4, 4, 4, 4,
  2475. 2, 2, 3, 4, 4, 5, 5, 5,
  2476. 3, 3, 4, 4, 5, 5, 5, 5,
  2477. 3, 4, 4, 4, 5, 5, 5, 5,
  2478. 4, 4, 4, 4, 5, 5, 5, 5
  2479. };
  2480. const unsigned char uvQuanTable511[] = {
  2481. 0, 2, 2, 3, 4, 4, 4, 4,
  2482. 2, 2, 2, 4, 4, 4, 4, 4,
  2483. 2, 2, 3, 4, 4, 4, 4, 4,
  2484. 3, 4, 4, 4, 4, 4, 4, 4,
  2485. 4, 4, 4, 4, 4, 4, 4, 4,
  2486. 4, 4, 4, 4, 4, 4, 4, 4,
  2487. 4, 4, 4, 4, 4, 4, 4, 4,
  2488. 4, 4, 4, 4, 4, 4, 4, 4
  2489. };
  2490. /* OV518 quantization tables are 8x4 (instead of 8x8) */
  2491. const unsigned char yQuanTable518[] = {
  2492. 5, 4, 5, 6, 6, 7, 7, 7,
  2493. 5, 5, 5, 5, 6, 7, 7, 7,
  2494. 6, 6, 6, 6, 7, 7, 7, 8,
  2495. 7, 7, 6, 7, 7, 7, 8, 8
  2496. };
  2497. const unsigned char uvQuanTable518[] = {
  2498. 6, 6, 6, 7, 7, 7, 7, 7,
  2499. 6, 6, 6, 7, 7, 7, 7, 7,
  2500. 6, 6, 6, 7, 7, 7, 7, 8,
  2501. 7, 7, 7, 7, 7, 7, 8, 8
  2502. };
  2503. const unsigned char *pYTable, *pUVTable;
  2504. unsigned char val0, val1;
  2505. int i, size, rc, reg = R51x_COMP_LUT_BEGIN;
  2506. PDEBUG(D_PROBE, "Uploading quantization tables");
  2507. if (sd->bridge == BRIDGE_OV511 || sd->bridge == BRIDGE_OV511PLUS) {
  2508. pYTable = yQuanTable511;
  2509. pUVTable = uvQuanTable511;
  2510. size = 32;
  2511. } else {
  2512. pYTable = yQuanTable518;
  2513. pUVTable = uvQuanTable518;
  2514. size = 16;
  2515. }
  2516. for (i = 0; i < size; i++) {
  2517. val0 = *pYTable++;
  2518. val1 = *pYTable++;
  2519. val0 &= 0x0f;
  2520. val1 &= 0x0f;
  2521. val0 |= val1 << 4;
  2522. rc = reg_w(sd, reg, val0);
  2523. if (rc < 0)
  2524. return rc;
  2525. val0 = *pUVTable++;
  2526. val1 = *pUVTable++;
  2527. val0 &= 0x0f;
  2528. val1 &= 0x0f;
  2529. val0 |= val1 << 4;
  2530. rc = reg_w(sd, reg + size, val0);
  2531. if (rc < 0)
  2532. return rc;
  2533. reg++;
  2534. }
  2535. return 0;
  2536. }
  2537. /* This initializes the OV511/OV511+ and the sensor */
  2538. static int ov511_configure(struct gspca_dev *gspca_dev)
  2539. {
  2540. struct sd *sd = (struct sd *) gspca_dev;
  2541. int rc;
  2542. /* For 511 and 511+ */
  2543. const struct ov_regvals init_511[] = {
  2544. { R51x_SYS_RESET, 0x7f },
  2545. { R51x_SYS_INIT, 0x01 },
  2546. { R51x_SYS_RESET, 0x7f },
  2547. { R51x_SYS_INIT, 0x01 },
  2548. { R51x_SYS_RESET, 0x3f },
  2549. { R51x_SYS_INIT, 0x01 },
  2550. { R51x_SYS_RESET, 0x3d },
  2551. };
  2552. const struct ov_regvals norm_511[] = {
  2553. { R511_DRAM_FLOW_CTL, 0x01 },
  2554. { R51x_SYS_SNAP, 0x00 },
  2555. { R51x_SYS_SNAP, 0x02 },
  2556. { R51x_SYS_SNAP, 0x00 },
  2557. { R511_FIFO_OPTS, 0x1f },
  2558. { R511_COMP_EN, 0x00 },
  2559. { R511_COMP_LUT_EN, 0x03 },
  2560. };
  2561. const struct ov_regvals norm_511_p[] = {
  2562. { R511_DRAM_FLOW_CTL, 0xff },
  2563. { R51x_SYS_SNAP, 0x00 },
  2564. { R51x_SYS_SNAP, 0x02 },
  2565. { R51x_SYS_SNAP, 0x00 },
  2566. { R511_FIFO_OPTS, 0xff },
  2567. { R511_COMP_EN, 0x00 },
  2568. { R511_COMP_LUT_EN, 0x03 },
  2569. };
  2570. const struct ov_regvals compress_511[] = {
  2571. { 0x70, 0x1f },
  2572. { 0x71, 0x05 },
  2573. { 0x72, 0x06 },
  2574. { 0x73, 0x06 },
  2575. { 0x74, 0x14 },
  2576. { 0x75, 0x03 },
  2577. { 0x76, 0x04 },
  2578. { 0x77, 0x04 },
  2579. };
  2580. PDEBUG(D_PROBE, "Device custom id %x", reg_r(sd, R51x_SYS_CUST_ID));
  2581. rc = write_regvals(sd, init_511, ARRAY_SIZE(init_511));
  2582. if (rc < 0)
  2583. return rc;
  2584. switch (sd->bridge) {
  2585. case BRIDGE_OV511:
  2586. rc = write_regvals(sd, norm_511, ARRAY_SIZE(norm_511));
  2587. if (rc < 0)
  2588. return rc;
  2589. break;
  2590. case BRIDGE_OV511PLUS:
  2591. rc = write_regvals(sd, norm_511_p, ARRAY_SIZE(norm_511_p));
  2592. if (rc < 0)
  2593. return rc;
  2594. break;
  2595. }
  2596. /* Init compression */
  2597. rc = write_regvals(sd, compress_511, ARRAY_SIZE(compress_511));
  2598. if (rc < 0)
  2599. return rc;
  2600. rc = ov51x_upload_quan_tables(sd);
  2601. if (rc < 0) {
  2602. PDEBUG(D_ERR, "Error uploading quantization tables");
  2603. return rc;
  2604. }
  2605. return 0;
  2606. }
  2607. /* This initializes the OV518/OV518+ and the sensor */
  2608. static int ov518_configure(struct gspca_dev *gspca_dev)
  2609. {
  2610. struct sd *sd = (struct sd *) gspca_dev;
  2611. int rc;
  2612. /* For 518 and 518+ */
  2613. const struct ov_regvals init_518[] = {
  2614. { R51x_SYS_RESET, 0x40 },
  2615. { R51x_SYS_INIT, 0xe1 },
  2616. { R51x_SYS_RESET, 0x3e },
  2617. { R51x_SYS_INIT, 0xe1 },
  2618. { R51x_SYS_RESET, 0x00 },
  2619. { R51x_SYS_INIT, 0xe1 },
  2620. { 0x46, 0x00 },
  2621. { 0x5d, 0x03 },
  2622. };
  2623. const struct ov_regvals norm_518[] = {
  2624. { R51x_SYS_SNAP, 0x02 }, /* Reset */
  2625. { R51x_SYS_SNAP, 0x01 }, /* Enable */
  2626. { 0x31, 0x0f },
  2627. { 0x5d, 0x03 },
  2628. { 0x24, 0x9f },
  2629. { 0x25, 0x90 },
  2630. { 0x20, 0x00 },
  2631. { 0x51, 0x04 },
  2632. { 0x71, 0x19 },
  2633. { 0x2f, 0x80 },
  2634. };
  2635. const struct ov_regvals norm_518_p[] = {
  2636. { R51x_SYS_SNAP, 0x02 }, /* Reset */
  2637. { R51x_SYS_SNAP, 0x01 }, /* Enable */
  2638. { 0x31, 0x0f },
  2639. { 0x5d, 0x03 },
  2640. { 0x24, 0x9f },
  2641. { 0x25, 0x90 },
  2642. { 0x20, 0x60 },
  2643. { 0x51, 0x02 },
  2644. { 0x71, 0x19 },
  2645. { 0x40, 0xff },
  2646. { 0x41, 0x42 },
  2647. { 0x46, 0x00 },
  2648. { 0x33, 0x04 },
  2649. { 0x21, 0x19 },
  2650. { 0x3f, 0x10 },
  2651. { 0x2f, 0x80 },
  2652. };
  2653. /* First 5 bits of custom ID reg are a revision ID on OV518 */
  2654. PDEBUG(D_PROBE, "Device revision %d",
  2655. 0x1f & reg_r(sd, R51x_SYS_CUST_ID));
  2656. rc = write_regvals(sd, init_518, ARRAY_SIZE(init_518));
  2657. if (rc < 0)
  2658. return rc;
  2659. /* Set LED GPIO pin to output mode */
  2660. rc = reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02);
  2661. if (rc < 0)
  2662. return rc;
  2663. switch (sd->bridge) {
  2664. case BRIDGE_OV518:
  2665. rc = write_regvals(sd, norm_518, ARRAY_SIZE(norm_518));
  2666. if (rc < 0)
  2667. return rc;
  2668. break;
  2669. case BRIDGE_OV518PLUS:
  2670. rc = write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p));
  2671. if (rc < 0)
  2672. return rc;
  2673. break;
  2674. }
  2675. rc = ov51x_upload_quan_tables(sd);
  2676. if (rc < 0) {
  2677. PDEBUG(D_ERR, "Error uploading quantization tables");
  2678. return rc;
  2679. }
  2680. rc = reg_w(sd, 0x2f, 0x80);
  2681. if (rc < 0)
  2682. return rc;
  2683. return 0;
  2684. }
  2685. static int ov519_configure(struct sd *sd)
  2686. {
  2687. static const struct ov_regvals init_519[] = {
  2688. { 0x5a, 0x6d }, /* EnableSystem */
  2689. { 0x53, 0x9b },
  2690. { OV519_R54_EN_CLK1, 0xff }, /* set bit2 to enable jpeg */
  2691. { 0x5d, 0x03 },
  2692. { 0x49, 0x01 },
  2693. { 0x48, 0x00 },
  2694. /* Set LED pin to output mode. Bit 4 must be cleared or sensor
  2695. * detection will fail. This deserves further investigation. */
  2696. { OV519_GPIO_IO_CTRL0, 0xee },
  2697. { OV519_R51_RESET1, 0x0f },
  2698. { OV519_R51_RESET1, 0x00 },
  2699. { 0x22, 0x00 },
  2700. /* windows reads 0x55 at this point*/
  2701. };
  2702. return write_regvals(sd, init_519, ARRAY_SIZE(init_519));
  2703. }
  2704. static int ovfx2_configure(struct sd *sd)
  2705. {
  2706. static const struct ov_regvals init_fx2[] = {
  2707. { 0x00, 0x60 },
  2708. { 0x02, 0x01 },
  2709. { 0x0f, 0x1d },
  2710. { 0xe9, 0x82 },
  2711. { 0xea, 0xc7 },
  2712. { 0xeb, 0x10 },
  2713. { 0xec, 0xf6 },
  2714. };
  2715. sd->stopped = 1;
  2716. return write_regvals(sd, init_fx2, ARRAY_SIZE(init_fx2));
  2717. }
  2718. /* this function is called at probe time */
  2719. static int sd_config(struct gspca_dev *gspca_dev,
  2720. const struct usb_device_id *id)
  2721. {
  2722. struct sd *sd = (struct sd *) gspca_dev;
  2723. struct cam *cam = &gspca_dev->cam;
  2724. int ret = 0;
  2725. sd->bridge = id->driver_info & BRIDGE_MASK;
  2726. sd->invert_led = id->driver_info & BRIDGE_INVERT_LED;
  2727. switch (sd->bridge) {
  2728. case BRIDGE_OV511:
  2729. case BRIDGE_OV511PLUS:
  2730. ret = ov511_configure(gspca_dev);
  2731. break;
  2732. case BRIDGE_OV518:
  2733. case BRIDGE_OV518PLUS:
  2734. ret = ov518_configure(gspca_dev);
  2735. break;
  2736. case BRIDGE_OV519:
  2737. ret = ov519_configure(sd);
  2738. break;
  2739. case BRIDGE_OVFX2:
  2740. ret = ovfx2_configure(sd);
  2741. cam->bulk_size = OVFX2_BULK_SIZE;
  2742. cam->bulk_nurbs = MAX_NURBS;
  2743. cam->bulk = 1;
  2744. break;
  2745. case BRIDGE_W9968CF:
  2746. ret = w9968cf_configure(sd);
  2747. cam->reverse_alts = 1;
  2748. break;
  2749. }
  2750. if (ret)
  2751. goto error;
  2752. ov51x_led_control(sd, 0); /* turn LED off */
  2753. /* The OV519 must be more aggressive about sensor detection since
  2754. * I2C write will never fail if the sensor is not present. We have
  2755. * to try to initialize the sensor to detect its presence */
  2756. sd->sensor = -1;
  2757. /* Test for 76xx */
  2758. if (init_ov_sensor(sd, OV7xx0_SID) >= 0) {
  2759. if (ov7xx0_configure(sd) < 0) {
  2760. PDEBUG(D_ERR, "Failed to configure OV7xx0");
  2761. goto error;
  2762. }
  2763. /* Test for 6xx0 */
  2764. } else if (init_ov_sensor(sd, OV6xx0_SID) >= 0) {
  2765. if (ov6xx0_configure(sd) < 0) {
  2766. PDEBUG(D_ERR, "Failed to configure OV6xx0");
  2767. goto error;
  2768. }
  2769. /* Test for 8xx0 */
  2770. } else if (init_ov_sensor(sd, OV8xx0_SID) >= 0) {
  2771. if (ov8xx0_configure(sd) < 0) {
  2772. PDEBUG(D_ERR, "Failed to configure OV8xx0");
  2773. goto error;
  2774. }
  2775. /* Test for 3xxx / 2xxx */
  2776. } else if (init_ov_sensor(sd, OV_HIRES_SID) >= 0) {
  2777. if (ov_hires_configure(sd) < 0) {
  2778. PDEBUG(D_ERR, "Failed to configure high res OV");
  2779. goto error;
  2780. }
  2781. } else {
  2782. err("Can't determine sensor slave IDs");
  2783. goto error;
  2784. }
  2785. if (sd->sensor < 0)
  2786. goto error;
  2787. switch (sd->bridge) {
  2788. case BRIDGE_OV511:
  2789. case BRIDGE_OV511PLUS:
  2790. if (!sd->sif) {
  2791. cam->cam_mode = ov511_vga_mode;
  2792. cam->nmodes = ARRAY_SIZE(ov511_vga_mode);
  2793. } else {
  2794. cam->cam_mode = ov511_sif_mode;
  2795. cam->nmodes = ARRAY_SIZE(ov511_sif_mode);
  2796. }
  2797. break;
  2798. case BRIDGE_OV518:
  2799. case BRIDGE_OV518PLUS:
  2800. if (!sd->sif) {
  2801. cam->cam_mode = ov518_vga_mode;
  2802. cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
  2803. } else {
  2804. cam->cam_mode = ov518_sif_mode;
  2805. cam->nmodes = ARRAY_SIZE(ov518_sif_mode);
  2806. }
  2807. break;
  2808. case BRIDGE_OV519:
  2809. if (!sd->sif) {
  2810. cam->cam_mode = ov519_vga_mode;
  2811. cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
  2812. } else {
  2813. cam->cam_mode = ov519_sif_mode;
  2814. cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
  2815. }
  2816. break;
  2817. case BRIDGE_OVFX2:
  2818. if (sd->sensor == SEN_OV2610) {
  2819. cam->cam_mode = ovfx2_ov2610_mode;
  2820. cam->nmodes = ARRAY_SIZE(ovfx2_ov2610_mode);
  2821. } else if (sd->sensor == SEN_OV3610) {
  2822. cam->cam_mode = ovfx2_ov3610_mode;
  2823. cam->nmodes = ARRAY_SIZE(ovfx2_ov3610_mode);
  2824. } else if (!sd->sif) {
  2825. cam->cam_mode = ov519_vga_mode;
  2826. cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
  2827. } else {
  2828. cam->cam_mode = ov519_sif_mode;
  2829. cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
  2830. }
  2831. break;
  2832. case BRIDGE_W9968CF:
  2833. cam->cam_mode = w9968cf_vga_mode;
  2834. cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode);
  2835. if (sd->sif)
  2836. cam->nmodes--;
  2837. /* w9968cf needs initialisation once the sensor is known */
  2838. if (w9968cf_init(sd) < 0)
  2839. goto error;
  2840. break;
  2841. }
  2842. gspca_dev->cam.ctrls = sd->ctrls;
  2843. sd->quality = QUALITY_DEF;
  2844. gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
  2845. return 0;
  2846. error:
  2847. PDEBUG(D_ERR, "OV519 Config failed");
  2848. return -EINVAL;
  2849. }
  2850. /* this function is called at probe and resume time */
  2851. static int sd_init(struct gspca_dev *gspca_dev)
  2852. {
  2853. struct sd *sd = (struct sd *) gspca_dev;
  2854. /* initialize the sensor */
  2855. switch (sd->sensor) {
  2856. case SEN_OV2610:
  2857. if (write_i2c_regvals(sd, norm_2610, ARRAY_SIZE(norm_2610)))
  2858. return -EIO;
  2859. /* Enable autogain, autoexpo, awb, bandfilter */
  2860. if (i2c_w_mask(sd, 0x13, 0x27, 0x27) < 0)
  2861. return -EIO;
  2862. break;
  2863. case SEN_OV3610:
  2864. if (write_i2c_regvals(sd, norm_3620b, ARRAY_SIZE(norm_3620b)))
  2865. return -EIO;
  2866. /* Enable autogain, autoexpo, awb, bandfilter */
  2867. if (i2c_w_mask(sd, 0x13, 0x27, 0x27) < 0)
  2868. return -EIO;
  2869. break;
  2870. case SEN_OV6620:
  2871. if (write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20)))
  2872. return -EIO;
  2873. break;
  2874. case SEN_OV6630:
  2875. case SEN_OV66308AF:
  2876. sd->ctrls[CONTRAST].def = 200;
  2877. /* The default is too low for the ov6630 */
  2878. if (write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30)))
  2879. return -EIO;
  2880. break;
  2881. default:
  2882. /* case SEN_OV7610: */
  2883. /* case SEN_OV76BE: */
  2884. if (write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610)))
  2885. return -EIO;
  2886. if (i2c_w_mask(sd, 0x0e, 0x00, 0x40))
  2887. return -EIO;
  2888. break;
  2889. case SEN_OV7620:
  2890. case SEN_OV7620AE:
  2891. if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620)))
  2892. return -EIO;
  2893. break;
  2894. case SEN_OV7640:
  2895. case SEN_OV7648:
  2896. if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640)))
  2897. return -EIO;
  2898. break;
  2899. case SEN_OV7670:
  2900. sd->ctrls[FREQ].max = 3; /* auto */
  2901. sd->ctrls[FREQ].def = 3;
  2902. if (write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670)))
  2903. return -EIO;
  2904. break;
  2905. case SEN_OV8610:
  2906. if (write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610)))
  2907. return -EIO;
  2908. break;
  2909. }
  2910. return 0;
  2911. }
  2912. /* Set up the OV511/OV511+ with the given image parameters.
  2913. *
  2914. * Do not put any sensor-specific code in here (including I2C I/O functions)
  2915. */
  2916. static int ov511_mode_init_regs(struct sd *sd)
  2917. {
  2918. int hsegs, vsegs, packet_size, fps, needed;
  2919. int interlaced = 0;
  2920. struct usb_host_interface *alt;
  2921. struct usb_interface *intf;
  2922. intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
  2923. alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
  2924. if (!alt) {
  2925. err("Couldn't get altsetting");
  2926. return -EIO;
  2927. }
  2928. packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
  2929. reg_w(sd, R51x_FIFO_PSIZE, packet_size >> 5);
  2930. reg_w(sd, R511_CAM_UV_EN, 0x01);
  2931. reg_w(sd, R511_SNAP_UV_EN, 0x01);
  2932. reg_w(sd, R511_SNAP_OPTS, 0x03);
  2933. /* Here I'm assuming that snapshot size == image size.
  2934. * I hope that's always true. --claudio
  2935. */
  2936. hsegs = (sd->gspca_dev.width >> 3) - 1;
  2937. vsegs = (sd->gspca_dev.height >> 3) - 1;
  2938. reg_w(sd, R511_CAM_PXCNT, hsegs);
  2939. reg_w(sd, R511_CAM_LNCNT, vsegs);
  2940. reg_w(sd, R511_CAM_PXDIV, 0x00);
  2941. reg_w(sd, R511_CAM_LNDIV, 0x00);
  2942. /* YUV420, low pass filter on */
  2943. reg_w(sd, R511_CAM_OPTS, 0x03);
  2944. /* Snapshot additions */
  2945. reg_w(sd, R511_SNAP_PXCNT, hsegs);
  2946. reg_w(sd, R511_SNAP_LNCNT, vsegs);
  2947. reg_w(sd, R511_SNAP_PXDIV, 0x00);
  2948. reg_w(sd, R511_SNAP_LNDIV, 0x00);
  2949. /******** Set the framerate ********/
  2950. if (frame_rate > 0)
  2951. sd->frame_rate = frame_rate;
  2952. switch (sd->sensor) {
  2953. case SEN_OV6620:
  2954. /* No framerate control, doesn't like higher rates yet */
  2955. sd->clockdiv = 3;
  2956. break;
  2957. /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed
  2958. for more sensors we need to do this for them too */
  2959. case SEN_OV7620:
  2960. case SEN_OV7620AE:
  2961. case SEN_OV7640:
  2962. case SEN_OV7648:
  2963. case SEN_OV76BE:
  2964. if (sd->gspca_dev.width == 320)
  2965. interlaced = 1;
  2966. /* Fall through */
  2967. case SEN_OV6630:
  2968. case SEN_OV7610:
  2969. case SEN_OV7670:
  2970. switch (sd->frame_rate) {
  2971. case 30:
  2972. case 25:
  2973. /* Not enough bandwidth to do 640x480 @ 30 fps */
  2974. if (sd->gspca_dev.width != 640) {
  2975. sd->clockdiv = 0;
  2976. break;
  2977. }
  2978. /* Fall through for 640x480 case */
  2979. default:
  2980. /* case 20: */
  2981. /* case 15: */
  2982. sd->clockdiv = 1;
  2983. break;
  2984. case 10:
  2985. sd->clockdiv = 2;
  2986. break;
  2987. case 5:
  2988. sd->clockdiv = 5;
  2989. break;
  2990. }
  2991. if (interlaced) {
  2992. sd->clockdiv = (sd->clockdiv + 1) * 2 - 1;
  2993. /* Higher then 10 does not work */
  2994. if (sd->clockdiv > 10)
  2995. sd->clockdiv = 10;
  2996. }
  2997. break;
  2998. case SEN_OV8610:
  2999. /* No framerate control ?? */
  3000. sd->clockdiv = 0;
  3001. break;
  3002. }
  3003. /* Check if we have enough bandwidth to disable compression */
  3004. fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1;
  3005. needed = fps * sd->gspca_dev.width * sd->gspca_dev.height * 3 / 2;
  3006. /* 1400 is a conservative estimate of the max nr of isoc packets/sec */
  3007. if (needed > 1400 * packet_size) {
  3008. /* Enable Y and UV quantization and compression */
  3009. reg_w(sd, R511_COMP_EN, 0x07);
  3010. reg_w(sd, R511_COMP_LUT_EN, 0x03);
  3011. } else {
  3012. reg_w(sd, R511_COMP_EN, 0x06);
  3013. reg_w(sd, R511_COMP_LUT_EN, 0x00);
  3014. }
  3015. reg_w(sd, R51x_SYS_RESET, OV511_RESET_OMNICE);
  3016. reg_w(sd, R51x_SYS_RESET, 0);
  3017. return 0;
  3018. }
  3019. /* Sets up the OV518/OV518+ with the given image parameters
  3020. *
  3021. * OV518 needs a completely different approach, until we can figure out what
  3022. * the individual registers do. Also, only 15 FPS is supported now.
  3023. *
  3024. * Do not put any sensor-specific code in here (including I2C I/O functions)
  3025. */
  3026. static int ov518_mode_init_regs(struct sd *sd)
  3027. {
  3028. int hsegs, vsegs, packet_size;
  3029. struct usb_host_interface *alt;
  3030. struct usb_interface *intf;
  3031. intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
  3032. alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
  3033. if (!alt) {
  3034. err("Couldn't get altsetting");
  3035. return -EIO;
  3036. }
  3037. packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
  3038. ov518_reg_w32(sd, R51x_FIFO_PSIZE, packet_size & ~7, 2);
  3039. /******** Set the mode ********/
  3040. reg_w(sd, 0x2b, 0);
  3041. reg_w(sd, 0x2c, 0);
  3042. reg_w(sd, 0x2d, 0);
  3043. reg_w(sd, 0x2e, 0);
  3044. reg_w(sd, 0x3b, 0);
  3045. reg_w(sd, 0x3c, 0);
  3046. reg_w(sd, 0x3d, 0);
  3047. reg_w(sd, 0x3e, 0);
  3048. if (sd->bridge == BRIDGE_OV518) {
  3049. /* Set 8-bit (YVYU) input format */
  3050. reg_w_mask(sd, 0x20, 0x08, 0x08);
  3051. /* Set 12-bit (4:2:0) output format */
  3052. reg_w_mask(sd, 0x28, 0x80, 0xf0);
  3053. reg_w_mask(sd, 0x38, 0x80, 0xf0);
  3054. } else {
  3055. reg_w(sd, 0x28, 0x80);
  3056. reg_w(sd, 0x38, 0x80);
  3057. }
  3058. hsegs = sd->gspca_dev.width / 16;
  3059. vsegs = sd->gspca_dev.height / 4;
  3060. reg_w(sd, 0x29, hsegs);
  3061. reg_w(sd, 0x2a, vsegs);
  3062. reg_w(sd, 0x39, hsegs);
  3063. reg_w(sd, 0x3a, vsegs);
  3064. /* Windows driver does this here; who knows why */
  3065. reg_w(sd, 0x2f, 0x80);
  3066. /******** Set the framerate ********/
  3067. sd->clockdiv = 1;
  3068. /* Mode independent, but framerate dependent, regs */
  3069. /* 0x51: Clock divider; Only works on some cams which use 2 crystals */
  3070. reg_w(sd, 0x51, 0x04);
  3071. reg_w(sd, 0x22, 0x18);
  3072. reg_w(sd, 0x23, 0xff);
  3073. if (sd->bridge == BRIDGE_OV518PLUS) {
  3074. switch (sd->sensor) {
  3075. case SEN_OV7620AE:
  3076. if (sd->gspca_dev.width == 320) {
  3077. reg_w(sd, 0x20, 0x00);
  3078. reg_w(sd, 0x21, 0x19);
  3079. } else {
  3080. reg_w(sd, 0x20, 0x60);
  3081. reg_w(sd, 0x21, 0x1f);
  3082. }
  3083. break;
  3084. case SEN_OV7620:
  3085. reg_w(sd, 0x20, 0x00);
  3086. reg_w(sd, 0x21, 0x19);
  3087. break;
  3088. default:
  3089. reg_w(sd, 0x21, 0x19);
  3090. }
  3091. } else
  3092. reg_w(sd, 0x71, 0x17); /* Compression-related? */
  3093. /* FIXME: Sensor-specific */
  3094. /* Bit 5 is what matters here. Of course, it is "reserved" */
  3095. i2c_w(sd, 0x54, 0x23);
  3096. reg_w(sd, 0x2f, 0x80);
  3097. if (sd->bridge == BRIDGE_OV518PLUS) {
  3098. reg_w(sd, 0x24, 0x94);
  3099. reg_w(sd, 0x25, 0x90);
  3100. ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
  3101. ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */
  3102. ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */
  3103. ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */
  3104. ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */
  3105. ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */
  3106. ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */
  3107. ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */
  3108. ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */
  3109. } else {
  3110. reg_w(sd, 0x24, 0x9f);
  3111. reg_w(sd, 0x25, 0x90);
  3112. ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
  3113. ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */
  3114. ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */
  3115. ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */
  3116. ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */
  3117. ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */
  3118. ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */
  3119. ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */
  3120. ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */
  3121. }
  3122. reg_w(sd, 0x2f, 0x80);
  3123. return 0;
  3124. }
  3125. /* Sets up the OV519 with the given image parameters
  3126. *
  3127. * OV519 needs a completely different approach, until we can figure out what
  3128. * the individual registers do.
  3129. *
  3130. * Do not put any sensor-specific code in here (including I2C I/O functions)
  3131. */
  3132. static int ov519_mode_init_regs(struct sd *sd)
  3133. {
  3134. static const struct ov_regvals mode_init_519_ov7670[] = {
  3135. { 0x5d, 0x03 }, /* Turn off suspend mode */
  3136. { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
  3137. { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
  3138. { 0xa2, 0x20 }, /* a2-a5 are undocumented */
  3139. { 0xa3, 0x18 },
  3140. { 0xa4, 0x04 },
  3141. { 0xa5, 0x28 },
  3142. { 0x37, 0x00 }, /* SetUsbInit */
  3143. { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
  3144. /* Enable both fields, YUV Input, disable defect comp (why?) */
  3145. { 0x20, 0x0c },
  3146. { 0x21, 0x38 },
  3147. { 0x22, 0x1d },
  3148. { 0x17, 0x50 }, /* undocumented */
  3149. { 0x37, 0x00 }, /* undocumented */
  3150. { 0x40, 0xff }, /* I2C timeout counter */
  3151. { 0x46, 0x00 }, /* I2C clock prescaler */
  3152. { 0x59, 0x04 }, /* new from windrv 090403 */
  3153. { 0xff, 0x00 }, /* undocumented */
  3154. /* windows reads 0x55 at this point, why? */
  3155. };
  3156. static const struct ov_regvals mode_init_519[] = {
  3157. { 0x5d, 0x03 }, /* Turn off suspend mode */
  3158. { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
  3159. { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
  3160. { 0xa2, 0x20 }, /* a2-a5 are undocumented */
  3161. { 0xa3, 0x18 },
  3162. { 0xa4, 0x04 },
  3163. { 0xa5, 0x28 },
  3164. { 0x37, 0x00 }, /* SetUsbInit */
  3165. { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
  3166. /* Enable both fields, YUV Input, disable defect comp (why?) */
  3167. { 0x22, 0x1d },
  3168. { 0x17, 0x50 }, /* undocumented */
  3169. { 0x37, 0x00 }, /* undocumented */
  3170. { 0x40, 0xff }, /* I2C timeout counter */
  3171. { 0x46, 0x00 }, /* I2C clock prescaler */
  3172. { 0x59, 0x04 }, /* new from windrv 090403 */
  3173. { 0xff, 0x00 }, /* undocumented */
  3174. /* windows reads 0x55 at this point, why? */
  3175. };
  3176. /******** Set the mode ********/
  3177. if (sd->sensor != SEN_OV7670) {
  3178. if (write_regvals(sd, mode_init_519,
  3179. ARRAY_SIZE(mode_init_519)))
  3180. return -EIO;
  3181. if (sd->sensor == SEN_OV7640 ||
  3182. sd->sensor == SEN_OV7648) {
  3183. /* Select 8-bit input mode */
  3184. reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
  3185. }
  3186. } else {
  3187. if (write_regvals(sd, mode_init_519_ov7670,
  3188. ARRAY_SIZE(mode_init_519_ov7670)))
  3189. return -EIO;
  3190. }
  3191. reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
  3192. reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
  3193. if (sd->sensor == SEN_OV7670 &&
  3194. sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
  3195. reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
  3196. else if (sd->sensor == SEN_OV7648 &&
  3197. sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
  3198. reg_w(sd, OV519_R12_X_OFFSETL, 0x01);
  3199. else
  3200. reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
  3201. reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
  3202. reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
  3203. reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
  3204. reg_w(sd, OV519_R16_DIVIDER, 0x00);
  3205. reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
  3206. reg_w(sd, 0x26, 0x00); /* Undocumented */
  3207. /******** Set the framerate ********/
  3208. if (frame_rate > 0)
  3209. sd->frame_rate = frame_rate;
  3210. /* FIXME: These are only valid at the max resolution. */
  3211. sd->clockdiv = 0;
  3212. switch (sd->sensor) {
  3213. case SEN_OV7640:
  3214. case SEN_OV7648:
  3215. switch (sd->frame_rate) {
  3216. default:
  3217. /* case 30: */
  3218. reg_w(sd, 0xa4, 0x0c);
  3219. reg_w(sd, 0x23, 0xff);
  3220. break;
  3221. case 25:
  3222. reg_w(sd, 0xa4, 0x0c);
  3223. reg_w(sd, 0x23, 0x1f);
  3224. break;
  3225. case 20:
  3226. reg_w(sd, 0xa4, 0x0c);
  3227. reg_w(sd, 0x23, 0x1b);
  3228. break;
  3229. case 15:
  3230. reg_w(sd, 0xa4, 0x04);
  3231. reg_w(sd, 0x23, 0xff);
  3232. sd->clockdiv = 1;
  3233. break;
  3234. case 10:
  3235. reg_w(sd, 0xa4, 0x04);
  3236. reg_w(sd, 0x23, 0x1f);
  3237. sd->clockdiv = 1;
  3238. break;
  3239. case 5:
  3240. reg_w(sd, 0xa4, 0x04);
  3241. reg_w(sd, 0x23, 0x1b);
  3242. sd->clockdiv = 1;
  3243. break;
  3244. }
  3245. break;
  3246. case SEN_OV8610:
  3247. switch (sd->frame_rate) {
  3248. default: /* 15 fps */
  3249. /* case 15: */
  3250. reg_w(sd, 0xa4, 0x06);
  3251. reg_w(sd, 0x23, 0xff);
  3252. break;
  3253. case 10:
  3254. reg_w(sd, 0xa4, 0x06);
  3255. reg_w(sd, 0x23, 0x1f);
  3256. break;
  3257. case 5:
  3258. reg_w(sd, 0xa4, 0x06);
  3259. reg_w(sd, 0x23, 0x1b);
  3260. break;
  3261. }
  3262. break;
  3263. case SEN_OV7670: /* guesses, based on 7640 */
  3264. PDEBUG(D_STREAM, "Setting framerate to %d fps",
  3265. (sd->frame_rate == 0) ? 15 : sd->frame_rate);
  3266. reg_w(sd, 0xa4, 0x10);
  3267. switch (sd->frame_rate) {
  3268. case 30:
  3269. reg_w(sd, 0x23, 0xff);
  3270. break;
  3271. case 20:
  3272. reg_w(sd, 0x23, 0x1b);
  3273. break;
  3274. default:
  3275. /* case 15: */
  3276. reg_w(sd, 0x23, 0xff);
  3277. sd->clockdiv = 1;
  3278. break;
  3279. }
  3280. break;
  3281. }
  3282. return 0;
  3283. }
  3284. static int mode_init_ov_sensor_regs(struct sd *sd)
  3285. {
  3286. struct gspca_dev *gspca_dev;
  3287. int qvga, xstart, xend, ystart, yend;
  3288. u8 v;
  3289. gspca_dev = &sd->gspca_dev;
  3290. qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
  3291. /******** Mode (VGA/QVGA) and sensor specific regs ********/
  3292. switch (sd->sensor) {
  3293. case SEN_OV2610:
  3294. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  3295. i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
  3296. i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
  3297. i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
  3298. i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
  3299. i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
  3300. i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
  3301. return 0;
  3302. case SEN_OV3610:
  3303. if (qvga) {
  3304. xstart = (1040 - gspca_dev->width) / 2 + (0x1f << 4);
  3305. ystart = (776 - gspca_dev->height) / 2;
  3306. } else {
  3307. xstart = (2076 - gspca_dev->width) / 2 + (0x10 << 4);
  3308. ystart = (1544 - gspca_dev->height) / 2;
  3309. }
  3310. xend = xstart + gspca_dev->width;
  3311. yend = ystart + gspca_dev->height;
  3312. /* Writing to the COMH register resets the other windowing regs
  3313. to their default values, so we must do this first. */
  3314. i2c_w_mask(sd, 0x12, qvga ? 0x40 : 0x00, 0xf0);
  3315. i2c_w_mask(sd, 0x32,
  3316. (((xend >> 1) & 7) << 3) | ((xstart >> 1) & 7),
  3317. 0x3f);
  3318. i2c_w_mask(sd, 0x03,
  3319. (((yend >> 1) & 3) << 2) | ((ystart >> 1) & 3),
  3320. 0x0f);
  3321. i2c_w(sd, 0x17, xstart >> 4);
  3322. i2c_w(sd, 0x18, xend >> 4);
  3323. i2c_w(sd, 0x19, ystart >> 3);
  3324. i2c_w(sd, 0x1a, yend >> 3);
  3325. return 0;
  3326. case SEN_OV8610:
  3327. /* For OV8610 qvga means qsvga */
  3328. i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
  3329. i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
  3330. i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
  3331. i2c_w_mask(sd, 0x2d, 0x00, 0x40); /* from windrv 090403 */
  3332. i2c_w_mask(sd, 0x28, 0x20, 0x20); /* progressive mode on */
  3333. break;
  3334. case SEN_OV7610:
  3335. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  3336. i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
  3337. i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
  3338. i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
  3339. break;
  3340. case SEN_OV7620:
  3341. case SEN_OV7620AE:
  3342. case SEN_OV76BE:
  3343. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  3344. i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
  3345. i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
  3346. i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
  3347. i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
  3348. i2c_w_mask(sd, 0x67, qvga ? 0xb0 : 0x90, 0xf0);
  3349. i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
  3350. i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
  3351. i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
  3352. if (sd->sensor == SEN_OV76BE)
  3353. i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
  3354. break;
  3355. case SEN_OV7640:
  3356. case SEN_OV7648:
  3357. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  3358. i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
  3359. /* Setting this undocumented bit in qvga mode removes a very
  3360. annoying vertical shaking of the image */
  3361. i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
  3362. /* Unknown */
  3363. i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
  3364. /* Allow higher automatic gain (to allow higher framerates) */
  3365. i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
  3366. i2c_w_mask(sd, 0x12, 0x04, 0x04); /* AWB: 1 */
  3367. break;
  3368. case SEN_OV7670:
  3369. /* set COM7_FMT_VGA or COM7_FMT_QVGA
  3370. * do we need to set anything else?
  3371. * HSTART etc are set in set_ov_sensor_window itself */
  3372. i2c_w_mask(sd, OV7670_R12_COM7,
  3373. qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
  3374. OV7670_COM7_FMT_MASK);
  3375. i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
  3376. i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_AWB,
  3377. OV7670_COM8_AWB);
  3378. if (qvga) { /* QVGA from ov7670.c by
  3379. * Jonathan Corbet */
  3380. xstart = 164;
  3381. xend = 28;
  3382. ystart = 14;
  3383. yend = 494;
  3384. } else { /* VGA */
  3385. xstart = 158;
  3386. xend = 14;
  3387. ystart = 10;
  3388. yend = 490;
  3389. }
  3390. /* OV7670 hardware window registers are split across
  3391. * multiple locations */
  3392. i2c_w(sd, OV7670_R17_HSTART, xstart >> 3);
  3393. i2c_w(sd, OV7670_R18_HSTOP, xend >> 3);
  3394. v = i2c_r(sd, OV7670_R32_HREF);
  3395. v = (v & 0xc0) | ((xend & 0x7) << 3) | (xstart & 0x07);
  3396. msleep(10); /* need to sleep between read and write to
  3397. * same reg! */
  3398. i2c_w(sd, OV7670_R32_HREF, v);
  3399. i2c_w(sd, OV7670_R19_VSTART, ystart >> 2);
  3400. i2c_w(sd, OV7670_R1A_VSTOP, yend >> 2);
  3401. v = i2c_r(sd, OV7670_R03_VREF);
  3402. v = (v & 0xc0) | ((yend & 0x3) << 2) | (ystart & 0x03);
  3403. msleep(10); /* need to sleep between read and write to
  3404. * same reg! */
  3405. i2c_w(sd, OV7670_R03_VREF, v);
  3406. break;
  3407. case SEN_OV6620:
  3408. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  3409. i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
  3410. i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
  3411. break;
  3412. case SEN_OV6630:
  3413. case SEN_OV66308AF:
  3414. i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
  3415. i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
  3416. break;
  3417. default:
  3418. return -EINVAL;
  3419. }
  3420. /******** Clock programming ********/
  3421. i2c_w(sd, 0x11, sd->clockdiv);
  3422. return 0;
  3423. }
  3424. static void sethvflip(struct gspca_dev *gspca_dev)
  3425. {
  3426. struct sd *sd = (struct sd *) gspca_dev;
  3427. if (sd->sensor != SEN_OV7670)
  3428. return;
  3429. if (sd->gspca_dev.streaming)
  3430. ov51x_stop(sd);
  3431. i2c_w_mask(sd, OV7670_R1E_MVFP,
  3432. OV7670_MVFP_MIRROR * sd->ctrls[HFLIP].val
  3433. | OV7670_MVFP_VFLIP * sd->ctrls[VFLIP].val,
  3434. OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
  3435. if (sd->gspca_dev.streaming)
  3436. ov51x_restart(sd);
  3437. }
  3438. static int set_ov_sensor_window(struct sd *sd)
  3439. {
  3440. struct gspca_dev *gspca_dev;
  3441. int qvga, crop;
  3442. int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
  3443. int ret;
  3444. /* mode setup is fully handled in mode_init_ov_sensor_regs for these */
  3445. if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610 ||
  3446. sd->sensor == SEN_OV7670)
  3447. return mode_init_ov_sensor_regs(sd);
  3448. gspca_dev = &sd->gspca_dev;
  3449. qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
  3450. crop = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 2;
  3451. /* The different sensor ICs handle setting up of window differently.
  3452. * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
  3453. switch (sd->sensor) {
  3454. case SEN_OV8610:
  3455. hwsbase = 0x1e;
  3456. hwebase = 0x1e;
  3457. vwsbase = 0x02;
  3458. vwebase = 0x02;
  3459. break;
  3460. case SEN_OV7610:
  3461. case SEN_OV76BE:
  3462. hwsbase = 0x38;
  3463. hwebase = 0x3a;
  3464. vwsbase = vwebase = 0x05;
  3465. break;
  3466. case SEN_OV6620:
  3467. case SEN_OV6630:
  3468. case SEN_OV66308AF:
  3469. hwsbase = 0x38;
  3470. hwebase = 0x3a;
  3471. vwsbase = 0x05;
  3472. vwebase = 0x06;
  3473. if (sd->sensor == SEN_OV66308AF && qvga)
  3474. /* HDG: this fixes U and V getting swapped */
  3475. hwsbase++;
  3476. if (crop) {
  3477. hwsbase += 8;
  3478. hwebase += 8;
  3479. vwsbase += 11;
  3480. vwebase += 11;
  3481. }
  3482. break;
  3483. case SEN_OV7620:
  3484. case SEN_OV7620AE:
  3485. hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
  3486. hwebase = 0x2f;
  3487. vwsbase = vwebase = 0x05;
  3488. break;
  3489. case SEN_OV7640:
  3490. case SEN_OV7648:
  3491. hwsbase = 0x1a;
  3492. hwebase = 0x1a;
  3493. vwsbase = vwebase = 0x03;
  3494. break;
  3495. default:
  3496. return -EINVAL;
  3497. }
  3498. switch (sd->sensor) {
  3499. case SEN_OV6620:
  3500. case SEN_OV6630:
  3501. case SEN_OV66308AF:
  3502. if (qvga) { /* QCIF */
  3503. hwscale = 0;
  3504. vwscale = 0;
  3505. } else { /* CIF */
  3506. hwscale = 1;
  3507. vwscale = 1; /* The datasheet says 0;
  3508. * it's wrong */
  3509. }
  3510. break;
  3511. case SEN_OV8610:
  3512. if (qvga) { /* QSVGA */
  3513. hwscale = 1;
  3514. vwscale = 1;
  3515. } else { /* SVGA */
  3516. hwscale = 2;
  3517. vwscale = 2;
  3518. }
  3519. break;
  3520. default: /* SEN_OV7xx0 */
  3521. if (qvga) { /* QVGA */
  3522. hwscale = 1;
  3523. vwscale = 0;
  3524. } else { /* VGA */
  3525. hwscale = 2;
  3526. vwscale = 1;
  3527. }
  3528. }
  3529. ret = mode_init_ov_sensor_regs(sd);
  3530. if (ret < 0)
  3531. return ret;
  3532. i2c_w(sd, 0x17, hwsbase);
  3533. i2c_w(sd, 0x18, hwebase + (sd->sensor_width >> hwscale));
  3534. i2c_w(sd, 0x19, vwsbase);
  3535. i2c_w(sd, 0x1a, vwebase + (sd->sensor_height >> vwscale));
  3536. return 0;
  3537. }
  3538. /* -- start the camera -- */
  3539. static int sd_start(struct gspca_dev *gspca_dev)
  3540. {
  3541. struct sd *sd = (struct sd *) gspca_dev;
  3542. int ret = 0;
  3543. /* Default for most bridges, allow bridge_mode_init_regs to override */
  3544. sd->sensor_width = sd->gspca_dev.width;
  3545. sd->sensor_height = sd->gspca_dev.height;
  3546. switch (sd->bridge) {
  3547. case BRIDGE_OV511:
  3548. case BRIDGE_OV511PLUS:
  3549. ret = ov511_mode_init_regs(sd);
  3550. break;
  3551. case BRIDGE_OV518:
  3552. case BRIDGE_OV518PLUS:
  3553. ret = ov518_mode_init_regs(sd);
  3554. break;
  3555. case BRIDGE_OV519:
  3556. ret = ov519_mode_init_regs(sd);
  3557. break;
  3558. /* case BRIDGE_OVFX2: nothing to do */
  3559. case BRIDGE_W9968CF:
  3560. ret = w9968cf_mode_init_regs(sd);
  3561. break;
  3562. }
  3563. if (ret < 0)
  3564. goto out;
  3565. ret = set_ov_sensor_window(sd);
  3566. if (ret < 0)
  3567. goto out;
  3568. setcontrast(gspca_dev);
  3569. setbrightness(gspca_dev);
  3570. setcolors(gspca_dev);
  3571. sethvflip(gspca_dev);
  3572. setautobright(gspca_dev);
  3573. setfreq_i(sd);
  3574. /* Force clear snapshot state in case the snapshot button was
  3575. pressed while we weren't streaming */
  3576. sd->snapshot_needs_reset = 1;
  3577. sd_reset_snapshot(gspca_dev);
  3578. sd->first_frame = 3;
  3579. ret = ov51x_restart(sd);
  3580. if (ret < 0)
  3581. goto out;
  3582. ov51x_led_control(sd, 1);
  3583. return 0;
  3584. out:
  3585. PDEBUG(D_ERR, "camera start error:%d", ret);
  3586. return ret;
  3587. }
  3588. static void sd_stopN(struct gspca_dev *gspca_dev)
  3589. {
  3590. struct sd *sd = (struct sd *) gspca_dev;
  3591. ov51x_stop(sd);
  3592. ov51x_led_control(sd, 0);
  3593. }
  3594. static void sd_stop0(struct gspca_dev *gspca_dev)
  3595. {
  3596. struct sd *sd = (struct sd *) gspca_dev;
  3597. if (!sd->gspca_dev.present)
  3598. return;
  3599. if (sd->bridge == BRIDGE_W9968CF)
  3600. w9968cf_stop0(sd);
  3601. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  3602. /* If the last button state is pressed, release it now! */
  3603. if (sd->snapshot_pressed) {
  3604. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
  3605. input_sync(gspca_dev->input_dev);
  3606. sd->snapshot_pressed = 0;
  3607. }
  3608. #endif
  3609. }
  3610. static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state)
  3611. {
  3612. struct sd *sd = (struct sd *) gspca_dev;
  3613. if (sd->snapshot_pressed != state) {
  3614. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  3615. input_report_key(gspca_dev->input_dev, KEY_CAMERA, state);
  3616. input_sync(gspca_dev->input_dev);
  3617. #endif
  3618. if (state)
  3619. sd->snapshot_needs_reset = 1;
  3620. sd->snapshot_pressed = state;
  3621. } else {
  3622. /* On the ov511 / ov519 we need to reset the button state
  3623. multiple times, as resetting does not work as long as the
  3624. button stays pressed */
  3625. switch (sd->bridge) {
  3626. case BRIDGE_OV511:
  3627. case BRIDGE_OV511PLUS:
  3628. case BRIDGE_OV519:
  3629. if (state)
  3630. sd->snapshot_needs_reset = 1;
  3631. break;
  3632. }
  3633. }
  3634. }
  3635. static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
  3636. u8 *in, /* isoc packet */
  3637. int len) /* iso packet length */
  3638. {
  3639. struct sd *sd = (struct sd *) gspca_dev;
  3640. /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
  3641. * byte non-zero. The EOF packet has image width/height in the
  3642. * 10th and 11th bytes. The 9th byte is given as follows:
  3643. *
  3644. * bit 7: EOF
  3645. * 6: compression enabled
  3646. * 5: 422/420/400 modes
  3647. * 4: 422/420/400 modes
  3648. * 3: 1
  3649. * 2: snapshot button on
  3650. * 1: snapshot frame
  3651. * 0: even/odd field
  3652. */
  3653. if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) &&
  3654. (in[8] & 0x08)) {
  3655. ov51x_handle_button(gspca_dev, (in[8] >> 2) & 1);
  3656. if (in[8] & 0x80) {
  3657. /* Frame end */
  3658. if ((in[9] + 1) * 8 != gspca_dev->width ||
  3659. (in[10] + 1) * 8 != gspca_dev->height) {
  3660. PDEBUG(D_ERR, "Invalid frame size, got: %dx%d,"
  3661. " requested: %dx%d\n",
  3662. (in[9] + 1) * 8, (in[10] + 1) * 8,
  3663. gspca_dev->width, gspca_dev->height);
  3664. gspca_dev->last_packet_type = DISCARD_PACKET;
  3665. return;
  3666. }
  3667. /* Add 11 byte footer to frame, might be usefull */
  3668. gspca_frame_add(gspca_dev, LAST_PACKET, in, 11);
  3669. return;
  3670. } else {
  3671. /* Frame start */
  3672. gspca_frame_add(gspca_dev, FIRST_PACKET, in, 0);
  3673. sd->packet_nr = 0;
  3674. }
  3675. }
  3676. /* Ignore the packet number */
  3677. len--;
  3678. /* intermediate packet */
  3679. gspca_frame_add(gspca_dev, INTER_PACKET, in, len);
  3680. }
  3681. static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
  3682. u8 *data, /* isoc packet */
  3683. int len) /* iso packet length */
  3684. {
  3685. struct sd *sd = (struct sd *) gspca_dev;
  3686. /* A false positive here is likely, until OVT gives me
  3687. * the definitive SOF/EOF format */
  3688. if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) {
  3689. ov51x_handle_button(gspca_dev, (data[6] >> 1) & 1);
  3690. gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
  3691. gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
  3692. sd->packet_nr = 0;
  3693. }
  3694. if (gspca_dev->last_packet_type == DISCARD_PACKET)
  3695. return;
  3696. /* Does this device use packet numbers ? */
  3697. if (len & 7) {
  3698. len--;
  3699. if (sd->packet_nr == data[len])
  3700. sd->packet_nr++;
  3701. /* The last few packets of the frame (which are all 0's
  3702. except that they may contain part of the footer), are
  3703. numbered 0 */
  3704. else if (sd->packet_nr == 0 || data[len]) {
  3705. PDEBUG(D_ERR, "Invalid packet nr: %d (expect: %d)",
  3706. (int)data[len], (int)sd->packet_nr);
  3707. gspca_dev->last_packet_type = DISCARD_PACKET;
  3708. return;
  3709. }
  3710. }
  3711. /* intermediate packet */
  3712. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  3713. }
  3714. static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
  3715. u8 *data, /* isoc packet */
  3716. int len) /* iso packet length */
  3717. {
  3718. /* Header of ov519 is 16 bytes:
  3719. * Byte Value Description
  3720. * 0 0xff magic
  3721. * 1 0xff magic
  3722. * 2 0xff magic
  3723. * 3 0xXX 0x50 = SOF, 0x51 = EOF
  3724. * 9 0xXX 0x01 initial frame without data,
  3725. * 0x00 standard frame with image
  3726. * 14 Lo in EOF: length of image data / 8
  3727. * 15 Hi
  3728. */
  3729. if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
  3730. switch (data[3]) {
  3731. case 0x50: /* start of frame */
  3732. /* Don't check the button state here, as the state
  3733. usually (always ?) changes at EOF and checking it
  3734. here leads to unnecessary snapshot state resets. */
  3735. #define HDRSZ 16
  3736. data += HDRSZ;
  3737. len -= HDRSZ;
  3738. #undef HDRSZ
  3739. if (data[0] == 0xff || data[1] == 0xd8)
  3740. gspca_frame_add(gspca_dev, FIRST_PACKET,
  3741. data, len);
  3742. else
  3743. gspca_dev->last_packet_type = DISCARD_PACKET;
  3744. return;
  3745. case 0x51: /* end of frame */
  3746. ov51x_handle_button(gspca_dev, data[11] & 1);
  3747. if (data[9] != 0)
  3748. gspca_dev->last_packet_type = DISCARD_PACKET;
  3749. gspca_frame_add(gspca_dev, LAST_PACKET,
  3750. NULL, 0);
  3751. return;
  3752. }
  3753. }
  3754. /* intermediate packet */
  3755. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  3756. }
  3757. static void ovfx2_pkt_scan(struct gspca_dev *gspca_dev,
  3758. u8 *data, /* isoc packet */
  3759. int len) /* iso packet length */
  3760. {
  3761. struct sd *sd = (struct sd *) gspca_dev;
  3762. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  3763. /* A short read signals EOF */
  3764. if (len < OVFX2_BULK_SIZE) {
  3765. /* If the frame is short, and it is one of the first ones
  3766. the sensor and bridge are still syncing, so drop it. */
  3767. if (sd->first_frame) {
  3768. sd->first_frame--;
  3769. if (gspca_dev->image_len <
  3770. sd->gspca_dev.width * sd->gspca_dev.height)
  3771. gspca_dev->last_packet_type = DISCARD_PACKET;
  3772. }
  3773. gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
  3774. gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
  3775. }
  3776. }
  3777. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  3778. u8 *data, /* isoc packet */
  3779. int len) /* iso packet length */
  3780. {
  3781. struct sd *sd = (struct sd *) gspca_dev;
  3782. switch (sd->bridge) {
  3783. case BRIDGE_OV511:
  3784. case BRIDGE_OV511PLUS:
  3785. ov511_pkt_scan(gspca_dev, data, len);
  3786. break;
  3787. case BRIDGE_OV518:
  3788. case BRIDGE_OV518PLUS:
  3789. ov518_pkt_scan(gspca_dev, data, len);
  3790. break;
  3791. case BRIDGE_OV519:
  3792. ov519_pkt_scan(gspca_dev, data, len);
  3793. break;
  3794. case BRIDGE_OVFX2:
  3795. ovfx2_pkt_scan(gspca_dev, data, len);
  3796. break;
  3797. case BRIDGE_W9968CF:
  3798. w9968cf_pkt_scan(gspca_dev, data, len);
  3799. break;
  3800. }
  3801. }
  3802. /* -- management routines -- */
  3803. static void setbrightness(struct gspca_dev *gspca_dev)
  3804. {
  3805. struct sd *sd = (struct sd *) gspca_dev;
  3806. int val;
  3807. val = sd->ctrls[BRIGHTNESS].val;
  3808. switch (sd->sensor) {
  3809. case SEN_OV8610:
  3810. case SEN_OV7610:
  3811. case SEN_OV76BE:
  3812. case SEN_OV6620:
  3813. case SEN_OV6630:
  3814. case SEN_OV66308AF:
  3815. case SEN_OV7640:
  3816. case SEN_OV7648:
  3817. i2c_w(sd, OV7610_REG_BRT, val);
  3818. break;
  3819. case SEN_OV7620:
  3820. case SEN_OV7620AE:
  3821. /* 7620 doesn't like manual changes when in auto mode */
  3822. if (!sd->ctrls[AUTOBRIGHT].val)
  3823. i2c_w(sd, OV7610_REG_BRT, val);
  3824. break;
  3825. case SEN_OV7670:
  3826. /*win trace
  3827. * i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_AEC); */
  3828. i2c_w(sd, OV7670_R55_BRIGHT, ov7670_abs_to_sm(val));
  3829. break;
  3830. }
  3831. }
  3832. static void setcontrast(struct gspca_dev *gspca_dev)
  3833. {
  3834. struct sd *sd = (struct sd *) gspca_dev;
  3835. int val;
  3836. val = sd->ctrls[CONTRAST].val;
  3837. switch (sd->sensor) {
  3838. case SEN_OV7610:
  3839. case SEN_OV6620:
  3840. i2c_w(sd, OV7610_REG_CNT, val);
  3841. break;
  3842. case SEN_OV6630:
  3843. case SEN_OV66308AF:
  3844. i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
  3845. break;
  3846. case SEN_OV8610: {
  3847. static const u8 ctab[] = {
  3848. 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
  3849. };
  3850. /* Use Y gamma control instead. Bit 0 enables it. */
  3851. i2c_w(sd, 0x64, ctab[val >> 5]);
  3852. break;
  3853. }
  3854. case SEN_OV7620:
  3855. case SEN_OV7620AE: {
  3856. static const u8 ctab[] = {
  3857. 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
  3858. 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
  3859. };
  3860. /* Use Y gamma control instead. Bit 0 enables it. */
  3861. i2c_w(sd, 0x64, ctab[val >> 4]);
  3862. break;
  3863. }
  3864. case SEN_OV7670:
  3865. /* check that this isn't just the same as ov7610 */
  3866. i2c_w(sd, OV7670_R56_CONTRAS, val >> 1);
  3867. break;
  3868. }
  3869. }
  3870. static void setcolors(struct gspca_dev *gspca_dev)
  3871. {
  3872. struct sd *sd = (struct sd *) gspca_dev;
  3873. int val;
  3874. val = sd->ctrls[COLORS].val;
  3875. switch (sd->sensor) {
  3876. case SEN_OV8610:
  3877. case SEN_OV7610:
  3878. case SEN_OV76BE:
  3879. case SEN_OV6620:
  3880. case SEN_OV6630:
  3881. case SEN_OV66308AF:
  3882. i2c_w(sd, OV7610_REG_SAT, val);
  3883. break;
  3884. case SEN_OV7620:
  3885. case SEN_OV7620AE:
  3886. /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
  3887. /* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
  3888. if (rc < 0)
  3889. goto out; */
  3890. i2c_w(sd, OV7610_REG_SAT, val);
  3891. break;
  3892. case SEN_OV7640:
  3893. case SEN_OV7648:
  3894. i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
  3895. break;
  3896. case SEN_OV7670:
  3897. /* supported later once I work out how to do it
  3898. * transparently fail now! */
  3899. /* set REG_COM13 values for UV sat auto mode */
  3900. break;
  3901. }
  3902. }
  3903. static void setautobright(struct gspca_dev *gspca_dev)
  3904. {
  3905. struct sd *sd = (struct sd *) gspca_dev;
  3906. if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7648 ||
  3907. sd->sensor == SEN_OV7670 ||
  3908. sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610)
  3909. return;
  3910. i2c_w_mask(sd, 0x2d, sd->ctrls[AUTOBRIGHT].val ? 0x10 : 0x00, 0x10);
  3911. }
  3912. static void setfreq_i(struct sd *sd)
  3913. {
  3914. if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610)
  3915. return;
  3916. if (sd->sensor == SEN_OV7670) {
  3917. switch (sd->ctrls[FREQ].val) {
  3918. case 0: /* Banding filter disabled */
  3919. i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_BFILT);
  3920. break;
  3921. case 1: /* 50 hz */
  3922. i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
  3923. OV7670_COM8_BFILT);
  3924. i2c_w_mask(sd, OV7670_R3B_COM11, 0x08, 0x18);
  3925. break;
  3926. case 2: /* 60 hz */
  3927. i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
  3928. OV7670_COM8_BFILT);
  3929. i2c_w_mask(sd, OV7670_R3B_COM11, 0x00, 0x18);
  3930. break;
  3931. case 3: /* Auto hz - ov7670 only */
  3932. i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
  3933. OV7670_COM8_BFILT);
  3934. i2c_w_mask(sd, OV7670_R3B_COM11, OV7670_COM11_HZAUTO,
  3935. 0x18);
  3936. break;
  3937. }
  3938. } else {
  3939. switch (sd->ctrls[FREQ].val) {
  3940. case 0: /* Banding filter disabled */
  3941. i2c_w_mask(sd, 0x2d, 0x00, 0x04);
  3942. i2c_w_mask(sd, 0x2a, 0x00, 0x80);
  3943. break;
  3944. case 1: /* 50 hz (filter on and framerate adj) */
  3945. i2c_w_mask(sd, 0x2d, 0x04, 0x04);
  3946. i2c_w_mask(sd, 0x2a, 0x80, 0x80);
  3947. /* 20 fps -> 16.667 fps */
  3948. if (sd->sensor == SEN_OV6620 ||
  3949. sd->sensor == SEN_OV6630 ||
  3950. sd->sensor == SEN_OV66308AF)
  3951. i2c_w(sd, 0x2b, 0x5e);
  3952. else
  3953. i2c_w(sd, 0x2b, 0xac);
  3954. break;
  3955. case 2: /* 60 hz (filter on, ...) */
  3956. i2c_w_mask(sd, 0x2d, 0x04, 0x04);
  3957. if (sd->sensor == SEN_OV6620 ||
  3958. sd->sensor == SEN_OV6630 ||
  3959. sd->sensor == SEN_OV66308AF) {
  3960. /* 20 fps -> 15 fps */
  3961. i2c_w_mask(sd, 0x2a, 0x80, 0x80);
  3962. i2c_w(sd, 0x2b, 0xa8);
  3963. } else {
  3964. /* no framerate adj. */
  3965. i2c_w_mask(sd, 0x2a, 0x00, 0x80);
  3966. }
  3967. break;
  3968. }
  3969. }
  3970. }
  3971. static void setfreq(struct gspca_dev *gspca_dev)
  3972. {
  3973. struct sd *sd = (struct sd *) gspca_dev;
  3974. setfreq_i(sd);
  3975. /* Ugly but necessary */
  3976. if (sd->bridge == BRIDGE_W9968CF)
  3977. w9968cf_set_crop_window(sd);
  3978. }
  3979. static int sd_querymenu(struct gspca_dev *gspca_dev,
  3980. struct v4l2_querymenu *menu)
  3981. {
  3982. struct sd *sd = (struct sd *) gspca_dev;
  3983. switch (menu->id) {
  3984. case V4L2_CID_POWER_LINE_FREQUENCY:
  3985. switch (menu->index) {
  3986. case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
  3987. strcpy((char *) menu->name, "NoFliker");
  3988. return 0;
  3989. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  3990. strcpy((char *) menu->name, "50 Hz");
  3991. return 0;
  3992. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  3993. strcpy((char *) menu->name, "60 Hz");
  3994. return 0;
  3995. case 3:
  3996. if (sd->sensor != SEN_OV7670)
  3997. return -EINVAL;
  3998. strcpy((char *) menu->name, "Automatic");
  3999. return 0;
  4000. }
  4001. break;
  4002. }
  4003. return -EINVAL;
  4004. }
  4005. static int sd_get_jcomp(struct gspca_dev *gspca_dev,
  4006. struct v4l2_jpegcompression *jcomp)
  4007. {
  4008. struct sd *sd = (struct sd *) gspca_dev;
  4009. if (sd->bridge != BRIDGE_W9968CF)
  4010. return -EINVAL;
  4011. memset(jcomp, 0, sizeof *jcomp);
  4012. jcomp->quality = sd->quality;
  4013. jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT | V4L2_JPEG_MARKER_DQT |
  4014. V4L2_JPEG_MARKER_DRI;
  4015. return 0;
  4016. }
  4017. static int sd_set_jcomp(struct gspca_dev *gspca_dev,
  4018. struct v4l2_jpegcompression *jcomp)
  4019. {
  4020. struct sd *sd = (struct sd *) gspca_dev;
  4021. if (sd->bridge != BRIDGE_W9968CF)
  4022. return -EINVAL;
  4023. if (gspca_dev->streaming)
  4024. return -EBUSY;
  4025. if (jcomp->quality < QUALITY_MIN)
  4026. sd->quality = QUALITY_MIN;
  4027. else if (jcomp->quality > QUALITY_MAX)
  4028. sd->quality = QUALITY_MAX;
  4029. else
  4030. sd->quality = jcomp->quality;
  4031. /* Return resulting jcomp params to app */
  4032. sd_get_jcomp(gspca_dev, jcomp);
  4033. return 0;
  4034. }
  4035. /* sub-driver description */
  4036. static const struct sd_desc sd_desc = {
  4037. .name = MODULE_NAME,
  4038. .ctrls = sd_ctrls,
  4039. .nctrls = ARRAY_SIZE(sd_ctrls),
  4040. .config = sd_config,
  4041. .init = sd_init,
  4042. .start = sd_start,
  4043. .stopN = sd_stopN,
  4044. .stop0 = sd_stop0,
  4045. .pkt_scan = sd_pkt_scan,
  4046. .dq_callback = sd_reset_snapshot,
  4047. .querymenu = sd_querymenu,
  4048. .get_jcomp = sd_get_jcomp,
  4049. .set_jcomp = sd_set_jcomp,
  4050. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  4051. .other_input = 1,
  4052. #endif
  4053. };
  4054. /* -- module initialisation -- */
  4055. static const __devinitdata struct usb_device_id device_table[] = {
  4056. {USB_DEVICE(0x041e, 0x4003), .driver_info = BRIDGE_W9968CF },
  4057. {USB_DEVICE(0x041e, 0x4052), .driver_info = BRIDGE_OV519 },
  4058. {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 },
  4059. {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 },
  4060. {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 },
  4061. {USB_DEVICE(0x041e, 0x4064),
  4062. .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
  4063. {USB_DEVICE(0x041e, 0x4067), .driver_info = BRIDGE_OV519 },
  4064. {USB_DEVICE(0x041e, 0x4068),
  4065. .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
  4066. {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
  4067. {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
  4068. {USB_DEVICE(0x054c, 0x0155),
  4069. .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
  4070. {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 },
  4071. {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
  4072. {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
  4073. {USB_DEVICE(0x05a9, 0x0530), .driver_info = BRIDGE_OV519 },
  4074. {USB_DEVICE(0x05a9, 0x2800), .driver_info = BRIDGE_OVFX2 },
  4075. {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 },
  4076. {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 },
  4077. {USB_DEVICE(0x05a9, 0xa511), .driver_info = BRIDGE_OV511PLUS },
  4078. {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS },
  4079. {USB_DEVICE(0x0813, 0x0002), .driver_info = BRIDGE_OV511PLUS },
  4080. {USB_DEVICE(0x0b62, 0x0059), .driver_info = BRIDGE_OVFX2 },
  4081. {USB_DEVICE(0x0e96, 0xc001), .driver_info = BRIDGE_OVFX2 },
  4082. {USB_DEVICE(0x1046, 0x9967), .driver_info = BRIDGE_W9968CF },
  4083. {USB_DEVICE(0x8020, 0xef04), .driver_info = BRIDGE_OVFX2 },
  4084. {}
  4085. };
  4086. MODULE_DEVICE_TABLE(usb, device_table);
  4087. /* -- device connect -- */
  4088. static int sd_probe(struct usb_interface *intf,
  4089. const struct usb_device_id *id)
  4090. {
  4091. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  4092. THIS_MODULE);
  4093. }
  4094. static struct usb_driver sd_driver = {
  4095. .name = MODULE_NAME,
  4096. .id_table = device_table,
  4097. .probe = sd_probe,
  4098. .disconnect = gspca_disconnect,
  4099. #ifdef CONFIG_PM
  4100. .suspend = gspca_suspend,
  4101. .resume = gspca_resume,
  4102. #endif
  4103. };
  4104. /* -- module insert / remove -- */
  4105. static int __init sd_mod_init(void)
  4106. {
  4107. return usb_register(&sd_driver);
  4108. }
  4109. static void __exit sd_mod_exit(void)
  4110. {
  4111. usb_deregister(&sd_driver);
  4112. }
  4113. module_init(sd_mod_init);
  4114. module_exit(sd_mod_exit);
  4115. module_param(frame_rate, int, 0644);
  4116. MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");