intel_runtime_pm.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  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. #include <drm/i915_powerwell.h>
  33. /**
  34. * DOC: runtime pm
  35. *
  36. * The i915 driver supports dynamic enabling and disabling of entire hardware
  37. * blocks at runtime. This is especially important on the display side where
  38. * software is supposed to control many power gates manually on recent hardware,
  39. * since on the GT side a lot of the power management is done by the hardware.
  40. * But even there some manual control at the device level is required.
  41. *
  42. * Since i915 supports a diverse set of platforms with a unified codebase and
  43. * hardware engineers just love to shuffle functionality around between power
  44. * domains there's a sizeable amount of indirection required. This file provides
  45. * generic functions to the driver for grabbing and releasing references for
  46. * abstract power domains. It then maps those to the actual power wells
  47. * present for a given platform.
  48. */
  49. static struct i915_power_domains *hsw_pwr;
  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. /*
  62. * We should only use the power well if we explicitly asked the hardware to
  63. * enable it, so check if it's enabled and also check if we've requested it to
  64. * be enabled.
  65. */
  66. static bool hsw_power_well_enabled(struct drm_i915_private *dev_priv,
  67. struct i915_power_well *power_well)
  68. {
  69. return I915_READ(HSW_PWR_WELL_DRIVER) ==
  70. (HSW_PWR_WELL_ENABLE_REQUEST | HSW_PWR_WELL_STATE_ENABLED);
  71. }
  72. /**
  73. * __intel_display_power_is_enabled - unlocked check for a power domain
  74. * @dev_priv: i915 device instance
  75. * @domain: power domain to check
  76. *
  77. * This is the unlocked version of intel_display_power_is_enabled() and should
  78. * only be used from error capture and recovery code where deadlocks are
  79. * possible.
  80. *
  81. * Returns:
  82. * True when the power domain is enabled, false otherwise.
  83. */
  84. bool __intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
  85. enum intel_display_power_domain domain)
  86. {
  87. struct i915_power_domains *power_domains;
  88. struct i915_power_well *power_well;
  89. bool is_enabled;
  90. int i;
  91. if (dev_priv->pm.suspended)
  92. return false;
  93. power_domains = &dev_priv->power_domains;
  94. is_enabled = true;
  95. for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
  96. if (power_well->always_on)
  97. continue;
  98. if (!power_well->hw_enabled) {
  99. is_enabled = false;
  100. break;
  101. }
  102. }
  103. return is_enabled;
  104. }
  105. /**
  106. * intel_display_power_is_enabled - unlocked check for a power domain
  107. * @dev_priv: i915 device instance
  108. * @domain: power domain to check
  109. *
  110. * This function can be used to check the hw power domain state. It is mostly
  111. * used in hardware state readout functions. Everywhere else code should rely
  112. * upon explicit power domain reference counting to ensure that the hardware
  113. * block is powered up before accessing it.
  114. *
  115. * Callers must hold the relevant modesetting locks to ensure that concurrent
  116. * threads can't disable the power well while the caller tries to read a few
  117. * registers.
  118. *
  119. * Returns:
  120. * True when the power domain is enabled, false otherwise.
  121. */
  122. bool intel_display_power_is_enabled(struct drm_i915_private *dev_priv,
  123. enum intel_display_power_domain domain)
  124. {
  125. struct i915_power_domains *power_domains;
  126. bool ret;
  127. power_domains = &dev_priv->power_domains;
  128. mutex_lock(&power_domains->lock);
  129. ret = __intel_display_power_is_enabled(dev_priv, domain);
  130. mutex_unlock(&power_domains->lock);
  131. return ret;
  132. }
  133. /**
  134. * intel_display_set_init_power - set the initial power domain state
  135. * @dev_priv: i915 device instance
  136. * @enable: whether to enable or disable the initial power domain state
  137. *
  138. * For simplicity our driver load/unload and system suspend/resume code assumes
  139. * that all power domains are always enabled. This functions controls the state
  140. * of this little hack. While the initial power domain state is enabled runtime
  141. * pm is effectively disabled.
  142. */
  143. void intel_display_set_init_power(struct drm_i915_private *dev_priv,
  144. bool enable)
  145. {
  146. if (dev_priv->power_domains.init_power_on == enable)
  147. return;
  148. if (enable)
  149. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  150. else
  151. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  152. dev_priv->power_domains.init_power_on = enable;
  153. }
  154. /*
  155. * Starting with Haswell, we have a "Power Down Well" that can be turned off
  156. * when not needed anymore. We have 4 registers that can request the power well
  157. * to be enabled, and it will only be disabled if none of the registers is
  158. * requesting it to be enabled.
  159. */
  160. static void hsw_power_well_post_enable(struct drm_i915_private *dev_priv)
  161. {
  162. struct drm_device *dev = dev_priv->dev;
  163. /*
  164. * After we re-enable the power well, if we touch VGA register 0x3d5
  165. * we'll get unclaimed register interrupts. This stops after we write
  166. * anything to the VGA MSR register. The vgacon module uses this
  167. * register all the time, so if we unbind our driver and, as a
  168. * consequence, bind vgacon, we'll get stuck in an infinite loop at
  169. * console_unlock(). So make here we touch the VGA MSR register, making
  170. * sure vgacon can keep working normally without triggering interrupts
  171. * and error messages.
  172. */
  173. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  174. outb(inb(VGA_MSR_READ), VGA_MSR_WRITE);
  175. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  176. if (IS_BROADWELL(dev) || (INTEL_INFO(dev)->gen >= 9))
  177. gen8_irq_power_well_post_enable(dev_priv);
  178. }
  179. static void hsw_set_power_well(struct drm_i915_private *dev_priv,
  180. struct i915_power_well *power_well, bool enable)
  181. {
  182. bool is_enabled, enable_requested;
  183. uint32_t tmp;
  184. tmp = I915_READ(HSW_PWR_WELL_DRIVER);
  185. is_enabled = tmp & HSW_PWR_WELL_STATE_ENABLED;
  186. enable_requested = tmp & HSW_PWR_WELL_ENABLE_REQUEST;
  187. if (enable) {
  188. if (!enable_requested)
  189. I915_WRITE(HSW_PWR_WELL_DRIVER,
  190. HSW_PWR_WELL_ENABLE_REQUEST);
  191. if (!is_enabled) {
  192. DRM_DEBUG_KMS("Enabling power well\n");
  193. if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER) &
  194. HSW_PWR_WELL_STATE_ENABLED), 20))
  195. DRM_ERROR("Timeout enabling power well\n");
  196. hsw_power_well_post_enable(dev_priv);
  197. }
  198. } else {
  199. if (enable_requested) {
  200. I915_WRITE(HSW_PWR_WELL_DRIVER, 0);
  201. POSTING_READ(HSW_PWR_WELL_DRIVER);
  202. DRM_DEBUG_KMS("Requesting to disable the power well\n");
  203. }
  204. }
  205. }
  206. static void hsw_power_well_sync_hw(struct drm_i915_private *dev_priv,
  207. struct i915_power_well *power_well)
  208. {
  209. hsw_set_power_well(dev_priv, power_well, power_well->count > 0);
  210. /*
  211. * We're taking over the BIOS, so clear any requests made by it since
  212. * the driver is in charge now.
  213. */
  214. if (I915_READ(HSW_PWR_WELL_BIOS) & HSW_PWR_WELL_ENABLE_REQUEST)
  215. I915_WRITE(HSW_PWR_WELL_BIOS, 0);
  216. }
  217. static void hsw_power_well_enable(struct drm_i915_private *dev_priv,
  218. struct i915_power_well *power_well)
  219. {
  220. hsw_set_power_well(dev_priv, power_well, true);
  221. }
  222. static void hsw_power_well_disable(struct drm_i915_private *dev_priv,
  223. struct i915_power_well *power_well)
  224. {
  225. hsw_set_power_well(dev_priv, power_well, false);
  226. }
  227. static void i9xx_always_on_power_well_noop(struct drm_i915_private *dev_priv,
  228. struct i915_power_well *power_well)
  229. {
  230. }
  231. static bool i9xx_always_on_power_well_enabled(struct drm_i915_private *dev_priv,
  232. struct i915_power_well *power_well)
  233. {
  234. return true;
  235. }
  236. static void vlv_set_power_well(struct drm_i915_private *dev_priv,
  237. struct i915_power_well *power_well, bool enable)
  238. {
  239. enum punit_power_well power_well_id = power_well->data;
  240. u32 mask;
  241. u32 state;
  242. u32 ctrl;
  243. mask = PUNIT_PWRGT_MASK(power_well_id);
  244. state = enable ? PUNIT_PWRGT_PWR_ON(power_well_id) :
  245. PUNIT_PWRGT_PWR_GATE(power_well_id);
  246. mutex_lock(&dev_priv->rps.hw_lock);
  247. #define COND \
  248. ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
  249. if (COND)
  250. goto out;
  251. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL);
  252. ctrl &= ~mask;
  253. ctrl |= state;
  254. vlv_punit_write(dev_priv, PUNIT_REG_PWRGT_CTRL, ctrl);
  255. if (wait_for(COND, 100))
  256. DRM_ERROR("timout setting power well state %08x (%08x)\n",
  257. state,
  258. vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL));
  259. #undef COND
  260. out:
  261. mutex_unlock(&dev_priv->rps.hw_lock);
  262. }
  263. static void vlv_power_well_sync_hw(struct drm_i915_private *dev_priv,
  264. struct i915_power_well *power_well)
  265. {
  266. vlv_set_power_well(dev_priv, power_well, power_well->count > 0);
  267. }
  268. static void vlv_power_well_enable(struct drm_i915_private *dev_priv,
  269. struct i915_power_well *power_well)
  270. {
  271. vlv_set_power_well(dev_priv, power_well, true);
  272. }
  273. static void vlv_power_well_disable(struct drm_i915_private *dev_priv,
  274. struct i915_power_well *power_well)
  275. {
  276. vlv_set_power_well(dev_priv, power_well, false);
  277. }
  278. static bool vlv_power_well_enabled(struct drm_i915_private *dev_priv,
  279. struct i915_power_well *power_well)
  280. {
  281. int power_well_id = power_well->data;
  282. bool enabled = false;
  283. u32 mask;
  284. u32 state;
  285. u32 ctrl;
  286. mask = PUNIT_PWRGT_MASK(power_well_id);
  287. ctrl = PUNIT_PWRGT_PWR_ON(power_well_id);
  288. mutex_lock(&dev_priv->rps.hw_lock);
  289. state = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask;
  290. /*
  291. * We only ever set the power-on and power-gate states, anything
  292. * else is unexpected.
  293. */
  294. WARN_ON(state != PUNIT_PWRGT_PWR_ON(power_well_id) &&
  295. state != PUNIT_PWRGT_PWR_GATE(power_well_id));
  296. if (state == ctrl)
  297. enabled = true;
  298. /*
  299. * A transient state at this point would mean some unexpected party
  300. * is poking at the power controls too.
  301. */
  302. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_CTRL) & mask;
  303. WARN_ON(ctrl != state);
  304. mutex_unlock(&dev_priv->rps.hw_lock);
  305. return enabled;
  306. }
  307. static void vlv_display_power_well_enable(struct drm_i915_private *dev_priv,
  308. struct i915_power_well *power_well)
  309. {
  310. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
  311. vlv_set_power_well(dev_priv, power_well, true);
  312. spin_lock_irq(&dev_priv->irq_lock);
  313. valleyview_enable_display_irqs(dev_priv);
  314. spin_unlock_irq(&dev_priv->irq_lock);
  315. /*
  316. * During driver initialization/resume we can avoid restoring the
  317. * part of the HW/SW state that will be inited anyway explicitly.
  318. */
  319. if (dev_priv->power_domains.initializing)
  320. return;
  321. intel_hpd_init(dev_priv);
  322. i915_redisable_vga_power_on(dev_priv->dev);
  323. }
  324. static void vlv_display_power_well_disable(struct drm_i915_private *dev_priv,
  325. struct i915_power_well *power_well)
  326. {
  327. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DISP2D);
  328. spin_lock_irq(&dev_priv->irq_lock);
  329. valleyview_disable_display_irqs(dev_priv);
  330. spin_unlock_irq(&dev_priv->irq_lock);
  331. vlv_set_power_well(dev_priv, power_well, false);
  332. vlv_power_sequencer_reset(dev_priv);
  333. }
  334. static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
  335. struct i915_power_well *power_well)
  336. {
  337. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
  338. /*
  339. * Enable the CRI clock source so we can get at the
  340. * display and the reference clock for VGA
  341. * hotplug / manual detection.
  342. */
  343. I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) |
  344. DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
  345. udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
  346. vlv_set_power_well(dev_priv, power_well, true);
  347. /*
  348. * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
  349. * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
  350. * a. GUnit 0x2110 bit[0] set to 1 (def 0)
  351. * b. The other bits such as sfr settings / modesel may all
  352. * be set to 0.
  353. *
  354. * This should only be done on init and resume from S3 with
  355. * both PLLs disabled, or we risk losing DPIO and PLL
  356. * synchronization.
  357. */
  358. I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
  359. }
  360. static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
  361. struct i915_power_well *power_well)
  362. {
  363. enum pipe pipe;
  364. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC);
  365. for_each_pipe(dev_priv, pipe)
  366. assert_pll_disabled(dev_priv, pipe);
  367. /* Assert common reset */
  368. I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) & ~DPIO_CMNRST);
  369. vlv_set_power_well(dev_priv, power_well, false);
  370. }
  371. static void chv_dpio_cmn_power_well_enable(struct drm_i915_private *dev_priv,
  372. struct i915_power_well *power_well)
  373. {
  374. enum dpio_phy phy;
  375. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
  376. power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
  377. /*
  378. * Enable the CRI clock source so we can get at the
  379. * display and the reference clock for VGA
  380. * hotplug / manual detection.
  381. */
  382. if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
  383. phy = DPIO_PHY0;
  384. I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) |
  385. DPLL_REFA_CLK_ENABLE_VLV);
  386. I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) |
  387. DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
  388. } else {
  389. phy = DPIO_PHY1;
  390. I915_WRITE(DPLL(PIPE_C), I915_READ(DPLL(PIPE_C)) |
  391. DPLL_REFA_CLK_ENABLE_VLV | DPLL_INTEGRATED_CRI_CLK_VLV);
  392. }
  393. udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
  394. vlv_set_power_well(dev_priv, power_well, true);
  395. /* Poll for phypwrgood signal */
  396. if (wait_for(I915_READ(DISPLAY_PHY_STATUS) & PHY_POWERGOOD(phy), 1))
  397. DRM_ERROR("Display PHY %d is not power up\n", phy);
  398. I915_WRITE(DISPLAY_PHY_CONTROL, I915_READ(DISPLAY_PHY_CONTROL) |
  399. PHY_COM_LANE_RESET_DEASSERT(phy));
  400. }
  401. static void chv_dpio_cmn_power_well_disable(struct drm_i915_private *dev_priv,
  402. struct i915_power_well *power_well)
  403. {
  404. enum dpio_phy phy;
  405. WARN_ON_ONCE(power_well->data != PUNIT_POWER_WELL_DPIO_CMN_BC &&
  406. power_well->data != PUNIT_POWER_WELL_DPIO_CMN_D);
  407. if (power_well->data == PUNIT_POWER_WELL_DPIO_CMN_BC) {
  408. phy = DPIO_PHY0;
  409. assert_pll_disabled(dev_priv, PIPE_A);
  410. assert_pll_disabled(dev_priv, PIPE_B);
  411. } else {
  412. phy = DPIO_PHY1;
  413. assert_pll_disabled(dev_priv, PIPE_C);
  414. }
  415. I915_WRITE(DISPLAY_PHY_CONTROL, I915_READ(DISPLAY_PHY_CONTROL) &
  416. ~PHY_COM_LANE_RESET_DEASSERT(phy));
  417. vlv_set_power_well(dev_priv, power_well, false);
  418. }
  419. static bool chv_pipe_power_well_enabled(struct drm_i915_private *dev_priv,
  420. struct i915_power_well *power_well)
  421. {
  422. enum pipe pipe = power_well->data;
  423. bool enabled;
  424. u32 state, ctrl;
  425. mutex_lock(&dev_priv->rps.hw_lock);
  426. state = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe);
  427. /*
  428. * We only ever set the power-on and power-gate states, anything
  429. * else is unexpected.
  430. */
  431. WARN_ON(state != DP_SSS_PWR_ON(pipe) && state != DP_SSS_PWR_GATE(pipe));
  432. enabled = state == DP_SSS_PWR_ON(pipe);
  433. /*
  434. * A transient state at this point would mean some unexpected party
  435. * is poking at the power controls too.
  436. */
  437. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSC_MASK(pipe);
  438. WARN_ON(ctrl << 16 != state);
  439. mutex_unlock(&dev_priv->rps.hw_lock);
  440. return enabled;
  441. }
  442. static void chv_set_pipe_power_well(struct drm_i915_private *dev_priv,
  443. struct i915_power_well *power_well,
  444. bool enable)
  445. {
  446. enum pipe pipe = power_well->data;
  447. u32 state;
  448. u32 ctrl;
  449. state = enable ? DP_SSS_PWR_ON(pipe) : DP_SSS_PWR_GATE(pipe);
  450. mutex_lock(&dev_priv->rps.hw_lock);
  451. #define COND \
  452. ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
  453. if (COND)
  454. goto out;
  455. ctrl = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  456. ctrl &= ~DP_SSC_MASK(pipe);
  457. ctrl |= enable ? DP_SSC_PWR_ON(pipe) : DP_SSC_PWR_GATE(pipe);
  458. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, ctrl);
  459. if (wait_for(COND, 100))
  460. DRM_ERROR("timout setting power well state %08x (%08x)\n",
  461. state,
  462. vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ));
  463. #undef COND
  464. out:
  465. mutex_unlock(&dev_priv->rps.hw_lock);
  466. }
  467. static void chv_pipe_power_well_sync_hw(struct drm_i915_private *dev_priv,
  468. struct i915_power_well *power_well)
  469. {
  470. chv_set_pipe_power_well(dev_priv, power_well, power_well->count > 0);
  471. }
  472. static void chv_pipe_power_well_enable(struct drm_i915_private *dev_priv,
  473. struct i915_power_well *power_well)
  474. {
  475. WARN_ON_ONCE(power_well->data != PIPE_A &&
  476. power_well->data != PIPE_B &&
  477. power_well->data != PIPE_C);
  478. chv_set_pipe_power_well(dev_priv, power_well, true);
  479. if (power_well->data == PIPE_A) {
  480. spin_lock_irq(&dev_priv->irq_lock);
  481. valleyview_enable_display_irqs(dev_priv);
  482. spin_unlock_irq(&dev_priv->irq_lock);
  483. /*
  484. * During driver initialization/resume we can avoid restoring the
  485. * part of the HW/SW state that will be inited anyway explicitly.
  486. */
  487. if (dev_priv->power_domains.initializing)
  488. return;
  489. intel_hpd_init(dev_priv);
  490. i915_redisable_vga_power_on(dev_priv->dev);
  491. }
  492. }
  493. static void chv_pipe_power_well_disable(struct drm_i915_private *dev_priv,
  494. struct i915_power_well *power_well)
  495. {
  496. WARN_ON_ONCE(power_well->data != PIPE_A &&
  497. power_well->data != PIPE_B &&
  498. power_well->data != PIPE_C);
  499. if (power_well->data == PIPE_A) {
  500. spin_lock_irq(&dev_priv->irq_lock);
  501. valleyview_disable_display_irqs(dev_priv);
  502. spin_unlock_irq(&dev_priv->irq_lock);
  503. }
  504. chv_set_pipe_power_well(dev_priv, power_well, false);
  505. if (power_well->data == PIPE_A)
  506. vlv_power_sequencer_reset(dev_priv);
  507. }
  508. /**
  509. * intel_display_power_get - grab a power domain reference
  510. * @dev_priv: i915 device instance
  511. * @domain: power domain to reference
  512. *
  513. * This function grabs a power domain reference for @domain and ensures that the
  514. * power domain and all its parents are powered up. Therefore users should only
  515. * grab a reference to the innermost power domain they need.
  516. *
  517. * Any power domain reference obtained by this function must have a symmetric
  518. * call to intel_display_power_put() to release the reference again.
  519. */
  520. void intel_display_power_get(struct drm_i915_private *dev_priv,
  521. enum intel_display_power_domain domain)
  522. {
  523. struct i915_power_domains *power_domains;
  524. struct i915_power_well *power_well;
  525. int i;
  526. intel_runtime_pm_get(dev_priv);
  527. power_domains = &dev_priv->power_domains;
  528. mutex_lock(&power_domains->lock);
  529. for_each_power_well(i, power_well, BIT(domain), power_domains) {
  530. if (!power_well->count++) {
  531. DRM_DEBUG_KMS("enabling %s\n", power_well->name);
  532. power_well->ops->enable(dev_priv, power_well);
  533. power_well->hw_enabled = true;
  534. }
  535. }
  536. power_domains->domain_use_count[domain]++;
  537. mutex_unlock(&power_domains->lock);
  538. }
  539. /**
  540. * intel_display_power_put - release a power domain reference
  541. * @dev_priv: i915 device instance
  542. * @domain: power domain to reference
  543. *
  544. * This function drops the power domain reference obtained by
  545. * intel_display_power_get() and might power down the corresponding hardware
  546. * block right away if this is the last reference.
  547. */
  548. void intel_display_power_put(struct drm_i915_private *dev_priv,
  549. enum intel_display_power_domain domain)
  550. {
  551. struct i915_power_domains *power_domains;
  552. struct i915_power_well *power_well;
  553. int i;
  554. power_domains = &dev_priv->power_domains;
  555. mutex_lock(&power_domains->lock);
  556. WARN_ON(!power_domains->domain_use_count[domain]);
  557. power_domains->domain_use_count[domain]--;
  558. for_each_power_well_rev(i, power_well, BIT(domain), power_domains) {
  559. WARN_ON(!power_well->count);
  560. if (!--power_well->count && i915.disable_power_well) {
  561. DRM_DEBUG_KMS("disabling %s\n", power_well->name);
  562. power_well->hw_enabled = false;
  563. power_well->ops->disable(dev_priv, power_well);
  564. }
  565. }
  566. mutex_unlock(&power_domains->lock);
  567. intel_runtime_pm_put(dev_priv);
  568. }
  569. #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
  570. #define HSW_ALWAYS_ON_POWER_DOMAINS ( \
  571. BIT(POWER_DOMAIN_PIPE_A) | \
  572. BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
  573. BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
  574. BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
  575. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  576. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  577. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  578. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  579. BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
  580. BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
  581. BIT(POWER_DOMAIN_PORT_CRT) | \
  582. BIT(POWER_DOMAIN_PLLS) | \
  583. BIT(POWER_DOMAIN_INIT))
  584. #define HSW_DISPLAY_POWER_DOMAINS ( \
  585. (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \
  586. BIT(POWER_DOMAIN_INIT))
  587. #define BDW_ALWAYS_ON_POWER_DOMAINS ( \
  588. HSW_ALWAYS_ON_POWER_DOMAINS | \
  589. BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER))
  590. #define BDW_DISPLAY_POWER_DOMAINS ( \
  591. (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \
  592. BIT(POWER_DOMAIN_INIT))
  593. #define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT)
  594. #define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK
  595. #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
  596. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  597. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  598. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  599. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  600. BIT(POWER_DOMAIN_PORT_CRT) | \
  601. BIT(POWER_DOMAIN_INIT))
  602. #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
  603. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  604. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  605. BIT(POWER_DOMAIN_INIT))
  606. #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
  607. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  608. BIT(POWER_DOMAIN_INIT))
  609. #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
  610. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  611. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  612. BIT(POWER_DOMAIN_INIT))
  613. #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
  614. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  615. BIT(POWER_DOMAIN_INIT))
  616. #define CHV_PIPE_A_POWER_DOMAINS ( \
  617. BIT(POWER_DOMAIN_PIPE_A) | \
  618. BIT(POWER_DOMAIN_INIT))
  619. #define CHV_PIPE_B_POWER_DOMAINS ( \
  620. BIT(POWER_DOMAIN_PIPE_B) | \
  621. BIT(POWER_DOMAIN_INIT))
  622. #define CHV_PIPE_C_POWER_DOMAINS ( \
  623. BIT(POWER_DOMAIN_PIPE_C) | \
  624. BIT(POWER_DOMAIN_INIT))
  625. #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
  626. BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
  627. BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
  628. BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
  629. BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
  630. BIT(POWER_DOMAIN_INIT))
  631. #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
  632. BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
  633. BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
  634. BIT(POWER_DOMAIN_INIT))
  635. #define CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS ( \
  636. BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
  637. BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
  638. BIT(POWER_DOMAIN_INIT))
  639. #define CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS ( \
  640. BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
  641. BIT(POWER_DOMAIN_INIT))
  642. static const struct i915_power_well_ops i9xx_always_on_power_well_ops = {
  643. .sync_hw = i9xx_always_on_power_well_noop,
  644. .enable = i9xx_always_on_power_well_noop,
  645. .disable = i9xx_always_on_power_well_noop,
  646. .is_enabled = i9xx_always_on_power_well_enabled,
  647. };
  648. static const struct i915_power_well_ops chv_pipe_power_well_ops = {
  649. .sync_hw = chv_pipe_power_well_sync_hw,
  650. .enable = chv_pipe_power_well_enable,
  651. .disable = chv_pipe_power_well_disable,
  652. .is_enabled = chv_pipe_power_well_enabled,
  653. };
  654. static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops = {
  655. .sync_hw = vlv_power_well_sync_hw,
  656. .enable = chv_dpio_cmn_power_well_enable,
  657. .disable = chv_dpio_cmn_power_well_disable,
  658. .is_enabled = vlv_power_well_enabled,
  659. };
  660. static struct i915_power_well i9xx_always_on_power_well[] = {
  661. {
  662. .name = "always-on",
  663. .always_on = 1,
  664. .domains = POWER_DOMAIN_MASK,
  665. .ops = &i9xx_always_on_power_well_ops,
  666. },
  667. };
  668. static const struct i915_power_well_ops hsw_power_well_ops = {
  669. .sync_hw = hsw_power_well_sync_hw,
  670. .enable = hsw_power_well_enable,
  671. .disable = hsw_power_well_disable,
  672. .is_enabled = hsw_power_well_enabled,
  673. };
  674. static struct i915_power_well hsw_power_wells[] = {
  675. {
  676. .name = "always-on",
  677. .always_on = 1,
  678. .domains = HSW_ALWAYS_ON_POWER_DOMAINS,
  679. .ops = &i9xx_always_on_power_well_ops,
  680. },
  681. {
  682. .name = "display",
  683. .domains = HSW_DISPLAY_POWER_DOMAINS,
  684. .ops = &hsw_power_well_ops,
  685. },
  686. };
  687. static struct i915_power_well bdw_power_wells[] = {
  688. {
  689. .name = "always-on",
  690. .always_on = 1,
  691. .domains = BDW_ALWAYS_ON_POWER_DOMAINS,
  692. .ops = &i9xx_always_on_power_well_ops,
  693. },
  694. {
  695. .name = "display",
  696. .domains = BDW_DISPLAY_POWER_DOMAINS,
  697. .ops = &hsw_power_well_ops,
  698. },
  699. };
  700. static const struct i915_power_well_ops vlv_display_power_well_ops = {
  701. .sync_hw = vlv_power_well_sync_hw,
  702. .enable = vlv_display_power_well_enable,
  703. .disable = vlv_display_power_well_disable,
  704. .is_enabled = vlv_power_well_enabled,
  705. };
  706. static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops = {
  707. .sync_hw = vlv_power_well_sync_hw,
  708. .enable = vlv_dpio_cmn_power_well_enable,
  709. .disable = vlv_dpio_cmn_power_well_disable,
  710. .is_enabled = vlv_power_well_enabled,
  711. };
  712. static const struct i915_power_well_ops vlv_dpio_power_well_ops = {
  713. .sync_hw = vlv_power_well_sync_hw,
  714. .enable = vlv_power_well_enable,
  715. .disable = vlv_power_well_disable,
  716. .is_enabled = vlv_power_well_enabled,
  717. };
  718. static struct i915_power_well vlv_power_wells[] = {
  719. {
  720. .name = "always-on",
  721. .always_on = 1,
  722. .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
  723. .ops = &i9xx_always_on_power_well_ops,
  724. },
  725. {
  726. .name = "display",
  727. .domains = VLV_DISPLAY_POWER_DOMAINS,
  728. .data = PUNIT_POWER_WELL_DISP2D,
  729. .ops = &vlv_display_power_well_ops,
  730. },
  731. {
  732. .name = "dpio-tx-b-01",
  733. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  734. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  735. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  736. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  737. .ops = &vlv_dpio_power_well_ops,
  738. .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
  739. },
  740. {
  741. .name = "dpio-tx-b-23",
  742. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  743. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  744. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  745. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  746. .ops = &vlv_dpio_power_well_ops,
  747. .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
  748. },
  749. {
  750. .name = "dpio-tx-c-01",
  751. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  752. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  753. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  754. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  755. .ops = &vlv_dpio_power_well_ops,
  756. .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
  757. },
  758. {
  759. .name = "dpio-tx-c-23",
  760. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  761. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS |
  762. VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  763. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  764. .ops = &vlv_dpio_power_well_ops,
  765. .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
  766. },
  767. {
  768. .name = "dpio-common",
  769. .domains = VLV_DPIO_CMN_BC_POWER_DOMAINS,
  770. .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
  771. .ops = &vlv_dpio_cmn_power_well_ops,
  772. },
  773. };
  774. static struct i915_power_well chv_power_wells[] = {
  775. {
  776. .name = "always-on",
  777. .always_on = 1,
  778. .domains = VLV_ALWAYS_ON_POWER_DOMAINS,
  779. .ops = &i9xx_always_on_power_well_ops,
  780. },
  781. #if 0
  782. {
  783. .name = "display",
  784. .domains = VLV_DISPLAY_POWER_DOMAINS,
  785. .data = PUNIT_POWER_WELL_DISP2D,
  786. .ops = &vlv_display_power_well_ops,
  787. },
  788. #endif
  789. {
  790. .name = "pipe-a",
  791. /*
  792. * FIXME: pipe A power well seems to be the new disp2d well.
  793. * At least all registers seem to be housed there. Figure
  794. * out if this a a temporary situation in pre-production
  795. * hardware or a permanent state of affairs.
  796. */
  797. .domains = CHV_PIPE_A_POWER_DOMAINS | VLV_DISPLAY_POWER_DOMAINS,
  798. .data = PIPE_A,
  799. .ops = &chv_pipe_power_well_ops,
  800. },
  801. #if 0
  802. {
  803. .name = "pipe-b",
  804. .domains = CHV_PIPE_B_POWER_DOMAINS,
  805. .data = PIPE_B,
  806. .ops = &chv_pipe_power_well_ops,
  807. },
  808. {
  809. .name = "pipe-c",
  810. .domains = CHV_PIPE_C_POWER_DOMAINS,
  811. .data = PIPE_C,
  812. .ops = &chv_pipe_power_well_ops,
  813. },
  814. #endif
  815. {
  816. .name = "dpio-common-bc",
  817. /*
  818. * XXX: cmnreset for one PHY seems to disturb the other.
  819. * As a workaround keep both powered on at the same
  820. * time for now.
  821. */
  822. .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS | CHV_DPIO_CMN_D_POWER_DOMAINS,
  823. .data = PUNIT_POWER_WELL_DPIO_CMN_BC,
  824. .ops = &chv_dpio_cmn_power_well_ops,
  825. },
  826. {
  827. .name = "dpio-common-d",
  828. /*
  829. * XXX: cmnreset for one PHY seems to disturb the other.
  830. * As a workaround keep both powered on at the same
  831. * time for now.
  832. */
  833. .domains = CHV_DPIO_CMN_BC_POWER_DOMAINS | CHV_DPIO_CMN_D_POWER_DOMAINS,
  834. .data = PUNIT_POWER_WELL_DPIO_CMN_D,
  835. .ops = &chv_dpio_cmn_power_well_ops,
  836. },
  837. #if 0
  838. {
  839. .name = "dpio-tx-b-01",
  840. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  841. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS,
  842. .ops = &vlv_dpio_power_well_ops,
  843. .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_01,
  844. },
  845. {
  846. .name = "dpio-tx-b-23",
  847. .domains = VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS |
  848. VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS,
  849. .ops = &vlv_dpio_power_well_ops,
  850. .data = PUNIT_POWER_WELL_DPIO_TX_B_LANES_23,
  851. },
  852. {
  853. .name = "dpio-tx-c-01",
  854. .domains = VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  855. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  856. .ops = &vlv_dpio_power_well_ops,
  857. .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_01,
  858. },
  859. {
  860. .name = "dpio-tx-c-23",
  861. .domains = VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS |
  862. VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS,
  863. .ops = &vlv_dpio_power_well_ops,
  864. .data = PUNIT_POWER_WELL_DPIO_TX_C_LANES_23,
  865. },
  866. {
  867. .name = "dpio-tx-d-01",
  868. .domains = CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS |
  869. CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS,
  870. .ops = &vlv_dpio_power_well_ops,
  871. .data = PUNIT_POWER_WELL_DPIO_TX_D_LANES_01,
  872. },
  873. {
  874. .name = "dpio-tx-d-23",
  875. .domains = CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS |
  876. CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS,
  877. .ops = &vlv_dpio_power_well_ops,
  878. .data = PUNIT_POWER_WELL_DPIO_TX_D_LANES_23,
  879. },
  880. #endif
  881. };
  882. static struct i915_power_well *lookup_power_well(struct drm_i915_private *dev_priv,
  883. enum punit_power_well power_well_id)
  884. {
  885. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  886. struct i915_power_well *power_well;
  887. int i;
  888. for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
  889. if (power_well->data == power_well_id)
  890. return power_well;
  891. }
  892. return NULL;
  893. }
  894. #define set_power_wells(power_domains, __power_wells) ({ \
  895. (power_domains)->power_wells = (__power_wells); \
  896. (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
  897. })
  898. /**
  899. * intel_power_domains_init - initializes the power domain structures
  900. * @dev_priv: i915 device instance
  901. *
  902. * Initializes the power domain structures for @dev_priv depending upon the
  903. * supported platform.
  904. */
  905. int intel_power_domains_init(struct drm_i915_private *dev_priv)
  906. {
  907. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  908. mutex_init(&power_domains->lock);
  909. /*
  910. * The enabling order will be from lower to higher indexed wells,
  911. * the disabling order is reversed.
  912. */
  913. if (IS_HASWELL(dev_priv->dev)) {
  914. set_power_wells(power_domains, hsw_power_wells);
  915. hsw_pwr = power_domains;
  916. } else if (IS_BROADWELL(dev_priv->dev)) {
  917. set_power_wells(power_domains, bdw_power_wells);
  918. hsw_pwr = power_domains;
  919. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  920. set_power_wells(power_domains, chv_power_wells);
  921. } else if (IS_VALLEYVIEW(dev_priv->dev)) {
  922. set_power_wells(power_domains, vlv_power_wells);
  923. } else {
  924. set_power_wells(power_domains, i9xx_always_on_power_well);
  925. }
  926. return 0;
  927. }
  928. static void intel_runtime_pm_disable(struct drm_i915_private *dev_priv)
  929. {
  930. struct drm_device *dev = dev_priv->dev;
  931. struct device *device = &dev->pdev->dev;
  932. if (!HAS_RUNTIME_PM(dev))
  933. return;
  934. if (!intel_enable_rc6(dev))
  935. return;
  936. /* Make sure we're not suspended first. */
  937. pm_runtime_get_sync(device);
  938. pm_runtime_disable(device);
  939. }
  940. /**
  941. * intel_power_domains_fini - finalizes the power domain structures
  942. * @dev_priv: i915 device instance
  943. *
  944. * Finalizes the power domain structures for @dev_priv depending upon the
  945. * supported platform. This function also disables runtime pm and ensures that
  946. * the device stays powered up so that the driver can be reloaded.
  947. */
  948. void intel_power_domains_fini(struct drm_i915_private *dev_priv)
  949. {
  950. intel_runtime_pm_disable(dev_priv);
  951. /* The i915.ko module is still not prepared to be loaded when
  952. * the power well is not enabled, so just enable it in case
  953. * we're going to unload/reload. */
  954. intel_display_set_init_power(dev_priv, true);
  955. hsw_pwr = NULL;
  956. }
  957. static void intel_power_domains_resume(struct drm_i915_private *dev_priv)
  958. {
  959. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  960. struct i915_power_well *power_well;
  961. int i;
  962. mutex_lock(&power_domains->lock);
  963. for_each_power_well(i, power_well, POWER_DOMAIN_MASK, power_domains) {
  964. power_well->ops->sync_hw(dev_priv, power_well);
  965. power_well->hw_enabled = power_well->ops->is_enabled(dev_priv,
  966. power_well);
  967. }
  968. mutex_unlock(&power_domains->lock);
  969. }
  970. static void vlv_cmnlane_wa(struct drm_i915_private *dev_priv)
  971. {
  972. struct i915_power_well *cmn =
  973. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC);
  974. struct i915_power_well *disp2d =
  975. lookup_power_well(dev_priv, PUNIT_POWER_WELL_DISP2D);
  976. /* If the display might be already active skip this */
  977. if (cmn->ops->is_enabled(dev_priv, cmn) &&
  978. disp2d->ops->is_enabled(dev_priv, disp2d) &&
  979. I915_READ(DPIO_CTL) & DPIO_CMNRST)
  980. return;
  981. DRM_DEBUG_KMS("toggling display PHY side reset\n");
  982. /* cmnlane needs DPLL registers */
  983. disp2d->ops->enable(dev_priv, disp2d);
  984. /*
  985. * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
  986. * Need to assert and de-assert PHY SB reset by gating the
  987. * common lane power, then un-gating it.
  988. * Simply ungating isn't enough to reset the PHY enough to get
  989. * ports and lanes running.
  990. */
  991. cmn->ops->disable(dev_priv, cmn);
  992. }
  993. /**
  994. * intel_power_domains_init_hw - initialize hardware power domain state
  995. * @dev_priv: i915 device instance
  996. *
  997. * This function initializes the hardware power domain state and enables all
  998. * power domains using intel_display_set_init_power().
  999. */
  1000. void intel_power_domains_init_hw(struct drm_i915_private *dev_priv)
  1001. {
  1002. struct drm_device *dev = dev_priv->dev;
  1003. struct i915_power_domains *power_domains = &dev_priv->power_domains;
  1004. power_domains->initializing = true;
  1005. if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) {
  1006. mutex_lock(&power_domains->lock);
  1007. vlv_cmnlane_wa(dev_priv);
  1008. mutex_unlock(&power_domains->lock);
  1009. }
  1010. /* For now, we need the power well to be always enabled. */
  1011. intel_display_set_init_power(dev_priv, true);
  1012. intel_power_domains_resume(dev_priv);
  1013. power_domains->initializing = false;
  1014. }
  1015. /**
  1016. * intel_aux_display_runtime_get - grab an auxilliary power domain reference
  1017. * @dev_priv: i915 device instance
  1018. *
  1019. * This function grabs a power domain reference for the auxiliary power domain
  1020. * (for access to the GMBUS and DP AUX blocks) and ensures that it and all its
  1021. * parents are powered up. Therefore users should only grab a reference to the
  1022. * innermost power domain they need.
  1023. *
  1024. * Any power domain reference obtained by this function must have a symmetric
  1025. * call to intel_aux_display_runtime_put() to release the reference again.
  1026. */
  1027. void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv)
  1028. {
  1029. intel_runtime_pm_get(dev_priv);
  1030. }
  1031. /**
  1032. * intel_aux_display_runtime_put - release an auxilliary power domain reference
  1033. * @dev_priv: i915 device instance
  1034. *
  1035. * This function drops the auxilliary power domain reference obtained by
  1036. * intel_aux_display_runtime_get() and might power down the corresponding
  1037. * hardware block right away if this is the last reference.
  1038. */
  1039. void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv)
  1040. {
  1041. intel_runtime_pm_put(dev_priv);
  1042. }
  1043. /**
  1044. * intel_runtime_pm_get - grab a runtime pm reference
  1045. * @dev_priv: i915 device instance
  1046. *
  1047. * This function grabs a device-level runtime pm reference (mostly used for GEM
  1048. * code to ensure the GTT or GT is on) and ensures that it is powered up.
  1049. *
  1050. * Any runtime pm reference obtained by this function must have a symmetric
  1051. * call to intel_runtime_pm_put() to release the reference again.
  1052. */
  1053. void intel_runtime_pm_get(struct drm_i915_private *dev_priv)
  1054. {
  1055. struct drm_device *dev = dev_priv->dev;
  1056. struct device *device = &dev->pdev->dev;
  1057. if (!HAS_RUNTIME_PM(dev))
  1058. return;
  1059. pm_runtime_get_sync(device);
  1060. WARN(dev_priv->pm.suspended, "Device still suspended.\n");
  1061. }
  1062. /**
  1063. * intel_runtime_pm_get_noresume - grab a runtime pm reference
  1064. * @dev_priv: i915 device instance
  1065. *
  1066. * This function grabs a device-level runtime pm reference (mostly used for GEM
  1067. * code to ensure the GTT or GT is on).
  1068. *
  1069. * It will _not_ power up the device but instead only check that it's powered
  1070. * on. Therefore it is only valid to call this functions from contexts where
  1071. * the device is known to be powered up and where trying to power it up would
  1072. * result in hilarity and deadlocks. That pretty much means only the system
  1073. * suspend/resume code where this is used to grab runtime pm references for
  1074. * delayed setup down in work items.
  1075. *
  1076. * Any runtime pm reference obtained by this function must have a symmetric
  1077. * call to intel_runtime_pm_put() to release the reference again.
  1078. */
  1079. void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv)
  1080. {
  1081. struct drm_device *dev = dev_priv->dev;
  1082. struct device *device = &dev->pdev->dev;
  1083. if (!HAS_RUNTIME_PM(dev))
  1084. return;
  1085. WARN(dev_priv->pm.suspended, "Getting nosync-ref while suspended.\n");
  1086. pm_runtime_get_noresume(device);
  1087. }
  1088. /**
  1089. * intel_runtime_pm_put - release a runtime pm reference
  1090. * @dev_priv: i915 device instance
  1091. *
  1092. * This function drops the device-level runtime pm reference obtained by
  1093. * intel_runtime_pm_get() and might power down the corresponding
  1094. * hardware block right away if this is the last reference.
  1095. */
  1096. void intel_runtime_pm_put(struct drm_i915_private *dev_priv)
  1097. {
  1098. struct drm_device *dev = dev_priv->dev;
  1099. struct device *device = &dev->pdev->dev;
  1100. if (!HAS_RUNTIME_PM(dev))
  1101. return;
  1102. pm_runtime_mark_last_busy(device);
  1103. pm_runtime_put_autosuspend(device);
  1104. }
  1105. /**
  1106. * intel_runtime_pm_enable - enable runtime pm
  1107. * @dev_priv: i915 device instance
  1108. *
  1109. * This function enables runtime pm at the end of the driver load sequence.
  1110. *
  1111. * Note that this function does currently not enable runtime pm for the
  1112. * subordinate display power domains. That is only done on the first modeset
  1113. * using intel_display_set_init_power().
  1114. */
  1115. void intel_runtime_pm_enable(struct drm_i915_private *dev_priv)
  1116. {
  1117. struct drm_device *dev = dev_priv->dev;
  1118. struct device *device = &dev->pdev->dev;
  1119. if (!HAS_RUNTIME_PM(dev))
  1120. return;
  1121. pm_runtime_set_active(device);
  1122. /*
  1123. * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
  1124. * requirement.
  1125. */
  1126. if (!intel_enable_rc6(dev)) {
  1127. DRM_INFO("RC6 disabled, disabling runtime PM support\n");
  1128. return;
  1129. }
  1130. pm_runtime_set_autosuspend_delay(device, 10000); /* 10s */
  1131. pm_runtime_mark_last_busy(device);
  1132. pm_runtime_use_autosuspend(device);
  1133. pm_runtime_put_autosuspend(device);
  1134. }
  1135. /* Display audio driver power well request */
  1136. int i915_request_power_well(void)
  1137. {
  1138. struct drm_i915_private *dev_priv;
  1139. if (!hsw_pwr)
  1140. return -ENODEV;
  1141. dev_priv = container_of(hsw_pwr, struct drm_i915_private,
  1142. power_domains);
  1143. intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
  1144. return 0;
  1145. }
  1146. EXPORT_SYMBOL_GPL(i915_request_power_well);
  1147. /* Display audio driver power well release */
  1148. int i915_release_power_well(void)
  1149. {
  1150. struct drm_i915_private *dev_priv;
  1151. if (!hsw_pwr)
  1152. return -ENODEV;
  1153. dev_priv = container_of(hsw_pwr, struct drm_i915_private,
  1154. power_domains);
  1155. intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
  1156. return 0;
  1157. }
  1158. EXPORT_SYMBOL_GPL(i915_release_power_well);
  1159. /*
  1160. * Private interface for the audio driver to get CDCLK in kHz.
  1161. *
  1162. * Caller must request power well using i915_request_power_well() prior to
  1163. * making the call.
  1164. */
  1165. int i915_get_cdclk_freq(void)
  1166. {
  1167. struct drm_i915_private *dev_priv;
  1168. if (!hsw_pwr)
  1169. return -ENODEV;
  1170. dev_priv = container_of(hsw_pwr, struct drm_i915_private,
  1171. power_domains);
  1172. return intel_ddi_get_cdclk_freq(dev_priv);
  1173. }
  1174. EXPORT_SYMBOL_GPL(i915_get_cdclk_freq);