intel_runtime_pm.c 100 KB

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