intel_runtime_pm.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174
  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. #define GEN9_ENABLE_DC5(dev) 0
  49. #define SKL_ENABLE_DC6(dev) IS_SKYLAKE(dev)
  50. #define for_each_power_well(i, power_well, domain_mask, power_domains) \
  51. for (i = 0; \
  52. i < (power_domains)->power_well_count && \
  53. ((power_well) = &(power_domains)->power_wells[i]); \
  54. i++) \
  55. if ((power_well)->domains & (domain_mask))
  56. #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \
  57. for (i = (power_domains)->power_well_count - 1; \
  58. i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\
  59. i--) \
  60. if ((power_well)->domains & (domain_mask))
  61. bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
  62. int power_well_id);
  63. static void intel_power_well_enable(struct drm_i915_private *dev_priv,
  64. struct i915_power_well *power_well)
  65. {
  66. DRM_DEBUG_KMS("enabling %s\n", power_well->name);
  67. power_well->ops->enable(dev_priv, power_well);
  68. power_well->hw_enabled = true;
  69. }
  70. static void intel_power_well_disable(struct drm_i915_private *dev_priv,
  71. struct i915_power_well *power_well)
  72. {
  73. DRM_DEBUG_KMS("disabling %s\n", power_well->name);
  74. power_well->hw_enabled = false;
  75. power_well->ops->disable(dev_priv, power_well);
  76. }
  77. /*
  78. * We should only use the power well if we explicitly asked the hardware to
  79. * enable it, so check if it's enabled and also check if we've requested it to
  80. * be enabled.
  81. */
  82. static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
  83. struct i915_power_well *power_well)
  84. {
  85. return I915_READ(HSW_PWR_WELL_DRIVER) ==
  86. (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
  87. }
  88. /**
  89. * __intel_display_power_is_enabled - unlocked check for a power domain
  90. * @dev_priv: i915 device instance
  91. * @domain: power domain to check
  92. *
  93. * This is the unlocked version of intel_display_power_is_enabled() and should
  94. * only be used from error capture and recovery code where deadlocks are
  95. * possible.
  96. *
  97. * Returns:
  98. * True when the power domain is enabled, false otherwise.
  99. */
  100. bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
  101. enum intel_display_power_domain domain)
  102. {
  103. struct i915_power_domains *power_domains;
  104. struct i915_power_well *power_well;
  105. bool is_enabled;
  106. int i;
  107. if (dev_priv->pm.suspended)
  108. return false;
  109. power_domains = &dev_priv->power_domains;
  110. is_enabled = true;
  111. for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
  112. if (power_well->always_on)
  113. continue;
  114. if (!power_well->hw_enabled) {
  115. is_enabled = false;
  116. break;
  117. }
  118. }
  119. return is_enabled;
  120. }
  121. /**
  122. * intel_display_power_is_enabled - check for a power domain
  123. * @dev_priv: i915 device instance
  124. * @domain: power domain to check
  125. *
  126. * This function can be used to check the hw power domain state. It is mostly
  127. * used in hardware state readout functions. Everywhere else code should rely
  128. * upon explicit power domain reference counting to ensure that the hardware
  129. * block is powered up before accessing it.
  130. *
  131. * Callers must hold the relevant modesetting locks to ensure that concurrent
  132. * threads can't disable the power well while the caller tries to read a few
  133. * registers.
  134. *
  135. * Returns:
  136. * True when the power domain is enabled, false otherwise.
  137. */
  138. bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
  139. enum intel_display_power_domain domain)
  140. {
  141. struct i915_power_domains *power_domains;
  142. bool ret;
  143. power_domains = &dev_priv->power_domains;
  144. mutex_lock(&power_domains->lock);
  145. ret = __intel_display_power_is_enabled(dev_priv, domain);
  146. mutex_unlock(&power_domains->lock);
  147. return ret;
  148. }
  149. /**
  150. * intel_display_set_init_power - set the initial power domain state
  151. * @dev_priv: i915 device instance
  152. * @enable: whether to enable or disable the initial power domain state
  153. *
  154. * For simplicity our driver load/unload and system suspend/resume code assumes
  155. * that all power domains are always enabled. This functions controls the state
  156. * of this little hack. While the initial power domain state is enabled runtime
  157. * pm is effectively disabled.
  158. */
  159. void intel_display_set_init_power(struct drm_i915_private *dev_priv,
  160. bool enable)
  161. {
  162. if (dev_priv->power_domains.init_power_on == enable)
  163. return;
  164. if (enable)
  165. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  166. else
  167. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  168. dev_priv->power_domains.init_power_on = enable;
  169. }
  170. /*
  171. * Starting with Haswell, we have a "Power Down Well" that can be turned off
  172. * when not needed anymore. We have 4 registers that can request the power well
  173. * to be enabled, and it will only be disabled if none of the registers is
  174. * requesting it to be enabled.
  175. */
  176. static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
  177. {
  178. struct drm_device *dev = dev_priv->dev;
  179. /*
  180. * After we re-enable the power well, if we touch VGA register 0x3d5
  181. * we'll get unclaimed register interrupts. This stops after we write
  182. * anything to the VGA MSR register. The vgacon module uses this
  183. * register all the time, so if we unbind our driver and, as a
  184. * consequence, bind vgacon, we'll get stuck in an infinite loop at
  185. * console_unlock(). So make here we touch the VGA MSR register, making
  186. * sure vgacon can keep working normally without triggering interrupts
  187. * and error messages.
  188. */
  189. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  190. outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
  191. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  192. if (IS_BROADWELL(dev))
  193. gen8_irq_power_well_post_enable(dev_priv,
  194. 1 << PIPE_C | 1 << PIPE_B);
  195. }
  196. static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
  197. struct i915_power_well *power_well)
  198. {
  199. struct drm_device *dev = dev_priv->dev;
  200. /*
  201. * After we re-enable the power well, if we touch VGA register 0x3d5
  202. * we'll get unclaimed register interrupts. This stops after we write
  203. * anything to the VGA MSR register. The vgacon module uses this
  204. * register all the time, so if we unbind our driver and, as a
  205. * consequence, bind vgacon, we'll get stuck in an infinite loop at
  206. * console_unlock(). So make here we touch the VGA MSR register, making
  207. * sure vgacon can keep working normally without triggering interrupts
  208. * and error messages.
  209. */
  210. if (power_well->data == SKL_DISP_PW_2) {
  211. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  212. outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
  213. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  214. gen8_irq_power_well_post_enable(dev_priv,
  215. 1 << PIPE_C | 1 << PIPE_B);
  216. }
  217. if (power_well->data == SKL_DISP_PW_1) {
  218. if (!dev_priv->power_domains.initializing)
  219. intel_prepare_ddi(dev);
  220. gen8_irq_power_well_post_enable(dev_priv, 1 << PIPE_A);
  221. }
  222. }
  223. static void hsw_set_power_well(struct drm_i915_private *dev_priv,
  224. struct i915_power_well *power_well, bool enable)
  225. {
  226. bool is_enabled, enable_requested;
  227. uint32_t tmp;
  228. tmp = I915_READ(HSW_PWR_WELL_DRIVER);
  229. is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
  230. enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
  231. if (enable) {
  232. if (!enable_requested)
  233. I915_WRITE(HSW_PWR_WELL_DRIVER,
  234. HSW_PWR_WELL_ENABLE_REQUEST);
  235. if (!is_enabled) {
  236. DRM_DEBUG_KMS("Enabling power well\n");
  237. if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
  238. HSW_PWR_WELL_STATE_ENABLED), 20))
  239. DRM_ERROR("Timeout enabling power well\n");
  240. hsw_power_well_post_enable(dev_priv);
  241. }
  242. } else {
  243. if (enable_requested) {
  244. I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
  245. POSTING_READ(HSW_PWR_WELL_DRIVER);
  246. DRM_DEBUG_KMS("Requesting to disable the power well\n");
  247. }
  248. }
  249. }
  250. #define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
  251. BIT(POWER_DOMAIN_TRANSCODER_A) | \
  252. BIT(POWER_DOMAIN_PIPE_B) | \
  253. BIT(POWER_DOMAIN_TRANSCODER_B) | \
  254. BIT(POWER_DOMAIN_PIPE_C) | \
  255. BIT(POWER_DOMAIN_TRANSCODER_C) | \
  256. BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  257. BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  258. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  259. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  260. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  261. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  262. BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
  263. BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
  264. BIT(POWER_DOMAIN_PORT_DDI_E_2_LANES) | \
  265. BIT(POWER_DOMAIN_AUX_B) | \
  266. BIT(POWER_DOMAIN_AUX_C) | \
  267. BIT(POWER_DOMAIN_AUX_D) | \
  268. BIT(POWER_DOMAIN_AUDIO) | \
  269. BIT(POWER_DOMAIN_VGA) | \
  270. BIT(POWER_DOMAIN_INIT))
  271. #define SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
  272. SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  273. BIT(POWER_DOMAIN_PLLS) | \
  274. BIT(POWER_DOMAIN_PIPE_A) | \
  275. BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
  276. BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
  277. BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
  278. BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
  279. BIT(POWER_DOMAIN_AUX_A) | \
  280. BIT(POWER_DOMAIN_INIT))
  281. #define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
  282. BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
  283. BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
  284. BIT(POWER_DOMAIN_PORT_DDI_E_2_LANES) | \
  285. BIT(POWER_DOMAIN_INIT))
  286. #define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
  287. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  288. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  289. BIT(POWER_DOMAIN_INIT))
  290. #define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
  291. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  292. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  293. BIT(POWER_DOMAIN_INIT))
  294. #define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
  295. BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
  296. BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
  297. BIT(POWER_DOMAIN_INIT))
  298. #define SKL_DISPLAY_MISC_IO_POWER_DOMAINS ( \
  299. SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
  300. BIT(POWER_DOMAIN_PLLS) | \
  301. BIT(POWER_DOMAIN_INIT))
  302. #define SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
  303. (POWER_DOMAIN_MASK & ~(SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
  304. SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  305. SKL_DISPLAY_DDI_A_E_POWER_DOMAINS | \
  306. SKL_DISPLAY_DDI_B_POWER_DOMAINS | \
  307. SKL_DISPLAY_DDI_C_POWER_DOMAINS | \
  308. SKL_DISPLAY_DDI_D_POWER_DOMAINS | \
  309. SKL_DISPLAY_MISC_IO_POWER_DOMAINS)) | \
  310. BIT(POWER_DOMAIN_INIT))
  311. #define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
  312. BIT(POWER_DOMAIN_TRANSCODER_A) | \
  313. BIT(POWER_DOMAIN_PIPE_B) | \
  314. BIT(POWER_DOMAIN_TRANSCODER_B) | \
  315. BIT(POWER_DOMAIN_PIPE_C) | \
  316. BIT(POWER_DOMAIN_TRANSCODER_C) | \
  317. BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  318. BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  319. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  320. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  321. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  322. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  323. BIT(POWER_DOMAIN_AUX_B) | \
  324. BIT(POWER_DOMAIN_AUX_C) | \
  325. BIT(POWER_DOMAIN_AUDIO) | \
  326. BIT(POWER_DOMAIN_VGA) | \
  327. BIT(POWER_DOMAIN_GMBUS) | \
  328. BIT(POWER_DOMAIN_INIT))
  329. #define BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
  330. BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  331. BIT(POWER_DOMAIN_PIPE_A) | \
  332. BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
  333. BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
  334. BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
  335. BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
  336. BIT(POWER_DOMAIN_AUX_A) | \
  337. BIT(POWER_DOMAIN_PLLS) | \
  338. BIT(POWER_DOMAIN_INIT))
  339. #define BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
  340. (POWER_DOMAIN_MASK & ~(BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
  341. BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS)) | \
  342. BIT(POWER_DOMAIN_INIT))
  343. static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
  344. {
  345. struct drm_device *dev = dev_priv->dev;
  346. WARN(!IS_BROXTON(dev), "Platform doesn't support DC9.\n");
  347. WARN((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
  348. "DC9 already programmed to be enabled.\n");
  349. WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
  350. "DC5 still not disabled to enable DC9.\n");
  351. WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on.\n");
  352. WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
  353. /*
  354. * TODO: check for the following to verify the conditions to enter DC9
  355. * state are satisfied:
  356. * 1] Check relevant display engine registers to verify if mode set
  357. * disable sequence was followed.
  358. * 2] Check if display uninitialize sequence is initialized.
  359. */
  360. }
  361. static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
  362. {
  363. WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
  364. WARN(!(I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
  365. "DC9 already programmed to be disabled.\n");
  366. WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
  367. "DC5 still not disabled.\n");
  368. /*
  369. * TODO: check for the following to verify DC9 state was indeed
  370. * entered before programming to disable it:
  371. * 1] Check relevant display engine registers to verify if mode
  372. * set disable sequence was followed.
  373. * 2] Check if display uninitialize sequence is initialized.
  374. */
  375. }
  376. void bxt_enable_dc9(struct drm_i915_private *dev_priv)
  377. {
  378. uint32_t val;
  379. assert_can_enable_dc9(dev_priv);
  380. DRM_DEBUG_KMS("Enabling DC9\n");
  381. val = I915_READ(DC_STATE_EN);
  382. val |= DC_STATE_EN_DC9;
  383. I915_WRITE(DC_STATE_EN, val);
  384. POSTING_READ(DC_STATE_EN);
  385. }
  386. void bxt_disable_dc9(struct drm_i915_private *dev_priv)
  387. {
  388. uint32_t val;
  389. assert_can_disable_dc9(dev_priv);
  390. DRM_DEBUG_KMS("Disabling DC9\n");
  391. val = I915_READ(DC_STATE_EN);
  392. val &= ~DC_STATE_EN_DC9;
  393. I915_WRITE(DC_STATE_EN, val);
  394. POSTING_READ(DC_STATE_EN);
  395. }
  396. static void gen9_set_dc_state_debugmask_memory_up(
  397. struct drm_i915_private *dev_priv)
  398. {
  399. uint32_t val;
  400. /* The below bit doesn't need to be cleared ever afterwards */
  401. val = I915_READ(DC_STATE_DEBUG);
  402. if (!(val & DC_STATE_DEBUG_MASK_MEMORY_UP)) {
  403. val |= DC_STATE_DEBUG_MASK_MEMORY_UP;
  404. I915_WRITE(DC_STATE_DEBUG, val);
  405. POSTING_READ(DC_STATE_DEBUG);
  406. }
  407. }
  408. static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
  409. {
  410. struct drm_device *dev = dev_priv->dev;
  411. bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
  412. SKL_DISP_PW_2);
  413. WARN_ONCE(!IS_SKYLAKE(dev), "Platform doesn't support DC5.\n");
  414. WARN_ONCE(!HAS_RUNTIME_PM(dev), "Runtime PM not enabled.\n");
  415. WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
  416. WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
  417. "DC5 already programmed to be enabled.\n");
  418. WARN_ONCE(dev_priv->pm.suspended,
  419. "DC5 cannot be enabled, if platform is runtime-suspended.\n");
  420. assert_csr_loaded(dev_priv);
  421. }
  422. static void assert_can_disable_dc5(struct drm_i915_private *dev_priv)
  423. {
  424. bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
  425. SKL_DISP_PW_2);
  426. /*
  427. * During initialization, the firmware may not be loaded yet.
  428. * We still want to make sure that the DC enabling flag is cleared.
  429. */
  430. if (dev_priv->power_domains.initializing)
  431. return;
  432. WARN_ONCE(!pg2_enabled, "PG2 not enabled to disable DC5.\n");
  433. WARN_ONCE(dev_priv->pm.suspended,
  434. "Disabling of DC5 while platform is runtime-suspended should never happen.\n");
  435. }
  436. static void gen9_enable_dc5(struct drm_i915_private *dev_priv)
  437. {
  438. uint32_t val;
  439. assert_can_enable_dc5(dev_priv);
  440. DRM_DEBUG_KMS("Enabling DC5\n");
  441. gen9_set_dc_state_debugmask_memory_up(dev_priv);
  442. val = I915_READ(DC_STATE_EN);
  443. val &= ~DC_STATE_EN_UPTO_DC5_DC6_MASK;
  444. val |= DC_STATE_EN_UPTO_DC5;
  445. I915_WRITE(DC_STATE_EN, val);
  446. POSTING_READ(DC_STATE_EN);
  447. }
  448. static void gen9_disable_dc5(struct drm_i915_private *dev_priv)
  449. {
  450. uint32_t val;
  451. assert_can_disable_dc5(dev_priv);
  452. DRM_DEBUG_KMS("Disabling DC5\n");
  453. val = I915_READ(DC_STATE_EN);
  454. val &= ~DC_STATE_EN_UPTO_DC5;
  455. I915_WRITE(DC_STATE_EN, val);
  456. POSTING_READ(DC_STATE_EN);
  457. }
  458. static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
  459. {
  460. struct drm_device *dev = dev_priv->dev;
  461. WARN_ONCE(!IS_SKYLAKE(dev), "Platform doesn't support DC6.\n");
  462. WARN_ONCE(!HAS_RUNTIME_PM(dev), "Runtime PM not enabled.\n");
  463. WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  464. "Backlight is not disabled.\n");
  465. WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
  466. "DC6 already programmed to be enabled.\n");
  467. assert_csr_loaded(dev_priv);
  468. }
  469. static void assert_can_disable_dc6(struct drm_i915_private *dev_priv)
  470. {
  471. /*
  472. * During initialization, the firmware may not be loaded yet.
  473. * We still want to make sure that the DC enabling flag is cleared.
  474. */
  475. if (dev_priv->power_domains.initializing)
  476. return;
  477. assert_csr_loaded(dev_priv);
  478. WARN_ONCE(!(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
  479. "DC6 already programmed to be disabled.\n");
  480. }
  481. static void skl_enable_dc6(struct drm_i915_private *dev_priv)
  482. {
  483. uint32_t val;
  484. assert_can_enable_dc6(dev_priv);
  485. DRM_DEBUG_KMS("Enabling DC6\n");
  486. gen9_set_dc_state_debugmask_memory_up(dev_priv);
  487. val = I915_READ(DC_STATE_EN);
  488. val &= ~DC_STATE_EN_UPTO_DC5_DC6_MASK;
  489. val |= DC_STATE_EN_UPTO_DC6;
  490. I915_WRITE(DC_STATE_EN, val);
  491. POSTING_READ(DC_STATE_EN);
  492. }
  493. static void skl_disable_dc6(struct drm_i915_private *dev_priv)
  494. {
  495. uint32_t val;
  496. assert_can_disable_dc6(dev_priv);
  497. DRM_DEBUG_KMS("Disabling DC6\n");
  498. val = I915_READ(DC_STATE_EN);
  499. val &= ~DC_STATE_EN_UPTO_DC6;
  500. I915_WRITE(DC_STATE_EN, val);
  501. POSTING_READ(DC_STATE_EN);
  502. }
  503. static void skl_set_power_well(struct drm_i915_private *dev_priv,
  504. struct i915_power_well *power_well, bool enable)
  505. {
  506. struct drm_device *dev = dev_priv->dev;
  507. uint32_t tmp, fuse_status;
  508. uint32_t req_mask, state_mask;
  509. bool is_enabled, enable_requested, check_fuse_status = false;
  510. tmp = I915_READ(HSW_PWR_WELL_DRIVER);
  511. fuse_status = I915_READ(SKL_FUSE_STATUS);
  512. switch (power_well->data) {
  513. case SKL_DISP_PW_1:
  514. if (wait_for((I915_READ(SKL_FUSE_STATUS) &
  515. SKL_FUSE_PG0_DIST_STATUS), 1)) {
  516. DRM_ERROR("PG0 not enabled\n");
  517. return;
  518. }
  519. break;
  520. case SKL_DISP_PW_2:
  521. if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
  522. DRM_ERROR("PG1 in disabled state\n");
  523. return;
  524. }
  525. break;
  526. case SKL_DISP_PW_DDI_A_E:
  527. case SKL_DISP_PW_DDI_B:
  528. case SKL_DISP_PW_DDI_C:
  529. case SKL_DISP_PW_DDI_D:
  530. case SKL_DISP_PW_MISC_IO:
  531. break;
  532. default:
  533. WARN(1, "Unknown power well %lu\n", power_well->data);
  534. return;
  535. }
  536. req_mask = SKL_POWER_WELL_REQ(power_well->data);
  537. enable_requested = tmp & req_mask;
  538. state_mask = SKL_POWER_WELL_STATE(power_well->data);
  539. is_enabled = tmp & state_mask;
  540. if (enable) {
  541. if (!enable_requested) {
  542. WARN((tmp & state_mask) &&
  543. !I915_READ(HSW_PWR_WELL_BIOS),
  544. "Invalid for power well status to be enabled, unless done by the BIOS, \
  545. when request is to disable!\n");
  546. if ((GEN9_ENABLE_DC5(dev) || SKL_ENABLE_DC6(dev)) &&
  547. power_well->data == SKL_DISP_PW_2) {
  548. if (SKL_ENABLE_DC6(dev)) {
  549. skl_disable_dc6(dev_priv);
  550. /*
  551. * DDI buffer programming unnecessary during driver-load/resume
  552. * as it's already done during modeset initialization then.
  553. * It's also invalid here as encoder list is still uninitialized.
  554. */
  555. if (!dev_priv->power_domains.initializing)
  556. intel_prepare_ddi(dev);
  557. } else {
  558. gen9_disable_dc5(dev_priv);
  559. }
  560. }
  561. I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
  562. }
  563. if (!is_enabled) {
  564. DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
  565. if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
  566. state_mask), 1))
  567. DRM_ERROR("%s enable timeout\n",
  568. power_well->name);
  569. check_fuse_status = true;
  570. }
  571. } else {
  572. if (enable_requested) {
  573. if (IS_SKYLAKE(dev) &&
  574. (power_well->data == SKL_DISP_PW_1) &&
  575. (intel_csr_load_status_get(dev_priv) == FW_LOADED))
  576. DRM_DEBUG_KMS("Not Disabling PW1, dmc will handle\n");
  577. else {
  578. I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
  579. POSTING_READ(HSW_PWR_WELL_DRIVER);
  580. DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
  581. }
  582. if ((GEN9_ENABLE_DC5(dev) || SKL_ENABLE_DC6(dev)) &&
  583. power_well->data == SKL_DISP_PW_2) {
  584. enum csr_state state;
  585. /* TODO: wait for a completion event or
  586. * similar here instead of busy
  587. * waiting using wait_for function.
  588. */
  589. wait_for((state = intel_csr_load_status_get(dev_priv)) !=
  590. FW_UNINITIALIZED, 1000);
  591. if (state != FW_LOADED)
  592. DRM_DEBUG("CSR firmware not ready (%d)\n",
  593. state);
  594. else
  595. if (SKL_ENABLE_DC6(dev))
  596. skl_enable_dc6(dev_priv);
  597. else
  598. gen9_enable_dc5(dev_priv);
  599. }
  600. }
  601. }
  602. if (check_fuse_status) {
  603. if (power_well->data == SKL_DISP_PW_1) {
  604. if (wait_for((I915_READ(SKL_FUSE_STATUS) &
  605. SKL_FUSE_PG1_DIST_STATUS), 1))
  606. DRM_ERROR("PG1 distributing status timeout\n");
  607. } else if (power_well->data == SKL_DISP_PW_2) {
  608. if (wait_for((I915_READ(SKL_FUSE_STATUS) &
  609. SKL_FUSE_PG2_DIST_STATUS), 1))
  610. DRM_ERROR("PG2 distributing status timeout\n");
  611. }
  612. }
  613. if (enable && !is_enabled)
  614. skl_power_well_post_enable(dev_priv, power_well);
  615. }
  616. static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
  617. struct i915_power_well *power_well)
  618. {
  619. hsw_set_power_well(dev_priv, power_well, power_well->count > 0);
  620. /*
  621. * We're taking over the BIOS, so clear any requests made by it since
  622. * the driver is in charge now.
  623. */
  624. if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
  625. I915_WRITE(HSW_PWR_WELL_BIOS, 0);
  626. }
  627. static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
  628. struct i915_power_well *power_well)
  629. {
  630. hsw_set_power_well(dev_priv, power_well, true);
  631. }
  632. static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
  633. struct i915_power_well *power_well)
  634. {
  635. hsw_set_power_well(dev_priv, power_well, false);
  636. }
  637. static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
  638. struct i915_power_well *power_well)
  639. {
  640. uint32_t mask = SKL_POWER_WELL_REQ(power_well->data) |
  641. SKL_POWER_WELL_STATE(power_well->data);
  642. return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
  643. }
  644. static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
  645. struct i915_power_well *power_well)
  646. {
  647. skl_set_power_well(dev_priv, power_well, power_well->count > 0);
  648. /* Clear any request made by BIOS as driver is taking over */
  649. I915_WRITE(HSW_PWR_WELL_BIOS, 0);
  650. }
  651. static void skl_power_well_enable(struct drm_i915_private *dev_priv,
  652. struct i915_power_well *power_well)
  653. {
  654. skl_set_power_well(dev_priv, power_well, true);
  655. }
  656. static void skl_power_well_disable(struct drm_i915_private *dev_priv,
  657. struct i915_power_well *power_well)
  658. {
  659. skl_set_power_well(dev_priv, power_well, false);
  660. }
  661. static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
  662. struct i915_power_well *power_well)
  663. {
  664. }
  665. static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
  666. struct i915_power_well *power_well)
  667. {
  668. return true;
  669. }
  670. static void vlv_set_power_well(struct drm_i915_private *dev_priv,
  671. struct i915_power_well *power_well, bool enable)
  672. {
  673. enum punit_power_well power_well_id = power_well->data;
  674. u32 mask;
  675. u32 state;
  676. u32 ctrl;
  677. mask = PUNIT_PWRGT_MASK(power_well_id);
  678. state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
  679. PUNIT_PWRGT_PWR_GATE(power_well_id);
  680. mutex_lock(&dev_priv->rps.hw_lock);
  681. #define COND \
  682. ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
  683. if (COND)
  684. goto out;
  685. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
  686. ctrl &= ~mask;
  687. ctrl |= state;
  688. vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
  689. if (wait_for(COND, 100))
  690. DRM_ERROR("timeout setting power well state %08x (%08x)\n",
  691. state,
  692. vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
  693. #undef COND
  694. out:
  695. mutex_unlock(&dev_priv->rps.hw_lock);
  696. }
  697. static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv,
  698. struct i915_power_well *power_well)
  699. {
  700. vlv_set_power_well(dev_priv, power_well, power_well->count > 0);
  701. }
  702. static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
  703. struct i915_power_well *power_well)
  704. {
  705. vlv_set_power_well(dev_priv, power_well, true);
  706. }
  707. static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
  708. struct i915_power_well *power_well)
  709. {
  710. vlv_set_power_well(dev_priv, power_well, false);
  711. }
  712. static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
  713. struct i915_power_well *power_well)
  714. {
  715. int power_well_id = power_well->data;
  716. bool enabled = false;
  717. u32 mask;
  718. u32 state;
  719. u32 ctrl;
  720. mask = PUNIT_PWRGT_MASK(power_well_id);
  721. ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
  722. mutex_lock(&dev_priv->rps.hw_lock);
  723. state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
  724. /*
  725. * We only ever set the power-on and power-gate states, anything
  726. * else is unexpected.
  727. */
  728. WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
  729. state != PUNIT_PWRGT_PWR_GATE(power_well_id));
  730. if (state == ctrl)
  731. enabled = true;
  732. /*
  733. * A transient state at this point would mean some unexpected party
  734. * is poking at the power controls too.
  735. */
  736. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
  737. WARN_ON(ctrl != state);
  738. mutex_unlock(&dev_priv->rps.hw_lock);
  739. return enabled;
  740. }
  741. static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
  742. {
  743. enum pipe pipe;
  744. /*
  745. * Enable the CRI clock source so we can get at the
  746. * display and the reference clock for VGA
  747. * hotplug / manual detection. Supposedly DSI also
  748. * needs the ref clock up and running.
  749. *
  750. * CHV DPLL B/C have some issues if VGA mode is enabled.
  751. */
  752. for_each_pipe(dev_priv->dev, pipe) {
  753. u32 val = I915_READ(DPLL(pipe));
  754. val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
  755. if (pipe != PIPE_A)
  756. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  757. I915_WRITE(DPLL(pipe), val);
  758. }
  759. spin_lock_irq(&dev_priv->irq_lock);
  760. valleyview_enable_display_irqs(dev_priv);
  761. spin_unlock_irq(&dev_priv->irq_lock);
  762. /*
  763. * During driver initialization/resume we can avoid restoring the
  764. * part of the HW/SW state that will be inited anyway explicitly.
  765. */
  766. if (dev_priv->power_domains.initializing)
  767. return;
  768. intel_hpd_init(dev_priv);
  769. i915_redisable_vga_power_on(dev_priv->dev);
  770. }
  771. static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
  772. {
  773. spin_lock_irq(&dev_priv->irq_lock);
  774. valleyview_disable_display_irqs(dev_priv);
  775. spin_unlock_irq(&dev_priv->irq_lock);
  776. vlv_power_sequencer_reset(dev_priv);
  777. }
  778. static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
  779. struct i915_power_well *power_well)
  780. {
  781. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
  782. vlv_set_power_well(dev_priv, power_well, true);
  783. vlv_display_power_well_init(dev_priv);
  784. }
  785. static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
  786. struct i915_power_well *power_well)
  787. {
  788. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
  789. vlv_display_power_well_deinit(dev_priv);
  790. vlv_set_power_well(dev_priv, power_well, false);
  791. }
  792. static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
  793. struct i915_power_well *power_well)
  794. {
  795. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
  796. /* since ref/cri clock was enabled */
  797. udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
  798. vlv_set_power_well(dev_priv, power_well, true);
  799. /*
  800. * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
  801. * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
  802. * a. GUnit 0x2110 bit[0] set to 1 (def 0)
  803. * b. The other bits such as sfr settings / modesel may all
  804. * be set to 0.
  805. *
  806. * This should only be done on init and resume from S3 with
  807. * both PLLs disabled, or we risk losing DPIO and PLL
  808. * synchronization.
  809. */
  810. I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
  811. }
  812. static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
  813. struct i915_power_well *power_well)
  814. {
  815. enum pipe pipe;
  816. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
  817. for_each_pipe(dev_priv, pipe)
  818. assert_pll_disabled(dev_priv, pipe);
  819. /* Assert common reset */
  820. I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
  821. vlv_set_power_well(dev_priv, power_well, false);
  822. }
  823. #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
  824. static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
  825. int power_well_id)
  826. {
  827. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  828. struct i915_power_well *power_well;
  829. int i;
  830. for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
  831. if (power_well->data == power_well_id)
  832. return power_well;
  833. }
  834. return NULL;
  835. }
  836. #define BITS_SET(val, bits) (((val) & (bits)) == (bits))
  837. static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
  838. {
  839. struct i915_power_well *cmn_bc =
  840. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
  841. struct i915_power_well *cmn_d =
  842. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
  843. u32 phy_control = dev_priv->chv_phy_control;
  844. u32 phy_status = 0;
  845. u32 phy_status_mask = 0xffffffff;
  846. u32 tmp;
  847. /*
  848. * The BIOS can leave the PHY is some weird state
  849. * where it doesn't fully power down some parts.
  850. * Disable the asserts until the PHY has been fully
  851. * reset (ie. the power well has been disabled at
  852. * least once).
  853. */
  854. if (!dev_priv->chv_phy_assert[DPIO_PHY0])
  855. phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
  856. PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
  857. PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
  858. PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
  859. PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
  860. PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
  861. if (!dev_priv->chv_phy_assert[DPIO_PHY1])
  862. phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
  863. PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
  864. PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
  865. if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
  866. phy_status |= PHY_POWERGOOD(DPIO_PHY0);
  867. /* this assumes override is only used to enable lanes */
  868. if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
  869. phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
  870. if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
  871. phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
  872. /* CL1 is on whenever anything is on in either channel */
  873. if (BITS_SET(phy_control,
  874. PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
  875. PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
  876. phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
  877. /*
  878. * The DPLLB check accounts for the pipe B + port A usage
  879. * with CL2 powered up but all the lanes in the second channel
  880. * powered down.
  881. */
  882. if (BITS_SET(phy_control,
  883. PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
  884. (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
  885. phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
  886. if (BITS_SET(phy_control,
  887. PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
  888. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
  889. if (BITS_SET(phy_control,
  890. PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
  891. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
  892. if (BITS_SET(phy_control,
  893. PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
  894. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
  895. if (BITS_SET(phy_control,
  896. PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
  897. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
  898. }
  899. if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
  900. phy_status |= PHY_POWERGOOD(DPIO_PHY1);
  901. /* this assumes override is only used to enable lanes */
  902. if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
  903. phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
  904. if (BITS_SET(phy_control,
  905. PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
  906. phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
  907. if (BITS_SET(phy_control,
  908. PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
  909. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
  910. if (BITS_SET(phy_control,
  911. PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
  912. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
  913. }
  914. phy_status &= phy_status_mask;
  915. /*
  916. * The PHY may be busy with some initial calibration and whatnot,
  917. * so the power state can take a while to actually change.
  918. */
  919. if (wait_for((tmp = I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask) == phy_status, 10))
  920. WARN(phy_status != tmp,
  921. "Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
  922. tmp, phy_status, dev_priv->chv_phy_control);
  923. }
  924. #undef BITS_SET
  925. static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
  926. struct i915_power_well *power_well)
  927. {
  928. enum dpio_phy phy;
  929. enum pipe pipe;
  930. uint32_t tmp;
  931. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
  932. power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
  933. if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
  934. pipe = PIPE_A;
  935. phy = DPIO_PHY0;
  936. } else {
  937. pipe = PIPE_C;
  938. phy = DPIO_PHY1;
  939. }
  940. /* since ref/cri clock was enabled */
  941. udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
  942. vlv_set_power_well(dev_priv, power_well, true);
  943. /* Poll for phypwrgood signal */
  944. if (wait_for(I915_READ(DISPLAY_PHY_STATUS) & PHY_POWERGOOD(phy), 1))
  945. DRM_ERROR("Display PHY %d is not power up\n", phy);
  946. mutex_lock(&dev_priv->sb_lock);
  947. /* Enable dynamic power down */
  948. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
  949. tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
  950. DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
  951. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
  952. if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
  953. tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
  954. tmp |= DPIO_DYNPWRDOWNEN_CH1;
  955. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
  956. } else {
  957. /*
  958. * Force the non-existing CL2 off. BXT does this
  959. * too, so maybe it saves some power even though
  960. * CL2 doesn't exist?
  961. */
  962. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
  963. tmp |= DPIO_CL2_LDOFUSE_PWRENB;
  964. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
  965. }
  966. mutex_unlock(&dev_priv->sb_lock);
  967. dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
  968. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  969. DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
  970. phy, dev_priv->chv_phy_control);
  971. assert_chv_phy_status(dev_priv);
  972. }
  973. static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
  974. struct i915_power_well *power_well)
  975. {
  976. enum dpio_phy phy;
  977. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
  978. power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
  979. if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
  980. phy = DPIO_PHY0;
  981. assert_pll_disabled(dev_priv, PIPE_A);
  982. assert_pll_disabled(dev_priv, PIPE_B);
  983. } else {
  984. phy = DPIO_PHY1;
  985. assert_pll_disabled(dev_priv, PIPE_C);
  986. }
  987. dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
  988. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  989. vlv_set_power_well(dev_priv, power_well, false);
  990. DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
  991. phy, dev_priv->chv_phy_control);
  992. /* PHY is fully reset now, so we can enable the PHY state asserts */
  993. dev_priv->chv_phy_assert[phy] = true;
  994. assert_chv_phy_status(dev_priv);
  995. }
  996. static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
  997. enum dpio_channel ch, bool override, unsigned int mask)
  998. {
  999. enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
  1000. u32 reg, val, expected, actual;
  1001. /*
  1002. * The BIOS can leave the PHY is some weird state
  1003. * where it doesn't fully power down some parts.
  1004. * Disable the asserts until the PHY has been fully
  1005. * reset (ie. the power well has been disabled at
  1006. * least once).
  1007. */
  1008. if (!dev_priv->chv_phy_assert[phy])
  1009. return;
  1010. if (ch == DPIO_CH0)
  1011. reg = _CHV_CMN_DW0_CH0;
  1012. else
  1013. reg = _CHV_CMN_DW6_CH1;
  1014. mutex_lock(&dev_priv->sb_lock);
  1015. val = vlv_dpio_read(dev_priv, pipe, reg);
  1016. mutex_unlock(&dev_priv->sb_lock);
  1017. /*
  1018. * This assumes !override is only used when the port is disabled.
  1019. * All lanes should power down even without the override when
  1020. * the port is disabled.
  1021. */
  1022. if (!override || mask == 0xf) {
  1023. expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
  1024. /*
  1025. * If CH1 common lane is not active anymore
  1026. * (eg. for pipe B DPLL) the entire channel will
  1027. * shut down, which causes the common lane registers
  1028. * to read as 0. That means we can't actually check
  1029. * the lane power down status bits, but as the entire
  1030. * register reads as 0 it's a good indication that the
  1031. * channel is indeed entirely powered down.
  1032. */
  1033. if (ch == DPIO_CH1 && val == 0)
  1034. expected = 0;
  1035. } else if (mask != 0x0) {
  1036. expected = DPIO_ANYDL_POWERDOWN;
  1037. } else {
  1038. expected = 0;
  1039. }
  1040. if (ch == DPIO_CH0)
  1041. actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
  1042. else
  1043. actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
  1044. actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
  1045. WARN(actual != expected,
  1046. "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
  1047. !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
  1048. !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
  1049. reg, val);
  1050. }
  1051. bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
  1052. enum dpio_channel ch, bool override)
  1053. {
  1054. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1055. bool was_override;
  1056. mutex_lock(&power_domains->lock);
  1057. was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1058. if (override == was_override)
  1059. goto out;
  1060. if (override)
  1061. dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1062. else
  1063. dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1064. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  1065. DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
  1066. phy, ch, dev_priv->chv_phy_control);
  1067. assert_chv_phy_status(dev_priv);
  1068. out:
  1069. mutex_unlock(&power_domains->lock);
  1070. return was_override;
  1071. }
  1072. void chv_phy_powergate_lanes(struct intel_encoder *encoder,
  1073. bool override, unsigned int mask)
  1074. {
  1075. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1076. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1077. enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
  1078. enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
  1079. mutex_lock(&power_domains->lock);
  1080. dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
  1081. dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
  1082. if (override)
  1083. dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1084. else
  1085. dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1086. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  1087. DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
  1088. phy, ch, mask, dev_priv->chv_phy_control);
  1089. assert_chv_phy_status(dev_priv);
  1090. assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
  1091. mutex_unlock(&power_domains->lock);
  1092. }
  1093. static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
  1094. struct i915_power_well *power_well)
  1095. {
  1096. enum pipe pipe = power_well->data;
  1097. bool enabled;
  1098. u32 state, ctrl;
  1099. mutex_lock(&dev_priv->rps.hw_lock);
  1100. state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
  1101. /*
  1102. * We only ever set the power-on and power-gate states, anything
  1103. * else is unexpected.
  1104. */
  1105. WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
  1106. enabled = state == DP_SSS_PWR_ON(pipe);
  1107. /*
  1108. * A transient state at this point would mean some unexpected party
  1109. * is poking at the power controls too.
  1110. */
  1111. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
  1112. WARN_ON(ctrl << 16 != state);
  1113. mutex_unlock(&dev_priv->rps.hw_lock);
  1114. return enabled;
  1115. }
  1116. static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
  1117. struct i915_power_well *power_well,
  1118. bool enable)
  1119. {
  1120. enum pipe pipe = power_well->data;
  1121. u32 state;
  1122. u32 ctrl;
  1123. state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
  1124. mutex_lock(&dev_priv->rps.hw_lock);
  1125. #define COND \
  1126. ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
  1127. if (COND)
  1128. goto out;
  1129. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  1130. ctrl &= ~DP_SSC_MASK(pipe);
  1131. ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
  1132. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
  1133. if (wait_for(COND, 100))
  1134. DRM_ERROR("timeout setting power well state %08x (%08x)\n",
  1135. state,
  1136. vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
  1137. #undef COND
  1138. out:
  1139. mutex_unlock(&dev_priv->rps.hw_lock);
  1140. }
  1141. static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv,
  1142. struct i915_power_well *power_well)
  1143. {
  1144. WARN_ON_ONCE(power_well->data != PIPE_A);
  1145. chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0);
  1146. }
  1147. static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
  1148. struct i915_power_well *power_well)
  1149. {
  1150. WARN_ON_ONCE(power_well->data != PIPE_A);
  1151. chv_set_pipe_power_well(dev_priv, power_well, true);
  1152. vlv_display_power_well_init(dev_priv);
  1153. }
  1154. static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
  1155. struct i915_power_well *power_well)
  1156. {
  1157. WARN_ON_ONCE(power_well->data != PIPE_A);
  1158. vlv_display_power_well_deinit(dev_priv);
  1159. chv_set_pipe_power_well(dev_priv, power_well, false);
  1160. }
  1161. /**
  1162. * intel_display_power_get - grab a power domain reference
  1163. * @dev_priv: i915 device instance
  1164. * @domain: power domain to reference
  1165. *
  1166. * This function grabs a power domain reference for @domain and ensures that the
  1167. * power domain and all its parents are powered up. Therefore users should only
  1168. * grab a reference to the innermost power domain they need.
  1169. *
  1170. * Any power domain reference obtained by this function must have a symmetric
  1171. * call to intel_display_power_put() to release the reference again.
  1172. */
  1173. void intel_display_power_get(struct drm_i915_private *dev_priv,
  1174. enum intel_display_power_domain domain)
  1175. {
  1176. struct i915_power_domains *power_domains;
  1177. struct i915_power_well *power_well;
  1178. int i;
  1179. intel_runtime_pm_get(dev_priv);
  1180. power_domains = &dev_priv->power_domains;
  1181. mutex_lock(&power_domains->lock);
  1182. for_each_power_well(i, power_well, BIT(domain), power_domains) {
  1183. if (!power_well->count++)
  1184. intel_power_well_enable(dev_priv, power_well);
  1185. }
  1186. power_domains->domain_use_count[domain]++;
  1187. mutex_unlock(&power_domains->lock);
  1188. }
  1189. /**
  1190. * intel_display_power_put - release a power domain reference
  1191. * @dev_priv: i915 device instance
  1192. * @domain: power domain to reference
  1193. *
  1194. * This function drops the power domain reference obtained by
  1195. * intel_display_power_get() and might power down the corresponding hardware
  1196. * block right away if this is the last reference.
  1197. */
  1198. void intel_display_power_put(struct drm_i915_private *dev_priv,
  1199. enum intel_display_power_domain domain)
  1200. {
  1201. struct i915_power_domains *power_domains;
  1202. struct i915_power_well *power_well;
  1203. int i;
  1204. power_domains = &dev_priv->power_domains;
  1205. mutex_lock(&power_domains->lock);
  1206. WARN_ON(!power_domains->domain_use_count[domain]);
  1207. power_domains->domain_use_count[domain]--;
  1208. for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
  1209. WARN_ON(!power_well->count);
  1210. if (!--power_well->count && i915.disable_power_well)
  1211. intel_power_well_disable(dev_priv, power_well);
  1212. }
  1213. mutex_unlock(&power_domains->lock);
  1214. intel_runtime_pm_put(dev_priv);
  1215. }
  1216. #define HSW_ALWAYS_ON_POWER_DOMAINS ( \
  1217. BIT(POWER_DOMAIN_PIPE_A) | \
  1218. BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
  1219. BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
  1220. BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
  1221. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  1222. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  1223. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  1224. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  1225. BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
  1226. BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
  1227. BIT(POWER_DOMAIN_PORT_CRT) | \
  1228. BIT(POWER_DOMAIN_PLLS) | \
  1229. BIT(POWER_DOMAIN_AUX_A) | \
  1230. BIT(POWER_DOMAIN_AUX_B) | \
  1231. BIT(POWER_DOMAIN_AUX_C) | \
  1232. BIT(POWER_DOMAIN_AUX_D) | \
  1233. BIT(POWER_DOMAIN_GMBUS) | \
  1234. BIT(POWER_DOMAIN_INIT))
  1235. #define HSW_DISPLAY_POWER_DOMAINS ( \
  1236. (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \
  1237. BIT(POWER_DOMAIN_INIT))
  1238. #define BDW_ALWAYS_ON_POWER_DOMAINS ( \
  1239. HSW_ALWAYS_ON_POWER_DOMAINS | \
  1240. BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER))
  1241. #define BDW_DISPLAY_POWER_DOMAINS ( \
  1242. (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \
  1243. BIT(POWER_DOMAIN_INIT))
  1244. #define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT)
  1245. #define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK
  1246. #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
  1247. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  1248. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  1249. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  1250. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  1251. BIT(POWER_DOMAIN_PORT_CRT) | \
  1252. BIT(POWER_DOMAIN_AUX_B) | \
  1253. BIT(POWER_DOMAIN_AUX_C) | \
  1254. BIT(POWER_DOMAIN_INIT))
  1255. #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
  1256. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  1257. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  1258. BIT(POWER_DOMAIN_AUX_B) | \
  1259. BIT(POWER_DOMAIN_INIT))
  1260. #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
  1261. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  1262. BIT(POWER_DOMAIN_AUX_B) | \
  1263. BIT(POWER_DOMAIN_INIT))
  1264. #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
  1265. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  1266. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  1267. BIT(POWER_DOMAIN_AUX_C) | \
  1268. BIT(POWER_DOMAIN_INIT))
  1269. #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
  1270. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  1271. BIT(POWER_DOMAIN_AUX_C) | \
  1272. BIT(POWER_DOMAIN_INIT))
  1273. #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
  1274. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  1275. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  1276. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  1277. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  1278. BIT(POWER_DOMAIN_AUX_B) | \
  1279. BIT(POWER_DOMAIN_AUX_C) | \
  1280. BIT(POWER_DOMAIN_INIT))
  1281. #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
  1282. BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
  1283. BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
  1284. BIT(POWER_DOMAIN_AUX_D) | \
  1285. BIT(POWER_DOMAIN_INIT))
  1286. static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
  1287. .sync_hw = i9xx_always_on_power_well_noop,
  1288. .enable = i9xx_always_on_power_well_noop,
  1289. .disable = i9xx_always_on_power_well_noop,
  1290. .is_enabled = i9xx_always_on_power_well_enabled,
  1291. };
  1292. static const struct i915_power_well_ops chv_pipe_power_well_ops = {
  1293. .sync_hw = chv_pipe_power_well_sync_hw,
  1294. .enable = chv_pipe_power_well_enable,
  1295. .disable = chv_pipe_power_well_disable,
  1296. .is_enabled = chv_pipe_power_well_enabled,
  1297. };
  1298. static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
  1299. .sync_hw = vlv_power_well_sync_hw,
  1300. .enable = chv_dpio_cmn_power_well_enable,
  1301. .disable = chv_dpio_cmn_power_well_disable,
  1302. .is_enabled = vlv_power_well_enabled,
  1303. };
  1304. static struct i915_power_well i9xx_always_on_power_well[] = {
  1305. {
  1306. .name = "always-on",
  1307. .always_on = 1,
  1308. .domains = POWER_DOMAIN_MASK,
  1309. .ops = &i9xx_always_on_power_well_ops,
  1310. },
  1311. };
  1312. static const struct i915_power_well_ops hsw_power_well_ops = {
  1313. .sync_hw = hsw_power_well_sync_hw,
  1314. .enable = hsw_power_well_enable,
  1315. .disable = hsw_power_well_disable,
  1316. .is_enabled = hsw_power_well_enabled,
  1317. };
  1318. static const struct i915_power_well_ops skl_power_well_ops = {
  1319. .sync_hw = skl_power_well_sync_hw,
  1320. .enable = skl_power_well_enable,
  1321. .disable = skl_power_well_disable,
  1322. .is_enabled = skl_power_well_enabled,
  1323. };
  1324. static struct i915_power_well hsw_power_wells[] = {
  1325. {
  1326. .name = "always-on",
  1327. .always_on = 1,
  1328. .domains = HSW_ALWAYS_ON_POWER_DOMAINS,
  1329. .ops = &i9xx_always_on_power_well_ops,
  1330. },
  1331. {
  1332. .name = "display",
  1333. .domains = HSW_DISPLAY_POWER_DOMAINS,
  1334. .ops = &hsw_power_well_ops,
  1335. },
  1336. };
  1337. static struct i915_power_well bdw_power_wells[] = {
  1338. {
  1339. .name = "always-on",
  1340. .always_on = 1,
  1341. .domains = BDW_ALWAYS_ON_POWER_DOMAINS,
  1342. .ops = &i9xx_always_on_power_well_ops,
  1343. },
  1344. {
  1345. .name = "display",
  1346. .domains = BDW_DISPLAY_POWER_DOMAINS,
  1347. .ops = &hsw_power_well_ops,
  1348. },
  1349. };
  1350. static const struct i915_power_well_ops vlv_display_power_well_ops = {
  1351. .sync_hw = vlv_power_well_sync_hw,
  1352. .enable = vlv_display_power_well_enable,
  1353. .disable = vlv_display_power_well_disable,
  1354. .is_enabled = vlv_power_well_enabled,
  1355. };
  1356. static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
  1357. .sync_hw = vlv_power_well_sync_hw,
  1358. .enable = vlv_dpio_cmn_power_well_enable,
  1359. .disable = vlv_dpio_cmn_power_well_disable,
  1360. .is_enabled = vlv_power_well_enabled,
  1361. };
  1362. static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
  1363. .sync_hw = vlv_power_well_sync_hw,
  1364. .enable = vlv_power_well_enable,
  1365. .disable = vlv_power_well_disable,
  1366. .is_enabled = vlv_power_well_enabled,
  1367. };
  1368. static struct i915_power_well vlv_power_wells[] = {
  1369. {
  1370. .name = "always-on",
  1371. .always_on = 1,
  1372. .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
  1373. .ops = &i9xx_always_on_power_well_ops,
  1374. },
  1375. {
  1376. .name = "display",
  1377. .domains = VLV_DISPLAY_POWER_DOMAINS,
  1378. .data = PUNIT_POWER_WELL_DISP2D,
  1379. .ops = &vlv_display_power_well_ops,
  1380. },
  1381. {
  1382. .name = "dpio-tx-b-01",
  1383. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1384. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1385. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1386. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1387. .ops = &vlv_dpio_power_well_ops,
  1388. .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
  1389. },
  1390. {
  1391. .name = "dpio-tx-b-23",
  1392. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1393. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1394. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1395. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1396. .ops = &vlv_dpio_power_well_ops,
  1397. .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
  1398. },
  1399. {
  1400. .name = "dpio-tx-c-01",
  1401. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1402. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1403. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1404. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1405. .ops = &vlv_dpio_power_well_ops,
  1406. .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
  1407. },
  1408. {
  1409. .name = "dpio-tx-c-23",
  1410. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1411. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1412. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1413. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1414. .ops = &vlv_dpio_power_well_ops,
  1415. .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
  1416. },
  1417. {
  1418. .name = "dpio-common",
  1419. .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
  1420. .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
  1421. .ops = &vlv_dpio_cmn_power_well_ops,
  1422. },
  1423. };
  1424. static struct i915_power_well chv_power_wells[] = {
  1425. {
  1426. .name = "always-on",
  1427. .always_on = 1,
  1428. .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
  1429. .ops = &i9xx_always_on_power_well_ops,
  1430. },
  1431. {
  1432. .name = "display",
  1433. /*
  1434. * Pipe A power well is the new disp2d well. Pipe B and C
  1435. * power wells don't actually exist. Pipe A power well is
  1436. * required for any pipe to work.
  1437. */
  1438. .domains = VLV_DISPLAY_POWER_DOMAINS,
  1439. .data = PIPE_A,
  1440. .ops = &chv_pipe_power_well_ops,
  1441. },
  1442. {
  1443. .name = "dpio-common-bc",
  1444. .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
  1445. .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
  1446. .ops = &chv_dpio_cmn_power_well_ops,
  1447. },
  1448. {
  1449. .name = "dpio-common-d",
  1450. .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
  1451. .data = PUNIT_POWER_WELL_DPIO_CMN_D,
  1452. .ops = &chv_dpio_cmn_power_well_ops,
  1453. },
  1454. };
  1455. bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
  1456. int power_well_id)
  1457. {
  1458. struct i915_power_well *power_well;
  1459. bool ret;
  1460. power_well = lookup_power_well(dev_priv, power_well_id);
  1461. ret = power_well->ops->is_enabled(dev_priv, power_well);
  1462. return ret;
  1463. }
  1464. static struct i915_power_well skl_power_wells[] = {
  1465. {
  1466. .name = "always-on",
  1467. .always_on = 1,
  1468. .domains = SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
  1469. .ops = &i9xx_always_on_power_well_ops,
  1470. },
  1471. {
  1472. .name = "power well 1",
  1473. .domains = SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS,
  1474. .ops = &skl_power_well_ops,
  1475. .data = SKL_DISP_PW_1,
  1476. },
  1477. {
  1478. .name = "MISC IO power well",
  1479. .domains = SKL_DISPLAY_MISC_IO_POWER_DOMAINS,
  1480. .ops = &skl_power_well_ops,
  1481. .data = SKL_DISP_PW_MISC_IO,
  1482. },
  1483. {
  1484. .name = "power well 2",
  1485. .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
  1486. .ops = &skl_power_well_ops,
  1487. .data = SKL_DISP_PW_2,
  1488. },
  1489. {
  1490. .name = "DDI A/E power well",
  1491. .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
  1492. .ops = &skl_power_well_ops,
  1493. .data = SKL_DISP_PW_DDI_A_E,
  1494. },
  1495. {
  1496. .name = "DDI B power well",
  1497. .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
  1498. .ops = &skl_power_well_ops,
  1499. .data = SKL_DISP_PW_DDI_B,
  1500. },
  1501. {
  1502. .name = "DDI C power well",
  1503. .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
  1504. .ops = &skl_power_well_ops,
  1505. .data = SKL_DISP_PW_DDI_C,
  1506. },
  1507. {
  1508. .name = "DDI D power well",
  1509. .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
  1510. .ops = &skl_power_well_ops,
  1511. .data = SKL_DISP_PW_DDI_D,
  1512. },
  1513. };
  1514. static struct i915_power_well bxt_power_wells[] = {
  1515. {
  1516. .name = "always-on",
  1517. .always_on = 1,
  1518. .domains = BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
  1519. .ops = &i9xx_always_on_power_well_ops,
  1520. },
  1521. {
  1522. .name = "power well 1",
  1523. .domains = BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS,
  1524. .ops = &skl_power_well_ops,
  1525. .data = SKL_DISP_PW_1,
  1526. },
  1527. {
  1528. .name = "power well 2",
  1529. .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
  1530. .ops = &skl_power_well_ops,
  1531. .data = SKL_DISP_PW_2,
  1532. }
  1533. };
  1534. static int
  1535. sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
  1536. int disable_power_well)
  1537. {
  1538. if (disable_power_well >= 0)
  1539. return !!disable_power_well;
  1540. if (IS_SKYLAKE(dev_priv)) {
  1541. DRM_DEBUG_KMS("Disabling display power well support\n");
  1542. return 0;
  1543. }
  1544. return 1;
  1545. }
  1546. #define set_power_wells(power_domains, __power_wells) ({ \
  1547. (power_domains)->power_wells = (__power_wells); \
  1548. (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
  1549. })
  1550. /**
  1551. * intel_power_domains_init - initializes the power domain structures
  1552. * @dev_priv: i915 device instance
  1553. *
  1554. * Initializes the power domain structures for @dev_priv depending upon the
  1555. * supported platform.
  1556. */
  1557. int intel_power_domains_init(struct drm_i915_private *dev_priv)
  1558. {
  1559. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1560. i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
  1561. i915.disable_power_well);
  1562. BUILD_BUG_ON(POWER_DOMAIN_NUM > 31);
  1563. mutex_init(&power_domains->lock);
  1564. /*
  1565. * The enabling order will be from lower to higher indexed wells,
  1566. * the disabling order is reversed.
  1567. */
  1568. if (IS_HASWELL(dev_priv->dev)) {
  1569. set_power_wells(power_domains, hsw_power_wells);
  1570. } else if (IS_BROADWELL(dev_priv->dev)) {
  1571. set_power_wells(power_domains, bdw_power_wells);
  1572. } else if (IS_SKYLAKE(dev_priv->dev)) {
  1573. set_power_wells(power_domains, skl_power_wells);
  1574. } else if (IS_BROXTON(dev_priv->dev)) {
  1575. set_power_wells(power_domains, bxt_power_wells);
  1576. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1577. set_power_wells(power_domains, chv_power_wells);
  1578. } else if (IS_VALLEYVIEW(dev_priv->dev)) {
  1579. set_power_wells(power_domains, vlv_power_wells);
  1580. } else {
  1581. set_power_wells(power_domains, i9xx_always_on_power_well);
  1582. }
  1583. return 0;
  1584. }
  1585. static void intel_runtime_pm_disable(struct drm_i915_private *dev_priv)
  1586. {
  1587. struct drm_device *dev = dev_priv->dev;
  1588. struct device *device = &dev->pdev->dev;
  1589. if (!HAS_RUNTIME_PM(dev))
  1590. return;
  1591. if (!intel_enable_rc6(dev))
  1592. return;
  1593. /* Make sure we're not suspended first. */
  1594. pm_runtime_get_sync(device);
  1595. }
  1596. /**
  1597. * intel_power_domains_fini - finalizes the power domain structures
  1598. * @dev_priv: i915 device instance
  1599. *
  1600. * Finalizes the power domain structures for @dev_priv depending upon the
  1601. * supported platform. This function also disables runtime pm and ensures that
  1602. * the device stays powered up so that the driver can be reloaded.
  1603. */
  1604. void intel_power_domains_fini(struct drm_i915_private *dev_priv)
  1605. {
  1606. intel_runtime_pm_disable(dev_priv);
  1607. /* The i915.ko module is still not prepared to be loaded when
  1608. * the power well is not enabled, so just enable it in case
  1609. * we're going to unload/reload. */
  1610. intel_display_set_init_power(dev_priv, true);
  1611. }
  1612. static void intel_power_domains_resume(struct drm_i915_private *dev_priv)
  1613. {
  1614. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1615. struct i915_power_well *power_well;
  1616. int i;
  1617. mutex_lock(&power_domains->lock);
  1618. for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
  1619. power_well->ops->sync_hw(dev_priv, power_well);
  1620. power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
  1621. power_well);
  1622. }
  1623. mutex_unlock(&power_domains->lock);
  1624. }
  1625. static void chv_phy_control_init(struct drm_i915_private *dev_priv)
  1626. {
  1627. struct i915_power_well *cmn_bc =
  1628. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
  1629. struct i915_power_well *cmn_d =
  1630. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
  1631. /*
  1632. * DISPLAY_PHY_CONTROL can get corrupted if read. As a
  1633. * workaround never ever read DISPLAY_PHY_CONTROL, and
  1634. * instead maintain a shadow copy ourselves. Use the actual
  1635. * power well state and lane status to reconstruct the
  1636. * expected initial value.
  1637. */
  1638. dev_priv->chv_phy_control =
  1639. PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
  1640. PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
  1641. PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
  1642. PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
  1643. PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
  1644. /*
  1645. * If all lanes are disabled we leave the override disabled
  1646. * with all power down bits cleared to match the state we
  1647. * would use after disabling the port. Otherwise enable the
  1648. * override and set the lane powerdown bits accding to the
  1649. * current lane status.
  1650. */
  1651. if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
  1652. uint32_t status = I915_READ(DPLL(PIPE_A));
  1653. unsigned int mask;
  1654. mask = status & DPLL_PORTB_READY_MASK;
  1655. if (mask == 0xf)
  1656. mask = 0x0;
  1657. else
  1658. dev_priv->chv_phy_control |=
  1659. PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
  1660. dev_priv->chv_phy_control |=
  1661. PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
  1662. mask = (status & DPLL_PORTC_READY_MASK) >> 4;
  1663. if (mask == 0xf)
  1664. mask = 0x0;
  1665. else
  1666. dev_priv->chv_phy_control |=
  1667. PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
  1668. dev_priv->chv_phy_control |=
  1669. PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
  1670. dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
  1671. dev_priv->chv_phy_assert[DPIO_PHY0] = false;
  1672. } else {
  1673. dev_priv->chv_phy_assert[DPIO_PHY0] = true;
  1674. }
  1675. if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
  1676. uint32_t status = I915_READ(DPIO_PHY_STATUS);
  1677. unsigned int mask;
  1678. mask = status & DPLL_PORTD_READY_MASK;
  1679. if (mask == 0xf)
  1680. mask = 0x0;
  1681. else
  1682. dev_priv->chv_phy_control |=
  1683. PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
  1684. dev_priv->chv_phy_control |=
  1685. PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
  1686. dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
  1687. dev_priv->chv_phy_assert[DPIO_PHY1] = false;
  1688. } else {
  1689. dev_priv->chv_phy_assert[DPIO_PHY1] = true;
  1690. }
  1691. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  1692. DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
  1693. dev_priv->chv_phy_control);
  1694. }
  1695. static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
  1696. {
  1697. struct i915_power_well *cmn =
  1698. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
  1699. struct i915_power_well *disp2d =
  1700. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
  1701. /* If the display might be already active skip this */
  1702. if (cmn->ops->is_enabled(dev_priv, cmn) &&
  1703. disp2d->ops->is_enabled(dev_priv, disp2d) &&
  1704. I915_READ(DPIO_CTL) & DPIO_CMNRST)
  1705. return;
  1706. DRM_DEBUG_KMS("toggling display PHY side reset\n");
  1707. /* cmnlane needs DPLL registers */
  1708. disp2d->ops->enable(dev_priv, disp2d);
  1709. /*
  1710. * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
  1711. * Need to assert and de-assert PHY SB reset by gating the
  1712. * common lane power, then un-gating it.
  1713. * Simply ungating isn't enough to reset the PHY enough to get
  1714. * ports and lanes running.
  1715. */
  1716. cmn->ops->disable(dev_priv, cmn);
  1717. }
  1718. /**
  1719. * intel_power_domains_init_hw - initialize hardware power domain state
  1720. * @dev_priv: i915 device instance
  1721. *
  1722. * This function initializes the hardware power domain state and enables all
  1723. * power domains using intel_display_set_init_power().
  1724. */
  1725. void intel_power_domains_init_hw(struct drm_i915_private *dev_priv)
  1726. {
  1727. struct drm_device *dev = dev_priv->dev;
  1728. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1729. power_domains->initializing = true;
  1730. if (IS_CHERRYVIEW(dev)) {
  1731. mutex_lock(&power_domains->lock);
  1732. chv_phy_control_init(dev_priv);
  1733. mutex_unlock(&power_domains->lock);
  1734. } else if (IS_VALLEYVIEW(dev)) {
  1735. mutex_lock(&power_domains->lock);
  1736. vlv_cmnlane_wa(dev_priv);
  1737. mutex_unlock(&power_domains->lock);
  1738. }
  1739. /* For now, we need the power well to be always enabled. */
  1740. intel_display_set_init_power(dev_priv, true);
  1741. intel_power_domains_resume(dev_priv);
  1742. power_domains->initializing = false;
  1743. }
  1744. /**
  1745. * intel_runtime_pm_get - grab a runtime pm reference
  1746. * @dev_priv: i915 device instance
  1747. *
  1748. * This function grabs a device-level runtime pm reference (mostly used for GEM
  1749. * code to ensure the GTT or GT is on) and ensures that it is powered up.
  1750. *
  1751. * Any runtime pm reference obtained by this function must have a symmetric
  1752. * call to intel_runtime_pm_put() to release the reference again.
  1753. */
  1754. void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
  1755. {
  1756. struct drm_device *dev = dev_priv->dev;
  1757. struct device *device = &dev->pdev->dev;
  1758. if (!HAS_RUNTIME_PM(dev))
  1759. return;
  1760. pm_runtime_get_sync(device);
  1761. WARN(dev_priv->pm.suspended, "Device still suspended.\n");
  1762. }
  1763. /**
  1764. * intel_runtime_pm_get_noresume - grab a runtime pm reference
  1765. * @dev_priv: i915 device instance
  1766. *
  1767. * This function grabs a device-level runtime pm reference (mostly used for GEM
  1768. * code to ensure the GTT or GT is on).
  1769. *
  1770. * It will _not_ power up the device but instead only check that it's powered
  1771. * on. Therefore it is only valid to call this functions from contexts where
  1772. * the device is known to be powered up and where trying to power it up would
  1773. * result in hilarity and deadlocks. That pretty much means only the system
  1774. * suspend/resume code where this is used to grab runtime pm references for
  1775. * delayed setup down in work items.
  1776. *
  1777. * Any runtime pm reference obtained by this function must have a symmetric
  1778. * call to intel_runtime_pm_put() to release the reference again.
  1779. */
  1780. void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
  1781. {
  1782. struct drm_device *dev = dev_priv->dev;
  1783. struct device *device = &dev->pdev->dev;
  1784. if (!HAS_RUNTIME_PM(dev))
  1785. return;
  1786. WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n");
  1787. pm_runtime_get_noresume(device);
  1788. }
  1789. /**
  1790. * intel_runtime_pm_put - release a runtime pm reference
  1791. * @dev_priv: i915 device instance
  1792. *
  1793. * This function drops the device-level runtime pm reference obtained by
  1794. * intel_runtime_pm_get() and might power down the corresponding
  1795. * hardware block right away if this is the last reference.
  1796. */
  1797. void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
  1798. {
  1799. struct drm_device *dev = dev_priv->dev;
  1800. struct device *device = &dev->pdev->dev;
  1801. if (!HAS_RUNTIME_PM(dev))
  1802. return;
  1803. pm_runtime_mark_last_busy(device);
  1804. pm_runtime_put_autosuspend(device);
  1805. }
  1806. /**
  1807. * intel_runtime_pm_enable - enable runtime pm
  1808. * @dev_priv: i915 device instance
  1809. *
  1810. * This function enables runtime pm at the end of the driver load sequence.
  1811. *
  1812. * Note that this function does currently not enable runtime pm for the
  1813. * subordinate display power domains. That is only done on the first modeset
  1814. * using intel_display_set_init_power().
  1815. */
  1816. void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
  1817. {
  1818. struct drm_device *dev = dev_priv->dev;
  1819. struct device *device = &dev->pdev->dev;
  1820. if (!HAS_RUNTIME_PM(dev))
  1821. return;
  1822. /*
  1823. * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
  1824. * requirement.
  1825. */
  1826. if (!intel_enable_rc6(dev)) {
  1827. DRM_INFO("RC6 disabled, disabling runtime PM support\n");
  1828. return;
  1829. }
  1830. pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */
  1831. pm_runtime_mark_last_busy(device);
  1832. pm_runtime_use_autosuspend(device);
  1833. pm_runtime_put_autosuspend(device);
  1834. }