ov519.c 134 KB

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