intel_runtime_pm.c 68 KB

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