intel_runtime_pm.c 95 KB

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