intel_runtime_pm.c 94 KB

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