intel_runtime_pm.c 54 KB

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