intel_runtime_pm.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839
  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. #define GEN9_ENABLE_DC5(dev) 0
  49. #define SKL_ENABLE_DC6(dev) IS_SKYLAKE(dev)
  50. #define for_each_power_well(i, power_well, domain_mask, power_domains) \
  51. for (i = 0; \
  52. i < (power_domains)->power_well_count && \
  53. ((power_well) = &(power_domains)->power_wells[i]); \
  54. i++) \
  55. if ((power_well)->domains & (domain_mask))
  56. #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \
  57. for (i = (power_domains)->power_well_count - 1; \
  58. i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\
  59. i--) \
  60. if ((power_well)->domains & (domain_mask))
  61. bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
  62. int power_well_id);
  63. static void intel_power_well_enable(struct drm_i915_private *dev_priv,
  64. struct i915_power_well *power_well)
  65. {
  66. DRM_DEBUG_KMS("enabling %s\n", power_well->name);
  67. power_well->ops->enable(dev_priv, power_well);
  68. power_well->hw_enabled = true;
  69. }
  70. static void intel_power_well_disable(struct drm_i915_private *dev_priv,
  71. struct i915_power_well *power_well)
  72. {
  73. DRM_DEBUG_KMS("disabling %s\n", power_well->name);
  74. power_well->hw_enabled = false;
  75. power_well->ops->disable(dev_priv, power_well);
  76. }
  77. /*
  78. * We should only use the power well if we explicitly asked the hardware to
  79. * enable it, so check if it's enabled and also check if we've requested it to
  80. * be enabled.
  81. */
  82. static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
  83. struct i915_power_well *power_well)
  84. {
  85. return I915_READ(HSW_PWR_WELL_DRIVER) ==
  86. (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
  87. }
  88. /**
  89. * __intel_display_power_is_enabled - unlocked check for a power domain
  90. * @dev_priv: i915 device instance
  91. * @domain: power domain to check
  92. *
  93. * This is the unlocked version of intel_display_power_is_enabled() and should
  94. * only be used from error capture and recovery code where deadlocks are
  95. * possible.
  96. *
  97. * Returns:
  98. * True when the power domain is enabled, false otherwise.
  99. */
  100. bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
  101. enum intel_display_power_domain domain)
  102. {
  103. struct i915_power_domains *power_domains;
  104. struct i915_power_well *power_well;
  105. bool is_enabled;
  106. int i;
  107. if (dev_priv->pm.suspended)
  108. return false;
  109. power_domains = &dev_priv->power_domains;
  110. is_enabled = true;
  111. for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
  112. if (power_well->always_on)
  113. continue;
  114. if (!power_well->hw_enabled) {
  115. is_enabled = false;
  116. break;
  117. }
  118. }
  119. return is_enabled;
  120. }
  121. /**
  122. * intel_display_power_is_enabled - check for a power domain
  123. * @dev_priv: i915 device instance
  124. * @domain: power domain to check
  125. *
  126. * This function can be used to check the hw power domain state. It is mostly
  127. * used in hardware state readout functions. Everywhere else code should rely
  128. * upon explicit power domain reference counting to ensure that the hardware
  129. * block is powered up before accessing it.
  130. *
  131. * Callers must hold the relevant modesetting locks to ensure that concurrent
  132. * threads can't disable the power well while the caller tries to read a few
  133. * registers.
  134. *
  135. * Returns:
  136. * True when the power domain is enabled, false otherwise.
  137. */
  138. bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
  139. enum intel_display_power_domain domain)
  140. {
  141. struct i915_power_domains *power_domains;
  142. bool ret;
  143. power_domains = &dev_priv->power_domains;
  144. mutex_lock(&power_domains->lock);
  145. ret = __intel_display_power_is_enabled(dev_priv, domain);
  146. mutex_unlock(&power_domains->lock);
  147. return ret;
  148. }
  149. /**
  150. * intel_display_set_init_power - set the initial power domain state
  151. * @dev_priv: i915 device instance
  152. * @enable: whether to enable or disable the initial power domain state
  153. *
  154. * For simplicity our driver load/unload and system suspend/resume code assumes
  155. * that all power domains are always enabled. This functions controls the state
  156. * of this little hack. While the initial power domain state is enabled runtime
  157. * pm is effectively disabled.
  158. */
  159. void intel_display_set_init_power(struct drm_i915_private *dev_priv,
  160. bool enable)
  161. {
  162. if (dev_priv->power_domains.init_power_on == enable)
  163. return;
  164. if (enable)
  165. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  166. else
  167. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  168. dev_priv->power_domains.init_power_on = enable;
  169. }
  170. /*
  171. * Starting with Haswell, we have a "Power Down Well" that can be turned off
  172. * when not needed anymore. We have 4 registers that can request the power well
  173. * to be enabled, and it will only be disabled if none of the registers is
  174. * requesting it to be enabled.
  175. */
  176. static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
  177. {
  178. struct drm_device *dev = dev_priv->dev;
  179. /*
  180. * After we re-enable the power well, if we touch VGA register 0x3d5
  181. * we'll get unclaimed register interrupts. This stops after we write
  182. * anything to the VGA MSR register. The vgacon module uses this
  183. * register all the time, so if we unbind our driver and, as a
  184. * consequence, bind vgacon, we'll get stuck in an infinite loop at
  185. * console_unlock(). So make here we touch the VGA MSR register, making
  186. * sure vgacon can keep working normally without triggering interrupts
  187. * and error messages.
  188. */
  189. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  190. outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
  191. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  192. if (IS_BROADWELL(dev))
  193. gen8_irq_power_well_post_enable(dev_priv,
  194. 1 << PIPE_C | 1 << PIPE_B);
  195. }
  196. static void skl_power_well_post_enable(struct drm_i915_private *dev_priv,
  197. struct i915_power_well *power_well)
  198. {
  199. struct drm_device *dev = dev_priv->dev;
  200. /*
  201. * After we re-enable the power well, if we touch VGA register 0x3d5
  202. * we'll get unclaimed register interrupts. This stops after we write
  203. * anything to the VGA MSR register. The vgacon module uses this
  204. * register all the time, so if we unbind our driver and, as a
  205. * consequence, bind vgacon, we'll get stuck in an infinite loop at
  206. * console_unlock(). So make here we touch the VGA MSR register, making
  207. * sure vgacon can keep working normally without triggering interrupts
  208. * and error messages.
  209. */
  210. if (power_well->data == SKL_DISP_PW_2) {
  211. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  212. outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
  213. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  214. gen8_irq_power_well_post_enable(dev_priv,
  215. 1 << PIPE_C | 1 << PIPE_B);
  216. }
  217. if (power_well->data == SKL_DISP_PW_1) {
  218. intel_prepare_ddi(dev);
  219. gen8_irq_power_well_post_enable(dev_priv, 1 << PIPE_A);
  220. }
  221. }
  222. static void hsw_set_power_well(struct drm_i915_private *dev_priv,
  223. struct i915_power_well *power_well, bool enable)
  224. {
  225. bool is_enabled, enable_requested;
  226. uint32_t tmp;
  227. tmp = I915_READ(HSW_PWR_WELL_DRIVER);
  228. is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
  229. enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
  230. if (enable) {
  231. if (!enable_requested)
  232. I915_WRITE(HSW_PWR_WELL_DRIVER,
  233. HSW_PWR_WELL_ENABLE_REQUEST);
  234. if (!is_enabled) {
  235. DRM_DEBUG_KMS("Enabling power well\n");
  236. if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
  237. HSW_PWR_WELL_STATE_ENABLED), 20))
  238. DRM_ERROR("Timeout enabling power well\n");
  239. hsw_power_well_post_enable(dev_priv);
  240. }
  241. } else {
  242. if (enable_requested) {
  243. I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
  244. POSTING_READ(HSW_PWR_WELL_DRIVER);
  245. DRM_DEBUG_KMS("Requesting to disable the power well\n");
  246. }
  247. }
  248. }
  249. #define SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
  250. BIT(POWER_DOMAIN_TRANSCODER_A) | \
  251. BIT(POWER_DOMAIN_PIPE_B) | \
  252. BIT(POWER_DOMAIN_TRANSCODER_B) | \
  253. BIT(POWER_DOMAIN_PIPE_C) | \
  254. BIT(POWER_DOMAIN_TRANSCODER_C) | \
  255. BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  256. BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  257. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  258. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  259. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  260. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  261. BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
  262. BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
  263. BIT(POWER_DOMAIN_PORT_DDI_E_2_LANES) | \
  264. BIT(POWER_DOMAIN_AUX_B) | \
  265. BIT(POWER_DOMAIN_AUX_C) | \
  266. BIT(POWER_DOMAIN_AUX_D) | \
  267. BIT(POWER_DOMAIN_AUDIO) | \
  268. BIT(POWER_DOMAIN_VGA) | \
  269. BIT(POWER_DOMAIN_INIT))
  270. #define SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
  271. SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  272. BIT(POWER_DOMAIN_PLLS) | \
  273. BIT(POWER_DOMAIN_PIPE_A) | \
  274. BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
  275. BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
  276. BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
  277. BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
  278. BIT(POWER_DOMAIN_AUX_A) | \
  279. BIT(POWER_DOMAIN_INIT))
  280. #define SKL_DISPLAY_DDI_A_E_POWER_DOMAINS ( \
  281. BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
  282. BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
  283. BIT(POWER_DOMAIN_PORT_DDI_E_2_LANES) | \
  284. BIT(POWER_DOMAIN_INIT))
  285. #define SKL_DISPLAY_DDI_B_POWER_DOMAINS ( \
  286. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  287. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  288. BIT(POWER_DOMAIN_INIT))
  289. #define SKL_DISPLAY_DDI_C_POWER_DOMAINS ( \
  290. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  291. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  292. BIT(POWER_DOMAIN_INIT))
  293. #define SKL_DISPLAY_DDI_D_POWER_DOMAINS ( \
  294. BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
  295. BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
  296. BIT(POWER_DOMAIN_INIT))
  297. #define SKL_DISPLAY_MISC_IO_POWER_DOMAINS ( \
  298. SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
  299. BIT(POWER_DOMAIN_PLLS) | \
  300. BIT(POWER_DOMAIN_INIT))
  301. #define SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
  302. (POWER_DOMAIN_MASK & ~(SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
  303. SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  304. SKL_DISPLAY_DDI_A_E_POWER_DOMAINS | \
  305. SKL_DISPLAY_DDI_B_POWER_DOMAINS | \
  306. SKL_DISPLAY_DDI_C_POWER_DOMAINS | \
  307. SKL_DISPLAY_DDI_D_POWER_DOMAINS | \
  308. SKL_DISPLAY_MISC_IO_POWER_DOMAINS)) | \
  309. BIT(POWER_DOMAIN_INIT))
  310. #define BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS ( \
  311. BIT(POWER_DOMAIN_TRANSCODER_A) | \
  312. BIT(POWER_DOMAIN_PIPE_B) | \
  313. BIT(POWER_DOMAIN_TRANSCODER_B) | \
  314. BIT(POWER_DOMAIN_PIPE_C) | \
  315. BIT(POWER_DOMAIN_TRANSCODER_C) | \
  316. BIT(POWER_DOMAIN_PIPE_B_PANEL_FITTER) | \
  317. BIT(POWER_DOMAIN_PIPE_C_PANEL_FITTER) | \
  318. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  319. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  320. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  321. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  322. BIT(POWER_DOMAIN_AUX_B) | \
  323. BIT(POWER_DOMAIN_AUX_C) | \
  324. BIT(POWER_DOMAIN_AUDIO) | \
  325. BIT(POWER_DOMAIN_VGA) | \
  326. BIT(POWER_DOMAIN_INIT))
  327. #define BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS ( \
  328. BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS | \
  329. BIT(POWER_DOMAIN_PIPE_A) | \
  330. BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
  331. BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER) | \
  332. BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
  333. BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
  334. BIT(POWER_DOMAIN_AUX_A) | \
  335. BIT(POWER_DOMAIN_PLLS) | \
  336. BIT(POWER_DOMAIN_INIT))
  337. #define BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS ( \
  338. (POWER_DOMAIN_MASK & ~(BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS | \
  339. BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS)) | \
  340. BIT(POWER_DOMAIN_INIT))
  341. static void assert_can_enable_dc9(struct drm_i915_private *dev_priv)
  342. {
  343. struct drm_device *dev = dev_priv->dev;
  344. WARN(!IS_BROXTON(dev), "Platform doesn't support DC9.\n");
  345. WARN((I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
  346. "DC9 already programmed to be enabled.\n");
  347. WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
  348. "DC5 still not disabled to enable DC9.\n");
  349. WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on.\n");
  350. WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
  351. /*
  352. * TODO: check for the following to verify the conditions to enter DC9
  353. * state are satisfied:
  354. * 1] Check relevant display engine registers to verify if mode set
  355. * disable sequence was followed.
  356. * 2] Check if display uninitialize sequence is initialized.
  357. */
  358. }
  359. static void assert_can_disable_dc9(struct drm_i915_private *dev_priv)
  360. {
  361. WARN(intel_irqs_enabled(dev_priv), "Interrupts not disabled yet.\n");
  362. WARN(!(I915_READ(DC_STATE_EN) & DC_STATE_EN_DC9),
  363. "DC9 already programmed to be disabled.\n");
  364. WARN(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5,
  365. "DC5 still not disabled.\n");
  366. /*
  367. * TODO: check for the following to verify DC9 state was indeed
  368. * entered before programming to disable it:
  369. * 1] Check relevant display engine registers to verify if mode
  370. * set disable sequence was followed.
  371. * 2] Check if display uninitialize sequence is initialized.
  372. */
  373. }
  374. void bxt_enable_dc9(struct drm_i915_private *dev_priv)
  375. {
  376. uint32_t val;
  377. assert_can_enable_dc9(dev_priv);
  378. DRM_DEBUG_KMS("Enabling DC9\n");
  379. val = I915_READ(DC_STATE_EN);
  380. val |= DC_STATE_EN_DC9;
  381. I915_WRITE(DC_STATE_EN, val);
  382. POSTING_READ(DC_STATE_EN);
  383. }
  384. void bxt_disable_dc9(struct drm_i915_private *dev_priv)
  385. {
  386. uint32_t val;
  387. assert_can_disable_dc9(dev_priv);
  388. DRM_DEBUG_KMS("Disabling DC9\n");
  389. val = I915_READ(DC_STATE_EN);
  390. val &= ~DC_STATE_EN_DC9;
  391. I915_WRITE(DC_STATE_EN, val);
  392. POSTING_READ(DC_STATE_EN);
  393. }
  394. static void gen9_set_dc_state_debugmask_memory_up(
  395. struct drm_i915_private *dev_priv)
  396. {
  397. uint32_t val;
  398. /* The below bit doesn't need to be cleared ever afterwards */
  399. val = I915_READ(DC_STATE_DEBUG);
  400. if (!(val & DC_STATE_DEBUG_MASK_MEMORY_UP)) {
  401. val |= DC_STATE_DEBUG_MASK_MEMORY_UP;
  402. I915_WRITE(DC_STATE_DEBUG, val);
  403. POSTING_READ(DC_STATE_DEBUG);
  404. }
  405. }
  406. static void assert_can_enable_dc5(struct drm_i915_private *dev_priv)
  407. {
  408. struct drm_device *dev = dev_priv->dev;
  409. bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
  410. SKL_DISP_PW_2);
  411. WARN(!IS_SKYLAKE(dev), "Platform doesn't support DC5.\n");
  412. WARN(!HAS_RUNTIME_PM(dev), "Runtime PM not enabled.\n");
  413. WARN(pg2_enabled, "PG2 not disabled to enable DC5.\n");
  414. WARN((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC5),
  415. "DC5 already programmed to be enabled.\n");
  416. WARN(dev_priv->pm.suspended,
  417. "DC5 cannot be enabled, if platform is runtime-suspended.\n");
  418. assert_csr_loaded(dev_priv);
  419. }
  420. static void assert_can_disable_dc5(struct drm_i915_private *dev_priv)
  421. {
  422. bool pg2_enabled = intel_display_power_well_is_enabled(dev_priv,
  423. SKL_DISP_PW_2);
  424. /*
  425. * During initialization, the firmware may not be loaded yet.
  426. * We still want to make sure that the DC enabling flag is cleared.
  427. */
  428. if (dev_priv->power_domains.initializing)
  429. return;
  430. WARN(!pg2_enabled, "PG2 not enabled to disable DC5.\n");
  431. WARN(dev_priv->pm.suspended,
  432. "Disabling of DC5 while platform is runtime-suspended should never happen.\n");
  433. }
  434. static void gen9_enable_dc5(struct drm_i915_private *dev_priv)
  435. {
  436. uint32_t val;
  437. assert_can_enable_dc5(dev_priv);
  438. DRM_DEBUG_KMS("Enabling DC5\n");
  439. gen9_set_dc_state_debugmask_memory_up(dev_priv);
  440. val = I915_READ(DC_STATE_EN);
  441. val &= ~DC_STATE_EN_UPTO_DC5_DC6_MASK;
  442. val |= DC_STATE_EN_UPTO_DC5;
  443. I915_WRITE(DC_STATE_EN, val);
  444. POSTING_READ(DC_STATE_EN);
  445. }
  446. static void gen9_disable_dc5(struct drm_i915_private *dev_priv)
  447. {
  448. uint32_t val;
  449. assert_can_disable_dc5(dev_priv);
  450. DRM_DEBUG_KMS("Disabling DC5\n");
  451. val = I915_READ(DC_STATE_EN);
  452. val &= ~DC_STATE_EN_UPTO_DC5;
  453. I915_WRITE(DC_STATE_EN, val);
  454. POSTING_READ(DC_STATE_EN);
  455. }
  456. static void assert_can_enable_dc6(struct drm_i915_private *dev_priv)
  457. {
  458. struct drm_device *dev = dev_priv->dev;
  459. WARN(!IS_SKYLAKE(dev), "Platform doesn't support DC6.\n");
  460. WARN(!HAS_RUNTIME_PM(dev), "Runtime PM not enabled.\n");
  461. WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  462. "Backlight is not disabled.\n");
  463. WARN((I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
  464. "DC6 already programmed to be enabled.\n");
  465. assert_csr_loaded(dev_priv);
  466. }
  467. static void assert_can_disable_dc6(struct drm_i915_private *dev_priv)
  468. {
  469. /*
  470. * During initialization, the firmware may not be loaded yet.
  471. * We still want to make sure that the DC enabling flag is cleared.
  472. */
  473. if (dev_priv->power_domains.initializing)
  474. return;
  475. assert_csr_loaded(dev_priv);
  476. WARN(!(I915_READ(DC_STATE_EN) & DC_STATE_EN_UPTO_DC6),
  477. "DC6 already programmed to be disabled.\n");
  478. }
  479. static void skl_enable_dc6(struct drm_i915_private *dev_priv)
  480. {
  481. uint32_t val;
  482. assert_can_enable_dc6(dev_priv);
  483. DRM_DEBUG_KMS("Enabling DC6\n");
  484. gen9_set_dc_state_debugmask_memory_up(dev_priv);
  485. val = I915_READ(DC_STATE_EN);
  486. val &= ~DC_STATE_EN_UPTO_DC5_DC6_MASK;
  487. val |= DC_STATE_EN_UPTO_DC6;
  488. I915_WRITE(DC_STATE_EN, val);
  489. POSTING_READ(DC_STATE_EN);
  490. }
  491. static void skl_disable_dc6(struct drm_i915_private *dev_priv)
  492. {
  493. uint32_t val;
  494. assert_can_disable_dc6(dev_priv);
  495. DRM_DEBUG_KMS("Disabling DC6\n");
  496. val = I915_READ(DC_STATE_EN);
  497. val &= ~DC_STATE_EN_UPTO_DC6;
  498. I915_WRITE(DC_STATE_EN, val);
  499. POSTING_READ(DC_STATE_EN);
  500. }
  501. static void skl_set_power_well(struct drm_i915_private *dev_priv,
  502. struct i915_power_well *power_well, bool enable)
  503. {
  504. struct drm_device *dev = dev_priv->dev;
  505. uint32_t tmp, fuse_status;
  506. uint32_t req_mask, state_mask;
  507. bool is_enabled, enable_requested, check_fuse_status = false;
  508. tmp = I915_READ(HSW_PWR_WELL_DRIVER);
  509. fuse_status = I915_READ(SKL_FUSE_STATUS);
  510. switch (power_well->data) {
  511. case SKL_DISP_PW_1:
  512. if (wait_for((I915_READ(SKL_FUSE_STATUS) &
  513. SKL_FUSE_PG0_DIST_STATUS), 1)) {
  514. DRM_ERROR("PG0 not enabled\n");
  515. return;
  516. }
  517. break;
  518. case SKL_DISP_PW_2:
  519. if (!(fuse_status & SKL_FUSE_PG1_DIST_STATUS)) {
  520. DRM_ERROR("PG1 in disabled state\n");
  521. return;
  522. }
  523. break;
  524. case SKL_DISP_PW_DDI_A_E:
  525. case SKL_DISP_PW_DDI_B:
  526. case SKL_DISP_PW_DDI_C:
  527. case SKL_DISP_PW_DDI_D:
  528. case SKL_DISP_PW_MISC_IO:
  529. break;
  530. default:
  531. WARN(1, "Unknown power well %lu\n", power_well->data);
  532. return;
  533. }
  534. req_mask = SKL_POWER_WELL_REQ(power_well->data);
  535. enable_requested = tmp & req_mask;
  536. state_mask = SKL_POWER_WELL_STATE(power_well->data);
  537. is_enabled = tmp & state_mask;
  538. if (enable) {
  539. if (!enable_requested) {
  540. WARN((tmp & state_mask) &&
  541. !I915_READ(HSW_PWR_WELL_BIOS),
  542. "Invalid for power well status to be enabled, unless done by the BIOS, \
  543. when request is to disable!\n");
  544. if ((GEN9_ENABLE_DC5(dev) || SKL_ENABLE_DC6(dev)) &&
  545. power_well->data == SKL_DISP_PW_2) {
  546. if (SKL_ENABLE_DC6(dev)) {
  547. skl_disable_dc6(dev_priv);
  548. /*
  549. * DDI buffer programming unnecessary during driver-load/resume
  550. * as it's already done during modeset initialization then.
  551. * It's also invalid here as encoder list is still uninitialized.
  552. */
  553. if (!dev_priv->power_domains.initializing)
  554. intel_prepare_ddi(dev);
  555. } else {
  556. gen9_disable_dc5(dev_priv);
  557. }
  558. }
  559. I915_WRITE(HSW_PWR_WELL_DRIVER, tmp | req_mask);
  560. }
  561. if (!is_enabled) {
  562. DRM_DEBUG_KMS("Enabling %s\n", power_well->name);
  563. if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
  564. state_mask), 1))
  565. DRM_ERROR("%s enable timeout\n",
  566. power_well->name);
  567. check_fuse_status = true;
  568. }
  569. } else {
  570. if (enable_requested) {
  571. I915_WRITE(HSW_PWR_WELL_DRIVER, tmp & ~req_mask);
  572. POSTING_READ(HSW_PWR_WELL_DRIVER);
  573. DRM_DEBUG_KMS("Disabling %s\n", power_well->name);
  574. if ((GEN9_ENABLE_DC5(dev) || SKL_ENABLE_DC6(dev)) &&
  575. power_well->data == SKL_DISP_PW_2) {
  576. enum csr_state state;
  577. /* TODO: wait for a completion event or
  578. * similar here instead of busy
  579. * waiting using wait_for function.
  580. */
  581. wait_for((state = intel_csr_load_status_get(dev_priv)) !=
  582. FW_UNINITIALIZED, 1000);
  583. if (state != FW_LOADED)
  584. DRM_ERROR("CSR firmware not ready (%d)\n",
  585. state);
  586. else
  587. if (SKL_ENABLE_DC6(dev))
  588. skl_enable_dc6(dev_priv);
  589. else
  590. gen9_enable_dc5(dev_priv);
  591. }
  592. }
  593. }
  594. if (check_fuse_status) {
  595. if (power_well->data == SKL_DISP_PW_1) {
  596. if (wait_for((I915_READ(SKL_FUSE_STATUS) &
  597. SKL_FUSE_PG1_DIST_STATUS), 1))
  598. DRM_ERROR("PG1 distributing status timeout\n");
  599. } else if (power_well->data == SKL_DISP_PW_2) {
  600. if (wait_for((I915_READ(SKL_FUSE_STATUS) &
  601. SKL_FUSE_PG2_DIST_STATUS), 1))
  602. DRM_ERROR("PG2 distributing status timeout\n");
  603. }
  604. }
  605. if (enable && !is_enabled)
  606. skl_power_well_post_enable(dev_priv, power_well);
  607. }
  608. static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
  609. struct i915_power_well *power_well)
  610. {
  611. hsw_set_power_well(dev_priv, power_well, power_well->count > 0);
  612. /*
  613. * We're taking over the BIOS, so clear any requests made by it since
  614. * the driver is in charge now.
  615. */
  616. if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
  617. I915_WRITE(HSW_PWR_WELL_BIOS, 0);
  618. }
  619. static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
  620. struct i915_power_well *power_well)
  621. {
  622. hsw_set_power_well(dev_priv, power_well, true);
  623. }
  624. static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
  625. struct i915_power_well *power_well)
  626. {
  627. hsw_set_power_well(dev_priv, power_well, false);
  628. }
  629. static bool skl_power_well_enabled(struct drm_i915_private *dev_priv,
  630. struct i915_power_well *power_well)
  631. {
  632. uint32_t mask = SKL_POWER_WELL_REQ(power_well->data) |
  633. SKL_POWER_WELL_STATE(power_well->data);
  634. return (I915_READ(HSW_PWR_WELL_DRIVER) & mask) == mask;
  635. }
  636. static void skl_power_well_sync_hw(struct drm_i915_private *dev_priv,
  637. struct i915_power_well *power_well)
  638. {
  639. skl_set_power_well(dev_priv, power_well, power_well->count > 0);
  640. /* Clear any request made by BIOS as driver is taking over */
  641. I915_WRITE(HSW_PWR_WELL_BIOS, 0);
  642. }
  643. static void skl_power_well_enable(struct drm_i915_private *dev_priv,
  644. struct i915_power_well *power_well)
  645. {
  646. skl_set_power_well(dev_priv, power_well, true);
  647. }
  648. static void skl_power_well_disable(struct drm_i915_private *dev_priv,
  649. struct i915_power_well *power_well)
  650. {
  651. skl_set_power_well(dev_priv, power_well, false);
  652. }
  653. static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
  654. struct i915_power_well *power_well)
  655. {
  656. }
  657. static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
  658. struct i915_power_well *power_well)
  659. {
  660. return true;
  661. }
  662. static void vlv_set_power_well(struct drm_i915_private *dev_priv,
  663. struct i915_power_well *power_well, bool enable)
  664. {
  665. enum punit_power_well power_well_id = power_well->data;
  666. u32 mask;
  667. u32 state;
  668. u32 ctrl;
  669. mask = PUNIT_PWRGT_MASK(power_well_id);
  670. state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
  671. PUNIT_PWRGT_PWR_GATE(power_well_id);
  672. mutex_lock(&dev_priv->rps.hw_lock);
  673. #define COND \
  674. ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
  675. if (COND)
  676. goto out;
  677. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
  678. ctrl &= ~mask;
  679. ctrl |= state;
  680. vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
  681. if (wait_for(COND, 100))
  682. DRM_ERROR("timeout setting power well state %08x (%08x)\n",
  683. state,
  684. vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
  685. #undef COND
  686. out:
  687. mutex_unlock(&dev_priv->rps.hw_lock);
  688. }
  689. static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv,
  690. struct i915_power_well *power_well)
  691. {
  692. vlv_set_power_well(dev_priv, power_well, power_well->count > 0);
  693. }
  694. static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
  695. struct i915_power_well *power_well)
  696. {
  697. vlv_set_power_well(dev_priv, power_well, true);
  698. }
  699. static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
  700. struct i915_power_well *power_well)
  701. {
  702. vlv_set_power_well(dev_priv, power_well, false);
  703. }
  704. static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
  705. struct i915_power_well *power_well)
  706. {
  707. int power_well_id = power_well->data;
  708. bool enabled = false;
  709. u32 mask;
  710. u32 state;
  711. u32 ctrl;
  712. mask = PUNIT_PWRGT_MASK(power_well_id);
  713. ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
  714. mutex_lock(&dev_priv->rps.hw_lock);
  715. state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
  716. /*
  717. * We only ever set the power-on and power-gate states, anything
  718. * else is unexpected.
  719. */
  720. WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
  721. state != PUNIT_PWRGT_PWR_GATE(power_well_id));
  722. if (state == ctrl)
  723. enabled = true;
  724. /*
  725. * A transient state at this point would mean some unexpected party
  726. * is poking at the power controls too.
  727. */
  728. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
  729. WARN_ON(ctrl != state);
  730. mutex_unlock(&dev_priv->rps.hw_lock);
  731. return enabled;
  732. }
  733. static void vlv_display_power_well_init(struct drm_i915_private *dev_priv)
  734. {
  735. spin_lock_irq(&dev_priv->irq_lock);
  736. valleyview_enable_display_irqs(dev_priv);
  737. spin_unlock_irq(&dev_priv->irq_lock);
  738. /*
  739. * During driver initialization/resume we can avoid restoring the
  740. * part of the HW/SW state that will be inited anyway explicitly.
  741. */
  742. if (dev_priv->power_domains.initializing)
  743. return;
  744. intel_hpd_init(dev_priv);
  745. i915_redisable_vga_power_on(dev_priv->dev);
  746. }
  747. static void vlv_display_power_well_deinit(struct drm_i915_private *dev_priv)
  748. {
  749. spin_lock_irq(&dev_priv->irq_lock);
  750. valleyview_disable_display_irqs(dev_priv);
  751. spin_unlock_irq(&dev_priv->irq_lock);
  752. vlv_power_sequencer_reset(dev_priv);
  753. }
  754. static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
  755. struct i915_power_well *power_well)
  756. {
  757. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
  758. vlv_set_power_well(dev_priv, power_well, true);
  759. vlv_display_power_well_init(dev_priv);
  760. }
  761. static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
  762. struct i915_power_well *power_well)
  763. {
  764. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
  765. vlv_display_power_well_deinit(dev_priv);
  766. vlv_set_power_well(dev_priv, power_well, false);
  767. }
  768. static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
  769. struct i915_power_well *power_well)
  770. {
  771. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
  772. /*
  773. * Enable the CRI clock source so we can get at the
  774. * display and the reference clock for VGA
  775. * hotplug / manual detection.
  776. */
  777. I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) | DPLL_VGA_MODE_DIS |
  778. DPLL_REF_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
  779. udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
  780. vlv_set_power_well(dev_priv, power_well, true);
  781. /*
  782. * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
  783. * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
  784. * a. GUnit 0x2110 bit[0] set to 1 (def 0)
  785. * b. The other bits such as sfr settings / modesel may all
  786. * be set to 0.
  787. *
  788. * This should only be done on init and resume from S3 with
  789. * both PLLs disabled, or we risk losing DPIO and PLL
  790. * synchronization.
  791. */
  792. I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
  793. }
  794. static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
  795. struct i915_power_well *power_well)
  796. {
  797. enum pipe pipe;
  798. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
  799. for_each_pipe(dev_priv, pipe)
  800. assert_pll_disabled(dev_priv, pipe);
  801. /* Assert common reset */
  802. I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
  803. vlv_set_power_well(dev_priv, power_well, false);
  804. }
  805. static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
  806. struct i915_power_well *power_well)
  807. {
  808. enum dpio_phy phy;
  809. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
  810. power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
  811. /*
  812. * Enable the CRI clock source so we can get at the
  813. * display and the reference clock for VGA
  814. * hotplug / manual detection.
  815. */
  816. if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
  817. phy = DPIO_PHY0;
  818. I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) | DPLL_VGA_MODE_DIS |
  819. DPLL_REF_CLK_ENABLE_VLV);
  820. I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) | DPLL_VGA_MODE_DIS |
  821. DPLL_REF_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
  822. } else {
  823. phy = DPIO_PHY1;
  824. I915_WRITE(DPLL(PIPE_C), I915_READ(DPLL(PIPE_C)) | DPLL_VGA_MODE_DIS |
  825. DPLL_REF_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
  826. }
  827. udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
  828. vlv_set_power_well(dev_priv, power_well, true);
  829. /* Poll for phypwrgood signal */
  830. if (wait_for(I915_READ(DISPLAY_PHY_STATUS) & PHY_POWERGOOD(phy), 1))
  831. DRM_ERROR("Display PHY %d is not power up\n", phy);
  832. dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(phy);
  833. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  834. }
  835. static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
  836. struct i915_power_well *power_well)
  837. {
  838. enum dpio_phy phy;
  839. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
  840. power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
  841. if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
  842. phy = DPIO_PHY0;
  843. assert_pll_disabled(dev_priv, PIPE_A);
  844. assert_pll_disabled(dev_priv, PIPE_B);
  845. } else {
  846. phy = DPIO_PHY1;
  847. assert_pll_disabled(dev_priv, PIPE_C);
  848. }
  849. dev_priv->chv_phy_control &= ~PHY_COM_LANE_RESET_DEASSERT(phy);
  850. I915_WRITE(DISPLAY_PHY_CONTROL, dev_priv->chv_phy_control);
  851. vlv_set_power_well(dev_priv, power_well, false);
  852. }
  853. static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
  854. struct i915_power_well *power_well)
  855. {
  856. enum pipe pipe = power_well->data;
  857. bool enabled;
  858. u32 state, ctrl;
  859. mutex_lock(&dev_priv->rps.hw_lock);
  860. state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
  861. /*
  862. * We only ever set the power-on and power-gate states, anything
  863. * else is unexpected.
  864. */
  865. WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
  866. enabled = state == DP_SSS_PWR_ON(pipe);
  867. /*
  868. * A transient state at this point would mean some unexpected party
  869. * is poking at the power controls too.
  870. */
  871. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
  872. WARN_ON(ctrl << 16 != state);
  873. mutex_unlock(&dev_priv->rps.hw_lock);
  874. return enabled;
  875. }
  876. static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
  877. struct i915_power_well *power_well,
  878. bool enable)
  879. {
  880. enum pipe pipe = power_well->data;
  881. u32 state;
  882. u32 ctrl;
  883. state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
  884. mutex_lock(&dev_priv->rps.hw_lock);
  885. #define COND \
  886. ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
  887. if (COND)
  888. goto out;
  889. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  890. ctrl &= ~DP_SSC_MASK(pipe);
  891. ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
  892. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
  893. if (wait_for(COND, 100))
  894. DRM_ERROR("timeout setting power well state %08x (%08x)\n",
  895. state,
  896. vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
  897. #undef COND
  898. out:
  899. mutex_unlock(&dev_priv->rps.hw_lock);
  900. }
  901. static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv,
  902. struct i915_power_well *power_well)
  903. {
  904. WARN_ON_ONCE(power_well->data != PIPE_A);
  905. chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0);
  906. }
  907. static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
  908. struct i915_power_well *power_well)
  909. {
  910. WARN_ON_ONCE(power_well->data != PIPE_A);
  911. chv_set_pipe_power_well(dev_priv, power_well, true);
  912. vlv_display_power_well_init(dev_priv);
  913. }
  914. static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
  915. struct i915_power_well *power_well)
  916. {
  917. WARN_ON_ONCE(power_well->data != PIPE_A);
  918. vlv_display_power_well_deinit(dev_priv);
  919. chv_set_pipe_power_well(dev_priv, power_well, false);
  920. }
  921. /**
  922. * intel_display_power_get - grab a power domain reference
  923. * @dev_priv: i915 device instance
  924. * @domain: power domain to reference
  925. *
  926. * This function grabs a power domain reference for @domain and ensures that the
  927. * power domain and all its parents are powered up. Therefore users should only
  928. * grab a reference to the innermost power domain they need.
  929. *
  930. * Any power domain reference obtained by this function must have a symmetric
  931. * call to intel_display_power_put() to release the reference again.
  932. */
  933. void intel_display_power_get(struct drm_i915_private *dev_priv,
  934. enum intel_display_power_domain domain)
  935. {
  936. struct i915_power_domains *power_domains;
  937. struct i915_power_well *power_well;
  938. int i;
  939. intel_runtime_pm_get(dev_priv);
  940. power_domains = &dev_priv->power_domains;
  941. mutex_lock(&power_domains->lock);
  942. for_each_power_well(i, power_well, BIT(domain), power_domains) {
  943. if (!power_well->count++)
  944. intel_power_well_enable(dev_priv, power_well);
  945. }
  946. power_domains->domain_use_count[domain]++;
  947. mutex_unlock(&power_domains->lock);
  948. }
  949. /**
  950. * intel_display_power_put - release a power domain reference
  951. * @dev_priv: i915 device instance
  952. * @domain: power domain to reference
  953. *
  954. * This function drops the power domain reference obtained by
  955. * intel_display_power_get() and might power down the corresponding hardware
  956. * block right away if this is the last reference.
  957. */
  958. void intel_display_power_put(struct drm_i915_private *dev_priv,
  959. enum intel_display_power_domain domain)
  960. {
  961. struct i915_power_domains *power_domains;
  962. struct i915_power_well *power_well;
  963. int i;
  964. power_domains = &dev_priv->power_domains;
  965. mutex_lock(&power_domains->lock);
  966. WARN_ON(!power_domains->domain_use_count[domain]);
  967. power_domains->domain_use_count[domain]--;
  968. for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
  969. WARN_ON(!power_well->count);
  970. if (!--power_well->count && i915.disable_power_well)
  971. intel_power_well_disable(dev_priv, power_well);
  972. }
  973. mutex_unlock(&power_domains->lock);
  974. intel_runtime_pm_put(dev_priv);
  975. }
  976. #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
  977. #define HSW_ALWAYS_ON_POWER_DOMAINS ( \
  978. BIT(POWER_DOMAIN_PIPE_A) | \
  979. BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
  980. BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
  981. BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
  982. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  983. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  984. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  985. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  986. BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
  987. BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
  988. BIT(POWER_DOMAIN_PORT_CRT) | \
  989. BIT(POWER_DOMAIN_PLLS) | \
  990. BIT(POWER_DOMAIN_AUX_A) | \
  991. BIT(POWER_DOMAIN_AUX_B) | \
  992. BIT(POWER_DOMAIN_AUX_C) | \
  993. BIT(POWER_DOMAIN_AUX_D) | \
  994. BIT(POWER_DOMAIN_INIT))
  995. #define HSW_DISPLAY_POWER_DOMAINS ( \
  996. (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \
  997. BIT(POWER_DOMAIN_INIT))
  998. #define BDW_ALWAYS_ON_POWER_DOMAINS ( \
  999. HSW_ALWAYS_ON_POWER_DOMAINS | \
  1000. BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER))
  1001. #define BDW_DISPLAY_POWER_DOMAINS ( \
  1002. (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \
  1003. BIT(POWER_DOMAIN_INIT))
  1004. #define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT)
  1005. #define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK
  1006. #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
  1007. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  1008. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  1009. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  1010. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  1011. BIT(POWER_DOMAIN_PORT_CRT) | \
  1012. BIT(POWER_DOMAIN_AUX_B) | \
  1013. BIT(POWER_DOMAIN_AUX_C) | \
  1014. BIT(POWER_DOMAIN_INIT))
  1015. #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
  1016. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  1017. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  1018. BIT(POWER_DOMAIN_AUX_B) | \
  1019. BIT(POWER_DOMAIN_INIT))
  1020. #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
  1021. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  1022. BIT(POWER_DOMAIN_AUX_B) | \
  1023. BIT(POWER_DOMAIN_INIT))
  1024. #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
  1025. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  1026. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  1027. BIT(POWER_DOMAIN_AUX_C) | \
  1028. BIT(POWER_DOMAIN_INIT))
  1029. #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
  1030. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  1031. BIT(POWER_DOMAIN_AUX_C) | \
  1032. BIT(POWER_DOMAIN_INIT))
  1033. #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
  1034. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  1035. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  1036. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  1037. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  1038. BIT(POWER_DOMAIN_AUX_B) | \
  1039. BIT(POWER_DOMAIN_AUX_C) | \
  1040. BIT(POWER_DOMAIN_INIT))
  1041. #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
  1042. BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
  1043. BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
  1044. BIT(POWER_DOMAIN_AUX_D) | \
  1045. BIT(POWER_DOMAIN_INIT))
  1046. static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
  1047. .sync_hw = i9xx_always_on_power_well_noop,
  1048. .enable = i9xx_always_on_power_well_noop,
  1049. .disable = i9xx_always_on_power_well_noop,
  1050. .is_enabled = i9xx_always_on_power_well_enabled,
  1051. };
  1052. static const struct i915_power_well_ops chv_pipe_power_well_ops = {
  1053. .sync_hw = chv_pipe_power_well_sync_hw,
  1054. .enable = chv_pipe_power_well_enable,
  1055. .disable = chv_pipe_power_well_disable,
  1056. .is_enabled = chv_pipe_power_well_enabled,
  1057. };
  1058. static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
  1059. .sync_hw = vlv_power_well_sync_hw,
  1060. .enable = chv_dpio_cmn_power_well_enable,
  1061. .disable = chv_dpio_cmn_power_well_disable,
  1062. .is_enabled = vlv_power_well_enabled,
  1063. };
  1064. static struct i915_power_well i9xx_always_on_power_well[] = {
  1065. {
  1066. .name = "always-on",
  1067. .always_on = 1,
  1068. .domains = POWER_DOMAIN_MASK,
  1069. .ops = &i9xx_always_on_power_well_ops,
  1070. },
  1071. };
  1072. static const struct i915_power_well_ops hsw_power_well_ops = {
  1073. .sync_hw = hsw_power_well_sync_hw,
  1074. .enable = hsw_power_well_enable,
  1075. .disable = hsw_power_well_disable,
  1076. .is_enabled = hsw_power_well_enabled,
  1077. };
  1078. static const struct i915_power_well_ops skl_power_well_ops = {
  1079. .sync_hw = skl_power_well_sync_hw,
  1080. .enable = skl_power_well_enable,
  1081. .disable = skl_power_well_disable,
  1082. .is_enabled = skl_power_well_enabled,
  1083. };
  1084. static struct i915_power_well hsw_power_wells[] = {
  1085. {
  1086. .name = "always-on",
  1087. .always_on = 1,
  1088. .domains = HSW_ALWAYS_ON_POWER_DOMAINS,
  1089. .ops = &i9xx_always_on_power_well_ops,
  1090. },
  1091. {
  1092. .name = "display",
  1093. .domains = HSW_DISPLAY_POWER_DOMAINS,
  1094. .ops = &hsw_power_well_ops,
  1095. },
  1096. };
  1097. static struct i915_power_well bdw_power_wells[] = {
  1098. {
  1099. .name = "always-on",
  1100. .always_on = 1,
  1101. .domains = BDW_ALWAYS_ON_POWER_DOMAINS,
  1102. .ops = &i9xx_always_on_power_well_ops,
  1103. },
  1104. {
  1105. .name = "display",
  1106. .domains = BDW_DISPLAY_POWER_DOMAINS,
  1107. .ops = &hsw_power_well_ops,
  1108. },
  1109. };
  1110. static const struct i915_power_well_ops vlv_display_power_well_ops = {
  1111. .sync_hw = vlv_power_well_sync_hw,
  1112. .enable = vlv_display_power_well_enable,
  1113. .disable = vlv_display_power_well_disable,
  1114. .is_enabled = vlv_power_well_enabled,
  1115. };
  1116. static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
  1117. .sync_hw = vlv_power_well_sync_hw,
  1118. .enable = vlv_dpio_cmn_power_well_enable,
  1119. .disable = vlv_dpio_cmn_power_well_disable,
  1120. .is_enabled = vlv_power_well_enabled,
  1121. };
  1122. static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
  1123. .sync_hw = vlv_power_well_sync_hw,
  1124. .enable = vlv_power_well_enable,
  1125. .disable = vlv_power_well_disable,
  1126. .is_enabled = vlv_power_well_enabled,
  1127. };
  1128. static struct i915_power_well vlv_power_wells[] = {
  1129. {
  1130. .name = "always-on",
  1131. .always_on = 1,
  1132. .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
  1133. .ops = &i9xx_always_on_power_well_ops,
  1134. },
  1135. {
  1136. .name = "display",
  1137. .domains = VLV_DISPLAY_POWER_DOMAINS,
  1138. .data = PUNIT_POWER_WELL_DISP2D,
  1139. .ops = &vlv_display_power_well_ops,
  1140. },
  1141. {
  1142. .name = "dpio-tx-b-01",
  1143. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1144. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1145. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1146. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1147. .ops = &vlv_dpio_power_well_ops,
  1148. .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
  1149. },
  1150. {
  1151. .name = "dpio-tx-b-23",
  1152. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1153. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1154. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1155. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1156. .ops = &vlv_dpio_power_well_ops,
  1157. .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
  1158. },
  1159. {
  1160. .name = "dpio-tx-c-01",
  1161. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1162. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1163. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1164. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1165. .ops = &vlv_dpio_power_well_ops,
  1166. .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
  1167. },
  1168. {
  1169. .name = "dpio-tx-c-23",
  1170. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  1171. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  1172. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  1173. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  1174. .ops = &vlv_dpio_power_well_ops,
  1175. .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
  1176. },
  1177. {
  1178. .name = "dpio-common",
  1179. .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
  1180. .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
  1181. .ops = &vlv_dpio_cmn_power_well_ops,
  1182. },
  1183. };
  1184. static struct i915_power_well chv_power_wells[] = {
  1185. {
  1186. .name = "always-on",
  1187. .always_on = 1,
  1188. .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
  1189. .ops = &i9xx_always_on_power_well_ops,
  1190. },
  1191. {
  1192. .name = "display",
  1193. /*
  1194. * Pipe A power well is the new disp2d well. Pipe B and C
  1195. * power wells don't actually exist. Pipe A power well is
  1196. * required for any pipe to work.
  1197. */
  1198. .domains = VLV_DISPLAY_POWER_DOMAINS,
  1199. .data = PIPE_A,
  1200. .ops = &chv_pipe_power_well_ops,
  1201. },
  1202. {
  1203. .name = "dpio-common-bc",
  1204. .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS,
  1205. .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
  1206. .ops = &chv_dpio_cmn_power_well_ops,
  1207. },
  1208. {
  1209. .name = "dpio-common-d",
  1210. .domains = CHV_DPIO_CMN_D_POWER_DOMAINS,
  1211. .data = PUNIT_POWER_WELL_DPIO_CMN_D,
  1212. .ops = &chv_dpio_cmn_power_well_ops,
  1213. },
  1214. };
  1215. static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
  1216. int power_well_id)
  1217. {
  1218. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1219. struct i915_power_well *power_well;
  1220. int i;
  1221. for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
  1222. if (power_well->data == power_well_id)
  1223. return power_well;
  1224. }
  1225. return NULL;
  1226. }
  1227. bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
  1228. int power_well_id)
  1229. {
  1230. struct i915_power_well *power_well;
  1231. bool ret;
  1232. power_well = lookup_power_well(dev_priv, power_well_id);
  1233. ret = power_well->ops->is_enabled(dev_priv, power_well);
  1234. return ret;
  1235. }
  1236. static struct i915_power_well skl_power_wells[] = {
  1237. {
  1238. .name = "always-on",
  1239. .always_on = 1,
  1240. .domains = SKL_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
  1241. .ops = &i9xx_always_on_power_well_ops,
  1242. },
  1243. {
  1244. .name = "power well 1",
  1245. .domains = SKL_DISPLAY_POWERWELL_1_POWER_DOMAINS,
  1246. .ops = &skl_power_well_ops,
  1247. .data = SKL_DISP_PW_1,
  1248. },
  1249. {
  1250. .name = "MISC IO power well",
  1251. .domains = SKL_DISPLAY_MISC_IO_POWER_DOMAINS,
  1252. .ops = &skl_power_well_ops,
  1253. .data = SKL_DISP_PW_MISC_IO,
  1254. },
  1255. {
  1256. .name = "power well 2",
  1257. .domains = SKL_DISPLAY_POWERWELL_2_POWER_DOMAINS,
  1258. .ops = &skl_power_well_ops,
  1259. .data = SKL_DISP_PW_2,
  1260. },
  1261. {
  1262. .name = "DDI A/E power well",
  1263. .domains = SKL_DISPLAY_DDI_A_E_POWER_DOMAINS,
  1264. .ops = &skl_power_well_ops,
  1265. .data = SKL_DISP_PW_DDI_A_E,
  1266. },
  1267. {
  1268. .name = "DDI B power well",
  1269. .domains = SKL_DISPLAY_DDI_B_POWER_DOMAINS,
  1270. .ops = &skl_power_well_ops,
  1271. .data = SKL_DISP_PW_DDI_B,
  1272. },
  1273. {
  1274. .name = "DDI C power well",
  1275. .domains = SKL_DISPLAY_DDI_C_POWER_DOMAINS,
  1276. .ops = &skl_power_well_ops,
  1277. .data = SKL_DISP_PW_DDI_C,
  1278. },
  1279. {
  1280. .name = "DDI D power well",
  1281. .domains = SKL_DISPLAY_DDI_D_POWER_DOMAINS,
  1282. .ops = &skl_power_well_ops,
  1283. .data = SKL_DISP_PW_DDI_D,
  1284. },
  1285. };
  1286. static struct i915_power_well bxt_power_wells[] = {
  1287. {
  1288. .name = "always-on",
  1289. .always_on = 1,
  1290. .domains = BXT_DISPLAY_ALWAYS_ON_POWER_DOMAINS,
  1291. .ops = &i9xx_always_on_power_well_ops,
  1292. },
  1293. {
  1294. .name = "power well 1",
  1295. .domains = BXT_DISPLAY_POWERWELL_1_POWER_DOMAINS,
  1296. .ops = &skl_power_well_ops,
  1297. .data = SKL_DISP_PW_1,
  1298. },
  1299. {
  1300. .name = "power well 2",
  1301. .domains = BXT_DISPLAY_POWERWELL_2_POWER_DOMAINS,
  1302. .ops = &skl_power_well_ops,
  1303. .data = SKL_DISP_PW_2,
  1304. }
  1305. };
  1306. #define set_power_wells(power_domains, __power_wells) ({ \
  1307. (power_domains)->power_wells = (__power_wells); \
  1308. (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
  1309. })
  1310. /**
  1311. * intel_power_domains_init - initializes the power domain structures
  1312. * @dev_priv: i915 device instance
  1313. *
  1314. * Initializes the power domain structures for @dev_priv depending upon the
  1315. * supported platform.
  1316. */
  1317. int intel_power_domains_init(struct drm_i915_private *dev_priv)
  1318. {
  1319. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1320. mutex_init(&power_domains->lock);
  1321. /*
  1322. * The enabling order will be from lower to higher indexed wells,
  1323. * the disabling order is reversed.
  1324. */
  1325. if (IS_HASWELL(dev_priv->dev)) {
  1326. set_power_wells(power_domains, hsw_power_wells);
  1327. } else if (IS_BROADWELL(dev_priv->dev)) {
  1328. set_power_wells(power_domains, bdw_power_wells);
  1329. } else if (IS_SKYLAKE(dev_priv->dev)) {
  1330. set_power_wells(power_domains, skl_power_wells);
  1331. } else if (IS_BROXTON(dev_priv->dev)) {
  1332. set_power_wells(power_domains, bxt_power_wells);
  1333. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1334. set_power_wells(power_domains, chv_power_wells);
  1335. } else if (IS_VALLEYVIEW(dev_priv->dev)) {
  1336. set_power_wells(power_domains, vlv_power_wells);
  1337. } else {
  1338. set_power_wells(power_domains, i9xx_always_on_power_well);
  1339. }
  1340. return 0;
  1341. }
  1342. static void intel_runtime_pm_disable(struct drm_i915_private *dev_priv)
  1343. {
  1344. struct drm_device *dev = dev_priv->dev;
  1345. struct device *device = &dev->pdev->dev;
  1346. if (!HAS_RUNTIME_PM(dev))
  1347. return;
  1348. if (!intel_enable_rc6(dev))
  1349. return;
  1350. /* Make sure we're not suspended first. */
  1351. pm_runtime_get_sync(device);
  1352. pm_runtime_disable(device);
  1353. }
  1354. /**
  1355. * intel_power_domains_fini - finalizes the power domain structures
  1356. * @dev_priv: i915 device instance
  1357. *
  1358. * Finalizes the power domain structures for @dev_priv depending upon the
  1359. * supported platform. This function also disables runtime pm and ensures that
  1360. * the device stays powered up so that the driver can be reloaded.
  1361. */
  1362. void intel_power_domains_fini(struct drm_i915_private *dev_priv)
  1363. {
  1364. intel_runtime_pm_disable(dev_priv);
  1365. /* The i915.ko module is still not prepared to be loaded when
  1366. * the power well is not enabled, so just enable it in case
  1367. * we're going to unload/reload. */
  1368. intel_display_set_init_power(dev_priv, true);
  1369. }
  1370. static void intel_power_domains_resume(struct drm_i915_private *dev_priv)
  1371. {
  1372. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1373. struct i915_power_well *power_well;
  1374. int i;
  1375. mutex_lock(&power_domains->lock);
  1376. for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
  1377. power_well->ops->sync_hw(dev_priv, power_well);
  1378. power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
  1379. power_well);
  1380. }
  1381. mutex_unlock(&power_domains->lock);
  1382. }
  1383. static void chv_phy_control_init(struct drm_i915_private *dev_priv)
  1384. {
  1385. struct i915_power_well *cmn_bc =
  1386. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
  1387. struct i915_power_well *cmn_d =
  1388. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_D);
  1389. /*
  1390. * DISPLAY_PHY_CONTROL can get corrupted if read. As a
  1391. * workaround never ever read DISPLAY_PHY_CONTROL, and
  1392. * instead maintain a shadow copy ourselves. Use the actual
  1393. * power well state to reconstruct the expected initial
  1394. * value.
  1395. */
  1396. dev_priv->chv_phy_control =
  1397. PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY0) |
  1398. PHY_LDO_SEQ_DELAY(PHY_LDO_DELAY_600NS, DPIO_PHY1) |
  1399. PHY_CH_POWER_MODE(PHY_CH_SU_PSR, DPIO_PHY0, DPIO_CH0) |
  1400. PHY_CH_POWER_MODE(PHY_CH_SU_PSR, DPIO_PHY0, DPIO_CH1) |
  1401. PHY_CH_POWER_MODE(PHY_CH_SU_PSR, DPIO_PHY1, DPIO_CH0);
  1402. if (cmn_bc->ops->is_enabled(dev_priv, cmn_bc))
  1403. dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY0);
  1404. if (cmn_d->ops->is_enabled(dev_priv, cmn_d))
  1405. dev_priv->chv_phy_control |= PHY_COM_LANE_RESET_DEASSERT(DPIO_PHY1);
  1406. }
  1407. static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
  1408. {
  1409. struct i915_power_well *cmn =
  1410. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
  1411. struct i915_power_well *disp2d =
  1412. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
  1413. /* If the display might be already active skip this */
  1414. if (cmn->ops->is_enabled(dev_priv, cmn) &&
  1415. disp2d->ops->is_enabled(dev_priv, disp2d) &&
  1416. I915_READ(DPIO_CTL) & DPIO_CMNRST)
  1417. return;
  1418. DRM_DEBUG_KMS("toggling display PHY side reset\n");
  1419. /* cmnlane needs DPLL registers */
  1420. disp2d->ops->enable(dev_priv, disp2d);
  1421. /*
  1422. * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
  1423. * Need to assert and de-assert PHY SB reset by gating the
  1424. * common lane power, then un-gating it.
  1425. * Simply ungating isn't enough to reset the PHY enough to get
  1426. * ports and lanes running.
  1427. */
  1428. cmn->ops->disable(dev_priv, cmn);
  1429. }
  1430. /**
  1431. * intel_power_domains_init_hw - initialize hardware power domain state
  1432. * @dev_priv: i915 device instance
  1433. *
  1434. * This function initializes the hardware power domain state and enables all
  1435. * power domains using intel_display_set_init_power().
  1436. */
  1437. void intel_power_domains_init_hw(struct drm_i915_private *dev_priv)
  1438. {
  1439. struct drm_device *dev = dev_priv->dev;
  1440. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1441. power_domains->initializing = true;
  1442. if (IS_CHERRYVIEW(dev)) {
  1443. chv_phy_control_init(dev_priv);
  1444. } else if (IS_VALLEYVIEW(dev)) {
  1445. mutex_lock(&power_domains->lock);
  1446. vlv_cmnlane_wa(dev_priv);
  1447. mutex_unlock(&power_domains->lock);
  1448. }
  1449. /* For now, we need the power well to be always enabled. */
  1450. intel_display_set_init_power(dev_priv, true);
  1451. intel_power_domains_resume(dev_priv);
  1452. power_domains->initializing = false;
  1453. }
  1454. /**
  1455. * intel_aux_display_runtime_get - grab an auxiliary power domain reference
  1456. * @dev_priv: i915 device instance
  1457. *
  1458. * This function grabs a power domain reference for the auxiliary power domain
  1459. * (for access to the GMBUS and DP AUX blocks) and ensures that it and all its
  1460. * parents are powered up. Therefore users should only grab a reference to the
  1461. * innermost power domain they need.
  1462. *
  1463. * Any power domain reference obtained by this function must have a symmetric
  1464. * call to intel_aux_display_runtime_put() to release the reference again.
  1465. */
  1466. void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv)
  1467. {
  1468. intel_runtime_pm_get(dev_priv);
  1469. }
  1470. /**
  1471. * intel_aux_display_runtime_put - release an auxiliary power domain reference
  1472. * @dev_priv: i915 device instance
  1473. *
  1474. * This function drops the auxiliary power domain reference obtained by
  1475. * intel_aux_display_runtime_get() and might power down the corresponding
  1476. * hardware block right away if this is the last reference.
  1477. */
  1478. void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv)
  1479. {
  1480. intel_runtime_pm_put(dev_priv);
  1481. }
  1482. /**
  1483. * intel_runtime_pm_get - grab a runtime pm reference
  1484. * @dev_priv: i915 device instance
  1485. *
  1486. * This function grabs a device-level runtime pm reference (mostly used for GEM
  1487. * code to ensure the GTT or GT is on) and ensures that it is powered up.
  1488. *
  1489. * Any runtime pm reference obtained by this function must have a symmetric
  1490. * call to intel_runtime_pm_put() to release the reference again.
  1491. */
  1492. void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
  1493. {
  1494. struct drm_device *dev = dev_priv->dev;
  1495. struct device *device = &dev->pdev->dev;
  1496. if (!HAS_RUNTIME_PM(dev))
  1497. return;
  1498. pm_runtime_get_sync(device);
  1499. WARN(dev_priv->pm.suspended, "Device still suspended.\n");
  1500. }
  1501. /**
  1502. * intel_runtime_pm_get_noresume - grab a runtime pm reference
  1503. * @dev_priv: i915 device instance
  1504. *
  1505. * This function grabs a device-level runtime pm reference (mostly used for GEM
  1506. * code to ensure the GTT or GT is on).
  1507. *
  1508. * It will _not_ power up the device but instead only check that it's powered
  1509. * on. Therefore it is only valid to call this functions from contexts where
  1510. * the device is known to be powered up and where trying to power it up would
  1511. * result in hilarity and deadlocks. That pretty much means only the system
  1512. * suspend/resume code where this is used to grab runtime pm references for
  1513. * delayed setup down in work items.
  1514. *
  1515. * Any runtime pm reference obtained by this function must have a symmetric
  1516. * call to intel_runtime_pm_put() to release the reference again.
  1517. */
  1518. void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
  1519. {
  1520. struct drm_device *dev = dev_priv->dev;
  1521. struct device *device = &dev->pdev->dev;
  1522. if (!HAS_RUNTIME_PM(dev))
  1523. return;
  1524. WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n");
  1525. pm_runtime_get_noresume(device);
  1526. }
  1527. /**
  1528. * intel_runtime_pm_put - release a runtime pm reference
  1529. * @dev_priv: i915 device instance
  1530. *
  1531. * This function drops the device-level runtime pm reference obtained by
  1532. * intel_runtime_pm_get() and might power down the corresponding
  1533. * hardware block right away if this is the last reference.
  1534. */
  1535. void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
  1536. {
  1537. struct drm_device *dev = dev_priv->dev;
  1538. struct device *device = &dev->pdev->dev;
  1539. if (!HAS_RUNTIME_PM(dev))
  1540. return;
  1541. pm_runtime_mark_last_busy(device);
  1542. pm_runtime_put_autosuspend(device);
  1543. }
  1544. /**
  1545. * intel_runtime_pm_enable - enable runtime pm
  1546. * @dev_priv: i915 device instance
  1547. *
  1548. * This function enables runtime pm at the end of the driver load sequence.
  1549. *
  1550. * Note that this function does currently not enable runtime pm for the
  1551. * subordinate display power domains. That is only done on the first modeset
  1552. * using intel_display_set_init_power().
  1553. */
  1554. void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
  1555. {
  1556. struct drm_device *dev = dev_priv->dev;
  1557. struct device *device = &dev->pdev->dev;
  1558. if (!HAS_RUNTIME_PM(dev))
  1559. return;
  1560. pm_runtime_set_active(device);
  1561. /*
  1562. * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
  1563. * requirement.
  1564. */
  1565. if (!intel_enable_rc6(dev)) {
  1566. DRM_INFO("RC6 disabled, disabling runtime PM support\n");
  1567. return;
  1568. }
  1569. pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */
  1570. pm_runtime_mark_last_busy(device);
  1571. pm_runtime_use_autosuspend(device);
  1572. pm_runtime_put_autosuspend(device);
  1573. }