intel_runtime_pm.c 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199
  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. bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
  49. enum i915_power_well_id power_well_id);
  50. static struct i915_power_well *
  51. lookup_power_well(struct drm_i915_private *dev_priv,
  52. enum i915_power_well_id power_well_id);
  53. const char *
  54. intel_display_power_domain_str(enum intel_display_power_domain domain)
  55. {
  56. switch (domain) {
  57. case POWER_DOMAIN_PIPE_A:
  58. return "PIPE_A";
  59. case POWER_DOMAIN_PIPE_B:
  60. return "PIPE_B";
  61. case POWER_DOMAIN_PIPE_C:
  62. return "PIPE_C";
  63. case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
  64. return "PIPE_A_PANEL_FITTER";
  65. case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
  66. return "PIPE_B_PANEL_FITTER";
  67. case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
  68. return "PIPE_C_PANEL_FITTER";
  69. case POWER_DOMAIN_TRANSCODER_A:
  70. return "TRANSCODER_A";
  71. case POWER_DOMAIN_TRANSCODER_B:
  72. return "TRANSCODER_B";
  73. case POWER_DOMAIN_TRANSCODER_C:
  74. return "TRANSCODER_C";
  75. case POWER_DOMAIN_TRANSCODER_EDP:
  76. return "TRANSCODER_EDP";
  77. case POWER_DOMAIN_TRANSCODER_DSI_A:
  78. return "TRANSCODER_DSI_A";
  79. case POWER_DOMAIN_TRANSCODER_DSI_C:
  80. return "TRANSCODER_DSI_C";
  81. case POWER_DOMAIN_PORT_DDI_A_LANES:
  82. return "PORT_DDI_A_LANES";
  83. case POWER_DOMAIN_PORT_DDI_B_LANES:
  84. return "PORT_DDI_B_LANES";
  85. case POWER_DOMAIN_PORT_DDI_C_LANES:
  86. return "PORT_DDI_C_LANES";
  87. case POWER_DOMAIN_PORT_DDI_D_LANES:
  88. return "PORT_DDI_D_LANES";
  89. case POWER_DOMAIN_PORT_DDI_E_LANES:
  90. return "PORT_DDI_E_LANES";
  91. case POWER_DOMAIN_PORT_DDI_A_IO:
  92. return "PORT_DDI_A_IO";
  93. case POWER_DOMAIN_PORT_DDI_B_IO:
  94. return "PORT_DDI_B_IO";
  95. case POWER_DOMAIN_PORT_DDI_C_IO:
  96. return "PORT_DDI_C_IO";
  97. case POWER_DOMAIN_PORT_DDI_D_IO:
  98. return "PORT_DDI_D_IO";
  99. case POWER_DOMAIN_PORT_DDI_E_IO:
  100. return "PORT_DDI_E_IO";
  101. case POWER_DOMAIN_PORT_DSI:
  102. return "PORT_DSI";
  103. case POWER_DOMAIN_PORT_CRT:
  104. return "PORT_CRT";
  105. case POWER_DOMAIN_PORT_OTHER:
  106. return "PORT_OTHER";
  107. case POWER_DOMAIN_VGA:
  108. return "VGA";
  109. case POWER_DOMAIN_AUDIO:
  110. return "AUDIO";
  111. case POWER_DOMAIN_PLLS:
  112. return "PLLS";
  113. case POWER_DOMAIN_AUX_A:
  114. return "AUX_A";
  115. case POWER_DOMAIN_AUX_B:
  116. return "AUX_B";
  117. case POWER_DOMAIN_AUX_C:
  118. return "AUX_C";
  119. case POWER_DOMAIN_AUX_D:
  120. return "AUX_D";
  121. case POWER_DOMAIN_GMBUS:
  122. return "GMBUS";
  123. case POWER_DOMAIN_INIT:
  124. return "INIT";
  125. case POWER_DOMAIN_MODESET:
  126. return "MODESET";
  127. default:
  128. MISSING_CASE(domain);
  129. return "?";
  130. }
  131. }
  132. static void intel_power_well_enable(struct drm_i915_private *dev_priv,
  133. struct i915_power_well *power_well)
  134. {
  135. DRM_DEBUG_KMS("enabling %s\n", power_well->name);
  136. power_well->ops->enable(dev_priv, power_well);
  137. power_well->hw_enabled = true;
  138. }
  139. static void intel_power_well_disable(struct drm_i915_private *dev_priv,
  140. struct i915_power_well *power_well)
  141. {
  142. DRM_DEBUG_KMS("disabling %s\n", power_well->name);
  143. power_well->hw_enabled = false;
  144. power_well->ops->disable(dev_priv, power_well);
  145. }
  146. static void intel_power_well_get(struct drm_i915_private *dev_priv,
  147. struct i915_power_well *power_well)
  148. {
  149. if (!power_well->count++)
  150. intel_power_well_enable(dev_priv, power_well);
  151. }
  152. static void intel_power_well_put(struct drm_i915_private *dev_priv,
  153. struct i915_power_well *power_well)
  154. {
  155. WARN(!power_well->count, "Use count on power well %s is already zero",
  156. power_well->name);
  157. if (!--power_well->count)
  158. intel_power_well_disable(dev_priv, power_well);
  159. }
  160. /**
  161. * __intel_display_power_is_enabled - unlocked check for a power domain
  162. * @dev_priv: i915 device instance
  163. * @domain: power domain to check
  164. *
  165. * This is the unlocked version of intel_display_power_is_enabled() and should
  166. * only be used from error capture and recovery code where deadlocks are
  167. * possible.
  168. *
  169. * Returns:
  170. * True when the power domain is enabled, false otherwise.
  171. */
  172. bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
  173. enum intel_display_power_domain domain)
  174. {
  175. struct i915_power_well *power_well;
  176. bool is_enabled;
  177. if (dev_priv->pm.suspended)
  178. return false;
  179. is_enabled = true;
  180. for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain)) {
  181. if (power_well->always_on)
  182. continue;
  183. if (!power_well->hw_enabled) {
  184. is_enabled = false;
  185. break;
  186. }
  187. }
  188. return is_enabled;
  189. }
  190. /**
  191. * intel_display_power_is_enabled - check for a power domain
  192. * @dev_priv: i915 device instance
  193. * @domain: power domain to check
  194. *
  195. * This function can be used to check the hw power domain state. It is mostly
  196. * used in hardware state readout functions. Everywhere else code should rely
  197. * upon explicit power domain reference counting to ensure that the hardware
  198. * block is powered up before accessing it.
  199. *
  200. * Callers must hold the relevant modesetting locks to ensure that concurrent
  201. * threads can't disable the power well while the caller tries to read a few
  202. * registers.
  203. *
  204. * Returns:
  205. * True when the power domain is enabled, false otherwise.
  206. */
  207. bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
  208. enum intel_display_power_domain domain)
  209. {
  210. struct i915_power_domains *power_domains;
  211. bool ret;
  212. power_domains = &dev_priv->power_domains;
  213. mutex_lock(&power_domains->lock);
  214. ret = __intel_display_power_is_enabled(dev_priv, domain);
  215. mutex_unlock(&power_domains->lock);
  216. return ret;
  217. }
  218. /**
  219. * intel_display_set_init_power - set the initial power domain state
  220. * @dev_priv: i915 device instance
  221. * @enable: whether to enable or disable the initial power domain state
  222. *
  223. * For simplicity our driver load/unload and system suspend/resume code assumes
  224. * that all power domains are always enabled. This functions controls the state
  225. * of this little hack. While the initial power domain state is enabled runtime
  226. * pm is effectively disabled.
  227. */
  228. void intel_display_set_init_power(struct drm_i915_private *dev_priv,
  229. bool enable)
  230. {
  231. if (dev_priv->power_domains.init_power_on == enable)
  232. return;
  233. if (enable)
  234. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  235. else
  236. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  237. dev_priv->power_domains.init_power_on = enable;
  238. }
  239. /*
  240. * Starting with Haswell, we have a "Power Down Well" that can be turned off
  241. * when not needed anymore. We have 4 registers that can request the power well
  242. * to be enabled, and it will only be disabled if none of the registers is
  243. * requesting it to be enabled.
  244. */
  245. static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv,
  246. u8 irq_pipe_mask, bool has_vga)
  247. {
  248. struct pci_dev *pdev = dev_priv->drm.pdev;
  249. /*
  250. * After we re-enable the power well, if we touch VGA register 0x3d5
  251. * we'll get unclaimed register interrupts. This stops after we write
  252. * anything to the VGA MSR register. The vgacon module uses this
  253. * register all the time, so if we unbind our driver and, as a
  254. * consequence, bind vgacon, we'll get stuck in an infinite loop at
  255. * console_unlock(). So make here we touch the VGA MSR register, making
  256. * sure vgacon can keep working normally without triggering interrupts
  257. * and error messages.
  258. */
  259. if (has_vga) {
  260. vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
  261. outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
  262. vga_put(pdev, VGA_RSRC_LEGACY_IO);
  263. }
  264. if (irq_pipe_mask)
  265. gen8_irq_power_well_post_enable(dev_priv, irq_pipe_mask);
  266. }
  267. static void hsw_power_well_pre_disable(struct drm_i915_private *dev_priv,
  268. u8 irq_pipe_mask)
  269. {
  270. if (irq_pipe_mask)
  271. gen8_irq_power_well_pre_disable(dev_priv, irq_pipe_mask);
  272. }
  273. static void hsw_wait_for_power_well_enable(struct drm_i915_private *dev_priv,
  274. struct i915_power_well *power_well)
  275. {
  276. enum i915_power_well_id id = power_well->id;
  277. /* Timeout for PW1:10 us, AUX:not specified, other PWs:20 us. */
  278. WARN_ON(intel_wait_for_register(dev_priv,
  279. HSW_PWR_WELL_DRIVER,
  280. HSW_PWR_WELL_CTL_STATE(id),
  281. HSW_PWR_WELL_CTL_STATE(id),
  282. 1));
  283. }
  284. static u32 hsw_power_well_requesters(struct drm_i915_private *dev_priv,
  285. enum i915_power_well_id id)
  286. {
  287. u32 req_mask = HSW_PWR_WELL_CTL_REQ(id);
  288. u32 ret;
  289. ret = I915_READ(HSW_PWR_WELL_BIOS) & req_mask ? 1 : 0;
  290. ret |= I915_READ(HSW_PWR_WELL_DRIVER) & req_mask ? 2 : 0;
  291. ret |= I915_READ(HSW_PWR_WELL_KVMR) & req_mask ? 4 : 0;
  292. ret |= I915_READ(HSW_PWR_WELL_DEBUG) & req_mask ? 8 : 0;
  293. return ret;
  294. }
  295. static void hsw_wait_for_power_well_disable(struct drm_i915_private *dev_priv,
  296. struct i915_power_well *power_well)
  297. {
  298. enum i915_power_well_id id = power_well->id;
  299. bool disabled;
  300. u32 reqs;
  301. /*
  302. * Bspec doesn't require waiting for PWs to get disabled, but still do
  303. * this for paranoia. The known cases where a PW will be forced on:
  304. * - a KVMR request on any power well via the KVMR request register
  305. * - a DMC request on PW1 and MISC_IO power wells via the BIOS and
  306. * DEBUG request registers
  307. * Skip the wait in case any of the request bits are set and print a
  308. * diagnostic message.
  309. */
  310. wait_for((disabled = !(I915_READ(HSW_PWR_WELL_DRIVER) &
  311. HSW_PWR_WELL_CTL_STATE(id))) ||
  312. (reqs = hsw_power_well_requesters(dev_priv, id)), 1);
  313. if (disabled)
  314. return;
  315. DRM_DEBUG_KMS("%s forced on (bios:%d driver:%d kvmr:%d debug:%d)\n",
  316. power_well->name,
  317. !!(reqs & 1), !!(reqs & 2), !!(reqs & 4), !!(reqs & 8));
  318. }
  319. static void gen9_wait_for_power_well_fuses(struct drm_i915_private *dev_priv,
  320. enum skl_power_gate pg)
  321. {
  322. /* Timeout 5us for PG#0, for other PGs 1us */
  323. WARN_ON(intel_wait_for_register(dev_priv, SKL_FUSE_STATUS,
  324. SKL_FUSE_PG_DIST_STATUS(pg),
  325. SKL_FUSE_PG_DIST_STATUS(pg), 1));
  326. }
  327. static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
  328. struct i915_power_well *power_well)
  329. {
  330. enum i915_power_well_id id = power_well->id;
  331. bool wait_fuses = power_well->hsw.has_fuses;
  332. enum skl_power_gate pg;
  333. u32 val;
  334. if (wait_fuses) {
  335. pg = SKL_PW_TO_PG(id);
  336. /*
  337. * For PW1 we have to wait both for the PW0/PG0 fuse state
  338. * before enabling the power well and PW1/PG1's own fuse
  339. * state after the enabling. For all other power wells with
  340. * fuses we only have to wait for that PW/PG's fuse state
  341. * after the enabling.
  342. */
  343. if (pg == SKL_PG1)
  344. gen9_wait_for_power_well_fuses(dev_priv, SKL_PG0);
  345. }
  346. val = I915_READ(HSW_PWR_WELL_DRIVER);
  347. I915_WRITE(HSW_PWR_WELL_DRIVER, val | HSW_PWR_WELL_CTL_REQ(id));
  348. hsw_wait_for_power_well_enable(dev_priv, power_well);
  349. if (wait_fuses)
  350. gen9_wait_for_power_well_fuses(dev_priv, pg);
  351. hsw_power_well_post_enable(dev_priv, power_well->hsw.irq_pipe_mask,
  352. power_well->hsw.has_vga);
  353. }
  354. static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
  355. struct i915_power_well *power_well)
  356. {
  357. enum i915_power_well_id id = power_well->id;
  358. u32 val;
  359. hsw_power_well_pre_disable(dev_priv, power_well->hsw.irq_pipe_mask);
  360. val = I915_READ(HSW_PWR_WELL_DRIVER);
  361. I915_WRITE(HSW_PWR_WELL_DRIVER, val & ~HSW_PWR_WELL_CTL_REQ(id));
  362. hsw_wait_for_power_well_disable(dev_priv, power_well);
  363. }
  364. /*
  365. * We should only use the power well if we explicitly asked the hardware to
  366. * enable it, so check if it's enabled and also check if we've requested it to
  367. * be enabled.
  368. */
  369. static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
  370. struct i915_power_well *power_well)
  371. {
  372. enum i915_power_well_id id = power_well->id;
  373. u32 mask = HSW_PWR_WELL_CTL_REQ(id) | HSW_PWR_WELL_CTL_STATE(id);
  374. return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
  375. }
  376. static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
  377. {
  378. WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
  379. "DC9 already programmed to be enabled.\n");
  380. WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
  381. "DC5 still not disabled to enable DC9.\n");
  382. WARN_ONCE(I915_READ(HSW_PWR_WELL_DRIVER) &
  383. HSW_PWR_WELL_CTL_REQ(SKL_DISP_PW_2),
  384. "Power well 2 on.\n");
  385. WARN_ONCE(intel_irqs_enabled(dev_priv),
  386. "Interrupts not disabled yet.\n");
  387. /*
  388. * TODO: check for the following to verify the conditions to enter DC9
  389. * state are satisfied:
  390. * 1] Check relevant display engine registers to verify if mode set
  391. * disable sequence was followed.
  392. * 2] Check if display uninitialize sequence is initialized.
  393. */
  394. }
  395. static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
  396. {
  397. WARN_ONCE(intel_irqs_enabled(dev_priv),
  398. "Interrupts not disabled yet.\n");
  399. WARN_ONCE(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
  400. "DC5 still not disabled.\n");
  401. /*
  402. * TODO: check for the following to verify DC9 state was indeed
  403. * entered before programming to disable it:
  404. * 1] Check relevant display engine registers to verify if mode
  405. * set disable sequence was followed.
  406. * 2] Check if display uninitialize sequence is initialized.
  407. */
  408. }
  409. static void gen9_write_dc_state(struct drm_i915_private *dev_priv,
  410. u32 state)
  411. {
  412. int rewrites = 0;
  413. int rereads = 0;
  414. u32 v;
  415. I915_WRITE(DC_STATE_EN, state);
  416. /* It has been observed that disabling the dc6 state sometimes
  417. * doesn't stick and dmc keeps returning old value. Make sure
  418. * the write really sticks enough times and also force rewrite until
  419. * we are confident that state is exactly what we want.
  420. */
  421. do {
  422. v = I915_READ(DC_STATE_EN);
  423. if (v != state) {
  424. I915_WRITE(DC_STATE_EN, state);
  425. rewrites++;
  426. rereads = 0;
  427. } else if (rereads++ > 5) {
  428. break;
  429. }
  430. } while (rewrites < 100);
  431. if (v != state)
  432. DRM_ERROR("Writing dc state to 0x%x failed, now 0x%x\n",
  433. state, v);
  434. /* Most of the times we need one retry, avoid spam */
  435. if (rewrites > 1)
  436. DRM_DEBUG_KMS("Rewrote dc state to 0x%x %d times\n",
  437. state, rewrites);
  438. }
  439. static u32 gen9_dc_mask(struct drm_i915_private *dev_priv)
  440. {
  441. u32 mask;
  442. mask = DC_STATE_EN_UPTO_DC5;
  443. if (IS_GEN9_LP(dev_priv))
  444. mask |= DC_STATE_EN_DC9;
  445. else
  446. mask |= DC_STATE_EN_UPTO_DC6;
  447. return mask;
  448. }
  449. void gen9_sanitize_dc_state(struct drm_i915_private *dev_priv)
  450. {
  451. u32 val;
  452. val = I915_READ(DC_STATE_EN) & gen9_dc_mask(dev_priv);
  453. DRM_DEBUG_KMS("Resetting DC state tracking from %02x to %02x\n",
  454. dev_priv->csr.dc_state, val);
  455. dev_priv->csr.dc_state = val;
  456. }
  457. static void gen9_set_dc_state(struct drm_i915_private *dev_priv, uint32_t state)
  458. {
  459. uint32_t val;
  460. uint32_t mask;
  461. if (WARN_ON_ONCE(state & ~dev_priv->csr.allowed_dc_mask))
  462. state &= dev_priv->csr.allowed_dc_mask;
  463. val = I915_READ(DC_STATE_EN);
  464. mask = gen9_dc_mask(dev_priv);
  465. DRM_DEBUG_KMS("Setting DC state from %02x to %02x\n",
  466. val & mask, state);
  467. /* Check if DMC is ignoring our DC state requests */
  468. if ((val & mask) != dev_priv->csr.dc_state)
  469. DRM_ERROR("DC state mismatch (0x%x -> 0x%x)\n",
  470. dev_priv->csr.dc_state, val & mask);
  471. val &= ~mask;
  472. val |= state;
  473. gen9_write_dc_state(dev_priv, val);
  474. dev_priv->csr.dc_state = val & mask;
  475. }
  476. void bxt_enable_dc9(struct drm_i915_private *dev_priv)
  477. {
  478. assert_can_enable_dc9(dev_priv);
  479. DRM_DEBUG_KMS("Enabling DC9\n");
  480. intel_power_sequencer_reset(dev_priv);
  481. gen9_set_dc_state(dev_priv, DC_STATE_EN_DC9);
  482. }
  483. void bxt_disable_dc9(struct drm_i915_private *dev_priv)
  484. {
  485. assert_can_disable_dc9(dev_priv);
  486. DRM_DEBUG_KMS("Disabling DC9\n");
  487. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  488. intel_pps_unlock_regs_wa(dev_priv);
  489. }
  490. static void assert_csr_loaded(struct drm_i915_private *dev_priv)
  491. {
  492. WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
  493. "CSR program storage start is NULL\n");
  494. WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
  495. WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
  496. }
  497. static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
  498. {
  499. bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
  500. SKL_DISP_PW_2);
  501. WARN_ONCE(pg2_enabled, "PG2 not disabled to enable DC5.\n");
  502. WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
  503. "DC5 already programmed to be enabled.\n");
  504. assert_rpm_wakelock_held(dev_priv);
  505. assert_csr_loaded(dev_priv);
  506. }
  507. void gen9_enable_dc5(struct drm_i915_private *dev_priv)
  508. {
  509. assert_can_enable_dc5(dev_priv);
  510. DRM_DEBUG_KMS("Enabling DC5\n");
  511. gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC5);
  512. }
  513. static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
  514. {
  515. WARN_ONCE(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  516. "Backlight is not disabled.\n");
  517. WARN_ONCE((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
  518. "DC6 already programmed to be enabled.\n");
  519. assert_csr_loaded(dev_priv);
  520. }
  521. void skl_enable_dc6(struct drm_i915_private *dev_priv)
  522. {
  523. assert_can_enable_dc6(dev_priv);
  524. DRM_DEBUG_KMS("Enabling DC6\n");
  525. gen9_set_dc_state(dev_priv, DC_STATE_EN_UPTO_DC6);
  526. }
  527. void skl_disable_dc6(struct drm_i915_private *dev_priv)
  528. {
  529. DRM_DEBUG_KMS("Disabling DC6\n");
  530. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  531. }
  532. static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
  533. struct i915_power_well *power_well)
  534. {
  535. enum i915_power_well_id id = power_well->id;
  536. u32 mask = HSW_PWR_WELL_CTL_REQ(id);
  537. u32 bios_req = I915_READ(HSW_PWR_WELL_BIOS);
  538. /* Take over the request bit if set by BIOS. */
  539. if (bios_req & mask) {
  540. u32 drv_req = I915_READ(HSW_PWR_WELL_DRIVER);
  541. if (!(drv_req & mask))
  542. I915_WRITE(HSW_PWR_WELL_DRIVER, drv_req | mask);
  543. I915_WRITE(HSW_PWR_WELL_BIOS, bios_req & ~mask);
  544. }
  545. }
  546. static void bxt_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
  547. struct i915_power_well *power_well)
  548. {
  549. bxt_ddi_phy_init(dev_priv, power_well->bxt.phy);
  550. }
  551. static void bxt_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
  552. struct i915_power_well *power_well)
  553. {
  554. bxt_ddi_phy_uninit(dev_priv, power_well->bxt.phy);
  555. }
  556. static bool bxt_dpio_cmn_power_well_enabled(struct drm_i915_private *dev_priv,
  557. struct i915_power_well *power_well)
  558. {
  559. return bxt_ddi_phy_is_enabled(dev_priv, power_well->bxt.phy);
  560. }
  561. static void bxt_verify_ddi_phy_power_wells(struct drm_i915_private *dev_priv)
  562. {
  563. struct i915_power_well *power_well;
  564. power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_A);
  565. if (power_well->count > 0)
  566. bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
  567. power_well = lookup_power_well(dev_priv, BXT_DPIO_CMN_BC);
  568. if (power_well->count > 0)
  569. bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
  570. if (IS_GEMINILAKE(dev_priv)) {
  571. power_well = lookup_power_well(dev_priv, GLK_DPIO_CMN_C);
  572. if (power_well->count > 0)
  573. bxt_ddi_phy_verify_state(dev_priv, power_well->bxt.phy);
  574. }
  575. }
  576. static bool gen9_dc_off_power_well_enabled(struct drm_i915_private *dev_priv,
  577. struct i915_power_well *power_well)
  578. {
  579. return (I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5_DC6_MASK) == 0;
  580. }
  581. static void gen9_assert_dbuf_enabled(struct drm_i915_private *dev_priv)
  582. {
  583. u32 tmp = I915_READ(DBUF_CTL);
  584. WARN((tmp & (DBUF_POWER_STATE | DBUF_POWER_REQUEST)) !=
  585. (DBUF_POWER_STATE | DBUF_POWER_REQUEST),
  586. "Unexpected DBuf power power state (0x%08x)\n", tmp);
  587. }
  588. static void gen9_dc_off_power_well_enable(struct drm_i915_private *dev_priv,
  589. struct i915_power_well *power_well)
  590. {
  591. struct intel_cdclk_state cdclk_state = {};
  592. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  593. dev_priv->display.get_cdclk(dev_priv, &cdclk_state);
  594. WARN_ON(!intel_cdclk_state_compare(&dev_priv->cdclk.hw, &cdclk_state));
  595. gen9_assert_dbuf_enabled(dev_priv);
  596. if (IS_GEN9_LP(dev_priv))
  597. bxt_verify_ddi_phy_power_wells(dev_priv);
  598. }
  599. static void gen9_dc_off_power_well_disable(struct drm_i915_private *dev_priv,
  600. struct i915_power_well *power_well)
  601. {
  602. if (!dev_priv->csr.dmc_payload)
  603. return;
  604. if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC6)
  605. skl_enable_dc6(dev_priv);
  606. else if (dev_priv->csr.allowed_dc_mask & DC_STATE_EN_UPTO_DC5)
  607. gen9_enable_dc5(dev_priv);
  608. }
  609. static void i9xx_power_well_sync_hw_noop(struct drm_i915_private *dev_priv,
  610. struct i915_power_well *power_well)
  611. {
  612. }
  613. static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
  614. struct i915_power_well *power_well)
  615. {
  616. }
  617. static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
  618. struct i915_power_well *power_well)
  619. {
  620. return true;
  621. }
  622. static void i830_pipes_power_well_enable(struct drm_i915_private *dev_priv,
  623. struct i915_power_well *power_well)
  624. {
  625. if ((I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE) == 0)
  626. i830_enable_pipe(dev_priv, PIPE_A);
  627. if ((I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE) == 0)
  628. i830_enable_pipe(dev_priv, PIPE_B);
  629. }
  630. static void i830_pipes_power_well_disable(struct drm_i915_private *dev_priv,
  631. struct i915_power_well *power_well)
  632. {
  633. i830_disable_pipe(dev_priv, PIPE_B);
  634. i830_disable_pipe(dev_priv, PIPE_A);
  635. }
  636. static bool i830_pipes_power_well_enabled(struct drm_i915_private *dev_priv,
  637. struct i915_power_well *power_well)
  638. {
  639. return I915_READ(PIPECONF(PIPE_A)) & PIPECONF_ENABLE &&
  640. I915_READ(PIPECONF(PIPE_B)) & PIPECONF_ENABLE;
  641. }
  642. static void i830_pipes_power_well_sync_hw(struct drm_i915_private *dev_priv,
  643. struct i915_power_well *power_well)
  644. {
  645. if (power_well->count > 0)
  646. i830_pipes_power_well_enable(dev_priv, power_well);
  647. else
  648. i830_pipes_power_well_disable(dev_priv, power_well);
  649. }
  650. static void vlv_set_power_well(struct drm_i915_private *dev_priv,
  651. struct i915_power_well *power_well, bool enable)
  652. {
  653. enum i915_power_well_id power_well_id = power_well->id;
  654. u32 mask;
  655. u32 state;
  656. u32 ctrl;
  657. mask = PUNIT_PWRGT_MASK(power_well_id);
  658. state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
  659. PUNIT_PWRGT_PWR_GATE(power_well_id);
  660. mutex_lock(&dev_priv->rps.hw_lock);
  661. #define COND \
  662. ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
  663. if (COND)
  664. goto out;
  665. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
  666. ctrl &= ~mask;
  667. ctrl |= state;
  668. vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
  669. if (wait_for(COND, 100))
  670. DRM_ERROR("timeout setting power well state %08x (%08x)\n",
  671. state,
  672. vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
  673. #undef COND
  674. out:
  675. mutex_unlock(&dev_priv->rps.hw_lock);
  676. }
  677. static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
  678. struct i915_power_well *power_well)
  679. {
  680. vlv_set_power_well(dev_priv, power_well, true);
  681. }
  682. static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
  683. struct i915_power_well *power_well)
  684. {
  685. vlv_set_power_well(dev_priv, power_well, false);
  686. }
  687. static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
  688. struct i915_power_well *power_well)
  689. {
  690. enum i915_power_well_id power_well_id = power_well->id;
  691. bool enabled = false;
  692. u32 mask;
  693. u32 state;
  694. u32 ctrl;
  695. mask = PUNIT_PWRGT_MASK(power_well_id);
  696. ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
  697. mutex_lock(&dev_priv->rps.hw_lock);
  698. state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
  699. /*
  700. * We only ever set the power-on and power-gate states, anything
  701. * else is unexpected.
  702. */
  703. WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
  704. state != PUNIT_PWRGT_PWR_GATE(power_well_id));
  705. if (state == ctrl)
  706. enabled = true;
  707. /*
  708. * A transient state at this point would mean some unexpected party
  709. * is poking at the power controls too.
  710. */
  711. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
  712. WARN_ON(ctrl != state);
  713. mutex_unlock(&dev_priv->rps.hw_lock);
  714. return enabled;
  715. }
  716. static void vlv_init_display_clock_gating(struct drm_i915_private *dev_priv)
  717. {
  718. u32 val;
  719. /*
  720. * On driver load, a pipe may be active and driving a DSI display.
  721. * Preserve DPOUNIT_CLOCK_GATE_DISABLE to avoid the pipe getting stuck
  722. * (and never recovering) in this case. intel_dsi_post_disable() will
  723. * clear it when we turn off the display.
  724. */
  725. val = I915_READ(DSPCLK_GATE_D);
  726. val &= DPOUNIT_CLOCK_GATE_DISABLE;
  727. val |= VRHUNIT_CLOCK_GATE_DISABLE;
  728. I915_WRITE(DSPCLK_GATE_D, val);
  729. /*
  730. * Disable trickle feed and enable pnd deadline calculation
  731. */
  732. I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
  733. I915_WRITE(CBR1_VLV, 0);
  734. WARN_ON(dev_priv->rawclk_freq == 0);
  735. I915_WRITE(RAWCLK_FREQ_VLV,
  736. DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 1000));
  737. }
  738. static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
  739. {
  740. struct intel_encoder *encoder;
  741. enum pipe pipe;
  742. /*
  743. * Enable the CRI clock source so we can get at the
  744. * display and the reference clock for VGA
  745. * hotplug / manual detection. Supposedly DSI also
  746. * needs the ref clock up and running.
  747. *
  748. * CHV DPLL B/C have some issues if VGA mode is enabled.
  749. */
  750. for_each_pipe(dev_priv, pipe) {
  751. u32 val = I915_READ(DPLL(pipe));
  752. val |= DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
  753. if (pipe != PIPE_A)
  754. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  755. I915_WRITE(DPLL(pipe), val);
  756. }
  757. vlv_init_display_clock_gating(dev_priv);
  758. spin_lock_irq(&dev_priv->irq_lock);
  759. valleyview_enable_display_irqs(dev_priv);
  760. spin_unlock_irq(&dev_priv->irq_lock);
  761. /*
  762. * During driver initialization/resume we can avoid restoring the
  763. * part of the HW/SW state that will be inited anyway explicitly.
  764. */
  765. if (dev_priv->power_domains.initializing)
  766. return;
  767. intel_hpd_init(dev_priv);
  768. /* Re-enable the ADPA, if we have one */
  769. for_each_intel_encoder(&dev_priv->drm, encoder) {
  770. if (encoder->type == INTEL_OUTPUT_ANALOG)
  771. intel_crt_reset(&encoder->base);
  772. }
  773. i915_redisable_vga_power_on(dev_priv);
  774. intel_pps_unlock_regs_wa(dev_priv);
  775. }
  776. static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
  777. {
  778. spin_lock_irq(&dev_priv->irq_lock);
  779. valleyview_disable_display_irqs(dev_priv);
  780. spin_unlock_irq(&dev_priv->irq_lock);
  781. /* make sure we're done processing display irqs */
  782. synchronize_irq(dev_priv->drm.irq);
  783. intel_power_sequencer_reset(dev_priv);
  784. /* Prevent us from re-enabling polling on accident in late suspend */
  785. if (!dev_priv->drm.dev->power.is_suspended)
  786. intel_hpd_poll_init(dev_priv);
  787. }
  788. static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
  789. struct i915_power_well *power_well)
  790. {
  791. WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
  792. vlv_set_power_well(dev_priv, power_well, true);
  793. vlv_display_power_well_init(dev_priv);
  794. }
  795. static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
  796. struct i915_power_well *power_well)
  797. {
  798. WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DISP2D);
  799. vlv_display_power_well_deinit(dev_priv);
  800. vlv_set_power_well(dev_priv, power_well, false);
  801. }
  802. static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
  803. struct i915_power_well *power_well)
  804. {
  805. WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
  806. /* since ref/cri clock was enabled */
  807. udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
  808. vlv_set_power_well(dev_priv, power_well, true);
  809. /*
  810. * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
  811. * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
  812. * a. GUnit 0x2110 bit[0] set to 1 (def 0)
  813. * b. The other bits such as sfr settings / modesel may all
  814. * be set to 0.
  815. *
  816. * This should only be done on init and resume from S3 with
  817. * both PLLs disabled, or we risk losing DPIO and PLL
  818. * synchronization.
  819. */
  820. I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
  821. }
  822. static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
  823. struct i915_power_well *power_well)
  824. {
  825. enum pipe pipe;
  826. WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC);
  827. for_each_pipe(dev_priv, pipe)
  828. assert_pll_disabled(dev_priv, pipe);
  829. /* Assert common reset */
  830. I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
  831. vlv_set_power_well(dev_priv, power_well, false);
  832. }
  833. #define POWER_DOMAIN_MASK (GENMASK_ULL(POWER_DOMAIN_NUM - 1, 0))
  834. static struct i915_power_well *
  835. lookup_power_well(struct drm_i915_private *dev_priv,
  836. enum i915_power_well_id power_well_id)
  837. {
  838. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  839. int i;
  840. for (i = 0; i < power_domains->power_well_count; i++) {
  841. struct i915_power_well *power_well;
  842. power_well = &power_domains->power_wells[i];
  843. if (power_well->id == power_well_id)
  844. return power_well;
  845. }
  846. return NULL;
  847. }
  848. #define BITS_SET(val, bits) (((val) & (bits)) == (bits))
  849. static void assert_chv_phy_status(struct drm_i915_private *dev_priv)
  850. {
  851. struct i915_power_well *cmn_bc =
  852. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
  853. struct i915_power_well *cmn_d =
  854. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
  855. u32 phy_control = dev_priv->chv_phy_control;
  856. u32 phy_status = 0;
  857. u32 phy_status_mask = 0xffffffff;
  858. /*
  859. * The BIOS can leave the PHY is some weird state
  860. * where it doesn't fully power down some parts.
  861. * Disable the asserts until the PHY has been fully
  862. * reset (ie. the power well has been disabled at
  863. * least once).
  864. */
  865. if (!dev_priv->chv_phy_assert[DPIO_PHY0])
  866. phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0) |
  867. PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0) |
  868. PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1) |
  869. PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1) |
  870. PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0) |
  871. PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1));
  872. if (!dev_priv->chv_phy_assert[DPIO_PHY1])
  873. phy_status_mask &= ~(PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0) |
  874. PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0) |
  875. PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1));
  876. if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
  877. phy_status |= PHY_POWERGOOD(DPIO_PHY0);
  878. /* this assumes override is only used to enable lanes */
  879. if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0)) == 0)
  880. phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0);
  881. if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1)) == 0)
  882. phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1);
  883. /* CL1 is on whenever anything is on in either channel */
  884. if (BITS_SET(phy_control,
  885. PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH0) |
  886. PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)))
  887. phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH0);
  888. /*
  889. * The DPLLB check accounts for the pipe B + port A usage
  890. * with CL2 powered up but all the lanes in the second channel
  891. * powered down.
  892. */
  893. if (BITS_SET(phy_control,
  894. PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY0, DPIO_CH1)) &&
  895. (I915_READ(DPLL(PIPE_B)) & DPLL_VCO_ENABLE) == 0)
  896. phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY0, DPIO_CH1);
  897. if (BITS_SET(phy_control,
  898. PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH0)))
  899. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 0);
  900. if (BITS_SET(phy_control,
  901. PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH0)))
  902. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH0, 1);
  903. if (BITS_SET(phy_control,
  904. PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY0, DPIO_CH1)))
  905. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 0);
  906. if (BITS_SET(phy_control,
  907. PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY0, DPIO_CH1)))
  908. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY0, DPIO_CH1, 1);
  909. }
  910. if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
  911. phy_status |= PHY_POWERGOOD(DPIO_PHY1);
  912. /* this assumes override is only used to enable lanes */
  913. if ((phy_control & PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0)) == 0)
  914. phy_control |= PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0);
  915. if (BITS_SET(phy_control,
  916. PHY_CH_POWER_DOWN_OVRD(0xf, DPIO_PHY1, DPIO_CH0)))
  917. phy_status |= PHY_STATUS_CMN_LDO(DPIO_PHY1, DPIO_CH0);
  918. if (BITS_SET(phy_control,
  919. PHY_CH_POWER_DOWN_OVRD(0x3, DPIO_PHY1, DPIO_CH0)))
  920. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 0);
  921. if (BITS_SET(phy_control,
  922. PHY_CH_POWER_DOWN_OVRD(0xc, DPIO_PHY1, DPIO_CH0)))
  923. phy_status |= PHY_STATUS_SPLINE_LDO(DPIO_PHY1, DPIO_CH0, 1);
  924. }
  925. phy_status &= phy_status_mask;
  926. /*
  927. * The PHY may be busy with some initial calibration and whatnot,
  928. * so the power state can take a while to actually change.
  929. */
  930. if (intel_wait_for_register(dev_priv,
  931. DISPLAY_PHY_STATUS,
  932. phy_status_mask,
  933. phy_status,
  934. 10))
  935. DRM_ERROR("Unexpected PHY_STATUS 0x%08x, expected 0x%08x (PHY_CONTROL=0x%08x)\n",
  936. I915_READ(DISPLAY_PHY_STATUS) & phy_status_mask,
  937. phy_status, dev_priv->chv_phy_control);
  938. }
  939. #undef BITS_SET
  940. static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
  941. struct i915_power_well *power_well)
  942. {
  943. enum dpio_phy phy;
  944. enum pipe pipe;
  945. uint32_t tmp;
  946. WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
  947. power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
  948. if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
  949. pipe = PIPE_A;
  950. phy = DPIO_PHY0;
  951. } else {
  952. pipe = PIPE_C;
  953. phy = DPIO_PHY1;
  954. }
  955. /* since ref/cri clock was enabled */
  956. udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
  957. vlv_set_power_well(dev_priv, power_well, true);
  958. /* Poll for phypwrgood signal */
  959. if (intel_wait_for_register(dev_priv,
  960. DISPLAY_PHY_STATUS,
  961. PHY_POWERGOOD(phy),
  962. PHY_POWERGOOD(phy),
  963. 1))
  964. DRM_ERROR("Display PHY %d is not power up\n", phy);
  965. mutex_lock(&dev_priv->sb_lock);
  966. /* Enable dynamic power down */
  967. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW28);
  968. tmp |= DPIO_DYNPWRDOWNEN_CH0 | DPIO_CL1POWERDOWNEN |
  969. DPIO_SUS_CLK_CONFIG_GATE_CLKREQ;
  970. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW28, tmp);
  971. if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
  972. tmp = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW6_CH1);
  973. tmp |= DPIO_DYNPWRDOWNEN_CH1;
  974. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW6_CH1, tmp);
  975. } else {
  976. /*
  977. * Force the non-existing CL2 off. BXT does this
  978. * too, so maybe it saves some power even though
  979. * CL2 doesn't exist?
  980. */
  981. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
  982. tmp |= DPIO_CL2_LDOFUSE_PWRENB;
  983. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, tmp);
  984. }
  985. mutex_unlock(&dev_priv->sb_lock);
  986. dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
  987. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  988. DRM_DEBUG_KMS("Enabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
  989. phy, dev_priv->chv_phy_control);
  990. assert_chv_phy_status(dev_priv);
  991. }
  992. static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
  993. struct i915_power_well *power_well)
  994. {
  995. enum dpio_phy phy;
  996. WARN_ON_ONCE(power_well->id != PUNIT_POWER_WELL_DPIO_CMN_BC &&
  997. power_well->id != PUNIT_POWER_WELL_DPIO_CMN_D);
  998. if (power_well->id == PUNIT_POWER_WELL_DPIO_CMN_BC) {
  999. phy = DPIO_PHY0;
  1000. assert_pll_disabled(dev_priv, PIPE_A);
  1001. assert_pll_disabled(dev_priv, PIPE_B);
  1002. } else {
  1003. phy = DPIO_PHY1;
  1004. assert_pll_disabled(dev_priv, PIPE_C);
  1005. }
  1006. dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
  1007. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  1008. vlv_set_power_well(dev_priv, power_well, false);
  1009. DRM_DEBUG_KMS("Disabled DPIO PHY%d (PHY_CONTROL=0x%08x)\n",
  1010. phy, dev_priv->chv_phy_control);
  1011. /* PHY is fully reset now, so we can enable the PHY state asserts */
  1012. dev_priv->chv_phy_assert[phy] = true;
  1013. assert_chv_phy_status(dev_priv);
  1014. }
  1015. static void assert_chv_phy_powergate(struct drm_i915_private *dev_priv, enum dpio_phy phy,
  1016. enum dpio_channel ch, bool override, unsigned int mask)
  1017. {
  1018. enum pipe pipe = phy == DPIO_PHY0 ? PIPE_A : PIPE_C;
  1019. u32 reg, val, expected, actual;
  1020. /*
  1021. * The BIOS can leave the PHY is some weird state
  1022. * where it doesn't fully power down some parts.
  1023. * Disable the asserts until the PHY has been fully
  1024. * reset (ie. the power well has been disabled at
  1025. * least once).
  1026. */
  1027. if (!dev_priv->chv_phy_assert[phy])
  1028. return;
  1029. if (ch == DPIO_CH0)
  1030. reg = _CHV_CMN_DW0_CH0;
  1031. else
  1032. reg = _CHV_CMN_DW6_CH1;
  1033. mutex_lock(&dev_priv->sb_lock);
  1034. val = vlv_dpio_read(dev_priv, pipe, reg);
  1035. mutex_unlock(&dev_priv->sb_lock);
  1036. /*
  1037. * This assumes !override is only used when the port is disabled.
  1038. * All lanes should power down even without the override when
  1039. * the port is disabled.
  1040. */
  1041. if (!override || mask == 0xf) {
  1042. expected = DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
  1043. /*
  1044. * If CH1 common lane is not active anymore
  1045. * (eg. for pipe B DPLL) the entire channel will
  1046. * shut down, which causes the common lane registers
  1047. * to read as 0. That means we can't actually check
  1048. * the lane power down status bits, but as the entire
  1049. * register reads as 0 it's a good indication that the
  1050. * channel is indeed entirely powered down.
  1051. */
  1052. if (ch == DPIO_CH1 && val == 0)
  1053. expected = 0;
  1054. } else if (mask != 0x0) {
  1055. expected = DPIO_ANYDL_POWERDOWN;
  1056. } else {
  1057. expected = 0;
  1058. }
  1059. if (ch == DPIO_CH0)
  1060. actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH0;
  1061. else
  1062. actual = val >> DPIO_ANYDL_POWERDOWN_SHIFT_CH1;
  1063. actual &= DPIO_ALLDL_POWERDOWN | DPIO_ANYDL_POWERDOWN;
  1064. WARN(actual != expected,
  1065. "Unexpected DPIO lane power down: all %d, any %d. Expected: all %d, any %d. (0x%x = 0x%08x)\n",
  1066. !!(actual & DPIO_ALLDL_POWERDOWN), !!(actual & DPIO_ANYDL_POWERDOWN),
  1067. !!(expected & DPIO_ALLDL_POWERDOWN), !!(expected & DPIO_ANYDL_POWERDOWN),
  1068. reg, val);
  1069. }
  1070. bool chv_phy_powergate_ch(struct drm_i915_private *dev_priv, enum dpio_phy phy,
  1071. enum dpio_channel ch, bool override)
  1072. {
  1073. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1074. bool was_override;
  1075. mutex_lock(&power_domains->lock);
  1076. was_override = dev_priv->chv_phy_control & PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1077. if (override == was_override)
  1078. goto out;
  1079. if (override)
  1080. dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1081. else
  1082. dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1083. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  1084. DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d (DPIO_PHY_CONTROL=0x%08x)\n",
  1085. phy, ch, dev_priv->chv_phy_control);
  1086. assert_chv_phy_status(dev_priv);
  1087. out:
  1088. mutex_unlock(&power_domains->lock);
  1089. return was_override;
  1090. }
  1091. void chv_phy_powergate_lanes(struct intel_encoder *encoder,
  1092. bool override, unsigned int mask)
  1093. {
  1094. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1095. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1096. enum dpio_phy phy = vlv_dport_to_phy(enc_to_dig_port(&encoder->base));
  1097. enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
  1098. mutex_lock(&power_domains->lock);
  1099. dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD(0xf, phy, ch);
  1100. dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD(mask, phy, ch);
  1101. if (override)
  1102. dev_priv->chv_phy_control |= PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1103. else
  1104. dev_priv->chv_phy_control &= ~PHY_CH_POWER_DOWN_OVRD_EN(phy, ch);
  1105. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  1106. DRM_DEBUG_KMS("Power gating DPIO PHY%d CH%d lanes 0x%x (PHY_CONTROL=0x%08x)\n",
  1107. phy, ch, mask, dev_priv->chv_phy_control);
  1108. assert_chv_phy_status(dev_priv);
  1109. assert_chv_phy_powergate(dev_priv, phy, ch, override, mask);
  1110. mutex_unlock(&power_domains->lock);
  1111. }
  1112. static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
  1113. struct i915_power_well *power_well)
  1114. {
  1115. enum pipe pipe = PIPE_A;
  1116. bool enabled;
  1117. u32 state, ctrl;
  1118. mutex_lock(&dev_priv->rps.hw_lock);
  1119. state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
  1120. /*
  1121. * We only ever set the power-on and power-gate states, anything
  1122. * else is unexpected.
  1123. */
  1124. WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
  1125. enabled = state == DP_SSS_PWR_ON(pipe);
  1126. /*
  1127. * A transient state at this point would mean some unexpected party
  1128. * is poking at the power controls too.
  1129. */
  1130. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
  1131. WARN_ON(ctrl << 16 != state);
  1132. mutex_unlock(&dev_priv->rps.hw_lock);
  1133. return enabled;
  1134. }
  1135. static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
  1136. struct i915_power_well *power_well,
  1137. bool enable)
  1138. {
  1139. enum pipe pipe = PIPE_A;
  1140. u32 state;
  1141. u32 ctrl;
  1142. state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
  1143. mutex_lock(&dev_priv->rps.hw_lock);
  1144. #define COND \
  1145. ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
  1146. if (COND)
  1147. goto out;
  1148. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  1149. ctrl &= ~DP_SSC_MASK(pipe);
  1150. ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
  1151. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
  1152. if (wait_for(COND, 100))
  1153. DRM_ERROR("timeout setting power well state %08x (%08x)\n",
  1154. state,
  1155. vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
  1156. #undef COND
  1157. out:
  1158. mutex_unlock(&dev_priv->rps.hw_lock);
  1159. }
  1160. static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
  1161. struct i915_power_well *power_well)
  1162. {
  1163. WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
  1164. chv_set_pipe_power_well(dev_priv, power_well, true);
  1165. vlv_display_power_well_init(dev_priv);
  1166. }
  1167. static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
  1168. struct i915_power_well *power_well)
  1169. {
  1170. WARN_ON_ONCE(power_well->id != CHV_DISP_PW_PIPE_A);
  1171. vlv_display_power_well_deinit(dev_priv);
  1172. chv_set_pipe_power_well(dev_priv, power_well, false);
  1173. }
  1174. static void
  1175. __intel_display_power_get_domain(struct drm_i915_private *dev_priv,
  1176. enum intel_display_power_domain domain)
  1177. {
  1178. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1179. struct i915_power_well *power_well;
  1180. for_each_power_domain_well(dev_priv, power_well, BIT_ULL(domain))
  1181. intel_power_well_get(dev_priv, power_well);
  1182. power_domains->domain_use_count[domain]++;
  1183. }
  1184. /**
  1185. * intel_display_power_get - grab a power domain reference
  1186. * @dev_priv: i915 device instance
  1187. * @domain: power domain to reference
  1188. *
  1189. * This function grabs a power domain reference for @domain and ensures that the
  1190. * power domain and all its parents are powered up. Therefore users should only
  1191. * grab a reference to the innermost power domain they need.
  1192. *
  1193. * Any power domain reference obtained by this function must have a symmetric
  1194. * call to intel_display_power_put() to release the reference again.
  1195. */
  1196. void intel_display_power_get(struct drm_i915_private *dev_priv,
  1197. enum intel_display_power_domain domain)
  1198. {
  1199. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1200. intel_runtime_pm_get(dev_priv);
  1201. mutex_lock(&power_domains->lock);
  1202. __intel_display_power_get_domain(dev_priv, domain);
  1203. mutex_unlock(&power_domains->lock);
  1204. }
  1205. /**
  1206. * intel_display_power_get_if_enabled - grab a reference for an enabled display power domain
  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. bool intel_display_power_get_if_enabled(struct drm_i915_private *dev_priv,
  1218. enum intel_display_power_domain domain)
  1219. {
  1220. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1221. bool is_enabled;
  1222. if (!intel_runtime_pm_get_if_in_use(dev_priv))
  1223. return false;
  1224. mutex_lock(&power_domains->lock);
  1225. if (__intel_display_power_is_enabled(dev_priv, domain)) {
  1226. __intel_display_power_get_domain(dev_priv, domain);
  1227. is_enabled = true;
  1228. } else {
  1229. is_enabled = false;
  1230. }
  1231. mutex_unlock(&power_domains->lock);
  1232. if (!is_enabled)
  1233. intel_runtime_pm_put(dev_priv);
  1234. return is_enabled;
  1235. }
  1236. /**
  1237. * intel_display_power_put - release a power domain reference
  1238. * @dev_priv: i915 device instance
  1239. * @domain: power domain to reference
  1240. *
  1241. * This function drops the power domain reference obtained by
  1242. * intel_display_power_get() and might power down the corresponding hardware
  1243. * block right away if this is the last reference.
  1244. */
  1245. void intel_display_power_put(struct drm_i915_private *dev_priv,
  1246. enum intel_display_power_domain domain)
  1247. {
  1248. struct i915_power_domains *power_domains;
  1249. struct i915_power_well *power_well;
  1250. power_domains = &dev_priv->power_domains;
  1251. mutex_lock(&power_domains->lock);
  1252. WARN(!power_domains->domain_use_count[domain],
  1253. "Use count on domain %s is already zero\n",
  1254. intel_display_power_domain_str(domain));
  1255. power_domains->domain_use_count[domain]--;
  1256. for_each_power_domain_well_rev(dev_priv, power_well, BIT_ULL(domain))
  1257. intel_power_well_put(dev_priv, power_well);
  1258. mutex_unlock(&power_domains->lock);
  1259. intel_runtime_pm_put(dev_priv);
  1260. }
  1261. #define I830_PIPES_POWER_DOMAINS ( \
  1262. BIT_ULL(POWER_DOMAIN_PIPE_A) | \
  1263. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1264. BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
  1265. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1266. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1267. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1268. BIT_ULL(POWER_DOMAIN_INIT))
  1269. #define VLV_DISPLAY_POWER_DOMAINS ( \
  1270. BIT_ULL(POWER_DOMAIN_PIPE_A) | \
  1271. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1272. BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
  1273. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1274. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1275. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1276. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1277. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1278. BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
  1279. BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
  1280. BIT_ULL(POWER_DOMAIN_VGA) | \
  1281. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1282. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1283. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1284. BIT_ULL(POWER_DOMAIN_GMBUS) | \
  1285. BIT_ULL(POWER_DOMAIN_INIT))
  1286. #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
  1287. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1288. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1289. BIT_ULL(POWER_DOMAIN_PORT_CRT) | \
  1290. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1291. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1292. BIT_ULL(POWER_DOMAIN_INIT))
  1293. #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
  1294. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1295. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1296. BIT_ULL(POWER_DOMAIN_INIT))
  1297. #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
  1298. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1299. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1300. BIT_ULL(POWER_DOMAIN_INIT))
  1301. #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
  1302. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1303. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1304. BIT_ULL(POWER_DOMAIN_INIT))
  1305. #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
  1306. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1307. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1308. BIT_ULL(POWER_DOMAIN_INIT))
  1309. #define CHV_DISPLAY_POWER_DOMAINS ( \
  1310. BIT_ULL(POWER_DOMAIN_PIPE_A) | \
  1311. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1312. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1313. BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
  1314. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1315. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1316. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1317. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1318. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1319. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1320. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1321. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
  1322. BIT_ULL(POWER_DOMAIN_PORT_DSI) | \
  1323. BIT_ULL(POWER_DOMAIN_VGA) | \
  1324. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1325. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1326. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1327. BIT_ULL(POWER_DOMAIN_AUX_D) | \
  1328. BIT_ULL(POWER_DOMAIN_GMBUS) | \
  1329. BIT_ULL(POWER_DOMAIN_INIT))
  1330. #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
  1331. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1332. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1333. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1334. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1335. BIT_ULL(POWER_DOMAIN_INIT))
  1336. #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
  1337. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
  1338. BIT_ULL(POWER_DOMAIN_AUX_D) | \
  1339. BIT_ULL(POWER_DOMAIN_INIT))
  1340. #define HSW_DISPLAY_POWER_DOMAINS ( \
  1341. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1342. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1343. BIT_ULL(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
  1344. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1345. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1346. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1347. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1348. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1349. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1350. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1351. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
  1352. BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
  1353. BIT_ULL(POWER_DOMAIN_VGA) | \
  1354. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1355. BIT_ULL(POWER_DOMAIN_INIT))
  1356. #define BDW_DISPLAY_POWER_DOMAINS ( \
  1357. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1358. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1359. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1360. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1361. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1362. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1363. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1364. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1365. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1366. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
  1367. BIT_ULL(POWER_DOMAIN_PORT_CRT) | /* DDI E */ \
  1368. BIT_ULL(POWER_DOMAIN_VGA) | \
  1369. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1370. BIT_ULL(POWER_DOMAIN_INIT))
  1371. #define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
  1372. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1373. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1374. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1375. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1376. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1377. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1378. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1379. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1380. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1381. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
  1382. BIT_ULL(POWER_DOMAIN_PORT_DDI_E_LANES) | \
  1383. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1384. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1385. BIT_ULL(POWER_DOMAIN_AUX_D) | \
  1386. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1387. BIT_ULL(POWER_DOMAIN_VGA) | \
  1388. BIT_ULL(POWER_DOMAIN_INIT))
  1389. #define SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS ( \
  1390. BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
  1391. BIT_ULL(POWER_DOMAIN_PORT_DDI_E_IO) | \
  1392. BIT_ULL(POWER_DOMAIN_INIT))
  1393. #define SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
  1394. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
  1395. BIT_ULL(POWER_DOMAIN_INIT))
  1396. #define SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
  1397. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
  1398. BIT_ULL(POWER_DOMAIN_INIT))
  1399. #define SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS ( \
  1400. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
  1401. BIT_ULL(POWER_DOMAIN_INIT))
  1402. #define SKL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
  1403. SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  1404. BIT_ULL(POWER_DOMAIN_MODESET) | \
  1405. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1406. BIT_ULL(POWER_DOMAIN_INIT))
  1407. #define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
  1408. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1409. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1410. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1411. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1412. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1413. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1414. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1415. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1416. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1417. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1418. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1419. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1420. BIT_ULL(POWER_DOMAIN_VGA) | \
  1421. BIT_ULL(POWER_DOMAIN_GMBUS) | \
  1422. BIT_ULL(POWER_DOMAIN_INIT))
  1423. #define BXT_DISPLAY_DC_OFF_POWER_DOMAINS ( \
  1424. BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  1425. BIT_ULL(POWER_DOMAIN_MODESET) | \
  1426. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1427. BIT_ULL(POWER_DOMAIN_INIT))
  1428. #define BXT_DPIO_CMN_A_POWER_DOMAINS ( \
  1429. BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
  1430. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1431. BIT_ULL(POWER_DOMAIN_INIT))
  1432. #define BXT_DPIO_CMN_BC_POWER_DOMAINS ( \
  1433. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1434. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1435. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1436. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1437. BIT_ULL(POWER_DOMAIN_INIT))
  1438. #define GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
  1439. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1440. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1441. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1442. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1443. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1444. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1445. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1446. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1447. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1448. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1449. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1450. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1451. BIT_ULL(POWER_DOMAIN_VGA) | \
  1452. BIT_ULL(POWER_DOMAIN_INIT))
  1453. #define GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS ( \
  1454. BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO))
  1455. #define GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS ( \
  1456. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO))
  1457. #define GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS ( \
  1458. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO))
  1459. #define GLK_DPIO_CMN_A_POWER_DOMAINS ( \
  1460. BIT_ULL(POWER_DOMAIN_PORT_DDI_A_LANES) | \
  1461. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1462. BIT_ULL(POWER_DOMAIN_INIT))
  1463. #define GLK_DPIO_CMN_B_POWER_DOMAINS ( \
  1464. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1465. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1466. BIT_ULL(POWER_DOMAIN_INIT))
  1467. #define GLK_DPIO_CMN_C_POWER_DOMAINS ( \
  1468. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1469. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1470. BIT_ULL(POWER_DOMAIN_INIT))
  1471. #define GLK_DISPLAY_AUX_A_POWER_DOMAINS ( \
  1472. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1473. BIT_ULL(POWER_DOMAIN_INIT))
  1474. #define GLK_DISPLAY_AUX_B_POWER_DOMAINS ( \
  1475. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1476. BIT_ULL(POWER_DOMAIN_INIT))
  1477. #define GLK_DISPLAY_AUX_C_POWER_DOMAINS ( \
  1478. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1479. BIT_ULL(POWER_DOMAIN_INIT))
  1480. #define GLK_DISPLAY_DC_OFF_POWER_DOMAINS ( \
  1481. GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  1482. BIT_ULL(POWER_DOMAIN_MODESET) | \
  1483. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1484. BIT_ULL(POWER_DOMAIN_INIT))
  1485. #define CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
  1486. BIT_ULL(POWER_DOMAIN_TRANSCODER_A) | \
  1487. BIT_ULL(POWER_DOMAIN_PIPE_B) | \
  1488. BIT_ULL(POWER_DOMAIN_TRANSCODER_B) | \
  1489. BIT_ULL(POWER_DOMAIN_PIPE_C) | \
  1490. BIT_ULL(POWER_DOMAIN_TRANSCODER_C) | \
  1491. BIT_ULL(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  1492. BIT_ULL(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  1493. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_LANES) | \
  1494. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_LANES) | \
  1495. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_LANES) | \
  1496. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1497. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1498. BIT_ULL(POWER_DOMAIN_AUX_D) | \
  1499. BIT_ULL(POWER_DOMAIN_AUDIO) | \
  1500. BIT_ULL(POWER_DOMAIN_VGA) | \
  1501. BIT_ULL(POWER_DOMAIN_INIT))
  1502. #define CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS ( \
  1503. BIT_ULL(POWER_DOMAIN_PORT_DDI_A_IO) | \
  1504. BIT_ULL(POWER_DOMAIN_INIT))
  1505. #define CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS ( \
  1506. BIT_ULL(POWER_DOMAIN_PORT_DDI_B_IO) | \
  1507. BIT_ULL(POWER_DOMAIN_INIT))
  1508. #define CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS ( \
  1509. BIT_ULL(POWER_DOMAIN_PORT_DDI_C_IO) | \
  1510. BIT_ULL(POWER_DOMAIN_INIT))
  1511. #define CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS ( \
  1512. BIT_ULL(POWER_DOMAIN_PORT_DDI_D_IO) | \
  1513. BIT_ULL(POWER_DOMAIN_INIT))
  1514. #define CNL_DISPLAY_AUX_A_POWER_DOMAINS ( \
  1515. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1516. BIT_ULL(POWER_DOMAIN_INIT))
  1517. #define CNL_DISPLAY_AUX_B_POWER_DOMAINS ( \
  1518. BIT_ULL(POWER_DOMAIN_AUX_B) | \
  1519. BIT_ULL(POWER_DOMAIN_INIT))
  1520. #define CNL_DISPLAY_AUX_C_POWER_DOMAINS ( \
  1521. BIT_ULL(POWER_DOMAIN_AUX_C) | \
  1522. BIT_ULL(POWER_DOMAIN_INIT))
  1523. #define CNL_DISPLAY_AUX_D_POWER_DOMAINS ( \
  1524. BIT_ULL(POWER_DOMAIN_AUX_D) | \
  1525. BIT_ULL(POWER_DOMAIN_INIT))
  1526. #define CNL_DISPLAY_DC_OFF_POWER_DOMAINS ( \
  1527. CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  1528. BIT_ULL(POWER_DOMAIN_MODESET) | \
  1529. BIT_ULL(POWER_DOMAIN_AUX_A) | \
  1530. BIT_ULL(POWER_DOMAIN_INIT))
  1531. static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
  1532. .sync_hw = i9xx_power_well_sync_hw_noop,
  1533. .enable = i9xx_always_on_power_well_noop,
  1534. .disable = i9xx_always_on_power_well_noop,
  1535. .is_enabled = i9xx_always_on_power_well_enabled,
  1536. };
  1537. static const struct i915_power_well_ops chv_pipe_power_well_ops = {
  1538. .sync_hw = i9xx_power_well_sync_hw_noop,
  1539. .enable = chv_pipe_power_well_enable,
  1540. .disable = chv_pipe_power_well_disable,
  1541. .is_enabled = chv_pipe_power_well_enabled,
  1542. };
  1543. static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
  1544. .sync_hw = i9xx_power_well_sync_hw_noop,
  1545. .enable = chv_dpio_cmn_power_well_enable,
  1546. .disable = chv_dpio_cmn_power_well_disable,
  1547. .is_enabled = vlv_power_well_enabled,
  1548. };
  1549. static struct i915_power_well i9xx_always_on_power_well[] = {
  1550. {
  1551. .name = "always-on",
  1552. .always_on = 1,
  1553. .domains = POWER_DOMAIN_MASK,
  1554. .ops = &i9xx_always_on_power_well_ops,
  1555. .id = I915_DISP_PW_ALWAYS_ON,
  1556. },
  1557. };
  1558. static const struct i915_power_well_ops i830_pipes_power_well_ops = {
  1559. .sync_hw = i830_pipes_power_well_sync_hw,
  1560. .enable = i830_pipes_power_well_enable,
  1561. .disable = i830_pipes_power_well_disable,
  1562. .is_enabled = i830_pipes_power_well_enabled,
  1563. };
  1564. static struct i915_power_well i830_power_wells[] = {
  1565. {
  1566. .name = "always-on",
  1567. .always_on = 1,
  1568. .domains = POWER_DOMAIN_MASK,
  1569. .ops = &i9xx_always_on_power_well_ops,
  1570. .id = I915_DISP_PW_ALWAYS_ON,
  1571. },
  1572. {
  1573. .name = "pipes",
  1574. .domains = I830_PIPES_POWER_DOMAINS,
  1575. .ops = &i830_pipes_power_well_ops,
  1576. .id = I830_DISP_PW_PIPES,
  1577. },
  1578. };
  1579. static const struct i915_power_well_ops hsw_power_well_ops = {
  1580. .sync_hw = hsw_power_well_sync_hw,
  1581. .enable = hsw_power_well_enable,
  1582. .disable = hsw_power_well_disable,
  1583. .is_enabled = hsw_power_well_enabled,
  1584. };
  1585. static const struct i915_power_well_ops gen9_dc_off_power_well_ops = {
  1586. .sync_hw = i9xx_power_well_sync_hw_noop,
  1587. .enable = gen9_dc_off_power_well_enable,
  1588. .disable = gen9_dc_off_power_well_disable,
  1589. .is_enabled = gen9_dc_off_power_well_enabled,
  1590. };
  1591. static const struct i915_power_well_ops bxt_dpio_cmn_power_well_ops = {
  1592. .sync_hw = i9xx_power_well_sync_hw_noop,
  1593. .enable = bxt_dpio_cmn_power_well_enable,
  1594. .disable = bxt_dpio_cmn_power_well_disable,
  1595. .is_enabled = bxt_dpio_cmn_power_well_enabled,
  1596. };
  1597. static struct i915_power_well hsw_power_wells[] = {
  1598. {
  1599. .name = "always-on",
  1600. .always_on = 1,
  1601. .domains = POWER_DOMAIN_MASK,
  1602. .ops = &i9xx_always_on_power_well_ops,
  1603. .id = I915_DISP_PW_ALWAYS_ON,
  1604. },
  1605. {
  1606. .name = "display",
  1607. .domains = HSW_DISPLAY_POWER_DOMAINS,
  1608. .ops = &hsw_power_well_ops,
  1609. .id = HSW_DISP_PW_GLOBAL,
  1610. .hsw.has_vga = true,
  1611. },
  1612. };
  1613. static struct i915_power_well bdw_power_wells[] = {
  1614. {
  1615. .name = "always-on",
  1616. .always_on = 1,
  1617. .domains = POWER_DOMAIN_MASK,
  1618. .ops = &i9xx_always_on_power_well_ops,
  1619. .id = I915_DISP_PW_ALWAYS_ON,
  1620. },
  1621. {
  1622. .name = "display",
  1623. .domains = BDW_DISPLAY_POWER_DOMAINS,
  1624. .ops = &hsw_power_well_ops,
  1625. .id = HSW_DISP_PW_GLOBAL,
  1626. .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
  1627. .hsw.has_vga = true,
  1628. },
  1629. };
  1630. static const struct i915_power_well_ops vlv_display_power_well_ops = {
  1631. .sync_hw = i9xx_power_well_sync_hw_noop,
  1632. .enable = vlv_display_power_well_enable,
  1633. .disable = vlv_display_power_well_disable,
  1634. .is_enabled = vlv_power_well_enabled,
  1635. };
  1636. static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
  1637. .sync_hw = i9xx_power_well_sync_hw_noop,
  1638. .enable = vlv_dpio_cmn_power_well_enable,
  1639. .disable = vlv_dpio_cmn_power_well_disable,
  1640. .is_enabled = vlv_power_well_enabled,
  1641. };
  1642. static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
  1643. .sync_hw = i9xx_power_well_sync_hw_noop,
  1644. .enable = vlv_power_well_enable,
  1645. .disable = vlv_power_well_disable,
  1646. .is_enabled = vlv_power_well_enabled,
  1647. };
  1648. static struct i915_power_well vlv_power_wells[] = {
  1649. {
  1650. .name = "always-on",
  1651. .always_on = 1,
  1652. .domains = POWER_DOMAIN_MASK,
  1653. .ops = &i9xx_always_on_power_well_ops,
  1654. .id = I915_DISP_PW_ALWAYS_ON,
  1655. },
  1656. {
  1657. .name = "display",
  1658. .domains = VLV_DISPLAY_POWER_DOMAINS,
  1659. .id = PUNIT_POWER_WELL_DISP2D,
  1660. .ops = &vlv_display_power_well_ops,
  1661. },
  1662. {
  1663. .name = "dpio-tx-b-01",
  1664. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1665. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1666. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1667. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1668. .ops = &vlv_dpio_power_well_ops,
  1669. .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
  1670. },
  1671. {
  1672. .name = "dpio-tx-b-23",
  1673. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1674. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1675. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1676. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1677. .ops = &vlv_dpio_power_well_ops,
  1678. .id = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
  1679. },
  1680. {
  1681. .name = "dpio-tx-c-01",
  1682. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1683. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1684. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1685. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1686. .ops = &vlv_dpio_power_well_ops,
  1687. .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
  1688. },
  1689. {
  1690. .name = "dpio-tx-c-23",
  1691. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1692. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1693. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1694. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1695. .ops = &vlv_dpio_power_well_ops,
  1696. .id = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
  1697. },
  1698. {
  1699. .name = "dpio-common",
  1700. .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
  1701. .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
  1702. .ops = &vlv_dpio_cmn_power_well_ops,
  1703. },
  1704. };
  1705. static struct i915_power_well chv_power_wells[] = {
  1706. {
  1707. .name = "always-on",
  1708. .always_on = 1,
  1709. .domains = POWER_DOMAIN_MASK,
  1710. .ops = &i9xx_always_on_power_well_ops,
  1711. .id = I915_DISP_PW_ALWAYS_ON,
  1712. },
  1713. {
  1714. .name = "display",
  1715. /*
  1716. * Pipe A power well is the new disp2d well. Pipe B and C
  1717. * power wells don't actually exist. Pipe A power well is
  1718. * required for any pipe to work.
  1719. */
  1720. .domains = CHV_DISPLAY_POWER_DOMAINS,
  1721. .id = CHV_DISP_PW_PIPE_A,
  1722. .ops = &chv_pipe_power_well_ops,
  1723. },
  1724. {
  1725. .name = "dpio-common-bc",
  1726. .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
  1727. .id = PUNIT_POWER_WELL_DPIO_CMN_BC,
  1728. .ops = &chv_dpio_cmn_power_well_ops,
  1729. },
  1730. {
  1731. .name = "dpio-common-d",
  1732. .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
  1733. .id = PUNIT_POWER_WELL_DPIO_CMN_D,
  1734. .ops = &chv_dpio_cmn_power_well_ops,
  1735. },
  1736. };
  1737. bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
  1738. enum i915_power_well_id power_well_id)
  1739. {
  1740. struct i915_power_well *power_well;
  1741. bool ret;
  1742. power_well = lookup_power_well(dev_priv, power_well_id);
  1743. ret = power_well->ops->is_enabled(dev_priv, power_well);
  1744. return ret;
  1745. }
  1746. static struct i915_power_well skl_power_wells[] = {
  1747. {
  1748. .name = "always-on",
  1749. .always_on = 1,
  1750. .domains = POWER_DOMAIN_MASK,
  1751. .ops = &i9xx_always_on_power_well_ops,
  1752. .id = I915_DISP_PW_ALWAYS_ON,
  1753. },
  1754. {
  1755. .name = "power well 1",
  1756. /* Handled by the DMC firmware */
  1757. .domains = 0,
  1758. .ops = &hsw_power_well_ops,
  1759. .id = SKL_DISP_PW_1,
  1760. .hsw.has_fuses = true,
  1761. },
  1762. {
  1763. .name = "MISC IO power well",
  1764. /* Handled by the DMC firmware */
  1765. .domains = 0,
  1766. .ops = &hsw_power_well_ops,
  1767. .id = SKL_DISP_PW_MISC_IO,
  1768. },
  1769. {
  1770. .name = "DC off",
  1771. .domains = SKL_DISPLAY_DC_OFF_POWER_DOMAINS,
  1772. .ops = &gen9_dc_off_power_well_ops,
  1773. .id = SKL_DISP_PW_DC_OFF,
  1774. },
  1775. {
  1776. .name = "power well 2",
  1777. .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
  1778. .ops = &hsw_power_well_ops,
  1779. .id = SKL_DISP_PW_2,
  1780. .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
  1781. .hsw.has_vga = true,
  1782. .hsw.has_fuses = true,
  1783. },
  1784. {
  1785. .name = "DDI A/E IO power well",
  1786. .domains = SKL_DISPLAY_DDI_IO_A_E_POWER_DOMAINS,
  1787. .ops = &hsw_power_well_ops,
  1788. .id = SKL_DISP_PW_DDI_A_E,
  1789. },
  1790. {
  1791. .name = "DDI B IO power well",
  1792. .domains = SKL_DISPLAY_DDI_IO_B_POWER_DOMAINS,
  1793. .ops = &hsw_power_well_ops,
  1794. .id = SKL_DISP_PW_DDI_B,
  1795. },
  1796. {
  1797. .name = "DDI C IO power well",
  1798. .domains = SKL_DISPLAY_DDI_IO_C_POWER_DOMAINS,
  1799. .ops = &hsw_power_well_ops,
  1800. .id = SKL_DISP_PW_DDI_C,
  1801. },
  1802. {
  1803. .name = "DDI D IO power well",
  1804. .domains = SKL_DISPLAY_DDI_IO_D_POWER_DOMAINS,
  1805. .ops = &hsw_power_well_ops,
  1806. .id = SKL_DISP_PW_DDI_D,
  1807. },
  1808. };
  1809. static struct i915_power_well bxt_power_wells[] = {
  1810. {
  1811. .name = "always-on",
  1812. .always_on = 1,
  1813. .domains = POWER_DOMAIN_MASK,
  1814. .ops = &i9xx_always_on_power_well_ops,
  1815. .id = I915_DISP_PW_ALWAYS_ON,
  1816. },
  1817. {
  1818. .name = "power well 1",
  1819. .domains = 0,
  1820. .ops = &hsw_power_well_ops,
  1821. .id = SKL_DISP_PW_1,
  1822. .hsw.has_fuses = true,
  1823. },
  1824. {
  1825. .name = "DC off",
  1826. .domains = BXT_DISPLAY_DC_OFF_POWER_DOMAINS,
  1827. .ops = &gen9_dc_off_power_well_ops,
  1828. .id = SKL_DISP_PW_DC_OFF,
  1829. },
  1830. {
  1831. .name = "power well 2",
  1832. .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
  1833. .ops = &hsw_power_well_ops,
  1834. .id = SKL_DISP_PW_2,
  1835. .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
  1836. .hsw.has_vga = true,
  1837. .hsw.has_fuses = true,
  1838. },
  1839. {
  1840. .name = "dpio-common-a",
  1841. .domains = BXT_DPIO_CMN_A_POWER_DOMAINS,
  1842. .ops = &bxt_dpio_cmn_power_well_ops,
  1843. .id = BXT_DPIO_CMN_A,
  1844. .bxt.phy = DPIO_PHY1,
  1845. },
  1846. {
  1847. .name = "dpio-common-bc",
  1848. .domains = BXT_DPIO_CMN_BC_POWER_DOMAINS,
  1849. .ops = &bxt_dpio_cmn_power_well_ops,
  1850. .id = BXT_DPIO_CMN_BC,
  1851. .bxt.phy = DPIO_PHY0,
  1852. },
  1853. };
  1854. static struct i915_power_well glk_power_wells[] = {
  1855. {
  1856. .name = "always-on",
  1857. .always_on = 1,
  1858. .domains = POWER_DOMAIN_MASK,
  1859. .ops = &i9xx_always_on_power_well_ops,
  1860. .id = I915_DISP_PW_ALWAYS_ON,
  1861. },
  1862. {
  1863. .name = "power well 1",
  1864. /* Handled by the DMC firmware */
  1865. .domains = 0,
  1866. .ops = &hsw_power_well_ops,
  1867. .id = SKL_DISP_PW_1,
  1868. .hsw.has_fuses = true,
  1869. },
  1870. {
  1871. .name = "DC off",
  1872. .domains = GLK_DISPLAY_DC_OFF_POWER_DOMAINS,
  1873. .ops = &gen9_dc_off_power_well_ops,
  1874. .id = SKL_DISP_PW_DC_OFF,
  1875. },
  1876. {
  1877. .name = "power well 2",
  1878. .domains = GLK_DISPLAY_POWERWELL_2_POWER_DOMAINS,
  1879. .ops = &hsw_power_well_ops,
  1880. .id = SKL_DISP_PW_2,
  1881. .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
  1882. .hsw.has_vga = true,
  1883. .hsw.has_fuses = true,
  1884. },
  1885. {
  1886. .name = "dpio-common-a",
  1887. .domains = GLK_DPIO_CMN_A_POWER_DOMAINS,
  1888. .ops = &bxt_dpio_cmn_power_well_ops,
  1889. .id = BXT_DPIO_CMN_A,
  1890. .bxt.phy = DPIO_PHY1,
  1891. },
  1892. {
  1893. .name = "dpio-common-b",
  1894. .domains = GLK_DPIO_CMN_B_POWER_DOMAINS,
  1895. .ops = &bxt_dpio_cmn_power_well_ops,
  1896. .id = BXT_DPIO_CMN_BC,
  1897. .bxt.phy = DPIO_PHY0,
  1898. },
  1899. {
  1900. .name = "dpio-common-c",
  1901. .domains = GLK_DPIO_CMN_C_POWER_DOMAINS,
  1902. .ops = &bxt_dpio_cmn_power_well_ops,
  1903. .id = GLK_DPIO_CMN_C,
  1904. .bxt.phy = DPIO_PHY2,
  1905. },
  1906. {
  1907. .name = "AUX A",
  1908. .domains = GLK_DISPLAY_AUX_A_POWER_DOMAINS,
  1909. .ops = &hsw_power_well_ops,
  1910. .id = GLK_DISP_PW_AUX_A,
  1911. },
  1912. {
  1913. .name = "AUX B",
  1914. .domains = GLK_DISPLAY_AUX_B_POWER_DOMAINS,
  1915. .ops = &hsw_power_well_ops,
  1916. .id = GLK_DISP_PW_AUX_B,
  1917. },
  1918. {
  1919. .name = "AUX C",
  1920. .domains = GLK_DISPLAY_AUX_C_POWER_DOMAINS,
  1921. .ops = &hsw_power_well_ops,
  1922. .id = GLK_DISP_PW_AUX_C,
  1923. },
  1924. {
  1925. .name = "DDI A IO power well",
  1926. .domains = GLK_DISPLAY_DDI_IO_A_POWER_DOMAINS,
  1927. .ops = &hsw_power_well_ops,
  1928. .id = GLK_DISP_PW_DDI_A,
  1929. },
  1930. {
  1931. .name = "DDI B IO power well",
  1932. .domains = GLK_DISPLAY_DDI_IO_B_POWER_DOMAINS,
  1933. .ops = &hsw_power_well_ops,
  1934. .id = SKL_DISP_PW_DDI_B,
  1935. },
  1936. {
  1937. .name = "DDI C IO power well",
  1938. .domains = GLK_DISPLAY_DDI_IO_C_POWER_DOMAINS,
  1939. .ops = &hsw_power_well_ops,
  1940. .id = SKL_DISP_PW_DDI_C,
  1941. },
  1942. };
  1943. static struct i915_power_well cnl_power_wells[] = {
  1944. {
  1945. .name = "always-on",
  1946. .always_on = 1,
  1947. .domains = POWER_DOMAIN_MASK,
  1948. .ops = &i9xx_always_on_power_well_ops,
  1949. .id = I915_DISP_PW_ALWAYS_ON,
  1950. },
  1951. {
  1952. .name = "power well 1",
  1953. /* Handled by the DMC firmware */
  1954. .domains = 0,
  1955. .ops = &hsw_power_well_ops,
  1956. .id = SKL_DISP_PW_1,
  1957. .hsw.has_fuses = true,
  1958. },
  1959. {
  1960. .name = "AUX A",
  1961. .domains = CNL_DISPLAY_AUX_A_POWER_DOMAINS,
  1962. .ops = &hsw_power_well_ops,
  1963. .id = CNL_DISP_PW_AUX_A,
  1964. },
  1965. {
  1966. .name = "AUX B",
  1967. .domains = CNL_DISPLAY_AUX_B_POWER_DOMAINS,
  1968. .ops = &hsw_power_well_ops,
  1969. .id = CNL_DISP_PW_AUX_B,
  1970. },
  1971. {
  1972. .name = "AUX C",
  1973. .domains = CNL_DISPLAY_AUX_C_POWER_DOMAINS,
  1974. .ops = &hsw_power_well_ops,
  1975. .id = CNL_DISP_PW_AUX_C,
  1976. },
  1977. {
  1978. .name = "AUX D",
  1979. .domains = CNL_DISPLAY_AUX_D_POWER_DOMAINS,
  1980. .ops = &hsw_power_well_ops,
  1981. .id = CNL_DISP_PW_AUX_D,
  1982. },
  1983. {
  1984. .name = "DC off",
  1985. .domains = CNL_DISPLAY_DC_OFF_POWER_DOMAINS,
  1986. .ops = &gen9_dc_off_power_well_ops,
  1987. .id = SKL_DISP_PW_DC_OFF,
  1988. },
  1989. {
  1990. .name = "power well 2",
  1991. .domains = CNL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
  1992. .ops = &hsw_power_well_ops,
  1993. .id = SKL_DISP_PW_2,
  1994. .hsw.irq_pipe_mask = BIT(PIPE_B) | BIT(PIPE_C),
  1995. .hsw.has_vga = true,
  1996. .hsw.has_fuses = true,
  1997. },
  1998. {
  1999. .name = "DDI A IO power well",
  2000. .domains = CNL_DISPLAY_DDI_A_IO_POWER_DOMAINS,
  2001. .ops = &hsw_power_well_ops,
  2002. .id = CNL_DISP_PW_DDI_A,
  2003. },
  2004. {
  2005. .name = "DDI B IO power well",
  2006. .domains = CNL_DISPLAY_DDI_B_IO_POWER_DOMAINS,
  2007. .ops = &hsw_power_well_ops,
  2008. .id = SKL_DISP_PW_DDI_B,
  2009. },
  2010. {
  2011. .name = "DDI C IO power well",
  2012. .domains = CNL_DISPLAY_DDI_C_IO_POWER_DOMAINS,
  2013. .ops = &hsw_power_well_ops,
  2014. .id = SKL_DISP_PW_DDI_C,
  2015. },
  2016. {
  2017. .name = "DDI D IO power well",
  2018. .domains = CNL_DISPLAY_DDI_D_IO_POWER_DOMAINS,
  2019. .ops = &hsw_power_well_ops,
  2020. .id = SKL_DISP_PW_DDI_D,
  2021. },
  2022. };
  2023. static int
  2024. sanitize_disable_power_well_option(const struct drm_i915_private *dev_priv,
  2025. int disable_power_well)
  2026. {
  2027. if (disable_power_well >= 0)
  2028. return !!disable_power_well;
  2029. return 1;
  2030. }
  2031. static uint32_t get_allowed_dc_mask(const struct drm_i915_private *dev_priv,
  2032. int enable_dc)
  2033. {
  2034. uint32_t mask;
  2035. int requested_dc;
  2036. int max_dc;
  2037. if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
  2038. max_dc = 2;
  2039. mask = 0;
  2040. } else if (IS_GEN9_LP(dev_priv)) {
  2041. max_dc = 1;
  2042. /*
  2043. * DC9 has a separate HW flow from the rest of the DC states,
  2044. * not depending on the DMC firmware. It's needed by system
  2045. * suspend/resume, so allow it unconditionally.
  2046. */
  2047. mask = DC_STATE_EN_DC9;
  2048. } else {
  2049. max_dc = 0;
  2050. mask = 0;
  2051. }
  2052. if (!i915.disable_power_well)
  2053. max_dc = 0;
  2054. if (enable_dc >= 0 && enable_dc <= max_dc) {
  2055. requested_dc = enable_dc;
  2056. } else if (enable_dc == -1) {
  2057. requested_dc = max_dc;
  2058. } else if (enable_dc > max_dc && enable_dc <= 2) {
  2059. DRM_DEBUG_KMS("Adjusting requested max DC state (%d->%d)\n",
  2060. enable_dc, max_dc);
  2061. requested_dc = max_dc;
  2062. } else {
  2063. DRM_ERROR("Unexpected value for enable_dc (%d)\n", enable_dc);
  2064. requested_dc = max_dc;
  2065. }
  2066. if (requested_dc > 1)
  2067. mask |= DC_STATE_EN_UPTO_DC6;
  2068. if (requested_dc > 0)
  2069. mask |= DC_STATE_EN_UPTO_DC5;
  2070. DRM_DEBUG_KMS("Allowed DC state mask %02x\n", mask);
  2071. return mask;
  2072. }
  2073. static void assert_power_well_ids_unique(struct drm_i915_private *dev_priv)
  2074. {
  2075. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2076. u64 power_well_ids;
  2077. int i;
  2078. power_well_ids = 0;
  2079. for (i = 0; i < power_domains->power_well_count; i++) {
  2080. enum i915_power_well_id id = power_domains->power_wells[i].id;
  2081. WARN_ON(id >= sizeof(power_well_ids) * 8);
  2082. WARN_ON(power_well_ids & BIT_ULL(id));
  2083. power_well_ids |= BIT_ULL(id);
  2084. }
  2085. }
  2086. #define set_power_wells(power_domains, __power_wells) ({ \
  2087. (power_domains)->power_wells = (__power_wells); \
  2088. (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
  2089. })
  2090. /**
  2091. * intel_power_domains_init - initializes the power domain structures
  2092. * @dev_priv: i915 device instance
  2093. *
  2094. * Initializes the power domain structures for @dev_priv depending upon the
  2095. * supported platform.
  2096. */
  2097. int intel_power_domains_init(struct drm_i915_private *dev_priv)
  2098. {
  2099. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2100. i915.disable_power_well = sanitize_disable_power_well_option(dev_priv,
  2101. i915.disable_power_well);
  2102. dev_priv->csr.allowed_dc_mask = get_allowed_dc_mask(dev_priv,
  2103. i915.enable_dc);
  2104. BUILD_BUG_ON(POWER_DOMAIN_NUM > 64);
  2105. mutex_init(&power_domains->lock);
  2106. /*
  2107. * The enabling order will be from lower to higher indexed wells,
  2108. * the disabling order is reversed.
  2109. */
  2110. if (IS_HASWELL(dev_priv)) {
  2111. set_power_wells(power_domains, hsw_power_wells);
  2112. } else if (IS_BROADWELL(dev_priv)) {
  2113. set_power_wells(power_domains, bdw_power_wells);
  2114. } else if (IS_GEN9_BC(dev_priv)) {
  2115. set_power_wells(power_domains, skl_power_wells);
  2116. } else if (IS_CANNONLAKE(dev_priv)) {
  2117. set_power_wells(power_domains, cnl_power_wells);
  2118. } else if (IS_BROXTON(dev_priv)) {
  2119. set_power_wells(power_domains, bxt_power_wells);
  2120. } else if (IS_GEMINILAKE(dev_priv)) {
  2121. set_power_wells(power_domains, glk_power_wells);
  2122. } else if (IS_CHERRYVIEW(dev_priv)) {
  2123. set_power_wells(power_domains, chv_power_wells);
  2124. } else if (IS_VALLEYVIEW(dev_priv)) {
  2125. set_power_wells(power_domains, vlv_power_wells);
  2126. } else if (IS_I830(dev_priv)) {
  2127. set_power_wells(power_domains, i830_power_wells);
  2128. } else {
  2129. set_power_wells(power_domains, i9xx_always_on_power_well);
  2130. }
  2131. assert_power_well_ids_unique(dev_priv);
  2132. return 0;
  2133. }
  2134. /**
  2135. * intel_power_domains_fini - finalizes the power domain structures
  2136. * @dev_priv: i915 device instance
  2137. *
  2138. * Finalizes the power domain structures for @dev_priv depending upon the
  2139. * supported platform. This function also disables runtime pm and ensures that
  2140. * the device stays powered up so that the driver can be reloaded.
  2141. */
  2142. void intel_power_domains_fini(struct drm_i915_private *dev_priv)
  2143. {
  2144. struct device *kdev = &dev_priv->drm.pdev->dev;
  2145. /*
  2146. * The i915.ko module is still not prepared to be loaded when
  2147. * the power well is not enabled, so just enable it in case
  2148. * we're going to unload/reload.
  2149. * The following also reacquires the RPM reference the core passed
  2150. * to the driver during loading, which is dropped in
  2151. * intel_runtime_pm_enable(). We have to hand back the control of the
  2152. * device to the core with this reference held.
  2153. */
  2154. intel_display_set_init_power(dev_priv, true);
  2155. /* Remove the refcount we took to keep power well support disabled. */
  2156. if (!i915.disable_power_well)
  2157. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  2158. /*
  2159. * Remove the refcount we took in intel_runtime_pm_enable() in case
  2160. * the platform doesn't support runtime PM.
  2161. */
  2162. if (!HAS_RUNTIME_PM(dev_priv))
  2163. pm_runtime_put(kdev);
  2164. }
  2165. static void intel_power_domains_sync_hw(struct drm_i915_private *dev_priv)
  2166. {
  2167. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2168. struct i915_power_well *power_well;
  2169. mutex_lock(&power_domains->lock);
  2170. for_each_power_well(dev_priv, power_well) {
  2171. power_well->ops->sync_hw(dev_priv, power_well);
  2172. power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
  2173. power_well);
  2174. }
  2175. mutex_unlock(&power_domains->lock);
  2176. }
  2177. static void gen9_dbuf_enable(struct drm_i915_private *dev_priv)
  2178. {
  2179. I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST);
  2180. POSTING_READ(DBUF_CTL);
  2181. udelay(10);
  2182. if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE))
  2183. DRM_ERROR("DBuf power enable timeout\n");
  2184. }
  2185. static void gen9_dbuf_disable(struct drm_i915_private *dev_priv)
  2186. {
  2187. I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST);
  2188. POSTING_READ(DBUF_CTL);
  2189. udelay(10);
  2190. if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE)
  2191. DRM_ERROR("DBuf power disable timeout!\n");
  2192. }
  2193. static void skl_display_core_init(struct drm_i915_private *dev_priv,
  2194. bool resume)
  2195. {
  2196. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2197. struct i915_power_well *well;
  2198. uint32_t val;
  2199. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  2200. /* enable PCH reset handshake */
  2201. val = I915_READ(HSW_NDE_RSTWRN_OPT);
  2202. I915_WRITE(HSW_NDE_RSTWRN_OPT, val | RESET_PCH_HANDSHAKE_ENABLE);
  2203. /* enable PG1 and Misc I/O */
  2204. mutex_lock(&power_domains->lock);
  2205. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  2206. intel_power_well_enable(dev_priv, well);
  2207. well = lookup_power_well(dev_priv, SKL_DISP_PW_MISC_IO);
  2208. intel_power_well_enable(dev_priv, well);
  2209. mutex_unlock(&power_domains->lock);
  2210. skl_init_cdclk(dev_priv);
  2211. gen9_dbuf_enable(dev_priv);
  2212. if (resume && dev_priv->csr.dmc_payload)
  2213. intel_csr_load_program(dev_priv);
  2214. }
  2215. static void skl_display_core_uninit(struct drm_i915_private *dev_priv)
  2216. {
  2217. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2218. struct i915_power_well *well;
  2219. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  2220. gen9_dbuf_disable(dev_priv);
  2221. skl_uninit_cdclk(dev_priv);
  2222. /* The spec doesn't call for removing the reset handshake flag */
  2223. /* disable PG1 and Misc I/O */
  2224. mutex_lock(&power_domains->lock);
  2225. /*
  2226. * BSpec says to keep the MISC IO power well enabled here, only
  2227. * remove our request for power well 1.
  2228. * Note that even though the driver's request is removed power well 1
  2229. * may stay enabled after this due to DMC's own request on it.
  2230. */
  2231. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  2232. intel_power_well_disable(dev_priv, well);
  2233. mutex_unlock(&power_domains->lock);
  2234. usleep_range(10, 30); /* 10 us delay per Bspec */
  2235. }
  2236. void bxt_display_core_init(struct drm_i915_private *dev_priv,
  2237. bool resume)
  2238. {
  2239. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2240. struct i915_power_well *well;
  2241. uint32_t val;
  2242. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  2243. /*
  2244. * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT
  2245. * or else the reset will hang because there is no PCH to respond.
  2246. * Move the handshake programming to initialization sequence.
  2247. * Previously was left up to BIOS.
  2248. */
  2249. val = I915_READ(HSW_NDE_RSTWRN_OPT);
  2250. val &= ~RESET_PCH_HANDSHAKE_ENABLE;
  2251. I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
  2252. /* Enable PG1 */
  2253. mutex_lock(&power_domains->lock);
  2254. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  2255. intel_power_well_enable(dev_priv, well);
  2256. mutex_unlock(&power_domains->lock);
  2257. bxt_init_cdclk(dev_priv);
  2258. gen9_dbuf_enable(dev_priv);
  2259. if (resume && dev_priv->csr.dmc_payload)
  2260. intel_csr_load_program(dev_priv);
  2261. }
  2262. void bxt_display_core_uninit(struct drm_i915_private *dev_priv)
  2263. {
  2264. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2265. struct i915_power_well *well;
  2266. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  2267. gen9_dbuf_disable(dev_priv);
  2268. bxt_uninit_cdclk(dev_priv);
  2269. /* The spec doesn't call for removing the reset handshake flag */
  2270. /*
  2271. * Disable PW1 (PG1).
  2272. * Note that even though the driver's request is removed power well 1
  2273. * may stay enabled after this due to DMC's own request on it.
  2274. */
  2275. mutex_lock(&power_domains->lock);
  2276. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  2277. intel_power_well_disable(dev_priv, well);
  2278. mutex_unlock(&power_domains->lock);
  2279. usleep_range(10, 30); /* 10 us delay per Bspec */
  2280. }
  2281. #define CNL_PROCMON_IDX(val) \
  2282. (((val) & (PROCESS_INFO_MASK | VOLTAGE_INFO_MASK)) >> VOLTAGE_INFO_SHIFT)
  2283. #define NUM_CNL_PROCMON \
  2284. (CNL_PROCMON_IDX(VOLTAGE_INFO_MASK | PROCESS_INFO_MASK) + 1)
  2285. static const struct cnl_procmon {
  2286. u32 dw1, dw9, dw10;
  2287. } cnl_procmon_values[NUM_CNL_PROCMON] = {
  2288. [CNL_PROCMON_IDX(VOLTAGE_INFO_0_85V | PROCESS_INFO_DOT_0)] =
  2289. { .dw1 = 0x00 << 16, .dw9 = 0x62AB67BB, .dw10 = 0x51914F96, },
  2290. [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_0)] =
  2291. { .dw1 = 0x00 << 16, .dw9 = 0x86E172C7, .dw10 = 0x77CA5EAB, },
  2292. [CNL_PROCMON_IDX(VOLTAGE_INFO_0_95V | PROCESS_INFO_DOT_1)] =
  2293. { .dw1 = 0x00 << 16, .dw9 = 0x93F87FE1, .dw10 = 0x8AE871C5, },
  2294. [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_0)] =
  2295. { .dw1 = 0x00 << 16, .dw9 = 0x98FA82DD, .dw10 = 0x89E46DC1, },
  2296. [CNL_PROCMON_IDX(VOLTAGE_INFO_1_05V | PROCESS_INFO_DOT_1)] =
  2297. { .dw1 = 0x44 << 16, .dw9 = 0x9A00AB25, .dw10 = 0x8AE38FF1, },
  2298. };
  2299. static void cnl_display_core_init(struct drm_i915_private *dev_priv, bool resume)
  2300. {
  2301. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2302. const struct cnl_procmon *procmon;
  2303. struct i915_power_well *well;
  2304. u32 val;
  2305. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  2306. /* 1. Enable PCH Reset Handshake */
  2307. val = I915_READ(HSW_NDE_RSTWRN_OPT);
  2308. val |= RESET_PCH_HANDSHAKE_ENABLE;
  2309. I915_WRITE(HSW_NDE_RSTWRN_OPT, val);
  2310. /* 2. Enable Comp */
  2311. val = I915_READ(CHICKEN_MISC_2);
  2312. val &= ~CNL_COMP_PWR_DOWN;
  2313. I915_WRITE(CHICKEN_MISC_2, val);
  2314. val = I915_READ(CNL_PORT_COMP_DW3);
  2315. procmon = &cnl_procmon_values[CNL_PROCMON_IDX(val)];
  2316. WARN_ON(procmon->dw10 == 0);
  2317. val = I915_READ(CNL_PORT_COMP_DW1);
  2318. val &= ~((0xff << 16) | 0xff);
  2319. val |= procmon->dw1;
  2320. I915_WRITE(CNL_PORT_COMP_DW1, val);
  2321. I915_WRITE(CNL_PORT_COMP_DW9, procmon->dw9);
  2322. I915_WRITE(CNL_PORT_COMP_DW10, procmon->dw10);
  2323. val = I915_READ(CNL_PORT_COMP_DW0);
  2324. val |= COMP_INIT;
  2325. I915_WRITE(CNL_PORT_COMP_DW0, val);
  2326. /* 3. */
  2327. val = I915_READ(CNL_PORT_CL1CM_DW5);
  2328. val |= CL_POWER_DOWN_ENABLE;
  2329. I915_WRITE(CNL_PORT_CL1CM_DW5, val);
  2330. /*
  2331. * 4. Enable Power Well 1 (PG1).
  2332. * The AUX IO power wells will be enabled on demand.
  2333. */
  2334. mutex_lock(&power_domains->lock);
  2335. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  2336. intel_power_well_enable(dev_priv, well);
  2337. mutex_unlock(&power_domains->lock);
  2338. /* 5. Enable CD clock */
  2339. cnl_init_cdclk(dev_priv);
  2340. /* 6. Enable DBUF */
  2341. gen9_dbuf_enable(dev_priv);
  2342. }
  2343. #undef CNL_PROCMON_IDX
  2344. #undef NUM_CNL_PROCMON
  2345. static void cnl_display_core_uninit(struct drm_i915_private *dev_priv)
  2346. {
  2347. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2348. struct i915_power_well *well;
  2349. u32 val;
  2350. gen9_set_dc_state(dev_priv, DC_STATE_DISABLE);
  2351. /* 1. Disable all display engine functions -> aready done */
  2352. /* 2. Disable DBUF */
  2353. gen9_dbuf_disable(dev_priv);
  2354. /* 3. Disable CD clock */
  2355. cnl_uninit_cdclk(dev_priv);
  2356. /*
  2357. * 4. Disable Power Well 1 (PG1).
  2358. * The AUX IO power wells are toggled on demand, so they are already
  2359. * disabled at this point.
  2360. */
  2361. mutex_lock(&power_domains->lock);
  2362. well = lookup_power_well(dev_priv, SKL_DISP_PW_1);
  2363. intel_power_well_disable(dev_priv, well);
  2364. mutex_unlock(&power_domains->lock);
  2365. usleep_range(10, 30); /* 10 us delay per Bspec */
  2366. /* 5. Disable Comp */
  2367. val = I915_READ(CHICKEN_MISC_2);
  2368. val |= CNL_COMP_PWR_DOWN;
  2369. I915_WRITE(CHICKEN_MISC_2, val);
  2370. }
  2371. static void chv_phy_control_init(struct drm_i915_private *dev_priv)
  2372. {
  2373. struct i915_power_well *cmn_bc =
  2374. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
  2375. struct i915_power_well *cmn_d =
  2376. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
  2377. /*
  2378. * DISPLAY_PHY_CONTROL can get corrupted if read. As a
  2379. * workaround never ever read DISPLAY_PHY_CONTROL, and
  2380. * instead maintain a shadow copy ourselves. Use the actual
  2381. * power well state and lane status to reconstruct the
  2382. * expected initial value.
  2383. */
  2384. dev_priv->chv_phy_control =
  2385. PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
  2386. PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
  2387. PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH0) |
  2388. PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY0, DPIO_CH1) |
  2389. PHY_CH_POWER_MODE(PHY_CH_DEEP_PSR, DPIO_PHY1, DPIO_CH0);
  2390. /*
  2391. * If all lanes are disabled we leave the override disabled
  2392. * with all power down bits cleared to match the state we
  2393. * would use after disabling the port. Otherwise enable the
  2394. * override and set the lane powerdown bits accding to the
  2395. * current lane status.
  2396. */
  2397. if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc)) {
  2398. uint32_t status = I915_READ(DPLL(PIPE_A));
  2399. unsigned int mask;
  2400. mask = status & DPLL_PORTB_READY_MASK;
  2401. if (mask == 0xf)
  2402. mask = 0x0;
  2403. else
  2404. dev_priv->chv_phy_control |=
  2405. PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH0);
  2406. dev_priv->chv_phy_control |=
  2407. PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH0);
  2408. mask = (status & DPLL_PORTC_READY_MASK) >> 4;
  2409. if (mask == 0xf)
  2410. mask = 0x0;
  2411. else
  2412. dev_priv->chv_phy_control |=
  2413. PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY0, DPIO_CH1);
  2414. dev_priv->chv_phy_control |=
  2415. PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY0, DPIO_CH1);
  2416. dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
  2417. dev_priv->chv_phy_assert[DPIO_PHY0] = false;
  2418. } else {
  2419. dev_priv->chv_phy_assert[DPIO_PHY0] = true;
  2420. }
  2421. if (cmn_d->ops->is_enabled(dev_priv, cmn_d)) {
  2422. uint32_t status = I915_READ(DPIO_PHY_STATUS);
  2423. unsigned int mask;
  2424. mask = status & DPLL_PORTD_READY_MASK;
  2425. if (mask == 0xf)
  2426. mask = 0x0;
  2427. else
  2428. dev_priv->chv_phy_control |=
  2429. PHY_CH_POWER_DOWN_OVRD_EN(DPIO_PHY1, DPIO_CH0);
  2430. dev_priv->chv_phy_control |=
  2431. PHY_CH_POWER_DOWN_OVRD(mask, DPIO_PHY1, DPIO_CH0);
  2432. dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
  2433. dev_priv->chv_phy_assert[DPIO_PHY1] = false;
  2434. } else {
  2435. dev_priv->chv_phy_assert[DPIO_PHY1] = true;
  2436. }
  2437. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  2438. DRM_DEBUG_KMS("Initial PHY_CONTROL=0x%08x\n",
  2439. dev_priv->chv_phy_control);
  2440. }
  2441. static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
  2442. {
  2443. struct i915_power_well *cmn =
  2444. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
  2445. struct i915_power_well *disp2d =
  2446. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
  2447. /* If the display might be already active skip this */
  2448. if (cmn->ops->is_enabled(dev_priv, cmn) &&
  2449. disp2d->ops->is_enabled(dev_priv, disp2d) &&
  2450. I915_READ(DPIO_CTL) & DPIO_CMNRST)
  2451. return;
  2452. DRM_DEBUG_KMS("toggling display PHY side reset\n");
  2453. /* cmnlane needs DPLL registers */
  2454. disp2d->ops->enable(dev_priv, disp2d);
  2455. /*
  2456. * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
  2457. * Need to assert and de-assert PHY SB reset by gating the
  2458. * common lane power, then un-gating it.
  2459. * Simply ungating isn't enough to reset the PHY enough to get
  2460. * ports and lanes running.
  2461. */
  2462. cmn->ops->disable(dev_priv, cmn);
  2463. }
  2464. /**
  2465. * intel_power_domains_init_hw - initialize hardware power domain state
  2466. * @dev_priv: i915 device instance
  2467. * @resume: Called from resume code paths or not
  2468. *
  2469. * This function initializes the hardware power domain state and enables all
  2470. * power wells belonging to the INIT power domain. Power wells in other
  2471. * domains (and not in the INIT domain) are referenced or disabled during the
  2472. * modeset state HW readout. After that the reference count of each power well
  2473. * must match its HW enabled state, see intel_power_domains_verify_state().
  2474. */
  2475. void intel_power_domains_init_hw(struct drm_i915_private *dev_priv, bool resume)
  2476. {
  2477. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2478. power_domains->initializing = true;
  2479. if (IS_CANNONLAKE(dev_priv)) {
  2480. cnl_display_core_init(dev_priv, resume);
  2481. } else if (IS_GEN9_BC(dev_priv)) {
  2482. skl_display_core_init(dev_priv, resume);
  2483. } else if (IS_GEN9_LP(dev_priv)) {
  2484. bxt_display_core_init(dev_priv, resume);
  2485. } else if (IS_CHERRYVIEW(dev_priv)) {
  2486. mutex_lock(&power_domains->lock);
  2487. chv_phy_control_init(dev_priv);
  2488. mutex_unlock(&power_domains->lock);
  2489. } else if (IS_VALLEYVIEW(dev_priv)) {
  2490. mutex_lock(&power_domains->lock);
  2491. vlv_cmnlane_wa(dev_priv);
  2492. mutex_unlock(&power_domains->lock);
  2493. }
  2494. /* For now, we need the power well to be always enabled. */
  2495. intel_display_set_init_power(dev_priv, true);
  2496. /* Disable power support if the user asked so. */
  2497. if (!i915.disable_power_well)
  2498. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  2499. intel_power_domains_sync_hw(dev_priv);
  2500. power_domains->initializing = false;
  2501. }
  2502. /**
  2503. * intel_power_domains_suspend - suspend power domain state
  2504. * @dev_priv: i915 device instance
  2505. *
  2506. * This function prepares the hardware power domain state before entering
  2507. * system suspend. It must be paired with intel_power_domains_init_hw().
  2508. */
  2509. void intel_power_domains_suspend(struct drm_i915_private *dev_priv)
  2510. {
  2511. /*
  2512. * Even if power well support was disabled we still want to disable
  2513. * power wells while we are system suspended.
  2514. */
  2515. if (!i915.disable_power_well)
  2516. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  2517. if (IS_CANNONLAKE(dev_priv))
  2518. cnl_display_core_uninit(dev_priv);
  2519. else if (IS_GEN9_BC(dev_priv))
  2520. skl_display_core_uninit(dev_priv);
  2521. else if (IS_GEN9_LP(dev_priv))
  2522. bxt_display_core_uninit(dev_priv);
  2523. }
  2524. static void intel_power_domains_dump_info(struct drm_i915_private *dev_priv)
  2525. {
  2526. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2527. struct i915_power_well *power_well;
  2528. for_each_power_well(dev_priv, power_well) {
  2529. enum intel_display_power_domain domain;
  2530. DRM_DEBUG_DRIVER("%-25s %d\n",
  2531. power_well->name, power_well->count);
  2532. for_each_power_domain(domain, power_well->domains)
  2533. DRM_DEBUG_DRIVER(" %-23s %d\n",
  2534. intel_display_power_domain_str(domain),
  2535. power_domains->domain_use_count[domain]);
  2536. }
  2537. }
  2538. /**
  2539. * intel_power_domains_verify_state - verify the HW/SW state for all power wells
  2540. * @dev_priv: i915 device instance
  2541. *
  2542. * Verify if the reference count of each power well matches its HW enabled
  2543. * state and the total refcount of the domains it belongs to. This must be
  2544. * called after modeset HW state sanitization, which is responsible for
  2545. * acquiring reference counts for any power wells in use and disabling the
  2546. * ones left on by BIOS but not required by any active output.
  2547. */
  2548. void intel_power_domains_verify_state(struct drm_i915_private *dev_priv)
  2549. {
  2550. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  2551. struct i915_power_well *power_well;
  2552. bool dump_domain_info;
  2553. mutex_lock(&power_domains->lock);
  2554. dump_domain_info = false;
  2555. for_each_power_well(dev_priv, power_well) {
  2556. enum intel_display_power_domain domain;
  2557. int domains_count;
  2558. bool enabled;
  2559. /*
  2560. * Power wells not belonging to any domain (like the MISC_IO
  2561. * and PW1 power wells) are under FW control, so ignore them,
  2562. * since their state can change asynchronously.
  2563. */
  2564. if (!power_well->domains)
  2565. continue;
  2566. enabled = power_well->ops->is_enabled(dev_priv, power_well);
  2567. if ((power_well->count || power_well->always_on) != enabled)
  2568. DRM_ERROR("power well %s state mismatch (refcount %d/enabled %d)",
  2569. power_well->name, power_well->count, enabled);
  2570. domains_count = 0;
  2571. for_each_power_domain(domain, power_well->domains)
  2572. domains_count += power_domains->domain_use_count[domain];
  2573. if (power_well->count != domains_count) {
  2574. DRM_ERROR("power well %s refcount/domain refcount mismatch "
  2575. "(refcount %d/domains refcount %d)\n",
  2576. power_well->name, power_well->count,
  2577. domains_count);
  2578. dump_domain_info = true;
  2579. }
  2580. }
  2581. if (dump_domain_info) {
  2582. static bool dumped;
  2583. if (!dumped) {
  2584. intel_power_domains_dump_info(dev_priv);
  2585. dumped = true;
  2586. }
  2587. }
  2588. mutex_unlock(&power_domains->lock);
  2589. }
  2590. /**
  2591. * intel_runtime_pm_get - grab a runtime pm reference
  2592. * @dev_priv: i915 device instance
  2593. *
  2594. * This function grabs a device-level runtime pm reference (mostly used for GEM
  2595. * code to ensure the GTT or GT is on) and ensures that it is powered up.
  2596. *
  2597. * Any runtime pm reference obtained by this function must have a symmetric
  2598. * call to intel_runtime_pm_put() to release the reference again.
  2599. */
  2600. void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
  2601. {
  2602. struct pci_dev *pdev = dev_priv->drm.pdev;
  2603. struct device *kdev = &pdev->dev;
  2604. int ret;
  2605. ret = pm_runtime_get_sync(kdev);
  2606. WARN_ONCE(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
  2607. atomic_inc(&dev_priv->pm.wakeref_count);
  2608. assert_rpm_wakelock_held(dev_priv);
  2609. }
  2610. /**
  2611. * intel_runtime_pm_get_if_in_use - grab a runtime pm reference if device in use
  2612. * @dev_priv: i915 device instance
  2613. *
  2614. * This function grabs a device-level runtime pm reference if the device is
  2615. * already in use and ensures that it is powered up.
  2616. *
  2617. * Any runtime pm reference obtained by this function must have a symmetric
  2618. * call to intel_runtime_pm_put() to release the reference again.
  2619. */
  2620. bool intel_runtime_pm_get_if_in_use(struct drm_i915_private *dev_priv)
  2621. {
  2622. struct pci_dev *pdev = dev_priv->drm.pdev;
  2623. struct device *kdev = &pdev->dev;
  2624. if (IS_ENABLED(CONFIG_PM)) {
  2625. int ret = pm_runtime_get_if_in_use(kdev);
  2626. /*
  2627. * In cases runtime PM is disabled by the RPM core and we get
  2628. * an -EINVAL return value we are not supposed to call this
  2629. * function, since the power state is undefined. This applies
  2630. * atm to the late/early system suspend/resume handlers.
  2631. */
  2632. WARN_ONCE(ret < 0,
  2633. "pm_runtime_get_if_in_use() failed: %d\n", ret);
  2634. if (ret <= 0)
  2635. return false;
  2636. }
  2637. atomic_inc(&dev_priv->pm.wakeref_count);
  2638. assert_rpm_wakelock_held(dev_priv);
  2639. return true;
  2640. }
  2641. /**
  2642. * intel_runtime_pm_get_noresume - grab a runtime pm reference
  2643. * @dev_priv: i915 device instance
  2644. *
  2645. * This function grabs a device-level runtime pm reference (mostly used for GEM
  2646. * code to ensure the GTT or GT is on).
  2647. *
  2648. * It will _not_ power up the device but instead only check that it's powered
  2649. * on. Therefore it is only valid to call this functions from contexts where
  2650. * the device is known to be powered up and where trying to power it up would
  2651. * result in hilarity and deadlocks. That pretty much means only the system
  2652. * suspend/resume code where this is used to grab runtime pm references for
  2653. * delayed setup down in work items.
  2654. *
  2655. * Any runtime pm reference obtained by this function must have a symmetric
  2656. * call to intel_runtime_pm_put() to release the reference again.
  2657. */
  2658. void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
  2659. {
  2660. struct pci_dev *pdev = dev_priv->drm.pdev;
  2661. struct device *kdev = &pdev->dev;
  2662. assert_rpm_wakelock_held(dev_priv);
  2663. pm_runtime_get_noresume(kdev);
  2664. atomic_inc(&dev_priv->pm.wakeref_count);
  2665. }
  2666. /**
  2667. * intel_runtime_pm_put - release a runtime pm reference
  2668. * @dev_priv: i915 device instance
  2669. *
  2670. * This function drops the device-level runtime pm reference obtained by
  2671. * intel_runtime_pm_get() and might power down the corresponding
  2672. * hardware block right away if this is the last reference.
  2673. */
  2674. void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
  2675. {
  2676. struct pci_dev *pdev = dev_priv->drm.pdev;
  2677. struct device *kdev = &pdev->dev;
  2678. assert_rpm_wakelock_held(dev_priv);
  2679. atomic_dec(&dev_priv->pm.wakeref_count);
  2680. pm_runtime_mark_last_busy(kdev);
  2681. pm_runtime_put_autosuspend(kdev);
  2682. }
  2683. /**
  2684. * intel_runtime_pm_enable - enable runtime pm
  2685. * @dev_priv: i915 device instance
  2686. *
  2687. * This function enables runtime pm at the end of the driver load sequence.
  2688. *
  2689. * Note that this function does currently not enable runtime pm for the
  2690. * subordinate display power domains. That is only done on the first modeset
  2691. * using intel_display_set_init_power().
  2692. */
  2693. void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
  2694. {
  2695. struct pci_dev *pdev = dev_priv->drm.pdev;
  2696. struct device *kdev = &pdev->dev;
  2697. pm_runtime_set_autosuspend_delay(kdev, 10000); /* 10s */
  2698. pm_runtime_mark_last_busy(kdev);
  2699. /*
  2700. * Take a permanent reference to disable the RPM functionality and drop
  2701. * it only when unloading the driver. Use the low level get/put helpers,
  2702. * so the driver's own RPM reference tracking asserts also work on
  2703. * platforms without RPM support.
  2704. */
  2705. if (!HAS_RUNTIME_PM(dev_priv)) {
  2706. int ret;
  2707. pm_runtime_dont_use_autosuspend(kdev);
  2708. ret = pm_runtime_get_sync(kdev);
  2709. WARN(ret < 0, "pm_runtime_get_sync() failed: %d\n", ret);
  2710. } else {
  2711. pm_runtime_use_autosuspend(kdev);
  2712. }
  2713. /*
  2714. * The core calls the driver load handler with an RPM reference held.
  2715. * We drop that here and will reacquire it during unloading in
  2716. * intel_power_domains_fini().
  2717. */
  2718. pm_runtime_put_autosuspend(kdev);
  2719. }