0010-cameras.patch 119 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047
  1. From d240380936c76e34eadcdba7ee87c91791287129 Mon Sep 17 00:00:00 2001
  2. From: Daniel Scally <djrscally@gmail.com>
  3. Date: Thu, 20 May 2021 15:09:21 +0100
  4. Subject: [PATCH] ACPI: scan: Extend acpi_walk_dep_device_list()
  5. The acpi_walk_dep_device_list() is not as generalisable as its name
  6. implies, serving only to decrement the dependency count for each
  7. dependent device of the input. Extend the function to instead accept
  8. a callback which can be applied to all the dependencies in acpi_dep_list.
  9. Replace all existing calls to the function with calls to a wrapper, passing
  10. a callback that applies the same dependency reduction.
  11. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  12. Patchset: cameras
  13. ---
  14. drivers/acpi/ec.c | 2 +-
  15. drivers/acpi/pmic/intel_pmic_chtdc_ti.c | 2 +-
  16. drivers/acpi/scan.c | 69 ++++++++++++++-----
  17. drivers/gpio/gpiolib-acpi.c | 10 +--
  18. drivers/i2c/i2c-core-acpi.c | 8 +--
  19. drivers/platform/surface/aggregator/core.c | 6 +-
  20. drivers/platform/surface/surface3_power.c | 22 +++---
  21. .../platform/surface/surface_acpi_notify.c | 7 +-
  22. include/acpi/acpi_bus.h | 7 ++
  23. include/linux/acpi.h | 4 +-
  24. 10 files changed, 90 insertions(+), 47 deletions(-)
  25. diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
  26. index 13565629ce0a..3f7680a007a3 100644
  27. --- a/drivers/acpi/ec.c
  28. +++ b/drivers/acpi/ec.c
  29. @@ -1627,7 +1627,7 @@ static int acpi_ec_add(struct acpi_device *device)
  30. WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr);
  31. /* Reprobe devices depending on the EC */
  32. - acpi_walk_dep_device_list(ec->handle);
  33. + acpi_dev_clear_dependencies(device);
  34. acpi_handle_debug(ec->handle, "enumerated.\n");
  35. return 0;
  36. diff --git a/drivers/acpi/pmic/intel_pmic_chtdc_ti.c b/drivers/acpi/pmic/intel_pmic_chtdc_ti.c
  37. index a5101b07611a..fef7831d0d63 100644
  38. --- a/drivers/acpi/pmic/intel_pmic_chtdc_ti.c
  39. +++ b/drivers/acpi/pmic/intel_pmic_chtdc_ti.c
  40. @@ -117,7 +117,7 @@ static int chtdc_ti_pmic_opregion_probe(struct platform_device *pdev)
  41. return err;
  42. /* Re-enumerate devices depending on PMIC */
  43. - acpi_walk_dep_device_list(ACPI_HANDLE(pdev->dev.parent));
  44. + acpi_dev_clear_dependencies(ACPI_COMPANION(pdev->dev.parent));
  45. return 0;
  46. }
  47. diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
  48. index 345777bf7af9..f5440729ffe9 100644
  49. --- a/drivers/acpi/scan.c
  50. +++ b/drivers/acpi/scan.c
  51. @@ -47,12 +47,6 @@ static DEFINE_MUTEX(acpi_hp_context_lock);
  52. */
  53. static u64 spcr_uart_addr;
  54. -struct acpi_dep_data {
  55. - struct list_head node;
  56. - acpi_handle supplier;
  57. - acpi_handle consumer;
  58. -};
  59. -
  60. void acpi_scan_lock_acquire(void)
  61. {
  62. mutex_lock(&acpi_scan_lock);
  63. @@ -2142,30 +2136,69 @@ static void acpi_bus_attach(struct acpi_device *device, bool first_pass)
  64. device->handler->hotplug.notify_online(device);
  65. }
  66. -void acpi_walk_dep_device_list(acpi_handle handle)
  67. +static int acpi_scan_clear_dep(struct acpi_dep_data *dep, void *data)
  68. {
  69. - struct acpi_dep_data *dep, *tmp;
  70. struct acpi_device *adev;
  71. + acpi_bus_get_device(dep->consumer, &adev);
  72. +
  73. + if (adev) {
  74. + adev->dep_unmet--;
  75. + if (!adev->dep_unmet)
  76. + acpi_bus_attach(adev, true);
  77. + }
  78. +
  79. + list_del(&dep->node);
  80. + kfree(dep);
  81. +
  82. + return 0;
  83. +}
  84. +
  85. +/**
  86. + * acpi_walk_dep_device_list - Apply a callback to every entry in acpi_dep_list
  87. + * @handle: The ACPI handle of the supplier device
  88. + * @callback: Pointer to the callback function to apply
  89. + * @data: Pointer to some data to pass to the callback
  90. + *
  91. + * The return value of the callback determines this function's behaviour. If 0
  92. + * is returned we continue to iterate over acpi_dep_list. If a positive value
  93. + * is returned then the loop is broken but this function returns 0. If a
  94. + * negative value is returned by the callback then the loop is broken and that
  95. + * value is returned as the final error.
  96. + */
  97. +int acpi_walk_dep_device_list(acpi_handle handle,
  98. + int (*callback)(struct acpi_dep_data *, void *),
  99. + void *data)
  100. +{
  101. + struct acpi_dep_data *dep, *tmp;
  102. + int ret;
  103. +
  104. mutex_lock(&acpi_dep_list_lock);
  105. list_for_each_entry_safe(dep, tmp, &acpi_dep_list, node) {
  106. if (dep->supplier == handle) {
  107. - acpi_bus_get_device(dep->consumer, &adev);
  108. -
  109. - if (adev) {
  110. - adev->dep_unmet--;
  111. - if (!adev->dep_unmet)
  112. - acpi_bus_attach(adev, true);
  113. - }
  114. -
  115. - list_del(&dep->node);
  116. - kfree(dep);
  117. + ret = callback(dep, data);
  118. + if (ret)
  119. + break;
  120. }
  121. }
  122. mutex_unlock(&acpi_dep_list_lock);
  123. +
  124. + return ret > 0 ? 0 : ret;
  125. }
  126. EXPORT_SYMBOL_GPL(acpi_walk_dep_device_list);
  127. +/**
  128. + * acpi_dev_clear_dependencies - Inform consumers that the device is now active
  129. + * @supplier: Pointer to the supplier &struct acpi_device
  130. + *
  131. + * Clear dependencies on the given device.
  132. + */
  133. +void acpi_dev_clear_dependencies(struct acpi_device *supplier)
  134. +{
  135. + acpi_walk_dep_device_list(supplier->handle, acpi_scan_clear_dep, NULL);
  136. +}
  137. +EXPORT_SYMBOL_GPL(acpi_dev_clear_dependencies);
  138. +
  139. /**
  140. * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
  141. * @handle: Root of the namespace scope to scan.
  142. diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
  143. index 174839f3772f..51a2f568e371 100644
  144. --- a/drivers/gpio/gpiolib-acpi.c
  145. +++ b/drivers/gpio/gpiolib-acpi.c
  146. @@ -1233,14 +1233,14 @@ static void acpi_gpiochip_scan_gpios(struct acpi_gpio_chip *achip)
  147. void acpi_gpiochip_add(struct gpio_chip *chip)
  148. {
  149. struct acpi_gpio_chip *acpi_gpio;
  150. - acpi_handle handle;
  151. + struct acpi_device *adev;
  152. acpi_status status;
  153. if (!chip || !chip->parent)
  154. return;
  155. - handle = ACPI_HANDLE(chip->parent);
  156. - if (!handle)
  157. + adev = ACPI_COMPANION(chip->parent);
  158. + if (!adev)
  159. return;
  160. acpi_gpio = kzalloc(sizeof(*acpi_gpio), GFP_KERNEL);
  161. @@ -1254,7 +1254,7 @@ void acpi_gpiochip_add(struct gpio_chip *chip)
  162. INIT_LIST_HEAD(&acpi_gpio->events);
  163. INIT_LIST_HEAD(&acpi_gpio->deferred_req_irqs_list_entry);
  164. - status = acpi_attach_data(handle, acpi_gpio_chip_dh, acpi_gpio);
  165. + status = acpi_attach_data(adev->handle, acpi_gpio_chip_dh, acpi_gpio);
  166. if (ACPI_FAILURE(status)) {
  167. dev_err(chip->parent, "Failed to attach ACPI GPIO chip\n");
  168. kfree(acpi_gpio);
  169. @@ -1263,7 +1263,7 @@ void acpi_gpiochip_add(struct gpio_chip *chip)
  170. acpi_gpiochip_request_regions(acpi_gpio);
  171. acpi_gpiochip_scan_gpios(acpi_gpio);
  172. - acpi_walk_dep_device_list(handle);
  173. + acpi_dev_clear_dependencies(adev);
  174. }
  175. void acpi_gpiochip_remove(struct gpio_chip *chip)
  176. diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
  177. index deceed0d76c6..13eb5ac82729 100644
  178. --- a/drivers/i2c/i2c-core-acpi.c
  179. +++ b/drivers/i2c/i2c-core-acpi.c
  180. @@ -259,8 +259,8 @@ static acpi_status i2c_acpi_add_device(acpi_handle handle, u32 level,
  181. */
  182. void i2c_acpi_register_devices(struct i2c_adapter *adap)
  183. {
  184. + struct acpi_device *adev;
  185. acpi_status status;
  186. - acpi_handle handle;
  187. if (!has_acpi_companion(&adap->dev))
  188. return;
  189. @@ -275,11 +275,11 @@ void i2c_acpi_register_devices(struct i2c_adapter *adap)
  190. if (!adap->dev.parent)
  191. return;
  192. - handle = ACPI_HANDLE(adap->dev.parent);
  193. - if (!handle)
  194. + adev = ACPI_COMPANION(adap->dev.parent);
  195. + if (!adev)
  196. return;
  197. - acpi_walk_dep_device_list(handle);
  198. + acpi_dev_clear_dependencies(adev);
  199. }
  200. static const struct acpi_device_id i2c_acpi_force_400khz_device_ids[] = {
  201. diff --git a/drivers/platform/surface/aggregator/core.c b/drivers/platform/surface/aggregator/core.c
  202. index 5d780e55f4a1..279d9df19c01 100644
  203. --- a/drivers/platform/surface/aggregator/core.c
  204. +++ b/drivers/platform/surface/aggregator/core.c
  205. @@ -621,8 +621,8 @@ static const struct acpi_gpio_mapping ssam_acpi_gpios[] = {
  206. static int ssam_serial_hub_probe(struct serdev_device *serdev)
  207. {
  208. + struct acpi_device *ssh = ACPI_COMPANION(&serdev->dev);
  209. struct ssam_controller *ctrl;
  210. - acpi_handle *ssh = ACPI_HANDLE(&serdev->dev);
  211. acpi_status astatus;
  212. int status;
  213. @@ -652,7 +652,7 @@ static int ssam_serial_hub_probe(struct serdev_device *serdev)
  214. if (status)
  215. goto err_devopen;
  216. - astatus = ssam_serdev_setup_via_acpi(ssh, serdev);
  217. + astatus = ssam_serdev_setup_via_acpi(ssh->handle, serdev);
  218. if (ACPI_FAILURE(astatus)) {
  219. status = -ENXIO;
  220. goto err_devinit;
  221. @@ -706,7 +706,7 @@ static int ssam_serial_hub_probe(struct serdev_device *serdev)
  222. * For now let's thus default power/wakeup to false.
  223. */
  224. device_set_wakeup_capable(&serdev->dev, true);
  225. - acpi_walk_dep_device_list(ssh);
  226. + acpi_dev_clear_dependencies(ssh);
  227. return 0;
  228. diff --git a/drivers/platform/surface/surface3_power.c b/drivers/platform/surface/surface3_power.c
  229. index cc4f9cba6856..dea82aa1abd4 100644
  230. --- a/drivers/platform/surface/surface3_power.c
  231. +++ b/drivers/platform/surface/surface3_power.c
  232. @@ -446,12 +446,12 @@ mshw0011_space_handler(u32 function, acpi_physical_address command,
  233. static int mshw0011_install_space_handler(struct i2c_client *client)
  234. {
  235. - acpi_handle handle;
  236. + struct acpi_device *adev;
  237. struct mshw0011_handler_data *data;
  238. acpi_status status;
  239. - handle = ACPI_HANDLE(&client->dev);
  240. - if (!handle)
  241. + adev = ACPI_COMPANION(&client->dev);
  242. + if (!adev)
  243. return -ENODEV;
  244. data = kzalloc(sizeof(struct mshw0011_handler_data),
  245. @@ -460,25 +460,25 @@ static int mshw0011_install_space_handler(struct i2c_client *client)
  246. return -ENOMEM;
  247. data->client = client;
  248. - status = acpi_bus_attach_private_data(handle, (void *)data);
  249. + status = acpi_bus_attach_private_data(adev->handle, (void *)data);
  250. if (ACPI_FAILURE(status)) {
  251. kfree(data);
  252. return -ENOMEM;
  253. }
  254. - status = acpi_install_address_space_handler(handle,
  255. - ACPI_ADR_SPACE_GSBUS,
  256. - &mshw0011_space_handler,
  257. - NULL,
  258. - data);
  259. + status = acpi_install_address_space_handler(adev->handle,
  260. + ACPI_ADR_SPACE_GSBUS,
  261. + &mshw0011_space_handler,
  262. + NULL,
  263. + data);
  264. if (ACPI_FAILURE(status)) {
  265. dev_err(&client->dev, "Error installing i2c space handler\n");
  266. - acpi_bus_detach_private_data(handle);
  267. + acpi_bus_detach_private_data(adev->handle);
  268. kfree(data);
  269. return -ENOMEM;
  270. }
  271. - acpi_walk_dep_device_list(handle);
  272. + acpi_dev_clear_dependencies(adev);
  273. return 0;
  274. }
  275. diff --git a/drivers/platform/surface/surface_acpi_notify.c b/drivers/platform/surface/surface_acpi_notify.c
  276. index ef9c1f8e8336..8339988d95c1 100644
  277. --- a/drivers/platform/surface/surface_acpi_notify.c
  278. +++ b/drivers/platform/surface/surface_acpi_notify.c
  279. @@ -798,7 +798,7 @@ static int san_consumer_links_setup(struct platform_device *pdev)
  280. static int san_probe(struct platform_device *pdev)
  281. {
  282. - acpi_handle san = ACPI_HANDLE(&pdev->dev);
  283. + struct acpi_device *san = ACPI_COMPANION(&pdev->dev);
  284. struct ssam_controller *ctrl;
  285. struct san_data *data;
  286. acpi_status astatus;
  287. @@ -821,7 +821,8 @@ static int san_probe(struct platform_device *pdev)
  288. platform_set_drvdata(pdev, data);
  289. - astatus = acpi_install_address_space_handler(san, ACPI_ADR_SPACE_GSBUS,
  290. + astatus = acpi_install_address_space_handler(san->handle,
  291. + ACPI_ADR_SPACE_GSBUS,
  292. &san_opreg_handler, NULL,
  293. &data->info);
  294. if (ACPI_FAILURE(astatus))
  295. @@ -835,7 +836,7 @@ static int san_probe(struct platform_device *pdev)
  296. if (status)
  297. goto err_install_dev;
  298. - acpi_walk_dep_device_list(san);
  299. + acpi_dev_clear_dependencies(san);
  300. return 0;
  301. err_install_dev:
  302. diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
  303. index f28b097c658f..849f3540ed53 100644
  304. --- a/include/acpi/acpi_bus.h
  305. +++ b/include/acpi/acpi_bus.h
  306. @@ -279,6 +279,12 @@ struct acpi_device_power {
  307. struct acpi_device_power_state states[ACPI_D_STATE_COUNT]; /* Power states (D0-D3Cold) */
  308. };
  309. +struct acpi_dep_data {
  310. + struct list_head node;
  311. + acpi_handle supplier;
  312. + acpi_handle consumer;
  313. +};
  314. +
  315. /* Performance Management */
  316. struct acpi_device_perf_flags {
  317. @@ -684,6 +690,7 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
  318. bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
  319. +void acpi_dev_clear_dependencies(struct acpi_device *supplier);
  320. struct acpi_device *
  321. acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
  322. struct acpi_device *
  323. diff --git a/include/linux/acpi.h b/include/linux/acpi.h
  324. index 3bdcfc4401b7..c2da6b8939c0 100644
  325. --- a/include/linux/acpi.h
  326. +++ b/include/linux/acpi.h
  327. @@ -666,7 +666,9 @@ extern bool acpi_driver_match_device(struct device *dev,
  328. const struct device_driver *drv);
  329. int acpi_device_uevent_modalias(struct device *, struct kobj_uevent_env *);
  330. int acpi_device_modalias(struct device *, char *, int);
  331. -void acpi_walk_dep_device_list(acpi_handle handle);
  332. +int acpi_walk_dep_device_list(acpi_handle handle,
  333. + int (*callback)(struct acpi_dep_data *, void *),
  334. + void *data);
  335. struct platform_device *acpi_create_platform_device(struct acpi_device *,
  336. struct property_entry *);
  337. --
  338. 2.32.0
  339. From 6d7e1348614f069b0ab99b75968c47c5492d039a Mon Sep 17 00:00:00 2001
  340. From: Daniel Scally <djrscally@gmail.com>
  341. Date: Thu, 20 May 2021 15:09:22 +0100
  342. Subject: [PATCH] ACPI: scan: Add function to fetch dependent of acpi device
  343. In some ACPI tables we encounter, devices use the _DEP method to assert
  344. a dependence on other ACPI devices as opposed to the OpRegions that the
  345. specification intends. We need to be able to find those devices "from"
  346. the dependee, so add a callback and a wrapper to walk over the
  347. acpi_dep_list and return the dependent ACPI device.
  348. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
  349. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  350. Patchset: cameras
  351. ---
  352. drivers/acpi/scan.c | 38 ++++++++++++++++++++++++++++++++++++++
  353. include/acpi/acpi_bus.h | 1 +
  354. 2 files changed, 39 insertions(+)
  355. diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
  356. index f5440729ffe9..4fcc7c95af78 100644
  357. --- a/drivers/acpi/scan.c
  358. +++ b/drivers/acpi/scan.c
  359. @@ -2136,6 +2136,21 @@ static void acpi_bus_attach(struct acpi_device *device, bool first_pass)
  360. device->handler->hotplug.notify_online(device);
  361. }
  362. +static int acpi_return_dep_dev(struct acpi_dep_data *dep, void *data)
  363. +{
  364. + struct acpi_device *adev;
  365. + int ret;
  366. +
  367. + ret = acpi_bus_get_device(dep->consumer, &adev);
  368. + if (ret)
  369. + /* If we don't find an adev then we want to continue parsing */
  370. + return 0;
  371. +
  372. + *(struct acpi_device **)data = adev;
  373. +
  374. + return 1;
  375. +}
  376. +
  377. static int acpi_scan_clear_dep(struct acpi_dep_data *dep, void *data)
  378. {
  379. struct acpi_device *adev;
  380. @@ -2199,6 +2214,29 @@ void acpi_dev_clear_dependencies(struct acpi_device *supplier)
  381. }
  382. EXPORT_SYMBOL_GPL(acpi_dev_clear_dependencies);
  383. +/**
  384. + * acpi_dev_get_dependent_dev - Return ACPI device dependent on @supplier
  385. + * @supplier: Pointer to the dependee device
  386. + *
  387. + * Returns the first &struct acpi_device which declares itself dependent on
  388. + * @supplier via the _DEP buffer, parsed from the acpi_dep_list.
  389. + *
  390. + * The caller is responsible for putting the reference to adev when it is no
  391. + * longer needed.
  392. + */
  393. +struct acpi_device *acpi_dev_get_dependent_dev(struct acpi_device *supplier)
  394. +{
  395. + struct acpi_device *adev = NULL;
  396. +
  397. + acpi_walk_dep_device_list(supplier->handle, acpi_return_dep_dev, &adev);
  398. +
  399. + if (adev)
  400. + get_device(&adev->dev);
  401. +
  402. + return adev;
  403. +}
  404. +EXPORT_SYMBOL_GPL(acpi_dev_get_dependent_dev);
  405. +
  406. /**
  407. * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
  408. * @handle: Root of the namespace scope to scan.
  409. diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
  410. index 849f3540ed53..b531750eb422 100644
  411. --- a/include/acpi/acpi_bus.h
  412. +++ b/include/acpi/acpi_bus.h
  413. @@ -691,6 +691,7 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
  414. bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
  415. void acpi_dev_clear_dependencies(struct acpi_device *supplier);
  416. +struct acpi_device *acpi_dev_get_dependent_dev(struct acpi_device *supplier);
  417. struct acpi_device *
  418. acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
  419. struct acpi_device *
  420. --
  421. 2.32.0
  422. From 43b6ae71e7425322c1fdf35bc1a126e045264581 Mon Sep 17 00:00:00 2001
  423. From: Daniel Scally <djrscally@gmail.com>
  424. Date: Thu, 20 May 2021 15:09:23 +0100
  425. Subject: [PATCH] i2c: core: Add a format macro for I2C device names
  426. Some places in the kernel allow users to map resources to a device
  427. using device name (for example, in the struct gpiod_lookup_table).
  428. Currently this involves waiting for the I2C client to have been registered
  429. so we can use dev_name(&client->dev). We want to add a function to allow
  430. users to refer to an I2C device by name before it has been instantiated,
  431. so create a macro for the format that's accessible outside the I2C layer
  432. and use it in i2c_dev_set_name().
  433. Acked-by: Wolfram Sang <wsa@kernel.org>
  434. Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  435. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  436. Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
  437. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  438. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  439. Patchset: cameras
  440. ---
  441. drivers/i2c/i2c-core-base.c | 4 ++--
  442. include/linux/i2c.h | 3 +++
  443. 2 files changed, 5 insertions(+), 2 deletions(-)
  444. diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
  445. index f21362355973..e2cf16f27d65 100644
  446. --- a/drivers/i2c/i2c-core-base.c
  447. +++ b/drivers/i2c/i2c-core-base.c
  448. @@ -812,12 +812,12 @@ static void i2c_dev_set_name(struct i2c_adapter *adap,
  449. struct acpi_device *adev = ACPI_COMPANION(&client->dev);
  450. if (info && info->dev_name) {
  451. - dev_set_name(&client->dev, "i2c-%s", info->dev_name);
  452. + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, info->dev_name);
  453. return;
  454. }
  455. if (adev) {
  456. - dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev));
  457. + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));
  458. return;
  459. }
  460. diff --git a/include/linux/i2c.h b/include/linux/i2c.h
  461. index a670ae129f4b..a2f6ee71b5be 100644
  462. --- a/include/linux/i2c.h
  463. +++ b/include/linux/i2c.h
  464. @@ -39,6 +39,9 @@ enum i2c_slave_event;
  465. typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
  466. enum i2c_slave_event event, u8 *val);
  467. +/* I2C Device Name Format - to maintain consistency outside the i2c layer */
  468. +#define I2C_DEV_NAME_FORMAT "i2c-%s"
  469. +
  470. /* I2C Frequency Modes */
  471. #define I2C_MAX_STANDARD_MODE_FREQ 100000
  472. #define I2C_MAX_FAST_MODE_FREQ 400000
  473. --
  474. 2.32.0
  475. From 194dd795351f3cd31c9a1518214ac61d26c6bc16 Mon Sep 17 00:00:00 2001
  476. From: Daniel Scally <djrscally@gmail.com>
  477. Date: Thu, 20 May 2021 15:09:24 +0100
  478. Subject: [PATCH] gpiolib: acpi: Export acpi_get_gpiod()
  479. We need to be able to translate GPIO resources in an ACPI device's _CRS
  480. into GPIO descriptor array. Those are represented in _CRS as a pathname
  481. to a GPIO device plus the pin's index number: the acpi_get_gpiod()
  482. function is perfect for that purpose.
  483. As it's currently only used internally within the GPIO layer, provide and
  484. export a wrapper function that additionally holds a reference to the GPIO
  485. device.
  486. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
  487. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  488. Patchset: cameras
  489. ---
  490. drivers/gpio/gpiolib-acpi.c | 28 ++++++++++++++++++++++++++++
  491. include/linux/gpio/consumer.h | 2 ++
  492. 2 files changed, 30 insertions(+)
  493. diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
  494. index 51a2f568e371..24432a1e8437 100644
  495. --- a/drivers/gpio/gpiolib-acpi.c
  496. +++ b/drivers/gpio/gpiolib-acpi.c
  497. @@ -128,6 +128,34 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
  498. return gpiochip_get_desc(chip, pin);
  499. }
  500. +/**
  501. + * acpi_get_and_request_gpiod() - Translate ACPI GPIO pin to GPIO descriptor
  502. + * and hold a refcount to the GPIO device.
  503. + * @path: ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1")
  504. + * @pin: ACPI GPIO pin number (0-based, controller-relative)
  505. + * @label: Label to pass to gpiod_request()
  506. + *
  507. + * This function is a simple pass-through to acpi_get_gpiod(), except that
  508. + * as it is intended for use outside of the GPIO layer (in a similar fashion to
  509. + * gpiod_get_index() for example) it also holds a reference to the GPIO device.
  510. + */
  511. +struct gpio_desc *acpi_get_and_request_gpiod(char *path, int pin, char *label)
  512. +{
  513. + struct gpio_desc *gpio;
  514. + int ret;
  515. +
  516. + gpio = acpi_get_gpiod(path, pin);
  517. + if (IS_ERR(gpio))
  518. + return gpio;
  519. +
  520. + ret = gpiod_request(gpio, label);
  521. + if (ret)
  522. + return ERR_PTR(ret);
  523. +
  524. + return gpio;
  525. +}
  526. +EXPORT_SYMBOL_GPL(acpi_get_and_request_gpiod);
  527. +
  528. static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
  529. {
  530. struct acpi_gpio_event *event = data;
  531. diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
  532. index c73b25bc9213..566feb56601f 100644
  533. --- a/include/linux/gpio/consumer.h
  534. +++ b/include/linux/gpio/consumer.h
  535. @@ -692,6 +692,8 @@ int devm_acpi_dev_add_driver_gpios(struct device *dev,
  536. const struct acpi_gpio_mapping *gpios);
  537. void devm_acpi_dev_remove_driver_gpios(struct device *dev);
  538. +struct gpio_desc *acpi_get_and_request_gpiod(char *path, int pin, char *label);
  539. +
  540. #else /* CONFIG_GPIOLIB && CONFIG_ACPI */
  541. struct acpi_device;
  542. --
  543. 2.32.0
  544. From d221d01156abe159f00c2756327859e4b091f125 Mon Sep 17 00:00:00 2001
  545. From: Daniel Scally <djrscally@gmail.com>
  546. Date: Thu, 20 May 2021 15:09:25 +0100
  547. Subject: [PATCH] clkdev: Make clkdev_drop() null aware
  548. To simplify error handling paths, many functions are no-ops when passed
  549. NULL pointers, for example gpiod_remove_lookup_table(). Mirror that
  550. behaviour for clkdev_drop().
  551. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  552. Patchset: cameras
  553. ---
  554. drivers/clk/clkdev.c | 3 +++
  555. 1 file changed, 3 insertions(+)
  556. diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
  557. index 0f2e3fcf0f19..c082720f8ade 100644
  558. --- a/drivers/clk/clkdev.c
  559. +++ b/drivers/clk/clkdev.c
  560. @@ -286,6 +286,9 @@ EXPORT_SYMBOL(clk_add_alias);
  561. */
  562. void clkdev_drop(struct clk_lookup *cl)
  563. {
  564. + if (!cl)
  565. + return;
  566. +
  567. mutex_lock(&clocks_mutex);
  568. list_del(&cl->node);
  569. mutex_unlock(&clocks_mutex);
  570. --
  571. 2.32.0
  572. From 1292bbbf83ab916bee76c5ce12bb6745a39dd9fe Mon Sep 17 00:00:00 2001
  573. From: Daniel Scally <djrscally@gmail.com>
  574. Date: Thu, 20 May 2021 15:09:26 +0100
  575. Subject: [PATCH] gpiolib: acpi: Add acpi_gpio_get_io_resource()
  576. Add a function to verify that a given acpi_resource represents an IO
  577. type GPIO resource, and return it if so.
  578. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  579. Patchset: cameras
  580. ---
  581. drivers/gpio/gpiolib-acpi.c | 23 +++++++++++++++++++++++
  582. include/linux/acpi.h | 7 +++++++
  583. 2 files changed, 30 insertions(+)
  584. diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
  585. index 24432a1e8437..f17bd347bd05 100644
  586. --- a/drivers/gpio/gpiolib-acpi.c
  587. +++ b/drivers/gpio/gpiolib-acpi.c
  588. @@ -196,6 +196,29 @@ bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
  589. }
  590. EXPORT_SYMBOL_GPL(acpi_gpio_get_irq_resource);
  591. +/**
  592. + * acpi_gpio_get_io_resource - Fetch details of an ACPI resource if it is a GPIO
  593. + * I/O resource or return False if not.
  594. + * @ares: Pointer to the ACPI resource to fetch
  595. + * @agpio: Pointer to a &struct acpi_resource_gpio to store the output pointer
  596. + */
  597. +bool acpi_gpio_get_io_resource(struct acpi_resource *ares,
  598. + struct acpi_resource_gpio **agpio)
  599. +{
  600. + struct acpi_resource_gpio *gpio;
  601. +
  602. + if (ares->type != ACPI_RESOURCE_TYPE_GPIO)
  603. + return false;
  604. +
  605. + gpio = &ares->data.gpio;
  606. + if (gpio->connection_type != ACPI_RESOURCE_GPIO_TYPE_IO)
  607. + return false;
  608. +
  609. + *agpio = gpio;
  610. + return true;
  611. +}
  612. +EXPORT_SYMBOL_GPL(acpi_gpio_get_io_resource);
  613. +
  614. static void acpi_gpiochip_request_irq(struct acpi_gpio_chip *acpi_gpio,
  615. struct acpi_gpio_event *event)
  616. {
  617. diff --git a/include/linux/acpi.h b/include/linux/acpi.h
  618. index c2da6b8939c0..07a0044397e1 100644
  619. --- a/include/linux/acpi.h
  620. +++ b/include/linux/acpi.h
  621. @@ -1088,6 +1088,8 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c
  622. #if defined(CONFIG_ACPI) && defined(CONFIG_GPIOLIB)
  623. bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
  624. struct acpi_resource_gpio **agpio);
  625. +bool acpi_gpio_get_io_resource(struct acpi_resource *ares,
  626. + struct acpi_resource_gpio **agpio);
  627. int acpi_dev_gpio_irq_get_by(struct acpi_device *adev, const char *name, int index);
  628. #else
  629. static inline bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
  630. @@ -1095,6 +1097,11 @@ static inline bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
  631. {
  632. return false;
  633. }
  634. +static inline bool acpi_gpio_get_io_resource(struct acpi_resource *ares,
  635. + struct acpi_resource_gpio **agpio)
  636. +{
  637. + return false;
  638. +}
  639. static inline int acpi_dev_gpio_irq_get_by(struct acpi_device *adev,
  640. const char *name, int index)
  641. {
  642. --
  643. 2.32.0
  644. From 910cf531bc23323813cba36f9aaaf5f894ab640c Mon Sep 17 00:00:00 2001
  645. From: Daniel Scally <djrscally@gmail.com>
  646. Date: Thu, 20 May 2021 15:09:27 +0100
  647. Subject: [PATCH] platform/x86: Add intel_skl_int3472 driver
  648. ACPI devices with _HID INT3472 are currently matched to the tps68470
  649. driver, however this does not cover all situations in which that _HID
  650. occurs. We've encountered three possibilities:
  651. 1. On Chrome OS devices, an ACPI device with _HID INT3472 (representing
  652. a physical TPS68470 device) that requires a GPIO and OpRegion driver
  653. 2. On devices designed for Windows, an ACPI device with _HID INT3472
  654. (again representing a physical TPS68470 device) which requires GPIO,
  655. Clock and Regulator drivers.
  656. 3. On other devices designed for Windows, an ACPI device with _HID
  657. INT3472 which does **not** represent a physical TPS68470, and is instead
  658. used as a dummy device to group some system GPIO lines which are meant
  659. to be consumed by the sensor that is dependent on this entry.
  660. This commit adds a new module, registering a platform driver to deal
  661. with the 3rd scenario plus an i2c driver to deal with #1 and #2, by
  662. querying the CLDB buffer found against INT3472 entries to determine
  663. which is most appropriate.
  664. Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  665. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  666. Patchset: cameras
  667. ---
  668. MAINTAINERS | 5 +
  669. drivers/platform/x86/Kconfig | 2 +
  670. drivers/platform/x86/Makefile | 1 +
  671. drivers/platform/x86/intel-int3472/Kconfig | 31 ++
  672. drivers/platform/x86/intel-int3472/Makefile | 5 +
  673. .../intel_skl_int3472_clk_and_regulator.c | 195 +++++++++
  674. .../intel-int3472/intel_skl_int3472_common.c | 106 +++++
  675. .../intel-int3472/intel_skl_int3472_common.h | 113 +++++
  676. .../intel_skl_int3472_discrete.c | 409 ++++++++++++++++++
  677. .../intel_skl_int3472_tps68470.c | 109 +++++
  678. 10 files changed, 976 insertions(+)
  679. create mode 100644 drivers/platform/x86/intel-int3472/Kconfig
  680. create mode 100644 drivers/platform/x86/intel-int3472/Makefile
  681. create mode 100644 drivers/platform/x86/intel-int3472/intel_skl_int3472_clk_and_regulator.c
  682. create mode 100644 drivers/platform/x86/intel-int3472/intel_skl_int3472_common.c
  683. create mode 100644 drivers/platform/x86/intel-int3472/intel_skl_int3472_common.h
  684. create mode 100644 drivers/platform/x86/intel-int3472/intel_skl_int3472_discrete.c
  685. create mode 100644 drivers/platform/x86/intel-int3472/intel_skl_int3472_tps68470.c
  686. diff --git a/MAINTAINERS b/MAINTAINERS
  687. index 710617e26f3e..2a421d2e4b07 100644
  688. --- a/MAINTAINERS
  689. +++ b/MAINTAINERS
  690. @@ -9191,6 +9191,11 @@ S: Maintained
  691. F: arch/x86/include/asm/intel_scu_ipc.h
  692. F: drivers/platform/x86/intel_scu_*
  693. +INTEL SKYLAKE INT3472 ACPI DEVICE DRIVER
  694. +M: Daniel Scally <djrscally@gmail.com>
  695. +S: Maintained
  696. +F: drivers/platform/x86/intel-int3472/intel_skl_int3472_*
  697. +
  698. INTEL SPEED SELECT TECHNOLOGY
  699. M: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
  700. L: platform-driver-x86@vger.kernel.org
  701. diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
  702. index 205a096e9cee..254056a353b2 100644
  703. --- a/drivers/platform/x86/Kconfig
  704. +++ b/drivers/platform/x86/Kconfig
  705. @@ -674,6 +674,8 @@ config INTEL_CHT_INT33FE
  706. device and CONFIG_TYPEC_FUSB302=m and CONFIG_BATTERY_MAX17042=m
  707. for Type-C device.
  708. +source "drivers/platform/x86/intel-int3472/Kconfig"
  709. +
  710. config INTEL_HID_EVENT
  711. tristate "INTEL HID Event"
  712. depends on ACPI
  713. diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
  714. index 60d554073749..4cbcff47a571 100644
  715. --- a/drivers/platform/x86/Makefile
  716. +++ b/drivers/platform/x86/Makefile
  717. @@ -72,6 +72,7 @@ obj-$(CONFIG_INTEL_HID_EVENT) += intel-hid.o
  718. obj-$(CONFIG_INTEL_INT0002_VGPIO) += intel_int0002_vgpio.o
  719. obj-$(CONFIG_INTEL_MENLOW) += intel_menlow.o
  720. obj-$(CONFIG_INTEL_OAKTRAIL) += intel_oaktrail.o
  721. +obj-$(CONFIG_INTEL_SKL_INT3472) += intel-int3472/
  722. obj-$(CONFIG_INTEL_VBTN) += intel-vbtn.o
  723. # MSI
  724. diff --git a/drivers/platform/x86/intel-int3472/Kconfig b/drivers/platform/x86/intel-int3472/Kconfig
  725. new file mode 100644
  726. index 000000000000..f0fd0df65e4d
  727. --- /dev/null
  728. +++ b/drivers/platform/x86/intel-int3472/Kconfig
  729. @@ -0,0 +1,31 @@
  730. +config INTEL_SKL_INT3472
  731. + tristate "Intel SkyLake ACPI INT3472 Driver"
  732. + depends on ACPI
  733. + depends on COMMON_CLK && CLKDEV_LOOKUP
  734. + depends on I2C
  735. + depends on GPIOLIB
  736. + depends on REGULATOR
  737. + select MFD_CORE
  738. + select REGMAP_I2C
  739. + help
  740. + This driver adds support for the INT3472 ACPI devices found on some
  741. + Intel SkyLake devices.
  742. +
  743. + The INT3472 is an Intel camera power controller, a logical device
  744. + found on some Skylake-based systems that can map to different
  745. + hardware devices depending on the platform. On machines
  746. + designed for Chrome OS, it maps to a TPS68470 camera PMIC. On
  747. + machines designed for Windows, it maps to either a TP68470
  748. + camera PMIC, a uP6641Q sensor PMIC, or a set of discrete GPIOs
  749. + and power gates.
  750. +
  751. + If your device was designed for Chrome OS, this driver will provide
  752. + an ACPI OpRegion, which must be available before any of the devices
  753. + using it are probed. For this reason, you should select Y if your
  754. + device was designed for ChromeOS. For the same reason the
  755. + I2C_DESIGNWARE_PLATFORM option must be set to Y too.
  756. +
  757. + Say Y or M here if you have a SkyLake device designed for use
  758. + with Windows or ChromeOS. Say N here if you are not sure.
  759. +
  760. + The module will be named "intel-skl-int3472"
  761. diff --git a/drivers/platform/x86/intel-int3472/Makefile b/drivers/platform/x86/intel-int3472/Makefile
  762. new file mode 100644
  763. index 000000000000..48bd97f0a04e
  764. --- /dev/null
  765. +++ b/drivers/platform/x86/intel-int3472/Makefile
  766. @@ -0,0 +1,5 @@
  767. +obj-$(CONFIG_INTEL_SKL_INT3472) += intel_skl_int3472.o
  768. +intel_skl_int3472-objs := intel_skl_int3472_common.o \
  769. + intel_skl_int3472_discrete.o \
  770. + intel_skl_int3472_tps68470.o \
  771. + intel_skl_int3472_clk_and_regulator.o
  772. diff --git a/drivers/platform/x86/intel-int3472/intel_skl_int3472_clk_and_regulator.c b/drivers/platform/x86/intel-int3472/intel_skl_int3472_clk_and_regulator.c
  773. new file mode 100644
  774. index 000000000000..82b95f753549
  775. --- /dev/null
  776. +++ b/drivers/platform/x86/intel-int3472/intel_skl_int3472_clk_and_regulator.c
  777. @@ -0,0 +1,195 @@
  778. +// SPDX-License-Identifier: GPL-2.0
  779. +/* Author: Dan Scally <djrscally@gmail.com> */
  780. +
  781. +#include <linux/acpi.h>
  782. +#include <linux/clkdev.h>
  783. +#include <linux/clk-provider.h>
  784. +#include <linux/device.h>
  785. +#include <linux/gpio/consumer.h>
  786. +#include <linux/regulator/driver.h>
  787. +#include <linux/slab.h>
  788. +
  789. +#include "intel_skl_int3472_common.h"
  790. +
  791. +/*
  792. + * The regulators have to have .ops to be valid, but the only ops we actually
  793. + * support are .enable and .disable which are handled via .ena_gpiod. Pass an
  794. + * empty struct to clear the check without lying about capabilities.
  795. + */
  796. +static const struct regulator_ops int3472_gpio_regulator_ops;
  797. +
  798. +static int skl_int3472_clk_prepare(struct clk_hw *hw)
  799. +{
  800. + struct int3472_gpio_clock *clk = to_int3472_clk(hw);
  801. +
  802. + gpiod_set_value(clk->ena_gpio, 1);
  803. + gpiod_set_value(clk->led_gpio, 1);
  804. +
  805. + return 0;
  806. +}
  807. +
  808. +static void skl_int3472_clk_unprepare(struct clk_hw *hw)
  809. +{
  810. + struct int3472_gpio_clock *clk = to_int3472_clk(hw);
  811. +
  812. + gpiod_set_value(clk->ena_gpio, 0);
  813. + gpiod_set_value(clk->led_gpio, 0);
  814. +}
  815. +
  816. +static int skl_int3472_clk_enable(struct clk_hw *hw)
  817. +{
  818. + /*
  819. + * We're just turning a GPIO on to enable the clock, which operation
  820. + * has the potential to sleep. Given .enable() cannot sleep, but
  821. + * .prepare() can, we toggle the GPIO in .prepare() instead. Thus,
  822. + * nothing to do here.
  823. + */
  824. + return 0;
  825. +}
  826. +
  827. +static void skl_int3472_clk_disable(struct clk_hw *hw)
  828. +{
  829. + /* Likewise, nothing to do here... */
  830. +}
  831. +
  832. +static unsigned int skl_int3472_get_clk_frequency(struct int3472_discrete_device *int3472)
  833. +{
  834. + union acpi_object *obj;
  835. + unsigned int freq;
  836. +
  837. + obj = skl_int3472_get_acpi_buffer(int3472->sensor, "SSDB");
  838. + if (IS_ERR(obj))
  839. + return 0; /* report rate as 0 on error */
  840. +
  841. + if (obj->buffer.length < CIO2_SENSOR_SSDB_MCLKSPEED_OFFSET + sizeof(u32)) {
  842. + dev_err(int3472->dev, "The buffer is too small\n");
  843. + goto out_free_buff;
  844. + }
  845. +
  846. + freq = *(u32 *)(obj->buffer.pointer + CIO2_SENSOR_SSDB_MCLKSPEED_OFFSET);
  847. +
  848. +out_free_buff:
  849. + kfree(obj);
  850. + return freq;
  851. +}
  852. +
  853. +static unsigned long skl_int3472_clk_recalc_rate(struct clk_hw *hw,
  854. + unsigned long parent_rate)
  855. +{
  856. + struct int3472_gpio_clock *clk = to_int3472_clk(hw);
  857. +
  858. + return clk->frequency;
  859. +}
  860. +
  861. +static const struct clk_ops skl_int3472_clock_ops = {
  862. + .prepare = skl_int3472_clk_prepare,
  863. + .unprepare = skl_int3472_clk_unprepare,
  864. + .enable = skl_int3472_clk_enable,
  865. + .disable = skl_int3472_clk_disable,
  866. + .recalc_rate = skl_int3472_clk_recalc_rate,
  867. +};
  868. +
  869. +int skl_int3472_register_clock(struct int3472_discrete_device *int3472)
  870. +{
  871. + struct clk_init_data init = {
  872. + .ops = &skl_int3472_clock_ops,
  873. + .flags = CLK_GET_RATE_NOCACHE,
  874. + };
  875. + int ret = 0;
  876. +
  877. + init.name = kasprintf(GFP_KERNEL, "%s-clk",
  878. + acpi_dev_name(int3472->adev));
  879. + if (!init.name)
  880. + return -ENOMEM;
  881. +
  882. + int3472->clock.frequency = skl_int3472_get_clk_frequency(int3472);
  883. +
  884. + int3472->clock.clk_hw.init = &init;
  885. + int3472->clock.clk = clk_register(&int3472->adev->dev,
  886. + &int3472->clock.clk_hw);
  887. + if (IS_ERR(int3472->clock.clk)) {
  888. + ret = PTR_ERR(int3472->clock.clk);
  889. + goto out_free_init_name;
  890. + }
  891. +
  892. + int3472->clock.cl = clkdev_create(int3472->clock.clk, NULL,
  893. + int3472->sensor_name);
  894. + if (!int3472->clock.cl) {
  895. + ret = -ENOMEM;
  896. + goto err_unregister_clk;
  897. + }
  898. +
  899. + goto out_free_init_name;
  900. +
  901. +err_unregister_clk:
  902. + clk_unregister(int3472->clock.clk);
  903. +out_free_init_name:
  904. + kfree(init.name);
  905. +
  906. + return ret;
  907. +}
  908. +
  909. +int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
  910. + struct acpi_resource *ares)
  911. +{
  912. + char *path = ares->data.gpio.resource_source.string_ptr;
  913. + const struct int3472_sensor_config *sensor_config;
  914. + struct regulator_consumer_supply supply_map;
  915. + struct regulator_init_data init_data = { };
  916. + struct regulator_config cfg = { };
  917. + int ret;
  918. +
  919. + sensor_config = int3472->sensor_config;
  920. + if (IS_ERR(sensor_config)) {
  921. + dev_err(int3472->dev, "No sensor module config\n");
  922. + return PTR_ERR(sensor_config);
  923. + }
  924. +
  925. + if (!sensor_config->supply_map.supply) {
  926. + dev_err(int3472->dev, "No supply name defined\n");
  927. + return -ENODEV;
  928. + }
  929. +
  930. + init_data.constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS;
  931. + init_data.num_consumer_supplies = 1;
  932. + supply_map = sensor_config->supply_map;
  933. + supply_map.dev_name = int3472->sensor_name;
  934. + init_data.consumer_supplies = &supply_map;
  935. +
  936. + snprintf(int3472->regulator.regulator_name,
  937. + sizeof(int3472->regulator.regulator_name), "%s-regulator",
  938. + acpi_dev_name(int3472->adev));
  939. + snprintf(int3472->regulator.supply_name,
  940. + GPIO_REGULATOR_SUPPLY_NAME_LENGTH, "supply-0");
  941. +
  942. + int3472->regulator.rdesc = INT3472_REGULATOR(
  943. + int3472->regulator.regulator_name,
  944. + int3472->regulator.supply_name,
  945. + &int3472_gpio_regulator_ops);
  946. +
  947. + int3472->regulator.gpio = acpi_get_and_request_gpiod(path,
  948. + ares->data.gpio.pin_table[0],
  949. + "int3472,regulator");
  950. + if (IS_ERR(int3472->regulator.gpio)) {
  951. + dev_err(int3472->dev, "Failed to get regulator GPIO line\n");
  952. + return PTR_ERR(int3472->regulator.gpio);
  953. + }
  954. +
  955. + cfg.dev = &int3472->adev->dev;
  956. + cfg.init_data = &init_data;
  957. + cfg.ena_gpiod = int3472->regulator.gpio;
  958. +
  959. + int3472->regulator.rdev = regulator_register(&int3472->regulator.rdesc,
  960. + &cfg);
  961. + if (IS_ERR(int3472->regulator.rdev)) {
  962. + ret = PTR_ERR(int3472->regulator.rdev);
  963. + goto err_free_gpio;
  964. + }
  965. +
  966. + return 0;
  967. +
  968. +err_free_gpio:
  969. + gpiod_put(int3472->regulator.gpio);
  970. +
  971. + return ret;
  972. +}
  973. diff --git a/drivers/platform/x86/intel-int3472/intel_skl_int3472_common.c b/drivers/platform/x86/intel-int3472/intel_skl_int3472_common.c
  974. new file mode 100644
  975. index 000000000000..8712ef9d8f59
  976. --- /dev/null
  977. +++ b/drivers/platform/x86/intel-int3472/intel_skl_int3472_common.c
  978. @@ -0,0 +1,106 @@
  979. +// SPDX-License-Identifier: GPL-2.0
  980. +/* Author: Dan Scally <djrscally@gmail.com> */
  981. +
  982. +#include <linux/acpi.h>
  983. +#include <linux/i2c.h>
  984. +#include <linux/platform_device.h>
  985. +#include <linux/slab.h>
  986. +
  987. +#include "intel_skl_int3472_common.h"
  988. +
  989. +union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev,
  990. + char *id)
  991. +{
  992. + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  993. + acpi_handle handle = adev->handle;
  994. + union acpi_object *obj;
  995. + acpi_status status;
  996. +
  997. + status = acpi_evaluate_object(handle, id, NULL, &buffer);
  998. + if (ACPI_FAILURE(status))
  999. + return ERR_PTR(-ENODEV);
  1000. +
  1001. + obj = buffer.pointer;
  1002. + if (!obj)
  1003. + return ERR_PTR(-ENODEV);
  1004. +
  1005. + if (obj->type != ACPI_TYPE_BUFFER) {
  1006. + acpi_handle_err(handle, "%s object is not an ACPI buffer\n", id);
  1007. + kfree(obj);
  1008. + return ERR_PTR(-EINVAL);
  1009. + }
  1010. +
  1011. + return obj;
  1012. +}
  1013. +
  1014. +int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb)
  1015. +{
  1016. + union acpi_object *obj;
  1017. + int ret = 0;
  1018. +
  1019. + obj = skl_int3472_get_acpi_buffer(adev, "CLDB");
  1020. + if (IS_ERR(obj))
  1021. + return PTR_ERR(obj);
  1022. +
  1023. + if (obj->buffer.length > sizeof(*cldb)) {
  1024. + acpi_handle_err(adev->handle, "The CLDB buffer is too large\n");
  1025. + ret = -EINVAL;
  1026. + goto out_free_obj;
  1027. + }
  1028. +
  1029. + memcpy(cldb, obj->buffer.pointer, obj->buffer.length);
  1030. +
  1031. +out_free_obj:
  1032. + kfree(obj);
  1033. + return ret;
  1034. +}
  1035. +
  1036. +static const struct acpi_device_id int3472_device_id[] = {
  1037. + { "INT3472", 0 },
  1038. + { }
  1039. +};
  1040. +MODULE_DEVICE_TABLE(acpi, int3472_device_id);
  1041. +
  1042. +static struct platform_driver int3472_discrete = {
  1043. + .driver = {
  1044. + .name = "int3472-discrete",
  1045. + .acpi_match_table = int3472_device_id,
  1046. + },
  1047. + .probe = skl_int3472_discrete_probe,
  1048. + .remove = skl_int3472_discrete_remove,
  1049. +};
  1050. +
  1051. +static struct i2c_driver int3472_tps68470 = {
  1052. + .driver = {
  1053. + .name = "int3472-tps68470",
  1054. + .acpi_match_table = int3472_device_id,
  1055. + },
  1056. + .probe_new = skl_int3472_tps68470_probe,
  1057. +};
  1058. +
  1059. +static int skl_int3472_init(void)
  1060. +{
  1061. + int ret;
  1062. +
  1063. + ret = platform_driver_register(&int3472_discrete);
  1064. + if (ret)
  1065. + return ret;
  1066. +
  1067. + ret = i2c_register_driver(THIS_MODULE, &int3472_tps68470);
  1068. + if (ret)
  1069. + platform_driver_unregister(&int3472_discrete);
  1070. +
  1071. + return ret;
  1072. +}
  1073. +module_init(skl_int3472_init);
  1074. +
  1075. +static void skl_int3472_exit(void)
  1076. +{
  1077. + platform_driver_unregister(&int3472_discrete);
  1078. + i2c_del_driver(&int3472_tps68470);
  1079. +}
  1080. +module_exit(skl_int3472_exit);
  1081. +
  1082. +MODULE_DESCRIPTION("Intel SkyLake INT3472 ACPI Device Driver");
  1083. +MODULE_AUTHOR("Daniel Scally <djrscally@gmail.com>");
  1084. +MODULE_LICENSE("GPL v2");
  1085. diff --git a/drivers/platform/x86/intel-int3472/intel_skl_int3472_common.h b/drivers/platform/x86/intel-int3472/intel_skl_int3472_common.h
  1086. new file mode 100644
  1087. index 000000000000..4c923d15e3b1
  1088. --- /dev/null
  1089. +++ b/drivers/platform/x86/intel-int3472/intel_skl_int3472_common.h
  1090. @@ -0,0 +1,113 @@
  1091. +/* SPDX-License-Identifier: GPL-2.0 */
  1092. +/* Author: Dan Scally <djrscally@gmail.com> */
  1093. +
  1094. +#ifndef _INTEL_SKL_INT3472_H
  1095. +#define _INTEL_SKL_INT3472_H
  1096. +
  1097. +#include <linux/clk-provider.h>
  1098. +#include <linux/gpio/machine.h>
  1099. +#include <linux/regulator/driver.h>
  1100. +#include <linux/regulator/machine.h>
  1101. +#include <linux/types.h>
  1102. +
  1103. +/* PMIC GPIO Types */
  1104. +#define INT3472_GPIO_TYPE_RESET 0x00
  1105. +#define INT3472_GPIO_TYPE_POWERDOWN 0x01
  1106. +#define INT3472_GPIO_TYPE_POWER_ENABLE 0x0b
  1107. +#define INT3472_GPIO_TYPE_CLK_ENABLE 0x0c
  1108. +#define INT3472_GPIO_TYPE_PRIVACY_LED 0x0d
  1109. +
  1110. +#define INT3472_PDEV_MAX_NAME_LEN 23
  1111. +#define INT3472_MAX_SENSOR_GPIOS 3
  1112. +
  1113. +#define GPIO_REGULATOR_NAME_LENGTH 21
  1114. +#define GPIO_REGULATOR_SUPPLY_NAME_LENGTH 9
  1115. +
  1116. +#define CIO2_SENSOR_SSDB_MCLKSPEED_OFFSET 86
  1117. +
  1118. +#define INT3472_REGULATOR(_name, _supply, _ops) \
  1119. + (const struct regulator_desc) { \
  1120. + .name = _name, \
  1121. + .supply_name = _supply, \
  1122. + .type = REGULATOR_VOLTAGE, \
  1123. + .ops = _ops, \
  1124. + .owner = THIS_MODULE, \
  1125. + }
  1126. +
  1127. +#define to_int3472_clk(hw) \
  1128. + container_of(hw, struct int3472_gpio_clock, clk_hw)
  1129. +
  1130. +#define to_int3472_device(clk) \
  1131. + container_of(clk, struct int3472_discrete_device, clock)
  1132. +
  1133. +struct acpi_device;
  1134. +struct i2c_client;
  1135. +struct platform_device;
  1136. +
  1137. +struct int3472_cldb {
  1138. + u8 version;
  1139. + /*
  1140. + * control logic type
  1141. + * 0: UNKNOWN
  1142. + * 1: DISCRETE(CRD-D)
  1143. + * 2: PMIC TPS68470
  1144. + * 3: PMIC uP6641
  1145. + */
  1146. + u8 control_logic_type;
  1147. + u8 control_logic_id;
  1148. + u8 sensor_card_sku;
  1149. + u8 reserved[28];
  1150. +};
  1151. +
  1152. +struct int3472_gpio_function_remap {
  1153. + const char *documented;
  1154. + const char *actual;
  1155. +};
  1156. +
  1157. +struct int3472_sensor_config {
  1158. + const char *sensor_module_name;
  1159. + struct regulator_consumer_supply supply_map;
  1160. + const struct int3472_gpio_function_remap *function_maps;
  1161. +};
  1162. +
  1163. +struct int3472_discrete_device {
  1164. + struct acpi_device *adev;
  1165. + struct device *dev;
  1166. + struct acpi_device *sensor;
  1167. + const char *sensor_name;
  1168. +
  1169. + const struct int3472_sensor_config *sensor_config;
  1170. +
  1171. + struct int3472_gpio_regulator {
  1172. + char regulator_name[GPIO_REGULATOR_NAME_LENGTH];
  1173. + char supply_name[GPIO_REGULATOR_SUPPLY_NAME_LENGTH];
  1174. + struct gpio_desc *gpio;
  1175. + struct regulator_dev *rdev;
  1176. + struct regulator_desc rdesc;
  1177. + } regulator;
  1178. +
  1179. + struct int3472_gpio_clock {
  1180. + struct clk *clk;
  1181. + struct clk_hw clk_hw;
  1182. + struct clk_lookup *cl;
  1183. + struct gpio_desc *ena_gpio;
  1184. + struct gpio_desc *led_gpio;
  1185. + u32 frequency;
  1186. + } clock;
  1187. +
  1188. + unsigned int n_gpios; /* how many GPIOs have we seen */
  1189. + unsigned int n_sensor_gpios; /* how many have we mapped to sensor */
  1190. + struct gpiod_lookup_table gpios;
  1191. +};
  1192. +
  1193. +int skl_int3472_discrete_probe(struct platform_device *pdev);
  1194. +int skl_int3472_discrete_remove(struct platform_device *pdev);
  1195. +int skl_int3472_tps68470_probe(struct i2c_client *client);
  1196. +union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev,
  1197. + char *id);
  1198. +int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb);
  1199. +int skl_int3472_register_clock(struct int3472_discrete_device *int3472);
  1200. +int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
  1201. + struct acpi_resource *ares);
  1202. +
  1203. +#endif
  1204. diff --git a/drivers/platform/x86/intel-int3472/intel_skl_int3472_discrete.c b/drivers/platform/x86/intel-int3472/intel_skl_int3472_discrete.c
  1205. new file mode 100644
  1206. index 000000000000..cb91ab9e65cc
  1207. --- /dev/null
  1208. +++ b/drivers/platform/x86/intel-int3472/intel_skl_int3472_discrete.c
  1209. @@ -0,0 +1,409 @@
  1210. +// SPDX-License-Identifier: GPL-2.0
  1211. +/* Author: Dan Scally <djrscally@gmail.com> */
  1212. +
  1213. +#include <linux/acpi.h>
  1214. +#include <linux/clkdev.h>
  1215. +#include <linux/clk-provider.h>
  1216. +#include <linux/device.h>
  1217. +#include <linux/gpio/consumer.h>
  1218. +#include <linux/gpio/machine.h>
  1219. +#include <linux/i2c.h>
  1220. +#include <linux/kernel.h>
  1221. +#include <linux/module.h>
  1222. +#include <linux/overflow.h>
  1223. +#include <linux/platform_device.h>
  1224. +#include <linux/uuid.h>
  1225. +
  1226. +#include "intel_skl_int3472_common.h"
  1227. +
  1228. +/*
  1229. + * 79234640-9e10-4fea-a5c1-b5aa8b19756f
  1230. + * This _DSM GUID returns information about the GPIO lines mapped to a
  1231. + * discrete INT3472 device. Function number 1 returns a count of the GPIO
  1232. + * lines that are mapped. Subsequent functions return 32 bit ints encoding
  1233. + * information about the GPIO line, including its purpose.
  1234. + */
  1235. +static const guid_t int3472_gpio_guid =
  1236. + GUID_INIT(0x79234640, 0x9e10, 0x4fea,
  1237. + 0xa5, 0xc1, 0xb5, 0xaa, 0x8b, 0x19, 0x75, 0x6f);
  1238. +
  1239. +/*
  1240. + * 822ace8f-2814-4174-a56b-5f029fe079ee
  1241. + * This _DSM GUID returns a string from the sensor device, which acts as a
  1242. + * module identifier.
  1243. + */
  1244. +static const guid_t cio2_sensor_module_guid =
  1245. + GUID_INIT(0x822ace8f, 0x2814, 0x4174,
  1246. + 0xa5, 0x6b, 0x5f, 0x02, 0x9f, 0xe0, 0x79, 0xee);
  1247. +
  1248. +/*
  1249. + * Here follows platform specific mapping information that we can pass to
  1250. + * the functions mapping resources to the sensors. Where the sensors have
  1251. + * a power enable pin defined in DSDT we need to provide a supply name so
  1252. + * the sensor drivers can find the regulator. The device name will be derived
  1253. + * from the sensor's ACPI device within the code. Optionally, we can provide a
  1254. + * NULL terminated array of function name mappings to deal with any platform
  1255. + * specific deviations from the documented behaviour of GPIOs.
  1256. + *
  1257. + * Map a GPIO function name to NULL to prevent the driver from mapping that
  1258. + * GPIO at all.
  1259. + */
  1260. +
  1261. +static const struct int3472_gpio_function_remap ov2680_gpio_function_remaps[] = {
  1262. + { "reset", NULL },
  1263. + { "powerdown", "reset" },
  1264. + { }
  1265. +};
  1266. +
  1267. +static const struct int3472_sensor_config int3472_sensor_configs[] = {
  1268. + /* Lenovo Miix 510-12ISK - OV2680, Front */
  1269. + { "GNDF140809R", { 0 }, ov2680_gpio_function_remaps },
  1270. + /* Lenovo Miix 510-12ISK - OV5648, Rear */
  1271. + { "GEFF150023R", REGULATOR_SUPPLY("avdd", NULL), NULL },
  1272. + /* Surface Go 1&2 - OV5693, Front */
  1273. + { "YHCU", REGULATOR_SUPPLY("avdd", NULL), NULL },
  1274. +};
  1275. +
  1276. +static const struct int3472_sensor_config *
  1277. +skl_int3472_get_sensor_module_config(struct int3472_discrete_device *int3472)
  1278. +{
  1279. + const struct int3472_sensor_config *ret;
  1280. + union acpi_object *obj;
  1281. + unsigned int i;
  1282. +
  1283. + obj = acpi_evaluate_dsm_typed(int3472->sensor->handle,
  1284. + &cio2_sensor_module_guid, 0x00,
  1285. + 0x01, NULL, ACPI_TYPE_STRING);
  1286. +
  1287. + if (!obj) {
  1288. + dev_err(int3472->dev,
  1289. + "Failed to get sensor module string from _DSM\n");
  1290. + return ERR_PTR(-ENODEV);
  1291. + }
  1292. +
  1293. + if (obj->string.type != ACPI_TYPE_STRING) {
  1294. + dev_err(int3472->dev,
  1295. + "Sensor _DSM returned a non-string value\n");
  1296. + ret = ERR_PTR(-EINVAL);
  1297. + goto out_free_obj;
  1298. + }
  1299. +
  1300. + ret = ERR_PTR(-EINVAL);
  1301. + for (i = 0; i < ARRAY_SIZE(int3472_sensor_configs); i++) {
  1302. + if (!strcmp(int3472_sensor_configs[i].sensor_module_name,
  1303. + obj->string.pointer)) {
  1304. + ret = &int3472_sensor_configs[i];
  1305. + break;
  1306. + }
  1307. + }
  1308. +
  1309. +out_free_obj:
  1310. + ACPI_FREE(obj);
  1311. + return ret;
  1312. +}
  1313. +
  1314. +static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int3472,
  1315. + struct acpi_resource *ares,
  1316. + const char *func, u32 polarity)
  1317. +{
  1318. + char *path = ares->data.gpio.resource_source.string_ptr;
  1319. + const struct int3472_sensor_config *sensor_config;
  1320. + struct gpiod_lookup *table_entry;
  1321. + struct acpi_device *adev;
  1322. + acpi_handle handle;
  1323. + acpi_status status;
  1324. + int ret;
  1325. +
  1326. + if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) {
  1327. + dev_warn(int3472->dev, "Too many GPIOs mapped\n");
  1328. + return -EINVAL;
  1329. + }
  1330. +
  1331. + sensor_config = int3472->sensor_config;
  1332. + if (!IS_ERR(sensor_config) && sensor_config->function_maps) {
  1333. + const struct int3472_gpio_function_remap *remap;
  1334. +
  1335. + for (remap = sensor_config->function_maps; remap->documented; remap++) {
  1336. + if (!strcmp(func, remap->documented)) {
  1337. + func = remap->actual;
  1338. + break;
  1339. + }
  1340. + }
  1341. + }
  1342. +
  1343. + /* Functions mapped to NULL should not be mapped to the sensor */
  1344. + if (!func)
  1345. + return 0;
  1346. +
  1347. + status = acpi_get_handle(NULL, path, &handle);
  1348. + if (ACPI_FAILURE(status))
  1349. + return -EINVAL;
  1350. +
  1351. + ret = acpi_bus_get_device(handle, &adev);
  1352. + if (ret)
  1353. + return -ENODEV;
  1354. +
  1355. + table_entry = &int3472->gpios.table[int3472->n_sensor_gpios];
  1356. + table_entry->key = acpi_dev_name(adev);
  1357. + table_entry->chip_hwnum = ares->data.gpio.pin_table[0];
  1358. + table_entry->con_id = func;
  1359. + table_entry->idx = 0;
  1360. + table_entry->flags = polarity;
  1361. +
  1362. + int3472->n_sensor_gpios++;
  1363. +
  1364. + return 0;
  1365. +}
  1366. +
  1367. +static int skl_int3472_map_gpio_to_clk(struct int3472_discrete_device *int3472,
  1368. + struct acpi_resource *ares, u8 type)
  1369. +{
  1370. + char *path = ares->data.gpio.resource_source.string_ptr;
  1371. + struct gpio_desc *gpio;
  1372. +
  1373. + switch (type) {
  1374. + case INT3472_GPIO_TYPE_CLK_ENABLE:
  1375. + gpio = acpi_get_and_request_gpiod(path, ares->data.gpio.pin_table[0],
  1376. + "int3472,clk-enable");
  1377. + if (IS_ERR(gpio))
  1378. + return (PTR_ERR(gpio));
  1379. +
  1380. + int3472->clock.ena_gpio = gpio;
  1381. + break;
  1382. + case INT3472_GPIO_TYPE_PRIVACY_LED:
  1383. + gpio = acpi_get_and_request_gpiod(path, ares->data.gpio.pin_table[0],
  1384. + "int3472,privacy-led");
  1385. + if (IS_ERR(gpio))
  1386. + return (PTR_ERR(gpio));
  1387. +
  1388. + int3472->clock.led_gpio = gpio;
  1389. + break;
  1390. + default:
  1391. + dev_err(int3472->dev, "Invalid GPIO type 0x%02x for clock\n",
  1392. + type);
  1393. + break;
  1394. + }
  1395. +
  1396. + return 0;
  1397. +}
  1398. +
  1399. +/**
  1400. + * skl_int3472_handle_gpio_resources: Map PMIC resources to consuming sensor
  1401. + * @ares: A pointer to a &struct acpi_resource
  1402. + * @data: A pointer to a &struct int3472_discrete_device
  1403. + *
  1404. + * This function handles GPIO resources that are against an INT3472
  1405. + * ACPI device, by checking the value of the corresponding _DSM entry.
  1406. + * This will return a 32bit int, where the lowest byte represents the
  1407. + * function of the GPIO pin:
  1408. + *
  1409. + * 0x00 Reset
  1410. + * 0x01 Power down
  1411. + * 0x0b Power enable
  1412. + * 0x0c Clock enable
  1413. + * 0x0d Privacy LED
  1414. + *
  1415. + * There are some known platform specific quirks where that does not quite
  1416. + * hold up; for example where a pin with type 0x01 (Power down) is mapped to
  1417. + * a sensor pin that performs a reset function or entries in _CRS and _DSM that
  1418. + * do not actually correspond to a physical connection. These will be handled
  1419. + * by the mapping sub-functions.
  1420. + *
  1421. + * GPIOs will either be mapped directly to the sensor device or else used
  1422. + * to create clocks and regulators via the usual frameworks.
  1423. + *
  1424. + * Return:
  1425. + * * 0 - When all resources found are handled properly.
  1426. + * * -EINVAL - If the resource is not a GPIO IO resource
  1427. + * * -ENODEV - If the resource has no corresponding _DSM entry
  1428. + * * -Other - Errors propagated from one of the sub-functions.
  1429. + */
  1430. +static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
  1431. + void *data)
  1432. +{
  1433. + struct int3472_discrete_device *int3472 = data;
  1434. + struct acpi_resource_gpio *agpio;
  1435. + union acpi_object *obj;
  1436. + const char *err_msg;
  1437. + int ret;
  1438. + u8 type;
  1439. +
  1440. + if (!acpi_gpio_get_io_resource(ares, &agpio))
  1441. + return 1; /* Deliberately positive so parsing continues */
  1442. +
  1443. + /*
  1444. + * n_gpios + 2 because the index of this _DSM function is 1-based and
  1445. + * the first function is just a count.
  1446. + */
  1447. + obj = acpi_evaluate_dsm_typed(int3472->adev->handle,
  1448. + &int3472_gpio_guid, 0x00,
  1449. + int3472->n_gpios + 2,
  1450. + NULL, ACPI_TYPE_INTEGER);
  1451. +
  1452. + if (!obj) {
  1453. + dev_warn(int3472->dev, "No _DSM entry for GPIO pin %u\n",
  1454. + ares->data.gpio.pin_table[0]);
  1455. + return 1;
  1456. + }
  1457. +
  1458. + type = obj->integer.value & 0xff;
  1459. +
  1460. + switch (type) {
  1461. + case INT3472_GPIO_TYPE_RESET:
  1462. + ret = skl_int3472_map_gpio_to_sensor(int3472, ares, "reset",
  1463. + GPIO_ACTIVE_LOW);
  1464. + if (ret)
  1465. + err_msg = "Failed to map reset pin to sensor\n";
  1466. +
  1467. + break;
  1468. + case INT3472_GPIO_TYPE_POWERDOWN:
  1469. + ret = skl_int3472_map_gpio_to_sensor(int3472, ares,
  1470. + "powerdown",
  1471. + GPIO_ACTIVE_LOW);
  1472. + if (ret)
  1473. + err_msg = "Failed to map powerdown pin to sensor\n";
  1474. +
  1475. + break;
  1476. + case INT3472_GPIO_TYPE_CLK_ENABLE:
  1477. + case INT3472_GPIO_TYPE_PRIVACY_LED:
  1478. + ret = skl_int3472_map_gpio_to_clk(int3472, ares, type);
  1479. + if (ret)
  1480. + err_msg = "Failed to map GPIO to clock\n";
  1481. +
  1482. + break;
  1483. + case INT3472_GPIO_TYPE_POWER_ENABLE:
  1484. + ret = skl_int3472_register_regulator(int3472, ares);
  1485. + if (ret)
  1486. + err_msg = "Failed to map regulator to sensor\n";
  1487. +
  1488. + break;
  1489. + default:
  1490. + dev_warn(int3472->dev,
  1491. + "GPIO type 0x%02x unknown; the sensor may not work\n",
  1492. + type);
  1493. + ret = 1;
  1494. + break;
  1495. + }
  1496. +
  1497. + int3472->n_gpios++;
  1498. + ACPI_FREE(obj);
  1499. +
  1500. + if (ret)
  1501. + return dev_err_probe(int3472->dev, ret, err_msg);
  1502. +
  1503. + return 0;
  1504. +}
  1505. +
  1506. +static int skl_int3472_parse_crs(struct int3472_discrete_device *int3472)
  1507. +{
  1508. + LIST_HEAD(resource_list);
  1509. + int ret;
  1510. +
  1511. + /*
  1512. + * No error check, because not having a sensor config is not necessarily
  1513. + * a failure mode.
  1514. + */
  1515. + int3472->sensor_config = skl_int3472_get_sensor_module_config(int3472);
  1516. +
  1517. + ret = acpi_dev_get_resources(int3472->adev, &resource_list,
  1518. + skl_int3472_handle_gpio_resources,
  1519. + int3472);
  1520. + if (ret)
  1521. + goto out_free_res_list;
  1522. +
  1523. + if (int3472->clock.ena_gpio) {
  1524. + ret = skl_int3472_register_clock(int3472);
  1525. + if (ret)
  1526. + goto out_free_res_list;
  1527. + } else {
  1528. + if (int3472->clock.led_gpio)
  1529. + dev_warn(int3472->dev,
  1530. + "No clk GPIO. The privacy LED won't work\n");
  1531. + }
  1532. +
  1533. + int3472->gpios.dev_id = int3472->sensor_name;
  1534. + gpiod_add_lookup_table(&int3472->gpios);
  1535. +
  1536. +out_free_res_list:
  1537. + acpi_dev_free_resource_list(&resource_list);
  1538. +
  1539. + return ret;
  1540. +}
  1541. +
  1542. +int skl_int3472_discrete_probe(struct platform_device *pdev)
  1543. +{
  1544. + struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
  1545. + struct int3472_discrete_device *int3472;
  1546. + struct int3472_cldb cldb;
  1547. + int ret;
  1548. +
  1549. + ret = skl_int3472_fill_cldb(adev, &cldb);
  1550. + if (ret) {
  1551. + dev_err(&pdev->dev, "Couldn't fill CLDB structure\n");
  1552. + return ret;
  1553. + }
  1554. +
  1555. + if (cldb.control_logic_type != 1) {
  1556. + dev_err(&pdev->dev, "Unsupported control logic type %u\n",
  1557. + cldb.control_logic_type);
  1558. + return -EINVAL;
  1559. + }
  1560. +
  1561. + /* Max num GPIOs we've seen plus a terminator */
  1562. + int3472 = devm_kzalloc(&pdev->dev, struct_size(int3472, gpios.table,
  1563. + INT3472_MAX_SENSOR_GPIOS + 1), GFP_KERNEL);
  1564. + if (!int3472)
  1565. + return -ENOMEM;
  1566. +
  1567. + int3472->adev = adev;
  1568. + int3472->dev = &pdev->dev;
  1569. + platform_set_drvdata(pdev, int3472);
  1570. +
  1571. + int3472->sensor = acpi_dev_get_dependent_dev(adev);
  1572. + if (!int3472->sensor) {
  1573. + dev_err(&pdev->dev, "INT3472 seems to have no dependents.\n");
  1574. + return -ENODEV;
  1575. + }
  1576. +
  1577. + int3472->sensor_name = devm_kasprintf(int3472->dev, GFP_KERNEL,
  1578. + I2C_DEV_NAME_FORMAT,
  1579. + acpi_dev_name(int3472->sensor));
  1580. + if (!int3472->sensor_name) {
  1581. + ret = -ENOMEM;
  1582. + goto err_put_sensor;
  1583. + }
  1584. +
  1585. + /*
  1586. + * Initialising this list means we can call gpiod_remove_lookup_table()
  1587. + * in failure paths without issue.
  1588. + */
  1589. + INIT_LIST_HEAD(&int3472->gpios.list);
  1590. +
  1591. + ret = skl_int3472_parse_crs(int3472);
  1592. + if (ret) {
  1593. + skl_int3472_discrete_remove(pdev);
  1594. + return ret;
  1595. + }
  1596. +
  1597. + return 0;
  1598. +
  1599. +err_put_sensor:
  1600. + acpi_dev_put(int3472->sensor);
  1601. +
  1602. + return ret;
  1603. +}
  1604. +
  1605. +int skl_int3472_discrete_remove(struct platform_device *pdev)
  1606. +{
  1607. + struct int3472_discrete_device *int3472 = platform_get_drvdata(pdev);
  1608. +
  1609. + gpiod_remove_lookup_table(&int3472->gpios);
  1610. + regulator_unregister(int3472->regulator.rdev);
  1611. + clk_unregister(int3472->clock.clk);
  1612. + clkdev_drop(int3472->clock.cl);
  1613. + gpiod_put(int3472->regulator.gpio);
  1614. + gpiod_put(int3472->clock.ena_gpio);
  1615. + gpiod_put(int3472->clock.led_gpio);
  1616. +
  1617. + return 0;
  1618. +}
  1619. diff --git a/drivers/platform/x86/intel-int3472/intel_skl_int3472_tps68470.c b/drivers/platform/x86/intel-int3472/intel_skl_int3472_tps68470.c
  1620. new file mode 100644
  1621. index 000000000000..843eaa27e9da
  1622. --- /dev/null
  1623. +++ b/drivers/platform/x86/intel-int3472/intel_skl_int3472_tps68470.c
  1624. @@ -0,0 +1,109 @@
  1625. +// SPDX-License-Identifier: GPL-2.0
  1626. +/* Author: Dan Scally <djrscally@gmail.com> */
  1627. +
  1628. +#include <linux/i2c.h>
  1629. +#include <linux/mfd/core.h>
  1630. +#include <linux/mfd/tps68470.h>
  1631. +#include <linux/platform_device.h>
  1632. +#include <linux/regmap.h>
  1633. +
  1634. +#include "intel_skl_int3472_common.h"
  1635. +
  1636. +static const struct mfd_cell tps68470_cros[] = {
  1637. + { .name = "tps68470-gpio" },
  1638. + { .name = "tps68470_pmic_opregion" },
  1639. +};
  1640. +
  1641. +static const struct mfd_cell tps68470_win[] = {
  1642. + { .name = "tps68470-gpio" },
  1643. + { .name = "tps68470-clk" },
  1644. + { .name = "tps68470-regulator" },
  1645. +};
  1646. +
  1647. +static const struct regmap_config tps68470_regmap_config = {
  1648. + .reg_bits = 8,
  1649. + .val_bits = 8,
  1650. + .max_register = TPS68470_REG_MAX,
  1651. +};
  1652. +
  1653. +static int tps68470_chip_init(struct device *dev, struct regmap *regmap)
  1654. +{
  1655. + unsigned int version;
  1656. + int ret;
  1657. +
  1658. + /* Force software reset */
  1659. + ret = regmap_write(regmap, TPS68470_REG_RESET, TPS68470_REG_RESET_MASK);
  1660. + if (ret)
  1661. + return ret;
  1662. +
  1663. + ret = regmap_read(regmap, TPS68470_REG_REVID, &version);
  1664. + if (ret) {
  1665. + dev_err(dev, "Failed to read revision register: %d\n", ret);
  1666. + return ret;
  1667. + }
  1668. +
  1669. + dev_info(dev, "TPS68470 REVID: 0x%02x\n", version);
  1670. +
  1671. + return 0;
  1672. +}
  1673. +
  1674. +int skl_int3472_tps68470_probe(struct i2c_client *client)
  1675. +{
  1676. + struct acpi_device *adev = ACPI_COMPANION(&client->dev);
  1677. + struct int3472_cldb cldb = { 0 };
  1678. + struct regmap *regmap;
  1679. + int ret;
  1680. +
  1681. + regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
  1682. + if (IS_ERR(regmap)) {
  1683. + dev_err(&client->dev, "Failed to create regmap: %ld\n",
  1684. + PTR_ERR(regmap));
  1685. + return PTR_ERR(regmap);
  1686. + }
  1687. +
  1688. + i2c_set_clientdata(client, regmap);
  1689. +
  1690. + ret = tps68470_chip_init(&client->dev, regmap);
  1691. + if (ret < 0) {
  1692. + dev_err(&client->dev, "TPS68470 init error %d\n", ret);
  1693. + return ret;
  1694. + }
  1695. +
  1696. + /*
  1697. + * Check CLDB buffer against the PMIC's adev. If present, then we check
  1698. + * the value of control_logic_type field and follow one of the
  1699. + * following scenarios:
  1700. + *
  1701. + * 1. No CLDB - likely ACPI tables designed for ChromeOS. We
  1702. + * create platform devices for the GPIOs and OpRegion drivers.
  1703. + *
  1704. + * 2. CLDB, with control_logic_type = 2 - probably ACPI tables
  1705. + * made for Windows 2-in-1 platforms. Register pdevs for GPIO,
  1706. + * Clock and Regulator drivers to bind to.
  1707. + *
  1708. + * 3. Any other value in control_logic_type, we should never have
  1709. + * gotten to this point; fail probe and return.
  1710. + */
  1711. + ret = skl_int3472_fill_cldb(adev, &cldb);
  1712. + if (!ret && cldb.control_logic_type != 2) {
  1713. + dev_err(&client->dev, "Unsupported control logic type %u\n",
  1714. + cldb.control_logic_type);
  1715. + return -EINVAL;
  1716. + }
  1717. +
  1718. + if (ret)
  1719. + ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
  1720. + tps68470_cros, ARRAY_SIZE(tps68470_cros),
  1721. + NULL, 0, NULL);
  1722. + else
  1723. + ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
  1724. + tps68470_win, ARRAY_SIZE(tps68470_win),
  1725. + NULL, 0, NULL);
  1726. +
  1727. + if (ret) {
  1728. + dev_err(&client->dev, "Failed to add MFD devices\n");
  1729. + return ret;
  1730. + }
  1731. +
  1732. + return 0;
  1733. +}
  1734. --
  1735. 2.32.0
  1736. From 6d2bc22506f8dde18ab75b64ad67d716da0db1af Mon Sep 17 00:00:00 2001
  1737. From: Daniel Scally <djrscally@gmail.com>
  1738. Date: Thu, 20 May 2021 15:09:28 +0100
  1739. Subject: [PATCH] mfd: tps68470: Remove tps68470 MFD driver
  1740. This driver only covered one scenario in which ACPI devices with _HID
  1741. INT3472 are found, and its functionality has been taken over by the
  1742. intel-skl-int3472 module, so remove it.
  1743. Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>
  1744. Acked-by: Lee Jones <lee.jones@linaro.org>
  1745. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  1746. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  1747. Patchset: cameras
  1748. ---
  1749. drivers/acpi/pmic/Kconfig | 2 +-
  1750. drivers/gpio/Kconfig | 2 +-
  1751. drivers/mfd/Kconfig | 18 --------
  1752. drivers/mfd/Makefile | 1 -
  1753. drivers/mfd/tps68470.c | 97 ---------------------------------------
  1754. 5 files changed, 2 insertions(+), 118 deletions(-)
  1755. delete mode 100644 drivers/mfd/tps68470.c
  1756. diff --git a/drivers/acpi/pmic/Kconfig b/drivers/acpi/pmic/Kconfig
  1757. index 56bbcb2ce61b..f84b8f6038dc 100644
  1758. --- a/drivers/acpi/pmic/Kconfig
  1759. +++ b/drivers/acpi/pmic/Kconfig
  1760. @@ -52,7 +52,7 @@ endif # PMIC_OPREGION
  1761. config TPS68470_PMIC_OPREGION
  1762. bool "ACPI operation region support for TPS68470 PMIC"
  1763. - depends on MFD_TPS68470
  1764. + depends on INTEL_SKL_INT3472
  1765. help
  1766. This config adds ACPI operation region support for TI TPS68470 PMIC.
  1767. TPS68470 device is an advanced power management unit that powers
  1768. diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
  1769. index e3607ec4c2e8..269d88c7d5a5 100644
  1770. --- a/drivers/gpio/Kconfig
  1771. +++ b/drivers/gpio/Kconfig
  1772. @@ -1345,7 +1345,7 @@ config GPIO_TPS65912
  1773. config GPIO_TPS68470
  1774. bool "TPS68470 GPIO"
  1775. - depends on MFD_TPS68470
  1776. + depends on INTEL_SKL_INT3472
  1777. help
  1778. Select this option to enable GPIO driver for the TPS68470
  1779. chip family.
  1780. diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
  1781. index b74efa469e90..8a112a194c3b 100644
  1782. --- a/drivers/mfd/Kconfig
  1783. +++ b/drivers/mfd/Kconfig
  1784. @@ -1511,24 +1511,6 @@ config MFD_TPS65217
  1785. This driver can also be built as a module. If so, the module
  1786. will be called tps65217.
  1787. -config MFD_TPS68470
  1788. - bool "TI TPS68470 Power Management / LED chips"
  1789. - depends on ACPI && PCI && I2C=y
  1790. - depends on I2C_DESIGNWARE_PLATFORM=y
  1791. - select MFD_CORE
  1792. - select REGMAP_I2C
  1793. - help
  1794. - If you say yes here you get support for the TPS68470 series of
  1795. - Power Management / LED chips.
  1796. -
  1797. - These include voltage regulators, LEDs and other features
  1798. - that are often used in portable devices.
  1799. -
  1800. - This option is a bool as it provides an ACPI operation
  1801. - region, which must be available before any of the devices
  1802. - using this are probed. This option also configures the
  1803. - designware-i2c driver to be built-in, for the same reason.
  1804. -
  1805. config MFD_TI_LP873X
  1806. tristate "TI LP873X Power Management IC"
  1807. depends on I2C
  1808. diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
  1809. index 834f5463af28..daccc3475de5 100644
  1810. --- a/drivers/mfd/Makefile
  1811. +++ b/drivers/mfd/Makefile
  1812. @@ -105,7 +105,6 @@ obj-$(CONFIG_MFD_TPS65910) += tps65910.o
  1813. obj-$(CONFIG_MFD_TPS65912) += tps65912-core.o
  1814. obj-$(CONFIG_MFD_TPS65912_I2C) += tps65912-i2c.o
  1815. obj-$(CONFIG_MFD_TPS65912_SPI) += tps65912-spi.o
  1816. -obj-$(CONFIG_MFD_TPS68470) += tps68470.o
  1817. obj-$(CONFIG_MFD_TPS80031) += tps80031.o
  1818. obj-$(CONFIG_MENELAUS) += menelaus.o
  1819. diff --git a/drivers/mfd/tps68470.c b/drivers/mfd/tps68470.c
  1820. deleted file mode 100644
  1821. index 4a4df4ffd18c..000000000000
  1822. --- a/drivers/mfd/tps68470.c
  1823. +++ /dev/null
  1824. @@ -1,97 +0,0 @@
  1825. -// SPDX-License-Identifier: GPL-2.0
  1826. -/*
  1827. - * TPS68470 chip Parent driver
  1828. - *
  1829. - * Copyright (C) 2017 Intel Corporation
  1830. - *
  1831. - * Authors:
  1832. - * Rajmohan Mani <rajmohan.mani@intel.com>
  1833. - * Tianshu Qiu <tian.shu.qiu@intel.com>
  1834. - * Jian Xu Zheng <jian.xu.zheng@intel.com>
  1835. - * Yuning Pu <yuning.pu@intel.com>
  1836. - */
  1837. -
  1838. -#include <linux/acpi.h>
  1839. -#include <linux/delay.h>
  1840. -#include <linux/i2c.h>
  1841. -#include <linux/init.h>
  1842. -#include <linux/mfd/core.h>
  1843. -#include <linux/mfd/tps68470.h>
  1844. -#include <linux/regmap.h>
  1845. -
  1846. -static const struct mfd_cell tps68470s[] = {
  1847. - { .name = "tps68470-gpio" },
  1848. - { .name = "tps68470_pmic_opregion" },
  1849. -};
  1850. -
  1851. -static const struct regmap_config tps68470_regmap_config = {
  1852. - .reg_bits = 8,
  1853. - .val_bits = 8,
  1854. - .max_register = TPS68470_REG_MAX,
  1855. -};
  1856. -
  1857. -static int tps68470_chip_init(struct device *dev, struct regmap *regmap)
  1858. -{
  1859. - unsigned int version;
  1860. - int ret;
  1861. -
  1862. - /* Force software reset */
  1863. - ret = regmap_write(regmap, TPS68470_REG_RESET, TPS68470_REG_RESET_MASK);
  1864. - if (ret)
  1865. - return ret;
  1866. -
  1867. - ret = regmap_read(regmap, TPS68470_REG_REVID, &version);
  1868. - if (ret) {
  1869. - dev_err(dev, "Failed to read revision register: %d\n", ret);
  1870. - return ret;
  1871. - }
  1872. -
  1873. - dev_info(dev, "TPS68470 REVID: 0x%x\n", version);
  1874. -
  1875. - return 0;
  1876. -}
  1877. -
  1878. -static int tps68470_probe(struct i2c_client *client)
  1879. -{
  1880. - struct device *dev = &client->dev;
  1881. - struct regmap *regmap;
  1882. - int ret;
  1883. -
  1884. - regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
  1885. - if (IS_ERR(regmap)) {
  1886. - dev_err(dev, "devm_regmap_init_i2c Error %ld\n",
  1887. - PTR_ERR(regmap));
  1888. - return PTR_ERR(regmap);
  1889. - }
  1890. -
  1891. - i2c_set_clientdata(client, regmap);
  1892. -
  1893. - ret = tps68470_chip_init(dev, regmap);
  1894. - if (ret < 0) {
  1895. - dev_err(dev, "TPS68470 Init Error %d\n", ret);
  1896. - return ret;
  1897. - }
  1898. -
  1899. - ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, tps68470s,
  1900. - ARRAY_SIZE(tps68470s), NULL, 0, NULL);
  1901. - if (ret < 0) {
  1902. - dev_err(dev, "devm_mfd_add_devices failed: %d\n", ret);
  1903. - return ret;
  1904. - }
  1905. -
  1906. - return 0;
  1907. -}
  1908. -
  1909. -static const struct acpi_device_id tps68470_acpi_ids[] = {
  1910. - {"INT3472"},
  1911. - {},
  1912. -};
  1913. -
  1914. -static struct i2c_driver tps68470_driver = {
  1915. - .driver = {
  1916. - .name = "tps68470",
  1917. - .acpi_match_table = tps68470_acpi_ids,
  1918. - },
  1919. - .probe_new = tps68470_probe,
  1920. -};
  1921. -builtin_i2c_driver(tps68470_driver);
  1922. --
  1923. 2.32.0
  1924. From b29ed9bc07d7f8de7ba84f6f7626902abb88fe09 Mon Sep 17 00:00:00 2001
  1925. From: Daniel Scally <djrscally@gmail.com>
  1926. Date: Mon, 5 Apr 2021 23:56:53 +0100
  1927. Subject: [PATCH] media: ipu3-cio2: Toggle sensor streaming in pm runtime ops
  1928. The .suspend() and .resume() runtime_pm operations for the ipu3-cio2
  1929. driver currently do not handle the sensor's stream. Setting .s_stream() on
  1930. or off for the sensor subdev means that sensors will pause and resume the
  1931. stream at the appropriate time even if their drivers don't implement those
  1932. operations.
  1933. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  1934. Patchset: cameras
  1935. ---
  1936. drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 15 ++++++++++++++-
  1937. 1 file changed, 14 insertions(+), 1 deletion(-)
  1938. diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  1939. index fecef85bd62e..9dafb9470708 100644
  1940. --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  1941. +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
  1942. @@ -1973,12 +1973,19 @@ static int __maybe_unused cio2_suspend(struct device *dev)
  1943. struct pci_dev *pci_dev = to_pci_dev(dev);
  1944. struct cio2_device *cio2 = pci_get_drvdata(pci_dev);
  1945. struct cio2_queue *q = cio2->cur_queue;
  1946. + int r;
  1947. dev_dbg(dev, "cio2 suspend\n");
  1948. if (!cio2->streaming)
  1949. return 0;
  1950. /* Stop stream */
  1951. + r = v4l2_subdev_call(q->sensor, video, s_stream, 0);
  1952. + if (r) {
  1953. + dev_err(dev, "failed to stop sensor streaming\n");
  1954. + return r;
  1955. + }
  1956. +
  1957. cio2_hw_exit(cio2, q);
  1958. synchronize_irq(pci_dev->irq);
  1959. @@ -2013,8 +2020,14 @@ static int __maybe_unused cio2_resume(struct device *dev)
  1960. }
  1961. r = cio2_hw_init(cio2, q);
  1962. - if (r)
  1963. + if (r) {
  1964. dev_err(dev, "fail to init cio2 hw\n");
  1965. + return r;
  1966. + }
  1967. +
  1968. + r = v4l2_subdev_call(q->sensor, video, s_stream, 1);
  1969. + if (r)
  1970. + dev_err(dev, "fail to start sensor streaming\n");
  1971. return r;
  1972. }
  1973. --
  1974. 2.32.0
  1975. From 455b9f9e61b3b1f57ad6b8042cd2cb89601cbb45 Mon Sep 17 00:00:00 2001
  1976. From: Daniel Scally <djrscally@gmail.com>
  1977. Date: Mon, 5 Apr 2021 23:56:54 +0100
  1978. Subject: [PATCH] media: i2c: Add support for ov5693 sensor
  1979. The OV5693 is a 5 Mpx CMOS image sensor, connected via MIPI CSI-2. The
  1980. chip is capable of a single lane configuration, but currently only two
  1981. lanes are supported.
  1982. Most of the sensor's features are supported, with the main exception
  1983. being the lens correction algorithm.
  1984. The driver provides all mandatory, optional and recommended V4L2 controls
  1985. for maximum compatibility with libcamera.
  1986. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  1987. Patchset: cameras
  1988. ---
  1989. MAINTAINERS | 7 +
  1990. drivers/media/i2c/Kconfig | 11 +
  1991. drivers/media/i2c/Makefile | 1 +
  1992. drivers/media/i2c/ov5693.c | 1557 ++++++++++++++++++++++++++++++++++++
  1993. 4 files changed, 1576 insertions(+)
  1994. create mode 100644 drivers/media/i2c/ov5693.c
  1995. diff --git a/MAINTAINERS b/MAINTAINERS
  1996. index 2a421d2e4b07..b270caa6f766 100644
  1997. --- a/MAINTAINERS
  1998. +++ b/MAINTAINERS
  1999. @@ -13276,6 +13276,13 @@ S: Maintained
  2000. T: git git://linuxtv.org/media_tree.git
  2001. F: drivers/media/i2c/ov5675.c
  2002. +OMNIVISION OV5693 SENSOR DRIVER
  2003. +M: Daniel Scally <djrscally@gmail.com>
  2004. +L: linux-media@vger.kernel.org
  2005. +S: Maintained
  2006. +T: git git://linuxtv.org/media_tree.git
  2007. +F: drivers/media/i2c/ov5693.c
  2008. +
  2009. OMNIVISION OV5695 SENSOR DRIVER
  2010. M: Shunqian Zheng <zhengsq@rock-chips.com>
  2011. L: linux-media@vger.kernel.org
  2012. diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
  2013. index 462c0e059754..2893e74af99a 100644
  2014. --- a/drivers/media/i2c/Kconfig
  2015. +++ b/drivers/media/i2c/Kconfig
  2016. @@ -999,6 +999,17 @@ config VIDEO_OV5675
  2017. To compile this driver as a module, choose M here: the
  2018. module will be called ov5675.
  2019. +config VIDEO_OV5693
  2020. + tristate "OmniVision OV5693 sensor support"
  2021. + depends on I2C && VIDEO_V4L2
  2022. + select V4L2_FWNODE
  2023. + help
  2024. + This is a Video4Linux2 sensor driver for the OmniVision
  2025. + OV5693 camera.
  2026. +
  2027. + To compile this driver as a module, choose M here: the
  2028. + module will be called ov5693.
  2029. +
  2030. config VIDEO_OV5695
  2031. tristate "OmniVision OV5695 sensor support"
  2032. depends on I2C && VIDEO_V4L2
  2033. diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
  2034. index 0c067beca066..7d0884bc89f1 100644
  2035. --- a/drivers/media/i2c/Makefile
  2036. +++ b/drivers/media/i2c/Makefile
  2037. @@ -75,6 +75,7 @@ obj-$(CONFIG_VIDEO_OV5647) += ov5647.o
  2038. obj-$(CONFIG_VIDEO_OV5648) += ov5648.o
  2039. obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
  2040. obj-$(CONFIG_VIDEO_OV5675) += ov5675.o
  2041. +obj-$(CONFIG_VIDEO_OV5693) += ov5693.o
  2042. obj-$(CONFIG_VIDEO_OV5695) += ov5695.o
  2043. obj-$(CONFIG_VIDEO_OV6650) += ov6650.o
  2044. obj-$(CONFIG_VIDEO_OV7251) += ov7251.o
  2045. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  2046. new file mode 100644
  2047. index 000000000000..da2ca99a7ad3
  2048. --- /dev/null
  2049. +++ b/drivers/media/i2c/ov5693.c
  2050. @@ -0,0 +1,1557 @@
  2051. +// SPDX-License-Identifier: GPL-2.0
  2052. +/*
  2053. + * Copyright (c) 2013 Intel Corporation. All Rights Reserved.
  2054. + *
  2055. + * Adapted from the atomisp-ov5693 driver, with contributions from:
  2056. + *
  2057. + * Daniel Scally
  2058. + * Jean-Michel Hautbois
  2059. + * Fabian Wuthrich
  2060. + * Tsuchiya Yuto
  2061. + * Jordan Hand
  2062. + * Jake Day
  2063. + */
  2064. +
  2065. +#include <asm/unaligned.h>
  2066. +#include <linux/acpi.h>
  2067. +#include <linux/clk.h>
  2068. +#include <linux/delay.h>
  2069. +#include <linux/device.h>
  2070. +#include <linux/i2c.h>
  2071. +#include <linux/module.h>
  2072. +#include <linux/pm_runtime.h>
  2073. +#include <linux/regulator/consumer.h>
  2074. +#include <linux/slab.h>
  2075. +#include <linux/types.h>
  2076. +#include <media/v4l2-ctrls.h>
  2077. +#include <media/v4l2-device.h>
  2078. +#include <media/v4l2-fwnode.h>
  2079. +
  2080. +/* System Control */
  2081. +#define OV5693_SW_RESET_REG 0x0103
  2082. +#define OV5693_SW_STREAM_REG 0x0100
  2083. +#define OV5693_START_STREAMING 0x01
  2084. +#define OV5693_STOP_STREAMING 0x00
  2085. +#define OV5693_SW_RESET 0x01
  2086. +
  2087. +#define OV5693_REG_CHIP_ID_H 0x300a
  2088. +#define OV5693_REG_CHIP_ID_L 0x300b
  2089. +/* Yes, this is right. The datasheet for the OV5693 gives its ID as 0x5690 */
  2090. +#define OV5693_CHIP_ID 0x5690
  2091. +
  2092. +/* Exposure */
  2093. +#define OV5693_EXPOSURE_L_CTRL_HH_REG 0x3500
  2094. +#define OV5693_EXPOSURE_L_CTRL_H_REG 0x3501
  2095. +#define OV5693_EXPOSURE_L_CTRL_L_REG 0x3502
  2096. +#define OV5693_EXPOSURE_CTRL_HH(v) (((v) & GENMASK(14, 12)) >> 12)
  2097. +#define OV5693_EXPOSURE_CTRL_H(v) (((v) & GENMASK(11, 4)) >> 4)
  2098. +#define OV5693_EXPOSURE_CTRL_L(v) (((v) & GENMASK(3, 0)) << 4)
  2099. +#define OV5693_INTEGRATION_TIME_MARGIN 8
  2100. +#define OV5693_EXPOSURE_MIN 1
  2101. +#define OV5693_EXPOSURE_STEP 1
  2102. +
  2103. +/* Analogue Gain */
  2104. +#define OV5693_GAIN_CTRL_H_REG 0x350a
  2105. +#define OV5693_GAIN_CTRL_H(v) (((v) >> 4) & GENMASK(2, 0))
  2106. +#define OV5693_GAIN_CTRL_L_REG 0x350b
  2107. +#define OV5693_GAIN_CTRL_L(v) (((v) << 4) & GENMASK(7, 4))
  2108. +#define OV5693_GAIN_MIN 1
  2109. +#define OV5693_GAIN_MAX 127
  2110. +#define OV5693_GAIN_DEF 8
  2111. +#define OV5693_GAIN_STEP 1
  2112. +
  2113. +/* Digital Gain */
  2114. +#define OV5693_MWB_RED_GAIN_H_REG 0x3400
  2115. +#define OV5693_MWB_RED_GAIN_L_REG 0x3401
  2116. +#define OV5693_MWB_GREEN_GAIN_H_REG 0x3402
  2117. +#define OV5693_MWB_GREEN_GAIN_L_REG 0x3403
  2118. +#define OV5693_MWB_BLUE_GAIN_H_REG 0x3404
  2119. +#define OV5693_MWB_BLUE_GAIN_L_REG 0x3405
  2120. +#define OV5693_MWB_GAIN_H_CTRL(v) (((v) >> 8) & GENMASK(3, 0))
  2121. +#define OV5693_MWB_GAIN_L_CTRL(v) ((v) & GENMASK(7, 0))
  2122. +#define OV5693_MWB_GAIN_MAX 0x0fff
  2123. +#define OV5693_DIGITAL_GAIN_MIN 1
  2124. +#define OV5693_DIGITAL_GAIN_MAX 4095
  2125. +#define OV5693_DIGITAL_GAIN_DEF 1024
  2126. +#define OV5693_DIGITAL_GAIN_STEP 1
  2127. +
  2128. +/* Timing and Format */
  2129. +#define OV5693_CROP_START_X_H_REG 0x3800
  2130. +#define OV5693_CROP_START_X_H(v) (((v) & GENMASK(12, 8)) >> 8)
  2131. +#define OV5693_CROP_START_X_L_REG 0x3801
  2132. +#define OV5693_CROP_START_X_L(v) ((v) & GENMASK(7, 0))
  2133. +
  2134. +#define OV5693_CROP_START_Y_H_REG 0x3802
  2135. +#define OV5693_CROP_START_Y_H(v) (((v) & GENMASK(11, 8)) >> 8)
  2136. +#define OV5693_CROP_START_Y_L_REG 0x3803
  2137. +#define OV5693_CROP_START_Y_L(v) ((v) & GENMASK(7, 0))
  2138. +
  2139. +#define OV5693_CROP_END_X_H_REG 0x3804
  2140. +#define OV5693_CROP_END_X_H(v) (((v) & GENMASK(12, 8)) >> 8)
  2141. +#define OV5693_CROP_END_X_L_REG 0x3805
  2142. +#define OV5693_CROP_END_X_L(v) ((v) & GENMASK(7, 0))
  2143. +
  2144. +#define OV5693_CROP_END_Y_H_REG 0x3806
  2145. +#define OV5693_CROP_END_Y_H(v) (((v) & GENMASK(11, 8)) >> 8)
  2146. +#define OV5693_CROP_END_Y_L_REG 0x3807
  2147. +#define OV5693_CROP_END_Y_L(v) ((v) & GENMASK(7, 0))
  2148. +
  2149. +#define OV5693_OUTPUT_SIZE_X_H_REG 0x3808
  2150. +#define OV5693_OUTPUT_SIZE_X_H(v) (((v) & GENMASK(15, 8)) >> 8)
  2151. +#define OV5693_OUTPUT_SIZE_X_L_REG 0x3809
  2152. +#define OV5693_OUTPUT_SIZE_X_L(v) ((v) & GENMASK(7, 0))
  2153. +
  2154. +#define OV5693_OUTPUT_SIZE_Y_H_REG 0x380a
  2155. +#define OV5693_OUTPUT_SIZE_Y_H(v) (((v) & GENMASK(15, 8)) >> 8)
  2156. +#define OV5693_OUTPUT_SIZE_Y_L_REG 0x380b
  2157. +#define OV5693_OUTPUT_SIZE_Y_L(v) ((v) & GENMASK(7, 0))
  2158. +
  2159. +#define OV5693_TIMING_HTS_H_REG 0x380c
  2160. +#define OV5693_TIMING_HTS_H(v) (((v) & GENMASK(15, 8)) >> 8)
  2161. +#define OV5693_TIMING_HTS_L_REG 0x380d
  2162. +#define OV5693_TIMING_HTS_L(v) ((v) & GENMASK(7, 0))
  2163. +#define OV5693_FIXED_PPL 2688U
  2164. +
  2165. +#define OV5693_TIMING_VTS_H_REG 0x380e
  2166. +#define OV5693_TIMING_VTS_H(v) (((v) & GENMASK(15, 8)) >> 8)
  2167. +#define OV5693_TIMING_VTS_L_REG 0x380f
  2168. +#define OV5693_TIMING_VTS_L(v) ((v) & GENMASK(7, 0))
  2169. +#define OV5693_TIMING_MAX_VTS 0xffff
  2170. +#define OV5693_TIMING_MIN_VTS 0x04
  2171. +
  2172. +#define OV5693_OFFSET_START_X_H_REG 0x3810
  2173. +#define OV5693_OFFSET_START_X_H(v) (((v) & GENMASK(15, 8)) >> 8)
  2174. +#define OV5693_OFFSET_START_X_L_REG 0x3811
  2175. +#define OV5693_OFFSET_START_X_L(v) ((v) & GENMASK(7, 0))
  2176. +
  2177. +#define OV5693_OFFSET_START_Y_H_REG 0x3812
  2178. +#define OV5693_OFFSET_START_Y_H(v) (((v) & GENMASK(15, 8)) >> 8)
  2179. +#define OV5693_OFFSET_START_Y_L_REG 0x3813
  2180. +#define OV5693_OFFSET_START_Y_L(v) ((v) & GENMASK(7, 0))
  2181. +
  2182. +#define OV5693_SUB_INC_X_REG 0x3814
  2183. +#define OV5693_SUB_INC_Y_REG 0x3815
  2184. +
  2185. +#define OV5693_FORMAT1_REG 0x3820
  2186. +#define OV5693_FORMAT1_FLIP_VERT_ISP_EN BIT(2)
  2187. +#define OV5693_FORMAT1_FLIP_VERT_SENSOR_EN BIT(1)
  2188. +#define OV5693_FORMAT1_VBIN_EN BIT(0)
  2189. +#define OV5693_FORMAT2_REG 0x3821
  2190. +#define OV5693_FORMAT2_HDR_EN BIT(7)
  2191. +#define OV5693_FORMAT2_FLIP_HORZ_ISP_EN BIT(2)
  2192. +#define OV5693_FORMAT2_FLIP_HORZ_SENSOR_EN BIT(1)
  2193. +#define OV5693_FORMAT2_HBIN_EN BIT(0)
  2194. +
  2195. +#define OV5693_ISP_CTRL2_REG 0x5002
  2196. +#define OV5693_ISP_SCALE_ENABLE BIT(7)
  2197. +
  2198. +/* Pixel Array */
  2199. +#define OV5693_NATIVE_WIDTH 2624
  2200. +#define OV5693_NATIVE_HEIGHT 1956
  2201. +#define OV5693_NATIVE_START_LEFT 0
  2202. +#define OV5693_NATIVE_START_TOP 0
  2203. +#define OV5693_ACTIVE_WIDTH 2592
  2204. +#define OV5693_ACTIVE_HEIGHT 1944
  2205. +#define OV5693_ACTIVE_START_LEFT 16
  2206. +#define OV5693_ACTIVE_START_TOP 6
  2207. +#define OV5693_MIN_CROP_WIDTH 2
  2208. +#define OV5693_MIN_CROP_HEIGHT 2
  2209. +
  2210. +/* Test Pattern */
  2211. +#define OV5693_TEST_PATTERN_REG 0x5e00
  2212. +#define OV5693_TEST_PATTERN_ENABLE BIT(7)
  2213. +#define OV5693_TEST_PATTERN_ROLLING BIT(6)
  2214. +#define OV5693_TEST_PATTERN_RANDOM 0x01
  2215. +#define OV5693_TEST_PATTERN_BARS 0x00
  2216. +
  2217. +/* System Frequencies */
  2218. +#define OV5693_XVCLK_FREQ 19200000
  2219. +#define OV5693_LINK_FREQ_400MHZ 400000000
  2220. +#define OV5693_PIXEL_RATE 160000000
  2221. +
  2222. +/* Miscellaneous */
  2223. +#define OV5693_NUM_SUPPLIES 2
  2224. +
  2225. +#define to_ov5693_sensor(x) container_of(x, struct ov5693_device, sd)
  2226. +
  2227. +struct ov5693_reg {
  2228. + u16 reg;
  2229. + u8 val;
  2230. +};
  2231. +
  2232. +struct ov5693_reg_list {
  2233. + u32 num_regs;
  2234. + const struct ov5693_reg *regs;
  2235. +};
  2236. +
  2237. +struct ov5693_device {
  2238. + struct i2c_client *client;
  2239. + struct device *dev;
  2240. +
  2241. + /* Protect against concurrent changes to controls */
  2242. + struct mutex lock;
  2243. +
  2244. + struct gpio_desc *reset;
  2245. + struct gpio_desc *powerdown;
  2246. + struct regulator_bulk_data supplies[OV5693_NUM_SUPPLIES];
  2247. + struct clk *clk;
  2248. +
  2249. + struct ov5693_mode {
  2250. + struct v4l2_rect crop;
  2251. + struct v4l2_mbus_framefmt format;
  2252. + bool binning_x;
  2253. + bool binning_y;
  2254. + unsigned int inc_x_odd;
  2255. + unsigned int inc_y_odd;
  2256. + unsigned int vts;
  2257. + } mode;
  2258. + bool streaming;
  2259. +
  2260. + struct v4l2_subdev sd;
  2261. + struct media_pad pad;
  2262. +
  2263. + struct ov5693_v4l2_ctrls {
  2264. + struct v4l2_ctrl_handler handler;
  2265. + struct v4l2_ctrl *link_freq;
  2266. + struct v4l2_ctrl *pixel_rate;
  2267. + struct v4l2_ctrl *exposure;
  2268. + struct v4l2_ctrl *analogue_gain;
  2269. + struct v4l2_ctrl *digital_gain;
  2270. + struct v4l2_ctrl *hflip;
  2271. + struct v4l2_ctrl *vflip;
  2272. + struct v4l2_ctrl *hblank;
  2273. + struct v4l2_ctrl *vblank;
  2274. + struct v4l2_ctrl *test_pattern;
  2275. + } ctrls;
  2276. +};
  2277. +
  2278. +static const struct ov5693_reg ov5693_global_regs[] = {
  2279. + {0x3016, 0xf0},
  2280. + {0x3017, 0xf0},
  2281. + {0x3018, 0xf0},
  2282. + {0x3022, 0x01},
  2283. + {0x3028, 0x44},
  2284. + {0x3098, 0x02},
  2285. + {0x3099, 0x19},
  2286. + {0x309a, 0x02},
  2287. + {0x309b, 0x01},
  2288. + {0x309c, 0x00},
  2289. + {0x30a0, 0xd2},
  2290. + {0x30a2, 0x01},
  2291. + {0x30b2, 0x00},
  2292. + {0x30b3, 0x7d},
  2293. + {0x30b4, 0x03},
  2294. + {0x30b5, 0x04},
  2295. + {0x30b6, 0x01},
  2296. + {0x3104, 0x21},
  2297. + {0x3106, 0x00},
  2298. + {0x3406, 0x01},
  2299. + {0x3503, 0x07},
  2300. + {0x350b, 0x40},
  2301. + {0x3601, 0x0a},
  2302. + {0x3602, 0x38},
  2303. + {0x3612, 0x80},
  2304. + {0x3620, 0x54},
  2305. + {0x3621, 0xc7},
  2306. + {0x3622, 0x0f},
  2307. + {0x3625, 0x10},
  2308. + {0x3630, 0x55},
  2309. + {0x3631, 0xf4},
  2310. + {0x3632, 0x00},
  2311. + {0x3633, 0x34},
  2312. + {0x3634, 0x02},
  2313. + {0x364d, 0x0d},
  2314. + {0x364f, 0xdd},
  2315. + {0x3660, 0x04},
  2316. + {0x3662, 0x10},
  2317. + {0x3663, 0xf1},
  2318. + {0x3665, 0x00},
  2319. + {0x3666, 0x20},
  2320. + {0x3667, 0x00},
  2321. + {0x366a, 0x80},
  2322. + {0x3680, 0xe0},
  2323. + {0x3681, 0x00},
  2324. + {0x3700, 0x42},
  2325. + {0x3701, 0x14},
  2326. + {0x3702, 0xa0},
  2327. + {0x3703, 0xd8},
  2328. + {0x3704, 0x78},
  2329. + {0x3705, 0x02},
  2330. + {0x370a, 0x00},
  2331. + {0x370b, 0x20},
  2332. + {0x370c, 0x0c},
  2333. + {0x370d, 0x11},
  2334. + {0x370e, 0x00},
  2335. + {0x370f, 0x40},
  2336. + {0x3710, 0x00},
  2337. + {0x371a, 0x1c},
  2338. + {0x371b, 0x05},
  2339. + {0x371c, 0x01},
  2340. + {0x371e, 0xa1},
  2341. + {0x371f, 0x0c},
  2342. + {0x3721, 0x00},
  2343. + {0x3724, 0x10},
  2344. + {0x3726, 0x00},
  2345. + {0x372a, 0x01},
  2346. + {0x3730, 0x10},
  2347. + {0x3738, 0x22},
  2348. + {0x3739, 0xe5},
  2349. + {0x373a, 0x50},
  2350. + {0x373b, 0x02},
  2351. + {0x373c, 0x41},
  2352. + {0x373f, 0x02},
  2353. + {0x3740, 0x42},
  2354. + {0x3741, 0x02},
  2355. + {0x3742, 0x18},
  2356. + {0x3743, 0x01},
  2357. + {0x3744, 0x02},
  2358. + {0x3747, 0x10},
  2359. + {0x374c, 0x04},
  2360. + {0x3751, 0xf0},
  2361. + {0x3752, 0x00},
  2362. + {0x3753, 0x00},
  2363. + {0x3754, 0xc0},
  2364. + {0x3755, 0x00},
  2365. + {0x3756, 0x1a},
  2366. + {0x3758, 0x00},
  2367. + {0x3759, 0x0f},
  2368. + {0x376b, 0x44},
  2369. + {0x375c, 0x04},
  2370. + {0x3774, 0x10},
  2371. + {0x3776, 0x00},
  2372. + {0x377f, 0x08},
  2373. + {0x3780, 0x22},
  2374. + {0x3781, 0x0c},
  2375. + {0x3784, 0x2c},
  2376. + {0x3785, 0x1e},
  2377. + {0x378f, 0xf5},
  2378. + {0x3791, 0xb0},
  2379. + {0x3795, 0x00},
  2380. + {0x3796, 0x64},
  2381. + {0x3797, 0x11},
  2382. + {0x3798, 0x30},
  2383. + {0x3799, 0x41},
  2384. + {0x379a, 0x07},
  2385. + {0x379b, 0xb0},
  2386. + {0x379c, 0x0c},
  2387. + {0x3a04, 0x06},
  2388. + {0x3a05, 0x14},
  2389. + {0x3e07, 0x20},
  2390. + {0x4000, 0x08},
  2391. + {0x4001, 0x04},
  2392. + {0x4004, 0x08},
  2393. + {0x4006, 0x20},
  2394. + {0x4008, 0x24},
  2395. + {0x4009, 0x10},
  2396. + {0x4058, 0x00},
  2397. + {0x4101, 0xb2},
  2398. + {0x4307, 0x31},
  2399. + {0x4511, 0x05},
  2400. + {0x4512, 0x01},
  2401. + {0x481f, 0x30},
  2402. + {0x4826, 0x2c},
  2403. + {0x4d02, 0xfd},
  2404. + {0x4d03, 0xf5},
  2405. + {0x4d04, 0x0c},
  2406. + {0x4d05, 0xcc},
  2407. + {0x4837, 0x0a},
  2408. + {0x5003, 0x20},
  2409. + {0x5013, 0x00},
  2410. + {0x5842, 0x01},
  2411. + {0x5843, 0x2b},
  2412. + {0x5844, 0x01},
  2413. + {0x5845, 0x92},
  2414. + {0x5846, 0x01},
  2415. + {0x5847, 0x8f},
  2416. + {0x5848, 0x01},
  2417. + {0x5849, 0x0c},
  2418. + {0x5e10, 0x0c},
  2419. + {0x3820, 0x00},
  2420. + {0x3821, 0x1e},
  2421. + {0x5041, 0x14}
  2422. +};
  2423. +
  2424. +static const struct ov5693_reg_list ov5693_global_setting = {
  2425. + .num_regs = ARRAY_SIZE(ov5693_global_regs),
  2426. + .regs = ov5693_global_regs,
  2427. +};
  2428. +
  2429. +static const struct v4l2_rect ov5693_default_crop = {
  2430. + .left = OV5693_ACTIVE_START_LEFT,
  2431. + .top = OV5693_ACTIVE_START_TOP,
  2432. + .width = OV5693_ACTIVE_WIDTH,
  2433. + .height = OV5693_ACTIVE_HEIGHT,
  2434. +};
  2435. +
  2436. +static const struct v4l2_mbus_framefmt ov5693_default_fmt = {
  2437. + .width = OV5693_ACTIVE_WIDTH,
  2438. + .height = OV5693_ACTIVE_HEIGHT,
  2439. + .code = MEDIA_BUS_FMT_SBGGR10_1X10,
  2440. +};
  2441. +
  2442. +static const s64 link_freq_menu_items[] = {
  2443. + OV5693_LINK_FREQ_400MHZ
  2444. +};
  2445. +
  2446. +static const char * const ov5693_supply_names[] = {
  2447. + "avdd",
  2448. + "dovdd",
  2449. +};
  2450. +
  2451. +static const char * const ov5693_test_pattern_menu[] = {
  2452. + "Disabled",
  2453. + "Random Data",
  2454. + "Colour Bars",
  2455. + "Colour Bars with Rolling Bar"
  2456. +};
  2457. +
  2458. +static const u8 ov5693_test_pattern_bits[] = {
  2459. + 0,
  2460. + OV5693_TEST_PATTERN_ENABLE | OV5693_TEST_PATTERN_RANDOM,
  2461. + OV5693_TEST_PATTERN_ENABLE | OV5693_TEST_PATTERN_BARS,
  2462. + OV5693_TEST_PATTERN_ENABLE | OV5693_TEST_PATTERN_BARS |
  2463. + OV5693_TEST_PATTERN_ROLLING,
  2464. +};
  2465. +
  2466. +/* I2C I/O Operations */
  2467. +
  2468. +static int ov5693_read_reg(struct ov5693_device *ov5693, u16 addr, u8 *value)
  2469. +{
  2470. + struct i2c_client *client = ov5693->client;
  2471. + struct i2c_msg msgs[2];
  2472. + u8 addr_buf[2];
  2473. + u8 data_buf;
  2474. + int ret;
  2475. +
  2476. + put_unaligned_be16(addr, addr_buf);
  2477. +
  2478. + /* Write register address */
  2479. + msgs[0].addr = client->addr;
  2480. + msgs[0].flags = 0;
  2481. + msgs[0].len = ARRAY_SIZE(addr_buf);
  2482. + msgs[0].buf = addr_buf;
  2483. +
  2484. + /* Read register value */
  2485. + msgs[1].addr = client->addr;
  2486. + msgs[1].flags = I2C_M_RD;
  2487. + msgs[1].len = 1;
  2488. + msgs[1].buf = &data_buf;
  2489. +
  2490. + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
  2491. + if (ret != ARRAY_SIZE(msgs))
  2492. + return -EIO;
  2493. +
  2494. + *value = data_buf;
  2495. +
  2496. + return 0;
  2497. +}
  2498. +
  2499. +static void ov5693_write_reg(struct ov5693_device *ov5693, u16 addr, u8 value,
  2500. + int *error)
  2501. +{
  2502. + unsigned char data[3] = { addr >> 8, addr & 0xff, value };
  2503. + int ret;
  2504. +
  2505. + if (*error < 0)
  2506. + return;
  2507. +
  2508. + ret = i2c_master_send(ov5693->client, data, sizeof(data));
  2509. + if (ret < 0) {
  2510. + dev_dbg(ov5693->dev, "i2c send error at address 0x%04x: %d\n",
  2511. + addr, ret);
  2512. + *error = ret;
  2513. + }
  2514. +}
  2515. +
  2516. +static int ov5693_write_reg_array(struct ov5693_device *ov5693,
  2517. + const struct ov5693_reg_list *reglist)
  2518. +{
  2519. + unsigned int i;
  2520. + int ret = 0;
  2521. +
  2522. + for (i = 0; i < reglist->num_regs; i++)
  2523. + ov5693_write_reg(ov5693, reglist->regs[i].reg,
  2524. + reglist->regs[i].val, &ret);
  2525. +
  2526. + return ret;
  2527. +}
  2528. +
  2529. +static int ov5693_update_bits(struct ov5693_device *ov5693, u16 address,
  2530. + u16 mask, u16 bits)
  2531. +{
  2532. + u8 value = 0;
  2533. + int ret;
  2534. +
  2535. + ret = ov5693_read_reg(ov5693, address, &value);
  2536. + if (ret)
  2537. + return ret;
  2538. +
  2539. + value &= ~mask;
  2540. + value |= bits;
  2541. +
  2542. + ov5693_write_reg(ov5693, address, value, &ret);
  2543. +
  2544. + return ret;
  2545. +}
  2546. +
  2547. +/* V4L2 Controls Functions */
  2548. +
  2549. +static int ov5693_flip_vert_configure(struct ov5693_device *ov5693, bool enable)
  2550. +{
  2551. + u8 bits = OV5693_FORMAT1_FLIP_VERT_ISP_EN |
  2552. + OV5693_FORMAT1_FLIP_VERT_SENSOR_EN;
  2553. + int ret;
  2554. +
  2555. + ret = ov5693_update_bits(ov5693, OV5693_FORMAT1_REG, bits,
  2556. + enable ? bits : 0);
  2557. + if (ret)
  2558. + return ret;
  2559. +
  2560. + return 0;
  2561. +}
  2562. +
  2563. +static int ov5693_flip_horz_configure(struct ov5693_device *ov5693, bool enable)
  2564. +{
  2565. + u8 bits = OV5693_FORMAT2_FLIP_HORZ_ISP_EN |
  2566. + OV5693_FORMAT2_FLIP_HORZ_SENSOR_EN;
  2567. + int ret;
  2568. +
  2569. + ret = ov5693_update_bits(ov5693, OV5693_FORMAT2_REG, bits,
  2570. + enable ? bits : 0);
  2571. + if (ret)
  2572. + return ret;
  2573. +
  2574. + return 0;
  2575. +}
  2576. +
  2577. +static int ov5693_get_exposure(struct ov5693_device *ov5693, s32 *value)
  2578. +{
  2579. + u8 exposure_hh = 0, exposure_h = 0, exposure_l = 0;
  2580. + int ret;
  2581. +
  2582. + ret = ov5693_read_reg(ov5693, OV5693_EXPOSURE_L_CTRL_HH_REG, &exposure_hh);
  2583. + if (ret)
  2584. + return ret;
  2585. +
  2586. + ret = ov5693_read_reg(ov5693, OV5693_EXPOSURE_L_CTRL_H_REG, &exposure_h);
  2587. + if (ret)
  2588. + return ret;
  2589. +
  2590. + ret = ov5693_read_reg(ov5693, OV5693_EXPOSURE_L_CTRL_L_REG, &exposure_l);
  2591. + if (ret)
  2592. + return ret;
  2593. +
  2594. + /* The lowest 4 bits are unsupported fractional bits */
  2595. + *value = ((exposure_hh << 16) | (exposure_h << 8) | exposure_l) >> 4;
  2596. +
  2597. + return 0;
  2598. +}
  2599. +
  2600. +static int ov5693_exposure_configure(struct ov5693_device *ov5693, u32 exposure)
  2601. +{
  2602. + int ret = 0;
  2603. +
  2604. + ov5693_write_reg(ov5693, OV5693_EXPOSURE_L_CTRL_HH_REG,
  2605. + OV5693_EXPOSURE_CTRL_HH(exposure), &ret);
  2606. + ov5693_write_reg(ov5693, OV5693_EXPOSURE_L_CTRL_H_REG,
  2607. + OV5693_EXPOSURE_CTRL_H(exposure), &ret);
  2608. + ov5693_write_reg(ov5693, OV5693_EXPOSURE_L_CTRL_L_REG,
  2609. + OV5693_EXPOSURE_CTRL_L(exposure), &ret);
  2610. +
  2611. + return ret;
  2612. +}
  2613. +
  2614. +static int ov5693_get_gain(struct ov5693_device *ov5693, u32 *gain)
  2615. +{
  2616. + u8 gain_l = 0, gain_h = 0;
  2617. + int ret;
  2618. +
  2619. + ret = ov5693_read_reg(ov5693, OV5693_GAIN_CTRL_H_REG, &gain_h);
  2620. + if (ret)
  2621. + return ret;
  2622. +
  2623. + ret = ov5693_read_reg(ov5693, OV5693_GAIN_CTRL_L_REG, &gain_l);
  2624. + if (ret)
  2625. + return ret;
  2626. +
  2627. + /* As with exposure, the lowest 4 bits are fractional bits. */
  2628. + *gain = ((gain_h << 8) | gain_l) >> 4;
  2629. +
  2630. + return ret;
  2631. +}
  2632. +
  2633. +static int ov5693_digital_gain_configure(struct ov5693_device *ov5693, u32 gain)
  2634. +{
  2635. + int ret = 0;
  2636. +
  2637. + ov5693_write_reg(ov5693, OV5693_MWB_RED_GAIN_H_REG,
  2638. + OV5693_MWB_GAIN_H_CTRL(gain), &ret);
  2639. + ov5693_write_reg(ov5693, OV5693_MWB_RED_GAIN_L_REG,
  2640. + OV5693_MWB_GAIN_L_CTRL(gain), &ret);
  2641. + ov5693_write_reg(ov5693, OV5693_MWB_GREEN_GAIN_H_REG,
  2642. + OV5693_MWB_GAIN_H_CTRL(gain), &ret);
  2643. + ov5693_write_reg(ov5693, OV5693_MWB_GREEN_GAIN_L_REG,
  2644. + OV5693_MWB_GAIN_L_CTRL(gain), &ret);
  2645. + ov5693_write_reg(ov5693, OV5693_MWB_BLUE_GAIN_H_REG,
  2646. + OV5693_MWB_GAIN_H_CTRL(gain), &ret);
  2647. + ov5693_write_reg(ov5693, OV5693_MWB_BLUE_GAIN_L_REG,
  2648. + OV5693_MWB_GAIN_L_CTRL(gain), &ret);
  2649. +
  2650. + return ret;
  2651. +}
  2652. +
  2653. +static int ov5693_analog_gain_configure(struct ov5693_device *ov5693, u32 gain)
  2654. +{
  2655. + int ret = 0;
  2656. +
  2657. + ov5693_write_reg(ov5693, OV5693_GAIN_CTRL_L_REG,
  2658. + OV5693_GAIN_CTRL_L(gain), &ret);
  2659. + ov5693_write_reg(ov5693, OV5693_GAIN_CTRL_H_REG,
  2660. + OV5693_GAIN_CTRL_H(gain), &ret);
  2661. +
  2662. + return ret;
  2663. +}
  2664. +
  2665. +static int ov5693_vts_configure(struct ov5693_device *ov5693, u32 vblank)
  2666. +{
  2667. + u16 vts = ov5693->mode.format.height + vblank;
  2668. + int ret = 0;
  2669. +
  2670. + ov5693_write_reg(ov5693, OV5693_TIMING_VTS_H_REG,
  2671. + OV5693_TIMING_VTS_H(vts), &ret);
  2672. + ov5693_write_reg(ov5693, OV5693_TIMING_VTS_L_REG,
  2673. + OV5693_TIMING_VTS_L(vts), &ret);
  2674. +
  2675. + return ret;
  2676. +}
  2677. +
  2678. +static int ov5693_test_pattern_configure(struct ov5693_device *ov5693, u32 idx)
  2679. +{
  2680. + int ret = 0;
  2681. +
  2682. + ov5693_write_reg(ov5693, OV5693_TEST_PATTERN_REG,
  2683. + ov5693_test_pattern_bits[idx], &ret);
  2684. +
  2685. + return ret;
  2686. +}
  2687. +
  2688. +static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
  2689. +{
  2690. + struct ov5693_device *ov5693 =
  2691. + container_of(ctrl->handler, struct ov5693_device, ctrls.handler);
  2692. + int ret = 0;
  2693. +
  2694. + /* If VBLANK is altered we need to update exposure to compensate */
  2695. + if (ctrl->id == V4L2_CID_VBLANK) {
  2696. + int exposure_max;
  2697. +
  2698. + exposure_max = ov5693->mode.format.height + ctrl->val -
  2699. + OV5693_INTEGRATION_TIME_MARGIN;
  2700. + __v4l2_ctrl_modify_range(ov5693->ctrls.exposure,
  2701. + ov5693->ctrls.exposure->minimum,
  2702. + exposure_max,
  2703. + ov5693->ctrls.exposure->step,
  2704. + min(ov5693->ctrls.exposure->val, exposure_max));
  2705. + }
  2706. +
  2707. + /* Only apply changes to the controls if the device is powered up */
  2708. + if (!pm_runtime_get_if_in_use(ov5693->dev))
  2709. + return 0;
  2710. +
  2711. + switch (ctrl->id) {
  2712. + case V4L2_CID_EXPOSURE:
  2713. + ret = ov5693_exposure_configure(ov5693, ctrl->val);
  2714. + break;
  2715. + case V4L2_CID_ANALOGUE_GAIN:
  2716. + ret = ov5693_analog_gain_configure(ov5693, ctrl->val);
  2717. + break;
  2718. + case V4L2_CID_DIGITAL_GAIN:
  2719. + ret = ov5693_digital_gain_configure(ov5693, ctrl->val);
  2720. + break;
  2721. + case V4L2_CID_HFLIP:
  2722. + ret = ov5693_flip_horz_configure(ov5693, !!ctrl->val);
  2723. + break;
  2724. + case V4L2_CID_VFLIP:
  2725. + ret = ov5693_flip_vert_configure(ov5693, !!ctrl->val);
  2726. + break;
  2727. + case V4L2_CID_VBLANK:
  2728. + ret = ov5693_vts_configure(ov5693, ctrl->val);
  2729. + break;
  2730. + case V4L2_CID_TEST_PATTERN:
  2731. + ret = ov5693_test_pattern_configure(ov5693, ctrl->val);
  2732. + break;
  2733. + default:
  2734. + ret = -EINVAL;
  2735. + }
  2736. +
  2737. + pm_runtime_put(ov5693->dev);
  2738. +
  2739. + return ret;
  2740. +}
  2741. +
  2742. +static int ov5693_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
  2743. +{
  2744. + struct ov5693_device *ov5693 =
  2745. + container_of(ctrl->handler, struct ov5693_device, ctrls.handler);
  2746. +
  2747. + switch (ctrl->id) {
  2748. + case V4L2_CID_EXPOSURE_ABSOLUTE:
  2749. + return ov5693_get_exposure(ov5693, &ctrl->val);
  2750. + case V4L2_CID_AUTOGAIN:
  2751. + return ov5693_get_gain(ov5693, &ctrl->val);
  2752. + default:
  2753. + return -EINVAL;
  2754. + }
  2755. +}
  2756. +
  2757. +static const struct v4l2_ctrl_ops ov5693_ctrl_ops = {
  2758. + .s_ctrl = ov5693_s_ctrl,
  2759. + .g_volatile_ctrl = ov5693_g_volatile_ctrl
  2760. +};
  2761. +
  2762. +/* System Control Functions */
  2763. +
  2764. +static int ov5693_mode_configure(struct ov5693_device *ov5693)
  2765. +{
  2766. + const struct ov5693_mode *mode = &ov5693->mode;
  2767. + int ret = 0;
  2768. +
  2769. + /* Crop Start X */
  2770. + ov5693_write_reg(ov5693, OV5693_CROP_START_X_H_REG,
  2771. + OV5693_CROP_START_X_H(mode->crop.left), &ret);
  2772. + ov5693_write_reg(ov5693, OV5693_CROP_START_X_L_REG,
  2773. + OV5693_CROP_START_X_L(mode->crop.left), &ret);
  2774. +
  2775. + /* Offset X */
  2776. + ov5693_write_reg(ov5693, OV5693_OFFSET_START_X_H_REG,
  2777. + OV5693_OFFSET_START_X_H(0), &ret);
  2778. + ov5693_write_reg(ov5693, OV5693_OFFSET_START_X_L_REG,
  2779. + OV5693_OFFSET_START_X_L(0), &ret);
  2780. +
  2781. + /* Output Size X */
  2782. + ov5693_write_reg(ov5693, OV5693_OUTPUT_SIZE_X_H_REG,
  2783. + OV5693_OUTPUT_SIZE_X_H(mode->format.width), &ret);
  2784. + ov5693_write_reg(ov5693, OV5693_OUTPUT_SIZE_X_L_REG,
  2785. + OV5693_OUTPUT_SIZE_X_L(mode->format.width), &ret);
  2786. +
  2787. + /* Crop End X */
  2788. + ov5693_write_reg(ov5693, OV5693_CROP_END_X_H_REG,
  2789. + OV5693_CROP_END_X_H(mode->crop.left + mode->crop.width),
  2790. + &ret);
  2791. + ov5693_write_reg(ov5693, OV5693_CROP_END_X_L_REG,
  2792. + OV5693_CROP_END_X_L(mode->crop.left + mode->crop.width),
  2793. + &ret);
  2794. +
  2795. + /* Horizontal Total Size */
  2796. + ov5693_write_reg(ov5693, OV5693_TIMING_HTS_H_REG,
  2797. + OV5693_TIMING_HTS_H(OV5693_FIXED_PPL), &ret);
  2798. + ov5693_write_reg(ov5693, OV5693_TIMING_HTS_L_REG,
  2799. + OV5693_TIMING_HTS_L(OV5693_FIXED_PPL), &ret);
  2800. +
  2801. + /* Crop Start Y */
  2802. + ov5693_write_reg(ov5693, OV5693_CROP_START_Y_H_REG,
  2803. + OV5693_CROP_START_Y_H(mode->crop.top), &ret);
  2804. + ov5693_write_reg(ov5693, OV5693_CROP_START_Y_L_REG,
  2805. + OV5693_CROP_START_Y_L(mode->crop.top), &ret);
  2806. +
  2807. + /* Offset Y */
  2808. + ov5693_write_reg(ov5693, OV5693_OFFSET_START_Y_H_REG,
  2809. + OV5693_OFFSET_START_Y_H(0), &ret);
  2810. + ov5693_write_reg(ov5693, OV5693_OFFSET_START_Y_L_REG,
  2811. + OV5693_OFFSET_START_Y_L(0), &ret);
  2812. +
  2813. + /* Output Size Y */
  2814. + ov5693_write_reg(ov5693, OV5693_OUTPUT_SIZE_Y_H_REG,
  2815. + OV5693_OUTPUT_SIZE_Y_H(mode->format.height), &ret);
  2816. + ov5693_write_reg(ov5693, OV5693_OUTPUT_SIZE_Y_L_REG,
  2817. + OV5693_OUTPUT_SIZE_Y_L(mode->format.height), &ret);
  2818. +
  2819. + /* Crop End Y */
  2820. + ov5693_write_reg(ov5693, OV5693_CROP_END_Y_H_REG,
  2821. + OV5693_CROP_END_Y_H(mode->crop.top + mode->crop.height),
  2822. + &ret);
  2823. + ov5693_write_reg(ov5693, OV5693_CROP_END_Y_L_REG,
  2824. + OV5693_CROP_END_Y_L(mode->crop.top + mode->crop.height),
  2825. + &ret);
  2826. +
  2827. + /* Vertical Total Size */
  2828. + ov5693_write_reg(ov5693, OV5693_TIMING_VTS_H_REG,
  2829. + OV5693_TIMING_VTS_H(mode->vts), &ret);
  2830. + ov5693_write_reg(ov5693, OV5693_TIMING_VTS_L_REG,
  2831. + OV5693_TIMING_VTS_L(mode->vts), &ret);
  2832. +
  2833. + /* Subsample X increase */
  2834. + ov5693_write_reg(ov5693, OV5693_SUB_INC_X_REG,
  2835. + ((mode->inc_x_odd << 4) & 0xf0) | 0x01, &ret);
  2836. + /* Subsample Y increase */
  2837. + ov5693_write_reg(ov5693, OV5693_SUB_INC_Y_REG,
  2838. + ((mode->inc_y_odd << 4) & 0xf0) | 0x01, &ret);
  2839. +
  2840. + /* Binning */
  2841. + ret = ov5693_update_bits(ov5693, OV5693_FORMAT1_REG,
  2842. + OV5693_FORMAT1_VBIN_EN,
  2843. + mode->binning_y ? OV5693_FORMAT1_VBIN_EN : 0);
  2844. + if (ret)
  2845. + return ret;
  2846. +
  2847. + ret = ov5693_update_bits(ov5693, OV5693_FORMAT2_REG,
  2848. + OV5693_FORMAT2_HBIN_EN,
  2849. + mode->binning_x ? OV5693_FORMAT2_HBIN_EN : 0);
  2850. +
  2851. + return ret;
  2852. +}
  2853. +
  2854. +static int ov5693_sw_standby(struct ov5693_device *ov5693, bool standby)
  2855. +{
  2856. + int ret = 0;
  2857. +
  2858. + ov5693_write_reg(ov5693, OV5693_SW_STREAM_REG,
  2859. + standby ? OV5693_STOP_STREAMING : OV5693_START_STREAMING,
  2860. + &ret);
  2861. +
  2862. + return ret;
  2863. +}
  2864. +
  2865. +static int ov5693_sw_reset(struct ov5693_device *ov5693)
  2866. +{
  2867. + int ret = 0;
  2868. +
  2869. + ov5693_write_reg(ov5693, OV5693_SW_RESET_REG, OV5693_SW_RESET, &ret);
  2870. +
  2871. + return ret;
  2872. +}
  2873. +
  2874. +static int ov5693_sensor_init(struct ov5693_device *ov5693)
  2875. +{
  2876. + int ret = 0;
  2877. +
  2878. + ret = ov5693_sw_reset(ov5693);
  2879. + if (ret) {
  2880. + dev_err(ov5693->dev, "%s software reset error\n", __func__);
  2881. + return ret;
  2882. + }
  2883. +
  2884. + ret = ov5693_write_reg_array(ov5693, &ov5693_global_setting);
  2885. + if (ret) {
  2886. + dev_err(ov5693->dev, "%s global settings error\n", __func__);
  2887. + return ret;
  2888. + }
  2889. +
  2890. + ret = ov5693_mode_configure(ov5693);
  2891. + if (ret) {
  2892. + dev_err(ov5693->dev, "%s mode configure error\n", __func__);
  2893. + return ret;
  2894. + }
  2895. +
  2896. + ret = ov5693_sw_standby(ov5693, true);
  2897. + if (ret)
  2898. + dev_err(ov5693->dev, "%s software standby error\n", __func__);
  2899. +
  2900. + return ret;
  2901. +}
  2902. +
  2903. +static void ov5693_sensor_powerdown(struct ov5693_device *ov5693)
  2904. +{
  2905. + gpiod_set_value_cansleep(ov5693->reset, 1);
  2906. + gpiod_set_value_cansleep(ov5693->powerdown, 1);
  2907. +
  2908. + regulator_bulk_disable(OV5693_NUM_SUPPLIES, ov5693->supplies);
  2909. +
  2910. + clk_disable_unprepare(ov5693->clk);
  2911. +}
  2912. +
  2913. +static int ov5693_sensor_powerup(struct ov5693_device *ov5693)
  2914. +{
  2915. + int ret;
  2916. +
  2917. + gpiod_set_value_cansleep(ov5693->reset, 1);
  2918. + gpiod_set_value_cansleep(ov5693->powerdown, 1);
  2919. +
  2920. + ret = clk_prepare_enable(ov5693->clk);
  2921. + if (ret) {
  2922. + dev_err(ov5693->dev, "Failed to enable clk\n");
  2923. + goto fail_power;
  2924. + }
  2925. +
  2926. + ret = regulator_bulk_enable(OV5693_NUM_SUPPLIES, ov5693->supplies);
  2927. + if (ret) {
  2928. + dev_err(ov5693->dev, "Failed to enable regulators\n");
  2929. + goto fail_power;
  2930. + }
  2931. +
  2932. + gpiod_set_value_cansleep(ov5693->powerdown, 0);
  2933. + gpiod_set_value_cansleep(ov5693->reset, 0);
  2934. +
  2935. + usleep_range(5000, 7500);
  2936. +
  2937. + return 0;
  2938. +
  2939. +fail_power:
  2940. + ov5693_sensor_powerdown(ov5693);
  2941. + return ret;
  2942. +}
  2943. +
  2944. +static int __maybe_unused ov5693_sensor_suspend(struct device *dev)
  2945. +{
  2946. + struct v4l2_subdev *sd = dev_get_drvdata(dev);
  2947. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  2948. +
  2949. + ov5693_sensor_powerdown(ov5693);
  2950. +
  2951. + return 0;
  2952. +}
  2953. +
  2954. +static int __maybe_unused ov5693_sensor_resume(struct device *dev)
  2955. +{
  2956. + struct v4l2_subdev *sd = dev_get_drvdata(dev);
  2957. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  2958. + int ret;
  2959. +
  2960. + mutex_lock(&ov5693->lock);
  2961. +
  2962. + ret = ov5693_sensor_powerup(ov5693);
  2963. + if (ret)
  2964. + goto out_unlock;
  2965. +
  2966. + ret = ov5693_sensor_init(ov5693);
  2967. + if (ret) {
  2968. + dev_err(dev, "ov5693 sensor init failure\n");
  2969. + goto err_power;
  2970. + }
  2971. +
  2972. + goto out_unlock;
  2973. +
  2974. +err_power:
  2975. + ov5693_sensor_powerdown(ov5693);
  2976. +out_unlock:
  2977. + mutex_unlock(&ov5693->lock);
  2978. + return ret;
  2979. +}
  2980. +
  2981. +static int ov5693_detect(struct ov5693_device *ov5693)
  2982. +{
  2983. + u8 id_l = 0, id_h = 0;
  2984. + u16 id = 0;
  2985. + int ret;
  2986. +
  2987. + ret = ov5693_read_reg(ov5693, OV5693_REG_CHIP_ID_H, &id_h);
  2988. + if (ret)
  2989. + return ret;
  2990. +
  2991. + ret = ov5693_read_reg(ov5693, OV5693_REG_CHIP_ID_L, &id_l);
  2992. + if (ret)
  2993. + return ret;
  2994. +
  2995. + id = (id_h << 8) | id_l;
  2996. +
  2997. + if (id != OV5693_CHIP_ID) {
  2998. + dev_err(ov5693->dev, "sensor ID mismatch. Found 0x%04x\n", id);
  2999. + return -ENODEV;
  3000. + }
  3001. +
  3002. + return 0;
  3003. +}
  3004. +
  3005. +/* V4L2 Framework callbacks */
  3006. +
  3007. +static unsigned int __ov5693_calc_vts(u32 height)
  3008. +{
  3009. + /*
  3010. + * We need to set a sensible default VTS for whatever format height we
  3011. + * happen to be given from set_fmt(). This function just targets
  3012. + * an even multiple of 30fps.
  3013. + */
  3014. +
  3015. + unsigned int tgt_fps;
  3016. +
  3017. + tgt_fps = rounddown(OV5693_PIXEL_RATE / OV5693_FIXED_PPL / height, 30);
  3018. +
  3019. + return ALIGN_DOWN(OV5693_PIXEL_RATE / OV5693_FIXED_PPL / tgt_fps, 2);
  3020. +}
  3021. +
  3022. +static struct v4l2_mbus_framefmt *
  3023. +__ov5693_get_pad_format(struct ov5693_device *ov5693,
  3024. + struct v4l2_subdev_pad_config *cfg,
  3025. + unsigned int pad, enum v4l2_subdev_format_whence which)
  3026. +{
  3027. + switch (which) {
  3028. + case V4L2_SUBDEV_FORMAT_TRY:
  3029. + return v4l2_subdev_get_try_format(&ov5693->sd, cfg, pad);
  3030. + case V4L2_SUBDEV_FORMAT_ACTIVE:
  3031. + return &ov5693->mode.format;
  3032. + default:
  3033. + return NULL;
  3034. + }
  3035. +}
  3036. +
  3037. +static struct v4l2_rect *
  3038. +__ov5693_get_pad_crop(struct ov5693_device *ov5693,
  3039. + struct v4l2_subdev_pad_config *cfg,
  3040. + unsigned int pad, enum v4l2_subdev_format_whence which)
  3041. +{
  3042. + switch (which) {
  3043. + case V4L2_SUBDEV_FORMAT_TRY:
  3044. + return v4l2_subdev_get_try_crop(&ov5693->sd, cfg, pad);
  3045. + case V4L2_SUBDEV_FORMAT_ACTIVE:
  3046. + return &ov5693->mode.crop;
  3047. + }
  3048. +
  3049. + return NULL;
  3050. +}
  3051. +
  3052. +static int ov5693_get_fmt(struct v4l2_subdev *sd,
  3053. + struct v4l2_subdev_pad_config *cfg,
  3054. + struct v4l2_subdev_format *format)
  3055. +{
  3056. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  3057. +
  3058. + format->format = ov5693->mode.format;
  3059. +
  3060. + return 0;
  3061. +}
  3062. +
  3063. +static int ov5693_set_fmt(struct v4l2_subdev *sd,
  3064. + struct v4l2_subdev_pad_config *cfg,
  3065. + struct v4l2_subdev_format *format)
  3066. +{
  3067. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  3068. + const struct v4l2_rect *crop;
  3069. + struct v4l2_mbus_framefmt *fmt;
  3070. + unsigned int hratio, vratio;
  3071. + unsigned int width, height;
  3072. + unsigned int hblank;
  3073. + int exposure_max;
  3074. + int ret = 0;
  3075. +
  3076. + crop = __ov5693_get_pad_crop(ov5693, cfg, format->pad, format->which);
  3077. +
  3078. + /*
  3079. + * Align to two to simplify the binning calculations below, and clamp
  3080. + * the requested format at the crop rectangle
  3081. + */
  3082. + width = clamp_t(unsigned int, ALIGN(format->format.width, 2),
  3083. + OV5693_MIN_CROP_WIDTH, crop->width);
  3084. + height = clamp_t(unsigned int, ALIGN(format->format.height, 2),
  3085. + OV5693_MIN_CROP_HEIGHT, crop->height);
  3086. +
  3087. + /*
  3088. + * We can only support setting either the dimensions of the crop rect
  3089. + * or those dimensions binned (separately) by a factor of two.
  3090. + */
  3091. + hratio = clamp_t(unsigned int, DIV_ROUND_CLOSEST(crop->width, width), 1, 2);
  3092. + vratio = clamp_t(unsigned int, DIV_ROUND_CLOSEST(crop->height, height), 1, 2);
  3093. +
  3094. + fmt = __ov5693_get_pad_format(ov5693, cfg, format->pad, format->which);
  3095. +
  3096. + fmt->width = crop->width / hratio;
  3097. + fmt->height = crop->height / vratio;
  3098. + fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
  3099. +
  3100. + format->format = *fmt;
  3101. +
  3102. + if (format->which == V4L2_SUBDEV_FORMAT_TRY)
  3103. + return ret;
  3104. +
  3105. + mutex_lock(&ov5693->lock);
  3106. +
  3107. + ov5693->mode.binning_x = hratio > 1 ? true : false;
  3108. + ov5693->mode.inc_x_odd = hratio > 1 ? 3 : 1;
  3109. + ov5693->mode.binning_y = vratio > 1 ? true : false;
  3110. + ov5693->mode.inc_y_odd = vratio > 1 ? 3 : 1;
  3111. +
  3112. + ov5693->mode.vts = __ov5693_calc_vts(fmt->height);
  3113. +
  3114. + __v4l2_ctrl_modify_range(ov5693->ctrls.vblank,
  3115. + OV5693_TIMING_MIN_VTS,
  3116. + OV5693_TIMING_MAX_VTS - fmt->height,
  3117. + 1, ov5693->mode.vts - fmt->height);
  3118. + __v4l2_ctrl_s_ctrl(ov5693->ctrls.vblank,
  3119. + ov5693->mode.vts - fmt->height);
  3120. +
  3121. + hblank = OV5693_FIXED_PPL - fmt->width;
  3122. + __v4l2_ctrl_modify_range(ov5693->ctrls.hblank, hblank, hblank, 1,
  3123. + hblank);
  3124. +
  3125. + exposure_max = ov5693->mode.vts - OV5693_INTEGRATION_TIME_MARGIN;
  3126. + __v4l2_ctrl_modify_range(ov5693->ctrls.exposure,
  3127. + ov5693->ctrls.exposure->minimum, exposure_max,
  3128. + ov5693->ctrls.exposure->step,
  3129. + min(ov5693->ctrls.exposure->val, exposure_max));
  3130. +
  3131. + mutex_unlock(&ov5693->lock);
  3132. + return ret;
  3133. +}
  3134. +
  3135. +static int ov5693_get_selection(struct v4l2_subdev *sd,
  3136. + struct v4l2_subdev_pad_config *cfg,
  3137. + struct v4l2_subdev_selection *sel)
  3138. +{
  3139. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  3140. +
  3141. + switch (sel->target) {
  3142. + case V4L2_SEL_TGT_CROP:
  3143. + mutex_lock(&ov5693->lock);
  3144. + sel->r = *__ov5693_get_pad_crop(ov5693, cfg, sel->pad,
  3145. + sel->which);
  3146. + mutex_unlock(&ov5693->lock);
  3147. + break;
  3148. + case V4L2_SEL_TGT_NATIVE_SIZE:
  3149. + sel->r.top = 0;
  3150. + sel->r.left = 0;
  3151. + sel->r.width = OV5693_NATIVE_WIDTH;
  3152. + sel->r.height = OV5693_NATIVE_HEIGHT;
  3153. + break;
  3154. + case V4L2_SEL_TGT_CROP_BOUNDS:
  3155. + case V4L2_SEL_TGT_CROP_DEFAULT:
  3156. + sel->r.top = OV5693_ACTIVE_START_TOP;
  3157. + sel->r.left = OV5693_ACTIVE_START_LEFT;
  3158. + sel->r.width = OV5693_ACTIVE_WIDTH;
  3159. + sel->r.height = OV5693_ACTIVE_HEIGHT;
  3160. + break;
  3161. + default:
  3162. + return -EINVAL;
  3163. + }
  3164. +
  3165. + return 0;
  3166. +}
  3167. +
  3168. +static int ov5693_set_selection(struct v4l2_subdev *sd,
  3169. + struct v4l2_subdev_pad_config *cfg,
  3170. + struct v4l2_subdev_selection *sel)
  3171. +{
  3172. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  3173. + struct v4l2_mbus_framefmt *format;
  3174. + struct v4l2_rect *__crop;
  3175. + struct v4l2_rect rect;
  3176. +
  3177. + if (sel->target != V4L2_SEL_TGT_CROP)
  3178. + return -EINVAL;
  3179. +
  3180. + /*
  3181. + * Clamp the boundaries of the crop rectangle to the size of the sensor
  3182. + * pixel array. Align to multiples of 2 to ensure Bayer pattern isn't
  3183. + * disrupted.
  3184. + */
  3185. + rect.left = clamp(ALIGN(sel->r.left, 2), OV5693_NATIVE_START_LEFT,
  3186. + OV5693_NATIVE_WIDTH);
  3187. + rect.top = clamp(ALIGN(sel->r.top, 2), OV5693_NATIVE_START_TOP,
  3188. + OV5693_NATIVE_HEIGHT);
  3189. + rect.width = clamp_t(unsigned int, ALIGN(sel->r.width, 2),
  3190. + OV5693_MIN_CROP_WIDTH, OV5693_NATIVE_WIDTH);
  3191. + rect.height = clamp_t(unsigned int, ALIGN(sel->r.height, 2),
  3192. + OV5693_MIN_CROP_HEIGHT, OV5693_NATIVE_HEIGHT);
  3193. +
  3194. + /* Make sure the crop rectangle isn't outside the bounds of the array */
  3195. + rect.width = min_t(unsigned int, rect.width,
  3196. + OV5693_NATIVE_WIDTH - rect.left);
  3197. + rect.height = min_t(unsigned int, rect.height,
  3198. + OV5693_NATIVE_HEIGHT - rect.top);
  3199. +
  3200. + __crop = __ov5693_get_pad_crop(ov5693, cfg, sel->pad, sel->which);
  3201. +
  3202. + if (rect.width != __crop->width || rect.height != __crop->height) {
  3203. + /*
  3204. + * Reset the output image size if the crop rectangle size has
  3205. + * been modified.
  3206. + */
  3207. + format = __ov5693_get_pad_format(ov5693, cfg, sel->pad, sel->which);
  3208. + format->width = rect.width;
  3209. + format->height = rect.height;
  3210. + }
  3211. +
  3212. + *__crop = rect;
  3213. + sel->r = rect;
  3214. +
  3215. + return 0;
  3216. +}
  3217. +
  3218. +static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
  3219. +{
  3220. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  3221. + int ret;
  3222. +
  3223. + if (enable) {
  3224. + ret = pm_runtime_get_sync(ov5693->dev);
  3225. + if (ret < 0)
  3226. + goto err_power_down;
  3227. +
  3228. + ret = __v4l2_ctrl_handler_setup(&ov5693->ctrls.handler);
  3229. + if (ret)
  3230. + goto err_power_down;
  3231. + }
  3232. +
  3233. + mutex_lock(&ov5693->lock);
  3234. + ret = ov5693_sw_standby(ov5693, !enable);
  3235. + mutex_unlock(&ov5693->lock);
  3236. +
  3237. + if (ret)
  3238. + goto err_power_down;
  3239. + ov5693->streaming = !!enable;
  3240. +
  3241. + if (!enable)
  3242. + pm_runtime_put(ov5693->dev);
  3243. +
  3244. + return 0;
  3245. +err_power_down:
  3246. + pm_runtime_put_noidle(ov5693->dev);
  3247. + return ret;
  3248. +}
  3249. +
  3250. +static int ov5693_g_frame_interval(struct v4l2_subdev *sd,
  3251. + struct v4l2_subdev_frame_interval *interval)
  3252. +{
  3253. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  3254. + unsigned int framesize = OV5693_FIXED_PPL * (ov5693->mode.format.height +
  3255. + ov5693->ctrls.vblank->val);
  3256. + unsigned int fps = DIV_ROUND_CLOSEST(OV5693_PIXEL_RATE, framesize);
  3257. +
  3258. + interval->interval.numerator = 1;
  3259. + interval->interval.denominator = fps;
  3260. +
  3261. + return 0;
  3262. +}
  3263. +
  3264. +static int ov5693_enum_mbus_code(struct v4l2_subdev *sd,
  3265. + struct v4l2_subdev_pad_config *cfg,
  3266. + struct v4l2_subdev_mbus_code_enum *code)
  3267. +{
  3268. + /* Only a single mbus format is supported */
  3269. + if (code->index > 0)
  3270. + return -EINVAL;
  3271. +
  3272. + code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
  3273. + return 0;
  3274. +}
  3275. +
  3276. +static int ov5693_enum_frame_size(struct v4l2_subdev *sd,
  3277. + struct v4l2_subdev_pad_config *cfg,
  3278. + struct v4l2_subdev_frame_size_enum *fse)
  3279. +{
  3280. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  3281. + struct v4l2_rect *__crop;
  3282. +
  3283. + if (fse->index > 1 || fse->code != MEDIA_BUS_FMT_SBGGR10_1X10)
  3284. + return -EINVAL;
  3285. +
  3286. + __crop = __ov5693_get_pad_crop(ov5693, cfg, fse->pad, fse->which);
  3287. + if (!__crop)
  3288. + return -EINVAL;
  3289. +
  3290. + fse->min_width = __crop->width / (fse->index + 1);
  3291. + fse->min_height = __crop->height / (fse->index + 1);
  3292. + fse->max_width = fse->min_width;
  3293. + fse->max_height = fse->min_height;
  3294. +
  3295. + return 0;
  3296. +}
  3297. +
  3298. +static const struct v4l2_subdev_video_ops ov5693_video_ops = {
  3299. + .s_stream = ov5693_s_stream,
  3300. + .g_frame_interval = ov5693_g_frame_interval,
  3301. +};
  3302. +
  3303. +static const struct v4l2_subdev_pad_ops ov5693_pad_ops = {
  3304. + .enum_mbus_code = ov5693_enum_mbus_code,
  3305. + .enum_frame_size = ov5693_enum_frame_size,
  3306. + .get_fmt = ov5693_get_fmt,
  3307. + .set_fmt = ov5693_set_fmt,
  3308. + .get_selection = ov5693_get_selection,
  3309. + .set_selection = ov5693_set_selection,
  3310. +};
  3311. +
  3312. +static const struct v4l2_subdev_ops ov5693_ops = {
  3313. + .video = &ov5693_video_ops,
  3314. + .pad = &ov5693_pad_ops,
  3315. +};
  3316. +
  3317. +/* Sensor and Driver Configuration Functions */
  3318. +
  3319. +static int ov5693_init_controls(struct ov5693_device *ov5693)
  3320. +{
  3321. + const struct v4l2_ctrl_ops *ops = &ov5693_ctrl_ops;
  3322. + struct v4l2_fwnode_device_properties props;
  3323. + int vblank_max, vblank_def;
  3324. + int exposure_max;
  3325. + int hblank;
  3326. + int ret;
  3327. +
  3328. + ret = v4l2_ctrl_handler_init(&ov5693->ctrls.handler, 12);
  3329. + if (ret)
  3330. + return ret;
  3331. +
  3332. + /* link freq */
  3333. + ov5693->ctrls.link_freq = v4l2_ctrl_new_int_menu(&ov5693->ctrls.handler,
  3334. + NULL, V4L2_CID_LINK_FREQ,
  3335. + 0, 0, link_freq_menu_items);
  3336. + if (ov5693->ctrls.link_freq)
  3337. + ov5693->ctrls.link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  3338. +
  3339. + /* pixel rate */
  3340. + ov5693->ctrls.pixel_rate = v4l2_ctrl_new_std(&ov5693->ctrls.handler, NULL,
  3341. + V4L2_CID_PIXEL_RATE, 0,
  3342. + OV5693_PIXEL_RATE, 1,
  3343. + OV5693_PIXEL_RATE);
  3344. +
  3345. + /* Exposure */
  3346. + exposure_max = ov5693->mode.vts - OV5693_INTEGRATION_TIME_MARGIN;
  3347. + ov5693->ctrls.exposure = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
  3348. + V4L2_CID_EXPOSURE,
  3349. + OV5693_EXPOSURE_MIN,
  3350. + exposure_max,
  3351. + OV5693_EXPOSURE_STEP,
  3352. + exposure_max);
  3353. +
  3354. + /* Gain */
  3355. + ov5693->ctrls.analogue_gain = v4l2_ctrl_new_std(&ov5693->ctrls.handler,
  3356. + ops, V4L2_CID_ANALOGUE_GAIN,
  3357. + OV5693_GAIN_MIN,
  3358. + OV5693_GAIN_MAX,
  3359. + OV5693_GAIN_STEP,
  3360. + OV5693_GAIN_DEF);
  3361. +
  3362. + ov5693->ctrls.digital_gain = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
  3363. + V4L2_CID_DIGITAL_GAIN,
  3364. + OV5693_DIGITAL_GAIN_MIN,
  3365. + OV5693_DIGITAL_GAIN_MAX,
  3366. + OV5693_DIGITAL_GAIN_STEP,
  3367. + OV5693_DIGITAL_GAIN_DEF);
  3368. +
  3369. + /* Flip */
  3370. + ov5693->ctrls.hflip = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
  3371. + V4L2_CID_HFLIP, 0, 1, 1, 0);
  3372. +
  3373. + ov5693->ctrls.vflip = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
  3374. + V4L2_CID_VFLIP, 0, 1, 1, 0);
  3375. +
  3376. + hblank = OV5693_FIXED_PPL - ov5693->mode.format.width;
  3377. + ov5693->ctrls.hblank = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
  3378. + V4L2_CID_HBLANK, hblank,
  3379. + hblank, 1, hblank);
  3380. +
  3381. + if (ov5693->ctrls.hblank)
  3382. + ov5693->ctrls.hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
  3383. +
  3384. + vblank_max = OV5693_TIMING_MAX_VTS - ov5693->mode.format.height;
  3385. + vblank_def = ov5693->mode.vts - ov5693->mode.format.height;
  3386. + ov5693->ctrls.vblank = v4l2_ctrl_new_std(&ov5693->ctrls.handler, ops,
  3387. + V4L2_CID_VBLANK,
  3388. + OV5693_TIMING_MIN_VTS,
  3389. + vblank_max, 1, vblank_def);
  3390. +
  3391. + ov5693->ctrls.test_pattern = v4l2_ctrl_new_std_menu_items(
  3392. + &ov5693->ctrls.handler, ops,
  3393. + V4L2_CID_TEST_PATTERN,
  3394. + ARRAY_SIZE(ov5693_test_pattern_menu) - 1,
  3395. + 0, 0, ov5693_test_pattern_menu);
  3396. +
  3397. + if (ov5693->ctrls.handler.error) {
  3398. + dev_err(ov5693->dev, "Error initialising v4l2 ctrls\n");
  3399. + ret = ov5693->ctrls.handler.error;
  3400. + goto err_free_handler;
  3401. + }
  3402. +
  3403. + /* set properties from fwnode (e.g. rotation, orientation) */
  3404. + ret = v4l2_fwnode_device_parse(ov5693->dev, &props);
  3405. + if (ret)
  3406. + goto err_free_handler;
  3407. +
  3408. + ret = v4l2_ctrl_new_fwnode_properties(&ov5693->ctrls.handler, ops,
  3409. + &props);
  3410. + if (ret)
  3411. + goto err_free_handler;
  3412. +
  3413. + /* Use same lock for controls as for everything else. */
  3414. + ov5693->ctrls.handler.lock = &ov5693->lock;
  3415. + ov5693->sd.ctrl_handler = &ov5693->ctrls.handler;
  3416. +
  3417. + return 0;
  3418. +
  3419. +err_free_handler:
  3420. + v4l2_ctrl_handler_free(&ov5693->ctrls.handler);
  3421. + return ret;
  3422. +}
  3423. +
  3424. +static int ov5693_configure_gpios(struct ov5693_device *ov5693)
  3425. +{
  3426. + ov5693->reset = devm_gpiod_get_optional(ov5693->dev, "reset",
  3427. + GPIOD_OUT_HIGH);
  3428. + if (IS_ERR(ov5693->reset)) {
  3429. + dev_err(ov5693->dev, "Error fetching reset GPIO\n");
  3430. + return PTR_ERR(ov5693->reset);
  3431. + }
  3432. +
  3433. + ov5693->powerdown = devm_gpiod_get_optional(ov5693->dev, "powerdown",
  3434. + GPIOD_OUT_HIGH);
  3435. + if (IS_ERR(ov5693->powerdown)) {
  3436. + dev_err(ov5693->dev, "Error fetching powerdown GPIO\n");
  3437. + return PTR_ERR(ov5693->powerdown);
  3438. + }
  3439. +
  3440. + return 0;
  3441. +}
  3442. +
  3443. +static int ov5693_get_regulators(struct ov5693_device *ov5693)
  3444. +{
  3445. + unsigned int i;
  3446. +
  3447. + for (i = 0; i < OV5693_NUM_SUPPLIES; i++)
  3448. + ov5693->supplies[i].supply = ov5693_supply_names[i];
  3449. +
  3450. + return devm_regulator_bulk_get(ov5693->dev, OV5693_NUM_SUPPLIES,
  3451. + ov5693->supplies);
  3452. +}
  3453. +
  3454. +static int ov5693_probe(struct i2c_client *client)
  3455. +{
  3456. + struct fwnode_handle *fwnode = dev_fwnode(&client->dev);
  3457. + struct fwnode_handle *endpoint;
  3458. + struct ov5693_device *ov5693;
  3459. + u32 clk_rate;
  3460. + int ret = 0;
  3461. +
  3462. + endpoint = fwnode_graph_get_next_endpoint(fwnode, NULL);
  3463. + if (!endpoint && !IS_ERR_OR_NULL(fwnode->secondary))
  3464. + endpoint = fwnode_graph_get_next_endpoint(fwnode->secondary, NULL);
  3465. + if (!endpoint)
  3466. + return -EPROBE_DEFER;
  3467. +
  3468. + ov5693 = devm_kzalloc(&client->dev, sizeof(*ov5693), GFP_KERNEL);
  3469. + if (!ov5693)
  3470. + return -ENOMEM;
  3471. +
  3472. + ov5693->client = client;
  3473. + ov5693->dev = &client->dev;
  3474. +
  3475. + mutex_init(&ov5693->lock);
  3476. +
  3477. + v4l2_i2c_subdev_init(&ov5693->sd, client, &ov5693_ops);
  3478. +
  3479. + ov5693->clk = devm_clk_get(&client->dev, "xvclk");
  3480. + if (IS_ERR(ov5693->clk)) {
  3481. + dev_err(&client->dev, "Error getting clock\n");
  3482. + return PTR_ERR(ov5693->clk);
  3483. + }
  3484. +
  3485. + clk_rate = clk_get_rate(ov5693->clk);
  3486. + if (clk_rate != OV5693_XVCLK_FREQ) {
  3487. + dev_err(&client->dev, "Unsupported clk freq %u, expected %u\n",
  3488. + clk_rate, OV5693_XVCLK_FREQ);
  3489. + return -EINVAL;
  3490. + }
  3491. +
  3492. + ret = ov5693_configure_gpios(ov5693);
  3493. + if (ret)
  3494. + return ret;
  3495. +
  3496. + ret = ov5693_get_regulators(ov5693);
  3497. + if (ret) {
  3498. + dev_err(&client->dev, "Error fetching regulators\n");
  3499. + return ret;
  3500. + }
  3501. +
  3502. + ov5693->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  3503. + ov5693->pad.flags = MEDIA_PAD_FL_SOURCE;
  3504. + ov5693->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
  3505. +
  3506. + ov5693->mode.crop = ov5693_default_crop;
  3507. + ov5693->mode.format = ov5693_default_fmt;
  3508. + ov5693->mode.vts = __ov5693_calc_vts(ov5693->mode.format.height);
  3509. +
  3510. + ret = ov5693_init_controls(ov5693);
  3511. + if (ret)
  3512. + return ret;
  3513. +
  3514. + ret = media_entity_pads_init(&ov5693->sd.entity, 1, &ov5693->pad);
  3515. + if (ret)
  3516. + goto err_ctrl_handler_free;
  3517. +
  3518. + /*
  3519. + * We need the driver to work in the event that pm runtime is disable in
  3520. + * the kernel, so power up and verify the chip now. In the event that
  3521. + * runtime pm is disabled this will leave the chip on, so that streaming
  3522. + * will work.
  3523. + */
  3524. +
  3525. + ret = ov5693_sensor_powerup(ov5693);
  3526. + if (ret)
  3527. + goto err_media_entity_cleanup;
  3528. +
  3529. + ret = ov5693_detect(ov5693);
  3530. + if (ret)
  3531. + goto err_powerdown;
  3532. +
  3533. + pm_runtime_set_active(&client->dev);
  3534. + pm_runtime_get_noresume(&client->dev);
  3535. + pm_runtime_enable(&client->dev);
  3536. +
  3537. + ret = v4l2_async_register_subdev_sensor_common(&ov5693->sd);
  3538. + if (ret) {
  3539. + dev_err(&client->dev, "failed to register V4L2 subdev: %d",
  3540. + ret);
  3541. + goto err_pm_runtime;
  3542. + }
  3543. +
  3544. + pm_runtime_set_autosuspend_delay(&client->dev, 1000);
  3545. + pm_runtime_use_autosuspend(&client->dev);
  3546. + pm_runtime_put_autosuspend(&client->dev);
  3547. +
  3548. + return ret;
  3549. +
  3550. +err_pm_runtime:
  3551. + pm_runtime_disable(&client->dev);
  3552. + pm_runtime_put_noidle(&client->dev);
  3553. +err_powerdown:
  3554. + ov5693_sensor_powerdown(ov5693);
  3555. +err_media_entity_cleanup:
  3556. + media_entity_cleanup(&ov5693->sd.entity);
  3557. +err_ctrl_handler_free:
  3558. + v4l2_ctrl_handler_free(&ov5693->ctrls.handler);
  3559. +
  3560. + return ret;
  3561. +}
  3562. +
  3563. +static int ov5693_remove(struct i2c_client *client)
  3564. +{
  3565. + struct v4l2_subdev *sd = i2c_get_clientdata(client);
  3566. + struct ov5693_device *ov5693 = to_ov5693_sensor(sd);
  3567. +
  3568. + v4l2_async_unregister_subdev(sd);
  3569. + media_entity_cleanup(&ov5693->sd.entity);
  3570. + v4l2_ctrl_handler_free(&ov5693->ctrls.handler);
  3571. + mutex_destroy(&ov5693->lock);
  3572. +
  3573. + /*
  3574. + * Disable runtime PM. In case runtime PM is disabled in the kernel,
  3575. + * make sure to turn power off manually.
  3576. + */
  3577. + pm_runtime_disable(&client->dev);
  3578. + if (!pm_runtime_status_suspended(&client->dev))
  3579. + ov5693_sensor_powerdown(ov5693);
  3580. + pm_runtime_set_suspended(&client->dev);
  3581. +
  3582. + return 0;
  3583. +}
  3584. +
  3585. +static const struct dev_pm_ops ov5693_pm_ops = {
  3586. + SET_RUNTIME_PM_OPS(ov5693_sensor_suspend, ov5693_sensor_resume, NULL)
  3587. +};
  3588. +
  3589. +static const struct acpi_device_id ov5693_acpi_match[] = {
  3590. + {"INT33BE"},
  3591. + {},
  3592. +};
  3593. +MODULE_DEVICE_TABLE(acpi, ov5693_acpi_match);
  3594. +
  3595. +static struct i2c_driver ov5693_driver = {
  3596. + .driver = {
  3597. + .name = "ov5693",
  3598. + .acpi_match_table = ov5693_acpi_match,
  3599. + .pm = &ov5693_pm_ops,
  3600. + },
  3601. + .probe_new = ov5693_probe,
  3602. + .remove = ov5693_remove,
  3603. +};
  3604. +module_i2c_driver(ov5693_driver);
  3605. +
  3606. +MODULE_DESCRIPTION("A low-level driver for OmniVision 5693 sensors");
  3607. +MODULE_LICENSE("GPL");
  3608. --
  3609. 2.32.0
  3610. From a3f2f62b38c961c6440adc29c88533ec2a9bb108 Mon Sep 17 00:00:00 2001
  3611. From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= <me@fabwu.ch>
  3612. Date: Fri, 22 Jan 2021 20:58:13 +0100
  3613. Subject: [PATCH] cio2-bridge: Parse sensor orientation and rotation
  3614. MIME-Version: 1.0
  3615. Content-Type: text/plain; charset=UTF-8
  3616. Content-Transfer-Encoding: 8bit
  3617. The sensor orientation is read from the _PLC ACPI buffer and converted
  3618. to a v4l2 format.
  3619. See https://uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf
  3620. page 351 for a definition of the Panel property.
  3621. The sensor rotation is read from the SSDB ACPI buffer and converted into
  3622. degrees.
  3623. Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
  3624. Patchset: cameras
  3625. ---
  3626. drivers/media/pci/intel/ipu3/cio2-bridge.c | 45 ++++++++++++++++++++--
  3627. drivers/media/pci/intel/ipu3/cio2-bridge.h | 3 ++
  3628. 2 files changed, 44 insertions(+), 4 deletions(-)
  3629. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  3630. index c2199042d3db..9a8a4a55d6a7 100644
  3631. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
  3632. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  3633. @@ -29,6 +29,7 @@ static const struct cio2_sensor_config cio2_supported_sensors[] = {
  3634. static const struct cio2_property_names prop_names = {
  3635. .clock_frequency = "clock-frequency",
  3636. .rotation = "rotation",
  3637. + .orientation = "orientation",
  3638. .bus_type = "bus-type",
  3639. .data_lanes = "data-lanes",
  3640. .remote_endpoint = "remote-endpoint",
  3641. @@ -72,11 +73,36 @@ static int cio2_bridge_read_acpi_buffer(struct acpi_device *adev, char *id,
  3642. return ret;
  3643. }
  3644. +static u32 cio2_bridge_parse_rotation(u8 rotation)
  3645. +{
  3646. + if (rotation == 1)
  3647. + return 180;
  3648. + return 0;
  3649. +}
  3650. +
  3651. +static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(u8 panel)
  3652. +{
  3653. + switch (panel) {
  3654. + case 4:
  3655. + return V4L2_FWNODE_ORIENTATION_FRONT;
  3656. + case 5:
  3657. + return V4L2_FWNODE_ORIENTATION_BACK;
  3658. + default:
  3659. + return V4L2_FWNODE_ORIENTATION_EXTERNAL;
  3660. + }
  3661. +}
  3662. +
  3663. static void cio2_bridge_create_fwnode_properties(
  3664. struct cio2_sensor *sensor,
  3665. struct cio2_bridge *bridge,
  3666. const struct cio2_sensor_config *cfg)
  3667. {
  3668. + u32 rotation;
  3669. + enum v4l2_fwnode_orientation orientation;
  3670. +
  3671. + rotation = cio2_bridge_parse_rotation(sensor->ssdb.degree);
  3672. + orientation = cio2_bridge_parse_orientation(sensor->pld->panel);
  3673. +
  3674. sensor->prop_names = prop_names;
  3675. sensor->local_ref[0].node = &sensor->swnodes[SWNODE_CIO2_ENDPOINT];
  3676. @@ -85,9 +111,12 @@ static void cio2_bridge_create_fwnode_properties(
  3677. sensor->dev_properties[0] = PROPERTY_ENTRY_U32(
  3678. sensor->prop_names.clock_frequency,
  3679. sensor->ssdb.mclkspeed);
  3680. - sensor->dev_properties[1] = PROPERTY_ENTRY_U8(
  3681. + sensor->dev_properties[1] = PROPERTY_ENTRY_U32(
  3682. sensor->prop_names.rotation,
  3683. - sensor->ssdb.degree);
  3684. + rotation);
  3685. + sensor->dev_properties[2] = PROPERTY_ENTRY_U32(
  3686. + sensor->prop_names.orientation,
  3687. + orientation);
  3688. sensor->ep_properties[0] = PROPERTY_ENTRY_U32(
  3689. sensor->prop_names.bus_type,
  3690. @@ -159,6 +188,7 @@ static void cio2_bridge_unregister_sensors(struct cio2_bridge *bridge)
  3691. for (i = 0; i < bridge->n_sensors; i++) {
  3692. sensor = &bridge->sensors[i];
  3693. software_node_unregister_nodes(sensor->swnodes);
  3694. + ACPI_FREE(sensor->pld);
  3695. acpi_dev_put(sensor->adev);
  3696. }
  3697. }
  3698. @@ -170,6 +200,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
  3699. struct fwnode_handle *fwnode;
  3700. struct cio2_sensor *sensor;
  3701. struct acpi_device *adev;
  3702. + acpi_status status;
  3703. int ret;
  3704. for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
  3705. @@ -193,11 +224,15 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
  3706. if (ret)
  3707. goto err_put_adev;
  3708. + status = acpi_get_physical_device_location(adev->handle, &sensor->pld);
  3709. + if (ACPI_FAILURE(status))
  3710. + goto err_put_adev;
  3711. +
  3712. if (sensor->ssdb.lanes > CIO2_MAX_LANES) {
  3713. dev_err(&adev->dev,
  3714. "Number of lanes in SSDB is invalid\n");
  3715. ret = -EINVAL;
  3716. - goto err_put_adev;
  3717. + goto err_free_pld;
  3718. }
  3719. cio2_bridge_create_fwnode_properties(sensor, bridge, cfg);
  3720. @@ -205,7 +240,7 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
  3721. ret = software_node_register_nodes(sensor->swnodes);
  3722. if (ret)
  3723. - goto err_put_adev;
  3724. + goto err_free_pld;
  3725. fwnode = software_node_fwnode(&sensor->swnodes[
  3726. SWNODE_SENSOR_HID]);
  3727. @@ -226,6 +261,8 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,
  3728. err_free_swnodes:
  3729. software_node_unregister_nodes(sensor->swnodes);
  3730. +err_free_pld:
  3731. + ACPI_FREE(sensor->pld);
  3732. err_put_adev:
  3733. acpi_dev_put(sensor->adev);
  3734. err_out:
  3735. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  3736. index dd0ffcafa489..924d99d20328 100644
  3737. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
  3738. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  3739. @@ -80,6 +80,7 @@ struct cio2_sensor_ssdb {
  3740. struct cio2_property_names {
  3741. char clock_frequency[16];
  3742. char rotation[9];
  3743. + char orientation[12];
  3744. char bus_type[9];
  3745. char data_lanes[11];
  3746. char remote_endpoint[16];
  3747. @@ -106,6 +107,8 @@ struct cio2_sensor {
  3748. struct cio2_node_names node_names;
  3749. struct cio2_sensor_ssdb ssdb;
  3750. + struct acpi_pld_info *pld;
  3751. +
  3752. struct cio2_property_names prop_names;
  3753. struct property_entry ep_properties[5];
  3754. struct property_entry dev_properties[3];
  3755. --
  3756. 2.32.0
  3757. From 997ee8fc601da7743d0c9abe4d0ac1dddec0327e Mon Sep 17 00:00:00 2001
  3758. From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= <me@fabwu.ch>
  3759. Date: Sun, 24 Jan 2021 11:07:42 +0100
  3760. Subject: [PATCH] cio2-bridge: Use macros and add warnings
  3761. MIME-Version: 1.0
  3762. Content-Type: text/plain; charset=UTF-8
  3763. Content-Transfer-Encoding: 8bit
  3764. Use macros for the _PLD panel as defined in the ACPI spec 6.3 and emit
  3765. a warning if we see an unknown value.
  3766. Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
  3767. Patchset: cameras
  3768. ---
  3769. drivers/media/pci/intel/ipu3/cio2-bridge.c | 33 ++++++++++++++++------
  3770. drivers/media/pci/intel/ipu3/cio2-bridge.h | 13 +++++++++
  3771. 2 files changed, 37 insertions(+), 9 deletions(-)
  3772. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  3773. index 9a8a4a55d6a7..503809907b92 100644
  3774. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c
  3775. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c
  3776. @@ -73,21 +73,36 @@ static int cio2_bridge_read_acpi_buffer(struct acpi_device *adev, char *id,
  3777. return ret;
  3778. }
  3779. -static u32 cio2_bridge_parse_rotation(u8 rotation)
  3780. +static u32 cio2_bridge_parse_rotation(struct cio2_sensor *sensor)
  3781. {
  3782. - if (rotation == 1)
  3783. + switch (sensor->ssdb.degree) {
  3784. + case CIO2_SENSOR_ROTATION_NORMAL:
  3785. + return 0;
  3786. + case CIO2_SENSOR_ROTATION_INVERTED:
  3787. return 180;
  3788. - return 0;
  3789. + default:
  3790. + dev_warn(&sensor->adev->dev,
  3791. + "Unknown rotation %d. Assume 0 degree rotation\n",
  3792. + sensor->ssdb.degree);
  3793. + return 0;
  3794. + }
  3795. }
  3796. -static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(u8 panel)
  3797. +static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(struct cio2_sensor *sensor)
  3798. {
  3799. - switch (panel) {
  3800. - case 4:
  3801. + switch (sensor->pld->panel) {
  3802. + case CIO2_PLD_PANEL_FRONT:
  3803. return V4L2_FWNODE_ORIENTATION_FRONT;
  3804. - case 5:
  3805. + case CIO2_PLD_PANEL_BACK:
  3806. return V4L2_FWNODE_ORIENTATION_BACK;
  3807. + case CIO2_PLD_PANEL_TOP:
  3808. + case CIO2_PLD_PANEL_LEFT:
  3809. + case CIO2_PLD_PANEL_RIGHT:
  3810. + case CIO2_PLD_PANEL_UNKNOWN:
  3811. + return V4L2_FWNODE_ORIENTATION_EXTERNAL;
  3812. default:
  3813. + dev_warn(&sensor->adev->dev, "Unknown _PLD panel value %d\n",
  3814. + sensor->pld->panel);
  3815. return V4L2_FWNODE_ORIENTATION_EXTERNAL;
  3816. }
  3817. }
  3818. @@ -100,8 +115,8 @@ static void cio2_bridge_create_fwnode_properties(
  3819. u32 rotation;
  3820. enum v4l2_fwnode_orientation orientation;
  3821. - rotation = cio2_bridge_parse_rotation(sensor->ssdb.degree);
  3822. - orientation = cio2_bridge_parse_orientation(sensor->pld->panel);
  3823. + rotation = cio2_bridge_parse_rotation(sensor);
  3824. + orientation = cio2_bridge_parse_orientation(sensor);
  3825. sensor->prop_names = prop_names;
  3826. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  3827. index 924d99d20328..e1e388cc9f45 100644
  3828. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
  3829. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  3830. @@ -12,6 +12,19 @@
  3831. #define CIO2_MAX_LANES 4
  3832. #define MAX_NUM_LINK_FREQS 3
  3833. +/* Values are estimated guesses as we don't have a spec */
  3834. +#define CIO2_SENSOR_ROTATION_NORMAL 0
  3835. +#define CIO2_SENSOR_ROTATION_INVERTED 1
  3836. +
  3837. +/* Panel position defined in _PLD section of ACPI Specification 6.3 */
  3838. +#define CIO2_PLD_PANEL_TOP 0
  3839. +#define CIO2_PLD_PANEL_BOTTOM 1
  3840. +#define CIO2_PLD_PANEL_LEFT 2
  3841. +#define CIO2_PLD_PANEL_RIGHT 3
  3842. +#define CIO2_PLD_PANEL_FRONT 4
  3843. +#define CIO2_PLD_PANEL_BACK 5
  3844. +#define CIO2_PLD_PANEL_UNKNOWN 6
  3845. +
  3846. #define CIO2_SENSOR_CONFIG(_HID, _NR, ...) \
  3847. (const struct cio2_sensor_config) { \
  3848. .hid = _HID, \
  3849. --
  3850. 2.32.0
  3851. From a0254719dee6757d140de3a409e80e5dd0a516d7 Mon Sep 17 00:00:00 2001
  3852. From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= <me@fabwu.ch>
  3853. Date: Thu, 6 May 2021 07:52:44 +0200
  3854. Subject: [PATCH] cio2-bridge: Use correct dev_properties size
  3855. Patchset: cameras
  3856. ---
  3857. drivers/media/pci/intel/ipu3/cio2-bridge.h | 2 +-
  3858. 1 file changed, 1 insertion(+), 1 deletion(-)
  3859. diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  3860. index e1e388cc9f45..deaf5804f70d 100644
  3861. --- a/drivers/media/pci/intel/ipu3/cio2-bridge.h
  3862. +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.h
  3863. @@ -124,7 +124,7 @@ struct cio2_sensor {
  3864. struct cio2_property_names prop_names;
  3865. struct property_entry ep_properties[5];
  3866. - struct property_entry dev_properties[3];
  3867. + struct property_entry dev_properties[4];
  3868. struct property_entry cio2_properties[3];
  3869. struct software_node_ref_args local_ref[1];
  3870. struct software_node_ref_args remote_ref[1];
  3871. --
  3872. 2.32.0
  3873. From 7196d9fff983f3b33d361e58cf5aef01e235808a Mon Sep 17 00:00:00 2001
  3874. From: Daniel Scally <djrscally@gmail.com>
  3875. Date: Thu, 20 May 2021 23:31:04 +0100
  3876. Subject: [PATCH] media: i2c: Fix vertical flip in ov5693
  3877. The pinkness experienced by users with rotated sensors in their laptops
  3878. was due to an incorrect setting for the vertical flip function; the
  3879. datasheet for the sensor gives the settings as bits 1&2 in one place and
  3880. bits 1&6 in another.
  3881. Switch to flipping bit 6 instead of bit 2 for 0x3820 in the vertical
  3882. flip function to fix the pink hue.
  3883. Signed-off-by: Daniel Scally <djrscally@gmail.com>
  3884. Patchset: cameras
  3885. ---
  3886. drivers/media/i2c/ov5693.c | 2 +-
  3887. 1 file changed, 1 insertion(+), 1 deletion(-)
  3888. diff --git a/drivers/media/i2c/ov5693.c b/drivers/media/i2c/ov5693.c
  3889. index da2ca99a7ad3..52279eeffc54 100644
  3890. --- a/drivers/media/i2c/ov5693.c
  3891. +++ b/drivers/media/i2c/ov5693.c
  3892. @@ -133,7 +133,7 @@
  3893. #define OV5693_SUB_INC_Y_REG 0x3815
  3894. #define OV5693_FORMAT1_REG 0x3820
  3895. -#define OV5693_FORMAT1_FLIP_VERT_ISP_EN BIT(2)
  3896. +#define OV5693_FORMAT1_FLIP_VERT_ISP_EN BIT(6)
  3897. #define OV5693_FORMAT1_FLIP_VERT_SENSOR_EN BIT(1)
  3898. #define OV5693_FORMAT1_VBIN_EN BIT(0)
  3899. #define OV5693_FORMAT2_REG 0x3821
  3900. --
  3901. 2.32.0