0011-cameras.patch 347 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662
  1. From 2474b15f441fc37985fac9a9458c9b5135f20907 Mon Sep 17 00:00:00 2001
  2. From: Sakari Ailus <sakari.ailus@linux.intel.com>
  3. Date: Mon, 12 Oct 2020 21:04:11 +0300
  4. Subject: [PATCH] ipu3-cio2: Use unsigned values where appropriate
  5. Use unsigned values for width, height, bit shifts and registers,
  6. effectively for all definitions that are not signed.
  7. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
  8. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
  9. Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  10. Patchset: cameras
  11. ---
  12. drivers/media/pci/intel/ipu3/ipu3-cio2.h | 156 +++++++++++------------
  13. 1 file changed, 78 insertions(+), 78 deletions(-)
  14. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.h b/drivers/media/pci/intel/ipu3/ipu3-cio2.h
  15. index 146492383aa5..7650d7998a3f 100644
  16. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.h
  17. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.h
  18. @@ -13,20 +13,20 @@
  19. #define CIO2_PCI_BAR 0
  20. #define CIO2_DMA_MASK DMA_BIT_MASK(39)
  21. -#define CIO2_IMAGE_MAX_WIDTH 4224
  22. -#define CIO2_IMAGE_MAX_LENGTH 3136
  23. +#define CIO2_IMAGE_MAX_WIDTH 4224U
  24. +#define CIO2_IMAGE_MAX_LENGTH 3136U
  25. /* 32MB = 8xFBPT_entry */
  26. #define CIO2_MAX_LOPS 8
  27. #define CIO2_MAX_BUFFERS (PAGE_SIZE / 16 / CIO2_MAX_LOPS)
  28. #define CIO2_LOP_ENTRIES (PAGE_SIZE / sizeof(u32))
  29. -#define CIO2_PAD_SINK 0
  30. -#define CIO2_PAD_SOURCE 1
  31. -#define CIO2_PADS 2
  32. +#define CIO2_PAD_SINK 0U
  33. +#define CIO2_PAD_SOURCE 1U
  34. +#define CIO2_PADS 2U
  35. -#define CIO2_NUM_DMA_CHAN 20
  36. -#define CIO2_NUM_PORTS 4 /* DPHYs */
  37. +#define CIO2_NUM_DMA_CHAN 20U
  38. +#define CIO2_NUM_PORTS 4U /* DPHYs */
  39. /* 1 for each sensor */
  40. #define CIO2_QUEUES CIO2_NUM_PORTS
  41. @@ -66,12 +66,12 @@
  42. #define CIO2_REG_MIPIBE_FORCE_RAW8 (CIO2_REG_MIPIBE_BASE + 0x20)
  43. #define CIO2_REG_MIPIBE_FORCE_RAW8_ENABLE BIT(0)
  44. #define CIO2_REG_MIPIBE_FORCE_RAW8_USE_TYPEID BIT(1)
  45. -#define CIO2_REG_MIPIBE_FORCE_RAW8_TYPEID_SHIFT 2
  46. +#define CIO2_REG_MIPIBE_FORCE_RAW8_TYPEID_SHIFT 2U
  47. #define CIO2_REG_MIPIBE_IRQ_STATUS (CIO2_REG_MIPIBE_BASE + 0x24)
  48. #define CIO2_REG_MIPIBE_IRQ_CLEAR (CIO2_REG_MIPIBE_BASE + 0x28)
  49. #define CIO2_REG_MIPIBE_GLOBAL_LUT_DISREGARD (CIO2_REG_MIPIBE_BASE + 0x68)
  50. -#define CIO2_MIPIBE_GLOBAL_LUT_DISREGARD 1
  51. +#define CIO2_MIPIBE_GLOBAL_LUT_DISREGARD 1U
  52. #define CIO2_REG_MIPIBE_PKT_STALL_STATUS (CIO2_REG_MIPIBE_BASE + 0x6c)
  53. #define CIO2_REG_MIPIBE_PARSE_GSP_THROUGH_LP_LUT_REG_IDX \
  54. (CIO2_REG_MIPIBE_BASE + 0x70)
  55. @@ -79,10 +79,10 @@
  56. (CIO2_REG_MIPIBE_BASE + 0x74 + 4 * (vc))
  57. #define CIO2_REG_MIPIBE_LP_LUT_ENTRY(m) /* m = 0..15 */ \
  58. (CIO2_REG_MIPIBE_BASE + 0x84 + 4 * (m))
  59. -#define CIO2_MIPIBE_LP_LUT_ENTRY_DISREGARD 1
  60. -#define CIO2_MIPIBE_LP_LUT_ENTRY_SID_SHIFT 1
  61. -#define CIO2_MIPIBE_LP_LUT_ENTRY_VC_SHIFT 5
  62. -#define CIO2_MIPIBE_LP_LUT_ENTRY_FORMAT_TYPE_SHIFT 7
  63. +#define CIO2_MIPIBE_LP_LUT_ENTRY_DISREGARD 1U
  64. +#define CIO2_MIPIBE_LP_LUT_ENTRY_SID_SHIFT 1U
  65. +#define CIO2_MIPIBE_LP_LUT_ENTRY_VC_SHIFT 5U
  66. +#define CIO2_MIPIBE_LP_LUT_ENTRY_FORMAT_TYPE_SHIFT 7U
  67. /* base register: CIO2_REG_PIPE_BASE(pipe) * CIO2_REG_IRQCTRL_BASE */
  68. /* IRQ registers are 18-bit wide, see cio2_irq_error for bit definitions */
  69. @@ -113,31 +113,31 @@
  70. #define CIO2_CGC_ROSC_DCGE BIT(12)
  71. #define CIO2_CGC_XOSC_DCGE BIT(13)
  72. #define CIO2_CGC_FLIS_DCGE BIT(14)
  73. -#define CIO2_CGC_CLKGATE_HOLDOFF_SHIFT 20
  74. -#define CIO2_CGC_CSI_CLKGATE_HOLDOFF_SHIFT 24
  75. +#define CIO2_CGC_CLKGATE_HOLDOFF_SHIFT 20U
  76. +#define CIO2_CGC_CSI_CLKGATE_HOLDOFF_SHIFT 24U
  77. #define CIO2_REG_D0I3C 0x1408
  78. #define CIO2_D0I3C_I3 BIT(2) /* Set D0I3 */
  79. #define CIO2_D0I3C_RR BIT(3) /* Restore? */
  80. #define CIO2_REG_SWRESET 0x140c
  81. -#define CIO2_SWRESET_SWRESET 1
  82. +#define CIO2_SWRESET_SWRESET 1U
  83. #define CIO2_REG_SENSOR_ACTIVE 0x1410
  84. #define CIO2_REG_INT_STS 0x1414
  85. #define CIO2_REG_INT_STS_EXT_OE 0x1418
  86. -#define CIO2_INT_EXT_OE_DMAOE_SHIFT 0
  87. +#define CIO2_INT_EXT_OE_DMAOE_SHIFT 0U
  88. #define CIO2_INT_EXT_OE_DMAOE_MASK 0x7ffff
  89. -#define CIO2_INT_EXT_OE_OES_SHIFT 24
  90. +#define CIO2_INT_EXT_OE_OES_SHIFT 24U
  91. #define CIO2_INT_EXT_OE_OES_MASK (0xf << CIO2_INT_EXT_OE_OES_SHIFT)
  92. #define CIO2_REG_INT_EN 0x1420
  93. #define CIO2_REG_INT_EN_IRQ (1 << 24)
  94. -#define CIO2_REG_INT_EN_IOS(dma) (1 << (((dma) >> 1) + 12))
  95. +#define CIO2_REG_INT_EN_IOS(dma) (1U << (((dma) >> 1U) + 12U))
  96. /*
  97. * Interrupt on completion bit, Eg. DMA 0-3 maps to bit 0-3,
  98. * DMA4 & DMA5 map to bit 4 ... DMA18 & DMA19 map to bit 11 Et cetera
  99. */
  100. -#define CIO2_INT_IOC(dma) (1 << ((dma) < 4 ? (dma) : ((dma) >> 1) + 2))
  101. +#define CIO2_INT_IOC(dma) (1U << ((dma) < 4U ? (dma) : ((dma) >> 1U) + 2U))
  102. #define CIO2_INT_IOC_SHIFT 0
  103. #define CIO2_INT_IOC_MASK (0x7ff << CIO2_INT_IOC_SHIFT)
  104. -#define CIO2_INT_IOS_IOLN(dma) (1 << (((dma) >> 1) + 12))
  105. +#define CIO2_INT_IOS_IOLN(dma) (1U << (((dma) >> 1U) + 12U))
  106. #define CIO2_INT_IOS_IOLN_SHIFT 12
  107. #define CIO2_INT_IOS_IOLN_MASK (0x3ff << CIO2_INT_IOS_IOLN_SHIFT)
  108. #define CIO2_INT_IOIE BIT(22)
  109. @@ -145,32 +145,32 @@
  110. #define CIO2_INT_IOIRQ BIT(24)
  111. #define CIO2_REG_INT_EN_EXT_OE 0x1424
  112. #define CIO2_REG_DMA_DBG 0x1448
  113. -#define CIO2_REG_DMA_DBG_DMA_INDEX_SHIFT 0
  114. +#define CIO2_REG_DMA_DBG_DMA_INDEX_SHIFT 0U
  115. #define CIO2_REG_PBM_ARB_CTRL 0x1460
  116. -#define CIO2_PBM_ARB_CTRL_LANES_DIV 0 /* 4-4-2-2 lanes */
  117. -#define CIO2_PBM_ARB_CTRL_LANES_DIV_SHIFT 0
  118. +#define CIO2_PBM_ARB_CTRL_LANES_DIV 0U /* 4-4-2-2 lanes */
  119. +#define CIO2_PBM_ARB_CTRL_LANES_DIV_SHIFT 0U
  120. #define CIO2_PBM_ARB_CTRL_LE_EN BIT(7)
  121. -#define CIO2_PBM_ARB_CTRL_PLL_POST_SHTDN 2
  122. -#define CIO2_PBM_ARB_CTRL_PLL_POST_SHTDN_SHIFT 8
  123. -#define CIO2_PBM_ARB_CTRL_PLL_AHD_WK_UP 480
  124. -#define CIO2_PBM_ARB_CTRL_PLL_AHD_WK_UP_SHIFT 16
  125. +#define CIO2_PBM_ARB_CTRL_PLL_POST_SHTDN 2U
  126. +#define CIO2_PBM_ARB_CTRL_PLL_POST_SHTDN_SHIFT 8U
  127. +#define CIO2_PBM_ARB_CTRL_PLL_AHD_WK_UP 480U
  128. +#define CIO2_PBM_ARB_CTRL_PLL_AHD_WK_UP_SHIFT 16U
  129. #define CIO2_REG_PBM_WMCTRL1 0x1464
  130. -#define CIO2_PBM_WMCTRL1_MIN_2CK_SHIFT 0
  131. -#define CIO2_PBM_WMCTRL1_MID1_2CK_SHIFT 8
  132. -#define CIO2_PBM_WMCTRL1_MID2_2CK_SHIFT 16
  133. +#define CIO2_PBM_WMCTRL1_MIN_2CK_SHIFT 0U
  134. +#define CIO2_PBM_WMCTRL1_MID1_2CK_SHIFT 8U
  135. +#define CIO2_PBM_WMCTRL1_MID2_2CK_SHIFT 16U
  136. #define CIO2_PBM_WMCTRL1_TS_COUNT_DISABLE BIT(31)
  137. #define CIO2_PBM_WMCTRL1_MIN_2CK (4 << CIO2_PBM_WMCTRL1_MIN_2CK_SHIFT)
  138. #define CIO2_PBM_WMCTRL1_MID1_2CK (16 << CIO2_PBM_WMCTRL1_MID1_2CK_SHIFT)
  139. #define CIO2_PBM_WMCTRL1_MID2_2CK (21 << CIO2_PBM_WMCTRL1_MID2_2CK_SHIFT)
  140. #define CIO2_REG_PBM_WMCTRL2 0x1468
  141. -#define CIO2_PBM_WMCTRL2_HWM_2CK 40
  142. -#define CIO2_PBM_WMCTRL2_HWM_2CK_SHIFT 0
  143. -#define CIO2_PBM_WMCTRL2_LWM_2CK 22
  144. -#define CIO2_PBM_WMCTRL2_LWM_2CK_SHIFT 8
  145. -#define CIO2_PBM_WMCTRL2_OBFFWM_2CK 2
  146. -#define CIO2_PBM_WMCTRL2_OBFFWM_2CK_SHIFT 16
  147. -#define CIO2_PBM_WMCTRL2_TRANSDYN 1
  148. -#define CIO2_PBM_WMCTRL2_TRANSDYN_SHIFT 24
  149. +#define CIO2_PBM_WMCTRL2_HWM_2CK 40U
  150. +#define CIO2_PBM_WMCTRL2_HWM_2CK_SHIFT 0U
  151. +#define CIO2_PBM_WMCTRL2_LWM_2CK 22U
  152. +#define CIO2_PBM_WMCTRL2_LWM_2CK_SHIFT 8U
  153. +#define CIO2_PBM_WMCTRL2_OBFFWM_2CK 2U
  154. +#define CIO2_PBM_WMCTRL2_OBFFWM_2CK_SHIFT 16U
  155. +#define CIO2_PBM_WMCTRL2_TRANSDYN 1U
  156. +#define CIO2_PBM_WMCTRL2_TRANSDYN_SHIFT 24U
  157. #define CIO2_PBM_WMCTRL2_DYNWMEN BIT(28)
  158. #define CIO2_PBM_WMCTRL2_OBFF_MEM_EN BIT(29)
  159. #define CIO2_PBM_WMCTRL2_OBFF_CPU_EN BIT(30)
  160. @@ -178,12 +178,12 @@
  161. #define CIO2_REG_PBM_TS_COUNT 0x146c
  162. #define CIO2_REG_PBM_FOPN_ABORT 0x1474
  163. /* below n = 0..3 */
  164. -#define CIO2_PBM_FOPN_ABORT(n) (0x1 << 8 * (n))
  165. -#define CIO2_PBM_FOPN_FORCE_ABORT(n) (0x2 << 8 * (n))
  166. -#define CIO2_PBM_FOPN_FRAMEOPEN(n) (0x8 << 8 * (n))
  167. +#define CIO2_PBM_FOPN_ABORT(n) (0x1 << 8U * (n))
  168. +#define CIO2_PBM_FOPN_FORCE_ABORT(n) (0x2 << 8U * (n))
  169. +#define CIO2_PBM_FOPN_FRAMEOPEN(n) (0x8 << 8U * (n))
  170. #define CIO2_REG_LTRCTRL 0x1480
  171. #define CIO2_LTRCTRL_LTRDYNEN BIT(16)
  172. -#define CIO2_LTRCTRL_LTRSTABLETIME_SHIFT 8
  173. +#define CIO2_LTRCTRL_LTRSTABLETIME_SHIFT 8U
  174. #define CIO2_LTRCTRL_LTRSTABLETIME_MASK 0xff
  175. #define CIO2_LTRCTRL_LTRSEL1S3 BIT(7)
  176. #define CIO2_LTRCTRL_LTRSEL1S2 BIT(6)
  177. @@ -195,28 +195,28 @@
  178. #define CIO2_LTRCTRL_LTRSEL2S0 BIT(0)
  179. #define CIO2_REG_LTRVAL23 0x1484
  180. #define CIO2_REG_LTRVAL01 0x1488
  181. -#define CIO2_LTRVAL02_VAL_SHIFT 0
  182. -#define CIO2_LTRVAL02_SCALE_SHIFT 10
  183. -#define CIO2_LTRVAL13_VAL_SHIFT 16
  184. -#define CIO2_LTRVAL13_SCALE_SHIFT 26
  185. +#define CIO2_LTRVAL02_VAL_SHIFT 0U
  186. +#define CIO2_LTRVAL02_SCALE_SHIFT 10U
  187. +#define CIO2_LTRVAL13_VAL_SHIFT 16U
  188. +#define CIO2_LTRVAL13_SCALE_SHIFT 26U
  189. -#define CIO2_LTRVAL0_VAL 175
  190. +#define CIO2_LTRVAL0_VAL 175U
  191. /* Value times 1024 ns */
  192. -#define CIO2_LTRVAL0_SCALE 2
  193. -#define CIO2_LTRVAL1_VAL 90
  194. -#define CIO2_LTRVAL1_SCALE 2
  195. -#define CIO2_LTRVAL2_VAL 90
  196. -#define CIO2_LTRVAL2_SCALE 2
  197. -#define CIO2_LTRVAL3_VAL 90
  198. -#define CIO2_LTRVAL3_SCALE 2
  199. +#define CIO2_LTRVAL0_SCALE 2U
  200. +#define CIO2_LTRVAL1_VAL 90U
  201. +#define CIO2_LTRVAL1_SCALE 2U
  202. +#define CIO2_LTRVAL2_VAL 90U
  203. +#define CIO2_LTRVAL2_SCALE 2U
  204. +#define CIO2_LTRVAL3_VAL 90U
  205. +#define CIO2_LTRVAL3_SCALE 2U
  206. #define CIO2_REG_CDMABA(n) (0x1500 + 0x10 * (n)) /* n = 0..19 */
  207. #define CIO2_REG_CDMARI(n) (0x1504 + 0x10 * (n))
  208. -#define CIO2_CDMARI_FBPT_RP_SHIFT 0
  209. +#define CIO2_CDMARI_FBPT_RP_SHIFT 0U
  210. #define CIO2_CDMARI_FBPT_RP_MASK 0xff
  211. #define CIO2_REG_CDMAC0(n) (0x1508 + 0x10 * (n))
  212. -#define CIO2_CDMAC0_FBPT_LEN_SHIFT 0
  213. -#define CIO2_CDMAC0_FBPT_WIDTH_SHIFT 8
  214. +#define CIO2_CDMAC0_FBPT_LEN_SHIFT 0U
  215. +#define CIO2_CDMAC0_FBPT_WIDTH_SHIFT 8U
  216. #define CIO2_CDMAC0_FBPT_NS BIT(25)
  217. #define CIO2_CDMAC0_DMA_INTR_ON_FS BIT(26)
  218. #define CIO2_CDMAC0_DMA_INTR_ON_FE BIT(27)
  219. @@ -225,12 +225,12 @@
  220. #define CIO2_CDMAC0_DMA_EN BIT(30)
  221. #define CIO2_CDMAC0_DMA_HALTED BIT(31)
  222. #define CIO2_REG_CDMAC1(n) (0x150c + 0x10 * (n))
  223. -#define CIO2_CDMAC1_LINENUMINT_SHIFT 0
  224. -#define CIO2_CDMAC1_LINENUMUPDATE_SHIFT 16
  225. +#define CIO2_CDMAC1_LINENUMINT_SHIFT 0U
  226. +#define CIO2_CDMAC1_LINENUMUPDATE_SHIFT 16U
  227. /* n = 0..3 */
  228. #define CIO2_REG_PXM_PXF_FMT_CFG0(n) (0x1700 + 0x30 * (n))
  229. -#define CIO2_PXM_PXF_FMT_CFG_SID0_SHIFT 0
  230. -#define CIO2_PXM_PXF_FMT_CFG_SID1_SHIFT 16
  231. +#define CIO2_PXM_PXF_FMT_CFG_SID0_SHIFT 0U
  232. +#define CIO2_PXM_PXF_FMT_CFG_SID1_SHIFT 16U
  233. #define CIO2_PXM_PXF_FMT_CFG_PCK_64B (0 << 0)
  234. #define CIO2_PXM_PXF_FMT_CFG_PCK_32B (1 << 0)
  235. #define CIO2_PXM_PXF_FMT_CFG_BPP_08 (0 << 2)
  236. @@ -249,27 +249,27 @@
  237. #define CIO2_PXM_PXF_FMT_CFG_PSWAP4_2ND_BD (1 << 10)
  238. #define CIO2_REG_INT_STS_EXT_IE 0x17e4
  239. #define CIO2_REG_INT_EN_EXT_IE 0x17e8
  240. -#define CIO2_INT_EXT_IE_ECC_RE(n) (0x01 << (8 * (n)))
  241. -#define CIO2_INT_EXT_IE_DPHY_NR(n) (0x02 << (8 * (n)))
  242. -#define CIO2_INT_EXT_IE_ECC_NR(n) (0x04 << (8 * (n)))
  243. -#define CIO2_INT_EXT_IE_CRCERR(n) (0x08 << (8 * (n)))
  244. -#define CIO2_INT_EXT_IE_INTERFRAMEDATA(n) (0x10 << (8 * (n)))
  245. -#define CIO2_INT_EXT_IE_PKT2SHORT(n) (0x20 << (8 * (n)))
  246. -#define CIO2_INT_EXT_IE_PKT2LONG(n) (0x40 << (8 * (n)))
  247. -#define CIO2_INT_EXT_IE_IRQ(n) (0x80 << (8 * (n)))
  248. +#define CIO2_INT_EXT_IE_ECC_RE(n) (0x01 << (8U * (n)))
  249. +#define CIO2_INT_EXT_IE_DPHY_NR(n) (0x02 << (8U * (n)))
  250. +#define CIO2_INT_EXT_IE_ECC_NR(n) (0x04 << (8U * (n)))
  251. +#define CIO2_INT_EXT_IE_CRCERR(n) (0x08 << (8U * (n)))
  252. +#define CIO2_INT_EXT_IE_INTERFRAMEDATA(n) (0x10 << (8U * (n)))
  253. +#define CIO2_INT_EXT_IE_PKT2SHORT(n) (0x20 << (8U * (n)))
  254. +#define CIO2_INT_EXT_IE_PKT2LONG(n) (0x40 << (8U * (n)))
  255. +#define CIO2_INT_EXT_IE_IRQ(n) (0x80 << (8U * (n)))
  256. #define CIO2_REG_PXM_FRF_CFG(n) (0x1720 + 0x30 * (n))
  257. #define CIO2_PXM_FRF_CFG_FNSEL BIT(0)
  258. #define CIO2_PXM_FRF_CFG_FN_RST BIT(1)
  259. #define CIO2_PXM_FRF_CFG_ABORT BIT(2)
  260. -#define CIO2_PXM_FRF_CFG_CRC_TH_SHIFT 3
  261. +#define CIO2_PXM_FRF_CFG_CRC_TH_SHIFT 3U
  262. #define CIO2_PXM_FRF_CFG_MSK_ECC_DPHY_NR BIT(8)
  263. #define CIO2_PXM_FRF_CFG_MSK_ECC_RE BIT(9)
  264. #define CIO2_PXM_FRF_CFG_MSK_ECC_DPHY_NE BIT(10)
  265. -#define CIO2_PXM_FRF_CFG_EVEN_ODD_MODE_SHIFT 11
  266. +#define CIO2_PXM_FRF_CFG_EVEN_ODD_MODE_SHIFT 11U
  267. #define CIO2_PXM_FRF_CFG_MASK_CRC_THRES BIT(13)
  268. #define CIO2_PXM_FRF_CFG_MASK_CSI_ACCEPT BIT(14)
  269. #define CIO2_PXM_FRF_CFG_CIOHC_FS_MODE BIT(15)
  270. -#define CIO2_PXM_FRF_CFG_CIOHC_FRST_FRM_SHIFT 16
  271. +#define CIO2_PXM_FRF_CFG_CIOHC_FRST_FRM_SHIFT 16U
  272. #define CIO2_REG_PXM_SID2BID0(n) (0x1724 + 0x30 * (n))
  273. #define CIO2_FB_HPLL_FREQ 0x2
  274. #define CIO2_ISCLK_RATIO 0xc
  275. @@ -278,14 +278,14 @@
  276. #define CIO2_INT_EN_EXT_OE_MASK 0x8f0fffff
  277. -#define CIO2_CGC_CLKGATE_HOLDOFF 3
  278. -#define CIO2_CGC_CSI_CLKGATE_HOLDOFF 5
  279. +#define CIO2_CGC_CLKGATE_HOLDOFF 3U
  280. +#define CIO2_CGC_CSI_CLKGATE_HOLDOFF 5U
  281. #define CIO2_PXM_FRF_CFG_CRC_TH 16
  282. #define CIO2_INT_EN_EXT_IE_MASK 0xffffffff
  283. -#define CIO2_DMA_CHAN 0
  284. +#define CIO2_DMA_CHAN 0U
  285. #define CIO2_CSIRX_DLY_CNT_CLANE_IDX -1
  286. @@ -302,8 +302,8 @@
  287. #define CIO2_CSIRX_DLY_CNT_TERMEN_DEFAULT 0x4
  288. #define CIO2_CSIRX_DLY_CNT_SETTLE_DEFAULT 0x570
  289. -#define CIO2_PMCSR_OFFSET 4
  290. -#define CIO2_PMCSR_D0D3_SHIFT 2
  291. +#define CIO2_PMCSR_OFFSET 4U
  292. +#define CIO2_PMCSR_D0D3_SHIFT 2U
  293. #define CIO2_PMCSR_D3 0x3
  294. struct cio2_csi2_timing {
  295. --
  296. 2.33.0
  297. From 80cc88e57e3b5b737e093f1a0b42a2f6da577ae6 Mon Sep 17 00:00:00 2001
  298. From: Sakari Ailus <sakari.ailus@linux.intel.com>
  299. Date: Mon, 12 Oct 2020 21:04:12 +0300
  300. Subject: [PATCH] ipu3-cio2: Remove explicit type from frame size checks
  301. Now that the values are unsigned, we can remove explicit cast to u32.
  302. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
  303. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
  304. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  305. Patchset: cameras
  306. ---
  307. drivers/media/pci/intel/ipu3/ipu3-cio2.c | 5 ++---
  308. 1 file changed, 2 insertions(+), 3 deletions(-)
  309. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
  310. index 2fe4a0bd0284..2061d7a50700 100644
  311. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c
  312. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
  313. @@ -1283,9 +1283,8 @@ static int cio2_subdev_set_fmt(struct v4l2_subdev *sd,
  314. }
  315. }
  316. - fmt->format.width = min_t(u32, fmt->format.width, CIO2_IMAGE_MAX_WIDTH);
  317. - fmt->format.height = min_t(u32, fmt->format.height,
  318. - CIO2_IMAGE_MAX_LENGTH);
  319. + fmt->format.width = min(fmt->format.width, CIO2_IMAGE_MAX_WIDTH);
  320. + fmt->format.height = min(fmt->format.height, CIO2_IMAGE_MAX_LENGTH);
  321. fmt->format.field = V4L2_FIELD_NONE;
  322. mutex_lock(&q->subdev_lock);
  323. --
  324. 2.33.0
  325. From dc8f0b080a1f793d85e993e1796883614e9ce6cc Mon Sep 17 00:00:00 2001
  326. From: Sakari Ailus <sakari.ailus@linux.intel.com>
  327. Date: Mon, 12 Oct 2020 21:04:13 +0300
  328. Subject: [PATCH] ipu3-cio2: Rename CIO2_IMAGE_MAX_LENGTH as
  329. CIO2_IMAGE_MAX_HEIGHT
  330. CIO2_IMAGE_MAX_LENGTH is the maximum width of the image. Rename it as
  331. "CIO2_IMAGE_MAX_HEIGHT" in order to better describe what it is.
  332. Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  333. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
  334. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
  335. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  336. Patchset: cameras
  337. ---
  338. drivers/media/pci/intel/ipu3/ipu3-cio2.c | 6 +++---
  339. drivers/media/pci/intel/ipu3/ipu3-cio2.h | 2 +-
  340. 2 files changed, 4 insertions(+), 4 deletions(-)
  341. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
  342. index 2061d7a50700..a0202166e2b0 100644
  343. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c
  344. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
  345. @@ -1095,8 +1095,8 @@ static int cio2_v4l2_try_fmt(struct file *file, void *fh, struct v4l2_format *f)
  346. /* Only supports up to 4224x3136 */
  347. if (mpix->width > CIO2_IMAGE_MAX_WIDTH)
  348. mpix->width = CIO2_IMAGE_MAX_WIDTH;
  349. - if (mpix->height > CIO2_IMAGE_MAX_LENGTH)
  350. - mpix->height = CIO2_IMAGE_MAX_LENGTH;
  351. + if (mpix->height > CIO2_IMAGE_MAX_HEIGHT)
  352. + mpix->height = CIO2_IMAGE_MAX_HEIGHT;
  353. mpix->num_planes = 1;
  354. mpix->pixelformat = fmt->fourcc;
  355. @@ -1284,7 +1284,7 @@ static int cio2_subdev_set_fmt(struct v4l2_subdev *sd,
  356. }
  357. fmt->format.width = min(fmt->format.width, CIO2_IMAGE_MAX_WIDTH);
  358. - fmt->format.height = min(fmt->format.height, CIO2_IMAGE_MAX_LENGTH);
  359. + fmt->format.height = min(fmt->format.height, CIO2_IMAGE_MAX_HEIGHT);
  360. fmt->format.field = V4L2_FIELD_NONE;
  361. mutex_lock(&q->subdev_lock);
  362. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.h b/drivers/media/pci/intel/ipu3/ipu3-cio2.h
  363. index 7650d7998a3f..ccf0b85ae36f 100644
  364. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.h
  365. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.h
  366. @@ -14,7 +14,7 @@
  367. #define CIO2_DMA_MASK DMA_BIT_MASK(39)
  368. #define CIO2_IMAGE_MAX_WIDTH 4224U
  369. -#define CIO2_IMAGE_MAX_LENGTH 3136U
  370. +#define CIO2_IMAGE_MAX_HEIGHT 3136U
  371. /* 32MB = 8xFBPT_entry */
  372. #define CIO2_MAX_LOPS 8
  373. --
  374. 2.33.0
  375. From 60dce090c91b1919a00bc95124dd008d049aa3d4 Mon Sep 17 00:00:00 2001
  376. From: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx>
  377. Date: Tue, 13 Oct 2020 17:25:35 +0300
  378. Subject: [PATCH] ipu3-cio2: Check receved the size against payload size, not
  379. buffer size
  380. Compare the received size of the payload size, not the allocated size of
  381. the buffer that is page aligned. This way also images that aren't aligned
  382. to page size are not warned about.
  383. Also wrap a line over 80 characters.
  384. Suggested-by: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>
  385. Signed-off-by: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx>
  386. Reviewed-by: Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>
  387. Tested-by: Jean-Michel Hautbois <jeanmichel.hautbois@xxxxxxxxx>
  388. Patchset: cameras
  389. ---
  390. drivers/media/pci/intel/ipu3/ipu3-cio2.c | 12 +++++++-----
  391. 1 file changed, 7 insertions(+), 5 deletions(-)
  392. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
  393. index a0202166e2b0..c0cd4606810c 100644
  394. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.c
  395. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c
  396. @@ -561,7 +561,9 @@ static void cio2_buffer_done(struct cio2_device *cio2, unsigned int dma_chan)
  397. b = q->bufs[q->bufs_first];
  398. if (b) {
  399. - unsigned int bytes = entry[1].second_entry.num_of_bytes;
  400. + unsigned int received = entry[1].second_entry.num_of_bytes;
  401. + unsigned long payload =
  402. + vb2_get_plane_payload(&b->vbb.vb2_buf, 0);
  403. q->bufs[q->bufs_first] = NULL;
  404. atomic_dec(&q->bufs_queued);
  405. @@ -571,10 +573,10 @@ static void cio2_buffer_done(struct cio2_device *cio2, unsigned int dma_chan)
  406. b->vbb.vb2_buf.timestamp = ns;
  407. b->vbb.field = V4L2_FIELD_NONE;
  408. b->vbb.sequence = atomic_read(&q->frame_sequence);
  409. - if (b->vbb.vb2_buf.planes[0].length != bytes)
  410. - dev_warn(dev, "buffer length is %d received %d\n",
  411. - b->vbb.vb2_buf.planes[0].length,
  412. - bytes);
  413. + if (payload != received)
  414. + dev_warn(dev,
  415. + "payload length is %lu, received %u\n",
  416. + payload, received);
  417. vb2_buffer_done(&b->vbb.vb2_buf, VB2_BUF_STATE_DONE);
  418. }
  419. atomic_inc(&q->frame_sequence);
  420. --
  421. 2.33.0
  422. From 77c2761d168b618b79be1dc908a649f2f3ba6e00 Mon Sep 17 00:00:00 2001
  423. From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  424. Date: Wed, 30 Dec 2020 22:44:05 +0200
  425. Subject: [PATCH] media: ipu3-cio2: Add headers that ipu3-cio2.h is direct user
  426. of
  427. Add headers that ipu3-cio2.h is direct user of.
  428. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  429. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  430. Reviewed-by: Daniel Scally <djrscally@gmail.com>
  431. Tested-by: Daniel Scally <djrscally@gmail.com>
  432. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  433. Patchset: cameras
  434. ---
  435. drivers/media/pci/intel/ipu3/ipu3-cio2.h | 18 ++++++++++++++++++
  436. 1 file changed, 18 insertions(+)
  437. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.h b/drivers/media/pci/intel/ipu3/ipu3-cio2.h
  438. index ccf0b85ae36f..62187ab5ae43 100644
  439. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.h
  440. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.h
  441. @@ -4,8 +4,26 @@
  442. #ifndef __IPU3_CIO2_H
  443. #define __IPU3_CIO2_H
  444. +#include <linux/bits.h>
  445. +#include <linux/dma-mapping.h>
  446. +#include <linux/kernel.h>
  447. +#include <linux/mutex.h>
  448. #include <linux/types.h>
  449. +#include <asm/page.h>
  450. +
  451. +#include <media/media-device.h>
  452. +#include <media/media-entity.h>
  453. +#include <media/v4l2-async.h>
  454. +#include <media/v4l2-dev.h>
  455. +#include <media/v4l2-device.h>
  456. +#include <media/v4l2-subdev.h>
  457. +#include <media/videobuf2-core.h>
  458. +#include <media/videobuf2-v4l2.h>
  459. +
  460. +struct cio2_fbpt_entry; /* defined here, after the first usage */
  461. +struct pci_dev;
  462. +
  463. #define CIO2_NAME "ipu3-cio2"
  464. #define CIO2_DEVICE_NAME "Intel IPU3 CIO2"
  465. #define CIO2_ENTITY_NAME "ipu3-csi2"
  466. --
  467. 2.33.0
  468. From 8baab94b24db7550d05fa3360efc24fb1cad79e9 Mon Sep 17 00:00:00 2001
  469. From: Daniel Scally <djrscally@gmail.com>
  470. Date: Sat, 24 Oct 2020 22:42:28 +0100
  471. Subject: [PATCH] device property: Return true in fwnode_device_is_available
  472. for NULL ops
  473. Some types of fwnode_handle do not implement the device_is_available()
  474. check, such as those created by software_nodes. There isn't really a
  475. meaningful way to check for the availability of a device that doesn't
  476. actually exist, so if the check isn't implemented just assume that the
  477. "device" is present.
  478. Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  479. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  480. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  481. Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
  482. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  483. Patchset: cameras
  484. ---
  485. drivers/base/property.c | 6 ++++++
  486. 1 file changed, 6 insertions(+)
  487. diff --git a/drivers/base/property.c b/drivers/base/property.c
  488. index 4c43d30145c6..bc9c634df6df 100644
  489. --- a/drivers/base/property.c
  490. +++ b/drivers/base/property.c
  491. @@ -785,9 +785,15 @@ EXPORT_SYMBOL_GPL(fwnode_handle_put);
  492. /**
  493. * fwnode_device_is_available - check if a device is available for use
  494. * @fwnode: Pointer to the fwnode of the device.
  495. + *
  496. + * For fwnode node types that don't implement the .device_is_available()
  497. + * operation, this function returns true.
  498. */
  499. bool fwnode_device_is_available(const struct fwnode_handle *fwnode)
  500. {
  501. + if (!fwnode_has_op(fwnode, device_is_available))
  502. + return true;
  503. +
  504. return fwnode_call_bool_op(fwnode, device_is_available);
  505. }
  506. EXPORT_SYMBOL_GPL(fwnode_device_is_available);
  507. --
  508. 2.33.0
  509. From ea49a99ed515607bdb999f35233be6c651492e4a Mon Sep 17 00:00:00 2001
  510. From: Daniel Scally <djrscally@gmail.com>
  511. Date: Sat, 21 Nov 2020 22:06:38 +0000
  512. Subject: [PATCH] device property: Call fwnode_graph_get_endpoint_by_id() for
  513. fwnode->secondary
  514. This function is used to find fwnode endpoints against a device. In
  515. some instances those endpoints are software nodes which are children of
  516. fwnode->secondary. Add support to fwnode_graph_get_endpoint_by_id() to
  517. find those endpoints by recursively calling itself passing the ptr to
  518. fwnode->secondary in the event no endpoint is found for the primary.
  519. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  520. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  521. Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
  522. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  523. Patchset: cameras
  524. ---
  525. drivers/base/property.c | 9 ++++++++-
  526. 1 file changed, 8 insertions(+), 1 deletion(-)
  527. diff --git a/drivers/base/property.c b/drivers/base/property.c
  528. index bc9c634df6df..ddba75d90af2 100644
  529. --- a/drivers/base/property.c
  530. +++ b/drivers/base/property.c
  531. @@ -1163,7 +1163,14 @@ fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode,
  532. best_ep_id = fwnode_ep.id;
  533. }
  534. - return best_ep;
  535. + if (best_ep)
  536. + return best_ep;
  537. +
  538. + if (fwnode && !IS_ERR_OR_NULL(fwnode->secondary))
  539. + return fwnode_graph_get_endpoint_by_id(fwnode->secondary, port,
  540. + endpoint, flags);
  541. +
  542. + return NULL;
  543. }
  544. EXPORT_SYMBOL_GPL(fwnode_graph_get_endpoint_by_id);
  545. --
  546. 2.33.0
  547. From 87fef2d943894c2b371af910231d00c662179442 Mon Sep 17 00:00:00 2001
  548. From: Daniel Scally <djrscally@gmail.com>
  549. Date: Sun, 25 Oct 2020 22:49:08 +0000
  550. Subject: [PATCH] software_node: Enforce parent before child ordering of nodes
  551. arrays
  552. Registering software_nodes with the .parent member set to point to a
  553. currently unregistered software_node has the potential for problems,
  554. so enforce parent -> child ordering in arrays passed in to
  555. software_node_register_nodes().
  556. Software nodes that are children of another software node should be
  557. unregistered before their parent. To allow easy unregistering of an array
  558. of software_nodes ordered parent to child, reverse the order in which
  559. software_node_unregister_nodes() unregisters software_nodes.
  560. Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  561. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  562. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  563. Patchset: cameras
  564. ---
  565. drivers/base/swnode.c | 42 ++++++++++++++++++++++++++++++------------
  566. 1 file changed, 30 insertions(+), 12 deletions(-)
  567. diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
  568. index 206bd4d7d7e2..eb89bdb9232c 100644
  569. --- a/drivers/base/swnode.c
  570. +++ b/drivers/base/swnode.c
  571. @@ -692,7 +692,11 @@ swnode_register(const struct software_node *node, struct swnode *parent,
  572. * software_node_register_nodes - Register an array of software nodes
  573. * @nodes: Zero terminated array of software nodes to be registered
  574. *
  575. - * Register multiple software nodes at once.
  576. + * Register multiple software nodes at once. If any node in the array
  577. + * has its .parent pointer set (which can only be to another software_node),
  578. + * then its parent **must** have been registered before it is; either outside
  579. + * of this function or by ordering the array such that parent comes before
  580. + * child.
  581. */
  582. int software_node_register_nodes(const struct software_node *nodes)
  583. {
  584. @@ -700,14 +704,23 @@ int software_node_register_nodes(const struct software_node *nodes)
  585. int i;
  586. for (i = 0; nodes[i].name; i++) {
  587. - ret = software_node_register(&nodes[i]);
  588. - if (ret) {
  589. - software_node_unregister_nodes(nodes);
  590. - return ret;
  591. + const struct software_node *parent = nodes[i].parent;
  592. +
  593. + if (parent && !software_node_to_swnode(parent)) {
  594. + ret = -EINVAL;
  595. + goto err_unregister_nodes;
  596. }
  597. +
  598. + ret = software_node_register(&nodes[i]);
  599. + if (ret)
  600. + goto err_unregister_nodes;
  601. }
  602. return 0;
  603. +
  604. +err_unregister_nodes:
  605. + software_node_unregister_nodes(nodes);
  606. + return ret;
  607. }
  608. EXPORT_SYMBOL_GPL(software_node_register_nodes);
  609. @@ -715,18 +728,23 @@ EXPORT_SYMBOL_GPL(software_node_register_nodes);
  610. * software_node_unregister_nodes - Unregister an array of software nodes
  611. * @nodes: Zero terminated array of software nodes to be unregistered
  612. *
  613. - * Unregister multiple software nodes at once.
  614. + * Unregister multiple software nodes at once. If parent pointers are set up
  615. + * in any of the software nodes then the array **must** be ordered such that
  616. + * parents come before their children.
  617. *
  618. - * NOTE: Be careful using this call if the nodes had parent pointers set up in
  619. - * them before registering. If so, it is wiser to remove the nodes
  620. - * individually, in the correct order (child before parent) instead of relying
  621. - * on the sequential order of the list of nodes in the array.
  622. + * NOTE: If you are uncertain whether the array is ordered such that
  623. + * parents will be unregistered before their children, it is wiser to
  624. + * remove the nodes individually, in the correct order (child before
  625. + * parent).
  626. */
  627. void software_node_unregister_nodes(const struct software_node *nodes)
  628. {
  629. - int i;
  630. + unsigned int i = 0;
  631. +
  632. + while (nodes[i].name)
  633. + i++;
  634. - for (i = 0; nodes[i].name; i++)
  635. + while (i--)
  636. software_node_unregister(&nodes[i]);
  637. }
  638. EXPORT_SYMBOL_GPL(software_node_unregister_nodes);
  639. --
  640. 2.33.0
  641. From e32a376cde000010f438c6fa0068e56765ac6eca Mon Sep 17 00:00:00 2001
  642. From: Daniel Scally <djrscally@gmail.com>
  643. Date: Wed, 21 Oct 2020 22:25:03 +0100
  644. Subject: [PATCH] software_node: unregister software_nodes in reverse order
  645. To maintain consistency with software_node_unregister_nodes(), reverse
  646. the order in which the software_node_unregister_node_group() function
  647. unregisters nodes.
  648. Reported-by: kernel test robot <lkp@intel.com>
  649. Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
  650. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  651. Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
  652. Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  653. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  654. Patchset: cameras
  655. ---
  656. drivers/base/swnode.c | 15 +++++++++++----
  657. 1 file changed, 11 insertions(+), 4 deletions(-)
  658. diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
  659. index eb89bdb9232c..032b24f60c78 100644
  660. --- a/drivers/base/swnode.c
  661. +++ b/drivers/base/swnode.c
  662. @@ -779,16 +779,23 @@ EXPORT_SYMBOL_GPL(software_node_register_node_group);
  663. * software_node_unregister_node_group - Unregister a group of software nodes
  664. * @node_group: NULL terminated array of software node pointers to be unregistered
  665. *
  666. - * Unregister multiple software nodes at once.
  667. + * Unregister multiple software nodes at once. The array will be unwound in
  668. + * reverse order (i.e. last entry first) and thus if any members of the array are
  669. + * children of another member then the children must appear later in the list such
  670. + * that they are unregistered first.
  671. */
  672. -void software_node_unregister_node_group(const struct software_node **node_group)
  673. +void software_node_unregister_node_group(
  674. + const struct software_node **node_group)
  675. {
  676. - unsigned int i;
  677. + unsigned int i = 0;
  678. if (!node_group)
  679. return;
  680. - for (i = 0; node_group[i]; i++)
  681. + while (node_group[i])
  682. + i++;
  683. +
  684. + while (i--)
  685. software_node_unregister(node_group[i]);
  686. }
  687. EXPORT_SYMBOL_GPL(software_node_unregister_node_group);
  688. --
  689. 2.33.0
  690. From 8d589207e02ba1733fc4d9b95eb6529871a8a291 Mon Sep 17 00:00:00 2001
  691. From: Daniel Scally <djrscally@gmail.com>
  692. Date: Tue, 22 Dec 2020 13:09:05 +0000
  693. Subject: [PATCH] device property: Define format macros for ports and endpoints
  694. OF, ACPI and software_nodes all implement graphs including nodes for ports
  695. and endpoints. These are all intended to be named with a common schema,
  696. as "port@n" and "endpoint@n" where n is an unsigned int representing the
  697. index of the node. To ensure commonality across the subsystems, provide a
  698. set of macros to define the format.
  699. Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  700. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
  701. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  702. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  703. Patchset: cameras
  704. ---
  705. include/linux/fwnode.h | 7 +++++++
  706. 1 file changed, 7 insertions(+)
  707. diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
  708. index 9506f8ec0974..72d36d46287d 100644
  709. --- a/include/linux/fwnode.h
  710. +++ b/include/linux/fwnode.h
  711. @@ -32,6 +32,13 @@ struct fwnode_endpoint {
  712. const struct fwnode_handle *local_fwnode;
  713. };
  714. +/*
  715. + * ports and endpoints defined as software_nodes should all follow a common
  716. + * naming scheme; use these macros to ensure commonality.
  717. + */
  718. +#define SWNODE_GRAPH_PORT_NAME_FMT "port@%u"
  719. +#define SWNODE_GRAPH_ENDPOINT_NAME_FMT "endpoint@%u"
  720. +
  721. #define NR_FWNODE_REFERENCE_ARGS 8
  722. /**
  723. --
  724. 2.33.0
  725. From b68f8d0583a0da5e4a766953b524016295d5df4b Mon Sep 17 00:00:00 2001
  726. From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
  727. Date: Tue, 15 Sep 2020 15:47:46 +0100
  728. Subject: [PATCH] software_node: Add support for fwnode_graph*() family of
  729. functions
  730. This implements the remaining .graph_*() callbacks in the fwnode
  731. operations structure for the software nodes. That makes the
  732. fwnode_graph_*() functions available in the drivers also when software
  733. nodes are used.
  734. The implementation tries to mimic the "OF graph" as much as possible, but
  735. there is no support for the "reg" device property. The ports will need to
  736. have the index in their name which starts with "port@" (for example
  737. "port@0", "port@1", ...) and endpoints will use the index of the software
  738. node that is given to them during creation. The port nodes can also be
  739. grouped under a specially named "ports" subnode, just like in DT, if
  740. necessary.
  741. The remote-endpoints are reference properties under the endpoint nodes
  742. that are named "remote-endpoint".
  743. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  744. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
  745. Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
  746. Co-developed-by: Daniel Scally <djrscally@gmail.com>
  747. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  748. Patchset: cameras
  749. ---
  750. drivers/base/swnode.c | 115 +++++++++++++++++++++++++++++++++++++++++-
  751. 1 file changed, 114 insertions(+), 1 deletion(-)
  752. diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
  753. index 032b24f60c78..7f056c5e0ed3 100644
  754. --- a/drivers/base/swnode.c
  755. +++ b/drivers/base/swnode.c
  756. @@ -540,6 +540,115 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,
  757. return 0;
  758. }
  759. +static struct fwnode_handle *
  760. +swnode_graph_find_next_port(const struct fwnode_handle *parent,
  761. + struct fwnode_handle *port)
  762. +{
  763. + struct fwnode_handle *old = port;
  764. +
  765. + while ((port = software_node_get_next_child(parent, old))) {
  766. + /*
  767. + * fwnode ports have naming style "port@", so we search for any
  768. + * children that follow that convention.
  769. + */
  770. + if (!strncmp(to_swnode(port)->node->name, "port@",
  771. + strlen("port@")))
  772. + return port;
  773. + old = port;
  774. + }
  775. +
  776. + return NULL;
  777. +}
  778. +
  779. +static struct fwnode_handle *
  780. +software_node_graph_get_next_endpoint(const struct fwnode_handle *fwnode,
  781. + struct fwnode_handle *endpoint)
  782. +{
  783. + struct swnode *swnode = to_swnode(fwnode);
  784. + struct fwnode_handle *parent;
  785. + struct fwnode_handle *port;
  786. +
  787. + if (!swnode)
  788. + return NULL;
  789. +
  790. + if (endpoint) {
  791. + port = software_node_get_parent(endpoint);
  792. + parent = software_node_get_parent(port);
  793. + } else {
  794. + parent = software_node_get_named_child_node(fwnode, "ports");
  795. + if (!parent)
  796. + parent = software_node_get(&swnode->fwnode);
  797. +
  798. + port = swnode_graph_find_next_port(parent, NULL);
  799. + }
  800. +
  801. + for (; port; port = swnode_graph_find_next_port(parent, port)) {
  802. + endpoint = software_node_get_next_child(port, endpoint);
  803. + if (endpoint) {
  804. + fwnode_handle_put(port);
  805. + break;
  806. + }
  807. + }
  808. +
  809. + fwnode_handle_put(parent);
  810. +
  811. + return endpoint;
  812. +}
  813. +
  814. +static struct fwnode_handle *
  815. +software_node_graph_get_remote_endpoint(const struct fwnode_handle *fwnode)
  816. +{
  817. + struct swnode *swnode = to_swnode(fwnode);
  818. + const struct software_node_ref_args *ref;
  819. + const struct property_entry *prop;
  820. +
  821. + if (!swnode)
  822. + return NULL;
  823. +
  824. + prop = property_entry_get(swnode->node->properties, "remote-endpoint");
  825. + if (!prop || prop->type != DEV_PROP_REF || prop->is_inline)
  826. + return NULL;
  827. +
  828. + ref = prop->pointer;
  829. +
  830. + return software_node_get(software_node_fwnode(ref[0].node));
  831. +}
  832. +
  833. +static struct fwnode_handle *
  834. +software_node_graph_get_port_parent(struct fwnode_handle *fwnode)
  835. +{
  836. + struct swnode *swnode = to_swnode(fwnode);
  837. +
  838. + swnode = swnode->parent;
  839. + if (swnode && !strcmp(swnode->node->name, "ports"))
  840. + swnode = swnode->parent;
  841. +
  842. + return swnode ? software_node_get(&swnode->fwnode) : NULL;
  843. +}
  844. +
  845. +static int
  846. +software_node_graph_parse_endpoint(const struct fwnode_handle *fwnode,
  847. + struct fwnode_endpoint *endpoint)
  848. +{
  849. + struct swnode *swnode = to_swnode(fwnode);
  850. + const char *parent_name = swnode->parent->node->name;
  851. + int ret;
  852. +
  853. + if (strlen("port@") >= strlen(parent_name) ||
  854. + strncmp(parent_name, "port@", strlen("port@")))
  855. + return -EINVAL;
  856. +
  857. + /* Ports have naming style "port@n", we need to select the n */
  858. + ret = kstrtou32(parent_name + strlen("port@"), 10, &endpoint->port);
  859. + if (ret)
  860. + return ret;
  861. +
  862. + endpoint->id = swnode->id;
  863. + endpoint->local_fwnode = fwnode;
  864. +
  865. + return 0;
  866. +}
  867. +
  868. static const struct fwnode_operations software_node_ops = {
  869. .get = software_node_get,
  870. .put = software_node_put,
  871. @@ -551,7 +660,11 @@ static const struct fwnode_operations software_node_ops = {
  872. .get_parent = software_node_get_parent,
  873. .get_next_child_node = software_node_get_next_child,
  874. .get_named_child_node = software_node_get_named_child_node,
  875. - .get_reference_args = software_node_get_reference_args
  876. + .get_reference_args = software_node_get_reference_args,
  877. + .graph_get_next_endpoint = software_node_graph_get_next_endpoint,
  878. + .graph_get_remote_endpoint = software_node_graph_get_remote_endpoint,
  879. + .graph_get_port_parent = software_node_graph_get_port_parent,
  880. + .graph_parse_endpoint = software_node_graph_parse_endpoint,
  881. };
  882. /* -------------------------------------------------------------------------- */
  883. --
  884. 2.33.0
  885. From 2074d259d4e0e363320583ce0eab59821fa2509a Mon Sep 17 00:00:00 2001
  886. From: Daniel Scally <djrscally@gmail.com>
  887. Date: Sat, 10 Oct 2020 23:07:22 +0100
  888. Subject: [PATCH] lib/test_printf.c: Use helper function to unwind array of
  889. software_nodes
  890. Use the software_node_unregister_nodes() helper function to unwind this
  891. array in a cleaner way.
  892. Acked-by: Petr Mladek <pmladek@suse.com>
  893. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  894. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  895. Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
  896. Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  897. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  898. Patchset: cameras
  899. ---
  900. lib/test_printf.c | 4 +---
  901. 1 file changed, 1 insertion(+), 3 deletions(-)
  902. diff --git a/lib/test_printf.c b/lib/test_printf.c
  903. index 7ac87f18a10f..7d60f24240a4 100644
  904. --- a/lib/test_printf.c
  905. +++ b/lib/test_printf.c
  906. @@ -644,9 +644,7 @@ static void __init fwnode_pointer(void)
  907. test(second_name, "%pfwP", software_node_fwnode(&softnodes[1]));
  908. test(third_name, "%pfwP", software_node_fwnode(&softnodes[2]));
  909. - software_node_unregister(&softnodes[2]);
  910. - software_node_unregister(&softnodes[1]);
  911. - software_node_unregister(&softnodes[0]);
  912. + software_node_unregister_nodes(softnodes);
  913. }
  914. static void __init
  915. --
  916. 2.33.0
  917. From 8aef347cd8368f0c56d6f26c5d8349d8c2321117 Mon Sep 17 00:00:00 2001
  918. From: Daniel Scally <djrscally@gmail.com>
  919. Date: Sat, 10 Oct 2020 23:11:36 +0100
  920. Subject: [PATCH] ipu3-cio2: Add T: entry to MAINTAINERS
  921. Development for the ipu3-cio2 driver is taking place in media_tree, but
  922. there's no T: entry in MAINTAINERS to denote that - rectify that oversight
  923. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  924. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  925. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  926. Patchset: cameras
  927. ---
  928. MAINTAINERS | 1 +
  929. 1 file changed, 1 insertion(+)
  930. diff --git a/MAINTAINERS b/MAINTAINERS
  931. index 4fef10dd2975..7ac7d1ae8764 100644
  932. --- a/MAINTAINERS
  933. +++ b/MAINTAINERS
  934. @@ -8938,6 +8938,7 @@ M: Bingbu Cao <bingbu.cao@intel.com>
  935. R: Tianshu Qiu <tian.shu.qiu@intel.com>
  936. L: linux-media@vger.kernel.org
  937. S: Maintained
  938. +T: git git://linuxtv.org/media_tree.git
  939. F: Documentation/userspace-api/media/v4l/pixfmt-srggb10-ipu3.rst
  940. F: drivers/media/pci/intel/ipu3/
  941. --
  942. 2.33.0
  943. From bc6f5e14d0a9b9926678e7baf0b75bfd09278ddc Mon Sep 17 00:00:00 2001
  944. From: Daniel Scally <djrscally@gmail.com>
  945. Date: Sat, 10 Oct 2020 22:47:21 +0100
  946. Subject: [PATCH] ipu3-cio2: Rename ipu3-cio2.c
  947. ipu3-cio2 driver needs extending with multiple files; rename the main
  948. source file and specify the renamed file in Makefile to accommodate that.
  949. Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  950. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  951. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  952. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  953. Patchset: cameras
  954. ---
  955. drivers/media/pci/intel/ipu3/Makefile | 2 ++
  956. drivers/media/pci/intel/ipu3/{ipu3-cio2.c => ipu3-cio2-main.c} | 0
  957. 2 files changed, 2 insertions(+)
  958. rename drivers/media/pci/intel/ipu3/{ipu3-cio2.c => ipu3-cio2-main.c} (100%)
  959. diff --git a/drivers/media/pci/intel/ipu3/Makefile b/drivers/media/pci/intel/ipu3/Makefile
  960. index 98ddd5beafe0..429d516452e4 100644
  961. --- a/drivers/media/pci/intel/ipu3/Makefile
  962. +++ b/drivers/media/pci/intel/ipu3/Makefile
  963. @@ -1,2 +1,4 @@
  964. # SPDX-License-Identifier: GPL-2.0-only
  965. obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o
  966. +
  967. +ipu3-cio2-y += ipu3-cio2-main.o
  968. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  969. similarity index 100%
  970. rename from drivers/media/pci/intel/ipu3/ipu3-cio2.c
  971. rename to drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  972. --
  973. 2.33.0
  974. From ce657d720915cf99a81a1c66e0331fbe0e1e1c2c Mon Sep 17 00:00:00 2001
  975. From: Daniel Scally <djrscally@gmail.com>
  976. Date: Wed, 21 Oct 2020 21:53:05 +0100
  977. Subject: [PATCH] media: v4l2-core: v4l2-async: Check sd->fwnode->secondary in
  978. match_fwnode()
  979. Where the fwnode graph is comprised of software_nodes, these will be
  980. assigned as the secondary to dev->fwnode. Check the v4l2_subdev's fwnode
  981. for a secondary and attempt to match against it during match_fwnode() to
  982. accommodate that possibility.
  983. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  984. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  985. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  986. Patchset: cameras
  987. ---
  988. drivers/media/v4l2-core/v4l2-async.c | 8 ++++++++
  989. 1 file changed, 8 insertions(+)
  990. diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
  991. index 33babe6e8b3a..d23dff76da3d 100644
  992. --- a/drivers/media/v4l2-core/v4l2-async.c
  993. +++ b/drivers/media/v4l2-core/v4l2-async.c
  994. @@ -87,6 +87,14 @@ static bool match_fwnode(struct v4l2_async_notifier *notifier,
  995. if (sd->fwnode == asd->match.fwnode)
  996. return true;
  997. + /*
  998. + * Check the same situation for any possible secondary assigned to the
  999. + * subdev's fwnode
  1000. + */
  1001. + if (!IS_ERR_OR_NULL(sd->fwnode->secondary) &&
  1002. + sd->fwnode->secondary == asd->match.fwnode)
  1003. + return true;
  1004. +
  1005. /*
  1006. * Otherwise, check if the sd fwnode and the asd fwnode refer to an
  1007. * endpoint or a device. If they're of the same type, there's no match.
  1008. --
  1009. 2.33.0
  1010. From cbb823597d62725a97cc98633d97b7145e13d6c2 Mon Sep 17 00:00:00 2001
  1011. From: Daniel Scally <djrscally@gmail.com>
  1012. Date: Sun, 15 Nov 2020 08:15:34 +0000
  1013. Subject: [PATCH] ACPI / bus: Add acpi_dev_get_next_match_dev() and helper
  1014. macro
  1015. To ensure we handle situations in which multiple sensors of the same
  1016. model (and therefore _HID) are present in a system, we need to be able
  1017. to iterate over devices matching a known _HID but unknown _UID and _HRV
  1018. - add acpi_dev_get_next_match_dev() to accommodate that possibility and
  1019. change acpi_dev_get_first_match_dev() to simply call the new function
  1020. with a NULL starting point. Add an iterator macro for convenience.
  1021. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  1022. Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
  1023. Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  1024. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  1025. Patchset: cameras
  1026. ---
  1027. drivers/acpi/utils.c | 30 ++++++++++++++++++++++++++----
  1028. include/acpi/acpi_bus.h | 7 +++++++
  1029. 2 files changed, 33 insertions(+), 4 deletions(-)
  1030. diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
  1031. index d5411a166685..ddca1550cce6 100644
  1032. --- a/drivers/acpi/utils.c
  1033. +++ b/drivers/acpi/utils.c
  1034. @@ -843,12 +843,13 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
  1035. EXPORT_SYMBOL(acpi_dev_present);
  1036. /**
  1037. - * acpi_dev_get_first_match_dev - Return the first match of ACPI device
  1038. + * acpi_dev_get_next_match_dev - Return the next match of ACPI device
  1039. + * @adev: Pointer to the previous acpi_device matching this @hid, @uid and @hrv
  1040. * @hid: Hardware ID of the device.
  1041. * @uid: Unique ID of the device, pass NULL to not check _UID
  1042. * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
  1043. *
  1044. - * Return the first match of ACPI device if a matching device was present
  1045. + * Return the next match of ACPI device if another matching device was present
  1046. * at the moment of invocation, or NULL otherwise.
  1047. *
  1048. * The caller is responsible to call put_device() on the returned device.
  1049. @@ -856,8 +857,9 @@ EXPORT_SYMBOL(acpi_dev_present);
  1050. * See additional information in acpi_dev_present() as well.
  1051. */
  1052. struct acpi_device *
  1053. -acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
  1054. +acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv)
  1055. {
  1056. + struct device *start = adev ? &adev->dev : NULL;
  1057. struct acpi_dev_match_info match = {};
  1058. struct device *dev;
  1059. @@ -865,9 +867,29 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
  1060. match.uid = uid;
  1061. match.hrv = hrv;
  1062. - dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb);
  1063. + dev = bus_find_device(&acpi_bus_type, start, &match, acpi_dev_match_cb);
  1064. return dev ? to_acpi_device(dev) : NULL;
  1065. }
  1066. +EXPORT_SYMBOL(acpi_dev_get_next_match_dev);
  1067. +
  1068. +/**
  1069. + * acpi_dev_get_first_match_dev - Return the first match of ACPI device
  1070. + * @hid: Hardware ID of the device.
  1071. + * @uid: Unique ID of the device, pass NULL to not check _UID
  1072. + * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
  1073. + *
  1074. + * Return the first match of ACPI device if a matching device was present
  1075. + * at the moment of invocation, or NULL otherwise.
  1076. + *
  1077. + * The caller is responsible to call put_device() on the returned device.
  1078. + *
  1079. + * See additional information in acpi_dev_present() as well.
  1080. + */
  1081. +struct acpi_device *
  1082. +acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
  1083. +{
  1084. + return acpi_dev_get_next_match_dev(NULL, hid, uid, hrv);
  1085. +}
  1086. EXPORT_SYMBOL(acpi_dev_get_first_match_dev);
  1087. /*
  1088. diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
  1089. index 6ad3b89a8a2e..7295aa50120a 100644
  1090. --- a/include/acpi/acpi_bus.h
  1091. +++ b/include/acpi/acpi_bus.h
  1092. @@ -684,9 +684,16 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
  1093. bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
  1094. +struct acpi_device *
  1095. +acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
  1096. struct acpi_device *
  1097. acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
  1098. +#define for_each_acpi_dev_match(adev, hid, uid, hrv) \
  1099. + for (adev = acpi_dev_get_first_match_dev(hid, uid, hrv); \
  1100. + adev; \
  1101. + adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv))
  1102. +
  1103. static inline void acpi_dev_put(struct acpi_device *adev)
  1104. {
  1105. if (adev)
  1106. --
  1107. 2.33.0
  1108. From 4c4ecb2b29db4aebb8a247643cf131b13a15b332 Mon Sep 17 00:00:00 2001
  1109. From: Daniel Scally <djrscally@gmail.com>
  1110. Date: Sat, 19 Dec 2020 23:55:04 +0000
  1111. Subject: [PATCH] media: v4l2-fwnode: Include v4l2_fwnode_bus_type
  1112. V4L2 fwnode bus types are enumerated in v4l2-fwnode.c, meaning they aren't
  1113. available to the rest of the kernel. Move the enum to the corresponding
  1114. header so that I can use the label to refer to those values.
  1115. Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  1116. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  1117. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
  1118. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  1119. Patchset: cameras
  1120. ---
  1121. drivers/media/v4l2-core/v4l2-fwnode.c | 11 -----------
  1122. include/media/v4l2-fwnode.h | 22 ++++++++++++++++++++++
  1123. 2 files changed, 22 insertions(+), 11 deletions(-)
  1124. diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
  1125. index dfc53d11053f..fe01aeb59fd4 100644
  1126. --- a/drivers/media/v4l2-core/v4l2-fwnode.c
  1127. +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
  1128. @@ -28,17 +28,6 @@
  1129. #include <media/v4l2-fwnode.h>
  1130. #include <media/v4l2-subdev.h>
  1131. -enum v4l2_fwnode_bus_type {
  1132. - V4L2_FWNODE_BUS_TYPE_GUESS = 0,
  1133. - V4L2_FWNODE_BUS_TYPE_CSI2_CPHY,
  1134. - V4L2_FWNODE_BUS_TYPE_CSI1,
  1135. - V4L2_FWNODE_BUS_TYPE_CCP2,
  1136. - V4L2_FWNODE_BUS_TYPE_CSI2_DPHY,
  1137. - V4L2_FWNODE_BUS_TYPE_PARALLEL,
  1138. - V4L2_FWNODE_BUS_TYPE_BT656,
  1139. - NR_OF_V4L2_FWNODE_BUS_TYPE,
  1140. -};
  1141. -
  1142. static const struct v4l2_fwnode_bus_conv {
  1143. enum v4l2_fwnode_bus_type fwnode_bus_type;
  1144. enum v4l2_mbus_type mbus_type;
  1145. diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h
  1146. index ed0840f3d5df..6ca337c28b3c 100644
  1147. --- a/include/media/v4l2-fwnode.h
  1148. +++ b/include/media/v4l2-fwnode.h
  1149. @@ -213,6 +213,28 @@ struct v4l2_fwnode_connector {
  1150. } connector;
  1151. };
  1152. +/**
  1153. + * enum v4l2_fwnode_bus_type - Video bus types defined by firmware properties
  1154. + * @V4L2_FWNODE_BUS_TYPE_GUESS: Default value if no bus-type fwnode property
  1155. + * @V4L2_FWNODE_BUS_TYPE_CSI2_CPHY: MIPI CSI-2 bus, C-PHY physical layer
  1156. + * @V4L2_FWNODE_BUS_TYPE_CSI1: MIPI CSI-1 bus
  1157. + * @V4L2_FWNODE_BUS_TYPE_CCP2: SMIA Compact Camera Port 2 bus
  1158. + * @V4L2_FWNODE_BUS_TYPE_CSI2_DPHY: MIPI CSI-2 bus, D-PHY physical layer
  1159. + * @V4L2_FWNODE_BUS_TYPE_PARALLEL: Camera Parallel Interface bus
  1160. + * @V4L2_FWNODE_BUS_TYPE_BT656: BT.656 video format bus-type
  1161. + * @NR_OF_V4L2_FWNODE_BUS_TYPE: Number of bus-types
  1162. + */
  1163. +enum v4l2_fwnode_bus_type {
  1164. + V4L2_FWNODE_BUS_TYPE_GUESS = 0,
  1165. + V4L2_FWNODE_BUS_TYPE_CSI2_CPHY,
  1166. + V4L2_FWNODE_BUS_TYPE_CSI1,
  1167. + V4L2_FWNODE_BUS_TYPE_CCP2,
  1168. + V4L2_FWNODE_BUS_TYPE_CSI2_DPHY,
  1169. + V4L2_FWNODE_BUS_TYPE_PARALLEL,
  1170. + V4L2_FWNODE_BUS_TYPE_BT656,
  1171. + NR_OF_V4L2_FWNODE_BUS_TYPE
  1172. +};
  1173. +
  1174. /**
  1175. * v4l2_fwnode_endpoint_parse() - parse all fwnode node properties
  1176. * @fwnode: pointer to the endpoint's fwnode handle
  1177. --
  1178. 2.33.0
  1179. From 0392fb1e916582a46fe6396ce6db45f1b7b1b2aa Mon Sep 17 00:00:00 2001
  1180. From: Daniel Scally <djrscally@gmail.com>
  1181. Date: Wed, 21 Oct 2020 21:53:44 +0100
  1182. Subject: [PATCH] ipu3-cio2: Add cio2-bridge to ipu3-cio2 driver
  1183. Currently on platforms designed for Windows, connections between CIO2 and
  1184. sensors are not properly defined in DSDT. This patch extends the ipu3-cio2
  1185. driver to compensate by building software_node connections, parsing the
  1186. connection properties from the sensor's SSDB buffer.
  1187. Suggested-by: Jordan Hand <jorhand@linux.microsoft.com>
  1188. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  1189. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
  1190. Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
  1191. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  1192. Patchset: cameras
  1193. ---
  1194. MAINTAINERS | 1 +
  1195. drivers/media/pci/intel/ipu3/Kconfig | 18 +
  1196. drivers/media/pci/intel/ipu3/Makefile | 1 +
  1197. drivers/media/pci/intel/ipu3/cio2-bridge.c | 311 ++++++++++++++++++
  1198. drivers/media/pci/intel/ipu3/cio2-bridge.h | 125 +++++++
  1199. drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 34 ++
  1200. drivers/media/pci/intel/ipu3/ipu3-cio2.h | 6 +
  1201. 7 files changed, 496 insertions(+)
  1202. create mode 100644 drivers/media/pci/intel/ipu3/cio2-bridge.c
  1203. create mode 100644 drivers/media/pci/intel/ipu3/cio2-bridge.h
  1204. diff --git a/MAINTAINERS b/MAINTAINERS
  1205. index 7ac7d1ae8764..f313ba49c2b8 100644
  1206. --- a/MAINTAINERS
  1207. +++ b/MAINTAINERS
  1208. @@ -8935,6 +8935,7 @@ INTEL IPU3 CSI-2 CIO2 DRIVER
  1209. M: Yong Zhi <yong.zhi@intel.com>
  1210. M: Sakari Ailus <sakari.ailus@linux.intel.com>
  1211. M: Bingbu Cao <bingbu.cao@intel.com>
  1212. +M: Dan Scally <djrscally@gmail.com>
  1213. R: Tianshu Qiu <tian.shu.qiu@intel.com>
  1214. L: linux-media@vger.kernel.org
  1215. S: Maintained
  1216. diff --git a/drivers/media/pci/intel/ipu3/Kconfig b/drivers/media/pci/intel/ipu3/Kconfig
  1217. index 7a805201034b..24f4e79fe0cb 100644
  1218. --- a/drivers/media/pci/intel/ipu3/Kconfig
  1219. +++ b/drivers/media/pci/intel/ipu3/Kconfig
  1220. @@ -17,3 +17,21 @@ config VIDEO_IPU3_CIO2
  1221. Say Y or M here if you have a Skylake/Kaby Lake SoC with MIPI CSI-2
  1222. connected camera.
  1223. The module will be called ipu3-cio2.
  1224. +
  1225. +config CIO2_BRIDGE
  1226. + bool "IPU3 CIO2 Sensors Bridge"
  1227. + depends on VIDEO_IPU3_CIO2
  1228. + help
  1229. + This extension provides an API for the ipu3-cio2 driver to create
  1230. + connections to cameras that are hidden in the SSDB buffer in ACPI.
  1231. + It can be used to enable support for cameras in detachable / hybrid
  1232. + devices that ship with Windows.
  1233. +
  1234. + Say Y here if your device is a detachable / hybrid laptop that comes
  1235. + with Windows installed by the OEM, for example:
  1236. +
  1237. + - Microsoft Surface models (except Surface Pro 3)
  1238. + - The Lenovo Miix line (for example the 510, 520, 710 and 720)
  1239. + - Dell 7285
  1240. +
  1241. + If in doubt, say N here.
  1242. diff --git a/drivers/media/pci/intel/ipu3/Makefile b/drivers/media/pci/intel/ipu3/Makefile
  1243. index 429d516452e4..933777e6ea8a 100644
  1244. --- a/drivers/media/pci/intel/ipu3/Makefile
  1245. +++ b/drivers/media/pci/intel/ipu3/Makefile
  1246. @@ -2,3 +2,4 @@
  1247. obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o
  1248. ipu3-cio2-y += ipu3-cio2-main.o
  1249. +ipu3-cio2-$(CONFIG_CIO2_BRIDGE) += cio2-bridge.o
  1250. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  1251. new file mode 100644
  1252. index 000000000000..143f3c0f445e
  1253. --- /dev/null
  1254. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  1255. @@ -0,0 +1,311 @@
  1256. +// SPDX-License-Identifier: GPL-2.0
  1257. +/* Author: Dan Scally <djrscally@gmail.com> */
  1258. +
  1259. +#include <linux/acpi.h>
  1260. +#include <linux/device.h>
  1261. +#include <linux/pci.h>
  1262. +#include <linux/property.h>
  1263. +#include <media/v4l2-fwnode.h>
  1264. +
  1265. +#include "cio2-bridge.h"
  1266. +
  1267. +/*
  1268. + * Extend this array with ACPI Hardware IDs of devices known to be working
  1269. + * plus the number of link-frequencies expected by their drivers, along with
  1270. + * the frequency values in hertz. This is somewhat opportunistic way of adding
  1271. + * support for this for now in the hopes of a better source for the information
  1272. + * (possibly some encoded value in the SSDB buffer that we're unaware of)
  1273. + * becoming apparent in the future.
  1274. + *
  1275. + * Do not add an entry for a sensor that is not actually supported.
  1276. + */
  1277. +static const struct cio2_sensor_config cio2_supported_sensors[] = {
  1278. + /* Omnivision OV5693 */
  1279. + CIO2_SENSOR_CONFIG("INT33BE", 0),
  1280. + /* Omnivision OV2680 */
  1281. + CIO2_SENSOR_CONFIG("OVTI2680", 0),
  1282. +};
  1283. +
  1284. +static const struct cio2_property_names prop_names = {
  1285. + .clock_frequency = "clock-frequency",
  1286. + .rotation = "rotation",
  1287. + .bus_type = "bus-type",
  1288. + .data_lanes = "data-lanes",
  1289. + .remote_endpoint = "remote-endpoint",
  1290. + .link_frequencies = "link-frequencies",
  1291. +};
  1292. +
  1293. +static int cio2_bridge_read_acpi_buffer(struct acpi_device *adev, char *id,
  1294. + void *data, u32 size)
  1295. +{
  1296. + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1297. + union acpi_object *obj;
  1298. + acpi_status status;
  1299. + int ret = 0;
  1300. +
  1301. + status = acpi_evaluate_object(adev->handle, id, NULL, &buffer);
  1302. + if (ACPI_FAILURE(status))
  1303. + return -ENODEV;
  1304. +
  1305. + obj = buffer.pointer;
  1306. + if (!obj) {
  1307. + dev_err(&adev->dev, "Couldn't locate ACPI buffer\n");
  1308. + return -ENODEV;
  1309. + }
  1310. +
  1311. + if (obj->type != ACPI_TYPE_BUFFER) {
  1312. + dev_err(&adev->dev, "Not an ACPI buffer\n");
  1313. + ret = -ENODEV;
  1314. + goto out_free_buff;
  1315. + }
  1316. +
  1317. + if (obj->buffer.length > size) {
  1318. + dev_err(&adev->dev, "Given buffer is too small\n");
  1319. + ret = -EINVAL;
  1320. + goto out_free_buff;
  1321. + }
  1322. +
  1323. + memcpy(data, obj->buffer.pointer, obj->buffer.length);
  1324. +
  1325. +out_free_buff:
  1326. + kfree(buffer.pointer);
  1327. + return ret;
  1328. +}
  1329. +
  1330. +static void cio2_bridge_create_fwnode_properties(
  1331. + struct cio2_sensor *sensor,
  1332. + struct cio2_bridge *bridge,
  1333. + const struct cio2_sensor_config *cfg)
  1334. +{
  1335. + sensor->prop_names = prop_names;
  1336. +
  1337. + sensor->local_ref[0].node = &sensor->swnodes[SWNODE_CIO2_ENDPOINT];
  1338. + sensor->remote_ref[0].node = &sensor->swnodes[SWNODE_SENSOR_ENDPOINT];
  1339. +
  1340. + sensor->dev_properties[0] = PROPERTY_ENTRY_U32(
  1341. + sensor->prop_names.clock_frequency,
  1342. + sensor->ssdb.mclkspeed);
  1343. + sensor->dev_properties[1] = PROPERTY_ENTRY_U8(
  1344. + sensor->prop_names.rotation,
  1345. + sensor->ssdb.degree);
  1346. +
  1347. + sensor->ep_properties[0] = PROPERTY_ENTRY_U32(
  1348. + sensor->prop_names.bus_type,
  1349. + V4L2_FWNODE_BUS_TYPE_CSI2_DPHY);
  1350. + sensor->ep_properties[1] = PROPERTY_ENTRY_U32_ARRAY_LEN(
  1351. + sensor->prop_names.data_lanes,
  1352. + bridge->data_lanes,
  1353. + sensor->ssdb.lanes);
  1354. + sensor->ep_properties[2] = PROPERTY_ENTRY_REF_ARRAY(
  1355. + sensor->prop_names.remote_endpoint,
  1356. + sensor->local_ref);
  1357. +
  1358. + if (cfg->nr_link_freqs > 0)
  1359. + sensor->ep_properties[3] = PROPERTY_ENTRY_U64_ARRAY_LEN(
  1360. + sensor->prop_names.link_frequencies,
  1361. + cfg->link_freqs,
  1362. + cfg->nr_link_freqs);
  1363. +
  1364. + sensor->cio2_properties[0] = PROPERTY_ENTRY_U32_ARRAY_LEN(
  1365. + sensor->prop_names.data_lanes,
  1366. + bridge->data_lanes,
  1367. + sensor->ssdb.lanes);
  1368. + sensor->cio2_properties[1] = PROPERTY_ENTRY_REF_ARRAY(
  1369. + sensor->prop_names.remote_endpoint,
  1370. + sensor->remote_ref);
  1371. +}
  1372. +
  1373. +static void cio2_bridge_init_swnode_names(struct cio2_sensor *sensor)
  1374. +{
  1375. + snprintf(sensor->node_names.remote_port,
  1376. + sizeof(sensor->node_names.remote_port),
  1377. + SWNODE_GRAPH_PORT_NAME_FMT, sensor->ssdb.link);
  1378. + snprintf(sensor->node_names.port,
  1379. + sizeof(sensor->node_names.port),
  1380. + SWNODE_GRAPH_PORT_NAME_FMT, 0); /* Always port 0 */
  1381. + snprintf(sensor->node_names.endpoint,
  1382. + sizeof(sensor->node_names.endpoint),
  1383. + SWNODE_GRAPH_ENDPOINT_NAME_FMT, 0); /* And endpoint 0 */
  1384. +}
  1385. +
  1386. +static void cio2_bridge_create_connection_swnodes(struct cio2_bridge *bridge,
  1387. + struct cio2_sensor *sensor)
  1388. +{
  1389. + struct software_node *nodes = sensor->swnodes;
  1390. +
  1391. + cio2_bridge_init_swnode_names(sensor);
  1392. +
  1393. + nodes[SWNODE_SENSOR_HID] = NODE_SENSOR(sensor->name,
  1394. + sensor->dev_properties);
  1395. + nodes[SWNODE_SENSOR_PORT] = NODE_PORT(sensor->node_names.port,
  1396. + &nodes[SWNODE_SENSOR_HID]);
  1397. + nodes[SWNODE_SENSOR_ENDPOINT] = NODE_ENDPOINT(
  1398. + sensor->node_names.endpoint,
  1399. + &nodes[SWNODE_SENSOR_PORT],
  1400. + sensor->ep_properties);
  1401. + nodes[SWNODE_CIO2_PORT] = NODE_PORT(sensor->node_names.remote_port,
  1402. + &bridge->cio2_hid_node);
  1403. + nodes[SWNODE_CIO2_ENDPOINT] = NODE_ENDPOINT(
  1404. + sensor->node_names.endpoint,
  1405. + &nodes[SWNODE_CIO2_PORT],
  1406. + sensor->cio2_properties);
  1407. +}
  1408. +
  1409. +static void cio2_bridge_unregister_sensors(struct cio2_bridge *bridge)
  1410. +{
  1411. + struct cio2_sensor *sensor;
  1412. + unsigned int i;
  1413. +
  1414. + for (i = 0; i < bridge->n_sensors; i++) {
  1415. + sensor = &bridge->sensors[i];
  1416. + software_node_unregister_nodes(sensor->swnodes);
  1417. + acpi_dev_put(sensor->adev);
  1418. + }
  1419. +}
  1420. +
  1421. +static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
  1422. + struct cio2_bridge *bridge,
  1423. + struct pci_dev *cio2)
  1424. +{
  1425. + struct fwnode_handle *fwnode;
  1426. + struct cio2_sensor *sensor;
  1427. + struct acpi_device *adev;
  1428. + int ret;
  1429. +
  1430. + for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
  1431. + if (!adev->status.enabled)
  1432. + continue;
  1433. +
  1434. + if (bridge->n_sensors >= CIO2_NUM_PORTS) {
  1435. + dev_err(&cio2->dev, "Exceeded available CIO2 ports\n");
  1436. + cio2_bridge_unregister_sensors(bridge);
  1437. + ret = -EINVAL;
  1438. + goto err_out;
  1439. + }
  1440. +
  1441. + sensor = &bridge->sensors[bridge->n_sensors];
  1442. + sensor->adev = adev;
  1443. + strscpy(sensor->name, cfg->hid, sizeof(sensor->name));
  1444. +
  1445. + ret = cio2_bridge_read_acpi_buffer(adev, "SSDB",
  1446. + &sensor->ssdb,
  1447. + sizeof(sensor->ssdb));
  1448. + if (ret)
  1449. + goto err_put_adev;
  1450. +
  1451. + if (sensor->ssdb.lanes > CIO2_MAX_LANES) {
  1452. + dev_err(&adev->dev,
  1453. + "Number of lanes in SSDB is invalid\n");
  1454. + ret = -EINVAL;
  1455. + goto err_put_adev;
  1456. + }
  1457. +
  1458. + cio2_bridge_create_fwnode_properties(sensor, bridge, cfg);
  1459. + cio2_bridge_create_connection_swnodes(bridge, sensor);
  1460. +
  1461. + ret = software_node_register_nodes(sensor->swnodes);
  1462. + if (ret)
  1463. + goto err_put_adev;
  1464. +
  1465. + fwnode = software_node_fwnode(&sensor->swnodes[SWNODE_SENSOR_HID]);
  1466. + if (!fwnode) {
  1467. + ret = -ENODEV;
  1468. + goto err_free_swnodes;
  1469. + }
  1470. +
  1471. + adev->fwnode.secondary = fwnode;
  1472. +
  1473. + dev_info(&cio2->dev, "Found supported sensor %s\n",
  1474. + acpi_dev_name(adev));
  1475. +
  1476. + bridge->n_sensors++;
  1477. + }
  1478. +
  1479. + return 0;
  1480. +
  1481. +err_free_swnodes:
  1482. + software_node_unregister_nodes(sensor->swnodes);
  1483. +err_put_adev:
  1484. + acpi_dev_put(sensor->adev);
  1485. +err_out:
  1486. + return ret;
  1487. +}
  1488. +
  1489. +static int cio2_bridge_connect_sensors(struct cio2_bridge *bridge,
  1490. + struct pci_dev *cio2)
  1491. +{
  1492. + unsigned int i;
  1493. + int ret;
  1494. +
  1495. + for (i = 0; i < ARRAY_SIZE(cio2_supported_sensors); i++) {
  1496. + const struct cio2_sensor_config *cfg = &cio2_supported_sensors[i];
  1497. +
  1498. + ret = cio2_bridge_connect_sensor(cfg, bridge, cio2);
  1499. + if (ret)
  1500. + goto err_unregister_sensors;
  1501. + }
  1502. +
  1503. + return 0;
  1504. +
  1505. +err_unregister_sensors:
  1506. + cio2_bridge_unregister_sensors(bridge);
  1507. + return ret;
  1508. +}
  1509. +
  1510. +int cio2_bridge_init(struct pci_dev *cio2)
  1511. +{
  1512. + struct device *dev = &cio2->dev;
  1513. + struct fwnode_handle *fwnode;
  1514. + struct cio2_bridge *bridge;
  1515. + unsigned int i;
  1516. + int ret;
  1517. +
  1518. + bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
  1519. + if (!bridge)
  1520. + return -ENOMEM;
  1521. +
  1522. + strscpy(bridge->cio2_node_name, CIO2_HID, sizeof(bridge->cio2_node_name));
  1523. + bridge->cio2_hid_node.name = bridge->cio2_node_name;
  1524. +
  1525. + ret = software_node_register(&bridge->cio2_hid_node);
  1526. + if (ret < 0) {
  1527. + dev_err(dev, "Failed to register the CIO2 HID node\n");
  1528. + goto err_free_bridge;
  1529. + }
  1530. +
  1531. + /*
  1532. + * Map the lane arrangement, which is fixed for the IPU3 (meaning we
  1533. + * only need one, rather than one per sensor). We include it as a
  1534. + * member of the struct cio2_bridge rather than a global variable so
  1535. + * that it survives if the module is unloaded along with the rest of
  1536. + * the struct.
  1537. + */
  1538. + for (i = 0; i < CIO2_MAX_LANES; i++)
  1539. + bridge->data_lanes[i] = i + 1;
  1540. +
  1541. + ret = cio2_bridge_connect_sensors(bridge, cio2);
  1542. + if (ret || bridge->n_sensors == 0)
  1543. + goto err_unregister_cio2;
  1544. +
  1545. + dev_info(dev, "Connected %d cameras\n", bridge->n_sensors);
  1546. +
  1547. + fwnode = software_node_fwnode(&bridge->cio2_hid_node);
  1548. + if (!fwnode) {
  1549. + dev_err(dev, "Error getting fwnode from cio2 software_node\n");
  1550. + ret = -ENODEV;
  1551. + goto err_unregister_sensors;
  1552. + }
  1553. +
  1554. + set_secondary_fwnode(dev, fwnode);
  1555. +
  1556. + return 0;
  1557. +
  1558. +err_unregister_sensors:
  1559. + cio2_bridge_unregister_sensors(bridge);
  1560. +err_unregister_cio2:
  1561. + software_node_unregister(&bridge->cio2_hid_node);
  1562. +err_free_bridge:
  1563. + kfree(bridge);
  1564. +
  1565. + return ret;
  1566. +}
  1567. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  1568. new file mode 100644
  1569. index 000000000000..dd0ffcafa489
  1570. --- /dev/null
  1571. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  1572. @@ -0,0 +1,125 @@
  1573. +/* SPDX-License-Identifier: GPL-2.0 */
  1574. +/* Author: Dan Scally <djrscally@gmail.com> */
  1575. +#ifndef __CIO2_BRIDGE_H
  1576. +#define __CIO2_BRIDGE_H
  1577. +
  1578. +#include <linux/property.h>
  1579. +#include <linux/types.h>
  1580. +
  1581. +#include "ipu3-cio2.h"
  1582. +
  1583. +#define CIO2_HID "INT343E"
  1584. +#define CIO2_MAX_LANES 4
  1585. +#define MAX_NUM_LINK_FREQS 3
  1586. +
  1587. +#define CIO2_SENSOR_CONFIG(_HID, _NR, ...) \
  1588. + (const struct cio2_sensor_config) { \
  1589. + .hid = _HID, \
  1590. + .nr_link_freqs = _NR, \
  1591. + .link_freqs = { __VA_ARGS__ } \
  1592. + }
  1593. +
  1594. +#define NODE_SENSOR(_HID, _PROPS) \
  1595. + (const struct software_node) { \
  1596. + .name = _HID, \
  1597. + .properties = _PROPS, \
  1598. + }
  1599. +
  1600. +#define NODE_PORT(_PORT, _SENSOR_NODE) \
  1601. + (const struct software_node) { \
  1602. + .name = _PORT, \
  1603. + .parent = _SENSOR_NODE, \
  1604. + }
  1605. +
  1606. +#define NODE_ENDPOINT(_EP, _PORT, _PROPS) \
  1607. + (const struct software_node) { \
  1608. + .name = _EP, \
  1609. + .parent = _PORT, \
  1610. + .properties = _PROPS, \
  1611. + }
  1612. +
  1613. +enum cio2_sensor_swnodes {
  1614. + SWNODE_SENSOR_HID,
  1615. + SWNODE_SENSOR_PORT,
  1616. + SWNODE_SENSOR_ENDPOINT,
  1617. + SWNODE_CIO2_PORT,
  1618. + SWNODE_CIO2_ENDPOINT,
  1619. + SWNODE_COUNT
  1620. +};
  1621. +
  1622. +/* Data representation as it is in ACPI SSDB buffer */
  1623. +struct cio2_sensor_ssdb {
  1624. + u8 version;
  1625. + u8 sku;
  1626. + u8 guid_csi2[16];
  1627. + u8 devfunction;
  1628. + u8 bus;
  1629. + u32 dphylinkenfuses;
  1630. + u32 clockdiv;
  1631. + u8 link;
  1632. + u8 lanes;
  1633. + u32 csiparams[10];
  1634. + u32 maxlanespeed;
  1635. + u8 sensorcalibfileidx;
  1636. + u8 sensorcalibfileidxInMBZ[3];
  1637. + u8 romtype;
  1638. + u8 vcmtype;
  1639. + u8 platforminfo;
  1640. + u8 platformsubinfo;
  1641. + u8 flash;
  1642. + u8 privacyled;
  1643. + u8 degree;
  1644. + u8 mipilinkdefined;
  1645. + u32 mclkspeed;
  1646. + u8 controllogicid;
  1647. + u8 reserved1[3];
  1648. + u8 mclkport;
  1649. + u8 reserved2[13];
  1650. +} __packed;
  1651. +
  1652. +struct cio2_property_names {
  1653. + char clock_frequency[16];
  1654. + char rotation[9];
  1655. + char bus_type[9];
  1656. + char data_lanes[11];
  1657. + char remote_endpoint[16];
  1658. + char link_frequencies[17];
  1659. +};
  1660. +
  1661. +struct cio2_node_names {
  1662. + char port[7];
  1663. + char endpoint[11];
  1664. + char remote_port[7];
  1665. +};
  1666. +
  1667. +struct cio2_sensor_config {
  1668. + const char *hid;
  1669. + const u8 nr_link_freqs;
  1670. + const u64 link_freqs[MAX_NUM_LINK_FREQS];
  1671. +};
  1672. +
  1673. +struct cio2_sensor {
  1674. + char name[ACPI_ID_LEN];
  1675. + struct acpi_device *adev;
  1676. +
  1677. + struct software_node swnodes[6];
  1678. + struct cio2_node_names node_names;
  1679. +
  1680. + struct cio2_sensor_ssdb ssdb;
  1681. + struct cio2_property_names prop_names;
  1682. + struct property_entry ep_properties[5];
  1683. + struct property_entry dev_properties[3];
  1684. + struct property_entry cio2_properties[3];
  1685. + struct software_node_ref_args local_ref[1];
  1686. + struct software_node_ref_args remote_ref[1];
  1687. +};
  1688. +
  1689. +struct cio2_bridge {
  1690. + char cio2_node_name[ACPI_ID_LEN];
  1691. + struct software_node cio2_hid_node;
  1692. + u32 data_lanes[4];
  1693. + unsigned int n_sensors;
  1694. + struct cio2_sensor sensors[CIO2_NUM_PORTS];
  1695. +};
  1696. +
  1697. +#endif
  1698. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  1699. index c0cd4606810c..77cea941fd8d 100644
  1700. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  1701. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  1702. @@ -1709,11 +1709,28 @@ static void cio2_queues_exit(struct cio2_device *cio2)
  1703. cio2_queue_exit(cio2, &cio2->queue[i]);
  1704. }
  1705. +static int cio2_check_fwnode_graph(struct fwnode_handle *fwnode)
  1706. +{
  1707. + struct fwnode_handle *endpoint;
  1708. +
  1709. + if (IS_ERR_OR_NULL(fwnode))
  1710. + return -EINVAL;
  1711. +
  1712. + endpoint = fwnode_graph_get_next_endpoint(fwnode, NULL);
  1713. + if (endpoint) {
  1714. + fwnode_handle_put(endpoint);
  1715. + return 0;
  1716. + }
  1717. +
  1718. + return cio2_check_fwnode_graph(fwnode->secondary);
  1719. +}
  1720. +
  1721. /**************** PCI interface ****************/
  1722. static int cio2_pci_probe(struct pci_dev *pci_dev,
  1723. const struct pci_device_id *id)
  1724. {
  1725. + struct fwnode_handle *fwnode = dev_fwnode(&pci_dev->dev);
  1726. struct cio2_device *cio2;
  1727. int r;
  1728. @@ -1722,6 +1739,23 @@ static int cio2_pci_probe(struct pci_dev *pci_dev,
  1729. return -ENOMEM;
  1730. cio2->pci_dev = pci_dev;
  1731. + /*
  1732. + * On some platforms no connections to sensors are defined in firmware,
  1733. + * if the device has no endpoints then we can try to build those as
  1734. + * software_nodes parsed from SSDB.
  1735. + */
  1736. + r = cio2_check_fwnode_graph(fwnode);
  1737. + if (r) {
  1738. + if (fwnode && !IS_ERR_OR_NULL(fwnode->secondary)) {
  1739. + dev_err(&pci_dev->dev, "fwnode graph has no endpoints connected\n");
  1740. + return -EINVAL;
  1741. + }
  1742. +
  1743. + r = cio2_bridge_init(pci_dev);
  1744. + if (r)
  1745. + return r;
  1746. + }
  1747. +
  1748. r = pcim_enable_device(pci_dev);
  1749. if (r) {
  1750. dev_err(&pci_dev->dev, "failed to enable device (%d)\n", r);
  1751. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.h b/drivers/media/pci/intel/ipu3/ipu3-cio2.h
  1752. index 62187ab5ae43..dc3e343a37fb 100644
  1753. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.h
  1754. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.h
  1755. @@ -455,4 +455,10 @@ static inline struct cio2_queue *vb2q_to_cio2_queue(struct vb2_queue *vq)
  1756. return container_of(vq, struct cio2_queue, vbq);
  1757. }
  1758. +#if IS_ENABLED(CONFIG_CIO2_BRIDGE)
  1759. +int cio2_bridge_init(struct pci_dev *cio2);
  1760. +#else
  1761. +int cio2_bridge_init(struct pci_dev *cio2) { return 0; }
  1762. +#endif
  1763. +
  1764. #endif
  1765. --
  1766. 2.33.0
  1767. From d870071b5f738817441b184b82b5b919b1515fae Mon Sep 17 00:00:00 2001
  1768. From: Daniel Scally <djrscally@gmail.com>
  1769. Date: Wed, 2 Dec 2020 12:38:10 +0000
  1770. Subject: [PATCH] acpi: utils: move acpi_lpss_dep() to utils
  1771. I need to be able to identify devices which declare themselves to be
  1772. dependent on other devices through _DEP; add this function to utils.c
  1773. and export it to the rest of the ACPI layer.
  1774. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  1775. Patchset: cameras
  1776. ---
  1777. drivers/acpi/acpi_lpss.c | 24 ------------------------
  1778. drivers/acpi/internal.h | 1 +
  1779. drivers/acpi/utils.c | 24 ++++++++++++++++++++++++
  1780. 3 files changed, 25 insertions(+), 24 deletions(-)
  1781. diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
  1782. index be73974ce449..70c7d9a3f715 100644
  1783. --- a/drivers/acpi/acpi_lpss.c
  1784. +++ b/drivers/acpi/acpi_lpss.c
  1785. @@ -543,30 +543,6 @@ static struct device *acpi_lpss_find_device(const char *hid, const char *uid)
  1786. return bus_find_device(&pci_bus_type, NULL, &data, match_hid_uid);
  1787. }
  1788. -static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
  1789. -{
  1790. - struct acpi_handle_list dep_devices;
  1791. - acpi_status status;
  1792. - int i;
  1793. -
  1794. - if (!acpi_has_method(adev->handle, "_DEP"))
  1795. - return false;
  1796. -
  1797. - status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
  1798. - &dep_devices);
  1799. - if (ACPI_FAILURE(status)) {
  1800. - dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
  1801. - return false;
  1802. - }
  1803. -
  1804. - for (i = 0; i < dep_devices.count; i++) {
  1805. - if (dep_devices.handles[i] == handle)
  1806. - return true;
  1807. - }
  1808. -
  1809. - return false;
  1810. -}
  1811. -
  1812. static void acpi_lpss_link_consumer(struct device *dev1,
  1813. const struct lpss_device_links *link)
  1814. {
  1815. diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
  1816. index a958ad60a339..3901a251c998 100644
  1817. --- a/drivers/acpi/internal.h
  1818. +++ b/drivers/acpi/internal.h
  1819. @@ -81,6 +81,7 @@ static inline void acpi_lpss_init(void) {}
  1820. #endif
  1821. void acpi_apd_init(void);
  1822. +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle);
  1823. acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src);
  1824. bool acpi_queue_hotplug_work(struct work_struct *work);
  1825. diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
  1826. index ddca1550cce6..78b38775f18b 100644
  1827. --- a/drivers/acpi/utils.c
  1828. +++ b/drivers/acpi/utils.c
  1829. @@ -807,6 +807,30 @@ static int acpi_dev_match_cb(struct device *dev, const void *data)
  1830. return hrv == match->hrv;
  1831. }
  1832. +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
  1833. +{
  1834. + struct acpi_handle_list dep_devices;
  1835. + acpi_status status;
  1836. + int i;
  1837. +
  1838. + if (!acpi_has_method(adev->handle, "_DEP"))
  1839. + return false;
  1840. +
  1841. + status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
  1842. + &dep_devices);
  1843. + if (ACPI_FAILURE(status)) {
  1844. + dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
  1845. + return false;
  1846. + }
  1847. +
  1848. + for (i = 0; i < dep_devices.count; i++) {
  1849. + if (dep_devices.handles[i] == handle)
  1850. + return true;
  1851. + }
  1852. +
  1853. + return false;
  1854. +}
  1855. +
  1856. /**
  1857. * acpi_dev_present - Detect that a given ACPI device is present
  1858. * @hid: Hardware ID of the device.
  1859. --
  1860. 2.33.0
  1861. From a659546aa2ac175585041d0cea87aa970ec7585c Mon Sep 17 00:00:00 2001
  1862. From: Daniel Scally <djrscally@gmail.com>
  1863. Date: Thu, 26 Nov 2020 21:12:41 +0000
  1864. Subject: [PATCH] acpi: utils: Add function to fetch dependent acpi_devices
  1865. In some ACPI tables we encounter, devices use the _DEP method to assert
  1866. a dependence on other ACPI devices as opposed to the OpRegions that the
  1867. specification intends. We need to be able to find those devices "from"
  1868. the dependee, so add a function to parse all ACPI Devices and check if
  1869. the include the handle of the dependee device in their _DEP buffer.
  1870. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  1871. Patchset: cameras
  1872. ---
  1873. drivers/acpi/utils.c | 34 ++++++++++++++++++++++++++++++++++
  1874. include/acpi/acpi_bus.h | 2 ++
  1875. 2 files changed, 36 insertions(+)
  1876. diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
  1877. index 78b38775f18b..ec6a2406a886 100644
  1878. --- a/drivers/acpi/utils.c
  1879. +++ b/drivers/acpi/utils.c
  1880. @@ -831,6 +831,18 @@ bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
  1881. return false;
  1882. }
  1883. +static int acpi_dev_match_by_dep(struct device *dev, const void *data)
  1884. +{
  1885. + struct acpi_device *adev = to_acpi_device(dev);
  1886. + const struct acpi_device *dependee = data;
  1887. + acpi_handle handle = dependee->handle;
  1888. +
  1889. + if (acpi_lpss_dep(adev, handle))
  1890. + return 1;
  1891. +
  1892. + return 0;
  1893. +}
  1894. +
  1895. /**
  1896. * acpi_dev_present - Detect that a given ACPI device is present
  1897. * @hid: Hardware ID of the device.
  1898. @@ -866,6 +878,28 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
  1899. }
  1900. EXPORT_SYMBOL(acpi_dev_present);
  1901. +/**
  1902. + * acpi_dev_get_next_dep_dev - Return next ACPI device dependent on input dev
  1903. + * @adev: Pointer to the dependee device
  1904. + * @prev: Pointer to the previous dependent device (or NULL for first match)
  1905. + *
  1906. + * Return the next ACPI device which declares itself dependent on @adev in
  1907. + * the _DEP buffer.
  1908. + *
  1909. + * The caller is responsible to call put_device() on the returned device.
  1910. + */
  1911. +struct acpi_device *acpi_dev_get_next_dep_dev(struct acpi_device *adev,
  1912. + struct acpi_device *prev)
  1913. +{
  1914. + struct device *start = prev ? &prev->dev : NULL;
  1915. + struct device *dev;
  1916. +
  1917. + dev = bus_find_device(&acpi_bus_type, start, adev, acpi_dev_match_by_dep);
  1918. +
  1919. + return dev ? to_acpi_device(dev) : NULL;
  1920. +}
  1921. +EXPORT_SYMBOL(acpi_dev_get_next_dep_dev);
  1922. +
  1923. /**
  1924. * acpi_dev_get_next_match_dev - Return the next match of ACPI device
  1925. * @adev: Pointer to the previous acpi_device matching this @hid, @uid and @hrv
  1926. diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
  1927. index 7295aa50120a..58f964471da5 100644
  1928. --- a/include/acpi/acpi_bus.h
  1929. +++ b/include/acpi/acpi_bus.h
  1930. @@ -684,6 +684,8 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
  1931. bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
  1932. +struct acpi_device *
  1933. +acpi_dev_get_next_dep_dev(struct acpi_device *adev, struct acpi_device *prev);
  1934. struct acpi_device *
  1935. acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
  1936. struct acpi_device *
  1937. --
  1938. 2.33.0
  1939. From d7f298e244aba7f166774f34339fd5d884fa7114 Mon Sep 17 00:00:00 2001
  1940. From: Daniel Scally <djrscally@gmail.com>
  1941. Date: Mon, 16 Nov 2020 21:38:49 +0000
  1942. Subject: [PATCH] i2c: i2c-core-base: Use format macro in i2c_dev_set_name()
  1943. Some places in the kernel allow users to map resources to a device
  1944. using device name (for example, gpiod_lookup_table). Currently
  1945. this involves waiting for the i2c_client to have been registered so we
  1946. can use dev_name(&client->dev). We want to add a function to allow users
  1947. to refer to an i2c device by name before it has been instantiated, so
  1948. create a macro for the format that's accessible outside the i2c layer
  1949. and use it in i2c_dev_set_name()
  1950. Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  1951. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  1952. Patchset: cameras
  1953. ---
  1954. drivers/i2c/i2c-core-base.c | 4 ++--
  1955. include/linux/i2c.h | 7 +++++++
  1956. 2 files changed, 9 insertions(+), 2 deletions(-)
  1957. diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
  1958. index bdce6d3e5327..f3ecc78dca4e 100644
  1959. --- a/drivers/i2c/i2c-core-base.c
  1960. +++ b/drivers/i2c/i2c-core-base.c
  1961. @@ -813,12 +813,12 @@ static void i2c_dev_set_name(struct i2c_adapter *adap,
  1962. struct acpi_device *adev = ACPI_COMPANION(&client->dev);
  1963. if (info && info->dev_name) {
  1964. - dev_set_name(&client->dev, "i2c-%s", info->dev_name);
  1965. + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, info->dev_name);
  1966. return;
  1967. }
  1968. if (adev) {
  1969. - dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev));
  1970. + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));
  1971. return;
  1972. }
  1973. diff --git a/include/linux/i2c.h b/include/linux/i2c.h
  1974. index a670ae129f4b..b18172f240af 100644
  1975. --- a/include/linux/i2c.h
  1976. +++ b/include/linux/i2c.h
  1977. @@ -39,6 +39,9 @@ enum i2c_slave_event;
  1978. typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
  1979. enum i2c_slave_event event, u8 *val);
  1980. +/* I2C Device Name Format - to maintain consistency outside the i2c layer */
  1981. +#define I2C_DEV_NAME_FORMAT "i2c-%s"
  1982. +
  1983. /* I2C Frequency Modes */
  1984. #define I2C_MAX_STANDARD_MODE_FREQ 100000
  1985. #define I2C_MAX_FAST_MODE_FREQ 400000
  1986. @@ -1013,6 +1016,10 @@ static inline struct i2c_client *i2c_acpi_new_device(struct device *dev,
  1987. {
  1988. return ERR_PTR(-ENODEV);
  1989. }
  1990. +static inline char *i2c_acpi_dev_name(struct acpi_device *adev)
  1991. +{
  1992. + return NULL;
  1993. +}
  1994. static inline struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
  1995. {
  1996. return NULL;
  1997. --
  1998. 2.33.0
  1999. From b39615bf56e9af6f6f601c992d48b2001c71f50b Mon Sep 17 00:00:00 2001
  2000. From: Daniel Scally <djrscally@gmail.com>
  2001. Date: Wed, 2 Dec 2020 16:41:42 +0000
  2002. Subject: [PATCH] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()
  2003. We want to refer to an i2c device by name before it has been
  2004. created by the kernel; add a function that constructs the name
  2005. from the acpi device instead.
  2006. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2007. Patchset: cameras
  2008. ---
  2009. drivers/i2c/i2c-core-acpi.c | 16 ++++++++++++++++
  2010. include/linux/i2c.h | 1 +
  2011. 2 files changed, 17 insertions(+)
  2012. diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
  2013. index aed579942436..89751415b69b 100644
  2014. --- a/drivers/i2c/i2c-core-acpi.c
  2015. +++ b/drivers/i2c/i2c-core-acpi.c
  2016. @@ -497,6 +497,22 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
  2017. }
  2018. EXPORT_SYMBOL_GPL(i2c_acpi_new_device);
  2019. +/**
  2020. + * i2c_acpi_dev_name - Construct i2c device name for devs sourced from ACPI
  2021. + * @adev: ACPI device to construct the name for
  2022. + *
  2023. + * Constructs the name of an i2c device matching the format used by
  2024. + * i2c_dev_set_name() to allow users to refer to an i2c device by name even
  2025. + * before they have been instantiated.
  2026. + *
  2027. + * The caller is responsible for freeing the returned pointer.
  2028. + */
  2029. +char *i2c_acpi_dev_name(struct acpi_device *adev)
  2030. +{
  2031. + return kasprintf(GFP_KERNEL, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));
  2032. +}
  2033. +EXPORT_SYMBOL_GPL(i2c_acpi_dev_name);
  2034. +
  2035. #ifdef CONFIG_ACPI_I2C_OPREGION
  2036. static int acpi_gsb_i2c_read_bytes(struct i2c_client *client,
  2037. u8 cmd, u8 *data, u8 data_len)
  2038. diff --git a/include/linux/i2c.h b/include/linux/i2c.h
  2039. index b18172f240af..269a2009080c 100644
  2040. --- a/include/linux/i2c.h
  2041. +++ b/include/linux/i2c.h
  2042. @@ -1000,6 +1000,7 @@ bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
  2043. u32 i2c_acpi_find_bus_speed(struct device *dev);
  2044. struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
  2045. struct i2c_board_info *info);
  2046. +char *i2c_acpi_dev_name(struct acpi_device *adev);
  2047. struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle);
  2048. #else
  2049. static inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
  2050. --
  2051. 2.33.0
  2052. From 93e728bae8143ccdc46578ce93feec0c40172d85 Mon Sep 17 00:00:00 2001
  2053. From: Daniel Scally <djrscally@gmail.com>
  2054. Date: Mon, 16 Nov 2020 00:16:56 +0000
  2055. Subject: [PATCH] gpio: gpiolib-acpi: Export acpi_get_gpiod()
  2056. I need to be able to translate GPIO resources in an acpi_device's _CRS
  2057. into gpio_descs. Those are represented in _CRS as a pathname to a GPIO
  2058. device plus the pin's index number: this function is perfect for that
  2059. purpose.
  2060. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2061. Patchset: cameras
  2062. ---
  2063. drivers/gpio/gpiolib-acpi.c | 3 ++-
  2064. include/linux/acpi.h | 5 +++++
  2065. 2 files changed, 7 insertions(+), 1 deletion(-)
  2066. diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
  2067. index 6f11714ce023..4ae6fd33b783 100644
  2068. --- a/drivers/gpio/gpiolib-acpi.c
  2069. +++ b/drivers/gpio/gpiolib-acpi.c
  2070. @@ -111,7 +111,7 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
  2071. * controller does not have GPIO chip registered at the moment. This is to
  2072. * support probe deferral.
  2073. */
  2074. -static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
  2075. +struct gpio_desc *acpi_get_gpiod(char *path, int pin)
  2076. {
  2077. struct gpio_chip *chip;
  2078. acpi_handle handle;
  2079. @@ -127,6 +127,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
  2080. return gpiochip_get_desc(chip, pin);
  2081. }
  2082. +EXPORT_SYMBOL_GPL(acpi_get_gpiod);
  2083. static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
  2084. {
  2085. diff --git a/include/linux/acpi.h b/include/linux/acpi.h
  2086. index fdb1d5262ce8..817f53506cfe 100644
  2087. --- a/include/linux/acpi.h
  2088. +++ b/include/linux/acpi.h
  2089. @@ -1080,6 +1080,7 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c
  2090. bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
  2091. struct acpi_resource_gpio **agpio);
  2092. int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *name, int index);
  2093. +struct gpio_desc *acpi_get_gpiod(char *path, int pin);
  2094. #else
  2095. static inline bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
  2096. struct acpi_resource_gpio **agpio)
  2097. @@ -1091,6 +1092,10 @@ static inline int acpi_dev_gpio_irq_get_by(struct acpi_device *adev,
  2098. {
  2099. return -ENXIO;
  2100. }
  2101. +struct gpio_desc *acpi_get_gpiod(char *path, int pin)
  2102. +{
  2103. + return NULL;
  2104. +}
  2105. #endif
  2106. static inline int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
  2107. --
  2108. 2.33.0
  2109. From f47c23f06fd6656dcc585ad8bcf6223b73f28e49 Mon Sep 17 00:00:00 2001
  2110. From: Daniel Scally <djrscally@gmail.com>
  2111. Date: Sat, 12 Dec 2020 23:56:59 +0000
  2112. Subject: [PATCH] mfd: Remove tps68470 MFD driver
  2113. This driver only covered one scenario in which ACPI devices with _HID
  2114. INT3472 are found, and its functionality has been taken over by the
  2115. intel-skl-int3472 module, so remove it.
  2116. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2117. Patchset: cameras
  2118. ---
  2119. drivers/acpi/pmic/Kconfig | 1 -
  2120. drivers/gpio/Kconfig | 1 -
  2121. drivers/mfd/Kconfig | 18 --------
  2122. drivers/mfd/Makefile | 1 -
  2123. drivers/mfd/tps68470.c | 97 ---------------------------------------
  2124. 5 files changed, 118 deletions(-)
  2125. delete mode 100644 drivers/mfd/tps68470.c
  2126. diff --git a/drivers/acpi/pmic/Kconfig b/drivers/acpi/pmic/Kconfig
  2127. index 56bbcb2ce61b..e27d8ef3a32c 100644
  2128. --- a/drivers/acpi/pmic/Kconfig
  2129. +++ b/drivers/acpi/pmic/Kconfig
  2130. @@ -52,7 +52,6 @@ endif # PMIC_OPREGION
  2131. config TPS68470_PMIC_OPREGION
  2132. bool "ACPI operation region support for TPS68470 PMIC"
  2133. - depends on MFD_TPS68470
  2134. help
  2135. This config adds ACPI operation region support for TI TPS68470 PMIC.
  2136. TPS68470 device is an advanced power management unit that powers
  2137. diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
  2138. index d1300fc003ed..923768bf2719 100644
  2139. --- a/drivers/gpio/Kconfig
  2140. +++ b/drivers/gpio/Kconfig
  2141. @@ -1321,7 +1321,6 @@ config GPIO_TPS65912
  2142. config GPIO_TPS68470
  2143. bool "TPS68470 GPIO"
  2144. - depends on MFD_TPS68470
  2145. help
  2146. Select this option to enable GPIO driver for the TPS68470
  2147. chip family.
  2148. diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
  2149. index b8847ae04d93..bd655a383cee 100644
  2150. --- a/drivers/mfd/Kconfig
  2151. +++ b/drivers/mfd/Kconfig
  2152. @@ -1534,24 +1534,6 @@ config MFD_TPS65217
  2153. This driver can also be built as a module. If so, the module
  2154. will be called tps65217.
  2155. -config MFD_TPS68470
  2156. - bool "TI TPS68470 Power Management / LED chips"
  2157. - depends on ACPI && PCI && I2C=y
  2158. - depends on I2C_DESIGNWARE_PLATFORM=y
  2159. - select MFD_CORE
  2160. - select REGMAP_I2C
  2161. - help
  2162. - If you say yes here you get support for the TPS68470 series of
  2163. - Power Management / LED chips.
  2164. -
  2165. - These include voltage regulators, LEDs and other features
  2166. - that are often used in portable devices.
  2167. -
  2168. - This option is a bool as it provides an ACPI operation
  2169. - region, which must be available before any of the devices
  2170. - using this are probed. This option also configures the
  2171. - designware-i2c driver to be built-in, for the same reason.
  2172. -
  2173. config MFD_TI_LP873X
  2174. tristate "TI LP873X Power Management IC"
  2175. depends on I2C
  2176. diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
  2177. index 1780019d2474..a23f38c4c38a 100644
  2178. --- a/drivers/mfd/Makefile
  2179. +++ b/drivers/mfd/Makefile
  2180. @@ -105,7 +105,6 @@ obj-$(CONFIG_MFD_TPS65910) += tps65910.o
  2181. obj-$(CONFIG_MFD_TPS65912) += tps65912-core.o
  2182. obj-$(CONFIG_MFD_TPS65912_I2C) += tps65912-i2c.o
  2183. obj-$(CONFIG_MFD_TPS65912_SPI) += tps65912-spi.o
  2184. -obj-$(CONFIG_MFD_TPS68470) += tps68470.o
  2185. obj-$(CONFIG_MFD_TPS80031) += tps80031.o
  2186. obj-$(CONFIG_MENELAUS) += menelaus.o
  2187. diff --git a/drivers/mfd/tps68470.c b/drivers/mfd/tps68470.c
  2188. deleted file mode 100644
  2189. index 4a4df4ffd18c..000000000000
  2190. --- a/drivers/mfd/tps68470.c
  2191. +++ /dev/null
  2192. @@ -1,97 +0,0 @@
  2193. -// SPDX-License-Identifier: GPL-2.0
  2194. -/*
  2195. - * TPS68470 chip Parent driver
  2196. - *
  2197. - * Copyright (C) 2017 Intel Corporation
  2198. - *
  2199. - * Authors:
  2200. - * Rajmohan Mani <rajmohan.mani@intel.com>
  2201. - * Tianshu Qiu <tian.shu.qiu@intel.com>
  2202. - * Jian Xu Zheng <jian.xu.zheng@intel.com>
  2203. - * Yuning Pu <yuning.pu@intel.com>
  2204. - */
  2205. -
  2206. -#include <linux/acpi.h>
  2207. -#include <linux/delay.h>
  2208. -#include <linux/i2c.h>
  2209. -#include <linux/init.h>
  2210. -#include <linux/mfd/core.h>
  2211. -#include <linux/mfd/tps68470.h>
  2212. -#include <linux/regmap.h>
  2213. -
  2214. -static const struct mfd_cell tps68470s[] = {
  2215. - { .name = "tps68470-gpio" },
  2216. - { .name = "tps68470_pmic_opregion" },
  2217. -};
  2218. -
  2219. -static const struct regmap_config tps68470_regmap_config = {
  2220. - .reg_bits = 8,
  2221. - .val_bits = 8,
  2222. - .max_register = TPS68470_REG_MAX,
  2223. -};
  2224. -
  2225. -static int tps68470_chip_init(struct device *dev, struct regmap *regmap)
  2226. -{
  2227. - unsigned int version;
  2228. - int ret;
  2229. -
  2230. - /* Force software reset */
  2231. - ret = regmap_write(regmap, TPS68470_REG_RESET, TPS68470_REG_RESET_MASK);
  2232. - if (ret)
  2233. - return ret;
  2234. -
  2235. - ret = regmap_read(regmap, TPS68470_REG_REVID, &version);
  2236. - if (ret) {
  2237. - dev_err(dev, "Failed to read revision register: %d\n", ret);
  2238. - return ret;
  2239. - }
  2240. -
  2241. - dev_info(dev, "TPS68470 REVID: 0x%x\n", version);
  2242. -
  2243. - return 0;
  2244. -}
  2245. -
  2246. -static int tps68470_probe(struct i2c_client *client)
  2247. -{
  2248. - struct device *dev = &client->dev;
  2249. - struct regmap *regmap;
  2250. - int ret;
  2251. -
  2252. - regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
  2253. - if (IS_ERR(regmap)) {
  2254. - dev_err(dev, "devm_regmap_init_i2c Error %ld\n",
  2255. - PTR_ERR(regmap));
  2256. - return PTR_ERR(regmap);
  2257. - }
  2258. -
  2259. - i2c_set_clientdata(client, regmap);
  2260. -
  2261. - ret = tps68470_chip_init(dev, regmap);
  2262. - if (ret < 0) {
  2263. - dev_err(dev, "TPS68470 Init Error %d\n", ret);
  2264. - return ret;
  2265. - }
  2266. -
  2267. - ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, tps68470s,
  2268. - ARRAY_SIZE(tps68470s), NULL, 0, NULL);
  2269. - if (ret < 0) {
  2270. - dev_err(dev, "devm_mfd_add_devices failed: %d\n", ret);
  2271. - return ret;
  2272. - }
  2273. -
  2274. - return 0;
  2275. -}
  2276. -
  2277. -static const struct acpi_device_id tps68470_acpi_ids[] = {
  2278. - {"INT3472"},
  2279. - {},
  2280. -};
  2281. -
  2282. -static struct i2c_driver tps68470_driver = {
  2283. - .driver = {
  2284. - .name = "tps68470",
  2285. - .acpi_match_table = tps68470_acpi_ids,
  2286. - },
  2287. - .probe_new = tps68470_probe,
  2288. -};
  2289. -builtin_i2c_driver(tps68470_driver);
  2290. --
  2291. 2.33.0
  2292. From 8fe7e113fe28d240202bf5047de448b5cd86a6de Mon Sep 17 00:00:00 2001
  2293. From: Daniel Scally <djrscally@gmail.com>
  2294. Date: Fri, 15 Jan 2021 12:37:31 +0000
  2295. Subject: [PATCH] platform: x86: Add intel_skl_int3472 driver
  2296. ACPI devices with _HID INT3472 are currently matched to the tps68470
  2297. driver, however this does not cover all situations in which that _HID
  2298. occurs. We've encountered three possibilities:
  2299. 1. On Chrome OS devices, an ACPI device with _HID INT3472 (representing
  2300. a physical tps68470 device) that requires a GPIO and OpRegion driver
  2301. 2. On devices designed for Windows, an ACPI device with _HID INT3472
  2302. (again representing a physical tps68470 device) which requires GPIO,
  2303. Clock and Regulator drivers.
  2304. 3. On other devices designed for Windows, an ACPI device with _HID
  2305. INT3472 which does NOT represent a physical tps68470, and is instead
  2306. used as a dummy device to group some system GPIO lines which are meant
  2307. to be consumed by the sensor that is dependent on this entry.
  2308. This commit adds a new module, registering a platform driver to deal
  2309. with the 3rd scenario plus an i2c-driver to deal with #1 and #2, by
  2310. querying the CLDB buffer found against INT3472 entries to determine
  2311. which is most appropriate.
  2312. Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  2313. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2314. Patchset: cameras
  2315. ---
  2316. MAINTAINERS | 5 +
  2317. drivers/platform/x86/Kconfig | 25 +
  2318. drivers/platform/x86/Makefile | 5 +
  2319. .../platform/x86/intel_skl_int3472_common.c | 100 ++++
  2320. .../platform/x86/intel_skl_int3472_common.h | 99 ++++
  2321. .../platform/x86/intel_skl_int3472_discrete.c | 489 ++++++++++++++++++
  2322. .../platform/x86/intel_skl_int3472_tps68470.c | 145 ++++++
  2323. 7 files changed, 868 insertions(+)
  2324. create mode 100644 drivers/platform/x86/intel_skl_int3472_common.c
  2325. create mode 100644 drivers/platform/x86/intel_skl_int3472_common.h
  2326. create mode 100644 drivers/platform/x86/intel_skl_int3472_discrete.c
  2327. create mode 100644 drivers/platform/x86/intel_skl_int3472_tps68470.c
  2328. diff --git a/MAINTAINERS b/MAINTAINERS
  2329. index f313ba49c2b8..7bec93adaae5 100644
  2330. --- a/MAINTAINERS
  2331. +++ b/MAINTAINERS
  2332. @@ -9045,6 +9045,11 @@ S: Maintained
  2333. F: arch/x86/include/asm/intel_scu_ipc.h
  2334. F: drivers/platform/x86/intel_scu_*
  2335. +INTEL SKL INT3472 ACPI DEVICE DRIVER
  2336. +M: Daniel Scally <djrscally@gmail.com>
  2337. +S: Maintained
  2338. +F: drivers/platform/x86/intel_skl_int3472_*
  2339. +
  2340. INTEL SPEED SELECT TECHNOLOGY
  2341. M: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
  2342. L: platform-driver-x86@vger.kernel.org
  2343. diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
  2344. index 533998040530..ab8324034c76 100644
  2345. --- a/drivers/platform/x86/Kconfig
  2346. +++ b/drivers/platform/x86/Kconfig
  2347. @@ -807,6 +807,31 @@ config INTEL_CHT_INT33FE
  2348. device and CONFIG_TYPEC_FUSB302=m and CONFIG_BATTERY_MAX17042=m
  2349. for Type-C device.
  2350. +config INTEL_SKL_INT3472
  2351. + tristate "Intel SkyLake ACPI INT3472 Driver"
  2352. + depends on X86 && ACPI
  2353. + select REGMAP_I2C
  2354. + help
  2355. + This driver adds support for the INT3472 ACPI devices found on some
  2356. + Intel SkyLake devices.
  2357. +
  2358. + There are 3 kinds of INT3472 ACPI device possible; two for devices
  2359. + designed for Windows (either with or without a physical tps68470
  2360. + PMIC) and one designed for Chrome OS. This driver handles all three
  2361. + situations by discovering information it needs to discern them at
  2362. + runtime.
  2363. +
  2364. + If your device was designed for Chrome OS, this driver will provide
  2365. + an ACPI operation region, which must be available before any of the
  2366. + devices using this are probed. For this reason, you should select Y
  2367. + if your device was designed for ChromeOS. This option also configures
  2368. + the designware-i2c driver to be built-in, for the same reason.
  2369. +
  2370. + Say Y or M here if you have a SkyLake device designed for use
  2371. + with Windows or ChromeOS. Say N here if you are not sure.
  2372. +
  2373. + The module will be named "intel-skl-int3472"
  2374. +
  2375. config INTEL_HID_EVENT
  2376. tristate "INTEL HID Event"
  2377. depends on ACPI
  2378. diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
  2379. index f552cbfb7914..dd8fc06b224c 100644
  2380. --- a/drivers/platform/x86/Makefile
  2381. +++ b/drivers/platform/x86/Makefile
  2382. @@ -79,6 +79,11 @@ obj-$(CONFIG_INTEL_HID_EVENT) += intel-hid.o
  2383. obj-$(CONFIG_INTEL_INT0002_VGPIO) += intel_int0002_vgpio.o
  2384. obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
  2385. obj-$(CONFIG_INTEL_OAKTRAIL) += intel_oaktrail.o
  2386. +obj-$(CONFIG_INTEL_SKL_INT3472) += intel_skl_int3472.o
  2387. +intel_skl_int3472-objs := intel_skl_int3472_common.o \
  2388. + intel_skl_int3472_discrete.o \
  2389. + intel_skl_int3472_tps68470.o
  2390. +
  2391. obj-$(CONFIG_INTEL_VBTN) += intel-vbtn.o
  2392. # Microsoft
  2393. diff --git a/drivers/platform/x86/intel_skl_int3472_common.c b/drivers/platform/x86/intel_skl_int3472_common.c
  2394. new file mode 100644
  2395. index 000000000000..08cb9d3c06aa
  2396. --- /dev/null
  2397. +++ b/drivers/platform/x86/intel_skl_int3472_common.c
  2398. @@ -0,0 +1,100 @@
  2399. +// SPDX-License-Identifier: GPL-2.0
  2400. +/* Author: Dan Scally <djrscally@gmail.com> */
  2401. +
  2402. +#include <linux/acpi.h>
  2403. +#include <linux/i2c.h>
  2404. +#include <linux/platform_device.h>
  2405. +
  2406. +#include "intel_skl_int3472_common.h"
  2407. +
  2408. +int skl_int3472_get_cldb_buffer(struct acpi_device *adev,
  2409. + struct int3472_cldb *cldb)
  2410. +{
  2411. + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  2412. + acpi_handle handle = adev->handle;
  2413. + union acpi_object *obj;
  2414. + acpi_status status;
  2415. + int ret = 0;
  2416. +
  2417. + status = acpi_evaluate_object(handle, "CLDB", NULL, &buffer);
  2418. + if (ACPI_FAILURE(status))
  2419. + return -ENODEV;
  2420. +
  2421. + obj = buffer.pointer;
  2422. + if (!obj) {
  2423. + dev_err(&adev->dev, "ACPI device has no CLDB object\n");
  2424. + return -ENODEV;
  2425. + }
  2426. +
  2427. + if (obj->type != ACPI_TYPE_BUFFER) {
  2428. + dev_err(&adev->dev, "CLDB object is not an ACPI buffer\n");
  2429. + ret = -EINVAL;
  2430. + goto out_free_buff;
  2431. + }
  2432. +
  2433. + if (obj->buffer.length > sizeof(*cldb)) {
  2434. + dev_err(&adev->dev, "The CLDB buffer is too large\n");
  2435. + ret = -EINVAL;
  2436. + goto out_free_buff;
  2437. + }
  2438. +
  2439. + memcpy(cldb, obj->buffer.pointer, obj->buffer.length);
  2440. +
  2441. +out_free_buff:
  2442. + kfree(buffer.pointer);
  2443. + return ret;
  2444. +}
  2445. +
  2446. +static const struct acpi_device_id int3472_device_id[] = {
  2447. + { "INT3472", 0 },
  2448. + { },
  2449. +};
  2450. +MODULE_DEVICE_TABLE(acpi, int3472_device_id);
  2451. +
  2452. +static struct platform_driver int3472_discrete = {
  2453. + .driver = {
  2454. + .name = "int3472-discrete",
  2455. + .acpi_match_table = int3472_device_id,
  2456. + },
  2457. + .probe = skl_int3472_discrete_probe,
  2458. + .remove = skl_int3472_discrete_remove,
  2459. +};
  2460. +
  2461. +static struct i2c_driver int3472_tps68470 = {
  2462. + .driver = {
  2463. + .name = "int3472-tps68470",
  2464. + .acpi_match_table = int3472_device_id,
  2465. + },
  2466. + .probe_new = skl_int3472_tps68470_probe,
  2467. +};
  2468. +
  2469. +static int skl_int3472_init(void)
  2470. +{
  2471. + int ret = 0;
  2472. +
  2473. + ret = platform_driver_register(&int3472_discrete);
  2474. + if (ret)
  2475. + return ret;
  2476. +
  2477. + ret = i2c_register_driver(THIS_MODULE, &int3472_tps68470);
  2478. + if (ret)
  2479. + goto err_unregister_plat_drv;
  2480. +
  2481. + return 0;
  2482. +
  2483. +err_unregister_plat_drv:
  2484. + platform_driver_unregister(&int3472_discrete);
  2485. + return ret;
  2486. +}
  2487. +module_init(skl_int3472_init);
  2488. +
  2489. +static void skl_int3472_exit(void)
  2490. +{
  2491. + platform_driver_unregister(&int3472_discrete);
  2492. + i2c_del_driver(&int3472_tps68470);
  2493. +}
  2494. +module_exit(skl_int3472_exit);
  2495. +
  2496. +MODULE_DESCRIPTION("Intel SkyLake INT3472 ACPI Device Driver");
  2497. +MODULE_AUTHOR("Daniel Scally <djrscally@gmail.com>");
  2498. +MODULE_LICENSE("GPL v2");
  2499. diff --git a/drivers/platform/x86/intel_skl_int3472_common.h b/drivers/platform/x86/intel_skl_int3472_common.h
  2500. new file mode 100644
  2501. index 000000000000..4ac6bb2b223f
  2502. --- /dev/null
  2503. +++ b/drivers/platform/x86/intel_skl_int3472_common.h
  2504. @@ -0,0 +1,99 @@
  2505. +/* SPDX-License-Identifier: GPL-2.0 */
  2506. +/* Author: Dan Scally <djrscally@gmail.com> */
  2507. +#include <linux/regulator/machine.h>
  2508. +#include <linux/clk-provider.h>
  2509. +#include <linux/gpio/machine.h>
  2510. +#include <linux/regulator/driver.h>
  2511. +#include <linux/types.h>
  2512. +
  2513. +/* PMIC GPIO Types */
  2514. +#define INT3472_GPIO_TYPE_RESET 0x00
  2515. +#define INT3472_GPIO_TYPE_POWERDOWN 0x01
  2516. +#define INT3472_GPIO_TYPE_CLK_ENABLE 0x0c
  2517. +#define INT3472_GPIO_TYPE_POWER_ENABLE 0x0b
  2518. +#define INT3472_GPIO_TYPE_PRIVACY_LED 0x0d
  2519. +#define INT3472_PDEV_MAX_NAME_LEN 23
  2520. +#define INT3472_MAX_SENSOR_GPIOS 3
  2521. +#define GPIO_REGULATOR_NAME_LENGTH 27
  2522. +#define GPIO_REGULATOR_SUPPLY_NAME_LENGTH 9
  2523. +
  2524. +#define INT3472_REGULATOR(_NAME, _SUPPLY, _OPS) \
  2525. + (const struct regulator_desc) { \
  2526. + .name = _NAME, \
  2527. + .supply_name = _SUPPLY, \
  2528. + .id = 0, \
  2529. + .type = REGULATOR_VOLTAGE, \
  2530. + .ops = _OPS, \
  2531. + .owner = THIS_MODULE, \
  2532. + }
  2533. +
  2534. +#define INT3472_GPIO_FUNCTION_REMAP(_PIN, _FUNCTION) \
  2535. + (const struct int3472_gpio_function_remap) { \
  2536. + .documented = _PIN, \
  2537. + .actual = _FUNCTION \
  2538. + }
  2539. +
  2540. +#define to_int3472_clk(hw) \
  2541. + container_of(hw, struct int3472_gpio_clock, clk_hw)
  2542. +
  2543. +struct int3472_cldb {
  2544. + u8 version;
  2545. + /*
  2546. + * control logic type
  2547. + * 0: UNKNOWN
  2548. + * 1: DISCRETE(CRD-D)
  2549. + * 2: PMIC TPS68470
  2550. + * 3: PMIC uP6641
  2551. + */
  2552. + u8 control_logic_type;
  2553. + u8 control_logic_id;
  2554. + u8 sensor_card_sku;
  2555. + u8 reserved[28];
  2556. +};
  2557. +
  2558. +struct int3472_gpio_regulator {
  2559. + char regulator_name[GPIO_REGULATOR_NAME_LENGTH];
  2560. + char supply_name[GPIO_REGULATOR_SUPPLY_NAME_LENGTH];
  2561. + struct gpio_desc *gpio;
  2562. + struct regulator_dev *rdev;
  2563. + struct regulator_desc rdesc;
  2564. +};
  2565. +
  2566. +struct int3472_gpio_clock {
  2567. + struct clk *clk;
  2568. + struct clk_hw clk_hw;
  2569. + struct gpio_desc *gpio;
  2570. +};
  2571. +
  2572. +struct int3472_device {
  2573. + struct acpi_device *adev;
  2574. + struct platform_device *pdev;
  2575. + struct acpi_device *sensor;
  2576. + char *sensor_name;
  2577. +
  2578. + unsigned int n_gpios; /* how many GPIOs have we seen */
  2579. +
  2580. + struct int3472_gpio_regulator regulator;
  2581. + struct int3472_gpio_clock clock;
  2582. +
  2583. + unsigned int n_sensor_gpios; /* how many have we mapped to sensor */
  2584. + bool gpios_mapped;
  2585. + struct gpiod_lookup_table gpios;
  2586. +};
  2587. +
  2588. +struct int3472_gpio_function_remap {
  2589. + char *documented;
  2590. + char *actual;
  2591. +};
  2592. +
  2593. +struct int3472_sensor_config {
  2594. + char *sensor_module_name;
  2595. + struct regulator_consumer_supply supply_map;
  2596. + const struct int3472_gpio_function_remap *function_maps;
  2597. +};
  2598. +
  2599. +int skl_int3472_discrete_probe(struct platform_device *pdev);
  2600. +int skl_int3472_discrete_remove(struct platform_device *pdev);
  2601. +int skl_int3472_tps68470_probe(struct i2c_client *client);
  2602. +int skl_int3472_get_cldb_buffer(struct acpi_device *adev,
  2603. + struct int3472_cldb *cldb);
  2604. diff --git a/drivers/platform/x86/intel_skl_int3472_discrete.c b/drivers/platform/x86/intel_skl_int3472_discrete.c
  2605. new file mode 100644
  2606. index 000000000000..ea7e57f3e3f0
  2607. --- /dev/null
  2608. +++ b/drivers/platform/x86/intel_skl_int3472_discrete.c
  2609. @@ -0,0 +1,489 @@
  2610. +// SPDX-License-Identifier: GPL-2.0
  2611. +/* Author: Dan Scally <djrscally@gmail.com> */
  2612. +
  2613. +#include <linux/acpi.h>
  2614. +#include <linux/clkdev.h>
  2615. +#include <linux/gpio/consumer.h>
  2616. +#include <linux/i2c.h>
  2617. +#include <linux/kernel.h>
  2618. +#include <linux/module.h>
  2619. +#include <linux/platform_device.h>
  2620. +#include <linux/regulator/driver.h>
  2621. +
  2622. +#include "intel_skl_int3472_common.h"
  2623. +
  2624. +/* 79234640-9e10-4fea-a5c1b5aa8b19756f */
  2625. +static const guid_t int3472_gpio_guid =
  2626. + GUID_INIT(0x79234640, 0x9e10, 0x4fea,
  2627. + 0xa5, 0xc1, 0xb5, 0xaa, 0x8b, 0x19, 0x75, 0x6f);
  2628. +
  2629. +/* 822ace8f-2814-4174-a56b5f029fe079ee */
  2630. +static const guid_t cio2_sensor_module_guid =
  2631. + GUID_INIT(0x822ace8f, 0x2814, 0x4174,
  2632. + 0xa5, 0x6b, 0x5f, 0x02, 0x9f, 0xe0, 0x79, 0xee);
  2633. +
  2634. +/*
  2635. + * Here follows platform specific mapping information that we can pass to
  2636. + * the functions mapping resources to the sensors. Where the sensors have
  2637. + * a power enable pin defined in DSDT we need to provide a supply name so
  2638. + * the sensor drivers can find the regulator. Optionally, we can provide a
  2639. + * NULL terminated array of function name mappings to deal with any platform
  2640. + * specific deviations from the documented behaviour of GPIOs.
  2641. + *
  2642. + * Map a GPIO function name to NULL to prevent the driver from mapping that
  2643. + * GPIO at all.
  2644. + */
  2645. +
  2646. +static const struct int3472_gpio_function_remap ov2680_gpio_function_remaps[] = {
  2647. + INT3472_GPIO_FUNCTION_REMAP("reset", NULL),
  2648. + INT3472_GPIO_FUNCTION_REMAP("powerdown", "reset"),
  2649. + { }
  2650. +};
  2651. +
  2652. +static struct int3472_sensor_config int3472_sensor_configs[] = {
  2653. + /* Lenovo Miix 510-12ISK - OV2680, Front */
  2654. + { "GNDF140809R", { 0 }, ov2680_gpio_function_remaps},
  2655. + /* Lenovo Miix 510-12ISK - OV5648, Rear */
  2656. + { "GEFF150023R", REGULATOR_SUPPLY("avdd", "i2c-OVTI5648:00"), NULL},
  2657. + /* Surface Go 1&2 - OV5693, Front */
  2658. + { "YHCU", REGULATOR_SUPPLY("avdd", "i2c-INT33BE:00"), NULL},
  2659. +};
  2660. +
  2661. +/*
  2662. + * The regulators have to have .ops to be valid, but the only ops we actually
  2663. + * support are .enable and .disable which are handled via .ena_gpiod. Pass an
  2664. + * empty struct to clear the check without lying about capabilities.
  2665. + */
  2666. +static const struct regulator_ops int3472_gpio_regulator_ops = { 0 };
  2667. +
  2668. +static int skl_int3472_clk_enable(struct clk_hw *hw)
  2669. +{
  2670. + struct int3472_gpio_clock *clk = to_int3472_clk(hw);
  2671. +
  2672. + gpiod_set_value(clk->gpio, 1);
  2673. +
  2674. + return 0;
  2675. +}
  2676. +
  2677. +static void skl_int3472_clk_disable(struct clk_hw *hw)
  2678. +{
  2679. + struct int3472_gpio_clock *clk = to_int3472_clk(hw);
  2680. +
  2681. + gpiod_set_value(clk->gpio, 0);
  2682. +}
  2683. +
  2684. +static int skl_int3472_clk_prepare(struct clk_hw *hw)
  2685. +{
  2686. + /*
  2687. + * We're just turning a GPIO on to enable, so nothing to do here, but
  2688. + * we want to provide the op so prepare_enable() works.
  2689. + */
  2690. + return 0;
  2691. +}
  2692. +
  2693. +static void skl_int3472_clk_unprepare(struct clk_hw *hw)
  2694. +{
  2695. + /* Likewise, nothing to do here... */
  2696. +}
  2697. +
  2698. +static const struct clk_ops skl_int3472_clock_ops = {
  2699. + .prepare = skl_int3472_clk_prepare,
  2700. + .unprepare = skl_int3472_clk_unprepare,
  2701. + .enable = skl_int3472_clk_enable,
  2702. + .disable = skl_int3472_clk_disable,
  2703. +};
  2704. +
  2705. +static struct int3472_sensor_config *
  2706. +int3472_get_sensor_module_config(struct int3472_device *int3472)
  2707. +{
  2708. + unsigned int i = ARRAY_SIZE(int3472_sensor_configs);
  2709. + struct int3472_sensor_config *ret;
  2710. + union acpi_object *obj;
  2711. +
  2712. + obj = acpi_evaluate_dsm_typed(int3472->sensor->handle,
  2713. + &cio2_sensor_module_guid, 0x00,
  2714. + 0x01, NULL, ACPI_TYPE_STRING);
  2715. +
  2716. + if (!obj) {
  2717. + dev_err(&int3472->pdev->dev,
  2718. + "Failed to get sensor module string from _DSM\n");
  2719. + return ERR_PTR(-ENODEV);
  2720. + }
  2721. +
  2722. + if (obj->string.type != ACPI_TYPE_STRING) {
  2723. + dev_err(&int3472->pdev->dev,
  2724. + "Sensor _DSM returned a non-string value\n");
  2725. + ret = ERR_PTR(-EINVAL);
  2726. + goto out_free_obj;
  2727. + }
  2728. +
  2729. + ret = ERR_PTR(-ENODEV);
  2730. + while (i--) {
  2731. + if (!strcmp(int3472_sensor_configs[i].sensor_module_name,
  2732. + obj->string.pointer)) {
  2733. + ret = &int3472_sensor_configs[i];
  2734. + goto out_free_obj;
  2735. + }
  2736. + }
  2737. +
  2738. +out_free_obj:
  2739. + ACPI_FREE(obj);
  2740. + return ret;
  2741. +}
  2742. +
  2743. +static int int3472_map_gpio_to_sensor(struct int3472_device *int3472,
  2744. + struct acpi_resource *ares,
  2745. + char *func, u32 polarity)
  2746. +{
  2747. + char *path = ares->data.gpio.resource_source.string_ptr;
  2748. + struct int3472_sensor_config *sensor_config;
  2749. + struct gpiod_lookup table_entry;
  2750. + struct acpi_device *adev;
  2751. + acpi_handle handle;
  2752. + acpi_status status;
  2753. + int ret;
  2754. +
  2755. + sensor_config = int3472_get_sensor_module_config(int3472);
  2756. + if (!IS_ERR(sensor_config) && sensor_config->function_maps) {
  2757. + unsigned int i = 0;
  2758. +
  2759. + while (sensor_config->function_maps[i].documented) {
  2760. + if (!strcmp(func, sensor_config->function_maps[i].documented)) {
  2761. + func = sensor_config->function_maps[i].actual;
  2762. +
  2763. + break;
  2764. + }
  2765. +
  2766. + i++;
  2767. + }
  2768. + }
  2769. +
  2770. + if (!func)
  2771. + return 0;
  2772. +
  2773. + if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) {
  2774. + dev_warn(&int3472->pdev->dev, "Too many GPIOs mapped\n");
  2775. + return -EINVAL;
  2776. + }
  2777. +
  2778. + status = acpi_get_handle(NULL, path, &handle);
  2779. + if (ACPI_FAILURE(status))
  2780. + return -EINVAL;
  2781. +
  2782. + ret = acpi_bus_get_device(handle, &adev);
  2783. + if (ret)
  2784. + return -ENODEV;
  2785. +
  2786. + table_entry = (struct gpiod_lookup)GPIO_LOOKUP_IDX(acpi_dev_name(adev),
  2787. + ares->data.gpio.pin_table[0],
  2788. + func, 0, polarity);
  2789. +
  2790. + memcpy(&int3472->gpios.table[int3472->n_sensor_gpios], &table_entry,
  2791. + sizeof(table_entry));
  2792. +
  2793. + int3472->n_sensor_gpios++;
  2794. +
  2795. + return 0;
  2796. +}
  2797. +
  2798. +static int int3472_register_clock(struct int3472_device *int3472,
  2799. + struct acpi_resource *ares)
  2800. +{
  2801. + char *path = ares->data.gpio.resource_source.string_ptr;
  2802. + struct clk_init_data init = { };
  2803. + int ret = 0;
  2804. +
  2805. + init.name = kasprintf(GFP_KERNEL, "%s-clk", acpi_dev_name(int3472->adev));
  2806. + init.ops = &skl_int3472_clock_ops;
  2807. +
  2808. + int3472->clock.gpio = acpi_get_gpiod(path, ares->data.gpio.pin_table[0]);
  2809. + if (IS_ERR(int3472->clock.gpio)) {
  2810. + ret = PTR_ERR(int3472->clock.gpio);
  2811. + goto out_free_init_name;
  2812. + }
  2813. +
  2814. + int3472->clock.clk_hw.init = &init;
  2815. + int3472->clock.clk = clk_register(&int3472->adev->dev,
  2816. + &int3472->clock.clk_hw);
  2817. + if (IS_ERR(int3472->clock.clk)) {
  2818. + ret = PTR_ERR(int3472->clock.clk);
  2819. + goto err_put_gpio;
  2820. + }
  2821. +
  2822. + ret = clk_register_clkdev(int3472->clock.clk, "xvclk", int3472->sensor_name);
  2823. + if (ret)
  2824. + goto err_unregister_clk;
  2825. +
  2826. + goto out_free_init_name;
  2827. +
  2828. +err_unregister_clk:
  2829. + clk_unregister(int3472->clock.clk);
  2830. +err_put_gpio:
  2831. + gpiod_put(int3472->clock.gpio);
  2832. +out_free_init_name:
  2833. + kfree(init.name);
  2834. +
  2835. + return ret;
  2836. +}
  2837. +
  2838. +static int int3472_register_regulator(struct int3472_device *int3472,
  2839. + struct acpi_resource *ares)
  2840. +{
  2841. + char *path = ares->data.gpio.resource_source.string_ptr;
  2842. + struct int3472_sensor_config *sensor_config;
  2843. + struct regulator_init_data init_data = { };
  2844. + struct int3472_gpio_regulator *regulator;
  2845. + struct regulator_config cfg = { };
  2846. + int ret;
  2847. +
  2848. + sensor_config = int3472_get_sensor_module_config(int3472);
  2849. + if (IS_ERR_OR_NULL(sensor_config)) {
  2850. + dev_err(&int3472->pdev->dev, "No sensor module config\n");
  2851. + return PTR_ERR(sensor_config);
  2852. + }
  2853. +
  2854. + if (!sensor_config->supply_map.supply) {
  2855. + dev_err(&int3472->pdev->dev, "No supply name defined\n");
  2856. + return -ENODEV;
  2857. + }
  2858. +
  2859. + init_data.supply_regulator = NULL;
  2860. + init_data.constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS;
  2861. + init_data.num_consumer_supplies = 1;
  2862. + init_data.consumer_supplies = &sensor_config->supply_map;
  2863. +
  2864. + snprintf(int3472->regulator.regulator_name, GPIO_REGULATOR_NAME_LENGTH,
  2865. + "int3472-discrete-regulator");
  2866. + snprintf(int3472->regulator.supply_name, GPIO_REGULATOR_SUPPLY_NAME_LENGTH,
  2867. + "supply-0");
  2868. +
  2869. + int3472->regulator.rdesc = INT3472_REGULATOR(int3472->regulator.regulator_name,
  2870. + int3472->regulator.supply_name,
  2871. + &int3472_gpio_regulator_ops);
  2872. +
  2873. + int3472->regulator.gpio = acpi_get_gpiod(path, ares->data.gpio.pin_table[0]);
  2874. + if (IS_ERR(int3472->regulator.gpio)) {
  2875. + ret = PTR_ERR(int3472->regulator.gpio);
  2876. + goto err_free_regulator;
  2877. + }
  2878. +
  2879. + cfg.dev = &int3472->adev->dev;
  2880. + cfg.init_data = &init_data;
  2881. + cfg.ena_gpiod = int3472->regulator.gpio;
  2882. +
  2883. + int3472->regulator.rdev = regulator_register(&int3472->regulator.rdesc, &cfg);
  2884. + if (IS_ERR(int3472->regulator.rdev)) {
  2885. + ret = PTR_ERR(int3472->regulator.rdev);
  2886. + goto err_free_gpio;
  2887. + }
  2888. +
  2889. + return 0;
  2890. +
  2891. +err_free_gpio:
  2892. + gpiod_put(regulator->gpio);
  2893. +err_free_regulator:
  2894. + kfree(regulator);
  2895. +
  2896. + return ret;
  2897. +}
  2898. +
  2899. +/**
  2900. + * int3472_handle_gpio_resources: maps PMIC resources to consuming sensor
  2901. + * @ares: A pointer to a &struct acpi_resource
  2902. + * @data: A pointer to a &struct int3472_device
  2903. + *
  2904. + * This function handles GPIO resources that are against an INT3472
  2905. + * ACPI device, by checking the value of the corresponding _DSM entry.
  2906. + * This will return a 32bit int, where the lowest byte represents the
  2907. + * function of the GPIO pin:
  2908. + *
  2909. + * 0x00 Reset
  2910. + * 0x01 Power down
  2911. + * 0x0b Power enable
  2912. + * 0x0c Clock enable
  2913. + * 0x0d Privacy LED
  2914. + *
  2915. + * There are some known platform specific quirks where that does not quite
  2916. + * hold up; for example where a pin with type 0x01 (Power down) is mapped to
  2917. + * a sensor pin that performs a reset function. These will be handled by the
  2918. + * mapping sub-functions.
  2919. + *
  2920. + * GPIOs will either be mapped directly to the sensor device or else used
  2921. + * to create clocks and regulators via the usual frameworks.
  2922. + *
  2923. + * Return:
  2924. + * * 0 - When all resources found are handled properly.
  2925. + * * -EINVAL - If the resource is not a GPIO IO resource
  2926. + * * -ENODEV - If the resource has no corresponding _DSM entry
  2927. + * * -Other - Errors propagated from one of the sub-functions.
  2928. + */
  2929. +static int int3472_handle_gpio_resources(struct acpi_resource *ares,
  2930. + void *data)
  2931. +{
  2932. + struct int3472_device *int3472 = data;
  2933. + union acpi_object *obj;
  2934. + int ret = 0;
  2935. +
  2936. + if (ares->type != ACPI_RESOURCE_TYPE_GPIO ||
  2937. + ares->data.gpio.connection_type != ACPI_RESOURCE_GPIO_TYPE_IO)
  2938. + return EINVAL; /* Deliberately positive so parsing continues */
  2939. +
  2940. + /*
  2941. + * n_gpios + 2 because the index of this _DSM function is 1-based and
  2942. + * the first function is just a count.
  2943. + */
  2944. + obj = acpi_evaluate_dsm_typed(int3472->adev->handle,
  2945. + &int3472_gpio_guid, 0x00,
  2946. + int3472->n_gpios + 2,
  2947. + NULL, ACPI_TYPE_INTEGER);
  2948. +
  2949. + if (!obj) {
  2950. + dev_warn(&int3472->pdev->dev,
  2951. + "No _DSM entry for this GPIO pin\n");
  2952. + return ENODEV;
  2953. + }
  2954. +
  2955. + switch (obj->integer.value & 0xff) {
  2956. + case INT3472_GPIO_TYPE_RESET:
  2957. + ret = int3472_map_gpio_to_sensor(int3472, ares, "reset",
  2958. + GPIO_ACTIVE_LOW);
  2959. + if (ret)
  2960. + dev_err(&int3472->pdev->dev,
  2961. + "Failed to map reset pin to sensor\n");
  2962. +
  2963. + break;
  2964. + case INT3472_GPIO_TYPE_POWERDOWN:
  2965. + ret = int3472_map_gpio_to_sensor(int3472, ares, "powerdown",
  2966. + GPIO_ACTIVE_LOW);
  2967. + if (ret)
  2968. + dev_err(&int3472->pdev->dev,
  2969. + "Failed to map powerdown pin to sensor\n");
  2970. +
  2971. + break;
  2972. + case INT3472_GPIO_TYPE_CLK_ENABLE:
  2973. + ret = int3472_register_clock(int3472, ares);
  2974. + if (ret)
  2975. + dev_err(&int3472->pdev->dev,
  2976. + "Failed to map clock to sensor\n");
  2977. +
  2978. + break;
  2979. + case INT3472_GPIO_TYPE_POWER_ENABLE:
  2980. + ret = int3472_register_regulator(int3472, ares);
  2981. + if (ret) {
  2982. + dev_err(&int3472->pdev->dev,
  2983. + "Failed to map regulator to sensor\n");
  2984. + }
  2985. +
  2986. + break;
  2987. + case INT3472_GPIO_TYPE_PRIVACY_LED:
  2988. + ret = int3472_map_gpio_to_sensor(int3472, ares, "indicator-led",
  2989. + GPIO_ACTIVE_HIGH);
  2990. + if (ret)
  2991. + dev_err(&int3472->pdev->dev,
  2992. + "Failed to map indicator led to sensor\n");
  2993. +
  2994. + break;
  2995. + default:
  2996. + dev_warn(&int3472->pdev->dev,
  2997. + "GPIO type 0x%llx unknown; the sensor may not work\n",
  2998. + (obj->integer.value & 0xff));
  2999. + ret = EINVAL;
  3000. + }
  3001. +
  3002. + int3472->n_gpios++;
  3003. + ACPI_FREE(obj);
  3004. +
  3005. + return ret;
  3006. +}
  3007. +
  3008. +static int int3472_parse_crs(struct int3472_device *int3472)
  3009. +{
  3010. + struct list_head resource_list;
  3011. + int ret = 0;
  3012. +
  3013. + INIT_LIST_HEAD(&resource_list);
  3014. +
  3015. + ret = acpi_dev_get_resources(int3472->adev, &resource_list,
  3016. + int3472_handle_gpio_resources, int3472);
  3017. +
  3018. + if (!ret) {
  3019. + gpiod_add_lookup_table(&int3472->gpios);
  3020. + int3472->gpios_mapped = true;
  3021. + }
  3022. +
  3023. + acpi_dev_free_resource_list(&resource_list);
  3024. +
  3025. + return ret;
  3026. +}
  3027. +
  3028. +int skl_int3472_discrete_probe(struct platform_device *pdev)
  3029. +{
  3030. + struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
  3031. + struct int3472_device *int3472;
  3032. + struct int3472_cldb cldb;
  3033. + int ret = 0;
  3034. +
  3035. + ret = skl_int3472_get_cldb_buffer(adev, &cldb);
  3036. + if (ret || cldb.control_logic_type != 1)
  3037. + return -EINVAL;
  3038. +
  3039. + int3472 = kzalloc(sizeof(*int3472) +
  3040. + ((INT3472_MAX_SENSOR_GPIOS + 1) * sizeof(struct gpiod_lookup)),
  3041. + GFP_KERNEL);
  3042. + if (!int3472)
  3043. + return -ENOMEM;
  3044. +
  3045. + int3472->adev = adev;
  3046. + int3472->pdev = pdev;
  3047. + platform_set_drvdata(pdev, int3472);
  3048. +
  3049. + int3472->sensor = acpi_dev_get_next_dep_dev(adev, NULL);
  3050. + if (!int3472->sensor) {
  3051. + dev_err(&pdev->dev,
  3052. + "This INT3472 entry seems to have no dependents.\n");
  3053. + ret = -ENODEV;
  3054. + goto err_free_int3472;
  3055. + }
  3056. + int3472->sensor_name = i2c_acpi_dev_name(int3472->sensor);
  3057. + int3472->gpios.dev_id = int3472->sensor_name;
  3058. +
  3059. + ret = int3472_parse_crs(int3472);
  3060. + if (ret) {
  3061. + skl_int3472_discrete_remove(pdev);
  3062. + goto err_return_ret;
  3063. + }
  3064. +
  3065. + return 0;
  3066. +
  3067. +err_free_int3472:
  3068. + kfree(int3472);
  3069. +err_return_ret:
  3070. + return ret;
  3071. +}
  3072. +
  3073. +int skl_int3472_discrete_remove(struct platform_device *pdev)
  3074. +{
  3075. + struct int3472_device *int3472;
  3076. +
  3077. + int3472 = platform_get_drvdata(pdev);
  3078. +
  3079. + if (int3472->gpios_mapped)
  3080. + gpiod_remove_lookup_table(&int3472->gpios);
  3081. +
  3082. + if (!IS_ERR_OR_NULL(int3472->regulator.rdev)) {
  3083. + gpiod_put(int3472->regulator.gpio);
  3084. + regulator_unregister(int3472->regulator.rdev);
  3085. + }
  3086. +
  3087. + if (!IS_ERR_OR_NULL(int3472->clock.clk)) {
  3088. + gpiod_put(int3472->clock.gpio);
  3089. + clk_unregister(int3472->clock.clk);
  3090. + }
  3091. +
  3092. + acpi_dev_put(int3472->sensor);
  3093. +
  3094. + kfree(int3472->sensor_name);
  3095. + kfree(int3472);
  3096. +
  3097. + return 0;
  3098. +}
  3099. diff --git a/drivers/platform/x86/intel_skl_int3472_tps68470.c b/drivers/platform/x86/intel_skl_int3472_tps68470.c
  3100. new file mode 100644
  3101. index 000000000000..3fe27ec0caff
  3102. --- /dev/null
  3103. +++ b/drivers/platform/x86/intel_skl_int3472_tps68470.c
  3104. @@ -0,0 +1,145 @@
  3105. +// SPDX-License-Identifier: GPL-2.0
  3106. +/* Author: Dan Scally <djrscally@gmail.com> */
  3107. +
  3108. +#include <linux/i2c.h>
  3109. +#include <linux/mfd/tps68470.h>
  3110. +#include <linux/platform_device.h>
  3111. +#include <linux/regmap.h>
  3112. +
  3113. +#include "intel_skl_int3472_common.h"
  3114. +
  3115. +static const struct regmap_config tps68470_regmap_config = {
  3116. + .reg_bits = 8,
  3117. + .val_bits = 8,
  3118. + .max_register = TPS68470_REG_MAX,
  3119. +};
  3120. +
  3121. +static int tps68470_chip_init(struct device *dev, struct regmap *regmap)
  3122. +{
  3123. + unsigned int version;
  3124. + int ret;
  3125. +
  3126. + /* Force software reset */
  3127. + ret = regmap_write(regmap, TPS68470_REG_RESET, TPS68470_REG_RESET_MASK);
  3128. + if (ret)
  3129. + return ret;
  3130. +
  3131. + ret = regmap_read(regmap, TPS68470_REG_REVID, &version);
  3132. + if (ret) {
  3133. + dev_err(dev, "Failed to read revision register: %d\n", ret);
  3134. + return ret;
  3135. + }
  3136. +
  3137. + dev_info(dev, "TPS68470 REVID: 0x%x\n", version);
  3138. +
  3139. + return 0;
  3140. +}
  3141. +
  3142. +static struct platform_device *
  3143. +skl_int3472_register_pdev(const char *name, struct device *parent)
  3144. +{
  3145. + struct platform_device *pdev;
  3146. + int ret;
  3147. +
  3148. + pdev = platform_device_alloc(name, PLATFORM_DEVID_NONE);
  3149. + if (IS_ERR_OR_NULL(pdev))
  3150. + return ERR_PTR(-ENOMEM);
  3151. +
  3152. + pdev->dev.parent = parent;
  3153. + pdev->driver_override = kstrndup(pdev->name, INT3472_PDEV_MAX_NAME_LEN,
  3154. + GFP_KERNEL);
  3155. +
  3156. + ret = platform_device_add(pdev);
  3157. + if (ret) {
  3158. + platform_device_put(pdev);
  3159. + return ERR_PTR(ret);
  3160. + }
  3161. +
  3162. + return pdev;
  3163. +}
  3164. +
  3165. +int skl_int3472_tps68470_probe(struct i2c_client *client)
  3166. +{
  3167. + struct acpi_device *adev = ACPI_COMPANION(&client->dev);
  3168. + struct platform_device *regulator_dev;
  3169. + struct platform_device *opregion_dev;
  3170. + struct platform_device *gpio_dev;
  3171. + struct int3472_cldb cldb = { 0 };
  3172. + struct platform_device *clk_dev;
  3173. + bool cldb_present = true;
  3174. + struct regmap *regmap;
  3175. + int ret = 0;
  3176. +
  3177. + regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
  3178. + if (IS_ERR(regmap)) {
  3179. + dev_err(&client->dev, "devm_regmap_init_i2c Error %ld\n",
  3180. + PTR_ERR(regmap));
  3181. + return PTR_ERR(regmap);
  3182. + }
  3183. +
  3184. + i2c_set_clientdata(client, regmap);
  3185. +
  3186. + ret = tps68470_chip_init(&client->dev, regmap);
  3187. + if (ret < 0) {
  3188. + dev_err(&client->dev, "TPS68470 Init Error %d\n", ret);
  3189. + return ret;
  3190. + }
  3191. +
  3192. + /*
  3193. + * Check CLDB buffer against the PMIC's adev. If present, then we check
  3194. + * the value of control_logic_type field and follow one of the following
  3195. + * scenarios:
  3196. + *
  3197. + * 1. No CLDB - likely ACPI tables designed for ChromeOS. We create
  3198. + * platform devices for the GPIOs and OpRegion drivers.
  3199. + *
  3200. + * 2. CLDB, with control_logic_type = 2 - probably ACPI tables made
  3201. + * for Windows 2-in-1 platforms. Register pdevs for GPIO, Clock and
  3202. + * Regulator drivers to bind to.
  3203. + *
  3204. + * 3. Any other value in control_logic_type, we should never have
  3205. + * gotten to this point; crash and burn.
  3206. + */
  3207. + ret = skl_int3472_get_cldb_buffer(adev, &cldb);
  3208. + if (!ret && cldb.control_logic_type != 2)
  3209. + return -EINVAL;
  3210. +
  3211. + if (ret)
  3212. + cldb_present = false;
  3213. +
  3214. + gpio_dev = skl_int3472_register_pdev("tps68470-gpio", &client->dev);
  3215. + if (IS_ERR(gpio_dev))
  3216. + return PTR_ERR(gpio_dev);
  3217. +
  3218. + if (cldb_present) {
  3219. + clk_dev = skl_int3472_register_pdev("tps68470-clk",
  3220. + &client->dev);
  3221. + if (IS_ERR(clk_dev)) {
  3222. + ret = PTR_ERR(clk_dev);
  3223. + goto err_free_gpio;
  3224. + }
  3225. +
  3226. + regulator_dev = skl_int3472_register_pdev("tps68470-regulator",
  3227. + &client->dev);
  3228. + if (IS_ERR(regulator_dev)) {
  3229. + ret = PTR_ERR(regulator_dev);
  3230. + goto err_free_clk;
  3231. + }
  3232. + } else {
  3233. + opregion_dev = skl_int3472_register_pdev("tps68470_pmic_opregion",
  3234. + &client->dev);
  3235. + if (IS_ERR(opregion_dev)) {
  3236. + ret = PTR_ERR(opregion_dev);
  3237. + goto err_free_gpio;
  3238. + }
  3239. + }
  3240. +
  3241. + return 0;
  3242. +
  3243. +err_free_clk:
  3244. + platform_device_put(clk_dev);
  3245. +err_free_gpio:
  3246. + platform_device_put(gpio_dev);
  3247. +
  3248. + return ret;
  3249. +}
  3250. --
  3251. 2.33.0
  3252. From dc854a10270465727e4ec5e9c25a2c88b55539b2 Mon Sep 17 00:00:00 2001
  3253. From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
  3254. Date: Fri, 11 Dec 2020 21:17:35 +0100
  3255. Subject: [PATCH] PCI: ACPI: Fix up ACPI companion lookup for device 0 on the
  3256. root bus
  3257. In some cases acpi_pci_find_companion() returns an incorrect device
  3258. object as the ACPI companion for device 0 on the root bus (bus 0).
  3259. On the affected systems that device is the PCI interface to the
  3260. host bridge and the "ACPI companion" returned for it corresponds
  3261. to a non-PCI device located in the SoC (e.g. a sensor on an I2C
  3262. bus). As a result of this, the ACPI device object "attached"
  3263. to PCI device 00:00.0 cannot be used for enumerating the device
  3264. that is really represented by it which (of course) is problematic.
  3265. Address that issue by preventing acpi_pci_find_companion() from
  3266. returning a device object with a valid _HID (which by the spec
  3267. should not be present uder ACPI device objects corresponding to
  3268. PCI devices) for PCI device 00:00.0.
  3269. Link: https://lore.kernel.org/linux-acpi/1409ba0c-1580-dc09-e6fe-a0c9bcda6462@gmail.com/
  3270. Reported-by: Daniel Scally <djrscally@gmail.com>
  3271. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  3272. Patchset: cameras
  3273. ---
  3274. drivers/pci/pci-acpi.c | 20 +++++++++++++++++++-
  3275. 1 file changed, 19 insertions(+), 1 deletion(-)
  3276. diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
  3277. index 745a4e0c4994..87e45a800919 100644
  3278. --- a/drivers/pci/pci-acpi.c
  3279. +++ b/drivers/pci/pci-acpi.c
  3280. @@ -1162,14 +1162,32 @@ void acpi_pci_remove_bus(struct pci_bus *bus)
  3281. static struct acpi_device *acpi_pci_find_companion(struct device *dev)
  3282. {
  3283. struct pci_dev *pci_dev = to_pci_dev(dev);
  3284. + struct acpi_device *adev;
  3285. bool check_children;
  3286. u64 addr;
  3287. check_children = pci_is_bridge(pci_dev);
  3288. /* Please ref to ACPI spec for the syntax of _ADR */
  3289. addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
  3290. - return acpi_find_child_device(ACPI_COMPANION(dev->parent), addr,
  3291. + adev = acpi_find_child_device(ACPI_COMPANION(dev->parent), addr,
  3292. check_children);
  3293. + /*
  3294. + * There may be ACPI device objects in the ACPI namespace that are
  3295. + * children of the device object representing the host bridge, but don't
  3296. + * represent PCI devices. Both _HID and _ADR may be present for them,
  3297. + * even though that is against the specification (for example, see
  3298. + * Section 6.1 of ACPI 6.3), but in many cases the _ADR returns 0 which
  3299. + * appears to indicate that they should not be taken into consideration
  3300. + * as potential companions of PCI devices on the root bus.
  3301. + *
  3302. + * To catch this special case, disregard the returned device object if
  3303. + * it has a valid _HID, addr is 0 and the PCI device at hand is on the
  3304. + * root bus.
  3305. + */
  3306. + if (adev && adev->pnp.type.platform_id && !addr && !pci_dev->bus->parent)
  3307. + return NULL;
  3308. +
  3309. + return adev;
  3310. }
  3311. /**
  3312. --
  3313. 2.33.0
  3314. From 1e350fd1a4d00b6b9fd895b017daece0db39380a Mon Sep 17 00:00:00 2001
  3315. From: Jake Day <jake@ninebysix.com>
  3316. Date: Fri, 25 Sep 2020 10:24:53 -0400
  3317. Subject: [PATCH] media: i2c: Add support for the OV5693 image sensor
  3318. The OV5693 is a 5 Mpx CMOS image sensor, connected via MIPI CSI-2
  3319. in a one or two lane configuration.
  3320. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@gmail.com>
  3321. Patchset: cameras
  3322. ---
  3323. drivers/media/i2c/Kconfig | 11 +
  3324. drivers/media/i2c/Makefile | 1 +
  3325. drivers/media/i2c/ad5823.h | 63 ++
  3326. drivers/media/i2c/ov5693.c | 1788 ++++++++++++++++++++++++++++++++++++
  3327. drivers/media/i2c/ov5693.h | 1430 ++++++++++++++++++++++++++++
  3328. 5 files changed, 3293 insertions(+)
  3329. create mode 100644 drivers/media/i2c/ad5823.h
  3330. create mode 100644 drivers/media/i2c/ov5693.c
  3331. create mode 100644 drivers/media/i2c/ov5693.h
  3332. diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
  3333. index 878f66ef2719..10bbc85d0aba 100644
  3334. --- a/drivers/media/i2c/Kconfig
  3335. +++ b/drivers/media/i2c/Kconfig
  3336. @@ -958,6 +958,17 @@ config VIDEO_OV5675
  3337. To compile this driver as a module, choose M here: the
  3338. module will be called ov5675.
  3339. +config VIDEO_OV5693
  3340. + tristate "OmniVision OV5693 sensor support"
  3341. + depends on I2C && VIDEO_V4L2
  3342. + select V4L2_FWNODE
  3343. + help
  3344. + This is a Video4Linux2 sensor driver for the OmniVision
  3345. + OV5693 camera.
  3346. +
  3347. + To compile this driver as a module, choose M here: the
  3348. + module will be called ov5693.
  3349. +
  3350. config VIDEO_OV5695
  3351. tristate "OmniVision OV5695 sensor support"
  3352. depends on I2C && VIDEO_V4L2
  3353. diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
  3354. index f0a77473979d..2bc1dd3e791b 100644
  3355. --- a/drivers/media/i2c/Makefile
  3356. +++ b/drivers/media/i2c/Makefile
  3357. @@ -73,6 +73,7 @@ obj-$(CONFIG_VIDEO_OV5645) += ov5645.o
  3358. obj-$(CONFIG_VIDEO_OV5647) += ov5647.o
  3359. obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
  3360. obj-$(CONFIG_VIDEO_OV5675) += ov5675.o
  3361. +obj-$(CONFIG_VIDEO_OV5693) += ov5693.o
  3362. obj-$(CONFIG_VIDEO_OV5695) += ov5695.o
  3363. obj-$(CONFIG_VIDEO_OV6650) += ov6650.o
  3364. obj-$(CONFIG_VIDEO_OV7251) += ov7251.o
  3365. diff --git a/drivers/media/i2c/ad5823.h b/drivers/media/i2c/ad5823.h
  3366. new file mode 100644
  3367. index 000000000000..f1362cd69f6e
  3368. --- /dev/null
  3369. +++ b/drivers/media/i2c/ad5823.h
  3370. @@ -0,0 +1,63 @@
  3371. +/* SPDX-License-Identifier: GPL-2.0 */
  3372. +/*
  3373. + * Support for AD5823 VCM.
  3374. + *
  3375. + * Copyright (c) 2013 Intel Corporation. All Rights Reserved.
  3376. + *
  3377. + * This program is free software; you can redistribute it and/or
  3378. + * modify it under the terms of the GNU General Public License version
  3379. + * 2 as published by the Free Software Foundation.
  3380. + *
  3381. + * This program is distributed in the hope that it will be useful,
  3382. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3383. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3384. + * GNU General Public License for more details.
  3385. + *
  3386. + *
  3387. + */
  3388. +
  3389. +#ifndef __AD5823_H__
  3390. +#define __AD5823_H__
  3391. +
  3392. +#include <linux/types.h>
  3393. +
  3394. +#define AD5823_VCM_ADDR 0x0c
  3395. +
  3396. +#define AD5823_REG_RESET 0x01
  3397. +#define AD5823_REG_MODE 0x02
  3398. +#define AD5823_REG_VCM_MOVE_TIME 0x03
  3399. +#define AD5823_REG_VCM_CODE_MSB 0x04
  3400. +#define AD5823_REG_VCM_CODE_LSB 0x05
  3401. +#define AD5823_REG_VCM_THRESHOLD_MSB 0x06
  3402. +#define AD5823_REG_VCM_THRESHOLD_LSB 0x07
  3403. +
  3404. +#define AD5823_REG_LENGTH 0x1
  3405. +
  3406. +#define AD5823_RING_CTRL_ENABLE 0x04
  3407. +#define AD5823_RING_CTRL_DISABLE 0x00
  3408. +
  3409. +#define AD5823_RESONANCE_PERIOD 100000
  3410. +#define AD5823_RESONANCE_COEF 512
  3411. +#define AD5823_HIGH_FREQ_RANGE 0x80
  3412. +
  3413. +#define VCM_CODE_MSB_MASK 0xfc
  3414. +#define AD5823_INIT_FOCUS_POS 350
  3415. +
  3416. +enum ad5823_tok_type {
  3417. + AD5823_8BIT = 0x1,
  3418. + AD5823_16BIT = 0x2,
  3419. +};
  3420. +
  3421. +enum ad5823_vcm_mode {
  3422. + AD5823_ARC_RES0 = 0x0, /* Actuator response control RES1 */
  3423. + AD5823_ARC_RES1 = 0x1, /* Actuator response control RES0.5 */
  3424. + AD5823_ARC_RES2 = 0x2, /* Actuator response control RES2 */
  3425. + AD5823_ESRC = 0x3, /* Enhanced slew rate control */
  3426. + AD5823_DIRECT = 0x4, /* Direct control */
  3427. +};
  3428. +
  3429. +#define AD5823_INVALID_CONFIG 0xffffffff
  3430. +#define AD5823_MAX_FOCUS_POS 1023
  3431. +#define DELAY_PER_STEP_NS 1000000
  3432. +#define DELAY_MAX_PER_STEP_NS (1000000 * 1023)
  3433. +#endif
  3434. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  3435. new file mode 100644
  3436. index 000000000000..32485e4ed42b
  3437. --- /dev/null
  3438. +++ b/drivers/media/i2c/ov5693.c
  3439. @@ -0,0 +1,1788 @@
  3440. +// SPDX-License-Identifier: GPL-2.0
  3441. +/*
  3442. + * Support for OmniVision OV5693 1080p HD camera sensor.
  3443. + *
  3444. + * Copyright (c) 2013 Intel Corporation. All Rights Reserved.
  3445. + *
  3446. + * This program is free software; you can redistribute it and/or
  3447. + * modify it under the terms of the GNU General Public License version
  3448. + * 2 as published by the Free Software Foundation.
  3449. + *
  3450. + * This program is distributed in the hope that it will be useful,
  3451. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3452. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3453. + * GNU General Public License for more details.
  3454. + *
  3455. + *
  3456. + */
  3457. +
  3458. +#include <linux/clk.h>
  3459. +#include <linux/module.h>
  3460. +#include <linux/types.h>
  3461. +#include <linux/kernel.h>
  3462. +#include <linux/mm.h>
  3463. +#include <linux/string.h>
  3464. +#include <linux/errno.h>
  3465. +#include <linux/init.h>
  3466. +#include <linux/kmod.h>
  3467. +#include <linux/device.h>
  3468. +#include <linux/delay.h>
  3469. +#include <linux/slab.h>
  3470. +#include <linux/i2c.h>
  3471. +#include <linux/moduleparam.h>
  3472. +#include <media/v4l2-device.h>
  3473. +#include <linux/io.h>
  3474. +#include <linux/acpi.h>
  3475. +#include <linux/regulator/consumer.h>
  3476. +
  3477. +#include "ov5693.h"
  3478. +#include "ad5823.h"
  3479. +
  3480. +#define __cci_delay(t) \
  3481. + do { \
  3482. + if ((t) < 10) { \
  3483. + usleep_range((t) * 1000, ((t) + 1) * 1000); \
  3484. + } else { \
  3485. + msleep((t)); \
  3486. + } \
  3487. + } while (0)
  3488. +
  3489. +/* Value 30ms reached through experimentation on byt ecs.
  3490. + * The DS specifies a much lower value but when using a smaller value
  3491. + * the I2C bus sometimes locks up permanently when starting the camera.
  3492. + * This issue could not be reproduced on cht, so we can reduce the
  3493. + * delay value to a lower value when insmod.
  3494. + */
  3495. +static uint up_delay = 30;
  3496. +module_param(up_delay, uint, 0644);
  3497. +MODULE_PARM_DESC(up_delay,
  3498. + "Delay prior to the first CCI transaction for ov5693");
  3499. +
  3500. +
  3501. +/* Exposure/gain */
  3502. +
  3503. +#define OV5693_EXPOSURE_CTRL_HH_REG 0x3500
  3504. +#define OV5693_EXPOSURE_CTRL_HH(v) (((v) & GENMASK(18, 16)) >> 16)
  3505. +#define OV5693_EXPOSURE_CTRL_H_REG 0x3501
  3506. +#define OV5693_EXPOSURE_CTRL_H(v) (((v) & GENMASK(15, 8)) >> 8)
  3507. +#define OV5693_EXPOSURE_CTRL_L_REG 0x3502
  3508. +#define OV5693_EXPOSURE_CTRL_L(v) ((v) & GENMASK(7, 0))
  3509. +#define OV5693_EXPOSURE_GAIN_MANUAL_REG 0x3509
  3510. +
  3511. +#define OV5693_GAIN_CTRL_H_REG 0x3504
  3512. +#define OV5693_GAIN_CTRL_H(v) (((v) & GENMASK(9, 8)) >> 8)
  3513. +#define OV5693_GAIN_CTRL_L_REG 0x3505
  3514. +#define OV5693_GAIN_CTRL_L(v) ((v) & GENMASK(7, 0))
  3515. +
  3516. +#define OV5693_FORMAT1_REG 0x3820
  3517. +#define OV5693_FORMAT1_FLIP_VERT_ISP_EN BIT(2)
  3518. +#define OV5693_FORMAT1_FLIP_VERT_SENSOR_EN BIT(1)
  3519. +#define OV5693_FORMAT2_REG 0x3821
  3520. +#define OV5693_FORMAT2_HSYNC_EN BIT(6)
  3521. +#define OV5693_FORMAT2_FST_VBIN_EN BIT(5)
  3522. +#define OV5693_FORMAT2_FST_HBIN_EN BIT(4)
  3523. +#define OV5693_FORMAT2_ISP_HORZ_VAR2_EN BIT(3)
  3524. +#define OV5693_FORMAT2_FLIP_HORZ_ISP_EN BIT(2)
  3525. +#define OV5693_FORMAT2_FLIP_HORZ_SENSOR_EN BIT(1)
  3526. +#define OV5693_FORMAT2_SYNC_HBIN_EN BIT(0)
  3527. +
  3528. +/* ISP */
  3529. +
  3530. +#define OV5693_ISP_CTRL0_REG 0x5000
  3531. +#define OV5693_ISP_CTRL0_LENC_EN BIT(7)
  3532. +#define OV5693_ISP_CTRL0_WHITE_BALANCE_EN BIT(4)
  3533. +#define OV5693_ISP_CTRL0_DPC_BLACK_EN BIT(2)
  3534. +#define OV5693_ISP_CTRL0_DPC_WHITE_EN BIT(1)
  3535. +#define OV5693_ISP_CTRL1_REG 0x5001
  3536. +#define OV5693_ISP_CTRL1_BLC_EN BIT(0)
  3537. +
  3538. +/* native and active pixel array size. */
  3539. +#define OV5693_NATIVE_WIDTH 2688U
  3540. +#define OV5693_NATIVE_HEIGHT 1984U
  3541. +#define OV5693_PIXEL_ARRAY_LEFT 48U
  3542. +#define OV5693_PIXEL_ARRAY_TOP 20U
  3543. +#define OV5693_PIXEL_ARRAY_WIDTH 2592U
  3544. +#define OV5693_PIXEL_ARRAY_HEIGHT 1944U
  3545. +
  3546. +#define OV5693_PPL_DEFAULT 2800
  3547. +
  3548. +static int vcm_ad_i2c_wr8(struct i2c_client *client, u8 reg, u8 val)
  3549. +{
  3550. + int err;
  3551. + struct i2c_msg msg;
  3552. + u8 buf[2];
  3553. +
  3554. + buf[0] = reg;
  3555. + buf[1] = val;
  3556. +
  3557. + msg.addr = VCM_ADDR;
  3558. + msg.flags = 0;
  3559. + msg.len = 2;
  3560. + msg.buf = &buf[0];
  3561. +
  3562. + err = i2c_transfer(client->adapter, &msg, 1);
  3563. + if (err != 1) {
  3564. + dev_err(&client->dev, "%s: vcm i2c fail, err code = %d\n",
  3565. + __func__, err);
  3566. + return -EIO;
  3567. + }
  3568. + return 0;
  3569. +}
  3570. +
  3571. +static int ad5823_i2c_write(struct i2c_client *client, u8 reg, u8 val)
  3572. +{
  3573. + struct i2c_msg msg;
  3574. + u8 buf[2];
  3575. +
  3576. + buf[0] = reg;
  3577. + buf[1] = val;
  3578. + msg.addr = AD5823_VCM_ADDR;
  3579. + msg.flags = 0;
  3580. + msg.len = 0x02;
  3581. + msg.buf = &buf[0];
  3582. +
  3583. + if (i2c_transfer(client->adapter, &msg, 1) != 1)
  3584. + return -EIO;
  3585. + return 0;
  3586. +}
  3587. +
  3588. +static int ad5823_i2c_read(struct i2c_client *client, u8 reg, u8 *val)
  3589. +{
  3590. + struct i2c_msg msg[2];
  3591. + u8 buf[2];
  3592. +
  3593. + buf[0] = reg;
  3594. + buf[1] = 0;
  3595. +
  3596. + msg[0].addr = AD5823_VCM_ADDR;
  3597. + msg[0].flags = 0;
  3598. + msg[0].len = 0x01;
  3599. + msg[0].buf = &buf[0];
  3600. +
  3601. + msg[1].addr = 0x0c;
  3602. + msg[1].flags = I2C_M_RD;
  3603. + msg[1].len = 0x01;
  3604. + msg[1].buf = &buf[1];
  3605. + *val = 0;
  3606. + if (i2c_transfer(client->adapter, msg, 2) != 2)
  3607. + return -EIO;
  3608. + *val = buf[1];
  3609. + return 0;
  3610. +}
  3611. +
  3612. +static const u32 ov5693_embedded_effective_size = 28;
  3613. +
  3614. +/* i2c read/write stuff */
  3615. +static int ov5693_read_reg(struct i2c_client *client,
  3616. + u16 data_length, u16 reg, u16 *val)
  3617. +{
  3618. + int err;
  3619. + struct i2c_msg msg[2];
  3620. + unsigned char data[6];
  3621. +
  3622. + if (!client->adapter) {
  3623. + dev_err(&client->dev, "%s error, no client->adapter\n",
  3624. + __func__);
  3625. + return -ENODEV;
  3626. + }
  3627. +
  3628. + if (data_length != OV5693_8BIT && data_length != OV5693_16BIT
  3629. + && data_length != OV5693_32BIT) {
  3630. + dev_err(&client->dev, "%s error, invalid data length\n",
  3631. + __func__);
  3632. + return -EINVAL;
  3633. + }
  3634. +
  3635. + memset(msg, 0, sizeof(msg));
  3636. +
  3637. + msg[0].addr = client->addr;
  3638. + msg[0].flags = 0;
  3639. + msg[0].len = I2C_MSG_LENGTH;
  3640. + msg[0].buf = data;
  3641. +
  3642. + /* high byte goes out first */
  3643. + data[0] = (u8)(reg >> 8);
  3644. + data[1] = (u8)(reg & 0xff);
  3645. +
  3646. + msg[1].addr = client->addr;
  3647. + msg[1].len = data_length;
  3648. + msg[1].flags = I2C_M_RD;
  3649. + msg[1].buf = data;
  3650. +
  3651. + err = i2c_transfer(client->adapter, msg, 2);
  3652. + if (err != 2) {
  3653. + if (err >= 0)
  3654. + err = -EIO;
  3655. + dev_err(&client->dev,
  3656. + "read from offset 0x%x error %d", reg, err);
  3657. + return err;
  3658. + }
  3659. +
  3660. + *val = 0;
  3661. + /* high byte comes first */
  3662. + if (data_length == OV5693_8BIT)
  3663. + *val = (u8)data[0];
  3664. + else if (data_length == OV5693_16BIT)
  3665. + *val = be16_to_cpu(*(__be16 *)&data[0]);
  3666. + else
  3667. + *val = be32_to_cpu(*(__be32 *)&data[0]);
  3668. +
  3669. + return 0;
  3670. +}
  3671. +
  3672. +static int ov5693_i2c_write(struct i2c_client *client, u16 len, u8 *data)
  3673. +{
  3674. + struct i2c_msg msg;
  3675. + const int num_msg = 1;
  3676. + int ret;
  3677. +
  3678. + msg.addr = client->addr;
  3679. + msg.flags = 0;
  3680. + msg.len = len;
  3681. + msg.buf = data;
  3682. + ret = i2c_transfer(client->adapter, &msg, 1);
  3683. +
  3684. + return ret == num_msg ? 0 : -EIO;
  3685. +}
  3686. +
  3687. +static int vcm_dw_i2c_write(struct i2c_client *client, u16 data)
  3688. +{
  3689. + struct i2c_msg msg;
  3690. + const int num_msg = 1;
  3691. + int ret;
  3692. + __be16 val;
  3693. +
  3694. + val = cpu_to_be16(data);
  3695. + msg.addr = VCM_ADDR;
  3696. + msg.flags = 0;
  3697. + msg.len = OV5693_16BIT;
  3698. + msg.buf = (void *)&val;
  3699. +
  3700. + ret = i2c_transfer(client->adapter, &msg, 1);
  3701. +
  3702. + return ret == num_msg ? 0 : -EIO;
  3703. +}
  3704. +
  3705. +/*
  3706. + * Theory: per datasheet, the two VCMs both allow for a 2-byte read.
  3707. + * The DW9714 doesn't actually specify what this does (it has a
  3708. + * two-byte write-only protocol, but specifies the read sequence as
  3709. + * legal), but it returns the same data (zeroes) always, after an
  3710. + * undocumented initial NAK. The AD5823 has a one-byte address
  3711. + * register to which all writes go, and subsequent reads will cycle
  3712. + * through the 8 bytes of registers. Notably, the default values (the
  3713. + * device is always power-cycled affirmatively, so we can rely on
  3714. + * these) in AD5823 are not pairwise repetitions of the same 16 bit
  3715. + * word. So all we have to do is sequentially read two bytes at a
  3716. + * time and see if we detect a difference in any of the first four
  3717. + * pairs.
  3718. + */
  3719. +static int vcm_detect(struct i2c_client *client)
  3720. +{
  3721. + int i, ret;
  3722. + struct i2c_msg msg;
  3723. + u16 data0 = 0, data;
  3724. +
  3725. + for (i = 0; i < 4; i++) {
  3726. + msg.addr = VCM_ADDR;
  3727. + msg.flags = I2C_M_RD;
  3728. + msg.len = sizeof(data);
  3729. + msg.buf = (u8 *)&data;
  3730. + ret = i2c_transfer(client->adapter, &msg, 1);
  3731. +
  3732. + /*
  3733. + * DW9714 always fails the first read and returns
  3734. + * zeroes for subsequent ones
  3735. + */
  3736. + if (i == 0 && ret == -EREMOTEIO) {
  3737. + data0 = 0;
  3738. + continue;
  3739. + }
  3740. +
  3741. + if (i == 0)
  3742. + data0 = data;
  3743. +
  3744. + if (data != data0)
  3745. + return VCM_AD5823;
  3746. + }
  3747. + return ret == 1 ? VCM_DW9714 : ret;
  3748. +}
  3749. +
  3750. +static int ov5693_write_reg(struct i2c_client *client, u16 data_length,
  3751. + u16 reg, u16 val)
  3752. +{
  3753. + int ret;
  3754. + unsigned char data[4] = {0};
  3755. + __be16 *wreg = (void *)data;
  3756. + const u16 len = data_length + sizeof(u16); /* 16-bit address + data */
  3757. +
  3758. + if (data_length != OV5693_8BIT && data_length != OV5693_16BIT) {
  3759. + dev_err(&client->dev,
  3760. + "%s error, invalid data_length\n", __func__);
  3761. + return -EINVAL;
  3762. + }
  3763. +
  3764. + /* high byte goes out first */
  3765. + *wreg = cpu_to_be16(reg);
  3766. +
  3767. + if (data_length == OV5693_8BIT) {
  3768. + data[2] = (u8)(val);
  3769. + } else {
  3770. + /* OV5693_16BIT */
  3771. + __be16 *wdata = (void *)&data[2];
  3772. +
  3773. + *wdata = cpu_to_be16(val);
  3774. + }
  3775. +
  3776. + ret = ov5693_i2c_write(client, len, data);
  3777. + if (ret)
  3778. + dev_err(&client->dev,
  3779. + "write error: wrote 0x%x to offset 0x%x error %d",
  3780. + val, reg, ret);
  3781. +
  3782. + return ret;
  3783. +}
  3784. +
  3785. +/*
  3786. + * ov5693_write_reg_array - Initializes a list of OV5693 registers
  3787. + * @client: i2c driver client structure
  3788. + * @reglist: list of registers to be written
  3789. + *
  3790. + * This function initializes a list of registers. When consecutive addresses
  3791. + * are found in a row on the list, this function creates a buffer and sends
  3792. + * consecutive data in a single i2c_transfer().
  3793. + *
  3794. + * __ov5693_flush_reg_array, __ov5693_buf_reg_array() and
  3795. + * __ov5693_write_reg_is_consecutive() are internal functions to
  3796. + * ov5693_write_reg_array_fast() and should be not used anywhere else.
  3797. + *
  3798. + */
  3799. +
  3800. +static int __ov5693_flush_reg_array(struct i2c_client *client,
  3801. + struct ov5693_write_ctrl *ctrl)
  3802. +{
  3803. + u16 size;
  3804. + __be16 *reg = (void *)&ctrl->buffer.addr;
  3805. +
  3806. + if (ctrl->index == 0)
  3807. + return 0;
  3808. +
  3809. + size = sizeof(u16) + ctrl->index; /* 16-bit address + data */
  3810. +
  3811. + *reg = cpu_to_be16(ctrl->buffer.addr);
  3812. + ctrl->index = 0;
  3813. +
  3814. + return ov5693_i2c_write(client, size, (u8 *)reg);
  3815. +}
  3816. +
  3817. +static int __ov5693_buf_reg_array(struct i2c_client *client,
  3818. + struct ov5693_write_ctrl *ctrl,
  3819. + const struct ov5693_reg *next)
  3820. +{
  3821. + int size;
  3822. + __be16 *data16;
  3823. +
  3824. + switch (next->type) {
  3825. + case OV5693_8BIT:
  3826. + size = 1;
  3827. + ctrl->buffer.data[ctrl->index] = (u8)next->val;
  3828. + break;
  3829. + case OV5693_16BIT:
  3830. + size = 2;
  3831. +
  3832. + data16 = (void *)&ctrl->buffer.data[ctrl->index];
  3833. + *data16 = cpu_to_be16((u16)next->val);
  3834. + break;
  3835. + default:
  3836. + return -EINVAL;
  3837. + }
  3838. +
  3839. + /* When first item is added, we need to store its starting address */
  3840. + if (ctrl->index == 0)
  3841. + ctrl->buffer.addr = next->reg;
  3842. +
  3843. + ctrl->index += size;
  3844. +
  3845. + /*
  3846. + * Buffer cannot guarantee free space for u32? Better flush it to avoid
  3847. + * possible lack of memory for next item.
  3848. + */
  3849. + if (ctrl->index + sizeof(u16) >= OV5693_MAX_WRITE_BUF_SIZE)
  3850. + return __ov5693_flush_reg_array(client, ctrl);
  3851. +
  3852. + return 0;
  3853. +}
  3854. +
  3855. +static int __ov5693_write_reg_is_consecutive(struct i2c_client *client,
  3856. + struct ov5693_write_ctrl *ctrl,
  3857. + const struct ov5693_reg *next)
  3858. +{
  3859. + if (ctrl->index == 0)
  3860. + return 1;
  3861. +
  3862. + return ctrl->buffer.addr + ctrl->index == next->reg;
  3863. +}
  3864. +
  3865. +static int ov5693_write_reg_array(struct i2c_client *client,
  3866. + const struct ov5693_reg *reglist)
  3867. +{
  3868. + const struct ov5693_reg *next = reglist;
  3869. + struct ov5693_write_ctrl ctrl;
  3870. + int err;
  3871. +
  3872. + ctrl.index = 0;
  3873. + for (; next->type != OV5693_TOK_TERM; next++) {
  3874. + switch (next->type & OV5693_TOK_MASK) {
  3875. + case OV5693_TOK_DELAY:
  3876. + err = __ov5693_flush_reg_array(client, &ctrl);
  3877. + if (err)
  3878. + return err;
  3879. + msleep(next->val);
  3880. + break;
  3881. + default:
  3882. + /*
  3883. + * If next address is not consecutive, data needs to be
  3884. + * flushed before proceed.
  3885. + */
  3886. + if (!__ov5693_write_reg_is_consecutive(client, &ctrl,
  3887. + next)) {
  3888. + err = __ov5693_flush_reg_array(client, &ctrl);
  3889. + if (err)
  3890. + return err;
  3891. + }
  3892. + err = __ov5693_buf_reg_array(client, &ctrl, next);
  3893. + if (err) {
  3894. + dev_err(&client->dev,
  3895. + "%s: write error, aborted\n",
  3896. + __func__);
  3897. + return err;
  3898. + }
  3899. + break;
  3900. + }
  3901. + }
  3902. +
  3903. + return __ov5693_flush_reg_array(client, &ctrl);
  3904. +}
  3905. +
  3906. +static int ov5693_read_otp_reg_array(struct i2c_client *client, u16 size,
  3907. + u16 addr, u8 *buf)
  3908. +{
  3909. + u16 index;
  3910. + int ret;
  3911. + u16 *pVal = NULL;
  3912. +
  3913. + for (index = 0; index <= size; index++) {
  3914. + pVal = (u16 *)(buf + index);
  3915. + ret =
  3916. + ov5693_read_reg(client, OV5693_8BIT, addr + index,
  3917. + pVal);
  3918. + if (ret)
  3919. + return ret;
  3920. + }
  3921. +
  3922. + return 0;
  3923. +}
  3924. +
  3925. +static int __ov5693_otp_read(struct v4l2_subdev *sd, u8 *buf)
  3926. +{
  3927. + struct i2c_client *client = v4l2_get_subdevdata(sd);
  3928. + struct ov5693_device *dev = to_ov5693_sensor(sd);
  3929. + int ret;
  3930. + int i;
  3931. + u8 *b = buf;
  3932. +
  3933. + dev->otp_size = 0;
  3934. + for (i = 1; i < OV5693_OTP_BANK_MAX; i++) {
  3935. + /*set bank NO and OTP read mode. */
  3936. + ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_OTP_BANK_REG,
  3937. + (i | 0xc0)); //[7:6] 2'b11 [5:0] bank no
  3938. + if (ret) {
  3939. + dev_err(&client->dev, "failed to prepare OTP page\n");
  3940. + return ret;
  3941. + }
  3942. + //dev_dbg(&client->dev, "write 0x%x->0x%x\n",OV5693_OTP_BANK_REG,(i|0xc0));
  3943. +
  3944. + /*enable read */
  3945. + ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_OTP_READ_REG,
  3946. + OV5693_OTP_MODE_READ); // enable :1
  3947. + if (ret) {
  3948. + dev_err(&client->dev,
  3949. + "failed to set OTP reading mode page");
  3950. + return ret;
  3951. + }
  3952. + //dev_dbg(&client->dev, "write 0x%x->0x%x\n",
  3953. + // OV5693_OTP_READ_REG,OV5693_OTP_MODE_READ);
  3954. +
  3955. + /* Reading the OTP data array */
  3956. + ret = ov5693_read_otp_reg_array(client, OV5693_OTP_BANK_SIZE,
  3957. + OV5693_OTP_START_ADDR,
  3958. + b);
  3959. + if (ret) {
  3960. + dev_err(&client->dev, "failed to read OTP data\n");
  3961. + return ret;
  3962. + }
  3963. +
  3964. + //dev_dbg(&client->dev,
  3965. + // "BANK[%2d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  3966. + // i, *b, *(b+1), *(b+2), *(b+3), *(b+4), *(b+5), *(b+6), *(b+7),
  3967. + // *(b+8), *(b+9), *(b+10), *(b+11), *(b+12), *(b+13), *(b+14), *(b+15));
  3968. +
  3969. + //Intel OTP map, try to read 320byts first.
  3970. + if (i == 21) {
  3971. + if ((*b) == 0) {
  3972. + dev->otp_size = 320;
  3973. + break;
  3974. + }
  3975. + /* (*b) != 0 */
  3976. + b = buf;
  3977. + continue;
  3978. + } else if (i ==
  3979. + 24) { //if the first 320bytes data doesn't not exist, try to read the next 32bytes data.
  3980. + if ((*b) == 0) {
  3981. + dev->otp_size = 32;
  3982. + break;
  3983. + }
  3984. + /* (*b) != 0 */
  3985. + b = buf;
  3986. + continue;
  3987. + } else if (i ==
  3988. + 27) { //if the prvious 32bytes data doesn't exist, try to read the next 32bytes data again.
  3989. + if ((*b) == 0) {
  3990. + dev->otp_size = 32;
  3991. + break;
  3992. + }
  3993. + /* (*b) != 0 */
  3994. + dev->otp_size = 0; // no OTP data.
  3995. + break;
  3996. + }
  3997. +
  3998. + b = b + OV5693_OTP_BANK_SIZE;
  3999. + }
  4000. + return 0;
  4001. +}
  4002. +
  4003. +/*
  4004. + * Read otp data and store it into a kmalloced buffer.
  4005. + * The caller must kfree the buffer when no more needed.
  4006. + * @size: set to the size of the returned otp data.
  4007. + */
  4008. +static void *ov5693_otp_read(struct v4l2_subdev *sd)
  4009. +{
  4010. + struct i2c_client *client = v4l2_get_subdevdata(sd);
  4011. + u8 *buf;
  4012. + int ret;
  4013. +
  4014. + buf = devm_kzalloc(&client->dev, (OV5693_OTP_DATA_SIZE + 16), GFP_KERNEL);
  4015. + if (!buf)
  4016. + return ERR_PTR(-ENOMEM);
  4017. +
  4018. + //otp valid after mipi on and sw stream on
  4019. + ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_FRAME_OFF_NUM, 0x00);
  4020. +
  4021. + ret = ov5693_write_reg(client, OV5693_8BIT,
  4022. + OV5693_SW_STREAM, OV5693_START_STREAMING);
  4023. +
  4024. + ret = __ov5693_otp_read(sd, buf);
  4025. +
  4026. + //mipi off and sw stream off after otp read
  4027. + ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_FRAME_OFF_NUM, 0x0f);
  4028. +
  4029. + ret = ov5693_write_reg(client, OV5693_8BIT,
  4030. + OV5693_SW_STREAM, OV5693_STOP_STREAMING);
  4031. +
  4032. + /* Driver has failed to find valid data */
  4033. + if (ret) {
  4034. + dev_err(&client->dev, "sensor found no valid OTP data\n");
  4035. + return ERR_PTR(ret);
  4036. + }
  4037. +
  4038. + return buf;
  4039. +}
  4040. +
  4041. +static int ov5693_update_bits(struct ov5693_device *sensor, u16 address,
  4042. + u16 mask, u16 bits)
  4043. +{
  4044. + u16 value = 0;
  4045. + int ret;
  4046. +
  4047. + ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT, address, &value);
  4048. + if (ret)
  4049. + return ret;
  4050. +
  4051. + value &= ~mask;
  4052. + value |= bits;
  4053. +
  4054. + ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT, address, value);
  4055. + if (ret)
  4056. + return ret;
  4057. +
  4058. + return 0;
  4059. +}
  4060. +
  4061. +/* Flip */
  4062. +
  4063. +static int ov5693_flip_vert_configure(struct ov5693_device *sensor, bool enable)
  4064. +{
  4065. + u8 bits = OV5693_FORMAT1_FLIP_VERT_ISP_EN |
  4066. + OV5693_FORMAT1_FLIP_VERT_SENSOR_EN;
  4067. + int ret;
  4068. +
  4069. + ret = ov5693_update_bits(sensor, OV5693_FORMAT1_REG, bits,
  4070. + enable ? bits : 0);
  4071. + if (ret)
  4072. + return ret;
  4073. +
  4074. + return 0;
  4075. +}
  4076. +
  4077. +static int ov5693_flip_horz_configure(struct ov5693_device *sensor, bool enable)
  4078. +{
  4079. + u8 bits = OV5693_FORMAT2_FLIP_HORZ_ISP_EN |
  4080. + OV5693_FORMAT2_FLIP_HORZ_SENSOR_EN;
  4081. + int ret;
  4082. +
  4083. + ret = ov5693_update_bits(sensor, OV5693_FORMAT2_REG, bits,
  4084. + enable ? bits : 0);
  4085. + if (ret)
  4086. + return ret;
  4087. +
  4088. + return 0;
  4089. +}
  4090. +
  4091. +/*
  4092. + * This returns the exposure time being used. This should only be used
  4093. + * for filling in EXIF data, not for actual image processing.
  4094. + */
  4095. +static int ov5693_q_exposure(struct v4l2_subdev *sd, s32 *value)
  4096. +{
  4097. + struct i2c_client *client = v4l2_get_subdevdata(sd);
  4098. + u16 reg_v, reg_v2;
  4099. + int ret;
  4100. +
  4101. + /* get exposure */
  4102. + ret = ov5693_read_reg(client, OV5693_8BIT,
  4103. + OV5693_EXPOSURE_L,
  4104. + &reg_v);
  4105. + if (ret)
  4106. + goto err;
  4107. +
  4108. + ret = ov5693_read_reg(client, OV5693_8BIT,
  4109. + OV5693_EXPOSURE_M,
  4110. + &reg_v2);
  4111. + if (ret)
  4112. + goto err;
  4113. +
  4114. + reg_v += reg_v2 << 8;
  4115. + ret = ov5693_read_reg(client, OV5693_8BIT,
  4116. + OV5693_EXPOSURE_H,
  4117. + &reg_v2);
  4118. + if (ret)
  4119. + goto err;
  4120. +
  4121. + *value = reg_v + (((u32)reg_v2 << 16));
  4122. +err:
  4123. + return ret;
  4124. +}
  4125. +
  4126. +static int ad5823_t_focus_vcm(struct v4l2_subdev *sd, u16 val)
  4127. +{
  4128. + struct i2c_client *client = v4l2_get_subdevdata(sd);
  4129. + int ret = -EINVAL;
  4130. + u8 vcm_code;
  4131. +
  4132. + ret = ad5823_i2c_read(client, AD5823_REG_VCM_CODE_MSB, &vcm_code);
  4133. + if (ret)
  4134. + return ret;
  4135. +
  4136. + /* set reg VCM_CODE_MSB Bit[1:0] */
  4137. + vcm_code = (vcm_code & VCM_CODE_MSB_MASK) |
  4138. + ((val >> 8) & ~VCM_CODE_MSB_MASK);
  4139. + ret = ad5823_i2c_write(client, AD5823_REG_VCM_CODE_MSB, vcm_code);
  4140. + if (ret)
  4141. + return ret;
  4142. +
  4143. + /* set reg VCM_CODE_LSB Bit[7:0] */
  4144. + ret = ad5823_i2c_write(client, AD5823_REG_VCM_CODE_LSB, (val & 0xff));
  4145. + if (ret)
  4146. + return ret;
  4147. +
  4148. + /* set required vcm move time */
  4149. + vcm_code = AD5823_RESONANCE_PERIOD / AD5823_RESONANCE_COEF
  4150. + - AD5823_HIGH_FREQ_RANGE;
  4151. + ret = ad5823_i2c_write(client, AD5823_REG_VCM_MOVE_TIME, vcm_code);
  4152. +
  4153. + return ret;
  4154. +}
  4155. +
  4156. +static int ad5823_t_focus_abs(struct v4l2_subdev *sd, s32 value)
  4157. +{
  4158. + value = min(value, AD5823_MAX_FOCUS_POS);
  4159. + return ad5823_t_focus_vcm(sd, value);
  4160. +}
  4161. +
  4162. +static int ov5693_t_focus_abs(struct v4l2_subdev *sd, s32 value)
  4163. +{
  4164. + struct ov5693_device *dev = to_ov5693_sensor(sd);
  4165. + struct i2c_client *client = v4l2_get_subdevdata(sd);
  4166. + int ret = 0;
  4167. +
  4168. + dev_dbg(&client->dev, "%s: FOCUS_POS: 0x%x\n", __func__, value);
  4169. + value = clamp(value, 0, OV5693_VCM_MAX_FOCUS_POS);
  4170. + if (dev->vcm == VCM_DW9714) {
  4171. + if (dev->vcm_update) {
  4172. + ret = vcm_dw_i2c_write(client, VCM_PROTECTION_OFF);
  4173. + if (ret)
  4174. + return ret;
  4175. + ret = vcm_dw_i2c_write(client, DIRECT_VCM);
  4176. + if (ret)
  4177. + return ret;
  4178. + ret = vcm_dw_i2c_write(client, VCM_PROTECTION_ON);
  4179. + if (ret)
  4180. + return ret;
  4181. + dev->vcm_update = false;
  4182. + }
  4183. + ret = vcm_dw_i2c_write(client,
  4184. + vcm_val(value, VCM_DEFAULT_S));
  4185. + } else if (dev->vcm == VCM_AD5823) {
  4186. + ad5823_t_focus_abs(sd, value);
  4187. + }
  4188. + if (ret == 0) {
  4189. + dev->number_of_steps = value - dev->focus;
  4190. + dev->focus = value;
  4191. + dev->timestamp_t_focus_abs = ktime_get();
  4192. + } else
  4193. + dev_err(&client->dev,
  4194. + "%s: i2c failed. ret %d\n", __func__, ret);
  4195. +
  4196. + return ret;
  4197. +}
  4198. +
  4199. +static int ov5693_t_focus_rel(struct v4l2_subdev *sd, s32 value)
  4200. +{
  4201. + struct ov5693_device *dev = to_ov5693_sensor(sd);
  4202. +
  4203. + return ov5693_t_focus_abs(sd, dev->focus + value);
  4204. +}
  4205. +
  4206. +#define DELAY_PER_STEP_NS 1000000
  4207. +#define DELAY_MAX_PER_STEP_NS (1000000 * 1023)
  4208. +
  4209. +/* Exposure */
  4210. +
  4211. +static int ov5693_get_exposure(struct ov5693_device *sensor)
  4212. +{
  4213. + u16 reg_v, reg_v2;
  4214. + int ret = 0;
  4215. +
  4216. + /* get exposure */
  4217. + ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT,
  4218. + OV5693_EXPOSURE_L,
  4219. + &reg_v);
  4220. + if (ret)
  4221. + return ret;
  4222. +
  4223. + ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT,
  4224. + OV5693_EXPOSURE_M,
  4225. + &reg_v2);
  4226. + if (ret)
  4227. + return ret;
  4228. +
  4229. + reg_v += reg_v2 << 8;
  4230. + ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT,
  4231. + OV5693_EXPOSURE_H,
  4232. + &reg_v2);
  4233. + if (ret)
  4234. + return ret;
  4235. +
  4236. + printk("exposure set to: %u\n", reg_v + (((u32)reg_v2 << 16)));
  4237. + return ret;
  4238. +}
  4239. +
  4240. +static int ov5693_exposure_configure(struct ov5693_device *sensor, u32 exposure)
  4241. +{
  4242. + int ret;
  4243. +
  4244. + ov5693_get_exposure(sensor);
  4245. + ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  4246. + OV5693_EXPOSURE_CTRL_HH_REG, OV5693_EXPOSURE_CTRL_HH(exposure));
  4247. + if (ret)
  4248. + return ret;
  4249. +
  4250. + ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  4251. + OV5693_EXPOSURE_CTRL_H_REG, OV5693_EXPOSURE_CTRL_H(exposure));
  4252. + if (ret)
  4253. + return ret;
  4254. +
  4255. + ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  4256. + OV5693_EXPOSURE_CTRL_L_REG, OV5693_EXPOSURE_CTRL_L(exposure));
  4257. + if (ret)
  4258. + return ret;
  4259. + ov5693_get_exposure(sensor);
  4260. +
  4261. + return 0;
  4262. +}
  4263. +
  4264. +/* Gain */
  4265. +
  4266. +static int ov5693_get_gain(struct ov5693_device *sensor, u32 *gain)
  4267. +{
  4268. + u16 gain_l, gain_h;
  4269. + int ret = 0;
  4270. +
  4271. + ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT,
  4272. + OV5693_GAIN_CTRL_L_REG,
  4273. + &gain_l);
  4274. + if (ret)
  4275. + return ret;
  4276. +
  4277. + ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT,
  4278. + OV5693_GAIN_CTRL_H_REG,
  4279. + &gain_h);
  4280. + if (ret)
  4281. + return ret;
  4282. +
  4283. + *gain = (u32)(((gain_h >> 8) & 0x03) |
  4284. + (gain_l & 0xff));
  4285. +
  4286. + return ret;
  4287. +}
  4288. +static int ov5693_gain_configure(struct ov5693_device *sensor, u32 gain)
  4289. +{
  4290. + int ret;
  4291. +
  4292. + /* A 1.0 gain is 0x400 */
  4293. + gain = (gain * 1024)/1000;
  4294. +
  4295. + ret = ov5693_write_reg(sensor->i2c_client, OV5693_16BIT,
  4296. + OV5693_MWB_RED_GAIN_H, gain);
  4297. + if (ret) {
  4298. + dev_err(&sensor->i2c_client->dev, "%s: write %x error, aborted\n",
  4299. + __func__, OV5693_MWB_RED_GAIN_H);
  4300. + return ret;
  4301. + }
  4302. +
  4303. + ret = ov5693_write_reg(sensor->i2c_client, OV5693_16BIT,
  4304. + OV5693_MWB_GREEN_GAIN_H, gain);
  4305. + if (ret) {
  4306. + dev_err(&sensor->i2c_client->dev, "%s: write %x error, aborted\n",
  4307. + __func__, OV5693_MWB_RED_GAIN_H);
  4308. + return ret;
  4309. + }
  4310. +
  4311. + ret = ov5693_write_reg(sensor->i2c_client, OV5693_16BIT,
  4312. + OV5693_MWB_BLUE_GAIN_H, gain);
  4313. + if (ret) {
  4314. + dev_err(&sensor->i2c_client->dev, "%s: write %x error, aborted\n",
  4315. + __func__, OV5693_MWB_RED_GAIN_H);
  4316. + return ret;
  4317. + }
  4318. +
  4319. + return 0;
  4320. +}
  4321. +
  4322. +static int ov5693_analog_gain_configure(struct ov5693_device *sensor, u32 gain)
  4323. +{
  4324. + int ret;
  4325. +
  4326. + /* Analog gain */
  4327. + ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  4328. + OV5693_AGC_L, gain & 0xff);
  4329. + if (ret) {
  4330. + dev_err(&sensor->i2c_client->dev, "%s: write %x error, aborted\n",
  4331. + __func__, OV5693_AGC_L);
  4332. + return ret;
  4333. + }
  4334. +
  4335. + ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  4336. + OV5693_AGC_H, (gain >> 8) & 0xff);
  4337. + if (ret) {
  4338. + dev_err(&sensor->i2c_client->dev, "%s: write %x error, aborted\n",
  4339. + __func__, OV5693_AGC_H);
  4340. + return ret;
  4341. + }
  4342. +
  4343. + return 0;
  4344. +}
  4345. +
  4346. +static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
  4347. +{
  4348. + struct ov5693_device *dev =
  4349. + container_of(ctrl->handler, struct ov5693_device, ctrl_handler);
  4350. + struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
  4351. + int ret = 0;
  4352. +
  4353. + switch (ctrl->id) {
  4354. + case V4L2_CID_FOCUS_ABSOLUTE:
  4355. + dev_dbg(&client->dev, "%s: CID_FOCUS_ABSOLUTE:%d.\n",
  4356. + __func__, ctrl->val);
  4357. + ret = ov5693_t_focus_abs(&dev->sd, ctrl->val);
  4358. + break;
  4359. + case V4L2_CID_FOCUS_RELATIVE:
  4360. + dev_dbg(&client->dev, "%s: CID_FOCUS_RELATIVE:%d.\n",
  4361. + __func__, ctrl->val);
  4362. + ret = ov5693_t_focus_rel(&dev->sd, ctrl->val);
  4363. + break;
  4364. + case V4L2_CID_EXPOSURE:
  4365. + dev_dbg(&client->dev, "%s: CID_EXPOSURE:%d.\n",
  4366. + __func__, ctrl->val);
  4367. + ret = ov5693_exposure_configure(dev, ctrl->val);
  4368. + if (ret)
  4369. + return ret;
  4370. + break;
  4371. + case V4L2_CID_ANALOGUE_GAIN:
  4372. + dev_dbg(&client->dev, "%s: CID_ANALOGUE_GAIN:%d.\n",
  4373. + __func__, ctrl->val);
  4374. + ret = ov5693_analog_gain_configure(dev, ctrl->val);
  4375. + if (ret)
  4376. + return ret;
  4377. + break;
  4378. + case V4L2_CID_DIGITAL_GAIN:
  4379. + dev_dbg(&client->dev, "%s: CID_DIGITAL_GAIN:%d.\n",
  4380. + __func__, ctrl->val);
  4381. + ret = ov5693_gain_configure(dev, ctrl->val);
  4382. + if (ret)
  4383. + return ret;
  4384. + break;
  4385. + case V4L2_CID_HFLIP:
  4386. + return ov5693_flip_horz_configure(dev, !!ctrl->val);
  4387. + case V4L2_CID_VFLIP:
  4388. + return ov5693_flip_vert_configure(dev, !!ctrl->val);
  4389. + default:
  4390. + ret = -EINVAL;
  4391. + }
  4392. + return ret;
  4393. +}
  4394. +
  4395. +static int ov5693_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
  4396. +{
  4397. + struct ov5693_device *dev =
  4398. + container_of(ctrl->handler, struct ov5693_device, ctrl_handler);
  4399. + int ret = 0;
  4400. +
  4401. + switch (ctrl->id) {
  4402. + case V4L2_CID_EXPOSURE_ABSOLUTE:
  4403. + ret = ov5693_q_exposure(&dev->sd, &ctrl->val);
  4404. + break;
  4405. + case V4L2_CID_AUTOGAIN:
  4406. + ret = ov5693_get_gain(dev, &ctrl->val);
  4407. + break;
  4408. + case V4L2_CID_FOCUS_ABSOLUTE:
  4409. + /* NOTE: there was atomisp-specific function ov5693_q_focus_abs() */
  4410. + break;
  4411. + default:
  4412. + ret = -EINVAL;
  4413. + }
  4414. +
  4415. + return ret;
  4416. +}
  4417. +
  4418. +static const struct v4l2_ctrl_ops ov5693_ctrl_ops = {
  4419. + .s_ctrl = ov5693_s_ctrl,
  4420. + .g_volatile_ctrl = ov5693_g_volatile_ctrl
  4421. +};
  4422. +
  4423. +static const struct v4l2_ctrl_config ov5693_controls[] = {
  4424. + {
  4425. + .ops = &ov5693_ctrl_ops,
  4426. + .id = V4L2_CID_FOCUS_ABSOLUTE,
  4427. + .type = V4L2_CTRL_TYPE_INTEGER,
  4428. + .name = "focus move absolute",
  4429. + .min = 0,
  4430. + .max = OV5693_VCM_MAX_FOCUS_POS,
  4431. + .step = 1,
  4432. + .def = 0,
  4433. + .flags = 0,
  4434. + },
  4435. + {
  4436. + .ops = &ov5693_ctrl_ops,
  4437. + .id = V4L2_CID_FOCUS_RELATIVE,
  4438. + .type = V4L2_CTRL_TYPE_INTEGER,
  4439. + .name = "focus move relative",
  4440. + .min = OV5693_VCM_MAX_FOCUS_NEG,
  4441. + .max = OV5693_VCM_MAX_FOCUS_POS,
  4442. + .step = 1,
  4443. + .def = 0,
  4444. + .flags = 0,
  4445. + },
  4446. +};
  4447. +
  4448. +static int ov5693_isp_configure(struct ov5693_device *sensor)
  4449. +{
  4450. + int ret;
  4451. +
  4452. + /* Enable lens correction. */
  4453. + ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  4454. + OV5693_ISP_CTRL0_REG, 0x86);
  4455. + if (ret)
  4456. + return ret;
  4457. +
  4458. + return 0;
  4459. +}
  4460. +
  4461. +static int ov5693_init(struct v4l2_subdev *sd)
  4462. +{
  4463. + struct ov5693_device *dev = to_ov5693_sensor(sd);
  4464. + struct i2c_client *client = v4l2_get_subdevdata(sd);
  4465. + int ret;
  4466. +
  4467. + if (!dev->has_vcm)
  4468. + return 0;
  4469. +
  4470. + dev_info(&client->dev, "%s\n", __func__);
  4471. + mutex_lock(&dev->input_lock);
  4472. + dev->vcm_update = false;
  4473. +
  4474. + if (dev->vcm == VCM_AD5823) {
  4475. + ret = vcm_ad_i2c_wr8(client, 0x01, 0x01); /* vcm init test */
  4476. + if (ret)
  4477. + dev_err(&client->dev,
  4478. + "vcm reset failed\n");
  4479. + /*change the mode*/
  4480. + ret = ad5823_i2c_write(client, AD5823_REG_VCM_CODE_MSB,
  4481. + AD5823_RING_CTRL_ENABLE);
  4482. + if (ret)
  4483. + dev_err(&client->dev,
  4484. + "vcm enable ringing failed\n");
  4485. + ret = ad5823_i2c_write(client, AD5823_REG_MODE,
  4486. + AD5823_ARC_RES1);
  4487. + if (ret)
  4488. + dev_err(&client->dev,
  4489. + "vcm change mode failed\n");
  4490. + }
  4491. +
  4492. + /*change initial focus value for ad5823*/
  4493. + if (dev->vcm == VCM_AD5823) {
  4494. + dev->focus = AD5823_INIT_FOCUS_POS;
  4495. + ov5693_t_focus_abs(sd, AD5823_INIT_FOCUS_POS);
  4496. + } else {
  4497. + dev->focus = 0;
  4498. + ov5693_t_focus_abs(sd, 0);
  4499. + }
  4500. +
  4501. + ov5693_isp_configure(dev);
  4502. + mutex_unlock(&dev->input_lock);
  4503. +
  4504. + return 0;
  4505. +}
  4506. +
  4507. +static int __power_up(struct v4l2_subdev *sd)
  4508. +{
  4509. + struct i2c_client *client = v4l2_get_subdevdata(sd);
  4510. + struct ov5693_device *sensor = to_ov5693_sensor(sd);
  4511. + int ret;
  4512. +
  4513. + ret = clk_prepare_enable(sensor->clk);
  4514. + if (ret) {
  4515. + dev_err(&client->dev, "Error enabling clock\n");
  4516. + return -EINVAL;
  4517. + }
  4518. +
  4519. + if (sensor->indicator_led)
  4520. + gpiod_set_value_cansleep(sensor->indicator_led, 1);
  4521. +
  4522. + ret = regulator_bulk_enable(OV5693_NUM_SUPPLIES,
  4523. + sensor->supplies);
  4524. + if (ret)
  4525. + goto fail_power;
  4526. +
  4527. + __cci_delay(up_delay);
  4528. +
  4529. + return 0;
  4530. +
  4531. +fail_power:
  4532. + if (sensor->indicator_led)
  4533. + gpiod_set_value_cansleep(sensor->indicator_led, 0);
  4534. + dev_err(&client->dev, "sensor power-up failed\n");
  4535. +
  4536. + return ret;
  4537. +}
  4538. +
  4539. +static int power_down(struct v4l2_subdev *sd)
  4540. +{
  4541. + struct ov5693_device *dev = to_ov5693_sensor(sd);
  4542. +
  4543. + dev->focus = OV5693_INVALID_CONFIG;
  4544. +
  4545. + clk_disable_unprepare(dev->clk);
  4546. +
  4547. + if (dev->indicator_led)
  4548. + gpiod_set_value_cansleep(dev->indicator_led, 0);
  4549. + return regulator_bulk_disable(OV5693_NUM_SUPPLIES, dev->supplies);
  4550. +}
  4551. +
  4552. +static int power_up(struct v4l2_subdev *sd)
  4553. +{
  4554. + static const int retry_count = 4;
  4555. + int i, ret;
  4556. +
  4557. + for (i = 0; i < retry_count; i++) {
  4558. + ret = __power_up(sd);
  4559. + if (!ret)
  4560. + return 0;
  4561. +
  4562. + power_down(sd);
  4563. + }
  4564. + return ret;
  4565. +}
  4566. +
  4567. +static int ov5693_s_power(struct v4l2_subdev *sd, int on)
  4568. +{
  4569. + struct i2c_client *client = v4l2_get_subdevdata(sd);
  4570. + int ret;
  4571. +
  4572. + dev_info(&client->dev, "%s: on %d\n", __func__, on);
  4573. +
  4574. + if (on == 0)
  4575. + return power_down(sd);
  4576. +
  4577. + /* on == 1 */
  4578. + ret = power_up(sd);
  4579. + if (!ret) {
  4580. + ret = ov5693_init(sd);
  4581. + /* restore settings */
  4582. + ov5693_res = ov5693_res_video;
  4583. + N_RES = N_RES_VIDEO;
  4584. + }
  4585. +
  4586. + return ret;
  4587. +}
  4588. +
  4589. +/*
  4590. + * distance - calculate the distance
  4591. + * @res: resolution
  4592. + * @w: width
  4593. + * @h: height
  4594. + *
  4595. + * Get the gap between res_w/res_h and w/h.
  4596. + * distance = (res_w/res_h - w/h) / (w/h) * 8192
  4597. + * res->width/height smaller than w/h wouldn't be considered.
  4598. + * The gap of ratio larger than 1/8 wouldn't be considered.
  4599. + * Returns the value of gap or -1 if fail.
  4600. + */
  4601. +#define LARGEST_ALLOWED_RATIO_MISMATCH 1024
  4602. +static int distance(struct ov5693_resolution *res, u32 w, u32 h)
  4603. +{
  4604. + int ratio;
  4605. + int distance;
  4606. +
  4607. + if (w == 0 || h == 0 ||
  4608. + res->width < w || res->height < h)
  4609. + return -1;
  4610. +
  4611. + ratio = res->width << 13;
  4612. + ratio /= w;
  4613. + ratio *= h;
  4614. + ratio /= res->height;
  4615. +
  4616. + distance = abs(ratio - 8192);
  4617. +
  4618. + if (distance > LARGEST_ALLOWED_RATIO_MISMATCH)
  4619. + return -1;
  4620. +
  4621. + return distance;
  4622. +}
  4623. +
  4624. +/* Return the nearest higher resolution index
  4625. + * Firstly try to find the approximate aspect ratio resolution
  4626. + * If we find multiple same AR resolutions, choose the
  4627. + * minimal size.
  4628. + */
  4629. +static int nearest_resolution_index(int w, int h)
  4630. +{
  4631. + int i;
  4632. + int idx = -1;
  4633. + int dist;
  4634. + int min_dist = INT_MAX;
  4635. + int min_res_w = INT_MAX;
  4636. + struct ov5693_resolution *tmp_res = NULL;
  4637. +
  4638. + for (i = 0; i < N_RES; i++) {
  4639. + tmp_res = &ov5693_res[i];
  4640. + dist = distance(tmp_res, w, h);
  4641. + if (dist == -1)
  4642. + continue;
  4643. + if (dist < min_dist) {
  4644. + min_dist = dist;
  4645. + idx = i;
  4646. + min_res_w = ov5693_res[i].width;
  4647. + continue;
  4648. + }
  4649. + if (dist == min_dist && ov5693_res[i].width < min_res_w)
  4650. + idx = i;
  4651. + }
  4652. +
  4653. + return idx;
  4654. +}
  4655. +
  4656. +static int get_resolution_index(int w, int h)
  4657. +{
  4658. + int i;
  4659. +
  4660. + for (i = 0; i < N_RES; i++) {
  4661. + if (w != ov5693_res[i].width)
  4662. + continue;
  4663. + if (h != ov5693_res[i].height)
  4664. + continue;
  4665. +
  4666. + return i;
  4667. + }
  4668. +
  4669. + return -1;
  4670. +}
  4671. +
  4672. +/* TODO: remove it. */
  4673. +static int startup(struct v4l2_subdev *sd)
  4674. +{
  4675. + struct ov5693_device *dev = to_ov5693_sensor(sd);
  4676. + struct i2c_client *client = v4l2_get_subdevdata(sd);
  4677. + int ret = 0;
  4678. +
  4679. + ret = ov5693_write_reg(client, OV5693_8BIT,
  4680. + OV5693_SW_RESET, 0x01);
  4681. + if (ret) {
  4682. + dev_err(&client->dev, "ov5693 reset err.\n");
  4683. + return ret;
  4684. + }
  4685. +
  4686. + ret = ov5693_write_reg_array(client, ov5693_global_setting);
  4687. + if (ret) {
  4688. + dev_err(&client->dev, "ov5693 write register err.\n");
  4689. + return ret;
  4690. + }
  4691. +
  4692. + ret = ov5693_write_reg_array(client, ov5693_res[dev->fmt_idx].regs);
  4693. + if (ret) {
  4694. + dev_err(&client->dev, "ov5693 write register err.\n");
  4695. + return ret;
  4696. + }
  4697. +
  4698. + return ret;
  4699. +}
  4700. +
  4701. +static int ov5693_set_fmt(struct v4l2_subdev *sd,
  4702. + struct v4l2_subdev_pad_config *cfg,
  4703. + struct v4l2_subdev_format *format)
  4704. +{
  4705. + struct v4l2_mbus_framefmt *fmt = &format->format;
  4706. + struct ov5693_device *dev = to_ov5693_sensor(sd);
  4707. + struct i2c_client *client = v4l2_get_subdevdata(sd);
  4708. + int ret = 0;
  4709. + int idx;
  4710. + int cnt;
  4711. +
  4712. + if (format->pad)
  4713. + return -EINVAL;
  4714. + if (!fmt)
  4715. + return -EINVAL;
  4716. +
  4717. + mutex_lock(&dev->input_lock);
  4718. + idx = nearest_resolution_index(fmt->width, fmt->height);
  4719. + if (idx == -1) {
  4720. + /* return the largest resolution */
  4721. + fmt->width = ov5693_res[N_RES - 1].width;
  4722. + fmt->height = ov5693_res[N_RES - 1].height;
  4723. + } else {
  4724. + fmt->width = ov5693_res[idx].width;
  4725. + fmt->height = ov5693_res[idx].height;
  4726. + }
  4727. +
  4728. + fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
  4729. + if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
  4730. + cfg->try_fmt = *fmt;
  4731. + ret = 0;
  4732. + goto mutex_unlock;
  4733. + }
  4734. +
  4735. + dev->fmt_idx = get_resolution_index(fmt->width, fmt->height);
  4736. + if (dev->fmt_idx == -1) {
  4737. + dev_err(&client->dev, "get resolution fail\n");
  4738. + ret = -EINVAL;
  4739. + goto mutex_unlock;
  4740. + }
  4741. +
  4742. + for (cnt = 0; cnt < OV5693_POWER_UP_RETRY_NUM; cnt++) {
  4743. + ret = power_up(sd);
  4744. + if (ret) {
  4745. + dev_err(&client->dev, "power up failed\n");
  4746. + continue;
  4747. + }
  4748. +
  4749. + mutex_unlock(&dev->input_lock);
  4750. + ov5693_init(sd);
  4751. + mutex_lock(&dev->input_lock);
  4752. + ret = startup(sd);
  4753. + if (ret)
  4754. + dev_err(&client->dev, " startup() FAILED!\n");
  4755. + else
  4756. + break;
  4757. + }
  4758. + if (cnt == OV5693_POWER_UP_RETRY_NUM) {
  4759. + dev_err(&client->dev, "power up failed, gave up\n");
  4760. + goto mutex_unlock;
  4761. + }
  4762. +
  4763. +
  4764. +
  4765. + /*
  4766. + * After sensor settings are set to HW, sometimes stream is started.
  4767. + * This would cause ISP timeout because ISP is not ready to receive
  4768. + * data yet. So add stop streaming here.
  4769. + */
  4770. + ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_SW_STREAM,
  4771. + OV5693_STOP_STREAMING);
  4772. + if (ret)
  4773. + dev_warn(&client->dev, "ov5693 stream off err\n");
  4774. +
  4775. +mutex_unlock:
  4776. + mutex_unlock(&dev->input_lock);
  4777. + return ret;
  4778. +}
  4779. +
  4780. +static const struct v4l2_rect *
  4781. +__ov5693_get_pad_crop(struct ov5693_device *dev, struct v4l2_subdev_pad_config *cfg,
  4782. + unsigned int pad, enum v4l2_subdev_format_whence which)
  4783. +{
  4784. + switch (which) {
  4785. + case V4L2_SUBDEV_FORMAT_TRY:
  4786. + return v4l2_subdev_get_try_crop(&dev->sd, cfg, pad);
  4787. + case V4L2_SUBDEV_FORMAT_ACTIVE:
  4788. + return &dev->mode->crop;
  4789. + }
  4790. +
  4791. + return NULL;
  4792. +}
  4793. +static int ov5693_get_selection(struct v4l2_subdev *sd,
  4794. + struct v4l2_subdev_pad_config *cfg,
  4795. + struct v4l2_subdev_selection *sel)
  4796. +{
  4797. + switch (sel->target) {
  4798. + case V4L2_SEL_TGT_CROP: {
  4799. + struct ov5693_device *dev = to_ov5693_sensor(sd);
  4800. +
  4801. + mutex_lock(&dev->input_lock);
  4802. + sel->r = *__ov5693_get_pad_crop(dev, cfg, sel->pad,
  4803. + sel->which);
  4804. + mutex_unlock(&dev->input_lock);
  4805. +
  4806. + return 0;
  4807. + }
  4808. +
  4809. + case V4L2_SEL_TGT_NATIVE_SIZE:
  4810. + sel->r.top = 0;
  4811. + sel->r.left = 0;
  4812. + sel->r.width = OV5693_NATIVE_WIDTH;
  4813. + sel->r.height = OV5693_NATIVE_HEIGHT;
  4814. +
  4815. + return 0;
  4816. +
  4817. + case V4L2_SEL_TGT_CROP_DEFAULT:
  4818. + sel->r.top = OV5693_PIXEL_ARRAY_TOP;
  4819. + sel->r.left = OV5693_PIXEL_ARRAY_LEFT;
  4820. + sel->r.width = OV5693_PIXEL_ARRAY_WIDTH;
  4821. + sel->r.height = OV5693_PIXEL_ARRAY_HEIGHT;
  4822. +
  4823. + return 0;
  4824. + }
  4825. +
  4826. + return -EINVAL;
  4827. +}
  4828. +
  4829. +static int ov5693_get_fmt(struct v4l2_subdev *sd,
  4830. + struct v4l2_subdev_pad_config *cfg,
  4831. + struct v4l2_subdev_format *format)
  4832. +{
  4833. + struct v4l2_mbus_framefmt *fmt = &format->format;
  4834. + struct ov5693_device *dev = to_ov5693_sensor(sd);
  4835. +
  4836. + if (format->pad)
  4837. + return -EINVAL;
  4838. +
  4839. + if (!fmt)
  4840. + return -EINVAL;
  4841. +
  4842. + fmt->width = ov5693_res[dev->fmt_idx].width;
  4843. + fmt->height = ov5693_res[dev->fmt_idx].height;
  4844. + fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
  4845. +
  4846. + return 0;
  4847. +}
  4848. +
  4849. +static int ov5693_detect(struct i2c_client *client)
  4850. +{
  4851. + struct i2c_adapter *adapter = client->adapter;
  4852. + u16 high, low;
  4853. + int ret;
  4854. + u16 id;
  4855. + u8 revision;
  4856. +
  4857. + if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
  4858. + return -ENODEV;
  4859. +
  4860. + ret = ov5693_read_reg(client, OV5693_8BIT,
  4861. + OV5693_SC_CMMN_CHIP_ID_H, &high);
  4862. + if (ret) {
  4863. + dev_err(&client->dev, "sensor_id_high = 0x%x\n", high);
  4864. + return -ENODEV;
  4865. + }
  4866. + ret = ov5693_read_reg(client, OV5693_8BIT,
  4867. + OV5693_SC_CMMN_CHIP_ID_L, &low);
  4868. + id = ((((u16)high) << 8) | (u16)low);
  4869. +
  4870. + if (id != OV5693_ID) {
  4871. + dev_err(&client->dev, "sensor ID error 0x%x\n", id);
  4872. + return -ENODEV;
  4873. + }
  4874. +
  4875. + ret = ov5693_read_reg(client, OV5693_8BIT,
  4876. + OV5693_SC_CMMN_SUB_ID, &high);
  4877. + revision = (u8)high & 0x0f;
  4878. +
  4879. + dev_info(&client->dev, "sensor_revision = 0x%x\n", revision);
  4880. + dev_info(&client->dev, "sensor_address = 0x%02x\n", client->addr);
  4881. + dev_info(&client->dev, "detect ov5693 success\n");
  4882. + return 0;
  4883. +}
  4884. +
  4885. +static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
  4886. +{
  4887. + struct ov5693_device *dev = to_ov5693_sensor(sd);
  4888. + struct i2c_client *client = v4l2_get_subdevdata(sd);
  4889. + int ret;
  4890. +
  4891. + mutex_lock(&dev->input_lock);
  4892. +
  4893. + /* power_on() here before streaming for regular PCs. */
  4894. + if (enable) {
  4895. + ret = power_up(sd);
  4896. + if (ret) {
  4897. + dev_err(&client->dev, "sensor power-up error\n");
  4898. + goto out;
  4899. + }
  4900. + }
  4901. +
  4902. + ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_SW_STREAM,
  4903. + enable ? OV5693_START_STREAMING :
  4904. + OV5693_STOP_STREAMING);
  4905. +
  4906. + /* power_off() here after streaming for regular PCs. */
  4907. + if (!enable)
  4908. + power_down(sd);
  4909. +
  4910. +out:
  4911. + mutex_unlock(&dev->input_lock);
  4912. +
  4913. + return ret;
  4914. +}
  4915. +
  4916. +static int ov5693_s_config(struct v4l2_subdev *sd, int irq)
  4917. +{
  4918. + struct ov5693_device *dev = to_ov5693_sensor(sd);
  4919. + struct i2c_client *client = v4l2_get_subdevdata(sd);
  4920. + int ret = 0;
  4921. +
  4922. + mutex_lock(&dev->input_lock);
  4923. + ret = power_up(sd);
  4924. + if (ret) {
  4925. + dev_err(&client->dev, "ov5693 power-up err.\n");
  4926. + goto fail_power_on;
  4927. + }
  4928. +
  4929. + if (!dev->vcm)
  4930. + dev->vcm = vcm_detect(client);
  4931. +
  4932. + /* config & detect sensor */
  4933. + ret = ov5693_detect(client);
  4934. + if (ret) {
  4935. + dev_err(&client->dev, "ov5693_detect err s_config.\n");
  4936. + goto fail_power_on;
  4937. + }
  4938. +
  4939. + dev->otp_data = ov5693_otp_read(sd);
  4940. +
  4941. + /* turn off sensor, after probed */
  4942. + ret = power_down(sd);
  4943. + if (ret) {
  4944. + dev_err(&client->dev, "ov5693 power-off err.\n");
  4945. + goto fail_power_on;
  4946. + }
  4947. + mutex_unlock(&dev->input_lock);
  4948. +
  4949. + return ret;
  4950. +
  4951. +fail_power_on:
  4952. + power_down(sd);
  4953. + dev_err(&client->dev, "sensor power-gating failed\n");
  4954. + mutex_unlock(&dev->input_lock);
  4955. + return ret;
  4956. +}
  4957. +
  4958. +static int ov5693_g_frame_interval(struct v4l2_subdev *sd,
  4959. + struct v4l2_subdev_frame_interval *interval)
  4960. +{
  4961. + struct ov5693_device *dev = to_ov5693_sensor(sd);
  4962. +
  4963. + interval->interval.numerator = 1;
  4964. + interval->interval.denominator = ov5693_res[dev->fmt_idx].fps;
  4965. +
  4966. + return 0;
  4967. +}
  4968. +
  4969. +static int ov5693_enum_mbus_code(struct v4l2_subdev *sd,
  4970. + struct v4l2_subdev_pad_config *cfg,
  4971. + struct v4l2_subdev_mbus_code_enum *code)
  4972. +{
  4973. + if (code->index >= MAX_FMTS)
  4974. + return -EINVAL;
  4975. +
  4976. + code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
  4977. + return 0;
  4978. +}
  4979. +
  4980. +static int ov5693_enum_frame_size(struct v4l2_subdev *sd,
  4981. + struct v4l2_subdev_pad_config *cfg,
  4982. + struct v4l2_subdev_frame_size_enum *fse)
  4983. +{
  4984. + int index = fse->index;
  4985. +
  4986. + if (index >= N_RES)
  4987. + return -EINVAL;
  4988. +
  4989. + fse->min_width = ov5693_res[index].width;
  4990. + fse->min_height = ov5693_res[index].height;
  4991. + fse->max_width = ov5693_res[index].width;
  4992. + fse->max_height = ov5693_res[index].height;
  4993. +
  4994. + return 0;
  4995. +}
  4996. +
  4997. +static const struct v4l2_subdev_video_ops ov5693_video_ops = {
  4998. + .s_stream = ov5693_s_stream,
  4999. + .g_frame_interval = ov5693_g_frame_interval,
  5000. +};
  5001. +
  5002. +static const struct v4l2_subdev_core_ops ov5693_core_ops = {
  5003. + .s_power = ov5693_s_power,
  5004. +};
  5005. +
  5006. +static const struct v4l2_subdev_pad_ops ov5693_pad_ops = {
  5007. + .enum_mbus_code = ov5693_enum_mbus_code,
  5008. + .enum_frame_size = ov5693_enum_frame_size,
  5009. + .get_fmt = ov5693_get_fmt,
  5010. + .set_fmt = ov5693_set_fmt,
  5011. + .get_selection = ov5693_get_selection,
  5012. +};
  5013. +
  5014. +static const struct v4l2_subdev_ops ov5693_ops = {
  5015. + .core = &ov5693_core_ops,
  5016. + .video = &ov5693_video_ops,
  5017. + .pad = &ov5693_pad_ops,
  5018. +};
  5019. +
  5020. +static int ov5693_remove(struct i2c_client *client)
  5021. +{
  5022. + struct v4l2_subdev *sd = i2c_get_clientdata(client);
  5023. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  5024. + unsigned int i = OV5693_NUM_SUPPLIES;
  5025. +
  5026. + dev_info(&client->dev, "%s...\n", __func__);
  5027. +
  5028. + gpiod_put(ov5693->reset);
  5029. + gpiod_put(ov5693->indicator_led);
  5030. + while (i--)
  5031. + regulator_put(ov5693->supplies[i].consumer);
  5032. +
  5033. + v4l2_async_unregister_subdev(sd);
  5034. +
  5035. + media_entity_cleanup(&ov5693->sd.entity);
  5036. + v4l2_ctrl_handler_free(&ov5693->ctrl_handler);
  5037. + kfree(ov5693);
  5038. +
  5039. + return 0;
  5040. +}
  5041. +
  5042. +static int ov5693_init_controls(struct ov5693_device *ov5693)
  5043. +{
  5044. + struct i2c_client *client = v4l2_get_subdevdata(&ov5693->sd);
  5045. + const struct v4l2_ctrl_ops *ops = &ov5693_ctrl_ops;
  5046. + struct v4l2_ctrl *ctrl;
  5047. + unsigned int i;
  5048. + int ret;
  5049. + int hblank;
  5050. +
  5051. + ret = v4l2_ctrl_handler_init(&ov5693->ctrl_handler,
  5052. + ARRAY_SIZE(ov5693_controls));
  5053. + if (ret) {
  5054. + ov5693_remove(client);
  5055. + return ret;
  5056. + }
  5057. +
  5058. + for (i = 0; i < ARRAY_SIZE(ov5693_controls); i++)
  5059. + v4l2_ctrl_new_custom(&ov5693->ctrl_handler,
  5060. + &ov5693_controls[i],
  5061. + NULL);
  5062. +
  5063. + /* link freq */
  5064. + ctrl = v4l2_ctrl_new_int_menu(&ov5693->ctrl_handler, NULL,
  5065. + V4L2_CID_LINK_FREQ,
  5066. + 0, 0, link_freq_menu_items);
  5067. + if (ctrl)
  5068. + ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  5069. +
  5070. + /* pixel rate */
  5071. + v4l2_ctrl_new_std(&ov5693->ctrl_handler, NULL, V4L2_CID_PIXEL_RATE,
  5072. + 0, OV5693_PIXEL_RATE, 1, OV5693_PIXEL_RATE);
  5073. +
  5074. + if (ov5693->ctrl_handler.error) {
  5075. + ov5693_remove(client);
  5076. + return ov5693->ctrl_handler.error;
  5077. + }
  5078. +
  5079. + /* Exposure */
  5080. +
  5081. + v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops, V4L2_CID_EXPOSURE, 16, 1048575, 16,
  5082. + 512);
  5083. +
  5084. + /* Gain */
  5085. +
  5086. + v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops, V4L2_CID_ANALOGUE_GAIN, 1, 1023, 1, 128);
  5087. + v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops, V4L2_CID_DIGITAL_GAIN, 1, 3999, 1, 1000);
  5088. +
  5089. + /* Flip */
  5090. +
  5091. + v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops, V4L2_CID_HFLIP, 0, 1, 1, 0);
  5092. + v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops, V4L2_CID_VFLIP, 0, 1, 1, 0);
  5093. +
  5094. + hblank = OV5693_PPL_DEFAULT - ov5693->mode->width;
  5095. + ov5693->hblank = v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops,
  5096. + V4L2_CID_HBLANK, hblank, hblank,
  5097. + 1, hblank);
  5098. + if (ov5693->hblank)
  5099. + ov5693->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  5100. +
  5101. + /* Use same lock for controls as for everything else. */
  5102. + ov5693->ctrl_handler.lock = &ov5693->input_lock;
  5103. + ov5693->sd.ctrl_handler = &ov5693->ctrl_handler;
  5104. +
  5105. + return 0;
  5106. +}
  5107. +
  5108. +static int ov5693_configure_gpios(struct ov5693_device *ov5693)
  5109. +{
  5110. + ov5693->reset = gpiod_get_index(&ov5693->i2c_client->dev, "reset", 0,
  5111. + GPIOD_OUT_HIGH);
  5112. + if (IS_ERR(ov5693->reset)) {
  5113. + dev_err(&ov5693->i2c_client->dev, "Couldn't find reset GPIO\n");
  5114. + return -EINVAL;
  5115. + }
  5116. +
  5117. + ov5693->indicator_led = gpiod_get_index_optional(&ov5693->i2c_client->dev, "indicator-led", 0,
  5118. + GPIOD_OUT_HIGH);
  5119. + if (IS_ERR(ov5693->indicator_led)) {
  5120. + dev_err(&ov5693->i2c_client->dev, "Couldn't find indicator-led GPIO\n");
  5121. + return -EINVAL;
  5122. + }
  5123. +
  5124. + return 0;
  5125. +}
  5126. +
  5127. +static int ov5693_get_regulators(struct ov5693_device *ov5693)
  5128. +{
  5129. + unsigned int i;
  5130. +
  5131. + for (i = 0; i < OV5693_NUM_SUPPLIES; i++)
  5132. + ov5693->supplies[i].supply = ov5693_supply_names[i];
  5133. +
  5134. + return regulator_bulk_get(&ov5693->i2c_client->dev,
  5135. + OV5693_NUM_SUPPLIES,
  5136. + ov5693->supplies);
  5137. +}
  5138. +
  5139. +static int ov5693_probe(struct i2c_client *client)
  5140. +{
  5141. + struct ov5693_device *ov5693;
  5142. + int ret = 0;
  5143. +
  5144. + dev_info(&client->dev, "%s() called", __func__);
  5145. +
  5146. + ov5693 = kzalloc(sizeof(*ov5693), GFP_KERNEL);
  5147. + if (!ov5693)
  5148. + return -ENOMEM;
  5149. +
  5150. + ov5693->i2c_client = client;
  5151. +
  5152. + /* check if VCM device exists */
  5153. + /* TODO: read from SSDB */
  5154. + ov5693->has_vcm = false;
  5155. +
  5156. + mutex_init(&ov5693->input_lock);
  5157. +
  5158. + v4l2_i2c_subdev_init(&ov5693->sd, client, &ov5693_ops);
  5159. +
  5160. + ov5693->clk = devm_clk_get(&client->dev, "xvclk");
  5161. + if (IS_ERR(ov5693->clk)) {
  5162. + dev_err(&client->dev, "Error getting clock\n");
  5163. + return -EINVAL;
  5164. + }
  5165. +
  5166. + ret = ov5693_configure_gpios(ov5693);
  5167. + if (ret)
  5168. + goto out_free;
  5169. +
  5170. + ret = ov5693_get_regulators(ov5693);
  5171. + if (ret)
  5172. + goto out_put_reset;
  5173. +
  5174. + ret = ov5693_s_config(&ov5693->sd, client->irq);
  5175. + if (ret)
  5176. + goto out_put_reset;
  5177. +
  5178. + ov5693->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  5179. + ov5693->pad.flags = MEDIA_PAD_FL_SOURCE;
  5180. + ov5693->format.code = MEDIA_BUS_FMT_SBGGR10_1X10;
  5181. + ov5693->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
  5182. + ov5693->mode = &ov5693_res_video[N_RES_VIDEO-1];
  5183. +
  5184. + ret = ov5693_init_controls(ov5693);
  5185. + if (ret)
  5186. + ov5693_remove(client);
  5187. +
  5188. + ret = media_entity_pads_init(&ov5693->sd.entity, 1, &ov5693->pad);
  5189. + if (ret)
  5190. + ov5693_remove(client);
  5191. +
  5192. + ret = v4l2_async_register_subdev_sensor_common(&ov5693->sd);
  5193. + if (ret) {
  5194. + dev_err(&client->dev, "failed to register V4L2 subdev: %d", ret);
  5195. + goto media_entity_cleanup;
  5196. + }
  5197. +
  5198. + return ret;
  5199. +
  5200. +media_entity_cleanup:
  5201. + media_entity_cleanup(&ov5693->sd.entity);
  5202. +out_put_reset:
  5203. + gpiod_put(ov5693->reset);
  5204. +out_free:
  5205. + v4l2_device_unregister_subdev(&ov5693->sd);
  5206. + kfree(ov5693);
  5207. + return ret;
  5208. +}
  5209. +
  5210. +static const struct acpi_device_id ov5693_acpi_match[] = {
  5211. + {"INT33BE"},
  5212. + {},
  5213. +};
  5214. +MODULE_DEVICE_TABLE(acpi, ov5693_acpi_match);
  5215. +
  5216. +static struct i2c_driver ov5693_driver = {
  5217. + .driver = {
  5218. + .name = "ov5693",
  5219. + .acpi_match_table = ov5693_acpi_match,
  5220. + },
  5221. + .probe_new = ov5693_probe,
  5222. + .remove = ov5693_remove,
  5223. +};
  5224. +module_i2c_driver(ov5693_driver);
  5225. +
  5226. +MODULE_DESCRIPTION("A low-level driver for OmniVision 5693 sensors");
  5227. +MODULE_LICENSE("GPL");
  5228. diff --git a/drivers/media/i2c/ov5693.h b/drivers/media/i2c/ov5693.h
  5229. new file mode 100644
  5230. index 000000000000..9a508e1f3624
  5231. --- /dev/null
  5232. +++ b/drivers/media/i2c/ov5693.h
  5233. @@ -0,0 +1,1430 @@
  5234. +/* SPDX-License-Identifier: GPL-2.0 */
  5235. +/*
  5236. + * Support for OmniVision OV5693 5M camera sensor.
  5237. + *
  5238. + * Copyright (c) 2013 Intel Corporation. All Rights Reserved.
  5239. + *
  5240. + * This program is free software; you can redistribute it and/or
  5241. + * modify it under the terms of the GNU General Public License version
  5242. + * 2 as published by the Free Software Foundation.
  5243. + *
  5244. + * This program is distributed in the hope that it will be useful,
  5245. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5246. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5247. + * GNU General Public License for more details.
  5248. + *
  5249. + *
  5250. + */
  5251. +
  5252. +#ifndef __OV5693_H__
  5253. +#define __OV5693_H__
  5254. +#include <linux/kernel.h>
  5255. +#include <linux/types.h>
  5256. +#include <linux/i2c.h>
  5257. +#include <linux/delay.h>
  5258. +#include <linux/videodev2.h>
  5259. +#include <linux/spinlock.h>
  5260. +#include <media/v4l2-subdev.h>
  5261. +#include <media/v4l2-device.h>
  5262. +#include <media/v4l2-ctrls.h>
  5263. +#include <linux/v4l2-mediabus.h>
  5264. +#include <media/media-entity.h>
  5265. +
  5266. +#define OV5693_HID "INT33BE"
  5267. +
  5268. +/*
  5269. + * FIXME: non-preview resolutions are currently broken
  5270. + */
  5271. +#define ENABLE_NON_PREVIEW 1
  5272. +
  5273. +#define OV5693_POWER_UP_RETRY_NUM 5
  5274. +
  5275. +/* Defines for register writes and register array processing */
  5276. +#define I2C_MSG_LENGTH 0x2
  5277. +#define I2C_RETRY_COUNT 5
  5278. +
  5279. +#define OV5693_FOCAL_LENGTH_NUM 334 /*3.34mm*/
  5280. +#define OV5693_FOCAL_LENGTH_DEM 100
  5281. +#define OV5693_F_NUMBER_DEFAULT_NUM 24
  5282. +#define OV5693_F_NUMBER_DEM 10
  5283. +
  5284. +#define MAX_FMTS 1
  5285. +
  5286. +/* sensor_mode_data read_mode adaptation */
  5287. +#define OV5693_READ_MODE_BINNING_ON 0x0400
  5288. +#define OV5693_READ_MODE_BINNING_OFF 0x00
  5289. +#define OV5693_INTEGRATION_TIME_MARGIN 8
  5290. +
  5291. +#define OV5693_MAX_EXPOSURE_VALUE 0xFFF1
  5292. +#define OV5693_MAX_GAIN_VALUE 0xFF
  5293. +
  5294. +/*
  5295. + * focal length bits definition:
  5296. + * bits 31-16: numerator, bits 15-0: denominator
  5297. + */
  5298. +#define OV5693_FOCAL_LENGTH_DEFAULT 0x1B70064
  5299. +
  5300. +/*
  5301. + * current f-number bits definition:
  5302. + * bits 31-16: numerator, bits 15-0: denominator
  5303. + */
  5304. +#define OV5693_F_NUMBER_DEFAULT 0x18000a
  5305. +
  5306. +/*
  5307. + * f-number range bits definition:
  5308. + * bits 31-24: max f-number numerator
  5309. + * bits 23-16: max f-number denominator
  5310. + * bits 15-8: min f-number numerator
  5311. + * bits 7-0: min f-number denominator
  5312. + */
  5313. +#define OV5693_F_NUMBER_RANGE 0x180a180a
  5314. +#define OV5693_ID 0x5690
  5315. +
  5316. +#define OV5693_FINE_INTG_TIME_MIN 0
  5317. +#define OV5693_FINE_INTG_TIME_MAX_MARGIN 0
  5318. +#define OV5693_COARSE_INTG_TIME_MIN 1
  5319. +#define OV5693_COARSE_INTG_TIME_MAX_MARGIN 6
  5320. +
  5321. +#define OV5693_BIN_FACTOR_MAX 4
  5322. +/*
  5323. + * OV5693 System control registers
  5324. + */
  5325. +#define OV5693_SW_SLEEP 0x0100
  5326. +#define OV5693_SW_RESET 0x0103
  5327. +#define OV5693_SW_STREAM 0x0100
  5328. +
  5329. +#define OV5693_SC_CMMN_CHIP_ID_H 0x300A
  5330. +#define OV5693_SC_CMMN_CHIP_ID_L 0x300B
  5331. +#define OV5693_SC_CMMN_SCCB_ID 0x300C
  5332. +#define OV5693_SC_CMMN_SUB_ID 0x302A /* process, version*/
  5333. +/*Bit[7:4] Group control, Bit[3:0] Group ID*/
  5334. +#define OV5693_GROUP_ACCESS 0x3208
  5335. +/*
  5336. +*Bit[3:0] Bit[19:16] of exposure,
  5337. +*remaining 16 bits lies in Reg0x3501&Reg0x3502
  5338. +*/
  5339. +#define OV5693_EXPOSURE_H 0x3500
  5340. +#define OV5693_EXPOSURE_M 0x3501
  5341. +#define OV5693_EXPOSURE_L 0x3502
  5342. +/*Bit[1:0] means Bit[9:8] of gain*/
  5343. +#define OV5693_AGC_H 0x350A
  5344. +#define OV5693_AGC_L 0x350B /*Bit[7:0] of gain*/
  5345. +
  5346. +#define OV5693_HORIZONTAL_START_H 0x3800 /*Bit[11:8]*/
  5347. +#define OV5693_HORIZONTAL_START_L 0x3801 /*Bit[7:0]*/
  5348. +#define OV5693_VERTICAL_START_H 0x3802 /*Bit[11:8]*/
  5349. +#define OV5693_VERTICAL_START_L 0x3803 /*Bit[7:0]*/
  5350. +#define OV5693_HORIZONTAL_END_H 0x3804 /*Bit[11:8]*/
  5351. +#define OV5693_HORIZONTAL_END_L 0x3805 /*Bit[7:0]*/
  5352. +#define OV5693_VERTICAL_END_H 0x3806 /*Bit[11:8]*/
  5353. +#define OV5693_VERTICAL_END_L 0x3807 /*Bit[7:0]*/
  5354. +#define OV5693_HORIZONTAL_OUTPUT_SIZE_H 0x3808 /*Bit[3:0]*/
  5355. +#define OV5693_HORIZONTAL_OUTPUT_SIZE_L 0x3809 /*Bit[7:0]*/
  5356. +#define OV5693_VERTICAL_OUTPUT_SIZE_H 0x380a /*Bit[3:0]*/
  5357. +#define OV5693_VERTICAL_OUTPUT_SIZE_L 0x380b /*Bit[7:0]*/
  5358. +/*High 8-bit, and low 8-bit HTS address is 0x380d*/
  5359. +#define OV5693_TIMING_HTS_H 0x380C
  5360. +/*High 8-bit, and low 8-bit HTS address is 0x380d*/
  5361. +#define OV5693_TIMING_HTS_L 0x380D
  5362. +/*High 8-bit, and low 8-bit HTS address is 0x380f*/
  5363. +#define OV5693_TIMING_VTS_H 0x380e
  5364. +/*High 8-bit, and low 8-bit HTS address is 0x380f*/
  5365. +#define OV5693_TIMING_VTS_L 0x380f
  5366. +
  5367. +#define OV5693_MWB_RED_GAIN_H 0x3400
  5368. +#define OV5693_MWB_GREEN_GAIN_H 0x3402
  5369. +#define OV5693_MWB_BLUE_GAIN_H 0x3404
  5370. +#define OV5693_MWB_GAIN_MAX 0x0fff
  5371. +
  5372. +#define OV5693_START_STREAMING 0x01
  5373. +#define OV5693_STOP_STREAMING 0x00
  5374. +
  5375. +#define VCM_ADDR 0x0c
  5376. +#define VCM_CODE_MSB 0x04
  5377. +
  5378. +#define OV5693_INVALID_CONFIG 0xffffffff
  5379. +
  5380. +#define OV5693_VCM_SLEW_STEP 0x30F0
  5381. +#define OV5693_VCM_SLEW_STEP_MAX 0x7
  5382. +#define OV5693_VCM_SLEW_STEP_MASK 0x7
  5383. +#define OV5693_VCM_CODE 0x30F2
  5384. +#define OV5693_VCM_SLEW_TIME 0x30F4
  5385. +#define OV5693_VCM_SLEW_TIME_MAX 0xffff
  5386. +#define OV5693_VCM_ENABLE 0x8000
  5387. +
  5388. +#define OV5693_VCM_MAX_FOCUS_NEG -1023
  5389. +#define OV5693_VCM_MAX_FOCUS_POS 1023
  5390. +
  5391. +#define DLC_ENABLE 1
  5392. +#define DLC_DISABLE 0
  5393. +#define VCM_PROTECTION_OFF 0xeca3
  5394. +#define VCM_PROTECTION_ON 0xdc51
  5395. +#define VCM_DEFAULT_S 0x0
  5396. +#define vcm_step_s(a) (u8)(a & 0xf)
  5397. +#define vcm_step_mclk(a) (u8)((a >> 4) & 0x3)
  5398. +#define vcm_dlc_mclk(dlc, mclk) (u16)((dlc << 3) | mclk | 0xa104)
  5399. +#define vcm_tsrc(tsrc) (u16)(tsrc << 3 | 0xf200)
  5400. +#define vcm_val(data, s) (u16)(data << 4 | s)
  5401. +#define DIRECT_VCM vcm_dlc_mclk(0, 0)
  5402. +
  5403. +/* Defines for OTP Data Registers */
  5404. +#define OV5693_FRAME_OFF_NUM 0x4202
  5405. +#define OV5693_OTP_BYTE_MAX 32 //change to 32 as needed by otpdata
  5406. +#define OV5693_OTP_SHORT_MAX 16
  5407. +#define OV5693_OTP_START_ADDR 0x3D00
  5408. +#define OV5693_OTP_END_ADDR 0x3D0F
  5409. +#define OV5693_OTP_DATA_SIZE 320
  5410. +#define OV5693_OTP_PROGRAM_REG 0x3D80
  5411. +#define OV5693_OTP_READ_REG 0x3D81 // 1:Enable 0:disable
  5412. +#define OV5693_OTP_BANK_REG 0x3D84 //otp bank and mode
  5413. +#define OV5693_OTP_READY_REG_DONE 1
  5414. +#define OV5693_OTP_BANK_MAX 28
  5415. +#define OV5693_OTP_BANK_SIZE 16 //16 bytes per bank
  5416. +#define OV5693_OTP_READ_ONETIME 16
  5417. +#define OV5693_OTP_MODE_READ 1
  5418. +
  5419. +/* link freq and pixel rate required for IPU3 */
  5420. +#define OV5693_LINK_FREQ_640MHZ 640000000
  5421. +/* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample
  5422. + * To avoid integer overflow, dividing by bits_per_sample first.
  5423. + */
  5424. +#define OV5693_PIXEL_RATE (OV5693_LINK_FREQ_640MHZ / 10) * 2 * 2
  5425. +static const s64 link_freq_menu_items[] = {
  5426. + OV5693_LINK_FREQ_640MHZ
  5427. +};
  5428. +
  5429. +#define OV5693_NUM_SUPPLIES 2
  5430. +static const char * const ov5693_supply_names[] = {
  5431. + "avdd",
  5432. + "dovdd",
  5433. +};
  5434. +
  5435. +struct regval_list {
  5436. + u16 reg_num;
  5437. + u8 value;
  5438. +};
  5439. +
  5440. +struct ov5693_resolution {
  5441. + u8 *desc;
  5442. + const struct ov5693_reg *regs;
  5443. + int res;
  5444. + int width;
  5445. + int height;
  5446. + int fps;
  5447. + int pix_clk_freq;
  5448. + u16 pixels_per_line;
  5449. + u16 lines_per_frame;
  5450. + u8 bin_factor_x;
  5451. + u8 bin_factor_y;
  5452. + u8 bin_mode;
  5453. + bool used;
  5454. +
  5455. + /* Analog crop rectangle. */
  5456. + struct v4l2_rect crop;
  5457. +};
  5458. +
  5459. +struct ov5693_format {
  5460. + u8 *desc;
  5461. + u32 pixelformat;
  5462. + struct ov5693_reg *regs;
  5463. +};
  5464. +
  5465. +enum vcm_type {
  5466. + VCM_UNKNOWN,
  5467. + VCM_AD5823,
  5468. + VCM_DW9714,
  5469. +};
  5470. +
  5471. +/*
  5472. + * ov5693 device structure.
  5473. + */
  5474. +struct ov5693_device {
  5475. + struct i2c_client *i2c_client;
  5476. + struct v4l2_subdev sd;
  5477. + struct media_pad pad;
  5478. + struct v4l2_mbus_framefmt format;
  5479. + struct mutex input_lock;
  5480. + struct v4l2_ctrl_handler ctrl_handler;
  5481. +
  5482. + struct gpio_desc *reset;
  5483. + struct gpio_desc *indicator_led;
  5484. + struct regulator_bulk_data supplies[OV5693_NUM_SUPPLIES];
  5485. + struct clk *clk;
  5486. +
  5487. + /* Current mode */
  5488. + const struct ov5693_resolution *mode;
  5489. +
  5490. + struct camera_sensor_platform_data *platform_data;
  5491. + ktime_t timestamp_t_focus_abs;
  5492. + int vt_pix_clk_freq_mhz;
  5493. + int fmt_idx;
  5494. + int run_mode;
  5495. + int otp_size;
  5496. + u8 *otp_data;
  5497. + u32 focus;
  5498. + s16 number_of_steps;
  5499. + u8 res;
  5500. + u8 type;
  5501. + bool vcm_update;
  5502. + enum vcm_type vcm;
  5503. +
  5504. + bool has_vcm;
  5505. +
  5506. + struct v4l2_ctrl *hblank;
  5507. +};
  5508. +
  5509. +enum ov5693_tok_type {
  5510. + OV5693_8BIT = 0x0001,
  5511. + OV5693_16BIT = 0x0002,
  5512. + OV5693_32BIT = 0x0004,
  5513. + OV5693_TOK_TERM = 0xf000, /* terminating token for reg list */
  5514. + OV5693_TOK_DELAY = 0xfe00, /* delay token for reg list */
  5515. + OV5693_TOK_MASK = 0xfff0
  5516. +};
  5517. +
  5518. +/**
  5519. + * struct ov5693_reg - MI sensor register format
  5520. + * @type: type of the register
  5521. + * @reg: 16-bit offset to register
  5522. + * @val: 8/16/32-bit register value
  5523. + *
  5524. + * Define a structure for sensor register initialization values
  5525. + */
  5526. +struct ov5693_reg {
  5527. + enum ov5693_tok_type type;
  5528. + u16 reg;
  5529. + u32 val; /* @set value for read/mod/write, @mask */
  5530. +};
  5531. +
  5532. +#define to_ov5693_sensor(x) container_of(x, struct ov5693_device, sd)
  5533. +
  5534. +#define OV5693_MAX_WRITE_BUF_SIZE 30
  5535. +
  5536. +struct ov5693_write_buffer {
  5537. + u16 addr;
  5538. + u8 data[OV5693_MAX_WRITE_BUF_SIZE];
  5539. +};
  5540. +
  5541. +struct ov5693_write_ctrl {
  5542. + int index;
  5543. + struct ov5693_write_buffer buffer;
  5544. +};
  5545. +
  5546. +static struct ov5693_reg const ov5693_global_setting[] = {
  5547. + {OV5693_8BIT, 0x0103, 0x01},
  5548. + {OV5693_8BIT, 0x3001, 0x0a},
  5549. + {OV5693_8BIT, 0x3002, 0x80},
  5550. + {OV5693_8BIT, 0x3006, 0x00},
  5551. + {OV5693_8BIT, 0x3011, 0x21},
  5552. + {OV5693_8BIT, 0x3012, 0x09},
  5553. + {OV5693_8BIT, 0x3013, 0x10},
  5554. + {OV5693_8BIT, 0x3014, 0x00},
  5555. + {OV5693_8BIT, 0x3015, 0x08},
  5556. + {OV5693_8BIT, 0x3016, 0xf0},
  5557. + {OV5693_8BIT, 0x3017, 0xf0},
  5558. + {OV5693_8BIT, 0x3018, 0xf0},
  5559. + {OV5693_8BIT, 0x301b, 0xb4},
  5560. + {OV5693_8BIT, 0x301d, 0x02},
  5561. + {OV5693_8BIT, 0x3021, 0x00},
  5562. + {OV5693_8BIT, 0x3022, 0x01},
  5563. + {OV5693_8BIT, 0x3028, 0x44},
  5564. + {OV5693_8BIT, 0x3098, 0x02},
  5565. + {OV5693_8BIT, 0x3099, 0x19},
  5566. + {OV5693_8BIT, 0x309a, 0x02},
  5567. + {OV5693_8BIT, 0x309b, 0x01},
  5568. + {OV5693_8BIT, 0x309c, 0x00},
  5569. + {OV5693_8BIT, 0x30a0, 0xd2},
  5570. + {OV5693_8BIT, 0x30a2, 0x01},
  5571. + {OV5693_8BIT, 0x30b2, 0x00},
  5572. + {OV5693_8BIT, 0x30b3, 0x7d},
  5573. + {OV5693_8BIT, 0x30b4, 0x03},
  5574. + {OV5693_8BIT, 0x30b5, 0x04},
  5575. + {OV5693_8BIT, 0x30b6, 0x01},
  5576. + {OV5693_8BIT, 0x3104, 0x21},
  5577. + {OV5693_8BIT, 0x3106, 0x00},
  5578. + {OV5693_8BIT, 0x3400, 0x04},
  5579. + {OV5693_8BIT, 0x3401, 0x00},
  5580. + {OV5693_8BIT, 0x3402, 0x04},
  5581. + {OV5693_8BIT, 0x3403, 0x00},
  5582. + {OV5693_8BIT, 0x3404, 0x04},
  5583. + {OV5693_8BIT, 0x3405, 0x00},
  5584. + {OV5693_8BIT, 0x3406, 0x01},
  5585. + {OV5693_8BIT, 0x3500, 0x00},
  5586. + {OV5693_8BIT, 0x3503, 0x07},
  5587. + {OV5693_8BIT, 0x3504, 0x00},
  5588. + {OV5693_8BIT, 0x3505, 0x00},
  5589. + {OV5693_8BIT, 0x3506, 0x00},
  5590. + {OV5693_8BIT, 0x3507, 0x02},
  5591. + {OV5693_8BIT, 0x3508, 0x00},
  5592. + {OV5693_8BIT, 0x3509, 0x10},
  5593. + {OV5693_8BIT, 0x350a, 0x00},
  5594. + {OV5693_8BIT, 0x350b, 0x40},
  5595. + {OV5693_8BIT, 0x3601, 0x0a},
  5596. + {OV5693_8BIT, 0x3602, 0x38},
  5597. + {OV5693_8BIT, 0x3612, 0x80},
  5598. + {OV5693_8BIT, 0x3620, 0x54},
  5599. + {OV5693_8BIT, 0x3621, 0xc7},
  5600. + {OV5693_8BIT, 0x3622, 0x0f},
  5601. + {OV5693_8BIT, 0x3625, 0x10},
  5602. + {OV5693_8BIT, 0x3630, 0x55},
  5603. + {OV5693_8BIT, 0x3631, 0xf4},
  5604. + {OV5693_8BIT, 0x3632, 0x00},
  5605. + {OV5693_8BIT, 0x3633, 0x34},
  5606. + {OV5693_8BIT, 0x3634, 0x02},
  5607. + {OV5693_8BIT, 0x364d, 0x0d},
  5608. + {OV5693_8BIT, 0x364f, 0xdd},
  5609. + {OV5693_8BIT, 0x3660, 0x04},
  5610. + {OV5693_8BIT, 0x3662, 0x10},
  5611. + {OV5693_8BIT, 0x3663, 0xf1},
  5612. + {OV5693_8BIT, 0x3665, 0x00},
  5613. + {OV5693_8BIT, 0x3666, 0x20},
  5614. + {OV5693_8BIT, 0x3667, 0x00},
  5615. + {OV5693_8BIT, 0x366a, 0x80},
  5616. + {OV5693_8BIT, 0x3680, 0xe0},
  5617. + {OV5693_8BIT, 0x3681, 0x00},
  5618. + {OV5693_8BIT, 0x3700, 0x42},
  5619. + {OV5693_8BIT, 0x3701, 0x14},
  5620. + {OV5693_8BIT, 0x3702, 0xa0},
  5621. + {OV5693_8BIT, 0x3703, 0xd8},
  5622. + {OV5693_8BIT, 0x3704, 0x78},
  5623. + {OV5693_8BIT, 0x3705, 0x02},
  5624. + {OV5693_8BIT, 0x370a, 0x00},
  5625. + {OV5693_8BIT, 0x370b, 0x20},
  5626. + {OV5693_8BIT, 0x370c, 0x0c},
  5627. + {OV5693_8BIT, 0x370d, 0x11},
  5628. + {OV5693_8BIT, 0x370e, 0x00},
  5629. + {OV5693_8BIT, 0x370f, 0x40},
  5630. + {OV5693_8BIT, 0x3710, 0x00},
  5631. + {OV5693_8BIT, 0x371a, 0x1c},
  5632. + {OV5693_8BIT, 0x371b, 0x05},
  5633. + {OV5693_8BIT, 0x371c, 0x01},
  5634. + {OV5693_8BIT, 0x371e, 0xa1},
  5635. + {OV5693_8BIT, 0x371f, 0x0c},
  5636. + {OV5693_8BIT, 0x3721, 0x00},
  5637. + {OV5693_8BIT, 0x3724, 0x10},
  5638. + {OV5693_8BIT, 0x3726, 0x00},
  5639. + {OV5693_8BIT, 0x372a, 0x01},
  5640. + {OV5693_8BIT, 0x3730, 0x10},
  5641. + {OV5693_8BIT, 0x3738, 0x22},
  5642. + {OV5693_8BIT, 0x3739, 0xe5},
  5643. + {OV5693_8BIT, 0x373a, 0x50},
  5644. + {OV5693_8BIT, 0x373b, 0x02},
  5645. + {OV5693_8BIT, 0x373c, 0x41},
  5646. + {OV5693_8BIT, 0x373f, 0x02},
  5647. + {OV5693_8BIT, 0x3740, 0x42},
  5648. + {OV5693_8BIT, 0x3741, 0x02},
  5649. + {OV5693_8BIT, 0x3742, 0x18},
  5650. + {OV5693_8BIT, 0x3743, 0x01},
  5651. + {OV5693_8BIT, 0x3744, 0x02},
  5652. + {OV5693_8BIT, 0x3747, 0x10},
  5653. + {OV5693_8BIT, 0x374c, 0x04},
  5654. + {OV5693_8BIT, 0x3751, 0xf0},
  5655. + {OV5693_8BIT, 0x3752, 0x00},
  5656. + {OV5693_8BIT, 0x3753, 0x00},
  5657. + {OV5693_8BIT, 0x3754, 0xc0},
  5658. + {OV5693_8BIT, 0x3755, 0x00},
  5659. + {OV5693_8BIT, 0x3756, 0x1a},
  5660. + {OV5693_8BIT, 0x3758, 0x00},
  5661. + {OV5693_8BIT, 0x3759, 0x0f},
  5662. + {OV5693_8BIT, 0x376b, 0x44},
  5663. + {OV5693_8BIT, 0x375c, 0x04},
  5664. + {OV5693_8BIT, 0x3774, 0x10},
  5665. + {OV5693_8BIT, 0x3776, 0x00},
  5666. + {OV5693_8BIT, 0x377f, 0x08},
  5667. + {OV5693_8BIT, 0x3780, 0x22},
  5668. + {OV5693_8BIT, 0x3781, 0x0c},
  5669. + {OV5693_8BIT, 0x3784, 0x2c},
  5670. + {OV5693_8BIT, 0x3785, 0x1e},
  5671. + {OV5693_8BIT, 0x378f, 0xf5},
  5672. + {OV5693_8BIT, 0x3791, 0xb0},
  5673. + {OV5693_8BIT, 0x3795, 0x00},
  5674. + {OV5693_8BIT, 0x3796, 0x64},
  5675. + {OV5693_8BIT, 0x3797, 0x11},
  5676. + {OV5693_8BIT, 0x3798, 0x30},
  5677. + {OV5693_8BIT, 0x3799, 0x41},
  5678. + {OV5693_8BIT, 0x379a, 0x07},
  5679. + {OV5693_8BIT, 0x379b, 0xb0},
  5680. + {OV5693_8BIT, 0x379c, 0x0c},
  5681. + {OV5693_8BIT, 0x37c5, 0x00},
  5682. + {OV5693_8BIT, 0x37c6, 0x00},
  5683. + {OV5693_8BIT, 0x37c7, 0x00},
  5684. + {OV5693_8BIT, 0x37c9, 0x00},
  5685. + {OV5693_8BIT, 0x37ca, 0x00},
  5686. + {OV5693_8BIT, 0x37cb, 0x00},
  5687. + {OV5693_8BIT, 0x37de, 0x00},
  5688. + {OV5693_8BIT, 0x37df, 0x00},
  5689. + {OV5693_8BIT, 0x3800, 0x00},
  5690. + {OV5693_8BIT, 0x3801, 0x00},
  5691. + {OV5693_8BIT, 0x3802, 0x00},
  5692. + {OV5693_8BIT, 0x3804, 0x0a},
  5693. + {OV5693_8BIT, 0x3805, 0x3f},
  5694. + {OV5693_8BIT, 0x3810, 0x00},
  5695. + {OV5693_8BIT, 0x3812, 0x00},
  5696. + {OV5693_8BIT, 0x3823, 0x00},
  5697. + {OV5693_8BIT, 0x3824, 0x00},
  5698. + {OV5693_8BIT, 0x3825, 0x00},
  5699. + {OV5693_8BIT, 0x3826, 0x00},
  5700. + {OV5693_8BIT, 0x3827, 0x00},
  5701. + {OV5693_8BIT, 0x382a, 0x04},
  5702. + {OV5693_8BIT, 0x3a04, 0x06},
  5703. + {OV5693_8BIT, 0x3a05, 0x14},
  5704. + {OV5693_8BIT, 0x3a06, 0x00},
  5705. + {OV5693_8BIT, 0x3a07, 0xfe},
  5706. + {OV5693_8BIT, 0x3b00, 0x00},
  5707. + {OV5693_8BIT, 0x3b02, 0x00},
  5708. + {OV5693_8BIT, 0x3b03, 0x00},
  5709. + {OV5693_8BIT, 0x3b04, 0x00},
  5710. + {OV5693_8BIT, 0x3b05, 0x00},
  5711. + {OV5693_8BIT, 0x3e07, 0x20},
  5712. + {OV5693_8BIT, 0x4000, 0x08},
  5713. + {OV5693_8BIT, 0x4001, 0x04},
  5714. + {OV5693_8BIT, 0x4002, 0x45},
  5715. + {OV5693_8BIT, 0x4004, 0x08},
  5716. + {OV5693_8BIT, 0x4005, 0x18},
  5717. + {OV5693_8BIT, 0x4006, 0x20},
  5718. + {OV5693_8BIT, 0x4008, 0x24},
  5719. + {OV5693_8BIT, 0x4009, 0x10},
  5720. + {OV5693_8BIT, 0x400c, 0x00},
  5721. + {OV5693_8BIT, 0x400d, 0x00},
  5722. + {OV5693_8BIT, 0x4058, 0x00},
  5723. + {OV5693_8BIT, 0x404e, 0x37},
  5724. + {OV5693_8BIT, 0x404f, 0x8f},
  5725. + {OV5693_8BIT, 0x4058, 0x00},
  5726. + {OV5693_8BIT, 0x4101, 0xb2},
  5727. + {OV5693_8BIT, 0x4303, 0x00},
  5728. + {OV5693_8BIT, 0x4304, 0x08},
  5729. + {OV5693_8BIT, 0x4307, 0x31},
  5730. + {OV5693_8BIT, 0x4311, 0x04},
  5731. + {OV5693_8BIT, 0x4315, 0x01},
  5732. + {OV5693_8BIT, 0x4511, 0x05},
  5733. + {OV5693_8BIT, 0x4512, 0x01},
  5734. + {OV5693_8BIT, 0x4806, 0x00},
  5735. + {OV5693_8BIT, 0x4816, 0x52},
  5736. + {OV5693_8BIT, 0x481f, 0x30},
  5737. + {OV5693_8BIT, 0x4826, 0x2c},
  5738. + {OV5693_8BIT, 0x4831, 0x64},
  5739. + {OV5693_8BIT, 0x4d00, 0x04},
  5740. + {OV5693_8BIT, 0x4d01, 0x71},
  5741. + {OV5693_8BIT, 0x4d02, 0xfd},
  5742. + {OV5693_8BIT, 0x4d03, 0xf5},
  5743. + {OV5693_8BIT, 0x4d04, 0x0c},
  5744. + {OV5693_8BIT, 0x4d05, 0xcc},
  5745. + {OV5693_8BIT, 0x4837, 0x0a},
  5746. + {OV5693_8BIT, 0x5000, 0x06},
  5747. + {OV5693_8BIT, 0x5001, 0x01},
  5748. + {OV5693_8BIT, 0x5003, 0x20},
  5749. + {OV5693_8BIT, 0x5046, 0x0a},
  5750. + {OV5693_8BIT, 0x5013, 0x00},
  5751. + {OV5693_8BIT, 0x5046, 0x0a},
  5752. + {OV5693_8BIT, 0x5780, 0x1c},
  5753. + {OV5693_8BIT, 0x5786, 0x20},
  5754. + {OV5693_8BIT, 0x5787, 0x10},
  5755. + {OV5693_8BIT, 0x5788, 0x18},
  5756. + {OV5693_8BIT, 0x578a, 0x04},
  5757. + {OV5693_8BIT, 0x578b, 0x02},
  5758. + {OV5693_8BIT, 0x578c, 0x02},
  5759. + {OV5693_8BIT, 0x578e, 0x06},
  5760. + {OV5693_8BIT, 0x578f, 0x02},
  5761. + {OV5693_8BIT, 0x5790, 0x02},
  5762. + {OV5693_8BIT, 0x5791, 0xff},
  5763. + {OV5693_8BIT, 0x5842, 0x01},
  5764. + {OV5693_8BIT, 0x5843, 0x2b},
  5765. + {OV5693_8BIT, 0x5844, 0x01},
  5766. + {OV5693_8BIT, 0x5845, 0x92},
  5767. + {OV5693_8BIT, 0x5846, 0x01},
  5768. + {OV5693_8BIT, 0x5847, 0x8f},
  5769. + {OV5693_8BIT, 0x5848, 0x01},
  5770. + {OV5693_8BIT, 0x5849, 0x0c},
  5771. + {OV5693_8BIT, 0x5e00, 0x00},
  5772. + {OV5693_8BIT, 0x5e10, 0x0c},
  5773. + {OV5693_8BIT, 0x0100, 0x00},
  5774. + {OV5693_TOK_TERM, 0, 0}
  5775. +};
  5776. +
  5777. +#if ENABLE_NON_PREVIEW
  5778. +/*
  5779. + * 654x496 30fps 17ms VBlanking 2lane 10Bit (Scaling)
  5780. + */
  5781. +static struct ov5693_reg const ov5693_654x496[] = {
  5782. + {OV5693_8BIT, 0x3501, 0x3d},
  5783. + {OV5693_8BIT, 0x3502, 0x00},
  5784. + {OV5693_8BIT, 0x3708, 0xe6},
  5785. + {OV5693_8BIT, 0x3709, 0xc7},
  5786. + {OV5693_8BIT, 0x3803, 0x00},
  5787. + {OV5693_8BIT, 0x3806, 0x07},
  5788. + {OV5693_8BIT, 0x3807, 0xa3},
  5789. + {OV5693_8BIT, 0x3808, 0x02},
  5790. + {OV5693_8BIT, 0x3809, 0x90},
  5791. + {OV5693_8BIT, 0x380a, 0x01},
  5792. + {OV5693_8BIT, 0x380b, 0xf0},
  5793. + {OV5693_8BIT, 0x380c, 0x0a},
  5794. + {OV5693_8BIT, 0x380d, 0x80},
  5795. + {OV5693_8BIT, 0x380e, 0x07},
  5796. + {OV5693_8BIT, 0x380f, 0xc0},
  5797. + {OV5693_8BIT, 0x3811, 0x08},
  5798. + {OV5693_8BIT, 0x3813, 0x02},
  5799. + {OV5693_8BIT, 0x3814, 0x31},
  5800. + {OV5693_8BIT, 0x3815, 0x31},
  5801. + {OV5693_8BIT, 0x3820, 0x04},
  5802. + {OV5693_8BIT, 0x3821, 0x1f},
  5803. + {OV5693_8BIT, 0x5002, 0x80},
  5804. + {OV5693_8BIT, 0x0100, 0x01},
  5805. + {OV5693_TOK_TERM, 0, 0}
  5806. +};
  5807. +
  5808. +/*
  5809. + * 1296x976 30fps 17ms VBlanking 2lane 10Bit (Scaling)
  5810. +*DS from 2592x1952
  5811. +*/
  5812. +static struct ov5693_reg const ov5693_1296x976[] = {
  5813. + {OV5693_8BIT, 0x3501, 0x7b},
  5814. + {OV5693_8BIT, 0x3502, 0x00},
  5815. + {OV5693_8BIT, 0x3708, 0xe2},
  5816. + {OV5693_8BIT, 0x3709, 0xc3},
  5817. +
  5818. + {OV5693_8BIT, 0x3800, 0x00},
  5819. + {OV5693_8BIT, 0x3801, 0x00},
  5820. + {OV5693_8BIT, 0x3802, 0x00},
  5821. + {OV5693_8BIT, 0x3803, 0x00},
  5822. +
  5823. + {OV5693_8BIT, 0x3804, 0x0a},
  5824. + {OV5693_8BIT, 0x3805, 0x3f},
  5825. + {OV5693_8BIT, 0x3806, 0x07},
  5826. + {OV5693_8BIT, 0x3807, 0xA3},
  5827. +
  5828. + {OV5693_8BIT, 0x3808, 0x05},
  5829. + {OV5693_8BIT, 0x3809, 0x10},
  5830. + {OV5693_8BIT, 0x380a, 0x03},
  5831. + {OV5693_8BIT, 0x380b, 0xD0},
  5832. +
  5833. + {OV5693_8BIT, 0x380c, 0x0a},
  5834. + {OV5693_8BIT, 0x380d, 0x80},
  5835. + {OV5693_8BIT, 0x380e, 0x07},
  5836. + {OV5693_8BIT, 0x380f, 0xc0},
  5837. +
  5838. + {OV5693_8BIT, 0x3810, 0x00},
  5839. + {OV5693_8BIT, 0x3811, 0x10},
  5840. + {OV5693_8BIT, 0x3812, 0x00},
  5841. + {OV5693_8BIT, 0x3813, 0x02},
  5842. +
  5843. + {OV5693_8BIT, 0x3814, 0x11}, /*X subsample control*/
  5844. + {OV5693_8BIT, 0x3815, 0x11}, /*Y subsample control*/
  5845. + {OV5693_8BIT, 0x3820, 0x00},
  5846. + {OV5693_8BIT, 0x3821, 0x1e},
  5847. + {OV5693_8BIT, 0x5002, 0x00},
  5848. + {OV5693_8BIT, 0x5041, 0x84}, /* scale is auto enabled */
  5849. + {OV5693_8BIT, 0x0100, 0x01},
  5850. + {OV5693_TOK_TERM, 0, 0}
  5851. +
  5852. +};
  5853. +
  5854. +/*
  5855. + * 336x256 30fps 17ms VBlanking 2lane 10Bit (Scaling)
  5856. + DS from 2564x1956
  5857. + */
  5858. +static struct ov5693_reg const ov5693_336x256[] = {
  5859. + {OV5693_8BIT, 0x3501, 0x3d},
  5860. + {OV5693_8BIT, 0x3502, 0x00},
  5861. + {OV5693_8BIT, 0x3708, 0xe6},
  5862. + {OV5693_8BIT, 0x3709, 0xc7},
  5863. + {OV5693_8BIT, 0x3806, 0x07},
  5864. + {OV5693_8BIT, 0x3807, 0xa3},
  5865. + {OV5693_8BIT, 0x3808, 0x01},
  5866. + {OV5693_8BIT, 0x3809, 0x50},
  5867. + {OV5693_8BIT, 0x380a, 0x01},
  5868. + {OV5693_8BIT, 0x380b, 0x00},
  5869. + {OV5693_8BIT, 0x380c, 0x0a},
  5870. + {OV5693_8BIT, 0x380d, 0x80},
  5871. + {OV5693_8BIT, 0x380e, 0x07},
  5872. + {OV5693_8BIT, 0x380f, 0xc0},
  5873. + {OV5693_8BIT, 0x3811, 0x1E},
  5874. + {OV5693_8BIT, 0x3814, 0x31},
  5875. + {OV5693_8BIT, 0x3815, 0x31},
  5876. + {OV5693_8BIT, 0x3820, 0x04},
  5877. + {OV5693_8BIT, 0x3821, 0x1f},
  5878. + {OV5693_8BIT, 0x5002, 0x80},
  5879. + {OV5693_8BIT, 0x0100, 0x01},
  5880. + {OV5693_TOK_TERM, 0, 0}
  5881. +};
  5882. +
  5883. +/*
  5884. + * 336x256 30fps 17ms VBlanking 2lane 10Bit (Scaling)
  5885. + DS from 2368x1956
  5886. + */
  5887. +static struct ov5693_reg const ov5693_368x304[] = {
  5888. + {OV5693_8BIT, 0x3501, 0x3d},
  5889. + {OV5693_8BIT, 0x3502, 0x00},
  5890. + {OV5693_8BIT, 0x3708, 0xe6},
  5891. + {OV5693_8BIT, 0x3709, 0xc7},
  5892. + {OV5693_8BIT, 0x3808, 0x01},
  5893. + {OV5693_8BIT, 0x3809, 0x70},
  5894. + {OV5693_8BIT, 0x380a, 0x01},
  5895. + {OV5693_8BIT, 0x380b, 0x30},
  5896. + {OV5693_8BIT, 0x380c, 0x0a},
  5897. + {OV5693_8BIT, 0x380d, 0x80},
  5898. + {OV5693_8BIT, 0x380e, 0x07},
  5899. + {OV5693_8BIT, 0x380f, 0xc0},
  5900. + {OV5693_8BIT, 0x3811, 0x80},
  5901. + {OV5693_8BIT, 0x3814, 0x31},
  5902. + {OV5693_8BIT, 0x3815, 0x31},
  5903. + {OV5693_8BIT, 0x3820, 0x04},
  5904. + {OV5693_8BIT, 0x3821, 0x1f},
  5905. + {OV5693_8BIT, 0x5002, 0x80},
  5906. + {OV5693_8BIT, 0x0100, 0x01},
  5907. + {OV5693_TOK_TERM, 0, 0}
  5908. +};
  5909. +
  5910. +/*
  5911. + * ov5693_192x160 30fps 17ms VBlanking 2lane 10Bit (Scaling)
  5912. + DS from 2460x1956
  5913. + */
  5914. +static struct ov5693_reg const ov5693_192x160[] = {
  5915. + {OV5693_8BIT, 0x3501, 0x7b},
  5916. + {OV5693_8BIT, 0x3502, 0x80},
  5917. + {OV5693_8BIT, 0x3708, 0xe2},
  5918. + {OV5693_8BIT, 0x3709, 0xc3},
  5919. + {OV5693_8BIT, 0x3804, 0x0a},
  5920. + {OV5693_8BIT, 0x3805, 0x3f},
  5921. + {OV5693_8BIT, 0x3806, 0x07},
  5922. + {OV5693_8BIT, 0x3807, 0xA3},
  5923. + {OV5693_8BIT, 0x3808, 0x00},
  5924. + {OV5693_8BIT, 0x3809, 0xC0},
  5925. + {OV5693_8BIT, 0x380a, 0x00},
  5926. + {OV5693_8BIT, 0x380b, 0xA0},
  5927. + {OV5693_8BIT, 0x380c, 0x0a},
  5928. + {OV5693_8BIT, 0x380d, 0x80},
  5929. + {OV5693_8BIT, 0x380e, 0x07},
  5930. + {OV5693_8BIT, 0x380f, 0xc0},
  5931. + {OV5693_8BIT, 0x3811, 0x40},
  5932. + {OV5693_8BIT, 0x3813, 0x00},
  5933. + {OV5693_8BIT, 0x3814, 0x31},
  5934. + {OV5693_8BIT, 0x3815, 0x31},
  5935. + {OV5693_8BIT, 0x3820, 0x04},
  5936. + {OV5693_8BIT, 0x3821, 0x1f},
  5937. + {OV5693_8BIT, 0x5002, 0x80},
  5938. + {OV5693_8BIT, 0x0100, 0x01},
  5939. + {OV5693_TOK_TERM, 0, 0}
  5940. +};
  5941. +
  5942. +static struct ov5693_reg const ov5693_736x496[] = {
  5943. + {OV5693_8BIT, 0x3501, 0x3d},
  5944. + {OV5693_8BIT, 0x3502, 0x00},
  5945. + {OV5693_8BIT, 0x3708, 0xe6},
  5946. + {OV5693_8BIT, 0x3709, 0xc7},
  5947. + {OV5693_8BIT, 0x3803, 0x68},
  5948. + {OV5693_8BIT, 0x3806, 0x07},
  5949. + {OV5693_8BIT, 0x3807, 0x3b},
  5950. + {OV5693_8BIT, 0x3808, 0x02},
  5951. + {OV5693_8BIT, 0x3809, 0xe0},
  5952. + {OV5693_8BIT, 0x380a, 0x01},
  5953. + {OV5693_8BIT, 0x380b, 0xf0},
  5954. + {OV5693_8BIT, 0x380c, 0x0a}, /*hts*/
  5955. + {OV5693_8BIT, 0x380d, 0x80},
  5956. + {OV5693_8BIT, 0x380e, 0x07}, /*vts*/
  5957. + {OV5693_8BIT, 0x380f, 0xc0},
  5958. + {OV5693_8BIT, 0x3811, 0x08},
  5959. + {OV5693_8BIT, 0x3813, 0x02},
  5960. + {OV5693_8BIT, 0x3814, 0x31},
  5961. + {OV5693_8BIT, 0x3815, 0x31},
  5962. + {OV5693_8BIT, 0x3820, 0x04},
  5963. + {OV5693_8BIT, 0x3821, 0x1f},
  5964. + {OV5693_8BIT, 0x5002, 0x80},
  5965. + {OV5693_8BIT, 0x0100, 0x01},
  5966. + {OV5693_TOK_TERM, 0, 0}
  5967. +};
  5968. +#endif
  5969. +
  5970. +/*
  5971. +static struct ov5693_reg const ov5693_736x496[] = {
  5972. + {OV5693_8BIT, 0x3501, 0x7b},
  5973. + {OV5693_8BIT, 0x3502, 0x00},
  5974. + {OV5693_8BIT, 0x3708, 0xe6},
  5975. + {OV5693_8BIT, 0x3709, 0xc3},
  5976. + {OV5693_8BIT, 0x3803, 0x00},
  5977. + {OV5693_8BIT, 0x3806, 0x07},
  5978. + {OV5693_8BIT, 0x3807, 0xa3},
  5979. + {OV5693_8BIT, 0x3808, 0x02},
  5980. + {OV5693_8BIT, 0x3809, 0xe0},
  5981. + {OV5693_8BIT, 0x380a, 0x01},
  5982. + {OV5693_8BIT, 0x380b, 0xf0},
  5983. + {OV5693_8BIT, 0x380c, 0x0d},
  5984. + {OV5693_8BIT, 0x380d, 0xb0},
  5985. + {OV5693_8BIT, 0x380e, 0x05},
  5986. + {OV5693_8BIT, 0x380f, 0xf2},
  5987. + {OV5693_8BIT, 0x3811, 0x08},
  5988. + {OV5693_8BIT, 0x3813, 0x02},
  5989. + {OV5693_8BIT, 0x3814, 0x31},
  5990. + {OV5693_8BIT, 0x3815, 0x31},
  5991. + {OV5693_8BIT, 0x3820, 0x01},
  5992. + {OV5693_8BIT, 0x3821, 0x1f},
  5993. + {OV5693_8BIT, 0x5002, 0x00},
  5994. + {OV5693_8BIT, 0x0100, 0x01},
  5995. + {OV5693_TOK_TERM, 0, 0}
  5996. +};
  5997. +*/
  5998. +/*
  5999. + * 976x556 30fps 8.8ms VBlanking 2lane 10Bit (Scaling)
  6000. + */
  6001. +#if ENABLE_NON_PREVIEW
  6002. +static struct ov5693_reg const ov5693_976x556[] = {
  6003. + {OV5693_8BIT, 0x3501, 0x7b},
  6004. + {OV5693_8BIT, 0x3502, 0x00},
  6005. + {OV5693_8BIT, 0x3708, 0xe2},
  6006. + {OV5693_8BIT, 0x3709, 0xc3},
  6007. + {OV5693_8BIT, 0x3803, 0xf0},
  6008. + {OV5693_8BIT, 0x3806, 0x06},
  6009. + {OV5693_8BIT, 0x3807, 0xa7},
  6010. + {OV5693_8BIT, 0x3808, 0x03},
  6011. + {OV5693_8BIT, 0x3809, 0xd0},
  6012. + {OV5693_8BIT, 0x380a, 0x02},
  6013. + {OV5693_8BIT, 0x380b, 0x2C},
  6014. + {OV5693_8BIT, 0x380c, 0x0a},
  6015. + {OV5693_8BIT, 0x380d, 0x80},
  6016. + {OV5693_8BIT, 0x380e, 0x07},
  6017. + {OV5693_8BIT, 0x380f, 0xc0},
  6018. + {OV5693_8BIT, 0x3811, 0x10},
  6019. + {OV5693_8BIT, 0x3813, 0x02},
  6020. + {OV5693_8BIT, 0x3814, 0x11},
  6021. + {OV5693_8BIT, 0x3815, 0x11},
  6022. + {OV5693_8BIT, 0x3820, 0x00},
  6023. + {OV5693_8BIT, 0x3821, 0x1e},
  6024. + {OV5693_8BIT, 0x5002, 0x80},
  6025. + {OV5693_8BIT, 0x0100, 0x01},
  6026. + {OV5693_TOK_TERM, 0, 0}
  6027. +};
  6028. +
  6029. +/*DS from 2624x1492*/
  6030. +static struct ov5693_reg const ov5693_1296x736[] = {
  6031. + {OV5693_8BIT, 0x3501, 0x7b},
  6032. + {OV5693_8BIT, 0x3502, 0x00},
  6033. + {OV5693_8BIT, 0x3708, 0xe2},
  6034. + {OV5693_8BIT, 0x3709, 0xc3},
  6035. +
  6036. + {OV5693_8BIT, 0x3800, 0x00},
  6037. + {OV5693_8BIT, 0x3801, 0x00},
  6038. + {OV5693_8BIT, 0x3802, 0x00},
  6039. + {OV5693_8BIT, 0x3803, 0x00},
  6040. +
  6041. + {OV5693_8BIT, 0x3804, 0x0a},
  6042. + {OV5693_8BIT, 0x3805, 0x3f},
  6043. + {OV5693_8BIT, 0x3806, 0x07},
  6044. + {OV5693_8BIT, 0x3807, 0xA3},
  6045. +
  6046. + {OV5693_8BIT, 0x3808, 0x05},
  6047. + {OV5693_8BIT, 0x3809, 0x10},
  6048. + {OV5693_8BIT, 0x380a, 0x02},
  6049. + {OV5693_8BIT, 0x380b, 0xe0},
  6050. +
  6051. + {OV5693_8BIT, 0x380c, 0x0a},
  6052. + {OV5693_8BIT, 0x380d, 0x80},
  6053. + {OV5693_8BIT, 0x380e, 0x07},
  6054. + {OV5693_8BIT, 0x380f, 0xc0},
  6055. +
  6056. + {OV5693_8BIT, 0x3813, 0xE8},
  6057. +
  6058. + {OV5693_8BIT, 0x3814, 0x11}, /*X subsample control*/
  6059. + {OV5693_8BIT, 0x3815, 0x11}, /*Y subsample control*/
  6060. + {OV5693_8BIT, 0x3820, 0x00},
  6061. + {OV5693_8BIT, 0x3821, 0x1e},
  6062. + {OV5693_8BIT, 0x5002, 0x00},
  6063. + {OV5693_8BIT, 0x5041, 0x84}, /* scale is auto enabled */
  6064. + {OV5693_8BIT, 0x0100, 0x01},
  6065. + {OV5693_TOK_TERM, 0, 0}
  6066. +};
  6067. +
  6068. +static struct ov5693_reg const ov5693_1636p_30fps[] = {
  6069. + {OV5693_8BIT, 0x3501, 0x7b},
  6070. + {OV5693_8BIT, 0x3502, 0x00},
  6071. + {OV5693_8BIT, 0x3708, 0xe2},
  6072. + {OV5693_8BIT, 0x3709, 0xc3},
  6073. + {OV5693_8BIT, 0x3803, 0xf0},
  6074. + {OV5693_8BIT, 0x3806, 0x06},
  6075. + {OV5693_8BIT, 0x3807, 0xa7},
  6076. + {OV5693_8BIT, 0x3808, 0x06},
  6077. + {OV5693_8BIT, 0x3809, 0x64},
  6078. + {OV5693_8BIT, 0x380a, 0x04},
  6079. + {OV5693_8BIT, 0x380b, 0x48},
  6080. + {OV5693_8BIT, 0x380c, 0x0a}, /*hts*/
  6081. + {OV5693_8BIT, 0x380d, 0x80},
  6082. + {OV5693_8BIT, 0x380e, 0x07}, /*vts*/
  6083. + {OV5693_8BIT, 0x380f, 0xc0},
  6084. + {OV5693_8BIT, 0x3811, 0x02},
  6085. + {OV5693_8BIT, 0x3813, 0x02},
  6086. + {OV5693_8BIT, 0x3814, 0x11},
  6087. + {OV5693_8BIT, 0x3815, 0x11},
  6088. + {OV5693_8BIT, 0x3820, 0x00},
  6089. + {OV5693_8BIT, 0x3821, 0x1e},
  6090. + {OV5693_8BIT, 0x5002, 0x80},
  6091. + {OV5693_8BIT, 0x0100, 0x01},
  6092. + {OV5693_TOK_TERM, 0, 0}
  6093. +};
  6094. +#endif
  6095. +
  6096. +static struct ov5693_reg const ov5693_1616x1216_30fps[] = {
  6097. + {OV5693_8BIT, 0x3501, 0x7b},
  6098. + {OV5693_8BIT, 0x3502, 0x80},
  6099. + {OV5693_8BIT, 0x3708, 0xe2},
  6100. + {OV5693_8BIT, 0x3709, 0xc3},
  6101. + {OV5693_8BIT, 0x3800, 0x00}, /*{3800,3801} Array X start*/
  6102. + {OV5693_8BIT, 0x3801, 0x08}, /* 04 //{3800,3801} Array X start*/
  6103. + {OV5693_8BIT, 0x3802, 0x00}, /*{3802,3803} Array Y start*/
  6104. + {OV5693_8BIT, 0x3803, 0x04}, /* 00 //{3802,3803} Array Y start*/
  6105. + {OV5693_8BIT, 0x3804, 0x0a}, /*{3804,3805} Array X end*/
  6106. + {OV5693_8BIT, 0x3805, 0x37}, /* 3b //{3804,3805} Array X end*/
  6107. + {OV5693_8BIT, 0x3806, 0x07}, /*{3806,3807} Array Y end*/
  6108. + {OV5693_8BIT, 0x3807, 0x9f}, /* a3 //{3806,3807} Array Y end*/
  6109. + {OV5693_8BIT, 0x3808, 0x06}, /*{3808,3809} Final output H size*/
  6110. + {OV5693_8BIT, 0x3809, 0x50}, /*{3808,3809} Final output H size*/
  6111. + {OV5693_8BIT, 0x380a, 0x04}, /*{380a,380b} Final output V size*/
  6112. + {OV5693_8BIT, 0x380b, 0xc0}, /*{380a,380b} Final output V size*/
  6113. + {OV5693_8BIT, 0x380c, 0x0a}, /*{380c,380d} HTS*/
  6114. + {OV5693_8BIT, 0x380d, 0x80}, /*{380c,380d} HTS*/
  6115. + {OV5693_8BIT, 0x380e, 0x07}, /*{380e,380f} VTS*/
  6116. + {OV5693_8BIT, 0x380f, 0xc0}, /* bc //{380e,380f} VTS*/
  6117. + {OV5693_8BIT, 0x3810, 0x00}, /*{3810,3811} windowing X offset*/
  6118. + {OV5693_8BIT, 0x3811, 0x10}, /*{3810,3811} windowing X offset*/
  6119. + {OV5693_8BIT, 0x3812, 0x00}, /*{3812,3813} windowing Y offset*/
  6120. + {OV5693_8BIT, 0x3813, 0x06}, /*{3812,3813} windowing Y offset*/
  6121. + {OV5693_8BIT, 0x3814, 0x11}, /*X subsample control*/
  6122. + {OV5693_8BIT, 0x3815, 0x11}, /*Y subsample control*/
  6123. + {OV5693_8BIT, 0x3820, 0x00}, /*FLIP/Binnning control*/
  6124. + {OV5693_8BIT, 0x3821, 0x1e}, /*MIRROR control*/
  6125. + {OV5693_8BIT, 0x5002, 0x00},
  6126. + {OV5693_8BIT, 0x5041, 0x84},
  6127. + {OV5693_8BIT, 0x0100, 0x01},
  6128. + {OV5693_TOK_TERM, 0, 0}
  6129. +};
  6130. +
  6131. +/*
  6132. + * 1940x1096 30fps 8.8ms VBlanking 2lane 10bit (Scaling)
  6133. + */
  6134. +#if ENABLE_NON_PREVIEW
  6135. +static struct ov5693_reg const ov5693_1940x1096[] = {
  6136. + {OV5693_8BIT, 0x3501, 0x7b},
  6137. + {OV5693_8BIT, 0x3502, 0x00},
  6138. + {OV5693_8BIT, 0x3708, 0xe2},
  6139. + {OV5693_8BIT, 0x3709, 0xc3},
  6140. + {OV5693_8BIT, 0x3803, 0xf0},
  6141. + {OV5693_8BIT, 0x3806, 0x06},
  6142. + {OV5693_8BIT, 0x3807, 0xa7},
  6143. + {OV5693_8BIT, 0x3808, 0x07},
  6144. + {OV5693_8BIT, 0x3809, 0x94},
  6145. + {OV5693_8BIT, 0x380a, 0x04},
  6146. + {OV5693_8BIT, 0x380b, 0x48},
  6147. + {OV5693_8BIT, 0x380c, 0x0a},
  6148. + {OV5693_8BIT, 0x380d, 0x80},
  6149. + {OV5693_8BIT, 0x380e, 0x07},
  6150. + {OV5693_8BIT, 0x380f, 0xc0},
  6151. + {OV5693_8BIT, 0x3811, 0x02},
  6152. + {OV5693_8BIT, 0x3813, 0x02},
  6153. + {OV5693_8BIT, 0x3814, 0x11},
  6154. + {OV5693_8BIT, 0x3815, 0x11},
  6155. + {OV5693_8BIT, 0x3820, 0x00},
  6156. + {OV5693_8BIT, 0x3821, 0x1e},
  6157. + {OV5693_8BIT, 0x5002, 0x80},
  6158. + {OV5693_8BIT, 0x0100, 0x01},
  6159. + {OV5693_TOK_TERM, 0, 0}
  6160. +};
  6161. +
  6162. +static struct ov5693_reg const ov5693_2592x1456_30fps[] = {
  6163. + {OV5693_8BIT, 0x3501, 0x7b},
  6164. + {OV5693_8BIT, 0x3502, 0x00},
  6165. + {OV5693_8BIT, 0x3708, 0xe2},
  6166. + {OV5693_8BIT, 0x3709, 0xc3},
  6167. + {OV5693_8BIT, 0x3800, 0x00},
  6168. + {OV5693_8BIT, 0x3801, 0x00},
  6169. + {OV5693_8BIT, 0x3802, 0x00},
  6170. + {OV5693_8BIT, 0x3803, 0xf0},
  6171. + {OV5693_8BIT, 0x3804, 0x0a},
  6172. + {OV5693_8BIT, 0x3805, 0x3f},
  6173. + {OV5693_8BIT, 0x3806, 0x06},
  6174. + {OV5693_8BIT, 0x3807, 0xa4},
  6175. + {OV5693_8BIT, 0x3808, 0x0a},
  6176. + {OV5693_8BIT, 0x3809, 0x20},
  6177. + {OV5693_8BIT, 0x380a, 0x05},
  6178. + {OV5693_8BIT, 0x380b, 0xb0},
  6179. + {OV5693_8BIT, 0x380c, 0x0a},
  6180. + {OV5693_8BIT, 0x380d, 0x80},
  6181. + {OV5693_8BIT, 0x380e, 0x07},
  6182. + {OV5693_8BIT, 0x380f, 0xc0},
  6183. + {OV5693_8BIT, 0x3811, 0x10},
  6184. + {OV5693_8BIT, 0x3813, 0x00},
  6185. + {OV5693_8BIT, 0x3814, 0x11},
  6186. + {OV5693_8BIT, 0x3815, 0x11},
  6187. + {OV5693_8BIT, 0x3820, 0x00},
  6188. + {OV5693_8BIT, 0x3821, 0x1e},
  6189. + {OV5693_8BIT, 0x5002, 0x00},
  6190. + {OV5693_TOK_TERM, 0, 0}
  6191. +};
  6192. +#endif
  6193. +
  6194. +static struct ov5693_reg const ov5693_2576x1456_30fps[] = {
  6195. + {OV5693_8BIT, 0x3501, 0x7b},
  6196. + {OV5693_8BIT, 0x3502, 0x00},
  6197. + {OV5693_8BIT, 0x3708, 0xe2},
  6198. + {OV5693_8BIT, 0x3709, 0xc3},
  6199. + {OV5693_8BIT, 0x3800, 0x00},
  6200. + {OV5693_8BIT, 0x3801, 0x00},
  6201. + {OV5693_8BIT, 0x3802, 0x00},
  6202. + {OV5693_8BIT, 0x3803, 0xf0},
  6203. + {OV5693_8BIT, 0x3804, 0x0a},
  6204. + {OV5693_8BIT, 0x3805, 0x3f},
  6205. + {OV5693_8BIT, 0x3806, 0x06},
  6206. + {OV5693_8BIT, 0x3807, 0xa4},
  6207. + {OV5693_8BIT, 0x3808, 0x0a},
  6208. + {OV5693_8BIT, 0x3809, 0x10},
  6209. + {OV5693_8BIT, 0x380a, 0x05},
  6210. + {OV5693_8BIT, 0x380b, 0xb0},
  6211. + {OV5693_8BIT, 0x380c, 0x0a},
  6212. + {OV5693_8BIT, 0x380d, 0x80},
  6213. + {OV5693_8BIT, 0x380e, 0x07},
  6214. + {OV5693_8BIT, 0x380f, 0xc0},
  6215. + {OV5693_8BIT, 0x3811, 0x18},
  6216. + {OV5693_8BIT, 0x3813, 0x00},
  6217. + {OV5693_8BIT, 0x3814, 0x11},
  6218. + {OV5693_8BIT, 0x3815, 0x11},
  6219. + {OV5693_8BIT, 0x3820, 0x00},
  6220. + {OV5693_8BIT, 0x3821, 0x1e},
  6221. + {OV5693_8BIT, 0x5002, 0x00},
  6222. + {OV5693_TOK_TERM, 0, 0}
  6223. +};
  6224. +
  6225. +/*
  6226. + * 2592x1944 30fps 0.6ms VBlanking 2lane 10Bit
  6227. + */
  6228. +#if ENABLE_NON_PREVIEW
  6229. +static struct ov5693_reg const ov5693_2592x1944_30fps[] = {
  6230. + {OV5693_8BIT, 0x3501, 0x7b},
  6231. + {OV5693_8BIT, 0x3502, 0x00},
  6232. + {OV5693_8BIT, 0x3708, 0xe2},
  6233. + {OV5693_8BIT, 0x3709, 0xc3},
  6234. + {OV5693_8BIT, 0x3803, 0x00},
  6235. + {OV5693_8BIT, 0x3806, 0x07},
  6236. + {OV5693_8BIT, 0x3807, 0xa3},
  6237. + {OV5693_8BIT, 0x3808, 0x0a},
  6238. + {OV5693_8BIT, 0x3809, 0x20},
  6239. + {OV5693_8BIT, 0x380a, 0x07},
  6240. + {OV5693_8BIT, 0x380b, 0x98},
  6241. + {OV5693_8BIT, 0x380c, 0x0a},
  6242. + {OV5693_8BIT, 0x380d, 0x80},
  6243. + {OV5693_8BIT, 0x380e, 0x07},
  6244. + {OV5693_8BIT, 0x380f, 0xc0},
  6245. + {OV5693_8BIT, 0x3811, 0x10},
  6246. + {OV5693_8BIT, 0x3813, 0x00},
  6247. + {OV5693_8BIT, 0x3814, 0x11},
  6248. + {OV5693_8BIT, 0x3815, 0x11},
  6249. + {OV5693_8BIT, 0x3820, 0x00},
  6250. + {OV5693_8BIT, 0x3821, 0x1e},
  6251. + {OV5693_8BIT, 0x5002, 0x00},
  6252. + {OV5693_8BIT, 0x0100, 0x01},
  6253. + {OV5693_TOK_TERM, 0, 0}
  6254. +};
  6255. +#endif
  6256. +
  6257. +/*
  6258. + * 11:9 Full FOV Output, expected FOV Res: 2346x1920
  6259. + * ISP Effect Res: 1408x1152
  6260. + * Sensor out: 1424x1168, DS From: 2380x1952
  6261. + *
  6262. + * WA: Left Offset: 8, Hor scal: 64
  6263. + */
  6264. +#if ENABLE_NON_PREVIEW
  6265. +static struct ov5693_reg const ov5693_1424x1168_30fps[] = {
  6266. + {OV5693_8BIT, 0x3501, 0x3b}, /* long exposure[15:8] */
  6267. + {OV5693_8BIT, 0x3502, 0x80}, /* long exposure[7:0] */
  6268. + {OV5693_8BIT, 0x3708, 0xe2},
  6269. + {OV5693_8BIT, 0x3709, 0xc3},
  6270. + {OV5693_8BIT, 0x3800, 0x00}, /* TIMING_X_ADDR_START */
  6271. + {OV5693_8BIT, 0x3801, 0x50}, /* 80 */
  6272. + {OV5693_8BIT, 0x3802, 0x00}, /* TIMING_Y_ADDR_START */
  6273. + {OV5693_8BIT, 0x3803, 0x02}, /* 2 */
  6274. + {OV5693_8BIT, 0x3804, 0x09}, /* TIMING_X_ADDR_END */
  6275. + {OV5693_8BIT, 0x3805, 0xdd}, /* 2525 */
  6276. + {OV5693_8BIT, 0x3806, 0x07}, /* TIMING_Y_ADDR_END */
  6277. + {OV5693_8BIT, 0x3807, 0xa1}, /* 1953 */
  6278. + {OV5693_8BIT, 0x3808, 0x05}, /* TIMING_X_OUTPUT_SIZE */
  6279. + {OV5693_8BIT, 0x3809, 0x90}, /* 1424 */
  6280. + {OV5693_8BIT, 0x380a, 0x04}, /* TIMING_Y_OUTPUT_SIZE */
  6281. + {OV5693_8BIT, 0x380b, 0x90}, /* 1168 */
  6282. + {OV5693_8BIT, 0x380c, 0x0a}, /* TIMING_HTS */
  6283. + {OV5693_8BIT, 0x380d, 0x80},
  6284. + {OV5693_8BIT, 0x380e, 0x07}, /* TIMING_VTS */
  6285. + {OV5693_8BIT, 0x380f, 0xc0},
  6286. + {OV5693_8BIT, 0x3810, 0x00}, /* TIMING_ISP_X_WIN */
  6287. + {OV5693_8BIT, 0x3811, 0x02}, /* 2 */
  6288. + {OV5693_8BIT, 0x3812, 0x00}, /* TIMING_ISP_Y_WIN */
  6289. + {OV5693_8BIT, 0x3813, 0x00}, /* 0 */
  6290. + {OV5693_8BIT, 0x3814, 0x11}, /* TIME_X_INC */
  6291. + {OV5693_8BIT, 0x3815, 0x11}, /* TIME_Y_INC */
  6292. + {OV5693_8BIT, 0x3820, 0x00},
  6293. + {OV5693_8BIT, 0x3821, 0x1e},
  6294. + {OV5693_8BIT, 0x5002, 0x00},
  6295. + {OV5693_8BIT, 0x5041, 0x84}, /* scale is auto enabled */
  6296. + {OV5693_8BIT, 0x0100, 0x01},
  6297. + {OV5693_TOK_TERM, 0, 0}
  6298. +};
  6299. +#endif
  6300. +
  6301. +/*
  6302. + * 3:2 Full FOV Output, expected FOV Res: 2560x1706
  6303. + * ISP Effect Res: 720x480
  6304. + * Sensor out: 736x496, DS From 2616x1764
  6305. + */
  6306. +static struct ov5693_reg const ov5693_736x496_30fps[] = {
  6307. + {OV5693_8BIT, 0x3501, 0x3b}, /* long exposure[15:8] */
  6308. + {OV5693_8BIT, 0x3502, 0x80}, /* long exposure[7:0] */
  6309. + {OV5693_8BIT, 0x3708, 0xe2},
  6310. + {OV5693_8BIT, 0x3709, 0xc3},
  6311. + {OV5693_8BIT, 0x3800, 0x00}, /* TIMING_X_ADDR_START */
  6312. + {OV5693_8BIT, 0x3801, 0x02}, /* 2 */
  6313. + {OV5693_8BIT, 0x3802, 0x00}, /* TIMING_Y_ADDR_START */
  6314. + {OV5693_8BIT, 0x3803, 0x62}, /* 98 */
  6315. + {OV5693_8BIT, 0x3804, 0x0a}, /* TIMING_X_ADDR_END */
  6316. + {OV5693_8BIT, 0x3805, 0x3b}, /* 2619 */
  6317. + {OV5693_8BIT, 0x3806, 0x07}, /* TIMING_Y_ADDR_END */
  6318. + {OV5693_8BIT, 0x3807, 0x43}, /* 1859 */
  6319. + {OV5693_8BIT, 0x3808, 0x02}, /* TIMING_X_OUTPUT_SIZE */
  6320. + {OV5693_8BIT, 0x3809, 0xe0}, /* 736 */
  6321. + {OV5693_8BIT, 0x380a, 0x01}, /* TIMING_Y_OUTPUT_SIZE */
  6322. + {OV5693_8BIT, 0x380b, 0xf0}, /* 496 */
  6323. + {OV5693_8BIT, 0x380c, 0x0a}, /* TIMING_HTS */
  6324. + {OV5693_8BIT, 0x380d, 0x80},
  6325. + {OV5693_8BIT, 0x380e, 0x07}, /* TIMING_VTS */
  6326. + {OV5693_8BIT, 0x380f, 0xc0},
  6327. + {OV5693_8BIT, 0x3810, 0x00}, /* TIMING_ISP_X_WIN */
  6328. + {OV5693_8BIT, 0x3811, 0x02}, /* 2 */
  6329. + {OV5693_8BIT, 0x3812, 0x00}, /* TIMING_ISP_Y_WIN */
  6330. + {OV5693_8BIT, 0x3813, 0x00}, /* 0 */
  6331. + {OV5693_8BIT, 0x3814, 0x11}, /* TIME_X_INC */
  6332. + {OV5693_8BIT, 0x3815, 0x11}, /* TIME_Y_INC */
  6333. + {OV5693_8BIT, 0x3820, 0x00},
  6334. + {OV5693_8BIT, 0x3821, 0x1e},
  6335. + {OV5693_8BIT, 0x5002, 0x00},
  6336. + {OV5693_8BIT, 0x5041, 0x84}, /* scale is auto enabled */
  6337. + {OV5693_8BIT, 0x0100, 0x01},
  6338. + {OV5693_TOK_TERM, 0, 0}
  6339. +};
  6340. +
  6341. +static struct ov5693_reg const ov5693_2576x1936_30fps[] = {
  6342. + {OV5693_8BIT, 0x3501, 0x7b},
  6343. + {OV5693_8BIT, 0x3502, 0x00},
  6344. + {OV5693_8BIT, 0x3708, 0xe2},
  6345. + {OV5693_8BIT, 0x3709, 0xc3},
  6346. + {OV5693_8BIT, 0x3803, 0x00},
  6347. + {OV5693_8BIT, 0x3806, 0x07},
  6348. + {OV5693_8BIT, 0x3807, 0xa3},
  6349. + {OV5693_8BIT, 0x3808, 0x0a},
  6350. + {OV5693_8BIT, 0x3809, 0x10},
  6351. + {OV5693_8BIT, 0x380a, 0x07},
  6352. + {OV5693_8BIT, 0x380b, 0x90},
  6353. + {OV5693_8BIT, 0x380c, 0x0a},
  6354. + {OV5693_8BIT, 0x380d, 0x80},
  6355. + {OV5693_8BIT, 0x380e, 0x07},
  6356. + {OV5693_8BIT, 0x380f, 0xc0},
  6357. + {OV5693_8BIT, 0x3811, 0x18},
  6358. + {OV5693_8BIT, 0x3813, 0x00},
  6359. + {OV5693_8BIT, 0x3814, 0x11},
  6360. + {OV5693_8BIT, 0x3815, 0x11},
  6361. + {OV5693_8BIT, 0x3820, 0x00},
  6362. + {OV5693_8BIT, 0x3821, 0x1e},
  6363. + {OV5693_8BIT, 0x5002, 0x00},
  6364. + {OV5693_8BIT, 0x0100, 0x01},
  6365. + {OV5693_TOK_TERM, 0, 0}
  6366. +};
  6367. +
  6368. +static struct ov5693_resolution ov5693_res_preview[] = {
  6369. + {
  6370. + .desc = "ov5693_736x496_30fps",
  6371. + .width = 736,
  6372. + .height = 496,
  6373. + .pix_clk_freq = 160,
  6374. + .fps = 30,
  6375. + .used = 0,
  6376. + .pixels_per_line = 2688,
  6377. + .lines_per_frame = 1984,
  6378. + .bin_factor_x = 1,
  6379. + .bin_factor_y = 1,
  6380. + .bin_mode = 0,
  6381. + .regs = ov5693_736x496_30fps,
  6382. + },
  6383. + {
  6384. + .desc = "ov5693_1616x1216_30fps",
  6385. + .width = 1616,
  6386. + .height = 1216,
  6387. + .pix_clk_freq = 160,
  6388. + .fps = 30,
  6389. + .used = 0,
  6390. + .pixels_per_line = 2688,
  6391. + .lines_per_frame = 1984,
  6392. + .bin_factor_x = 1,
  6393. + .bin_factor_y = 1,
  6394. + .bin_mode = 0,
  6395. + .regs = ov5693_1616x1216_30fps,
  6396. + },
  6397. + {
  6398. + .desc = "ov5693_5M_30fps",
  6399. + .width = 2576,
  6400. + .height = 1456,
  6401. + .pix_clk_freq = 160,
  6402. + .fps = 30,
  6403. + .used = 0,
  6404. + .pixels_per_line = 2688,
  6405. + .lines_per_frame = 1984,
  6406. + .bin_factor_x = 1,
  6407. + .bin_factor_y = 1,
  6408. + .bin_mode = 0,
  6409. + .regs = ov5693_2576x1456_30fps,
  6410. + },
  6411. + {
  6412. + .desc = "ov5693_5M_30fps",
  6413. + .width = 2576,
  6414. + .height = 1936,
  6415. + .pix_clk_freq = 160,
  6416. + .fps = 30,
  6417. + .used = 0,
  6418. + .pixels_per_line = 2688,
  6419. + .lines_per_frame = 1984,
  6420. + .bin_factor_x = 1,
  6421. + .bin_factor_y = 1,
  6422. + .bin_mode = 0,
  6423. + .regs = ov5693_2576x1936_30fps,
  6424. + },
  6425. +};
  6426. +
  6427. +#define N_RES_PREVIEW (ARRAY_SIZE(ov5693_res_preview))
  6428. +
  6429. +/*
  6430. + * Disable non-preview configurations until the configuration selection is
  6431. + * improved.
  6432. + */
  6433. +#if ENABLE_NON_PREVIEW
  6434. +struct ov5693_resolution ov5693_res_still[] = {
  6435. + {
  6436. + .desc = "ov5693_736x496_30fps",
  6437. + .width = 736,
  6438. + .height = 496,
  6439. + .pix_clk_freq = 160,
  6440. + .fps = 30,
  6441. + .used = 0,
  6442. + .pixels_per_line = 2688,
  6443. + .lines_per_frame = 1984,
  6444. + .bin_factor_x = 1,
  6445. + .bin_factor_y = 1,
  6446. + .bin_mode = 0,
  6447. + .regs = ov5693_736x496_30fps,
  6448. + },
  6449. + {
  6450. + .desc = "ov5693_1424x1168_30fps",
  6451. + .width = 1424,
  6452. + .height = 1168,
  6453. + .pix_clk_freq = 160,
  6454. + .fps = 30,
  6455. + .used = 0,
  6456. + .pixels_per_line = 2688,
  6457. + .lines_per_frame = 1984,
  6458. + .bin_factor_x = 1,
  6459. + .bin_factor_y = 1,
  6460. + .bin_mode = 0,
  6461. + .regs = ov5693_1424x1168_30fps,
  6462. + },
  6463. + {
  6464. + .desc = "ov5693_1616x1216_30fps",
  6465. + .width = 1616,
  6466. + .height = 1216,
  6467. + .pix_clk_freq = 160,
  6468. + .fps = 30,
  6469. + .used = 0,
  6470. + .pixels_per_line = 2688,
  6471. + .lines_per_frame = 1984,
  6472. + .bin_factor_x = 1,
  6473. + .bin_factor_y = 1,
  6474. + .bin_mode = 0,
  6475. + .regs = ov5693_1616x1216_30fps,
  6476. + },
  6477. + {
  6478. + .desc = "ov5693_5M_30fps",
  6479. + .width = 2592,
  6480. + .height = 1456,
  6481. + .pix_clk_freq = 160,
  6482. + .fps = 30,
  6483. + .used = 0,
  6484. + .pixels_per_line = 2688,
  6485. + .lines_per_frame = 1984,
  6486. + .bin_factor_x = 1,
  6487. + .bin_factor_y = 1,
  6488. + .bin_mode = 0,
  6489. + .regs = ov5693_2592x1456_30fps,
  6490. + },
  6491. + {
  6492. + .desc = "ov5693_5M_30fps",
  6493. + .width = 2592,
  6494. + .height = 1944,
  6495. + .pix_clk_freq = 160,
  6496. + .fps = 30,
  6497. + .used = 0,
  6498. + .pixels_per_line = 2688,
  6499. + .lines_per_frame = 1984,
  6500. + .bin_factor_x = 1,
  6501. + .bin_factor_y = 1,
  6502. + .bin_mode = 0,
  6503. + .regs = ov5693_2592x1944_30fps,
  6504. + },
  6505. +};
  6506. +
  6507. +#define N_RES_STILL (ARRAY_SIZE(ov5693_res_still))
  6508. +
  6509. +struct ov5693_resolution ov5693_res_video[] = {
  6510. + {
  6511. + .desc = "ov5693_736x496_30fps",
  6512. + .width = 736,
  6513. + .height = 496,
  6514. + .fps = 30,
  6515. + .pix_clk_freq = 160,
  6516. + .used = 0,
  6517. + .pixels_per_line = 2688,
  6518. + .lines_per_frame = 1984,
  6519. + .bin_factor_x = 2,
  6520. + .bin_factor_y = 2,
  6521. + .bin_mode = 1,
  6522. + .regs = ov5693_736x496,
  6523. + },
  6524. + {
  6525. + .desc = "ov5693_336x256_30fps",
  6526. + .width = 336,
  6527. + .height = 256,
  6528. + .fps = 30,
  6529. + .pix_clk_freq = 160,
  6530. + .used = 0,
  6531. + .pixels_per_line = 2688,
  6532. + .lines_per_frame = 1984,
  6533. + .bin_factor_x = 2,
  6534. + .bin_factor_y = 2,
  6535. + .bin_mode = 1,
  6536. + .regs = ov5693_336x256,
  6537. + },
  6538. + {
  6539. + .desc = "ov5693_368x304_30fps",
  6540. + .width = 368,
  6541. + .height = 304,
  6542. + .fps = 30,
  6543. + .pix_clk_freq = 160,
  6544. + .used = 0,
  6545. + .pixels_per_line = 2688,
  6546. + .lines_per_frame = 1984,
  6547. + .bin_factor_x = 2,
  6548. + .bin_factor_y = 2,
  6549. + .bin_mode = 1,
  6550. + .regs = ov5693_368x304,
  6551. + },
  6552. + {
  6553. + .desc = "ov5693_192x160_30fps",
  6554. + .width = 192,
  6555. + .height = 160,
  6556. + .fps = 30,
  6557. + .pix_clk_freq = 160,
  6558. + .used = 0,
  6559. + .pixels_per_line = 2688,
  6560. + .lines_per_frame = 1984,
  6561. + .bin_factor_x = 2,
  6562. + .bin_factor_y = 2,
  6563. + .bin_mode = 1,
  6564. + .regs = ov5693_192x160,
  6565. + },
  6566. + {
  6567. + .desc = "ov5693_1296x736_30fps",
  6568. + .width = 1296,
  6569. + .height = 736,
  6570. + .fps = 30,
  6571. + .pix_clk_freq = 160,
  6572. + .used = 0,
  6573. + .pixels_per_line = 2688,
  6574. + .lines_per_frame = 1984,
  6575. + .bin_factor_x = 2,
  6576. + .bin_factor_y = 2,
  6577. + .bin_mode = 0,
  6578. + .regs = ov5693_1296x736,
  6579. + },
  6580. + {
  6581. + .desc = "ov5693_1296x976_30fps",
  6582. + .width = 1296,
  6583. + .height = 976,
  6584. + .fps = 30,
  6585. + .pix_clk_freq = 160,
  6586. + .used = 0,
  6587. + .pixels_per_line = 2688,
  6588. + .lines_per_frame = 1984,
  6589. + .bin_factor_x = 2,
  6590. + .bin_factor_y = 2,
  6591. + .bin_mode = 0,
  6592. + .regs = ov5693_1296x976,
  6593. + },
  6594. + {
  6595. + .desc = "ov5693_1636P_30fps",
  6596. + .width = 1636,
  6597. + .height = 1096,
  6598. + .fps = 30,
  6599. + .pix_clk_freq = 160,
  6600. + .used = 0,
  6601. + .pixels_per_line = 2688,
  6602. + .lines_per_frame = 1984,
  6603. + .bin_factor_x = 1,
  6604. + .bin_factor_y = 1,
  6605. + .bin_mode = 0,
  6606. + .regs = ov5693_1636p_30fps,
  6607. + },
  6608. + {
  6609. + .desc = "ov5693_1080P_30fps",
  6610. + .width = 1940,
  6611. + .height = 1096,
  6612. + .fps = 30,
  6613. + .pix_clk_freq = 160,
  6614. + .used = 0,
  6615. + .pixels_per_line = 2688,
  6616. + .lines_per_frame = 1984,
  6617. + .bin_factor_x = 1,
  6618. + .bin_factor_y = 1,
  6619. + .bin_mode = 0,
  6620. + .regs = ov5693_1940x1096,
  6621. + },
  6622. + {
  6623. + .desc = "ov5693_5M_30fps",
  6624. + .width = 2592,
  6625. + .height = 1456,
  6626. + .pix_clk_freq = 160,
  6627. + .fps = 30,
  6628. + .used = 0,
  6629. + .pixels_per_line = 2688,
  6630. + .lines_per_frame = 1984,
  6631. + .bin_factor_x = 1,
  6632. + .bin_factor_y = 1,
  6633. + .bin_mode = 0,
  6634. + .regs = ov5693_2592x1456_30fps,
  6635. + },
  6636. + {
  6637. + .desc = "ov5693_5M_30fps",
  6638. + .width = 2592,
  6639. + .height = 1944,
  6640. + .pix_clk_freq = 160,
  6641. + .fps = 30,
  6642. + .used = 0,
  6643. + .pixels_per_line = 2688,
  6644. + .lines_per_frame = 1984,
  6645. + .bin_factor_x = 1,
  6646. + .bin_factor_y = 1,
  6647. + .bin_mode = 0,
  6648. + .regs = ov5693_2592x1944_30fps,
  6649. + .crop = {
  6650. + .left = 0,
  6651. + .top = 0,
  6652. + .width = 2592,
  6653. + .height = 1944
  6654. + },
  6655. + },
  6656. +};
  6657. +
  6658. +#define N_RES_VIDEO (ARRAY_SIZE(ov5693_res_video))
  6659. +#endif
  6660. +
  6661. +static struct ov5693_resolution *ov5693_res = ov5693_res_video;
  6662. +static unsigned long N_RES = N_RES_VIDEO;
  6663. +#endif
  6664. --
  6665. 2.33.0
  6666. From 636227d49ba696aefb0608471380d2d7306fdb8c Mon Sep 17 00:00:00 2001
  6667. From: Daniel Scally <djrscally@gmail.com>
  6668. Date: Sun, 17 Jan 2021 19:08:18 +0000
  6669. Subject: [PATCH] media: i2c: Add reset pin toggling to ov5693
  6670. The ov5693 has an xshutdown pin which can be present and, if so, needs
  6671. toggling as part of power on sequence.
  6672. Add calls to handle the reset GPIO
  6673. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  6674. Patchset: cameras
  6675. ---
  6676. drivers/media/i2c/ov5693.c | 4 ++++
  6677. 1 file changed, 4 insertions(+)
  6678. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  6679. index 32485e4ed42b..f9ced52ad37a 100644
  6680. --- a/drivers/media/i2c/ov5693.c
  6681. +++ b/drivers/media/i2c/ov5693.c
  6682. @@ -1085,6 +1085,8 @@ static int __power_up(struct v4l2_subdev *sd)
  6683. if (ret)
  6684. goto fail_power;
  6685. + gpiod_set_value_cansleep(sensor->reset, 0);
  6686. +
  6687. __cci_delay(up_delay);
  6688. return 0;
  6689. @@ -1103,6 +1105,8 @@ static int power_down(struct v4l2_subdev *sd)
  6690. dev->focus = OV5693_INVALID_CONFIG;
  6691. + gpiod_set_value_cansleep(sensor->reset, 1);
  6692. +
  6693. clk_disable_unprepare(dev->clk);
  6694. if (dev->indicator_led)
  6695. --
  6696. 2.33.0
  6697. From 2dffcd137b3a665ea278785f3c01c0f143e301e8 Mon Sep 17 00:00:00 2001
  6698. From: Daniel Scally <djrscally@gmail.com>
  6699. Date: Sun, 17 Jan 2021 21:39:15 +0000
  6700. Subject: [PATCH] media: i2c: Fix misnamed variable in power_down() for ov5693
  6701. Fix the misnamed variable in gpiod_set_value_cansleep().
  6702. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  6703. Patchset: cameras
  6704. ---
  6705. drivers/media/i2c/ov5693.c | 2 +-
  6706. 1 file changed, 1 insertion(+), 1 deletion(-)
  6707. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  6708. index f9ced52ad37a..9fd44a3d1d85 100644
  6709. --- a/drivers/media/i2c/ov5693.c
  6710. +++ b/drivers/media/i2c/ov5693.c
  6711. @@ -1105,7 +1105,7 @@ static int power_down(struct v4l2_subdev *sd)
  6712. dev->focus = OV5693_INVALID_CONFIG;
  6713. - gpiod_set_value_cansleep(sensor->reset, 1);
  6714. + gpiod_set_value_cansleep(dev->reset, 1);
  6715. clk_disable_unprepare(dev->clk);
  6716. --
  6717. 2.33.0
  6718. From 238061b3ae97913f96ade9beba6c26947de52d6c Mon Sep 17 00:00:00 2001
  6719. From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= <me@fabwu.ch>
  6720. Date: Fri, 22 Jan 2021 20:58:13 +0100
  6721. Subject: [PATCH] cio2-bridge: Parse sensor orientation and rotation
  6722. MIME-Version: 1.0
  6723. Content-Type: text/plain; charset=UTF-8
  6724. Content-Transfer-Encoding: 8bit
  6725. The sensor orientation is read from the _PLC ACPI buffer and converted
  6726. to a v4l2 format.
  6727. See https://uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf
  6728. page 351 for a definition of the Panel property.
  6729. The sensor rotation is read from the SSDB ACPI buffer and converted into
  6730. degrees.
  6731. Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
  6732. Patchset: cameras
  6733. ---
  6734. drivers/media/pci/intel/ipu3/cio2-bridge.c | 45 ++++++++++++++++++++--
  6735. drivers/media/pci/intel/ipu3/cio2-bridge.h | 3 ++
  6736. 2 files changed, 44 insertions(+), 4 deletions(-)
  6737. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  6738. index 143f3c0f445e..806d4e5fc177 100644
  6739. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
  6740. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  6741. @@ -29,6 +29,7 @@ static const struct cio2_sensor_config cio2_supported_sensors[] = {
  6742. static const struct cio2_property_names prop_names = {
  6743. .clock_frequency = "clock-frequency",
  6744. .rotation = "rotation",
  6745. + .orientation = "orientation",
  6746. .bus_type = "bus-type",
  6747. .data_lanes = "data-lanes",
  6748. .remote_endpoint = "remote-endpoint",
  6749. @@ -72,11 +73,36 @@ static int cio2_bridge_read_acpi_buffer(struct acpi_device *adev, char *id,
  6750. return ret;
  6751. }
  6752. +static u32 cio2_bridge_parse_rotation(u8 rotation)
  6753. +{
  6754. + if (rotation == 1)
  6755. + return 180;
  6756. + return 0;
  6757. +}
  6758. +
  6759. +static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(u8 panel)
  6760. +{
  6761. + switch (panel) {
  6762. + case 4:
  6763. + return V4L2_FWNODE_ORIENTATION_FRONT;
  6764. + case 5:
  6765. + return V4L2_FWNODE_ORIENTATION_BACK;
  6766. + default:
  6767. + return V4L2_FWNODE_ORIENTATION_EXTERNAL;
  6768. + }
  6769. +}
  6770. +
  6771. static void cio2_bridge_create_fwnode_properties(
  6772. struct cio2_sensor *sensor,
  6773. struct cio2_bridge *bridge,
  6774. const struct cio2_sensor_config *cfg)
  6775. {
  6776. + u32 rotation;
  6777. + enum v4l2_fwnode_orientation orientation;
  6778. +
  6779. + rotation = cio2_bridge_parse_rotation(sensor->ssdb.degree);
  6780. + orientation = cio2_bridge_parse_orientation(sensor->pld->panel);
  6781. +
  6782. sensor->prop_names = prop_names;
  6783. sensor->local_ref[0].node = &sensor->swnodes[SWNODE_CIO2_ENDPOINT];
  6784. @@ -85,9 +111,12 @@ static void cio2_bridge_create_fwnode_properties(
  6785. sensor->dev_properties[0] = PROPERTY_ENTRY_U32(
  6786. sensor->prop_names.clock_frequency,
  6787. sensor->ssdb.mclkspeed);
  6788. - sensor->dev_properties[1] = PROPERTY_ENTRY_U8(
  6789. + sensor->dev_properties[1] = PROPERTY_ENTRY_U32(
  6790. sensor->prop_names.rotation,
  6791. - sensor->ssdb.degree);
  6792. + rotation);
  6793. + sensor->dev_properties[2] = PROPERTY_ENTRY_U32(
  6794. + sensor->prop_names.orientation,
  6795. + orientation);
  6796. sensor->ep_properties[0] = PROPERTY_ENTRY_U32(
  6797. sensor->prop_names.bus_type,
  6798. @@ -159,6 +188,7 @@ static void cio2_bridge_unregister_sensors(struct cio2_bridge *bridge)
  6799. for (i = 0; i < bridge->n_sensors; i++) {
  6800. sensor = &bridge->sensors[i];
  6801. software_node_unregister_nodes(sensor->swnodes);
  6802. + ACPI_FREE(sensor->pld);
  6803. acpi_dev_put(sensor->adev);
  6804. }
  6805. }
  6806. @@ -170,6 +200,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
  6807. struct fwnode_handle *fwnode;
  6808. struct cio2_sensor *sensor;
  6809. struct acpi_device *adev;
  6810. + acpi_status status;
  6811. int ret;
  6812. for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
  6813. @@ -193,11 +224,15 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
  6814. if (ret)
  6815. goto err_put_adev;
  6816. + status = acpi_get_physical_device_location(adev->handle, &sensor->pld);
  6817. + if (ACPI_FAILURE(status))
  6818. + goto err_put_adev;
  6819. +
  6820. if (sensor->ssdb.lanes > CIO2_MAX_LANES) {
  6821. dev_err(&adev->dev,
  6822. "Number of lanes in SSDB is invalid\n");
  6823. ret = -EINVAL;
  6824. - goto err_put_adev;
  6825. + goto err_free_pld;
  6826. }
  6827. cio2_bridge_create_fwnode_properties(sensor, bridge, cfg);
  6828. @@ -205,7 +240,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
  6829. ret = software_node_register_nodes(sensor->swnodes);
  6830. if (ret)
  6831. - goto err_put_adev;
  6832. + goto err_free_pld;
  6833. fwnode = software_node_fwnode(&sensor->swnodes[SWNODE_SENSOR_HID]);
  6834. if (!fwnode) {
  6835. @@ -225,6 +260,8 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
  6836. err_free_swnodes:
  6837. software_node_unregister_nodes(sensor->swnodes);
  6838. +err_free_pld:
  6839. + ACPI_FREE(sensor->pld);
  6840. err_put_adev:
  6841. acpi_dev_put(sensor->adev);
  6842. err_out:
  6843. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  6844. index dd0ffcafa489..924d99d20328 100644
  6845. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
  6846. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  6847. @@ -80,6 +80,7 @@ struct cio2_sensor_ssdb {
  6848. struct cio2_property_names {
  6849. char clock_frequency[16];
  6850. char rotation[9];
  6851. + char orientation[12];
  6852. char bus_type[9];
  6853. char data_lanes[11];
  6854. char remote_endpoint[16];
  6855. @@ -106,6 +107,8 @@ struct cio2_sensor {
  6856. struct cio2_node_names node_names;
  6857. struct cio2_sensor_ssdb ssdb;
  6858. + struct acpi_pld_info *pld;
  6859. +
  6860. struct cio2_property_names prop_names;
  6861. struct property_entry ep_properties[5];
  6862. struct property_entry dev_properties[3];
  6863. --
  6864. 2.33.0
  6865. From 0c8bba6d8661cbb5f7a54ba8ccd17678ae58ebc9 Mon Sep 17 00:00:00 2001
  6866. From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= <me@fabwu.ch>
  6867. Date: Fri, 22 Jan 2021 21:23:47 +0100
  6868. Subject: [PATCH] ov5693: Add orientation and rotation controls
  6869. MIME-Version: 1.0
  6870. Content-Type: text/plain; charset=UTF-8
  6871. Content-Transfer-Encoding: 8bit
  6872. Parse orientation and rotation from fwnodes and initialize the
  6873. respective controls.
  6874. Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
  6875. Patchset: cameras
  6876. ---
  6877. drivers/media/i2c/ov5693.c | 11 +++++++++++
  6878. 1 file changed, 11 insertions(+)
  6879. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  6880. index 9fd44a3d1d85..1a85800df7ed 100644
  6881. --- a/drivers/media/i2c/ov5693.c
  6882. +++ b/drivers/media/i2c/ov5693.c
  6883. @@ -31,6 +31,7 @@
  6884. #include <linux/i2c.h>
  6885. #include <linux/moduleparam.h>
  6886. #include <media/v4l2-device.h>
  6887. +#include <media/v4l2-fwnode.h>
  6888. #include <linux/io.h>
  6889. #include <linux/acpi.h>
  6890. #include <linux/regulator/consumer.h>
  6891. @@ -1608,6 +1609,7 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  6892. {
  6893. struct i2c_client *client = v4l2_get_subdevdata(&ov5693->sd);
  6894. const struct v4l2_ctrl_ops *ops = &ov5693_ctrl_ops;
  6895. + struct v4l2_fwnode_device_properties props;
  6896. struct v4l2_ctrl *ctrl;
  6897. unsigned int i;
  6898. int ret;
  6899. @@ -1663,6 +1665,15 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  6900. if (ov5693->hblank)
  6901. ov5693->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  6902. + /* set properties from fwnode (e.g. rotation, orientation) */
  6903. + ret = v4l2_fwnode_device_parse(&client->dev, &props);
  6904. + if (ret)
  6905. + return ret;
  6906. +
  6907. + ret = v4l2_ctrl_new_fwnode_properties(&ov5693->ctrl_handler, ops, &props);
  6908. + if (ret)
  6909. + return ret;
  6910. +
  6911. /* Use same lock for controls as for everything else. */
  6912. ov5693->ctrl_handler.lock = &ov5693->input_lock;
  6913. ov5693->sd.ctrl_handler = &ov5693->ctrl_handler;
  6914. --
  6915. 2.33.0
  6916. From 2e7dcc9a3f803030d102e9cdfba6a995311b5a55 Mon Sep 17 00:00:00 2001
  6917. From: Daniel Scally <djrscally@gmail.com>
  6918. Date: Sat, 23 Jan 2021 00:28:32 +0000
  6919. Subject: [PATCH] platform: x86: Stylistic updates for intel-skl-int3472
  6920. This commit makes a bunch of stylistic updates, minor changes and other
  6921. stuff that's part of the improvements pass I'm doing to the code after
  6922. taking into account feedback from the list.
  6923. It also alters the ACPI buffer fetching code to be more generalisable so
  6924. I can re-use it to fetch the clock frequency.
  6925. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  6926. Patchset: cameras
  6927. ---
  6928. .../platform/x86/intel_skl_int3472_common.c | 37 ++++---
  6929. .../platform/x86/intel_skl_int3472_common.h | 7 +-
  6930. .../platform/x86/intel_skl_int3472_discrete.c | 101 +++++++++---------
  6931. .../platform/x86/intel_skl_int3472_tps68470.c | 16 +--
  6932. 4 files changed, 89 insertions(+), 72 deletions(-)
  6933. diff --git a/drivers/platform/x86/intel_skl_int3472_common.c b/drivers/platform/x86/intel_skl_int3472_common.c
  6934. index 08cb9d3c06aa..549d211979e1 100644
  6935. --- a/drivers/platform/x86/intel_skl_int3472_common.c
  6936. +++ b/drivers/platform/x86/intel_skl_int3472_common.c
  6937. @@ -7,41 +7,52 @@
  6938. #include "intel_skl_int3472_common.h"
  6939. -int skl_int3472_get_cldb_buffer(struct acpi_device *adev,
  6940. - struct int3472_cldb *cldb)
  6941. +union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev,
  6942. + char *id)
  6943. {
  6944. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  6945. acpi_handle handle = adev->handle;
  6946. union acpi_object *obj;
  6947. acpi_status status;
  6948. - int ret = 0;
  6949. - status = acpi_evaluate_object(handle, "CLDB", NULL, &buffer);
  6950. + status = acpi_evaluate_object(handle, id, NULL, &buffer);
  6951. if (ACPI_FAILURE(status))
  6952. - return -ENODEV;
  6953. + return ERR_PTR(-ENODEV);
  6954. obj = buffer.pointer;
  6955. if (!obj) {
  6956. - dev_err(&adev->dev, "ACPI device has no CLDB object\n");
  6957. - return -ENODEV;
  6958. + dev_err(&adev->dev, "ACPI device has no %s object\n", id);
  6959. + return ERR_PTR(-ENODEV);
  6960. }
  6961. if (obj->type != ACPI_TYPE_BUFFER) {
  6962. - dev_err(&adev->dev, "CLDB object is not an ACPI buffer\n");
  6963. - ret = -EINVAL;
  6964. - goto out_free_buff;
  6965. + dev_err(&adev->dev, "%s object is not an ACPI buffer\n", id);
  6966. + kfree(obj);
  6967. + return ERR_PTR(-EINVAL);
  6968. }
  6969. + return obj;
  6970. +}
  6971. +
  6972. +int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb)
  6973. +{
  6974. + union acpi_object *obj;
  6975. + int ret = 0;
  6976. +
  6977. + obj = skl_int3472_get_acpi_buffer(adev, "CLDB");
  6978. + if (IS_ERR(obj))
  6979. + return PTR_ERR(obj);
  6980. +
  6981. if (obj->buffer.length > sizeof(*cldb)) {
  6982. dev_err(&adev->dev, "The CLDB buffer is too large\n");
  6983. ret = -EINVAL;
  6984. - goto out_free_buff;
  6985. + goto out_free_obj;
  6986. }
  6987. memcpy(cldb, obj->buffer.pointer, obj->buffer.length);
  6988. -out_free_buff:
  6989. - kfree(buffer.pointer);
  6990. +out_free_obj:
  6991. + kfree(obj);
  6992. return ret;
  6993. }
  6994. diff --git a/drivers/platform/x86/intel_skl_int3472_common.h b/drivers/platform/x86/intel_skl_int3472_common.h
  6995. index 4ac6bb2b223f..e1083bb67dc6 100644
  6996. --- a/drivers/platform/x86/intel_skl_int3472_common.h
  6997. +++ b/drivers/platform/x86/intel_skl_int3472_common.h
  6998. @@ -29,7 +29,7 @@
  6999. #define INT3472_GPIO_FUNCTION_REMAP(_PIN, _FUNCTION) \
  7000. (const struct int3472_gpio_function_remap) { \
  7001. - .documented = _PIN, \
  7002. + .documented = _PIN, \
  7003. .actual = _FUNCTION \
  7004. }
  7005. @@ -95,5 +95,6 @@ struct int3472_sensor_config {
  7006. int skl_int3472_discrete_probe(struct platform_device *pdev);
  7007. int skl_int3472_discrete_remove(struct platform_device *pdev);
  7008. int skl_int3472_tps68470_probe(struct i2c_client *client);
  7009. -int skl_int3472_get_cldb_buffer(struct acpi_device *adev,
  7010. - struct int3472_cldb *cldb);
  7011. +union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev,
  7012. + char *id);
  7013. +int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb);
  7014. diff --git a/drivers/platform/x86/intel_skl_int3472_discrete.c b/drivers/platform/x86/intel_skl_int3472_discrete.c
  7015. index ea7e57f3e3f0..42ae8396eb64 100644
  7016. --- a/drivers/platform/x86/intel_skl_int3472_discrete.c
  7017. +++ b/drivers/platform/x86/intel_skl_int3472_discrete.c
  7018. @@ -12,12 +12,12 @@
  7019. #include "intel_skl_int3472_common.h"
  7020. -/* 79234640-9e10-4fea-a5c1b5aa8b19756f */
  7021. +/* 79234640-9e10-4fea-a5c1-b5aa8b19756f */
  7022. static const guid_t int3472_gpio_guid =
  7023. GUID_INIT(0x79234640, 0x9e10, 0x4fea,
  7024. 0xa5, 0xc1, 0xb5, 0xaa, 0x8b, 0x19, 0x75, 0x6f);
  7025. -/* 822ace8f-2814-4174-a56b5f029fe079ee */
  7026. +/* 822ace8f-2814-4174-a56b-5f029fe079ee */
  7027. static const guid_t cio2_sensor_module_guid =
  7028. GUID_INIT(0x822ace8f, 0x2814, 0x4174,
  7029. 0xa5, 0x6b, 0x5f, 0x02, 0x9f, 0xe0, 0x79, 0xee);
  7030. @@ -94,7 +94,7 @@ static const struct clk_ops skl_int3472_clock_ops = {
  7031. };
  7032. static struct int3472_sensor_config *
  7033. -int3472_get_sensor_module_config(struct int3472_device *int3472)
  7034. +skl_int3472_get_sensor_module_config(struct int3472_device *int3472)
  7035. {
  7036. unsigned int i = ARRAY_SIZE(int3472_sensor_configs);
  7037. struct int3472_sensor_config *ret;
  7038. @@ -131,9 +131,9 @@ int3472_get_sensor_module_config(struct int3472_device *int3472)
  7039. return ret;
  7040. }
  7041. -static int int3472_map_gpio_to_sensor(struct int3472_device *int3472,
  7042. - struct acpi_resource *ares,
  7043. - char *func, u32 polarity)
  7044. +static int skl_int3472_map_gpio_to_sensor(struct int3472_device *int3472,
  7045. + struct acpi_resource *ares,
  7046. + char *func, u32 polarity)
  7047. {
  7048. char *path = ares->data.gpio.resource_source.string_ptr;
  7049. struct int3472_sensor_config *sensor_config;
  7050. @@ -143,7 +143,7 @@ static int int3472_map_gpio_to_sensor(struct int3472_device *int3472,
  7051. acpi_status status;
  7052. int ret;
  7053. - sensor_config = int3472_get_sensor_module_config(int3472);
  7054. + sensor_config = skl_int3472_get_sensor_module_config(int3472);
  7055. if (!IS_ERR(sensor_config) && sensor_config->function_maps) {
  7056. unsigned int i = 0;
  7057. @@ -186,17 +186,19 @@ static int int3472_map_gpio_to_sensor(struct int3472_device *int3472,
  7058. return 0;
  7059. }
  7060. -static int int3472_register_clock(struct int3472_device *int3472,
  7061. - struct acpi_resource *ares)
  7062. +static int skl_int3472_register_clock(struct int3472_device *int3472,
  7063. + struct acpi_resource *ares)
  7064. {
  7065. char *path = ares->data.gpio.resource_source.string_ptr;
  7066. - struct clk_init_data init = { };
  7067. + struct clk_init_data init = { 0 };
  7068. int ret = 0;
  7069. - init.name = kasprintf(GFP_KERNEL, "%s-clk", acpi_dev_name(int3472->adev));
  7070. + init.name = kasprintf(GFP_KERNEL, "%s-clk",
  7071. + acpi_dev_name(int3472->adev));
  7072. init.ops = &skl_int3472_clock_ops;
  7073. - int3472->clock.gpio = acpi_get_gpiod(path, ares->data.gpio.pin_table[0]);
  7074. + int3472->clock.gpio = acpi_get_gpiod(path,
  7075. + ares->data.gpio.pin_table[0]);
  7076. if (IS_ERR(int3472->clock.gpio)) {
  7077. ret = PTR_ERR(int3472->clock.gpio);
  7078. goto out_free_init_name;
  7079. @@ -226,17 +228,16 @@ static int int3472_register_clock(struct int3472_device *int3472,
  7080. return ret;
  7081. }
  7082. -static int int3472_register_regulator(struct int3472_device *int3472,
  7083. - struct acpi_resource *ares)
  7084. +static int skl_int3472_register_regulator(struct int3472_device *int3472,
  7085. + struct acpi_resource *ares)
  7086. {
  7087. char *path = ares->data.gpio.resource_source.string_ptr;
  7088. struct int3472_sensor_config *sensor_config;
  7089. struct regulator_init_data init_data = { };
  7090. - struct int3472_gpio_regulator *regulator;
  7091. struct regulator_config cfg = { };
  7092. int ret;
  7093. - sensor_config = int3472_get_sensor_module_config(int3472);
  7094. + sensor_config = skl_int3472_get_sensor_module_config(int3472);
  7095. if (IS_ERR_OR_NULL(sensor_config)) {
  7096. dev_err(&int3472->pdev->dev, "No sensor module config\n");
  7097. return PTR_ERR(sensor_config);
  7098. @@ -252,26 +253,29 @@ static int int3472_register_regulator(struct int3472_device *int3472,
  7099. init_data.num_consumer_supplies = 1;
  7100. init_data.consumer_supplies = &sensor_config->supply_map;
  7101. - snprintf(int3472->regulator.regulator_name, GPIO_REGULATOR_NAME_LENGTH,
  7102. - "int3472-discrete-regulator");
  7103. - snprintf(int3472->regulator.supply_name, GPIO_REGULATOR_SUPPLY_NAME_LENGTH,
  7104. - "supply-0");
  7105. + snprintf(int3472->regulator.regulator_name,
  7106. + GPIO_REGULATOR_NAME_LENGTH, "int3472-discrete-regulator");
  7107. + snprintf(int3472->regulator.supply_name,
  7108. + GPIO_REGULATOR_SUPPLY_NAME_LENGTH, "supply-0");
  7109. - int3472->regulator.rdesc = INT3472_REGULATOR(int3472->regulator.regulator_name,
  7110. - int3472->regulator.supply_name,
  7111. - &int3472_gpio_regulator_ops);
  7112. + int3472->regulator.rdesc = INT3472_REGULATOR(
  7113. + int3472->regulator.regulator_name,
  7114. + int3472->regulator.supply_name,
  7115. + &int3472_gpio_regulator_ops);
  7116. - int3472->regulator.gpio = acpi_get_gpiod(path, ares->data.gpio.pin_table[0]);
  7117. + int3472->regulator.gpio = acpi_get_gpiod(path,
  7118. + ares->data.gpio.pin_table[0]);
  7119. if (IS_ERR(int3472->regulator.gpio)) {
  7120. - ret = PTR_ERR(int3472->regulator.gpio);
  7121. - goto err_free_regulator;
  7122. + dev_err(&int3472->pdev->dev, "Failed to get GPIO line\n");
  7123. + return PTR_ERR(int3472->regulator.gpio);
  7124. }
  7125. cfg.dev = &int3472->adev->dev;
  7126. cfg.init_data = &init_data;
  7127. cfg.ena_gpiod = int3472->regulator.gpio;
  7128. - int3472->regulator.rdev = regulator_register(&int3472->regulator.rdesc, &cfg);
  7129. + int3472->regulator.rdev = regulator_register(&int3472->regulator.rdesc,
  7130. + &cfg);
  7131. if (IS_ERR(int3472->regulator.rdev)) {
  7132. ret = PTR_ERR(int3472->regulator.rdev);
  7133. goto err_free_gpio;
  7134. @@ -280,15 +284,13 @@ static int int3472_register_regulator(struct int3472_device *int3472,
  7135. return 0;
  7136. err_free_gpio:
  7137. - gpiod_put(regulator->gpio);
  7138. -err_free_regulator:
  7139. - kfree(regulator);
  7140. + gpiod_put(int3472->regulator.gpio);
  7141. return ret;
  7142. }
  7143. /**
  7144. - * int3472_handle_gpio_resources: maps PMIC resources to consuming sensor
  7145. + * skl_int3472_handle_gpio_resources: maps PMIC resources to consuming sensor
  7146. * @ares: A pointer to a &struct acpi_resource
  7147. * @data: A pointer to a &struct int3472_device
  7148. *
  7149. @@ -305,8 +307,9 @@ static int int3472_register_regulator(struct int3472_device *int3472,
  7150. *
  7151. * There are some known platform specific quirks where that does not quite
  7152. * hold up; for example where a pin with type 0x01 (Power down) is mapped to
  7153. - * a sensor pin that performs a reset function. These will be handled by the
  7154. - * mapping sub-functions.
  7155. + * a sensor pin that performs a reset function or entries in _CRS and _DSM that
  7156. + * do not actually correspond to a physical connection. These will be handled by
  7157. + * the mapping sub-functions.
  7158. *
  7159. * GPIOs will either be mapped directly to the sensor device or else used
  7160. * to create clocks and regulators via the usual frameworks.
  7161. @@ -317,8 +320,8 @@ static int int3472_register_regulator(struct int3472_device *int3472,
  7162. * * -ENODEV - If the resource has no corresponding _DSM entry
  7163. * * -Other - Errors propagated from one of the sub-functions.
  7164. */
  7165. -static int int3472_handle_gpio_resources(struct acpi_resource *ares,
  7166. - void *data)
  7167. +static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
  7168. + void *data)
  7169. {
  7170. struct int3472_device *int3472 = data;
  7171. union acpi_object *obj;
  7172. @@ -345,30 +348,30 @@ static int int3472_handle_gpio_resources(struct acpi_resource *ares,
  7173. switch (obj->integer.value & 0xff) {
  7174. case INT3472_GPIO_TYPE_RESET:
  7175. - ret = int3472_map_gpio_to_sensor(int3472, ares, "reset",
  7176. - GPIO_ACTIVE_LOW);
  7177. + ret = skl_int3472_map_gpio_to_sensor(int3472, ares, "reset",
  7178. + GPIO_ACTIVE_LOW);
  7179. if (ret)
  7180. dev_err(&int3472->pdev->dev,
  7181. "Failed to map reset pin to sensor\n");
  7182. break;
  7183. case INT3472_GPIO_TYPE_POWERDOWN:
  7184. - ret = int3472_map_gpio_to_sensor(int3472, ares, "powerdown",
  7185. - GPIO_ACTIVE_LOW);
  7186. + ret = skl_int3472_map_gpio_to_sensor(int3472, ares, "powerdown",
  7187. + GPIO_ACTIVE_LOW);
  7188. if (ret)
  7189. dev_err(&int3472->pdev->dev,
  7190. "Failed to map powerdown pin to sensor\n");
  7191. break;
  7192. case INT3472_GPIO_TYPE_CLK_ENABLE:
  7193. - ret = int3472_register_clock(int3472, ares);
  7194. + ret = skl_int3472_register_clock(int3472, ares);
  7195. if (ret)
  7196. dev_err(&int3472->pdev->dev,
  7197. "Failed to map clock to sensor\n");
  7198. break;
  7199. case INT3472_GPIO_TYPE_POWER_ENABLE:
  7200. - ret = int3472_register_regulator(int3472, ares);
  7201. + ret = skl_int3472_register_regulator(int3472, ares);
  7202. if (ret) {
  7203. dev_err(&int3472->pdev->dev,
  7204. "Failed to map regulator to sensor\n");
  7205. @@ -376,8 +379,9 @@ static int int3472_handle_gpio_resources(struct acpi_resource *ares,
  7206. break;
  7207. case INT3472_GPIO_TYPE_PRIVACY_LED:
  7208. - ret = int3472_map_gpio_to_sensor(int3472, ares, "indicator-led",
  7209. - GPIO_ACTIVE_HIGH);
  7210. + ret = skl_int3472_map_gpio_to_sensor(int3472, ares,
  7211. + "indicator-led",
  7212. + GPIO_ACTIVE_HIGH);
  7213. if (ret)
  7214. dev_err(&int3472->pdev->dev,
  7215. "Failed to map indicator led to sensor\n");
  7216. @@ -396,7 +400,7 @@ static int int3472_handle_gpio_resources(struct acpi_resource *ares,
  7217. return ret;
  7218. }
  7219. -static int int3472_parse_crs(struct int3472_device *int3472)
  7220. +static int skl_int3472_parse_crs(struct int3472_device *int3472)
  7221. {
  7222. struct list_head resource_list;
  7223. int ret = 0;
  7224. @@ -404,7 +408,8 @@ static int int3472_parse_crs(struct int3472_device *int3472)
  7225. INIT_LIST_HEAD(&resource_list);
  7226. ret = acpi_dev_get_resources(int3472->adev, &resource_list,
  7227. - int3472_handle_gpio_resources, int3472);
  7228. + skl_int3472_handle_gpio_resources,
  7229. + int3472);
  7230. if (!ret) {
  7231. gpiod_add_lookup_table(&int3472->gpios);
  7232. @@ -423,7 +428,7 @@ int skl_int3472_discrete_probe(struct platform_device *pdev)
  7233. struct int3472_cldb cldb;
  7234. int ret = 0;
  7235. - ret = skl_int3472_get_cldb_buffer(adev, &cldb);
  7236. + ret = skl_int3472_fill_cldb(adev, &cldb);
  7237. if (ret || cldb.control_logic_type != 1)
  7238. return -EINVAL;
  7239. @@ -444,10 +449,10 @@ int skl_int3472_discrete_probe(struct platform_device *pdev)
  7240. ret = -ENODEV;
  7241. goto err_free_int3472;
  7242. }
  7243. - int3472->sensor_name = i2c_acpi_dev_name(int3472->sensor);
  7244. + int3472->sensor_name = kasprintf(GFP_KERNEL, I2C_DEV_NAME_FORMAT, acpi_dev_name(int3472->sensor));
  7245. int3472->gpios.dev_id = int3472->sensor_name;
  7246. - ret = int3472_parse_crs(int3472);
  7247. + ret = skl_int3472_parse_crs(int3472);
  7248. if (ret) {
  7249. skl_int3472_discrete_remove(pdev);
  7250. goto err_return_ret;
  7251. diff --git a/drivers/platform/x86/intel_skl_int3472_tps68470.c b/drivers/platform/x86/intel_skl_int3472_tps68470.c
  7252. index 3fe27ec0caff..40629291b339 100644
  7253. --- a/drivers/platform/x86/intel_skl_int3472_tps68470.c
  7254. +++ b/drivers/platform/x86/intel_skl_int3472_tps68470.c
  7255. @@ -87,20 +87,20 @@ int skl_int3472_tps68470_probe(struct i2c_client *client)
  7256. /*
  7257. * Check CLDB buffer against the PMIC's adev. If present, then we check
  7258. - * the value of control_logic_type field and follow one of the following
  7259. - * scenarios:
  7260. + * the value of control_logic_type field and follow one of the
  7261. + * following scenarios:
  7262. *
  7263. - * 1. No CLDB - likely ACPI tables designed for ChromeOS. We create
  7264. - * platform devices for the GPIOs and OpRegion drivers.
  7265. + * 1. No CLDB - likely ACPI tables designed for ChromeOS. We
  7266. + * create platform devices for the GPIOs and OpRegion drivers.
  7267. *
  7268. - * 2. CLDB, with control_logic_type = 2 - probably ACPI tables made
  7269. - * for Windows 2-in-1 platforms. Register pdevs for GPIO, Clock and
  7270. - * Regulator drivers to bind to.
  7271. + * 2. CLDB, with control_logic_type = 2 - probably ACPI tables
  7272. + * made for Windows 2-in-1 platforms. Register pdevs for GPIO,
  7273. + * Clock and Regulator drivers to bind to.
  7274. *
  7275. * 3. Any other value in control_logic_type, we should never have
  7276. * gotten to this point; crash and burn.
  7277. */
  7278. - ret = skl_int3472_get_cldb_buffer(adev, &cldb);
  7279. + ret = skl_int3472_fill_cldb(adev, &cldb);
  7280. if (!ret && cldb.control_logic_type != 2)
  7281. return -EINVAL;
  7282. --
  7283. 2.33.0
  7284. From 44e995a18984d3b9406e53da163ec61619c56d9a Mon Sep 17 00:00:00 2001
  7285. From: Daniel Scally <djrscally@gmail.com>
  7286. Date: Sat, 23 Jan 2021 00:30:15 +0000
  7287. Subject: [PATCH] platform: x86: Add recalc_rate opp to int3472-discrete clock
  7288. This commit adds the recalc_rate opp to the clock registered by
  7289. int3472-discrete so that sensor drivers calling clk_get_rate() will get a
  7290. valid value returned.
  7291. The value is simply read from the sensor's SSDB buffer, and so we pass
  7292. CLK_GET_RATE_NOCACHE
  7293. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  7294. Patchset: cameras
  7295. ---
  7296. .../platform/x86/intel_skl_int3472_common.h | 6 +++
  7297. .../platform/x86/intel_skl_int3472_discrete.c | 37 ++++++++++++++++++-
  7298. 2 files changed, 41 insertions(+), 2 deletions(-)
  7299. diff --git a/drivers/platform/x86/intel_skl_int3472_common.h b/drivers/platform/x86/intel_skl_int3472_common.h
  7300. index e1083bb67dc6..860c849b7769 100644
  7301. --- a/drivers/platform/x86/intel_skl_int3472_common.h
  7302. +++ b/drivers/platform/x86/intel_skl_int3472_common.h
  7303. @@ -17,6 +17,8 @@
  7304. #define GPIO_REGULATOR_NAME_LENGTH 27
  7305. #define GPIO_REGULATOR_SUPPLY_NAME_LENGTH 9
  7306. +#define CIO2_SENSOR_SSDB_MCLKSPEED_OFFSET 86
  7307. +
  7308. #define INT3472_REGULATOR(_NAME, _SUPPLY, _OPS) \
  7309. (const struct regulator_desc) { \
  7310. .name = _NAME, \
  7311. @@ -36,6 +38,9 @@
  7312. #define to_int3472_clk(hw) \
  7313. container_of(hw, struct int3472_gpio_clock, clk_hw)
  7314. +#define to_int3472_device(clk) \
  7315. + container_of(clk, struct int3472_device, clock)
  7316. +
  7317. struct int3472_cldb {
  7318. u8 version;
  7319. /*
  7320. @@ -62,6 +67,7 @@ struct int3472_gpio_regulator {
  7321. struct int3472_gpio_clock {
  7322. struct clk *clk;
  7323. struct clk_hw clk_hw;
  7324. + struct clk_lookup *cl;
  7325. struct gpio_desc *gpio;
  7326. };
  7327. diff --git a/drivers/platform/x86/intel_skl_int3472_discrete.c b/drivers/platform/x86/intel_skl_int3472_discrete.c
  7328. index 42ae8396eb64..98eb1ec3399e 100644
  7329. --- a/drivers/platform/x86/intel_skl_int3472_discrete.c
  7330. +++ b/drivers/platform/x86/intel_skl_int3472_discrete.c
  7331. @@ -86,11 +86,41 @@ static void skl_int3472_clk_unprepare(struct clk_hw *hw)
  7332. /* Likewise, nothing to do here... */
  7333. }
  7334. +static unsigned int skl_int3472_get_clk_frequency(struct int3472_device *int3472)
  7335. +{
  7336. + union acpi_object *obj;
  7337. + unsigned int ret = 0;
  7338. +
  7339. + obj = skl_int3472_get_acpi_buffer(int3472->sensor, "SSDB");
  7340. + if (IS_ERR(obj))
  7341. + goto out_free_buff; /* report rate as 0 on error */
  7342. +
  7343. + if (obj->buffer.length < CIO2_SENSOR_SSDB_MCLKSPEED_OFFSET + sizeof(u32)) {
  7344. + dev_err(&int3472->pdev->dev, "The buffer is too small\n");
  7345. + goto out_free_buff;
  7346. + }
  7347. +
  7348. + ret = *(u32*)(obj->buffer.pointer + CIO2_SENSOR_SSDB_MCLKSPEED_OFFSET);
  7349. +
  7350. +out_free_buff:
  7351. + kfree(obj);
  7352. + return ret;
  7353. +}
  7354. +
  7355. +static unsigned long skl_int3472_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
  7356. +{
  7357. + struct int3472_gpio_clock *clk = to_int3472_clk(hw);
  7358. + struct int3472_device *int3472 = to_int3472_device(clk);
  7359. +
  7360. + return skl_int3472_get_clk_frequency(int3472);
  7361. +}
  7362. +
  7363. static const struct clk_ops skl_int3472_clock_ops = {
  7364. .prepare = skl_int3472_clk_prepare,
  7365. .unprepare = skl_int3472_clk_unprepare,
  7366. .enable = skl_int3472_clk_enable,
  7367. .disable = skl_int3472_clk_disable,
  7368. + .recalc_rate = skl_int3472_clk_recalc_rate,
  7369. };
  7370. static struct int3472_sensor_config *
  7371. @@ -196,6 +226,7 @@ static int skl_int3472_register_clock(struct int3472_device *int3472,
  7372. init.name = kasprintf(GFP_KERNEL, "%s-clk",
  7373. acpi_dev_name(int3472->adev));
  7374. init.ops = &skl_int3472_clock_ops;
  7375. + init.flags |= CLK_GET_RATE_NOCACHE;
  7376. int3472->clock.gpio = acpi_get_gpiod(path,
  7377. ares->data.gpio.pin_table[0]);
  7378. @@ -212,8 +243,9 @@ static int skl_int3472_register_clock(struct int3472_device *int3472,
  7379. goto err_put_gpio;
  7380. }
  7381. - ret = clk_register_clkdev(int3472->clock.clk, "xvclk", int3472->sensor_name);
  7382. - if (ret)
  7383. + int3472->clock.cl = clkdev_create(int3472->clock.clk, "xvclk",
  7384. + int3472->sensor_name);
  7385. + if (IS_ERR_OR_NULL(int3472->clock.cl))
  7386. goto err_unregister_clk;
  7387. goto out_free_init_name;
  7388. @@ -483,6 +515,7 @@ int skl_int3472_discrete_remove(struct platform_device *pdev)
  7389. if (!IS_ERR_OR_NULL(int3472->clock.clk)) {
  7390. gpiod_put(int3472->clock.gpio);
  7391. clk_unregister(int3472->clock.clk);
  7392. + clkdev_drop(int3472->clock.cl);
  7393. }
  7394. acpi_dev_put(int3472->sensor);
  7395. --
  7396. 2.33.0
  7397. From af463fa43654ac271940b47b9f9bd31a6d332750 Mon Sep 17 00:00:00 2001
  7398. From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= <me@fabwu.ch>
  7399. Date: Sun, 24 Jan 2021 11:07:42 +0100
  7400. Subject: [PATCH] cio2-bridge: Use macros and add warnings
  7401. MIME-Version: 1.0
  7402. Content-Type: text/plain; charset=UTF-8
  7403. Content-Transfer-Encoding: 8bit
  7404. Use macros for the _PLD panel as defined in the ACPI spec 6.3 and emit
  7405. a warning if we see an unknown value.
  7406. Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
  7407. Patchset: cameras
  7408. ---
  7409. drivers/media/pci/intel/ipu3/cio2-bridge.c | 33 ++++++++++++++++------
  7410. drivers/media/pci/intel/ipu3/cio2-bridge.h | 13 +++++++++
  7411. 2 files changed, 37 insertions(+), 9 deletions(-)
  7412. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  7413. index 806d4e5fc177..3c373ad1c0b0 100644
  7414. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
  7415. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  7416. @@ -73,21 +73,36 @@ static int cio2_bridge_read_acpi_buffer(struct acpi_device *adev, char *id,
  7417. return ret;
  7418. }
  7419. -static u32 cio2_bridge_parse_rotation(u8 rotation)
  7420. +static u32 cio2_bridge_parse_rotation(struct cio2_sensor *sensor)
  7421. {
  7422. - if (rotation == 1)
  7423. + switch (sensor->ssdb.degree) {
  7424. + case CIO2_SENSOR_ROTATION_NORMAL:
  7425. + return 0;
  7426. + case CIO2_SENSOR_ROTATION_INVERTED:
  7427. return 180;
  7428. - return 0;
  7429. + default:
  7430. + dev_warn(&sensor->adev->dev,
  7431. + "Unknown rotation %d. Assume 0 degree rotation\n",
  7432. + sensor->ssdb.degree);
  7433. + return 0;
  7434. + }
  7435. }
  7436. -static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(u8 panel)
  7437. +static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(struct cio2_sensor *sensor)
  7438. {
  7439. - switch (panel) {
  7440. - case 4:
  7441. + switch (sensor->pld->panel) {
  7442. + case CIO2_PLD_PANEL_FRONT:
  7443. return V4L2_FWNODE_ORIENTATION_FRONT;
  7444. - case 5:
  7445. + case CIO2_PLD_PANEL_BACK:
  7446. return V4L2_FWNODE_ORIENTATION_BACK;
  7447. + case CIO2_PLD_PANEL_TOP:
  7448. + case CIO2_PLD_PANEL_LEFT:
  7449. + case CIO2_PLD_PANEL_RIGHT:
  7450. + case CIO2_PLD_PANEL_UNKNOWN:
  7451. + return V4L2_FWNODE_ORIENTATION_EXTERNAL;
  7452. default:
  7453. + dev_warn(&sensor->adev->dev, "Unknown _PLD panel value %d\n",
  7454. + sensor->pld->panel);
  7455. return V4L2_FWNODE_ORIENTATION_EXTERNAL;
  7456. }
  7457. }
  7458. @@ -100,8 +115,8 @@ static void cio2_bridge_create_fwnode_properties(
  7459. u32 rotation;
  7460. enum v4l2_fwnode_orientation orientation;
  7461. - rotation = cio2_bridge_parse_rotation(sensor->ssdb.degree);
  7462. - orientation = cio2_bridge_parse_orientation(sensor->pld->panel);
  7463. + rotation = cio2_bridge_parse_rotation(sensor);
  7464. + orientation = cio2_bridge_parse_orientation(sensor);
  7465. sensor->prop_names = prop_names;
  7466. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  7467. index 924d99d20328..e1e388cc9f45 100644
  7468. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
  7469. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  7470. @@ -12,6 +12,19 @@
  7471. #define CIO2_MAX_LANES 4
  7472. #define MAX_NUM_LINK_FREQS 3
  7473. +/* Values are estimated guesses as we don't have a spec */
  7474. +#define CIO2_SENSOR_ROTATION_NORMAL 0
  7475. +#define CIO2_SENSOR_ROTATION_INVERTED 1
  7476. +
  7477. +/* Panel position defined in _PLD section of ACPI Specification 6.3 */
  7478. +#define CIO2_PLD_PANEL_TOP 0
  7479. +#define CIO2_PLD_PANEL_BOTTOM 1
  7480. +#define CIO2_PLD_PANEL_LEFT 2
  7481. +#define CIO2_PLD_PANEL_RIGHT 3
  7482. +#define CIO2_PLD_PANEL_FRONT 4
  7483. +#define CIO2_PLD_PANEL_BACK 5
  7484. +#define CIO2_PLD_PANEL_UNKNOWN 6
  7485. +
  7486. #define CIO2_SENSOR_CONFIG(_HID, _NR, ...) \
  7487. (const struct cio2_sensor_config) { \
  7488. .hid = _HID, \
  7489. --
  7490. 2.33.0
  7491. From 9f5594c8807e188c8f57a84a9574be82446118fb Mon Sep 17 00:00:00 2001
  7492. From: Daniel Scally <djrscally@gmail.com>
  7493. Date: Mon, 8 Feb 2021 21:44:38 +0000
  7494. Subject: [PATCH] media: i2c: Tidy up ov5693_init_controls()
  7495. The ov5693 driver initialises a bunch of v4l2 controls and throws away
  7496. the pointers. This seems weird, let's not do that.
  7497. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  7498. Patchset: cameras
  7499. ---
  7500. drivers/media/i2c/ov5693.c | 46 ++++++++++++++++++++++----------------
  7501. drivers/media/i2c/ov5693.h | 12 +++++++++-
  7502. 2 files changed, 38 insertions(+), 20 deletions(-)
  7503. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  7504. index 1a85800df7ed..a9747ab783d7 100644
  7505. --- a/drivers/media/i2c/ov5693.c
  7506. +++ b/drivers/media/i2c/ov5693.c
  7507. @@ -1610,7 +1610,6 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  7508. struct i2c_client *client = v4l2_get_subdevdata(&ov5693->sd);
  7509. const struct v4l2_ctrl_ops *ops = &ov5693_ctrl_ops;
  7510. struct v4l2_fwnode_device_properties props;
  7511. - struct v4l2_ctrl *ctrl;
  7512. unsigned int i;
  7513. int ret;
  7514. int hblank;
  7515. @@ -1628,15 +1627,17 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  7516. NULL);
  7517. /* link freq */
  7518. - ctrl = v4l2_ctrl_new_int_menu(&ov5693->ctrl_handler, NULL,
  7519. - V4L2_CID_LINK_FREQ,
  7520. - 0, 0, link_freq_menu_items);
  7521. - if (ctrl)
  7522. - ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  7523. + ov5693->ctrls.link_freq = v4l2_ctrl_new_int_menu(&ov5693->ctrl_handler,
  7524. + NULL, V4L2_CID_LINK_FREQ,
  7525. + 0, 0, link_freq_menu_items);
  7526. + if (ov5693->ctrls.link_freq)
  7527. + ov5693->ctrls.link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  7528. /* pixel rate */
  7529. - v4l2_ctrl_new_std(&ov5693->ctrl_handler, NULL, V4L2_CID_PIXEL_RATE,
  7530. - 0, OV5693_PIXEL_RATE, 1, OV5693_PIXEL_RATE);
  7531. + ov5693->ctrls.pixel_rate = v4l2_ctrl_new_std(&ov5693->ctrl_handler, NULL,
  7532. + V4L2_CID_PIXEL_RATE, 0,
  7533. + OV5693_PIXEL_RATE, 1,
  7534. + OV5693_PIXEL_RATE);
  7535. if (ov5693->ctrl_handler.error) {
  7536. ov5693_remove(client);
  7537. @@ -1645,25 +1646,32 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  7538. /* Exposure */
  7539. - v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops, V4L2_CID_EXPOSURE, 16, 1048575, 16,
  7540. - 512);
  7541. + ov5693->ctrls.exposure = v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops,
  7542. + V4L2_CID_EXPOSURE, 16,
  7543. + 1048575, 16, 512);
  7544. /* Gain */
  7545. - v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops, V4L2_CID_ANALOGUE_GAIN, 1, 1023, 1, 128);
  7546. - v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops, V4L2_CID_DIGITAL_GAIN, 1, 3999, 1, 1000);
  7547. + ov5693->ctrls.analogue_gain = v4l2_ctrl_new_std(&ov5693->ctrl_handler,
  7548. + ops, V4L2_CID_ANALOGUE_GAIN,
  7549. + 1, 1023, 1, 128);
  7550. + ov5693->ctrls.digital_gain = v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops,
  7551. + V4L2_CID_DIGITAL_GAIN, 1,
  7552. + 3999, 1, 1000);
  7553. /* Flip */
  7554. - v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops, V4L2_CID_HFLIP, 0, 1, 1, 0);
  7555. - v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops, V4L2_CID_VFLIP, 0, 1, 1, 0);
  7556. + ov5693->ctrls.hflip = v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops,
  7557. + V4L2_CID_HFLIP, 0, 1, 1, 0);
  7558. + ov5693->ctrls.vflip = v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops,
  7559. + V4L2_CID_VFLIP, 0, 1, 1, 0);
  7560. hblank = OV5693_PPL_DEFAULT - ov5693->mode->width;
  7561. - ov5693->hblank = v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops,
  7562. - V4L2_CID_HBLANK, hblank, hblank,
  7563. - 1, hblank);
  7564. - if (ov5693->hblank)
  7565. - ov5693->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  7566. + ov5693->ctrls.hblank = v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops,
  7567. + V4L2_CID_HBLANK, hblank, hblank,
  7568. + 1, hblank);
  7569. + if (ov5693->ctrls.hblank)
  7570. + ov5693->ctrls.hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  7571. /* set properties from fwnode (e.g. rotation, orientation) */
  7572. ret = v4l2_fwnode_device_parse(&client->dev, &props);
  7573. diff --git a/drivers/media/i2c/ov5693.h b/drivers/media/i2c/ov5693.h
  7574. index 9a508e1f3624..26819cf3f4d2 100644
  7575. --- a/drivers/media/i2c/ov5693.h
  7576. +++ b/drivers/media/i2c/ov5693.h
  7577. @@ -270,7 +270,17 @@ struct ov5693_device {
  7578. bool has_vcm;
  7579. - struct v4l2_ctrl *hblank;
  7580. + struct ov5693_v4l2_ctrls {
  7581. + struct v4l2_ctrl *link_freq;
  7582. + struct v4l2_ctrl *pixel_rate;
  7583. + struct v4l2_ctrl *exposure;
  7584. + struct v4l2_ctrl *analogue_gain;
  7585. + struct v4l2_ctrl *digital_gain;
  7586. + struct v4l2_ctrl *hflip;
  7587. + struct v4l2_ctrl *vflip;
  7588. + struct v4l2_ctrl *hblank;
  7589. + } ctrls;
  7590. +
  7591. };
  7592. enum ov5693_tok_type {
  7593. --
  7594. 2.33.0
  7595. From 5fc8a53c12d4549b0196f9cecac40c4a4f985873 Mon Sep 17 00:00:00 2001
  7596. From: Daniel Scally <djrscally@gmail.com>
  7597. Date: Mon, 8 Feb 2021 21:46:49 +0000
  7598. Subject: [PATCH] media: i2c: Remove OV5693_PPL_DEFAULT
  7599. No need for this macro, the PPL setting is against the mode structs.
  7600. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  7601. Patchset: cameras
  7602. ---
  7603. drivers/media/i2c/ov5693.c | 4 +---
  7604. 1 file changed, 1 insertion(+), 3 deletions(-)
  7605. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  7606. index a9747ab783d7..7fb368eec327 100644
  7607. --- a/drivers/media/i2c/ov5693.c
  7608. +++ b/drivers/media/i2c/ov5693.c
  7609. @@ -105,8 +105,6 @@ MODULE_PARM_DESC(up_delay,
  7610. #define OV5693_PIXEL_ARRAY_WIDTH 2592U
  7611. #define OV5693_PIXEL_ARRAY_HEIGHT 1944U
  7612. -#define OV5693_PPL_DEFAULT 2800
  7613. -
  7614. static int vcm_ad_i2c_wr8(struct i2c_client *client, u8 reg, u8 val)
  7615. {
  7616. int err;
  7617. @@ -1666,7 +1664,7 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  7618. ov5693->ctrls.vflip = v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops,
  7619. V4L2_CID_VFLIP, 0, 1, 1, 0);
  7620. - hblank = OV5693_PPL_DEFAULT - ov5693->mode->width;
  7621. + hblank = ov5693->mode->pixels_per_line - ov5693->mode->width;
  7622. ov5693->ctrls.hblank = v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops,
  7623. V4L2_CID_HBLANK, hblank, hblank,
  7624. 1, hblank);
  7625. --
  7626. 2.33.0
  7627. From 9b6b3a7cc2420c4b57591404ed70378e4cc7c237 Mon Sep 17 00:00:00 2001
  7628. From: Daniel Scally <djrscally@gmail.com>
  7629. Date: Mon, 8 Feb 2021 22:53:02 +0000
  7630. Subject: [PATCH] media: i2c: Add vblank control to ov5693 driver
  7631. The latest libcamera requires a V4L2_CID_VBLANK control in each sensor
  7632. driver; add a skeleton one to the ov5693 to fulfill the requirement.
  7633. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  7634. Patchset: cameras
  7635. ---
  7636. drivers/media/i2c/ov5693.c | 12 ++++++++++++
  7637. drivers/media/i2c/ov5693.h | 3 +++
  7638. 2 files changed, 15 insertions(+)
  7639. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  7640. index 7fb368eec327..1950d7ac2d54 100644
  7641. --- a/drivers/media/i2c/ov5693.c
  7642. +++ b/drivers/media/i2c/ov5693.c
  7643. @@ -946,6 +946,10 @@ static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
  7644. return ov5693_flip_horz_configure(dev, !!ctrl->val);
  7645. case V4L2_CID_VFLIP:
  7646. return ov5693_flip_vert_configure(dev, !!ctrl->val);
  7647. + case V4L2_CID_VBLANK:
  7648. + ret = ov5693_write_reg(client, OV5693_16BIT, OV5693_TIMING_VTS_H,
  7649. + dev->mode->height + ctrl->val);
  7650. + break;
  7651. default:
  7652. ret = -EINVAL;
  7653. }
  7654. @@ -1611,6 +1615,7 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  7655. unsigned int i;
  7656. int ret;
  7657. int hblank;
  7658. + int vblank_max, vblank_min, vblank_def;
  7659. ret = v4l2_ctrl_handler_init(&ov5693->ctrl_handler,
  7660. ARRAY_SIZE(ov5693_controls));
  7661. @@ -1671,6 +1676,13 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  7662. if (ov5693->ctrls.hblank)
  7663. ov5693->ctrls.hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  7664. + vblank_max = OV5693_TIMING_MAX_VTS - ov5693->mode->height;
  7665. + vblank_def = ov5693->mode->lines_per_frame - ov5693->mode->height;
  7666. + vblank_min = ov5693->mode->lines_per_frame - ov5693->mode->height;
  7667. + ov5693->ctrls.vblank = v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops,
  7668. + V4L2_CID_VBLANK, vblank_min,
  7669. + vblank_max, 1, vblank_def);
  7670. +
  7671. /* set properties from fwnode (e.g. rotation, orientation) */
  7672. ret = v4l2_fwnode_device_parse(&client->dev, &props);
  7673. if (ret)
  7674. diff --git a/drivers/media/i2c/ov5693.h b/drivers/media/i2c/ov5693.h
  7675. index 26819cf3f4d2..9d7eed97963b 100644
  7676. --- a/drivers/media/i2c/ov5693.h
  7677. +++ b/drivers/media/i2c/ov5693.h
  7678. @@ -131,6 +131,8 @@
  7679. /*High 8-bit, and low 8-bit HTS address is 0x380f*/
  7680. #define OV5693_TIMING_VTS_L 0x380f
  7681. +#define OV5693_TIMING_MAX_VTS 0xffff
  7682. +
  7683. #define OV5693_MWB_RED_GAIN_H 0x3400
  7684. #define OV5693_MWB_GREEN_GAIN_H 0x3402
  7685. #define OV5693_MWB_BLUE_GAIN_H 0x3404
  7686. @@ -279,6 +281,7 @@ struct ov5693_device {
  7687. struct v4l2_ctrl *hflip;
  7688. struct v4l2_ctrl *vflip;
  7689. struct v4l2_ctrl *hblank;
  7690. + struct v4l2_ctrl *vblank;
  7691. } ctrls;
  7692. };
  7693. --
  7694. 2.33.0
  7695. From 32c9eeba5037cf58eafa718260a6e678efc52089 Mon Sep 17 00:00:00 2001
  7696. From: Daniel Scally <djrscally@gmail.com>
  7697. Date: Wed, 10 Feb 2021 00:36:32 +0000
  7698. Subject: [PATCH] media: i2c: update exposure control for ov5693
  7699. The exposure control for ov5693 currently is in units of 1/16th of a line,
  7700. but I think the framework expects it in units of lines. Set the control to
  7701. work in lines and simply apply the multiplication when configuring the chip
  7702. registers instead.
  7703. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  7704. Patchset: cameras
  7705. ---
  7706. drivers/media/i2c/ov5693.c | 23 ++++++++++++++++++++---
  7707. 1 file changed, 20 insertions(+), 3 deletions(-)
  7708. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  7709. index 1950d7ac2d54..cea767230aa9 100644
  7710. --- a/drivers/media/i2c/ov5693.c
  7711. +++ b/drivers/media/i2c/ov5693.c
  7712. @@ -801,6 +801,12 @@ static int ov5693_exposure_configure(struct ov5693_device *sensor, u32 exposure)
  7713. {
  7714. int ret;
  7715. + /*
  7716. + * The control for exposure seems to be in units of lines, but the chip
  7717. + * datasheet specifies exposure is in units of 1/16th of a line.
  7718. + */
  7719. + exposure = exposure * 16;
  7720. +
  7721. ov5693_get_exposure(sensor);
  7722. ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  7723. OV5693_EXPOSURE_CTRL_HH_REG, OV5693_EXPOSURE_CTRL_HH(exposure));
  7724. @@ -910,6 +916,16 @@ static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
  7725. struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
  7726. int ret = 0;
  7727. + /* If VBLANK is altered we need to update exposure to compensate */
  7728. + if (ctrl->id == V4L2_CID_VBLANK) {
  7729. + int exposure_max;
  7730. + exposure_max = dev->mode->lines_per_frame - 8;
  7731. + __v4l2_ctrl_modify_range(dev->ctrls.exposure, dev->ctrls.exposure->minimum,
  7732. + exposure_max, dev->ctrls.exposure->step,
  7733. + dev->ctrls.exposure->val < exposure_max ?
  7734. + dev->ctrls.exposure->val : exposure_max);
  7735. + }
  7736. +
  7737. switch (ctrl->id) {
  7738. case V4L2_CID_FOCUS_ABSOLUTE:
  7739. dev_dbg(&client->dev, "%s: CID_FOCUS_ABSOLUTE:%d.\n",
  7740. @@ -1616,6 +1632,7 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  7741. int ret;
  7742. int hblank;
  7743. int vblank_max, vblank_min, vblank_def;
  7744. + int exposure_max;
  7745. ret = v4l2_ctrl_handler_init(&ov5693->ctrl_handler,
  7746. ARRAY_SIZE(ov5693_controls));
  7747. @@ -1648,10 +1665,10 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  7748. }
  7749. /* Exposure */
  7750. -
  7751. + exposure_max = ov5693->mode->lines_per_frame - 8;
  7752. ov5693->ctrls.exposure = v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops,
  7753. - V4L2_CID_EXPOSURE, 16,
  7754. - 1048575, 16, 512);
  7755. + V4L2_CID_EXPOSURE, 1,
  7756. + exposure_max, 1, 123);
  7757. /* Gain */
  7758. --
  7759. 2.33.0
  7760. From 49678e1440330e97a36563a1f245fb52e7823e04 Mon Sep 17 00:00:00 2001
  7761. From: Daniel Scally <djrscally@gmail.com>
  7762. Date: Wed, 10 Feb 2021 00:39:42 +0000
  7763. Subject: [PATCH] media: i2c: Fix incorrect bit-setting
  7764. The bitmask macros to set the exposure for the ov5693 are not quite right.
  7765. Update them so that they're setting the correct bits in the registers.
  7766. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  7767. Patchset: cameras
  7768. ---
  7769. drivers/media/i2c/ov5693.c | 6 +++---
  7770. 1 file changed, 3 insertions(+), 3 deletions(-)
  7771. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  7772. index cea767230aa9..f681dbfcec56 100644
  7773. --- a/drivers/media/i2c/ov5693.c
  7774. +++ b/drivers/media/i2c/ov5693.c
  7775. @@ -63,11 +63,11 @@ MODULE_PARM_DESC(up_delay,
  7776. /* Exposure/gain */
  7777. #define OV5693_EXPOSURE_CTRL_HH_REG 0x3500
  7778. -#define OV5693_EXPOSURE_CTRL_HH(v) (((v) & GENMASK(18, 16)) >> 16)
  7779. +#define OV5693_EXPOSURE_CTRL_HH(v) (((v) & GENMASK(14, 12)) >> 12)
  7780. #define OV5693_EXPOSURE_CTRL_H_REG 0x3501
  7781. -#define OV5693_EXPOSURE_CTRL_H(v) (((v) & GENMASK(15, 8)) >> 8)
  7782. +#define OV5693_EXPOSURE_CTRL_H(v) (((v) & GENMASK(11, 4)) >> 4)
  7783. #define OV5693_EXPOSURE_CTRL_L_REG 0x3502
  7784. -#define OV5693_EXPOSURE_CTRL_L(v) ((v) & GENMASK(7, 0))
  7785. +#define OV5693_EXPOSURE_CTRL_L(v) (((v) & GENMASK(3, 0)) << 4)
  7786. #define OV5693_EXPOSURE_GAIN_MANUAL_REG 0x3509
  7787. #define OV5693_GAIN_CTRL_H_REG 0x3504
  7788. --
  7789. 2.33.0
  7790. From 0397bb78961d71bcf4cd0ff8ede80826d3ddd717 Mon Sep 17 00:00:00 2001
  7791. From: Daniel Scally <djrscally@gmail.com>
  7792. Date: Wed, 10 Feb 2021 16:25:48 +0000
  7793. Subject: [PATCH] media: i2c: Don't set stream on during mode config
  7794. Currently the register lists for the ov5693 include setting stream on.
  7795. That register shouldn't be set until the control is called, so remove
  7796. this setting from all of the modes.
  7797. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  7798. Patchset: cameras
  7799. ---
  7800. drivers/media/i2c/ov5693.h | 16 ----------------
  7801. 1 file changed, 16 deletions(-)
  7802. diff --git a/drivers/media/i2c/ov5693.h b/drivers/media/i2c/ov5693.h
  7803. index 9d7eed97963b..965208078c2b 100644
  7804. --- a/drivers/media/i2c/ov5693.h
  7805. +++ b/drivers/media/i2c/ov5693.h
  7806. @@ -581,7 +581,6 @@ static struct ov5693_reg const ov5693_654x496[] = {
  7807. {OV5693_8BIT, 0x3820, 0x04},
  7808. {OV5693_8BIT, 0x3821, 0x1f},
  7809. {OV5693_8BIT, 0x5002, 0x80},
  7810. - {OV5693_8BIT, 0x0100, 0x01},
  7811. {OV5693_TOK_TERM, 0, 0}
  7812. };
  7813. @@ -626,7 +625,6 @@ static struct ov5693_reg const ov5693_1296x976[] = {
  7814. {OV5693_8BIT, 0x3821, 0x1e},
  7815. {OV5693_8BIT, 0x5002, 0x00},
  7816. {OV5693_8BIT, 0x5041, 0x84}, /* scale is auto enabled */
  7817. - {OV5693_8BIT, 0x0100, 0x01},
  7818. {OV5693_TOK_TERM, 0, 0}
  7819. };
  7820. @@ -656,7 +654,6 @@ static struct ov5693_reg const ov5693_336x256[] = {
  7821. {OV5693_8BIT, 0x3820, 0x04},
  7822. {OV5693_8BIT, 0x3821, 0x1f},
  7823. {OV5693_8BIT, 0x5002, 0x80},
  7824. - {OV5693_8BIT, 0x0100, 0x01},
  7825. {OV5693_TOK_TERM, 0, 0}
  7826. };
  7827. @@ -683,7 +680,6 @@ static struct ov5693_reg const ov5693_368x304[] = {
  7828. {OV5693_8BIT, 0x3820, 0x04},
  7829. {OV5693_8BIT, 0x3821, 0x1f},
  7830. {OV5693_8BIT, 0x5002, 0x80},
  7831. - {OV5693_8BIT, 0x0100, 0x01},
  7832. {OV5693_TOK_TERM, 0, 0}
  7833. };
  7834. @@ -715,7 +711,6 @@ static struct ov5693_reg const ov5693_192x160[] = {
  7835. {OV5693_8BIT, 0x3820, 0x04},
  7836. {OV5693_8BIT, 0x3821, 0x1f},
  7837. {OV5693_8BIT, 0x5002, 0x80},
  7838. - {OV5693_8BIT, 0x0100, 0x01},
  7839. {OV5693_TOK_TERM, 0, 0}
  7840. };
  7841. @@ -742,7 +737,6 @@ static struct ov5693_reg const ov5693_736x496[] = {
  7842. {OV5693_8BIT, 0x3820, 0x04},
  7843. {OV5693_8BIT, 0x3821, 0x1f},
  7844. {OV5693_8BIT, 0x5002, 0x80},
  7845. - {OV5693_8BIT, 0x0100, 0x01},
  7846. {OV5693_TOK_TERM, 0, 0}
  7847. };
  7848. #endif
  7849. @@ -771,7 +765,6 @@ static struct ov5693_reg const ov5693_736x496[] = {
  7850. {OV5693_8BIT, 0x3820, 0x01},
  7851. {OV5693_8BIT, 0x3821, 0x1f},
  7852. {OV5693_8BIT, 0x5002, 0x00},
  7853. - {OV5693_8BIT, 0x0100, 0x01},
  7854. {OV5693_TOK_TERM, 0, 0}
  7855. };
  7856. */
  7857. @@ -802,7 +795,6 @@ static struct ov5693_reg const ov5693_976x556[] = {
  7858. {OV5693_8BIT, 0x3820, 0x00},
  7859. {OV5693_8BIT, 0x3821, 0x1e},
  7860. {OV5693_8BIT, 0x5002, 0x80},
  7861. - {OV5693_8BIT, 0x0100, 0x01},
  7862. {OV5693_TOK_TERM, 0, 0}
  7863. };
  7864. @@ -841,7 +833,6 @@ static struct ov5693_reg const ov5693_1296x736[] = {
  7865. {OV5693_8BIT, 0x3821, 0x1e},
  7866. {OV5693_8BIT, 0x5002, 0x00},
  7867. {OV5693_8BIT, 0x5041, 0x84}, /* scale is auto enabled */
  7868. - {OV5693_8BIT, 0x0100, 0x01},
  7869. {OV5693_TOK_TERM, 0, 0}
  7870. };
  7871. @@ -868,7 +859,6 @@ static struct ov5693_reg const ov5693_1636p_30fps[] = {
  7872. {OV5693_8BIT, 0x3820, 0x00},
  7873. {OV5693_8BIT, 0x3821, 0x1e},
  7874. {OV5693_8BIT, 0x5002, 0x80},
  7875. - {OV5693_8BIT, 0x0100, 0x01},
  7876. {OV5693_TOK_TERM, 0, 0}
  7877. };
  7878. #endif
  7879. @@ -904,7 +894,6 @@ static struct ov5693_reg const ov5693_1616x1216_30fps[] = {
  7880. {OV5693_8BIT, 0x3821, 0x1e}, /*MIRROR control*/
  7881. {OV5693_8BIT, 0x5002, 0x00},
  7882. {OV5693_8BIT, 0x5041, 0x84},
  7883. - {OV5693_8BIT, 0x0100, 0x01},
  7884. {OV5693_TOK_TERM, 0, 0}
  7885. };
  7886. @@ -935,7 +924,6 @@ static struct ov5693_reg const ov5693_1940x1096[] = {
  7887. {OV5693_8BIT, 0x3820, 0x00},
  7888. {OV5693_8BIT, 0x3821, 0x1e},
  7889. {OV5693_8BIT, 0x5002, 0x80},
  7890. - {OV5693_8BIT, 0x0100, 0x01},
  7891. {OV5693_TOK_TERM, 0, 0}
  7892. };
  7893. @@ -1029,7 +1017,6 @@ static struct ov5693_reg const ov5693_2592x1944_30fps[] = {
  7894. {OV5693_8BIT, 0x3820, 0x00},
  7895. {OV5693_8BIT, 0x3821, 0x1e},
  7896. {OV5693_8BIT, 0x5002, 0x00},
  7897. - {OV5693_8BIT, 0x0100, 0x01},
  7898. {OV5693_TOK_TERM, 0, 0}
  7899. };
  7900. #endif
  7901. @@ -1073,7 +1060,6 @@ static struct ov5693_reg const ov5693_1424x1168_30fps[] = {
  7902. {OV5693_8BIT, 0x3821, 0x1e},
  7903. {OV5693_8BIT, 0x5002, 0x00},
  7904. {OV5693_8BIT, 0x5041, 0x84}, /* scale is auto enabled */
  7905. - {OV5693_8BIT, 0x0100, 0x01},
  7906. {OV5693_TOK_TERM, 0, 0}
  7907. };
  7908. #endif
  7909. @@ -1114,7 +1100,6 @@ static struct ov5693_reg const ov5693_736x496_30fps[] = {
  7910. {OV5693_8BIT, 0x3821, 0x1e},
  7911. {OV5693_8BIT, 0x5002, 0x00},
  7912. {OV5693_8BIT, 0x5041, 0x84}, /* scale is auto enabled */
  7913. - {OV5693_8BIT, 0x0100, 0x01},
  7914. {OV5693_TOK_TERM, 0, 0}
  7915. };
  7916. @@ -1141,7 +1126,6 @@ static struct ov5693_reg const ov5693_2576x1936_30fps[] = {
  7917. {OV5693_8BIT, 0x3820, 0x00},
  7918. {OV5693_8BIT, 0x3821, 0x1e},
  7919. {OV5693_8BIT, 0x5002, 0x00},
  7920. - {OV5693_8BIT, 0x0100, 0x01},
  7921. {OV5693_TOK_TERM, 0, 0}
  7922. };
  7923. --
  7924. 2.33.0
  7925. From 05691584e795bd16965cf2cc3b27ca0133e2ae7e Mon Sep 17 00:00:00 2001
  7926. From: Daniel Scally <djrscally@gmail.com>
  7927. Date: Wed, 10 Feb 2021 16:35:24 +0000
  7928. Subject: [PATCH] media: i2c: Update gain control for ov5693
  7929. The gain control of the ov5693 driver is setting the wrong bits and
  7930. defining an invalid maximum value; change (and use) the bitshifting
  7931. macros and update the control's ranges.
  7932. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  7933. Patchset: cameras
  7934. ---
  7935. drivers/media/i2c/ov5693.c | 18 +++++++++++-------
  7936. 1 file changed, 11 insertions(+), 7 deletions(-)
  7937. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  7938. index f681dbfcec56..51eb3b05d121 100644
  7939. --- a/drivers/media/i2c/ov5693.c
  7940. +++ b/drivers/media/i2c/ov5693.c
  7941. @@ -71,9 +71,9 @@ MODULE_PARM_DESC(up_delay,
  7942. #define OV5693_EXPOSURE_GAIN_MANUAL_REG 0x3509
  7943. #define OV5693_GAIN_CTRL_H_REG 0x3504
  7944. -#define OV5693_GAIN_CTRL_H(v) (((v) & GENMASK(9, 8)) >> 8)
  7945. +#define OV5693_GAIN_CTRL_H(v) ((v >> 4) & GENMASK(2, 0))
  7946. #define OV5693_GAIN_CTRL_L_REG 0x3505
  7947. -#define OV5693_GAIN_CTRL_L(v) ((v) & GENMASK(7, 0))
  7948. +#define OV5693_GAIN_CTRL_L(v) ((v << 4) & GENMASK(7, 4))
  7949. #define OV5693_FORMAT1_REG 0x3820
  7950. #define OV5693_FORMAT1_FLIP_VERT_ISP_EN BIT(2)
  7951. @@ -889,9 +889,13 @@ static int ov5693_analog_gain_configure(struct ov5693_device *sensor, u32 gain)
  7952. {
  7953. int ret;
  7954. - /* Analog gain */
  7955. + /*
  7956. + * As with exposure, the lowest 4 bits are fractional bits. Setting
  7957. + * those is not supported, so we have a tiny bit of bit shifting to
  7958. + * do.
  7959. + */
  7960. ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  7961. - OV5693_AGC_L, gain & 0xff);
  7962. + OV5693_AGC_L, OV5693_GAIN_CTRL_L(gain));
  7963. if (ret) {
  7964. dev_err(&sensor->i2c_client->dev, "%s: write %x error, aborted\n",
  7965. __func__, OV5693_AGC_L);
  7966. @@ -899,7 +903,7 @@ static int ov5693_analog_gain_configure(struct ov5693_device *sensor, u32 gain)
  7967. }
  7968. ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  7969. - OV5693_AGC_H, (gain >> 8) & 0xff);
  7970. + OV5693_AGC_H, OV5693_GAIN_CTRL_H(gain));
  7971. if (ret) {
  7972. dev_err(&sensor->i2c_client->dev, "%s: write %x error, aborted\n",
  7973. __func__, OV5693_AGC_H);
  7974. @@ -1674,10 +1678,10 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  7975. ov5693->ctrls.analogue_gain = v4l2_ctrl_new_std(&ov5693->ctrl_handler,
  7976. ops, V4L2_CID_ANALOGUE_GAIN,
  7977. - 1, 1023, 1, 128);
  7978. + 1, 127, 1, 8);
  7979. ov5693->ctrls.digital_gain = v4l2_ctrl_new_std(&ov5693->ctrl_handler, ops,
  7980. V4L2_CID_DIGITAL_GAIN, 1,
  7981. - 3999, 1, 1000);
  7982. + 4095, 1, 1024);
  7983. /* Flip */
  7984. --
  7985. 2.33.0
  7986. From 000757caef6c4e3162b28447cdb832659cf01b88 Mon Sep 17 00:00:00 2001
  7987. From: Daniel Scally <djrscally@gmail.com>
  7988. Date: Wed, 10 Feb 2021 23:44:39 +0000
  7989. Subject: [PATCH] media: i2c: Fixup gain read
  7990. This function reads the bits from the gain registers poorly. Update
  7991. it to do that properly (although, it probably just needs to be deleted)
  7992. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  7993. Patchset: cameras
  7994. ---
  7995. drivers/media/i2c/ov5693.c | 17 +++++++++++------
  7996. 1 file changed, 11 insertions(+), 6 deletions(-)
  7997. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  7998. index 51eb3b05d121..952558c4f33b 100644
  7999. --- a/drivers/media/i2c/ov5693.c
  8000. +++ b/drivers/media/i2c/ov5693.c
  8001. @@ -770,30 +770,35 @@ static int ov5693_t_focus_rel(struct v4l2_subdev *sd, s32 value)
  8002. static int ov5693_get_exposure(struct ov5693_device *sensor)
  8003. {
  8004. - u16 reg_v, reg_v2;
  8005. + u32 exposure = 0;
  8006. + u16 tmp;
  8007. int ret = 0;
  8008. /* get exposure */
  8009. ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT,
  8010. OV5693_EXPOSURE_L,
  8011. - &reg_v);
  8012. + &tmp);
  8013. if (ret)
  8014. return ret;
  8015. + exposure |= ((tmp >> 4) & 0b1111);
  8016. +
  8017. ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT,
  8018. OV5693_EXPOSURE_M,
  8019. - &reg_v2);
  8020. + &tmp);
  8021. if (ret)
  8022. return ret;
  8023. - reg_v += reg_v2 << 8;
  8024. + exposure |= (tmp << 4);
  8025. ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT,
  8026. OV5693_EXPOSURE_H,
  8027. - &reg_v2);
  8028. + &tmp);
  8029. if (ret)
  8030. return ret;
  8031. - printk("exposure set to: %u\n", reg_v + (((u32)reg_v2 << 16)));
  8032. + exposure |= (tmp << 12);
  8033. +
  8034. + printk("exposure set to: %u\n", exposure);
  8035. return ret;
  8036. }
  8037. --
  8038. 2.33.0
  8039. From e34f12d5d1acd241e7b9eebd15fa0dc4c5ae692e Mon Sep 17 00:00:00 2001
  8040. From: Daniel Scally <djrscally@gmail.com>
  8041. Date: Thu, 11 Feb 2021 00:40:10 +0000
  8042. Subject: [PATCH] media: i2c: Update controls on stream
  8043. Currently the ov5693 driver throws away control setting by simply loading
  8044. each mode's default registers. Instead, re-set the user defined controls
  8045. during stream with __v4l2_ctrl_handler_setup()
  8046. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  8047. Patchset: cameras
  8048. ---
  8049. drivers/media/i2c/ov5693.c | 6 ++++++
  8050. 1 file changed, 6 insertions(+)
  8051. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  8052. index 952558c4f33b..dd31083eeb7b 100644
  8053. --- a/drivers/media/i2c/ov5693.c
  8054. +++ b/drivers/media/i2c/ov5693.c
  8055. @@ -1492,6 +1492,12 @@ static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
  8056. }
  8057. }
  8058. + ret = __v4l2_ctrl_handler_setup(&dev->ctrl_handler);
  8059. + if (ret) {
  8060. + power_down(sd);
  8061. + return ret;
  8062. + }
  8063. +
  8064. ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_SW_STREAM,
  8065. enable ? OV5693_START_STREAMING :
  8066. OV5693_STOP_STREAMING);
  8067. --
  8068. 2.33.0
  8069. From bcf152f00576999a15a184e41818742dd01a0313 Mon Sep 17 00:00:00 2001
  8070. From: Daniel Scally <djrscally@gmail.com>
  8071. Date: Thu, 11 Feb 2021 23:29:15 +0000
  8072. Subject: [PATCH] media: i2c: Correct link frequency value
  8073. The link frequency is given by vts * hts * fps * bits / lanes / 2. In the
  8074. case of the ov5693 driver that works out to 400MHz, not 640Mhz. Correct
  8075. the macro.
  8076. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  8077. Patchset: cameras
  8078. ---
  8079. drivers/media/i2c/ov5693.h | 6 +++---
  8080. 1 file changed, 3 insertions(+), 3 deletions(-)
  8081. diff --git a/drivers/media/i2c/ov5693.h b/drivers/media/i2c/ov5693.h
  8082. index 965208078c2b..7f1d31a82d3d 100644
  8083. --- a/drivers/media/i2c/ov5693.h
  8084. +++ b/drivers/media/i2c/ov5693.h
  8085. @@ -186,13 +186,13 @@
  8086. #define OV5693_OTP_MODE_READ 1
  8087. /* link freq and pixel rate required for IPU3 */
  8088. -#define OV5693_LINK_FREQ_640MHZ 640000000
  8089. +#define OV5693_LINK_FREQ_400MHZ 400000000
  8090. /* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample
  8091. * To avoid integer overflow, dividing by bits_per_sample first.
  8092. */
  8093. -#define OV5693_PIXEL_RATE (OV5693_LINK_FREQ_640MHZ / 10) * 2 * 2
  8094. +#define OV5693_PIXEL_RATE (OV5693_LINK_FREQ_400MHZ / 10) * 2 * 2
  8095. static const s64 link_freq_menu_items[] = {
  8096. - OV5693_LINK_FREQ_640MHZ
  8097. + OV5693_LINK_FREQ_400MHZ
  8098. };
  8099. #define OV5693_NUM_SUPPLIES 2
  8100. --
  8101. 2.33.0
  8102. From e1d20f8442fdb17668d029b8726466810e297385 Mon Sep 17 00:00:00 2001
  8103. From: Daniel Scally <djrscally@gmail.com>
  8104. Date: Mon, 25 Jan 2021 23:12:09 +0000
  8105. Subject: [PATCH] media: i2c: Cleanup ov5693 driver
  8106. This commit performs some cleanup to the ov5693 driver:
  8107. 1. Superfluous words in variable names dropped; "i2c_client" becomes
  8108. "client", "input_lock" becomes "lock"
  8109. 2. ov5693_configure_gpios() is does error handling properly, and uses
  8110. gpiod_get_optional()
  8111. 3. The name of the struct ov5693_device variable in each functions, which
  8112. previously was a mix of dev, sensor or ov5693, is standardised to the
  8113. latter.
  8114. 4. The list of headers is alphabetised (and probably also needs trimming)
  8115. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  8116. Patchset: cameras
  8117. ---
  8118. drivers/media/i2c/ov5693.c | 309 +++++++++++++++++++------------------
  8119. drivers/media/i2c/ov5693.h | 5 +-
  8120. 2 files changed, 165 insertions(+), 149 deletions(-)
  8121. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  8122. index dd31083eeb7b..0643390c872a 100644
  8123. --- a/drivers/media/i2c/ov5693.c
  8124. +++ b/drivers/media/i2c/ov5693.c
  8125. @@ -16,25 +16,25 @@
  8126. *
  8127. */
  8128. +#include <linux/acpi.h>
  8129. #include <linux/clk.h>
  8130. -#include <linux/module.h>
  8131. -#include <linux/types.h>
  8132. -#include <linux/kernel.h>
  8133. -#include <linux/mm.h>
  8134. -#include <linux/string.h>
  8135. +#include <linux/delay.h>
  8136. +#include <linux/device.h>
  8137. #include <linux/errno.h>
  8138. +#include <linux/i2c.h>
  8139. #include <linux/init.h>
  8140. +#include <linux/io.h>
  8141. +#include <linux/kernel.h>
  8142. #include <linux/kmod.h>
  8143. -#include <linux/device.h>
  8144. -#include <linux/delay.h>
  8145. -#include <linux/slab.h>
  8146. -#include <linux/i2c.h>
  8147. +#include <linux/module.h>
  8148. #include <linux/moduleparam.h>
  8149. +#include <linux/mm.h>
  8150. +#include <linux/regulator/consumer.h>
  8151. +#include <linux/slab.h>
  8152. +#include <linux/string.h>
  8153. +#include <linux/types.h>
  8154. #include <media/v4l2-device.h>
  8155. #include <media/v4l2-fwnode.h>
  8156. -#include <linux/io.h>
  8157. -#include <linux/acpi.h>
  8158. -#include <linux/regulator/consumer.h>
  8159. #include "ov5693.h"
  8160. #include "ad5823.h"
  8161. @@ -485,12 +485,12 @@ static int ov5693_read_otp_reg_array(struct i2c_client *client, u16 size,
  8162. static int __ov5693_otp_read(struct v4l2_subdev *sd, u8 *buf)
  8163. {
  8164. struct i2c_client *client = v4l2_get_subdevdata(sd);
  8165. - struct ov5693_device *dev = to_ov5693_sensor(sd);
  8166. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  8167. int ret;
  8168. int i;
  8169. u8 *b = buf;
  8170. - dev->otp_size = 0;
  8171. + ov5693->otp_size = 0;
  8172. for (i = 1; i < OV5693_OTP_BANK_MAX; i++) {
  8173. /*set bank NO and OTP read mode. */
  8174. ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_OTP_BANK_REG,
  8175. @@ -529,7 +529,7 @@ static int __ov5693_otp_read(struct v4l2_subdev *sd, u8 *buf)
  8176. //Intel OTP map, try to read 320byts first.
  8177. if (i == 21) {
  8178. if ((*b) == 0) {
  8179. - dev->otp_size = 320;
  8180. + ov5693->otp_size = 320;
  8181. break;
  8182. }
  8183. /* (*b) != 0 */
  8184. @@ -538,7 +538,7 @@ static int __ov5693_otp_read(struct v4l2_subdev *sd, u8 *buf)
  8185. } else if (i ==
  8186. 24) { //if the first 320bytes data doesn't not exist, try to read the next 32bytes data.
  8187. if ((*b) == 0) {
  8188. - dev->otp_size = 32;
  8189. + ov5693->otp_size = 32;
  8190. break;
  8191. }
  8192. /* (*b) != 0 */
  8193. @@ -547,11 +547,11 @@ static int __ov5693_otp_read(struct v4l2_subdev *sd, u8 *buf)
  8194. } else if (i ==
  8195. 27) { //if the prvious 32bytes data doesn't exist, try to read the next 32bytes data again.
  8196. if ((*b) == 0) {
  8197. - dev->otp_size = 32;
  8198. + ov5693->otp_size = 32;
  8199. break;
  8200. }
  8201. /* (*b) != 0 */
  8202. - dev->otp_size = 0; // no OTP data.
  8203. + ov5693->otp_size = 0; // no OTP data.
  8204. break;
  8205. }
  8206. @@ -598,20 +598,20 @@ static void *ov5693_otp_read(struct v4l2_subdev *sd)
  8207. return buf;
  8208. }
  8209. -static int ov5693_update_bits(struct ov5693_device *sensor, u16 address,
  8210. +static int ov5693_update_bits(struct ov5693_device *ov5693, u16 address,
  8211. u16 mask, u16 bits)
  8212. {
  8213. u16 value = 0;
  8214. int ret;
  8215. - ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT, address, &value);
  8216. + ret = ov5693_read_reg(ov5693->client, OV5693_8BIT, address, &value);
  8217. if (ret)
  8218. return ret;
  8219. value &= ~mask;
  8220. value |= bits;
  8221. - ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT, address, value);
  8222. + ret = ov5693_write_reg(ov5693->client, OV5693_8BIT, address, value);
  8223. if (ret)
  8224. return ret;
  8225. @@ -620,13 +620,13 @@ static int ov5693_update_bits(struct ov5693_device *sensor, u16 address,
  8226. /* Flip */
  8227. -static int ov5693_flip_vert_configure(struct ov5693_device *sensor, bool enable)
  8228. +static int ov5693_flip_vert_configure(struct ov5693_device *ov5693, bool enable)
  8229. {
  8230. u8 bits = OV5693_FORMAT1_FLIP_VERT_ISP_EN |
  8231. OV5693_FORMAT1_FLIP_VERT_SENSOR_EN;
  8232. int ret;
  8233. - ret = ov5693_update_bits(sensor, OV5693_FORMAT1_REG, bits,
  8234. + ret = ov5693_update_bits(ov5693, OV5693_FORMAT1_REG, bits,
  8235. enable ? bits : 0);
  8236. if (ret)
  8237. return ret;
  8238. @@ -634,13 +634,13 @@ static int ov5693_flip_vert_configure(struct ov5693_device *sensor, bool enable)
  8239. return 0;
  8240. }
  8241. -static int ov5693_flip_horz_configure(struct ov5693_device *sensor, bool enable)
  8242. +static int ov5693_flip_horz_configure(struct ov5693_device *ov5693, bool enable)
  8243. {
  8244. u8 bits = OV5693_FORMAT2_FLIP_HORZ_ISP_EN |
  8245. OV5693_FORMAT2_FLIP_HORZ_SENSOR_EN;
  8246. int ret;
  8247. - ret = ov5693_update_bits(sensor, OV5693_FORMAT2_REG, bits,
  8248. + ret = ov5693_update_bits(ov5693, OV5693_FORMAT2_REG, bits,
  8249. enable ? bits : 0);
  8250. if (ret)
  8251. return ret;
  8252. @@ -721,14 +721,14 @@ static int ad5823_t_focus_abs(struct v4l2_subdev *sd, s32 value)
  8253. static int ov5693_t_focus_abs(struct v4l2_subdev *sd, s32 value)
  8254. {
  8255. - struct ov5693_device *dev = to_ov5693_sensor(sd);
  8256. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  8257. struct i2c_client *client = v4l2_get_subdevdata(sd);
  8258. int ret = 0;
  8259. dev_dbg(&client->dev, "%s: FOCUS_POS: 0x%x\n", __func__, value);
  8260. value = clamp(value, 0, OV5693_VCM_MAX_FOCUS_POS);
  8261. - if (dev->vcm == VCM_DW9714) {
  8262. - if (dev->vcm_update) {
  8263. + if (ov5693->vcm == VCM_DW9714) {
  8264. + if (ov5693->vcm_update) {
  8265. ret = vcm_dw_i2c_write(client, VCM_PROTECTION_OFF);
  8266. if (ret)
  8267. return ret;
  8268. @@ -738,17 +738,17 @@ static int ov5693_t_focus_abs(struct v4l2_subdev *sd, s32 value)
  8269. ret = vcm_dw_i2c_write(client, VCM_PROTECTION_ON);
  8270. if (ret)
  8271. return ret;
  8272. - dev->vcm_update = false;
  8273. + ov5693->vcm_update = false;
  8274. }
  8275. ret = vcm_dw_i2c_write(client,
  8276. vcm_val(value, VCM_DEFAULT_S));
  8277. - } else if (dev->vcm == VCM_AD5823) {
  8278. + } else if (ov5693->vcm == VCM_AD5823) {
  8279. ad5823_t_focus_abs(sd, value);
  8280. }
  8281. if (ret == 0) {
  8282. - dev->number_of_steps = value - dev->focus;
  8283. - dev->focus = value;
  8284. - dev->timestamp_t_focus_abs = ktime_get();
  8285. + ov5693->number_of_steps = value - ov5693->focus;
  8286. + ov5693->focus = value;
  8287. + ov5693->timestamp_t_focus_abs = ktime_get();
  8288. } else
  8289. dev_err(&client->dev,
  8290. "%s: i2c failed. ret %d\n", __func__, ret);
  8291. @@ -758,9 +758,9 @@ static int ov5693_t_focus_abs(struct v4l2_subdev *sd, s32 value)
  8292. static int ov5693_t_focus_rel(struct v4l2_subdev *sd, s32 value)
  8293. {
  8294. - struct ov5693_device *dev = to_ov5693_sensor(sd);
  8295. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  8296. - return ov5693_t_focus_abs(sd, dev->focus + value);
  8297. + return ov5693_t_focus_abs(sd, ov5693->focus + value);
  8298. }
  8299. #define DELAY_PER_STEP_NS 1000000
  8300. @@ -768,14 +768,14 @@ static int ov5693_t_focus_rel(struct v4l2_subdev *sd, s32 value)
  8301. /* Exposure */
  8302. -static int ov5693_get_exposure(struct ov5693_device *sensor)
  8303. +static int ov5693_get_exposure(struct ov5693_device *ov5693)
  8304. {
  8305. u32 exposure = 0;
  8306. u16 tmp;
  8307. int ret = 0;
  8308. /* get exposure */
  8309. - ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT,
  8310. + ret = ov5693_read_reg(ov5693->client, OV5693_8BIT,
  8311. OV5693_EXPOSURE_L,
  8312. &tmp);
  8313. if (ret)
  8314. @@ -783,14 +783,14 @@ static int ov5693_get_exposure(struct ov5693_device *sensor)
  8315. exposure |= ((tmp >> 4) & 0b1111);
  8316. - ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT,
  8317. + ret = ov5693_read_reg(ov5693->client, OV5693_8BIT,
  8318. OV5693_EXPOSURE_M,
  8319. &tmp);
  8320. if (ret)
  8321. return ret;
  8322. exposure |= (tmp << 4);
  8323. - ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT,
  8324. + ret = ov5693_read_reg(ov5693->client, OV5693_8BIT,
  8325. OV5693_EXPOSURE_H,
  8326. &tmp);
  8327. if (ret)
  8328. @@ -802,7 +802,7 @@ static int ov5693_get_exposure(struct ov5693_device *sensor)
  8329. return ret;
  8330. }
  8331. -static int ov5693_exposure_configure(struct ov5693_device *sensor, u32 exposure)
  8332. +static int ov5693_exposure_configure(struct ov5693_device *ov5693, u32 exposure)
  8333. {
  8334. int ret;
  8335. @@ -812,40 +812,40 @@ static int ov5693_exposure_configure(struct ov5693_device *sensor, u32 exposure)
  8336. */
  8337. exposure = exposure * 16;
  8338. - ov5693_get_exposure(sensor);
  8339. - ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  8340. + ov5693_get_exposure(ov5693);
  8341. + ret = ov5693_write_reg(ov5693->client, OV5693_8BIT,
  8342. OV5693_EXPOSURE_CTRL_HH_REG, OV5693_EXPOSURE_CTRL_HH(exposure));
  8343. if (ret)
  8344. return ret;
  8345. - ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  8346. + ret = ov5693_write_reg(ov5693->client, OV5693_8BIT,
  8347. OV5693_EXPOSURE_CTRL_H_REG, OV5693_EXPOSURE_CTRL_H(exposure));
  8348. if (ret)
  8349. return ret;
  8350. - ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  8351. + ret = ov5693_write_reg(ov5693->client, OV5693_8BIT,
  8352. OV5693_EXPOSURE_CTRL_L_REG, OV5693_EXPOSURE_CTRL_L(exposure));
  8353. if (ret)
  8354. return ret;
  8355. - ov5693_get_exposure(sensor);
  8356. + ov5693_get_exposure(ov5693);
  8357. return 0;
  8358. }
  8359. /* Gain */
  8360. -static int ov5693_get_gain(struct ov5693_device *sensor, u32 *gain)
  8361. +static int ov5693_get_gain(struct ov5693_device *ov5693, u32 *gain)
  8362. {
  8363. u16 gain_l, gain_h;
  8364. int ret = 0;
  8365. - ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT,
  8366. + ret = ov5693_read_reg(ov5693->client, OV5693_8BIT,
  8367. OV5693_GAIN_CTRL_L_REG,
  8368. &gain_l);
  8369. if (ret)
  8370. return ret;
  8371. - ret = ov5693_read_reg(sensor->i2c_client, OV5693_8BIT,
  8372. + ret = ov5693_read_reg(ov5693->client, OV5693_8BIT,
  8373. OV5693_GAIN_CTRL_H_REG,
  8374. &gain_h);
  8375. if (ret)
  8376. @@ -856,33 +856,33 @@ static int ov5693_get_gain(struct ov5693_device *sensor, u32 *gain)
  8377. return ret;
  8378. }
  8379. -static int ov5693_gain_configure(struct ov5693_device *sensor, u32 gain)
  8380. +static int ov5693_gain_configure(struct ov5693_device *ov5693, u32 gain)
  8381. {
  8382. int ret;
  8383. /* A 1.0 gain is 0x400 */
  8384. gain = (gain * 1024)/1000;
  8385. - ret = ov5693_write_reg(sensor->i2c_client, OV5693_16BIT,
  8386. + ret = ov5693_write_reg(ov5693->client, OV5693_16BIT,
  8387. OV5693_MWB_RED_GAIN_H, gain);
  8388. if (ret) {
  8389. - dev_err(&sensor->i2c_client->dev, "%s: write %x error, aborted\n",
  8390. + dev_err(&ov5693->client->dev, "%s: write %x error, aborted\n",
  8391. __func__, OV5693_MWB_RED_GAIN_H);
  8392. return ret;
  8393. }
  8394. - ret = ov5693_write_reg(sensor->i2c_client, OV5693_16BIT,
  8395. + ret = ov5693_write_reg(ov5693->client, OV5693_16BIT,
  8396. OV5693_MWB_GREEN_GAIN_H, gain);
  8397. if (ret) {
  8398. - dev_err(&sensor->i2c_client->dev, "%s: write %x error, aborted\n",
  8399. + dev_err(&ov5693->client->dev, "%s: write %x error, aborted\n",
  8400. __func__, OV5693_MWB_RED_GAIN_H);
  8401. return ret;
  8402. }
  8403. - ret = ov5693_write_reg(sensor->i2c_client, OV5693_16BIT,
  8404. + ret = ov5693_write_reg(ov5693->client, OV5693_16BIT,
  8405. OV5693_MWB_BLUE_GAIN_H, gain);
  8406. if (ret) {
  8407. - dev_err(&sensor->i2c_client->dev, "%s: write %x error, aborted\n",
  8408. + dev_err(&ov5693->client->dev, "%s: write %x error, aborted\n",
  8409. __func__, OV5693_MWB_RED_GAIN_H);
  8410. return ret;
  8411. }
  8412. @@ -890,7 +890,7 @@ static int ov5693_gain_configure(struct ov5693_device *sensor, u32 gain)
  8413. return 0;
  8414. }
  8415. -static int ov5693_analog_gain_configure(struct ov5693_device *sensor, u32 gain)
  8416. +static int ov5693_analog_gain_configure(struct ov5693_device *ov5693, u32 gain)
  8417. {
  8418. int ret;
  8419. @@ -899,18 +899,18 @@ static int ov5693_analog_gain_configure(struct ov5693_device *sensor, u32 gain)
  8420. * those is not supported, so we have a tiny bit of bit shifting to
  8421. * do.
  8422. */
  8423. - ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  8424. + ret = ov5693_write_reg(ov5693->client, OV5693_8BIT,
  8425. OV5693_AGC_L, OV5693_GAIN_CTRL_L(gain));
  8426. if (ret) {
  8427. - dev_err(&sensor->i2c_client->dev, "%s: write %x error, aborted\n",
  8428. + dev_err(&ov5693->client->dev, "%s: write %x error, aborted\n",
  8429. __func__, OV5693_AGC_L);
  8430. return ret;
  8431. }
  8432. - ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  8433. + ret = ov5693_write_reg(ov5693->client, OV5693_8BIT,
  8434. OV5693_AGC_H, OV5693_GAIN_CTRL_H(gain));
  8435. if (ret) {
  8436. - dev_err(&sensor->i2c_client->dev, "%s: write %x error, aborted\n",
  8437. + dev_err(&ov5693->client->dev, "%s: write %x error, aborted\n",
  8438. __func__, OV5693_AGC_H);
  8439. return ret;
  8440. }
  8441. @@ -920,60 +920,60 @@ static int ov5693_analog_gain_configure(struct ov5693_device *sensor, u32 gain)
  8442. static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
  8443. {
  8444. - struct ov5693_device *dev =
  8445. + struct ov5693_device *ov5693 =
  8446. container_of(ctrl->handler, struct ov5693_device, ctrl_handler);
  8447. - struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
  8448. + struct i2c_client *client = v4l2_get_subdevdata(&ov5693->sd);
  8449. int ret = 0;
  8450. /* If VBLANK is altered we need to update exposure to compensate */
  8451. if (ctrl->id == V4L2_CID_VBLANK) {
  8452. int exposure_max;
  8453. - exposure_max = dev->mode->lines_per_frame - 8;
  8454. - __v4l2_ctrl_modify_range(dev->ctrls.exposure, dev->ctrls.exposure->minimum,
  8455. - exposure_max, dev->ctrls.exposure->step,
  8456. - dev->ctrls.exposure->val < exposure_max ?
  8457. - dev->ctrls.exposure->val : exposure_max);
  8458. + exposure_max = ov5693->mode->lines_per_frame - 8;
  8459. + __v4l2_ctrl_modify_range(ov5693->ctrls.exposure, ov5693->ctrls.exposure->minimum,
  8460. + exposure_max, ov5693->ctrls.exposure->step,
  8461. + ov5693->ctrls.exposure->val < exposure_max ?
  8462. + ov5693->ctrls.exposure->val : exposure_max);
  8463. }
  8464. switch (ctrl->id) {
  8465. case V4L2_CID_FOCUS_ABSOLUTE:
  8466. dev_dbg(&client->dev, "%s: CID_FOCUS_ABSOLUTE:%d.\n",
  8467. __func__, ctrl->val);
  8468. - ret = ov5693_t_focus_abs(&dev->sd, ctrl->val);
  8469. + ret = ov5693_t_focus_abs(&ov5693->sd, ctrl->val);
  8470. break;
  8471. case V4L2_CID_FOCUS_RELATIVE:
  8472. dev_dbg(&client->dev, "%s: CID_FOCUS_RELATIVE:%d.\n",
  8473. __func__, ctrl->val);
  8474. - ret = ov5693_t_focus_rel(&dev->sd, ctrl->val);
  8475. + ret = ov5693_t_focus_rel(&ov5693->sd, ctrl->val);
  8476. break;
  8477. case V4L2_CID_EXPOSURE:
  8478. dev_dbg(&client->dev, "%s: CID_EXPOSURE:%d.\n",
  8479. __func__, ctrl->val);
  8480. - ret = ov5693_exposure_configure(dev, ctrl->val);
  8481. + ret = ov5693_exposure_configure(ov5693, ctrl->val);
  8482. if (ret)
  8483. return ret;
  8484. break;
  8485. case V4L2_CID_ANALOGUE_GAIN:
  8486. dev_dbg(&client->dev, "%s: CID_ANALOGUE_GAIN:%d.\n",
  8487. __func__, ctrl->val);
  8488. - ret = ov5693_analog_gain_configure(dev, ctrl->val);
  8489. + ret = ov5693_analog_gain_configure(ov5693, ctrl->val);
  8490. if (ret)
  8491. return ret;
  8492. break;
  8493. case V4L2_CID_DIGITAL_GAIN:
  8494. dev_dbg(&client->dev, "%s: CID_DIGITAL_GAIN:%d.\n",
  8495. __func__, ctrl->val);
  8496. - ret = ov5693_gain_configure(dev, ctrl->val);
  8497. + ret = ov5693_gain_configure(ov5693, ctrl->val);
  8498. if (ret)
  8499. return ret;
  8500. break;
  8501. case V4L2_CID_HFLIP:
  8502. - return ov5693_flip_horz_configure(dev, !!ctrl->val);
  8503. + return ov5693_flip_horz_configure(ov5693, !!ctrl->val);
  8504. case V4L2_CID_VFLIP:
  8505. - return ov5693_flip_vert_configure(dev, !!ctrl->val);
  8506. + return ov5693_flip_vert_configure(ov5693, !!ctrl->val);
  8507. case V4L2_CID_VBLANK:
  8508. ret = ov5693_write_reg(client, OV5693_16BIT, OV5693_TIMING_VTS_H,
  8509. - dev->mode->height + ctrl->val);
  8510. + ov5693->mode->height + ctrl->val);
  8511. break;
  8512. default:
  8513. ret = -EINVAL;
  8514. @@ -983,16 +983,16 @@ static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
  8515. static int ov5693_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
  8516. {
  8517. - struct ov5693_device *dev =
  8518. + struct ov5693_device *ov5693 =
  8519. container_of(ctrl->handler, struct ov5693_device, ctrl_handler);
  8520. int ret = 0;
  8521. switch (ctrl->id) {
  8522. case V4L2_CID_EXPOSURE_ABSOLUTE:
  8523. - ret = ov5693_q_exposure(&dev->sd, &ctrl->val);
  8524. + ret = ov5693_q_exposure(&ov5693->sd, &ctrl->val);
  8525. break;
  8526. case V4L2_CID_AUTOGAIN:
  8527. - ret = ov5693_get_gain(dev, &ctrl->val);
  8528. + ret = ov5693_get_gain(ov5693, &ctrl->val);
  8529. break;
  8530. case V4L2_CID_FOCUS_ABSOLUTE:
  8531. /* NOTE: there was atomisp-specific function ov5693_q_focus_abs() */
  8532. @@ -1034,12 +1034,12 @@ static const struct v4l2_ctrl_config ov5693_controls[] = {
  8533. },
  8534. };
  8535. -static int ov5693_isp_configure(struct ov5693_device *sensor)
  8536. +static int ov5693_isp_configure(struct ov5693_device *ov5693)
  8537. {
  8538. int ret;
  8539. /* Enable lens correction. */
  8540. - ret = ov5693_write_reg(sensor->i2c_client, OV5693_8BIT,
  8541. + ret = ov5693_write_reg(ov5693->client, OV5693_8BIT,
  8542. OV5693_ISP_CTRL0_REG, 0x86);
  8543. if (ret)
  8544. return ret;
  8545. @@ -1049,18 +1049,18 @@ static int ov5693_isp_configure(struct ov5693_device *sensor)
  8546. static int ov5693_init(struct v4l2_subdev *sd)
  8547. {
  8548. - struct ov5693_device *dev = to_ov5693_sensor(sd);
  8549. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  8550. struct i2c_client *client = v4l2_get_subdevdata(sd);
  8551. int ret;
  8552. - if (!dev->has_vcm)
  8553. + if (!ov5693->has_vcm)
  8554. return 0;
  8555. dev_info(&client->dev, "%s\n", __func__);
  8556. - mutex_lock(&dev->input_lock);
  8557. - dev->vcm_update = false;
  8558. + mutex_lock(&ov5693->lock);
  8559. + ov5693->vcm_update = false;
  8560. - if (dev->vcm == VCM_AD5823) {
  8561. + if (ov5693->vcm == VCM_AD5823) {
  8562. ret = vcm_ad_i2c_wr8(client, 0x01, 0x01); /* vcm init test */
  8563. if (ret)
  8564. dev_err(&client->dev,
  8565. @@ -1079,16 +1079,16 @@ static int ov5693_init(struct v4l2_subdev *sd)
  8566. }
  8567. /*change initial focus value for ad5823*/
  8568. - if (dev->vcm == VCM_AD5823) {
  8569. - dev->focus = AD5823_INIT_FOCUS_POS;
  8570. + if (ov5693->vcm == VCM_AD5823) {
  8571. + ov5693->focus = AD5823_INIT_FOCUS_POS;
  8572. ov5693_t_focus_abs(sd, AD5823_INIT_FOCUS_POS);
  8573. } else {
  8574. - dev->focus = 0;
  8575. + ov5693->focus = 0;
  8576. ov5693_t_focus_abs(sd, 0);
  8577. }
  8578. - ov5693_isp_configure(dev);
  8579. - mutex_unlock(&dev->input_lock);
  8580. + ov5693_isp_configure(ov5693);
  8581. + mutex_unlock(&ov5693->lock);
  8582. return 0;
  8583. }
  8584. @@ -1096,32 +1096,32 @@ static int ov5693_init(struct v4l2_subdev *sd)
  8585. static int __power_up(struct v4l2_subdev *sd)
  8586. {
  8587. struct i2c_client *client = v4l2_get_subdevdata(sd);
  8588. - struct ov5693_device *sensor = to_ov5693_sensor(sd);
  8589. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  8590. int ret;
  8591. - ret = clk_prepare_enable(sensor->clk);
  8592. + ret = clk_prepare_enable(ov5693->clk);
  8593. if (ret) {
  8594. dev_err(&client->dev, "Error enabling clock\n");
  8595. return -EINVAL;
  8596. }
  8597. - if (sensor->indicator_led)
  8598. - gpiod_set_value_cansleep(sensor->indicator_led, 1);
  8599. + if (ov5693->indicator_led)
  8600. + gpiod_set_value_cansleep(ov5693->indicator_led, 1);
  8601. ret = regulator_bulk_enable(OV5693_NUM_SUPPLIES,
  8602. - sensor->supplies);
  8603. + ov5693->supplies);
  8604. if (ret)
  8605. goto fail_power;
  8606. - gpiod_set_value_cansleep(sensor->reset, 0);
  8607. + gpiod_set_value_cansleep(ov5693->reset, 0);
  8608. __cci_delay(up_delay);
  8609. return 0;
  8610. fail_power:
  8611. - if (sensor->indicator_led)
  8612. - gpiod_set_value_cansleep(sensor->indicator_led, 0);
  8613. + if (ov5693->indicator_led)
  8614. + gpiod_set_value_cansleep(ov5693->indicator_led, 0);
  8615. dev_err(&client->dev, "sensor power-up failed\n");
  8616. return ret;
  8617. @@ -1129,17 +1129,17 @@ static int __power_up(struct v4l2_subdev *sd)
  8618. static int power_down(struct v4l2_subdev *sd)
  8619. {
  8620. - struct ov5693_device *dev = to_ov5693_sensor(sd);
  8621. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  8622. - dev->focus = OV5693_INVALID_CONFIG;
  8623. + ov5693->focus = OV5693_INVALID_CONFIG;
  8624. - gpiod_set_value_cansleep(dev->reset, 1);
  8625. + gpiod_set_value_cansleep(ov5693->reset, 1);
  8626. - clk_disable_unprepare(dev->clk);
  8627. + clk_disable_unprepare(ov5693->clk);
  8628. - if (dev->indicator_led)
  8629. - gpiod_set_value_cansleep(dev->indicator_led, 0);
  8630. - return regulator_bulk_disable(OV5693_NUM_SUPPLIES, dev->supplies);
  8631. + if (ov5693->indicator_led)
  8632. + gpiod_set_value_cansleep(ov5693->indicator_led, 0);
  8633. + return regulator_bulk_disable(OV5693_NUM_SUPPLIES, ov5693->supplies);
  8634. }
  8635. static int power_up(struct v4l2_subdev *sd)
  8636. @@ -1265,7 +1265,7 @@ static int get_resolution_index(int w, int h)
  8637. /* TODO: remove it. */
  8638. static int startup(struct v4l2_subdev *sd)
  8639. {
  8640. - struct ov5693_device *dev = to_ov5693_sensor(sd);
  8641. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  8642. struct i2c_client *client = v4l2_get_subdevdata(sd);
  8643. int ret = 0;
  8644. @@ -1282,7 +1282,7 @@ static int startup(struct v4l2_subdev *sd)
  8645. return ret;
  8646. }
  8647. - ret = ov5693_write_reg_array(client, ov5693_res[dev->fmt_idx].regs);
  8648. + ret = ov5693_write_reg_array(client, ov5693_res[ov5693->fmt_idx].regs);
  8649. if (ret) {
  8650. dev_err(&client->dev, "ov5693 write register err.\n");
  8651. return ret;
  8652. @@ -1296,7 +1296,7 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd,
  8653. struct v4l2_subdev_format *format)
  8654. {
  8655. struct v4l2_mbus_framefmt *fmt = &format->format;
  8656. - struct ov5693_device *dev = to_ov5693_sensor(sd);
  8657. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  8658. struct i2c_client *client = v4l2_get_subdevdata(sd);
  8659. int ret = 0;
  8660. int idx;
  8661. @@ -1307,7 +1307,7 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd,
  8662. if (!fmt)
  8663. return -EINVAL;
  8664. - mutex_lock(&dev->input_lock);
  8665. + mutex_lock(&ov5693->lock);
  8666. idx = nearest_resolution_index(fmt->width, fmt->height);
  8667. if (idx == -1) {
  8668. /* return the largest resolution */
  8669. @@ -1325,8 +1325,8 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd,
  8670. goto mutex_unlock;
  8671. }
  8672. - dev->fmt_idx = get_resolution_index(fmt->width, fmt->height);
  8673. - if (dev->fmt_idx == -1) {
  8674. + ov5693->fmt_idx = get_resolution_index(fmt->width, fmt->height);
  8675. + if (ov5693->fmt_idx == -1) {
  8676. dev_err(&client->dev, "get resolution fail\n");
  8677. ret = -EINVAL;
  8678. goto mutex_unlock;
  8679. @@ -1339,9 +1339,9 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd,
  8680. continue;
  8681. }
  8682. - mutex_unlock(&dev->input_lock);
  8683. + mutex_unlock(&ov5693->lock);
  8684. ov5693_init(sd);
  8685. - mutex_lock(&dev->input_lock);
  8686. + mutex_lock(&ov5693->lock);
  8687. ret = startup(sd);
  8688. if (ret)
  8689. dev_err(&client->dev, " startup() FAILED!\n");
  8690. @@ -1353,8 +1353,6 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd,
  8691. goto mutex_unlock;
  8692. }
  8693. -
  8694. -
  8695. /*
  8696. * After sensor settings are set to HW, sometimes stream is started.
  8697. * This would cause ISP timeout because ISP is not ready to receive
  8698. @@ -1366,19 +1364,19 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd,
  8699. dev_warn(&client->dev, "ov5693 stream off err\n");
  8700. mutex_unlock:
  8701. - mutex_unlock(&dev->input_lock);
  8702. + mutex_unlock(&ov5693->lock);
  8703. return ret;
  8704. }
  8705. static const struct v4l2_rect *
  8706. -__ov5693_get_pad_crop(struct ov5693_device *dev, struct v4l2_subdev_pad_config *cfg,
  8707. +__ov5693_get_pad_crop(struct ov5693_device *ov5693, struct v4l2_subdev_pad_config *cfg,
  8708. unsigned int pad, enum v4l2_subdev_format_whence which)
  8709. {
  8710. switch (which) {
  8711. case V4L2_SUBDEV_FORMAT_TRY:
  8712. - return v4l2_subdev_get_try_crop(&dev->sd, cfg, pad);
  8713. + return v4l2_subdev_get_try_crop(&ov5693->sd, cfg, pad);
  8714. case V4L2_SUBDEV_FORMAT_ACTIVE:
  8715. - return &dev->mode->crop;
  8716. + return &ov5693->mode->crop;
  8717. }
  8718. return NULL;
  8719. @@ -1389,12 +1387,12 @@ static int ov5693_get_selection(struct v4l2_subdev *sd,
  8720. {
  8721. switch (sel->target) {
  8722. case V4L2_SEL_TGT_CROP: {
  8723. - struct ov5693_device *dev = to_ov5693_sensor(sd);
  8724. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  8725. - mutex_lock(&dev->input_lock);
  8726. - sel->r = *__ov5693_get_pad_crop(dev, cfg, sel->pad,
  8727. + mutex_lock(&ov5693->lock);
  8728. + sel->r = *__ov5693_get_pad_crop(ov5693, cfg, sel->pad,
  8729. sel->which);
  8730. - mutex_unlock(&dev->input_lock);
  8731. + mutex_unlock(&ov5693->lock);
  8732. return 0;
  8733. }
  8734. @@ -1424,7 +1422,7 @@ static int ov5693_get_fmt(struct v4l2_subdev *sd,
  8735. struct v4l2_subdev_format *format)
  8736. {
  8737. struct v4l2_mbus_framefmt *fmt = &format->format;
  8738. - struct ov5693_device *dev = to_ov5693_sensor(sd);
  8739. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  8740. if (format->pad)
  8741. return -EINVAL;
  8742. @@ -1432,8 +1430,8 @@ static int ov5693_get_fmt(struct v4l2_subdev *sd,
  8743. if (!fmt)
  8744. return -EINVAL;
  8745. - fmt->width = ov5693_res[dev->fmt_idx].width;
  8746. - fmt->height = ov5693_res[dev->fmt_idx].height;
  8747. + fmt->width = ov5693_res[ov5693->fmt_idx].width;
  8748. + fmt->height = ov5693_res[ov5693->fmt_idx].height;
  8749. fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
  8750. return 0;
  8751. @@ -1481,7 +1479,7 @@ static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
  8752. struct i2c_client *client = v4l2_get_subdevdata(sd);
  8753. int ret;
  8754. - mutex_lock(&dev->input_lock);
  8755. + mutex_lock(&dev->lock);
  8756. /* power_on() here before streaming for regular PCs. */
  8757. if (enable) {
  8758. @@ -1507,26 +1505,26 @@ static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
  8759. power_down(sd);
  8760. out:
  8761. - mutex_unlock(&dev->input_lock);
  8762. + mutex_unlock(&dev->lock);
  8763. return ret;
  8764. }
  8765. static int ov5693_s_config(struct v4l2_subdev *sd, int irq)
  8766. {
  8767. - struct ov5693_device *dev = to_ov5693_sensor(sd);
  8768. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  8769. struct i2c_client *client = v4l2_get_subdevdata(sd);
  8770. int ret = 0;
  8771. - mutex_lock(&dev->input_lock);
  8772. + mutex_lock(&ov5693->lock);
  8773. ret = power_up(sd);
  8774. if (ret) {
  8775. dev_err(&client->dev, "ov5693 power-up err.\n");
  8776. goto fail_power_on;
  8777. }
  8778. - if (!dev->vcm)
  8779. - dev->vcm = vcm_detect(client);
  8780. + if (!ov5693->vcm)
  8781. + ov5693->vcm = vcm_detect(client);
  8782. /* config & detect sensor */
  8783. ret = ov5693_detect(client);
  8784. @@ -1535,7 +1533,7 @@ static int ov5693_s_config(struct v4l2_subdev *sd, int irq)
  8785. goto fail_power_on;
  8786. }
  8787. - dev->otp_data = ov5693_otp_read(sd);
  8788. + ov5693->otp_data = ov5693_otp_read(sd);
  8789. /* turn off sensor, after probed */
  8790. ret = power_down(sd);
  8791. @@ -1543,24 +1541,24 @@ static int ov5693_s_config(struct v4l2_subdev *sd, int irq)
  8792. dev_err(&client->dev, "ov5693 power-off err.\n");
  8793. goto fail_power_on;
  8794. }
  8795. - mutex_unlock(&dev->input_lock);
  8796. + mutex_unlock(&ov5693->lock);
  8797. return ret;
  8798. fail_power_on:
  8799. power_down(sd);
  8800. dev_err(&client->dev, "sensor power-gating failed\n");
  8801. - mutex_unlock(&dev->input_lock);
  8802. + mutex_unlock(&ov5693->lock);
  8803. return ret;
  8804. }
  8805. static int ov5693_g_frame_interval(struct v4l2_subdev *sd,
  8806. struct v4l2_subdev_frame_interval *interval)
  8807. {
  8808. - struct ov5693_device *dev = to_ov5693_sensor(sd);
  8809. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  8810. interval->interval.numerator = 1;
  8811. - interval->interval.denominator = ov5693_res[dev->fmt_idx].fps;
  8812. + interval->interval.denominator = ov5693_res[ov5693->fmt_idx].fps;
  8813. return 0;
  8814. }
  8815. @@ -1725,7 +1723,7 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  8816. return ret;
  8817. /* Use same lock for controls as for everything else. */
  8818. - ov5693->ctrl_handler.lock = &ov5693->input_lock;
  8819. + ov5693->ctrl_handler.lock = &ov5693->lock;
  8820. ov5693->sd.ctrl_handler = &ov5693->ctrl_handler;
  8821. return 0;
  8822. @@ -1733,21 +1731,38 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  8823. static int ov5693_configure_gpios(struct ov5693_device *ov5693)
  8824. {
  8825. - ov5693->reset = gpiod_get_index(&ov5693->i2c_client->dev, "reset", 0,
  8826. + int ret;
  8827. +
  8828. + ov5693->reset = gpiod_get_optional(&ov5693->client->dev, "reset",
  8829. GPIOD_OUT_HIGH);
  8830. if (IS_ERR(ov5693->reset)) {
  8831. - dev_err(&ov5693->i2c_client->dev, "Couldn't find reset GPIO\n");
  8832. - return -EINVAL;
  8833. + dev_err(&ov5693->client->dev, "Couldn't find reset GPIO\n");
  8834. + return PTR_ERR(ov5693->reset);
  8835. + }
  8836. +
  8837. + ov5693->powerdown = gpiod_get_optional(&ov5693->client->dev, "powerdown",
  8838. + GPIOD_OUT_HIGH);
  8839. + if (IS_ERR(ov5693->powerdown)) {
  8840. + dev_err(&ov5693->client->dev, "Couldn't find powerdown GPIO\n");
  8841. + ret = PTR_ERR(ov5693->powerdown);
  8842. + goto err_put_reset;
  8843. }
  8844. - ov5693->indicator_led = gpiod_get_index_optional(&ov5693->i2c_client->dev, "indicator-led", 0,
  8845. + ov5693->indicator_led = gpiod_get_optional(&ov5693->client->dev, "indicator-led",
  8846. GPIOD_OUT_HIGH);
  8847. if (IS_ERR(ov5693->indicator_led)) {
  8848. - dev_err(&ov5693->i2c_client->dev, "Couldn't find indicator-led GPIO\n");
  8849. - return -EINVAL;
  8850. + dev_err(&ov5693->client->dev, "Couldn't find indicator-led GPIO\n");
  8851. + ret = PTR_ERR(ov5693->indicator_led);
  8852. + goto err_put_powerdown;
  8853. }
  8854. return 0;
  8855. +err_put_reset:
  8856. + gpiod_put(ov5693->reset);
  8857. +err_put_powerdown:
  8858. + gpiod_put(ov5693->powerdown);
  8859. +
  8860. + return ret;
  8861. }
  8862. static int ov5693_get_regulators(struct ov5693_device *ov5693)
  8863. @@ -1757,7 +1772,7 @@ static int ov5693_get_regulators(struct ov5693_device *ov5693)
  8864. for (i = 0; i < OV5693_NUM_SUPPLIES; i++)
  8865. ov5693->supplies[i].supply = ov5693_supply_names[i];
  8866. - return regulator_bulk_get(&ov5693->i2c_client->dev,
  8867. + return regulator_bulk_get(&ov5693->client->dev,
  8868. OV5693_NUM_SUPPLIES,
  8869. ov5693->supplies);
  8870. }
  8871. @@ -1773,13 +1788,13 @@ static int ov5693_probe(struct i2c_client *client)
  8872. if (!ov5693)
  8873. return -ENOMEM;
  8874. - ov5693->i2c_client = client;
  8875. + ov5693->client = client;
  8876. /* check if VCM device exists */
  8877. /* TODO: read from SSDB */
  8878. ov5693->has_vcm = false;
  8879. - mutex_init(&ov5693->input_lock);
  8880. + mutex_init(&ov5693->lock);
  8881. v4l2_i2c_subdev_init(&ov5693->sd, client, &ov5693_ops);
  8882. diff --git a/drivers/media/i2c/ov5693.h b/drivers/media/i2c/ov5693.h
  8883. index 7f1d31a82d3d..70ccb3aae4c7 100644
  8884. --- a/drivers/media/i2c/ov5693.h
  8885. +++ b/drivers/media/i2c/ov5693.h
  8886. @@ -241,14 +241,15 @@ enum vcm_type {
  8887. * ov5693 device structure.
  8888. */
  8889. struct ov5693_device {
  8890. - struct i2c_client *i2c_client;
  8891. + struct i2c_client *client;
  8892. struct v4l2_subdev sd;
  8893. struct media_pad pad;
  8894. struct v4l2_mbus_framefmt format;
  8895. - struct mutex input_lock;
  8896. + struct mutex lock;
  8897. struct v4l2_ctrl_handler ctrl_handler;
  8898. struct gpio_desc *reset;
  8899. + struct gpio_desc *powerdown;
  8900. struct gpio_desc *indicator_led;
  8901. struct regulator_bulk_data supplies[OV5693_NUM_SUPPLIES];
  8902. struct clk *clk;
  8903. --
  8904. 2.33.0
  8905. From 00545008dfbfb2e4447504e41561beedfb9ccdf0 Mon Sep 17 00:00:00 2001
  8906. From: Daniel Scally <djrscally@gmail.com>
  8907. Date: Thu, 28 Jan 2021 12:04:38 +0000
  8908. Subject: [PATCH] media: i2c: Add pm_runtime support to ov5693 driver
  8909. The ov5693 driver currently uses hacky and horrible power up/down methods
  8910. called directly in s_stream. Add pm_runtime support and use that in
  8911. s_stream instead. Replace all other uses of the power+up/down() calls with
  8912. the single ov5693_sensor_stream() for now.
  8913. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  8914. Patchset: cameras
  8915. ---
  8916. drivers/media/i2c/ov5693.c | 183 +++++++++++++++++++++++++++++--------
  8917. drivers/media/i2c/ov5693.h | 1 +
  8918. 2 files changed, 146 insertions(+), 38 deletions(-)
  8919. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  8920. index 0643390c872a..f2eaa5f71a31 100644
  8921. --- a/drivers/media/i2c/ov5693.c
  8922. +++ b/drivers/media/i2c/ov5693.c
  8923. @@ -29,6 +29,7 @@
  8924. #include <linux/module.h>
  8925. #include <linux/moduleparam.h>
  8926. #include <linux/mm.h>
  8927. +#include <linux/pm_runtime.h>
  8928. #include <linux/regulator/consumer.h>
  8929. #include <linux/slab.h>
  8930. #include <linux/string.h>
  8931. @@ -935,6 +936,10 @@ static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
  8932. ov5693->ctrls.exposure->val : exposure_max);
  8933. }
  8934. + /* Only apply changes to the controls if the device is powered up */
  8935. + if (!pm_runtime_get_if_in_use(&ov5693->client->dev))
  8936. + return 0;
  8937. +
  8938. switch (ctrl->id) {
  8939. case V4L2_CID_FOCUS_ABSOLUTE:
  8940. dev_dbg(&client->dev, "%s: CID_FOCUS_ABSOLUTE:%d.\n",
  8941. @@ -950,27 +955,23 @@ static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
  8942. dev_dbg(&client->dev, "%s: CID_EXPOSURE:%d.\n",
  8943. __func__, ctrl->val);
  8944. ret = ov5693_exposure_configure(ov5693, ctrl->val);
  8945. - if (ret)
  8946. - return ret;
  8947. break;
  8948. case V4L2_CID_ANALOGUE_GAIN:
  8949. dev_dbg(&client->dev, "%s: CID_ANALOGUE_GAIN:%d.\n",
  8950. __func__, ctrl->val);
  8951. ret = ov5693_analog_gain_configure(ov5693, ctrl->val);
  8952. - if (ret)
  8953. - return ret;
  8954. break;
  8955. case V4L2_CID_DIGITAL_GAIN:
  8956. dev_dbg(&client->dev, "%s: CID_DIGITAL_GAIN:%d.\n",
  8957. __func__, ctrl->val);
  8958. ret = ov5693_gain_configure(ov5693, ctrl->val);
  8959. - if (ret)
  8960. - return ret;
  8961. break;
  8962. case V4L2_CID_HFLIP:
  8963. - return ov5693_flip_horz_configure(ov5693, !!ctrl->val);
  8964. + ret = ov5693_flip_horz_configure(ov5693, !!ctrl->val);
  8965. + break;
  8966. case V4L2_CID_VFLIP:
  8967. - return ov5693_flip_vert_configure(ov5693, !!ctrl->val);
  8968. + ret = ov5693_flip_vert_configure(ov5693, !!ctrl->val);
  8969. + break;
  8970. case V4L2_CID_VBLANK:
  8971. ret = ov5693_write_reg(client, OV5693_16BIT, OV5693_TIMING_VTS_H,
  8972. ov5693->mode->height + ctrl->val);
  8973. @@ -978,6 +979,9 @@ static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
  8974. default:
  8975. ret = -EINVAL;
  8976. }
  8977. +
  8978. + pm_runtime_put(&ov5693->client->dev);
  8979. +
  8980. return ret;
  8981. }
  8982. @@ -1093,6 +1097,106 @@ static int ov5693_init(struct v4l2_subdev *sd)
  8983. return 0;
  8984. }
  8985. +static int ov5693_sw_standby(struct ov5693_device *ov5693, bool standby)
  8986. +{
  8987. + return ov5693_write_reg(ov5693->client, OV5693_8BIT, OV5693_SW_STREAM,
  8988. + standby ? OV5693_STOP_STREAMING : OV5693_START_STREAMING);
  8989. +}
  8990. +
  8991. +static void ov5693_sensor_powerdown(struct ov5693_device *ov5693)
  8992. +{
  8993. + gpiod_set_value_cansleep(ov5693->reset, 1);
  8994. + gpiod_set_value_cansleep(ov5693->powerdown, 1);
  8995. +
  8996. + regulator_bulk_disable(OV5693_NUM_SUPPLIES, ov5693->supplies);
  8997. +
  8998. + clk_disable_unprepare(ov5693->clk);
  8999. + gpiod_set_value_cansleep(ov5693->indicator_led, 0);
  9000. +}
  9001. +
  9002. +
  9003. +static int ov5693_sensor_powerup(struct ov5693_device *ov5693)
  9004. +{
  9005. + int ret = 0;
  9006. +
  9007. + gpiod_set_value_cansleep(ov5693->reset, 1);
  9008. + gpiod_set_value_cansleep(ov5693->powerdown, 1);
  9009. +
  9010. + ret = clk_prepare_enable(ov5693->clk);
  9011. + if (ret) {
  9012. + dev_err(&ov5693->client->dev, "Failed to enable clk\n");
  9013. + goto fail_power;
  9014. + }
  9015. +
  9016. + ret = regulator_bulk_enable(OV5693_NUM_SUPPLIES, ov5693->supplies);
  9017. + if (ret) {
  9018. + dev_err(&ov5693->client->dev, "Failed to enable regulators\n");
  9019. + goto fail_power;
  9020. + }
  9021. +
  9022. + gpiod_set_value_cansleep(ov5693->reset, 0);
  9023. + gpiod_set_value_cansleep(ov5693->powerdown, 0);
  9024. + gpiod_set_value_cansleep(ov5693->indicator_led, 1);
  9025. +
  9026. + usleep_range(20000, 25000);
  9027. +
  9028. + return 0;
  9029. +
  9030. +fail_power:
  9031. + ov5693_sensor_powerdown(ov5693);
  9032. + return ret;
  9033. +}
  9034. +
  9035. +static int __maybe_unused ov5693_sensor_suspend(struct device *dev)
  9036. +{
  9037. + struct i2c_client *client = i2c_verify_client(dev);
  9038. + struct v4l2_subdev *sd = i2c_get_clientdata(client);
  9039. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  9040. + int ret;
  9041. +
  9042. + mutex_lock(&ov5693->lock);
  9043. +
  9044. + if (ov5693->streaming) {
  9045. + ret = ov5693_sw_standby(ov5693, true);
  9046. + if (ret)
  9047. + goto out_unlock;
  9048. + }
  9049. +
  9050. + ov5693_sensor_powerdown(ov5693);
  9051. +
  9052. +out_unlock:
  9053. + mutex_unlock(&ov5693->lock);
  9054. + return ret;
  9055. +}
  9056. +
  9057. +static int __maybe_unused ov5693_sensor_resume(struct device *dev)
  9058. +{
  9059. + struct i2c_client *client = i2c_verify_client(dev);
  9060. + struct v4l2_subdev *sd = i2c_get_clientdata(client);
  9061. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  9062. + int ret;
  9063. +
  9064. + mutex_lock(&ov5693->lock);
  9065. +
  9066. + ret = ov5693_sensor_powerup(ov5693);
  9067. + if (ret)
  9068. + goto out_unlock;
  9069. +
  9070. + if (ov5693->streaming) {
  9071. + ret = ov5693_sw_standby(ov5693, false);
  9072. + if (ret)
  9073. + goto err_power;
  9074. + }
  9075. +
  9076. + goto out_unlock;
  9077. +
  9078. +err_power:
  9079. + ov5693_sensor_powerdown(ov5693);
  9080. +out_unlock:
  9081. + mutex_unlock(&ov5693->lock);
  9082. + return ret;
  9083. +}
  9084. +
  9085. static int __power_up(struct v4l2_subdev *sd)
  9086. {
  9087. struct i2c_client *client = v4l2_get_subdevdata(sd);
  9088. @@ -1134,6 +1238,7 @@ static int power_down(struct v4l2_subdev *sd)
  9089. ov5693->focus = OV5693_INVALID_CONFIG;
  9090. gpiod_set_value_cansleep(ov5693->reset, 1);
  9091. + gpiod_set_value_cansleep(ov5693->powerdown, 1);
  9092. clk_disable_unprepare(ov5693->clk);
  9093. @@ -1333,7 +1438,7 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd,
  9094. }
  9095. for (cnt = 0; cnt < OV5693_POWER_UP_RETRY_NUM; cnt++) {
  9096. - ret = power_up(sd);
  9097. + ret = ov5693_sensor_powerup(ov5693);
  9098. if (ret) {
  9099. dev_err(&client->dev, "power up failed\n");
  9100. continue;
  9101. @@ -1475,38 +1580,34 @@ static int ov5693_detect(struct i2c_client *client)
  9102. static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
  9103. {
  9104. - struct ov5693_device *dev = to_ov5693_sensor(sd);
  9105. - struct i2c_client *client = v4l2_get_subdevdata(sd);
  9106. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  9107. int ret;
  9108. - mutex_lock(&dev->lock);
  9109. -
  9110. - /* power_on() here before streaming for regular PCs. */
  9111. if (enable) {
  9112. - ret = power_up(sd);
  9113. - if (ret) {
  9114. - dev_err(&client->dev, "sensor power-up error\n");
  9115. - goto out;
  9116. - }
  9117. + ret = pm_runtime_get_sync(&ov5693->client->dev);
  9118. + if (ret < 0)
  9119. + goto err_power_down;
  9120. }
  9121. - ret = __v4l2_ctrl_handler_setup(&dev->ctrl_handler);
  9122. - if (ret) {
  9123. - power_down(sd);
  9124. - return ret;
  9125. - }
  9126. + ret = __v4l2_ctrl_handler_setup(&ov5693->ctrl_handler);
  9127. + if (ret)
  9128. + goto err_power_down;
  9129. - ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_SW_STREAM,
  9130. - enable ? OV5693_START_STREAMING :
  9131. - OV5693_STOP_STREAMING);
  9132. + mutex_lock(&ov5693->lock);
  9133. + ret = ov5693_sw_standby(ov5693, !enable);
  9134. + mutex_unlock(&ov5693->lock);
  9135. +
  9136. + if (ret)
  9137. + goto err_power_down;
  9138. + ov5693->streaming = !!enable;
  9139. /* power_off() here after streaming for regular PCs. */
  9140. if (!enable)
  9141. - power_down(sd);
  9142. -
  9143. -out:
  9144. - mutex_unlock(&dev->lock);
  9145. + pm_runtime_put(&ov5693->client->dev);
  9146. + return 0;
  9147. +err_power_down:
  9148. + pm_runtime_put_noidle(&ov5693->client->dev);
  9149. return ret;
  9150. }
  9151. @@ -1517,7 +1618,7 @@ static int ov5693_s_config(struct v4l2_subdev *sd, int irq)
  9152. int ret = 0;
  9153. mutex_lock(&ov5693->lock);
  9154. - ret = power_up(sd);
  9155. + ret = ov5693_sensor_powerup(ov5693);
  9156. if (ret) {
  9157. dev_err(&client->dev, "ov5693 power-up err.\n");
  9158. goto fail_power_on;
  9159. @@ -1536,17 +1637,14 @@ static int ov5693_s_config(struct v4l2_subdev *sd, int irq)
  9160. ov5693->otp_data = ov5693_otp_read(sd);
  9161. /* turn off sensor, after probed */
  9162. - ret = power_down(sd);
  9163. - if (ret) {
  9164. - dev_err(&client->dev, "ov5693 power-off err.\n");
  9165. - goto fail_power_on;
  9166. - }
  9167. + ov5693_sensor_powerdown(ov5693);
  9168. +
  9169. mutex_unlock(&ov5693->lock);
  9170. return ret;
  9171. fail_power_on:
  9172. - power_down(sd);
  9173. + ov5693_sensor_powerdown(ov5693);
  9174. dev_err(&client->dev, "sensor power-gating failed\n");
  9175. mutex_unlock(&ov5693->lock);
  9176. return ret;
  9177. @@ -1830,6 +1928,9 @@ static int ov5693_probe(struct i2c_client *client)
  9178. if (ret)
  9179. ov5693_remove(client);
  9180. + pm_runtime_enable(&client->dev);
  9181. + pm_runtime_set_suspended(&client->dev);
  9182. +
  9183. ret = v4l2_async_register_subdev_sensor_common(&ov5693->sd);
  9184. if (ret) {
  9185. dev_err(&client->dev, "failed to register V4L2 subdev: %d", ret);
  9186. @@ -1839,6 +1940,7 @@ static int ov5693_probe(struct i2c_client *client)
  9187. return ret;
  9188. media_entity_cleanup:
  9189. + pm_runtime_disable(&client->dev);
  9190. media_entity_cleanup(&ov5693->sd.entity);
  9191. out_put_reset:
  9192. gpiod_put(ov5693->reset);
  9193. @@ -1848,6 +1950,10 @@ static int ov5693_probe(struct i2c_client *client)
  9194. return ret;
  9195. }
  9196. +static const struct dev_pm_ops ov5693_pm_ops = {
  9197. + SET_RUNTIME_PM_OPS(ov5693_sensor_suspend, ov5693_sensor_resume, NULL)
  9198. +};
  9199. +
  9200. static const struct acpi_device_id ov5693_acpi_match[] = {
  9201. {"INT33BE"},
  9202. {},
  9203. @@ -1858,6 +1964,7 @@ static struct i2c_driver ov5693_driver = {
  9204. .driver = {
  9205. .name = "ov5693",
  9206. .acpi_match_table = ov5693_acpi_match,
  9207. + .pm = &ov5693_pm_ops,
  9208. },
  9209. .probe_new = ov5693_probe,
  9210. .remove = ov5693_remove,
  9211. diff --git a/drivers/media/i2c/ov5693.h b/drivers/media/i2c/ov5693.h
  9212. index 70ccb3aae4c7..b78d3b474a43 100644
  9213. --- a/drivers/media/i2c/ov5693.h
  9214. +++ b/drivers/media/i2c/ov5693.h
  9215. @@ -256,6 +256,7 @@ struct ov5693_device {
  9216. /* Current mode */
  9217. const struct ov5693_resolution *mode;
  9218. + bool streaming;
  9219. struct camera_sensor_platform_data *platform_data;
  9220. ktime_t timestamp_t_focus_abs;
  9221. --
  9222. 2.33.0
  9223. From 0a057ee3ecd60dd5eb0d8ba418c226cf772cb72b Mon Sep 17 00:00:00 2001
  9224. From: Daniel Scally <djrscally@gmail.com>
  9225. Date: Thu, 28 Jan 2021 12:07:36 +0000
  9226. Subject: [PATCH] media: i2c: Remove old power methods from ov5693
  9227. Now that we have replaced the power_up/down() methods with a unified
  9228. function and pm_runtime support, we can remove these old methods from the
  9229. driver entirely along with some macros and a header.
  9230. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  9231. Patchset: cameras
  9232. ---
  9233. drivers/media/i2c/ov5693.c | 114 -------------------------------------
  9234. 1 file changed, 114 deletions(-)
  9235. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  9236. index f2eaa5f71a31..ce26ce86fbd5 100644
  9237. --- a/drivers/media/i2c/ov5693.c
  9238. +++ b/drivers/media/i2c/ov5693.c
  9239. @@ -27,7 +27,6 @@
  9240. #include <linux/kernel.h>
  9241. #include <linux/kmod.h>
  9242. #include <linux/module.h>
  9243. -#include <linux/moduleparam.h>
  9244. #include <linux/mm.h>
  9245. #include <linux/pm_runtime.h>
  9246. #include <linux/regulator/consumer.h>
  9247. @@ -40,27 +39,6 @@
  9248. #include "ov5693.h"
  9249. #include "ad5823.h"
  9250. -#define __cci_delay(t) \
  9251. - do { \
  9252. - if ((t) < 10) { \
  9253. - usleep_range((t) * 1000, ((t) + 1) * 1000); \
  9254. - } else { \
  9255. - msleep((t)); \
  9256. - } \
  9257. - } while (0)
  9258. -
  9259. -/* Value 30ms reached through experimentation on byt ecs.
  9260. - * The DS specifies a much lower value but when using a smaller value
  9261. - * the I2C bus sometimes locks up permanently when starting the camera.
  9262. - * This issue could not be reproduced on cht, so we can reduce the
  9263. - * delay value to a lower value when insmod.
  9264. - */
  9265. -static uint up_delay = 30;
  9266. -module_param(up_delay, uint, 0644);
  9267. -MODULE_PARM_DESC(up_delay,
  9268. - "Delay prior to the first CCI transaction for ov5693");
  9269. -
  9270. -
  9271. /* Exposure/gain */
  9272. #define OV5693_EXPOSURE_CTRL_HH_REG 0x3500
  9273. @@ -1197,93 +1175,6 @@ static int __maybe_unused ov5693_sensor_resume(struct device *dev)
  9274. return ret;
  9275. }
  9276. -static int __power_up(struct v4l2_subdev *sd)
  9277. -{
  9278. - struct i2c_client *client = v4l2_get_subdevdata(sd);
  9279. - struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  9280. - int ret;
  9281. -
  9282. - ret = clk_prepare_enable(ov5693->clk);
  9283. - if (ret) {
  9284. - dev_err(&client->dev, "Error enabling clock\n");
  9285. - return -EINVAL;
  9286. - }
  9287. -
  9288. - if (ov5693->indicator_led)
  9289. - gpiod_set_value_cansleep(ov5693->indicator_led, 1);
  9290. -
  9291. - ret = regulator_bulk_enable(OV5693_NUM_SUPPLIES,
  9292. - ov5693->supplies);
  9293. - if (ret)
  9294. - goto fail_power;
  9295. -
  9296. - gpiod_set_value_cansleep(ov5693->reset, 0);
  9297. -
  9298. - __cci_delay(up_delay);
  9299. -
  9300. - return 0;
  9301. -
  9302. -fail_power:
  9303. - if (ov5693->indicator_led)
  9304. - gpiod_set_value_cansleep(ov5693->indicator_led, 0);
  9305. - dev_err(&client->dev, "sensor power-up failed\n");
  9306. -
  9307. - return ret;
  9308. -}
  9309. -
  9310. -static int power_down(struct v4l2_subdev *sd)
  9311. -{
  9312. - struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  9313. -
  9314. - ov5693->focus = OV5693_INVALID_CONFIG;
  9315. -
  9316. - gpiod_set_value_cansleep(ov5693->reset, 1);
  9317. - gpiod_set_value_cansleep(ov5693->powerdown, 1);
  9318. -
  9319. - clk_disable_unprepare(ov5693->clk);
  9320. -
  9321. - if (ov5693->indicator_led)
  9322. - gpiod_set_value_cansleep(ov5693->indicator_led, 0);
  9323. - return regulator_bulk_disable(OV5693_NUM_SUPPLIES, ov5693->supplies);
  9324. -}
  9325. -
  9326. -static int power_up(struct v4l2_subdev *sd)
  9327. -{
  9328. - static const int retry_count = 4;
  9329. - int i, ret;
  9330. -
  9331. - for (i = 0; i < retry_count; i++) {
  9332. - ret = __power_up(sd);
  9333. - if (!ret)
  9334. - return 0;
  9335. -
  9336. - power_down(sd);
  9337. - }
  9338. - return ret;
  9339. -}
  9340. -
  9341. -static int ov5693_s_power(struct v4l2_subdev *sd, int on)
  9342. -{
  9343. - struct i2c_client *client = v4l2_get_subdevdata(sd);
  9344. - int ret;
  9345. -
  9346. - dev_info(&client->dev, "%s: on %d\n", __func__, on);
  9347. -
  9348. - if (on == 0)
  9349. - return power_down(sd);
  9350. -
  9351. - /* on == 1 */
  9352. - ret = power_up(sd);
  9353. - if (!ret) {
  9354. - ret = ov5693_init(sd);
  9355. - /* restore settings */
  9356. - ov5693_res = ov5693_res_video;
  9357. - N_RES = N_RES_VIDEO;
  9358. - }
  9359. -
  9360. - return ret;
  9361. -}
  9362. -
  9363. /*
  9364. * distance - calculate the distance
  9365. * @res: resolution
  9366. @@ -1694,10 +1585,6 @@ static const struct v4l2_subdev_video_ops ov5693_video_ops = {
  9367. .g_frame_interval = ov5693_g_frame_interval,
  9368. };
  9369. -static const struct v4l2_subdev_core_ops ov5693_core_ops = {
  9370. - .s_power = ov5693_s_power,
  9371. -};
  9372. -
  9373. static const struct v4l2_subdev_pad_ops ov5693_pad_ops = {
  9374. .enum_mbus_code = ov5693_enum_mbus_code,
  9375. .enum_frame_size = ov5693_enum_frame_size,
  9376. @@ -1707,7 +1594,6 @@ static const struct v4l2_subdev_pad_ops ov5693_pad_ops = {
  9377. };
  9378. static const struct v4l2_subdev_ops ov5693_ops = {
  9379. - .core = &ov5693_core_ops,
  9380. .video = &ov5693_video_ops,
  9381. .pad = &ov5693_pad_ops,
  9382. };
  9383. --
  9384. 2.33.0
  9385. From 1cce1c2b2913dde59e9c2083bdfb8fac1946df44 Mon Sep 17 00:00:00 2001
  9386. From: Daniel Scally <djrscally@gmail.com>
  9387. Date: Thu, 28 Jan 2021 12:14:00 +0000
  9388. Subject: [PATCH] media: i2c: Trim unused headers from ov5693
  9389. The ov5693 driver includes a ton of unecessary headers,
  9390. trim the list down.
  9391. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  9392. Patchset: cameras
  9393. ---
  9394. drivers/media/i2c/ov5693.c | 8 --------
  9395. 1 file changed, 8 deletions(-)
  9396. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  9397. index ce26ce86fbd5..b3b391a49fdb 100644
  9398. --- a/drivers/media/i2c/ov5693.c
  9399. +++ b/drivers/media/i2c/ov5693.c
  9400. @@ -20,19 +20,11 @@
  9401. #include <linux/clk.h>
  9402. #include <linux/delay.h>
  9403. #include <linux/device.h>
  9404. -#include <linux/errno.h>
  9405. #include <linux/i2c.h>
  9406. -#include <linux/init.h>
  9407. -#include <linux/io.h>
  9408. -#include <linux/kernel.h>
  9409. -#include <linux/kmod.h>
  9410. #include <linux/module.h>
  9411. -#include <linux/mm.h>
  9412. #include <linux/pm_runtime.h>
  9413. #include <linux/regulator/consumer.h>
  9414. #include <linux/slab.h>
  9415. -#include <linux/string.h>
  9416. -#include <linux/types.h>
  9417. #include <media/v4l2-device.h>
  9418. #include <media/v4l2-fwnode.h>
  9419. --
  9420. 2.33.0
  9421. From 9a9284056a8c43d857e95e9748164a23ecd2597d Mon Sep 17 00:00:00 2001
  9422. From: Daniel Scally <djrscally@gmail.com>
  9423. Date: Sat, 13 Feb 2021 21:39:35 +0000
  9424. Subject: [PATCH] media: i2c: Remove VCM stuff
  9425. This all needs binning, since we have no idea if it's right. It needs to
  9426. be moved to a driver for the VCM device I guess.
  9427. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  9428. Patchset: cameras
  9429. ---
  9430. drivers/media/i2c/ov5693.c | 325 +------------------------------------
  9431. 1 file changed, 1 insertion(+), 324 deletions(-)
  9432. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  9433. index b3b391a49fdb..2c82b6578de9 100644
  9434. --- a/drivers/media/i2c/ov5693.c
  9435. +++ b/drivers/media/i2c/ov5693.c
  9436. @@ -76,72 +76,6 @@
  9437. #define OV5693_PIXEL_ARRAY_WIDTH 2592U
  9438. #define OV5693_PIXEL_ARRAY_HEIGHT 1944U
  9439. -static int vcm_ad_i2c_wr8(struct i2c_client *client, u8 reg, u8 val)
  9440. -{
  9441. - int err;
  9442. - struct i2c_msg msg;
  9443. - u8 buf[2];
  9444. -
  9445. - buf[0] = reg;
  9446. - buf[1] = val;
  9447. -
  9448. - msg.addr = VCM_ADDR;
  9449. - msg.flags = 0;
  9450. - msg.len = 2;
  9451. - msg.buf = &buf[0];
  9452. -
  9453. - err = i2c_transfer(client->adapter, &msg, 1);
  9454. - if (err != 1) {
  9455. - dev_err(&client->dev, "%s: vcm i2c fail, err code = %d\n",
  9456. - __func__, err);
  9457. - return -EIO;
  9458. - }
  9459. - return 0;
  9460. -}
  9461. -
  9462. -static int ad5823_i2c_write(struct i2c_client *client, u8 reg, u8 val)
  9463. -{
  9464. - struct i2c_msg msg;
  9465. - u8 buf[2];
  9466. -
  9467. - buf[0] = reg;
  9468. - buf[1] = val;
  9469. - msg.addr = AD5823_VCM_ADDR;
  9470. - msg.flags = 0;
  9471. - msg.len = 0x02;
  9472. - msg.buf = &buf[0];
  9473. -
  9474. - if (i2c_transfer(client->adapter, &msg, 1) != 1)
  9475. - return -EIO;
  9476. - return 0;
  9477. -}
  9478. -
  9479. -static int ad5823_i2c_read(struct i2c_client *client, u8 reg, u8 *val)
  9480. -{
  9481. - struct i2c_msg msg[2];
  9482. - u8 buf[2];
  9483. -
  9484. - buf[0] = reg;
  9485. - buf[1] = 0;
  9486. -
  9487. - msg[0].addr = AD5823_VCM_ADDR;
  9488. - msg[0].flags = 0;
  9489. - msg[0].len = 0x01;
  9490. - msg[0].buf = &buf[0];
  9491. -
  9492. - msg[1].addr = 0x0c;
  9493. - msg[1].flags = I2C_M_RD;
  9494. - msg[1].len = 0x01;
  9495. - msg[1].buf = &buf[1];
  9496. - *val = 0;
  9497. - if (i2c_transfer(client->adapter, msg, 2) != 2)
  9498. - return -EIO;
  9499. - *val = buf[1];
  9500. - return 0;
  9501. -}
  9502. -
  9503. -static const u32 ov5693_embedded_effective_size = 28;
  9504. -
  9505. /* i2c read/write stuff */
  9506. static int ov5693_read_reg(struct i2c_client *client,
  9507. u16 data_length, u16 reg, u16 *val)
  9508. @@ -215,69 +149,6 @@ static int ov5693_i2c_write(struct i2c_client *client, u16 len, u8 *data)
  9509. return ret == num_msg ? 0 : -EIO;
  9510. }
  9511. -static int vcm_dw_i2c_write(struct i2c_client *client, u16 data)
  9512. -{
  9513. - struct i2c_msg msg;
  9514. - const int num_msg = 1;
  9515. - int ret;
  9516. - __be16 val;
  9517. -
  9518. - val = cpu_to_be16(data);
  9519. - msg.addr = VCM_ADDR;
  9520. - msg.flags = 0;
  9521. - msg.len = OV5693_16BIT;
  9522. - msg.buf = (void *)&val;
  9523. -
  9524. - ret = i2c_transfer(client->adapter, &msg, 1);
  9525. -
  9526. - return ret == num_msg ? 0 : -EIO;
  9527. -}
  9528. -
  9529. -/*
  9530. - * Theory: per datasheet, the two VCMs both allow for a 2-byte read.
  9531. - * The DW9714 doesn't actually specify what this does (it has a
  9532. - * two-byte write-only protocol, but specifies the read sequence as
  9533. - * legal), but it returns the same data (zeroes) always, after an
  9534. - * undocumented initial NAK. The AD5823 has a one-byte address
  9535. - * register to which all writes go, and subsequent reads will cycle
  9536. - * through the 8 bytes of registers. Notably, the default values (the
  9537. - * device is always power-cycled affirmatively, so we can rely on
  9538. - * these) in AD5823 are not pairwise repetitions of the same 16 bit
  9539. - * word. So all we have to do is sequentially read two bytes at a
  9540. - * time and see if we detect a difference in any of the first four
  9541. - * pairs.
  9542. - */
  9543. -static int vcm_detect(struct i2c_client *client)
  9544. -{
  9545. - int i, ret;
  9546. - struct i2c_msg msg;
  9547. - u16 data0 = 0, data;
  9548. -
  9549. - for (i = 0; i < 4; i++) {
  9550. - msg.addr = VCM_ADDR;
  9551. - msg.flags = I2C_M_RD;
  9552. - msg.len = sizeof(data);
  9553. - msg.buf = (u8 *)&data;
  9554. - ret = i2c_transfer(client->adapter, &msg, 1);
  9555. -
  9556. - /*
  9557. - * DW9714 always fails the first read and returns
  9558. - * zeroes for subsequent ones
  9559. - */
  9560. - if (i == 0 && ret == -EREMOTEIO) {
  9561. - data0 = 0;
  9562. - continue;
  9563. - }
  9564. -
  9565. - if (i == 0)
  9566. - data0 = data;
  9567. -
  9568. - if (data != data0)
  9569. - return VCM_AD5823;
  9570. - }
  9571. - return ret == 1 ? VCM_DW9714 : ret;
  9572. -}
  9573. -
  9574. static int ov5693_write_reg(struct i2c_client *client, u16 data_length,
  9575. u16 reg, u16 val)
  9576. {
  9577. @@ -654,89 +525,6 @@ static int ov5693_q_exposure(struct v4l2_subdev *sd, s32 *value)
  9578. return ret;
  9579. }
  9580. -static int ad5823_t_focus_vcm(struct v4l2_subdev *sd, u16 val)
  9581. -{
  9582. - struct i2c_client *client = v4l2_get_subdevdata(sd);
  9583. - int ret = -EINVAL;
  9584. - u8 vcm_code;
  9585. -
  9586. - ret = ad5823_i2c_read(client, AD5823_REG_VCM_CODE_MSB, &vcm_code);
  9587. - if (ret)
  9588. - return ret;
  9589. -
  9590. - /* set reg VCM_CODE_MSB Bit[1:0] */
  9591. - vcm_code = (vcm_code & VCM_CODE_MSB_MASK) |
  9592. - ((val >> 8) & ~VCM_CODE_MSB_MASK);
  9593. - ret = ad5823_i2c_write(client, AD5823_REG_VCM_CODE_MSB, vcm_code);
  9594. - if (ret)
  9595. - return ret;
  9596. -
  9597. - /* set reg VCM_CODE_LSB Bit[7:0] */
  9598. - ret = ad5823_i2c_write(client, AD5823_REG_VCM_CODE_LSB, (val & 0xff));
  9599. - if (ret)
  9600. - return ret;
  9601. -
  9602. - /* set required vcm move time */
  9603. - vcm_code = AD5823_RESONANCE_PERIOD / AD5823_RESONANCE_COEF
  9604. - - AD5823_HIGH_FREQ_RANGE;
  9605. - ret = ad5823_i2c_write(client, AD5823_REG_VCM_MOVE_TIME, vcm_code);
  9606. -
  9607. - return ret;
  9608. -}
  9609. -
  9610. -static int ad5823_t_focus_abs(struct v4l2_subdev *sd, s32 value)
  9611. -{
  9612. - value = min(value, AD5823_MAX_FOCUS_POS);
  9613. - return ad5823_t_focus_vcm(sd, value);
  9614. -}
  9615. -
  9616. -static int ov5693_t_focus_abs(struct v4l2_subdev *sd, s32 value)
  9617. -{
  9618. - struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  9619. - struct i2c_client *client = v4l2_get_subdevdata(sd);
  9620. - int ret = 0;
  9621. -
  9622. - dev_dbg(&client->dev, "%s: FOCUS_POS: 0x%x\n", __func__, value);
  9623. - value = clamp(value, 0, OV5693_VCM_MAX_FOCUS_POS);
  9624. - if (ov5693->vcm == VCM_DW9714) {
  9625. - if (ov5693->vcm_update) {
  9626. - ret = vcm_dw_i2c_write(client, VCM_PROTECTION_OFF);
  9627. - if (ret)
  9628. - return ret;
  9629. - ret = vcm_dw_i2c_write(client, DIRECT_VCM);
  9630. - if (ret)
  9631. - return ret;
  9632. - ret = vcm_dw_i2c_write(client, VCM_PROTECTION_ON);
  9633. - if (ret)
  9634. - return ret;
  9635. - ov5693->vcm_update = false;
  9636. - }
  9637. - ret = vcm_dw_i2c_write(client,
  9638. - vcm_val(value, VCM_DEFAULT_S));
  9639. - } else if (ov5693->vcm == VCM_AD5823) {
  9640. - ad5823_t_focus_abs(sd, value);
  9641. - }
  9642. - if (ret == 0) {
  9643. - ov5693->number_of_steps = value - ov5693->focus;
  9644. - ov5693->focus = value;
  9645. - ov5693->timestamp_t_focus_abs = ktime_get();
  9646. - } else
  9647. - dev_err(&client->dev,
  9648. - "%s: i2c failed. ret %d\n", __func__, ret);
  9649. -
  9650. - return ret;
  9651. -}
  9652. -
  9653. -static int ov5693_t_focus_rel(struct v4l2_subdev *sd, s32 value)
  9654. -{
  9655. - struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  9656. -
  9657. - return ov5693_t_focus_abs(sd, ov5693->focus + value);
  9658. -}
  9659. -
  9660. -#define DELAY_PER_STEP_NS 1000000
  9661. -#define DELAY_MAX_PER_STEP_NS (1000000 * 1023)
  9662. -
  9663. /* Exposure */
  9664. static int ov5693_get_exposure(struct ov5693_device *ov5693)
  9665. @@ -911,16 +699,6 @@ static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
  9666. return 0;
  9667. switch (ctrl->id) {
  9668. - case V4L2_CID_FOCUS_ABSOLUTE:
  9669. - dev_dbg(&client->dev, "%s: CID_FOCUS_ABSOLUTE:%d.\n",
  9670. - __func__, ctrl->val);
  9671. - ret = ov5693_t_focus_abs(&ov5693->sd, ctrl->val);
  9672. - break;
  9673. - case V4L2_CID_FOCUS_RELATIVE:
  9674. - dev_dbg(&client->dev, "%s: CID_FOCUS_RELATIVE:%d.\n",
  9675. - __func__, ctrl->val);
  9676. - ret = ov5693_t_focus_rel(&ov5693->sd, ctrl->val);
  9677. - break;
  9678. case V4L2_CID_EXPOSURE:
  9679. dev_dbg(&client->dev, "%s: CID_EXPOSURE:%d.\n",
  9680. __func__, ctrl->val);
  9681. @@ -983,90 +761,6 @@ static const struct v4l2_ctrl_ops ov5693_ctrl_ops = {
  9682. .g_volatile_ctrl = ov5693_g_volatile_ctrl
  9683. };
  9684. -static const struct v4l2_ctrl_config ov5693_controls[] = {
  9685. - {
  9686. - .ops = &ov5693_ctrl_ops,
  9687. - .id = V4L2_CID_FOCUS_ABSOLUTE,
  9688. - .type = V4L2_CTRL_TYPE_INTEGER,
  9689. - .name = "focus move absolute",
  9690. - .min = 0,
  9691. - .max = OV5693_VCM_MAX_FOCUS_POS,
  9692. - .step = 1,
  9693. - .def = 0,
  9694. - .flags = 0,
  9695. - },
  9696. - {
  9697. - .ops = &ov5693_ctrl_ops,
  9698. - .id = V4L2_CID_FOCUS_RELATIVE,
  9699. - .type = V4L2_CTRL_TYPE_INTEGER,
  9700. - .name = "focus move relative",
  9701. - .min = OV5693_VCM_MAX_FOCUS_NEG,
  9702. - .max = OV5693_VCM_MAX_FOCUS_POS,
  9703. - .step = 1,
  9704. - .def = 0,
  9705. - .flags = 0,
  9706. - },
  9707. -};
  9708. -
  9709. -static int ov5693_isp_configure(struct ov5693_device *ov5693)
  9710. -{
  9711. - int ret;
  9712. -
  9713. - /* Enable lens correction. */
  9714. - ret = ov5693_write_reg(ov5693->client, OV5693_8BIT,
  9715. - OV5693_ISP_CTRL0_REG, 0x86);
  9716. - if (ret)
  9717. - return ret;
  9718. -
  9719. - return 0;
  9720. -}
  9721. -
  9722. -static int ov5693_init(struct v4l2_subdev *sd)
  9723. -{
  9724. - struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  9725. - struct i2c_client *client = v4l2_get_subdevdata(sd);
  9726. - int ret;
  9727. -
  9728. - if (!ov5693->has_vcm)
  9729. - return 0;
  9730. -
  9731. - dev_info(&client->dev, "%s\n", __func__);
  9732. - mutex_lock(&ov5693->lock);
  9733. - ov5693->vcm_update = false;
  9734. -
  9735. - if (ov5693->vcm == VCM_AD5823) {
  9736. - ret = vcm_ad_i2c_wr8(client, 0x01, 0x01); /* vcm init test */
  9737. - if (ret)
  9738. - dev_err(&client->dev,
  9739. - "vcm reset failed\n");
  9740. - /*change the mode*/
  9741. - ret = ad5823_i2c_write(client, AD5823_REG_VCM_CODE_MSB,
  9742. - AD5823_RING_CTRL_ENABLE);
  9743. - if (ret)
  9744. - dev_err(&client->dev,
  9745. - "vcm enable ringing failed\n");
  9746. - ret = ad5823_i2c_write(client, AD5823_REG_MODE,
  9747. - AD5823_ARC_RES1);
  9748. - if (ret)
  9749. - dev_err(&client->dev,
  9750. - "vcm change mode failed\n");
  9751. - }
  9752. -
  9753. - /*change initial focus value for ad5823*/
  9754. - if (ov5693->vcm == VCM_AD5823) {
  9755. - ov5693->focus = AD5823_INIT_FOCUS_POS;
  9756. - ov5693_t_focus_abs(sd, AD5823_INIT_FOCUS_POS);
  9757. - } else {
  9758. - ov5693->focus = 0;
  9759. - ov5693_t_focus_abs(sd, 0);
  9760. - }
  9761. -
  9762. - ov5693_isp_configure(ov5693);
  9763. - mutex_unlock(&ov5693->lock);
  9764. -
  9765. - return 0;
  9766. -}
  9767. -
  9768. static int ov5693_sw_standby(struct ov5693_device *ov5693, bool standby)
  9769. {
  9770. return ov5693_write_reg(ov5693->client, OV5693_8BIT, OV5693_SW_STREAM,
  9771. @@ -1327,9 +1021,6 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd,
  9772. continue;
  9773. }
  9774. - mutex_unlock(&ov5693->lock);
  9775. - ov5693_init(sd);
  9776. - mutex_lock(&ov5693->lock);
  9777. ret = startup(sd);
  9778. if (ret)
  9779. dev_err(&client->dev, " startup() FAILED!\n");
  9780. @@ -1507,9 +1198,6 @@ static int ov5693_s_config(struct v4l2_subdev *sd, int irq)
  9781. goto fail_power_on;
  9782. }
  9783. - if (!ov5693->vcm)
  9784. - ov5693->vcm = vcm_detect(client);
  9785. -
  9786. /* config & detect sensor */
  9787. ret = ov5693_detect(client);
  9788. if (ret) {
  9789. @@ -1617,24 +1305,17 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  9790. struct i2c_client *client = v4l2_get_subdevdata(&ov5693->sd);
  9791. const struct v4l2_ctrl_ops *ops = &ov5693_ctrl_ops;
  9792. struct v4l2_fwnode_device_properties props;
  9793. - unsigned int i;
  9794. int ret;
  9795. int hblank;
  9796. int vblank_max, vblank_min, vblank_def;
  9797. int exposure_max;
  9798. - ret = v4l2_ctrl_handler_init(&ov5693->ctrl_handler,
  9799. - ARRAY_SIZE(ov5693_controls));
  9800. + ret = v4l2_ctrl_handler_init(&ov5693->ctrl_handler, 8);
  9801. if (ret) {
  9802. ov5693_remove(client);
  9803. return ret;
  9804. }
  9805. - for (i = 0; i < ARRAY_SIZE(ov5693_controls); i++)
  9806. - v4l2_ctrl_new_custom(&ov5693->ctrl_handler,
  9807. - &ov5693_controls[i],
  9808. - NULL);
  9809. -
  9810. /* link freq */
  9811. ov5693->ctrls.link_freq = v4l2_ctrl_new_int_menu(&ov5693->ctrl_handler,
  9812. NULL, V4L2_CID_LINK_FREQ,
  9813. @@ -1766,10 +1447,6 @@ static int ov5693_probe(struct i2c_client *client)
  9814. ov5693->client = client;
  9815. - /* check if VCM device exists */
  9816. - /* TODO: read from SSDB */
  9817. - ov5693->has_vcm = false;
  9818. -
  9819. mutex_init(&ov5693->lock);
  9820. v4l2_i2c_subdev_init(&ov5693->sd, client, &ov5693_ops);
  9821. --
  9822. 2.33.0
  9823. From b52dadcfd79b26724cf0dee8c22649dffbc766a9 Mon Sep 17 00:00:00 2001
  9824. From: Daniel Scally <djrscally@gmail.com>
  9825. Date: Sat, 13 Feb 2021 22:16:08 +0000
  9826. Subject: [PATCH] media: i2c: Tidy up ov5693 sensor init
  9827. The initialisation of a mode when the sensor is activated is a bit messy,
  9828. so lets tidy that up a bit to bring it in line with other drivers.
  9829. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  9830. Patchset: cameras
  9831. ---
  9832. drivers/media/i2c/ov5693.c | 100 ++++++++++++++++---------------------
  9833. 1 file changed, 42 insertions(+), 58 deletions(-)
  9834. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  9835. index 2c82b6578de9..313bc9177328 100644
  9836. --- a/drivers/media/i2c/ov5693.c
  9837. +++ b/drivers/media/i2c/ov5693.c
  9838. @@ -767,6 +767,42 @@ static int ov5693_sw_standby(struct ov5693_device *ov5693, bool standby)
  9839. standby ? OV5693_STOP_STREAMING : OV5693_START_STREAMING);
  9840. }
  9841. +static int ov5693_sw_reset(struct ov5693_device *ov5693)
  9842. +{
  9843. + return ov5693_write_reg(ov5693->client, OV5693_8BIT, OV5693_SW_RESET,
  9844. + 0x01);
  9845. +}
  9846. +
  9847. +static int ov5693_sensor_init(struct ov5693_device *ov5693)
  9848. +{
  9849. + struct i2c_client *client = ov5693->client;
  9850. + int ret = 0;
  9851. +
  9852. + ret = ov5693_sw_reset(ov5693);
  9853. + if (ret) {
  9854. + dev_err(&client->dev, "ov5693 reset err.\n");
  9855. + return ret;
  9856. + }
  9857. +
  9858. + ret = ov5693_write_reg_array(client, ov5693_global_setting);
  9859. + if (ret) {
  9860. + dev_err(&client->dev, "ov5693 write register err.\n");
  9861. + return ret;
  9862. + }
  9863. +
  9864. + ret = ov5693_write_reg_array(client, ov5693_res[ov5693->fmt_idx].regs);
  9865. + if (ret) {
  9866. + dev_err(&client->dev, "ov5693 write register err.\n");
  9867. + return ret;
  9868. + }
  9869. +
  9870. + ret = ov5693_sw_standby(ov5693, true);
  9871. + if (ret)
  9872. + dev_err(&client->dev, "ov5693 stream off error\n");
  9873. +
  9874. + return ret;
  9875. +}
  9876. +
  9877. static void ov5693_sensor_powerdown(struct ov5693_device *ov5693)
  9878. {
  9879. gpiod_set_value_cansleep(ov5693->reset, 1);
  9880. @@ -846,6 +882,12 @@ static int __maybe_unused ov5693_sensor_resume(struct device *dev)
  9881. if (ret)
  9882. goto out_unlock;
  9883. + ret = ov5693_sensor_init(ov5693);
  9884. + if (ret) {
  9885. + dev_err(&client->dev, "ov5693 sensor init failure\n");
  9886. + goto err_power;
  9887. + }
  9888. +
  9889. if (ov5693->streaming) {
  9890. ret = ov5693_sw_standby(ov5693, false);
  9891. if (ret)
  9892. @@ -944,35 +986,6 @@ static int get_resolution_index(int w, int h)
  9893. return -1;
  9894. }
  9895. -/* TODO: remove it. */
  9896. -static int startup(struct v4l2_subdev *sd)
  9897. -{
  9898. - struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  9899. - struct i2c_client *client = v4l2_get_subdevdata(sd);
  9900. - int ret = 0;
  9901. -
  9902. - ret = ov5693_write_reg(client, OV5693_8BIT,
  9903. - OV5693_SW_RESET, 0x01);
  9904. - if (ret) {
  9905. - dev_err(&client->dev, "ov5693 reset err.\n");
  9906. - return ret;
  9907. - }
  9908. -
  9909. - ret = ov5693_write_reg_array(client, ov5693_global_setting);
  9910. - if (ret) {
  9911. - dev_err(&client->dev, "ov5693 write register err.\n");
  9912. - return ret;
  9913. - }
  9914. -
  9915. - ret = ov5693_write_reg_array(client, ov5693_res[ov5693->fmt_idx].regs);
  9916. - if (ret) {
  9917. - dev_err(&client->dev, "ov5693 write register err.\n");
  9918. - return ret;
  9919. - }
  9920. -
  9921. - return ret;
  9922. -}
  9923. -
  9924. static int ov5693_set_fmt(struct v4l2_subdev *sd,
  9925. struct v4l2_subdev_pad_config *cfg,
  9926. struct v4l2_subdev_format *format)
  9927. @@ -982,7 +995,6 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd,
  9928. struct i2c_client *client = v4l2_get_subdevdata(sd);
  9929. int ret = 0;
  9930. int idx;
  9931. - int cnt;
  9932. if (format->pad)
  9933. return -EINVAL;
  9934. @@ -1014,34 +1026,6 @@ static int ov5693_set_fmt(struct v4l2_subdev *sd,
  9935. goto mutex_unlock;
  9936. }
  9937. - for (cnt = 0; cnt < OV5693_POWER_UP_RETRY_NUM; cnt++) {
  9938. - ret = ov5693_sensor_powerup(ov5693);
  9939. - if (ret) {
  9940. - dev_err(&client->dev, "power up failed\n");
  9941. - continue;
  9942. - }
  9943. -
  9944. - ret = startup(sd);
  9945. - if (ret)
  9946. - dev_err(&client->dev, " startup() FAILED!\n");
  9947. - else
  9948. - break;
  9949. - }
  9950. - if (cnt == OV5693_POWER_UP_RETRY_NUM) {
  9951. - dev_err(&client->dev, "power up failed, gave up\n");
  9952. - goto mutex_unlock;
  9953. - }
  9954. -
  9955. - /*
  9956. - * After sensor settings are set to HW, sometimes stream is started.
  9957. - * This would cause ISP timeout because ISP is not ready to receive
  9958. - * data yet. So add stop streaming here.
  9959. - */
  9960. - ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_SW_STREAM,
  9961. - OV5693_STOP_STREAMING);
  9962. - if (ret)
  9963. - dev_warn(&client->dev, "ov5693 stream off err\n");
  9964. -
  9965. mutex_unlock:
  9966. mutex_unlock(&ov5693->lock);
  9967. return ret;
  9968. --
  9969. 2.33.0
  9970. From b0e47f06039b2b73908b044681c9d311edf1fe5e Mon Sep 17 00:00:00 2001
  9971. From: Daniel Scally <djrscally@gmail.com>
  9972. Date: Fri, 12 Feb 2021 16:14:04 +0000
  9973. Subject: [PATCH] media: i2c: cleanup macros in ov5693.h
  9974. Lots of orphaned or duplicated macros in this header file. Clean
  9975. those up a bit so it's less ugly.
  9976. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  9977. Patchset: cameras
  9978. ---
  9979. drivers/media/i2c/ov5693.h | 89 +-------------------------------------
  9980. 1 file changed, 2 insertions(+), 87 deletions(-)
  9981. diff --git a/drivers/media/i2c/ov5693.h b/drivers/media/i2c/ov5693.h
  9982. index b78d3b474a43..6502777eb5f3 100644
  9983. --- a/drivers/media/i2c/ov5693.h
  9984. +++ b/drivers/media/i2c/ov5693.h
  9985. @@ -37,68 +37,23 @@
  9986. */
  9987. #define ENABLE_NON_PREVIEW 1
  9988. -#define OV5693_POWER_UP_RETRY_NUM 5
  9989. -
  9990. /* Defines for register writes and register array processing */
  9991. -#define I2C_MSG_LENGTH 0x2
  9992. -#define I2C_RETRY_COUNT 5
  9993. -
  9994. -#define OV5693_FOCAL_LENGTH_NUM 334 /*3.34mm*/
  9995. -#define OV5693_FOCAL_LENGTH_DEM 100
  9996. -#define OV5693_F_NUMBER_DEFAULT_NUM 24
  9997. -#define OV5693_F_NUMBER_DEM 10
  9998. +#define I2C_MSG_LENGTH 0x2
  9999. #define MAX_FMTS 1
  10000. -/* sensor_mode_data read_mode adaptation */
  10001. -#define OV5693_READ_MODE_BINNING_ON 0x0400
  10002. -#define OV5693_READ_MODE_BINNING_OFF 0x00
  10003. -#define OV5693_INTEGRATION_TIME_MARGIN 8
  10004. -
  10005. -#define OV5693_MAX_EXPOSURE_VALUE 0xFFF1
  10006. -#define OV5693_MAX_GAIN_VALUE 0xFF
  10007. -
  10008. -/*
  10009. - * focal length bits definition:
  10010. - * bits 31-16: numerator, bits 15-0: denominator
  10011. - */
  10012. -#define OV5693_FOCAL_LENGTH_DEFAULT 0x1B70064
  10013. -
  10014. -/*
  10015. - * current f-number bits definition:
  10016. - * bits 31-16: numerator, bits 15-0: denominator
  10017. - */
  10018. -#define OV5693_F_NUMBER_DEFAULT 0x18000a
  10019. -
  10020. -/*
  10021. - * f-number range bits definition:
  10022. - * bits 31-24: max f-number numerator
  10023. - * bits 23-16: max f-number denominator
  10024. - * bits 15-8: min f-number numerator
  10025. - * bits 7-0: min f-number denominator
  10026. - */
  10027. -#define OV5693_F_NUMBER_RANGE 0x180a180a
  10028. #define OV5693_ID 0x5690
  10029. -#define OV5693_FINE_INTG_TIME_MIN 0
  10030. -#define OV5693_FINE_INTG_TIME_MAX_MARGIN 0
  10031. -#define OV5693_COARSE_INTG_TIME_MIN 1
  10032. -#define OV5693_COARSE_INTG_TIME_MAX_MARGIN 6
  10033. -
  10034. -#define OV5693_BIN_FACTOR_MAX 4
  10035. /*
  10036. * OV5693 System control registers
  10037. */
  10038. -#define OV5693_SW_SLEEP 0x0100
  10039. #define OV5693_SW_RESET 0x0103
  10040. #define OV5693_SW_STREAM 0x0100
  10041. #define OV5693_SC_CMMN_CHIP_ID_H 0x300A
  10042. #define OV5693_SC_CMMN_CHIP_ID_L 0x300B
  10043. -#define OV5693_SC_CMMN_SCCB_ID 0x300C
  10044. #define OV5693_SC_CMMN_SUB_ID 0x302A /* process, version*/
  10045. -/*Bit[7:4] Group control, Bit[3:0] Group ID*/
  10046. -#define OV5693_GROUP_ACCESS 0x3208
  10047. +
  10048. /*
  10049. *Bit[3:0] Bit[19:16] of exposure,
  10050. *remaining 16 bits lies in Reg0x3501&Reg0x3502
  10051. @@ -110,18 +65,6 @@
  10052. #define OV5693_AGC_H 0x350A
  10053. #define OV5693_AGC_L 0x350B /*Bit[7:0] of gain*/
  10054. -#define OV5693_HORIZONTAL_START_H 0x3800 /*Bit[11:8]*/
  10055. -#define OV5693_HORIZONTAL_START_L 0x3801 /*Bit[7:0]*/
  10056. -#define OV5693_VERTICAL_START_H 0x3802 /*Bit[11:8]*/
  10057. -#define OV5693_VERTICAL_START_L 0x3803 /*Bit[7:0]*/
  10058. -#define OV5693_HORIZONTAL_END_H 0x3804 /*Bit[11:8]*/
  10059. -#define OV5693_HORIZONTAL_END_L 0x3805 /*Bit[7:0]*/
  10060. -#define OV5693_VERTICAL_END_H 0x3806 /*Bit[11:8]*/
  10061. -#define OV5693_VERTICAL_END_L 0x3807 /*Bit[7:0]*/
  10062. -#define OV5693_HORIZONTAL_OUTPUT_SIZE_H 0x3808 /*Bit[3:0]*/
  10063. -#define OV5693_HORIZONTAL_OUTPUT_SIZE_L 0x3809 /*Bit[7:0]*/
  10064. -#define OV5693_VERTICAL_OUTPUT_SIZE_H 0x380a /*Bit[3:0]*/
  10065. -#define OV5693_VERTICAL_OUTPUT_SIZE_L 0x380b /*Bit[7:0]*/
  10066. /*High 8-bit, and low 8-bit HTS address is 0x380d*/
  10067. #define OV5693_TIMING_HTS_H 0x380C
  10068. /*High 8-bit, and low 8-bit HTS address is 0x380d*/
  10069. @@ -141,34 +84,6 @@
  10070. #define OV5693_START_STREAMING 0x01
  10071. #define OV5693_STOP_STREAMING 0x00
  10072. -#define VCM_ADDR 0x0c
  10073. -#define VCM_CODE_MSB 0x04
  10074. -
  10075. -#define OV5693_INVALID_CONFIG 0xffffffff
  10076. -
  10077. -#define OV5693_VCM_SLEW_STEP 0x30F0
  10078. -#define OV5693_VCM_SLEW_STEP_MAX 0x7
  10079. -#define OV5693_VCM_SLEW_STEP_MASK 0x7
  10080. -#define OV5693_VCM_CODE 0x30F2
  10081. -#define OV5693_VCM_SLEW_TIME 0x30F4
  10082. -#define OV5693_VCM_SLEW_TIME_MAX 0xffff
  10083. -#define OV5693_VCM_ENABLE 0x8000
  10084. -
  10085. -#define OV5693_VCM_MAX_FOCUS_NEG -1023
  10086. -#define OV5693_VCM_MAX_FOCUS_POS 1023
  10087. -
  10088. -#define DLC_ENABLE 1
  10089. -#define DLC_DISABLE 0
  10090. -#define VCM_PROTECTION_OFF 0xeca3
  10091. -#define VCM_PROTECTION_ON 0xdc51
  10092. -#define VCM_DEFAULT_S 0x0
  10093. -#define vcm_step_s(a) (u8)(a & 0xf)
  10094. -#define vcm_step_mclk(a) (u8)((a >> 4) & 0x3)
  10095. -#define vcm_dlc_mclk(dlc, mclk) (u16)((dlc << 3) | mclk | 0xa104)
  10096. -#define vcm_tsrc(tsrc) (u16)(tsrc << 3 | 0xf200)
  10097. -#define vcm_val(data, s) (u16)(data << 4 | s)
  10098. -#define DIRECT_VCM vcm_dlc_mclk(0, 0)
  10099. -
  10100. /* Defines for OTP Data Registers */
  10101. #define OV5693_FRAME_OFF_NUM 0x4202
  10102. #define OV5693_OTP_BYTE_MAX 32 //change to 32 as needed by otpdata
  10103. --
  10104. 2.33.0
  10105. From 07688f98d5cf042a675581a0d50543379b280c18 Mon Sep 17 00:00:00 2001
  10106. From: Daniel Scally <djrscally@gmail.com>
  10107. Date: Fri, 12 Feb 2021 16:19:09 +0000
  10108. Subject: [PATCH] media: i2c: use devm_kzalloc() to initialise ov5693
  10109. There's a memory leak in probe because we're not using devres; swtich
  10110. so that we are.
  10111. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  10112. Patchset: cameras
  10113. ---
  10114. drivers/media/i2c/ov5693.c | 2 +-
  10115. 1 file changed, 1 insertion(+), 1 deletion(-)
  10116. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  10117. index 313bc9177328..d092ed698eb3 100644
  10118. --- a/drivers/media/i2c/ov5693.c
  10119. +++ b/drivers/media/i2c/ov5693.c
  10120. @@ -1425,7 +1425,7 @@ static int ov5693_probe(struct i2c_client *client)
  10121. dev_info(&client->dev, "%s() called", __func__);
  10122. - ov5693 = kzalloc(sizeof(*ov5693), GFP_KERNEL);
  10123. + ov5693 = devm_kzalloc(&client->dev, sizeof(*ov5693), GFP_KERNEL);
  10124. if (!ov5693)
  10125. return -ENOMEM;
  10126. --
  10127. 2.33.0
  10128. From 227f50c100aa3939be34d4cee2b2eaedd8e6eb32 Mon Sep 17 00:00:00 2001
  10129. From: Daniel Scally <djrscally@gmail.com>
  10130. Date: Fri, 12 Feb 2021 16:26:21 +0000
  10131. Subject: [PATCH] media: i2c: Check for supported clk rate in probe
  10132. The ov5693 driver is configured to support a 19.2MHz external clock only.
  10133. Check that we do indeed have that value and if not, exit with -EINVAL.
  10134. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  10135. Patchset: cameras
  10136. ---
  10137. drivers/media/i2c/ov5693.c | 8 ++++++++
  10138. drivers/media/i2c/ov5693.h | 2 ++
  10139. 2 files changed, 10 insertions(+)
  10140. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  10141. index d092ed698eb3..8082d37841da 100644
  10142. --- a/drivers/media/i2c/ov5693.c
  10143. +++ b/drivers/media/i2c/ov5693.c
  10144. @@ -1421,6 +1421,7 @@ static int ov5693_get_regulators(struct ov5693_device *ov5693)
  10145. static int ov5693_probe(struct i2c_client *client)
  10146. {
  10147. struct ov5693_device *ov5693;
  10148. + u32 clk_rate;
  10149. int ret = 0;
  10150. dev_info(&client->dev, "%s() called", __func__);
  10151. @@ -1441,6 +1442,13 @@ static int ov5693_probe(struct i2c_client *client)
  10152. return -EINVAL;
  10153. }
  10154. + clk_rate = clk_get_rate(ov5693->clk);
  10155. + if (clk_rate != OV5693_XVCLK_FREQ) {
  10156. + dev_err(&client->dev, "Unsupported clk freq %u, expected %u\n",
  10157. + clk_rate, OV5693_XVCLK_FREQ);
  10158. + return -EINVAL;
  10159. + }
  10160. +
  10161. ret = ov5693_configure_gpios(ov5693);
  10162. if (ret)
  10163. goto out_free;
  10164. diff --git a/drivers/media/i2c/ov5693.h b/drivers/media/i2c/ov5693.h
  10165. index 6502777eb5f3..0dfbbe9a0ff2 100644
  10166. --- a/drivers/media/i2c/ov5693.h
  10167. +++ b/drivers/media/i2c/ov5693.h
  10168. @@ -100,6 +100,8 @@
  10169. #define OV5693_OTP_READ_ONETIME 16
  10170. #define OV5693_OTP_MODE_READ 1
  10171. +#define OV5693_XVCLK_FREQ 19200000
  10172. +
  10173. /* link freq and pixel rate required for IPU3 */
  10174. #define OV5693_LINK_FREQ_400MHZ 400000000
  10175. /* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample
  10176. --
  10177. 2.33.0
  10178. From 5a0cbf1fec50b3cbcf2ffdfedb8a28c00f15310a Mon Sep 17 00:00:00 2001
  10179. From: Daniel Scally <djrscally@gmail.com>
  10180. Date: Sat, 13 Feb 2021 23:17:50 +0000
  10181. Subject: [PATCH] media: i2c: Use devres to fetch gpios
  10182. Use devres; it'll simplify error handling through this function
  10183. and probe.
  10184. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  10185. Patchset: cameras
  10186. ---
  10187. drivers/media/i2c/ov5693.c | 22 +++++-----------------
  10188. 1 file changed, 5 insertions(+), 17 deletions(-)
  10189. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  10190. index 8082d37841da..c580159079d2 100644
  10191. --- a/drivers/media/i2c/ov5693.c
  10192. +++ b/drivers/media/i2c/ov5693.c
  10193. @@ -1270,8 +1270,6 @@ static int ov5693_remove(struct i2c_client *client)
  10194. dev_info(&client->dev, "%s...\n", __func__);
  10195. - gpiod_put(ov5693->reset);
  10196. - gpiod_put(ov5693->indicator_led);
  10197. while (i--)
  10198. regulator_put(ov5693->supplies[i].consumer);
  10199. @@ -1372,38 +1370,28 @@ static int ov5693_init_controls(struct ov5693_device *ov5693)
  10200. static int ov5693_configure_gpios(struct ov5693_device *ov5693)
  10201. {
  10202. - int ret;
  10203. -
  10204. - ov5693->reset = gpiod_get_optional(&ov5693->client->dev, "reset",
  10205. + ov5693->reset = devm_gpiod_get_optional(&ov5693->client->dev, "reset",
  10206. GPIOD_OUT_HIGH);
  10207. if (IS_ERR(ov5693->reset)) {
  10208. dev_err(&ov5693->client->dev, "Couldn't find reset GPIO\n");
  10209. return PTR_ERR(ov5693->reset);
  10210. }
  10211. - ov5693->powerdown = gpiod_get_optional(&ov5693->client->dev, "powerdown",
  10212. + ov5693->powerdown = devm_gpiod_get_optional(&ov5693->client->dev, "powerdown",
  10213. GPIOD_OUT_HIGH);
  10214. if (IS_ERR(ov5693->powerdown)) {
  10215. dev_err(&ov5693->client->dev, "Couldn't find powerdown GPIO\n");
  10216. - ret = PTR_ERR(ov5693->powerdown);
  10217. - goto err_put_reset;
  10218. + return PTR_ERR(ov5693->powerdown);
  10219. }
  10220. - ov5693->indicator_led = gpiod_get_optional(&ov5693->client->dev, "indicator-led",
  10221. + ov5693->indicator_led = devm_gpiod_get_optional(&ov5693->client->dev, "indicator-led",
  10222. GPIOD_OUT_HIGH);
  10223. if (IS_ERR(ov5693->indicator_led)) {
  10224. dev_err(&ov5693->client->dev, "Couldn't find indicator-led GPIO\n");
  10225. - ret = PTR_ERR(ov5693->indicator_led);
  10226. - goto err_put_powerdown;
  10227. + return PTR_ERR(ov5693->indicator_led);
  10228. }
  10229. return 0;
  10230. -err_put_reset:
  10231. - gpiod_put(ov5693->reset);
  10232. -err_put_powerdown:
  10233. - gpiod_put(ov5693->powerdown);
  10234. -
  10235. - return ret;
  10236. }
  10237. static int ov5693_get_regulators(struct ov5693_device *ov5693)
  10238. --
  10239. 2.33.0
  10240. From fb99f6001c7ffec79ece7a941fbc9b85acd9e180 Mon Sep 17 00:00:00 2001
  10241. From: Daniel Scally <djrscally@gmail.com>
  10242. Date: Sat, 13 Feb 2021 23:20:47 +0000
  10243. Subject: [PATCH] media: i2c: Use devres to fetch regulators
  10244. As before, use devres to simplify error handling and driver removal
  10245. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  10246. Patchset: cameras
  10247. ---
  10248. drivers/media/i2c/ov5693.c | 6 +-----
  10249. 1 file changed, 1 insertion(+), 5 deletions(-)
  10250. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  10251. index c580159079d2..9f61b470f8ba 100644
  10252. --- a/drivers/media/i2c/ov5693.c
  10253. +++ b/drivers/media/i2c/ov5693.c
  10254. @@ -1266,13 +1266,9 @@ static int ov5693_remove(struct i2c_client *client)
  10255. {
  10256. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  10257. struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  10258. - unsigned int i = OV5693_NUM_SUPPLIES;
  10259. dev_info(&client->dev, "%s...\n", __func__);
  10260. - while (i--)
  10261. - regulator_put(ov5693->supplies[i].consumer);
  10262. -
  10263. v4l2_async_unregister_subdev(sd);
  10264. media_entity_cleanup(&ov5693->sd.entity);
  10265. @@ -1401,7 +1397,7 @@ static int ov5693_get_regulators(struct ov5693_device *ov5693)
  10266. for (i = 0; i < OV5693_NUM_SUPPLIES; i++)
  10267. ov5693->supplies[i].supply = ov5693_supply_names[i];
  10268. - return regulator_bulk_get(&ov5693->client->dev,
  10269. + return devm_regulator_bulk_get(&ov5693->client->dev,
  10270. OV5693_NUM_SUPPLIES,
  10271. ov5693->supplies);
  10272. }
  10273. --
  10274. 2.33.0
  10275. From 89bcec14cf2e9d0ee4dc3938bda2cb8377007007 Mon Sep 17 00:00:00 2001
  10276. From: Daniel Scally <djrscally@gmail.com>
  10277. Date: Sun, 14 Feb 2021 12:39:14 +0000
  10278. Subject: [PATCH] media: i2c: remove debug print
  10279. The exposure configure function has a debug print. It's working fine,
  10280. so bin it.
  10281. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  10282. Patchset: cameras
  10283. ---
  10284. drivers/media/i2c/ov5693.c | 37 -------------------------------------
  10285. 1 file changed, 37 deletions(-)
  10286. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  10287. index 9f61b470f8ba..622a7ddf4063 100644
  10288. --- a/drivers/media/i2c/ov5693.c
  10289. +++ b/drivers/media/i2c/ov5693.c
  10290. @@ -526,41 +526,6 @@ static int ov5693_q_exposure(struct v4l2_subdev *sd, s32 *value)
  10291. }
  10292. /* Exposure */
  10293. -
  10294. -static int ov5693_get_exposure(struct ov5693_device *ov5693)
  10295. -{
  10296. - u32 exposure = 0;
  10297. - u16 tmp;
  10298. - int ret = 0;
  10299. -
  10300. - /* get exposure */
  10301. - ret = ov5693_read_reg(ov5693->client, OV5693_8BIT,
  10302. - OV5693_EXPOSURE_L,
  10303. - &tmp);
  10304. - if (ret)
  10305. - return ret;
  10306. -
  10307. - exposure |= ((tmp >> 4) & 0b1111);
  10308. -
  10309. - ret = ov5693_read_reg(ov5693->client, OV5693_8BIT,
  10310. - OV5693_EXPOSURE_M,
  10311. - &tmp);
  10312. - if (ret)
  10313. - return ret;
  10314. -
  10315. - exposure |= (tmp << 4);
  10316. - ret = ov5693_read_reg(ov5693->client, OV5693_8BIT,
  10317. - OV5693_EXPOSURE_H,
  10318. - &tmp);
  10319. - if (ret)
  10320. - return ret;
  10321. -
  10322. - exposure |= (tmp << 12);
  10323. -
  10324. - printk("exposure set to: %u\n", exposure);
  10325. - return ret;
  10326. -}
  10327. -
  10328. static int ov5693_exposure_configure(struct ov5693_device *ov5693, u32 exposure)
  10329. {
  10330. int ret;
  10331. @@ -571,7 +536,6 @@ static int ov5693_exposure_configure(struct ov5693_device *ov5693, u32 exposure)
  10332. */
  10333. exposure = exposure * 16;
  10334. - ov5693_get_exposure(ov5693);
  10335. ret = ov5693_write_reg(ov5693->client, OV5693_8BIT,
  10336. OV5693_EXPOSURE_CTRL_HH_REG, OV5693_EXPOSURE_CTRL_HH(exposure));
  10337. if (ret)
  10338. @@ -586,7 +550,6 @@ static int ov5693_exposure_configure(struct ov5693_device *ov5693, u32 exposure)
  10339. OV5693_EXPOSURE_CTRL_L_REG, OV5693_EXPOSURE_CTRL_L(exposure));
  10340. if (ret)
  10341. return ret;
  10342. - ov5693_get_exposure(ov5693);
  10343. return 0;
  10344. }
  10345. --
  10346. 2.33.0
  10347. From 20db0005a194231baa4b02dde2133631072add3c Mon Sep 17 00:00:00 2001
  10348. From: Daniel Scally <djrscally@gmail.com>
  10349. Date: Sun, 14 Feb 2021 14:32:50 +0000
  10350. Subject: [PATCH] media: i2c: Remove unused resolutions from ov5693
  10351. The list of resolutions in here is really unmaintanably long. For now just
  10352. bin all of the ones that are not part of ov5693_res_video, which is the
  10353. only array of resolutions in use anyway.
  10354. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  10355. Patchset: cameras
  10356. ---
  10357. drivers/media/i2c/ov5693.h | 357 +------------------------------------
  10358. 1 file changed, 1 insertion(+), 356 deletions(-)
  10359. diff --git a/drivers/media/i2c/ov5693.h b/drivers/media/i2c/ov5693.h
  10360. index 0dfbbe9a0ff2..29e6735112da 100644
  10361. --- a/drivers/media/i2c/ov5693.h
  10362. +++ b/drivers/media/i2c/ov5693.h
  10363. @@ -474,34 +474,7 @@ static struct ov5693_reg const ov5693_global_setting[] = {
  10364. };
  10365. #if ENABLE_NON_PREVIEW
  10366. -/*
  10367. - * 654x496 30fps 17ms VBlanking 2lane 10Bit (Scaling)
  10368. - */
  10369. -static struct ov5693_reg const ov5693_654x496[] = {
  10370. - {OV5693_8BIT, 0x3501, 0x3d},
  10371. - {OV5693_8BIT, 0x3502, 0x00},
  10372. - {OV5693_8BIT, 0x3708, 0xe6},
  10373. - {OV5693_8BIT, 0x3709, 0xc7},
  10374. - {OV5693_8BIT, 0x3803, 0x00},
  10375. - {OV5693_8BIT, 0x3806, 0x07},
  10376. - {OV5693_8BIT, 0x3807, 0xa3},
  10377. - {OV5693_8BIT, 0x3808, 0x02},
  10378. - {OV5693_8BIT, 0x3809, 0x90},
  10379. - {OV5693_8BIT, 0x380a, 0x01},
  10380. - {OV5693_8BIT, 0x380b, 0xf0},
  10381. - {OV5693_8BIT, 0x380c, 0x0a},
  10382. - {OV5693_8BIT, 0x380d, 0x80},
  10383. - {OV5693_8BIT, 0x380e, 0x07},
  10384. - {OV5693_8BIT, 0x380f, 0xc0},
  10385. - {OV5693_8BIT, 0x3811, 0x08},
  10386. - {OV5693_8BIT, 0x3813, 0x02},
  10387. - {OV5693_8BIT, 0x3814, 0x31},
  10388. - {OV5693_8BIT, 0x3815, 0x31},
  10389. - {OV5693_8BIT, 0x3820, 0x04},
  10390. - {OV5693_8BIT, 0x3821, 0x1f},
  10391. - {OV5693_8BIT, 0x5002, 0x80},
  10392. - {OV5693_TOK_TERM, 0, 0}
  10393. -};
  10394. +
  10395. /*
  10396. * 1296x976 30fps 17ms VBlanking 2lane 10Bit (Scaling)
  10397. @@ -660,62 +633,10 @@ static struct ov5693_reg const ov5693_736x496[] = {
  10398. };
  10399. #endif
  10400. -/*
  10401. -static struct ov5693_reg const ov5693_736x496[] = {
  10402. - {OV5693_8BIT, 0x3501, 0x7b},
  10403. - {OV5693_8BIT, 0x3502, 0x00},
  10404. - {OV5693_8BIT, 0x3708, 0xe6},
  10405. - {OV5693_8BIT, 0x3709, 0xc3},
  10406. - {OV5693_8BIT, 0x3803, 0x00},
  10407. - {OV5693_8BIT, 0x3806, 0x07},
  10408. - {OV5693_8BIT, 0x3807, 0xa3},
  10409. - {OV5693_8BIT, 0x3808, 0x02},
  10410. - {OV5693_8BIT, 0x3809, 0xe0},
  10411. - {OV5693_8BIT, 0x380a, 0x01},
  10412. - {OV5693_8BIT, 0x380b, 0xf0},
  10413. - {OV5693_8BIT, 0x380c, 0x0d},
  10414. - {OV5693_8BIT, 0x380d, 0xb0},
  10415. - {OV5693_8BIT, 0x380e, 0x05},
  10416. - {OV5693_8BIT, 0x380f, 0xf2},
  10417. - {OV5693_8BIT, 0x3811, 0x08},
  10418. - {OV5693_8BIT, 0x3813, 0x02},
  10419. - {OV5693_8BIT, 0x3814, 0x31},
  10420. - {OV5693_8BIT, 0x3815, 0x31},
  10421. - {OV5693_8BIT, 0x3820, 0x01},
  10422. - {OV5693_8BIT, 0x3821, 0x1f},
  10423. - {OV5693_8BIT, 0x5002, 0x00},
  10424. - {OV5693_TOK_TERM, 0, 0}
  10425. -};
  10426. -*/
  10427. /*
  10428. * 976x556 30fps 8.8ms VBlanking 2lane 10Bit (Scaling)
  10429. */
  10430. #if ENABLE_NON_PREVIEW
  10431. -static struct ov5693_reg const ov5693_976x556[] = {
  10432. - {OV5693_8BIT, 0x3501, 0x7b},
  10433. - {OV5693_8BIT, 0x3502, 0x00},
  10434. - {OV5693_8BIT, 0x3708, 0xe2},
  10435. - {OV5693_8BIT, 0x3709, 0xc3},
  10436. - {OV5693_8BIT, 0x3803, 0xf0},
  10437. - {OV5693_8BIT, 0x3806, 0x06},
  10438. - {OV5693_8BIT, 0x3807, 0xa7},
  10439. - {OV5693_8BIT, 0x3808, 0x03},
  10440. - {OV5693_8BIT, 0x3809, 0xd0},
  10441. - {OV5693_8BIT, 0x380a, 0x02},
  10442. - {OV5693_8BIT, 0x380b, 0x2C},
  10443. - {OV5693_8BIT, 0x380c, 0x0a},
  10444. - {OV5693_8BIT, 0x380d, 0x80},
  10445. - {OV5693_8BIT, 0x380e, 0x07},
  10446. - {OV5693_8BIT, 0x380f, 0xc0},
  10447. - {OV5693_8BIT, 0x3811, 0x10},
  10448. - {OV5693_8BIT, 0x3813, 0x02},
  10449. - {OV5693_8BIT, 0x3814, 0x11},
  10450. - {OV5693_8BIT, 0x3815, 0x11},
  10451. - {OV5693_8BIT, 0x3820, 0x00},
  10452. - {OV5693_8BIT, 0x3821, 0x1e},
  10453. - {OV5693_8BIT, 0x5002, 0x80},
  10454. - {OV5693_TOK_TERM, 0, 0}
  10455. -};
  10456. /*DS from 2624x1492*/
  10457. static struct ov5693_reg const ov5693_1296x736[] = {
  10458. @@ -782,40 +703,6 @@ static struct ov5693_reg const ov5693_1636p_30fps[] = {
  10459. };
  10460. #endif
  10461. -static struct ov5693_reg const ov5693_1616x1216_30fps[] = {
  10462. - {OV5693_8BIT, 0x3501, 0x7b},
  10463. - {OV5693_8BIT, 0x3502, 0x80},
  10464. - {OV5693_8BIT, 0x3708, 0xe2},
  10465. - {OV5693_8BIT, 0x3709, 0xc3},
  10466. - {OV5693_8BIT, 0x3800, 0x00}, /*{3800,3801} Array X start*/
  10467. - {OV5693_8BIT, 0x3801, 0x08}, /* 04 //{3800,3801} Array X start*/
  10468. - {OV5693_8BIT, 0x3802, 0x00}, /*{3802,3803} Array Y start*/
  10469. - {OV5693_8BIT, 0x3803, 0x04}, /* 00 //{3802,3803} Array Y start*/
  10470. - {OV5693_8BIT, 0x3804, 0x0a}, /*{3804,3805} Array X end*/
  10471. - {OV5693_8BIT, 0x3805, 0x37}, /* 3b //{3804,3805} Array X end*/
  10472. - {OV5693_8BIT, 0x3806, 0x07}, /*{3806,3807} Array Y end*/
  10473. - {OV5693_8BIT, 0x3807, 0x9f}, /* a3 //{3806,3807} Array Y end*/
  10474. - {OV5693_8BIT, 0x3808, 0x06}, /*{3808,3809} Final output H size*/
  10475. - {OV5693_8BIT, 0x3809, 0x50}, /*{3808,3809} Final output H size*/
  10476. - {OV5693_8BIT, 0x380a, 0x04}, /*{380a,380b} Final output V size*/
  10477. - {OV5693_8BIT, 0x380b, 0xc0}, /*{380a,380b} Final output V size*/
  10478. - {OV5693_8BIT, 0x380c, 0x0a}, /*{380c,380d} HTS*/
  10479. - {OV5693_8BIT, 0x380d, 0x80}, /*{380c,380d} HTS*/
  10480. - {OV5693_8BIT, 0x380e, 0x07}, /*{380e,380f} VTS*/
  10481. - {OV5693_8BIT, 0x380f, 0xc0}, /* bc //{380e,380f} VTS*/
  10482. - {OV5693_8BIT, 0x3810, 0x00}, /*{3810,3811} windowing X offset*/
  10483. - {OV5693_8BIT, 0x3811, 0x10}, /*{3810,3811} windowing X offset*/
  10484. - {OV5693_8BIT, 0x3812, 0x00}, /*{3812,3813} windowing Y offset*/
  10485. - {OV5693_8BIT, 0x3813, 0x06}, /*{3812,3813} windowing Y offset*/
  10486. - {OV5693_8BIT, 0x3814, 0x11}, /*X subsample control*/
  10487. - {OV5693_8BIT, 0x3815, 0x11}, /*Y subsample control*/
  10488. - {OV5693_8BIT, 0x3820, 0x00}, /*FLIP/Binnning control*/
  10489. - {OV5693_8BIT, 0x3821, 0x1e}, /*MIRROR control*/
  10490. - {OV5693_8BIT, 0x5002, 0x00},
  10491. - {OV5693_8BIT, 0x5041, 0x84},
  10492. - {OV5693_TOK_TERM, 0, 0}
  10493. -};
  10494. -
  10495. /*
  10496. * 1940x1096 30fps 8.8ms VBlanking 2lane 10bit (Scaling)
  10497. */
  10498. @@ -878,37 +765,6 @@ static struct ov5693_reg const ov5693_2592x1456_30fps[] = {
  10499. };
  10500. #endif
  10501. -static struct ov5693_reg const ov5693_2576x1456_30fps[] = {
  10502. - {OV5693_8BIT, 0x3501, 0x7b},
  10503. - {OV5693_8BIT, 0x3502, 0x00},
  10504. - {OV5693_8BIT, 0x3708, 0xe2},
  10505. - {OV5693_8BIT, 0x3709, 0xc3},
  10506. - {OV5693_8BIT, 0x3800, 0x00},
  10507. - {OV5693_8BIT, 0x3801, 0x00},
  10508. - {OV5693_8BIT, 0x3802, 0x00},
  10509. - {OV5693_8BIT, 0x3803, 0xf0},
  10510. - {OV5693_8BIT, 0x3804, 0x0a},
  10511. - {OV5693_8BIT, 0x3805, 0x3f},
  10512. - {OV5693_8BIT, 0x3806, 0x06},
  10513. - {OV5693_8BIT, 0x3807, 0xa4},
  10514. - {OV5693_8BIT, 0x3808, 0x0a},
  10515. - {OV5693_8BIT, 0x3809, 0x10},
  10516. - {OV5693_8BIT, 0x380a, 0x05},
  10517. - {OV5693_8BIT, 0x380b, 0xb0},
  10518. - {OV5693_8BIT, 0x380c, 0x0a},
  10519. - {OV5693_8BIT, 0x380d, 0x80},
  10520. - {OV5693_8BIT, 0x380e, 0x07},
  10521. - {OV5693_8BIT, 0x380f, 0xc0},
  10522. - {OV5693_8BIT, 0x3811, 0x18},
  10523. - {OV5693_8BIT, 0x3813, 0x00},
  10524. - {OV5693_8BIT, 0x3814, 0x11},
  10525. - {OV5693_8BIT, 0x3815, 0x11},
  10526. - {OV5693_8BIT, 0x3820, 0x00},
  10527. - {OV5693_8BIT, 0x3821, 0x1e},
  10528. - {OV5693_8BIT, 0x5002, 0x00},
  10529. - {OV5693_TOK_TERM, 0, 0}
  10530. -};
  10531. -
  10532. /*
  10533. * 2592x1944 30fps 0.6ms VBlanking 2lane 10Bit
  10534. */
  10535. @@ -940,49 +796,6 @@ static struct ov5693_reg const ov5693_2592x1944_30fps[] = {
  10536. };
  10537. #endif
  10538. -/*
  10539. - * 11:9 Full FOV Output, expected FOV Res: 2346x1920
  10540. - * ISP Effect Res: 1408x1152
  10541. - * Sensor out: 1424x1168, DS From: 2380x1952
  10542. - *
  10543. - * WA: Left Offset: 8, Hor scal: 64
  10544. - */
  10545. -#if ENABLE_NON_PREVIEW
  10546. -static struct ov5693_reg const ov5693_1424x1168_30fps[] = {
  10547. - {OV5693_8BIT, 0x3501, 0x3b}, /* long exposure[15:8] */
  10548. - {OV5693_8BIT, 0x3502, 0x80}, /* long exposure[7:0] */
  10549. - {OV5693_8BIT, 0x3708, 0xe2},
  10550. - {OV5693_8BIT, 0x3709, 0xc3},
  10551. - {OV5693_8BIT, 0x3800, 0x00}, /* TIMING_X_ADDR_START */
  10552. - {OV5693_8BIT, 0x3801, 0x50}, /* 80 */
  10553. - {OV5693_8BIT, 0x3802, 0x00}, /* TIMING_Y_ADDR_START */
  10554. - {OV5693_8BIT, 0x3803, 0x02}, /* 2 */
  10555. - {OV5693_8BIT, 0x3804, 0x09}, /* TIMING_X_ADDR_END */
  10556. - {OV5693_8BIT, 0x3805, 0xdd}, /* 2525 */
  10557. - {OV5693_8BIT, 0x3806, 0x07}, /* TIMING_Y_ADDR_END */
  10558. - {OV5693_8BIT, 0x3807, 0xa1}, /* 1953 */
  10559. - {OV5693_8BIT, 0x3808, 0x05}, /* TIMING_X_OUTPUT_SIZE */
  10560. - {OV5693_8BIT, 0x3809, 0x90}, /* 1424 */
  10561. - {OV5693_8BIT, 0x380a, 0x04}, /* TIMING_Y_OUTPUT_SIZE */
  10562. - {OV5693_8BIT, 0x380b, 0x90}, /* 1168 */
  10563. - {OV5693_8BIT, 0x380c, 0x0a}, /* TIMING_HTS */
  10564. - {OV5693_8BIT, 0x380d, 0x80},
  10565. - {OV5693_8BIT, 0x380e, 0x07}, /* TIMING_VTS */
  10566. - {OV5693_8BIT, 0x380f, 0xc0},
  10567. - {OV5693_8BIT, 0x3810, 0x00}, /* TIMING_ISP_X_WIN */
  10568. - {OV5693_8BIT, 0x3811, 0x02}, /* 2 */
  10569. - {OV5693_8BIT, 0x3812, 0x00}, /* TIMING_ISP_Y_WIN */
  10570. - {OV5693_8BIT, 0x3813, 0x00}, /* 0 */
  10571. - {OV5693_8BIT, 0x3814, 0x11}, /* TIME_X_INC */
  10572. - {OV5693_8BIT, 0x3815, 0x11}, /* TIME_Y_INC */
  10573. - {OV5693_8BIT, 0x3820, 0x00},
  10574. - {OV5693_8BIT, 0x3821, 0x1e},
  10575. - {OV5693_8BIT, 0x5002, 0x00},
  10576. - {OV5693_8BIT, 0x5041, 0x84}, /* scale is auto enabled */
  10577. - {OV5693_TOK_TERM, 0, 0}
  10578. -};
  10579. -#endif
  10580. -
  10581. /*
  10582. * 3:2 Full FOV Output, expected FOV Res: 2560x1706
  10583. * ISP Effect Res: 720x480
  10584. @@ -1022,173 +835,6 @@ static struct ov5693_reg const ov5693_736x496_30fps[] = {
  10585. {OV5693_TOK_TERM, 0, 0}
  10586. };
  10587. -static struct ov5693_reg const ov5693_2576x1936_30fps[] = {
  10588. - {OV5693_8BIT, 0x3501, 0x7b},
  10589. - {OV5693_8BIT, 0x3502, 0x00},
  10590. - {OV5693_8BIT, 0x3708, 0xe2},
  10591. - {OV5693_8BIT, 0x3709, 0xc3},
  10592. - {OV5693_8BIT, 0x3803, 0x00},
  10593. - {OV5693_8BIT, 0x3806, 0x07},
  10594. - {OV5693_8BIT, 0x3807, 0xa3},
  10595. - {OV5693_8BIT, 0x3808, 0x0a},
  10596. - {OV5693_8BIT, 0x3809, 0x10},
  10597. - {OV5693_8BIT, 0x380a, 0x07},
  10598. - {OV5693_8BIT, 0x380b, 0x90},
  10599. - {OV5693_8BIT, 0x380c, 0x0a},
  10600. - {OV5693_8BIT, 0x380d, 0x80},
  10601. - {OV5693_8BIT, 0x380e, 0x07},
  10602. - {OV5693_8BIT, 0x380f, 0xc0},
  10603. - {OV5693_8BIT, 0x3811, 0x18},
  10604. - {OV5693_8BIT, 0x3813, 0x00},
  10605. - {OV5693_8BIT, 0x3814, 0x11},
  10606. - {OV5693_8BIT, 0x3815, 0x11},
  10607. - {OV5693_8BIT, 0x3820, 0x00},
  10608. - {OV5693_8BIT, 0x3821, 0x1e},
  10609. - {OV5693_8BIT, 0x5002, 0x00},
  10610. - {OV5693_TOK_TERM, 0, 0}
  10611. -};
  10612. -
  10613. -static struct ov5693_resolution ov5693_res_preview[] = {
  10614. - {
  10615. - .desc = "ov5693_736x496_30fps",
  10616. - .width = 736,
  10617. - .height = 496,
  10618. - .pix_clk_freq = 160,
  10619. - .fps = 30,
  10620. - .used = 0,
  10621. - .pixels_per_line = 2688,
  10622. - .lines_per_frame = 1984,
  10623. - .bin_factor_x = 1,
  10624. - .bin_factor_y = 1,
  10625. - .bin_mode = 0,
  10626. - .regs = ov5693_736x496_30fps,
  10627. - },
  10628. - {
  10629. - .desc = "ov5693_1616x1216_30fps",
  10630. - .width = 1616,
  10631. - .height = 1216,
  10632. - .pix_clk_freq = 160,
  10633. - .fps = 30,
  10634. - .used = 0,
  10635. - .pixels_per_line = 2688,
  10636. - .lines_per_frame = 1984,
  10637. - .bin_factor_x = 1,
  10638. - .bin_factor_y = 1,
  10639. - .bin_mode = 0,
  10640. - .regs = ov5693_1616x1216_30fps,
  10641. - },
  10642. - {
  10643. - .desc = "ov5693_5M_30fps",
  10644. - .width = 2576,
  10645. - .height = 1456,
  10646. - .pix_clk_freq = 160,
  10647. - .fps = 30,
  10648. - .used = 0,
  10649. - .pixels_per_line = 2688,
  10650. - .lines_per_frame = 1984,
  10651. - .bin_factor_x = 1,
  10652. - .bin_factor_y = 1,
  10653. - .bin_mode = 0,
  10654. - .regs = ov5693_2576x1456_30fps,
  10655. - },
  10656. - {
  10657. - .desc = "ov5693_5M_30fps",
  10658. - .width = 2576,
  10659. - .height = 1936,
  10660. - .pix_clk_freq = 160,
  10661. - .fps = 30,
  10662. - .used = 0,
  10663. - .pixels_per_line = 2688,
  10664. - .lines_per_frame = 1984,
  10665. - .bin_factor_x = 1,
  10666. - .bin_factor_y = 1,
  10667. - .bin_mode = 0,
  10668. - .regs = ov5693_2576x1936_30fps,
  10669. - },
  10670. -};
  10671. -
  10672. -#define N_RES_PREVIEW (ARRAY_SIZE(ov5693_res_preview))
  10673. -
  10674. -/*
  10675. - * Disable non-preview configurations until the configuration selection is
  10676. - * improved.
  10677. - */
  10678. -#if ENABLE_NON_PREVIEW
  10679. -struct ov5693_resolution ov5693_res_still[] = {
  10680. - {
  10681. - .desc = "ov5693_736x496_30fps",
  10682. - .width = 736,
  10683. - .height = 496,
  10684. - .pix_clk_freq = 160,
  10685. - .fps = 30,
  10686. - .used = 0,
  10687. - .pixels_per_line = 2688,
  10688. - .lines_per_frame = 1984,
  10689. - .bin_factor_x = 1,
  10690. - .bin_factor_y = 1,
  10691. - .bin_mode = 0,
  10692. - .regs = ov5693_736x496_30fps,
  10693. - },
  10694. - {
  10695. - .desc = "ov5693_1424x1168_30fps",
  10696. - .width = 1424,
  10697. - .height = 1168,
  10698. - .pix_clk_freq = 160,
  10699. - .fps = 30,
  10700. - .used = 0,
  10701. - .pixels_per_line = 2688,
  10702. - .lines_per_frame = 1984,
  10703. - .bin_factor_x = 1,
  10704. - .bin_factor_y = 1,
  10705. - .bin_mode = 0,
  10706. - .regs = ov5693_1424x1168_30fps,
  10707. - },
  10708. - {
  10709. - .desc = "ov5693_1616x1216_30fps",
  10710. - .width = 1616,
  10711. - .height = 1216,
  10712. - .pix_clk_freq = 160,
  10713. - .fps = 30,
  10714. - .used = 0,
  10715. - .pixels_per_line = 2688,
  10716. - .lines_per_frame = 1984,
  10717. - .bin_factor_x = 1,
  10718. - .bin_factor_y = 1,
  10719. - .bin_mode = 0,
  10720. - .regs = ov5693_1616x1216_30fps,
  10721. - },
  10722. - {
  10723. - .desc = "ov5693_5M_30fps",
  10724. - .width = 2592,
  10725. - .height = 1456,
  10726. - .pix_clk_freq = 160,
  10727. - .fps = 30,
  10728. - .used = 0,
  10729. - .pixels_per_line = 2688,
  10730. - .lines_per_frame = 1984,
  10731. - .bin_factor_x = 1,
  10732. - .bin_factor_y = 1,
  10733. - .bin_mode = 0,
  10734. - .regs = ov5693_2592x1456_30fps,
  10735. - },
  10736. - {
  10737. - .desc = "ov5693_5M_30fps",
  10738. - .width = 2592,
  10739. - .height = 1944,
  10740. - .pix_clk_freq = 160,
  10741. - .fps = 30,
  10742. - .used = 0,
  10743. - .pixels_per_line = 2688,
  10744. - .lines_per_frame = 1984,
  10745. - .bin_factor_x = 1,
  10746. - .bin_factor_y = 1,
  10747. - .bin_mode = 0,
  10748. - .regs = ov5693_2592x1944_30fps,
  10749. - },
  10750. -};
  10751. -
  10752. -#define N_RES_STILL (ARRAY_SIZE(ov5693_res_still))
  10753. -
  10754. struct ov5693_resolution ov5693_res_video[] = {
  10755. {
  10756. .desc = "ov5693_736x496_30fps",
  10757. @@ -1343,4 +989,3 @@ struct ov5693_resolution ov5693_res_video[] = {
  10758. static struct ov5693_resolution *ov5693_res = ov5693_res_video;
  10759. static unsigned long N_RES = N_RES_VIDEO;
  10760. -#endif
  10761. --
  10762. 2.33.0
  10763. From 4ddf83de46c2815e6cf66cc2121558ccba73c432 Mon Sep 17 00:00:00 2001
  10764. From: Daniel Scally <djrscally@gmail.com>
  10765. Date: Sun, 14 Feb 2021 14:45:58 +0000
  10766. Subject: [PATCH] media: i2c: update set_fmt() for ov5693
  10767. The set_fmt() function is a bit messy still, using home grown solutions to
  10768. find the closest supported resolution instead of the v4l2 helpers. It also
  10769. fails to update control ranges to account for the new mode (though this is
  10770. moot currently as they're all the same, but the probably shouldn't be).
  10771. Fix it up a little.
  10772. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  10773. Patchset: cameras
  10774. ---
  10775. drivers/media/i2c/ov5693.c | 148 ++++++++++---------------------------
  10776. drivers/media/i2c/ov5693.h | 5 +-
  10777. 2 files changed, 40 insertions(+), 113 deletions(-)
  10778. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  10779. index 622a7ddf4063..09c84006d5c9 100644
  10780. --- a/drivers/media/i2c/ov5693.c
  10781. +++ b/drivers/media/i2c/ov5693.c
  10782. @@ -753,7 +753,7 @@ static int ov5693_sensor_init(struct ov5693_device *ov5693)
  10783. return ret;
  10784. }
  10785. - ret = ov5693_write_reg_array(client, ov5693_res[ov5693->fmt_idx].regs);
  10786. + ret = ov5693_write_reg_array(client, ov5693->mode->regs);
  10787. if (ret) {
  10788. dev_err(&client->dev, "ov5693 write register err.\n");
  10789. return ret;
  10790. @@ -866,128 +866,56 @@ static int __maybe_unused ov5693_sensor_resume(struct device *dev)
  10791. return ret;
  10792. }
  10793. -/*
  10794. - * distance - calculate the distance
  10795. - * @res: resolution
  10796. - * @w: width
  10797. - * @h: height
  10798. - *
  10799. - * Get the gap between res_w/res_h and w/h.
  10800. - * distance = (res_w/res_h - w/h) / (w/h) * 8192
  10801. - * res->width/height smaller than w/h wouldn't be considered.
  10802. - * The gap of ratio larger than 1/8 wouldn't be considered.
  10803. - * Returns the value of gap or -1 if fail.
  10804. - */
  10805. -#define LARGEST_ALLOWED_RATIO_MISMATCH 1024
  10806. -static int distance(struct ov5693_resolution *res, u32 w, u32 h)
  10807. -{
  10808. - int ratio;
  10809. - int distance;
  10810. -
  10811. - if (w == 0 || h == 0 ||
  10812. - res->width < w || res->height < h)
  10813. - return -1;
  10814. -
  10815. - ratio = res->width << 13;
  10816. - ratio /= w;
  10817. - ratio *= h;
  10818. - ratio /= res->height;
  10819. -
  10820. - distance = abs(ratio - 8192);
  10821. -
  10822. - if (distance > LARGEST_ALLOWED_RATIO_MISMATCH)
  10823. - return -1;
  10824. -
  10825. - return distance;
  10826. -}
  10827. -
  10828. -/* Return the nearest higher resolution index
  10829. - * Firstly try to find the approximate aspect ratio resolution
  10830. - * If we find multiple same AR resolutions, choose the
  10831. - * minimal size.
  10832. - */
  10833. -static int nearest_resolution_index(int w, int h)
  10834. -{
  10835. - int i;
  10836. - int idx = -1;
  10837. - int dist;
  10838. - int min_dist = INT_MAX;
  10839. - int min_res_w = INT_MAX;
  10840. - struct ov5693_resolution *tmp_res = NULL;
  10841. -
  10842. - for (i = 0; i < N_RES; i++) {
  10843. - tmp_res = &ov5693_res[i];
  10844. - dist = distance(tmp_res, w, h);
  10845. - if (dist == -1)
  10846. - continue;
  10847. - if (dist < min_dist) {
  10848. - min_dist = dist;
  10849. - idx = i;
  10850. - min_res_w = ov5693_res[i].width;
  10851. - continue;
  10852. - }
  10853. - if (dist == min_dist && ov5693_res[i].width < min_res_w)
  10854. - idx = i;
  10855. - }
  10856. -
  10857. - return idx;
  10858. -}
  10859. -
  10860. -static int get_resolution_index(int w, int h)
  10861. -{
  10862. - int i;
  10863. -
  10864. - for (i = 0; i < N_RES; i++) {
  10865. - if (w != ov5693_res[i].width)
  10866. - continue;
  10867. - if (h != ov5693_res[i].height)
  10868. - continue;
  10869. -
  10870. - return i;
  10871. - }
  10872. -
  10873. - return -1;
  10874. -}
  10875. -
  10876. static int ov5693_set_fmt(struct v4l2_subdev *sd,
  10877. struct v4l2_subdev_pad_config *cfg,
  10878. struct v4l2_subdev_format *format)
  10879. {
  10880. - struct v4l2_mbus_framefmt *fmt = &format->format;
  10881. struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  10882. - struct i2c_client *client = v4l2_get_subdevdata(sd);
  10883. + const struct ov5693_resolution *mode;
  10884. + int exposure_max;
  10885. int ret = 0;
  10886. - int idx;
  10887. + int hblank;
  10888. if (format->pad)
  10889. return -EINVAL;
  10890. - if (!fmt)
  10891. - return -EINVAL;
  10892. mutex_lock(&ov5693->lock);
  10893. - idx = nearest_resolution_index(fmt->width, fmt->height);
  10894. - if (idx == -1) {
  10895. - /* return the largest resolution */
  10896. - fmt->width = ov5693_res[N_RES - 1].width;
  10897. - fmt->height = ov5693_res[N_RES - 1].height;
  10898. - } else {
  10899. - fmt->width = ov5693_res[idx].width;
  10900. - fmt->height = ov5693_res[idx].height;
  10901. - }
  10902. - fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
  10903. + mode = v4l2_find_nearest_size(ov5693_res_video, ARRAY_SIZE(ov5693_res_video),
  10904. + width, height, format->format.width,
  10905. + format->format.height);
  10906. +
  10907. + if (!mode)
  10908. + return -EINVAL;
  10909. +
  10910. + format->format.width = mode->width;
  10911. + format->format.height = mode->height;
  10912. + format->format.code = MEDIA_BUS_FMT_SBGGR10_1X10;
  10913. +
  10914. if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
  10915. - cfg->try_fmt = *fmt;
  10916. - ret = 0;
  10917. + *v4l2_subdev_get_try_format(sd, cfg, format->pad) = format->format;
  10918. goto mutex_unlock;
  10919. }
  10920. - ov5693->fmt_idx = get_resolution_index(fmt->width, fmt->height);
  10921. - if (ov5693->fmt_idx == -1) {
  10922. - dev_err(&client->dev, "get resolution fail\n");
  10923. - ret = -EINVAL;
  10924. - goto mutex_unlock;
  10925. - }
  10926. + ov5693->mode = mode;
  10927. +
  10928. + /* Update limits and set FPS to default */
  10929. + __v4l2_ctrl_modify_range(ov5693->ctrls.vblank,
  10930. + mode->lines_per_frame - mode->height,
  10931. + OV5693_TIMING_MAX_VTS - mode->height,
  10932. + 1, mode->lines_per_frame - mode->height);
  10933. + __v4l2_ctrl_s_ctrl(ov5693->ctrls.vblank,
  10934. + mode->lines_per_frame - mode->height);
  10935. +
  10936. + hblank = mode->pixels_per_line - mode->width;
  10937. + __v4l2_ctrl_modify_range(ov5693->ctrls.hblank, hblank, hblank, 1, hblank);
  10938. +
  10939. + exposure_max = mode->lines_per_frame - 8;
  10940. + __v4l2_ctrl_modify_range(ov5693->ctrls.exposure,
  10941. + ov5693->ctrls.exposure->minimum, exposure_max,
  10942. + ov5693->ctrls.exposure->step,
  10943. + ov5693->ctrls.exposure->val < exposure_max ?
  10944. + ov5693->ctrls.exposure->val : exposure_max);
  10945. mutex_unlock:
  10946. mutex_unlock(&ov5693->lock);
  10947. @@ -1056,8 +984,8 @@ static int ov5693_get_fmt(struct v4l2_subdev *sd,
  10948. if (!fmt)
  10949. return -EINVAL;
  10950. - fmt->width = ov5693_res[ov5693->fmt_idx].width;
  10951. - fmt->height = ov5693_res[ov5693->fmt_idx].height;
  10952. + fmt->width = ov5693->mode->width;
  10953. + fmt->height = ov5693->mode->height;
  10954. fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
  10955. return 0;
  10956. @@ -1174,7 +1102,7 @@ static int ov5693_g_frame_interval(struct v4l2_subdev *sd,
  10957. struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  10958. interval->interval.numerator = 1;
  10959. - interval->interval.denominator = ov5693_res[ov5693->fmt_idx].fps;
  10960. + interval->interval.denominator = ov5693->mode->fps;
  10961. return 0;
  10962. }
  10963. diff --git a/drivers/media/i2c/ov5693.h b/drivers/media/i2c/ov5693.h
  10964. index 29e6735112da..0377853f8b2b 100644
  10965. --- a/drivers/media/i2c/ov5693.h
  10966. +++ b/drivers/media/i2c/ov5693.h
  10967. @@ -127,8 +127,8 @@ struct ov5693_resolution {
  10968. u8 *desc;
  10969. const struct ov5693_reg *regs;
  10970. int res;
  10971. - int width;
  10972. - int height;
  10973. + u32 width;
  10974. + u32 height;
  10975. int fps;
  10976. int pix_clk_freq;
  10977. u16 pixels_per_line;
  10978. @@ -178,7 +178,6 @@ struct ov5693_device {
  10979. struct camera_sensor_platform_data *platform_data;
  10980. ktime_t timestamp_t_focus_abs;
  10981. int vt_pix_clk_freq_mhz;
  10982. - int fmt_idx;
  10983. int run_mode;
  10984. int otp_size;
  10985. u8 *otp_data;
  10986. --
  10987. 2.33.0