0010-cameras.patch 165 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357
  1. From 92a75d7afacee622b3f426bc75c7b59aeb36d304 Mon Sep 17 00:00:00 2001
  2. From: Daniel Scally <djrscally@gmail.com>
  3. Date: Mon, 5 Apr 2021 23:56:53 +0100
  4. Subject: [PATCH] media: ipu3-cio2: Toggle sensor streaming in pm runtime ops
  5. The .suspend() and .resume() runtime_pm operations for the ipu3-cio2
  6. driver currently do not handle the sensor's stream. Setting .s_stream() on
  7. or off for the sensor subdev means that sensors will pause and resume the
  8. stream at the appropriate time even if their drivers don't implement those
  9. operations.
  10. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  11. Patchset: cameras
  12. ---
  13. drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 15 ++++++++++++++-
  14. 1 file changed, 14 insertions(+), 1 deletion(-)
  15. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  16. index 47db0ee0fcbf..7bb86e246ebe 100644
  17. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  18. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  19. @@ -1973,12 +1973,19 @@ static int __maybe_unused cio2_suspend(struct device *dev)
  20. struct pci_dev *pci_dev = to_pci_dev(dev);
  21. struct cio2_device *cio2 = pci_get_drvdata(pci_dev);
  22. struct cio2_queue *q = cio2->cur_queue;
  23. + int r;
  24. dev_dbg(dev, "cio2 suspend\n");
  25. if (!cio2->streaming)
  26. return 0;
  27. /* Stop stream */
  28. + r = v4l2_subdev_call(q->sensor, video, s_stream, 0);
  29. + if (r) {
  30. + dev_err(dev, "failed to stop sensor streaming\n");
  31. + return r;
  32. + }
  33. +
  34. cio2_hw_exit(cio2, q);
  35. synchronize_irq(pci_dev->irq);
  36. @@ -2013,8 +2020,14 @@ static int __maybe_unused cio2_resume(struct device *dev)
  37. }
  38. r = cio2_hw_init(cio2, q);
  39. - if (r)
  40. + if (r) {
  41. dev_err(dev, "fail to init cio2 hw\n");
  42. + return r;
  43. + }
  44. +
  45. + r = v4l2_subdev_call(q->sensor, video, s_stream, 1);
  46. + if (r)
  47. + dev_err(dev, "fail to start sensor streaming\n");
  48. return r;
  49. }
  50. --
  51. 2.34.0
  52. From aef7dcd154115d18e90e2bc4b48891730ecff98b Mon Sep 17 00:00:00 2001
  53. From: Daniel Scally <djrscally@gmail.com>
  54. Date: Mon, 5 Apr 2021 23:56:54 +0100
  55. Subject: [PATCH] media: i2c: Add support for ov5693 sensor
  56. The OV5693 is a 5 Mpx CMOS image sensor, connected via MIPI CSI-2. The
  57. chip is capable of a single lane configuration, but currently only two
  58. lanes are supported.
  59. Most of the sensor's features are supported, with the main exception
  60. being the lens correction algorithm.
  61. The driver provides all mandatory, optional and recommended V4L2 controls
  62. for maximum compatibility with libcamera.
  63. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  64. Patchset: cameras
  65. ---
  66. MAINTAINERS | 7 +
  67. drivers/media/i2c/Kconfig | 11 +
  68. drivers/media/i2c/Makefile | 1 +
  69. drivers/media/i2c/ov5693.c | 1557 ++++++++++++++++++++++++++++++++++++
  70. 4 files changed, 1576 insertions(+)
  71. create mode 100644 drivers/media/i2c/ov5693.c
  72. diff --git a/MAINTAINERS b/MAINTAINERS
  73. index 5713585d060d..33fdad7a7ddf 100644
  74. --- a/MAINTAINERS
  75. +++ b/MAINTAINERS
  76. @@ -13757,6 +13757,13 @@ S: Maintained
  77. T: git git://linuxtv.org/media_tree.git
  78. F: drivers/media/i2c/ov5675.c
  79. +OMNIVISION OV5693 SENSOR DRIVER
  80. +M: Daniel Scally <djrscally@gmail.com>
  81. +L: linux-media@vger.kernel.org
  82. +S: Maintained
  83. +T: git git://linuxtv.org/media_tree.git
  84. +F: drivers/media/i2c/ov5693.c
  85. +
  86. OMNIVISION OV5695 SENSOR DRIVER
  87. M: Shunqian Zheng <zhengsq@rock-chips.com>
  88. L: linux-media@vger.kernel.org
  89. diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
  90. index bde7fb021564..b2ac84d78b91 100644
  91. --- a/drivers/media/i2c/Kconfig
  92. +++ b/drivers/media/i2c/Kconfig
  93. @@ -1015,6 +1015,17 @@ config VIDEO_OV5675
  94. To compile this driver as a module, choose M here: the
  95. module will be called ov5675.
  96. +config VIDEO_OV5693
  97. + tristate "OmniVision OV5693 sensor support"
  98. + depends on I2C && VIDEO_V4L2
  99. + select V4L2_FWNODE
  100. + help
  101. + This is a Video4Linux2 sensor driver for the OmniVision
  102. + OV5693 camera.
  103. +
  104. + To compile this driver as a module, choose M here: the
  105. + module will be called ov5693.
  106. +
  107. config VIDEO_OV5695
  108. tristate "OmniVision OV5695 sensor support"
  109. depends on I2C && VIDEO_V4L2
  110. diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
  111. index 1168fa6b84ed..011e90c1a288 100644
  112. --- a/drivers/media/i2c/Makefile
  113. +++ b/drivers/media/i2c/Makefile
  114. @@ -75,6 +75,7 @@ obj-$(CONFIG_VIDEO_OV5647) += ov5647.o
  115. obj-$(CONFIG_VIDEO_OV5648) += ov5648.o
  116. obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
  117. obj-$(CONFIG_VIDEO_OV5675) += ov5675.o
  118. +obj-$(CONFIG_VIDEO_OV5693) += ov5693.o
  119. obj-$(CONFIG_VIDEO_OV5695) += ov5695.o
  120. obj-$(CONFIG_VIDEO_OV6650) += ov6650.o
  121. obj-$(CONFIG_VIDEO_OV7251) += ov7251.o
  122. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  123. new file mode 100644
  124. index 000000000000..9499ee10f56c
  125. --- /dev/null
  126. +++ b/drivers/media/i2c/ov5693.c
  127. @@ -0,0 +1,1557 @@
  128. +// SPDX-License-Identifier: GPL-2.0
  129. +/*
  130. + * Copyright (c) 2013 Intel Corporation. All Rights Reserved.
  131. + *
  132. + * Adapted from the atomisp-ov5693 driver, with contributions from:
  133. + *
  134. + * Daniel Scally
  135. + * Jean-Michel Hautbois
  136. + * Fabian Wuthrich
  137. + * Tsuchiya Yuto
  138. + * Jordan Hand
  139. + * Jake Day
  140. + */
  141. +
  142. +#include <asm/unaligned.h>
  143. +#include <linux/acpi.h>
  144. +#include <linux/clk.h>
  145. +#include <linux/delay.h>
  146. +#include <linux/device.h>
  147. +#include <linux/i2c.h>
  148. +#include <linux/module.h>
  149. +#include <linux/pm_runtime.h>
  150. +#include <linux/regulator/consumer.h>
  151. +#include <linux/slab.h>
  152. +#include <linux/types.h>
  153. +#include <media/v4l2-ctrls.h>
  154. +#include <media/v4l2-device.h>
  155. +#include <media/v4l2-fwnode.h>
  156. +
  157. +/* System Control */
  158. +#define OV5693_SW_RESET_REG 0x0103
  159. +#define OV5693_SW_STREAM_REG 0x0100
  160. +#define OV5693_START_STREAMING 0x01
  161. +#define OV5693_STOP_STREAMING 0x00
  162. +#define OV5693_SW_RESET 0x01
  163. +
  164. +#define OV5693_REG_CHIP_ID_H 0x300a
  165. +#define OV5693_REG_CHIP_ID_L 0x300b
  166. +/* Yes, this is right. The datasheet for the OV5693 gives its ID as 0x5690 */
  167. +#define OV5693_CHIP_ID 0x5690
  168. +
  169. +/* Exposure */
  170. +#define OV5693_EXPOSURE_L_CTRL_HH_REG 0x3500
  171. +#define OV5693_EXPOSURE_L_CTRL_H_REG 0x3501
  172. +#define OV5693_EXPOSURE_L_CTRL_L_REG 0x3502
  173. +#define OV5693_EXPOSURE_CTRL_HH(v) (((v) & GENMASK(14, 12)) >> 12)
  174. +#define OV5693_EXPOSURE_CTRL_H(v) (((v) & GENMASK(11, 4)) >> 4)
  175. +#define OV5693_EXPOSURE_CTRL_L(v) (((v) & GENMASK(3, 0)) << 4)
  176. +#define OV5693_INTEGRATION_TIME_MARGIN 8
  177. +#define OV5693_EXPOSURE_MIN 1
  178. +#define OV5693_EXPOSURE_STEP 1
  179. +
  180. +/* Analogue Gain */
  181. +#define OV5693_GAIN_CTRL_H_REG 0x350a
  182. +#define OV5693_GAIN_CTRL_H(v) (((v) >> 4) & GENMASK(2, 0))
  183. +#define OV5693_GAIN_CTRL_L_REG 0x350b
  184. +#define OV5693_GAIN_CTRL_L(v) (((v) << 4) & GENMASK(7, 4))
  185. +#define OV5693_GAIN_MIN 1
  186. +#define OV5693_GAIN_MAX 127
  187. +#define OV5693_GAIN_DEF 8
  188. +#define OV5693_GAIN_STEP 1
  189. +
  190. +/* Digital Gain */
  191. +#define OV5693_MWB_RED_GAIN_H_REG 0x3400
  192. +#define OV5693_MWB_RED_GAIN_L_REG 0x3401
  193. +#define OV5693_MWB_GREEN_GAIN_H_REG 0x3402
  194. +#define OV5693_MWB_GREEN_GAIN_L_REG 0x3403
  195. +#define OV5693_MWB_BLUE_GAIN_H_REG 0x3404
  196. +#define OV5693_MWB_BLUE_GAIN_L_REG 0x3405
  197. +#define OV5693_MWB_GAIN_H_CTRL(v) (((v) >> 8) & GENMASK(3, 0))
  198. +#define OV5693_MWB_GAIN_L_CTRL(v) ((v) & GENMASK(7, 0))
  199. +#define OV5693_MWB_GAIN_MAX 0x0fff
  200. +#define OV5693_DIGITAL_GAIN_MIN 1
  201. +#define OV5693_DIGITAL_GAIN_MAX 4095
  202. +#define OV5693_DIGITAL_GAIN_DEF 1024
  203. +#define OV5693_DIGITAL_GAIN_STEP 1
  204. +
  205. +/* Timing and Format */
  206. +#define OV5693_CROP_START_X_H_REG 0x3800
  207. +#define OV5693_CROP_START_X_H(v) (((v) & GENMASK(12, 8)) >> 8)
  208. +#define OV5693_CROP_START_X_L_REG 0x3801
  209. +#define OV5693_CROP_START_X_L(v) ((v) & GENMASK(7, 0))
  210. +
  211. +#define OV5693_CROP_START_Y_H_REG 0x3802
  212. +#define OV5693_CROP_START_Y_H(v) (((v) & GENMASK(11, 8)) >> 8)
  213. +#define OV5693_CROP_START_Y_L_REG 0x3803
  214. +#define OV5693_CROP_START_Y_L(v) ((v) & GENMASK(7, 0))
  215. +
  216. +#define OV5693_CROP_END_X_H_REG 0x3804
  217. +#define OV5693_CROP_END_X_H(v) (((v) & GENMASK(12, 8)) >> 8)
  218. +#define OV5693_CROP_END_X_L_REG 0x3805
  219. +#define OV5693_CROP_END_X_L(v) ((v) & GENMASK(7, 0))
  220. +
  221. +#define OV5693_CROP_END_Y_H_REG 0x3806
  222. +#define OV5693_CROP_END_Y_H(v) (((v) & GENMASK(11, 8)) >> 8)
  223. +#define OV5693_CROP_END_Y_L_REG 0x3807
  224. +#define OV5693_CROP_END_Y_L(v) ((v) & GENMASK(7, 0))
  225. +
  226. +#define OV5693_OUTPUT_SIZE_X_H_REG 0x3808
  227. +#define OV5693_OUTPUT_SIZE_X_H(v) (((v) & GENMASK(15, 8)) >> 8)
  228. +#define OV5693_OUTPUT_SIZE_X_L_REG 0x3809
  229. +#define OV5693_OUTPUT_SIZE_X_L(v) ((v) & GENMASK(7, 0))
  230. +
  231. +#define OV5693_OUTPUT_SIZE_Y_H_REG 0x380a
  232. +#define OV5693_OUTPUT_SIZE_Y_H(v) (((v) & GENMASK(15, 8)) >> 8)
  233. +#define OV5693_OUTPUT_SIZE_Y_L_REG 0x380b
  234. +#define OV5693_OUTPUT_SIZE_Y_L(v) ((v) & GENMASK(7, 0))
  235. +
  236. +#define OV5693_TIMING_HTS_H_REG 0x380c
  237. +#define OV5693_TIMING_HTS_H(v) (((v) & GENMASK(15, 8)) >> 8)
  238. +#define OV5693_TIMING_HTS_L_REG 0x380d
  239. +#define OV5693_TIMING_HTS_L(v) ((v) & GENMASK(7, 0))
  240. +#define OV5693_FIXED_PPL 2688U
  241. +
  242. +#define OV5693_TIMING_VTS_H_REG 0x380e
  243. +#define OV5693_TIMING_VTS_H(v) (((v) & GENMASK(15, 8)) >> 8)
  244. +#define OV5693_TIMING_VTS_L_REG 0x380f
  245. +#define OV5693_TIMING_VTS_L(v) ((v) & GENMASK(7, 0))
  246. +#define OV5693_TIMING_MAX_VTS 0xffff
  247. +#define OV5693_TIMING_MIN_VTS 0x04
  248. +
  249. +#define OV5693_OFFSET_START_X_H_REG 0x3810
  250. +#define OV5693_OFFSET_START_X_H(v) (((v) & GENMASK(15, 8)) >> 8)
  251. +#define OV5693_OFFSET_START_X_L_REG 0x3811
  252. +#define OV5693_OFFSET_START_X_L(v) ((v) & GENMASK(7, 0))
  253. +
  254. +#define OV5693_OFFSET_START_Y_H_REG 0x3812
  255. +#define OV5693_OFFSET_START_Y_H(v) (((v) & GENMASK(15, 8)) >> 8)
  256. +#define OV5693_OFFSET_START_Y_L_REG 0x3813
  257. +#define OV5693_OFFSET_START_Y_L(v) ((v) & GENMASK(7, 0))
  258. +
  259. +#define OV5693_SUB_INC_X_REG 0x3814
  260. +#define OV5693_SUB_INC_Y_REG 0x3815
  261. +
  262. +#define OV5693_FORMAT1_REG 0x3820
  263. +#define OV5693_FORMAT1_FLIP_VERT_ISP_EN BIT(2)
  264. +#define OV5693_FORMAT1_FLIP_VERT_SENSOR_EN BIT(1)
  265. +#define OV5693_FORMAT1_VBIN_EN BIT(0)
  266. +#define OV5693_FORMAT2_REG 0x3821
  267. +#define OV5693_FORMAT2_HDR_EN BIT(7)
  268. +#define OV5693_FORMAT2_FLIP_HORZ_ISP_EN BIT(2)
  269. +#define OV5693_FORMAT2_FLIP_HORZ_SENSOR_EN BIT(1)
  270. +#define OV5693_FORMAT2_HBIN_EN BIT(0)
  271. +
  272. +#define OV5693_ISP_CTRL2_REG 0x5002
  273. +#define OV5693_ISP_SCALE_ENABLE BIT(7)
  274. +
  275. +/* Pixel Array */
  276. +#define OV5693_NATIVE_WIDTH 2624
  277. +#define OV5693_NATIVE_HEIGHT 1956
  278. +#define OV5693_NATIVE_START_LEFT 0
  279. +#define OV5693_NATIVE_START_TOP 0
  280. +#define OV5693_ACTIVE_WIDTH 2592
  281. +#define OV5693_ACTIVE_HEIGHT 1944
  282. +#define OV5693_ACTIVE_START_LEFT 16
  283. +#define OV5693_ACTIVE_START_TOP 6
  284. +#define OV5693_MIN_CROP_WIDTH 2
  285. +#define OV5693_MIN_CROP_HEIGHT 2
  286. +
  287. +/* Test Pattern */
  288. +#define OV5693_TEST_PATTERN_REG 0x5e00
  289. +#define OV5693_TEST_PATTERN_ENABLE BIT(7)
  290. +#define OV5693_TEST_PATTERN_ROLLING BIT(6)
  291. +#define OV5693_TEST_PATTERN_RANDOM 0x01
  292. +#define OV5693_TEST_PATTERN_BARS 0x00
  293. +
  294. +/* System Frequencies */
  295. +#define OV5693_XVCLK_FREQ 19200000
  296. +#define OV5693_LINK_FREQ_400MHZ 400000000
  297. +#define OV5693_PIXEL_RATE 160000000
  298. +
  299. +/* Miscellaneous */
  300. +#define OV5693_NUM_SUPPLIES 2
  301. +
  302. +#define to_ov5693_sensor(x) container_of(x, struct ov5693_device, sd)
  303. +
  304. +struct ov5693_reg {
  305. + u16 reg;
  306. + u8 val;
  307. +};
  308. +
  309. +struct ov5693_reg_list {
  310. + u32 num_regs;
  311. + const struct ov5693_reg *regs;
  312. +};
  313. +
  314. +struct ov5693_device {
  315. + struct i2c_client *client;
  316. + struct device *dev;
  317. +
  318. + /* Protect against concurrent changes to controls */
  319. + struct mutex lock;
  320. +
  321. + struct gpio_desc *reset;
  322. + struct gpio_desc *powerdown;
  323. + struct regulator_bulk_data supplies[OV5693_NUM_SUPPLIES];
  324. + struct clk *clk;
  325. +
  326. + struct ov5693_mode {
  327. + struct v4l2_rect crop;
  328. + struct v4l2_mbus_framefmt format;
  329. + bool binning_x;
  330. + bool binning_y;
  331. + unsigned int inc_x_odd;
  332. + unsigned int inc_y_odd;
  333. + unsigned int vts;
  334. + } mode;
  335. + bool streaming;
  336. +
  337. + struct v4l2_subdev sd;
  338. + struct media_pad pad;
  339. +
  340. + struct ov5693_v4l2_ctrls {
  341. + struct v4l2_ctrl_handler handler;
  342. + struct v4l2_ctrl *link_freq;
  343. + struct v4l2_ctrl *pixel_rate;
  344. + struct v4l2_ctrl *exposure;
  345. + struct v4l2_ctrl *analogue_gain;
  346. + struct v4l2_ctrl *digital_gain;
  347. + struct v4l2_ctrl *hflip;
  348. + struct v4l2_ctrl *vflip;
  349. + struct v4l2_ctrl *hblank;
  350. + struct v4l2_ctrl *vblank;
  351. + struct v4l2_ctrl *test_pattern;
  352. + } ctrls;
  353. +};
  354. +
  355. +static const struct ov5693_reg ov5693_global_regs[] = {
  356. + {0x3016, 0xf0},
  357. + {0x3017, 0xf0},
  358. + {0x3018, 0xf0},
  359. + {0x3022, 0x01},
  360. + {0x3028, 0x44},
  361. + {0x3098, 0x02},
  362. + {0x3099, 0x19},
  363. + {0x309a, 0x02},
  364. + {0x309b, 0x01},
  365. + {0x309c, 0x00},
  366. + {0x30a0, 0xd2},
  367. + {0x30a2, 0x01},
  368. + {0x30b2, 0x00},
  369. + {0x30b3, 0x7d},
  370. + {0x30b4, 0x03},
  371. + {0x30b5, 0x04},
  372. + {0x30b6, 0x01},
  373. + {0x3104, 0x21},
  374. + {0x3106, 0x00},
  375. + {0x3406, 0x01},
  376. + {0x3503, 0x07},
  377. + {0x350b, 0x40},
  378. + {0x3601, 0x0a},
  379. + {0x3602, 0x38},
  380. + {0x3612, 0x80},
  381. + {0x3620, 0x54},
  382. + {0x3621, 0xc7},
  383. + {0x3622, 0x0f},
  384. + {0x3625, 0x10},
  385. + {0x3630, 0x55},
  386. + {0x3631, 0xf4},
  387. + {0x3632, 0x00},
  388. + {0x3633, 0x34},
  389. + {0x3634, 0x02},
  390. + {0x364d, 0x0d},
  391. + {0x364f, 0xdd},
  392. + {0x3660, 0x04},
  393. + {0x3662, 0x10},
  394. + {0x3663, 0xf1},
  395. + {0x3665, 0x00},
  396. + {0x3666, 0x20},
  397. + {0x3667, 0x00},
  398. + {0x366a, 0x80},
  399. + {0x3680, 0xe0},
  400. + {0x3681, 0x00},
  401. + {0x3700, 0x42},
  402. + {0x3701, 0x14},
  403. + {0x3702, 0xa0},
  404. + {0x3703, 0xd8},
  405. + {0x3704, 0x78},
  406. + {0x3705, 0x02},
  407. + {0x370a, 0x00},
  408. + {0x370b, 0x20},
  409. + {0x370c, 0x0c},
  410. + {0x370d, 0x11},
  411. + {0x370e, 0x00},
  412. + {0x370f, 0x40},
  413. + {0x3710, 0x00},
  414. + {0x371a, 0x1c},
  415. + {0x371b, 0x05},
  416. + {0x371c, 0x01},
  417. + {0x371e, 0xa1},
  418. + {0x371f, 0x0c},
  419. + {0x3721, 0x00},
  420. + {0x3724, 0x10},
  421. + {0x3726, 0x00},
  422. + {0x372a, 0x01},
  423. + {0x3730, 0x10},
  424. + {0x3738, 0x22},
  425. + {0x3739, 0xe5},
  426. + {0x373a, 0x50},
  427. + {0x373b, 0x02},
  428. + {0x373c, 0x41},
  429. + {0x373f, 0x02},
  430. + {0x3740, 0x42},
  431. + {0x3741, 0x02},
  432. + {0x3742, 0x18},
  433. + {0x3743, 0x01},
  434. + {0x3744, 0x02},
  435. + {0x3747, 0x10},
  436. + {0x374c, 0x04},
  437. + {0x3751, 0xf0},
  438. + {0x3752, 0x00},
  439. + {0x3753, 0x00},
  440. + {0x3754, 0xc0},
  441. + {0x3755, 0x00},
  442. + {0x3756, 0x1a},
  443. + {0x3758, 0x00},
  444. + {0x3759, 0x0f},
  445. + {0x376b, 0x44},
  446. + {0x375c, 0x04},
  447. + {0x3774, 0x10},
  448. + {0x3776, 0x00},
  449. + {0x377f, 0x08},
  450. + {0x3780, 0x22},
  451. + {0x3781, 0x0c},
  452. + {0x3784, 0x2c},
  453. + {0x3785, 0x1e},
  454. + {0x378f, 0xf5},
  455. + {0x3791, 0xb0},
  456. + {0x3795, 0x00},
  457. + {0x3796, 0x64},
  458. + {0x3797, 0x11},
  459. + {0x3798, 0x30},
  460. + {0x3799, 0x41},
  461. + {0x379a, 0x07},
  462. + {0x379b, 0xb0},
  463. + {0x379c, 0x0c},
  464. + {0x3a04, 0x06},
  465. + {0x3a05, 0x14},
  466. + {0x3e07, 0x20},
  467. + {0x4000, 0x08},
  468. + {0x4001, 0x04},
  469. + {0x4004, 0x08},
  470. + {0x4006, 0x20},
  471. + {0x4008, 0x24},
  472. + {0x4009, 0x10},
  473. + {0x4058, 0x00},
  474. + {0x4101, 0xb2},
  475. + {0x4307, 0x31},
  476. + {0x4511, 0x05},
  477. + {0x4512, 0x01},
  478. + {0x481f, 0x30},
  479. + {0x4826, 0x2c},
  480. + {0x4d02, 0xfd},
  481. + {0x4d03, 0xf5},
  482. + {0x4d04, 0x0c},
  483. + {0x4d05, 0xcc},
  484. + {0x4837, 0x0a},
  485. + {0x5003, 0x20},
  486. + {0x5013, 0x00},
  487. + {0x5842, 0x01},
  488. + {0x5843, 0x2b},
  489. + {0x5844, 0x01},
  490. + {0x5845, 0x92},
  491. + {0x5846, 0x01},
  492. + {0x5847, 0x8f},
  493. + {0x5848, 0x01},
  494. + {0x5849, 0x0c},
  495. + {0x5e10, 0x0c},
  496. + {0x3820, 0x00},
  497. + {0x3821, 0x1e},
  498. + {0x5041, 0x14}
  499. +};
  500. +
  501. +static const struct ov5693_reg_list ov5693_global_setting = {
  502. + .num_regs = ARRAY_SIZE(ov5693_global_regs),
  503. + .regs = ov5693_global_regs,
  504. +};
  505. +
  506. +static const struct v4l2_rect ov5693_default_crop = {
  507. + .left = OV5693_ACTIVE_START_LEFT,
  508. + .top = OV5693_ACTIVE_START_TOP,
  509. + .width = OV5693_ACTIVE_WIDTH,
  510. + .height = OV5693_ACTIVE_HEIGHT,
  511. +};
  512. +
  513. +static const struct v4l2_mbus_framefmt ov5693_default_fmt = {
  514. + .width = OV5693_ACTIVE_WIDTH,
  515. + .height = OV5693_ACTIVE_HEIGHT,
  516. + .code = MEDIA_BUS_FMT_SBGGR10_1X10,
  517. +};
  518. +
  519. +static const s64 link_freq_menu_items[] = {
  520. + OV5693_LINK_FREQ_400MHZ
  521. +};
  522. +
  523. +static const char * const ov5693_supply_names[] = {
  524. + "avdd",
  525. + "dovdd",
  526. +};
  527. +
  528. +static const char * const ov5693_test_pattern_menu[] = {
  529. + "Disabled",
  530. + "Random Data",
  531. + "Colour Bars",
  532. + "Colour Bars with Rolling Bar"
  533. +};
  534. +
  535. +static const u8 ov5693_test_pattern_bits[] = {
  536. + 0,
  537. + OV5693_TEST_PATTERN_ENABLE | OV5693_TEST_PATTERN_RANDOM,
  538. + OV5693_TEST_PATTERN_ENABLE | OV5693_TEST_PATTERN_BARS,
  539. + OV5693_TEST_PATTERN_ENABLE | OV5693_TEST_PATTERN_BARS |
  540. + OV5693_TEST_PATTERN_ROLLING,
  541. +};
  542. +
  543. +/* I2C I/O Operations */
  544. +
  545. +static int ov5693_read_reg(struct ov5693_device *ov5693, u16 addr, u8 *value)
  546. +{
  547. + struct i2c_client *client = ov5693->client;
  548. + struct i2c_msg msgs[2];
  549. + u8 addr_buf[2];
  550. + u8 data_buf;
  551. + int ret;
  552. +
  553. + put_unaligned_be16(addr, addr_buf);
  554. +
  555. + /* Write register address */
  556. + msgs[0].addr = client->addr;
  557. + msgs[0].flags = 0;
  558. + msgs[0].len = ARRAY_SIZE(addr_buf);
  559. + msgs[0].buf = addr_buf;
  560. +
  561. + /* Read register value */
  562. + msgs[1].addr = client->addr;
  563. + msgs[1].flags = I2C_M_RD;
  564. + msgs[1].len = 1;
  565. + msgs[1].buf = &data_buf;
  566. +
  567. + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
  568. + if (ret != ARRAY_SIZE(msgs))
  569. + return -EIO;
  570. +
  571. + *value = data_buf;
  572. +
  573. + return 0;
  574. +}
  575. +
  576. +static void ov5693_write_reg(struct ov5693_device *ov5693, u16 addr, u8 value,
  577. + int *error)
  578. +{
  579. + unsigned char data[3] = { addr >> 8, addr & 0xff, value };
  580. + int ret;
  581. +
  582. + if (*error < 0)
  583. + return;
  584. +
  585. + ret = i2c_master_send(ov5693->client, data, sizeof(data));
  586. + if (ret < 0) {
  587. + dev_dbg(ov5693->dev, "i2c send error at address 0x%04x: %d\n",
  588. + addr, ret);
  589. + *error = ret;
  590. + }
  591. +}
  592. +
  593. +static int ov5693_write_reg_array(struct ov5693_device *ov5693,
  594. + const struct ov5693_reg_list *reglist)
  595. +{
  596. + unsigned int i;
  597. + int ret = 0;
  598. +
  599. + for (i = 0; i < reglist->num_regs; i++)
  600. + ov5693_write_reg(ov5693, reglist->regs[i].reg,
  601. + reglist->regs[i].val, &ret);
  602. +
  603. + return ret;
  604. +}
  605. +
  606. +static int ov5693_update_bits(struct ov5693_device *ov5693, u16 address,
  607. + u16 mask, u16 bits)
  608. +{
  609. + u8 value = 0;
  610. + int ret;
  611. +
  612. + ret = ov5693_read_reg(ov5693, address, &value);
  613. + if (ret)
  614. + return ret;
  615. +
  616. + value &= ~mask;
  617. + value |= bits;
  618. +
  619. + ov5693_write_reg(ov5693, address, value, &ret);
  620. +
  621. + return ret;
  622. +}
  623. +
  624. +/* V4L2 Controls Functions */
  625. +
  626. +static int ov5693_flip_vert_configure(struct ov5693_device *ov5693, bool enable)
  627. +{
  628. + u8 bits = OV5693_FORMAT1_FLIP_VERT_ISP_EN |
  629. + OV5693_FORMAT1_FLIP_VERT_SENSOR_EN;
  630. + int ret;
  631. +
  632. + ret = ov5693_update_bits(ov5693, OV5693_FORMAT1_REG, bits,
  633. + enable ? bits : 0);
  634. + if (ret)
  635. + return ret;
  636. +
  637. + return 0;
  638. +}
  639. +
  640. +static int ov5693_flip_horz_configure(struct ov5693_device *ov5693, bool enable)
  641. +{
  642. + u8 bits = OV5693_FORMAT2_FLIP_HORZ_ISP_EN |
  643. + OV5693_FORMAT2_FLIP_HORZ_SENSOR_EN;
  644. + int ret;
  645. +
  646. + ret = ov5693_update_bits(ov5693, OV5693_FORMAT2_REG, bits,
  647. + enable ? bits : 0);
  648. + if (ret)
  649. + return ret;
  650. +
  651. + return 0;
  652. +}
  653. +
  654. +static int ov5693_get_exposure(struct ov5693_device *ov5693, s32 *value)
  655. +{
  656. + u8 exposure_hh = 0, exposure_h = 0, exposure_l = 0;
  657. + int ret;
  658. +
  659. + ret = ov5693_read_reg(ov5693, OV5693_EXPOSURE_L_CTRL_HH_REG, &exposure_hh);
  660. + if (ret)
  661. + return ret;
  662. +
  663. + ret = ov5693_read_reg(ov5693, OV5693_EXPOSURE_L_CTRL_H_REG, &exposure_h);
  664. + if (ret)
  665. + return ret;
  666. +
  667. + ret = ov5693_read_reg(ov5693, OV5693_EXPOSURE_L_CTRL_L_REG, &exposure_l);
  668. + if (ret)
  669. + return ret;
  670. +
  671. + /* The lowest 4 bits are unsupported fractional bits */
  672. + *value = ((exposure_hh << 16) | (exposure_h << 8) | exposure_l) >> 4;
  673. +
  674. + return 0;
  675. +}
  676. +
  677. +static int ov5693_exposure_configure(struct ov5693_device *ov5693, u32 exposure)
  678. +{
  679. + int ret = 0;
  680. +
  681. + ov5693_write_reg(ov5693, OV5693_EXPOSURE_L_CTRL_HH_REG,
  682. + OV5693_EXPOSURE_CTRL_HH(exposure), &ret);
  683. + ov5693_write_reg(ov5693, OV5693_EXPOSURE_L_CTRL_H_REG,
  684. + OV5693_EXPOSURE_CTRL_H(exposure), &ret);
  685. + ov5693_write_reg(ov5693, OV5693_EXPOSURE_L_CTRL_L_REG,
  686. + OV5693_EXPOSURE_CTRL_L(exposure), &ret);
  687. +
  688. + return ret;
  689. +}
  690. +
  691. +static int ov5693_get_gain(struct ov5693_device *ov5693, u32 *gain)
  692. +{
  693. + u8 gain_l = 0, gain_h = 0;
  694. + int ret;
  695. +
  696. + ret = ov5693_read_reg(ov5693, OV5693_GAIN_CTRL_H_REG, &gain_h);
  697. + if (ret)
  698. + return ret;
  699. +
  700. + ret = ov5693_read_reg(ov5693, OV5693_GAIN_CTRL_L_REG, &gain_l);
  701. + if (ret)
  702. + return ret;
  703. +
  704. + /* As with exposure, the lowest 4 bits are fractional bits. */
  705. + *gain = ((gain_h << 8) | gain_l) >> 4;
  706. +
  707. + return ret;
  708. +}
  709. +
  710. +static int ov5693_digital_gain_configure(struct ov5693_device *ov5693, u32 gain)
  711. +{
  712. + int ret = 0;
  713. +
  714. + ov5693_write_reg(ov5693, OV5693_MWB_RED_GAIN_H_REG,
  715. + OV5693_MWB_GAIN_H_CTRL(gain), &ret);
  716. + ov5693_write_reg(ov5693, OV5693_MWB_RED_GAIN_L_REG,
  717. + OV5693_MWB_GAIN_L_CTRL(gain), &ret);
  718. + ov5693_write_reg(ov5693, OV5693_MWB_GREEN_GAIN_H_REG,
  719. + OV5693_MWB_GAIN_H_CTRL(gain), &ret);
  720. + ov5693_write_reg(ov5693, OV5693_MWB_GREEN_GAIN_L_REG,
  721. + OV5693_MWB_GAIN_L_CTRL(gain), &ret);
  722. + ov5693_write_reg(ov5693, OV5693_MWB_BLUE_GAIN_H_REG,
  723. + OV5693_MWB_GAIN_H_CTRL(gain), &ret);
  724. + ov5693_write_reg(ov5693, OV5693_MWB_BLUE_GAIN_L_REG,
  725. + OV5693_MWB_GAIN_L_CTRL(gain), &ret);
  726. +
  727. + return ret;
  728. +}
  729. +
  730. +static int ov5693_analog_gain_configure(struct ov5693_device *ov5693, u32 gain)
  731. +{
  732. + int ret = 0;
  733. +
  734. + ov5693_write_reg(ov5693, OV5693_GAIN_CTRL_L_REG,
  735. + OV5693_GAIN_CTRL_L(gain), &ret);
  736. + ov5693_write_reg(ov5693, OV5693_GAIN_CTRL_H_REG,
  737. + OV5693_GAIN_CTRL_H(gain), &ret);
  738. +
  739. + return ret;
  740. +}
  741. +
  742. +static int ov5693_vts_configure(struct ov5693_device *ov5693, u32 vblank)
  743. +{
  744. + u16 vts = ov5693->mode.format.height + vblank;
  745. + int ret = 0;
  746. +
  747. + ov5693_write_reg(ov5693, OV5693_TIMING_VTS_H_REG,
  748. + OV5693_TIMING_VTS_H(vts), &ret);
  749. + ov5693_write_reg(ov5693, OV5693_TIMING_VTS_L_REG,
  750. + OV5693_TIMING_VTS_L(vts), &ret);
  751. +
  752. + return ret;
  753. +}
  754. +
  755. +static int ov5693_test_pattern_configure(struct ov5693_device *ov5693, u32 idx)
  756. +{
  757. + int ret = 0;
  758. +
  759. + ov5693_write_reg(ov5693, OV5693_TEST_PATTERN_REG,
  760. + ov5693_test_pattern_bits[idx], &ret);
  761. +
  762. + return ret;
  763. +}
  764. +
  765. +static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
  766. +{
  767. + struct ov5693_device *ov5693 =
  768. + container_of(ctrl->handler, struct ov5693_device, ctrls.handler);
  769. + int ret = 0;
  770. +
  771. + /* If VBLANK is altered we need to update exposure to compensate */
  772. + if (ctrl->id == V4L2_CID_VBLANK) {
  773. + int exposure_max;
  774. +
  775. + exposure_max = ov5693->mode.format.height + ctrl->val -
  776. + OV5693_INTEGRATION_TIME_MARGIN;
  777. + __v4l2_ctrl_modify_range(ov5693->ctrls.exposure,
  778. + ov5693->ctrls.exposure->minimum,
  779. + exposure_max,
  780. + ov5693->ctrls.exposure->step,
  781. + min(ov5693->ctrls.exposure->val, exposure_max));
  782. + }
  783. +
  784. + /* Only apply changes to the controls if the device is powered up */
  785. + if (!pm_runtime_get_if_in_use(ov5693->dev))
  786. + return 0;
  787. +
  788. + switch (ctrl->id) {
  789. + case V4L2_CID_EXPOSURE:
  790. + ret = ov5693_exposure_configure(ov5693, ctrl->val);
  791. + break;
  792. + case V4L2_CID_ANALOGUE_GAIN:
  793. + ret = ov5693_analog_gain_configure(ov5693, ctrl->val);
  794. + break;
  795. + case V4L2_CID_DIGITAL_GAIN:
  796. + ret = ov5693_digital_gain_configure(ov5693, ctrl->val);
  797. + break;
  798. + case V4L2_CID_HFLIP:
  799. + ret = ov5693_flip_horz_configure(ov5693, !!ctrl->val);
  800. + break;
  801. + case V4L2_CID_VFLIP:
  802. + ret = ov5693_flip_vert_configure(ov5693, !!ctrl->val);
  803. + break;
  804. + case V4L2_CID_VBLANK:
  805. + ret = ov5693_vts_configure(ov5693, ctrl->val);
  806. + break;
  807. + case V4L2_CID_TEST_PATTERN:
  808. + ret = ov5693_test_pattern_configure(ov5693, ctrl->val);
  809. + break;
  810. + default:
  811. + ret = -EINVAL;
  812. + }
  813. +
  814. + pm_runtime_put(ov5693->dev);
  815. +
  816. + return ret;
  817. +}
  818. +
  819. +static int ov5693_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
  820. +{
  821. + struct ov5693_device *ov5693 =
  822. + container_of(ctrl->handler, struct ov5693_device, ctrls.handler);
  823. +
  824. + switch (ctrl->id) {
  825. + case V4L2_CID_EXPOSURE_ABSOLUTE:
  826. + return ov5693_get_exposure(ov5693, &ctrl->val);
  827. + case V4L2_CID_AUTOGAIN:
  828. + return ov5693_get_gain(ov5693, &ctrl->val);
  829. + default:
  830. + return -EINVAL;
  831. + }
  832. +}
  833. +
  834. +static const struct v4l2_ctrl_ops ov5693_ctrl_ops = {
  835. + .s_ctrl = ov5693_s_ctrl,
  836. + .g_volatile_ctrl = ov5693_g_volatile_ctrl
  837. +};
  838. +
  839. +/* System Control Functions */
  840. +
  841. +static int ov5693_mode_configure(struct ov5693_device *ov5693)
  842. +{
  843. + const struct ov5693_mode *mode = &ov5693->mode;
  844. + int ret = 0;
  845. +
  846. + /* Crop Start X */
  847. + ov5693_write_reg(ov5693, OV5693_CROP_START_X_H_REG,
  848. + OV5693_CROP_START_X_H(mode->crop.left), &ret);
  849. + ov5693_write_reg(ov5693, OV5693_CROP_START_X_L_REG,
  850. + OV5693_CROP_START_X_L(mode->crop.left), &ret);
  851. +
  852. + /* Offset X */
  853. + ov5693_write_reg(ov5693, OV5693_OFFSET_START_X_H_REG,
  854. + OV5693_OFFSET_START_X_H(0), &ret);
  855. + ov5693_write_reg(ov5693, OV5693_OFFSET_START_X_L_REG,
  856. + OV5693_OFFSET_START_X_L(0), &ret);
  857. +
  858. + /* Output Size X */
  859. + ov5693_write_reg(ov5693, OV5693_OUTPUT_SIZE_X_H_REG,
  860. + OV5693_OUTPUT_SIZE_X_H(mode->format.width), &ret);
  861. + ov5693_write_reg(ov5693, OV5693_OUTPUT_SIZE_X_L_REG,
  862. + OV5693_OUTPUT_SIZE_X_L(mode->format.width), &ret);
  863. +
  864. + /* Crop End X */
  865. + ov5693_write_reg(ov5693, OV5693_CROP_END_X_H_REG,
  866. + OV5693_CROP_END_X_H(mode->crop.left + mode->crop.width),
  867. + &ret);
  868. + ov5693_write_reg(ov5693, OV5693_CROP_END_X_L_REG,
  869. + OV5693_CROP_END_X_L(mode->crop.left + mode->crop.width),
  870. + &ret);
  871. +
  872. + /* Horizontal Total Size */
  873. + ov5693_write_reg(ov5693, OV5693_TIMING_HTS_H_REG,
  874. + OV5693_TIMING_HTS_H(OV5693_FIXED_PPL), &ret);
  875. + ov5693_write_reg(ov5693, OV5693_TIMING_HTS_L_REG,
  876. + OV5693_TIMING_HTS_L(OV5693_FIXED_PPL), &ret);
  877. +
  878. + /* Crop Start Y */
  879. + ov5693_write_reg(ov5693, OV5693_CROP_START_Y_H_REG,
  880. + OV5693_CROP_START_Y_H(mode->crop.top), &ret);
  881. + ov5693_write_reg(ov5693, OV5693_CROP_START_Y_L_REG,
  882. + OV5693_CROP_START_Y_L(mode->crop.top), &ret);
  883. +
  884. + /* Offset Y */
  885. + ov5693_write_reg(ov5693, OV5693_OFFSET_START_Y_H_REG,
  886. + OV5693_OFFSET_START_Y_H(0), &ret);
  887. + ov5693_write_reg(ov5693, OV5693_OFFSET_START_Y_L_REG,
  888. + OV5693_OFFSET_START_Y_L(0), &ret);
  889. +
  890. + /* Output Size Y */
  891. + ov5693_write_reg(ov5693, OV5693_OUTPUT_SIZE_Y_H_REG,
  892. + OV5693_OUTPUT_SIZE_Y_H(mode->format.height), &ret);
  893. + ov5693_write_reg(ov5693, OV5693_OUTPUT_SIZE_Y_L_REG,
  894. + OV5693_OUTPUT_SIZE_Y_L(mode->format.height), &ret);
  895. +
  896. + /* Crop End Y */
  897. + ov5693_write_reg(ov5693, OV5693_CROP_END_Y_H_REG,
  898. + OV5693_CROP_END_Y_H(mode->crop.top + mode->crop.height),
  899. + &ret);
  900. + ov5693_write_reg(ov5693, OV5693_CROP_END_Y_L_REG,
  901. + OV5693_CROP_END_Y_L(mode->crop.top + mode->crop.height),
  902. + &ret);
  903. +
  904. + /* Vertical Total Size */
  905. + ov5693_write_reg(ov5693, OV5693_TIMING_VTS_H_REG,
  906. + OV5693_TIMING_VTS_H(mode->vts), &ret);
  907. + ov5693_write_reg(ov5693, OV5693_TIMING_VTS_L_REG,
  908. + OV5693_TIMING_VTS_L(mode->vts), &ret);
  909. +
  910. + /* Subsample X increase */
  911. + ov5693_write_reg(ov5693, OV5693_SUB_INC_X_REG,
  912. + ((mode->inc_x_odd << 4) & 0xf0) | 0x01, &ret);
  913. + /* Subsample Y increase */
  914. + ov5693_write_reg(ov5693, OV5693_SUB_INC_Y_REG,
  915. + ((mode->inc_y_odd << 4) & 0xf0) | 0x01, &ret);
  916. +
  917. + /* Binning */
  918. + ret = ov5693_update_bits(ov5693, OV5693_FORMAT1_REG,
  919. + OV5693_FORMAT1_VBIN_EN,
  920. + mode->binning_y ? OV5693_FORMAT1_VBIN_EN : 0);
  921. + if (ret)
  922. + return ret;
  923. +
  924. + ret = ov5693_update_bits(ov5693, OV5693_FORMAT2_REG,
  925. + OV5693_FORMAT2_HBIN_EN,
  926. + mode->binning_x ? OV5693_FORMAT2_HBIN_EN : 0);
  927. +
  928. + return ret;
  929. +}
  930. +
  931. +static int ov5693_sw_standby(struct ov5693_device *ov5693, bool standby)
  932. +{
  933. + int ret = 0;
  934. +
  935. + ov5693_write_reg(ov5693, OV5693_SW_STREAM_REG,
  936. + standby ? OV5693_STOP_STREAMING : OV5693_START_STREAMING,
  937. + &ret);
  938. +
  939. + return ret;
  940. +}
  941. +
  942. +static int ov5693_sw_reset(struct ov5693_device *ov5693)
  943. +{
  944. + int ret = 0;
  945. +
  946. + ov5693_write_reg(ov5693, OV5693_SW_RESET_REG, OV5693_SW_RESET, &ret);
  947. +
  948. + return ret;
  949. +}
  950. +
  951. +static int ov5693_sensor_init(struct ov5693_device *ov5693)
  952. +{
  953. + int ret = 0;
  954. +
  955. + ret = ov5693_sw_reset(ov5693);
  956. + if (ret) {
  957. + dev_err(ov5693->dev, "%s software reset error\n", __func__);
  958. + return ret;
  959. + }
  960. +
  961. + ret = ov5693_write_reg_array(ov5693, &ov5693_global_setting);
  962. + if (ret) {
  963. + dev_err(ov5693->dev, "%s global settings error\n", __func__);
  964. + return ret;
  965. + }
  966. +
  967. + ret = ov5693_mode_configure(ov5693);
  968. + if (ret) {
  969. + dev_err(ov5693->dev, "%s mode configure error\n", __func__);
  970. + return ret;
  971. + }
  972. +
  973. + ret = ov5693_sw_standby(ov5693, true);
  974. + if (ret)
  975. + dev_err(ov5693->dev, "%s software standby error\n", __func__);
  976. +
  977. + return ret;
  978. +}
  979. +
  980. +static void ov5693_sensor_powerdown(struct ov5693_device *ov5693)
  981. +{
  982. + gpiod_set_value_cansleep(ov5693->reset, 1);
  983. + gpiod_set_value_cansleep(ov5693->powerdown, 1);
  984. +
  985. + regulator_bulk_disable(OV5693_NUM_SUPPLIES, ov5693->supplies);
  986. +
  987. + clk_disable_unprepare(ov5693->clk);
  988. +}
  989. +
  990. +static int ov5693_sensor_powerup(struct ov5693_device *ov5693)
  991. +{
  992. + int ret;
  993. +
  994. + gpiod_set_value_cansleep(ov5693->reset, 1);
  995. + gpiod_set_value_cansleep(ov5693->powerdown, 1);
  996. +
  997. + ret = clk_prepare_enable(ov5693->clk);
  998. + if (ret) {
  999. + dev_err(ov5693->dev, "Failed to enable clk\n");
  1000. + goto fail_power;
  1001. + }
  1002. +
  1003. + ret = regulator_bulk_enable(OV5693_NUM_SUPPLIES, ov5693->supplies);
  1004. + if (ret) {
  1005. + dev_err(ov5693->dev, "Failed to enable regulators\n");
  1006. + goto fail_power;
  1007. + }
  1008. +
  1009. + gpiod_set_value_cansleep(ov5693->powerdown, 0);
  1010. + gpiod_set_value_cansleep(ov5693->reset, 0);
  1011. +
  1012. + usleep_range(5000, 7500);
  1013. +
  1014. + return 0;
  1015. +
  1016. +fail_power:
  1017. + ov5693_sensor_powerdown(ov5693);
  1018. + return ret;
  1019. +}
  1020. +
  1021. +static int __maybe_unused ov5693_sensor_suspend(struct device *dev)
  1022. +{
  1023. + struct v4l2_subdev *sd = dev_get_drvdata(dev);
  1024. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  1025. +
  1026. + ov5693_sensor_powerdown(ov5693);
  1027. +
  1028. + return 0;
  1029. +}
  1030. +
  1031. +static int __maybe_unused ov5693_sensor_resume(struct device *dev)
  1032. +{
  1033. + struct v4l2_subdev *sd = dev_get_drvdata(dev);
  1034. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  1035. + int ret;
  1036. +
  1037. + mutex_lock(&ov5693->lock);
  1038. +
  1039. + ret = ov5693_sensor_powerup(ov5693);
  1040. + if (ret)
  1041. + goto out_unlock;
  1042. +
  1043. + ret = ov5693_sensor_init(ov5693);
  1044. + if (ret) {
  1045. + dev_err(dev, "ov5693 sensor init failure\n");
  1046. + goto err_power;
  1047. + }
  1048. +
  1049. + goto out_unlock;
  1050. +
  1051. +err_power:
  1052. + ov5693_sensor_powerdown(ov5693);
  1053. +out_unlock:
  1054. + mutex_unlock(&ov5693->lock);
  1055. + return ret;
  1056. +}
  1057. +
  1058. +static int ov5693_detect(struct ov5693_device *ov5693)
  1059. +{
  1060. + u8 id_l = 0, id_h = 0;
  1061. + u16 id = 0;
  1062. + int ret;
  1063. +
  1064. + ret = ov5693_read_reg(ov5693, OV5693_REG_CHIP_ID_H, &id_h);
  1065. + if (ret)
  1066. + return ret;
  1067. +
  1068. + ret = ov5693_read_reg(ov5693, OV5693_REG_CHIP_ID_L, &id_l);
  1069. + if (ret)
  1070. + return ret;
  1071. +
  1072. + id = (id_h << 8) | id_l;
  1073. +
  1074. + if (id != OV5693_CHIP_ID) {
  1075. + dev_err(ov5693->dev, "sensor ID mismatch. Found 0x%04x\n", id);
  1076. + return -ENODEV;
  1077. + }
  1078. +
  1079. + return 0;
  1080. +}
  1081. +
  1082. +/* V4L2 Framework callbacks */
  1083. +
  1084. +static unsigned int __ov5693_calc_vts(u32 height)
  1085. +{
  1086. + /*
  1087. + * We need to set a sensible default VTS for whatever format height we
  1088. + * happen to be given from set_fmt(). This function just targets
  1089. + * an even multiple of 30fps.
  1090. + */
  1091. +
  1092. + unsigned int tgt_fps;
  1093. +
  1094. + tgt_fps = rounddown(OV5693_PIXEL_RATE / OV5693_FIXED_PPL / height, 30);
  1095. +
  1096. + return ALIGN_DOWN(OV5693_PIXEL_RATE / OV5693_FIXED_PPL / tgt_fps, 2);
  1097. +}
  1098. +
  1099. +static struct v4l2_mbus_framefmt *
  1100. +__ov5693_get_pad_format(struct ov5693_device *ov5693,
  1101. + struct v4l2_subdev_state *state,
  1102. + unsigned int pad, enum v4l2_subdev_format_whence which)
  1103. +{
  1104. + switch (which) {
  1105. + case V4L2_SUBDEV_FORMAT_TRY:
  1106. + return v4l2_subdev_get_try_format(&ov5693->sd, state, pad);
  1107. + case V4L2_SUBDEV_FORMAT_ACTIVE:
  1108. + return &ov5693->mode.format;
  1109. + default:
  1110. + return NULL;
  1111. + }
  1112. +}
  1113. +
  1114. +static struct v4l2_rect *
  1115. +__ov5693_get_pad_crop(struct ov5693_device *ov5693,
  1116. + struct v4l2_subdev_state *state,
  1117. + unsigned int pad, enum v4l2_subdev_format_whence which)
  1118. +{
  1119. + switch (which) {
  1120. + case V4L2_SUBDEV_FORMAT_TRY:
  1121. + return v4l2_subdev_get_try_crop(&ov5693->sd, state, pad);
  1122. + case V4L2_SUBDEV_FORMAT_ACTIVE:
  1123. + return &ov5693->mode.crop;
  1124. + }
  1125. +
  1126. + return NULL;
  1127. +}
  1128. +
  1129. +static int ov5693_get_fmt(struct v4l2_subdev *sd,
  1130. + struct v4l2_subdev_state *state,
  1131. + struct v4l2_subdev_format *format)
  1132. +{
  1133. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  1134. +
  1135. + format->format = ov5693->mode.format;
  1136. +
  1137. + return 0;
  1138. +}
  1139. +
  1140. +static int ov5693_set_fmt(struct v4l2_subdev *sd,
  1141. + struct v4l2_subdev_state *state,
  1142. + struct v4l2_subdev_format *format)
  1143. +{
  1144. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  1145. + const struct v4l2_rect *crop;
  1146. + struct v4l2_mbus_framefmt *fmt;
  1147. + unsigned int hratio, vratio;
  1148. + unsigned int width, height;
  1149. + unsigned int hblank;
  1150. + int exposure_max;
  1151. + int ret = 0;
  1152. +
  1153. + crop = __ov5693_get_pad_crop(ov5693, state, format->pad, format->which);
  1154. +
  1155. + /*
  1156. + * Align to two to simplify the binning calculations below, and clamp
  1157. + * the requested format at the crop rectangle
  1158. + */
  1159. + width = clamp_t(unsigned int, ALIGN(format->format.width, 2),
  1160. + OV5693_MIN_CROP_WIDTH, crop->width);
  1161. + height = clamp_t(unsigned int, ALIGN(format->format.height, 2),
  1162. + OV5693_MIN_CROP_HEIGHT, crop->height);
  1163. +
  1164. + /*
  1165. + * We can only support setting either the dimensions of the crop rect
  1166. + * or those dimensions binned (separately) by a factor of two.
  1167. + */
  1168. + hratio = clamp_t(unsigned int, DIV_ROUND_CLOSEST(crop->width, width), 1, 2);
  1169. + vratio = clamp_t(unsigned int, DIV_ROUND_CLOSEST(crop->height, height), 1, 2);
  1170. +
  1171. + fmt = __ov5693_get_pad_format(ov5693, state, format->pad, format->which);
  1172. +
  1173. + fmt->width = crop->width / hratio;
  1174. + fmt->height = crop->height / vratio;
  1175. + fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
  1176. +
  1177. + format->format = *fmt;
  1178. +
  1179. + if (format->which == V4L2_SUBDEV_FORMAT_TRY)
  1180. + return ret;
  1181. +
  1182. + mutex_lock(&ov5693->lock);
  1183. +
  1184. + ov5693->mode.binning_x = hratio > 1 ? true : false;
  1185. + ov5693->mode.inc_x_odd = hratio > 1 ? 3 : 1;
  1186. + ov5693->mode.binning_y = vratio > 1 ? true : false;
  1187. + ov5693->mode.inc_y_odd = vratio > 1 ? 3 : 1;
  1188. +
  1189. + ov5693->mode.vts = __ov5693_calc_vts(fmt->height);
  1190. +
  1191. + __v4l2_ctrl_modify_range(ov5693->ctrls.vblank,
  1192. + OV5693_TIMING_MIN_VTS,
  1193. + OV5693_TIMING_MAX_VTS - fmt->height,
  1194. + 1, ov5693->mode.vts - fmt->height);
  1195. + __v4l2_ctrl_s_ctrl(ov5693->ctrls.vblank,
  1196. + ov5693->mode.vts - fmt->height);
  1197. +
  1198. + hblank = OV5693_FIXED_PPL - fmt->width;
  1199. + __v4l2_ctrl_modify_range(ov5693->ctrls.hblank, hblank, hblank, 1,
  1200. + hblank);
  1201. +
  1202. + exposure_max = ov5693->mode.vts - OV5693_INTEGRATION_TIME_MARGIN;
  1203. + __v4l2_ctrl_modify_range(ov5693->ctrls.exposure,
  1204. + ov5693->ctrls.exposure->minimum, exposure_max,
  1205. + ov5693->ctrls.exposure->step,
  1206. + min(ov5693->ctrls.exposure->val, exposure_max));
  1207. +
  1208. + mutex_unlock(&ov5693->lock);
  1209. + return ret;
  1210. +}
  1211. +
  1212. +static int ov5693_get_selection(struct v4l2_subdev *sd,
  1213. + struct v4l2_subdev_state *state,
  1214. + struct v4l2_subdev_selection *sel)
  1215. +{
  1216. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  1217. +
  1218. + switch (sel->target) {
  1219. + case V4L2_SEL_TGT_CROP:
  1220. + mutex_lock(&ov5693->lock);
  1221. + sel->r = *__ov5693_get_pad_crop(ov5693, state, sel->pad,
  1222. + sel->which);
  1223. + mutex_unlock(&ov5693->lock);
  1224. + break;
  1225. + case V4L2_SEL_TGT_NATIVE_SIZE:
  1226. + sel->r.top = 0;
  1227. + sel->r.left = 0;
  1228. + sel->r.width = OV5693_NATIVE_WIDTH;
  1229. + sel->r.height = OV5693_NATIVE_HEIGHT;
  1230. + break;
  1231. + case V4L2_SEL_TGT_CROP_BOUNDS:
  1232. + case V4L2_SEL_TGT_CROP_DEFAULT:
  1233. + sel->r.top = OV5693_ACTIVE_START_TOP;
  1234. + sel->r.left = OV5693_ACTIVE_START_LEFT;
  1235. + sel->r.width = OV5693_ACTIVE_WIDTH;
  1236. + sel->r.height = OV5693_ACTIVE_HEIGHT;
  1237. + break;
  1238. + default:
  1239. + return -EINVAL;
  1240. + }
  1241. +
  1242. + return 0;
  1243. +}
  1244. +
  1245. +static int ov5693_set_selection(struct v4l2_subdev *sd,
  1246. + struct v4l2_subdev_state *state,
  1247. + struct v4l2_subdev_selection *sel)
  1248. +{
  1249. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  1250. + struct v4l2_mbus_framefmt *format;
  1251. + struct v4l2_rect *__crop;
  1252. + struct v4l2_rect rect;
  1253. +
  1254. + if (sel->target != V4L2_SEL_TGT_CROP)
  1255. + return -EINVAL;
  1256. +
  1257. + /*
  1258. + * Clamp the boundaries of the crop rectangle to the size of the sensor
  1259. + * pixel array. Align to multiples of 2 to ensure Bayer pattern isn't
  1260. + * disrupted.
  1261. + */
  1262. + rect.left = clamp(ALIGN(sel->r.left, 2), OV5693_NATIVE_START_LEFT,
  1263. + OV5693_NATIVE_WIDTH);
  1264. + rect.top = clamp(ALIGN(sel->r.top, 2), OV5693_NATIVE_START_TOP,
  1265. + OV5693_NATIVE_HEIGHT);
  1266. + rect.width = clamp_t(unsigned int, ALIGN(sel->r.width, 2),
  1267. + OV5693_MIN_CROP_WIDTH, OV5693_NATIVE_WIDTH);
  1268. + rect.height = clamp_t(unsigned int, ALIGN(sel->r.height, 2),
  1269. + OV5693_MIN_CROP_HEIGHT, OV5693_NATIVE_HEIGHT);
  1270. +
  1271. + /* Make sure the crop rectangle isn't outside the bounds of the array */
  1272. + rect.width = min_t(unsigned int, rect.width,
  1273. + OV5693_NATIVE_WIDTH - rect.left);
  1274. + rect.height = min_t(unsigned int, rect.height,
  1275. + OV5693_NATIVE_HEIGHT - rect.top);
  1276. +
  1277. + __crop = __ov5693_get_pad_crop(ov5693, state, sel->pad, sel->which);
  1278. +
  1279. + if (rect.width != __crop->width || rect.height != __crop->height) {
  1280. + /*
  1281. + * Reset the output image size if the crop rectangle size has
  1282. + * been modified.
  1283. + */
  1284. + format = __ov5693_get_pad_format(ov5693, state, sel->pad, sel->which);
  1285. + format->width = rect.width;
  1286. + format->height = rect.height;
  1287. + }
  1288. +
  1289. + *__crop = rect;
  1290. + sel->r = rect;
  1291. +
  1292. + return 0;
  1293. +}
  1294. +
  1295. +static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
  1296. +{
  1297. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  1298. + int ret;
  1299. +
  1300. + if (enable) {
  1301. + ret = pm_runtime_get_sync(ov5693->dev);
  1302. + if (ret < 0)
  1303. + goto err_power_down;
  1304. +
  1305. + ret = __v4l2_ctrl_handler_setup(&ov5693->ctrls.handler);
  1306. + if (ret)
  1307. + goto err_power_down;
  1308. + }
  1309. +
  1310. + mutex_lock(&ov5693->lock);
  1311. + ret = ov5693_sw_standby(ov5693, !enable);
  1312. + mutex_unlock(&ov5693->lock);
  1313. +
  1314. + if (ret)
  1315. + goto err_power_down;
  1316. + ov5693->streaming = !!enable;
  1317. +
  1318. + if (!enable)
  1319. + pm_runtime_put(ov5693->dev);
  1320. +
  1321. + return 0;
  1322. +err_power_down:
  1323. + pm_runtime_put_noidle(ov5693->dev);
  1324. + return ret;
  1325. +}
  1326. +
  1327. +static int ov5693_g_frame_interval(struct v4l2_subdev *sd,
  1328. + struct v4l2_subdev_frame_interval *interval)
  1329. +{
  1330. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  1331. + unsigned int framesize = OV5693_FIXED_PPL * (ov5693->mode.format.height +
  1332. + ov5693->ctrls.vblank->val);
  1333. + unsigned int fps = DIV_ROUND_CLOSEST(OV5693_PIXEL_RATE, framesize);
  1334. +
  1335. + interval->interval.numerator = 1;
  1336. + interval->interval.denominator = fps;
  1337. +
  1338. + return 0;
  1339. +}
  1340. +
  1341. +static int ov5693_enum_mbus_code(struct v4l2_subdev *sd,
  1342. + struct v4l2_subdev_state *state,
  1343. + struct v4l2_subdev_mbus_code_enum *code)
  1344. +{
  1345. + /* Only a single mbus format is supported */
  1346. + if (code->index > 0)
  1347. + return -EINVAL;
  1348. +
  1349. + code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
  1350. + return 0;
  1351. +}
  1352. +
  1353. +static int ov5693_enum_frame_size(struct v4l2_subdev *sd,
  1354. + struct v4l2_subdev_state *state,
  1355. + struct v4l2_subdev_frame_size_enum *fse)
  1356. +{
  1357. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  1358. + struct v4l2_rect *__crop;
  1359. +
  1360. + if (fse->index > 1 || fse->code != MEDIA_BUS_FMT_SBGGR10_1X10)
  1361. + return -EINVAL;
  1362. +
  1363. + __crop = __ov5693_get_pad_crop(ov5693, state, fse->pad, fse->which);
  1364. + if (!__crop)
  1365. + return -EINVAL;
  1366. +
  1367. + fse->min_width = __crop->width / (fse->index + 1);
  1368. + fse->min_height = __crop->height / (fse->index + 1);
  1369. + fse->max_width = fse->min_width;
  1370. + fse->max_height = fse->min_height;
  1371. +
  1372. + return 0;
  1373. +}
  1374. +
  1375. +static const struct v4l2_subdev_video_ops ov5693_video_ops = {
  1376. + .s_stream = ov5693_s_stream,
  1377. + .g_frame_interval = ov5693_g_frame_interval,
  1378. +};
  1379. +
  1380. +static const struct v4l2_subdev_pad_ops ov5693_pad_ops = {
  1381. + .enum_mbus_code = ov5693_enum_mbus_code,
  1382. + .enum_frame_size = ov5693_enum_frame_size,
  1383. + .get_fmt = ov5693_get_fmt,
  1384. + .set_fmt = ov5693_set_fmt,
  1385. + .get_selection = ov5693_get_selection,
  1386. + .set_selection = ov5693_set_selection,
  1387. +};
  1388. +
  1389. +static const struct v4l2_subdev_ops ov5693_ops = {
  1390. + .video = &ov5693_video_ops,
  1391. + .pad = &ov5693_pad_ops,
  1392. +};
  1393. +
  1394. +/* Sensor and Driver Configuration Functions */
  1395. +
  1396. +static int ov5693_init_controls(struct ov5693_device *ov5693)
  1397. +{
  1398. + const struct v4l2_ctrl_ops *ops = &ov5693_ctrl_ops;
  1399. + struct v4l2_fwnode_device_properties props;
  1400. + int vblank_max, vblank_def;
  1401. + int exposure_max;
  1402. + int hblank;
  1403. + int ret;
  1404. +
  1405. + ret = v4l2_ctrl_handler_init(&ov5693->ctrls.handler, 12);
  1406. + if (ret)
  1407. + return ret;
  1408. +
  1409. + /* link freq */
  1410. + ov5693->ctrls.link_freq = v4l2_ctrl_new_int_menu(&ov5693->ctrls.handler,
  1411. + NULL, V4L2_CID_LINK_FREQ,
  1412. + 0, 0, link_freq_menu_items);
  1413. + if (ov5693->ctrls.link_freq)
  1414. + ov5693->ctrls.link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  1415. +
  1416. + /* pixel rate */
  1417. + ov5693->ctrls.pixel_rate = v4l2_ctrl_new_std(&ov5693->ctrls.handler, NULL,
  1418. + V4L2_CID_PIXEL_RATE, 0,
  1419. + OV5693_PIXEL_RATE, 1,
  1420. + OV5693_PIXEL_RATE);
  1421. +
  1422. + /* Exposure */
  1423. + exposure_max = ov5693->mode.vts - OV5693_INTEGRATION_TIME_MARGIN;
  1424. + ov5693->ctrls.exposure = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
  1425. + V4L2_CID_EXPOSURE,
  1426. + OV5693_EXPOSURE_MIN,
  1427. + exposure_max,
  1428. + OV5693_EXPOSURE_STEP,
  1429. + exposure_max);
  1430. +
  1431. + /* Gain */
  1432. + ov5693->ctrls.analogue_gain = v4l2_ctrl_new_std(&ov5693->ctrls.handler,
  1433. + ops, V4L2_CID_ANALOGUE_GAIN,
  1434. + OV5693_GAIN_MIN,
  1435. + OV5693_GAIN_MAX,
  1436. + OV5693_GAIN_STEP,
  1437. + OV5693_GAIN_DEF);
  1438. +
  1439. + ov5693->ctrls.digital_gain = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
  1440. + V4L2_CID_DIGITAL_GAIN,
  1441. + OV5693_DIGITAL_GAIN_MIN,
  1442. + OV5693_DIGITAL_GAIN_MAX,
  1443. + OV5693_DIGITAL_GAIN_STEP,
  1444. + OV5693_DIGITAL_GAIN_DEF);
  1445. +
  1446. + /* Flip */
  1447. + ov5693->ctrls.hflip = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
  1448. + V4L2_CID_HFLIP, 0, 1, 1, 0);
  1449. +
  1450. + ov5693->ctrls.vflip = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
  1451. + V4L2_CID_VFLIP, 0, 1, 1, 0);
  1452. +
  1453. + hblank = OV5693_FIXED_PPL - ov5693->mode.format.width;
  1454. + ov5693->ctrls.hblank = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
  1455. + V4L2_CID_HBLANK, hblank,
  1456. + hblank, 1, hblank);
  1457. +
  1458. + if (ov5693->ctrls.hblank)
  1459. + ov5693->ctrls.hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  1460. +
  1461. + vblank_max = OV5693_TIMING_MAX_VTS - ov5693->mode.format.height;
  1462. + vblank_def = ov5693->mode.vts - ov5693->mode.format.height;
  1463. + ov5693->ctrls.vblank = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
  1464. + V4L2_CID_VBLANK,
  1465. + OV5693_TIMING_MIN_VTS,
  1466. + vblank_max, 1, vblank_def);
  1467. +
  1468. + ov5693->ctrls.test_pattern = v4l2_ctrl_new_std_menu_items(
  1469. + &ov5693->ctrls.handler, ops,
  1470. + V4L2_CID_TEST_PATTERN,
  1471. + ARRAY_SIZE(ov5693_test_pattern_menu) - 1,
  1472. + 0, 0, ov5693_test_pattern_menu);
  1473. +
  1474. + if (ov5693->ctrls.handler.error) {
  1475. + dev_err(ov5693->dev, "Error initialising v4l2 ctrls\n");
  1476. + ret = ov5693->ctrls.handler.error;
  1477. + goto err_free_handler;
  1478. + }
  1479. +
  1480. + /* set properties from fwnode (e.g. rotation, orientation) */
  1481. + ret = v4l2_fwnode_device_parse(ov5693->dev, &props);
  1482. + if (ret)
  1483. + goto err_free_handler;
  1484. +
  1485. + ret = v4l2_ctrl_new_fwnode_properties(&ov5693->ctrls.handler, ops,
  1486. + &props);
  1487. + if (ret)
  1488. + goto err_free_handler;
  1489. +
  1490. + /* Use same lock for controls as for everything else. */
  1491. + ov5693->ctrls.handler.lock = &ov5693->lock;
  1492. + ov5693->sd.ctrl_handler = &ov5693->ctrls.handler;
  1493. +
  1494. + return 0;
  1495. +
  1496. +err_free_handler:
  1497. + v4l2_ctrl_handler_free(&ov5693->ctrls.handler);
  1498. + return ret;
  1499. +}
  1500. +
  1501. +static int ov5693_configure_gpios(struct ov5693_device *ov5693)
  1502. +{
  1503. + ov5693->reset = devm_gpiod_get_optional(ov5693->dev, "reset",
  1504. + GPIOD_OUT_HIGH);
  1505. + if (IS_ERR(ov5693->reset)) {
  1506. + dev_err(ov5693->dev, "Error fetching reset GPIO\n");
  1507. + return PTR_ERR(ov5693->reset);
  1508. + }
  1509. +
  1510. + ov5693->powerdown = devm_gpiod_get_optional(ov5693->dev, "powerdown",
  1511. + GPIOD_OUT_HIGH);
  1512. + if (IS_ERR(ov5693->powerdown)) {
  1513. + dev_err(ov5693->dev, "Error fetching powerdown GPIO\n");
  1514. + return PTR_ERR(ov5693->powerdown);
  1515. + }
  1516. +
  1517. + return 0;
  1518. +}
  1519. +
  1520. +static int ov5693_get_regulators(struct ov5693_device *ov5693)
  1521. +{
  1522. + unsigned int i;
  1523. +
  1524. + for (i = 0; i < OV5693_NUM_SUPPLIES; i++)
  1525. + ov5693->supplies[i].supply = ov5693_supply_names[i];
  1526. +
  1527. + return devm_regulator_bulk_get(ov5693->dev, OV5693_NUM_SUPPLIES,
  1528. + ov5693->supplies);
  1529. +}
  1530. +
  1531. +static int ov5693_probe(struct i2c_client *client)
  1532. +{
  1533. + struct fwnode_handle *fwnode = dev_fwnode(&client->dev);
  1534. + struct fwnode_handle *endpoint;
  1535. + struct ov5693_device *ov5693;
  1536. + u32 clk_rate;
  1537. + int ret = 0;
  1538. +
  1539. + endpoint = fwnode_graph_get_next_endpoint(fwnode, NULL);
  1540. + if (!endpoint && !IS_ERR_OR_NULL(fwnode->secondary))
  1541. + endpoint = fwnode_graph_get_next_endpoint(fwnode->secondary, NULL);
  1542. + if (!endpoint)
  1543. + return -EPROBE_DEFER;
  1544. +
  1545. + ov5693 = devm_kzalloc(&client->dev, sizeof(*ov5693), GFP_KERNEL);
  1546. + if (!ov5693)
  1547. + return -ENOMEM;
  1548. +
  1549. + ov5693->client = client;
  1550. + ov5693->dev = &client->dev;
  1551. +
  1552. + mutex_init(&ov5693->lock);
  1553. +
  1554. + v4l2_i2c_subdev_init(&ov5693->sd, client, &ov5693_ops);
  1555. +
  1556. + ov5693->clk = devm_clk_get(&client->dev, "xvclk");
  1557. + if (IS_ERR(ov5693->clk)) {
  1558. + dev_err(&client->dev, "Error getting clock\n");
  1559. + return PTR_ERR(ov5693->clk);
  1560. + }
  1561. +
  1562. + clk_rate = clk_get_rate(ov5693->clk);
  1563. + if (clk_rate != OV5693_XVCLK_FREQ) {
  1564. + dev_err(&client->dev, "Unsupported clk freq %u, expected %u\n",
  1565. + clk_rate, OV5693_XVCLK_FREQ);
  1566. + return -EINVAL;
  1567. + }
  1568. +
  1569. + ret = ov5693_configure_gpios(ov5693);
  1570. + if (ret)
  1571. + return ret;
  1572. +
  1573. + ret = ov5693_get_regulators(ov5693);
  1574. + if (ret) {
  1575. + dev_err(&client->dev, "Error fetching regulators\n");
  1576. + return ret;
  1577. + }
  1578. +
  1579. + ov5693->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  1580. + ov5693->pad.flags = MEDIA_PAD_FL_SOURCE;
  1581. + ov5693->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
  1582. +
  1583. + ov5693->mode.crop = ov5693_default_crop;
  1584. + ov5693->mode.format = ov5693_default_fmt;
  1585. + ov5693->mode.vts = __ov5693_calc_vts(ov5693->mode.format.height);
  1586. +
  1587. + ret = ov5693_init_controls(ov5693);
  1588. + if (ret)
  1589. + return ret;
  1590. +
  1591. + ret = media_entity_pads_init(&ov5693->sd.entity, 1, &ov5693->pad);
  1592. + if (ret)
  1593. + goto err_ctrl_handler_free;
  1594. +
  1595. + /*
  1596. + * We need the driver to work in the event that pm runtime is disable in
  1597. + * the kernel, so power up and verify the chip now. In the event that
  1598. + * runtime pm is disabled this will leave the chip on, so that streaming
  1599. + * will work.
  1600. + */
  1601. +
  1602. + ret = ov5693_sensor_powerup(ov5693);
  1603. + if (ret)
  1604. + goto err_media_entity_cleanup;
  1605. +
  1606. + ret = ov5693_detect(ov5693);
  1607. + if (ret)
  1608. + goto err_powerdown;
  1609. +
  1610. + pm_runtime_set_active(&client->dev);
  1611. + pm_runtime_get_noresume(&client->dev);
  1612. + pm_runtime_enable(&client->dev);
  1613. +
  1614. + ret = v4l2_async_register_subdev_sensor(&ov5693->sd);
  1615. + if (ret) {
  1616. + dev_err(&client->dev, "failed to register V4L2 subdev: %d",
  1617. + ret);
  1618. + goto err_pm_runtime;
  1619. + }
  1620. +
  1621. + pm_runtime_set_autosuspend_delay(&client->dev, 1000);
  1622. + pm_runtime_use_autosuspend(&client->dev);
  1623. + pm_runtime_put_autosuspend(&client->dev);
  1624. +
  1625. + return ret;
  1626. +
  1627. +err_pm_runtime:
  1628. + pm_runtime_disable(&client->dev);
  1629. + pm_runtime_put_noidle(&client->dev);
  1630. +err_powerdown:
  1631. + ov5693_sensor_powerdown(ov5693);
  1632. +err_media_entity_cleanup:
  1633. + media_entity_cleanup(&ov5693->sd.entity);
  1634. +err_ctrl_handler_free:
  1635. + v4l2_ctrl_handler_free(&ov5693->ctrls.handler);
  1636. +
  1637. + return ret;
  1638. +}
  1639. +
  1640. +static int ov5693_remove(struct i2c_client *client)
  1641. +{
  1642. + struct v4l2_subdev *sd = i2c_get_clientdata(client);
  1643. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  1644. +
  1645. + v4l2_async_unregister_subdev(sd);
  1646. + media_entity_cleanup(&ov5693->sd.entity);
  1647. + v4l2_ctrl_handler_free(&ov5693->ctrls.handler);
  1648. + mutex_destroy(&ov5693->lock);
  1649. +
  1650. + /*
  1651. + * Disable runtime PM. In case runtime PM is disabled in the kernel,
  1652. + * make sure to turn power off manually.
  1653. + */
  1654. + pm_runtime_disable(&client->dev);
  1655. + if (!pm_runtime_status_suspended(&client->dev))
  1656. + ov5693_sensor_powerdown(ov5693);
  1657. + pm_runtime_set_suspended(&client->dev);
  1658. +
  1659. + return 0;
  1660. +}
  1661. +
  1662. +static const struct dev_pm_ops ov5693_pm_ops = {
  1663. + SET_RUNTIME_PM_OPS(ov5693_sensor_suspend, ov5693_sensor_resume, NULL)
  1664. +};
  1665. +
  1666. +static const struct acpi_device_id ov5693_acpi_match[] = {
  1667. + {"INT33BE"},
  1668. + {},
  1669. +};
  1670. +MODULE_DEVICE_TABLE(acpi, ov5693_acpi_match);
  1671. +
  1672. +static struct i2c_driver ov5693_driver = {
  1673. + .driver = {
  1674. + .name = "ov5693",
  1675. + .acpi_match_table = ov5693_acpi_match,
  1676. + .pm = &ov5693_pm_ops,
  1677. + },
  1678. + .probe_new = ov5693_probe,
  1679. + .remove = ov5693_remove,
  1680. +};
  1681. +module_i2c_driver(ov5693_driver);
  1682. +
  1683. +MODULE_DESCRIPTION("A low-level driver for OmniVision 5693 sensors");
  1684. +MODULE_LICENSE("GPL");
  1685. --
  1686. 2.34.0
  1687. From 7e9c49131077a564296f86e3d3e1813448b0fdae Mon Sep 17 00:00:00 2001
  1688. From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= <me@fabwu.ch>
  1689. Date: Fri, 22 Jan 2021 20:58:13 +0100
  1690. Subject: [PATCH] cio2-bridge: Parse sensor orientation and rotation
  1691. MIME-Version: 1.0
  1692. Content-Type: text/plain; charset=UTF-8
  1693. Content-Transfer-Encoding: 8bit
  1694. The sensor orientation is read from the _PLC ACPI buffer and converted
  1695. to a v4l2 format.
  1696. See https://uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf
  1697. page 351 for a definition of the Panel property.
  1698. The sensor rotation is read from the SSDB ACPI buffer and converted into
  1699. degrees.
  1700. Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
  1701. Patchset: cameras
  1702. ---
  1703. drivers/media/pci/intel/ipu3/cio2-bridge.c | 45 ++++++++++++++++++++--
  1704. drivers/media/pci/intel/ipu3/cio2-bridge.h | 3 ++
  1705. 2 files changed, 44 insertions(+), 4 deletions(-)
  1706. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  1707. index 30d29b96a339..77c97bf6521e 100644
  1708. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
  1709. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  1710. @@ -29,6 +29,7 @@ static const struct cio2_sensor_config cio2_supported_sensors[] = {
  1711. static const struct cio2_property_names prop_names = {
  1712. .clock_frequency = "clock-frequency",
  1713. .rotation = "rotation",
  1714. + .orientation = "orientation",
  1715. .bus_type = "bus-type",
  1716. .data_lanes = "data-lanes",
  1717. .remote_endpoint = "remote-endpoint",
  1718. @@ -72,11 +73,36 @@ static int cio2_bridge_read_acpi_buffer(struct acpi_device *adev, char *id,
  1719. return ret;
  1720. }
  1721. +static u32 cio2_bridge_parse_rotation(u8 rotation)
  1722. +{
  1723. + if (rotation == 1)
  1724. + return 180;
  1725. + return 0;
  1726. +}
  1727. +
  1728. +static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(u8 panel)
  1729. +{
  1730. + switch (panel) {
  1731. + case 4:
  1732. + return V4L2_FWNODE_ORIENTATION_FRONT;
  1733. + case 5:
  1734. + return V4L2_FWNODE_ORIENTATION_BACK;
  1735. + default:
  1736. + return V4L2_FWNODE_ORIENTATION_EXTERNAL;
  1737. + }
  1738. +}
  1739. +
  1740. static void cio2_bridge_create_fwnode_properties(
  1741. struct cio2_sensor *sensor,
  1742. struct cio2_bridge *bridge,
  1743. const struct cio2_sensor_config *cfg)
  1744. {
  1745. + u32 rotation;
  1746. + enum v4l2_fwnode_orientation orientation;
  1747. +
  1748. + rotation = cio2_bridge_parse_rotation(sensor->ssdb.degree);
  1749. + orientation = cio2_bridge_parse_orientation(sensor->pld->panel);
  1750. +
  1751. sensor->prop_names = prop_names;
  1752. sensor->local_ref[0] = SOFTWARE_NODE_REFERENCE(&sensor->swnodes[SWNODE_CIO2_ENDPOINT]);
  1753. @@ -85,9 +111,12 @@ static void cio2_bridge_create_fwnode_properties(
  1754. sensor->dev_properties[0] = PROPERTY_ENTRY_U32(
  1755. sensor->prop_names.clock_frequency,
  1756. sensor->ssdb.mclkspeed);
  1757. - sensor->dev_properties[1] = PROPERTY_ENTRY_U8(
  1758. + sensor->dev_properties[1] = PROPERTY_ENTRY_U32(
  1759. sensor->prop_names.rotation,
  1760. - sensor->ssdb.degree);
  1761. + rotation);
  1762. + sensor->dev_properties[2] = PROPERTY_ENTRY_U32(
  1763. + sensor->prop_names.orientation,
  1764. + orientation);
  1765. sensor->ep_properties[0] = PROPERTY_ENTRY_U32(
  1766. sensor->prop_names.bus_type,
  1767. @@ -159,6 +188,7 @@ static void cio2_bridge_unregister_sensors(struct cio2_bridge *bridge)
  1768. for (i = 0; i < bridge->n_sensors; i++) {
  1769. sensor = &bridge->sensors[i];
  1770. software_node_unregister_nodes(sensor->swnodes);
  1771. + ACPI_FREE(sensor->pld);
  1772. acpi_dev_put(sensor->adev);
  1773. }
  1774. }
  1775. @@ -170,6 +200,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
  1776. struct fwnode_handle *fwnode;
  1777. struct cio2_sensor *sensor;
  1778. struct acpi_device *adev;
  1779. + acpi_status status;
  1780. int ret;
  1781. for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
  1782. @@ -191,11 +222,15 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
  1783. if (ret)
  1784. goto err_put_adev;
  1785. + status = acpi_get_physical_device_location(adev->handle, &sensor->pld);
  1786. + if (ACPI_FAILURE(status))
  1787. + goto err_put_adev;
  1788. +
  1789. if (sensor->ssdb.lanes > CIO2_MAX_LANES) {
  1790. dev_err(&adev->dev,
  1791. "Number of lanes in SSDB is invalid\n");
  1792. ret = -EINVAL;
  1793. - goto err_put_adev;
  1794. + goto err_free_pld;
  1795. }
  1796. cio2_bridge_create_fwnode_properties(sensor, bridge, cfg);
  1797. @@ -203,7 +238,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
  1798. ret = software_node_register_nodes(sensor->swnodes);
  1799. if (ret)
  1800. - goto err_put_adev;
  1801. + goto err_free_pld;
  1802. fwnode = software_node_fwnode(&sensor->swnodes[
  1803. SWNODE_SENSOR_HID]);
  1804. @@ -225,6 +260,8 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
  1805. err_free_swnodes:
  1806. software_node_unregister_nodes(sensor->swnodes);
  1807. +err_free_pld:
  1808. + ACPI_FREE(sensor->pld);
  1809. err_put_adev:
  1810. acpi_dev_put(adev);
  1811. return ret;
  1812. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  1813. index dd0ffcafa489..924d99d20328 100644
  1814. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
  1815. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  1816. @@ -80,6 +80,7 @@ struct cio2_sensor_ssdb {
  1817. struct cio2_property_names {
  1818. char clock_frequency[16];
  1819. char rotation[9];
  1820. + char orientation[12];
  1821. char bus_type[9];
  1822. char data_lanes[11];
  1823. char remote_endpoint[16];
  1824. @@ -106,6 +107,8 @@ struct cio2_sensor {
  1825. struct cio2_node_names node_names;
  1826. struct cio2_sensor_ssdb ssdb;
  1827. + struct acpi_pld_info *pld;
  1828. +
  1829. struct cio2_property_names prop_names;
  1830. struct property_entry ep_properties[5];
  1831. struct property_entry dev_properties[3];
  1832. --
  1833. 2.34.0
  1834. From e163137f9b923398a4d31e3a21fe78486974d0d9 Mon Sep 17 00:00:00 2001
  1835. From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= <me@fabwu.ch>
  1836. Date: Sun, 24 Jan 2021 11:07:42 +0100
  1837. Subject: [PATCH] cio2-bridge: Use macros and add warnings
  1838. MIME-Version: 1.0
  1839. Content-Type: text/plain; charset=UTF-8
  1840. Content-Transfer-Encoding: 8bit
  1841. Use macros for the _PLD panel as defined in the ACPI spec 6.3 and emit
  1842. a warning if we see an unknown value.
  1843. Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
  1844. Patchset: cameras
  1845. ---
  1846. drivers/media/pci/intel/ipu3/cio2-bridge.c | 33 ++++++++++++++++------
  1847. drivers/media/pci/intel/ipu3/cio2-bridge.h | 13 +++++++++
  1848. 2 files changed, 37 insertions(+), 9 deletions(-)
  1849. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  1850. index 77c97bf6521e..7e582135dfb8 100644
  1851. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
  1852. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  1853. @@ -73,21 +73,36 @@ static int cio2_bridge_read_acpi_buffer(struct acpi_device *adev, char *id,
  1854. return ret;
  1855. }
  1856. -static u32 cio2_bridge_parse_rotation(u8 rotation)
  1857. +static u32 cio2_bridge_parse_rotation(struct cio2_sensor *sensor)
  1858. {
  1859. - if (rotation == 1)
  1860. + switch (sensor->ssdb.degree) {
  1861. + case CIO2_SENSOR_ROTATION_NORMAL:
  1862. + return 0;
  1863. + case CIO2_SENSOR_ROTATION_INVERTED:
  1864. return 180;
  1865. - return 0;
  1866. + default:
  1867. + dev_warn(&sensor->adev->dev,
  1868. + "Unknown rotation %d. Assume 0 degree rotation\n",
  1869. + sensor->ssdb.degree);
  1870. + return 0;
  1871. + }
  1872. }
  1873. -static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(u8 panel)
  1874. +static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(struct cio2_sensor *sensor)
  1875. {
  1876. - switch (panel) {
  1877. - case 4:
  1878. + switch (sensor->pld->panel) {
  1879. + case CIO2_PLD_PANEL_FRONT:
  1880. return V4L2_FWNODE_ORIENTATION_FRONT;
  1881. - case 5:
  1882. + case CIO2_PLD_PANEL_BACK:
  1883. return V4L2_FWNODE_ORIENTATION_BACK;
  1884. + case CIO2_PLD_PANEL_TOP:
  1885. + case CIO2_PLD_PANEL_LEFT:
  1886. + case CIO2_PLD_PANEL_RIGHT:
  1887. + case CIO2_PLD_PANEL_UNKNOWN:
  1888. + return V4L2_FWNODE_ORIENTATION_EXTERNAL;
  1889. default:
  1890. + dev_warn(&sensor->adev->dev, "Unknown _PLD panel value %d\n",
  1891. + sensor->pld->panel);
  1892. return V4L2_FWNODE_ORIENTATION_EXTERNAL;
  1893. }
  1894. }
  1895. @@ -100,8 +115,8 @@ static void cio2_bridge_create_fwnode_properties(
  1896. u32 rotation;
  1897. enum v4l2_fwnode_orientation orientation;
  1898. - rotation = cio2_bridge_parse_rotation(sensor->ssdb.degree);
  1899. - orientation = cio2_bridge_parse_orientation(sensor->pld->panel);
  1900. + rotation = cio2_bridge_parse_rotation(sensor);
  1901. + orientation = cio2_bridge_parse_orientation(sensor);
  1902. sensor->prop_names = prop_names;
  1903. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  1904. index 924d99d20328..e1e388cc9f45 100644
  1905. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
  1906. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  1907. @@ -12,6 +12,19 @@
  1908. #define CIO2_MAX_LANES 4
  1909. #define MAX_NUM_LINK_FREQS 3
  1910. +/* Values are estimated guesses as we don't have a spec */
  1911. +#define CIO2_SENSOR_ROTATION_NORMAL 0
  1912. +#define CIO2_SENSOR_ROTATION_INVERTED 1
  1913. +
  1914. +/* Panel position defined in _PLD section of ACPI Specification 6.3 */
  1915. +#define CIO2_PLD_PANEL_TOP 0
  1916. +#define CIO2_PLD_PANEL_BOTTOM 1
  1917. +#define CIO2_PLD_PANEL_LEFT 2
  1918. +#define CIO2_PLD_PANEL_RIGHT 3
  1919. +#define CIO2_PLD_PANEL_FRONT 4
  1920. +#define CIO2_PLD_PANEL_BACK 5
  1921. +#define CIO2_PLD_PANEL_UNKNOWN 6
  1922. +
  1923. #define CIO2_SENSOR_CONFIG(_HID, _NR, ...) \
  1924. (const struct cio2_sensor_config) { \
  1925. .hid = _HID, \
  1926. --
  1927. 2.34.0
  1928. From d6e2797aba5ac844c067d177000d8a7966481adc Mon Sep 17 00:00:00 2001
  1929. From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= <me@fabwu.ch>
  1930. Date: Thu, 6 May 2021 07:52:44 +0200
  1931. Subject: [PATCH] cio2-bridge: Use correct dev_properties size
  1932. Patchset: cameras
  1933. ---
  1934. drivers/media/pci/intel/ipu3/cio2-bridge.h | 2 +-
  1935. 1 file changed, 1 insertion(+), 1 deletion(-)
  1936. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  1937. index e1e388cc9f45..deaf5804f70d 100644
  1938. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
  1939. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  1940. @@ -124,7 +124,7 @@ struct cio2_sensor {
  1941. struct cio2_property_names prop_names;
  1942. struct property_entry ep_properties[5];
  1943. - struct property_entry dev_properties[3];
  1944. + struct property_entry dev_properties[4];
  1945. struct property_entry cio2_properties[3];
  1946. struct software_node_ref_args local_ref[1];
  1947. struct software_node_ref_args remote_ref[1];
  1948. --
  1949. 2.34.0
  1950. From d12db7dfc3e8a96d138c575811131acd50f227da Mon Sep 17 00:00:00 2001
  1951. From: Daniel Scally <djrscally@gmail.com>
  1952. Date: Thu, 20 May 2021 23:31:04 +0100
  1953. Subject: [PATCH] media: i2c: Fix vertical flip in ov5693
  1954. The pinkness experienced by users with rotated sensors in their laptops
  1955. was due to an incorrect setting for the vertical flip function; the
  1956. datasheet for the sensor gives the settings as bits 1&2 in one place and
  1957. bits 1&6 in another.
  1958. Switch to flipping bit 6 instead of bit 2 for 0x3820 in the vertical
  1959. flip function to fix the pink hue.
  1960. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  1961. Patchset: cameras
  1962. ---
  1963. drivers/media/i2c/ov5693.c | 2 +-
  1964. 1 file changed, 1 insertion(+), 1 deletion(-)
  1965. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  1966. index 9499ee10f56c..c558f9b48c83 100644
  1967. --- a/drivers/media/i2c/ov5693.c
  1968. +++ b/drivers/media/i2c/ov5693.c
  1969. @@ -133,7 +133,7 @@
  1970. #define OV5693_SUB_INC_Y_REG 0x3815
  1971. #define OV5693_FORMAT1_REG 0x3820
  1972. -#define OV5693_FORMAT1_FLIP_VERT_ISP_EN BIT(2)
  1973. +#define OV5693_FORMAT1_FLIP_VERT_ISP_EN BIT(6)
  1974. #define OV5693_FORMAT1_FLIP_VERT_SENSOR_EN BIT(1)
  1975. #define OV5693_FORMAT1_VBIN_EN BIT(0)
  1976. #define OV5693_FORMAT2_REG 0x3821
  1977. --
  1978. 2.34.0
  1979. From daec57877a80e0d8f6657619fffada365a5b6371 Mon Sep 17 00:00:00 2001
  1980. From: Daniel Scally <djrscally@gmail.com>
  1981. Date: Fri, 9 Jul 2021 16:39:18 +0100
  1982. Subject: [PATCH] media: i2c: Add ACPI support to ov8865
  1983. The ov8865 sensor is sometimes found on x86 platforms enumerated via ACPI.
  1984. Add an ACPI match table to the driver so that it's probed on those
  1985. platforms.
  1986. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  1987. Patchset: cameras
  1988. ---
  1989. drivers/media/i2c/ov8865.c | 8 ++++++++
  1990. 1 file changed, 8 insertions(+)
  1991. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  1992. index ce50f3ea87b8..7626c8608f8f 100644
  1993. --- a/drivers/media/i2c/ov8865.c
  1994. +++ b/drivers/media/i2c/ov8865.c
  1995. @@ -9,6 +9,7 @@
  1996. #include <linux/delay.h>
  1997. #include <linux/device.h>
  1998. #include <linux/i2c.h>
  1999. +#include <linux/mod_devicetable.h>
  2000. #include <linux/module.h>
  2001. #include <linux/of_graph.h>
  2002. #include <linux/pm_runtime.h>
  2003. @@ -2946,6 +2947,12 @@ static const struct dev_pm_ops ov8865_pm_ops = {
  2004. SET_RUNTIME_PM_OPS(ov8865_suspend, ov8865_resume, NULL)
  2005. };
  2006. +static const struct acpi_device_id ov8865_acpi_match[] = {
  2007. + {"INT347A"},
  2008. + { }
  2009. +};
  2010. +MODULE_DEVICE_TABLE(acpi, ov8865_acpi_match);
  2011. +
  2012. static const struct of_device_id ov8865_of_match[] = {
  2013. { .compatible = "ovti,ov8865" },
  2014. { }
  2015. @@ -2956,6 +2963,7 @@ static struct i2c_driver ov8865_driver = {
  2016. .driver = {
  2017. .name = "ov8865",
  2018. .of_match_table = ov8865_of_match,
  2019. + .acpi_match_table = ov8865_acpi_match,
  2020. .pm = &ov8865_pm_ops,
  2021. },
  2022. .probe_new = ov8865_probe,
  2023. --
  2024. 2.34.0
  2025. From 9213ddc74a32af22cb5de8af6e0a249fa9ed8351 Mon Sep 17 00:00:00 2001
  2026. From: Daniel Scally <djrscally@gmail.com>
  2027. Date: Sat, 10 Jul 2021 21:20:17 +0100
  2028. Subject: [PATCH] media: i2c: Fix incorrect value in comment
  2029. The PLL configuration defined here sets 72MHz (which is correct), not
  2030. 80MHz. Correct the comment.
  2031. Reviewed-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
  2032. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2033. Patchset: cameras
  2034. ---
  2035. drivers/media/i2c/ov8865.c | 2 +-
  2036. 1 file changed, 1 insertion(+), 1 deletion(-)
  2037. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  2038. index 7626c8608f8f..8e3f8a554452 100644
  2039. --- a/drivers/media/i2c/ov8865.c
  2040. +++ b/drivers/media/i2c/ov8865.c
  2041. @@ -713,7 +713,7 @@ static const struct ov8865_pll2_config ov8865_pll2_config_native = {
  2042. /*
  2043. * EXTCLK = 24 MHz
  2044. * DAC_CLK = 360 MHz
  2045. - * SCLK = 80 MHz
  2046. + * SCLK = 72 MHz
  2047. */
  2048. static const struct ov8865_pll2_config ov8865_pll2_config_binning = {
  2049. --
  2050. 2.34.0
  2051. From 5c3e54c1c791a2b7781bf37572d8e8c2f602dffa Mon Sep 17 00:00:00 2001
  2052. From: Daniel Scally <djrscally@gmail.com>
  2053. Date: Sat, 10 Jul 2021 22:21:52 +0100
  2054. Subject: [PATCH] media: i2c: Defer probe if not endpoint found
  2055. The ov8865 driver is one of those that can be connected to a CIO2
  2056. device by the cio2-bridge code. This means that the absence of an
  2057. endpoint for this device is not necessarily fatal, as one might be
  2058. built by the cio2-bridge when it probes. Return -EPROBE_DEFER if no
  2059. endpoint is found rather than a fatal error.
  2060. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2061. Patchset: cameras
  2062. ---
  2063. drivers/media/i2c/ov8865.c | 6 ++----
  2064. 1 file changed, 2 insertions(+), 4 deletions(-)
  2065. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  2066. index 8e3f8a554452..9bc8d5d8199b 100644
  2067. --- a/drivers/media/i2c/ov8865.c
  2068. +++ b/drivers/media/i2c/ov8865.c
  2069. @@ -2796,10 +2796,8 @@ static int ov8865_probe(struct i2c_client *client)
  2070. /* Graph Endpoint */
  2071. handle = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
  2072. - if (!handle) {
  2073. - dev_err(dev, "unable to find endpoint node\n");
  2074. - return -EINVAL;
  2075. - }
  2076. + if (!handle)
  2077. + return -EPROBE_DEFER;
  2078. sensor->endpoint.bus_type = V4L2_MBUS_CSI2_DPHY;
  2079. --
  2080. 2.34.0
  2081. From d7e4c156c95f8a52d1290b245cc9b7144c2e750d Mon Sep 17 00:00:00 2001
  2082. From: Daniel Scally <djrscally@gmail.com>
  2083. Date: Sat, 10 Jul 2021 22:00:25 +0100
  2084. Subject: [PATCH] media: i2c: Support 19.2MHz input clock in ov8865
  2085. The ov8865 driver as written expects a 24MHz input clock, but the sensor
  2086. is sometimes found on x86 platforms with a 19.2MHz input clock supplied.
  2087. Add a set of PLL configurations to the driver to support that rate too.
  2088. As ACPI doesn't auto-configure the clock rate, check for a clock-frequency
  2089. during probe and set that rate if one is found.
  2090. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2091. Patchset: cameras
  2092. ---
  2093. drivers/media/i2c/ov8865.c | 186 +++++++++++++++++++++++++++----------
  2094. 1 file changed, 135 insertions(+), 51 deletions(-)
  2095. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  2096. index 9bc8d5d8199b..4ddc1b277cc0 100644
  2097. --- a/drivers/media/i2c/ov8865.c
  2098. +++ b/drivers/media/i2c/ov8865.c
  2099. @@ -21,10 +21,6 @@
  2100. #include <media/v4l2-image-sizes.h>
  2101. #include <media/v4l2-mediabus.h>
  2102. -/* Clock rate */
  2103. -
  2104. -#define OV8865_EXTCLK_RATE 24000000
  2105. -
  2106. /* Register definitions */
  2107. /* System */
  2108. @@ -567,6 +563,25 @@ struct ov8865_sclk_config {
  2109. unsigned int sclk_div;
  2110. };
  2111. +struct ov8865_pll_configs {
  2112. + const struct ov8865_pll1_config *pll1_config;
  2113. + const struct ov8865_pll2_config *pll2_config_native;
  2114. + const struct ov8865_pll2_config *pll2_config_binning;
  2115. +};
  2116. +
  2117. +/* Clock rate */
  2118. +
  2119. +enum extclk_rate {
  2120. + OV8865_19_2_MHZ,
  2121. + OV8865_24_MHZ,
  2122. + OV8865_NUM_SUPPORTED_RATES
  2123. +};
  2124. +
  2125. +static const unsigned long supported_extclk_rates[] = {
  2126. + [OV8865_19_2_MHZ] = 19200000,
  2127. + [OV8865_24_MHZ] = 24000000,
  2128. +};
  2129. +
  2130. /*
  2131. * General formulas for (array-centered) mode calculation:
  2132. * - photo_array_width = 3296
  2133. @@ -635,9 +650,7 @@ struct ov8865_mode {
  2134. struct v4l2_fract frame_interval;
  2135. - const struct ov8865_pll1_config *pll1_config;
  2136. - const struct ov8865_pll2_config *pll2_config;
  2137. - const struct ov8865_sclk_config *sclk_config;
  2138. + bool pll2_binning;
  2139. const struct ov8865_register_value *register_values;
  2140. unsigned int register_values_count;
  2141. @@ -665,6 +678,9 @@ struct ov8865_sensor {
  2142. struct regulator *avdd;
  2143. struct regulator *dvdd;
  2144. struct regulator *dovdd;
  2145. +
  2146. + unsigned long extclk_rate;
  2147. + const struct ov8865_pll_configs *pll_configs;
  2148. struct clk *extclk;
  2149. struct v4l2_fwnode_endpoint endpoint;
  2150. @@ -680,43 +696,70 @@ struct ov8865_sensor {
  2151. /* Static definitions */
  2152. /*
  2153. - * EXTCLK = 24 MHz
  2154. * PHY_SCLK = 720 MHz
  2155. * MIPI_PCLK = 90 MHz
  2156. */
  2157. -static const struct ov8865_pll1_config ov8865_pll1_config_native = {
  2158. - .pll_pre_div_half = 1,
  2159. - .pll_pre_div = 0,
  2160. - .pll_mul = 30,
  2161. - .m_div = 1,
  2162. - .mipi_div = 3,
  2163. - .pclk_div = 1,
  2164. - .sys_pre_div = 1,
  2165. - .sys_div = 2,
  2166. +
  2167. +static const struct ov8865_pll1_config ov8865_pll1_config_native_19_2mhz = {
  2168. + .pll_pre_div_half = 1,
  2169. + .pll_pre_div = 2,
  2170. + .pll_mul = 75,
  2171. + .m_div = 1,
  2172. + .mipi_div = 3,
  2173. + .pclk_div = 1,
  2174. + .sys_pre_div = 1,
  2175. + .sys_div = 2,
  2176. +};
  2177. +
  2178. +static const struct ov8865_pll1_config ov8865_pll1_config_native_24mhz = {
  2179. + .pll_pre_div_half = 1,
  2180. + .pll_pre_div = 0,
  2181. + .pll_mul = 30,
  2182. + .m_div = 1,
  2183. + .mipi_div = 3,
  2184. + .pclk_div = 1,
  2185. + .sys_pre_div = 1,
  2186. + .sys_div = 2,
  2187. };
  2188. /*
  2189. - * EXTCLK = 24 MHz
  2190. * DAC_CLK = 360 MHz
  2191. * SCLK = 144 MHz
  2192. */
  2193. -static const struct ov8865_pll2_config ov8865_pll2_config_native = {
  2194. - .pll_pre_div_half = 1,
  2195. - .pll_pre_div = 0,
  2196. - .pll_mul = 30,
  2197. - .dac_div = 2,
  2198. - .sys_pre_div = 5,
  2199. - .sys_div = 0,
  2200. +static const struct ov8865_pll2_config ov8865_pll2_config_native_19_2mhz = {
  2201. + .pll_pre_div_half = 1,
  2202. + .pll_pre_div = 5,
  2203. + .pll_mul = 75,
  2204. + .dac_div = 1,
  2205. + .sys_pre_div = 1,
  2206. + .sys_div = 3,
  2207. +};
  2208. +
  2209. +static const struct ov8865_pll2_config ov8865_pll2_config_native_24mhz = {
  2210. + .pll_pre_div_half = 1,
  2211. + .pll_pre_div = 0,
  2212. + .pll_mul = 30,
  2213. + .dac_div = 2,
  2214. + .sys_pre_div = 5,
  2215. + .sys_div = 0,
  2216. };
  2217. /*
  2218. - * EXTCLK = 24 MHz
  2219. * DAC_CLK = 360 MHz
  2220. * SCLK = 72 MHz
  2221. */
  2222. -static const struct ov8865_pll2_config ov8865_pll2_config_binning = {
  2223. +static const struct ov8865_pll2_config ov8865_pll2_config_binning_19_2mhz = {
  2224. + .pll_pre_div_half = 1,
  2225. + .pll_pre_div = 2,
  2226. + .pll_mul = 75,
  2227. + .dac_div = 2,
  2228. + .sys_pre_div = 10,
  2229. + .sys_div = 0,
  2230. +};
  2231. +
  2232. +static const struct ov8865_pll2_config ov8865_pll2_config_binning_24mhz = {
  2233. .pll_pre_div_half = 1,
  2234. .pll_pre_div = 0,
  2235. .pll_mul = 30,
  2236. @@ -725,6 +768,23 @@ static const struct ov8865_pll2_config ov8865_pll2_config_binning = {
  2237. .sys_div = 0,
  2238. };
  2239. +static struct ov8865_pll_configs ov8865_pll_configs_19_2mhz = {
  2240. + .pll1_config = &ov8865_pll1_config_native_19_2mhz,
  2241. + .pll2_config_native = &ov8865_pll2_config_native_19_2mhz,
  2242. + .pll2_config_binning = &ov8865_pll2_config_binning_19_2mhz,
  2243. +};
  2244. +
  2245. +static struct ov8865_pll_configs ov8865_pll_configs_24mhz = {
  2246. + .pll1_config = &ov8865_pll1_config_native_24mhz,
  2247. + .pll2_config_native = &ov8865_pll2_config_native_24mhz,
  2248. + .pll2_config_binning = &ov8865_pll2_config_binning_24mhz,
  2249. +};
  2250. +
  2251. +static const struct ov8865_pll_configs *ov8865_pll_configs[] = {
  2252. + &ov8865_pll_configs_19_2mhz,
  2253. + &ov8865_pll_configs_24mhz,
  2254. +};
  2255. +
  2256. static const struct ov8865_sclk_config ov8865_sclk_config_native = {
  2257. .sys_sel = 1,
  2258. .sclk_sel = 0,
  2259. @@ -934,9 +994,7 @@ static const struct ov8865_mode ov8865_modes[] = {
  2260. .frame_interval = { 1, 30 },
  2261. /* PLL */
  2262. - .pll1_config = &ov8865_pll1_config_native,
  2263. - .pll2_config = &ov8865_pll2_config_native,
  2264. - .sclk_config = &ov8865_sclk_config_native,
  2265. + .pll2_binning = false,
  2266. /* Registers */
  2267. .register_values = ov8865_register_values_native,
  2268. @@ -990,9 +1048,7 @@ static const struct ov8865_mode ov8865_modes[] = {
  2269. .frame_interval = { 1, 30 },
  2270. /* PLL */
  2271. - .pll1_config = &ov8865_pll1_config_native,
  2272. - .pll2_config = &ov8865_pll2_config_native,
  2273. - .sclk_config = &ov8865_sclk_config_native,
  2274. + .pll2_binning = false,
  2275. /* Registers */
  2276. .register_values = ov8865_register_values_native,
  2277. @@ -1050,9 +1106,7 @@ static const struct ov8865_mode ov8865_modes[] = {
  2278. .frame_interval = { 1, 30 },
  2279. /* PLL */
  2280. - .pll1_config = &ov8865_pll1_config_native,
  2281. - .pll2_config = &ov8865_pll2_config_binning,
  2282. - .sclk_config = &ov8865_sclk_config_native,
  2283. + .pll2_binning = true,
  2284. /* Registers */
  2285. .register_values = ov8865_register_values_binning,
  2286. @@ -1116,9 +1170,7 @@ static const struct ov8865_mode ov8865_modes[] = {
  2287. .frame_interval = { 1, 90 },
  2288. /* PLL */
  2289. - .pll1_config = &ov8865_pll1_config_native,
  2290. - .pll2_config = &ov8865_pll2_config_binning,
  2291. - .sclk_config = &ov8865_sclk_config_native,
  2292. + .pll2_binning = true,
  2293. /* Registers */
  2294. .register_values = ov8865_register_values_binning,
  2295. @@ -1513,12 +1565,11 @@ static int ov8865_isp_configure(struct ov8865_sensor *sensor)
  2296. static unsigned long ov8865_mode_pll1_rate(struct ov8865_sensor *sensor,
  2297. const struct ov8865_mode *mode)
  2298. {
  2299. - const struct ov8865_pll1_config *config = mode->pll1_config;
  2300. - unsigned long extclk_rate;
  2301. + const struct ov8865_pll1_config *config;
  2302. unsigned long pll1_rate;
  2303. - extclk_rate = clk_get_rate(sensor->extclk);
  2304. - pll1_rate = extclk_rate * config->pll_mul / config->pll_pre_div_half;
  2305. + config = sensor->pll_configs->pll1_config;
  2306. + pll1_rate = sensor->extclk_rate * config->pll_mul / config->pll_pre_div_half;
  2307. switch (config->pll_pre_div) {
  2308. case 0:
  2309. @@ -1552,10 +1603,12 @@ static int ov8865_mode_pll1_configure(struct ov8865_sensor *sensor,
  2310. const struct ov8865_mode *mode,
  2311. u32 mbus_code)
  2312. {
  2313. - const struct ov8865_pll1_config *config = mode->pll1_config;
  2314. + const struct ov8865_pll1_config *config;
  2315. u8 value;
  2316. int ret;
  2317. + config = sensor->pll_configs->pll1_config;
  2318. +
  2319. switch (mbus_code) {
  2320. case MEDIA_BUS_FMT_SBGGR10_1X10:
  2321. value = OV8865_MIPI_BIT_SEL(10);
  2322. @@ -1622,9 +1675,12 @@ static int ov8865_mode_pll1_configure(struct ov8865_sensor *sensor,
  2323. static int ov8865_mode_pll2_configure(struct ov8865_sensor *sensor,
  2324. const struct ov8865_mode *mode)
  2325. {
  2326. - const struct ov8865_pll2_config *config = mode->pll2_config;
  2327. + const struct ov8865_pll2_config *config;
  2328. int ret;
  2329. + config = mode->pll2_binning ? sensor->pll_configs->pll2_config_binning :
  2330. + sensor->pll_configs->pll2_config_native;
  2331. +
  2332. ret = ov8865_write(sensor, OV8865_PLL_CTRL12_REG,
  2333. OV8865_PLL_CTRL12_PRE_DIV_HALF(config->pll_pre_div_half) |
  2334. OV8865_PLL_CTRL12_DAC_DIV(config->dac_div));
  2335. @@ -1658,7 +1714,7 @@ static int ov8865_mode_pll2_configure(struct ov8865_sensor *sensor,
  2336. static int ov8865_mode_sclk_configure(struct ov8865_sensor *sensor,
  2337. const struct ov8865_mode *mode)
  2338. {
  2339. - const struct ov8865_sclk_config *config = mode->sclk_config;
  2340. + const struct ov8865_sclk_config *config = &ov8865_sclk_config_native;
  2341. int ret;
  2342. ret = ov8865_write(sensor, OV8865_CLK_SEL0_REG,
  2343. @@ -2053,9 +2109,11 @@ static int ov8865_mode_configure(struct ov8865_sensor *sensor,
  2344. static unsigned long ov8865_mode_mipi_clk_rate(struct ov8865_sensor *sensor,
  2345. const struct ov8865_mode *mode)
  2346. {
  2347. - const struct ov8865_pll1_config *config = mode->pll1_config;
  2348. + const struct ov8865_pll1_config *config;
  2349. unsigned long pll1_rate;
  2350. + config = sensor->pll_configs->pll1_config;
  2351. +
  2352. pll1_rate = ov8865_mode_pll1_rate(sensor, mode);
  2353. return pll1_rate / config->m_div / 2;
  2354. @@ -2783,7 +2841,8 @@ static int ov8865_probe(struct i2c_client *client)
  2355. struct ov8865_sensor *sensor;
  2356. struct v4l2_subdev *subdev;
  2357. struct media_pad *pad;
  2358. - unsigned long rate;
  2359. + unsigned int rate;
  2360. + unsigned int i;
  2361. int ret;
  2362. sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
  2363. @@ -2858,13 +2917,38 @@ static int ov8865_probe(struct i2c_client *client)
  2364. goto error_endpoint;
  2365. }
  2366. - rate = clk_get_rate(sensor->extclk);
  2367. - if (rate != OV8865_EXTCLK_RATE) {
  2368. - dev_err(dev, "clock rate %lu Hz is unsupported\n", rate);
  2369. + /*
  2370. + * We could have either a 24MHz or 19.2MHz clock rate. Check for a
  2371. + * clock-frequency property and if found, set that rate. This should
  2372. + * cover the ACPI case. If the system uses devicetree then the
  2373. + * configured rate should already be set, so we'll have to check it.
  2374. + */
  2375. + ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
  2376. + &rate);
  2377. + if (!ret) {
  2378. + ret = clk_set_rate(sensor->extclk, rate);
  2379. + if (ret) {
  2380. + dev_err(dev, "failed to set clock rate\n");
  2381. + return ret;
  2382. + }
  2383. + }
  2384. +
  2385. + sensor->extclk_rate = clk_get_rate(sensor->extclk);
  2386. +
  2387. + for (i = 0; i < ARRAY_SIZE(supported_extclk_rates); i++) {
  2388. + if (sensor->extclk_rate == supported_extclk_rates[i])
  2389. + break;
  2390. + }
  2391. +
  2392. + if (i == ARRAY_SIZE(supported_extclk_rates)) {
  2393. + dev_err(dev, "clock rate %lu Hz is unsupported\n",
  2394. + sensor->extclk_rate);
  2395. ret = -EINVAL;
  2396. goto error_endpoint;
  2397. }
  2398. + sensor->pll_configs = ov8865_pll_configs[i];
  2399. +
  2400. /* Subdev, entity and pad */
  2401. subdev = &sensor->subdev;
  2402. --
  2403. 2.34.0
  2404. From 82e605cd4e01ec30e300e0c03a5c805ce311ef86 Mon Sep 17 00:00:00 2001
  2405. From: Daniel Scally <djrscally@gmail.com>
  2406. Date: Sat, 10 Jul 2021 22:19:10 +0100
  2407. Subject: [PATCH] media: i2c: Add .get_selection() support to ov8865
  2408. The ov8865 driver's v4l2_subdev_pad_ops currently does not include
  2409. .get_selection() - add support for that callback.
  2410. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2411. Patchset: cameras
  2412. ---
  2413. drivers/media/i2c/ov8865.c | 64 ++++++++++++++++++++++++++++++++++++++
  2414. 1 file changed, 64 insertions(+)
  2415. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  2416. index 4ddc1b277cc0..0f2776390a8e 100644
  2417. --- a/drivers/media/i2c/ov8865.c
  2418. +++ b/drivers/media/i2c/ov8865.c
  2419. @@ -450,6 +450,15 @@
  2420. #define OV8865_PRE_CTRL0_PATTERN_COLOR_SQUARES 2
  2421. #define OV8865_PRE_CTRL0_PATTERN_BLACK 3
  2422. +/* Pixel Array */
  2423. +
  2424. +#define OV8865_NATIVE_WIDTH 3296
  2425. +#define OV8865_NATIVE_HEIGHT 2528
  2426. +#define OV8865_ACTIVE_START_TOP 32
  2427. +#define OV8865_ACTIVE_START_LEFT 80
  2428. +#define OV8865_ACTIVE_WIDTH 3264
  2429. +#define OV8865_ACTIVE_HEIGHT 2448
  2430. +
  2431. /* Macros */
  2432. #define ov8865_subdev_sensor(s) \
  2433. @@ -2756,12 +2765,67 @@ static int ov8865_enum_frame_interval(struct v4l2_subdev *subdev,
  2434. return 0;
  2435. }
  2436. +static void
  2437. +__ov8865_get_pad_crop(struct ov8865_sensor *sensor,
  2438. + struct v4l2_subdev_state *state, unsigned int pad,
  2439. + enum v4l2_subdev_format_whence which, struct v4l2_rect *r)
  2440. +{
  2441. + const struct ov8865_mode *mode = sensor->state.mode;
  2442. +
  2443. + switch (which) {
  2444. + case V4L2_SUBDEV_FORMAT_TRY:
  2445. + *r = *v4l2_subdev_get_try_crop(&sensor->subdev, state, pad);
  2446. + break;
  2447. + case V4L2_SUBDEV_FORMAT_ACTIVE:
  2448. + r->height = mode->output_size_y;
  2449. + r->width = mode->output_size_x;
  2450. + r->top = (OV8865_NATIVE_HEIGHT - mode->output_size_y) / 2;
  2451. + r->left = (OV8865_NATIVE_WIDTH - mode->output_size_x) / 2;
  2452. + break;
  2453. + }
  2454. +}
  2455. +
  2456. +static int ov8865_get_selection(struct v4l2_subdev *subdev,
  2457. + struct v4l2_subdev_state *state,
  2458. + struct v4l2_subdev_selection *sel)
  2459. +{
  2460. + struct ov8865_sensor *sensor = ov8865_subdev_sensor(subdev);
  2461. +
  2462. + switch (sel->target) {
  2463. + case V4L2_SEL_TGT_CROP:
  2464. + mutex_lock(&sensor->mutex);
  2465. + __ov8865_get_pad_crop(sensor, state, sel->pad,
  2466. + sel->which, &sel->r);
  2467. + mutex_unlock(&sensor->mutex);
  2468. + break;
  2469. + case V4L2_SEL_TGT_NATIVE_SIZE:
  2470. + sel->r.top = 0;
  2471. + sel->r.left = 0;
  2472. + sel->r.width = OV8865_NATIVE_WIDTH;
  2473. + sel->r.height = OV8865_NATIVE_HEIGHT;
  2474. + break;
  2475. + case V4L2_SEL_TGT_CROP_BOUNDS:
  2476. + case V4L2_SEL_TGT_CROP_DEFAULT:
  2477. + sel->r.top = OV8865_ACTIVE_START_TOP;
  2478. + sel->r.left = OV8865_ACTIVE_START_LEFT;
  2479. + sel->r.width = OV8865_ACTIVE_WIDTH;
  2480. + sel->r.height = OV8865_ACTIVE_HEIGHT;
  2481. + break;
  2482. + default:
  2483. + return -EINVAL;
  2484. + }
  2485. +
  2486. + return 0;
  2487. +}
  2488. +
  2489. static const struct v4l2_subdev_pad_ops ov8865_subdev_pad_ops = {
  2490. .enum_mbus_code = ov8865_enum_mbus_code,
  2491. .get_fmt = ov8865_get_fmt,
  2492. .set_fmt = ov8865_set_fmt,
  2493. .enum_frame_size = ov8865_enum_frame_size,
  2494. .enum_frame_interval = ov8865_enum_frame_interval,
  2495. + .get_selection = ov8865_get_selection,
  2496. + .set_selection = ov8865_get_selection,
  2497. };
  2498. static const struct v4l2_subdev_ops ov8865_subdev_ops = {
  2499. --
  2500. 2.34.0
  2501. From 66365119072809fd0a13addb7149ec8637b564a1 Mon Sep 17 00:00:00 2001
  2502. From: Daniel Scally <djrscally@gmail.com>
  2503. Date: Sat, 10 Jul 2021 22:34:43 +0100
  2504. Subject: [PATCH] media: i2c: Switch control to V4L2_CID_ANALOGUE_GAIN
  2505. The V4L2_CID_GAIN control for this driver configures registers that
  2506. the datasheet specifies as analogue gain. Switch the control's ID
  2507. to V4L2_CID_ANALOGUE_GAIN.
  2508. Reviewed-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
  2509. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2510. Patchset: cameras
  2511. ---
  2512. drivers/media/i2c/ov8865.c | 9 +++++----
  2513. 1 file changed, 5 insertions(+), 4 deletions(-)
  2514. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  2515. index 0f2776390a8e..a832938c33b6 100644
  2516. --- a/drivers/media/i2c/ov8865.c
  2517. +++ b/drivers/media/i2c/ov8865.c
  2518. @@ -2150,7 +2150,7 @@ static int ov8865_exposure_configure(struct ov8865_sensor *sensor, u32 exposure)
  2519. /* Gain */
  2520. -static int ov8865_gain_configure(struct ov8865_sensor *sensor, u32 gain)
  2521. +static int ov8865_analog_gain_configure(struct ov8865_sensor *sensor, u32 gain)
  2522. {
  2523. int ret;
  2524. @@ -2460,8 +2460,8 @@ static int ov8865_s_ctrl(struct v4l2_ctrl *ctrl)
  2525. if (ret)
  2526. return ret;
  2527. break;
  2528. - case V4L2_CID_GAIN:
  2529. - ret = ov8865_gain_configure(sensor, ctrl->val);
  2530. + case V4L2_CID_ANALOGUE_GAIN:
  2531. + ret = ov8865_analog_gain_configure(sensor, ctrl->val);
  2532. if (ret)
  2533. return ret;
  2534. break;
  2535. @@ -2506,7 +2506,8 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
  2536. /* Gain */
  2537. - v4l2_ctrl_new_std(handler, ops, V4L2_CID_GAIN, 128, 8191, 128, 128);
  2538. + v4l2_ctrl_new_std(handler, ops, V4L2_CID_ANALOGUE_GAIN, 128, 8191, 128,
  2539. + 128);
  2540. /* White Balance */
  2541. --
  2542. 2.34.0
  2543. From c49266bfb501eeb85eba0420be36e42ffcbd7063 Mon Sep 17 00:00:00 2001
  2544. From: Daniel Scally <djrscally@gmail.com>
  2545. Date: Mon, 12 Jul 2021 22:54:56 +0100
  2546. Subject: [PATCH] media: i2c: Add vblank control to ov8865
  2547. Add a V4L2_CID_VBLANK control to the ov8865 driver.
  2548. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2549. Patchset: cameras
  2550. ---
  2551. drivers/media/i2c/ov8865.c | 34 ++++++++++++++++++++++++++++++++++
  2552. 1 file changed, 34 insertions(+)
  2553. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  2554. index a832938c33b6..f741c0713ca4 100644
  2555. --- a/drivers/media/i2c/ov8865.c
  2556. +++ b/drivers/media/i2c/ov8865.c
  2557. @@ -183,6 +183,8 @@
  2558. #define OV8865_VTS_H(v) (((v) & GENMASK(11, 8)) >> 8)
  2559. #define OV8865_VTS_L_REG 0x380f
  2560. #define OV8865_VTS_L(v) ((v) & GENMASK(7, 0))
  2561. +#define OV8865_TIMING_MAX_VTS 0xffff
  2562. +#define OV8865_TIMING_MIN_VTS 0x04
  2563. #define OV8865_OFFSET_X_H_REG 0x3810
  2564. #define OV8865_OFFSET_X_H(v) (((v) & GENMASK(15, 8)) >> 8)
  2565. #define OV8865_OFFSET_X_L_REG 0x3811
  2566. @@ -675,6 +677,7 @@ struct ov8865_state {
  2567. struct ov8865_ctrls {
  2568. struct v4l2_ctrl *link_freq;
  2569. struct v4l2_ctrl *pixel_rate;
  2570. + struct v4l2_ctrl *vblank;
  2571. struct v4l2_ctrl_handler handler;
  2572. };
  2573. @@ -2225,6 +2228,20 @@ static int ov8865_test_pattern_configure(struct ov8865_sensor *sensor,
  2574. ov8865_test_pattern_bits[index]);
  2575. }
  2576. +/* Blanking */
  2577. +
  2578. +static int ov8865_vts_configure(struct ov8865_sensor *sensor, u32 vblank)
  2579. +{
  2580. + u16 vts = sensor->state.mode->output_size_y + vblank;
  2581. + int ret;
  2582. +
  2583. + ret = ov8865_write(sensor, OV8865_VTS_H_REG, OV8865_VTS_H(vts));
  2584. + if (ret)
  2585. + return ret;
  2586. +
  2587. + return ov8865_write(sensor, OV8865_VTS_L_REG, OV8865_VTS_L(vts));
  2588. +}
  2589. +
  2590. /* State */
  2591. static int ov8865_state_mipi_configure(struct ov8865_sensor *sensor,
  2592. @@ -2476,6 +2493,8 @@ static int ov8865_s_ctrl(struct v4l2_ctrl *ctrl)
  2593. case V4L2_CID_TEST_PATTERN:
  2594. index = (unsigned int)ctrl->val;
  2595. return ov8865_test_pattern_configure(sensor, index);
  2596. + case V4L2_CID_VBLANK:
  2597. + return ov8865_vts_configure(sensor, ctrl->val);
  2598. default:
  2599. return -EINVAL;
  2600. }
  2601. @@ -2492,6 +2511,8 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
  2602. struct ov8865_ctrls *ctrls = &sensor->ctrls;
  2603. struct v4l2_ctrl_handler *handler = &ctrls->handler;
  2604. const struct v4l2_ctrl_ops *ops = &ov8865_ctrl_ops;
  2605. + const struct ov8865_mode *mode = sensor->state.mode;
  2606. + unsigned int vblank_max, vblank_def;
  2607. int ret;
  2608. v4l2_ctrl_handler_init(handler, 32);
  2609. @@ -2528,6 +2549,13 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
  2610. ARRAY_SIZE(ov8865_test_pattern_menu) - 1,
  2611. 0, 0, ov8865_test_pattern_menu);
  2612. + /* Blanking */
  2613. + vblank_max = OV8865_TIMING_MAX_VTS - mode->output_size_y;
  2614. + vblank_def = mode->vts - mode->output_size_y;
  2615. + ctrls->vblank = v4l2_ctrl_new_std(handler, ops, V4L2_CID_VBLANK,
  2616. + OV8865_TIMING_MIN_VTS, vblank_max, 1,
  2617. + vblank_def);
  2618. +
  2619. /* MIPI CSI-2 */
  2620. ctrls->link_freq =
  2621. @@ -2708,6 +2736,10 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev,
  2622. sensor->state.mbus_code != mbus_code)
  2623. ret = ov8865_state_configure(sensor, mode, mbus_code);
  2624. + __v4l2_ctrl_modify_range(sensor->ctrls.vblank, OV8865_TIMING_MIN_VTS,
  2625. + OV8865_TIMING_MAX_VTS - mode->output_size_y,
  2626. + 1, mode->vts - mode->output_size_y);
  2627. +
  2628. complete:
  2629. mutex_unlock(&sensor->mutex);
  2630. @@ -3035,6 +3067,8 @@ static int ov8865_probe(struct i2c_client *client)
  2631. /* Sensor */
  2632. + sensor->state.mode = &ov8865_modes[0];
  2633. +
  2634. ret = ov8865_ctrls_init(sensor);
  2635. if (ret)
  2636. goto error_mutex;
  2637. --
  2638. 2.34.0
  2639. From 808fd37ee10d2cca8e039c3ae88cb8a9191b3eed Mon Sep 17 00:00:00 2001
  2640. From: Daniel Scally <djrscally@gmail.com>
  2641. Date: Tue, 13 Jul 2021 23:40:33 +0100
  2642. Subject: [PATCH] media: i2c: Add hblank control to ov8865
  2643. Add a V4L2_CID_HBLANK control to the ov8865 driver. This is read only
  2644. with timing control intended to be done via vblanking alone.
  2645. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2646. Patchset: cameras
  2647. ---
  2648. drivers/media/i2c/ov8865.c | 14 ++++++++++++++
  2649. 1 file changed, 14 insertions(+)
  2650. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  2651. index f741c0713ca4..4b18cc80f985 100644
  2652. --- a/drivers/media/i2c/ov8865.c
  2653. +++ b/drivers/media/i2c/ov8865.c
  2654. @@ -677,6 +677,7 @@ struct ov8865_state {
  2655. struct ov8865_ctrls {
  2656. struct v4l2_ctrl *link_freq;
  2657. struct v4l2_ctrl *pixel_rate;
  2658. + struct v4l2_ctrl *hblank;
  2659. struct v4l2_ctrl *vblank;
  2660. struct v4l2_ctrl_handler handler;
  2661. @@ -2513,6 +2514,7 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
  2662. const struct v4l2_ctrl_ops *ops = &ov8865_ctrl_ops;
  2663. const struct ov8865_mode *mode = sensor->state.mode;
  2664. unsigned int vblank_max, vblank_def;
  2665. + unsigned int hblank;
  2666. int ret;
  2667. v4l2_ctrl_handler_init(handler, 32);
  2668. @@ -2550,6 +2552,13 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
  2669. 0, 0, ov8865_test_pattern_menu);
  2670. /* Blanking */
  2671. + hblank = mode->hts - mode->output_size_x;
  2672. + ctrls->hblank = v4l2_ctrl_new_std(handler, ops, V4L2_CID_HBLANK, hblank,
  2673. + hblank, 1, hblank);
  2674. +
  2675. + if (ctrls->hblank)
  2676. + ctrls->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  2677. +
  2678. vblank_max = OV8865_TIMING_MAX_VTS - mode->output_size_y;
  2679. vblank_def = mode->vts - mode->output_size_y;
  2680. ctrls->vblank = v4l2_ctrl_new_std(handler, ops, V4L2_CID_VBLANK,
  2681. @@ -2696,6 +2705,7 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev,
  2682. struct v4l2_mbus_framefmt *mbus_format = &format->format;
  2683. const struct ov8865_mode *mode;
  2684. u32 mbus_code = 0;
  2685. + unsigned int hblank;
  2686. unsigned int index;
  2687. int ret = 0;
  2688. @@ -2740,6 +2750,10 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev,
  2689. OV8865_TIMING_MAX_VTS - mode->output_size_y,
  2690. 1, mode->vts - mode->output_size_y);
  2691. + hblank = mode->hts - mode->output_size_x;
  2692. + __v4l2_ctrl_modify_range(sensor->ctrls.hblank, hblank, hblank, 1,
  2693. + hblank);
  2694. +
  2695. complete:
  2696. mutex_unlock(&sensor->mutex);
  2697. --
  2698. 2.34.0
  2699. From 94ef87e674e1e6a3585b34aebf00c612f189c7ec Mon Sep 17 00:00:00 2001
  2700. From: Daniel Scally <djrscally@gmail.com>
  2701. Date: Wed, 20 Oct 2021 22:43:54 +0100
  2702. Subject: [PATCH] media: i2c: Update HTS values in ov8865
  2703. The HTS values for some of the modes in the ov8865 driver are a bit
  2704. unusual, coming in lower than the output_size_x is set to. It seems
  2705. like they might be calculated to fit the desired framerate into a
  2706. configuration with just two data lanes. To bring this more in line
  2707. with expected behaviour, raise the HTS values above the output_size_x.
  2708. The corollary of that change is that the hardcoded frame intervals
  2709. against the modes no longer make sense, so remove those entirely.
  2710. Update the .g/s_frame_interval() callbacks to calculate the frame
  2711. interval based on the current mode and the vblank and hblank settings
  2712. plus the number of data lanes detected from firmware.
  2713. The implementation of the .enum_frame_interval() callback is no longer
  2714. suitable since the possible frame rate is now a continuous range depending
  2715. on the vblank control setting, so remove that callback entirely.
  2716. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2717. Patchset: cameras
  2718. ---
  2719. drivers/media/i2c/ov8865.c | 65 +++++++-------------------------------
  2720. 1 file changed, 11 insertions(+), 54 deletions(-)
  2721. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  2722. index 4b18cc80f985..1b8674152750 100644
  2723. --- a/drivers/media/i2c/ov8865.c
  2724. +++ b/drivers/media/i2c/ov8865.c
  2725. @@ -659,8 +659,6 @@ struct ov8865_mode {
  2726. unsigned int blc_anchor_right_start;
  2727. unsigned int blc_anchor_right_end;
  2728. - struct v4l2_fract frame_interval;
  2729. -
  2730. bool pll2_binning;
  2731. const struct ov8865_register_value *register_values;
  2732. @@ -964,7 +962,7 @@ static const struct ov8865_mode ov8865_modes[] = {
  2733. {
  2734. /* Horizontal */
  2735. .output_size_x = 3264,
  2736. - .hts = 1944,
  2737. + .hts = 3888,
  2738. /* Vertical */
  2739. .output_size_y = 2448,
  2740. @@ -1003,9 +1001,6 @@ static const struct ov8865_mode ov8865_modes[] = {
  2741. .blc_anchor_right_start = 1984,
  2742. .blc_anchor_right_end = 2239,
  2743. - /* Frame Interval */
  2744. - .frame_interval = { 1, 30 },
  2745. -
  2746. /* PLL */
  2747. .pll2_binning = false,
  2748. @@ -1018,11 +1013,11 @@ static const struct ov8865_mode ov8865_modes[] = {
  2749. {
  2750. /* Horizontal */
  2751. .output_size_x = 3264,
  2752. - .hts = 2582,
  2753. + .hts = 3888,
  2754. /* Vertical */
  2755. .output_size_y = 1836,
  2756. - .vts = 2002,
  2757. + .vts = 2470,
  2758. .size_auto = true,
  2759. .size_auto_boundary_x = 8,
  2760. @@ -1057,9 +1052,6 @@ static const struct ov8865_mode ov8865_modes[] = {
  2761. .blc_anchor_right_start = 1984,
  2762. .blc_anchor_right_end = 2239,
  2763. - /* Frame Interval */
  2764. - .frame_interval = { 1, 30 },
  2765. -
  2766. /* PLL */
  2767. .pll2_binning = false,
  2768. @@ -1115,9 +1107,6 @@ static const struct ov8865_mode ov8865_modes[] = {
  2769. .blc_anchor_right_start = 992,
  2770. .blc_anchor_right_end = 1119,
  2771. - /* Frame Interval */
  2772. - .frame_interval = { 1, 30 },
  2773. -
  2774. /* PLL */
  2775. .pll2_binning = true,
  2776. @@ -1179,9 +1168,6 @@ static const struct ov8865_mode ov8865_modes[] = {
  2777. .blc_anchor_right_start = 992,
  2778. .blc_anchor_right_end = 1119,
  2779. - /* Frame Interval */
  2780. - .frame_interval = { 1, 90 },
  2781. -
  2782. /* PLL */
  2783. .pll2_binning = true,
  2784. @@ -2628,11 +2614,18 @@ static int ov8865_g_frame_interval(struct v4l2_subdev *subdev,
  2785. {
  2786. struct ov8865_sensor *sensor = ov8865_subdev_sensor(subdev);
  2787. const struct ov8865_mode *mode;
  2788. + unsigned int framesize;
  2789. + unsigned int fps;
  2790. mutex_lock(&sensor->mutex);
  2791. mode = sensor->state.mode;
  2792. - interval->interval = mode->frame_interval;
  2793. + framesize = mode->hts * (mode->output_size_y +
  2794. + sensor->ctrls.vblank->val);
  2795. + fps = DIV_ROUND_CLOSEST(sensor->ctrls.pixel_rate->val, framesize);
  2796. +
  2797. + interval->interval.numerator = 1;
  2798. + interval->interval.denominator = fps;
  2799. mutex_unlock(&sensor->mutex);
  2800. @@ -2777,41 +2770,6 @@ static int ov8865_enum_frame_size(struct v4l2_subdev *subdev,
  2801. return 0;
  2802. }
  2803. -static int ov8865_enum_frame_interval(struct v4l2_subdev *subdev,
  2804. - struct v4l2_subdev_state *sd_state,
  2805. - struct v4l2_subdev_frame_interval_enum *interval_enum)
  2806. -{
  2807. - const struct ov8865_mode *mode = NULL;
  2808. - unsigned int mode_index;
  2809. - unsigned int interval_index;
  2810. -
  2811. - if (interval_enum->index > 0)
  2812. - return -EINVAL;
  2813. - /*
  2814. - * Multiple modes with the same dimensions may have different frame
  2815. - * intervals, so look up each relevant mode.
  2816. - */
  2817. - for (mode_index = 0, interval_index = 0;
  2818. - mode_index < ARRAY_SIZE(ov8865_modes); mode_index++) {
  2819. - mode = &ov8865_modes[mode_index];
  2820. -
  2821. - if (mode->output_size_x == interval_enum->width &&
  2822. - mode->output_size_y == interval_enum->height) {
  2823. - if (interval_index == interval_enum->index)
  2824. - break;
  2825. -
  2826. - interval_index++;
  2827. - }
  2828. - }
  2829. -
  2830. - if (mode_index == ARRAY_SIZE(ov8865_modes))
  2831. - return -EINVAL;
  2832. -
  2833. - interval_enum->interval = mode->frame_interval;
  2834. -
  2835. - return 0;
  2836. -}
  2837. -
  2838. static void
  2839. __ov8865_get_pad_crop(struct ov8865_sensor *sensor,
  2840. struct v4l2_subdev_state *state, unsigned int pad,
  2841. @@ -2870,7 +2828,6 @@ static const struct v4l2_subdev_pad_ops ov8865_subdev_pad_ops = {
  2842. .get_fmt = ov8865_get_fmt,
  2843. .set_fmt = ov8865_set_fmt,
  2844. .enum_frame_size = ov8865_enum_frame_size,
  2845. - .enum_frame_interval = ov8865_enum_frame_interval,
  2846. .get_selection = ov8865_get_selection,
  2847. .set_selection = ov8865_get_selection,
  2848. };
  2849. --
  2850. 2.34.0
  2851. From 34188431bc1debbcba03078f71629f03a044343a Mon Sep 17 00:00:00 2001
  2852. From: Daniel Scally <djrscally@gmail.com>
  2853. Date: Tue, 13 Jul 2021 23:43:17 +0100
  2854. Subject: [PATCH] media: i2c: cap exposure at height + vblank in ov8865
  2855. Exposure limits depend on the total height; when vblank is altered (and
  2856. thus the total height is altered), change the exposure limits to reflect
  2857. the new cap.
  2858. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2859. Patchset: cameras
  2860. ---
  2861. drivers/media/i2c/ov8865.c | 26 ++++++++++++++++++++++++--
  2862. 1 file changed, 24 insertions(+), 2 deletions(-)
  2863. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  2864. index 1b8674152750..99548ad15dcd 100644
  2865. --- a/drivers/media/i2c/ov8865.c
  2866. +++ b/drivers/media/i2c/ov8865.c
  2867. @@ -677,6 +677,7 @@ struct ov8865_ctrls {
  2868. struct v4l2_ctrl *pixel_rate;
  2869. struct v4l2_ctrl *hblank;
  2870. struct v4l2_ctrl *vblank;
  2871. + struct v4l2_ctrl *exposure;
  2872. struct v4l2_ctrl_handler handler;
  2873. };
  2874. @@ -2454,6 +2455,19 @@ static int ov8865_s_ctrl(struct v4l2_ctrl *ctrl)
  2875. unsigned int index;
  2876. int ret;
  2877. + /* If VBLANK is altered we need to update exposure to compensate */
  2878. + if (ctrl->id == V4L2_CID_VBLANK) {
  2879. + int exposure_max;
  2880. +
  2881. + exposure_max = sensor->state.mode->output_size_y + ctrl->val;
  2882. + __v4l2_ctrl_modify_range(sensor->ctrls.exposure,
  2883. + sensor->ctrls.exposure->minimum,
  2884. + exposure_max,
  2885. + sensor->ctrls.exposure->step,
  2886. + min(sensor->ctrls.exposure->val,
  2887. + exposure_max));
  2888. + }
  2889. +
  2890. /* Wait for the sensor to be on before setting controls. */
  2891. if (pm_runtime_suspended(sensor->dev))
  2892. return 0;
  2893. @@ -2510,8 +2524,8 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
  2894. /* Exposure */
  2895. - v4l2_ctrl_new_std(handler, ops, V4L2_CID_EXPOSURE, 16, 1048575, 16,
  2896. - 512);
  2897. + ctrls->exposure = v4l2_ctrl_new_std(handler, ops, V4L2_CID_EXPOSURE, 16,
  2898. + 1048575, 16, 512);
  2899. /* Gain */
  2900. @@ -2700,6 +2714,7 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev,
  2901. u32 mbus_code = 0;
  2902. unsigned int hblank;
  2903. unsigned int index;
  2904. + int exposure_max;
  2905. int ret = 0;
  2906. mutex_lock(&sensor->mutex);
  2907. @@ -2747,6 +2762,13 @@ static int ov8865_set_fmt(struct v4l2_subdev *subdev,
  2908. __v4l2_ctrl_modify_range(sensor->ctrls.hblank, hblank, hblank, 1,
  2909. hblank);
  2910. + exposure_max = mode->vts;
  2911. + __v4l2_ctrl_modify_range(sensor->ctrls.exposure,
  2912. + sensor->ctrls.exposure->minimum, exposure_max,
  2913. + sensor->ctrls.exposure->step,
  2914. + min(sensor->ctrls.exposure->val,
  2915. + exposure_max));
  2916. +
  2917. complete:
  2918. mutex_unlock(&sensor->mutex);
  2919. --
  2920. 2.34.0
  2921. From 50e23908b0e79c2f2b936b136b6050fae46fed5c Mon Sep 17 00:00:00 2001
  2922. From: Daniel Scally <djrscally@gmail.com>
  2923. Date: Fri, 16 Jul 2021 22:56:15 +0100
  2924. Subject: [PATCH] media: i2c: Add controls from fwnode to ov8865
  2925. Add V4L2_CID_CAMERA_ORIENTATION and V4L2_CID_CAMERA_SENSOR_ROTATION
  2926. controls to the ov8865 driver by attempting to parse them from firmware.
  2927. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2928. Patchset: cameras
  2929. ---
  2930. drivers/media/i2c/ov8865.c | 10 ++++++++++
  2931. 1 file changed, 10 insertions(+)
  2932. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  2933. index 99548ad15dcd..dfb5095ef16b 100644
  2934. --- a/drivers/media/i2c/ov8865.c
  2935. +++ b/drivers/media/i2c/ov8865.c
  2936. @@ -2513,6 +2513,7 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
  2937. struct v4l2_ctrl_handler *handler = &ctrls->handler;
  2938. const struct v4l2_ctrl_ops *ops = &ov8865_ctrl_ops;
  2939. const struct ov8865_mode *mode = sensor->state.mode;
  2940. + struct v4l2_fwnode_device_properties props;
  2941. unsigned int vblank_max, vblank_def;
  2942. unsigned int hblank;
  2943. int ret;
  2944. @@ -2576,6 +2577,15 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
  2945. v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE, 1,
  2946. INT_MAX, 1, 1);
  2947. + /* set properties from fwnode (e.g. rotation, orientation) */
  2948. + ret = v4l2_fwnode_device_parse(sensor->dev, &props);
  2949. + if (ret)
  2950. + goto error_ctrls;
  2951. +
  2952. + ret = v4l2_ctrl_new_fwnode_properties(handler, ops, &props);
  2953. + if (ret)
  2954. + goto error_ctrls;
  2955. +
  2956. if (handler->error) {
  2957. ret = handler->error;
  2958. goto error_ctrls;
  2959. --
  2960. 2.34.0
  2961. From 6464bee63f9a1de50640765b8942e142d8e73d3c Mon Sep 17 00:00:00 2001
  2962. From: Daniel Scally <djrscally@gmail.com>
  2963. Date: Fri, 16 Jul 2021 00:00:54 +0100
  2964. Subject: [PATCH] media: i2c: Switch exposure control unit to lines
  2965. The ov8865 driver currently has the unit of the V4L2_CID_EXPOSURE control
  2966. as 1/16th of a line. This is what the sensor expects, but isn't very
  2967. intuitive. Switch the control to be in units of a line and simply do the
  2968. 16x multiplication before passing the value to the sensor.
  2969. The datasheet for this sensor gives minimum exposure as 2 lines, so take
  2970. the opportunity to correct the lower bounds of the control.
  2971. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  2972. Patchset: cameras
  2973. ---
  2974. drivers/media/i2c/ov8865.c | 7 +++++--
  2975. 1 file changed, 5 insertions(+), 2 deletions(-)
  2976. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  2977. index dfb5095ef16b..5f19d82554df 100644
  2978. --- a/drivers/media/i2c/ov8865.c
  2979. +++ b/drivers/media/i2c/ov8865.c
  2980. @@ -2125,6 +2125,9 @@ static int ov8865_exposure_configure(struct ov8865_sensor *sensor, u32 exposure)
  2981. {
  2982. int ret;
  2983. + /* The sensor stores exposure in units of 1/16th of a line */
  2984. + exposure *= 16;
  2985. +
  2986. ret = ov8865_write(sensor, OV8865_EXPOSURE_CTRL_HH_REG,
  2987. OV8865_EXPOSURE_CTRL_HH(exposure));
  2988. if (ret)
  2989. @@ -2525,8 +2528,8 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
  2990. /* Exposure */
  2991. - ctrls->exposure = v4l2_ctrl_new_std(handler, ops, V4L2_CID_EXPOSURE, 16,
  2992. - 1048575, 16, 512);
  2993. + ctrls->exposure = v4l2_ctrl_new_std(handler, ops, V4L2_CID_EXPOSURE, 2,
  2994. + 65535, 1, 32);
  2995. /* Gain */
  2996. --
  2997. 2.34.0
  2998. From db9b9acd48871e17f9b2ebb11c77a3512496e154 Mon Sep 17 00:00:00 2001
  2999. From: Daniel Scally <djrscally@gmail.com>
  3000. Date: Tue, 24 Aug 2021 22:39:02 +0100
  3001. Subject: [PATCH] media: i2c: Re-order runtime pm initialisation
  3002. The kerneldoc for pm_runtime_set_suspended() says:
  3003. "It is not valid to call this function for devices with runtime PM
  3004. enabled"
  3005. To satisfy that requirement, re-order the calls so that
  3006. pm_runtime_enable() is the last one.
  3007. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  3008. Patchset: cameras
  3009. ---
  3010. drivers/media/i2c/ov8865.c | 2 +-
  3011. 1 file changed, 1 insertion(+), 1 deletion(-)
  3012. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  3013. index 5f19d82554df..18b5f1e8e9a7 100644
  3014. --- a/drivers/media/i2c/ov8865.c
  3015. +++ b/drivers/media/i2c/ov8865.c
  3016. @@ -3085,8 +3085,8 @@ static int ov8865_probe(struct i2c_client *client)
  3017. /* Runtime PM */
  3018. - pm_runtime_enable(sensor->dev);
  3019. pm_runtime_set_suspended(sensor->dev);
  3020. + pm_runtime_enable(sensor->dev);
  3021. /* V4L2 subdev register */
  3022. --
  3023. 2.34.0
  3024. From 4be77309a0952399f9ff05ce08129ddc35936c77 Mon Sep 17 00:00:00 2001
  3025. From: Daniel Scally <djrscally@gmail.com>
  3026. Date: Tue, 24 Aug 2021 23:17:39 +0100
  3027. Subject: [PATCH] media: i2c: Use dev_err_probe() in ov8865
  3028. There is a chance that regulator_get() returns -EPROBE_DEFER, in which
  3029. case printing an error message is undesirable. To avoid spurious messages
  3030. in dmesg in the event that -EPROBE_DEFER is returned, use dev_err_probe()
  3031. on error paths for regulator_get().
  3032. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  3033. Patchset: cameras
  3034. ---
  3035. drivers/media/i2c/ov8865.c | 46 +++++++++++++++++---------------------
  3036. 1 file changed, 20 insertions(+), 26 deletions(-)
  3037. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  3038. index 18b5f1e8e9a7..19e6bebf340d 100644
  3039. --- a/drivers/media/i2c/ov8865.c
  3040. +++ b/drivers/media/i2c/ov8865.c
  3041. @@ -2955,6 +2955,26 @@ static int ov8865_probe(struct i2c_client *client)
  3042. sensor->dev = dev;
  3043. sensor->i2c_client = client;
  3044. + /* Regulators */
  3045. +
  3046. + /* DVDD: digital core */
  3047. + sensor->dvdd = devm_regulator_get(dev, "dvdd");
  3048. + if (IS_ERR(sensor->dvdd))
  3049. + return dev_err_probe(dev, PTR_ERR(sensor->dvdd),
  3050. + "cannot get DVDD regulator\n");
  3051. +
  3052. + /* DOVDD: digital I/O */
  3053. + sensor->dovdd = devm_regulator_get(dev, "dovdd");
  3054. + if (IS_ERR(sensor->dovdd))
  3055. + return dev_err_probe(dev, PTR_ERR(sensor->dovdd),
  3056. + "cannot get DOVDD regulator\n");
  3057. +
  3058. + /* AVDD: analog */
  3059. + sensor->avdd = devm_regulator_get(dev, "avdd");
  3060. + if (IS_ERR(sensor->avdd))
  3061. + return dev_err_probe(dev, PTR_ERR(sensor->avdd),
  3062. + "cannot get AVDD regulator\n");
  3063. +
  3064. /* Graph Endpoint */
  3065. handle = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
  3066. @@ -2985,32 +3005,6 @@ static int ov8865_probe(struct i2c_client *client)
  3067. goto error_endpoint;
  3068. }
  3069. - /* Regulators */
  3070. -
  3071. - /* DVDD: digital core */
  3072. - sensor->dvdd = devm_regulator_get(dev, "dvdd");
  3073. - if (IS_ERR(sensor->dvdd)) {
  3074. - dev_err(dev, "cannot get DVDD (digital core) regulator\n");
  3075. - ret = PTR_ERR(sensor->dvdd);
  3076. - goto error_endpoint;
  3077. - }
  3078. -
  3079. - /* DOVDD: digital I/O */
  3080. - sensor->dovdd = devm_regulator_get(dev, "dovdd");
  3081. - if (IS_ERR(sensor->dovdd)) {
  3082. - dev_err(dev, "cannot get DOVDD (digital I/O) regulator\n");
  3083. - ret = PTR_ERR(sensor->dovdd);
  3084. - goto error_endpoint;
  3085. - }
  3086. -
  3087. - /* AVDD: analog */
  3088. - sensor->avdd = devm_regulator_get(dev, "avdd");
  3089. - if (IS_ERR(sensor->avdd)) {
  3090. - dev_err(dev, "cannot get AVDD (analog) regulator\n");
  3091. - ret = PTR_ERR(sensor->avdd);
  3092. - goto error_endpoint;
  3093. - }
  3094. -
  3095. /* External Clock */
  3096. sensor->extclk = devm_clk_get(dev, NULL);
  3097. --
  3098. 2.34.0
  3099. From 8058a58388e75455a71addd0f9c2bc8fba1ab0ad Mon Sep 17 00:00:00 2001
  3100. From: Daniel Scally <djrscally@gmail.com>
  3101. Date: Wed, 14 Jul 2021 00:05:04 +0100
  3102. Subject: [PATCH] media: ipu3-cio2: Add INT347A to cio2-bridge
  3103. ACPI _HID INT347A represents the OV8865 sensor, the driver for which can
  3104. support the platforms that the cio2-bridge serves. Add it to the array
  3105. of supported sensors so the bridge will connect the sensor to the CIO2
  3106. device.
  3107. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
  3108. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  3109. Patchset: cameras
  3110. ---
  3111. drivers/media/pci/intel/ipu3/cio2-bridge.c | 2 ++
  3112. 1 file changed, 2 insertions(+)
  3113. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  3114. index 7e582135dfb8..0132f0bd9b41 100644
  3115. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
  3116. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  3117. @@ -22,6 +22,8 @@
  3118. static const struct cio2_sensor_config cio2_supported_sensors[] = {
  3119. /* Omnivision OV5693 */
  3120. CIO2_SENSOR_CONFIG("INT33BE", 0),
  3121. + /* Omnivision OV8865 */
  3122. + CIO2_SENSOR_CONFIG("INT347A", 1, 360000000),
  3123. /* Omnivision OV2680 */
  3124. CIO2_SENSOR_CONFIG("OVTI2680", 0),
  3125. };
  3126. --
  3127. 2.34.0
  3128. From 20864ac9a8f63bfb299e092dba9fe8534aa46a10 Mon Sep 17 00:00:00 2001
  3129. From: Hans de Goede <hdegoede@redhat.com>
  3130. Date: Thu, 7 Oct 2021 15:34:52 +0200
  3131. Subject: [PATCH] media: i2c: ov8865: Fix lockdep error
  3132. ov8865_state_init() calls ov8865_state_mipi_configure() which uses
  3133. __v4l2_ctrl_s_ctrl[_int64](). This means that sensor->mutex (which
  3134. is also sensor->ctrls.handler.lock) must be locked before calling
  3135. ov8865_state_init().
  3136. Note ov8865_state_mipi_configure() is also used in other places where
  3137. the lock is already held so it cannot be changed itself.
  3138. This fixes the following lockdep kernel WARN:
  3139. [ 13.233413] ------------[ cut here ]------------
  3140. [ 13.233421] WARNING: CPU: 0 PID: 8 at drivers/media/v4l2-core/v4l2-ctrls-api.c:833 __v4l2_ctrl_s_ctrl+0x4d/0x60 [videodev]
  3141. ...
  3142. [ 13.234063] Call Trace:
  3143. [ 13.234074] ov8865_state_configure+0x98b/0xc00 [ov8865]
  3144. [ 13.234095] ov8865_probe+0x4b1/0x54c [ov8865]
  3145. [ 13.234117] i2c_device_probe+0x13c/0x2d0
  3146. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  3147. Patchset: cameras
  3148. ---
  3149. drivers/media/i2c/ov8865.c | 2 ++
  3150. 1 file changed, 2 insertions(+)
  3151. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  3152. index 19e6bebf340d..d5af8aedf5e8 100644
  3153. --- a/drivers/media/i2c/ov8865.c
  3154. +++ b/drivers/media/i2c/ov8865.c
  3155. @@ -3073,7 +3073,9 @@ static int ov8865_probe(struct i2c_client *client)
  3156. if (ret)
  3157. goto error_mutex;
  3158. + mutex_lock(&sensor->mutex);
  3159. ret = ov8865_state_init(sensor);
  3160. + mutex_unlock(&sensor->mutex);
  3161. if (ret)
  3162. goto error_ctrls;
  3163. --
  3164. 2.34.0
  3165. From 719656084e09243f5ad1a6f795d5f74dd72f4867 Mon Sep 17 00:00:00 2001
  3166. From: Hans de Goede <hdegoede@redhat.com>
  3167. Date: Sun, 10 Oct 2021 20:56:57 +0200
  3168. Subject: [PATCH] ACPI: delay enumeration of devices with a _DEP pointing to an
  3169. INT3472 device
  3170. The clk and regulator frameworks expect clk/regulator consumer-devices
  3171. to have info about the consumed clks/regulators described in the device's
  3172. fw_node.
  3173. To work around cases where this info is not present in the firmware tables,
  3174. which is often the case on x86/ACPI devices, both frameworks allow the
  3175. provider-driver to attach info about consumers to the clks/regulators
  3176. when registering these.
  3177. This causes problems with the probe ordering wrt drivers for consumers
  3178. of these clks/regulators. Since the lookups are only registered when the
  3179. provider-driver binds, trying to get these clks/regulators before then
  3180. results in a -ENOENT error for clks and a dummy regulator for regulators.
  3181. One case where we hit this issue is camera sensors such as e.g. the OV8865
  3182. sensor found on the Microsoft Surface Go. The sensor uses clks, regulators
  3183. and GPIOs provided by a TPS68470 PMIC which is described in an INT3472
  3184. ACPI device. There is special platform code handling this and setting
  3185. platform_data with the necessary consumer info on the MFD cells
  3186. instantiated for the PMIC under: drivers/platform/x86/intel/int3472.
  3187. For this to work properly the ov8865 driver must not bind to the I2C-client
  3188. for the OV8865 sensor until after the TPS68470 PMIC gpio, regulator and
  3189. clk MFD cells have all been fully setup.
  3190. The OV8865 on the Microsoft Surface Go is just one example, all X86
  3191. devices using the Intel IPU3 camera block found on recent Intel SoCs
  3192. have similar issues where there is an INT3472 HID ACPI-device, which
  3193. describes the clks and regulators, and the driver for this INT3472 device
  3194. must be fully initialized before the sensor driver (any sensor driver)
  3195. binds for things to work properly.
  3196. On these devices the ACPI nodes describing the sensors all have a _DEP
  3197. dependency on the matching INT3472 ACPI device (there is one per sensor).
  3198. This allows solving the probe-ordering problem by delaying the enumeration
  3199. (instantiation of the I2C-client in the ov8865 example) of ACPI-devices
  3200. which have a _DEP dependency on an INT3472 device.
  3201. The new acpi_dev_ready_for_enumeration() helper used for this is also
  3202. exported because for devices, which have the enumeration_by_parent flag
  3203. set, the parent-driver will do its own scan of child ACPI devices and
  3204. it will try to enumerate those during its probe(). Code doing this such
  3205. as e.g. the i2c-core-acpi.c code must call this new helper to ensure
  3206. that it too delays the enumeration until all the _DEP dependencies are
  3207. met on devices which have the new honor_deps flag set.
  3208. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  3209. Patchset: cameras
  3210. ---
  3211. drivers/acpi/scan.c | 36 ++++++++++++++++++++++++++++++++++--
  3212. include/acpi/acpi_bus.h | 5 ++++-
  3213. 2 files changed, 38 insertions(+), 3 deletions(-)
  3214. diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
  3215. index ae9464091f1b..4a5cc1d695b4 100644
  3216. --- a/drivers/acpi/scan.c
  3217. +++ b/drivers/acpi/scan.c
  3218. @@ -797,6 +797,12 @@ static const char * const acpi_ignore_dep_ids[] = {
  3219. NULL
  3220. };
  3221. +/* List of HIDs for which we honor deps of matching ACPI devs, when checking _DEP lists. */
  3222. +static const char * const acpi_honor_dep_ids[] = {
  3223. + "INT3472", /* Camera sensor PMIC / clk and regulator info */
  3224. + NULL
  3225. +};
  3226. +
  3227. static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)
  3228. {
  3229. struct acpi_device *device = NULL;
  3230. @@ -1758,8 +1764,12 @@ static void acpi_scan_dep_init(struct acpi_device *adev)
  3231. struct acpi_dep_data *dep;
  3232. list_for_each_entry(dep, &acpi_dep_list, node) {
  3233. - if (dep->consumer == adev->handle)
  3234. + if (dep->consumer == adev->handle) {
  3235. + if (dep->honor_dep)
  3236. + adev->flags.honor_deps = 1;
  3237. +
  3238. adev->dep_unmet++;
  3239. + }
  3240. }
  3241. }
  3242. @@ -1963,7 +1973,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)
  3243. for (count = 0, i = 0; i < dep_devices.count; i++) {
  3244. struct acpi_device_info *info;
  3245. struct acpi_dep_data *dep;
  3246. - bool skip;
  3247. + bool skip, honor_dep;
  3248. status = acpi_get_object_info(dep_devices.handles[i], &info);
  3249. if (ACPI_FAILURE(status)) {
  3250. @@ -1972,6 +1982,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)
  3251. }
  3252. skip = acpi_info_matches_ids(info, acpi_ignore_dep_ids);
  3253. + honor_dep = acpi_info_matches_ids(info, acpi_honor_dep_ids);
  3254. kfree(info);
  3255. if (skip)
  3256. @@ -1985,6 +1996,7 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)
  3257. dep->supplier = dep_devices.handles[i];
  3258. dep->consumer = handle;
  3259. + dep->honor_dep = honor_dep;
  3260. mutex_lock(&acpi_dep_list_lock);
  3261. list_add_tail(&dep->node , &acpi_dep_list);
  3262. @@ -2072,6 +2084,9 @@ static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used,
  3263. static void acpi_default_enumeration(struct acpi_device *device)
  3264. {
  3265. + if (!acpi_dev_ready_for_enumeration(device))
  3266. + return;
  3267. +
  3268. /*
  3269. * Do not enumerate devices with enumeration_by_parent flag set as
  3270. * they will be enumerated by their respective parents.
  3271. @@ -2314,6 +2329,23 @@ void acpi_dev_clear_dependencies(struct acpi_device *supplier)
  3272. }
  3273. EXPORT_SYMBOL_GPL(acpi_dev_clear_dependencies);
  3274. +/**
  3275. + * acpi_dev_ready_for_enumeration - Check if the ACPI device is ready for enumeration
  3276. + * @device: Pointer to the &struct acpi_device to check
  3277. + *
  3278. + * Check if the device is present and has no unmet dependencies.
  3279. + *
  3280. + * Return true if the device is ready for enumeratino. Otherwise, return false.
  3281. + */
  3282. +bool acpi_dev_ready_for_enumeration(const struct acpi_device *device)
  3283. +{
  3284. + if (device->flags.honor_deps && device->dep_unmet)
  3285. + return false;
  3286. +
  3287. + return acpi_device_is_present(device);
  3288. +}
  3289. +EXPORT_SYMBOL_GPL(acpi_dev_ready_for_enumeration);
  3290. +
  3291. /**
  3292. * acpi_dev_get_first_consumer_dev - Return ACPI device dependent on @supplier
  3293. * @supplier: Pointer to the dependee device
  3294. diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
  3295. index 13d93371790e..2da53b7b4965 100644
  3296. --- a/include/acpi/acpi_bus.h
  3297. +++ b/include/acpi/acpi_bus.h
  3298. @@ -202,7 +202,8 @@ struct acpi_device_flags {
  3299. u32 coherent_dma:1;
  3300. u32 cca_seen:1;
  3301. u32 enumeration_by_parent:1;
  3302. - u32 reserved:19;
  3303. + u32 honor_deps:1;
  3304. + u32 reserved:18;
  3305. };
  3306. /* File System */
  3307. @@ -284,6 +285,7 @@ struct acpi_dep_data {
  3308. struct list_head node;
  3309. acpi_handle supplier;
  3310. acpi_handle consumer;
  3311. + bool honor_dep;
  3312. };
  3313. /* Performance Management */
  3314. @@ -693,6 +695,7 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
  3315. bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
  3316. void acpi_dev_clear_dependencies(struct acpi_device *supplier);
  3317. +bool acpi_dev_ready_for_enumeration(const struct acpi_device *device);
  3318. struct acpi_device *acpi_dev_get_first_consumer_dev(struct acpi_device *supplier);
  3319. struct acpi_device *
  3320. acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
  3321. --
  3322. 2.34.0
  3323. From 7d90f6ec28235414b69af24ff2cab4d172c8ad1a Mon Sep 17 00:00:00 2001
  3324. From: Hans de Goede <hdegoede@redhat.com>
  3325. Date: Sun, 10 Oct 2021 20:56:58 +0200
  3326. Subject: [PATCH] i2c: acpi: Use acpi_dev_ready_for_enumeration() helper
  3327. The clk and regulator frameworks expect clk/regulator consumer-devices
  3328. to have info about the consumed clks/regulators described in the device's
  3329. fw_node.
  3330. To work around cases where this info is not present in the firmware tables,
  3331. which is often the case on x86/ACPI devices, both frameworks allow the
  3332. provider-driver to attach info about consumers to the clks/regulators
  3333. when registering these.
  3334. This causes problems with the probe ordering wrt drivers for consumers
  3335. of these clks/regulators. Since the lookups are only registered when the
  3336. provider-driver binds, trying to get these clks/regulators before then
  3337. results in a -ENOENT error for clks and a dummy regulator for regulators.
  3338. To ensure the correct probe-ordering the ACPI core has code to defer the
  3339. enumeration of consumers affected by this until the providers are ready.
  3340. Call the new acpi_dev_ready_for_enumeration() helper to avoid
  3341. enumerating / instantiating i2c-clients too early.
  3342. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  3343. Patchset: cameras
  3344. ---
  3345. drivers/i2c/i2c-core-acpi.c | 5 ++++-
  3346. 1 file changed, 4 insertions(+), 1 deletion(-)
  3347. diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
  3348. index 169713964358..9f0e719cd2c8 100644
  3349. --- a/drivers/i2c/i2c-core-acpi.c
  3350. +++ b/drivers/i2c/i2c-core-acpi.c
  3351. @@ -112,9 +112,12 @@ static int i2c_acpi_do_lookup(struct acpi_device *adev,
  3352. struct list_head resource_list;
  3353. int ret;
  3354. - if (acpi_bus_get_status(adev) || !adev->status.present)
  3355. + if (acpi_bus_get_status(adev))
  3356. return -EINVAL;
  3357. + if (!acpi_dev_ready_for_enumeration(adev))
  3358. + return -ENODEV;
  3359. +
  3360. if (acpi_match_device_ids(adev, i2c_acpi_ignored_device_ids) == 0)
  3361. return -ENODEV;
  3362. --
  3363. 2.34.0
  3364. From 2eacb6feb10dd81f94140bb16dbef6c335d20b9b Mon Sep 17 00:00:00 2001
  3365. From: Hans de Goede <hdegoede@redhat.com>
  3366. Date: Sun, 10 Oct 2021 20:56:59 +0200
  3367. Subject: [PATCH] platform_data: Add linux/platform_data/tps68470.h file
  3368. The clk and regulator frameworks expect clk/regulator consumer-devices
  3369. to have info about the consumed clks/regulators described in the device's
  3370. fw_node.
  3371. To work around cases where this info is not present in the firmware tables,
  3372. which is often the case on x86/ACPI devices, both frameworks allow the
  3373. provider-driver to attach info about consumers to the provider-device
  3374. during probe/registration of the provider device.
  3375. The TI TPS68470 PMIC is used x86/ACPI devices with the consumer-info
  3376. missing from the ACPI tables. Thus the tps68470-clk and tps68470-regulator
  3377. drivers must provide the consumer-info at probe time.
  3378. Define tps68470_clk_platform_data and tps68470_regulator_platform_data
  3379. structs to allow the x86 platform code to pass the necessary consumer info
  3380. to these drivers.
  3381. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  3382. Patchset: cameras
  3383. ---
  3384. include/linux/platform_data/tps68470.h | 35 ++++++++++++++++++++++++++
  3385. 1 file changed, 35 insertions(+)
  3386. create mode 100644 include/linux/platform_data/tps68470.h
  3387. diff --git a/include/linux/platform_data/tps68470.h b/include/linux/platform_data/tps68470.h
  3388. new file mode 100644
  3389. index 000000000000..126d082c3f2e
  3390. --- /dev/null
  3391. +++ b/include/linux/platform_data/tps68470.h
  3392. @@ -0,0 +1,35 @@
  3393. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  3394. +/*
  3395. + * TI TPS68470 PMIC platform data definition.
  3396. + *
  3397. + * Copyright (c) 2021 Red Hat Inc.
  3398. + *
  3399. + * Red Hat authors:
  3400. + * Hans de Goede <hdegoede@redhat.com>
  3401. + */
  3402. +#ifndef __PDATA_TPS68470_H
  3403. +#define __PDATA_TPS68470_H
  3404. +
  3405. +enum tps68470_regulators {
  3406. + TPS68470_CORE,
  3407. + TPS68470_ANA,
  3408. + TPS68470_VCM,
  3409. + TPS68470_VIO,
  3410. + TPS68470_VSIO,
  3411. + TPS68470_AUX1,
  3412. + TPS68470_AUX2,
  3413. + TPS68470_NUM_REGULATORS
  3414. +};
  3415. +
  3416. +struct regulator_init_data;
  3417. +
  3418. +struct tps68470_regulator_platform_data {
  3419. + const struct regulator_init_data *reg_init_data[TPS68470_NUM_REGULATORS];
  3420. +};
  3421. +
  3422. +struct tps68470_clk_platform_data {
  3423. + const char *consumer_dev_name;
  3424. + const char *consumer_con_id;
  3425. +};
  3426. +
  3427. +#endif
  3428. --
  3429. 2.34.0
  3430. From 2f1936ac79975f2a90f821bac31cf20c76a8bbce Mon Sep 17 00:00:00 2001
  3431. From: Hans de Goede <hdegoede@redhat.com>
  3432. Date: Sun, 10 Oct 2021 20:57:00 +0200
  3433. Subject: [PATCH] regulator: Introduce tps68470-regulator driver
  3434. The TPS68470 PMIC provides Clocks, GPIOs and Regulators. At present in
  3435. the kernel the Regulators and Clocks are controlled by an OpRegion
  3436. driver designed to work with power control methods defined in ACPI, but
  3437. some platforms lack those methods, meaning drivers need to be able to
  3438. consume the resources of these chips through the usual frameworks.
  3439. This commit adds a driver for the regulators provided by the tps68470,
  3440. and is designed to bind to the platform_device registered by the
  3441. intel_skl_int3472 module.
  3442. This is based on this out of tree driver written by Intel:
  3443. https://github.com/intel/linux-intel-lts/blob/4.14/base/drivers/regulator/tps68470-regulator.c
  3444. with various cleanups added.
  3445. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  3446. Patchset: cameras
  3447. ---
  3448. drivers/regulator/Kconfig | 9 ++
  3449. drivers/regulator/Makefile | 1 +
  3450. drivers/regulator/tps68470-regulator.c | 193 +++++++++++++++++++++++++
  3451. 3 files changed, 203 insertions(+)
  3452. create mode 100644 drivers/regulator/tps68470-regulator.c
  3453. diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
  3454. index 24ce9a17ab4f..97caab5f7f9f 100644
  3455. --- a/drivers/regulator/Kconfig
  3456. +++ b/drivers/regulator/Kconfig
  3457. @@ -1319,6 +1319,15 @@ config REGULATOR_TPS65912
  3458. help
  3459. This driver supports TPS65912 voltage regulator chip.
  3460. +config REGULATOR_TPS68470
  3461. + tristate "TI TPS68370 PMIC Regulators Driver"
  3462. + depends on INTEL_SKL_INT3472
  3463. + help
  3464. + This driver adds support for the TPS68470 PMIC to register
  3465. + regulators against the usual framework.
  3466. +
  3467. + The module will be called "tps68470-regulator"
  3468. +
  3469. config REGULATOR_TPS80031
  3470. tristate "TI TPS80031/TPS80032 power regulator driver"
  3471. depends on MFD_TPS80031
  3472. diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
  3473. index 8c2f82206b94..8dcc4506ecf8 100644
  3474. --- a/drivers/regulator/Makefile
  3475. +++ b/drivers/regulator/Makefile
  3476. @@ -156,6 +156,7 @@ obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o
  3477. obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o
  3478. obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o
  3479. obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o
  3480. +obj-$(CONFIG_REGULATOR_TPS68470) += tps68470-regulator.o
  3481. obj-$(CONFIG_REGULATOR_TPS80031) += tps80031-regulator.o
  3482. obj-$(CONFIG_REGULATOR_TPS65132) += tps65132-regulator.o
  3483. obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o twl6030-regulator.o
  3484. diff --git a/drivers/regulator/tps68470-regulator.c b/drivers/regulator/tps68470-regulator.c
  3485. new file mode 100644
  3486. index 000000000000..3129fa13a122
  3487. --- /dev/null
  3488. +++ b/drivers/regulator/tps68470-regulator.c
  3489. @@ -0,0 +1,193 @@
  3490. +// SPDX-License-Identifier: GPL-2.0
  3491. +/*
  3492. + * Regulator driver for TPS68470 PMIC
  3493. + *
  3494. + * Copyright (C) 2018 Intel Corporation
  3495. + *
  3496. + * Authors:
  3497. + * Zaikuo Wang <zaikuo.wang@intel.com>
  3498. + * Tianshu Qiu <tian.shu.qiu@intel.com>
  3499. + * Jian Xu Zheng <jian.xu.zheng@intel.com>
  3500. + * Yuning Pu <yuning.pu@intel.com>
  3501. + * Rajmohan Mani <rajmohan.mani@intel.com>
  3502. + */
  3503. +
  3504. +#include <linux/device.h>
  3505. +#include <linux/err.h>
  3506. +#include <linux/init.h>
  3507. +#include <linux/kernel.h>
  3508. +#include <linux/mfd/tps68470.h>
  3509. +#include <linux/module.h>
  3510. +#include <linux/platform_data/tps68470.h>
  3511. +#include <linux/platform_device.h>
  3512. +#include <linux/regulator/driver.h>
  3513. +#include <linux/regulator/machine.h>
  3514. +
  3515. +#define TPS68470_REGULATOR(_name, _id, _ops, _n, _vr, \
  3516. + _vm, _er, _em, _t, _lr, _nlr) \
  3517. + [TPS68470_ ## _name] = { \
  3518. + .name = # _name, \
  3519. + .id = _id, \
  3520. + .ops = &_ops, \
  3521. + .n_voltages = _n, \
  3522. + .type = REGULATOR_VOLTAGE, \
  3523. + .owner = THIS_MODULE, \
  3524. + .vsel_reg = _vr, \
  3525. + .vsel_mask = _vm, \
  3526. + .enable_reg = _er, \
  3527. + .enable_mask = _em, \
  3528. + .volt_table = _t, \
  3529. + .linear_ranges = _lr, \
  3530. + .n_linear_ranges = _nlr, \
  3531. + }
  3532. +
  3533. +static const struct linear_range tps68470_ldo_ranges[] = {
  3534. + REGULATOR_LINEAR_RANGE(875000, 0, 125, 17800),
  3535. +};
  3536. +
  3537. +static const struct linear_range tps68470_core_ranges[] = {
  3538. + REGULATOR_LINEAR_RANGE(900000, 0, 42, 25000),
  3539. +};
  3540. +
  3541. +/* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */
  3542. +static const struct regulator_ops tps68470_regulator_ops = {
  3543. + .is_enabled = regulator_is_enabled_regmap,
  3544. + .enable = regulator_enable_regmap,
  3545. + .disable = regulator_disable_regmap,
  3546. + .get_voltage_sel = regulator_get_voltage_sel_regmap,
  3547. + .set_voltage_sel = regulator_set_voltage_sel_regmap,
  3548. + .list_voltage = regulator_list_voltage_linear_range,
  3549. + .map_voltage = regulator_map_voltage_linear_range,
  3550. +};
  3551. +
  3552. +static const struct regulator_desc regulators[] = {
  3553. + TPS68470_REGULATOR(CORE, TPS68470_CORE,
  3554. + tps68470_regulator_ops, 43, TPS68470_REG_VDVAL,
  3555. + TPS68470_VDVAL_DVOLT_MASK, TPS68470_REG_VDCTL,
  3556. + TPS68470_VDCTL_EN_MASK,
  3557. + NULL, tps68470_core_ranges,
  3558. + ARRAY_SIZE(tps68470_core_ranges)),
  3559. + TPS68470_REGULATOR(ANA, TPS68470_ANA,
  3560. + tps68470_regulator_ops, 126, TPS68470_REG_VAVAL,
  3561. + TPS68470_VAVAL_AVOLT_MASK, TPS68470_REG_VACTL,
  3562. + TPS68470_VACTL_EN_MASK,
  3563. + NULL, tps68470_ldo_ranges,
  3564. + ARRAY_SIZE(tps68470_ldo_ranges)),
  3565. + TPS68470_REGULATOR(VCM, TPS68470_VCM,
  3566. + tps68470_regulator_ops, 126, TPS68470_REG_VCMVAL,
  3567. + TPS68470_VCMVAL_VCVOLT_MASK, TPS68470_REG_VCMCTL,
  3568. + TPS68470_VCMCTL_EN_MASK,
  3569. + NULL, tps68470_ldo_ranges,
  3570. + ARRAY_SIZE(tps68470_ldo_ranges)),
  3571. + TPS68470_REGULATOR(VIO, TPS68470_VIO,
  3572. + tps68470_regulator_ops, 126, TPS68470_REG_VIOVAL,
  3573. + TPS68470_VIOVAL_IOVOLT_MASK, TPS68470_REG_S_I2C_CTL,
  3574. + TPS68470_S_I2C_CTL_EN_MASK,
  3575. + NULL, tps68470_ldo_ranges,
  3576. + ARRAY_SIZE(tps68470_ldo_ranges)),
  3577. +
  3578. +/*
  3579. + * (1) This register must have same setting as VIOVAL if S_IO LDO is used to
  3580. + * power daisy chained IOs in the receive side.
  3581. + * (2) If there is no I2C daisy chain it can be set freely.
  3582. + *
  3583. + */
  3584. + TPS68470_REGULATOR(VSIO, TPS68470_VSIO,
  3585. + tps68470_regulator_ops, 126, TPS68470_REG_VSIOVAL,
  3586. + TPS68470_VSIOVAL_IOVOLT_MASK, TPS68470_REG_S_I2C_CTL,
  3587. + TPS68470_S_I2C_CTL_EN_MASK,
  3588. + NULL, tps68470_ldo_ranges,
  3589. + ARRAY_SIZE(tps68470_ldo_ranges)),
  3590. + TPS68470_REGULATOR(AUX1, TPS68470_AUX1,
  3591. + tps68470_regulator_ops, 126, TPS68470_REG_VAUX1VAL,
  3592. + TPS68470_VAUX1VAL_AUX1VOLT_MASK,
  3593. + TPS68470_REG_VAUX1CTL,
  3594. + TPS68470_VAUX1CTL_EN_MASK,
  3595. + NULL, tps68470_ldo_ranges,
  3596. + ARRAY_SIZE(tps68470_ldo_ranges)),
  3597. + TPS68470_REGULATOR(AUX2, TPS68470_AUX2,
  3598. + tps68470_regulator_ops, 126, TPS68470_REG_VAUX2VAL,
  3599. + TPS68470_VAUX2VAL_AUX2VOLT_MASK,
  3600. + TPS68470_REG_VAUX2CTL,
  3601. + TPS68470_VAUX2CTL_EN_MASK,
  3602. + NULL, tps68470_ldo_ranges,
  3603. + ARRAY_SIZE(tps68470_ldo_ranges)),
  3604. +};
  3605. +
  3606. +#define TPS68470_REG_INIT_DATA(_name, _min_uV, _max_uV) \
  3607. + [TPS68470_ ## _name] = { \
  3608. + .constraints = { \
  3609. + .name = # _name, \
  3610. + .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | \
  3611. + REGULATOR_CHANGE_STATUS, \
  3612. + .min_uV = _min_uV, \
  3613. + .max_uV = _max_uV, \
  3614. + }, \
  3615. + }
  3616. +
  3617. +struct regulator_init_data tps68470_init[] = {
  3618. + TPS68470_REG_INIT_DATA(CORE, 900000, 1950000),
  3619. + TPS68470_REG_INIT_DATA(ANA, 875000, 3100000),
  3620. + TPS68470_REG_INIT_DATA(VCM, 875000, 3100000),
  3621. + TPS68470_REG_INIT_DATA(VIO, 875000, 3100000),
  3622. + TPS68470_REG_INIT_DATA(VSIO, 875000, 3100000),
  3623. + TPS68470_REG_INIT_DATA(AUX1, 875000, 3100000),
  3624. + TPS68470_REG_INIT_DATA(AUX2, 875000, 3100000),
  3625. +};
  3626. +
  3627. +static int tps68470_regulator_probe(struct platform_device *pdev)
  3628. +{
  3629. + struct tps68470_regulator_platform_data *pdata = pdev->dev.platform_data;
  3630. + struct regulator_config config = { };
  3631. + struct regmap *tps68470_regmap;
  3632. + struct regulator_dev *rdev;
  3633. + int i;
  3634. +
  3635. + tps68470_regmap = dev_get_drvdata(pdev->dev.parent);
  3636. +
  3637. + for (i = 0; i < TPS68470_NUM_REGULATORS; i++) {
  3638. + config.dev = pdev->dev.parent;
  3639. + config.regmap = tps68470_regmap;
  3640. + if (pdata && pdata->reg_init_data[i])
  3641. + config.init_data = pdata->reg_init_data[i];
  3642. + else
  3643. + config.init_data = &tps68470_init[i];
  3644. +
  3645. + rdev = devm_regulator_register(&pdev->dev, &regulators[i], &config);
  3646. + if (IS_ERR(rdev)) {
  3647. + dev_err(&pdev->dev, "failed to register %s regulator\n",
  3648. + regulators[i].name);
  3649. + return PTR_ERR(rdev);
  3650. + }
  3651. + }
  3652. +
  3653. + return 0;
  3654. +}
  3655. +
  3656. +static struct platform_driver tps68470_regulator_driver = {
  3657. + .driver = {
  3658. + .name = "tps68470-regulator",
  3659. + },
  3660. + .probe = tps68470_regulator_probe,
  3661. +};
  3662. +
  3663. +/*
  3664. + * The ACPI tps68470 probe-ordering depends on the clk/gpio/regulator drivers
  3665. + * registering before the drivers for the camera-sensors which use them bind.
  3666. + * subsys_initcall() ensures this when the drivers are builtin.
  3667. + */
  3668. +static int __init tps68470_regulator_init(void)
  3669. +{
  3670. + return platform_driver_register(&tps68470_regulator_driver);
  3671. +}
  3672. +subsys_initcall(tps68470_regulator_init);
  3673. +
  3674. +static void __exit tps68470_regulator_exit(void)
  3675. +{
  3676. + platform_driver_unregister(&tps68470_regulator_driver);
  3677. +}
  3678. +module_exit(tps68470_regulator_exit);
  3679. +
  3680. +MODULE_ALIAS("platform:tps68470-regulator");
  3681. +MODULE_DESCRIPTION("TPS68470 voltage regulator driver");
  3682. +MODULE_LICENSE("GPL v2");
  3683. --
  3684. 2.34.0
  3685. From d114fbffa257b641e5f21a3d65878ec0ff6a012f Mon Sep 17 00:00:00 2001
  3686. From: Hans de Goede <hdegoede@redhat.com>
  3687. Date: Sun, 10 Oct 2021 20:57:01 +0200
  3688. Subject: [PATCH] clk: Introduce clk-tps68470 driver
  3689. The TPS68470 PMIC provides Clocks, GPIOs and Regulators. At present in
  3690. the kernel the Regulators and Clocks are controlled by an OpRegion
  3691. driver designed to work with power control methods defined in ACPI, but
  3692. some platforms lack those methods, meaning drivers need to be able to
  3693. consume the resources of these chips through the usual frameworks.
  3694. This commit adds a driver for the clocks provided by the tps68470,
  3695. and is designed to bind to the platform_device registered by the
  3696. intel_skl_int3472 module.
  3697. This is based on this out of tree driver written by Intel:
  3698. https://github.com/intel/linux-intel-lts/blob/4.14/base/drivers/clk/clk-tps68470.c
  3699. with various cleanups added.
  3700. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  3701. Patchset: cameras
  3702. ---
  3703. drivers/clk/Kconfig | 6 +
  3704. drivers/clk/Makefile | 1 +
  3705. drivers/clk/clk-tps68470.c | 256 +++++++++++++++++++++++++++++++++++
  3706. include/linux/mfd/tps68470.h | 11 ++
  3707. 4 files changed, 274 insertions(+)
  3708. create mode 100644 drivers/clk/clk-tps68470.c
  3709. diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
  3710. index e873f9ea2e65..f5255b085fe2 100644
  3711. --- a/drivers/clk/Kconfig
  3712. +++ b/drivers/clk/Kconfig
  3713. @@ -169,6 +169,12 @@ config COMMON_CLK_CDCE706
  3714. help
  3715. This driver supports TI CDCE706 programmable 3-PLL clock synthesizer.
  3716. +config COMMON_CLK_TPS68470
  3717. + tristate "Clock Driver for TI TPS68470 PMIC"
  3718. + depends on I2C && REGMAP_I2C && INTEL_SKL_INT3472
  3719. + help
  3720. + This driver supports the clocks provided by TPS68470
  3721. +
  3722. config COMMON_CLK_CDCE925
  3723. tristate "Clock driver for TI CDCE913/925/937/949 devices"
  3724. depends on I2C
  3725. diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
  3726. index 2b91d34c582b..1f7dad3461f2 100644
  3727. --- a/drivers/clk/Makefile
  3728. +++ b/drivers/clk/Makefile
  3729. @@ -63,6 +63,7 @@ obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o
  3730. obj-$(CONFIG_COMMON_CLK_STM32F) += clk-stm32f4.o
  3731. obj-$(CONFIG_COMMON_CLK_STM32H7) += clk-stm32h7.o
  3732. obj-$(CONFIG_COMMON_CLK_STM32MP157) += clk-stm32mp1.o
  3733. +obj-$(CONFIG_COMMON_CLK_TPS68470) += clk-tps68470.o
  3734. obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o
  3735. obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o
  3736. obj-$(CONFIG_COMMON_CLK_VC5) += clk-versaclock5.o
  3737. diff --git a/drivers/clk/clk-tps68470.c b/drivers/clk/clk-tps68470.c
  3738. new file mode 100644
  3739. index 000000000000..27e8cbd0f60e
  3740. --- /dev/null
  3741. +++ b/drivers/clk/clk-tps68470.c
  3742. @@ -0,0 +1,256 @@
  3743. +// SPDX-License-Identifier: GPL-2.0
  3744. +/*
  3745. + * Clock driver for TPS68470 PMIC
  3746. + *
  3747. + * Copyright (C) 2018 Intel Corporation
  3748. + *
  3749. + * Authors:
  3750. + * Zaikuo Wang <zaikuo.wang@intel.com>
  3751. + * Tianshu Qiu <tian.shu.qiu@intel.com>
  3752. + * Jian Xu Zheng <jian.xu.zheng@intel.com>
  3753. + * Yuning Pu <yuning.pu@intel.com>
  3754. + * Antti Laakso <antti.laakso@intel.com>
  3755. + */
  3756. +
  3757. +#include <linux/clk-provider.h>
  3758. +#include <linux/clkdev.h>
  3759. +#include <linux/kernel.h>
  3760. +#include <linux/mfd/tps68470.h>
  3761. +#include <linux/module.h>
  3762. +#include <linux/platform_device.h>
  3763. +#include <linux/platform_data/tps68470.h>
  3764. +#include <linux/regmap.h>
  3765. +
  3766. +#define TPS68470_CLK_NAME "tps68470-clk"
  3767. +
  3768. +#define to_tps68470_clkdata(clkd) \
  3769. + container_of(clkd, struct tps68470_clkdata, clkout_hw)
  3770. +
  3771. +struct tps68470_clkout_freqs {
  3772. + unsigned long freq;
  3773. + unsigned int xtaldiv;
  3774. + unsigned int plldiv;
  3775. + unsigned int postdiv;
  3776. + unsigned int buckdiv;
  3777. + unsigned int boostdiv;
  3778. +} clk_freqs[] = {
  3779. +/*
  3780. + * The PLL is used to multiply the crystal oscillator
  3781. + * frequency range of 3 MHz to 27 MHz by a programmable
  3782. + * factor of F = (M/N)*(1/P) such that the output
  3783. + * available at the HCLK_A or HCLK_B pins are in the range
  3784. + * of 4 MHz to 64 MHz in increments of 0.1 MHz
  3785. + *
  3786. + * hclk_# = osc_in * (((plldiv*2)+320) / (xtaldiv+30)) * (1 / 2^postdiv)
  3787. + *
  3788. + * PLL_REF_CLK should be as close as possible to 100kHz
  3789. + * PLL_REF_CLK = input clk / XTALDIV[7:0] + 30)
  3790. + *
  3791. + * PLL_VCO_CLK = (PLL_REF_CLK * (plldiv*2 + 320))
  3792. + *
  3793. + * BOOST should be as close as possible to 2Mhz
  3794. + * BOOST = PLL_VCO_CLK / (BOOSTDIV[4:0] + 16) *
  3795. + *
  3796. + * BUCK should be as close as possible to 5.2Mhz
  3797. + * BUCK = PLL_VCO_CLK / (BUCKDIV[3:0] + 5)
  3798. + *
  3799. + * osc_in xtaldiv plldiv postdiv hclk_#
  3800. + * 20Mhz 170 32 1 19.2Mhz
  3801. + * 20Mhz 170 40 1 20Mhz
  3802. + * 20Mhz 170 80 1 24Mhz
  3803. + *
  3804. + */
  3805. + { 19200000, 170, 32, 1, 2, 3 },
  3806. + { 20000000, 170, 40, 1, 3, 4 },
  3807. + { 24000000, 170, 80, 1, 4, 8 },
  3808. +};
  3809. +
  3810. +struct tps68470_clkdata {
  3811. + struct clk_hw clkout_hw;
  3812. + struct regmap *regmap;
  3813. + struct clk *clk;
  3814. + int clk_cfg_idx;
  3815. +};
  3816. +
  3817. +static int tps68470_clk_is_prepared(struct clk_hw *hw)
  3818. +{
  3819. + struct tps68470_clkdata *clkdata = to_tps68470_clkdata(hw);
  3820. + int val;
  3821. +
  3822. + if (regmap_read(clkdata->regmap, TPS68470_REG_PLLCTL, &val))
  3823. + return 0;
  3824. +
  3825. + return val & TPS68470_PLL_EN_MASK;
  3826. +}
  3827. +
  3828. +static int tps68470_clk_prepare(struct clk_hw *hw)
  3829. +{
  3830. + struct tps68470_clkdata *clkdata = to_tps68470_clkdata(hw);
  3831. + int idx = clkdata->clk_cfg_idx;
  3832. +
  3833. + regmap_write(clkdata->regmap, TPS68470_REG_BOOSTDIV, clk_freqs[idx].boostdiv);
  3834. + regmap_write(clkdata->regmap, TPS68470_REG_BUCKDIV, clk_freqs[idx].buckdiv);
  3835. + regmap_write(clkdata->regmap, TPS68470_REG_PLLSWR, TPS68470_PLLSWR_DEFAULT);
  3836. + regmap_write(clkdata->regmap, TPS68470_REG_XTALDIV, clk_freqs[idx].xtaldiv);
  3837. + regmap_write(clkdata->regmap, TPS68470_REG_PLLDIV, clk_freqs[idx].plldiv);
  3838. + regmap_write(clkdata->regmap, TPS68470_REG_POSTDIV, clk_freqs[idx].postdiv);
  3839. + regmap_write(clkdata->regmap, TPS68470_REG_POSTDIV2, clk_freqs[idx].postdiv);
  3840. + regmap_write(clkdata->regmap, TPS68470_REG_CLKCFG2, TPS68470_CLKCFG2_DRV_STR_2MA);
  3841. +
  3842. + regmap_write(clkdata->regmap, TPS68470_REG_PLLCTL,
  3843. + TPS68470_OSC_EXT_CAP_DEFAULT << TPS68470_OSC_EXT_CAP_SHIFT |
  3844. + TPS68470_CLK_SRC_XTAL << TPS68470_CLK_SRC_SHIFT);
  3845. +
  3846. + regmap_write(clkdata->regmap, TPS68470_REG_CLKCFG1,
  3847. + (TPS68470_PLL_OUTPUT_ENABLE <<
  3848. + TPS68470_OUTPUT_A_SHIFT) |
  3849. + (TPS68470_PLL_OUTPUT_ENABLE <<
  3850. + TPS68470_OUTPUT_B_SHIFT));
  3851. +
  3852. + regmap_update_bits(clkdata->regmap, TPS68470_REG_PLLCTL,
  3853. + TPS68470_PLL_EN_MASK, TPS68470_PLL_EN_MASK);
  3854. +
  3855. + return 0;
  3856. +}
  3857. +
  3858. +static void tps68470_clk_unprepare(struct clk_hw *hw)
  3859. +{
  3860. + struct tps68470_clkdata *clkdata = to_tps68470_clkdata(hw);
  3861. +
  3862. + /* disable clock first*/
  3863. + regmap_update_bits(clkdata->regmap, TPS68470_REG_PLLCTL, TPS68470_PLL_EN_MASK, 0);
  3864. +
  3865. + /* write hw defaults */
  3866. + regmap_write(clkdata->regmap, TPS68470_REG_BOOSTDIV, 0);
  3867. + regmap_write(clkdata->regmap, TPS68470_REG_BUCKDIV, 0);
  3868. + regmap_write(clkdata->regmap, TPS68470_REG_PLLSWR, 0);
  3869. + regmap_write(clkdata->regmap, TPS68470_REG_XTALDIV, 0);
  3870. + regmap_write(clkdata->regmap, TPS68470_REG_PLLDIV, 0);
  3871. + regmap_write(clkdata->regmap, TPS68470_REG_POSTDIV, 0);
  3872. + regmap_write(clkdata->regmap, TPS68470_REG_CLKCFG2, 0);
  3873. + regmap_write(clkdata->regmap, TPS68470_REG_CLKCFG1, 0);
  3874. +}
  3875. +
  3876. +static unsigned long tps68470_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
  3877. +{
  3878. + struct tps68470_clkdata *clkdata = to_tps68470_clkdata(hw);
  3879. +
  3880. + return clk_freqs[clkdata->clk_cfg_idx].freq;
  3881. +}
  3882. +
  3883. +static int tps68470_clk_cfg_lookup(unsigned long rate)
  3884. +{
  3885. + long diff, best_diff = LONG_MAX;
  3886. + int i, best_idx = 0;
  3887. +
  3888. + for (i = 0; i < ARRAY_SIZE(clk_freqs); i++) {
  3889. + diff = clk_freqs[i].freq - rate;
  3890. + if (diff == 0)
  3891. + return i;
  3892. +
  3893. + diff = abs(diff);
  3894. + if (diff < best_diff) {
  3895. + best_diff = diff;
  3896. + best_idx = i;
  3897. + }
  3898. + }
  3899. +
  3900. + return best_idx;
  3901. +}
  3902. +
  3903. +static long tps68470_clk_round_rate(struct clk_hw *hw, unsigned long rate,
  3904. + unsigned long *parent_rate)
  3905. +{
  3906. + int idx = tps68470_clk_cfg_lookup(rate);
  3907. +
  3908. + return clk_freqs[idx].freq;
  3909. +}
  3910. +
  3911. +static int tps68470_clk_set_rate(struct clk_hw *hw, unsigned long rate,
  3912. + unsigned long parent_rate)
  3913. +{
  3914. + struct tps68470_clkdata *clkdata = to_tps68470_clkdata(hw);
  3915. + int idx = tps68470_clk_cfg_lookup(rate);
  3916. +
  3917. + if (rate != clk_freqs[idx].freq)
  3918. + return -EINVAL;
  3919. +
  3920. + clkdata->clk_cfg_idx = idx;
  3921. + return 0;
  3922. +}
  3923. +
  3924. +static const struct clk_ops tps68470_clk_ops = {
  3925. + .is_prepared = tps68470_clk_is_prepared,
  3926. + .prepare = tps68470_clk_prepare,
  3927. + .unprepare = tps68470_clk_unprepare,
  3928. + .recalc_rate = tps68470_clk_recalc_rate,
  3929. + .round_rate = tps68470_clk_round_rate,
  3930. + .set_rate = tps68470_clk_set_rate,
  3931. +};
  3932. +
  3933. +static struct clk_init_data tps68470_clk_initdata = {
  3934. + .name = TPS68470_CLK_NAME,
  3935. + .ops = &tps68470_clk_ops,
  3936. +};
  3937. +
  3938. +static int tps68470_clk_probe(struct platform_device *pdev)
  3939. +{
  3940. + struct tps68470_clk_platform_data *pdata = pdev->dev.platform_data;
  3941. + struct tps68470_clkdata *tps68470_clkdata;
  3942. + int ret;
  3943. +
  3944. + tps68470_clkdata = devm_kzalloc(&pdev->dev, sizeof(*tps68470_clkdata),
  3945. + GFP_KERNEL);
  3946. + if (!tps68470_clkdata)
  3947. + return -ENOMEM;
  3948. +
  3949. + tps68470_clkdata->regmap = dev_get_drvdata(pdev->dev.parent);
  3950. + tps68470_clkdata->clkout_hw.init = &tps68470_clk_initdata;
  3951. + tps68470_clkdata->clk = devm_clk_register(&pdev->dev, &tps68470_clkdata->clkout_hw);
  3952. + if (IS_ERR(tps68470_clkdata->clk))
  3953. + return PTR_ERR(tps68470_clkdata->clk);
  3954. +
  3955. + ret = devm_clk_hw_register_clkdev(&pdev->dev, &tps68470_clkdata->clkout_hw,
  3956. + TPS68470_CLK_NAME, NULL);
  3957. + if (ret)
  3958. + return ret;
  3959. +
  3960. + if (pdata) {
  3961. + ret = devm_clk_hw_register_clkdev(&pdev->dev,
  3962. + &tps68470_clkdata->clkout_hw,
  3963. + pdata->consumer_con_id,
  3964. + pdata->consumer_dev_name);
  3965. + if (ret)
  3966. + return ret;
  3967. + }
  3968. +
  3969. + return 0;
  3970. +}
  3971. +
  3972. +static struct platform_driver tps68470_clk_driver = {
  3973. + .driver = {
  3974. + .name = TPS68470_CLK_NAME,
  3975. + },
  3976. + .probe = tps68470_clk_probe,
  3977. +};
  3978. +
  3979. +/*
  3980. + * The ACPI tps68470 probe-ordering depends on the clk/gpio/regulator drivers
  3981. + * registering before the drivers for the camera-sensors which use them bind.
  3982. + * subsys_initcall() ensures this when the drivers are builtin.
  3983. + */
  3984. +static int __init tps68470_clk_init(void)
  3985. +{
  3986. + return platform_driver_register(&tps68470_clk_driver);
  3987. +}
  3988. +subsys_initcall(tps68470_clk_init);
  3989. +
  3990. +static void __exit tps68470_clk_exit(void)
  3991. +{
  3992. + platform_driver_unregister(&tps68470_clk_driver);
  3993. +}
  3994. +module_exit(tps68470_clk_exit);
  3995. +
  3996. +MODULE_ALIAS("platform:tps68470-clk");
  3997. +MODULE_DESCRIPTION("clock driver for TPS68470 pmic");
  3998. +MODULE_LICENSE("GPL");
  3999. diff --git a/include/linux/mfd/tps68470.h b/include/linux/mfd/tps68470.h
  4000. index ffe81127d91c..7807fa329db0 100644
  4001. --- a/include/linux/mfd/tps68470.h
  4002. +++ b/include/linux/mfd/tps68470.h
  4003. @@ -75,6 +75,17 @@
  4004. #define TPS68470_CLKCFG1_MODE_A_MASK GENMASK(1, 0)
  4005. #define TPS68470_CLKCFG1_MODE_B_MASK GENMASK(3, 2)
  4006. +#define TPS68470_CLKCFG2_DRV_STR_2MA 0x05
  4007. +#define TPS68470_PLL_OUTPUT_ENABLE 0x02
  4008. +#define TPS68470_CLK_SRC_XTAL BIT(0)
  4009. +#define TPS68470_PLLSWR_DEFAULT GENMASK(1, 0)
  4010. +#define TPS68470_OSC_EXT_CAP_DEFAULT 0x05
  4011. +
  4012. +#define TPS68470_OUTPUT_A_SHIFT 0x00
  4013. +#define TPS68470_OUTPUT_B_SHIFT 0x02
  4014. +#define TPS68470_CLK_SRC_SHIFT GENMASK(2, 0)
  4015. +#define TPS68470_OSC_EXT_CAP_SHIFT BIT(2)
  4016. +
  4017. #define TPS68470_GPIO_CTL_REG_A(x) (TPS68470_REG_GPCTL0A + (x) * 2)
  4018. #define TPS68470_GPIO_CTL_REG_B(x) (TPS68470_REG_GPCTL0B + (x) * 2)
  4019. #define TPS68470_GPIO_MODE_MASK GENMASK(1, 0)
  4020. --
  4021. 2.34.0
  4022. From 235191b72abd1f1b529b5917c3f6fe60415ae4f5 Mon Sep 17 00:00:00 2001
  4023. From: Daniel Scally <djrscally@gmail.com>
  4024. Date: Sun, 10 Oct 2021 20:57:02 +0200
  4025. Subject: [PATCH] platform/x86: int3472: Enable I2c daisy chain
  4026. The TPS68470 PMIC has an I2C passthrough mode through which I2C traffic
  4027. can be forwarded to a device connected to the PMIC as though it were
  4028. connected directly to the system bus. Enable this mode when the chip
  4029. is initialised.
  4030. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  4031. Patchset: cameras
  4032. ---
  4033. .../x86/intel/int3472/intel_skl_int3472_tps68470.c | 7 +++++++
  4034. 1 file changed, 7 insertions(+)
  4035. diff --git a/drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c b/drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c
  4036. index c05b4cf502fe..42e688f4cad4 100644
  4037. --- a/drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c
  4038. +++ b/drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c
  4039. @@ -45,6 +45,13 @@ static int tps68470_chip_init(struct device *dev, struct regmap *regmap)
  4040. return ret;
  4041. }
  4042. + /* Enable I2C daisy chain */
  4043. + ret = regmap_write(regmap, TPS68470_REG_S_I2C_CTL, 0x03);
  4044. + if (ret) {
  4045. + dev_err(dev, "Failed to enable i2c daisy chain\n");
  4046. + return ret;
  4047. + }
  4048. +
  4049. dev_info(dev, "TPS68470 REVID: 0x%02x\n", version);
  4050. return 0;
  4051. --
  4052. 2.34.0
  4053. From eef319f98c64c8e155be21f592cbb16ef30da91e Mon Sep 17 00:00:00 2001
  4054. From: Hans de Goede <hdegoede@redhat.com>
  4055. Date: Sun, 10 Oct 2021 20:57:03 +0200
  4056. Subject: [PATCH] platform/x86: int3472: Split into 2 drivers
  4057. The intel_skl_int3472.ko module contains 2 separate drivers,
  4058. the int3472_discrete platform driver and the int3472_tps68470
  4059. I2C-driver.
  4060. These 2 drivers contain very little shared code, only
  4061. skl_int3472_get_acpi_buffer() and skl_int3472_fill_cldb() are
  4062. shared.
  4063. Split the module into 2 drivers, linking the little shared code
  4064. directly into both.
  4065. This will allow us to add soft-module dependencies for the
  4066. tps68470 clk, gpio and regulator drivers to the new
  4067. intel_skl_int3472_tps68470.ko to help with probe ordering issues
  4068. without causing these modules to get loaded on boards which only
  4069. use the int3472_discrete platform driver.
  4070. While at it also rename the .c and .h files to remove the
  4071. cumbersome intel_skl_int3472_ prefix.
  4072. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  4073. Patchset: cameras
  4074. ---
  4075. drivers/platform/x86/intel/int3472/Makefile | 9 ++--
  4076. ...lk_and_regulator.c => clk_and_regulator.c} | 2 +-
  4077. drivers/platform/x86/intel/int3472/common.c | 54 +++++++++++++++++++
  4078. .../{intel_skl_int3472_common.h => common.h} | 3 --
  4079. ...ntel_skl_int3472_discrete.c => discrete.c} | 28 ++++++++--
  4080. ...ntel_skl_int3472_tps68470.c => tps68470.c} | 23 +++++++-
  4081. 6 files changed, 105 insertions(+), 14 deletions(-)
  4082. rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_clk_and_regulator.c => clk_and_regulator.c} (99%)
  4083. create mode 100644 drivers/platform/x86/intel/int3472/common.c
  4084. rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_common.h => common.h} (94%)
  4085. rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_discrete.c => discrete.c} (93%)
  4086. rename drivers/platform/x86/intel/int3472/{intel_skl_int3472_tps68470.c => tps68470.c} (85%)
  4087. diff --git a/drivers/platform/x86/intel/int3472/Makefile b/drivers/platform/x86/intel/int3472/Makefile
  4088. index 48bd97f0a04e..4a4b2518ea16 100644
  4089. --- a/drivers/platform/x86/intel/int3472/Makefile
  4090. +++ b/drivers/platform/x86/intel/int3472/Makefile
  4091. @@ -1,5 +1,4 @@
  4092. -obj-$(CONFIG_INTEL_SKL_INT3472) += intel_skl_int3472.o
  4093. -intel_skl_int3472-objs := intel_skl_int3472_common.o \
  4094. - intel_skl_int3472_discrete.o \
  4095. - intel_skl_int3472_tps68470.o \
  4096. - intel_skl_int3472_clk_and_regulator.o
  4097. +obj-$(CONFIG_INTEL_SKL_INT3472) += intel_skl_int3472_discrete.o \
  4098. + intel_skl_int3472_tps68470.o
  4099. +intel_skl_int3472_discrete-y := discrete.o clk_and_regulator.o common.o
  4100. +intel_skl_int3472_tps68470-y := tps68470.o common.o
  4101. 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
  4102. similarity index 99%
  4103. rename from drivers/platform/x86/intel/int3472/intel_skl_int3472_clk_and_regulator.c
  4104. rename to drivers/platform/x86/intel/int3472/clk_and_regulator.c
  4105. index 1700e7557a82..1cf958983e86 100644
  4106. --- a/drivers/platform/x86/intel/int3472/intel_skl_int3472_clk_and_regulator.c
  4107. +++ b/drivers/platform/x86/intel/int3472/clk_and_regulator.c
  4108. @@ -9,7 +9,7 @@
  4109. #include <linux/regulator/driver.h>
  4110. #include <linux/slab.h>
  4111. -#include "intel_skl_int3472_common.h"
  4112. +#include "common.h"
  4113. /*
  4114. * The regulators have to have .ops to be valid, but the only ops we actually
  4115. diff --git a/drivers/platform/x86/intel/int3472/common.c b/drivers/platform/x86/intel/int3472/common.c
  4116. new file mode 100644
  4117. index 000000000000..350655a9515b
  4118. --- /dev/null
  4119. +++ b/drivers/platform/x86/intel/int3472/common.c
  4120. @@ -0,0 +1,54 @@
  4121. +// SPDX-License-Identifier: GPL-2.0
  4122. +/* Author: Dan Scally <djrscally@gmail.com> */
  4123. +
  4124. +#include <linux/acpi.h>
  4125. +#include <linux/slab.h>
  4126. +
  4127. +#include "common.h"
  4128. +
  4129. +union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev, char *id)
  4130. +{
  4131. + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  4132. + acpi_handle handle = adev->handle;
  4133. + union acpi_object *obj;
  4134. + acpi_status status;
  4135. +
  4136. + status = acpi_evaluate_object(handle, id, NULL, &buffer);
  4137. + if (ACPI_FAILURE(status))
  4138. + return ERR_PTR(-ENODEV);
  4139. +
  4140. + obj = buffer.pointer;
  4141. + if (!obj)
  4142. + return ERR_PTR(-ENODEV);
  4143. +
  4144. + if (obj->type != ACPI_TYPE_BUFFER) {
  4145. + acpi_handle_err(handle, "%s object is not an ACPI buffer\n", id);
  4146. + kfree(obj);
  4147. + return ERR_PTR(-EINVAL);
  4148. + }
  4149. +
  4150. + return obj;
  4151. +}
  4152. +
  4153. +int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb)
  4154. +{
  4155. + union acpi_object *obj;
  4156. + int ret;
  4157. +
  4158. + obj = skl_int3472_get_acpi_buffer(adev, "CLDB");
  4159. + if (IS_ERR(obj))
  4160. + return PTR_ERR(obj);
  4161. +
  4162. + if (obj->buffer.length > sizeof(*cldb)) {
  4163. + acpi_handle_err(adev->handle, "The CLDB buffer is too large\n");
  4164. + ret = -EINVAL;
  4165. + goto out_free_obj;
  4166. + }
  4167. +
  4168. + memcpy(cldb, obj->buffer.pointer, obj->buffer.length);
  4169. + ret = 0;
  4170. +
  4171. +out_free_obj:
  4172. + kfree(obj);
  4173. + return ret;
  4174. +}
  4175. diff --git a/drivers/platform/x86/intel/int3472/intel_skl_int3472_common.h b/drivers/platform/x86/intel/int3472/common.h
  4176. similarity index 94%
  4177. rename from drivers/platform/x86/intel/int3472/intel_skl_int3472_common.h
  4178. rename to drivers/platform/x86/intel/int3472/common.h
  4179. index 714fde73b524..d14944ee8586 100644
  4180. --- a/drivers/platform/x86/intel/int3472/intel_skl_int3472_common.h
  4181. +++ b/drivers/platform/x86/intel/int3472/common.h
  4182. @@ -105,9 +105,6 @@ struct int3472_discrete_device {
  4183. struct gpiod_lookup_table gpios;
  4184. };
  4185. -int skl_int3472_discrete_probe(struct platform_device *pdev);
  4186. -int skl_int3472_discrete_remove(struct platform_device *pdev);
  4187. -int skl_int3472_tps68470_probe(struct i2c_client *client);
  4188. union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev,
  4189. char *id);
  4190. int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb);
  4191. diff --git a/drivers/platform/x86/intel/int3472/intel_skl_int3472_discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
  4192. similarity index 93%
  4193. rename from drivers/platform/x86/intel/int3472/intel_skl_int3472_discrete.c
  4194. rename to drivers/platform/x86/intel/int3472/discrete.c
  4195. index 9fe0a2527e1c..856602a2f6bb 100644
  4196. --- a/drivers/platform/x86/intel/int3472/intel_skl_int3472_discrete.c
  4197. +++ b/drivers/platform/x86/intel/int3472/discrete.c
  4198. @@ -14,7 +14,7 @@
  4199. #include <linux/platform_device.h>
  4200. #include <linux/uuid.h>
  4201. -#include "intel_skl_int3472_common.h"
  4202. +#include "common.h"
  4203. /*
  4204. * 79234640-9e10-4fea-a5c1-b5aa8b19756f
  4205. @@ -332,7 +332,9 @@ static int skl_int3472_parse_crs(struct int3472_discrete_device *int3472)
  4206. return 0;
  4207. }
  4208. -int skl_int3472_discrete_probe(struct platform_device *pdev)
  4209. +static int skl_int3472_discrete_remove(struct platform_device *pdev);
  4210. +
  4211. +static int skl_int3472_discrete_probe(struct platform_device *pdev)
  4212. {
  4213. struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
  4214. struct int3472_discrete_device *int3472;
  4215. @@ -395,7 +397,7 @@ int skl_int3472_discrete_probe(struct platform_device *pdev)
  4216. return ret;
  4217. }
  4218. -int skl_int3472_discrete_remove(struct platform_device *pdev)
  4219. +static int skl_int3472_discrete_remove(struct platform_device *pdev)
  4220. {
  4221. struct int3472_discrete_device *int3472 = platform_get_drvdata(pdev);
  4222. @@ -411,3 +413,23 @@ int skl_int3472_discrete_remove(struct platform_device *pdev)
  4223. return 0;
  4224. }
  4225. +
  4226. +static const struct acpi_device_id int3472_device_id[] = {
  4227. + { "INT3472", 0 },
  4228. + { }
  4229. +};
  4230. +MODULE_DEVICE_TABLE(acpi, int3472_device_id);
  4231. +
  4232. +static struct platform_driver int3472_discrete = {
  4233. + .driver = {
  4234. + .name = "int3472-discrete",
  4235. + .acpi_match_table = int3472_device_id,
  4236. + },
  4237. + .probe = skl_int3472_discrete_probe,
  4238. + .remove = skl_int3472_discrete_remove,
  4239. +};
  4240. +module_platform_driver(int3472_discrete);
  4241. +
  4242. +MODULE_DESCRIPTION("Intel SkyLake INT3472 ACPI Discrete Device Driver");
  4243. +MODULE_AUTHOR("Daniel Scally <djrscally@gmail.com>");
  4244. +MODULE_LICENSE("GPL v2");
  4245. diff --git a/drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c b/drivers/platform/x86/intel/int3472/tps68470.c
  4246. similarity index 85%
  4247. rename from drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c
  4248. rename to drivers/platform/x86/intel/int3472/tps68470.c
  4249. index 42e688f4cad4..b94cf66ab61f 100644
  4250. --- a/drivers/platform/x86/intel/int3472/intel_skl_int3472_tps68470.c
  4251. +++ b/drivers/platform/x86/intel/int3472/tps68470.c
  4252. @@ -7,7 +7,7 @@
  4253. #include <linux/platform_device.h>
  4254. #include <linux/regmap.h>
  4255. -#include "intel_skl_int3472_common.h"
  4256. +#include "common.h"
  4257. #define DESIGNED_FOR_CHROMEOS 1
  4258. #define DESIGNED_FOR_WINDOWS 2
  4259. @@ -102,7 +102,7 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev)
  4260. return DESIGNED_FOR_WINDOWS;
  4261. }
  4262. -int skl_int3472_tps68470_probe(struct i2c_client *client)
  4263. +static int skl_int3472_tps68470_probe(struct i2c_client *client)
  4264. {
  4265. struct acpi_device *adev = ACPI_COMPANION(&client->dev);
  4266. struct regmap *regmap;
  4267. @@ -142,3 +142,22 @@ int skl_int3472_tps68470_probe(struct i2c_client *client)
  4268. return ret;
  4269. }
  4270. +
  4271. +static const struct acpi_device_id int3472_device_id[] = {
  4272. + { "INT3472", 0 },
  4273. + { }
  4274. +};
  4275. +MODULE_DEVICE_TABLE(acpi, int3472_device_id);
  4276. +
  4277. +static struct i2c_driver int3472_tps68470 = {
  4278. + .driver = {
  4279. + .name = "int3472-tps68470",
  4280. + .acpi_match_table = int3472_device_id,
  4281. + },
  4282. + .probe_new = skl_int3472_tps68470_probe,
  4283. +};
  4284. +module_i2c_driver(int3472_tps68470);
  4285. +
  4286. +MODULE_DESCRIPTION("Intel SkyLake INT3472 ACPI TPS68470 Device Driver");
  4287. +MODULE_AUTHOR("Daniel Scally <djrscally@gmail.com>");
  4288. +MODULE_LICENSE("GPL v2");
  4289. --
  4290. 2.34.0
  4291. From 25895ad4036113835c557ee75f9f9c524d56adb7 Mon Sep 17 00:00:00 2001
  4292. From: Hans de Goede <hdegoede@redhat.com>
  4293. Date: Sun, 10 Oct 2021 20:57:04 +0200
  4294. Subject: [PATCH] platform/x86: int3472: Add get_sensor_adev_and_name() helper
  4295. The discrete.c code is not the only code which needs to lookup the
  4296. acpi_device and device-name for the sensor for which the INT3472
  4297. ACPI-device is a GPIO/clk/regulator provider.
  4298. The tps68470.c code also needs this functionality, so factor this
  4299. out into a new get_sensor_adev_and_name() helper.
  4300. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  4301. Patchset: cameras
  4302. ---
  4303. drivers/platform/x86/intel/int3472/common.c | 28 +++++++++++++++++++
  4304. drivers/platform/x86/intel/int3472/common.h | 3 ++
  4305. drivers/platform/x86/intel/int3472/discrete.c | 22 +++------------
  4306. 3 files changed, 35 insertions(+), 18 deletions(-)
  4307. diff --git a/drivers/platform/x86/intel/int3472/common.c b/drivers/platform/x86/intel/int3472/common.c
  4308. index 350655a9515b..77cf058e4168 100644
  4309. --- a/drivers/platform/x86/intel/int3472/common.c
  4310. +++ b/drivers/platform/x86/intel/int3472/common.c
  4311. @@ -52,3 +52,31 @@ int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb)
  4312. kfree(obj);
  4313. return ret;
  4314. }
  4315. +
  4316. +/* sensor_adev_ret may be NULL, name_ret must not be NULL */
  4317. +int skl_int3472_get_sensor_adev_and_name(struct device *dev,
  4318. + struct acpi_device **sensor_adev_ret,
  4319. + const char **name_ret)
  4320. +{
  4321. + struct acpi_device *adev = ACPI_COMPANION(dev);
  4322. + struct acpi_device *sensor;
  4323. + int ret = 0;
  4324. +
  4325. + sensor = acpi_dev_get_first_consumer_dev(adev);
  4326. + if (!sensor) {
  4327. + dev_err(dev, "INT3472 seems to have no dependents.\n");
  4328. + return -ENODEV;
  4329. + }
  4330. +
  4331. + *name_ret = devm_kasprintf(dev, GFP_KERNEL, I2C_DEV_NAME_FORMAT,
  4332. + acpi_dev_name(sensor));
  4333. + if (!*name_ret)
  4334. + ret = -ENOMEM;
  4335. +
  4336. + if (ret == 0 && sensor_adev_ret)
  4337. + *sensor_adev_ret = sensor;
  4338. + else
  4339. + acpi_dev_put(sensor);
  4340. +
  4341. + return ret;
  4342. +}
  4343. diff --git a/drivers/platform/x86/intel/int3472/common.h b/drivers/platform/x86/intel/int3472/common.h
  4344. index d14944ee8586..53270d19c73a 100644
  4345. --- a/drivers/platform/x86/intel/int3472/common.h
  4346. +++ b/drivers/platform/x86/intel/int3472/common.h
  4347. @@ -108,6 +108,9 @@ struct int3472_discrete_device {
  4348. union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev,
  4349. char *id);
  4350. int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb);
  4351. +int skl_int3472_get_sensor_adev_and_name(struct device *dev,
  4352. + struct acpi_device **sensor_adev_ret,
  4353. + const char **name_ret);
  4354. int skl_int3472_register_clock(struct int3472_discrete_device *int3472);
  4355. void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472);
  4356. diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
  4357. index 856602a2f6bb..22a4894f1cc7 100644
  4358. --- a/drivers/platform/x86/intel/int3472/discrete.c
  4359. +++ b/drivers/platform/x86/intel/int3472/discrete.c
  4360. @@ -363,19 +363,10 @@ static int skl_int3472_discrete_probe(struct platform_device *pdev)
  4361. int3472->dev = &pdev->dev;
  4362. platform_set_drvdata(pdev, int3472);
  4363. - int3472->sensor = acpi_dev_get_first_consumer_dev(adev);
  4364. - if (!int3472->sensor) {
  4365. - dev_err(&pdev->dev, "INT3472 seems to have no dependents.\n");
  4366. - return -ENODEV;
  4367. - }
  4368. -
  4369. - int3472->sensor_name = devm_kasprintf(int3472->dev, GFP_KERNEL,
  4370. - I2C_DEV_NAME_FORMAT,
  4371. - acpi_dev_name(int3472->sensor));
  4372. - if (!int3472->sensor_name) {
  4373. - ret = -ENOMEM;
  4374. - goto err_put_sensor;
  4375. - }
  4376. + ret = skl_int3472_get_sensor_adev_and_name(&pdev->dev, &int3472->sensor,
  4377. + &int3472->sensor_name);
  4378. + if (ret)
  4379. + return ret;
  4380. /*
  4381. * Initialising this list means we can call gpiod_remove_lookup_table()
  4382. @@ -390,11 +381,6 @@ static int skl_int3472_discrete_probe(struct platform_device *pdev)
  4383. }
  4384. return 0;
  4385. -
  4386. -err_put_sensor:
  4387. - acpi_dev_put(int3472->sensor);
  4388. -
  4389. - return ret;
  4390. }
  4391. static int skl_int3472_discrete_remove(struct platform_device *pdev)
  4392. --
  4393. 2.34.0
  4394. From 3ed4113df3ad5142e726a54ae3c6592733ee8367 Mon Sep 17 00:00:00 2001
  4395. From: Hans de Goede <hdegoede@redhat.com>
  4396. Date: Sun, 10 Oct 2021 20:57:05 +0200
  4397. Subject: [PATCH] platform/x86: int3472: Pass tps68470_clk_platform_data to the
  4398. tps68470-regulator MFD-cell
  4399. Pass tps68470_clk_platform_data to the tps68470-clk MFD-cell,
  4400. so that sensors which use the TPS68470 can find their clock.
  4401. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  4402. Patchset: cameras
  4403. ---
  4404. drivers/platform/x86/intel/int3472/tps68470.c | 33 ++++++++++++++-----
  4405. 1 file changed, 25 insertions(+), 8 deletions(-)
  4406. diff --git a/drivers/platform/x86/intel/int3472/tps68470.c b/drivers/platform/x86/intel/int3472/tps68470.c
  4407. index b94cf66ab61f..78e34e7b6969 100644
  4408. --- a/drivers/platform/x86/intel/int3472/tps68470.c
  4409. +++ b/drivers/platform/x86/intel/int3472/tps68470.c
  4410. @@ -5,6 +5,7 @@
  4411. #include <linux/mfd/core.h>
  4412. #include <linux/mfd/tps68470.h>
  4413. #include <linux/platform_device.h>
  4414. +#include <linux/platform_data/tps68470.h>
  4415. #include <linux/regmap.h>
  4416. #include "common.h"
  4417. @@ -17,12 +18,6 @@ static const struct mfd_cell tps68470_cros[] = {
  4418. { .name = "tps68470_pmic_opregion" },
  4419. };
  4420. -static const struct mfd_cell tps68470_win[] = {
  4421. - { .name = "tps68470-gpio" },
  4422. - { .name = "tps68470-clk" },
  4423. - { .name = "tps68470-regulator" },
  4424. -};
  4425. -
  4426. static const struct regmap_config tps68470_regmap_config = {
  4427. .reg_bits = 8,
  4428. .val_bits = 8,
  4429. @@ -105,10 +100,17 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev)
  4430. static int skl_int3472_tps68470_probe(struct i2c_client *client)
  4431. {
  4432. struct acpi_device *adev = ACPI_COMPANION(&client->dev);
  4433. + struct tps68470_clk_platform_data clk_pdata = {};
  4434. + struct mfd_cell *cells;
  4435. struct regmap *regmap;
  4436. int device_type;
  4437. int ret;
  4438. + ret = skl_int3472_get_sensor_adev_and_name(&client->dev, NULL,
  4439. + &clk_pdata.consumer_dev_name);
  4440. + if (ret)
  4441. + return ret;
  4442. +
  4443. regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
  4444. if (IS_ERR(regmap)) {
  4445. dev_err(&client->dev, "Failed to create regmap: %ld\n", PTR_ERR(regmap));
  4446. @@ -126,9 +128,24 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
  4447. device_type = skl_int3472_tps68470_calc_type(adev);
  4448. switch (device_type) {
  4449. case DESIGNED_FOR_WINDOWS:
  4450. - ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
  4451. - tps68470_win, ARRAY_SIZE(tps68470_win),
  4452. + cells = kcalloc(3, sizeof(*cells), GFP_KERNEL);
  4453. + if (!cells)
  4454. + return -ENOMEM;
  4455. +
  4456. + cells[0].name = "tps68470-clk";
  4457. + cells[0].platform_data = &clk_pdata;
  4458. + cells[0].pdata_size = sizeof(clk_pdata);
  4459. + cells[1].name = "tps68470-regulator";
  4460. + /*
  4461. + * The GPIO cell must be last because acpi_gpiochip_add() calls
  4462. + * acpi_dev_clear_dependencies() and the clk + regulators must
  4463. + * be ready when this happens.
  4464. + */
  4465. + cells[2].name = "tps68470-gpio";
  4466. +
  4467. + ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE, cells, 3,
  4468. NULL, 0, NULL);
  4469. + kfree(cells);
  4470. break;
  4471. case DESIGNED_FOR_CHROMEOS:
  4472. ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
  4473. --
  4474. 2.34.0
  4475. From 63ac25978683d2ab14df13c54f566c1e49558d77 Mon Sep 17 00:00:00 2001
  4476. From: Hans de Goede <hdegoede@redhat.com>
  4477. Date: Sun, 10 Oct 2021 20:57:06 +0200
  4478. Subject: [PATCH] platform/x86: int3472: Pass tps68470_regulator_platform_data
  4479. to the tps68470-regulator MFD-cell
  4480. Pass tps68470_regulator_platform_data to the tps68470-regulator
  4481. MFD-cell, specifying the voltages of the various regulators and
  4482. tying the regulators to the sensor supplies so that sensors which use
  4483. the TPS68470 can find their regulators.
  4484. Since the voltages and supply connections are board-specific, this
  4485. introduces a DMI matches int3472_tps68470_board_data struct which
  4486. contains the necessary per-board info.
  4487. This per-board info also includes GPIO lookup information for the
  4488. sensor GPIOs which may be connected to the tps68470 gpios.
  4489. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  4490. Patchset: cameras
  4491. ---
  4492. drivers/platform/x86/intel/int3472/Makefile | 2 +-
  4493. drivers/platform/x86/intel/int3472/tps68470.c | 43 +++++--
  4494. drivers/platform/x86/intel/int3472/tps68470.h | 25 ++++
  4495. .../x86/intel/int3472/tps68470_board_data.c | 118 ++++++++++++++++++
  4496. 4 files changed, 180 insertions(+), 8 deletions(-)
  4497. create mode 100644 drivers/platform/x86/intel/int3472/tps68470.h
  4498. create mode 100644 drivers/platform/x86/intel/int3472/tps68470_board_data.c
  4499. diff --git a/drivers/platform/x86/intel/int3472/Makefile b/drivers/platform/x86/intel/int3472/Makefile
  4500. index 4a4b2518ea16..ca56e7eea781 100644
  4501. --- a/drivers/platform/x86/intel/int3472/Makefile
  4502. +++ b/drivers/platform/x86/intel/int3472/Makefile
  4503. @@ -1,4 +1,4 @@
  4504. obj-$(CONFIG_INTEL_SKL_INT3472) += intel_skl_int3472_discrete.o \
  4505. intel_skl_int3472_tps68470.o
  4506. intel_skl_int3472_discrete-y := discrete.o clk_and_regulator.o common.o
  4507. -intel_skl_int3472_tps68470-y := tps68470.o common.o
  4508. +intel_skl_int3472_tps68470-y := tps68470.o tps68470_board_data.o common.o
  4509. diff --git a/drivers/platform/x86/intel/int3472/tps68470.c b/drivers/platform/x86/intel/int3472/tps68470.c
  4510. index 78e34e7b6969..aae24d228770 100644
  4511. --- a/drivers/platform/x86/intel/int3472/tps68470.c
  4512. +++ b/drivers/platform/x86/intel/int3472/tps68470.c
  4513. @@ -9,6 +9,7 @@
  4514. #include <linux/regmap.h>
  4515. #include "common.h"
  4516. +#include "tps68470.h"
  4517. #define DESIGNED_FOR_CHROMEOS 1
  4518. #define DESIGNED_FOR_WINDOWS 2
  4519. @@ -100,6 +101,7 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev)
  4520. static int skl_int3472_tps68470_probe(struct i2c_client *client)
  4521. {
  4522. struct acpi_device *adev = ACPI_COMPANION(&client->dev);
  4523. + const struct int3472_tps68470_board_data *board_data;
  4524. struct tps68470_clk_platform_data clk_pdata = {};
  4525. struct mfd_cell *cells;
  4526. struct regmap *regmap;
  4527. @@ -128,6 +130,12 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
  4528. device_type = skl_int3472_tps68470_calc_type(adev);
  4529. switch (device_type) {
  4530. case DESIGNED_FOR_WINDOWS:
  4531. + board_data = int3472_tps68470_get_board_data(dev_name(&client->dev));
  4532. + if (!board_data) {
  4533. + dev_err(&client->dev, "No board-data found for this laptop/tablet model\n");
  4534. + return -ENODEV;
  4535. + }
  4536. +
  4537. cells = kcalloc(3, sizeof(*cells), GFP_KERNEL);
  4538. if (!cells)
  4539. return -ENOMEM;
  4540. @@ -136,6 +144,8 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
  4541. cells[0].platform_data = &clk_pdata;
  4542. cells[0].pdata_size = sizeof(clk_pdata);
  4543. cells[1].name = "tps68470-regulator";
  4544. + cells[1].platform_data = (void *)board_data->tps68470_regulator_pdata;
  4545. + cells[1].pdata_size = sizeof(struct tps68470_regulator_platform_data);
  4546. /*
  4547. * The GPIO cell must be last because acpi_gpiochip_add() calls
  4548. * acpi_dev_clear_dependencies() and the clk + regulators must
  4549. @@ -143,9 +153,15 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
  4550. */
  4551. cells[2].name = "tps68470-gpio";
  4552. + gpiod_add_lookup_table(board_data->tps68470_gpio_lookup_table);
  4553. +
  4554. ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE, cells, 3,
  4555. NULL, 0, NULL);
  4556. kfree(cells);
  4557. +
  4558. + if (ret)
  4559. + gpiod_remove_lookup_table(board_data->tps68470_gpio_lookup_table);
  4560. +
  4561. break;
  4562. case DESIGNED_FOR_CHROMEOS:
  4563. ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
  4564. @@ -160,18 +176,31 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
  4565. return ret;
  4566. }
  4567. +static int skl_int3472_tps68470_remove(struct i2c_client *client)
  4568. +{
  4569. + const struct int3472_tps68470_board_data *board_data;
  4570. +
  4571. + board_data = int3472_tps68470_get_board_data(dev_name(&client->dev));
  4572. + if (board_data)
  4573. + gpiod_remove_lookup_table(board_data->tps68470_gpio_lookup_table);
  4574. +
  4575. + return 0;
  4576. +}
  4577. +
  4578. +
  4579. static const struct acpi_device_id int3472_device_id[] = {
  4580. - { "INT3472", 0 },
  4581. - { }
  4582. + { "INT3472", 0 },
  4583. + { }
  4584. };
  4585. MODULE_DEVICE_TABLE(acpi, int3472_device_id);
  4586. static struct i2c_driver int3472_tps68470 = {
  4587. - .driver = {
  4588. - .name = "int3472-tps68470",
  4589. - .acpi_match_table = int3472_device_id,
  4590. - },
  4591. - .probe_new = skl_int3472_tps68470_probe,
  4592. + .driver = {
  4593. + .name = "int3472-tps68470",
  4594. + .acpi_match_table = int3472_device_id,
  4595. + },
  4596. + .probe_new = skl_int3472_tps68470_probe,
  4597. + .remove = skl_int3472_tps68470_remove,
  4598. };
  4599. module_i2c_driver(int3472_tps68470);
  4600. diff --git a/drivers/platform/x86/intel/int3472/tps68470.h b/drivers/platform/x86/intel/int3472/tps68470.h
  4601. new file mode 100644
  4602. index 000000000000..cfd33eb62740
  4603. --- /dev/null
  4604. +++ b/drivers/platform/x86/intel/int3472/tps68470.h
  4605. @@ -0,0 +1,25 @@
  4606. +/* SPDX-License-Identifier: GPL-2.0 */
  4607. +/*
  4608. + * TI TPS68470 PMIC platform data definition.
  4609. + *
  4610. + * Copyright (c) 2021 Red Hat Inc.
  4611. + *
  4612. + * Red Hat authors:
  4613. + * Hans de Goede <hdegoede@redhat.com>
  4614. + */
  4615. +
  4616. +#ifndef _INTEL_SKL_INT3472_TPS68470_H
  4617. +#define _INTEL_SKL_INT3472_TPS68470_H
  4618. +
  4619. +struct gpiod_lookup_table;
  4620. +struct tps68470_regulator_platform_data;
  4621. +
  4622. +struct int3472_tps68470_board_data {
  4623. + const char *dev_name;
  4624. + struct gpiod_lookup_table *tps68470_gpio_lookup_table;
  4625. + const struct tps68470_regulator_platform_data *tps68470_regulator_pdata;
  4626. +};
  4627. +
  4628. +const struct int3472_tps68470_board_data *int3472_tps68470_get_board_data(const char *dev_name);
  4629. +
  4630. +#endif
  4631. diff --git a/drivers/platform/x86/intel/int3472/tps68470_board_data.c b/drivers/platform/x86/intel/int3472/tps68470_board_data.c
  4632. new file mode 100644
  4633. index 000000000000..96954a789bb8
  4634. --- /dev/null
  4635. +++ b/drivers/platform/x86/intel/int3472/tps68470_board_data.c
  4636. @@ -0,0 +1,118 @@
  4637. +// SPDX-License-Identifier: GPL-2.0
  4638. +/*
  4639. + * TI TPS68470 PMIC platform data definition.
  4640. + *
  4641. + * Copyright (c) 2021 Dan Scally <djrscally@gmail.com>
  4642. + * Copyright (c) 2021 Red Hat Inc.
  4643. + *
  4644. + * Red Hat authors:
  4645. + * Hans de Goede <hdegoede@redhat.com>
  4646. + */
  4647. +
  4648. +#include <linux/dmi.h>
  4649. +#include <linux/gpio/machine.h>
  4650. +#include <linux/platform_data/tps68470.h>
  4651. +#include <linux/regulator/machine.h>
  4652. +#include "tps68470.h"
  4653. +
  4654. +static struct regulator_consumer_supply int347a_core_consumer_supplies[] = {
  4655. + REGULATOR_SUPPLY("dvdd", "i2c-INT347A:00"),
  4656. +};
  4657. +
  4658. +static struct regulator_consumer_supply int347a_ana_consumer_supplies[] = {
  4659. + REGULATOR_SUPPLY("avdd", "i2c-INT347A:00"),
  4660. +};
  4661. +
  4662. +static struct regulator_consumer_supply int347a_vsio_consumer_supplies[] = {
  4663. + REGULATOR_SUPPLY("dovdd", "i2c-INT347A:00"),
  4664. +};
  4665. +
  4666. +static const struct regulator_init_data surface_go_tps68470_core_reg_init_data = {
  4667. + .constraints = {
  4668. + .min_uV = 1200000,
  4669. + .max_uV = 1200000,
  4670. + .apply_uV = 1,
  4671. + .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  4672. + },
  4673. + .num_consumer_supplies = ARRAY_SIZE(int347a_core_consumer_supplies),
  4674. + .consumer_supplies = int347a_core_consumer_supplies,
  4675. +};
  4676. +
  4677. +static const struct regulator_init_data surface_go_tps68470_ana_reg_init_data = {
  4678. + .constraints = {
  4679. + .min_uV = 2815200,
  4680. + .max_uV = 2815200,
  4681. + .apply_uV = 1,
  4682. + .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  4683. + },
  4684. + .num_consumer_supplies = ARRAY_SIZE(int347a_ana_consumer_supplies),
  4685. + .consumer_supplies = int347a_ana_consumer_supplies,
  4686. +};
  4687. +
  4688. +static const struct regulator_init_data surface_go_tps68470_vsio_reg_init_data = {
  4689. + .constraints = {
  4690. + .min_uV = 1800600,
  4691. + .max_uV = 1800600,
  4692. + .apply_uV = 1,
  4693. + .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  4694. + },
  4695. + .num_consumer_supplies = ARRAY_SIZE(int347a_vsio_consumer_supplies),
  4696. + .consumer_supplies = int347a_vsio_consumer_supplies,
  4697. +};
  4698. +
  4699. +static const struct tps68470_regulator_platform_data surface_go_tps68470_pdata = {
  4700. + .reg_init_data = {
  4701. + [TPS68470_CORE] = &surface_go_tps68470_core_reg_init_data,
  4702. + [TPS68470_ANA] = &surface_go_tps68470_ana_reg_init_data,
  4703. + [TPS68470_VSIO] = &surface_go_tps68470_vsio_reg_init_data,
  4704. + },
  4705. +};
  4706. +
  4707. +static struct gpiod_lookup_table surface_go_tps68470_gpios = {
  4708. + .dev_id = "i2c-INT347A:00",
  4709. + .table = {
  4710. + GPIO_LOOKUP("tps68470-gpio", 9, "reset", GPIO_ACTIVE_LOW),
  4711. + GPIO_LOOKUP("tps68470-gpio", 7, "powerdown", GPIO_ACTIVE_LOW)
  4712. + }
  4713. +};
  4714. +
  4715. +static const struct int3472_tps68470_board_data surface_go_tps68470_board_data = {
  4716. + .dev_name = "i2c-INT3472:05",
  4717. + .tps68470_gpio_lookup_table = &surface_go_tps68470_gpios,
  4718. + .tps68470_regulator_pdata = &surface_go_tps68470_pdata,
  4719. +};
  4720. +
  4721. +static const struct dmi_system_id int3472_tps68470_board_data_table[] = {
  4722. + {
  4723. + .matches = {
  4724. + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
  4725. + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Surface Go"),
  4726. + },
  4727. + .driver_data = (void *)&surface_go_tps68470_board_data,
  4728. + },
  4729. + {
  4730. + .matches = {
  4731. + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
  4732. + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Surface Go 2"),
  4733. + },
  4734. + .driver_data = (void *)&surface_go_tps68470_board_data,
  4735. + },
  4736. + { }
  4737. +};
  4738. +
  4739. +const struct int3472_tps68470_board_data *int3472_tps68470_get_board_data(const char *dev_name)
  4740. +{
  4741. + const struct int3472_tps68470_board_data *board_data;
  4742. + const struct dmi_system_id *match;
  4743. +
  4744. + match = dmi_first_match(int3472_tps68470_board_data_table);
  4745. + while (match) {
  4746. + board_data = match->driver_data;
  4747. + if (strcmp(board_data->dev_name, dev_name) == 0)
  4748. + return board_data;
  4749. +
  4750. + dmi_first_match(++match);
  4751. + }
  4752. +
  4753. + return NULL;
  4754. +}
  4755. --
  4756. 2.34.0
  4757. From d6ccffda8953c4027933bd1d9a8e8d08794d737b Mon Sep 17 00:00:00 2001
  4758. From: Hans de Goede <hdegoede@redhat.com>
  4759. Date: Sun, 10 Oct 2021 20:57:07 +0200
  4760. Subject: [PATCH] platform/x86: int3472: Deal with probe ordering issues
  4761. The clk and regulator frameworks expect clk/regulator consumer-devices
  4762. to have info about the consumed clks/regulators described in the device's
  4763. fw_node.
  4764. To work around this info missing from the ACPI tables on devices where
  4765. the int3472 driver is used, the int3472 MFD-cell drivers attach info about
  4766. consumers to the clks/regulators when registering these.
  4767. This causes problems with the probe ordering wrt drivers for consumers
  4768. of these clks/regulators. Since the lookups are only registered when the
  4769. provider-driver binds, trying to get these clks/regulators before then
  4770. results in a -ENOENT error for clks and a dummy regulator for regulators.
  4771. All the sensor ACPI fw-nodes have a _DEP dependency on the INT3472 ACPI
  4772. fw-node, so to work around these probe ordering issues the ACPI core /
  4773. i2c-code does not instantiate the I2C-clients for any ACPI devices
  4774. which have a _DEP dependency on an INT3472 ACPI device until all
  4775. _DEP-s are met.
  4776. This relies on acpi_dev_clear_dependencies() getting called by the driver
  4777. for the _DEP-s when they are ready, add a acpi_dev_clear_dependencies()
  4778. call to the discrete.c probe code.
  4779. In the tps68470 case calling acpi_dev_clear_dependencies() is already done
  4780. by the acpi_gpiochip_add() call done by the driver for the GPIO MFD cell
  4781. (The GPIO cell is deliberately the last cell created to make sure the
  4782. clk + regulator cells are already instantiated when this happens).
  4783. However for proper probe ordering, the clk/regulator cells must not just
  4784. be instantiated the must be fully ready (the clks + regulators must be
  4785. registered with their subsystems).
  4786. Add MODULE_SOFTDEP dependencies for the clk and regulator drivers for
  4787. the instantiated MFD-cells so that these are loaded before us and so
  4788. that they bind immediately when the platform-devs are instantiated.
  4789. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  4790. Patchset: cameras
  4791. ---
  4792. drivers/platform/x86/intel/int3472/discrete.c | 1 +
  4793. drivers/platform/x86/intel/int3472/tps68470.c | 6 ++++++
  4794. 2 files changed, 7 insertions(+)
  4795. diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
  4796. index 22a4894f1cc7..3e1d755b3f83 100644
  4797. --- a/drivers/platform/x86/intel/int3472/discrete.c
  4798. +++ b/drivers/platform/x86/intel/int3472/discrete.c
  4799. @@ -380,6 +380,7 @@ static int skl_int3472_discrete_probe(struct platform_device *pdev)
  4800. return ret;
  4801. }
  4802. + acpi_dev_clear_dependencies(adev);
  4803. return 0;
  4804. }
  4805. diff --git a/drivers/platform/x86/intel/int3472/tps68470.c b/drivers/platform/x86/intel/int3472/tps68470.c
  4806. index aae24d228770..21c6c1a6edfc 100644
  4807. --- a/drivers/platform/x86/intel/int3472/tps68470.c
  4808. +++ b/drivers/platform/x86/intel/int3472/tps68470.c
  4809. @@ -173,6 +173,11 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
  4810. return device_type;
  4811. }
  4812. + /*
  4813. + * No acpi_dev_clear_dependencies() here, since the acpi_gpiochip_add()
  4814. + * for the GPIO cell already does this.
  4815. + */
  4816. +
  4817. return ret;
  4818. }
  4819. @@ -207,3 +212,4 @@ module_i2c_driver(int3472_tps68470);
  4820. MODULE_DESCRIPTION("Intel SkyLake INT3472 ACPI TPS68470 Device Driver");
  4821. MODULE_AUTHOR("Daniel Scally <djrscally@gmail.com>");
  4822. MODULE_LICENSE("GPL v2");
  4823. +MODULE_SOFTDEP("pre: clk-tps68470 tps68470-regulator");
  4824. --
  4825. 2.34.0
  4826. From 64c49983fc05d4f61403f89c1640710efcaf6373 Mon Sep 17 00:00:00 2001
  4827. From: Daniel Scally <djrscally@gmail.com>
  4828. Date: Thu, 22 Jul 2021 00:20:46 +0100
  4829. Subject: [PATCH] Revert "media: device property: Call
  4830. fwnode_graph_get_endpoint_by_id() for fwnode->secondary"
  4831. This reverts commit acd418bfcfc415cf5e6414b6d1c6acfec850f290. Checking for
  4832. endpoints against fwnode->secondary in fwnode_graph_get_next_endpoint() is
  4833. a better way to do this since that function is also used in a bunch of
  4834. other places, for instance sensor drivers checking that they do have an
  4835. endpoint connected during probe.
  4836. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  4837. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  4838. Patchset: cameras
  4839. ---
  4840. drivers/base/property.c | 9 +--------
  4841. 1 file changed, 1 insertion(+), 8 deletions(-)
  4842. diff --git a/drivers/base/property.c b/drivers/base/property.c
  4843. index d0874f6c29bb..4d7ff55df95d 100644
  4844. --- a/drivers/base/property.c
  4845. +++ b/drivers/base/property.c
  4846. @@ -1212,14 +1212,7 @@ fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode,
  4847. best_ep_id = fwnode_ep.id;
  4848. }
  4849. - if (best_ep)
  4850. - return best_ep;
  4851. -
  4852. - if (fwnode && !IS_ERR_OR_NULL(fwnode->secondary))
  4853. - return fwnode_graph_get_endpoint_by_id(fwnode->secondary, port,
  4854. - endpoint, flags);
  4855. -
  4856. - return NULL;
  4857. + return best_ep;
  4858. }
  4859. EXPORT_SYMBOL_GPL(fwnode_graph_get_endpoint_by_id);
  4860. --
  4861. 2.34.0
  4862. From 4a3ae1cf1b9f54a434dfc7bfbf9cb9a28a311133 Mon Sep 17 00:00:00 2001
  4863. From: Daniel Scally <djrscally@gmail.com>
  4864. Date: Sun, 18 Jul 2021 23:52:42 +0100
  4865. Subject: [PATCH] device property: Check fwnode->secondary in
  4866. fwnode_graph_get_next_endpoint()
  4867. Sensor drivers often check for an endpoint to make sure that they're
  4868. connected to a consuming device like a CIO2 during .probe(). Some of
  4869. those endpoints might be in the form of software_nodes assigned as
  4870. a secondary to the device's fwnode_handle. Account for this possibility
  4871. in fwnode_graph_get_next_endpoint() to avoid having to do it in the
  4872. sensor drivers themselves.
  4873. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  4874. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  4875. Patchset: cameras
  4876. ---
  4877. drivers/base/property.c | 21 ++++++++++++++++++++-
  4878. 1 file changed, 20 insertions(+), 1 deletion(-)
  4879. diff --git a/drivers/base/property.c b/drivers/base/property.c
  4880. index 4d7ff55df95d..453918eb7390 100644
  4881. --- a/drivers/base/property.c
  4882. +++ b/drivers/base/property.c
  4883. @@ -1033,7 +1033,26 @@ struct fwnode_handle *
  4884. fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode,
  4885. struct fwnode_handle *prev)
  4886. {
  4887. - return fwnode_call_ptr_op(fwnode, graph_get_next_endpoint, prev);
  4888. + const struct fwnode_handle *parent;
  4889. + struct fwnode_handle *ep;
  4890. +
  4891. + /*
  4892. + * If this function is in a loop and the previous iteration returned
  4893. + * an endpoint from fwnode->secondary, then we need to use the secondary
  4894. + * as parent rather than @fwnode.
  4895. + */
  4896. + if (prev)
  4897. + parent = fwnode_graph_get_port_parent(prev);
  4898. + else
  4899. + parent = fwnode;
  4900. +
  4901. + ep = fwnode_call_ptr_op(parent, graph_get_next_endpoint, prev);
  4902. +
  4903. + if (IS_ERR_OR_NULL(ep) &&
  4904. + !IS_ERR_OR_NULL(parent) && !IS_ERR_OR_NULL(parent->secondary))
  4905. + ep = fwnode_graph_get_next_endpoint(parent->secondary, NULL);
  4906. +
  4907. + return ep;
  4908. }
  4909. EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);
  4910. --
  4911. 2.34.0
  4912. From cdfc01465ee94ccc1a18afca99de9e63cc9dae34 Mon Sep 17 00:00:00 2001
  4913. From: Daniel Scally <djrscally@gmail.com>
  4914. Date: Thu, 4 Nov 2021 21:46:27 +0000
  4915. Subject: [PATCH] media: i2c: Add integration time margin to ov8865
  4916. Without this integration margin to reduce the max exposure, it seems
  4917. that we trip over a limit that results in the image being entirely
  4918. black when max exposure is set. Add the margin to prevent this issue.
  4919. With thanks to jhautbois for spotting and reporting.
  4920. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  4921. Patchset: cameras
  4922. ---
  4923. drivers/media/i2c/ov8865.c | 4 +++-
  4924. 1 file changed, 3 insertions(+), 1 deletion(-)
  4925. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  4926. index d5af8aedf5e8..966487e32bfe 100644
  4927. --- a/drivers/media/i2c/ov8865.c
  4928. +++ b/drivers/media/i2c/ov8865.c
  4929. @@ -143,6 +143,7 @@
  4930. #define OV8865_EXPOSURE_CTRL_L_REG 0x3502
  4931. #define OV8865_EXPOSURE_CTRL_L(v) ((v) & GENMASK(7, 0))
  4932. #define OV8865_EXPOSURE_GAIN_MANUAL_REG 0x3503
  4933. +#define OV8865_INTEGRATION_TIME_MARGIN 8
  4934. #define OV8865_GAIN_CTRL_H_REG 0x3508
  4935. #define OV8865_GAIN_CTRL_H(v) (((v) & GENMASK(12, 8)) >> 8)
  4936. @@ -2462,7 +2463,8 @@ static int ov8865_s_ctrl(struct v4l2_ctrl *ctrl)
  4937. if (ctrl->id == V4L2_CID_VBLANK) {
  4938. int exposure_max;
  4939. - exposure_max = sensor->state.mode->output_size_y + ctrl->val;
  4940. + exposure_max = sensor->state.mode->output_size_y + ctrl->val -
  4941. + OV8865_INTEGRATION_TIME_MARGIN;
  4942. __v4l2_ctrl_modify_range(sensor->ctrls.exposure,
  4943. sensor->ctrls.exposure->minimum,
  4944. exposure_max,
  4945. --
  4946. 2.34.0
  4947. From 65117e827b931d5b5b62bc8428ee3543efbb422c Mon Sep 17 00:00:00 2001
  4948. From: Daniel Scally <djrscally@gmail.com>
  4949. Date: Thu, 4 Nov 2021 21:48:38 +0000
  4950. Subject: [PATCH] media: i2c: Fix max gain in ov8865
  4951. The maximum gain figure in the v4l2 ctrl is wrong. The field is 12 bits
  4952. wide, which is where the 8191 figure comes from, but the datasheet is
  4953. specific that maximum gain is 16x (the low seven bits are fractional, so
  4954. 16x gain is 2048)
  4955. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  4956. Patchset: cameras
  4957. ---
  4958. drivers/media/i2c/ov8865.c | 2 +-
  4959. 1 file changed, 1 insertion(+), 1 deletion(-)
  4960. diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
  4961. index 966487e32bfe..6c78edb65d1e 100644
  4962. --- a/drivers/media/i2c/ov8865.c
  4963. +++ b/drivers/media/i2c/ov8865.c
  4964. @@ -2535,7 +2535,7 @@ static int ov8865_ctrls_init(struct ov8865_sensor *sensor)
  4965. /* Gain */
  4966. - v4l2_ctrl_new_std(handler, ops, V4L2_CID_ANALOGUE_GAIN, 128, 8191, 128,
  4967. + v4l2_ctrl_new_std(handler, ops, V4L2_CID_ANALOGUE_GAIN, 128, 2048, 128,
  4968. 128);
  4969. /* White Balance */
  4970. --
  4971. 2.34.0