intel_runtime_pm.c 96 KB

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