intel_runtime_pm.c 96 KB

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