intel_runtime_pm.c 102 KB

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