intel_runtime_pm.c 90 KB

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