intel_runtime_pm.c 51 KB

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