12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357 |
- From 92a75d7afacee622b3f426bc75c7b59aeb36d304 Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Mon, 5 Apr 2021 23:56:53 +0100
- Subject: [PATCH] media: ipu3-cio2: Toggle sensor streaming in pm runtime ops
- The .suspend() and .resume() runtime_pm operations for the ipu3-cio2
- driver currently do not handle the sensor's stream. Setting .s_stream() on
- or off for the sensor subdev means that sensors will pause and resume the
- stream at the appropriate time even if their drivers don't implement those
- operations.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 15 ++++++++++++++-
- 1 file changed, 14 insertions(+), 1 deletion(-)
- diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
- index 47db0ee0fcbf..7bb86e246ebe 100644
- --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
- +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
- @@ -1973,12 +1973,19 @@ static int __maybe_unused cio2_suspend(struct device *dev)
- struct pci_dev *pci_dev = to_pci_dev(dev);
- struct cio2_device *cio2 = pci_get_drvdata(pci_dev);
- struct cio2_queue *q = cio2->cur_queue;
- + int r;
-
- dev_dbg(dev, "cio2 suspend\n");
- if (!cio2->streaming)
- return 0;
-
- /* Stop stream */
- + r = v4l2_subdev_call(q->sensor, video, s_stream, 0);
- + if (r) {
- + dev_err(dev, "failed to stop sensor streaming\n");
- + return r;
- + }
- +
- cio2_hw_exit(cio2, q);
- synchronize_irq(pci_dev->irq);
-
- @@ -2013,8 +2020,14 @@ static int __maybe_unused cio2_resume(struct device *dev)
- }
-
- r = cio2_hw_init(cio2, q);
- - if (r)
- + if (r) {
- dev_err(dev, "fail to init cio2 hw\n");
- + return r;
- + }
- +
- + r = v4l2_subdev_call(q->sensor, video, s_stream, 1);
- + if (r)
- + dev_err(dev, "fail to start sensor streaming\n");
-
- return r;
- }
- --
- 2.34.0
- From aef7dcd154115d18e90e2bc4b48891730ecff98b Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Mon, 5 Apr 2021 23:56:54 +0100
- Subject: [PATCH] media: i2c: Add support for ov5693 sensor
- The OV5693 is a 5 Mpx CMOS image sensor, connected via MIPI CSI-2. The
- chip is capable of a single lane configuration, but currently only two
- lanes are supported.
- Most of the sensor's features are supported, with the main exception
- being the lens correction algorithm.
- The driver provides all mandatory, optional and recommended V4L2 controls
- for maximum compatibility with libcamera.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- MAINTAINERS | 7 +
- drivers/media/i2c/Kconfig | 11 +
- drivers/media/i2c/Makefile | 1 +
- drivers/media/i2c/ov5693.c | 1557 ++++++++++++++++++++++++++++++++++++
- 4 files changed, 1576 insertions(+)
- create mode 100644 drivers/media/i2c/ov5693.c
- diff --git a/MAINTAINERS b/MAINTAINERS
- index 5713585d060d..33fdad7a7ddf 100644
- --- a/MAINTAINERS
- +++ b/MAINTAINERS
- @@ -13757,6 +13757,13 @@ S: Maintained
- T: git git://linuxtv.org/media_tree.git
- F: drivers/media/i2c/ov5675.c
-
- +OMNIVISION OV5693 SENSOR DRIVER
- +M: Daniel Scally <djrscally@gmail.com>
- +L: linux-media@vger.kernel.org
- +S: Maintained
- +T: git git://linuxtv.org/media_tree.git
- +F: drivers/media/i2c/ov5693.c
- +
- OMNIVISION OV5695 SENSOR DRIVER
- M: Shunqian Zheng <zhengsq@rock-chips.com>
- L: linux-media@vger.kernel.org
- diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
- index bde7fb021564..b2ac84d78b91 100644
- --- a/drivers/media/i2c/Kconfig
- +++ b/drivers/media/i2c/Kconfig
- @@ -1015,6 +1015,17 @@ config VIDEO_OV5675
- To compile this driver as a module, choose M here: the
- module will be called ov5675.
-
- +config VIDEO_OV5693
- + tristate "OmniVision OV5693 sensor support"
- + depends on I2C && VIDEO_V4L2
- + select V4L2_FWNODE
- + help
- + This is a Video4Linux2 sensor driver for the OmniVision
- + OV5693 camera.
- +
- + To compile this driver as a module, choose M here: the
- + module will be called ov5693.
- +
- config VIDEO_OV5695
- tristate "OmniVision OV5695 sensor support"
- depends on I2C && VIDEO_V4L2
- diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
- index 1168fa6b84ed..011e90c1a288 100644
- --- a/drivers/media/i2c/Makefile
- +++ b/drivers/media/i2c/Makefile
- @@ -75,6 +75,7 @@ obj-$(CONFIG_VIDEO_OV5647) += ov5647.o
- obj-$(CONFIG_VIDEO_OV5648) += ov5648.o
- obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
- obj-$(CONFIG_VIDEO_OV5675) += ov5675.o
- +obj-$(CONFIG_VIDEO_OV5693) += ov5693.o
- obj-$(CONFIG_VIDEO_OV5695) += ov5695.o
- obj-$(CONFIG_VIDEO_OV6650) += ov6650.o
- obj-$(CONFIG_VIDEO_OV7251) += ov7251.o
- diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
- new file mode 100644
- index 000000000000..9499ee10f56c
- --- /dev/null
- +++ b/drivers/media/i2c/ov5693.c
- @@ -0,0 +1,1557 @@
- +// SPDX-License-Identifier: GPL-2.0
- +/*
- + * Copyright (c) 2013 Intel Corporation. All Rights Reserved.
- + *
- + * Adapted from the atomisp-ov5693 driver, with contributions from:
- + *
- + * Daniel Scally
- + * Jean-Michel Hautbois
- + * Fabian Wuthrich
- + * Tsuchiya Yuto
- + * Jordan Hand
- + * Jake Day
- + */
- +
- +#include <asm/unaligned.h>
- +#include <linux/acpi.h>
- +#include <linux/clk.h>
- +#include <linux/delay.h>
- +#include <linux/device.h>
- +#include <linux/i2c.h>
- +#include <linux/module.h>
- +#include <linux/pm_runtime.h>
- +#include <linux/regulator/consumer.h>
- +#include <linux/slab.h>
- +#include <linux/types.h>
- +#include <media/v4l2-ctrls.h>
- +#include <media/v4l2-device.h>
- +#include <media/v4l2-fwnode.h>
- +
- +/* System Control */
- +#define OV5693_SW_RESET_REG 0x0103
- +#define OV5693_SW_STREAM_REG 0x0100
- +#define OV5693_START_STREAMING 0x01
- +#define OV5693_STOP_STREAMING 0x00
- +#define OV5693_SW_RESET 0x01
- +
- +#define OV5693_REG_CHIP_ID_H 0x300a
- +#define OV5693_REG_CHIP_ID_L 0x300b
- +/* Yes, this is right. The datasheet for the OV5693 gives its ID as 0x5690 */
- +#define OV5693_CHIP_ID 0x5690
- +
- +/* Exposure */
- +#define OV5693_EXPOSURE_L_CTRL_HH_REG 0x3500
- +#define OV5693_EXPOSURE_L_CTRL_H_REG 0x3501
- +#define OV5693_EXPOSURE_L_CTRL_L_REG 0x3502
- +#define OV5693_EXPOSURE_CTRL_HH(v) (((v) & GENMASK(14, 12)) >> 12)
- +#define OV5693_EXPOSURE_CTRL_H(v) (((v) & GENMASK(11, 4)) >> 4)
- +#define OV5693_EXPOSURE_CTRL_L(v) (((v) & GENMASK(3, 0)) << 4)
- +#define OV5693_INTEGRATION_TIME_MARGIN 8
- +#define OV5693_EXPOSURE_MIN 1
- +#define OV5693_EXPOSURE_STEP 1
- +
- +/* Analogue Gain */
- +#define OV5693_GAIN_CTRL_H_REG 0x350a
- +#define OV5693_GAIN_CTRL_H(v) (((v) >> 4) & GENMASK(2, 0))
- +#define OV5693_GAIN_CTRL_L_REG 0x350b
- +#define OV5693_GAIN_CTRL_L(v) (((v) << 4) & GENMASK(7, 4))
- +#define OV5693_GAIN_MIN 1
- +#define OV5693_GAIN_MAX 127
- +#define OV5693_GAIN_DEF 8
- +#define OV5693_GAIN_STEP 1
- +
- +/* Digital Gain */
- +#define OV5693_MWB_RED_GAIN_H_REG 0x3400
- +#define OV5693_MWB_RED_GAIN_L_REG 0x3401
- +#define OV5693_MWB_GREEN_GAIN_H_REG 0x3402
- +#define OV5693_MWB_GREEN_GAIN_L_REG 0x3403
- +#define OV5693_MWB_BLUE_GAIN_H_REG 0x3404
- +#define OV5693_MWB_BLUE_GAIN_L_REG 0x3405
- +#define OV5693_MWB_GAIN_H_CTRL(v) (((v) >> 8) & GENMASK(3, 0))
- +#define OV5693_MWB_GAIN_L_CTRL(v) ((v) & GENMASK(7, 0))
- +#define OV5693_MWB_GAIN_MAX 0x0fff
- +#define OV5693_DIGITAL_GAIN_MIN 1
- +#define OV5693_DIGITAL_GAIN_MAX 4095
- +#define OV5693_DIGITAL_GAIN_DEF 1024
- +#define OV5693_DIGITAL_GAIN_STEP 1
- +
- +/* Timing and Format */
- +#define OV5693_CROP_START_X_H_REG 0x3800
- +#define OV5693_CROP_START_X_H(v) (((v) & GENMASK(12, 8)) >> 8)
- +#define OV5693_CROP_START_X_L_REG 0x3801
- +#define OV5693_CROP_START_X_L(v) ((v) & GENMASK(7, 0))
- +
- +#define OV5693_CROP_START_Y_H_REG 0x3802
- +#define OV5693_CROP_START_Y_H(v) (((v) & GENMASK(11, 8)) >> 8)
- +#define OV5693_CROP_START_Y_L_REG 0x3803
- +#define OV5693_CROP_START_Y_L(v) ((v) & GENMASK(7, 0))
- +
- +#define OV5693_CROP_END_X_H_REG 0x3804
- +#define OV5693_CROP_END_X_H(v) (((v) & GENMASK(12, 8)) >> 8)
- +#define OV5693_CROP_END_X_L_REG 0x3805
- +#define OV5693_CROP_END_X_L(v) ((v) & GENMASK(7, 0))
- +
- +#define OV5693_CROP_END_Y_H_REG 0x3806
- +#define OV5693_CROP_END_Y_H(v) (((v) & GENMASK(11, 8)) >> 8)
- +#define OV5693_CROP_END_Y_L_REG 0x3807
- +#define OV5693_CROP_END_Y_L(v) ((v) & GENMASK(7, 0))
- +
- +#define OV5693_OUTPUT_SIZE_X_H_REG 0x3808
- +#define OV5693_OUTPUT_SIZE_X_H(v) (((v) & GENMASK(15, 8)) >> 8)
- +#define OV5693_OUTPUT_SIZE_X_L_REG 0x3809
- +#define OV5693_OUTPUT_SIZE_X_L(v) ((v) & GENMASK(7, 0))
- +
- +#define OV5693_OUTPUT_SIZE_Y_H_REG 0x380a
- +#define OV5693_OUTPUT_SIZE_Y_H(v) (((v) & GENMASK(15, 8)) >> 8)
- +#define OV5693_OUTPUT_SIZE_Y_L_REG 0x380b
- +#define OV5693_OUTPUT_SIZE_Y_L(v) ((v) & GENMASK(7, 0))
- +
- +#define OV5693_TIMING_HTS_H_REG 0x380c
- +#define OV5693_TIMING_HTS_H(v) (((v) & GENMASK(15, 8)) >> 8)
- +#define OV5693_TIMING_HTS_L_REG 0x380d
- +#define OV5693_TIMING_HTS_L(v) ((v) & GENMASK(7, 0))
- +#define OV5693_FIXED_PPL 2688U
- +
- +#define OV5693_TIMING_VTS_H_REG 0x380e
- +#define OV5693_TIMING_VTS_H(v) (((v) & GENMASK(15, 8)) >> 8)
- +#define OV5693_TIMING_VTS_L_REG 0x380f
- +#define OV5693_TIMING_VTS_L(v) ((v) & GENMASK(7, 0))
- +#define OV5693_TIMING_MAX_VTS 0xffff
- +#define OV5693_TIMING_MIN_VTS 0x04
- +
- +#define OV5693_OFFSET_START_X_H_REG 0x3810
- +#define OV5693_OFFSET_START_X_H(v) (((v) & GENMASK(15, 8)) >> 8)
- +#define OV5693_OFFSET_START_X_L_REG 0x3811
- +#define OV5693_OFFSET_START_X_L(v) ((v) & GENMASK(7, 0))
- +
- +#define OV5693_OFFSET_START_Y_H_REG 0x3812
- +#define OV5693_OFFSET_START_Y_H(v) (((v) & GENMASK(15, 8)) >> 8)
- +#define OV5693_OFFSET_START_Y_L_REG 0x3813
- +#define OV5693_OFFSET_START_Y_L(v) ((v) & GENMASK(7, 0))
- +
- +#define OV5693_SUB_INC_X_REG 0x3814
- +#define OV5693_SUB_INC_Y_REG 0x3815
- +
- +#define OV5693_FORMAT1_REG 0x3820
- +#define OV5693_FORMAT1_FLIP_VERT_ISP_EN BIT(2)
- +#define OV5693_FORMAT1_FLIP_VERT_SENSOR_EN BIT(1)
- +#define OV5693_FORMAT1_VBIN_EN BIT(0)
- +#define OV5693_FORMAT2_REG 0x3821
- +#define OV5693_FORMAT2_HDR_EN BIT(7)
- +#define OV5693_FORMAT2_FLIP_HORZ_ISP_EN BIT(2)
- +#define OV5693_FORMAT2_FLIP_HORZ_SENSOR_EN BIT(1)
- +#define OV5693_FORMAT2_HBIN_EN BIT(0)
- +
- +#define OV5693_ISP_CTRL2_REG 0x5002
- +#define OV5693_ISP_SCALE_ENABLE BIT(7)
- +
- +/* Pixel Array */
- +#define OV5693_NATIVE_WIDTH 2624
- +#define OV5693_NATIVE_HEIGHT 1956
- +#define OV5693_NATIVE_START_LEFT 0
- +#define OV5693_NATIVE_START_TOP 0
- +#define OV5693_ACTIVE_WIDTH 2592
- +#define OV5693_ACTIVE_HEIGHT 1944
- +#define OV5693_ACTIVE_START_LEFT 16
- +#define OV5693_ACTIVE_START_TOP 6
- +#define OV5693_MIN_CROP_WIDTH 2
- +#define OV5693_MIN_CROP_HEIGHT 2
- +
- +/* Test Pattern */
- +#define OV5693_TEST_PATTERN_REG 0x5e00
- +#define OV5693_TEST_PATTERN_ENABLE BIT(7)
- +#define OV5693_TEST_PATTERN_ROLLING BIT(6)
- +#define OV5693_TEST_PATTERN_RANDOM 0x01
- +#define OV5693_TEST_PATTERN_BARS 0x00
- +
- +/* System Frequencies */
- +#define OV5693_XVCLK_FREQ 19200000
- +#define OV5693_LINK_FREQ_400MHZ 400000000
- +#define OV5693_PIXEL_RATE 160000000
- +
- +/* Miscellaneous */
- +#define OV5693_NUM_SUPPLIES 2
- +
- +#define to_ov5693_sensor(x) container_of(x, struct ov5693_device, sd)
- +
- +struct ov5693_reg {
- + u16 reg;
- + u8 val;
- +};
- +
- +struct ov5693_reg_list {
- + u32 num_regs;
- + const struct ov5693_reg *regs;
- +};
- +
- +struct ov5693_device {
- + struct i2c_client *client;
- + struct device *dev;
- +
- + /* Protect against concurrent changes to controls */
- + struct mutex lock;
- +
- + struct gpio_desc *reset;
- + struct gpio_desc *powerdown;
- + struct regulator_bulk_data supplies[OV5693_NUM_SUPPLIES];
- + struct clk *clk;
- +
- + struct ov5693_mode {
- + struct v4l2_rect crop;
- + struct v4l2_mbus_framefmt format;
- + bool binning_x;
- + bool binning_y;
- + unsigned int inc_x_odd;
- + unsigned int inc_y_odd;
- + unsigned int vts;
- + } mode;
- + bool streaming;
- +
- + struct v4l2_subdev sd;
- + struct media_pad pad;
- +
- + struct ov5693_v4l2_ctrls {
- + struct v4l2_ctrl_handler handler;
- + struct v4l2_ctrl *link_freq;
- + struct v4l2_ctrl *pixel_rate;
- + struct v4l2_ctrl *exposure;
- + struct v4l2_ctrl *analogue_gain;
- + struct v4l2_ctrl *digital_gain;
- + struct v4l2_ctrl *hflip;
- + struct v4l2_ctrl *vflip;
- + struct v4l2_ctrl *hblank;
- + struct v4l2_ctrl *vblank;
- + struct v4l2_ctrl *test_pattern;
- + } ctrls;
- +};
- +
- +static const struct ov5693_reg ov5693_global_regs[] = {
- + {0x3016, 0xf0},
- + {0x3017, 0xf0},
- + {0x3018, 0xf0},
- + {0x3022, 0x01},
- + {0x3028, 0x44},
- + {0x3098, 0x02},
- + {0x3099, 0x19},
- + {0x309a, 0x02},
- + {0x309b, 0x01},
- + {0x309c, 0x00},
- + {0x30a0, 0xd2},
- + {0x30a2, 0x01},
- + {0x30b2, 0x00},
- + {0x30b3, 0x7d},
- + {0x30b4, 0x03},
- + {0x30b5, 0x04},
- + {0x30b6, 0x01},
- + {0x3104, 0x21},
- + {0x3106, 0x00},
- + {0x3406, 0x01},
- + {0x3503, 0x07},
- + {0x350b, 0x40},
- + {0x3601, 0x0a},
- + {0x3602, 0x38},
- + {0x3612, 0x80},
- + {0x3620, 0x54},
- + {0x3621, 0xc7},
- + {0x3622, 0x0f},
- + {0x3625, 0x10},
- + {0x3630, 0x55},
- + {0x3631, 0xf4},
- + {0x3632, 0x00},
- + {0x3633, 0x34},
- + {0x3634, 0x02},
- + {0x364d, 0x0d},
- + {0x364f, 0xdd},
- + {0x3660, 0x04},
- + {0x3662, 0x10},
- + {0x3663, 0xf1},
- + {0x3665, 0x00},
- + {0x3666, 0x20},
- + {0x3667, 0x00},
- + {0x366a, 0x80},
- + {0x3680, 0xe0},
- + {0x3681, 0x00},
- + {0x3700, 0x42},
- + {0x3701, 0x14},
- + {0x3702, 0xa0},
- + {0x3703, 0xd8},
- + {0x3704, 0x78},
- + {0x3705, 0x02},
- + {0x370a, 0x00},
- + {0x370b, 0x20},
- + {0x370c, 0x0c},
- + {0x370d, 0x11},
- + {0x370e, 0x00},
- + {0x370f, 0x40},
- + {0x3710, 0x00},
- + {0x371a, 0x1c},
- + {0x371b, 0x05},
- + {0x371c, 0x01},
- + {0x371e, 0xa1},
- + {0x371f, 0x0c},
- + {0x3721, 0x00},
- + {0x3724, 0x10},
- + {0x3726, 0x00},
- + {0x372a, 0x01},
- + {0x3730, 0x10},
- + {0x3738, 0x22},
- + {0x3739, 0xe5},
- + {0x373a, 0x50},
- + {0x373b, 0x02},
- + {0x373c, 0x41},
- + {0x373f, 0x02},
- + {0x3740, 0x42},
- + {0x3741, 0x02},
- + {0x3742, 0x18},
- + {0x3743, 0x01},
- + {0x3744, 0x02},
- + {0x3747, 0x10},
- + {0x374c, 0x04},
- + {0x3751, 0xf0},
- + {0x3752, 0x00},
- + {0x3753, 0x00},
- + {0x3754, 0xc0},
- + {0x3755, 0x00},
- + {0x3756, 0x1a},
- + {0x3758, 0x00},
- + {0x3759, 0x0f},
- + {0x376b, 0x44},
- + {0x375c, 0x04},
- + {0x3774, 0x10},
- + {0x3776, 0x00},
- + {0x377f, 0x08},
- + {0x3780, 0x22},
- + {0x3781, 0x0c},
- + {0x3784, 0x2c},
- + {0x3785, 0x1e},
- + {0x378f, 0xf5},
- + {0x3791, 0xb0},
- + {0x3795, 0x00},
- + {0x3796, 0x64},
- + {0x3797, 0x11},
- + {0x3798, 0x30},
- + {0x3799, 0x41},
- + {0x379a, 0x07},
- + {0x379b, 0xb0},
- + {0x379c, 0x0c},
- + {0x3a04, 0x06},
- + {0x3a05, 0x14},
- + {0x3e07, 0x20},
- + {0x4000, 0x08},
- + {0x4001, 0x04},
- + {0x4004, 0x08},
- + {0x4006, 0x20},
- + {0x4008, 0x24},
- + {0x4009, 0x10},
- + {0x4058, 0x00},
- + {0x4101, 0xb2},
- + {0x4307, 0x31},
- + {0x4511, 0x05},
- + {0x4512, 0x01},
- + {0x481f, 0x30},
- + {0x4826, 0x2c},
- + {0x4d02, 0xfd},
- + {0x4d03, 0xf5},
- + {0x4d04, 0x0c},
- + {0x4d05, 0xcc},
- + {0x4837, 0x0a},
- + {0x5003, 0x20},
- + {0x5013, 0x00},
- + {0x5842, 0x01},
- + {0x5843, 0x2b},
- + {0x5844, 0x01},
- + {0x5845, 0x92},
- + {0x5846, 0x01},
- + {0x5847, 0x8f},
- + {0x5848, 0x01},
- + {0x5849, 0x0c},
- + {0x5e10, 0x0c},
- + {0x3820, 0x00},
- + {0x3821, 0x1e},
- + {0x5041, 0x14}
- +};
- +
- +static const struct ov5693_reg_list ov5693_global_setting = {
- + .num_regs = ARRAY_SIZE(ov5693_global_regs),
- + .regs = ov5693_global_regs,
- +};
- +
- +static const struct v4l2_rect ov5693_default_crop = {
- + .left = OV5693_ACTIVE_START_LEFT,
- + .top = OV5693_ACTIVE_START_TOP,
- + .width = OV5693_ACTIVE_WIDTH,
- + .height = OV5693_ACTIVE_HEIGHT,
- +};
- +
- +static const struct v4l2_mbus_framefmt ov5693_default_fmt = {
- + .width = OV5693_ACTIVE_WIDTH,
- + .height = OV5693_ACTIVE_HEIGHT,
- + .code = MEDIA_BUS_FMT_SBGGR10_1X10,
- +};
- +
- +static const s64 link_freq_menu_items[] = {
- + OV5693_LINK_FREQ_400MHZ
- +};
- +
- +static const char * const ov5693_supply_names[] = {
- + "avdd",
- + "dovdd",
- +};
- +
- +static const char * const ov5693_test_pattern_menu[] = {
- + "Disabled",
- + "Random Data",
- + "Colour Bars",
- + "Colour Bars with Rolling Bar"
- +};
- +
- +static const u8 ov5693_test_pattern_bits[] = {
- + 0,
- + OV5693_TEST_PATTERN_ENABLE | OV5693_TEST_PATTERN_RANDOM,
- + OV5693_TEST_PATTERN_ENABLE | OV5693_TEST_PATTERN_BARS,
- + OV5693_TEST_PATTERN_ENABLE | OV5693_TEST_PATTERN_BARS |
- + OV5693_TEST_PATTERN_ROLLING,
- +};
- +
- +/* I2C I/O Operations */
- +
- +static int ov5693_read_reg(struct ov5693_device *ov5693, u16 addr, u8 *value)
- +{
- + struct i2c_client *client = ov5693->client;
- + struct i2c_msg msgs[2];
- + u8 addr_buf[2];
- + u8 data_buf;
- + int ret;
- +
- + put_unaligned_be16(addr, addr_buf);
- +
- + /* Write register address */
- + msgs[0].addr = client->addr;
- + msgs[0].flags = 0;
- + msgs[0].len = ARRAY_SIZE(addr_buf);
- + msgs[0].buf = addr_buf;
- +
- + /* Read register value */
- + msgs[1].addr = client->addr;
- + msgs[1].flags = I2C_M_RD;
- + msgs[1].len = 1;
- + msgs[1].buf = &data_buf;
- +
- + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
- + if (ret != ARRAY_SIZE(msgs))
- + return -EIO;
- +
- + *value = data_buf;
- +
- + return 0;
- +}
- +
- +static void ov5693_write_reg(struct ov5693_device *ov5693, u16 addr, u8 value,
- + int *error)
- +{
- + unsigned char data[3] = { addr >> 8, addr & 0xff, value };
- + int ret;
- +
- + if (*error < 0)
- + return;
- +
- + ret = i2c_master_send(ov5693->client, data, sizeof(data));
- + if (ret < 0) {
- + dev_dbg(ov5693->dev, "i2c send error at address 0x%04x: %d\n",
- + addr, ret);
- + *error = ret;
- + }
- +}
- +
- +static int ov5693_write_reg_array(struct ov5693_device *ov5693,
- + const struct ov5693_reg_list *reglist)
- +{
- + unsigned int i;
- + int ret = 0;
- +
- + for (i = 0; i < reglist->num_regs; i++)
- + ov5693_write_reg(ov5693, reglist->regs[i].reg,
- + reglist->regs[i].val, &ret);
- +
- + return ret;
- +}
- +
- +static int ov5693_update_bits(struct ov5693_device *ov5693, u16 address,
- + u16 mask, u16 bits)
- +{
- + u8 value = 0;
- + int ret;
- +
- + ret = ov5693_read_reg(ov5693, address, &value);
- + if (ret)
- + return ret;
- +
- + value &= ~mask;
- + value |= bits;
- +
- + ov5693_write_reg(ov5693, address, value, &ret);
- +
- + return ret;
- +}
- +
- +/* V4L2 Controls Functions */
- +
- +static int ov5693_flip_vert_configure(struct ov5693_device *ov5693, bool enable)
- +{
- + u8 bits = OV5693_FORMAT1_FLIP_VERT_ISP_EN |
- + OV5693_FORMAT1_FLIP_VERT_SENSOR_EN;
- + int ret;
- +
- + ret = ov5693_update_bits(ov5693, OV5693_FORMAT1_REG, bits,
- + enable ? bits : 0);
- + if (ret)
- + return ret;
- +
- + return 0;
- +}
- +
- +static int ov5693_flip_horz_configure(struct ov5693_device *ov5693, bool enable)
- +{
- + u8 bits = OV5693_FORMAT2_FLIP_HORZ_ISP_EN |
- + OV5693_FORMAT2_FLIP_HORZ_SENSOR_EN;
- + int ret;
- +
- + ret = ov5693_update_bits(ov5693, OV5693_FORMAT2_REG, bits,
- + enable ? bits : 0);
- + if (ret)
- + return ret;
- +
- + return 0;
- +}
- +
- +static int ov5693_get_exposure(struct ov5693_device *ov5693, s32 *value)
- +{
- + u8 exposure_hh = 0, exposure_h = 0, exposure_l = 0;
- + int ret;
- +
- + ret = ov5693_read_reg(ov5693, OV5693_EXPOSURE_L_CTRL_HH_REG, &exposure_hh);
- + if (ret)
- + return ret;
- +
- + ret = ov5693_read_reg(ov5693, OV5693_EXPOSURE_L_CTRL_H_REG, &exposure_h);
- + if (ret)
- + return ret;
- +
- + ret = ov5693_read_reg(ov5693, OV5693_EXPOSURE_L_CTRL_L_REG, &exposure_l);
- + if (ret)
- + return ret;
- +
- + /* The lowest 4 bits are unsupported fractional bits */
- + *value = ((exposure_hh << 16) | (exposure_h << 8) | exposure_l) >> 4;
- +
- + return 0;
- +}
- +
- +static int ov5693_exposure_configure(struct ov5693_device *ov5693, u32 exposure)
- +{
- + int ret = 0;
- +
- + ov5693_write_reg(ov5693, OV5693_EXPOSURE_L_CTRL_HH_REG,
- + OV5693_EXPOSURE_CTRL_HH(exposure), &ret);
- + ov5693_write_reg(ov5693, OV5693_EXPOSURE_L_CTRL_H_REG,
- + OV5693_EXPOSURE_CTRL_H(exposure), &ret);
- + ov5693_write_reg(ov5693, OV5693_EXPOSURE_L_CTRL_L_REG,
- + OV5693_EXPOSURE_CTRL_L(exposure), &ret);
- +
- + return ret;
- +}
- +
- +static int ov5693_get_gain(struct ov5693_device *ov5693, u32 *gain)
- +{
- + u8 gain_l = 0, gain_h = 0;
- + int ret;
- +
- + ret = ov5693_read_reg(ov5693, OV5693_GAIN_CTRL_H_REG, &gain_h);
- + if (ret)
- + return ret;
- +
- + ret = ov5693_read_reg(ov5693, OV5693_GAIN_CTRL_L_REG, &gain_l);
- + if (ret)
- + return ret;
- +
- + /* As with exposure, the lowest 4 bits are fractional bits. */
- + *gain = ((gain_h << 8) | gain_l) >> 4;
- +
- + return ret;
- +}
- +
- +static int ov5693_digital_gain_configure(struct ov5693_device *ov5693, u32 gain)
- +{
- + int ret = 0;
- +
- + ov5693_write_reg(ov5693, OV5693_MWB_RED_GAIN_H_REG,
- + OV5693_MWB_GAIN_H_CTRL(gain), &ret);
- + ov5693_write_reg(ov5693, OV5693_MWB_RED_GAIN_L_REG,
- + OV5693_MWB_GAIN_L_CTRL(gain), &ret);
- + ov5693_write_reg(ov5693, OV5693_MWB_GREEN_GAIN_H_REG,
- + OV5693_MWB_GAIN_H_CTRL(gain), &ret);
- + ov5693_write_reg(ov5693, OV5693_MWB_GREEN_GAIN_L_REG,
- + OV5693_MWB_GAIN_L_CTRL(gain), &ret);
- + ov5693_write_reg(ov5693, OV5693_MWB_BLUE_GAIN_H_REG,
- + OV5693_MWB_GAIN_H_CTRL(gain), &ret);
- + ov5693_write_reg(ov5693, OV5693_MWB_BLUE_GAIN_L_REG,
- + OV5693_MWB_GAIN_L_CTRL(gain), &ret);
- +
- + return ret;
- +}
- +
- +static int ov5693_analog_gain_configure(struct ov5693_device *ov5693, u32 gain)
- +{
- + int ret = 0;
- +
- + ov5693_write_reg(ov5693, OV5693_GAIN_CTRL_L_REG,
- + OV5693_GAIN_CTRL_L(gain), &ret);
- + ov5693_write_reg(ov5693, OV5693_GAIN_CTRL_H_REG,
- + OV5693_GAIN_CTRL_H(gain), &ret);
- +
- + return ret;
- +}
- +
- +static int ov5693_vts_configure(struct ov5693_device *ov5693, u32 vblank)
- +{
- + u16 vts = ov5693->mode.format.height + vblank;
- + int ret = 0;
- +
- + ov5693_write_reg(ov5693, OV5693_TIMING_VTS_H_REG,
- + OV5693_TIMING_VTS_H(vts), &ret);
- + ov5693_write_reg(ov5693, OV5693_TIMING_VTS_L_REG,
- + OV5693_TIMING_VTS_L(vts), &ret);
- +
- + return ret;
- +}
- +
- +static int ov5693_test_pattern_configure(struct ov5693_device *ov5693, u32 idx)
- +{
- + int ret = 0;
- +
- + ov5693_write_reg(ov5693, OV5693_TEST_PATTERN_REG,
- + ov5693_test_pattern_bits[idx], &ret);
- +
- + return ret;
- +}
- +
- +static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
- +{
- + struct ov5693_device *ov5693 =
- + container_of(ctrl->handler, struct ov5693_device, ctrls.handler);
- + int ret = 0;
- +
- + /* If VBLANK is altered we need to update exposure to compensate */
- + if (ctrl->id == V4L2_CID_VBLANK) {
- + int exposure_max;
- +
- + exposure_max = ov5693->mode.format.height + ctrl->val -
- + OV5693_INTEGRATION_TIME_MARGIN;
- + __v4l2_ctrl_modify_range(ov5693->ctrls.exposure,
- + ov5693->ctrls.exposure->minimum,
- + exposure_max,
- + ov5693->ctrls.exposure->step,
- + min(ov5693->ctrls.exposure->val, exposure_max));
- + }
- +
- + /* Only apply changes to the controls if the device is powered up */
- + if (!pm_runtime_get_if_in_use(ov5693->dev))
- + return 0;
- +
- + switch (ctrl->id) {
- + case V4L2_CID_EXPOSURE:
- + ret = ov5693_exposure_configure(ov5693, ctrl->val);
- + break;
- + case V4L2_CID_ANALOGUE_GAIN:
- + ret = ov5693_analog_gain_configure(ov5693, ctrl->val);
- + break;
- + case V4L2_CID_DIGITAL_GAIN:
- + ret = ov5693_digital_gain_configure(ov5693, ctrl->val);
- + break;
- + case V4L2_CID_HFLIP:
- + ret = ov5693_flip_horz_configure(ov5693, !!ctrl->val);
- + break;
- + case V4L2_CID_VFLIP:
- + ret = ov5693_flip_vert_configure(ov5693, !!ctrl->val);
- + break;
- + case V4L2_CID_VBLANK:
- + ret = ov5693_vts_configure(ov5693, ctrl->val);
- + break;
- + case V4L2_CID_TEST_PATTERN:
- + ret = ov5693_test_pattern_configure(ov5693, ctrl->val);
- + break;
- + default:
- + ret = -EINVAL;
- + }
- +
- + pm_runtime_put(ov5693->dev);
- +
- + return ret;
- +}
- +
- +static int ov5693_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
- +{
- + struct ov5693_device *ov5693 =
- + container_of(ctrl->handler, struct ov5693_device, ctrls.handler);
- +
- + switch (ctrl->id) {
- + case V4L2_CID_EXPOSURE_ABSOLUTE:
- + return ov5693_get_exposure(ov5693, &ctrl->val);
- + case V4L2_CID_AUTOGAIN:
- + return ov5693_get_gain(ov5693, &ctrl->val);
- + default:
- + return -EINVAL;
- + }
- +}
- +
- +static const struct v4l2_ctrl_ops ov5693_ctrl_ops = {
- + .s_ctrl = ov5693_s_ctrl,
- + .g_volatile_ctrl = ov5693_g_volatile_ctrl
- +};
- +
- +/* System Control Functions */
- +
- +static int ov5693_mode_configure(struct ov5693_device *ov5693)
- +{
- + const struct ov5693_mode *mode = &ov5693->mode;
- + int ret = 0;
- +
- + /* Crop Start X */
- + ov5693_write_reg(ov5693, OV5693_CROP_START_X_H_REG,
- + OV5693_CROP_START_X_H(mode->crop.left), &ret);
- + ov5693_write_reg(ov5693, OV5693_CROP_START_X_L_REG,
- + OV5693_CROP_START_X_L(mode->crop.left), &ret);
- +
- + /* Offset X */
- + ov5693_write_reg(ov5693, OV5693_OFFSET_START_X_H_REG,
- + OV5693_OFFSET_START_X_H(0), &ret);
- + ov5693_write_reg(ov5693, OV5693_OFFSET_START_X_L_REG,
- + OV5693_OFFSET_START_X_L(0), &ret);
- +
- + /* Output Size X */
- + ov5693_write_reg(ov5693, OV5693_OUTPUT_SIZE_X_H_REG,
- + OV5693_OUTPUT_SIZE_X_H(mode->format.width), &ret);
- + ov5693_write_reg(ov5693, OV5693_OUTPUT_SIZE_X_L_REG,
- + OV5693_OUTPUT_SIZE_X_L(mode->format.width), &ret);
- +
- + /* Crop End X */
- + ov5693_write_reg(ov5693, OV5693_CROP_END_X_H_REG,
- + OV5693_CROP_END_X_H(mode->crop.left + mode->crop.width),
- + &ret);
- + ov5693_write_reg(ov5693, OV5693_CROP_END_X_L_REG,
- + OV5693_CROP_END_X_L(mode->crop.left + mode->crop.width),
- + &ret);
- +
- + /* Horizontal Total Size */
- + ov5693_write_reg(ov5693, OV5693_TIMING_HTS_H_REG,
- + OV5693_TIMING_HTS_H(OV5693_FIXED_PPL), &ret);
- + ov5693_write_reg(ov5693, OV5693_TIMING_HTS_L_REG,
- + OV5693_TIMING_HTS_L(OV5693_FIXED_PPL), &ret);
- +
- + /* Crop Start Y */
- + ov5693_write_reg(ov5693, OV5693_CROP_START_Y_H_REG,
- + OV5693_CROP_START_Y_H(mode->crop.top), &ret);
- + ov5693_write_reg(ov5693, OV5693_CROP_START_Y_L_REG,
- + OV5693_CROP_START_Y_L(mode->crop.top), &ret);
- +
- + /* Offset Y */
- + ov5693_write_reg(ov5693, OV5693_OFFSET_START_Y_H_REG,
- + OV5693_OFFSET_START_Y_H(0), &ret);
- + ov5693_write_reg(ov5693, OV5693_OFFSET_START_Y_L_REG,
- + OV5693_OFFSET_START_Y_L(0), &ret);
- +
- + /* Output Size Y */
- + ov5693_write_reg(ov5693, OV5693_OUTPUT_SIZE_Y_H_REG,
- + OV5693_OUTPUT_SIZE_Y_H(mode->format.height), &ret);
- + ov5693_write_reg(ov5693, OV5693_OUTPUT_SIZE_Y_L_REG,
- + OV5693_OUTPUT_SIZE_Y_L(mode->format.height), &ret);
- +
- + /* Crop End Y */
- + ov5693_write_reg(ov5693, OV5693_CROP_END_Y_H_REG,
- + OV5693_CROP_END_Y_H(mode->crop.top + mode->crop.height),
- + &ret);
- + ov5693_write_reg(ov5693, OV5693_CROP_END_Y_L_REG,
- + OV5693_CROP_END_Y_L(mode->crop.top + mode->crop.height),
- + &ret);
- +
- + /* Vertical Total Size */
- + ov5693_write_reg(ov5693, OV5693_TIMING_VTS_H_REG,
- + OV5693_TIMING_VTS_H(mode->vts), &ret);
- + ov5693_write_reg(ov5693, OV5693_TIMING_VTS_L_REG,
- + OV5693_TIMING_VTS_L(mode->vts), &ret);
- +
- + /* Subsample X increase */
- + ov5693_write_reg(ov5693, OV5693_SUB_INC_X_REG,
- + ((mode->inc_x_odd << 4) & 0xf0) | 0x01, &ret);
- + /* Subsample Y increase */
- + ov5693_write_reg(ov5693, OV5693_SUB_INC_Y_REG,
- + ((mode->inc_y_odd << 4) & 0xf0) | 0x01, &ret);
- +
- + /* Binning */
- + ret = ov5693_update_bits(ov5693, OV5693_FORMAT1_REG,
- + OV5693_FORMAT1_VBIN_EN,
- + mode->binning_y ? OV5693_FORMAT1_VBIN_EN : 0);
- + if (ret)
- + return ret;
- +
- + ret = ov5693_update_bits(ov5693, OV5693_FORMAT2_REG,
- + OV5693_FORMAT2_HBIN_EN,
- + mode->binning_x ? OV5693_FORMAT2_HBIN_EN : 0);
- +
- + return ret;
- +}
- +
- +static int ov5693_sw_standby(struct ov5693_device *ov5693, bool standby)
- +{
- + int ret = 0;
- +
- + ov5693_write_reg(ov5693, OV5693_SW_STREAM_REG,
- + standby ? OV5693_STOP_STREAMING : OV5693_START_STREAMING,
- + &ret);
- +
- + return ret;
- +}
- +
- +static int ov5693_sw_reset(struct ov5693_device *ov5693)
- +{
- + int ret = 0;
- +
- + ov5693_write_reg(ov5693, OV5693_SW_RESET_REG, OV5693_SW_RESET, &ret);
- +
- + return ret;
- +}
- +
- +static int ov5693_sensor_init(struct ov5693_device *ov5693)
- +{
- + int ret = 0;
- +
- + ret = ov5693_sw_reset(ov5693);
- + if (ret) {
- + dev_err(ov5693->dev, "%s software reset error\n", __func__);
- + return ret;
- + }
- +
- + ret = ov5693_write_reg_array(ov5693, &ov5693_global_setting);
- + if (ret) {
- + dev_err(ov5693->dev, "%s global settings error\n", __func__);
- + return ret;
- + }
- +
- + ret = ov5693_mode_configure(ov5693);
- + if (ret) {
- + dev_err(ov5693->dev, "%s mode configure error\n", __func__);
- + return ret;
- + }
- +
- + ret = ov5693_sw_standby(ov5693, true);
- + if (ret)
- + dev_err(ov5693->dev, "%s software standby error\n", __func__);
- +
- + return ret;
- +}
- +
- +static void ov5693_sensor_powerdown(struct ov5693_device *ov5693)
- +{
- + gpiod_set_value_cansleep(ov5693->reset, 1);
- + gpiod_set_value_cansleep(ov5693->powerdown, 1);
- +
- + regulator_bulk_disable(OV5693_NUM_SUPPLIES, ov5693->supplies);
- +
- + clk_disable_unprepare(ov5693->clk);
- +}
- +
- +static int ov5693_sensor_powerup(struct ov5693_device *ov5693)
- +{
- + int ret;
- +
- + gpiod_set_value_cansleep(ov5693->reset, 1);
- + gpiod_set_value_cansleep(ov5693->powerdown, 1);
- +
- + ret = clk_prepare_enable(ov5693->clk);
- + if (ret) {
- + dev_err(ov5693->dev, "Failed to enable clk\n");
- + goto fail_power;
- + }
- +
- + ret = regulator_bulk_enable(OV5693_NUM_SUPPLIES, ov5693->supplies);
- + if (ret) {
- + dev_err(ov5693->dev, "Failed to enable regulators\n");
- + goto fail_power;
- + }
- +
- + gpiod_set_value_cansleep(ov5693->powerdown, 0);
- + gpiod_set_value_cansleep(ov5693->reset, 0);
- +
- + usleep_range(5000, 7500);
- +
- + return 0;
- +
- +fail_power:
- + ov5693_sensor_powerdown(ov5693);
- + return ret;
- +}
- +
- +static int __maybe_unused ov5693_sensor_suspend(struct device *dev)
- +{
- + struct v4l2_subdev *sd = dev_get_drvdata(dev);
- + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
- +
- + ov5693_sensor_powerdown(ov5693);
- +
- + return 0;
- +}
- +
- +static int __maybe_unused ov5693_sensor_resume(struct device *dev)
- +{
- + struct v4l2_subdev *sd = dev_get_drvdata(dev);
- + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
- + int ret;
- +
- + mutex_lock(&ov5693->lock);
- +
- + ret = ov5693_sensor_powerup(ov5693);
- + if (ret)
- + goto out_unlock;
- +
- + ret = ov5693_sensor_init(ov5693);
- + if (ret) {
- + dev_err(dev, "ov5693 sensor init failure\n");
- + goto err_power;
- + }
- +
- + goto out_unlock;
- +
- +err_power:
- + ov5693_sensor_powerdown(ov5693);
- +out_unlock:
- + mutex_unlock(&ov5693->lock);
- + return ret;
- +}
- +
- +static int ov5693_detect(struct ov5693_device *ov5693)
- +{
- + u8 id_l = 0, id_h = 0;
- + u16 id = 0;
- + int ret;
- +
- + ret = ov5693_read_reg(ov5693, OV5693_REG_CHIP_ID_H, &id_h);
- + if (ret)
- + return ret;
- +
- + ret = ov5693_read_reg(ov5693, OV5693_REG_CHIP_ID_L, &id_l);
- + if (ret)
- + return ret;
- +
- + id = (id_h << 8) | id_l;
- +
- + if (id != OV5693_CHIP_ID) {
- + dev_err(ov5693->dev, "sensor ID mismatch. Found 0x%04x\n", id);
- + return -ENODEV;
- + }
- +
- + return 0;
- +}
- +
- +/* V4L2 Framework callbacks */
- +
- +static unsigned int __ov5693_calc_vts(u32 height)
- +{
- + /*
- + * We need to set a sensible default VTS for whatever format height we
- + * happen to be given from set_fmt(). This function just targets
- + * an even multiple of 30fps.
- + */
- +
- + unsigned int tgt_fps;
- +
- + tgt_fps = rounddown(OV5693_PIXEL_RATE / OV5693_FIXED_PPL / height, 30);
- +
- + return ALIGN_DOWN(OV5693_PIXEL_RATE / OV5693_FIXED_PPL / tgt_fps, 2);
- +}
- +
- +static struct v4l2_mbus_framefmt *
- +__ov5693_get_pad_format(struct ov5693_device *ov5693,
- + struct v4l2_subdev_state *state,
- + unsigned int pad, enum v4l2_subdev_format_whence which)
- +{
- + switch (which) {
- + case V4L2_SUBDEV_FORMAT_TRY:
- + return v4l2_subdev_get_try_format(&ov5693->sd, state, pad);
- + case V4L2_SUBDEV_FORMAT_ACTIVE:
- + return &ov5693->mode.format;
- + default:
- + return NULL;
- + }
- +}
- +
- +static struct v4l2_rect *
- +__ov5693_get_pad_crop(struct ov5693_device *ov5693,
- + struct v4l2_subdev_state *state,
- + unsigned int pad, enum v4l2_subdev_format_whence which)
- +{
- + switch (which) {
- + case V4L2_SUBDEV_FORMAT_TRY:
- + return v4l2_subdev_get_try_crop(&ov5693->sd, state, pad);
- + case V4L2_SUBDEV_FORMAT_ACTIVE:
- + return &ov5693->mode.crop;
- + }
- +
- + return NULL;
- +}
- +
- +static int ov5693_get_fmt(struct v4l2_subdev *sd,
- + struct v4l2_subdev_state *state,
- + struct v4l2_subdev_format *format)
- +{
- + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
- +
- + format->format = ov5693->mode.format;
- +
- + return 0;
- +}
- +
- +static int ov5693_set_fmt(struct v4l2_subdev *sd,
- + struct v4l2_subdev_state *state,
- + struct v4l2_subdev_format *format)
- +{
- + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
- + const struct v4l2_rect *crop;
- + struct v4l2_mbus_framefmt *fmt;
- + unsigned int hratio, vratio;
- + unsigned int width, height;
- + unsigned int hblank;
- + int exposure_max;
- + int ret = 0;
- +
- + crop = __ov5693_get_pad_crop(ov5693, state, format->pad, format->which);
- +
- + /*
- + * Align to two to simplify the binning calculations below, and clamp
- + * the requested format at the crop rectangle
- + */
- + width = clamp_t(unsigned int, ALIGN(format->format.width, 2),
- + OV5693_MIN_CROP_WIDTH, crop->width);
- + height = clamp_t(unsigned int, ALIGN(format->format.height, 2),
- + OV5693_MIN_CROP_HEIGHT, crop->height);
- +
- + /*
- + * We can only support setting either the dimensions of the crop rect
- + * or those dimensions binned (separately) by a factor of two.
- + */
- + hratio = clamp_t(unsigned int, DIV_ROUND_CLOSEST(crop->width, width), 1, 2);
- + vratio = clamp_t(unsigned int, DIV_ROUND_CLOSEST(crop->height, height), 1, 2);
- +
- + fmt = __ov5693_get_pad_format(ov5693, state, format->pad, format->which);
- +
- + fmt->width = crop->width / hratio;
- + fmt->height = crop->height / vratio;
- + fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
- +
- + format->format = *fmt;
- +
- + if (format->which == V4L2_SUBDEV_FORMAT_TRY)
- + return ret;
- +
- + mutex_lock(&ov5693->lock);
- +
- + ov5693->mode.binning_x = hratio > 1 ? true : false;
- + ov5693->mode.inc_x_odd = hratio > 1 ? 3 : 1;
- + ov5693->mode.binning_y = vratio > 1 ? true : false;
- + ov5693->mode.inc_y_odd = vratio > 1 ? 3 : 1;
- +
- + ov5693->mode.vts = __ov5693_calc_vts(fmt->height);
- +
- + __v4l2_ctrl_modify_range(ov5693->ctrls.vblank,
- + OV5693_TIMING_MIN_VTS,
- + OV5693_TIMING_MAX_VTS - fmt->height,
- + 1, ov5693->mode.vts - fmt->height);
- + __v4l2_ctrl_s_ctrl(ov5693->ctrls.vblank,
- + ov5693->mode.vts - fmt->height);
- +
- + hblank = OV5693_FIXED_PPL - fmt->width;
- + __v4l2_ctrl_modify_range(ov5693->ctrls.hblank, hblank, hblank, 1,
- + hblank);
- +
- + exposure_max = ov5693->mode.vts - OV5693_INTEGRATION_TIME_MARGIN;
- + __v4l2_ctrl_modify_range(ov5693->ctrls.exposure,
- + ov5693->ctrls.exposure->minimum, exposure_max,
- + ov5693->ctrls.exposure->step,
- + min(ov5693->ctrls.exposure->val, exposure_max));
- +
- + mutex_unlock(&ov5693->lock);
- + return ret;
- +}
- +
- +static int ov5693_get_selection(struct v4l2_subdev *sd,
- + struct v4l2_subdev_state *state,
- + struct v4l2_subdev_selection *sel)
- +{
- + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
- +
- + switch (sel->target) {
- + case V4L2_SEL_TGT_CROP:
- + mutex_lock(&ov5693->lock);
- + sel->r = *__ov5693_get_pad_crop(ov5693, state, sel->pad,
- + sel->which);
- + mutex_unlock(&ov5693->lock);
- + break;
- + case V4L2_SEL_TGT_NATIVE_SIZE:
- + sel->r.top = 0;
- + sel->r.left = 0;
- + sel->r.width = OV5693_NATIVE_WIDTH;
- + sel->r.height = OV5693_NATIVE_HEIGHT;
- + break;
- + case V4L2_SEL_TGT_CROP_BOUNDS:
- + case V4L2_SEL_TGT_CROP_DEFAULT:
- + sel->r.top = OV5693_ACTIVE_START_TOP;
- + sel->r.left = OV5693_ACTIVE_START_LEFT;
- + sel->r.width = OV5693_ACTIVE_WIDTH;
- + sel->r.height = OV5693_ACTIVE_HEIGHT;
- + break;
- + default:
- + return -EINVAL;
- + }
- +
- + return 0;
- +}
- +
- +static int ov5693_set_selection(struct v4l2_subdev *sd,
- + struct v4l2_subdev_state *state,
- + struct v4l2_subdev_selection *sel)
- +{
- + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
- + struct v4l2_mbus_framefmt *format;
- + struct v4l2_rect *__crop;
- + struct v4l2_rect rect;
- +
- + if (sel->target != V4L2_SEL_TGT_CROP)
- + return -EINVAL;
- +
- + /*
- + * Clamp the boundaries of the crop rectangle to the size of the sensor
- + * pixel array. Align to multiples of 2 to ensure Bayer pattern isn't
- + * disrupted.
- + */
- + rect.left = clamp(ALIGN(sel->r.left, 2), OV5693_NATIVE_START_LEFT,
- + OV5693_NATIVE_WIDTH);
- + rect.top = clamp(ALIGN(sel->r.top, 2), OV5693_NATIVE_START_TOP,
- + OV5693_NATIVE_HEIGHT);
- + rect.width = clamp_t(unsigned int, ALIGN(sel->r.width, 2),
- + OV5693_MIN_CROP_WIDTH, OV5693_NATIVE_WIDTH);
- + rect.height = clamp_t(unsigned int, ALIGN(sel->r.height, 2),
- + OV5693_MIN_CROP_HEIGHT, OV5693_NATIVE_HEIGHT);
- +
- + /* Make sure the crop rectangle isn't outside the bounds of the array */
- + rect.width = min_t(unsigned int, rect.width,
- + OV5693_NATIVE_WIDTH - rect.left);
- + rect.height = min_t(unsigned int, rect.height,
- + OV5693_NATIVE_HEIGHT - rect.top);
- +
- + __crop = __ov5693_get_pad_crop(ov5693, state, sel->pad, sel->which);
- +
- + if (rect.width != __crop->width || rect.height != __crop->height) {
- + /*
- + * Reset the output image size if the crop rectangle size has
- + * been modified.
- + */
- + format = __ov5693_get_pad_format(ov5693, state, sel->pad, sel->which);
- + format->width = rect.width;
- + format->height = rect.height;
- + }
- +
- + *__crop = rect;
- + sel->r = rect;
- +
- + return 0;
- +}
- +
- +static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
- +{
- + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
- + int ret;
- +
- + if (enable) {
- + ret = pm_runtime_get_sync(ov5693->dev);
- + if (ret < 0)
- + goto err_power_down;
- +
- + ret = __v4l2_ctrl_handler_setup(&ov5693->ctrls.handler);
- + if (ret)
- + goto err_power_down;
- + }
- +
- + mutex_lock(&ov5693->lock);
- + ret = ov5693_sw_standby(ov5693, !enable);
- + mutex_unlock(&ov5693->lock);
- +
- + if (ret)
- + goto err_power_down;
- + ov5693->streaming = !!enable;
- +
- + if (!enable)
- + pm_runtime_put(ov5693->dev);
- +
- + return 0;
- +err_power_down:
- + pm_runtime_put_noidle(ov5693->dev);
- + return ret;
- +}
- +
- +static int ov5693_g_frame_interval(struct v4l2_subdev *sd,
- + struct v4l2_subdev_frame_interval *interval)
- +{
- + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
- + unsigned int framesize = OV5693_FIXED_PPL * (ov5693->mode.format.height +
- + ov5693->ctrls.vblank->val);
- + unsigned int fps = DIV_ROUND_CLOSEST(OV5693_PIXEL_RATE, framesize);
- +
- + interval->interval.numerator = 1;
- + interval->interval.denominator = fps;
- +
- + return 0;
- +}
- +
- +static int ov5693_enum_mbus_code(struct v4l2_subdev *sd,
- + struct v4l2_subdev_state *state,
- + struct v4l2_subdev_mbus_code_enum *code)
- +{
- + /* Only a single mbus format is supported */
- + if (code->index > 0)
- + return -EINVAL;
- +
- + code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
- + return 0;
- +}
- +
- +static int ov5693_enum_frame_size(struct v4l2_subdev *sd,
- + struct v4l2_subdev_state *state,
- + struct v4l2_subdev_frame_size_enum *fse)
- +{
- + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
- + struct v4l2_rect *__crop;
- +
- + if (fse->index > 1 || fse->code != MEDIA_BUS_FMT_SBGGR10_1X10)
- + return -EINVAL;
- +
- + __crop = __ov5693_get_pad_crop(ov5693, state, fse->pad, fse->which);
- + if (!__crop)
- + return -EINVAL;
- +
- + fse->min_width = __crop->width / (fse->index + 1);
- + fse->min_height = __crop->height / (fse->index + 1);
- + fse->max_width = fse->min_width;
- + fse->max_height = fse->min_height;
- +
- + return 0;
- +}
- +
- +static const struct v4l2_subdev_video_ops ov5693_video_ops = {
- + .s_stream = ov5693_s_stream,
- + .g_frame_interval = ov5693_g_frame_interval,
- +};
- +
- +static const struct v4l2_subdev_pad_ops ov5693_pad_ops = {
- + .enum_mbus_code = ov5693_enum_mbus_code,
- + .enum_frame_size = ov5693_enum_frame_size,
- + .get_fmt = ov5693_get_fmt,
- + .set_fmt = ov5693_set_fmt,
- + .get_selection = ov5693_get_selection,
- + .set_selection = ov5693_set_selection,
- +};
- +
- +static const struct v4l2_subdev_ops ov5693_ops = {
- + .video = &ov5693_video_ops,
- + .pad = &ov5693_pad_ops,
- +};
- +
- +/* Sensor and Driver Configuration Functions */
- +
- +static int ov5693_init_controls(struct ov5693_device *ov5693)
- +{
- + const struct v4l2_ctrl_ops *ops = &ov5693_ctrl_ops;
- + struct v4l2_fwnode_device_properties props;
- + int vblank_max, vblank_def;
- + int exposure_max;
- + int hblank;
- + int ret;
- +
- + ret = v4l2_ctrl_handler_init(&ov5693->ctrls.handler, 12);
- + if (ret)
- + return ret;
- +
- + /* link freq */
- + ov5693->ctrls.link_freq = v4l2_ctrl_new_int_menu(&ov5693->ctrls.handler,
- + NULL, V4L2_CID_LINK_FREQ,
- + 0, 0, link_freq_menu_items);
- + if (ov5693->ctrls.link_freq)
- + ov5693->ctrls.link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
- +
- + /* pixel rate */
- + ov5693->ctrls.pixel_rate = v4l2_ctrl_new_std(&ov5693->ctrls.handler, NULL,
- + V4L2_CID_PIXEL_RATE, 0,
- + OV5693_PIXEL_RATE, 1,
- + OV5693_PIXEL_RATE);
- +
- + /* Exposure */
- + exposure_max = ov5693->mode.vts - OV5693_INTEGRATION_TIME_MARGIN;
- + ov5693->ctrls.exposure = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
- + V4L2_CID_EXPOSURE,
- + OV5693_EXPOSURE_MIN,
- + exposure_max,
- + OV5693_EXPOSURE_STEP,
- + exposure_max);
- +
- + /* Gain */
- + ov5693->ctrls.analogue_gain = v4l2_ctrl_new_std(&ov5693->ctrls.handler,
- + ops, V4L2_CID_ANALOGUE_GAIN,
- + OV5693_GAIN_MIN,
- + OV5693_GAIN_MAX,
- + OV5693_GAIN_STEP,
- + OV5693_GAIN_DEF);
- +
- + ov5693->ctrls.digital_gain = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
- + V4L2_CID_DIGITAL_GAIN,
- + OV5693_DIGITAL_GAIN_MIN,
- + OV5693_DIGITAL_GAIN_MAX,
- + OV5693_DIGITAL_GAIN_STEP,
- + OV5693_DIGITAL_GAIN_DEF);
- +
- + /* Flip */
- + ov5693->ctrls.hflip = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
- + V4L2_CID_HFLIP, 0, 1, 1, 0);
- +
- + ov5693->ctrls.vflip = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
- + V4L2_CID_VFLIP, 0, 1, 1, 0);
- +
- + hblank = OV5693_FIXED_PPL - ov5693->mode.format.width;
- + ov5693->ctrls.hblank = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
- + V4L2_CID_HBLANK, hblank,
- + hblank, 1, hblank);
- +
- + if (ov5693->ctrls.hblank)
- + ov5693->ctrls.hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
- +
- + vblank_max = OV5693_TIMING_MAX_VTS - ov5693->mode.format.height;
- + vblank_def = ov5693->mode.vts - ov5693->mode.format.height;
- + ov5693->ctrls.vblank = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
- + V4L2_CID_VBLANK,
- + OV5693_TIMING_MIN_VTS,
- + vblank_max, 1, vblank_def);
- +
- + ov5693->ctrls.test_pattern = v4l2_ctrl_new_std_menu_items(
- + &ov5693->ctrls.handler, ops,
- + V4L2_CID_TEST_PATTERN,
- + ARRAY_SIZE(ov5693_test_pattern_menu) - 1,
- + 0, 0, ov5693_test_pattern_menu);
- +
- + if (ov5693->ctrls.handler.error) {
- + dev_err(ov5693->dev, "Error initialising v4l2 ctrls\n");
- + ret = ov5693->ctrls.handler.error;
- + goto err_free_handler;
- + }
- +
- + /* set properties from fwnode (e.g. rotation, orientation) */
- + ret = v4l2_fwnode_device_parse(ov5693->dev, &props);
- + if (ret)
- + goto err_free_handler;
- +
- + ret = v4l2_ctrl_new_fwnode_properties(&ov5693->ctrls.handler, ops,
- + &props);
- + if (ret)
- + goto err_free_handler;
- +
- + /* Use same lock for controls as for everything else. */
- + ov5693->ctrls.handler.lock = &ov5693->lock;
- + ov5693->sd.ctrl_handler = &ov5693->ctrls.handler;
- +
- + return 0;
- +
- +err_free_handler:
- + v4l2_ctrl_handler_free(&ov5693->ctrls.handler);
- + return ret;
- +}
- +
- +static int ov5693_configure_gpios(struct ov5693_device *ov5693)
- +{
- + ov5693->reset = devm_gpiod_get_optional(ov5693->dev, "reset",
- + GPIOD_OUT_HIGH);
- + if (IS_ERR(ov5693->reset)) {
- + dev_err(ov5693->dev, "Error fetching reset GPIO\n");
- + return PTR_ERR(ov5693->reset);
- + }
- +
- + ov5693->powerdown = devm_gpiod_get_optional(ov5693->dev, "powerdown",
- + GPIOD_OUT_HIGH);
- + if (IS_ERR(ov5693->powerdown)) {
- + dev_err(ov5693->dev, "Error fetching powerdown GPIO\n");
- + return PTR_ERR(ov5693->powerdown);
- + }
- +
- + return 0;
- +}
- +
- +static int ov5693_get_regulators(struct ov5693_device *ov5693)
- +{
- + unsigned int i;
- +
- + for (i = 0; i < OV5693_NUM_SUPPLIES; i++)
- + ov5693->supplies[i].supply = ov5693_supply_names[i];
- +
- + return devm_regulator_bulk_get(ov5693->dev, OV5693_NUM_SUPPLIES,
- + ov5693->supplies);
- +}
- +
- +static int ov5693_probe(struct i2c_client *client)
- +{
- + struct fwnode_handle *fwnode = dev_fwnode(&client->dev);
- + struct fwnode_handle *endpoint;
- + struct ov5693_device *ov5693;
- + u32 clk_rate;
- + int ret = 0;
- +
- + endpoint = fwnode_graph_get_next_endpoint(fwnode, NULL);
- + if (!endpoint && !IS_ERR_OR_NULL(fwnode->secondary))
- + endpoint = fwnode_graph_get_next_endpoint(fwnode->secondary, NULL);
- + if (!endpoint)
- + return -EPROBE_DEFER;
- +
- + ov5693 = devm_kzalloc(&client->dev, sizeof(*ov5693), GFP_KERNEL);
- + if (!ov5693)
- + return -ENOMEM;
- +
- + ov5693->client = client;
- + ov5693->dev = &client->dev;
- +
- + mutex_init(&ov5693->lock);
- +
- + v4l2_i2c_subdev_init(&ov5693->sd, client, &ov5693_ops);
- +
- + ov5693->clk = devm_clk_get(&client->dev, "xvclk");
- + if (IS_ERR(ov5693->clk)) {
- + dev_err(&client->dev, "Error getting clock\n");
- + return PTR_ERR(ov5693->clk);
- + }
- +
- + clk_rate = clk_get_rate(ov5693->clk);
- + if (clk_rate != OV5693_XVCLK_FREQ) {
- + dev_err(&client->dev, "Unsupported clk freq %u, expected %u\n",
- + clk_rate, OV5693_XVCLK_FREQ);
- + return -EINVAL;
- + }
- +
- + ret = ov5693_configure_gpios(ov5693);
- + if (ret)
- + return ret;
- +
- + ret = ov5693_get_regulators(ov5693);
- + if (ret) {
- + dev_err(&client->dev, "Error fetching regulators\n");
- + return ret;
- + }
- +
- + ov5693->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
- + ov5693->pad.flags = MEDIA_PAD_FL_SOURCE;
- + ov5693->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
- +
- + ov5693->mode.crop = ov5693_default_crop;
- + ov5693->mode.format = ov5693_default_fmt;
- + ov5693->mode.vts = __ov5693_calc_vts(ov5693->mode.format.height);
- +
- + ret = ov5693_init_controls(ov5693);
- + if (ret)
- + return ret;
- +
- + ret = media_entity_pads_init(&ov5693->sd.entity, 1, &ov5693->pad);
- + if (ret)
- + goto err_ctrl_handler_free;
- +
- + /*
- + * We need the driver to work in the event that pm runtime is disable in
- + * the kernel, so power up and verify the chip now. In the event that
- + * runtime pm is disabled this will leave the chip on, so that streaming
- + * will work.
- + */
- +
- + ret = ov5693_sensor_powerup(ov5693);
- + if (ret)
- + goto err_media_entity_cleanup;
- +
- + ret = ov5693_detect(ov5693);
- + if (ret)
- + goto err_powerdown;
- +
- + pm_runtime_set_active(&client->dev);
- + pm_runtime_get_noresume(&client->dev);
- + pm_runtime_enable(&client->dev);
- +
- + ret = v4l2_async_register_subdev_sensor(&ov5693->sd);
- + if (ret) {
- + dev_err(&client->dev, "failed to register V4L2 subdev: %d",
- + ret);
- + goto err_pm_runtime;
- + }
- +
- + pm_runtime_set_autosuspend_delay(&client->dev, 1000);
- + pm_runtime_use_autosuspend(&client->dev);
- + pm_runtime_put_autosuspend(&client->dev);
- +
- + return ret;
- +
- +err_pm_runtime:
- + pm_runtime_disable(&client->dev);
- + pm_runtime_put_noidle(&client->dev);
- +err_powerdown:
- + ov5693_sensor_powerdown(ov5693);
- +err_media_entity_cleanup:
- + media_entity_cleanup(&ov5693->sd.entity);
- +err_ctrl_handler_free:
- + v4l2_ctrl_handler_free(&ov5693->ctrls.handler);
- +
- + return ret;
- +}
- +
- +static int ov5693_remove(struct i2c_client *client)
- +{
- + struct v4l2_subdev *sd = i2c_get_clientdata(client);
- + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
- +
- + v4l2_async_unregister_subdev(sd);
- + media_entity_cleanup(&ov5693->sd.entity);
- + v4l2_ctrl_handler_free(&ov5693->ctrls.handler);
- + mutex_destroy(&ov5693->lock);
- +
- + /*
- + * Disable runtime PM. In case runtime PM is disabled in the kernel,
- + * make sure to turn power off manually.
- + */
- + pm_runtime_disable(&client->dev);
- + if (!pm_runtime_status_suspended(&client->dev))
- + ov5693_sensor_powerdown(ov5693);
- + pm_runtime_set_suspended(&client->dev);
- +
- + return 0;
- +}
- +
- +static const struct dev_pm_ops ov5693_pm_ops = {
- + SET_RUNTIME_PM_OPS(ov5693_sensor_suspend, ov5693_sensor_resume, NULL)
- +};
- +
- +static const struct acpi_device_id ov5693_acpi_match[] = {
- + {"INT33BE"},
- + {},
- +};
- +MODULE_DEVICE_TABLE(acpi, ov5693_acpi_match);
- +
- +static struct i2c_driver ov5693_driver = {
- + .driver = {
- + .name = "ov5693",
- + .acpi_match_table = ov5693_acpi_match,
- + .pm = &ov5693_pm_ops,
- + },
- + .probe_new = ov5693_probe,
- + .remove = ov5693_remove,
- +};
- +module_i2c_driver(ov5693_driver);
- +
- +MODULE_DESCRIPTION("A low-level driver for OmniVision 5693 sensors");
- +MODULE_LICENSE("GPL");
- --
- 2.34.0
- From 7e9c49131077a564296f86e3d3e1813448b0fdae Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= <me@fabwu.ch>
- Date: Fri, 22 Jan 2021 20:58:13 +0100
- Subject: [PATCH] cio2-bridge: Parse sensor orientation and rotation
- MIME-Version: 1.0
- Content-Type: text/plain; charset=UTF-8
- Content-Transfer-Encoding: 8bit
- The sensor orientation is read from the _PLC ACPI buffer and converted
- to a v4l2 format.
- See https://uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf
- page 351 for a definition of the Panel property.
- The sensor rotation is read from the SSDB ACPI buffer and converted into
- degrees.
- Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
- Patchset: cameras
- ---
- drivers/media/pci/intel/ipu3/cio2-bridge.c | 45 ++++++++++++++++++++--
- drivers/media/pci/intel/ipu3/cio2-bridge.h | 3 ++
- 2 files changed, 44 insertions(+), 4 deletions(-)
- diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
- index 30d29b96a339..77c97bf6521e 100644
- --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
- +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
- @@ -29,6 +29,7 @@ static const struct cio2_sensor_config cio2_supported_sensors[] = {
- static const struct cio2_property_names prop_names = {
- .clock_frequency = "clock-frequency",
- .rotation = "rotation",
- + .orientation = "orientation",
- .bus_type = "bus-type",
- .data_lanes = "data-lanes",
- .remote_endpoint = "remote-endpoint",
- @@ -72,11 +73,36 @@ static int cio2_bridge_read_acpi_buffer(struct acpi_device *adev, char *id,
- return ret;
- }
-
- +static u32 cio2_bridge_parse_rotation(u8 rotation)
- +{
- + if (rotation == 1)
- + return 180;
- + return 0;
- +}
- +
- +static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(u8 panel)
- +{
- + switch (panel) {
- + case 4:
- + return V4L2_FWNODE_ORIENTATION_FRONT;
- + case 5:
- + return V4L2_FWNODE_ORIENTATION_BACK;
- + default:
- + return V4L2_FWNODE_ORIENTATION_EXTERNAL;
- + }
- +}
- +
- static void cio2_bridge_create_fwnode_properties(
- struct cio2_sensor *sensor,
- struct cio2_bridge *bridge,
- const struct cio2_sensor_config *cfg)
- {
- + u32 rotation;
- + enum v4l2_fwnode_orientation orientation;
- +
- + rotation = cio2_bridge_parse_rotation(sensor->ssdb.degree);
- + orientation = cio2_bridge_parse_orientation(sensor->pld->panel);
- +
- sensor->prop_names = prop_names;
-
- sensor->local_ref[0] = SOFTWARE_NODE_REFERENCE(&sensor->swnodes[SWNODE_CIO2_ENDPOINT]);
- @@ -85,9 +111,12 @@ static void cio2_bridge_create_fwnode_properties(
- sensor->dev_properties[0] = PROPERTY_ENTRY_U32(
- sensor->prop_names.clock_frequency,
- sensor->ssdb.mclkspeed);
- - sensor->dev_properties[1] = PROPERTY_ENTRY_U8(
- + sensor->dev_properties[1] = PROPERTY_ENTRY_U32(
- sensor->prop_names.rotation,
- - sensor->ssdb.degree);
- + rotation);
- + sensor->dev_properties[2] = PROPERTY_ENTRY_U32(
- + sensor->prop_names.orientation,
- + orientation);
-
- sensor->ep_properties[0] = PROPERTY_ENTRY_U32(
- sensor->prop_names.bus_type,
- @@ -159,6 +188,7 @@ static void cio2_bridge_unregister_sensors(struct cio2_bridge *bridge)
- for (i = 0; i < bridge->n_sensors; i++) {
- sensor = &bridge->sensors[i];
- software_node_unregister_nodes(sensor->swnodes);
- + ACPI_FREE(sensor->pld);
- acpi_dev_put(sensor->adev);
- }
- }
- @@ -170,6 +200,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
- struct fwnode_handle *fwnode;
- struct cio2_sensor *sensor;
- struct acpi_device *adev;
- + acpi_status status;
- int ret;
-
- for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
- @@ -191,11 +222,15 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
- if (ret)
- goto err_put_adev;
-
- + status = acpi_get_physical_device_location(adev->handle, &sensor->pld);
- + if (ACPI_FAILURE(status))
- + goto err_put_adev;
- +
- if (sensor->ssdb.lanes > CIO2_MAX_LANES) {
- dev_err(&adev->dev,
- "Number of lanes in SSDB is invalid\n");
- ret = -EINVAL;
- - goto err_put_adev;
- + goto err_free_pld;
- }
-
- cio2_bridge_create_fwnode_properties(sensor, bridge, cfg);
- @@ -203,7 +238,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
-
- ret = software_node_register_nodes(sensor->swnodes);
- if (ret)
- - goto err_put_adev;
- + goto err_free_pld;
-
- fwnode = software_node_fwnode(&sensor->swnodes[
- SWNODE_SENSOR_HID]);
- @@ -225,6 +260,8 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
-
- err_free_swnodes:
- software_node_unregister_nodes(sensor->swnodes);
- +err_free_pld:
- + ACPI_FREE(sensor->pld);
- err_put_adev:
- acpi_dev_put(adev);
- return ret;
- diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
- index dd0ffcafa489..924d99d20328 100644
- --- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
- +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
- @@ -80,6 +80,7 @@ struct cio2_sensor_ssdb {
- struct cio2_property_names {
- char clock_frequency[16];
- char rotation[9];
- + char orientation[12];
- char bus_type[9];
- char data_lanes[11];
- char remote_endpoint[16];
- @@ -106,6 +107,8 @@ struct cio2_sensor {
- struct cio2_node_names node_names;
-
- struct cio2_sensor_ssdb ssdb;
- + struct acpi_pld_info *pld;
- +
- struct cio2_property_names prop_names;
- struct property_entry ep_properties[5];
- struct property_entry dev_properties[3];
- --
- 2.34.0
- From e163137f9b923398a4d31e3a21fe78486974d0d9 Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= <me@fabwu.ch>
- Date: Sun, 24 Jan 2021 11:07:42 +0100
- Subject: [PATCH] cio2-bridge: Use macros and add warnings
- MIME-Version: 1.0
- Content-Type: text/plain; charset=UTF-8
- Content-Transfer-Encoding: 8bit
- Use macros for the _PLD panel as defined in the ACPI spec 6.3 and emit
- a warning if we see an unknown value.
- Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
- Patchset: cameras
- ---
- drivers/media/pci/intel/ipu3/cio2-bridge.c | 33 ++++++++++++++++------
- drivers/media/pci/intel/ipu3/cio2-bridge.h | 13 +++++++++
- 2 files changed, 37 insertions(+), 9 deletions(-)
- diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
- index 77c97bf6521e..7e582135dfb8 100644
- --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
- +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
- @@ -73,21 +73,36 @@ static int cio2_bridge_read_acpi_buffer(struct acpi_device *adev, char *id,
- return ret;
- }
-
- -static u32 cio2_bridge_parse_rotation(u8 rotation)
- +static u32 cio2_bridge_parse_rotation(struct cio2_sensor *sensor)
- {
- - if (rotation == 1)
- + switch (sensor->ssdb.degree) {
- + case CIO2_SENSOR_ROTATION_NORMAL:
- + return 0;
- + case CIO2_SENSOR_ROTATION_INVERTED:
- return 180;
- - return 0;
- + default:
- + dev_warn(&sensor->adev->dev,
- + "Unknown rotation %d. Assume 0 degree rotation\n",
- + sensor->ssdb.degree);
- + return 0;
- + }
- }
-
- -static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(u8 panel)
- +static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(struct cio2_sensor *sensor)
- {
- - switch (panel) {
- - case 4:
- + switch (sensor->pld->panel) {
- + case CIO2_PLD_PANEL_FRONT:
- return V4L2_FWNODE_ORIENTATION_FRONT;
- - case 5:
- + case CIO2_PLD_PANEL_BACK:
- return V4L2_FWNODE_ORIENTATION_BACK;
- + case CIO2_PLD_PANEL_TOP:
- + case CIO2_PLD_PANEL_LEFT:
- + case CIO2_PLD_PANEL_RIGHT:
- + case CIO2_PLD_PANEL_UNKNOWN:
- + return V4L2_FWNODE_ORIENTATION_EXTERNAL;
- default:
- + dev_warn(&sensor->adev->dev, "Unknown _PLD panel value %d\n",
- + sensor->pld->panel);
- return V4L2_FWNODE_ORIENTATION_EXTERNAL;
- }
- }
- @@ -100,8 +115,8 @@ static void cio2_bridge_create_fwnode_properties(
- u32 rotation;
- enum v4l2_fwnode_orientation orientation;
-
- - rotation = cio2_bridge_parse_rotation(sensor->ssdb.degree);
- - orientation = cio2_bridge_parse_orientation(sensor->pld->panel);
- + rotation = cio2_bridge_parse_rotation(sensor);
- + orientation = cio2_bridge_parse_orientation(sensor);
-
- sensor->prop_names = prop_names;
-
- diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
- index 924d99d20328..e1e388cc9f45 100644
- --- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
- +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
- @@ -12,6 +12,19 @@
- #define CIO2_MAX_LANES 4
- #define MAX_NUM_LINK_FREQS 3
-
- +/* Values are estimated guesses as we don't have a spec */
- +#define CIO2_SENSOR_ROTATION_NORMAL 0
- +#define CIO2_SENSOR_ROTATION_INVERTED 1
- +
- +/* Panel position defined in _PLD section of ACPI Specification 6.3 */
- +#define CIO2_PLD_PANEL_TOP 0
- +#define CIO2_PLD_PANEL_BOTTOM 1
- +#define CIO2_PLD_PANEL_LEFT 2
- +#define CIO2_PLD_PANEL_RIGHT 3
- +#define CIO2_PLD_PANEL_FRONT 4
- +#define CIO2_PLD_PANEL_BACK 5
- +#define CIO2_PLD_PANEL_UNKNOWN 6
- +
- #define CIO2_SENSOR_CONFIG(_HID, _NR, ...) \
- (const struct cio2_sensor_config) { \
- .hid = _HID, \
- --
- 2.34.0
- From d6e2797aba5ac844c067d177000d8a7966481adc Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= <me@fabwu.ch>
- Date: Thu, 6 May 2021 07:52:44 +0200
- Subject: [PATCH] cio2-bridge: Use correct dev_properties size
- Patchset: cameras
- ---
- drivers/media/pci/intel/ipu3/cio2-bridge.h | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
- diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
- index e1e388cc9f45..deaf5804f70d 100644
- --- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
- +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
- @@ -124,7 +124,7 @@ struct cio2_sensor {
-
- struct cio2_property_names prop_names;
- struct property_entry ep_properties[5];
- - struct property_entry dev_properties[3];
- + struct property_entry dev_properties[4];
- struct property_entry cio2_properties[3];
- struct software_node_ref_args local_ref[1];
- struct software_node_ref_args remote_ref[1];
- --
- 2.34.0
- From d12db7dfc3e8a96d138c575811131acd50f227da Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Thu, 20 May 2021 23:31:04 +0100
- Subject: [PATCH] media: i2c: Fix vertical flip in ov5693
- The pinkness experienced by users with rotated sensors in their laptops
- was due to an incorrect setting for the vertical flip function; the
- datasheet for the sensor gives the settings as bits 1&2 in one place and
- bits 1&6 in another.
- Switch to flipping bit 6 instead of bit 2 for 0x3820 in the vertical
- flip function to fix the pink hue.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov5693.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
- diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
- index 9499ee10f56c..c558f9b48c83 100644
- --- a/drivers/media/i2c/ov5693.c
- +++ b/drivers/media/i2c/ov5693.c
- @@ -133,7 +133,7 @@
- #define OV5693_SUB_INC_Y_REG 0x3815
-
- #define OV5693_FORMAT1_REG 0x3820
- -#define OV5693_FORMAT1_FLIP_VERT_ISP_EN BIT(2)
- +#define OV5693_FORMAT1_FLIP_VERT_ISP_EN BIT(6)
- #define OV5693_FORMAT1_FLIP_VERT_SENSOR_EN BIT(1)
- #define OV5693_FORMAT1_VBIN_EN BIT(0)
- #define OV5693_FORMAT2_REG 0x3821
- --
- 2.34.0
- From daec57877a80e0d8f6657619fffada365a5b6371 Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Fri, 9 Jul 2021 16:39:18 +0100
- Subject: [PATCH] media: i2c: Add ACPI support to ov8865
- The ov8865 sensor is sometimes found on x86 platforms enumerated via ACPI.
- Add an ACPI match table to the driver so that it's probed on those
- platforms.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 8 ++++++++
- 1 file changed, 8 insertions(+)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index ce50f3ea87b8..7626c8608f8f 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -9,6 +9,7 @@
- #include <linux/delay.h>
- #include <linux/device.h>
- #include <linux/i2c.h>
- +#include <linux/mod_devicetable.h>
- #include <linux/module.h>
- #include <linux/of_graph.h>
- #include <linux/pm_runtime.h>
- @@ -2946,6 +2947,12 @@ static const struct dev_pm_ops ov8865_pm_ops = {
- SET_RUNTIME_PM_OPS(ov8865_suspend, ov8865_resume, NULL)
- };
-
- +static const struct acpi_device_id ov8865_acpi_match[] = {
- + {"INT347A"},
- + { }
- +};
- +MODULE_DEVICE_TABLE(acpi, ov8865_acpi_match);
- +
- static const struct of_device_id ov8865_of_match[] = {
- { .compatible = "ovti,ov8865" },
- { }
- @@ -2956,6 +2963,7 @@ static struct i2c_driver ov8865_driver = {
- .driver = {
- .name = "ov8865",
- .of_match_table = ov8865_of_match,
- + .acpi_match_table = ov8865_acpi_match,
- .pm = &ov8865_pm_ops,
- },
- .probe_new = ov8865_probe,
- --
- 2.34.0
- From 9213ddc74a32af22cb5de8af6e0a249fa9ed8351 Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Sat, 10 Jul 2021 21:20:17 +0100
- Subject: [PATCH] media: i2c: Fix incorrect value in comment
- The PLL configuration defined here sets 72MHz (which is correct), not
- 80MHz. Correct the comment.
- Reviewed-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index 7626c8608f8f..8e3f8a554452 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -713,7 +713,7 @@ static const struct ov8865_pll2_config ov8865_pll2_config_native = {
- /*
- * EXTCLK = 24 MHz
- * DAC_CLK = 360 MHz
- - * SCLK = 80 MHz
- + * SCLK = 72 MHz
- */
-
- static const struct ov8865_pll2_config ov8865_pll2_config_binning = {
- --
- 2.34.0
- From 5c3e54c1c791a2b7781bf37572d8e8c2f602dffa Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Sat, 10 Jul 2021 22:21:52 +0100
- Subject: [PATCH] media: i2c: Defer probe if not endpoint found
- The ov8865 driver is one of those that can be connected to a CIO2
- device by the cio2-bridge code. This means that the absence of an
- endpoint for this device is not necessarily fatal, as one might be
- built by the cio2-bridge when it probes. Return -EPROBE_DEFER if no
- endpoint is found rather than a fatal error.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 6 ++----
- 1 file changed, 2 insertions(+), 4 deletions(-)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index 8e3f8a554452..9bc8d5d8199b 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -2796,10 +2796,8 @@ static int ov8865_probe(struct i2c_client *client)
- /* Graph Endpoint */
-
- handle = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
- - if (!handle) {
- - dev_err(dev, "unable to find endpoint node\n");
- - return -EINVAL;
- - }
- + if (!handle)
- + return -EPROBE_DEFER;
-
- sensor->endpoint.bus_type = V4L2_MBUS_CSI2_DPHY;
-
- --
- 2.34.0
- From d7e4c156c95f8a52d1290b245cc9b7144c2e750d Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Sat, 10 Jul 2021 22:00:25 +0100
- Subject: [PATCH] media: i2c: Support 19.2MHz input clock in ov8865
- The ov8865 driver as written expects a 24MHz input clock, but the sensor
- is sometimes found on x86 platforms with a 19.2MHz input clock supplied.
- Add a set of PLL configurations to the driver to support that rate too.
- As ACPI doesn't auto-configure the clock rate, check for a clock-frequency
- during probe and set that rate if one is found.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 186 +++++++++++++++++++++++++++----------
- 1 file changed, 135 insertions(+), 51 deletions(-)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index 9bc8d5d8199b..4ddc1b277cc0 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -21,10 +21,6 @@
- #include <media/v4l2-image-sizes.h>
- #include <media/v4l2-mediabus.h>
-
- -/* Clock rate */
- -
- -#define OV8865_EXTCLK_RATE 24000000
- -
- /* Register definitions */
-
- /* System */
- @@ -567,6 +563,25 @@ struct ov8865_sclk_config {
- unsigned int sclk_div;
- };
-
- +struct ov8865_pll_configs {
- + const struct ov8865_pll1_config *pll1_config;
- + const struct ov8865_pll2_config *pll2_config_native;
- + const struct ov8865_pll2_config *pll2_config_binning;
- +};
- +
- +/* Clock rate */
- +
- +enum extclk_rate {
- + OV8865_19_2_MHZ,
- + OV8865_24_MHZ,
- + OV8865_NUM_SUPPORTED_RATES
- +};
- +
- +static const unsigned long supported_extclk_rates[] = {
- + [OV8865_19_2_MHZ] = 19200000,
- + [OV8865_24_MHZ] = 24000000,
- +};
- +
- /*
- * General formulas for (array-centered) mode calculation:
- * - photo_array_width = 3296
- @@ -635,9 +650,7 @@ struct ov8865_mode {
-
- struct v4l2_fract frame_interval;
-
- - const struct ov8865_pll1_config *pll1_config;
- - const struct ov8865_pll2_config *pll2_config;
- - const struct ov8865_sclk_config *sclk_config;
- + bool pll2_binning;
-
- const struct ov8865_register_value *register_values;
- unsigned int register_values_count;
- @@ -665,6 +678,9 @@ struct ov8865_sensor {
- struct regulator *avdd;
- struct regulator *dvdd;
- struct regulator *dovdd;
- +
- + unsigned long extclk_rate;
- + const struct ov8865_pll_configs *pll_configs;
- struct clk *extclk;
-
- struct v4l2_fwnode_endpoint endpoint;
- @@ -680,43 +696,70 @@ struct ov8865_sensor {
- /* Static definitions */
-
- /*
- - * EXTCLK = 24 MHz
- * PHY_SCLK = 720 MHz
- * MIPI_PCLK = 90 MHz
- */
- -static const struct ov8865_pll1_config ov8865_pll1_config_native = {
- - .pll_pre_div_half = 1,
- - .pll_pre_div = 0,
- - .pll_mul = 30,
- - .m_div = 1,
- - .mipi_div = 3,
- - .pclk_div = 1,
- - .sys_pre_div = 1,
- - .sys_div = 2,
- +
- +static const struct ov8865_pll1_config ov8865_pll1_config_native_19_2mhz = {
- + .pll_pre_div_half = 1,
- + .pll_pre_div = 2,
- + .pll_mul = 75,
- + .m_div = 1,
- + .mipi_div = 3,
- + .pclk_div = 1,
- + .sys_pre_div = 1,
- + .sys_div = 2,
- +};
- +
- +static const struct ov8865_pll1_config ov8865_pll1_config_native_24mhz = {
- + .pll_pre_div_half = 1,
- + .pll_pre_div = 0,
- + .pll_mul = 30,
- + .m_div = 1,
- + .mipi_div = 3,
- + .pclk_div = 1,
- + .sys_pre_div = 1,
- + .sys_div = 2,
- };
-
- /*
- - * EXTCLK = 24 MHz
- * DAC_CLK = 360 MHz
- * SCLK = 144 MHz
- */
-
- -static const struct ov8865_pll2_config ov8865_pll2_config_native = {
- - .pll_pre_div_half = 1,
- - .pll_pre_div = 0,
- - .pll_mul = 30,
- - .dac_div = 2,
- - .sys_pre_div = 5,
- - .sys_div = 0,
- +static const struct ov8865_pll2_config ov8865_pll2_config_native_19_2mhz = {
- + .pll_pre_div_half = 1,
- + .pll_pre_div = 5,
- + .pll_mul = 75,
- + .dac_div = 1,
- + .sys_pre_div = 1,
- + .sys_div = 3,
- +};
- +
- +static const struct ov8865_pll2_config ov8865_pll2_config_native_24mhz = {
- + .pll_pre_div_half = 1,
- + .pll_pre_div = 0,
- + .pll_mul = 30,
- + .dac_div = 2,
- + .sys_pre_div = 5,
- + .sys_div = 0,
- };
-
- /*
- - * EXTCLK = 24 MHz
- * DAC_CLK = 360 MHz
- * SCLK = 72 MHz
- */
-
- -static const struct ov8865_pll2_config ov8865_pll2_config_binning = {
- +static const struct ov8865_pll2_config ov8865_pll2_config_binning_19_2mhz = {
- + .pll_pre_div_half = 1,
- + .pll_pre_div = 2,
- + .pll_mul = 75,
- + .dac_div = 2,
- + .sys_pre_div = 10,
- + .sys_div = 0,
- +};
- +
- +static const struct ov8865_pll2_config ov8865_pll2_config_binning_24mhz = {
- .pll_pre_div_half = 1,
- .pll_pre_div = 0,
- .pll_mul = 30,
- @@ -725,6 +768,23 @@ static const struct ov8865_pll2_config ov8865_pll2_config_binning = {
- .sys_div = 0,
- };
-
- +static struct ov8865_pll_configs ov8865_pll_configs_19_2mhz = {
- + .pll1_config = &ov8865_pll1_config_native_19_2mhz,
- + .pll2_config_native = &ov8865_pll2_config_native_19_2mhz,
- + .pll2_config_binning = &ov8865_pll2_config_binning_19_2mhz,
- +};
- +
- +static struct ov8865_pll_configs ov8865_pll_configs_24mhz = {
- + .pll1_config = &ov8865_pll1_config_native_24mhz,
- + .pll2_config_native = &ov8865_pll2_config_native_24mhz,
- + .pll2_config_binning = &ov8865_pll2_config_binning_24mhz,
- +};
- +
- +static const struct ov8865_pll_configs *ov8865_pll_configs[] = {
- + &ov8865_pll_configs_19_2mhz,
- + &ov8865_pll_configs_24mhz,
- +};
- +
- static const struct ov8865_sclk_config ov8865_sclk_config_native = {
- .sys_sel = 1,
- .sclk_sel = 0,
- @@ -934,9 +994,7 @@ static const struct ov8865_mode ov8865_modes[] = {
- .frame_interval = { 1, 30 },
-
- /* PLL */
- - .pll1_config = &ov8865_pll1_config_native,
- - .pll2_config = &ov8865_pll2_config_native,
- - .sclk_config = &ov8865_sclk_config_native,
- + .pll2_binning = false,
-
- /* Registers */
- .register_values = ov8865_register_values_native,
- @@ -990,9 +1048,7 @@ static const struct ov8865_mode ov8865_modes[] = {
- .frame_interval = { 1, 30 },
-
- /* PLL */
- - .pll1_config = &ov8865_pll1_config_native,
- - .pll2_config = &ov8865_pll2_config_native,
- - .sclk_config = &ov8865_sclk_config_native,
- + .pll2_binning = false,
-
- /* Registers */
- .register_values = ov8865_register_values_native,
- @@ -1050,9 +1106,7 @@ static const struct ov8865_mode ov8865_modes[] = {
- .frame_interval = { 1, 30 },
-
- /* PLL */
- - .pll1_config = &ov8865_pll1_config_native,
- - .pll2_config = &ov8865_pll2_config_binning,
- - .sclk_config = &ov8865_sclk_config_native,
- + .pll2_binning = true,
-
- /* Registers */
- .register_values = ov8865_register_values_binning,
- @@ -1116,9 +1170,7 @@ static const struct ov8865_mode ov8865_modes[] = {
- .frame_interval = { 1, 90 },
-
- /* PLL */
- - .pll1_config = &ov8865_pll1_config_native,
- - .pll2_config = &ov8865_pll2_config_binning,
- - .sclk_config = &ov8865_sclk_config_native,
- + .pll2_binning = true,
-
- /* Registers */
- .register_values = ov8865_register_values_binning,
- @@ -1513,12 +1565,11 @@ static int ov8865_isp_configure(struct ov8865_sensor *sensor)
- static unsigned long ov8865_mode_pll1_rate(struct ov8865_sensor *sensor,
- const struct ov8865_mode *mode)
- {
- - const struct ov8865_pll1_config *config = mode->pll1_config;
- - unsigned long extclk_rate;
- + const struct ov8865_pll1_config *config;
- unsigned long pll1_rate;
-
- - extclk_rate = clk_get_rate(sensor->extclk);
- - pll1_rate = extclk_rate * config->pll_mul / config->pll_pre_div_half;
- + config = sensor->pll_configs->pll1_config;
- + pll1_rate = sensor->extclk_rate * config->pll_mul / config->pll_pre_div_half;
-
- switch (config->pll_pre_div) {
- case 0:
- @@ -1552,10 +1603,12 @@ static int ov8865_mode_pll1_configure(struct ov8865_sensor *sensor,
- const struct ov8865_mode *mode,
- u32 mbus_code)
- {
- - const struct ov8865_pll1_config *config = mode->pll1_config;
- + const struct ov8865_pll1_config *config;
- u8 value;
- int ret;
-
- + config = sensor->pll_configs->pll1_config;
- +
- switch (mbus_code) {
- case MEDIA_BUS_FMT_SBGGR10_1X10:
- value = OV8865_MIPI_BIT_SEL(10);
- @@ -1622,9 +1675,12 @@ static int ov8865_mode_pll1_configure(struct ov8865_sensor *sensor,
- static int ov8865_mode_pll2_configure(struct ov8865_sensor *sensor,
- const struct ov8865_mode *mode)
- {
- - const struct ov8865_pll2_config *config = mode->pll2_config;
- + const struct ov8865_pll2_config *config;
- int ret;
-
- + config = mode->pll2_binning ? sensor->pll_configs->pll2_config_binning :
- + sensor->pll_configs->pll2_config_native;
- +
- ret = ov8865_write(sensor, OV8865_PLL_CTRL12_REG,
- OV8865_PLL_CTRL12_PRE_DIV_HALF(config->pll_pre_div_half) |
- OV8865_PLL_CTRL12_DAC_DIV(config->dac_div));
- @@ -1658,7 +1714,7 @@ static int ov8865_mode_pll2_configure(struct ov8865_sensor *sensor,
- static int ov8865_mode_sclk_configure(struct ov8865_sensor *sensor,
- const struct ov8865_mode *mode)
- {
- - const struct ov8865_sclk_config *config = mode->sclk_config;
- + const struct ov8865_sclk_config *config = &ov8865_sclk_config_native;
- int ret;
-
- ret = ov8865_write(sensor, OV8865_CLK_SEL0_REG,
- @@ -2053,9 +2109,11 @@ static int ov8865_mode_configure(struct ov8865_sensor *sensor,
- static unsigned long ov8865_mode_mipi_clk_rate(struct ov8865_sensor *sensor,
- const struct ov8865_mode *mode)
- {
- - const struct ov8865_pll1_config *config = mode->pll1_config;
- + const struct ov8865_pll1_config *config;
- unsigned long pll1_rate;
-
- + config = sensor->pll_configs->pll1_config;
- +
- pll1_rate = ov8865_mode_pll1_rate(sensor, mode);
-
- return pll1_rate / config->m_div / 2;
- @@ -2783,7 +2841,8 @@ static int ov8865_probe(struct i2c_client *client)
- struct ov8865_sensor *sensor;
- struct v4l2_subdev *subdev;
- struct media_pad *pad;
- - unsigned long rate;
- + unsigned int rate;
- + unsigned int i;
- int ret;
-
- sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
- @@ -2858,13 +2917,38 @@ static int ov8865_probe(struct i2c_client *client)
- goto error_endpoint;
- }
-
- - rate = clk_get_rate(sensor->extclk);
- - if (rate != OV8865_EXTCLK_RATE) {
- - dev_err(dev, "clock rate %lu Hz is unsupported\n", rate);
- + /*
- + * We could have either a 24MHz or 19.2MHz clock rate. Check for a
- + * clock-frequency property and if found, set that rate. This should
- + * cover the ACPI case. If the system uses devicetree then the
- + * configured rate should already be set, so we'll have to check it.
- + */
- + ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
- + &rate);
- + if (!ret) {
- + ret = clk_set_rate(sensor->extclk, rate);
- + if (ret) {
- + dev_err(dev, "failed to set clock rate\n");
- + return ret;
- + }
- + }
- +
- + sensor->extclk_rate = clk_get_rate(sensor->extclk);
- +
- + for (i = 0; i < ARRAY_SIZE(supported_extclk_rates); i++) {
- + if (sensor->extclk_rate == supported_extclk_rates[i])
- + break;
- + }
- +
- + if (i == ARRAY_SIZE(supported_extclk_rates)) {
- + dev_err(dev, "clock rate %lu Hz is unsupported\n",
- + sensor->extclk_rate);
- ret = -EINVAL;
- goto error_endpoint;
- }
-
- + sensor->pll_configs = ov8865_pll_configs[i];
- +
- /* Subdev, entity and pad */
-
- subdev = &sensor->subdev;
- --
- 2.34.0
- From 82e605cd4e01ec30e300e0c03a5c805ce311ef86 Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Sat, 10 Jul 2021 22:19:10 +0100
- Subject: [PATCH] media: i2c: Add .get_selection() support to ov8865
- The ov8865 driver's v4l2_subdev_pad_ops currently does not include
- .get_selection() - add support for that callback.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 64 ++++++++++++++++++++++++++++++++++++++
- 1 file changed, 64 insertions(+)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index 4ddc1b277cc0..0f2776390a8e 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -450,6 +450,15 @@
- #define OV8865_PRE_CTRL0_PATTERN_COLOR_SQUARES 2
- #define OV8865_PRE_CTRL0_PATTERN_BLACK 3
-
- +/* Pixel Array */
- +
- +#define OV8865_NATIVE_WIDTH 3296
- +#define OV8865_NATIVE_HEIGHT 2528
- +#define OV8865_ACTIVE_START_TOP 32
- +#define OV8865_ACTIVE_START_LEFT 80
- +#define OV8865_ACTIVE_WIDTH 3264
- +#define OV8865_ACTIVE_HEIGHT 2448
- +
- /* Macros */
-
- #define ov8865_subdev_sensor(s) \
- @@ -2756,12 +2765,67 @@ static int ov8865_enum_frame_interval(struct v4l2_subdev *subdev,
- return 0;
- }
-
- +static void
- +__ov8865_get_pad_crop(struct ov8865_sensor *sensor,
- + struct v4l2_subdev_state *state, unsigned int pad,
- + enum v4l2_subdev_format_whence which, struct v4l2_rect *r)
- +{
- + const struct ov8865_mode *mode = sensor->state.mode;
- +
- + switch (which) {
- + case V4L2_SUBDEV_FORMAT_TRY:
- + *r = *v4l2_subdev_get_try_crop(&sensor->subdev, state, pad);
- + break;
- + case V4L2_SUBDEV_FORMAT_ACTIVE:
- + r->height = mode->output_size_y;
- + r->width = mode->output_size_x;
- + r->top = (OV8865_NATIVE_HEIGHT - mode->output_size_y) / 2;
- + r->left = (OV8865_NATIVE_WIDTH - mode->output_size_x) / 2;
- + break;
- + }
- +}
- +
- +static int ov8865_get_selection(struct v4l2_subdev *subdev,
- + struct v4l2_subdev_state *state,
- + struct v4l2_subdev_selection *sel)
- +{
- + struct ov8865_sensor *sensor = ov8865_subdev_sensor(subdev);
- +
- + switch (sel->target) {
- + case V4L2_SEL_TGT_CROP:
- + mutex_lock(&sensor->mutex);
- + __ov8865_get_pad_crop(sensor, state, sel->pad,
- + sel->which, &sel->r);
- + mutex_unlock(&sensor->mutex);
- + break;
- + case V4L2_SEL_TGT_NATIVE_SIZE:
- + sel->r.top = 0;
- + sel->r.left = 0;
- + sel->r.width = OV8865_NATIVE_WIDTH;
- + sel->r.height = OV8865_NATIVE_HEIGHT;
- + break;
- + case V4L2_SEL_TGT_CROP_BOUNDS:
- + case V4L2_SEL_TGT_CROP_DEFAULT:
- + sel->r.top = OV8865_ACTIVE_START_TOP;
- + sel->r.left = OV8865_ACTIVE_START_LEFT;
- + sel->r.width = OV8865_ACTIVE_WIDTH;
- + sel->r.height = OV8865_ACTIVE_HEIGHT;
- + break;
- + default:
- + return -EINVAL;
- + }
- +
- + return 0;
- +}
- +
- static const struct v4l2_subdev_pad_ops ov8865_subdev_pad_ops = {
- .enum_mbus_code = ov8865_enum_mbus_code,
- .get_fmt = ov8865_get_fmt,
- .set_fmt = ov8865_set_fmt,
- .enum_frame_size = ov8865_enum_frame_size,
- .enum_frame_interval = ov8865_enum_frame_interval,
- + .get_selection = ov8865_get_selection,
- + .set_selection = ov8865_get_selection,
- };
-
- static const struct v4l2_subdev_ops ov8865_subdev_ops = {
- --
- 2.34.0
- From 66365119072809fd0a13addb7149ec8637b564a1 Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Sat, 10 Jul 2021 22:34:43 +0100
- Subject: [PATCH] media: i2c: Switch control to V4L2_CID_ANALOGUE_GAIN
- The V4L2_CID_GAIN control for this driver configures registers that
- the datasheet specifies as analogue gain. Switch the control's ID
- to V4L2_CID_ANALOGUE_GAIN.
- Reviewed-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 9 +++++----
- 1 file changed, 5 insertions(+), 4 deletions(-)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index 0f2776390a8e..a832938c33b6 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -2150,7 +2150,7 @@ static int ov8865_exposure_configure(struct ov8865_sensor *sensor, u32 exposure)
-
- /* Gain */
-
- -static int ov8865_gain_configure(struct ov8865_sensor *sensor, u32 gain)
- +static int ov8865_analog_gain_configure(struct ov8865_sensor *sensor, u32 gain)
- {
- int ret;
-
- @@ -2460,8 +2460,8 @@ static int ov8865_s_ctrl(struct v4l2_ctrl *ctrl)
- if (ret)
- return ret;
- break;
- - case V4L2_CID_GAIN:
- - ret = ov8865_gain_configure(sensor, ctrl->val);
- + case V4L2_CID_ANALOGUE_GAIN:
- + ret = ov8865_analog_gain_configure(sensor, ctrl->val);
- if (ret)
- return ret;
- break;
- @@ -2506,7 +2506,8 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
-
- /* Gain */
-
- - v4l2_ctrl_new_std(handler, ops, V4L2_CID_GAIN, 128, 8191, 128, 128);
- + v4l2_ctrl_new_std(handler, ops, V4L2_CID_ANALOGUE_GAIN, 128, 8191, 128,
- + 128);
-
- /* White Balance */
-
- --
- 2.34.0
- From c49266bfb501eeb85eba0420be36e42ffcbd7063 Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Mon, 12 Jul 2021 22:54:56 +0100
- Subject: [PATCH] media: i2c: Add vblank control to ov8865
- Add a V4L2_CID_VBLANK control to the ov8865 driver.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 34 ++++++++++++++++++++++++++++++++++
- 1 file changed, 34 insertions(+)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index a832938c33b6..f741c0713ca4 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -183,6 +183,8 @@
- #define OV8865_VTS_H(v) (((v) & GENMASK(11, 8)) >> 8)
- #define OV8865_VTS_L_REG 0x380f
- #define OV8865_VTS_L(v) ((v) & GENMASK(7, 0))
- +#define OV8865_TIMING_MAX_VTS 0xffff
- +#define OV8865_TIMING_MIN_VTS 0x04
- #define OV8865_OFFSET_X_H_REG 0x3810
- #define OV8865_OFFSET_X_H(v) (((v) & GENMASK(15, 8)) >> 8)
- #define OV8865_OFFSET_X_L_REG 0x3811
- @@ -675,6 +677,7 @@ struct ov8865_state {
- struct ov8865_ctrls {
- struct v4l2_ctrl *link_freq;
- struct v4l2_ctrl *pixel_rate;
- + struct v4l2_ctrl *vblank;
-
- struct v4l2_ctrl_handler handler;
- };
- @@ -2225,6 +2228,20 @@ static int ov8865_test_pattern_configure(struct ov8865_sensor *sensor,
- ov8865_test_pattern_bits[index]);
- }
-
- +/* Blanking */
- +
- +static int ov8865_vts_configure(struct ov8865_sensor *sensor, u32 vblank)
- +{
- + u16 vts = sensor->state.mode->output_size_y + vblank;
- + int ret;
- +
- + ret = ov8865_write(sensor, OV8865_VTS_H_REG, OV8865_VTS_H(vts));
- + if (ret)
- + return ret;
- +
- + return ov8865_write(sensor, OV8865_VTS_L_REG, OV8865_VTS_L(vts));
- +}
- +
- /* State */
-
- static int ov8865_state_mipi_configure(struct ov8865_sensor *sensor,
- @@ -2476,6 +2493,8 @@ static int ov8865_s_ctrl(struct v4l2_ctrl *ctrl)
- case V4L2_CID_TEST_PATTERN:
- index = (unsigned int)ctrl->val;
- return ov8865_test_pattern_configure(sensor, index);
- + case V4L2_CID_VBLANK:
- + return ov8865_vts_configure(sensor, ctrl->val);
- default:
- return -EINVAL;
- }
- @@ -2492,6 +2511,8 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
- struct ov8865_ctrls *ctrls = &sensor->ctrls;
- struct v4l2_ctrl_handler *handler = &ctrls->handler;
- const struct v4l2_ctrl_ops *ops = &ov8865_ctrl_ops;
- + const struct ov8865_mode *mode = sensor->state.mode;
- + unsigned int vblank_max, vblank_def;
- int ret;
-
- v4l2_ctrl_handler_init(handler, 32);
- @@ -2528,6 +2549,13 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
- ARRAY_SIZE(ov8865_test_pattern_menu) - 1,
- 0, 0, ov8865_test_pattern_menu);
-
- + /* Blanking */
- + vblank_max = OV8865_TIMING_MAX_VTS - mode->output_size_y;
- + vblank_def = mode->vts - mode->output_size_y;
- + ctrls->vblank = v4l2_ctrl_new_std(handler, ops, V4L2_CID_VBLANK,
- + OV8865_TIMING_MIN_VTS, vblank_max, 1,
- + vblank_def);
- +
- /* MIPI CSI-2 */
-
- ctrls->link_freq =
- @@ -2708,6 +2736,10 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev,
- sensor->state.mbus_code != mbus_code)
- ret = ov8865_state_configure(sensor, mode, mbus_code);
-
- + __v4l2_ctrl_modify_range(sensor->ctrls.vblank, OV8865_TIMING_MIN_VTS,
- + OV8865_TIMING_MAX_VTS - mode->output_size_y,
- + 1, mode->vts - mode->output_size_y);
- +
- complete:
- mutex_unlock(&sensor->mutex);
-
- @@ -3035,6 +3067,8 @@ static int ov8865_probe(struct i2c_client *client)
-
- /* Sensor */
-
- + sensor->state.mode = &ov8865_modes[0];
- +
- ret = ov8865_ctrls_init(sensor);
- if (ret)
- goto error_mutex;
- --
- 2.34.0
- From 808fd37ee10d2cca8e039c3ae88cb8a9191b3eed Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Tue, 13 Jul 2021 23:40:33 +0100
- Subject: [PATCH] media: i2c: Add hblank control to ov8865
- Add a V4L2_CID_HBLANK control to the ov8865 driver. This is read only
- with timing control intended to be done via vblanking alone.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 14 ++++++++++++++
- 1 file changed, 14 insertions(+)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index f741c0713ca4..4b18cc80f985 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -677,6 +677,7 @@ struct ov8865_state {
- struct ov8865_ctrls {
- struct v4l2_ctrl *link_freq;
- struct v4l2_ctrl *pixel_rate;
- + struct v4l2_ctrl *hblank;
- struct v4l2_ctrl *vblank;
-
- struct v4l2_ctrl_handler handler;
- @@ -2513,6 +2514,7 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
- const struct v4l2_ctrl_ops *ops = &ov8865_ctrl_ops;
- const struct ov8865_mode *mode = sensor->state.mode;
- unsigned int vblank_max, vblank_def;
- + unsigned int hblank;
- int ret;
-
- v4l2_ctrl_handler_init(handler, 32);
- @@ -2550,6 +2552,13 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
- 0, 0, ov8865_test_pattern_menu);
-
- /* Blanking */
- + hblank = mode->hts - mode->output_size_x;
- + ctrls->hblank = v4l2_ctrl_new_std(handler, ops, V4L2_CID_HBLANK, hblank,
- + hblank, 1, hblank);
- +
- + if (ctrls->hblank)
- + ctrls->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
- +
- vblank_max = OV8865_TIMING_MAX_VTS - mode->output_size_y;
- vblank_def = mode->vts - mode->output_size_y;
- ctrls->vblank = v4l2_ctrl_new_std(handler, ops, V4L2_CID_VBLANK,
- @@ -2696,6 +2705,7 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev,
- struct v4l2_mbus_framefmt *mbus_format = &format->format;
- const struct ov8865_mode *mode;
- u32 mbus_code = 0;
- + unsigned int hblank;
- unsigned int index;
- int ret = 0;
-
- @@ -2740,6 +2750,10 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev,
- OV8865_TIMING_MAX_VTS - mode->output_size_y,
- 1, mode->vts - mode->output_size_y);
-
- + hblank = mode->hts - mode->output_size_x;
- + __v4l2_ctrl_modify_range(sensor->ctrls.hblank, hblank, hblank, 1,
- + hblank);
- +
- complete:
- mutex_unlock(&sensor->mutex);
-
- --
- 2.34.0
- From 94ef87e674e1e6a3585b34aebf00c612f189c7ec Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Wed, 20 Oct 2021 22:43:54 +0100
- Subject: [PATCH] media: i2c: Update HTS values in ov8865
- The HTS values for some of the modes in the ov8865 driver are a bit
- unusual, coming in lower than the output_size_x is set to. It seems
- like they might be calculated to fit the desired framerate into a
- configuration with just two data lanes. To bring this more in line
- with expected behaviour, raise the HTS values above the output_size_x.
- The corollary of that change is that the hardcoded frame intervals
- against the modes no longer make sense, so remove those entirely.
- Update the .g/s_frame_interval() callbacks to calculate the frame
- interval based on the current mode and the vblank and hblank settings
- plus the number of data lanes detected from firmware.
- The implementation of the .enum_frame_interval() callback is no longer
- suitable since the possible frame rate is now a continuous range depending
- on the vblank control setting, so remove that callback entirely.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 65 +++++++-------------------------------
- 1 file changed, 11 insertions(+), 54 deletions(-)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index 4b18cc80f985..1b8674152750 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -659,8 +659,6 @@ struct ov8865_mode {
- unsigned int blc_anchor_right_start;
- unsigned int blc_anchor_right_end;
-
- - struct v4l2_fract frame_interval;
- -
- bool pll2_binning;
-
- const struct ov8865_register_value *register_values;
- @@ -964,7 +962,7 @@ static const struct ov8865_mode ov8865_modes[] = {
- {
- /* Horizontal */
- .output_size_x = 3264,
- - .hts = 1944,
- + .hts = 3888,
-
- /* Vertical */
- .output_size_y = 2448,
- @@ -1003,9 +1001,6 @@ static const struct ov8865_mode ov8865_modes[] = {
- .blc_anchor_right_start = 1984,
- .blc_anchor_right_end = 2239,
-
- - /* Frame Interval */
- - .frame_interval = { 1, 30 },
- -
- /* PLL */
- .pll2_binning = false,
-
- @@ -1018,11 +1013,11 @@ static const struct ov8865_mode ov8865_modes[] = {
- {
- /* Horizontal */
- .output_size_x = 3264,
- - .hts = 2582,
- + .hts = 3888,
-
- /* Vertical */
- .output_size_y = 1836,
- - .vts = 2002,
- + .vts = 2470,
-
- .size_auto = true,
- .size_auto_boundary_x = 8,
- @@ -1057,9 +1052,6 @@ static const struct ov8865_mode ov8865_modes[] = {
- .blc_anchor_right_start = 1984,
- .blc_anchor_right_end = 2239,
-
- - /* Frame Interval */
- - .frame_interval = { 1, 30 },
- -
- /* PLL */
- .pll2_binning = false,
-
- @@ -1115,9 +1107,6 @@ static const struct ov8865_mode ov8865_modes[] = {
- .blc_anchor_right_start = 992,
- .blc_anchor_right_end = 1119,
-
- - /* Frame Interval */
- - .frame_interval = { 1, 30 },
- -
- /* PLL */
- .pll2_binning = true,
-
- @@ -1179,9 +1168,6 @@ static const struct ov8865_mode ov8865_modes[] = {
- .blc_anchor_right_start = 992,
- .blc_anchor_right_end = 1119,
-
- - /* Frame Interval */
- - .frame_interval = { 1, 90 },
- -
- /* PLL */
- .pll2_binning = true,
-
- @@ -2628,11 +2614,18 @@ static int ov8865_g_frame_interval(struct v4l2_subdev *subdev,
- {
- struct ov8865_sensor *sensor = ov8865_subdev_sensor(subdev);
- const struct ov8865_mode *mode;
- + unsigned int framesize;
- + unsigned int fps;
-
- mutex_lock(&sensor->mutex);
-
- mode = sensor->state.mode;
- - interval->interval = mode->frame_interval;
- + framesize = mode->hts * (mode->output_size_y +
- + sensor->ctrls.vblank->val);
- + fps = DIV_ROUND_CLOSEST(sensor->ctrls.pixel_rate->val, framesize);
- +
- + interval->interval.numerator = 1;
- + interval->interval.denominator = fps;
-
- mutex_unlock(&sensor->mutex);
-
- @@ -2777,41 +2770,6 @@ static int ov8865_enum_frame_size(struct v4l2_subdev *subdev,
- return 0;
- }
-
- -static int ov8865_enum_frame_interval(struct v4l2_subdev *subdev,
- - struct v4l2_subdev_state *sd_state,
- - struct v4l2_subdev_frame_interval_enum *interval_enum)
- -{
- - const struct ov8865_mode *mode = NULL;
- - unsigned int mode_index;
- - unsigned int interval_index;
- -
- - if (interval_enum->index > 0)
- - return -EINVAL;
- - /*
- - * Multiple modes with the same dimensions may have different frame
- - * intervals, so look up each relevant mode.
- - */
- - for (mode_index = 0, interval_index = 0;
- - mode_index < ARRAY_SIZE(ov8865_modes); mode_index++) {
- - mode = &ov8865_modes[mode_index];
- -
- - if (mode->output_size_x == interval_enum->width &&
- - mode->output_size_y == interval_enum->height) {
- - if (interval_index == interval_enum->index)
- - break;
- -
- - interval_index++;
- - }
- - }
- -
- - if (mode_index == ARRAY_SIZE(ov8865_modes))
- - return -EINVAL;
- -
- - interval_enum->interval = mode->frame_interval;
- -
- - return 0;
- -}
- -
- static void
- __ov8865_get_pad_crop(struct ov8865_sensor *sensor,
- struct v4l2_subdev_state *state, unsigned int pad,
- @@ -2870,7 +2828,6 @@ static const struct v4l2_subdev_pad_ops ov8865_subdev_pad_ops = {
- .get_fmt = ov8865_get_fmt,
- .set_fmt = ov8865_set_fmt,
- .enum_frame_size = ov8865_enum_frame_size,
- - .enum_frame_interval = ov8865_enum_frame_interval,
- .get_selection = ov8865_get_selection,
- .set_selection = ov8865_get_selection,
- };
- --
- 2.34.0
- From 34188431bc1debbcba03078f71629f03a044343a Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Tue, 13 Jul 2021 23:43:17 +0100
- Subject: [PATCH] media: i2c: cap exposure at height + vblank in ov8865
- Exposure limits depend on the total height; when vblank is altered (and
- thus the total height is altered), change the exposure limits to reflect
- the new cap.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 26 ++++++++++++++++++++++++--
- 1 file changed, 24 insertions(+), 2 deletions(-)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index 1b8674152750..99548ad15dcd 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -677,6 +677,7 @@ struct ov8865_ctrls {
- struct v4l2_ctrl *pixel_rate;
- struct v4l2_ctrl *hblank;
- struct v4l2_ctrl *vblank;
- + struct v4l2_ctrl *exposure;
-
- struct v4l2_ctrl_handler handler;
- };
- @@ -2454,6 +2455,19 @@ static int ov8865_s_ctrl(struct v4l2_ctrl *ctrl)
- unsigned int index;
- int ret;
-
- + /* If VBLANK is altered we need to update exposure to compensate */
- + if (ctrl->id == V4L2_CID_VBLANK) {
- + int exposure_max;
- +
- + exposure_max = sensor->state.mode->output_size_y + ctrl->val;
- + __v4l2_ctrl_modify_range(sensor->ctrls.exposure,
- + sensor->ctrls.exposure->minimum,
- + exposure_max,
- + sensor->ctrls.exposure->step,
- + min(sensor->ctrls.exposure->val,
- + exposure_max));
- + }
- +
- /* Wait for the sensor to be on before setting controls. */
- if (pm_runtime_suspended(sensor->dev))
- return 0;
- @@ -2510,8 +2524,8 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
-
- /* Exposure */
-
- - v4l2_ctrl_new_std(handler, ops, V4L2_CID_EXPOSURE, 16, 1048575, 16,
- - 512);
- + ctrls->exposure = v4l2_ctrl_new_std(handler, ops, V4L2_CID_EXPOSURE, 16,
- + 1048575, 16, 512);
-
- /* Gain */
-
- @@ -2700,6 +2714,7 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev,
- u32 mbus_code = 0;
- unsigned int hblank;
- unsigned int index;
- + int exposure_max;
- int ret = 0;
-
- mutex_lock(&sensor->mutex);
- @@ -2747,6 +2762,13 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev,
- __v4l2_ctrl_modify_range(sensor->ctrls.hblank, hblank, hblank, 1,
- hblank);
-
- + exposure_max = mode->vts;
- + __v4l2_ctrl_modify_range(sensor->ctrls.exposure,
- + sensor->ctrls.exposure->minimum, exposure_max,
- + sensor->ctrls.exposure->step,
- + min(sensor->ctrls.exposure->val,
- + exposure_max));
- +
- complete:
- mutex_unlock(&sensor->mutex);
-
- --
- 2.34.0
- From 50e23908b0e79c2f2b936b136b6050fae46fed5c Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Fri, 16 Jul 2021 22:56:15 +0100
- Subject: [PATCH] media: i2c: Add controls from fwnode to ov8865
- Add V4L2_CID_CAMERA_ORIENTATION and V4L2_CID_CAMERA_SENSOR_ROTATION
- controls to the ov8865 driver by attempting to parse them from firmware.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 10 ++++++++++
- 1 file changed, 10 insertions(+)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index 99548ad15dcd..dfb5095ef16b 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -2513,6 +2513,7 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
- struct v4l2_ctrl_handler *handler = &ctrls->handler;
- const struct v4l2_ctrl_ops *ops = &ov8865_ctrl_ops;
- const struct ov8865_mode *mode = sensor->state.mode;
- + struct v4l2_fwnode_device_properties props;
- unsigned int vblank_max, vblank_def;
- unsigned int hblank;
- int ret;
- @@ -2576,6 +2577,15 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
- v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE, 1,
- INT_MAX, 1, 1);
-
- + /* set properties from fwnode (e.g. rotation, orientation) */
- + ret = v4l2_fwnode_device_parse(sensor->dev, &props);
- + if (ret)
- + goto error_ctrls;
- +
- + ret = v4l2_ctrl_new_fwnode_properties(handler, ops, &props);
- + if (ret)
- + goto error_ctrls;
- +
- if (handler->error) {
- ret = handler->error;
- goto error_ctrls;
- --
- 2.34.0
- From 6464bee63f9a1de50640765b8942e142d8e73d3c Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Fri, 16 Jul 2021 00:00:54 +0100
- Subject: [PATCH] media: i2c: Switch exposure control unit to lines
- The ov8865 driver currently has the unit of the V4L2_CID_EXPOSURE control
- as 1/16th of a line. This is what the sensor expects, but isn't very
- intuitive. Switch the control to be in units of a line and simply do the
- 16x multiplication before passing the value to the sensor.
- The datasheet for this sensor gives minimum exposure as 2 lines, so take
- the opportunity to correct the lower bounds of the control.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 7 +++++--
- 1 file changed, 5 insertions(+), 2 deletions(-)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index dfb5095ef16b..5f19d82554df 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -2125,6 +2125,9 @@ static int ov8865_exposure_configure(struct ov8865_sensor *sensor, u32 exposure)
- {
- int ret;
-
- + /* The sensor stores exposure in units of 1/16th of a line */
- + exposure *= 16;
- +
- ret = ov8865_write(sensor, OV8865_EXPOSURE_CTRL_HH_REG,
- OV8865_EXPOSURE_CTRL_HH(exposure));
- if (ret)
- @@ -2525,8 +2528,8 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
-
- /* Exposure */
-
- - ctrls->exposure = v4l2_ctrl_new_std(handler, ops, V4L2_CID_EXPOSURE, 16,
- - 1048575, 16, 512);
- + ctrls->exposure = v4l2_ctrl_new_std(handler, ops, V4L2_CID_EXPOSURE, 2,
- + 65535, 1, 32);
-
- /* Gain */
-
- --
- 2.34.0
- From db9b9acd48871e17f9b2ebb11c77a3512496e154 Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Tue, 24 Aug 2021 22:39:02 +0100
- Subject: [PATCH] media: i2c: Re-order runtime pm initialisation
- The kerneldoc for pm_runtime_set_suspended() says:
- "It is not valid to call this function for devices with runtime PM
- enabled"
- To satisfy that requirement, re-order the calls so that
- pm_runtime_enable() is the last one.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index 5f19d82554df..18b5f1e8e9a7 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -3085,8 +3085,8 @@ static int ov8865_probe(struct i2c_client *client)
-
- /* Runtime PM */
-
- - pm_runtime_enable(sensor->dev);
- pm_runtime_set_suspended(sensor->dev);
- + pm_runtime_enable(sensor->dev);
-
- /* V4L2 subdev register */
-
- --
- 2.34.0
- From 4be77309a0952399f9ff05ce08129ddc35936c77 Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Tue, 24 Aug 2021 23:17:39 +0100
- Subject: [PATCH] media: i2c: Use dev_err_probe() in ov8865
- There is a chance that regulator_get() returns -EPROBE_DEFER, in which
- case printing an error message is undesirable. To avoid spurious messages
- in dmesg in the event that -EPROBE_DEFER is returned, use dev_err_probe()
- on error paths for regulator_get().
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 46 +++++++++++++++++---------------------
- 1 file changed, 20 insertions(+), 26 deletions(-)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index 18b5f1e8e9a7..19e6bebf340d 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -2955,6 +2955,26 @@ static int ov8865_probe(struct i2c_client *client)
- sensor->dev = dev;
- sensor->i2c_client = client;
-
- + /* Regulators */
- +
- + /* DVDD: digital core */
- + sensor->dvdd = devm_regulator_get(dev, "dvdd");
- + if (IS_ERR(sensor->dvdd))
- + return dev_err_probe(dev, PTR_ERR(sensor->dvdd),
- + "cannot get DVDD regulator\n");
- +
- + /* DOVDD: digital I/O */
- + sensor->dovdd = devm_regulator_get(dev, "dovdd");
- + if (IS_ERR(sensor->dovdd))
- + return dev_err_probe(dev, PTR_ERR(sensor->dovdd),
- + "cannot get DOVDD regulator\n");
- +
- + /* AVDD: analog */
- + sensor->avdd = devm_regulator_get(dev, "avdd");
- + if (IS_ERR(sensor->avdd))
- + return dev_err_probe(dev, PTR_ERR(sensor->avdd),
- + "cannot get AVDD regulator\n");
- +
- /* Graph Endpoint */
-
- handle = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
- @@ -2985,32 +3005,6 @@ static int ov8865_probe(struct i2c_client *client)
- goto error_endpoint;
- }
-
- - /* Regulators */
- -
- - /* DVDD: digital core */
- - sensor->dvdd = devm_regulator_get(dev, "dvdd");
- - if (IS_ERR(sensor->dvdd)) {
- - dev_err(dev, "cannot get DVDD (digital core) regulator\n");
- - ret = PTR_ERR(sensor->dvdd);
- - goto error_endpoint;
- - }
- -
- - /* DOVDD: digital I/O */
- - sensor->dovdd = devm_regulator_get(dev, "dovdd");
- - if (IS_ERR(sensor->dovdd)) {
- - dev_err(dev, "cannot get DOVDD (digital I/O) regulator\n");
- - ret = PTR_ERR(sensor->dovdd);
- - goto error_endpoint;
- - }
- -
- - /* AVDD: analog */
- - sensor->avdd = devm_regulator_get(dev, "avdd");
- - if (IS_ERR(sensor->avdd)) {
- - dev_err(dev, "cannot get AVDD (analog) regulator\n");
- - ret = PTR_ERR(sensor->avdd);
- - goto error_endpoint;
- - }
- -
- /* External Clock */
-
- sensor->extclk = devm_clk_get(dev, NULL);
- --
- 2.34.0
- From 8058a58388e75455a71addd0f9c2bc8fba1ab0ad Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Wed, 14 Jul 2021 00:05:04 +0100
- Subject: [PATCH] media: ipu3-cio2: Add INT347A to cio2-bridge
- ACPI _HID INT347A represents the OV8865 sensor, the driver for which can
- support the platforms that the cio2-bridge serves. Add it to the array
- of supported sensors so the bridge will connect the sensor to the CIO2
- device.
- Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/pci/intel/ipu3/cio2-bridge.c | 2 ++
- 1 file changed, 2 insertions(+)
- diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
- index 7e582135dfb8..0132f0bd9b41 100644
- --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
- +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
- @@ -22,6 +22,8 @@
- static const struct cio2_sensor_config cio2_supported_sensors[] = {
- /* Omnivision OV5693 */
- CIO2_SENSOR_CONFIG("INT33BE", 0),
- + /* Omnivision OV8865 */
- + CIO2_SENSOR_CONFIG("INT347A", 1, 360000000),
- /* Omnivision OV2680 */
- CIO2_SENSOR_CONFIG("OVTI2680", 0),
- };
- --
- 2.34.0
- From 20864ac9a8f63bfb299e092dba9fe8534aa46a10 Mon Sep 17 00:00:00 2001
- From: Hans de Goede <hdegoede@redhat.com>
- Date: Thu, 7 Oct 2021 15:34:52 +0200
- Subject: [PATCH] media: i2c: ov8865: Fix lockdep error
- ov8865_state_init() calls ov8865_state_mipi_configure() which uses
- __v4l2_ctrl_s_ctrl[_int64](). This means that sensor->mutex (which
- is also sensor->ctrls.handler.lock) must be locked before calling
- ov8865_state_init().
- Note ov8865_state_mipi_configure() is also used in other places where
- the lock is already held so it cannot be changed itself.
- This fixes the following lockdep kernel WARN:
- [ 13.233413] ------------[ cut here ]------------
- [ 13.233421] WARNING: CPU: 0 PID: 8 at drivers/media/v4l2-core/v4l2-ctrls-api.c:833 __v4l2_ctrl_s_ctrl+0x4d/0x60 [videodev]
- ...
- [ 13.234063] Call Trace:
- [ 13.234074] ov8865_state_configure+0x98b/0xc00 [ov8865]
- [ 13.234095] ov8865_probe+0x4b1/0x54c [ov8865]
- [ 13.234117] i2c_device_probe+0x13c/0x2d0
- Signed-off-by: Hans de Goede <hdegoede@redhat.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 2 ++
- 1 file changed, 2 insertions(+)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index 19e6bebf340d..d5af8aedf5e8 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -3073,7 +3073,9 @@ static int ov8865_probe(struct i2c_client *client)
- if (ret)
- goto error_mutex;
-
- + mutex_lock(&sensor->mutex);
- ret = ov8865_state_init(sensor);
- + mutex_unlock(&sensor->mutex);
- if (ret)
- goto error_ctrls;
-
- --
- 2.34.0
- From 719656084e09243f5ad1a6f795d5f74dd72f4867 Mon Sep 17 00:00:00 2001
- From: Hans de Goede <hdegoede@redhat.com>
- Date: Sun, 10 Oct 2021 20:56:57 +0200
- Subject: [PATCH] ACPI: delay enumeration of devices with a _DEP pointing to an
- INT3472 device
- The clk and regulator frameworks expect clk/regulator consumer-devices
- to have info about the consumed clks/regulators described in the device's
- fw_node.
- To work around cases where this info is not present in the firmware tables,
- which is often the case on x86/ACPI devices, both frameworks allow the
- provider-driver to attach info about consumers to the clks/regulators
- when registering these.
- This causes problems with the probe ordering wrt drivers for consumers
- of these clks/regulators. Since the lookups are only registered when the
- provider-driver binds, trying to get these clks/regulators before then
- results in a -ENOENT error for clks and a dummy regulator for regulators.
- One case where we hit this issue is camera sensors such as e.g. the OV8865
- sensor found on the Microsoft Surface Go. The sensor uses clks, regulators
- and GPIOs provided by a TPS68470 PMIC which is described in an INT3472
- ACPI device. There is special platform code handling this and setting
- platform_data with the necessary consumer info on the MFD cells
- instantiated for the PMIC under: drivers/platform/x86/intel/int3472.
- For this to work properly the ov8865 driver must not bind to the I2C-client
- for the OV8865 sensor until after the TPS68470 PMIC gpio, regulator and
- clk MFD cells have all been fully setup.
- The OV8865 on the Microsoft Surface Go is just one example, all X86
- devices using the Intel IPU3 camera block found on recent Intel SoCs
- have similar issues where there is an INT3472 HID ACPI-device, which
- describes the clks and regulators, and the driver for this INT3472 device
- must be fully initialized before the sensor driver (any sensor driver)
- binds for things to work properly.
- On these devices the ACPI nodes describing the sensors all have a _DEP
- dependency on the matching INT3472 ACPI device (there is one per sensor).
- This allows solving the probe-ordering problem by delaying the enumeration
- (instantiation of the I2C-client in the ov8865 example) of ACPI-devices
- which have a _DEP dependency on an INT3472 device.
- The new acpi_dev_ready_for_enumeration() helper used for this is also
- exported because for devices, which have the enumeration_by_parent flag
- set, the parent-driver will do its own scan of child ACPI devices and
- it will try to enumerate those during its probe(). Code doing this such
- as e.g. the i2c-core-acpi.c code must call this new helper to ensure
- that it too delays the enumeration until all the _DEP dependencies are
- met on devices which have the new honor_deps flag set.
- Signed-off-by: Hans de Goede <hdegoede@redhat.com>
- Patchset: cameras
- ---
- drivers/acpi/scan.c | 36 ++++++++++++++++++++++++++++++++++--
- include/acpi/acpi_bus.h | 5 ++++-
- 2 files changed, 38 insertions(+), 3 deletions(-)
- diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
- index ae9464091f1b..4a5cc1d695b4 100644
- --- a/drivers/acpi/scan.c
- +++ b/drivers/acpi/scan.c
- @@ -797,6 +797,12 @@ static const char * const acpi_ignore_dep_ids[] = {
- NULL
- };
-
- +/* List of HIDs for which we honor deps of matching ACPI devs, when checking _DEP lists. */
- +static const char * const acpi_honor_dep_ids[] = {
- + "INT3472", /* Camera sensor PMIC / clk and regulator info */
- + NULL
- +};
- +
- static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)
- {
- struct acpi_device *device = NULL;
- @@ -1758,8 +1764,12 @@ static void acpi_scan_dep_init(struct acpi_device *adev)
- struct acpi_dep_data *dep;
-
- list_for_each_entry(dep, &acpi_dep_list, node) {
- - if (dep->consumer == adev->handle)
- + if (dep->consumer == adev->handle) {
- + if (dep->honor_dep)
- + adev->flags.honor_deps = 1;
- +
- adev->dep_unmet++;
- + }
- }
- }
-
- @@ -1963,7 +1973,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)
- for (count = 0, i = 0; i < dep_devices.count; i++) {
- struct acpi_device_info *info;
- struct acpi_dep_data *dep;
- - bool skip;
- + bool skip, honor_dep;
-
- status = acpi_get_object_info(dep_devices.handles[i], &info);
- if (ACPI_FAILURE(status)) {
- @@ -1972,6 +1982,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)
- }
-
- skip = acpi_info_matches_ids(info, acpi_ignore_dep_ids);
- + honor_dep = acpi_info_matches_ids(info, acpi_honor_dep_ids);
- kfree(info);
-
- if (skip)
- @@ -1985,6 +1996,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)
-
- dep->supplier = dep_devices.handles[i];
- dep->consumer = handle;
- + dep->honor_dep = honor_dep;
-
- mutex_lock(&acpi_dep_list_lock);
- list_add_tail(&dep->node , &acpi_dep_list);
- @@ -2072,6 +2084,9 @@ static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used,
-
- static void acpi_default_enumeration(struct acpi_device *device)
- {
- + if (!acpi_dev_ready_for_enumeration(device))
- + return;
- +
- /*
- * Do not enumerate devices with enumeration_by_parent flag set as
- * they will be enumerated by their respective parents.
- @@ -2314,6 +2329,23 @@ void acpi_dev_clear_dependencies(struct acpi_device *supplier)
- }
- EXPORT_SYMBOL_GPL(acpi_dev_clear_dependencies);
-
- +/**
- + * acpi_dev_ready_for_enumeration - Check if the ACPI device is ready for enumeration
- + * @device: Pointer to the &struct acpi_device to check
- + *
- + * Check if the device is present and has no unmet dependencies.
- + *
- + * Return true if the device is ready for enumeratino. Otherwise, return false.
- + */
- +bool acpi_dev_ready_for_enumeration(const struct acpi_device *device)
- +{
- + if (device->flags.honor_deps && device->dep_unmet)
- + return false;
- +
- + return acpi_device_is_present(device);
- +}
- +EXPORT_SYMBOL_GPL(acpi_dev_ready_for_enumeration);
- +
- /**
- * acpi_dev_get_first_consumer_dev - Return ACPI device dependent on @supplier
- * @supplier: Pointer to the dependee device
- diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
- index 13d93371790e..2da53b7b4965 100644
- --- a/include/acpi/acpi_bus.h
- +++ b/include/acpi/acpi_bus.h
- @@ -202,7 +202,8 @@ struct acpi_device_flags {
- u32 coherent_dma:1;
- u32 cca_seen:1;
- u32 enumeration_by_parent:1;
- - u32 reserved:19;
- + u32 honor_deps:1;
- + u32 reserved:18;
- };
-
- /* File System */
- @@ -284,6 +285,7 @@ struct acpi_dep_data {
- struct list_head node;
- acpi_handle supplier;
- acpi_handle consumer;
- + bool honor_dep;
- };
-
- /* Performance Management */
- @@ -693,6 +695,7 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
- bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
-
- void acpi_dev_clear_dependencies(struct acpi_device *supplier);
- +bool acpi_dev_ready_for_enumeration(const struct acpi_device *device);
- struct acpi_device *acpi_dev_get_first_consumer_dev(struct acpi_device *supplier);
- struct acpi_device *
- acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
- --
- 2.34.0
- From 7d90f6ec28235414b69af24ff2cab4d172c8ad1a Mon Sep 17 00:00:00 2001
- From: Hans de Goede <hdegoede@redhat.com>
- Date: Sun, 10 Oct 2021 20:56:58 +0200
- Subject: [PATCH] i2c: acpi: Use acpi_dev_ready_for_enumeration() helper
- The clk and regulator frameworks expect clk/regulator consumer-devices
- to have info about the consumed clks/regulators described in the device's
- fw_node.
- To work around cases where this info is not present in the firmware tables,
- which is often the case on x86/ACPI devices, both frameworks allow the
- provider-driver to attach info about consumers to the clks/regulators
- when registering these.
- This causes problems with the probe ordering wrt drivers for consumers
- of these clks/regulators. Since the lookups are only registered when the
- provider-driver binds, trying to get these clks/regulators before then
- results in a -ENOENT error for clks and a dummy regulator for regulators.
- To ensure the correct probe-ordering the ACPI core has code to defer the
- enumeration of consumers affected by this until the providers are ready.
- Call the new acpi_dev_ready_for_enumeration() helper to avoid
- enumerating / instantiating i2c-clients too early.
- Signed-off-by: Hans de Goede <hdegoede@redhat.com>
- Patchset: cameras
- ---
- drivers/i2c/i2c-core-acpi.c | 5 ++++-
- 1 file changed, 4 insertions(+), 1 deletion(-)
- diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
- index 169713964358..9f0e719cd2c8 100644
- --- a/drivers/i2c/i2c-core-acpi.c
- +++ b/drivers/i2c/i2c-core-acpi.c
- @@ -112,9 +112,12 @@ static int i2c_acpi_do_lookup(struct acpi_device *adev,
- struct list_head resource_list;
- int ret;
-
- - if (acpi_bus_get_status(adev) || !adev->status.present)
- + if (acpi_bus_get_status(adev))
- return -EINVAL;
-
- + if (!acpi_dev_ready_for_enumeration(adev))
- + return -ENODEV;
- +
- if (acpi_match_device_ids(adev, i2c_acpi_ignored_device_ids) == 0)
- return -ENODEV;
-
- --
- 2.34.0
- From 2eacb6feb10dd81f94140bb16dbef6c335d20b9b Mon Sep 17 00:00:00 2001
- From: Hans de Goede <hdegoede@redhat.com>
- Date: Sun, 10 Oct 2021 20:56:59 +0200
- Subject: [PATCH] platform_data: Add linux/platform_data/tps68470.h file
- The clk and regulator frameworks expect clk/regulator consumer-devices
- to have info about the consumed clks/regulators described in the device's
- fw_node.
- To work around cases where this info is not present in the firmware tables,
- which is often the case on x86/ACPI devices, both frameworks allow the
- provider-driver to attach info about consumers to the provider-device
- during probe/registration of the provider device.
- The TI TPS68470 PMIC is used x86/ACPI devices with the consumer-info
- missing from the ACPI tables. Thus the tps68470-clk and tps68470-regulator
- drivers must provide the consumer-info at probe time.
- Define tps68470_clk_platform_data and tps68470_regulator_platform_data
- structs to allow the x86 platform code to pass the necessary consumer info
- to these drivers.
- Signed-off-by: Hans de Goede <hdegoede@redhat.com>
- Patchset: cameras
- ---
- include/linux/platform_data/tps68470.h | 35 ++++++++++++++++++++++++++
- 1 file changed, 35 insertions(+)
- create mode 100644 include/linux/platform_data/tps68470.h
- diff --git a/include/linux/platform_data/tps68470.h b/include/linux/platform_data/tps68470.h
- new file mode 100644
- index 000000000000..126d082c3f2e
- --- /dev/null
- +++ b/include/linux/platform_data/tps68470.h
- @@ -0,0 +1,35 @@
- +/* SPDX-License-Identifier: GPL-2.0-or-later */
- +/*
- + * TI TPS68470 PMIC platform data definition.
- + *
- + * Copyright (c) 2021 Red Hat Inc.
- + *
- + * Red Hat authors:
- + * Hans de Goede <hdegoede@redhat.com>
- + */
- +#ifndef __PDATA_TPS68470_H
- +#define __PDATA_TPS68470_H
- +
- +enum tps68470_regulators {
- + TPS68470_CORE,
- + TPS68470_ANA,
- + TPS68470_VCM,
- + TPS68470_VIO,
- + TPS68470_VSIO,
- + TPS68470_AUX1,
- + TPS68470_AUX2,
- + TPS68470_NUM_REGULATORS
- +};
- +
- +struct regulator_init_data;
- +
- +struct tps68470_regulator_platform_data {
- + const struct regulator_init_data *reg_init_data[TPS68470_NUM_REGULATORS];
- +};
- +
- +struct tps68470_clk_platform_data {
- + const char *consumer_dev_name;
- + const char *consumer_con_id;
- +};
- +
- +#endif
- --
- 2.34.0
- From 2f1936ac79975f2a90f821bac31cf20c76a8bbce Mon Sep 17 00:00:00 2001
- From: Hans de Goede <hdegoede@redhat.com>
- Date: Sun, 10 Oct 2021 20:57:00 +0200
- Subject: [PATCH] regulator: Introduce tps68470-regulator driver
- The TPS68470 PMIC provides Clocks, GPIOs and Regulators. At present in
- the kernel the Regulators and Clocks are controlled by an OpRegion
- driver designed to work with power control methods defined in ACPI, but
- some platforms lack those methods, meaning drivers need to be able to
- consume the resources of these chips through the usual frameworks.
- This commit adds a driver for the regulators provided by the tps68470,
- and is designed to bind to the platform_device registered by the
- intel_skl_int3472 module.
- This is based on this out of tree driver written by Intel:
- https://github.com/intel/linux-intel-lts/blob/4.14/base/drivers/regulator/tps68470-regulator.c
- with various cleanups added.
- Signed-off-by: Hans de Goede <hdegoede@redhat.com>
- Patchset: cameras
- ---
- drivers/regulator/Kconfig | 9 ++
- drivers/regulator/Makefile | 1 +
- drivers/regulator/tps68470-regulator.c | 193 +++++++++++++++++++++++++
- 3 files changed, 203 insertions(+)
- create mode 100644 drivers/regulator/tps68470-regulator.c
- diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
- index 24ce9a17ab4f..97caab5f7f9f 100644
- --- a/drivers/regulator/Kconfig
- +++ b/drivers/regulator/Kconfig
- @@ -1319,6 +1319,15 @@ config REGULATOR_TPS65912
- help
- This driver supports TPS65912 voltage regulator chip.
-
- +config REGULATOR_TPS68470
- + tristate "TI TPS68370 PMIC Regulators Driver"
- + depends on INTEL_SKL_INT3472
- + help
- + This driver adds support for the TPS68470 PMIC to register
- + regulators against the usual framework.
- +
- + The module will be called "tps68470-regulator"
- +
- config REGULATOR_TPS80031
- tristate "TI TPS80031/TPS80032 power regulator driver"
- depends on MFD_TPS80031
- diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
- index 8c2f82206b94..8dcc4506ecf8 100644
- --- a/drivers/regulator/Makefile
- +++ b/drivers/regulator/Makefile
- @@ -156,6 +156,7 @@ obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o
- obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o
- obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o
- obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o
- +obj-$(CONFIG_REGULATOR_TPS68470) += tps68470-regulator.o
- obj-$(CONFIG_REGULATOR_TPS80031) += tps80031-regulator.o
- obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o
- obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o
- diff --git a/drivers/regulator/tps68470-regulator.c b/drivers/regulator/tps68470-regulator.c
- new file mode 100644
- index 000000000000..3129fa13a122
- --- /dev/null
- +++ b/drivers/regulator/tps68470-regulator.c
- @@ -0,0 +1,193 @@
- +// SPDX-License-Identifier: GPL-2.0
- +/*
- + * Regulator driver for TPS68470 PMIC
- + *
- + * Copyright (C) 2018 Intel Corporation
- + *
- + * Authors:
- + * Zaikuo Wang <zaikuo.wang@intel.com>
- + * Tianshu Qiu <tian.shu.qiu@intel.com>
- + * Jian Xu Zheng <jian.xu.zheng@intel.com>
- + * Yuning Pu <yuning.pu@intel.com>
- + * Rajmohan Mani <rajmohan.mani@intel.com>
- + */
- +
- +#include <linux/device.h>
- +#include <linux/err.h>
- +#include <linux/init.h>
- +#include <linux/kernel.h>
- +#include <linux/mfd/tps68470.h>
- +#include <linux/module.h>
- +#include <linux/platform_data/tps68470.h>
- +#include <linux/platform_device.h>
- +#include <linux/regulator/driver.h>
- +#include <linux/regulator/machine.h>
- +
- +#define TPS68470_REGULATOR(_name, _id, _ops, _n, _vr, \
- + _vm, _er, _em, _t, _lr, _nlr) \
- + [TPS68470_ ## _name] = { \
- + .name = # _name, \
- + .id = _id, \
- + .ops = &_ops, \
- + .n_voltages = _n, \
- + .type = REGULATOR_VOLTAGE, \
- + .owner = THIS_MODULE, \
- + .vsel_reg = _vr, \
- + .vsel_mask = _vm, \
- + .enable_reg = _er, \
- + .enable_mask = _em, \
- + .volt_table = _t, \
- + .linear_ranges = _lr, \
- + .n_linear_ranges = _nlr, \
- + }
- +
- +static const struct linear_range tps68470_ldo_ranges[] = {
- + REGULATOR_LINEAR_RANGE(875000, 0, 125, 17800),
- +};
- +
- +static const struct linear_range tps68470_core_ranges[] = {
- + REGULATOR_LINEAR_RANGE(900000, 0, 42, 25000),
- +};
- +
- +/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */
- +static const struct regulator_ops tps68470_regulator_ops = {
- + .is_enabled = regulator_is_enabled_regmap,
- + .enable = regulator_enable_regmap,
- + .disable = regulator_disable_regmap,
- + .get_voltage_sel = regulator_get_voltage_sel_regmap,
- + .set_voltage_sel = regulator_set_voltage_sel_regmap,
- + .list_voltage = regulator_list_voltage_linear_range,
- + .map_voltage = regulator_map_voltage_linear_range,
- +};
- +
- +static const struct regulator_desc regulators[] = {
- + TPS68470_REGULATOR(CORE, TPS68470_CORE,
- + tps68470_regulator_ops, 43, TPS68470_REG_VDVAL,
- + TPS68470_VDVAL_DVOLT_MASK, TPS68470_REG_VDCTL,
- + TPS68470_VDCTL_EN_MASK,
- + NULL, tps68470_core_ranges,
- + ARRAY_SIZE(tps68470_core_ranges)),
- + TPS68470_REGULATOR(ANA, TPS68470_ANA,
- + tps68470_regulator_ops, 126, TPS68470_REG_VAVAL,
- + TPS68470_VAVAL_AVOLT_MASK, TPS68470_REG_VACTL,
- + TPS68470_VACTL_EN_MASK,
- + NULL, tps68470_ldo_ranges,
- + ARRAY_SIZE(tps68470_ldo_ranges)),
- + TPS68470_REGULATOR(VCM, TPS68470_VCM,
- + tps68470_regulator_ops, 126, TPS68470_REG_VCMVAL,
- + TPS68470_VCMVAL_VCVOLT_MASK, TPS68470_REG_VCMCTL,
- + TPS68470_VCMCTL_EN_MASK,
- + NULL, tps68470_ldo_ranges,
- + ARRAY_SIZE(tps68470_ldo_ranges)),
- + TPS68470_REGULATOR(VIO, TPS68470_VIO,
- + tps68470_regulator_ops, 126, TPS68470_REG_VIOVAL,
- + TPS68470_VIOVAL_IOVOLT_MASK, TPS68470_REG_S_I2C_CTL,
- + TPS68470_S_I2C_CTL_EN_MASK,
- + NULL, tps68470_ldo_ranges,
- + ARRAY_SIZE(tps68470_ldo_ranges)),
- +
- +/*
- + * (1) This register must have same setting as VIOVAL if S_IO LDO is used to
- + * power daisy chained IOs in the receive side.
- + * (2) If there is no I2C daisy chain it can be set freely.
- + *
- + */
- + TPS68470_REGULATOR(VSIO, TPS68470_VSIO,
- + tps68470_regulator_ops, 126, TPS68470_REG_VSIOVAL,
- + TPS68470_VSIOVAL_IOVOLT_MASK, TPS68470_REG_S_I2C_CTL,
- + TPS68470_S_I2C_CTL_EN_MASK,
- + NULL, tps68470_ldo_ranges,
- + ARRAY_SIZE(tps68470_ldo_ranges)),
- + TPS68470_REGULATOR(AUX1, TPS68470_AUX1,
- + tps68470_regulator_ops, 126, TPS68470_REG_VAUX1VAL,
- + TPS68470_VAUX1VAL_AUX1VOLT_MASK,
- + TPS68470_REG_VAUX1CTL,
- + TPS68470_VAUX1CTL_EN_MASK,
- + NULL, tps68470_ldo_ranges,
- + ARRAY_SIZE(tps68470_ldo_ranges)),
- + TPS68470_REGULATOR(AUX2, TPS68470_AUX2,
- + tps68470_regulator_ops, 126, TPS68470_REG_VAUX2VAL,
- + TPS68470_VAUX2VAL_AUX2VOLT_MASK,
- + TPS68470_REG_VAUX2CTL,
- + TPS68470_VAUX2CTL_EN_MASK,
- + NULL, tps68470_ldo_ranges,
- + ARRAY_SIZE(tps68470_ldo_ranges)),
- +};
- +
- +#define TPS68470_REG_INIT_DATA(_name, _min_uV, _max_uV) \
- + [TPS68470_ ## _name] = { \
- + .constraints = { \
- + .name = # _name, \
- + .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | \
- + REGULATOR_CHANGE_STATUS, \
- + .min_uV = _min_uV, \
- + .max_uV = _max_uV, \
- + }, \
- + }
- +
- +struct regulator_init_data tps68470_init[] = {
- + TPS68470_REG_INIT_DATA(CORE, 900000, 1950000),
- + TPS68470_REG_INIT_DATA(ANA, 875000, 3100000),
- + TPS68470_REG_INIT_DATA(VCM, 875000, 3100000),
- + TPS68470_REG_INIT_DATA(VIO, 875000, 3100000),
- + TPS68470_REG_INIT_DATA(VSIO, 875000, 3100000),
- + TPS68470_REG_INIT_DATA(AUX1, 875000, 3100000),
- + TPS68470_REG_INIT_DATA(AUX2, 875000, 3100000),
- +};
- +
- +static int tps68470_regulator_probe(struct platform_device *pdev)
- +{
- + struct tps68470_regulator_platform_data *pdata = pdev->dev.platform_data;
- + struct regulator_config config = { };
- + struct regmap *tps68470_regmap;
- + struct regulator_dev *rdev;
- + int i;
- +
- + tps68470_regmap = dev_get_drvdata(pdev->dev.parent);
- +
- + for (i = 0; i < TPS68470_NUM_REGULATORS; i++) {
- + config.dev = pdev->dev.parent;
- + config.regmap = tps68470_regmap;
- + if (pdata && pdata->reg_init_data[i])
- + config.init_data = pdata->reg_init_data[i];
- + else
- + config.init_data = &tps68470_init[i];
- +
- + rdev = devm_regulator_register(&pdev->dev, ®ulators[i], &config);
- + if (IS_ERR(rdev)) {
- + dev_err(&pdev->dev, "failed to register %s regulator\n",
- + regulators[i].name);
- + return PTR_ERR(rdev);
- + }
- + }
- +
- + return 0;
- +}
- +
- +static struct platform_driver tps68470_regulator_driver = {
- + .driver = {
- + .name = "tps68470-regulator",
- + },
- + .probe = tps68470_regulator_probe,
- +};
- +
- +/*
- + * The ACPI tps68470 probe-ordering depends on the clk/gpio/regulator drivers
- + * registering before the drivers for the camera-sensors which use them bind.
- + * subsys_initcall() ensures this when the drivers are builtin.
- + */
- +static int __init tps68470_regulator_init(void)
- +{
- + return platform_driver_register(&tps68470_regulator_driver);
- +}
- +subsys_initcall(tps68470_regulator_init);
- +
- +static void __exit tps68470_regulator_exit(void)
- +{
- + platform_driver_unregister(&tps68470_regulator_driver);
- +}
- +module_exit(tps68470_regulator_exit);
- +
- +MODULE_ALIAS("platform:tps68470-regulator");
- +MODULE_DESCRIPTION("TPS68470 voltage regulator driver");
- +MODULE_LICENSE("GPL v2");
- --
- 2.34.0
- From d114fbffa257b641e5f21a3d65878ec0ff6a012f Mon Sep 17 00:00:00 2001
- From: Hans de Goede <hdegoede@redhat.com>
- Date: Sun, 10 Oct 2021 20:57:01 +0200
- Subject: [PATCH] clk: Introduce clk-tps68470 driver
- The TPS68470 PMIC provides Clocks, GPIOs and Regulators. At present in
- the kernel the Regulators and Clocks are controlled by an OpRegion
- driver designed to work with power control methods defined in ACPI, but
- some platforms lack those methods, meaning drivers need to be able to
- consume the resources of these chips through the usual frameworks.
- This commit adds a driver for the clocks provided by the tps68470,
- and is designed to bind to the platform_device registered by the
- intel_skl_int3472 module.
- This is based on this out of tree driver written by Intel:
- https://github.com/intel/linux-intel-lts/blob/4.14/base/drivers/clk/clk-tps68470.c
- with various cleanups added.
- Signed-off-by: Hans de Goede <hdegoede@redhat.com>
- Patchset: cameras
- ---
- drivers/clk/Kconfig | 6 +
- drivers/clk/Makefile | 1 +
- drivers/clk/clk-tps68470.c | 256 +++++++++++++++++++++++++++++++++++
- include/linux/mfd/tps68470.h | 11 ++
- 4 files changed, 274 insertions(+)
- create mode 100644 drivers/clk/clk-tps68470.c
- diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
- index e873f9ea2e65..f5255b085fe2 100644
- --- a/drivers/clk/Kconfig
- +++ b/drivers/clk/Kconfig
- @@ -169,6 +169,12 @@ config COMMON_CLK_CDCE706
- help
- This driver supports TI CDCE706 programmable 3-PLL clock synthesizer.
-
- +config COMMON_CLK_TPS68470
- + tristate "Clock Driver for TI TPS68470 PMIC"
- + depends on I2C && REGMAP_I2C && INTEL_SKL_INT3472
- + help
- + This driver supports the clocks provided by TPS68470
- +
- config COMMON_CLK_CDCE925
- tristate "Clock driver for TI CDCE913/925/937/949 devices"
- depends on I2C
- diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
- index 2b91d34c582b..1f7dad3461f2 100644
- --- a/drivers/clk/Makefile
- +++ b/drivers/clk/Makefile
- @@ -63,6 +63,7 @@ obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o
- obj-$(CONFIG_COMMON_CLK_STM32F) += clk-stm32f4.o
- obj-$(CONFIG_COMMON_CLK_STM32H7) += clk-stm32h7.o
- obj-$(CONFIG_COMMON_CLK_STM32MP157) += clk-stm32mp1.o
- +obj-$(CONFIG_COMMON_CLK_TPS68470) += clk-tps68470.o
- obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o
- obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o
- obj-$(CONFIG_COMMON_CLK_VC5) += clk-versaclock5.o
- diff --git a/drivers/clk/clk-tps68470.c b/drivers/clk/clk-tps68470.c
- new file mode 100644
- index 000000000000..27e8cbd0f60e
- --- /dev/null
- +++ b/drivers/clk/clk-tps68470.c
- @@ -0,0 +1,256 @@
- +// SPDX-License-Identifier: GPL-2.0
- +/*
- + * Clock driver for TPS68470 PMIC
- + *
- + * Copyright (C) 2018 Intel Corporation
- + *
- + * Authors:
- + * Zaikuo Wang <zaikuo.wang@intel.com>
- + * Tianshu Qiu <tian.shu.qiu@intel.com>
- + * Jian Xu Zheng <jian.xu.zheng@intel.com>
- + * Yuning Pu <yuning.pu@intel.com>
- + * Antti Laakso <antti.laakso@intel.com>
- + */
- +
- +#include <linux/clk-provider.h>
- +#include <linux/clkdev.h>
- +#include <linux/kernel.h>
- +#include <linux/mfd/tps68470.h>
- +#include <linux/module.h>
- +#include <linux/platform_device.h>
- +#include <linux/platform_data/tps68470.h>
- +#include <linux/regmap.h>
- +
- +#define TPS68470_CLK_NAME "tps68470-clk"
- +
- +#define to_tps68470_clkdata(clkd) \
- + container_of(clkd, struct tps68470_clkdata, clkout_hw)
- +
- +struct tps68470_clkout_freqs {
- + unsigned long freq;
- + unsigned int xtaldiv;
- + unsigned int plldiv;
- + unsigned int postdiv;
- + unsigned int buckdiv;
- + unsigned int boostdiv;
- +} clk_freqs[] = {
- +/*
- + * The PLL is used to multiply the crystal oscillator
- + * frequency range of 3 MHz to 27 MHz by a programmable
- + * factor of F = (M/N)*(1/P) such that the output
- + * available at the HCLK_A or HCLK_B pins are in the range
- + * of 4 MHz to 64 MHz in increments of 0.1 MHz
- + *
- + * hclk_# = osc_in * (((plldiv*2)+320) / (xtaldiv+30)) * (1 / 2^postdiv)
- + *
- + * PLL_REF_CLK should be as close as possible to 100kHz
- + * PLL_REF_CLK = input clk / XTALDIV[7:0] + 30)
- + *
- + * PLL_VCO_CLK = (PLL_REF_CLK * (plldiv*2 + 320))
- + *
- + * BOOST should be as close as possible to 2Mhz
- + * BOOST = PLL_VCO_CLK / (BOOSTDIV[4:0] + 16) *
- + *
- + * BUCK should be as close as possible to 5.2Mhz
- + * BUCK = PLL_VCO_CLK / (BUCKDIV[3:0] + 5)
- + *
- + * osc_in xtaldiv plldiv postdiv hclk_#
- + * 20Mhz 170 32 1 19.2Mhz
- + * 20Mhz 170 40 1 20Mhz
- + * 20Mhz 170 80 1 24Mhz
- + *
- + */
- + { 19200000, 170, 32, 1, 2, 3 },
- + { 20000000, 170, 40, 1, 3, 4 },
- + { 24000000, 170, 80, 1, 4, 8 },
- +};
- +
- +struct tps68470_clkdata {
- + struct clk_hw clkout_hw;
- + struct regmap *regmap;
- + struct clk *clk;
- + int clk_cfg_idx;
- +};
- +
- +static int tps68470_clk_is_prepared(struct clk_hw *hw)
- +{
- + struct tps68470_clkdata *clkdata = to_tps68470_clkdata(hw);
- + int val;
- +
- + if (regmap_read(clkdata->regmap, TPS68470_REG_PLLCTL, &val))
- + return 0;
- +
- + return val & TPS68470_PLL_EN_MASK;
- +}
- +
- +static int tps68470_clk_prepare(struct clk_hw *hw)
- +{
- + struct tps68470_clkdata *clkdata = to_tps68470_clkdata(hw);
- + int idx = clkdata->clk_cfg_idx;
- +
- + regmap_write(clkdata->regmap, TPS68470_REG_BOOSTDIV, clk_freqs[idx].boostdiv);
- + regmap_write(clkdata->regmap, TPS68470_REG_BUCKDIV, clk_freqs[idx].buckdiv);
- + regmap_write(clkdata->regmap, TPS68470_REG_PLLSWR, TPS68470_PLLSWR_DEFAULT);
- + regmap_write(clkdata->regmap, TPS68470_REG_XTALDIV, clk_freqs[idx].xtaldiv);
- + regmap_write(clkdata->regmap, TPS68470_REG_PLLDIV, clk_freqs[idx].plldiv);
- + regmap_write(clkdata->regmap, TPS68470_REG_POSTDIV, clk_freqs[idx].postdiv);
- + regmap_write(clkdata->regmap, TPS68470_REG_POSTDIV2, clk_freqs[idx].postdiv);
- + regmap_write(clkdata->regmap, TPS68470_REG_CLKCFG2, TPS68470_CLKCFG2_DRV_STR_2MA);
- +
- + regmap_write(clkdata->regmap, TPS68470_REG_PLLCTL,
- + TPS68470_OSC_EXT_CAP_DEFAULT << TPS68470_OSC_EXT_CAP_SHIFT |
- + TPS68470_CLK_SRC_XTAL << TPS68470_CLK_SRC_SHIFT);
- +
- + regmap_write(clkdata->regmap, TPS68470_REG_CLKCFG1,
- + (TPS68470_PLL_OUTPUT_ENABLE <<
- + TPS68470_OUTPUT_A_SHIFT) |
- + (TPS68470_PLL_OUTPUT_ENABLE <<
- + TPS68470_OUTPUT_B_SHIFT));
- +
- + regmap_update_bits(clkdata->regmap, TPS68470_REG_PLLCTL,
- + TPS68470_PLL_EN_MASK, TPS68470_PLL_EN_MASK);
- +
- + return 0;
- +}
- +
- +static void tps68470_clk_unprepare(struct clk_hw *hw)
- +{
- + struct tps68470_clkdata *clkdata = to_tps68470_clkdata(hw);
- +
- + /* disable clock first*/
- + regmap_update_bits(clkdata->regmap, TPS68470_REG_PLLCTL, TPS68470_PLL_EN_MASK, 0);
- +
- + /* write hw defaults */
- + regmap_write(clkdata->regmap, TPS68470_REG_BOOSTDIV, 0);
- + regmap_write(clkdata->regmap, TPS68470_REG_BUCKDIV, 0);
- + regmap_write(clkdata->regmap, TPS68470_REG_PLLSWR, 0);
- + regmap_write(clkdata->regmap, TPS68470_REG_XTALDIV, 0);
- + regmap_write(clkdata->regmap, TPS68470_REG_PLLDIV, 0);
- + regmap_write(clkdata->regmap, TPS68470_REG_POSTDIV, 0);
- + regmap_write(clkdata->regmap, TPS68470_REG_CLKCFG2, 0);
- + regmap_write(clkdata->regmap, TPS68470_REG_CLKCFG1, 0);
- +}
- +
- +static unsigned long tps68470_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
- +{
- + struct tps68470_clkdata *clkdata = to_tps68470_clkdata(hw);
- +
- + return clk_freqs[clkdata->clk_cfg_idx].freq;
- +}
- +
- +static int tps68470_clk_cfg_lookup(unsigned long rate)
- +{
- + long diff, best_diff = LONG_MAX;
- + int i, best_idx = 0;
- +
- + for (i = 0; i < ARRAY_SIZE(clk_freqs); i++) {
- + diff = clk_freqs[i].freq - rate;
- + if (diff == 0)
- + return i;
- +
- + diff = abs(diff);
- + if (diff < best_diff) {
- + best_diff = diff;
- + best_idx = i;
- + }
- + }
- +
- + return best_idx;
- +}
- +
- +static long tps68470_clk_round_rate(struct clk_hw *hw, unsigned long rate,
- + unsigned long *parent_rate)
- +{
- + int idx = tps68470_clk_cfg_lookup(rate);
- +
- + return clk_freqs[idx].freq;
- +}
- +
- +static int tps68470_clk_set_rate(struct clk_hw *hw, unsigned long rate,
- + unsigned long parent_rate)
- +{
- + struct tps68470_clkdata *clkdata = to_tps68470_clkdata(hw);
- + int idx = tps68470_clk_cfg_lookup(rate);
- +
- + if (rate != clk_freqs[idx].freq)
- + return -EINVAL;
- +
- + clkdata->clk_cfg_idx = idx;
- + return 0;
- +}
- +
- +static const struct clk_ops tps68470_clk_ops = {
- + .is_prepared = tps68470_clk_is_prepared,
- + .prepare = tps68470_clk_prepare,
- + .unprepare = tps68470_clk_unprepare,
- + .recalc_rate = tps68470_clk_recalc_rate,
- + .round_rate = tps68470_clk_round_rate,
- + .set_rate = tps68470_clk_set_rate,
- +};
- +
- +static struct clk_init_data tps68470_clk_initdata = {
- + .name = TPS68470_CLK_NAME,
- + .ops = &tps68470_clk_ops,
- +};
- +
- +static int tps68470_clk_probe(struct platform_device *pdev)
- +{
- + struct tps68470_clk_platform_data *pdata = pdev->dev.platform_data;
- + struct tps68470_clkdata *tps68470_clkdata;
- + int ret;
- +
- + tps68470_clkdata = devm_kzalloc(&pdev->dev, sizeof(*tps68470_clkdata),
- + GFP_KERNEL);
- + if (!tps68470_clkdata)
- + return -ENOMEM;
- +
- + tps68470_clkdata->regmap = dev_get_drvdata(pdev->dev.parent);
- + tps68470_clkdata->clkout_hw.init = &tps68470_clk_initdata;
- + tps68470_clkdata->clk = devm_clk_register(&pdev->dev, &tps68470_clkdata->clkout_hw);
- + if (IS_ERR(tps68470_clkdata->clk))
- + return PTR_ERR(tps68470_clkdata->clk);
- +
- + ret = devm_clk_hw_register_clkdev(&pdev->dev, &tps68470_clkdata->clkout_hw,
- + TPS68470_CLK_NAME, NULL);
- + if (ret)
- + return ret;
- +
- + if (pdata) {
- + ret = devm_clk_hw_register_clkdev(&pdev->dev,
- + &tps68470_clkdata->clkout_hw,
- + pdata->consumer_con_id,
- + pdata->consumer_dev_name);
- + if (ret)
- + return ret;
- + }
- +
- + return 0;
- +}
- +
- +static struct platform_driver tps68470_clk_driver = {
- + .driver = {
- + .name = TPS68470_CLK_NAME,
- + },
- + .probe = tps68470_clk_probe,
- +};
- +
- +/*
- + * The ACPI tps68470 probe-ordering depends on the clk/gpio/regulator drivers
- + * registering before the drivers for the camera-sensors which use them bind.
- + * subsys_initcall() ensures this when the drivers are builtin.
- + */
- +static int __init tps68470_clk_init(void)
- +{
- + return platform_driver_register(&tps68470_clk_driver);
- +}
- +subsys_initcall(tps68470_clk_init);
- +
- +static void __exit tps68470_clk_exit(void)
- +{
- + platform_driver_unregister(&tps68470_clk_driver);
- +}
- +module_exit(tps68470_clk_exit);
- +
- +MODULE_ALIAS("platform:tps68470-clk");
- +MODULE_DESCRIPTION("clock driver for TPS68470 pmic");
- +MODULE_LICENSE("GPL");
- diff --git a/include/linux/mfd/tps68470.h b/include/linux/mfd/tps68470.h
- index ffe81127d91c..7807fa329db0 100644
- --- a/include/linux/mfd/tps68470.h
- +++ b/include/linux/mfd/tps68470.h
- @@ -75,6 +75,17 @@
- #define TPS68470_CLKCFG1_MODE_A_MASK GENMASK(1, 0)
- #define TPS68470_CLKCFG1_MODE_B_MASK GENMASK(3, 2)
-
- +#define TPS68470_CLKCFG2_DRV_STR_2MA 0x05
- +#define TPS68470_PLL_OUTPUT_ENABLE 0x02
- +#define TPS68470_CLK_SRC_XTAL BIT(0)
- +#define TPS68470_PLLSWR_DEFAULT GENMASK(1, 0)
- +#define TPS68470_OSC_EXT_CAP_DEFAULT 0x05
- +
- +#define TPS68470_OUTPUT_A_SHIFT 0x00
- +#define TPS68470_OUTPUT_B_SHIFT 0x02
- +#define TPS68470_CLK_SRC_SHIFT GENMASK(2, 0)
- +#define TPS68470_OSC_EXT_CAP_SHIFT BIT(2)
- +
- #define TPS68470_GPIO_CTL_REG_A(x) (TPS68470_REG_GPCTL0A + (x) * 2)
- #define TPS68470_GPIO_CTL_REG_B(x) (TPS68470_REG_GPCTL0B + (x) * 2)
- #define TPS68470_GPIO_MODE_MASK GENMASK(1, 0)
- --
- 2.34.0
- From 235191b72abd1f1b529b5917c3f6fe60415ae4f5 Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Sun, 10 Oct 2021 20:57:02 +0200
- Subject: [PATCH] platform/x86: int3472: Enable I2c daisy chain
- The TPS68470 PMIC has an I2C passthrough mode through which I2C traffic
- can be forwarded to a device connected to the PMIC as though it were
- connected directly to the system bus. Enable this mode when the chip
- is initialised.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- .../x86/intel/int3472/intel_skl_int3472_tps68470.c | 7 +++++++
- 1 file changed, 7 insertions(+)
- diff --git a/drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c b/drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c
- index c05b4cf502fe..42e688f4cad4 100644
- --- a/drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c
- +++ b/drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c
- @@ -45,6 +45,13 @@ static int tps68470_chip_init(struct device *dev, struct regmap *regmap)
- return ret;
- }
-
- + /* Enable I2C daisy chain */
- + ret = regmap_write(regmap, TPS68470_REG_S_I2C_CTL, 0x03);
- + if (ret) {
- + dev_err(dev, "Failed to enable i2c daisy chain\n");
- + return ret;
- + }
- +
- dev_info(dev, "TPS68470 REVID: 0x%02x\n", version);
-
- return 0;
- --
- 2.34.0
- From eef319f98c64c8e155be21f592cbb16ef30da91e Mon Sep 17 00:00:00 2001
- From: Hans de Goede <hdegoede@redhat.com>
- Date: Sun, 10 Oct 2021 20:57:03 +0200
- Subject: [PATCH] platform/x86: int3472: Split into 2 drivers
- The intel_skl_int3472.ko module contains 2 separate drivers,
- the int3472_discrete platform driver and the int3472_tps68470
- I2C-driver.
- These 2 drivers contain very little shared code, only
- skl_int3472_get_acpi_buffer() and skl_int3472_fill_cldb() are
- shared.
- Split the module into 2 drivers, linking the little shared code
- directly into both.
- This will allow us to add soft-module dependencies for the
- tps68470 clk, gpio and regulator drivers to the new
- intel_skl_int3472_tps68470.ko to help with probe ordering issues
- without causing these modules to get loaded on boards which only
- use the int3472_discrete platform driver.
- While at it also rename the .c and .h files to remove the
- cumbersome intel_skl_int3472_ prefix.
- Signed-off-by: Hans de Goede <hdegoede@redhat.com>
- Patchset: cameras
- ---
- drivers/platform/x86/intel/int3472/Makefile | 9 ++--
- ...lk_and_regulator.c => clk_and_regulator.c} | 2 +-
- drivers/platform/x86/intel/int3472/common.c | 54 +++++++++++++++++++
- .../{intel_skl_int3472_common.h => common.h} | 3 --
- ...ntel_skl_int3472_discrete.c => discrete.c} | 28 ++++++++--
- ...ntel_skl_int3472_tps68470.c => tps68470.c} | 23 +++++++-
- 6 files changed, 105 insertions(+), 14 deletions(-)
- rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_clk_and_regulator.c => clk_and_regulator.c} (99%)
- create mode 100644 drivers/platform/x86/intel/int3472/common.c
- rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_common.h => common.h} (94%)
- rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_discrete.c => discrete.c} (93%)
- rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_tps68470.c => tps68470.c} (85%)
- diff --git a/drivers/platform/x86/intel/int3472/Makefile b/drivers/platform/x86/intel/int3472/Makefile
- index 48bd97f0a04e..4a4b2518ea16 100644
- --- a/drivers/platform/x86/intel/int3472/Makefile
- +++ b/drivers/platform/x86/intel/int3472/Makefile
- @@ -1,5 +1,4 @@
- -obj-$(CONFIG_INTEL_SKL_INT3472) += intel_skl_int3472.o
- -intel_skl_int3472-objs := intel_skl_int3472_common.o \
- - intel_skl_int3472_discrete.o \
- - intel_skl_int3472_tps68470.o \
- - intel_skl_int3472_clk_and_regulator.o
- +obj-$(CONFIG_INTEL_SKL_INT3472) += intel_skl_int3472_discrete.o \
- + intel_skl_int3472_tps68470.o
- +intel_skl_int3472_discrete-y := discrete.o clk_and_regulator.o common.o
- +intel_skl_int3472_tps68470-y := tps68470.o common.o
- diff --git a/drivers/platform/x86/intel/int3472/intel_skl_int3472_clk_and_regulator.c b/drivers/platform/x86/intel/int3472/clk_and_regulator.c
- similarity index 99%
- rename from drivers/platform/x86/intel/int3472/intel_skl_int3472_clk_and_regulator.c
- rename to drivers/platform/x86/intel/int3472/clk_and_regulator.c
- index 1700e7557a82..1cf958983e86 100644
- --- a/drivers/platform/x86/intel/int3472/intel_skl_int3472_clk_and_regulator.c
- +++ b/drivers/platform/x86/intel/int3472/clk_and_regulator.c
- @@ -9,7 +9,7 @@
- #include <linux/regulator/driver.h>
- #include <linux/slab.h>
-
- -#include "intel_skl_int3472_common.h"
- +#include "common.h"
-
- /*
- * The regulators have to have .ops to be valid, but the only ops we actually
- diff --git a/drivers/platform/x86/intel/int3472/common.c b/drivers/platform/x86/intel/int3472/common.c
- new file mode 100644
- index 000000000000..350655a9515b
- --- /dev/null
- +++ b/drivers/platform/x86/intel/int3472/common.c
- @@ -0,0 +1,54 @@
- +// SPDX-License-Identifier: GPL-2.0
- +/* Author: Dan Scally <djrscally@gmail.com> */
- +
- +#include <linux/acpi.h>
- +#include <linux/slab.h>
- +
- +#include "common.h"
- +
- +union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev, char *id)
- +{
- + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
- + acpi_handle handle = adev->handle;
- + union acpi_object *obj;
- + acpi_status status;
- +
- + status = acpi_evaluate_object(handle, id, NULL, &buffer);
- + if (ACPI_FAILURE(status))
- + return ERR_PTR(-ENODEV);
- +
- + obj = buffer.pointer;
- + if (!obj)
- + return ERR_PTR(-ENODEV);
- +
- + if (obj->type != ACPI_TYPE_BUFFER) {
- + acpi_handle_err(handle, "%s object is not an ACPI buffer\n", id);
- + kfree(obj);
- + return ERR_PTR(-EINVAL);
- + }
- +
- + return obj;
- +}
- +
- +int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb)
- +{
- + union acpi_object *obj;
- + int ret;
- +
- + obj = skl_int3472_get_acpi_buffer(adev, "CLDB");
- + if (IS_ERR(obj))
- + return PTR_ERR(obj);
- +
- + if (obj->buffer.length > sizeof(*cldb)) {
- + acpi_handle_err(adev->handle, "The CLDB buffer is too large\n");
- + ret = -EINVAL;
- + goto out_free_obj;
- + }
- +
- + memcpy(cldb, obj->buffer.pointer, obj->buffer.length);
- + ret = 0;
- +
- +out_free_obj:
- + kfree(obj);
- + return ret;
- +}
- diff --git a/drivers/platform/x86/intel/int3472/intel_skl_int3472_common.h b/drivers/platform/x86/intel/int3472/common.h
- similarity index 94%
- rename from drivers/platform/x86/intel/int3472/intel_skl_int3472_common.h
- rename to drivers/platform/x86/intel/int3472/common.h
- index 714fde73b524..d14944ee8586 100644
- --- a/drivers/platform/x86/intel/int3472/intel_skl_int3472_common.h
- +++ b/drivers/platform/x86/intel/int3472/common.h
- @@ -105,9 +105,6 @@ struct int3472_discrete_device {
- struct gpiod_lookup_table gpios;
- };
-
- -int skl_int3472_discrete_probe(struct platform_device *pdev);
- -int skl_int3472_discrete_remove(struct platform_device *pdev);
- -int skl_int3472_tps68470_probe(struct i2c_client *client);
- union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev,
- char *id);
- int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb);
- diff --git a/drivers/platform/x86/intel/int3472/intel_skl_int3472_discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
- similarity index 93%
- rename from drivers/platform/x86/intel/int3472/intel_skl_int3472_discrete.c
- rename to drivers/platform/x86/intel/int3472/discrete.c
- index 9fe0a2527e1c..856602a2f6bb 100644
- --- a/drivers/platform/x86/intel/int3472/intel_skl_int3472_discrete.c
- +++ b/drivers/platform/x86/intel/int3472/discrete.c
- @@ -14,7 +14,7 @@
- #include <linux/platform_device.h>
- #include <linux/uuid.h>
-
- -#include "intel_skl_int3472_common.h"
- +#include "common.h"
-
- /*
- * 79234640-9e10-4fea-a5c1-b5aa8b19756f
- @@ -332,7 +332,9 @@ static int skl_int3472_parse_crs(struct int3472_discrete_device *int3472)
- return 0;
- }
-
- -int skl_int3472_discrete_probe(struct platform_device *pdev)
- +static int skl_int3472_discrete_remove(struct platform_device *pdev);
- +
- +static int skl_int3472_discrete_probe(struct platform_device *pdev)
- {
- struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
- struct int3472_discrete_device *int3472;
- @@ -395,7 +397,7 @@ int skl_int3472_discrete_probe(struct platform_device *pdev)
- return ret;
- }
-
- -int skl_int3472_discrete_remove(struct platform_device *pdev)
- +static int skl_int3472_discrete_remove(struct platform_device *pdev)
- {
- struct int3472_discrete_device *int3472 = platform_get_drvdata(pdev);
-
- @@ -411,3 +413,23 @@ int skl_int3472_discrete_remove(struct platform_device *pdev)
-
- return 0;
- }
- +
- +static const struct acpi_device_id int3472_device_id[] = {
- + { "INT3472", 0 },
- + { }
- +};
- +MODULE_DEVICE_TABLE(acpi, int3472_device_id);
- +
- +static struct platform_driver int3472_discrete = {
- + .driver = {
- + .name = "int3472-discrete",
- + .acpi_match_table = int3472_device_id,
- + },
- + .probe = skl_int3472_discrete_probe,
- + .remove = skl_int3472_discrete_remove,
- +};
- +module_platform_driver(int3472_discrete);
- +
- +MODULE_DESCRIPTION("Intel SkyLake INT3472 ACPI Discrete Device Driver");
- +MODULE_AUTHOR("Daniel Scally <djrscally@gmail.com>");
- +MODULE_LICENSE("GPL v2");
- diff --git a/drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c b/drivers/platform/x86/intel/int3472/tps68470.c
- similarity index 85%
- rename from drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c
- rename to drivers/platform/x86/intel/int3472/tps68470.c
- index 42e688f4cad4..b94cf66ab61f 100644
- --- a/drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c
- +++ b/drivers/platform/x86/intel/int3472/tps68470.c
- @@ -7,7 +7,7 @@
- #include <linux/platform_device.h>
- #include <linux/regmap.h>
-
- -#include "intel_skl_int3472_common.h"
- +#include "common.h"
-
- #define DESIGNED_FOR_CHROMEOS 1
- #define DESIGNED_FOR_WINDOWS 2
- @@ -102,7 +102,7 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev)
- return DESIGNED_FOR_WINDOWS;
- }
-
- -int skl_int3472_tps68470_probe(struct i2c_client *client)
- +static int skl_int3472_tps68470_probe(struct i2c_client *client)
- {
- struct acpi_device *adev = ACPI_COMPANION(&client->dev);
- struct regmap *regmap;
- @@ -142,3 +142,22 @@ int skl_int3472_tps68470_probe(struct i2c_client *client)
-
- return ret;
- }
- +
- +static const struct acpi_device_id int3472_device_id[] = {
- + { "INT3472", 0 },
- + { }
- +};
- +MODULE_DEVICE_TABLE(acpi, int3472_device_id);
- +
- +static struct i2c_driver int3472_tps68470 = {
- + .driver = {
- + .name = "int3472-tps68470",
- + .acpi_match_table = int3472_device_id,
- + },
- + .probe_new = skl_int3472_tps68470_probe,
- +};
- +module_i2c_driver(int3472_tps68470);
- +
- +MODULE_DESCRIPTION("Intel SkyLake INT3472 ACPI TPS68470 Device Driver");
- +MODULE_AUTHOR("Daniel Scally <djrscally@gmail.com>");
- +MODULE_LICENSE("GPL v2");
- --
- 2.34.0
- From 25895ad4036113835c557ee75f9f9c524d56adb7 Mon Sep 17 00:00:00 2001
- From: Hans de Goede <hdegoede@redhat.com>
- Date: Sun, 10 Oct 2021 20:57:04 +0200
- Subject: [PATCH] platform/x86: int3472: Add get_sensor_adev_and_name() helper
- The discrete.c code is not the only code which needs to lookup the
- acpi_device and device-name for the sensor for which the INT3472
- ACPI-device is a GPIO/clk/regulator provider.
- The tps68470.c code also needs this functionality, so factor this
- out into a new get_sensor_adev_and_name() helper.
- Signed-off-by: Hans de Goede <hdegoede@redhat.com>
- Patchset: cameras
- ---
- drivers/platform/x86/intel/int3472/common.c | 28 +++++++++++++++++++
- drivers/platform/x86/intel/int3472/common.h | 3 ++
- drivers/platform/x86/intel/int3472/discrete.c | 22 +++------------
- 3 files changed, 35 insertions(+), 18 deletions(-)
- diff --git a/drivers/platform/x86/intel/int3472/common.c b/drivers/platform/x86/intel/int3472/common.c
- index 350655a9515b..77cf058e4168 100644
- --- a/drivers/platform/x86/intel/int3472/common.c
- +++ b/drivers/platform/x86/intel/int3472/common.c
- @@ -52,3 +52,31 @@ int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb)
- kfree(obj);
- return ret;
- }
- +
- +/* sensor_adev_ret may be NULL, name_ret must not be NULL */
- +int skl_int3472_get_sensor_adev_and_name(struct device *dev,
- + struct acpi_device **sensor_adev_ret,
- + const char **name_ret)
- +{
- + struct acpi_device *adev = ACPI_COMPANION(dev);
- + struct acpi_device *sensor;
- + int ret = 0;
- +
- + sensor = acpi_dev_get_first_consumer_dev(adev);
- + if (!sensor) {
- + dev_err(dev, "INT3472 seems to have no dependents.\n");
- + return -ENODEV;
- + }
- +
- + *name_ret = devm_kasprintf(dev, GFP_KERNEL, I2C_DEV_NAME_FORMAT,
- + acpi_dev_name(sensor));
- + if (!*name_ret)
- + ret = -ENOMEM;
- +
- + if (ret == 0 && sensor_adev_ret)
- + *sensor_adev_ret = sensor;
- + else
- + acpi_dev_put(sensor);
- +
- + return ret;
- +}
- diff --git a/drivers/platform/x86/intel/int3472/common.h b/drivers/platform/x86/intel/int3472/common.h
- index d14944ee8586..53270d19c73a 100644
- --- a/drivers/platform/x86/intel/int3472/common.h
- +++ b/drivers/platform/x86/intel/int3472/common.h
- @@ -108,6 +108,9 @@ struct int3472_discrete_device {
- union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev,
- char *id);
- int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb);
- +int skl_int3472_get_sensor_adev_and_name(struct device *dev,
- + struct acpi_device **sensor_adev_ret,
- + const char **name_ret);
-
- int skl_int3472_register_clock(struct int3472_discrete_device *int3472);
- void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472);
- diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
- index 856602a2f6bb..22a4894f1cc7 100644
- --- a/drivers/platform/x86/intel/int3472/discrete.c
- +++ b/drivers/platform/x86/intel/int3472/discrete.c
- @@ -363,19 +363,10 @@ static int skl_int3472_discrete_probe(struct platform_device *pdev)
- int3472->dev = &pdev->dev;
- platform_set_drvdata(pdev, int3472);
-
- - int3472->sensor = acpi_dev_get_first_consumer_dev(adev);
- - if (!int3472->sensor) {
- - dev_err(&pdev->dev, "INT3472 seems to have no dependents.\n");
- - return -ENODEV;
- - }
- -
- - int3472->sensor_name = devm_kasprintf(int3472->dev, GFP_KERNEL,
- - I2C_DEV_NAME_FORMAT,
- - acpi_dev_name(int3472->sensor));
- - if (!int3472->sensor_name) {
- - ret = -ENOMEM;
- - goto err_put_sensor;
- - }
- + ret = skl_int3472_get_sensor_adev_and_name(&pdev->dev, &int3472->sensor,
- + &int3472->sensor_name);
- + if (ret)
- + return ret;
-
- /*
- * Initialising this list means we can call gpiod_remove_lookup_table()
- @@ -390,11 +381,6 @@ static int skl_int3472_discrete_probe(struct platform_device *pdev)
- }
-
- return 0;
- -
- -err_put_sensor:
- - acpi_dev_put(int3472->sensor);
- -
- - return ret;
- }
-
- static int skl_int3472_discrete_remove(struct platform_device *pdev)
- --
- 2.34.0
- From 3ed4113df3ad5142e726a54ae3c6592733ee8367 Mon Sep 17 00:00:00 2001
- From: Hans de Goede <hdegoede@redhat.com>
- Date: Sun, 10 Oct 2021 20:57:05 +0200
- Subject: [PATCH] platform/x86: int3472: Pass tps68470_clk_platform_data to the
- tps68470-regulator MFD-cell
- Pass tps68470_clk_platform_data to the tps68470-clk MFD-cell,
- so that sensors which use the TPS68470 can find their clock.
- Signed-off-by: Hans de Goede <hdegoede@redhat.com>
- Patchset: cameras
- ---
- drivers/platform/x86/intel/int3472/tps68470.c | 33 ++++++++++++++-----
- 1 file changed, 25 insertions(+), 8 deletions(-)
- diff --git a/drivers/platform/x86/intel/int3472/tps68470.c b/drivers/platform/x86/intel/int3472/tps68470.c
- index b94cf66ab61f..78e34e7b6969 100644
- --- a/drivers/platform/x86/intel/int3472/tps68470.c
- +++ b/drivers/platform/x86/intel/int3472/tps68470.c
- @@ -5,6 +5,7 @@
- #include <linux/mfd/core.h>
- #include <linux/mfd/tps68470.h>
- #include <linux/platform_device.h>
- +#include <linux/platform_data/tps68470.h>
- #include <linux/regmap.h>
-
- #include "common.h"
- @@ -17,12 +18,6 @@ static const struct mfd_cell tps68470_cros[] = {
- { .name = "tps68470_pmic_opregion" },
- };
-
- -static const struct mfd_cell tps68470_win[] = {
- - { .name = "tps68470-gpio" },
- - { .name = "tps68470-clk" },
- - { .name = "tps68470-regulator" },
- -};
- -
- static const struct regmap_config tps68470_regmap_config = {
- .reg_bits = 8,
- .val_bits = 8,
- @@ -105,10 +100,17 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev)
- static int skl_int3472_tps68470_probe(struct i2c_client *client)
- {
- struct acpi_device *adev = ACPI_COMPANION(&client->dev);
- + struct tps68470_clk_platform_data clk_pdata = {};
- + struct mfd_cell *cells;
- struct regmap *regmap;
- int device_type;
- int ret;
-
- + ret = skl_int3472_get_sensor_adev_and_name(&client->dev, NULL,
- + &clk_pdata.consumer_dev_name);
- + if (ret)
- + return ret;
- +
- regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
- if (IS_ERR(regmap)) {
- dev_err(&client->dev, "Failed to create regmap: %ld\n", PTR_ERR(regmap));
- @@ -126,9 +128,24 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
- device_type = skl_int3472_tps68470_calc_type(adev);
- switch (device_type) {
- case DESIGNED_FOR_WINDOWS:
- - ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
- - tps68470_win, ARRAY_SIZE(tps68470_win),
- + cells = kcalloc(3, sizeof(*cells), GFP_KERNEL);
- + if (!cells)
- + return -ENOMEM;
- +
- + cells[0].name = "tps68470-clk";
- + cells[0].platform_data = &clk_pdata;
- + cells[0].pdata_size = sizeof(clk_pdata);
- + cells[1].name = "tps68470-regulator";
- + /*
- + * The GPIO cell must be last because acpi_gpiochip_add() calls
- + * acpi_dev_clear_dependencies() and the clk + regulators must
- + * be ready when this happens.
- + */
- + cells[2].name = "tps68470-gpio";
- +
- + ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE, cells, 3,
- NULL, 0, NULL);
- + kfree(cells);
- break;
- case DESIGNED_FOR_CHROMEOS:
- ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
- --
- 2.34.0
- From 63ac25978683d2ab14df13c54f566c1e49558d77 Mon Sep 17 00:00:00 2001
- From: Hans de Goede <hdegoede@redhat.com>
- Date: Sun, 10 Oct 2021 20:57:06 +0200
- Subject: [PATCH] platform/x86: int3472: Pass tps68470_regulator_platform_data
- to the tps68470-regulator MFD-cell
- Pass tps68470_regulator_platform_data to the tps68470-regulator
- MFD-cell, specifying the voltages of the various regulators and
- tying the regulators to the sensor supplies so that sensors which use
- the TPS68470 can find their regulators.
- Since the voltages and supply connections are board-specific, this
- introduces a DMI matches int3472_tps68470_board_data struct which
- contains the necessary per-board info.
- This per-board info also includes GPIO lookup information for the
- sensor GPIOs which may be connected to the tps68470 gpios.
- Signed-off-by: Hans de Goede <hdegoede@redhat.com>
- Patchset: cameras
- ---
- drivers/platform/x86/intel/int3472/Makefile | 2 +-
- drivers/platform/x86/intel/int3472/tps68470.c | 43 +++++--
- drivers/platform/x86/intel/int3472/tps68470.h | 25 ++++
- .../x86/intel/int3472/tps68470_board_data.c | 118 ++++++++++++++++++
- 4 files changed, 180 insertions(+), 8 deletions(-)
- create mode 100644 drivers/platform/x86/intel/int3472/tps68470.h
- create mode 100644 drivers/platform/x86/intel/int3472/tps68470_board_data.c
- diff --git a/drivers/platform/x86/intel/int3472/Makefile b/drivers/platform/x86/intel/int3472/Makefile
- index 4a4b2518ea16..ca56e7eea781 100644
- --- a/drivers/platform/x86/intel/int3472/Makefile
- +++ b/drivers/platform/x86/intel/int3472/Makefile
- @@ -1,4 +1,4 @@
- obj-$(CONFIG_INTEL_SKL_INT3472) += intel_skl_int3472_discrete.o \
- intel_skl_int3472_tps68470.o
- intel_skl_int3472_discrete-y := discrete.o clk_and_regulator.o common.o
- -intel_skl_int3472_tps68470-y := tps68470.o common.o
- +intel_skl_int3472_tps68470-y := tps68470.o tps68470_board_data.o common.o
- diff --git a/drivers/platform/x86/intel/int3472/tps68470.c b/drivers/platform/x86/intel/int3472/tps68470.c
- index 78e34e7b6969..aae24d228770 100644
- --- a/drivers/platform/x86/intel/int3472/tps68470.c
- +++ b/drivers/platform/x86/intel/int3472/tps68470.c
- @@ -9,6 +9,7 @@
- #include <linux/regmap.h>
-
- #include "common.h"
- +#include "tps68470.h"
-
- #define DESIGNED_FOR_CHROMEOS 1
- #define DESIGNED_FOR_WINDOWS 2
- @@ -100,6 +101,7 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev)
- static int skl_int3472_tps68470_probe(struct i2c_client *client)
- {
- struct acpi_device *adev = ACPI_COMPANION(&client->dev);
- + const struct int3472_tps68470_board_data *board_data;
- struct tps68470_clk_platform_data clk_pdata = {};
- struct mfd_cell *cells;
- struct regmap *regmap;
- @@ -128,6 +130,12 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
- device_type = skl_int3472_tps68470_calc_type(adev);
- switch (device_type) {
- case DESIGNED_FOR_WINDOWS:
- + board_data = int3472_tps68470_get_board_data(dev_name(&client->dev));
- + if (!board_data) {
- + dev_err(&client->dev, "No board-data found for this laptop/tablet model\n");
- + return -ENODEV;
- + }
- +
- cells = kcalloc(3, sizeof(*cells), GFP_KERNEL);
- if (!cells)
- return -ENOMEM;
- @@ -136,6 +144,8 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
- cells[0].platform_data = &clk_pdata;
- cells[0].pdata_size = sizeof(clk_pdata);
- cells[1].name = "tps68470-regulator";
- + cells[1].platform_data = (void *)board_data->tps68470_regulator_pdata;
- + cells[1].pdata_size = sizeof(struct tps68470_regulator_platform_data);
- /*
- * The GPIO cell must be last because acpi_gpiochip_add() calls
- * acpi_dev_clear_dependencies() and the clk + regulators must
- @@ -143,9 +153,15 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
- */
- cells[2].name = "tps68470-gpio";
-
- + gpiod_add_lookup_table(board_data->tps68470_gpio_lookup_table);
- +
- ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE, cells, 3,
- NULL, 0, NULL);
- kfree(cells);
- +
- + if (ret)
- + gpiod_remove_lookup_table(board_data->tps68470_gpio_lookup_table);
- +
- break;
- case DESIGNED_FOR_CHROMEOS:
- ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
- @@ -160,18 +176,31 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
- return ret;
- }
-
- +static int skl_int3472_tps68470_remove(struct i2c_client *client)
- +{
- + const struct int3472_tps68470_board_data *board_data;
- +
- + board_data = int3472_tps68470_get_board_data(dev_name(&client->dev));
- + if (board_data)
- + gpiod_remove_lookup_table(board_data->tps68470_gpio_lookup_table);
- +
- + return 0;
- +}
- +
- +
- static const struct acpi_device_id int3472_device_id[] = {
- - { "INT3472", 0 },
- - { }
- + { "INT3472", 0 },
- + { }
- };
- MODULE_DEVICE_TABLE(acpi, int3472_device_id);
-
- static struct i2c_driver int3472_tps68470 = {
- - .driver = {
- - .name = "int3472-tps68470",
- - .acpi_match_table = int3472_device_id,
- - },
- - .probe_new = skl_int3472_tps68470_probe,
- + .driver = {
- + .name = "int3472-tps68470",
- + .acpi_match_table = int3472_device_id,
- + },
- + .probe_new = skl_int3472_tps68470_probe,
- + .remove = skl_int3472_tps68470_remove,
- };
- module_i2c_driver(int3472_tps68470);
-
- diff --git a/drivers/platform/x86/intel/int3472/tps68470.h b/drivers/platform/x86/intel/int3472/tps68470.h
- new file mode 100644
- index 000000000000..cfd33eb62740
- --- /dev/null
- +++ b/drivers/platform/x86/intel/int3472/tps68470.h
- @@ -0,0 +1,25 @@
- +/* SPDX-License-Identifier: GPL-2.0 */
- +/*
- + * TI TPS68470 PMIC platform data definition.
- + *
- + * Copyright (c) 2021 Red Hat Inc.
- + *
- + * Red Hat authors:
- + * Hans de Goede <hdegoede@redhat.com>
- + */
- +
- +#ifndef _INTEL_SKL_INT3472_TPS68470_H
- +#define _INTEL_SKL_INT3472_TPS68470_H
- +
- +struct gpiod_lookup_table;
- +struct tps68470_regulator_platform_data;
- +
- +struct int3472_tps68470_board_data {
- + const char *dev_name;
- + struct gpiod_lookup_table *tps68470_gpio_lookup_table;
- + const struct tps68470_regulator_platform_data *tps68470_regulator_pdata;
- +};
- +
- +const struct int3472_tps68470_board_data *int3472_tps68470_get_board_data(const char *dev_name);
- +
- +#endif
- diff --git a/drivers/platform/x86/intel/int3472/tps68470_board_data.c b/drivers/platform/x86/intel/int3472/tps68470_board_data.c
- new file mode 100644
- index 000000000000..96954a789bb8
- --- /dev/null
- +++ b/drivers/platform/x86/intel/int3472/tps68470_board_data.c
- @@ -0,0 +1,118 @@
- +// SPDX-License-Identifier: GPL-2.0
- +/*
- + * TI TPS68470 PMIC platform data definition.
- + *
- + * Copyright (c) 2021 Dan Scally <djrscally@gmail.com>
- + * Copyright (c) 2021 Red Hat Inc.
- + *
- + * Red Hat authors:
- + * Hans de Goede <hdegoede@redhat.com>
- + */
- +
- +#include <linux/dmi.h>
- +#include <linux/gpio/machine.h>
- +#include <linux/platform_data/tps68470.h>
- +#include <linux/regulator/machine.h>
- +#include "tps68470.h"
- +
- +static struct regulator_consumer_supply int347a_core_consumer_supplies[] = {
- + REGULATOR_SUPPLY("dvdd", "i2c-INT347A:00"),
- +};
- +
- +static struct regulator_consumer_supply int347a_ana_consumer_supplies[] = {
- + REGULATOR_SUPPLY("avdd", "i2c-INT347A:00"),
- +};
- +
- +static struct regulator_consumer_supply int347a_vsio_consumer_supplies[] = {
- + REGULATOR_SUPPLY("dovdd", "i2c-INT347A:00"),
- +};
- +
- +static const struct regulator_init_data surface_go_tps68470_core_reg_init_data = {
- + .constraints = {
- + .min_uV = 1200000,
- + .max_uV = 1200000,
- + .apply_uV = 1,
- + .valid_ops_mask = REGULATOR_CHANGE_STATUS,
- + },
- + .num_consumer_supplies = ARRAY_SIZE(int347a_core_consumer_supplies),
- + .consumer_supplies = int347a_core_consumer_supplies,
- +};
- +
- +static const struct regulator_init_data surface_go_tps68470_ana_reg_init_data = {
- + .constraints = {
- + .min_uV = 2815200,
- + .max_uV = 2815200,
- + .apply_uV = 1,
- + .valid_ops_mask = REGULATOR_CHANGE_STATUS,
- + },
- + .num_consumer_supplies = ARRAY_SIZE(int347a_ana_consumer_supplies),
- + .consumer_supplies = int347a_ana_consumer_supplies,
- +};
- +
- +static const struct regulator_init_data surface_go_tps68470_vsio_reg_init_data = {
- + .constraints = {
- + .min_uV = 1800600,
- + .max_uV = 1800600,
- + .apply_uV = 1,
- + .valid_ops_mask = REGULATOR_CHANGE_STATUS,
- + },
- + .num_consumer_supplies = ARRAY_SIZE(int347a_vsio_consumer_supplies),
- + .consumer_supplies = int347a_vsio_consumer_supplies,
- +};
- +
- +static const struct tps68470_regulator_platform_data surface_go_tps68470_pdata = {
- + .reg_init_data = {
- + [TPS68470_CORE] = &surface_go_tps68470_core_reg_init_data,
- + [TPS68470_ANA] = &surface_go_tps68470_ana_reg_init_data,
- + [TPS68470_VSIO] = &surface_go_tps68470_vsio_reg_init_data,
- + },
- +};
- +
- +static struct gpiod_lookup_table surface_go_tps68470_gpios = {
- + .dev_id = "i2c-INT347A:00",
- + .table = {
- + GPIO_LOOKUP("tps68470-gpio", 9, "reset", GPIO_ACTIVE_LOW),
- + GPIO_LOOKUP("tps68470-gpio", 7, "powerdown", GPIO_ACTIVE_LOW)
- + }
- +};
- +
- +static const struct int3472_tps68470_board_data surface_go_tps68470_board_data = {
- + .dev_name = "i2c-INT3472:05",
- + .tps68470_gpio_lookup_table = &surface_go_tps68470_gpios,
- + .tps68470_regulator_pdata = &surface_go_tps68470_pdata,
- +};
- +
- +static const struct dmi_system_id int3472_tps68470_board_data_table[] = {
- + {
- + .matches = {
- + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
- + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Surface Go"),
- + },
- + .driver_data = (void *)&surface_go_tps68470_board_data,
- + },
- + {
- + .matches = {
- + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
- + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Surface Go 2"),
- + },
- + .driver_data = (void *)&surface_go_tps68470_board_data,
- + },
- + { }
- +};
- +
- +const struct int3472_tps68470_board_data *int3472_tps68470_get_board_data(const char *dev_name)
- +{
- + const struct int3472_tps68470_board_data *board_data;
- + const struct dmi_system_id *match;
- +
- + match = dmi_first_match(int3472_tps68470_board_data_table);
- + while (match) {
- + board_data = match->driver_data;
- + if (strcmp(board_data->dev_name, dev_name) == 0)
- + return board_data;
- +
- + dmi_first_match(++match);
- + }
- +
- + return NULL;
- +}
- --
- 2.34.0
- From d6ccffda8953c4027933bd1d9a8e8d08794d737b Mon Sep 17 00:00:00 2001
- From: Hans de Goede <hdegoede@redhat.com>
- Date: Sun, 10 Oct 2021 20:57:07 +0200
- Subject: [PATCH] platform/x86: int3472: Deal with probe ordering issues
- The clk and regulator frameworks expect clk/regulator consumer-devices
- to have info about the consumed clks/regulators described in the device's
- fw_node.
- To work around this info missing from the ACPI tables on devices where
- the int3472 driver is used, the int3472 MFD-cell drivers attach info about
- consumers to the clks/regulators when registering these.
- This causes problems with the probe ordering wrt drivers for consumers
- of these clks/regulators. Since the lookups are only registered when the
- provider-driver binds, trying to get these clks/regulators before then
- results in a -ENOENT error for clks and a dummy regulator for regulators.
- All the sensor ACPI fw-nodes have a _DEP dependency on the INT3472 ACPI
- fw-node, so to work around these probe ordering issues the ACPI core /
- i2c-code does not instantiate the I2C-clients for any ACPI devices
- which have a _DEP dependency on an INT3472 ACPI device until all
- _DEP-s are met.
- This relies on acpi_dev_clear_dependencies() getting called by the driver
- for the _DEP-s when they are ready, add a acpi_dev_clear_dependencies()
- call to the discrete.c probe code.
- In the tps68470 case calling acpi_dev_clear_dependencies() is already done
- by the acpi_gpiochip_add() call done by the driver for the GPIO MFD cell
- (The GPIO cell is deliberately the last cell created to make sure the
- clk + regulator cells are already instantiated when this happens).
- However for proper probe ordering, the clk/regulator cells must not just
- be instantiated the must be fully ready (the clks + regulators must be
- registered with their subsystems).
- Add MODULE_SOFTDEP dependencies for the clk and regulator drivers for
- the instantiated MFD-cells so that these are loaded before us and so
- that they bind immediately when the platform-devs are instantiated.
- Signed-off-by: Hans de Goede <hdegoede@redhat.com>
- Patchset: cameras
- ---
- drivers/platform/x86/intel/int3472/discrete.c | 1 +
- drivers/platform/x86/intel/int3472/tps68470.c | 6 ++++++
- 2 files changed, 7 insertions(+)
- diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
- index 22a4894f1cc7..3e1d755b3f83 100644
- --- a/drivers/platform/x86/intel/int3472/discrete.c
- +++ b/drivers/platform/x86/intel/int3472/discrete.c
- @@ -380,6 +380,7 @@ static int skl_int3472_discrete_probe(struct platform_device *pdev)
- return ret;
- }
-
- + acpi_dev_clear_dependencies(adev);
- return 0;
- }
-
- diff --git a/drivers/platform/x86/intel/int3472/tps68470.c b/drivers/platform/x86/intel/int3472/tps68470.c
- index aae24d228770..21c6c1a6edfc 100644
- --- a/drivers/platform/x86/intel/int3472/tps68470.c
- +++ b/drivers/platform/x86/intel/int3472/tps68470.c
- @@ -173,6 +173,11 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
- return device_type;
- }
-
- + /*
- + * No acpi_dev_clear_dependencies() here, since the acpi_gpiochip_add()
- + * for the GPIO cell already does this.
- + */
- +
- return ret;
- }
-
- @@ -207,3 +212,4 @@ module_i2c_driver(int3472_tps68470);
- MODULE_DESCRIPTION("Intel SkyLake INT3472 ACPI TPS68470 Device Driver");
- MODULE_AUTHOR("Daniel Scally <djrscally@gmail.com>");
- MODULE_LICENSE("GPL v2");
- +MODULE_SOFTDEP("pre: clk-tps68470 tps68470-regulator");
- --
- 2.34.0
- From 64c49983fc05d4f61403f89c1640710efcaf6373 Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Thu, 22 Jul 2021 00:20:46 +0100
- Subject: [PATCH] Revert "media: device property: Call
- fwnode_graph_get_endpoint_by_id() for fwnode->secondary"
- This reverts commit acd418bfcfc415cf5e6414b6d1c6acfec850f290. Checking for
- endpoints against fwnode->secondary in fwnode_graph_get_next_endpoint() is
- a better way to do this since that function is also used in a bunch of
- other places, for instance sensor drivers checking that they do have an
- endpoint connected during probe.
- Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/base/property.c | 9 +--------
- 1 file changed, 1 insertion(+), 8 deletions(-)
- diff --git a/drivers/base/property.c b/drivers/base/property.c
- index d0874f6c29bb..4d7ff55df95d 100644
- --- a/drivers/base/property.c
- +++ b/drivers/base/property.c
- @@ -1212,14 +1212,7 @@ fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode,
- best_ep_id = fwnode_ep.id;
- }
-
- - if (best_ep)
- - return best_ep;
- -
- - if (fwnode && !IS_ERR_OR_NULL(fwnode->secondary))
- - return fwnode_graph_get_endpoint_by_id(fwnode->secondary, port,
- - endpoint, flags);
- -
- - return NULL;
- + return best_ep;
- }
- EXPORT_SYMBOL_GPL(fwnode_graph_get_endpoint_by_id);
-
- --
- 2.34.0
- From 4a3ae1cf1b9f54a434dfc7bfbf9cb9a28a311133 Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Sun, 18 Jul 2021 23:52:42 +0100
- Subject: [PATCH] device property: Check fwnode->secondary in
- fwnode_graph_get_next_endpoint()
- Sensor drivers often check for an endpoint to make sure that they're
- connected to a consuming device like a CIO2 during .probe(). Some of
- those endpoints might be in the form of software_nodes assigned as
- a secondary to the device's fwnode_handle. Account for this possibility
- in fwnode_graph_get_next_endpoint() to avoid having to do it in the
- sensor drivers themselves.
- Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/base/property.c | 21 ++++++++++++++++++++-
- 1 file changed, 20 insertions(+), 1 deletion(-)
- diff --git a/drivers/base/property.c b/drivers/base/property.c
- index 4d7ff55df95d..453918eb7390 100644
- --- a/drivers/base/property.c
- +++ b/drivers/base/property.c
- @@ -1033,7 +1033,26 @@ struct fwnode_handle *
- fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode,
- struct fwnode_handle *prev)
- {
- - return fwnode_call_ptr_op(fwnode, graph_get_next_endpoint, prev);
- + const struct fwnode_handle *parent;
- + struct fwnode_handle *ep;
- +
- + /*
- + * If this function is in a loop and the previous iteration returned
- + * an endpoint from fwnode->secondary, then we need to use the secondary
- + * as parent rather than @fwnode.
- + */
- + if (prev)
- + parent = fwnode_graph_get_port_parent(prev);
- + else
- + parent = fwnode;
- +
- + ep = fwnode_call_ptr_op(parent, graph_get_next_endpoint, prev);
- +
- + if (IS_ERR_OR_NULL(ep) &&
- + !IS_ERR_OR_NULL(parent) && !IS_ERR_OR_NULL(parent->secondary))
- + ep = fwnode_graph_get_next_endpoint(parent->secondary, NULL);
- +
- + return ep;
- }
- EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);
-
- --
- 2.34.0
- From cdfc01465ee94ccc1a18afca99de9e63cc9dae34 Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Thu, 4 Nov 2021 21:46:27 +0000
- Subject: [PATCH] media: i2c: Add integration time margin to ov8865
- Without this integration margin to reduce the max exposure, it seems
- that we trip over a limit that results in the image being entirely
- black when max exposure is set. Add the margin to prevent this issue.
- With thanks to jhautbois for spotting and reporting.
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 4 +++-
- 1 file changed, 3 insertions(+), 1 deletion(-)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index d5af8aedf5e8..966487e32bfe 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -143,6 +143,7 @@
- #define OV8865_EXPOSURE_CTRL_L_REG 0x3502
- #define OV8865_EXPOSURE_CTRL_L(v) ((v) & GENMASK(7, 0))
- #define OV8865_EXPOSURE_GAIN_MANUAL_REG 0x3503
- +#define OV8865_INTEGRATION_TIME_MARGIN 8
-
- #define OV8865_GAIN_CTRL_H_REG 0x3508
- #define OV8865_GAIN_CTRL_H(v) (((v) & GENMASK(12, 8)) >> 8)
- @@ -2462,7 +2463,8 @@ static int ov8865_s_ctrl(struct v4l2_ctrl *ctrl)
- if (ctrl->id == V4L2_CID_VBLANK) {
- int exposure_max;
-
- - exposure_max = sensor->state.mode->output_size_y + ctrl->val;
- + exposure_max = sensor->state.mode->output_size_y + ctrl->val -
- + OV8865_INTEGRATION_TIME_MARGIN;
- __v4l2_ctrl_modify_range(sensor->ctrls.exposure,
- sensor->ctrls.exposure->minimum,
- exposure_max,
- --
- 2.34.0
- From 65117e827b931d5b5b62bc8428ee3543efbb422c Mon Sep 17 00:00:00 2001
- From: Daniel Scally <djrscally@gmail.com>
- Date: Thu, 4 Nov 2021 21:48:38 +0000
- Subject: [PATCH] media: i2c: Fix max gain in ov8865
- The maximum gain figure in the v4l2 ctrl is wrong. The field is 12 bits
- wide, which is where the 8191 figure comes from, but the datasheet is
- specific that maximum gain is 16x (the low seven bits are fractional, so
- 16x gain is 2048)
- Signed-off-by: Daniel Scally <djrscally@gmail.com>
- Patchset: cameras
- ---
- drivers/media/i2c/ov8865.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
- diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
- index 966487e32bfe..6c78edb65d1e 100644
- --- a/drivers/media/i2c/ov8865.c
- +++ b/drivers/media/i2c/ov8865.c
- @@ -2535,7 +2535,7 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
-
- /* Gain */
-
- - v4l2_ctrl_new_std(handler, ops, V4L2_CID_ANALOGUE_GAIN, 128, 8191, 128,
- + v4l2_ctrl_new_std(handler, ops, V4L2_CID_ANALOGUE_GAIN, 128, 2048, 128,
- 128);
-
- /* White Balance */
- --
- 2.34.0
|