intel_runtime_pm.c 110 KB

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