intel_runtime_pm.c 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174
  1. /*
  2. * Copyright © 2012-2014 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eugeni Dodonov <eugeni.dodonov@intel.com>
  25. * Daniel Vetter <daniel.vetter@ffwll.ch>
  26. *
  27. */
  28. #include <linux/pm_runtime.h>
  29. #include <linux/vgaarb.h>
  30. #include "i915_drv.h"
  31. #include "intel_drv.h"
  32. /**
  33. * DOC: runtime pm
  34. *
  35. * The i915 driver supports dynamic enabling and disabling of entire hardware
  36. * blocks at runtime. This is especially important on the display side where
  37. * software is supposed to control many power gates manually on recent hardware,
  38. * since on the GT side a lot of the power management is done by the hardware.
  39. * But even there some manual control at the device level is required.
  40. *
  41. * Since i915 supports a diverse set of platforms with a unified codebase and
  42. * hardware engineers just love to shuffle functionality around between power
  43. * domains there's a sizeable amount of indirection required. This file provides
  44. * generic functions to the driver for grabbing and releasing references for
  45. * abstract power domains. It then maps those to the actual power wells
  46. * present for a given platform.
  47. */
  48. bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
  49. enum i915_power_well_id power_well_id);
  50. const char *
  51. intel_display_power_domain_str(enum intel_display_power_domain domain)
  52. {
  53. switch (domain) {
  54. case POWER_DOMAIN_PIPE_A:
  55. return "PIPE_A";
  56. case POWER_DOMAIN_PIPE_B:
  57. return "PIPE_B";
  58. case POWER_DOMAIN_PIPE_C:
  59. return "PIPE_C";
  60. case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
  61. return "PIPE_A_PANEL_FITTER";
  62. case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
  63. return "PIPE_B_PANEL_FITTER";
  64. case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
  65. return "PIPE_C_PANEL_FITTER";
  66. case POWER_DOMAIN_TRANSCODER_A:
  67. return "TRANSCODER_A";
  68. case POWER_DOMAIN_TRANSCODER_B:
  69. return "TRANSCODER_B";
  70. case POWER_DOMAIN_TRANSCODER_C:
  71. return "TRANSCODER_C";
  72. case POWER_DOMAIN_TRANSCODER_EDP:
  73. return "TRANSCODER_EDP";
  74. case POWER_DOMAIN_TRANSCODER_DSI_A:
  75. return "TRANSCODER_DSI_A";
  76. case POWER_DOMAIN_TRANSCODER_DSI_C:
  77. return "TRANSCODER_DSI_C";
  78. case POWER_DOMAIN_PORT_DDI_A_LANES:
  79. return "PORT_DDI_A_LANES";
  80. case POWER_DOMAIN_PORT_DDI_B_LANES:
  81. return "PORT_DDI_B_LANES";
  82. case POWER_DOMAIN_PORT_DDI_C_LANES:
  83. return "PORT_DDI_C_LANES";
  84. case POWER_DOMAIN_PORT_DDI_D_LANES:
  85. return "PORT_DDI_D_LANES";
  86. case POWER_DOMAIN_PORT_DDI_E_LANES:
  87. return "PORT_DDI_E_LANES";
  88. case POWER_DOMAIN_PORT_DDI_F_LANES:
  89. return "PORT_DDI_F_LANES";
  90. case POWER_DOMAIN_PORT_DDI_A_IO:
  91. return "PORT_DDI_A_IO";
  92. case POWER_DOMAIN_PORT_DDI_B_IO:
  93. return "PORT_DDI_B_IO";
  94. case POWER_DOMAIN_PORT_DDI_C_IO:
  95. return "PORT_DDI_C_IO";
  96. case POWER_DOMAIN_PORT_DDI_D_IO:
  97. return "PORT_DDI_D_IO";
  98. case POWER_DOMAIN_PORT_DDI_E_IO:
  99. return "PORT_DDI_E_IO";
  100. case POWER_DOMAIN_PORT_DDI_F_IO:
  101. return "PORT_DDI_F_IO";
  102. case POWER_DOMAIN_PORT_DSI:
  103. return "PORT_DSI";
  104. case POWER_DOMAIN_PORT_CRT:
  105. return "PORT_CRT";
  106. case POWER_DOMAIN_PORT_OTHER:
  107. return "PORT_OTHER";
  108. case POWER_DOMAIN_VGA:
  109. return "VGA";
  110. case POWER_DOMAIN_AUDIO:
  111. return "AUDIO";
  112. case POWER_DOMAIN_PLLS:
  113. return "PLLS";
  114. case POWER_DOMAIN_AUX_A:
  115. return "AUX_A";
  116. case POWER_DOMAIN_AUX_B:
  117. return "AUX_B";
  118. case POWER_DOMAIN_AUX_C:
  119. return "AUX_C";
  120. case POWER_DOMAIN_AUX_D:
  121. return "AUX_D";
  122. case POWER_DOMAIN_AUX_E:
  123. return "AUX_E";
  124. case POWER_DOMAIN_AUX_F:
  125. return "AUX_F";
  126. case POWER_DOMAIN_AUX_IO_A:
  127. return "AUX_IO_A";
  128. case POWER_DOMAIN_AUX_TBT1:
  129. return "AUX_TBT1";
  130. case POWER_DOMAIN_AUX_TBT2:
  131. return "AUX_TBT2";
  132. case POWER_DOMAIN_AUX_TBT3:
  133. return "AUX_TBT3";
  134. case POWER_DOMAIN_AUX_TBT4:
  135. return "AUX_TBT4";
  136. case POWER_DOMAIN_GMBUS:
  137. return "GMBUS";
  138. case POWER_DOMAIN_INIT:
  139. return "INIT";
  140. case POWER_DOMAIN_MODESET:
  141. return "MODESET";
  142. case POWER_DOMAIN_GT_IRQ:
  143. return "GT_IRQ";
  144. default:
  145. MISSING_CASE(domain);
  146. return "?";
  147. }
  148. }
  149. static void intel_power_well_enable(struct drm_i915_private *dev_priv,
  150. struct i915_power_well *power_well)
  151. {
  152. DRM_DEBUG_KMS("enabling %s\n", power_well->desc->name);
  153. power_well->desc->ops->enable(dev_priv, power_well);
  154. power_well->hw_enabled = true;
  155. }
  156. static void intel_power_well_disable(struct drm_i915_private *dev_priv,
  157. struct i915_power_well *power_well)
  158. {
  159. DRM_DEBUG_KMS("disabling %s\n", power_well->desc->name);
  160. power_well->hw_enabled = false;
  161. power_well->desc->ops->disable(dev_priv, power_well);
  162. }
  163. static void intel_power_well_get(struct drm_i915_private *dev_priv,
  164. struct i915_power_well *power_well)
  165. {
  166. if (!power_well->count++)
  167. intel_power_well_enable(dev_priv, power_well);
  168. }
  169. static void intel_power_well_put(struct drm_i915_private *dev_priv,
  170. struct i915_power_well *power_well)
  171. {
  172. WARN(!power_well->count, "Use count on power well %s is already zero",
  173. power_well->desc->name);
  174. if (!--power_well->count)
  175. intel_power_well_disable(dev_priv, power_well);
  176. }
  177. /**
  178. * __intel_display_power_is_enabled - unlocked check for a power domain
  179. * @dev_priv: i915 device instance
  180. * @domain: power domain to check
  181. *
  182. * This is the unlocked version of intel_display_power_is_enabled() and should
  183. * only be used from error capture and recovery code where deadlocks are
  184. * possible.
  185. *
  186. * Returns:
  187. * True when the power domain is enabled, false otherwise.
  188. */
  189. bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
  190. enum intel_display_power_domain domain)
  191. {
  192. struct i915_power_well *power_well;
  193. bool is_enabled;
  194. if (dev_priv->runtime_pm.suspended)
  195. return false;
  196. is_enabled = true;
  197. for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain)) {
  198. if (power_well->desc->always_on)
  199. continue;
  200. if (!power_well->hw_enabled) {
  201. is_enabled = false;
  202. break;
  203. }
  204. }
  205. return is_enabled;
  206. }
  207. /**
  208. * intel_display_power_is_enabled - check for a power domain
  209. * @dev_priv: i915 device instance
  210. * @domain: power domain to check
  211. *
  212. * This function can be used to check the hw power domain state. It is mostly
  213. * used in hardware state readout functions. Everywhere else code should rely
  214. * upon explicit power domain reference counting to ensure that the hardware
  215. * block is powered up before accessing it.
  216. *
  217. * Callers must hold the relevant modesetting locks to ensure that concurrent
  218. * threads can't disable the power well while the caller tries to read a few
  219. * registers.
  220. *
  221. * Returns:
  222. * True when the power domain is enabled, false otherwise.
  223. */
  224. bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
  225. enum intel_display_power_domain domain)
  226. {
  227. struct i915_power_domains *power_domains;
  228. bool ret;
  229. power_domains = &dev_priv->power_domains;
  230. mutex_lock(&power_domains->lock);
  231. ret = __intel_display_power_is_enabled(dev_priv, domain);
  232. mutex_unlock(&power_domains->lock);
  233. return ret;
  234. }
  235. /*
  236. * Starting with Haswell, we have a "Power Down Well" that can be turned off
  237. * when not needed anymore. We have 4 registers that can request the power well
  238. * to be enabled, and it will only be disabled if none of the registers is
  239. * requesting it to be enabled.
  240. */
  241. static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv,
  242. u8 irq_pipe_mask, bool has_vga)
  243. {
  244. struct pci_dev *pdev = dev_priv->drm.pdev;
  245. /*
  246. * After we re-enable the power well, if we touch VGA register 0x3d5
  247. * we'll get unclaimed register interrupts. This stops after we write
  248. * anything to the VGA MSR register. The vgacon module uses this
  249. * register all the time, so if we unbind our driver and, as a
  250. * consequence, bind vgacon, we'll get stuck in an infinite loop at
  251. * console_unlock(). So make here we touch the VGA MSR register, making
  252. * sure vgacon can keep working normally without triggering interrupts
  253. * and error messages.
  254. */
  255. if (has_vga) {
  256. vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
  257. outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
  258. vga_put(pdev, VGA_RSRC_LEGACY_IO);
  259. }
  260. if (irq_pipe_mask)
  261. gen8_irq_power_well_post_enable(dev_priv, irq_pipe_mask);
  262. }
  263. static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv,
  264. u8 irq_pipe_mask)
  265. {
  266. if (irq_pipe_mask)
  267. gen8_irq_power_well_pre_disable(dev_priv, irq_pipe_mask);
  268. }
  269. static void hsw_wait_for_power_well_enable(struct drm_i915_private *dev_priv,
  270. struct i915_power_well *power_well)
  271. {
  272. const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
  273. int pw_idx = power_well->desc->hsw.idx;
  274. /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
  275. WARN_ON(intel_wait_for_register(dev_priv,
  276. regs->driver,
  277. HSW_PWR_WELL_CTL_STATE(pw_idx),
  278. HSW_PWR_WELL_CTL_STATE(pw_idx),
  279. 1));
  280. }
  281. static u32 hsw_power_well_requesters(struct drm_i915_private *dev_priv,
  282. const struct i915_power_well_regs *regs,
  283. int pw_idx)
  284. {
  285. u32 req_mask = HSW_PWR_WELL_CTL_REQ(pw_idx);
  286. u32 ret;
  287. ret = I915_READ(regs->bios) & req_mask ? 1 : 0;
  288. ret |= I915_READ(regs->driver) & req_mask ? 2 : 0;
  289. if (regs->kvmr.reg)
  290. ret |= I915_READ(regs->kvmr) & req_mask ? 4 : 0;
  291. ret |= I915_READ(regs->debug) & req_mask ? 8 : 0;
  292. return ret;
  293. }
  294. static void hsw_wait_for_power_well_disable(struct drm_i915_private *dev_priv,
  295. struct i915_power_well *power_well)
  296. {
  297. const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
  298. int pw_idx = power_well->desc->hsw.idx;
  299. bool disabled;
  300. u32 reqs;
  301. /*
  302. * Bspec doesn't require waiting for PWs to get disabled, but still do
  303. * this for paranoia. The known cases where a PW will be forced on:
  304. * - a KVMR request on any power well via the KVMR request register
  305. * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
  306. * DEBUG request registers
  307. * Skip the wait in case any of the request bits are set and print a
  308. * diagnostic message.
  309. */
  310. wait_for((disabled = !(I915_READ(regs->driver) &
  311. HSW_PWR_WELL_CTL_STATE(pw_idx))) ||
  312. (reqs = hsw_power_well_requesters(dev_priv, regs, pw_idx)), 1);
  313. if (disabled)
  314. return;
  315. DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
  316. power_well->desc->name,
  317. !!(reqs & 1), !!(reqs & 2), !!(reqs & 4), !!(reqs & 8));
  318. }
  319. static void gen9_wait_for_power_well_fuses(struct drm_i915_private *dev_priv,
  320. enum skl_power_gate pg)
  321. {
  322. /* Timeout 5us for PG#0, for other PGs 1us */
  323. WARN_ON(intel_wait_for_register(dev_priv, SKL_FUSE_STATUS,
  324. SKL_FUSE_PG_DIST_STATUS(pg),
  325. SKL_FUSE_PG_DIST_STATUS(pg), 1));
  326. }
  327. static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
  328. struct i915_power_well *power_well)
  329. {
  330. const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
  331. int pw_idx = power_well->desc->hsw.idx;
  332. bool wait_fuses = power_well->desc->hsw.has_fuses;
  333. enum skl_power_gate uninitialized_var(pg);
  334. u32 val;
  335. if (wait_fuses) {
  336. pg = INTEL_GEN(dev_priv) >= 11 ? ICL_PW_CTL_IDX_TO_PG(pw_idx) :
  337. SKL_PW_CTL_IDX_TO_PG(pw_idx);
  338. /*
  339. * For PW1 we have to wait both for the PW0/PG0 fuse state
  340. * before enabling the power well and PW1/PG1's own fuse
  341. * state after the enabling. For all other power wells with
  342. * fuses we only have to wait for that PW/PG's fuse state
  343. * after the enabling.
  344. */
  345. if (pg == SKL_PG1)
  346. gen9_wait_for_power_well_fuses(dev_priv, SKL_PG0);
  347. }
  348. val = I915_READ(regs->driver);
  349. I915_WRITE(regs->driver, val | HSW_PWR_WELL_CTL_REQ(pw_idx));
  350. hsw_wait_for_power_well_enable(dev_priv, power_well);
  351. /* Display WA #1178: cnl */
  352. if (IS_CANNONLAKE(dev_priv) &&
  353. pw_idx >= GLK_PW_CTL_IDX_AUX_B &&
  354. pw_idx <= CNL_PW_CTL_IDX_AUX_F) {
  355. val = I915_READ(CNL_AUX_ANAOVRD1(pw_idx));
  356. val |= CNL_AUX_ANAOVRD1_ENABLE | CNL_AUX_ANAOVRD1_LDO_BYPASS;
  357. I915_WRITE(CNL_AUX_ANAOVRD1(pw_idx), val);
  358. }
  359. if (wait_fuses)
  360. gen9_wait_for_power_well_fuses(dev_priv, pg);
  361. hsw_power_well_post_enable(dev_priv,
  362. power_well->desc->hsw.irq_pipe_mask,
  363. power_well->desc->hsw.has_vga);
  364. }
  365. static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
  366. struct i915_power_well *power_well)
  367. {
  368. const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
  369. int pw_idx = power_well->desc->hsw.idx;
  370. u32 val;
  371. hsw_power_well_pre_disable(dev_priv,
  372. power_well->desc->hsw.irq_pipe_mask);
  373. val = I915_READ(regs->driver);
  374. I915_WRITE(regs->driver, val & ~HSW_PWR_WELL_CTL_REQ(pw_idx));
  375. hsw_wait_for_power_well_disable(dev_priv, power_well);
  376. }
  377. #define ICL_AUX_PW_TO_PORT(pw_idx) ((pw_idx) - ICL_PW_CTL_IDX_AUX_A)
  378. static void
  379. icl_combo_phy_aux_power_well_enable(struct drm_i915_private *dev_priv,
  380. struct i915_power_well *power_well)
  381. {
  382. const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
  383. int pw_idx = power_well->desc->hsw.idx;
  384. enum port port = ICL_AUX_PW_TO_PORT(pw_idx);
  385. u32 val;
  386. val = I915_READ(regs->driver);
  387. I915_WRITE(regs->driver, val | HSW_PWR_WELL_CTL_REQ(pw_idx));
  388. val = I915_READ(ICL_PORT_CL_DW12(port));
  389. I915_WRITE(ICL_PORT_CL_DW12(port), val | ICL_LANE_ENABLE_AUX);
  390. hsw_wait_for_power_well_enable(dev_priv, power_well);
  391. }
  392. static void
  393. icl_combo_phy_aux_power_well_disable(struct drm_i915_private *dev_priv,
  394. struct i915_power_well *power_well)
  395. {
  396. const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
  397. int pw_idx = power_well->desc->hsw.idx;
  398. enum port port = ICL_AUX_PW_TO_PORT(pw_idx);
  399. u32 val;
  400. val = I915_READ(ICL_PORT_CL_DW12(port));
  401. I915_WRITE(ICL_PORT_CL_DW12(port), val & ~ICL_LANE_ENABLE_AUX);
  402. val = I915_READ(regs->driver);
  403. I915_WRITE(regs->driver, val & ~HSW_PWR_WELL_CTL_REQ(pw_idx));
  404. hsw_wait_for_power_well_disable(dev_priv, power_well);
  405. }
  406. /*
  407. * We should only use the power well if we explicitly asked the hardware to
  408. * enable it, so check if it's enabled and also check if we've requested it to
  409. * be enabled.
  410. */
  411. static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
  412. struct i915_power_well *power_well)
  413. {
  414. const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
  415. int pw_idx = power_well->desc->hsw.idx;
  416. u32 mask = HSW_PWR_WELL_CTL_REQ(pw_idx) |
  417. HSW_PWR_WELL_CTL_STATE(pw_idx);
  418. return (I915_READ(regs->driver) & mask) == mask;
  419. }
  420. static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
  421. {
  422. WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
  423. "DC9 already programmed to be enabled.\n");
  424. WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
  425. "DC5 still not disabled to enable DC9.\n");
  426. WARN_ONCE(I915_READ(HSW_PWR_WELL_CTL2) &
  427. HSW_PWR_WELL_CTL_REQ(SKL_PW_CTL_IDX_PW_2),
  428. "Power well 2 on.\n");
  429. WARN_ONCE(intel_irqs_enabled(dev_priv),
  430. "Interrupts not disabled yet.\n");
  431. /*
  432. * TODO: check for the following to verify the conditions to enter DC9
  433. * state are satisfied:
  434. * 1] Check relevant display engine registers to verify if mode set
  435. * disable sequence was followed.
  436. * 2] Check if display uninitialize sequence is initialized.
  437. */
  438. }
  439. static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
  440. {
  441. WARN_ONCE(intel_irqs_enabled(dev_priv),
  442. "Interrupts not disabled yet.\n");
  443. WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
  444. "DC5 still not disabled.\n");
  445. /*
  446. * TODO: check for the following to verify DC9 state was indeed
  447. * entered before programming to disable it:
  448. * 1] Check relevant display engine registers to verify if mode
  449. * set disable sequence was followed.
  450. * 2] Check if display uninitialize sequence is initialized.
  451. */
  452. }
  453. static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
  454. u32 state)
  455. {
  456. int rewrites = 0;
  457. int rereads = 0;
  458. u32 v;
  459. I915_WRITE(DC_STATE_EN, state);
  460. /* It has been observed that disabling the dc6 state sometimes
  461. * doesn't stick and dmc keeps returning old value. Make sure
  462. * the write really sticks enough times and also force rewrite until
  463. * we are confident that state is exactly what we want.
  464. */
  465. do {
  466. v = I915_READ(DC_STATE_EN);
  467. if (v != state) {
  468. I915_WRITE(DC_STATE_EN, state);
  469. rewrites++;
  470. rereads = 0;
  471. } else if (rereads++ > 5) {
  472. break;
  473. }
  474. } while (rewrites < 100);
  475. if (v != state)
  476. DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
  477. state, v);
  478. /* Most of the times we need one retry, avoid spam */
  479. if (rewrites > 1)
  480. DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
  481. state, rewrites);
  482. }
  483. static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
  484. {
  485. u32 mask;
  486. mask = DC_STATE_EN_UPTO_DC5;
  487. if (IS_GEN9_LP(dev_priv))
  488. mask |= DC_STATE_EN_DC9;
  489. else
  490. mask |= DC_STATE_EN_UPTO_DC6;
  491. return mask;
  492. }
  493. void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
  494. {
  495. u32 val;
  496. val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
  497. DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
  498. dev_priv->csr.dc_state, val);
  499. dev_priv->csr.dc_state = val;
  500. }
  501. /**
  502. * gen9_set_dc_state - set target display C power state
  503. * @dev_priv: i915 device instance
  504. * @state: target DC power state
  505. * - DC_STATE_DISABLE
  506. * - DC_STATE_EN_UPTO_DC5
  507. * - DC_STATE_EN_UPTO_DC6
  508. * - DC_STATE_EN_DC9
  509. *
  510. * Signal to DMC firmware/HW the target DC power state passed in @state.
  511. * DMC/HW can turn off individual display clocks and power rails when entering
  512. * a deeper DC power state (higher in number) and turns these back when exiting
  513. * that state to a shallower power state (lower in number). The HW will decide
  514. * when to actually enter a given state on an on-demand basis, for instance
  515. * depending on the active state of display pipes. The state of display
  516. * registers backed by affected power rails are saved/restored as needed.
  517. *
  518. * Based on the above enabling a deeper DC power state is asynchronous wrt.
  519. * enabling it. Disabling a deeper power state is synchronous: for instance
  520. * setting %DC_STATE_DISABLE won't complete until all HW resources are turned
  521. * back on and register state is restored. This is guaranteed by the MMIO write
  522. * to DC_STATE_EN blocking until the state is restored.
  523. */
  524. static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
  525. {
  526. uint32_t val;
  527. uint32_t mask;
  528. if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
  529. state &= dev_priv->csr.allowed_dc_mask;
  530. val = I915_READ(DC_STATE_EN);
  531. mask = gen9_dc_mask(dev_priv);
  532. DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
  533. val & mask, state);
  534. /* Check if DMC is ignoring our DC state requests */
  535. if ((val & mask) != dev_priv->csr.dc_state)
  536. DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
  537. dev_priv->csr.dc_state, val & mask);
  538. val &= ~mask;
  539. val |= state;
  540. gen9_write_dc_state(dev_priv, val);
  541. dev_priv->csr.dc_state = val & mask;
  542. }
  543. void bxt_enable_dc9(struct drm_i915_private *dev_priv)
  544. {
  545. assert_can_enable_dc9(dev_priv);
  546. DRM_DEBUG_KMS("Enabling DC9\n");
  547. intel_power_sequencer_reset(dev_priv);
  548. gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
  549. }
  550. void bxt_disable_dc9(struct drm_i915_private *dev_priv)
  551. {
  552. assert_can_disable_dc9(dev_priv);
  553. DRM_DEBUG_KMS("Disabling DC9\n");
  554. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  555. intel_pps_unlock_regs_wa(dev_priv);
  556. }
  557. static void assert_csr_loaded(struct drm_i915_private *dev_priv)
  558. {
  559. WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
  560. "CSR program storage start is NULL\n");
  561. WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
  562. WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
  563. }
  564. static struct i915_power_well *
  565. lookup_power_well(struct drm_i915_private *dev_priv,
  566. enum i915_power_well_id power_well_id)
  567. {
  568. struct i915_power_well *power_well;
  569. for_each_power_well(dev_priv, power_well)
  570. if (power_well->desc->id == power_well_id)
  571. return power_well;
  572. /*
  573. * It's not feasible to add error checking code to the callers since
  574. * this condition really shouldn't happen and it doesn't even make sense
  575. * to abort things like display initialization sequences. Just return
  576. * the first power well and hope the WARN gets reported so we can fix
  577. * our driver.
  578. */
  579. WARN(1, "Power well %d not defined for this platform\n", power_well_id);
  580. return &dev_priv->power_domains.power_wells[0];
  581. }
  582. static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
  583. {
  584. bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
  585. SKL_DISP_PW_2);
  586. WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
  587. WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
  588. "DC5 already programmed to be enabled.\n");
  589. assert_rpm_wakelock_held(dev_priv);
  590. assert_csr_loaded(dev_priv);
  591. }
  592. void gen9_enable_dc5(struct drm_i915_private *dev_priv)
  593. {
  594. assert_can_enable_dc5(dev_priv);
  595. DRM_DEBUG_KMS("Enabling DC5\n");
  596. /* Wa Display #1183: skl,kbl,cfl */
  597. if (IS_GEN9_BC(dev_priv))
  598. I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
  599. SKL_SELECT_ALTERNATE_DC_EXIT);
  600. gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
  601. }
  602. static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
  603. {
  604. WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  605. "Backlight is not disabled.\n");
  606. WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
  607. "DC6 already programmed to be enabled.\n");
  608. assert_csr_loaded(dev_priv);
  609. }
  610. static void skl_enable_dc6(struct drm_i915_private *dev_priv)
  611. {
  612. assert_can_enable_dc6(dev_priv);
  613. DRM_DEBUG_KMS("Enabling DC6\n");
  614. /* Wa Display #1183: skl,kbl,cfl */
  615. if (IS_GEN9_BC(dev_priv))
  616. I915_WRITE(GEN8_CHICKEN_DCPR_1, I915_READ(GEN8_CHICKEN_DCPR_1) |
  617. SKL_SELECT_ALTERNATE_DC_EXIT);
  618. gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
  619. }
  620. static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
  621. struct i915_power_well *power_well)
  622. {
  623. const struct i915_power_well_regs *regs = power_well->desc->hsw.regs;
  624. int pw_idx = power_well->desc->hsw.idx;
  625. u32 mask = HSW_PWR_WELL_CTL_REQ(pw_idx);
  626. u32 bios_req = I915_READ(regs->bios);
  627. /* Take over the request bit if set by BIOS. */
  628. if (bios_req & mask) {
  629. u32 drv_req = I915_READ(regs->driver);
  630. if (!(drv_req & mask))
  631. I915_WRITE(regs->driver, drv_req | mask);
  632. I915_WRITE(regs->bios, bios_req & ~mask);
  633. }
  634. }
  635. static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
  636. struct i915_power_well *power_well)
  637. {
  638. bxt_ddi_phy_init(dev_priv, power_well->desc->bxt.phy);
  639. }
  640. static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
  641. struct i915_power_well *power_well)
  642. {
  643. bxt_ddi_phy_uninit(dev_priv, power_well->desc->bxt.phy);
  644. }
  645. static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
  646. struct i915_power_well *power_well)
  647. {
  648. return bxt_ddi_phy_is_enabled(dev_priv, power_well->desc->bxt.phy);
  649. }
  650. static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
  651. {
  652. struct i915_power_well *power_well;
  653. power_well = lookup_power_well(dev_priv, BXT_DISP_PW_DPIO_CMN_A);
  654. if (power_well->count > 0)
  655. bxt_ddi_phy_verify_state(dev_priv, power_well->desc->bxt.phy);
  656. power_well = lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
  657. if (power_well->count > 0)
  658. bxt_ddi_phy_verify_state(dev_priv, power_well->desc->bxt.phy);
  659. if (IS_GEMINILAKE(dev_priv)) {
  660. power_well = lookup_power_well(dev_priv,
  661. GLK_DISP_PW_DPIO_CMN_C);
  662. if (power_well->count > 0)
  663. bxt_ddi_phy_verify_state(dev_priv,
  664. power_well->desc->bxt.phy);
  665. }
  666. }
  667. static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
  668. struct i915_power_well *power_well)
  669. {
  670. return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
  671. }
  672. static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
  673. {
  674. u32 tmp = I915_READ(DBUF_CTL);
  675. WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
  676. (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
  677. "Unexpected DBuf power power state (0x%08x)\n", tmp);
  678. }
  679. static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
  680. struct i915_power_well *power_well)
  681. {
  682. struct intel_cdclk_state cdclk_state = {};
  683. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  684. dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
  685. /* Can't read out voltage_level so can't use intel_cdclk_changed() */
  686. WARN_ON(intel_cdclk_needs_modeset(&dev_priv->cdclk.hw, &cdclk_state));
  687. gen9_assert_dbuf_enabled(dev_priv);
  688. if (IS_GEN9_LP(dev_priv))
  689. bxt_verify_ddi_phy_power_wells(dev_priv);
  690. }
  691. static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
  692. struct i915_power_well *power_well)
  693. {
  694. if (!dev_priv->csr.dmc_payload)
  695. return;
  696. if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
  697. skl_enable_dc6(dev_priv);
  698. else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
  699. gen9_enable_dc5(dev_priv);
  700. }
  701. static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
  702. struct i915_power_well *power_well)
  703. {
  704. }
  705. static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
  706. struct i915_power_well *power_well)
  707. {
  708. }
  709. static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
  710. struct i915_power_well *power_well)
  711. {
  712. return true;
  713. }
  714. static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
  715. struct i915_power_well *power_well)
  716. {
  717. if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
  718. i830_enable_pipe(dev_priv, PIPE_A);
  719. if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
  720. i830_enable_pipe(dev_priv, PIPE_B);
  721. }
  722. static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
  723. struct i915_power_well *power_well)
  724. {
  725. i830_disable_pipe(dev_priv, PIPE_B);
  726. i830_disable_pipe(dev_priv, PIPE_A);
  727. }
  728. static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
  729. struct i915_power_well *power_well)
  730. {
  731. return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
  732. I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
  733. }
  734. static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
  735. struct i915_power_well *power_well)
  736. {
  737. if (power_well->count > 0)
  738. i830_pipes_power_well_enable(dev_priv, power_well);
  739. else
  740. i830_pipes_power_well_disable(dev_priv, power_well);
  741. }
  742. static void vlv_set_power_well(struct drm_i915_private *dev_priv,
  743. struct i915_power_well *power_well, bool enable)
  744. {
  745. int pw_idx = power_well->desc->vlv.idx;
  746. u32 mask;
  747. u32 state;
  748. u32 ctrl;
  749. mask = PUNIT_PWRGT_MASK(pw_idx);
  750. state = enable ? PUNIT_PWRGT_PWR_ON(pw_idx) :
  751. PUNIT_PWRGT_PWR_GATE(pw_idx);
  752. mutex_lock(&dev_priv->pcu_lock);
  753. #define COND \
  754. ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
  755. if (COND)
  756. goto out;
  757. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
  758. ctrl &= ~mask;
  759. ctrl |= state;
  760. vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
  761. if (wait_for(COND, 100))
  762. DRM_ERROR("timeout setting power well state %08x (%08x)\n",
  763. state,
  764. vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
  765. #undef COND
  766. out:
  767. mutex_unlock(&dev_priv->pcu_lock);
  768. }
  769. static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
  770. struct i915_power_well *power_well)
  771. {
  772. vlv_set_power_well(dev_priv, power_well, true);
  773. }
  774. static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
  775. struct i915_power_well *power_well)
  776. {
  777. vlv_set_power_well(dev_priv, power_well, false);
  778. }
  779. static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
  780. struct i915_power_well *power_well)
  781. {
  782. int pw_idx = power_well->desc->vlv.idx;
  783. bool enabled = false;
  784. u32 mask;
  785. u32 state;
  786. u32 ctrl;
  787. mask = PUNIT_PWRGT_MASK(pw_idx);
  788. ctrl = PUNIT_PWRGT_PWR_ON(pw_idx);
  789. mutex_lock(&dev_priv->pcu_lock);
  790. state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
  791. /*
  792. * We only ever set the power-on and power-gate states, anything
  793. * else is unexpected.
  794. */
  795. WARN_ON(state != PUNIT_PWRGT_PWR_ON(pw_idx) &&
  796. state != PUNIT_PWRGT_PWR_GATE(pw_idx));
  797. if (state == ctrl)
  798. enabled = true;
  799. /*
  800. * A transient state at this point would mean some unexpected party
  801. * is poking at the power controls too.
  802. */
  803. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
  804. WARN_ON(ctrl != state);
  805. mutex_unlock(&dev_priv->pcu_lock);
  806. return enabled;
  807. }
  808. static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
  809. {
  810. u32 val;
  811. /*
  812. * On driver load, a pipe may be active and driving a DSI display.
  813. * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
  814. * (and never recovering) in this case. intel_dsi_post_disable() will
  815. * clear it when we turn off the display.
  816. */
  817. val = I915_READ(DSPCLK_GATE_D);
  818. val &= DPOUNIT_CLOCK_GATE_DISABLE;
  819. val |= VRHUNIT_CLOCK_GATE_DISABLE;
  820. I915_WRITE(DSPCLK_GATE_D, val);
  821. /*
  822. * Disable trickle feed and enable pnd deadline calculation
  823. */
  824. I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
  825. I915_WRITE(CBR1_VLV, 0);
  826. WARN_ON(dev_priv->rawclk_freq == 0);
  827. I915_WRITE(RAWCLK_FREQ_VLV,
  828. DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
  829. }
  830. static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
  831. {
  832. struct intel_encoder *encoder;
  833. enum pipe pipe;
  834. /*
  835. * Enable the CRI clock source so we can get at the
  836. * display and the reference clock for VGA
  837. * hotplug / manual detection. Supposedly DSI also
  838. * needs the ref clock up and running.
  839. *
  840. * CHV DPLL B/C have some issues if VGA mode is enabled.
  841. */
  842. for_each_pipe(dev_priv, pipe) {
  843. u32 val = I915_READ(DPLL(pipe));
  844. val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
  845. if (pipe != PIPE_A)
  846. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  847. I915_WRITE(DPLL(pipe), val);
  848. }
  849. vlv_init_display_clock_gating(dev_priv);
  850. spin_lock_irq(&dev_priv->irq_lock);
  851. valleyview_enable_display_irqs(dev_priv);
  852. spin_unlock_irq(&dev_priv->irq_lock);
  853. /*
  854. * During driver initialization/resume we can avoid restoring the
  855. * part of the HW/SW state that will be inited anyway explicitly.
  856. */
  857. if (dev_priv->power_domains.initializing)
  858. return;
  859. intel_hpd_init(dev_priv);
  860. /* Re-enable the ADPA, if we have one */
  861. for_each_intel_encoder(&dev_priv->drm, encoder) {
  862. if (encoder->type == INTEL_OUTPUT_ANALOG)
  863. intel_crt_reset(&encoder->base);
  864. }
  865. i915_redisable_vga_power_on(dev_priv);
  866. intel_pps_unlock_regs_wa(dev_priv);
  867. }
  868. static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
  869. {
  870. spin_lock_irq(&dev_priv->irq_lock);
  871. valleyview_disable_display_irqs(dev_priv);
  872. spin_unlock_irq(&dev_priv->irq_lock);
  873. /* make sure we're done processing display irqs */
  874. synchronize_irq(dev_priv->drm.irq);
  875. intel_power_sequencer_reset(dev_priv);
  876. /* Prevent us from re-enabling polling on accident in late suspend */
  877. if (!dev_priv->drm.dev->power.is_suspended)
  878. intel_hpd_poll_init(dev_priv);
  879. }
  880. static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
  881. struct i915_power_well *power_well)
  882. {
  883. vlv_set_power_well(dev_priv, power_well, true);
  884. vlv_display_power_well_init(dev_priv);
  885. }
  886. static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
  887. struct i915_power_well *power_well)
  888. {
  889. vlv_display_power_well_deinit(dev_priv);
  890. vlv_set_power_well(dev_priv, power_well, false);
  891. }
  892. static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
  893. struct i915_power_well *power_well)
  894. {
  895. /* since ref/cri clock was enabled */
  896. udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
  897. vlv_set_power_well(dev_priv, power_well, true);
  898. /*
  899. * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
  900. * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
  901. * a. GUnit 0x2110 bit[0] set to 1 (def 0)
  902. * b. The other bits such as sfr settings / modesel may all
  903. * be set to 0.
  904. *
  905. * This should only be done on init and resume from S3 with
  906. * both PLLs disabled, or we risk losing DPIO and PLL
  907. * synchronization.
  908. */
  909. I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
  910. }
  911. static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
  912. struct i915_power_well *power_well)
  913. {
  914. enum pipe pipe;
  915. for_each_pipe(dev_priv, pipe)
  916. assert_pll_disabled(dev_priv, pipe);
  917. /* Assert common reset */
  918. I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
  919. vlv_set_power_well(dev_priv, power_well, false);
  920. }
  921. #define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
  922. #define BITS_SET(val, bits) (((val) & (bits)) == (bits))
  923. static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
  924. {
  925. struct i915_power_well *cmn_bc =
  926. lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
  927. struct i915_power_well *cmn_d =
  928. lookup_power_well(dev_priv, CHV_DISP_PW_DPIO_CMN_D);
  929. u32 phy_control = dev_priv->chv_phy_control;
  930. u32 phy_status = 0;
  931. u32 phy_status_mask = 0xffffffff;
  932. /*
  933. * The BIOS can leave the PHY is some weird state
  934. * where it doesn't fully power down some parts.
  935. * Disable the asserts until the PHY has been fully
  936. * reset (ie. the power well has been disabled at
  937. * least once).
  938. */
  939. if (!dev_priv->chv_phy_assert[DPIO_PHY0])
  940. phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
  941. PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
  942. PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
  943. PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
  944. PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
  945. PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
  946. if (!dev_priv->chv_phy_assert[DPIO_PHY1])
  947. phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
  948. PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
  949. PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
  950. if (cmn_bc->desc->ops->is_enabled(dev_priv, cmn_bc)) {
  951. phy_status |= PHY_POWERGOOD(DPIO_PHY0);
  952. /* this assumes override is only used to enable lanes */
  953. if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
  954. phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
  955. if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
  956. phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
  957. /* CL1 is on whenever anything is on in either channel */
  958. if (BITS_SET(phy_control,
  959. PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
  960. PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
  961. phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
  962. /*
  963. * The DPLLB check accounts for the pipe B + port A usage
  964. * with CL2 powered up but all the lanes in the second channel
  965. * powered down.
  966. */
  967. if (BITS_SET(phy_control,
  968. PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
  969. (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
  970. phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
  971. if (BITS_SET(phy_control,
  972. PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
  973. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
  974. if (BITS_SET(phy_control,
  975. PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
  976. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
  977. if (BITS_SET(phy_control,
  978. PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
  979. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
  980. if (BITS_SET(phy_control,
  981. PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
  982. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
  983. }
  984. if (cmn_d->desc->ops->is_enabled(dev_priv, cmn_d)) {
  985. phy_status |= PHY_POWERGOOD(DPIO_PHY1);
  986. /* this assumes override is only used to enable lanes */
  987. if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
  988. phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
  989. if (BITS_SET(phy_control,
  990. PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
  991. phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
  992. if (BITS_SET(phy_control,
  993. PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
  994. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
  995. if (BITS_SET(phy_control,
  996. PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
  997. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
  998. }
  999. phy_status &= phy_status_mask;
  1000. /*
  1001. * The PHY may be busy with some initial calibration and whatnot,
  1002. * so the power state can take a while to actually change.
  1003. */
  1004. if (intel_wait_for_register(dev_priv,
  1005. DISPLAY_PHY_STATUS,
  1006. phy_status_mask,
  1007. phy_status,
  1008. 10))
  1009. DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
  1010. I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
  1011. phy_status, dev_priv->chv_phy_control);
  1012. }
  1013. #undef BITS_SET
  1014. static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
  1015. struct i915_power_well *power_well)
  1016. {
  1017. enum dpio_phy phy;
  1018. enum pipe pipe;
  1019. uint32_t tmp;
  1020. WARN_ON_ONCE(power_well->desc->id != VLV_DISP_PW_DPIO_CMN_BC &&
  1021. power_well->desc->id != CHV_DISP_PW_DPIO_CMN_D);
  1022. if (power_well->desc->id == VLV_DISP_PW_DPIO_CMN_BC) {
  1023. pipe = PIPE_A;
  1024. phy = DPIO_PHY0;
  1025. } else {
  1026. pipe = PIPE_C;
  1027. phy = DPIO_PHY1;
  1028. }
  1029. /* since ref/cri clock was enabled */
  1030. udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
  1031. vlv_set_power_well(dev_priv, power_well, true);
  1032. /* Poll for phypwrgood signal */
  1033. if (intel_wait_for_register(dev_priv,
  1034. DISPLAY_PHY_STATUS,
  1035. PHY_POWERGOOD(phy),
  1036. PHY_POWERGOOD(phy),
  1037. 1))
  1038. DRM_ERROR("Display PHY %d is not power up\n", phy);
  1039. mutex_lock(&dev_priv->sb_lock);
  1040. /* Enable dynamic power down */
  1041. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
  1042. tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
  1043. DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
  1044. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
  1045. if (power_well->desc->id == VLV_DISP_PW_DPIO_CMN_BC) {
  1046. tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
  1047. tmp |= DPIO_DYNPWRDOWNEN_CH1;
  1048. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
  1049. } else {
  1050. /*
  1051. * Force the non-existing CL2 off. BXT does this
  1052. * too, so maybe it saves some power even though
  1053. * CL2 doesn't exist?
  1054. */
  1055. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
  1056. tmp |= DPIO_CL2_LDOFUSE_PWRENB;
  1057. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
  1058. }
  1059. mutex_unlock(&dev_priv->sb_lock);
  1060. dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
  1061. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  1062. DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
  1063. phy, dev_priv->chv_phy_control);
  1064. assert_chv_phy_status(dev_priv);
  1065. }
  1066. static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
  1067. struct i915_power_well *power_well)
  1068. {
  1069. enum dpio_phy phy;
  1070. WARN_ON_ONCE(power_well->desc->id != VLV_DISP_PW_DPIO_CMN_BC &&
  1071. power_well->desc->id != CHV_DISP_PW_DPIO_CMN_D);
  1072. if (power_well->desc->id == VLV_DISP_PW_DPIO_CMN_BC) {
  1073. phy = DPIO_PHY0;
  1074. assert_pll_disabled(dev_priv, PIPE_A);
  1075. assert_pll_disabled(dev_priv, PIPE_B);
  1076. } else {
  1077. phy = DPIO_PHY1;
  1078. assert_pll_disabled(dev_priv, PIPE_C);
  1079. }
  1080. dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
  1081. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  1082. vlv_set_power_well(dev_priv, power_well, false);
  1083. DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
  1084. phy, dev_priv->chv_phy_control);
  1085. /* PHY is fully reset now, so we can enable the PHY state asserts */
  1086. dev_priv->chv_phy_assert[phy] = true;
  1087. assert_chv_phy_status(dev_priv);
  1088. }
  1089. static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
  1090. enum dpio_channel ch, bool override, unsigned int mask)
  1091. {
  1092. enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
  1093. u32 reg, val, expected, actual;
  1094. /*
  1095. * The BIOS can leave the PHY is some weird state
  1096. * where it doesn't fully power down some parts.
  1097. * Disable the asserts until the PHY has been fully
  1098. * reset (ie. the power well has been disabled at
  1099. * least once).
  1100. */
  1101. if (!dev_priv->chv_phy_assert[phy])
  1102. return;
  1103. if (ch == DPIO_CH0)
  1104. reg = _CHV_CMN_DW0_CH0;
  1105. else
  1106. reg = _CHV_CMN_DW6_CH1;
  1107. mutex_lock(&dev_priv->sb_lock);
  1108. val = vlv_dpio_read(dev_priv, pipe, reg);
  1109. mutex_unlock(&dev_priv->sb_lock);
  1110. /*
  1111. * This assumes !override is only used when the port is disabled.
  1112. * All lanes should power down even without the override when
  1113. * the port is disabled.
  1114. */
  1115. if (!override || mask == 0xf) {
  1116. expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
  1117. /*
  1118. * If CH1 common lane is not active anymore
  1119. * (eg. for pipe B DPLL) the entire channel will
  1120. * shut down, which causes the common lane registers
  1121. * to read as 0. That means we can't actually check
  1122. * the lane power down status bits, but as the entire
  1123. * register reads as 0 it's a good indication that the
  1124. * channel is indeed entirely powered down.
  1125. */
  1126. if (ch == DPIO_CH1 && val == 0)
  1127. expected = 0;
  1128. } else if (mask != 0x0) {
  1129. expected = DPIO_ANYDL_POWERDOWN;
  1130. } else {
  1131. expected = 0;
  1132. }
  1133. if (ch == DPIO_CH0)
  1134. actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
  1135. else
  1136. actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
  1137. actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
  1138. WARN(actual != expected,
  1139. "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
  1140. !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
  1141. !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
  1142. reg, val);
  1143. }
  1144. bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
  1145. enum dpio_channel ch, bool override)
  1146. {
  1147. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1148. bool was_override;
  1149. mutex_lock(&power_domains->lock);
  1150. was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1151. if (override == was_override)
  1152. goto out;
  1153. if (override)
  1154. dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1155. else
  1156. dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1157. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  1158. DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
  1159. phy, ch, dev_priv->chv_phy_control);
  1160. assert_chv_phy_status(dev_priv);
  1161. out:
  1162. mutex_unlock(&power_domains->lock);
  1163. return was_override;
  1164. }
  1165. void chv_phy_powergate_lanes(struct intel_encoder *encoder,
  1166. bool override, unsigned int mask)
  1167. {
  1168. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1169. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1170. enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
  1171. enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
  1172. mutex_lock(&power_domains->lock);
  1173. dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
  1174. dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
  1175. if (override)
  1176. dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1177. else
  1178. dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1179. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  1180. DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
  1181. phy, ch, mask, dev_priv->chv_phy_control);
  1182. assert_chv_phy_status(dev_priv);
  1183. assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
  1184. mutex_unlock(&power_domains->lock);
  1185. }
  1186. static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
  1187. struct i915_power_well *power_well)
  1188. {
  1189. enum pipe pipe = PIPE_A;
  1190. bool enabled;
  1191. u32 state, ctrl;
  1192. mutex_lock(&dev_priv->pcu_lock);
  1193. state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
  1194. /*
  1195. * We only ever set the power-on and power-gate states, anything
  1196. * else is unexpected.
  1197. */
  1198. WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
  1199. enabled = state == DP_SSS_PWR_ON(pipe);
  1200. /*
  1201. * A transient state at this point would mean some unexpected party
  1202. * is poking at the power controls too.
  1203. */
  1204. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
  1205. WARN_ON(ctrl << 16 != state);
  1206. mutex_unlock(&dev_priv->pcu_lock);
  1207. return enabled;
  1208. }
  1209. static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
  1210. struct i915_power_well *power_well,
  1211. bool enable)
  1212. {
  1213. enum pipe pipe = PIPE_A;
  1214. u32 state;
  1215. u32 ctrl;
  1216. state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
  1217. mutex_lock(&dev_priv->pcu_lock);
  1218. #define COND \
  1219. ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
  1220. if (COND)
  1221. goto out;
  1222. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  1223. ctrl &= ~DP_SSC_MASK(pipe);
  1224. ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
  1225. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
  1226. if (wait_for(COND, 100))
  1227. DRM_ERROR("timeout setting power well state %08x (%08x)\n",
  1228. state,
  1229. vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
  1230. #undef COND
  1231. out:
  1232. mutex_unlock(&dev_priv->pcu_lock);
  1233. }
  1234. static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
  1235. struct i915_power_well *power_well)
  1236. {
  1237. chv_set_pipe_power_well(dev_priv, power_well, true);
  1238. vlv_display_power_well_init(dev_priv);
  1239. }
  1240. static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
  1241. struct i915_power_well *power_well)
  1242. {
  1243. vlv_display_power_well_deinit(dev_priv);
  1244. chv_set_pipe_power_well(dev_priv, power_well, false);
  1245. }
  1246. static void
  1247. __intel_display_power_get_domain(struct drm_i915_private *dev_priv,
  1248. enum intel_display_power_domain domain)
  1249. {
  1250. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1251. struct i915_power_well *power_well;
  1252. for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
  1253. intel_power_well_get(dev_priv, power_well);
  1254. power_domains->domain_use_count[domain]++;
  1255. }
  1256. /**
  1257. * intel_display_power_get - grab a power domain reference
  1258. * @dev_priv: i915 device instance
  1259. * @domain: power domain to reference
  1260. *
  1261. * This function grabs a power domain reference for @domain and ensures that the
  1262. * power domain and all its parents are powered up. Therefore users should only
  1263. * grab a reference to the innermost power domain they need.
  1264. *
  1265. * Any power domain reference obtained by this function must have a symmetric
  1266. * call to intel_display_power_put() to release the reference again.
  1267. */
  1268. void intel_display_power_get(struct drm_i915_private *dev_priv,
  1269. enum intel_display_power_domain domain)
  1270. {
  1271. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1272. intel_runtime_pm_get(dev_priv);
  1273. mutex_lock(&power_domains->lock);
  1274. __intel_display_power_get_domain(dev_priv, domain);
  1275. mutex_unlock(&power_domains->lock);
  1276. }
  1277. /**
  1278. * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
  1279. * @dev_priv: i915 device instance
  1280. * @domain: power domain to reference
  1281. *
  1282. * This function grabs a power domain reference for @domain and ensures that the
  1283. * power domain and all its parents are powered up. Therefore users should only
  1284. * grab a reference to the innermost power domain they need.
  1285. *
  1286. * Any power domain reference obtained by this function must have a symmetric
  1287. * call to intel_display_power_put() to release the reference again.
  1288. */
  1289. bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
  1290. enum intel_display_power_domain domain)
  1291. {
  1292. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1293. bool is_enabled;
  1294. if (!intel_runtime_pm_get_if_in_use(dev_priv))
  1295. return false;
  1296. mutex_lock(&power_domains->lock);
  1297. if (__intel_display_power_is_enabled(dev_priv, domain)) {
  1298. __intel_display_power_get_domain(dev_priv, domain);
  1299. is_enabled = true;
  1300. } else {
  1301. is_enabled = false;
  1302. }
  1303. mutex_unlock(&power_domains->lock);
  1304. if (!is_enabled)
  1305. intel_runtime_pm_put(dev_priv);
  1306. return is_enabled;
  1307. }
  1308. /**
  1309. * intel_display_power_put - release a power domain reference
  1310. * @dev_priv: i915 device instance
  1311. * @domain: power domain to reference
  1312. *
  1313. * This function drops the power domain reference obtained by
  1314. * intel_display_power_get() and might power down the corresponding hardware
  1315. * block right away if this is the last reference.
  1316. */
  1317. void intel_display_power_put(struct drm_i915_private *dev_priv,
  1318. enum intel_display_power_domain domain)
  1319. {
  1320. struct i915_power_domains *power_domains;
  1321. struct i915_power_well *power_well;
  1322. power_domains = &dev_priv->power_domains;
  1323. mutex_lock(&power_domains->lock);
  1324. WARN(!power_domains->domain_use_count[domain],
  1325. "Use count on domain %s is already zero\n",
  1326. intel_display_power_domain_str(domain));
  1327. power_domains->domain_use_count[domain]--;
  1328. for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
  1329. intel_power_well_put(dev_priv, power_well);
  1330. mutex_unlock(&power_domains->lock);
  1331. intel_runtime_pm_put(dev_priv);
  1332. }
  1333. #define I830_PIPES_POWER_DOMAINS ( \
  1334. BIT_ULL(POWER_DOMAIN_PIPE_A) | \
  1335. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1336. BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
  1337. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1338. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1339. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1340. BIT_ULL(POWER_DOMAIN_INIT))
  1341. #define VLV_DISPLAY_POWER_DOMAINS ( \
  1342. BIT_ULL(POWER_DOMAIN_PIPE_A) | \
  1343. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1344. BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
  1345. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1346. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1347. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1348. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1349. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1350. BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
  1351. BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
  1352. BIT_ULL(POWER_DOMAIN_VGA) | \
  1353. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1354. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1355. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1356. BIT_ULL(POWER_DOMAIN_GMBUS) | \
  1357. BIT_ULL(POWER_DOMAIN_INIT))
  1358. #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
  1359. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1360. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1361. BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
  1362. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1363. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1364. BIT_ULL(POWER_DOMAIN_INIT))
  1365. #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
  1366. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1367. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1368. BIT_ULL(POWER_DOMAIN_INIT))
  1369. #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
  1370. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1371. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1372. BIT_ULL(POWER_DOMAIN_INIT))
  1373. #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
  1374. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1375. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1376. BIT_ULL(POWER_DOMAIN_INIT))
  1377. #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
  1378. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1379. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1380. BIT_ULL(POWER_DOMAIN_INIT))
  1381. #define CHV_DISPLAY_POWER_DOMAINS ( \
  1382. BIT_ULL(POWER_DOMAIN_PIPE_A) | \
  1383. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1384. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1385. BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
  1386. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1387. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1388. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1389. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1390. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1391. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1392. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1393. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
  1394. BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
  1395. BIT_ULL(POWER_DOMAIN_VGA) | \
  1396. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1397. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1398. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1399. BIT_ULL(POWER_DOMAIN_AUX_D) | \
  1400. BIT_ULL(POWER_DOMAIN_GMBUS) | \
  1401. BIT_ULL(POWER_DOMAIN_INIT))
  1402. #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
  1403. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1404. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1405. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1406. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1407. BIT_ULL(POWER_DOMAIN_INIT))
  1408. #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
  1409. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
  1410. BIT_ULL(POWER_DOMAIN_AUX_D) | \
  1411. BIT_ULL(POWER_DOMAIN_INIT))
  1412. #define HSW_DISPLAY_POWER_DOMAINS ( \
  1413. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1414. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1415. BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
  1416. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1417. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1418. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1419. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1420. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1421. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1422. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1423. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
  1424. BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
  1425. BIT_ULL(POWER_DOMAIN_VGA) | \
  1426. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1427. BIT_ULL(POWER_DOMAIN_INIT))
  1428. #define BDW_DISPLAY_POWER_DOMAINS ( \
  1429. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1430. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1431. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1432. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1433. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1434. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1435. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1436. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1437. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1438. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
  1439. BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
  1440. BIT_ULL(POWER_DOMAIN_VGA) | \
  1441. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1442. BIT_ULL(POWER_DOMAIN_INIT))
  1443. #define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
  1444. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1445. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1446. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1447. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1448. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1449. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1450. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1451. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1452. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1453. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
  1454. BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
  1455. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1456. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1457. BIT_ULL(POWER_DOMAIN_AUX_D) | \
  1458. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1459. BIT_ULL(POWER_DOMAIN_VGA) | \
  1460. BIT_ULL(POWER_DOMAIN_INIT))
  1461. #define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
  1462. BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
  1463. BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
  1464. BIT_ULL(POWER_DOMAIN_INIT))
  1465. #define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
  1466. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
  1467. BIT_ULL(POWER_DOMAIN_INIT))
  1468. #define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
  1469. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
  1470. BIT_ULL(POWER_DOMAIN_INIT))
  1471. #define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
  1472. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
  1473. BIT_ULL(POWER_DOMAIN_INIT))
  1474. #define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
  1475. SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  1476. BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
  1477. BIT_ULL(POWER_DOMAIN_MODESET) | \
  1478. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1479. BIT_ULL(POWER_DOMAIN_INIT))
  1480. #define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
  1481. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1482. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1483. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1484. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1485. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1486. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1487. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1488. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1489. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1490. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1491. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1492. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1493. BIT_ULL(POWER_DOMAIN_VGA) | \
  1494. BIT_ULL(POWER_DOMAIN_INIT))
  1495. #define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
  1496. BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  1497. BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
  1498. BIT_ULL(POWER_DOMAIN_MODESET) | \
  1499. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1500. BIT_ULL(POWER_DOMAIN_GMBUS) | \
  1501. BIT_ULL(POWER_DOMAIN_INIT))
  1502. #define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
  1503. BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
  1504. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1505. BIT_ULL(POWER_DOMAIN_INIT))
  1506. #define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
  1507. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1508. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1509. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1510. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1511. BIT_ULL(POWER_DOMAIN_INIT))
  1512. #define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
  1513. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1514. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1515. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1516. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1517. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1518. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1519. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1520. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1521. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1522. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1523. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1524. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1525. BIT_ULL(POWER_DOMAIN_VGA) | \
  1526. BIT_ULL(POWER_DOMAIN_INIT))
  1527. #define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
  1528. BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
  1529. #define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
  1530. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
  1531. #define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
  1532. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
  1533. #define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
  1534. BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
  1535. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1536. BIT_ULL(POWER_DOMAIN_INIT))
  1537. #define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
  1538. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1539. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1540. BIT_ULL(POWER_DOMAIN_INIT))
  1541. #define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
  1542. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1543. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1544. BIT_ULL(POWER_DOMAIN_INIT))
  1545. #define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
  1546. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1547. BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
  1548. BIT_ULL(POWER_DOMAIN_INIT))
  1549. #define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
  1550. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1551. BIT_ULL(POWER_DOMAIN_INIT))
  1552. #define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
  1553. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1554. BIT_ULL(POWER_DOMAIN_INIT))
  1555. #define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
  1556. GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  1557. BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
  1558. BIT_ULL(POWER_DOMAIN_MODESET) | \
  1559. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1560. BIT_ULL(POWER_DOMAIN_GMBUS) | \
  1561. BIT_ULL(POWER_DOMAIN_INIT))
  1562. #define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
  1563. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1564. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1565. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1566. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1567. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1568. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1569. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1570. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1571. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1572. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
  1573. BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
  1574. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1575. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1576. BIT_ULL(POWER_DOMAIN_AUX_D) | \
  1577. BIT_ULL(POWER_DOMAIN_AUX_F) | \
  1578. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1579. BIT_ULL(POWER_DOMAIN_VGA) | \
  1580. BIT_ULL(POWER_DOMAIN_INIT))
  1581. #define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
  1582. BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
  1583. BIT_ULL(POWER_DOMAIN_INIT))
  1584. #define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
  1585. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
  1586. BIT_ULL(POWER_DOMAIN_INIT))
  1587. #define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
  1588. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
  1589. BIT_ULL(POWER_DOMAIN_INIT))
  1590. #define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
  1591. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
  1592. BIT_ULL(POWER_DOMAIN_INIT))
  1593. #define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
  1594. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1595. BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
  1596. BIT_ULL(POWER_DOMAIN_INIT))
  1597. #define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
  1598. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1599. BIT_ULL(POWER_DOMAIN_INIT))
  1600. #define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
  1601. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1602. BIT_ULL(POWER_DOMAIN_INIT))
  1603. #define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
  1604. BIT_ULL(POWER_DOMAIN_AUX_D) | \
  1605. BIT_ULL(POWER_DOMAIN_INIT))
  1606. #define CNL_DISPLAY_AUX_F_POWER_DOMAINS ( \
  1607. BIT_ULL(POWER_DOMAIN_AUX_F) | \
  1608. BIT_ULL(POWER_DOMAIN_INIT))
  1609. #define CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS ( \
  1610. BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
  1611. BIT_ULL(POWER_DOMAIN_INIT))
  1612. #define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
  1613. CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  1614. BIT_ULL(POWER_DOMAIN_GT_IRQ) | \
  1615. BIT_ULL(POWER_DOMAIN_MODESET) | \
  1616. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1617. BIT_ULL(POWER_DOMAIN_INIT))
  1618. /*
  1619. * ICL PW_0/PG_0 domains (HW/DMC control):
  1620. * - PCI
  1621. * - clocks except port PLL
  1622. * - central power except FBC
  1623. * - shared functions except pipe interrupts, pipe MBUS, DBUF registers
  1624. * ICL PW_1/PG_1 domains (HW/DMC control):
  1625. * - DBUF function
  1626. * - PIPE_A and its planes, except VGA
  1627. * - transcoder EDP + PSR
  1628. * - transcoder DSI
  1629. * - DDI_A
  1630. * - FBC
  1631. */
  1632. #define ICL_PW_4_POWER_DOMAINS ( \
  1633. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1634. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1635. BIT_ULL(POWER_DOMAIN_INIT))
  1636. /* VDSC/joining */
  1637. #define ICL_PW_3_POWER_DOMAINS ( \
  1638. ICL_PW_4_POWER_DOMAINS | \
  1639. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1640. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1641. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1642. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1643. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1644. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1645. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
  1646. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1647. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
  1648. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
  1649. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
  1650. BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
  1651. BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
  1652. BIT_ULL(POWER_DOMAIN_PORT_DDI_F_LANES) | \
  1653. BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO) | \
  1654. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1655. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1656. BIT_ULL(POWER_DOMAIN_AUX_D) | \
  1657. BIT_ULL(POWER_DOMAIN_AUX_E) | \
  1658. BIT_ULL(POWER_DOMAIN_AUX_F) | \
  1659. BIT_ULL(POWER_DOMAIN_AUX_TBT1) | \
  1660. BIT_ULL(POWER_DOMAIN_AUX_TBT2) | \
  1661. BIT_ULL(POWER_DOMAIN_AUX_TBT3) | \
  1662. BIT_ULL(POWER_DOMAIN_AUX_TBT4) | \
  1663. BIT_ULL(POWER_DOMAIN_VGA) | \
  1664. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1665. BIT_ULL(POWER_DOMAIN_INIT))
  1666. /*
  1667. * - transcoder WD
  1668. * - KVMR (HW control)
  1669. */
  1670. #define ICL_PW_2_POWER_DOMAINS ( \
  1671. ICL_PW_3_POWER_DOMAINS | \
  1672. BIT_ULL(POWER_DOMAIN_INIT))
  1673. /*
  1674. * - eDP/DSI VDSC
  1675. * - KVMR (HW control)
  1676. */
  1677. #define ICL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
  1678. ICL_PW_2_POWER_DOMAINS | \
  1679. BIT_ULL(POWER_DOMAIN_MODESET) | \
  1680. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1681. BIT_ULL(POWER_DOMAIN_INIT))
  1682. #define ICL_DDI_IO_A_POWER_DOMAINS ( \
  1683. BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
  1684. #define ICL_DDI_IO_B_POWER_DOMAINS ( \
  1685. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
  1686. #define ICL_DDI_IO_C_POWER_DOMAINS ( \
  1687. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
  1688. #define ICL_DDI_IO_D_POWER_DOMAINS ( \
  1689. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO))
  1690. #define ICL_DDI_IO_E_POWER_DOMAINS ( \
  1691. BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO))
  1692. #define ICL_DDI_IO_F_POWER_DOMAINS ( \
  1693. BIT_ULL(POWER_DOMAIN_PORT_DDI_F_IO))
  1694. #define ICL_AUX_A_IO_POWER_DOMAINS ( \
  1695. BIT_ULL(POWER_DOMAIN_AUX_IO_A) | \
  1696. BIT_ULL(POWER_DOMAIN_AUX_A))
  1697. #define ICL_AUX_B_IO_POWER_DOMAINS ( \
  1698. BIT_ULL(POWER_DOMAIN_AUX_B))
  1699. #define ICL_AUX_C_IO_POWER_DOMAINS ( \
  1700. BIT_ULL(POWER_DOMAIN_AUX_C))
  1701. #define ICL_AUX_D_IO_POWER_DOMAINS ( \
  1702. BIT_ULL(POWER_DOMAIN_AUX_D))
  1703. #define ICL_AUX_E_IO_POWER_DOMAINS ( \
  1704. BIT_ULL(POWER_DOMAIN_AUX_E))
  1705. #define ICL_AUX_F_IO_POWER_DOMAINS ( \
  1706. BIT_ULL(POWER_DOMAIN_AUX_F))
  1707. #define ICL_AUX_TBT1_IO_POWER_DOMAINS ( \
  1708. BIT_ULL(POWER_DOMAIN_AUX_TBT1))
  1709. #define ICL_AUX_TBT2_IO_POWER_DOMAINS ( \
  1710. BIT_ULL(POWER_DOMAIN_AUX_TBT2))
  1711. #define ICL_AUX_TBT3_IO_POWER_DOMAINS ( \
  1712. BIT_ULL(POWER_DOMAIN_AUX_TBT3))
  1713. #define ICL_AUX_TBT4_IO_POWER_DOMAINS ( \
  1714. BIT_ULL(POWER_DOMAIN_AUX_TBT4))
  1715. static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
  1716. .sync_hw = i9xx_power_well_sync_hw_noop,
  1717. .enable = i9xx_always_on_power_well_noop,
  1718. .disable = i9xx_always_on_power_well_noop,
  1719. .is_enabled = i9xx_always_on_power_well_enabled,
  1720. };
  1721. static const struct i915_power_well_ops chv_pipe_power_well_ops = {
  1722. .sync_hw = i9xx_power_well_sync_hw_noop,
  1723. .enable = chv_pipe_power_well_enable,
  1724. .disable = chv_pipe_power_well_disable,
  1725. .is_enabled = chv_pipe_power_well_enabled,
  1726. };
  1727. static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
  1728. .sync_hw = i9xx_power_well_sync_hw_noop,
  1729. .enable = chv_dpio_cmn_power_well_enable,
  1730. .disable = chv_dpio_cmn_power_well_disable,
  1731. .is_enabled = vlv_power_well_enabled,
  1732. };
  1733. static const struct i915_power_well_desc i9xx_always_on_power_well[] = {
  1734. {
  1735. .name = "always-on",
  1736. .always_on = 1,
  1737. .domains = POWER_DOMAIN_MASK,
  1738. .ops = &i9xx_always_on_power_well_ops,
  1739. .id = DISP_PW_ID_NONE,
  1740. },
  1741. };
  1742. static const struct i915_power_well_ops i830_pipes_power_well_ops = {
  1743. .sync_hw = i830_pipes_power_well_sync_hw,
  1744. .enable = i830_pipes_power_well_enable,
  1745. .disable = i830_pipes_power_well_disable,
  1746. .is_enabled = i830_pipes_power_well_enabled,
  1747. };
  1748. static const struct i915_power_well_desc i830_power_wells[] = {
  1749. {
  1750. .name = "always-on",
  1751. .always_on = 1,
  1752. .domains = POWER_DOMAIN_MASK,
  1753. .ops = &i9xx_always_on_power_well_ops,
  1754. .id = DISP_PW_ID_NONE,
  1755. },
  1756. {
  1757. .name = "pipes",
  1758. .domains = I830_PIPES_POWER_DOMAINS,
  1759. .ops = &i830_pipes_power_well_ops,
  1760. .id = DISP_PW_ID_NONE,
  1761. },
  1762. };
  1763. static const struct i915_power_well_ops hsw_power_well_ops = {
  1764. .sync_hw = hsw_power_well_sync_hw,
  1765. .enable = hsw_power_well_enable,
  1766. .disable = hsw_power_well_disable,
  1767. .is_enabled = hsw_power_well_enabled,
  1768. };
  1769. static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
  1770. .sync_hw = i9xx_power_well_sync_hw_noop,
  1771. .enable = gen9_dc_off_power_well_enable,
  1772. .disable = gen9_dc_off_power_well_disable,
  1773. .is_enabled = gen9_dc_off_power_well_enabled,
  1774. };
  1775. static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
  1776. .sync_hw = i9xx_power_well_sync_hw_noop,
  1777. .enable = bxt_dpio_cmn_power_well_enable,
  1778. .disable = bxt_dpio_cmn_power_well_disable,
  1779. .is_enabled = bxt_dpio_cmn_power_well_enabled,
  1780. };
  1781. static const struct i915_power_well_regs hsw_power_well_regs = {
  1782. .bios = HSW_PWR_WELL_CTL1,
  1783. .driver = HSW_PWR_WELL_CTL2,
  1784. .kvmr = HSW_PWR_WELL_CTL3,
  1785. .debug = HSW_PWR_WELL_CTL4,
  1786. };
  1787. static const struct i915_power_well_desc hsw_power_wells[] = {
  1788. {
  1789. .name = "always-on",
  1790. .always_on = 1,
  1791. .domains = POWER_DOMAIN_MASK,
  1792. .ops = &i9xx_always_on_power_well_ops,
  1793. .id = DISP_PW_ID_NONE,
  1794. },
  1795. {
  1796. .name = "display",
  1797. .domains = HSW_DISPLAY_POWER_DOMAINS,
  1798. .ops = &hsw_power_well_ops,
  1799. .id = HSW_DISP_PW_GLOBAL,
  1800. {
  1801. .hsw.regs = &hsw_power_well_regs,
  1802. .hsw.idx = HSW_PW_CTL_IDX_GLOBAL,
  1803. .hsw.has_vga = true,
  1804. },
  1805. },
  1806. };
  1807. static const struct i915_power_well_desc bdw_power_wells[] = {
  1808. {
  1809. .name = "always-on",
  1810. .always_on = 1,
  1811. .domains = POWER_DOMAIN_MASK,
  1812. .ops = &i9xx_always_on_power_well_ops,
  1813. .id = DISP_PW_ID_NONE,
  1814. },
  1815. {
  1816. .name = "display",
  1817. .domains = BDW_DISPLAY_POWER_DOMAINS,
  1818. .ops = &hsw_power_well_ops,
  1819. .id = HSW_DISP_PW_GLOBAL,
  1820. {
  1821. .hsw.regs = &hsw_power_well_regs,
  1822. .hsw.idx = HSW_PW_CTL_IDX_GLOBAL,
  1823. .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
  1824. .hsw.has_vga = true,
  1825. },
  1826. },
  1827. };
  1828. static const struct i915_power_well_ops vlv_display_power_well_ops = {
  1829. .sync_hw = i9xx_power_well_sync_hw_noop,
  1830. .enable = vlv_display_power_well_enable,
  1831. .disable = vlv_display_power_well_disable,
  1832. .is_enabled = vlv_power_well_enabled,
  1833. };
  1834. static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
  1835. .sync_hw = i9xx_power_well_sync_hw_noop,
  1836. .enable = vlv_dpio_cmn_power_well_enable,
  1837. .disable = vlv_dpio_cmn_power_well_disable,
  1838. .is_enabled = vlv_power_well_enabled,
  1839. };
  1840. static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
  1841. .sync_hw = i9xx_power_well_sync_hw_noop,
  1842. .enable = vlv_power_well_enable,
  1843. .disable = vlv_power_well_disable,
  1844. .is_enabled = vlv_power_well_enabled,
  1845. };
  1846. static const struct i915_power_well_desc vlv_power_wells[] = {
  1847. {
  1848. .name = "always-on",
  1849. .always_on = 1,
  1850. .domains = POWER_DOMAIN_MASK,
  1851. .ops = &i9xx_always_on_power_well_ops,
  1852. .id = DISP_PW_ID_NONE,
  1853. },
  1854. {
  1855. .name = "display",
  1856. .domains = VLV_DISPLAY_POWER_DOMAINS,
  1857. .ops = &vlv_display_power_well_ops,
  1858. .id = VLV_DISP_PW_DISP2D,
  1859. {
  1860. .vlv.idx = PUNIT_PWGT_IDX_DISP2D,
  1861. },
  1862. },
  1863. {
  1864. .name = "dpio-tx-b-01",
  1865. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1866. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1867. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1868. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1869. .ops = &vlv_dpio_power_well_ops,
  1870. .id = DISP_PW_ID_NONE,
  1871. {
  1872. .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_B_LANES_01,
  1873. },
  1874. },
  1875. {
  1876. .name = "dpio-tx-b-23",
  1877. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1878. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1879. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1880. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1881. .ops = &vlv_dpio_power_well_ops,
  1882. .id = DISP_PW_ID_NONE,
  1883. {
  1884. .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_B_LANES_23,
  1885. },
  1886. },
  1887. {
  1888. .name = "dpio-tx-c-01",
  1889. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1890. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1891. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1892. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1893. .ops = &vlv_dpio_power_well_ops,
  1894. .id = DISP_PW_ID_NONE,
  1895. {
  1896. .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_C_LANES_01,
  1897. },
  1898. },
  1899. {
  1900. .name = "dpio-tx-c-23",
  1901. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1902. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1903. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1904. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1905. .ops = &vlv_dpio_power_well_ops,
  1906. .id = DISP_PW_ID_NONE,
  1907. {
  1908. .vlv.idx = PUNIT_PWGT_IDX_DPIO_TX_C_LANES_23,
  1909. },
  1910. },
  1911. {
  1912. .name = "dpio-common",
  1913. .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
  1914. .ops = &vlv_dpio_cmn_power_well_ops,
  1915. .id = VLV_DISP_PW_DPIO_CMN_BC,
  1916. {
  1917. .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_BC,
  1918. },
  1919. },
  1920. };
  1921. static const struct i915_power_well_desc chv_power_wells[] = {
  1922. {
  1923. .name = "always-on",
  1924. .always_on = 1,
  1925. .domains = POWER_DOMAIN_MASK,
  1926. .ops = &i9xx_always_on_power_well_ops,
  1927. .id = DISP_PW_ID_NONE,
  1928. },
  1929. {
  1930. .name = "display",
  1931. /*
  1932. * Pipe A power well is the new disp2d well. Pipe B and C
  1933. * power wells don't actually exist. Pipe A power well is
  1934. * required for any pipe to work.
  1935. */
  1936. .domains = CHV_DISPLAY_POWER_DOMAINS,
  1937. .ops = &chv_pipe_power_well_ops,
  1938. .id = DISP_PW_ID_NONE,
  1939. },
  1940. {
  1941. .name = "dpio-common-bc",
  1942. .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
  1943. .ops = &chv_dpio_cmn_power_well_ops,
  1944. .id = VLV_DISP_PW_DPIO_CMN_BC,
  1945. {
  1946. .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_BC,
  1947. },
  1948. },
  1949. {
  1950. .name = "dpio-common-d",
  1951. .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
  1952. .ops = &chv_dpio_cmn_power_well_ops,
  1953. .id = CHV_DISP_PW_DPIO_CMN_D,
  1954. {
  1955. .vlv.idx = PUNIT_PWGT_IDX_DPIO_CMN_D,
  1956. },
  1957. },
  1958. };
  1959. bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
  1960. enum i915_power_well_id power_well_id)
  1961. {
  1962. struct i915_power_well *power_well;
  1963. bool ret;
  1964. power_well = lookup_power_well(dev_priv, power_well_id);
  1965. ret = power_well->desc->ops->is_enabled(dev_priv, power_well);
  1966. return ret;
  1967. }
  1968. static const struct i915_power_well_desc skl_power_wells[] = {
  1969. {
  1970. .name = "always-on",
  1971. .always_on = 1,
  1972. .domains = POWER_DOMAIN_MASK,
  1973. .ops = &i9xx_always_on_power_well_ops,
  1974. .id = DISP_PW_ID_NONE,
  1975. },
  1976. {
  1977. .name = "power well 1",
  1978. /* Handled by the DMC firmware */
  1979. .domains = 0,
  1980. .ops = &hsw_power_well_ops,
  1981. .id = SKL_DISP_PW_1,
  1982. {
  1983. .hsw.regs = &hsw_power_well_regs,
  1984. .hsw.idx = SKL_PW_CTL_IDX_PW_1,
  1985. .hsw.has_fuses = true,
  1986. },
  1987. },
  1988. {
  1989. .name = "MISC IO power well",
  1990. /* Handled by the DMC firmware */
  1991. .domains = 0,
  1992. .ops = &hsw_power_well_ops,
  1993. .id = SKL_DISP_PW_MISC_IO,
  1994. {
  1995. .hsw.regs = &hsw_power_well_regs,
  1996. .hsw.idx = SKL_PW_CTL_IDX_MISC_IO,
  1997. },
  1998. },
  1999. {
  2000. .name = "DC off",
  2001. .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
  2002. .ops = &gen9_dc_off_power_well_ops,
  2003. .id = DISP_PW_ID_NONE,
  2004. },
  2005. {
  2006. .name = "power well 2",
  2007. .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
  2008. .ops = &hsw_power_well_ops,
  2009. .id = SKL_DISP_PW_2,
  2010. {
  2011. .hsw.regs = &hsw_power_well_regs,
  2012. .hsw.idx = SKL_PW_CTL_IDX_PW_2,
  2013. .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
  2014. .hsw.has_vga = true,
  2015. .hsw.has_fuses = true,
  2016. },
  2017. },
  2018. {
  2019. .name = "DDI A/E IO power well",
  2020. .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
  2021. .ops = &hsw_power_well_ops,
  2022. .id = DISP_PW_ID_NONE,
  2023. {
  2024. .hsw.regs = &hsw_power_well_regs,
  2025. .hsw.idx = SKL_PW_CTL_IDX_DDI_A_E,
  2026. },
  2027. },
  2028. {
  2029. .name = "DDI B IO power well",
  2030. .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
  2031. .ops = &hsw_power_well_ops,
  2032. .id = DISP_PW_ID_NONE,
  2033. {
  2034. .hsw.regs = &hsw_power_well_regs,
  2035. .hsw.idx = SKL_PW_CTL_IDX_DDI_B,
  2036. },
  2037. },
  2038. {
  2039. .name = "DDI C IO power well",
  2040. .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
  2041. .ops = &hsw_power_well_ops,
  2042. .id = DISP_PW_ID_NONE,
  2043. {
  2044. .hsw.regs = &hsw_power_well_regs,
  2045. .hsw.idx = SKL_PW_CTL_IDX_DDI_C,
  2046. },
  2047. },
  2048. {
  2049. .name = "DDI D IO power well",
  2050. .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
  2051. .ops = &hsw_power_well_ops,
  2052. .id = DISP_PW_ID_NONE,
  2053. {
  2054. .hsw.regs = &hsw_power_well_regs,
  2055. .hsw.idx = SKL_PW_CTL_IDX_DDI_D,
  2056. },
  2057. },
  2058. };
  2059. static const struct i915_power_well_desc bxt_power_wells[] = {
  2060. {
  2061. .name = "always-on",
  2062. .always_on = 1,
  2063. .domains = POWER_DOMAIN_MASK,
  2064. .ops = &i9xx_always_on_power_well_ops,
  2065. .id = DISP_PW_ID_NONE,
  2066. },
  2067. {
  2068. .name = "power well 1",
  2069. .domains = 0,
  2070. .ops = &hsw_power_well_ops,
  2071. .id = SKL_DISP_PW_1,
  2072. {
  2073. .hsw.regs = &hsw_power_well_regs,
  2074. .hsw.idx = SKL_PW_CTL_IDX_PW_1,
  2075. .hsw.has_fuses = true,
  2076. },
  2077. },
  2078. {
  2079. .name = "DC off",
  2080. .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
  2081. .ops = &gen9_dc_off_power_well_ops,
  2082. .id = DISP_PW_ID_NONE,
  2083. },
  2084. {
  2085. .name = "power well 2",
  2086. .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
  2087. .ops = &hsw_power_well_ops,
  2088. .id = SKL_DISP_PW_2,
  2089. {
  2090. .hsw.regs = &hsw_power_well_regs,
  2091. .hsw.idx = SKL_PW_CTL_IDX_PW_2,
  2092. .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
  2093. .hsw.has_vga = true,
  2094. .hsw.has_fuses = true,
  2095. },
  2096. },
  2097. {
  2098. .name = "dpio-common-a",
  2099. .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
  2100. .ops = &bxt_dpio_cmn_power_well_ops,
  2101. .id = BXT_DISP_PW_DPIO_CMN_A,
  2102. {
  2103. .bxt.phy = DPIO_PHY1,
  2104. },
  2105. },
  2106. {
  2107. .name = "dpio-common-bc",
  2108. .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
  2109. .ops = &bxt_dpio_cmn_power_well_ops,
  2110. .id = VLV_DISP_PW_DPIO_CMN_BC,
  2111. {
  2112. .bxt.phy = DPIO_PHY0,
  2113. },
  2114. },
  2115. };
  2116. static const struct i915_power_well_desc glk_power_wells[] = {
  2117. {
  2118. .name = "always-on",
  2119. .always_on = 1,
  2120. .domains = POWER_DOMAIN_MASK,
  2121. .ops = &i9xx_always_on_power_well_ops,
  2122. .id = DISP_PW_ID_NONE,
  2123. },
  2124. {
  2125. .name = "power well 1",
  2126. /* Handled by the DMC firmware */
  2127. .domains = 0,
  2128. .ops = &hsw_power_well_ops,
  2129. .id = SKL_DISP_PW_1,
  2130. {
  2131. .hsw.regs = &hsw_power_well_regs,
  2132. .hsw.idx = SKL_PW_CTL_IDX_PW_1,
  2133. .hsw.has_fuses = true,
  2134. },
  2135. },
  2136. {
  2137. .name = "DC off",
  2138. .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
  2139. .ops = &gen9_dc_off_power_well_ops,
  2140. .id = DISP_PW_ID_NONE,
  2141. },
  2142. {
  2143. .name = "power well 2",
  2144. .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
  2145. .ops = &hsw_power_well_ops,
  2146. .id = SKL_DISP_PW_2,
  2147. {
  2148. .hsw.regs = &hsw_power_well_regs,
  2149. .hsw.idx = SKL_PW_CTL_IDX_PW_2,
  2150. .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
  2151. .hsw.has_vga = true,
  2152. .hsw.has_fuses = true,
  2153. },
  2154. },
  2155. {
  2156. .name = "dpio-common-a",
  2157. .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
  2158. .ops = &bxt_dpio_cmn_power_well_ops,
  2159. .id = BXT_DISP_PW_DPIO_CMN_A,
  2160. {
  2161. .bxt.phy = DPIO_PHY1,
  2162. },
  2163. },
  2164. {
  2165. .name = "dpio-common-b",
  2166. .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
  2167. .ops = &bxt_dpio_cmn_power_well_ops,
  2168. .id = VLV_DISP_PW_DPIO_CMN_BC,
  2169. {
  2170. .bxt.phy = DPIO_PHY0,
  2171. },
  2172. },
  2173. {
  2174. .name = "dpio-common-c",
  2175. .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
  2176. .ops = &bxt_dpio_cmn_power_well_ops,
  2177. .id = GLK_DISP_PW_DPIO_CMN_C,
  2178. {
  2179. .bxt.phy = DPIO_PHY2,
  2180. },
  2181. },
  2182. {
  2183. .name = "AUX A",
  2184. .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
  2185. .ops = &hsw_power_well_ops,
  2186. .id = DISP_PW_ID_NONE,
  2187. {
  2188. .hsw.regs = &hsw_power_well_regs,
  2189. .hsw.idx = GLK_PW_CTL_IDX_AUX_A,
  2190. },
  2191. },
  2192. {
  2193. .name = "AUX B",
  2194. .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
  2195. .ops = &hsw_power_well_ops,
  2196. .id = DISP_PW_ID_NONE,
  2197. {
  2198. .hsw.regs = &hsw_power_well_regs,
  2199. .hsw.idx = GLK_PW_CTL_IDX_AUX_B,
  2200. },
  2201. },
  2202. {
  2203. .name = "AUX C",
  2204. .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
  2205. .ops = &hsw_power_well_ops,
  2206. .id = DISP_PW_ID_NONE,
  2207. {
  2208. .hsw.regs = &hsw_power_well_regs,
  2209. .hsw.idx = GLK_PW_CTL_IDX_AUX_C,
  2210. },
  2211. },
  2212. {
  2213. .name = "DDI A IO power well",
  2214. .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
  2215. .ops = &hsw_power_well_ops,
  2216. .id = DISP_PW_ID_NONE,
  2217. {
  2218. .hsw.regs = &hsw_power_well_regs,
  2219. .hsw.idx = GLK_PW_CTL_IDX_DDI_A,
  2220. },
  2221. },
  2222. {
  2223. .name = "DDI B IO power well",
  2224. .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
  2225. .ops = &hsw_power_well_ops,
  2226. .id = DISP_PW_ID_NONE,
  2227. {
  2228. .hsw.regs = &hsw_power_well_regs,
  2229. .hsw.idx = SKL_PW_CTL_IDX_DDI_B,
  2230. },
  2231. },
  2232. {
  2233. .name = "DDI C IO power well",
  2234. .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
  2235. .ops = &hsw_power_well_ops,
  2236. .id = DISP_PW_ID_NONE,
  2237. {
  2238. .hsw.regs = &hsw_power_well_regs,
  2239. .hsw.idx = SKL_PW_CTL_IDX_DDI_C,
  2240. },
  2241. },
  2242. };
  2243. static const struct i915_power_well_desc cnl_power_wells[] = {
  2244. {
  2245. .name = "always-on",
  2246. .always_on = 1,
  2247. .domains = POWER_DOMAIN_MASK,
  2248. .ops = &i9xx_always_on_power_well_ops,
  2249. .id = DISP_PW_ID_NONE,
  2250. },
  2251. {
  2252. .name = "power well 1",
  2253. /* Handled by the DMC firmware */
  2254. .domains = 0,
  2255. .ops = &hsw_power_well_ops,
  2256. .id = SKL_DISP_PW_1,
  2257. {
  2258. .hsw.regs = &hsw_power_well_regs,
  2259. .hsw.idx = SKL_PW_CTL_IDX_PW_1,
  2260. .hsw.has_fuses = true,
  2261. },
  2262. },
  2263. {
  2264. .name = "AUX A",
  2265. .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
  2266. .ops = &hsw_power_well_ops,
  2267. .id = DISP_PW_ID_NONE,
  2268. {
  2269. .hsw.regs = &hsw_power_well_regs,
  2270. .hsw.idx = GLK_PW_CTL_IDX_AUX_A,
  2271. },
  2272. },
  2273. {
  2274. .name = "AUX B",
  2275. .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
  2276. .ops = &hsw_power_well_ops,
  2277. .id = DISP_PW_ID_NONE,
  2278. {
  2279. .hsw.regs = &hsw_power_well_regs,
  2280. .hsw.idx = GLK_PW_CTL_IDX_AUX_B,
  2281. },
  2282. },
  2283. {
  2284. .name = "AUX C",
  2285. .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
  2286. .ops = &hsw_power_well_ops,
  2287. .id = DISP_PW_ID_NONE,
  2288. {
  2289. .hsw.regs = &hsw_power_well_regs,
  2290. .hsw.idx = GLK_PW_CTL_IDX_AUX_C,
  2291. },
  2292. },
  2293. {
  2294. .name = "AUX D",
  2295. .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
  2296. .ops = &hsw_power_well_ops,
  2297. .id = DISP_PW_ID_NONE,
  2298. {
  2299. .hsw.regs = &hsw_power_well_regs,
  2300. .hsw.idx = CNL_PW_CTL_IDX_AUX_D,
  2301. },
  2302. },
  2303. {
  2304. .name = "DC off",
  2305. .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
  2306. .ops = &gen9_dc_off_power_well_ops,
  2307. .id = DISP_PW_ID_NONE,
  2308. },
  2309. {
  2310. .name = "power well 2",
  2311. .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
  2312. .ops = &hsw_power_well_ops,
  2313. .id = SKL_DISP_PW_2,
  2314. {
  2315. .hsw.regs = &hsw_power_well_regs,
  2316. .hsw.idx = SKL_PW_CTL_IDX_PW_2,
  2317. .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
  2318. .hsw.has_vga = true,
  2319. .hsw.has_fuses = true,
  2320. },
  2321. },
  2322. {
  2323. .name = "DDI A IO power well",
  2324. .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
  2325. .ops = &hsw_power_well_ops,
  2326. .id = DISP_PW_ID_NONE,
  2327. {
  2328. .hsw.regs = &hsw_power_well_regs,
  2329. .hsw.idx = GLK_PW_CTL_IDX_DDI_A,
  2330. },
  2331. },
  2332. {
  2333. .name = "DDI B IO power well",
  2334. .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
  2335. .ops = &hsw_power_well_ops,
  2336. .id = DISP_PW_ID_NONE,
  2337. {
  2338. .hsw.regs = &hsw_power_well_regs,
  2339. .hsw.idx = SKL_PW_CTL_IDX_DDI_B,
  2340. },
  2341. },
  2342. {
  2343. .name = "DDI C IO power well",
  2344. .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
  2345. .ops = &hsw_power_well_ops,
  2346. .id = DISP_PW_ID_NONE,
  2347. {
  2348. .hsw.regs = &hsw_power_well_regs,
  2349. .hsw.idx = SKL_PW_CTL_IDX_DDI_C,
  2350. },
  2351. },
  2352. {
  2353. .name = "DDI D IO power well",
  2354. .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
  2355. .ops = &hsw_power_well_ops,
  2356. .id = DISP_PW_ID_NONE,
  2357. {
  2358. .hsw.regs = &hsw_power_well_regs,
  2359. .hsw.idx = SKL_PW_CTL_IDX_DDI_D,
  2360. },
  2361. },
  2362. {
  2363. .name = "DDI F IO power well",
  2364. .domains = CNL_DISPLAY_DDI_F_IO_POWER_DOMAINS,
  2365. .ops = &hsw_power_well_ops,
  2366. .id = DISP_PW_ID_NONE,
  2367. {
  2368. .hsw.regs = &hsw_power_well_regs,
  2369. .hsw.idx = CNL_PW_CTL_IDX_DDI_F,
  2370. },
  2371. },
  2372. {
  2373. .name = "AUX F",
  2374. .domains = CNL_DISPLAY_AUX_F_POWER_DOMAINS,
  2375. .ops = &hsw_power_well_ops,
  2376. .id = DISP_PW_ID_NONE,
  2377. {
  2378. .hsw.regs = &hsw_power_well_regs,
  2379. .hsw.idx = CNL_PW_CTL_IDX_AUX_F,
  2380. },
  2381. },
  2382. };
  2383. static const struct i915_power_well_ops icl_combo_phy_aux_power_well_ops = {
  2384. .sync_hw = hsw_power_well_sync_hw,
  2385. .enable = icl_combo_phy_aux_power_well_enable,
  2386. .disable = icl_combo_phy_aux_power_well_disable,
  2387. .is_enabled = hsw_power_well_enabled,
  2388. };
  2389. static const struct i915_power_well_regs icl_aux_power_well_regs = {
  2390. .bios = ICL_PWR_WELL_CTL_AUX1,
  2391. .driver = ICL_PWR_WELL_CTL_AUX2,
  2392. .debug = ICL_PWR_WELL_CTL_AUX4,
  2393. };
  2394. static const struct i915_power_well_regs icl_ddi_power_well_regs = {
  2395. .bios = ICL_PWR_WELL_CTL_DDI1,
  2396. .driver = ICL_PWR_WELL_CTL_DDI2,
  2397. .debug = ICL_PWR_WELL_CTL_DDI4,
  2398. };
  2399. static const struct i915_power_well_desc icl_power_wells[] = {
  2400. {
  2401. .name = "always-on",
  2402. .always_on = 1,
  2403. .domains = POWER_DOMAIN_MASK,
  2404. .ops = &i9xx_always_on_power_well_ops,
  2405. .id = DISP_PW_ID_NONE,
  2406. },
  2407. {
  2408. .name = "power well 1",
  2409. /* Handled by the DMC firmware */
  2410. .domains = 0,
  2411. .ops = &hsw_power_well_ops,
  2412. .id = SKL_DISP_PW_1,
  2413. {
  2414. .hsw.regs = &hsw_power_well_regs,
  2415. .hsw.idx = ICL_PW_CTL_IDX_PW_1,
  2416. .hsw.has_fuses = true,
  2417. },
  2418. },
  2419. {
  2420. .name = "DC off",
  2421. .domains = ICL_DISPLAY_DC_OFF_POWER_DOMAINS,
  2422. .ops = &gen9_dc_off_power_well_ops,
  2423. .id = DISP_PW_ID_NONE,
  2424. },
  2425. {
  2426. .name = "power well 2",
  2427. .domains = ICL_PW_2_POWER_DOMAINS,
  2428. .ops = &hsw_power_well_ops,
  2429. .id = SKL_DISP_PW_2,
  2430. {
  2431. .hsw.regs = &hsw_power_well_regs,
  2432. .hsw.idx = ICL_PW_CTL_IDX_PW_2,
  2433. .hsw.has_fuses = true,
  2434. },
  2435. },
  2436. {
  2437. .name = "power well 3",
  2438. .domains = ICL_PW_3_POWER_DOMAINS,
  2439. .ops = &hsw_power_well_ops,
  2440. .id = DISP_PW_ID_NONE,
  2441. {
  2442. .hsw.regs = &hsw_power_well_regs,
  2443. .hsw.idx = ICL_PW_CTL_IDX_PW_3,
  2444. .hsw.irq_pipe_mask = BIT(PIPE_B),
  2445. .hsw.has_vga = true,
  2446. .hsw.has_fuses = true,
  2447. },
  2448. },
  2449. {
  2450. .name = "DDI A IO",
  2451. .domains = ICL_DDI_IO_A_POWER_DOMAINS,
  2452. .ops = &hsw_power_well_ops,
  2453. .id = DISP_PW_ID_NONE,
  2454. {
  2455. .hsw.regs = &icl_ddi_power_well_regs,
  2456. .hsw.idx = ICL_PW_CTL_IDX_DDI_A,
  2457. },
  2458. },
  2459. {
  2460. .name = "DDI B IO",
  2461. .domains = ICL_DDI_IO_B_POWER_DOMAINS,
  2462. .ops = &hsw_power_well_ops,
  2463. .id = DISP_PW_ID_NONE,
  2464. {
  2465. .hsw.regs = &icl_ddi_power_well_regs,
  2466. .hsw.idx = ICL_PW_CTL_IDX_DDI_B,
  2467. },
  2468. },
  2469. {
  2470. .name = "DDI C IO",
  2471. .domains = ICL_DDI_IO_C_POWER_DOMAINS,
  2472. .ops = &hsw_power_well_ops,
  2473. .id = DISP_PW_ID_NONE,
  2474. {
  2475. .hsw.regs = &icl_ddi_power_well_regs,
  2476. .hsw.idx = ICL_PW_CTL_IDX_DDI_C,
  2477. },
  2478. },
  2479. {
  2480. .name = "DDI D IO",
  2481. .domains = ICL_DDI_IO_D_POWER_DOMAINS,
  2482. .ops = &hsw_power_well_ops,
  2483. .id = DISP_PW_ID_NONE,
  2484. {
  2485. .hsw.regs = &icl_ddi_power_well_regs,
  2486. .hsw.idx = ICL_PW_CTL_IDX_DDI_D,
  2487. },
  2488. },
  2489. {
  2490. .name = "DDI E IO",
  2491. .domains = ICL_DDI_IO_E_POWER_DOMAINS,
  2492. .ops = &hsw_power_well_ops,
  2493. .id = DISP_PW_ID_NONE,
  2494. {
  2495. .hsw.regs = &icl_ddi_power_well_regs,
  2496. .hsw.idx = ICL_PW_CTL_IDX_DDI_E,
  2497. },
  2498. },
  2499. {
  2500. .name = "DDI F IO",
  2501. .domains = ICL_DDI_IO_F_POWER_DOMAINS,
  2502. .ops = &hsw_power_well_ops,
  2503. .id = DISP_PW_ID_NONE,
  2504. {
  2505. .hsw.regs = &icl_ddi_power_well_regs,
  2506. .hsw.idx = ICL_PW_CTL_IDX_DDI_F,
  2507. },
  2508. },
  2509. {
  2510. .name = "AUX A",
  2511. .domains = ICL_AUX_A_IO_POWER_DOMAINS,
  2512. .ops = &icl_combo_phy_aux_power_well_ops,
  2513. .id = DISP_PW_ID_NONE,
  2514. {
  2515. .hsw.regs = &icl_aux_power_well_regs,
  2516. .hsw.idx = ICL_PW_CTL_IDX_AUX_A,
  2517. },
  2518. },
  2519. {
  2520. .name = "AUX B",
  2521. .domains = ICL_AUX_B_IO_POWER_DOMAINS,
  2522. .ops = &icl_combo_phy_aux_power_well_ops,
  2523. .id = DISP_PW_ID_NONE,
  2524. {
  2525. .hsw.regs = &icl_aux_power_well_regs,
  2526. .hsw.idx = ICL_PW_CTL_IDX_AUX_B,
  2527. },
  2528. },
  2529. {
  2530. .name = "AUX C",
  2531. .domains = ICL_AUX_C_IO_POWER_DOMAINS,
  2532. .ops = &hsw_power_well_ops,
  2533. .id = DISP_PW_ID_NONE,
  2534. {
  2535. .hsw.regs = &icl_aux_power_well_regs,
  2536. .hsw.idx = ICL_PW_CTL_IDX_AUX_C,
  2537. },
  2538. },
  2539. {
  2540. .name = "AUX D",
  2541. .domains = ICL_AUX_D_IO_POWER_DOMAINS,
  2542. .ops = &hsw_power_well_ops,
  2543. .id = DISP_PW_ID_NONE,
  2544. {
  2545. .hsw.regs = &icl_aux_power_well_regs,
  2546. .hsw.idx = ICL_PW_CTL_IDX_AUX_D,
  2547. },
  2548. },
  2549. {
  2550. .name = "AUX E",
  2551. .domains = ICL_AUX_E_IO_POWER_DOMAINS,
  2552. .ops = &hsw_power_well_ops,
  2553. .id = DISP_PW_ID_NONE,
  2554. {
  2555. .hsw.regs = &icl_aux_power_well_regs,
  2556. .hsw.idx = ICL_PW_CTL_IDX_AUX_E,
  2557. },
  2558. },
  2559. {
  2560. .name = "AUX F",
  2561. .domains = ICL_AUX_F_IO_POWER_DOMAINS,
  2562. .ops = &hsw_power_well_ops,
  2563. .id = DISP_PW_ID_NONE,
  2564. {
  2565. .hsw.regs = &icl_aux_power_well_regs,
  2566. .hsw.idx = ICL_PW_CTL_IDX_AUX_F,
  2567. },
  2568. },
  2569. {
  2570. .name = "AUX TBT1",
  2571. .domains = ICL_AUX_TBT1_IO_POWER_DOMAINS,
  2572. .ops = &hsw_power_well_ops,
  2573. .id = DISP_PW_ID_NONE,
  2574. {
  2575. .hsw.regs = &icl_aux_power_well_regs,
  2576. .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT1,
  2577. },
  2578. },
  2579. {
  2580. .name = "AUX TBT2",
  2581. .domains = ICL_AUX_TBT2_IO_POWER_DOMAINS,
  2582. .ops = &hsw_power_well_ops,
  2583. .id = DISP_PW_ID_NONE,
  2584. {
  2585. .hsw.regs = &icl_aux_power_well_regs,
  2586. .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT2,
  2587. },
  2588. },
  2589. {
  2590. .name = "AUX TBT3",
  2591. .domains = ICL_AUX_TBT3_IO_POWER_DOMAINS,
  2592. .ops = &hsw_power_well_ops,
  2593. .id = DISP_PW_ID_NONE,
  2594. {
  2595. .hsw.regs = &icl_aux_power_well_regs,
  2596. .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT3,
  2597. },
  2598. },
  2599. {
  2600. .name = "AUX TBT4",
  2601. .domains = ICL_AUX_TBT4_IO_POWER_DOMAINS,
  2602. .ops = &hsw_power_well_ops,
  2603. .id = DISP_PW_ID_NONE,
  2604. {
  2605. .hsw.regs = &icl_aux_power_well_regs,
  2606. .hsw.idx = ICL_PW_CTL_IDX_AUX_TBT4,
  2607. },
  2608. },
  2609. {
  2610. .name = "power well 4",
  2611. .domains = ICL_PW_4_POWER_DOMAINS,
  2612. .ops = &hsw_power_well_ops,
  2613. .id = DISP_PW_ID_NONE,
  2614. {
  2615. .hsw.regs = &hsw_power_well_regs,
  2616. .hsw.idx = ICL_PW_CTL_IDX_PW_4,
  2617. .hsw.has_fuses = true,
  2618. .hsw.irq_pipe_mask = BIT(PIPE_C),
  2619. },
  2620. },
  2621. };
  2622. static int
  2623. sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
  2624. int disable_power_well)
  2625. {
  2626. if (disable_power_well >= 0)
  2627. return !!disable_power_well;
  2628. return 1;
  2629. }
  2630. static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
  2631. int enable_dc)
  2632. {
  2633. uint32_t mask;
  2634. int requested_dc;
  2635. int max_dc;
  2636. if (IS_GEN9_BC(dev_priv) || INTEL_INFO(dev_priv)->gen >= 10) {
  2637. max_dc = 2;
  2638. mask = 0;
  2639. } else if (IS_GEN9_LP(dev_priv)) {
  2640. max_dc = 1;
  2641. /*
  2642. * DC9 has a separate HW flow from the rest of the DC states,
  2643. * not depending on the DMC firmware. It's needed by system
  2644. * suspend/resume, so allow it unconditionally.
  2645. */
  2646. mask = DC_STATE_EN_DC9;
  2647. } else {
  2648. max_dc = 0;
  2649. mask = 0;
  2650. }
  2651. if (!i915_modparams.disable_power_well)
  2652. max_dc = 0;
  2653. if (enable_dc >= 0 && enable_dc <= max_dc) {
  2654. requested_dc = enable_dc;
  2655. } else if (enable_dc == -1) {
  2656. requested_dc = max_dc;
  2657. } else if (enable_dc > max_dc && enable_dc <= 2) {
  2658. DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
  2659. enable_dc, max_dc);
  2660. requested_dc = max_dc;
  2661. } else {
  2662. DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
  2663. requested_dc = max_dc;
  2664. }
  2665. if (requested_dc > 1)
  2666. mask |= DC_STATE_EN_UPTO_DC6;
  2667. if (requested_dc > 0)
  2668. mask |= DC_STATE_EN_UPTO_DC5;
  2669. DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
  2670. return mask;
  2671. }
  2672. static int
  2673. __set_power_wells(struct i915_power_domains *power_domains,
  2674. const struct i915_power_well_desc *power_well_descs,
  2675. int power_well_count)
  2676. {
  2677. u64 power_well_ids = 0;
  2678. int i;
  2679. power_domains->power_well_count = power_well_count;
  2680. power_domains->power_wells =
  2681. kcalloc(power_well_count,
  2682. sizeof(*power_domains->power_wells),
  2683. GFP_KERNEL);
  2684. if (!power_domains->power_wells)
  2685. return -ENOMEM;
  2686. for (i = 0; i < power_well_count; i++) {
  2687. enum i915_power_well_id id = power_well_descs[i].id;
  2688. power_domains->power_wells[i].desc = &power_well_descs[i];
  2689. if (id == DISP_PW_ID_NONE)
  2690. continue;
  2691. WARN_ON(id >= sizeof(power_well_ids) * 8);
  2692. WARN_ON(power_well_ids & BIT_ULL(id));
  2693. power_well_ids |= BIT_ULL(id);
  2694. }
  2695. return 0;
  2696. }
  2697. #define set_power_wells(power_domains, __power_well_descs) \
  2698. __set_power_wells(power_domains, __power_well_descs, \
  2699. ARRAY_SIZE(__power_well_descs))
  2700. /**
  2701. * intel_power_domains_init - initializes the power domain structures
  2702. * @dev_priv: i915 device instance
  2703. *
  2704. * Initializes the power domain structures for @dev_priv depending upon the
  2705. * supported platform.
  2706. */
  2707. int intel_power_domains_init(struct drm_i915_private *dev_priv)
  2708. {
  2709. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2710. int err;
  2711. i915_modparams.disable_power_well =
  2712. sanitize_disable_power_well_option(dev_priv,
  2713. i915_modparams.disable_power_well);
  2714. dev_priv->csr.allowed_dc_mask =
  2715. get_allowed_dc_mask(dev_priv, i915_modparams.enable_dc);
  2716. BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
  2717. mutex_init(&power_domains->lock);
  2718. /*
  2719. * The enabling order will be from lower to higher indexed wells,
  2720. * the disabling order is reversed.
  2721. */
  2722. if (IS_ICELAKE(dev_priv)) {
  2723. err = set_power_wells(power_domains, icl_power_wells);
  2724. } else if (IS_HASWELL(dev_priv)) {
  2725. err = set_power_wells(power_domains, hsw_power_wells);
  2726. } else if (IS_BROADWELL(dev_priv)) {
  2727. err = set_power_wells(power_domains, bdw_power_wells);
  2728. } else if (IS_GEN9_BC(dev_priv)) {
  2729. err = set_power_wells(power_domains, skl_power_wells);
  2730. } else if (IS_CANNONLAKE(dev_priv)) {
  2731. err = set_power_wells(power_domains, cnl_power_wells);
  2732. /*
  2733. * DDI and Aux IO are getting enabled for all ports
  2734. * regardless the presence or use. So, in order to avoid
  2735. * timeouts, lets remove them from the list
  2736. * for the SKUs without port F.
  2737. */
  2738. if (!IS_CNL_WITH_PORT_F(dev_priv))
  2739. power_domains->power_well_count -= 2;
  2740. } else if (IS_BROXTON(dev_priv)) {
  2741. err = set_power_wells(power_domains, bxt_power_wells);
  2742. } else if (IS_GEMINILAKE(dev_priv)) {
  2743. err = set_power_wells(power_domains, glk_power_wells);
  2744. } else if (IS_CHERRYVIEW(dev_priv)) {
  2745. err = set_power_wells(power_domains, chv_power_wells);
  2746. } else if (IS_VALLEYVIEW(dev_priv)) {
  2747. err = set_power_wells(power_domains, vlv_power_wells);
  2748. } else if (IS_I830(dev_priv)) {
  2749. err = set_power_wells(power_domains, i830_power_wells);
  2750. } else {
  2751. err = set_power_wells(power_domains, i9xx_always_on_power_well);
  2752. }
  2753. return err;
  2754. }
  2755. /**
  2756. * intel_power_domains_cleanup - clean up power domains resources
  2757. * @dev_priv: i915 device instance
  2758. *
  2759. * Release any resources acquired by intel_power_domains_init()
  2760. */
  2761. void intel_power_domains_cleanup(struct drm_i915_private *dev_priv)
  2762. {
  2763. kfree(dev_priv->power_domains.power_wells);
  2764. }
  2765. static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
  2766. {
  2767. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2768. struct i915_power_well *power_well;
  2769. mutex_lock(&power_domains->lock);
  2770. for_each_power_well(dev_priv, power_well) {
  2771. power_well->desc->ops->sync_hw(dev_priv, power_well);
  2772. power_well->hw_enabled =
  2773. power_well->desc->ops->is_enabled(dev_priv, power_well);
  2774. }
  2775. mutex_unlock(&power_domains->lock);
  2776. }
  2777. static inline
  2778. bool intel_dbuf_slice_set(struct drm_i915_private *dev_priv,
  2779. i915_reg_t reg, bool enable)
  2780. {
  2781. u32 val, status;
  2782. val = I915_READ(reg);
  2783. val = enable ? (val | DBUF_POWER_REQUEST) : (val & ~DBUF_POWER_REQUEST);
  2784. I915_WRITE(reg, val);
  2785. POSTING_READ(reg);
  2786. udelay(10);
  2787. status = I915_READ(reg) & DBUF_POWER_STATE;
  2788. if ((enable && !status) || (!enable && status)) {
  2789. DRM_ERROR("DBus power %s timeout!\n",
  2790. enable ? "enable" : "disable");
  2791. return false;
  2792. }
  2793. return true;
  2794. }
  2795. static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
  2796. {
  2797. intel_dbuf_slice_set(dev_priv, DBUF_CTL, true);
  2798. }
  2799. static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
  2800. {
  2801. intel_dbuf_slice_set(dev_priv, DBUF_CTL, false);
  2802. }
  2803. static u8 intel_dbuf_max_slices(struct drm_i915_private *dev_priv)
  2804. {
  2805. if (INTEL_GEN(dev_priv) < 11)
  2806. return 1;
  2807. return 2;
  2808. }
  2809. void icl_dbuf_slices_update(struct drm_i915_private *dev_priv,
  2810. u8 req_slices)
  2811. {
  2812. const u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
  2813. bool ret;
  2814. if (req_slices > intel_dbuf_max_slices(dev_priv)) {
  2815. DRM_ERROR("Invalid number of dbuf slices requested\n");
  2816. return;
  2817. }
  2818. if (req_slices == hw_enabled_slices || req_slices == 0)
  2819. return;
  2820. if (req_slices > hw_enabled_slices)
  2821. ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, true);
  2822. else
  2823. ret = intel_dbuf_slice_set(dev_priv, DBUF_CTL_S2, false);
  2824. if (ret)
  2825. dev_priv->wm.skl_hw.ddb.enabled_slices = req_slices;
  2826. }
  2827. static void icl_dbuf_enable(struct drm_i915_private *dev_priv)
  2828. {
  2829. I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) | DBUF_POWER_REQUEST);
  2830. I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) | DBUF_POWER_REQUEST);
  2831. POSTING_READ(DBUF_CTL_S2);
  2832. udelay(10);
  2833. if (!(I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
  2834. !(I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
  2835. DRM_ERROR("DBuf power enable timeout\n");
  2836. else
  2837. dev_priv->wm.skl_hw.ddb.enabled_slices = 2;
  2838. }
  2839. static void icl_dbuf_disable(struct drm_i915_private *dev_priv)
  2840. {
  2841. I915_WRITE(DBUF_CTL_S1, I915_READ(DBUF_CTL_S1) & ~DBUF_POWER_REQUEST);
  2842. I915_WRITE(DBUF_CTL_S2, I915_READ(DBUF_CTL_S2) & ~DBUF_POWER_REQUEST);
  2843. POSTING_READ(DBUF_CTL_S2);
  2844. udelay(10);
  2845. if ((I915_READ(DBUF_CTL_S1) & DBUF_POWER_STATE) ||
  2846. (I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE))
  2847. DRM_ERROR("DBuf power disable timeout!\n");
  2848. else
  2849. dev_priv->wm.skl_hw.ddb.enabled_slices = 0;
  2850. }
  2851. static void icl_mbus_init(struct drm_i915_private *dev_priv)
  2852. {
  2853. uint32_t val;
  2854. val = MBUS_ABOX_BT_CREDIT_POOL1(16) |
  2855. MBUS_ABOX_BT_CREDIT_POOL2(16) |
  2856. MBUS_ABOX_B_CREDIT(1) |
  2857. MBUS_ABOX_BW_CREDIT(1);
  2858. I915_WRITE(MBUS_ABOX_CTL, val);
  2859. }
  2860. static void skl_display_core_init(struct drm_i915_private *dev_priv,
  2861. bool resume)
  2862. {
  2863. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2864. struct i915_power_well *well;
  2865. uint32_t val;
  2866. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  2867. /* enable PCH reset handshake */
  2868. val = I915_READ(HSW_NDE_RSTWRN_OPT);
  2869. I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
  2870. /* enable PG1 and Misc I/O */
  2871. mutex_lock(&power_domains->lock);
  2872. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  2873. intel_power_well_enable(dev_priv, well);
  2874. well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
  2875. intel_power_well_enable(dev_priv, well);
  2876. mutex_unlock(&power_domains->lock);
  2877. skl_init_cdclk(dev_priv);
  2878. gen9_dbuf_enable(dev_priv);
  2879. if (resume && dev_priv->csr.dmc_payload)
  2880. intel_csr_load_program(dev_priv);
  2881. }
  2882. static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
  2883. {
  2884. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2885. struct i915_power_well *well;
  2886. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  2887. gen9_dbuf_disable(dev_priv);
  2888. skl_uninit_cdclk(dev_priv);
  2889. /* The spec doesn't call for removing the reset handshake flag */
  2890. /* disable PG1 and Misc I/O */
  2891. mutex_lock(&power_domains->lock);
  2892. /*
  2893. * BSpec says to keep the MISC IO power well enabled here, only
  2894. * remove our request for power well 1.
  2895. * Note that even though the driver's request is removed power well 1
  2896. * may stay enabled after this due to DMC's own request on it.
  2897. */
  2898. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  2899. intel_power_well_disable(dev_priv, well);
  2900. mutex_unlock(&power_domains->lock);
  2901. usleep_range(10, 30); /* 10 us delay per Bspec */
  2902. }
  2903. void bxt_display_core_init(struct drm_i915_private *dev_priv,
  2904. bool resume)
  2905. {
  2906. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2907. struct i915_power_well *well;
  2908. uint32_t val;
  2909. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  2910. /*
  2911. * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
  2912. * or else the reset will hang because there is no PCH to respond.
  2913. * Move the handshake programming to initialization sequence.
  2914. * Previously was left up to BIOS.
  2915. */
  2916. val = I915_READ(HSW_NDE_RSTWRN_OPT);
  2917. val &= ~RESET_PCH_HANDSHAKE_ENABLE;
  2918. I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
  2919. /* Enable PG1 */
  2920. mutex_lock(&power_domains->lock);
  2921. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  2922. intel_power_well_enable(dev_priv, well);
  2923. mutex_unlock(&power_domains->lock);
  2924. bxt_init_cdclk(dev_priv);
  2925. gen9_dbuf_enable(dev_priv);
  2926. if (resume && dev_priv->csr.dmc_payload)
  2927. intel_csr_load_program(dev_priv);
  2928. }
  2929. void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
  2930. {
  2931. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2932. struct i915_power_well *well;
  2933. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  2934. gen9_dbuf_disable(dev_priv);
  2935. bxt_uninit_cdclk(dev_priv);
  2936. /* The spec doesn't call for removing the reset handshake flag */
  2937. /*
  2938. * Disable PW1 (PG1).
  2939. * Note that even though the driver's request is removed power well 1
  2940. * may stay enabled after this due to DMC's own request on it.
  2941. */
  2942. mutex_lock(&power_domains->lock);
  2943. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  2944. intel_power_well_disable(dev_priv, well);
  2945. mutex_unlock(&power_domains->lock);
  2946. usleep_range(10, 30); /* 10 us delay per Bspec */
  2947. }
  2948. enum {
  2949. PROCMON_0_85V_DOT_0,
  2950. PROCMON_0_95V_DOT_0,
  2951. PROCMON_0_95V_DOT_1,
  2952. PROCMON_1_05V_DOT_0,
  2953. PROCMON_1_05V_DOT_1,
  2954. };
  2955. static const struct cnl_procmon {
  2956. u32 dw1, dw9, dw10;
  2957. } cnl_procmon_values[] = {
  2958. [PROCMON_0_85V_DOT_0] =
  2959. { .dw1 = 0x00000000, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
  2960. [PROCMON_0_95V_DOT_0] =
  2961. { .dw1 = 0x00000000, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
  2962. [PROCMON_0_95V_DOT_1] =
  2963. { .dw1 = 0x00000000, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
  2964. [PROCMON_1_05V_DOT_0] =
  2965. { .dw1 = 0x00000000, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
  2966. [PROCMON_1_05V_DOT_1] =
  2967. { .dw1 = 0x00440000, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
  2968. };
  2969. /*
  2970. * CNL has just one set of registers, while ICL has two sets: one for port A and
  2971. * the other for port B. The CNL registers are equivalent to the ICL port A
  2972. * registers, that's why we call the ICL macros even though the function has CNL
  2973. * on its name.
  2974. */
  2975. static void cnl_set_procmon_ref_values(struct drm_i915_private *dev_priv,
  2976. enum port port)
  2977. {
  2978. const struct cnl_procmon *procmon;
  2979. u32 val;
  2980. val = I915_READ(ICL_PORT_COMP_DW3(port));
  2981. switch (val & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) {
  2982. default:
  2983. MISSING_CASE(val);
  2984. /* fall through */
  2985. case VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0:
  2986. procmon = &cnl_procmon_values[PROCMON_0_85V_DOT_0];
  2987. break;
  2988. case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0:
  2989. procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_0];
  2990. break;
  2991. case VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1:
  2992. procmon = &cnl_procmon_values[PROCMON_0_95V_DOT_1];
  2993. break;
  2994. case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0:
  2995. procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_0];
  2996. break;
  2997. case VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1:
  2998. procmon = &cnl_procmon_values[PROCMON_1_05V_DOT_1];
  2999. break;
  3000. }
  3001. val = I915_READ(ICL_PORT_COMP_DW1(port));
  3002. val &= ~((0xff << 16) | 0xff);
  3003. val |= procmon->dw1;
  3004. I915_WRITE(ICL_PORT_COMP_DW1(port), val);
  3005. I915_WRITE(ICL_PORT_COMP_DW9(port), procmon->dw9);
  3006. I915_WRITE(ICL_PORT_COMP_DW10(port), procmon->dw10);
  3007. }
  3008. static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
  3009. {
  3010. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  3011. struct i915_power_well *well;
  3012. u32 val;
  3013. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  3014. /* 1. Enable PCH Reset Handshake */
  3015. val = I915_READ(HSW_NDE_RSTWRN_OPT);
  3016. val |= RESET_PCH_HANDSHAKE_ENABLE;
  3017. I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
  3018. /* 2. Enable Comp */
  3019. val = I915_READ(CHICKEN_MISC_2);
  3020. val &= ~CNL_COMP_PWR_DOWN;
  3021. I915_WRITE(CHICKEN_MISC_2, val);
  3022. /* Dummy PORT_A to get the correct CNL register from the ICL macro */
  3023. cnl_set_procmon_ref_values(dev_priv, PORT_A);
  3024. val = I915_READ(CNL_PORT_COMP_DW0);
  3025. val |= COMP_INIT;
  3026. I915_WRITE(CNL_PORT_COMP_DW0, val);
  3027. /* 3. */
  3028. val = I915_READ(CNL_PORT_CL1CM_DW5);
  3029. val |= CL_POWER_DOWN_ENABLE;
  3030. I915_WRITE(CNL_PORT_CL1CM_DW5, val);
  3031. /*
  3032. * 4. Enable Power Well 1 (PG1).
  3033. * The AUX IO power wells will be enabled on demand.
  3034. */
  3035. mutex_lock(&power_domains->lock);
  3036. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  3037. intel_power_well_enable(dev_priv, well);
  3038. mutex_unlock(&power_domains->lock);
  3039. /* 5. Enable CD clock */
  3040. cnl_init_cdclk(dev_priv);
  3041. /* 6. Enable DBUF */
  3042. gen9_dbuf_enable(dev_priv);
  3043. if (resume && dev_priv->csr.dmc_payload)
  3044. intel_csr_load_program(dev_priv);
  3045. }
  3046. static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
  3047. {
  3048. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  3049. struct i915_power_well *well;
  3050. u32 val;
  3051. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  3052. /* 1. Disable all display engine functions -> aready done */
  3053. /* 2. Disable DBUF */
  3054. gen9_dbuf_disable(dev_priv);
  3055. /* 3. Disable CD clock */
  3056. cnl_uninit_cdclk(dev_priv);
  3057. /*
  3058. * 4. Disable Power Well 1 (PG1).
  3059. * The AUX IO power wells are toggled on demand, so they are already
  3060. * disabled at this point.
  3061. */
  3062. mutex_lock(&power_domains->lock);
  3063. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  3064. intel_power_well_disable(dev_priv, well);
  3065. mutex_unlock(&power_domains->lock);
  3066. usleep_range(10, 30); /* 10 us delay per Bspec */
  3067. /* 5. Disable Comp */
  3068. val = I915_READ(CHICKEN_MISC_2);
  3069. val |= CNL_COMP_PWR_DOWN;
  3070. I915_WRITE(CHICKEN_MISC_2, val);
  3071. }
  3072. static void icl_display_core_init(struct drm_i915_private *dev_priv,
  3073. bool resume)
  3074. {
  3075. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  3076. struct i915_power_well *well;
  3077. enum port port;
  3078. u32 val;
  3079. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  3080. /* 1. Enable PCH reset handshake. */
  3081. val = I915_READ(HSW_NDE_RSTWRN_OPT);
  3082. val |= RESET_PCH_HANDSHAKE_ENABLE;
  3083. I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
  3084. for (port = PORT_A; port <= PORT_B; port++) {
  3085. /* 2. Enable DDI combo PHY comp. */
  3086. val = I915_READ(ICL_PHY_MISC(port));
  3087. val &= ~ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
  3088. I915_WRITE(ICL_PHY_MISC(port), val);
  3089. cnl_set_procmon_ref_values(dev_priv, port);
  3090. val = I915_READ(ICL_PORT_COMP_DW0(port));
  3091. val |= COMP_INIT;
  3092. I915_WRITE(ICL_PORT_COMP_DW0(port), val);
  3093. /* 3. Set power down enable. */
  3094. val = I915_READ(ICL_PORT_CL_DW5(port));
  3095. val |= CL_POWER_DOWN_ENABLE;
  3096. I915_WRITE(ICL_PORT_CL_DW5(port), val);
  3097. }
  3098. /*
  3099. * 4. Enable Power Well 1 (PG1).
  3100. * The AUX IO power wells will be enabled on demand.
  3101. */
  3102. mutex_lock(&power_domains->lock);
  3103. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  3104. intel_power_well_enable(dev_priv, well);
  3105. mutex_unlock(&power_domains->lock);
  3106. /* 5. Enable CDCLK. */
  3107. icl_init_cdclk(dev_priv);
  3108. /* 6. Enable DBUF. */
  3109. icl_dbuf_enable(dev_priv);
  3110. /* 7. Setup MBUS. */
  3111. icl_mbus_init(dev_priv);
  3112. if (resume && dev_priv->csr.dmc_payload)
  3113. intel_csr_load_program(dev_priv);
  3114. }
  3115. static void icl_display_core_uninit(struct drm_i915_private *dev_priv)
  3116. {
  3117. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  3118. struct i915_power_well *well;
  3119. enum port port;
  3120. u32 val;
  3121. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  3122. /* 1. Disable all display engine functions -> aready done */
  3123. /* 2. Disable DBUF */
  3124. icl_dbuf_disable(dev_priv);
  3125. /* 3. Disable CD clock */
  3126. icl_uninit_cdclk(dev_priv);
  3127. /*
  3128. * 4. Disable Power Well 1 (PG1).
  3129. * The AUX IO power wells are toggled on demand, so they are already
  3130. * disabled at this point.
  3131. */
  3132. mutex_lock(&power_domains->lock);
  3133. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  3134. intel_power_well_disable(dev_priv, well);
  3135. mutex_unlock(&power_domains->lock);
  3136. /* 5. Disable Comp */
  3137. for (port = PORT_A; port <= PORT_B; port++) {
  3138. val = I915_READ(ICL_PHY_MISC(port));
  3139. val |= ICL_PHY_MISC_DE_IO_COMP_PWR_DOWN;
  3140. I915_WRITE(ICL_PHY_MISC(port), val);
  3141. }
  3142. }
  3143. static void chv_phy_control_init(struct drm_i915_private *dev_priv)
  3144. {
  3145. struct i915_power_well *cmn_bc =
  3146. lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
  3147. struct i915_power_well *cmn_d =
  3148. lookup_power_well(dev_priv, CHV_DISP_PW_DPIO_CMN_D);
  3149. /*
  3150. * DISPLAY_PHY_CONTROL can get corrupted if read. As a
  3151. * workaround never ever read DISPLAY_PHY_CONTROL, and
  3152. * instead maintain a shadow copy ourselves. Use the actual
  3153. * power well state and lane status to reconstruct the
  3154. * expected initial value.
  3155. */
  3156. dev_priv->chv_phy_control =
  3157. PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
  3158. PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
  3159. PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
  3160. PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
  3161. PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
  3162. /*
  3163. * If all lanes are disabled we leave the override disabled
  3164. * with all power down bits cleared to match the state we
  3165. * would use after disabling the port. Otherwise enable the
  3166. * override and set the lane powerdown bits accding to the
  3167. * current lane status.
  3168. */
  3169. if (cmn_bc->desc->ops->is_enabled(dev_priv, cmn_bc)) {
  3170. uint32_t status = I915_READ(DPLL(PIPE_A));
  3171. unsigned int mask;
  3172. mask = status & DPLL_PORTB_READY_MASK;
  3173. if (mask == 0xf)
  3174. mask = 0x0;
  3175. else
  3176. dev_priv->chv_phy_control |=
  3177. PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
  3178. dev_priv->chv_phy_control |=
  3179. PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
  3180. mask = (status & DPLL_PORTC_READY_MASK) >> 4;
  3181. if (mask == 0xf)
  3182. mask = 0x0;
  3183. else
  3184. dev_priv->chv_phy_control |=
  3185. PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
  3186. dev_priv->chv_phy_control |=
  3187. PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
  3188. dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
  3189. dev_priv->chv_phy_assert[DPIO_PHY0] = false;
  3190. } else {
  3191. dev_priv->chv_phy_assert[DPIO_PHY0] = true;
  3192. }
  3193. if (cmn_d->desc->ops->is_enabled(dev_priv, cmn_d)) {
  3194. uint32_t status = I915_READ(DPIO_PHY_STATUS);
  3195. unsigned int mask;
  3196. mask = status & DPLL_PORTD_READY_MASK;
  3197. if (mask == 0xf)
  3198. mask = 0x0;
  3199. else
  3200. dev_priv->chv_phy_control |=
  3201. PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
  3202. dev_priv->chv_phy_control |=
  3203. PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
  3204. dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
  3205. dev_priv->chv_phy_assert[DPIO_PHY1] = false;
  3206. } else {
  3207. dev_priv->chv_phy_assert[DPIO_PHY1] = true;
  3208. }
  3209. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  3210. DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
  3211. dev_priv->chv_phy_control);
  3212. }
  3213. static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
  3214. {
  3215. struct i915_power_well *cmn =
  3216. lookup_power_well(dev_priv, VLV_DISP_PW_DPIO_CMN_BC);
  3217. struct i915_power_well *disp2d =
  3218. lookup_power_well(dev_priv, VLV_DISP_PW_DISP2D);
  3219. /* If the display might be already active skip this */
  3220. if (cmn->desc->ops->is_enabled(dev_priv, cmn) &&
  3221. disp2d->desc->ops->is_enabled(dev_priv, disp2d) &&
  3222. I915_READ(DPIO_CTL) & DPIO_CMNRST)
  3223. return;
  3224. DRM_DEBUG_KMS("toggling display PHY side reset\n");
  3225. /* cmnlane needs DPLL registers */
  3226. disp2d->desc->ops->enable(dev_priv, disp2d);
  3227. /*
  3228. * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
  3229. * Need to assert and de-assert PHY SB reset by gating the
  3230. * common lane power, then un-gating it.
  3231. * Simply ungating isn't enough to reset the PHY enough to get
  3232. * ports and lanes running.
  3233. */
  3234. cmn->desc->ops->disable(dev_priv, cmn);
  3235. }
  3236. static void intel_power_domains_verify_state(struct drm_i915_private *dev_priv);
  3237. /**
  3238. * intel_power_domains_init_hw - initialize hardware power domain state
  3239. * @dev_priv: i915 device instance
  3240. * @resume: Called from resume code paths or not
  3241. *
  3242. * This function initializes the hardware power domain state and enables all
  3243. * power wells belonging to the INIT power domain. Power wells in other
  3244. * domains (and not in the INIT domain) are referenced or disabled by
  3245. * intel_modeset_readout_hw_state(). After that the reference count of each
  3246. * power well must match its HW enabled state, see
  3247. * intel_power_domains_verify_state().
  3248. *
  3249. * It will return with power domains disabled (to be enabled later by
  3250. * intel_power_domains_enable()) and must be paired with
  3251. * intel_power_domains_fini_hw().
  3252. */
  3253. void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
  3254. {
  3255. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  3256. power_domains->initializing = true;
  3257. if (IS_ICELAKE(dev_priv)) {
  3258. icl_display_core_init(dev_priv, resume);
  3259. } else if (IS_CANNONLAKE(dev_priv)) {
  3260. cnl_display_core_init(dev_priv, resume);
  3261. } else if (IS_GEN9_BC(dev_priv)) {
  3262. skl_display_core_init(dev_priv, resume);
  3263. } else if (IS_GEN9_LP(dev_priv)) {
  3264. bxt_display_core_init(dev_priv, resume);
  3265. } else if (IS_CHERRYVIEW(dev_priv)) {
  3266. mutex_lock(&power_domains->lock);
  3267. chv_phy_control_init(dev_priv);
  3268. mutex_unlock(&power_domains->lock);
  3269. } else if (IS_VALLEYVIEW(dev_priv)) {
  3270. mutex_lock(&power_domains->lock);
  3271. vlv_cmnlane_wa(dev_priv);
  3272. mutex_unlock(&power_domains->lock);
  3273. }
  3274. /*
  3275. * Keep all power wells enabled for any dependent HW access during
  3276. * initialization and to make sure we keep BIOS enabled display HW
  3277. * resources powered until display HW readout is complete. We drop
  3278. * this reference in intel_power_domains_enable().
  3279. */
  3280. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  3281. /* Disable power support if the user asked so. */
  3282. if (!i915_modparams.disable_power_well)
  3283. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  3284. intel_power_domains_sync_hw(dev_priv);
  3285. power_domains->initializing = false;
  3286. }
  3287. /**
  3288. * intel_power_domains_fini_hw - deinitialize hw power domain state
  3289. * @dev_priv: i915 device instance
  3290. *
  3291. * De-initializes the display power domain HW state. It also ensures that the
  3292. * device stays powered up so that the driver can be reloaded.
  3293. *
  3294. * It must be called with power domains already disabled (after a call to
  3295. * intel_power_domains_disable()) and must be paired with
  3296. * intel_power_domains_init_hw().
  3297. */
  3298. void intel_power_domains_fini_hw(struct drm_i915_private *dev_priv)
  3299. {
  3300. /* Keep the power well enabled, but cancel its rpm wakeref. */
  3301. intel_runtime_pm_put(dev_priv);
  3302. /* Remove the refcount we took to keep power well support disabled. */
  3303. if (!i915_modparams.disable_power_well)
  3304. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  3305. intel_power_domains_verify_state(dev_priv);
  3306. }
  3307. /**
  3308. * intel_power_domains_enable - enable toggling of display power wells
  3309. * @dev_priv: i915 device instance
  3310. *
  3311. * Enable the ondemand enabling/disabling of the display power wells. Note that
  3312. * power wells not belonging to POWER_DOMAIN_INIT are allowed to be toggled
  3313. * only at specific points of the display modeset sequence, thus they are not
  3314. * affected by the intel_power_domains_enable()/disable() calls. The purpose
  3315. * of these function is to keep the rest of power wells enabled until the end
  3316. * of display HW readout (which will acquire the power references reflecting
  3317. * the current HW state).
  3318. */
  3319. void intel_power_domains_enable(struct drm_i915_private *dev_priv)
  3320. {
  3321. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  3322. intel_power_domains_verify_state(dev_priv);
  3323. }
  3324. /**
  3325. * intel_power_domains_disable - disable toggling of display power wells
  3326. * @dev_priv: i915 device instance
  3327. *
  3328. * Disable the ondemand enabling/disabling of the display power wells. See
  3329. * intel_power_domains_enable() for which power wells this call controls.
  3330. */
  3331. void intel_power_domains_disable(struct drm_i915_private *dev_priv)
  3332. {
  3333. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  3334. intel_power_domains_verify_state(dev_priv);
  3335. }
  3336. /**
  3337. * intel_power_domains_suspend - suspend power domain state
  3338. * @dev_priv: i915 device instance
  3339. * @suspend_mode: specifies the target suspend state (idle, mem, hibernation)
  3340. *
  3341. * This function prepares the hardware power domain state before entering
  3342. * system suspend.
  3343. *
  3344. * It must be called with power domains already disabled (after a call to
  3345. * intel_power_domains_disable()) and paired with intel_power_domains_resume().
  3346. */
  3347. void intel_power_domains_suspend(struct drm_i915_private *dev_priv,
  3348. enum i915_drm_suspend_mode suspend_mode)
  3349. {
  3350. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  3351. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  3352. /*
  3353. * In case of suspend-to-idle (aka S0ix) on a DMC platform without DC9
  3354. * support don't manually deinit the power domains. This also means the
  3355. * CSR/DMC firmware will stay active, it will power down any HW
  3356. * resources as required and also enable deeper system power states
  3357. * that would be blocked if the firmware was inactive.
  3358. */
  3359. if (!(dev_priv->csr.allowed_dc_mask & DC_STATE_EN_DC9) &&
  3360. suspend_mode == I915_DRM_SUSPEND_IDLE &&
  3361. dev_priv->csr.dmc_payload != NULL) {
  3362. intel_power_domains_verify_state(dev_priv);
  3363. return;
  3364. }
  3365. /*
  3366. * Even if power well support was disabled we still want to disable
  3367. * power wells if power domains must be deinitialized for suspend.
  3368. */
  3369. if (!i915_modparams.disable_power_well) {
  3370. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  3371. intel_power_domains_verify_state(dev_priv);
  3372. }
  3373. if (IS_ICELAKE(dev_priv))
  3374. icl_display_core_uninit(dev_priv);
  3375. else if (IS_CANNONLAKE(dev_priv))
  3376. cnl_display_core_uninit(dev_priv);
  3377. else if (IS_GEN9_BC(dev_priv))
  3378. skl_display_core_uninit(dev_priv);
  3379. else if (IS_GEN9_LP(dev_priv))
  3380. bxt_display_core_uninit(dev_priv);
  3381. power_domains->display_core_suspended = true;
  3382. }
  3383. /**
  3384. * intel_power_domains_resume - resume power domain state
  3385. * @dev_priv: i915 device instance
  3386. *
  3387. * This function resume the hardware power domain state during system resume.
  3388. *
  3389. * It will return with power domain support disabled (to be enabled later by
  3390. * intel_power_domains_enable()) and must be paired with
  3391. * intel_power_domains_suspend().
  3392. */
  3393. void intel_power_domains_resume(struct drm_i915_private *dev_priv)
  3394. {
  3395. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  3396. if (power_domains->display_core_suspended) {
  3397. intel_power_domains_init_hw(dev_priv, true);
  3398. power_domains->display_core_suspended = false;
  3399. } else {
  3400. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  3401. }
  3402. intel_power_domains_verify_state(dev_priv);
  3403. }
  3404. #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
  3405. static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
  3406. {
  3407. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  3408. struct i915_power_well *power_well;
  3409. for_each_power_well(dev_priv, power_well) {
  3410. enum intel_display_power_domain domain;
  3411. DRM_DEBUG_DRIVER("%-25s %d\n",
  3412. power_well->desc->name, power_well->count);
  3413. for_each_power_domain(domain, power_well->desc->domains)
  3414. DRM_DEBUG_DRIVER(" %-23s %d\n",
  3415. intel_display_power_domain_str(domain),
  3416. power_domains->domain_use_count[domain]);
  3417. }
  3418. }
  3419. /**
  3420. * intel_power_domains_verify_state - verify the HW/SW state for all power wells
  3421. * @dev_priv: i915 device instance
  3422. *
  3423. * Verify if the reference count of each power well matches its HW enabled
  3424. * state and the total refcount of the domains it belongs to. This must be
  3425. * called after modeset HW state sanitization, which is responsible for
  3426. * acquiring reference counts for any power wells in use and disabling the
  3427. * ones left on by BIOS but not required by any active output.
  3428. */
  3429. static void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
  3430. {
  3431. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  3432. struct i915_power_well *power_well;
  3433. bool dump_domain_info;
  3434. mutex_lock(&power_domains->lock);
  3435. dump_domain_info = false;
  3436. for_each_power_well(dev_priv, power_well) {
  3437. enum intel_display_power_domain domain;
  3438. int domains_count;
  3439. bool enabled;
  3440. /*
  3441. * Power wells not belonging to any domain (like the MISC_IO
  3442. * and PW1 power wells) are under FW control, so ignore them,
  3443. * since their state can change asynchronously.
  3444. */
  3445. if (!power_well->desc->domains)
  3446. continue;
  3447. enabled = power_well->desc->ops->is_enabled(dev_priv,
  3448. power_well);
  3449. if ((power_well->count || power_well->desc->always_on) !=
  3450. enabled)
  3451. DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
  3452. power_well->desc->name,
  3453. power_well->count, enabled);
  3454. domains_count = 0;
  3455. for_each_power_domain(domain, power_well->desc->domains)
  3456. domains_count += power_domains->domain_use_count[domain];
  3457. if (power_well->count != domains_count) {
  3458. DRM_ERROR("power well %s refcount/domain refcount mismatch "
  3459. "(refcount %d/domains refcount %d)\n",
  3460. power_well->desc->name, power_well->count,
  3461. domains_count);
  3462. dump_domain_info = true;
  3463. }
  3464. }
  3465. if (dump_domain_info) {
  3466. static bool dumped;
  3467. if (!dumped) {
  3468. intel_power_domains_dump_info(dev_priv);
  3469. dumped = true;
  3470. }
  3471. }
  3472. mutex_unlock(&power_domains->lock);
  3473. }
  3474. #else
  3475. static void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
  3476. {
  3477. }
  3478. #endif
  3479. /**
  3480. * intel_runtime_pm_get - grab a runtime pm reference
  3481. * @dev_priv: i915 device instance
  3482. *
  3483. * This function grabs a device-level runtime pm reference (mostly used for GEM
  3484. * code to ensure the GTT or GT is on) and ensures that it is powered up.
  3485. *
  3486. * Any runtime pm reference obtained by this function must have a symmetric
  3487. * call to intel_runtime_pm_put() to release the reference again.
  3488. */
  3489. void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
  3490. {
  3491. struct pci_dev *pdev = dev_priv->drm.pdev;
  3492. struct device *kdev = &pdev->dev;
  3493. int ret;
  3494. ret = pm_runtime_get_sync(kdev);
  3495. WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
  3496. atomic_inc(&dev_priv->runtime_pm.wakeref_count);
  3497. assert_rpm_wakelock_held(dev_priv);
  3498. }
  3499. /**
  3500. * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
  3501. * @dev_priv: i915 device instance
  3502. *
  3503. * This function grabs a device-level runtime pm reference if the device is
  3504. * already in use and ensures that it is powered up. It is illegal to try
  3505. * and access the HW should intel_runtime_pm_get_if_in_use() report failure.
  3506. *
  3507. * Any runtime pm reference obtained by this function must have a symmetric
  3508. * call to intel_runtime_pm_put() to release the reference again.
  3509. *
  3510. * Returns: True if the wakeref was acquired, or False otherwise.
  3511. */
  3512. bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
  3513. {
  3514. if (IS_ENABLED(CONFIG_PM)) {
  3515. struct pci_dev *pdev = dev_priv->drm.pdev;
  3516. struct device *kdev = &pdev->dev;
  3517. /*
  3518. * In cases runtime PM is disabled by the RPM core and we get
  3519. * an -EINVAL return value we are not supposed to call this
  3520. * function, since the power state is undefined. This applies
  3521. * atm to the late/early system suspend/resume handlers.
  3522. */
  3523. if (pm_runtime_get_if_in_use(kdev) <= 0)
  3524. return false;
  3525. }
  3526. atomic_inc(&dev_priv->runtime_pm.wakeref_count);
  3527. assert_rpm_wakelock_held(dev_priv);
  3528. return true;
  3529. }
  3530. /**
  3531. * intel_runtime_pm_get_noresume - grab a runtime pm reference
  3532. * @dev_priv: i915 device instance
  3533. *
  3534. * This function grabs a device-level runtime pm reference (mostly used for GEM
  3535. * code to ensure the GTT or GT is on).
  3536. *
  3537. * It will _not_ power up the device but instead only check that it's powered
  3538. * on. Therefore it is only valid to call this functions from contexts where
  3539. * the device is known to be powered up and where trying to power it up would
  3540. * result in hilarity and deadlocks. That pretty much means only the system
  3541. * suspend/resume code where this is used to grab runtime pm references for
  3542. * delayed setup down in work items.
  3543. *
  3544. * Any runtime pm reference obtained by this function must have a symmetric
  3545. * call to intel_runtime_pm_put() to release the reference again.
  3546. */
  3547. void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
  3548. {
  3549. struct pci_dev *pdev = dev_priv->drm.pdev;
  3550. struct device *kdev = &pdev->dev;
  3551. assert_rpm_wakelock_held(dev_priv);
  3552. pm_runtime_get_noresume(kdev);
  3553. atomic_inc(&dev_priv->runtime_pm.wakeref_count);
  3554. }
  3555. /**
  3556. * intel_runtime_pm_put - release a runtime pm reference
  3557. * @dev_priv: i915 device instance
  3558. *
  3559. * This function drops the device-level runtime pm reference obtained by
  3560. * intel_runtime_pm_get() and might power down the corresponding
  3561. * hardware block right away if this is the last reference.
  3562. */
  3563. void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
  3564. {
  3565. struct pci_dev *pdev = dev_priv->drm.pdev;
  3566. struct device *kdev = &pdev->dev;
  3567. assert_rpm_wakelock_held(dev_priv);
  3568. atomic_dec(&dev_priv->runtime_pm.wakeref_count);
  3569. pm_runtime_mark_last_busy(kdev);
  3570. pm_runtime_put_autosuspend(kdev);
  3571. }
  3572. /**
  3573. * intel_runtime_pm_enable - enable runtime pm
  3574. * @dev_priv: i915 device instance
  3575. *
  3576. * This function enables runtime pm at the end of the driver load sequence.
  3577. *
  3578. * Note that this function does currently not enable runtime pm for the
  3579. * subordinate display power domains. That is done by
  3580. * intel_power_domains_enable().
  3581. */
  3582. void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
  3583. {
  3584. struct pci_dev *pdev = dev_priv->drm.pdev;
  3585. struct device *kdev = &pdev->dev;
  3586. /*
  3587. * Disable the system suspend direct complete optimization, which can
  3588. * leave the device suspended skipping the driver's suspend handlers
  3589. * if the device was already runtime suspended. This is needed due to
  3590. * the difference in our runtime and system suspend sequence and
  3591. * becaue the HDA driver may require us to enable the audio power
  3592. * domain during system suspend.
  3593. */
  3594. dev_pm_set_driver_flags(kdev, DPM_FLAG_NEVER_SKIP);
  3595. pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
  3596. pm_runtime_mark_last_busy(kdev);
  3597. /*
  3598. * Take a permanent reference to disable the RPM functionality and drop
  3599. * it only when unloading the driver. Use the low level get/put helpers,
  3600. * so the driver's own RPM reference tracking asserts also work on
  3601. * platforms without RPM support.
  3602. */
  3603. if (!HAS_RUNTIME_PM(dev_priv)) {
  3604. int ret;
  3605. pm_runtime_dont_use_autosuspend(kdev);
  3606. ret = pm_runtime_get_sync(kdev);
  3607. WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
  3608. } else {
  3609. pm_runtime_use_autosuspend(kdev);
  3610. }
  3611. /*
  3612. * The core calls the driver load handler with an RPM reference held.
  3613. * We drop that here and will reacquire it during unloading in
  3614. * intel_power_domains_fini().
  3615. */
  3616. pm_runtime_put_autosuspend(kdev);
  3617. }
  3618. void intel_runtime_pm_disable(struct drm_i915_private *dev_priv)
  3619. {
  3620. struct pci_dev *pdev = dev_priv->drm.pdev;
  3621. struct device *kdev = &pdev->dev;
  3622. /* Transfer rpm ownership back to core */
  3623. WARN(pm_runtime_get_sync(&dev_priv->drm.pdev->dev) < 0,
  3624. "Failed to pass rpm ownership back to core\n");
  3625. pm_runtime_dont_use_autosuspend(kdev);
  3626. if (!HAS_RUNTIME_PM(dev_priv))
  3627. pm_runtime_put(kdev);
  3628. }