intel_runtime_pm.c 95 KB

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