intel_runtime_pm.c 94 KB

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