intel_runtime_pm.c 66 KB

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