intel_runtime_pm.c 100 KB

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