ov519.c 119 KB

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