intel_dpio_phy.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  1. /*
  2. * Copyright © 2014-2016 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
  21. * DEALINGS IN THE SOFTWARE.
  22. */
  23. #include "intel_drv.h"
  24. /**
  25. * DOC: DPIO
  26. *
  27. * VLV, CHV and BXT have slightly peculiar display PHYs for driving DP/HDMI
  28. * ports. DPIO is the name given to such a display PHY. These PHYs
  29. * don't follow the standard programming model using direct MMIO
  30. * registers, and instead their registers must be accessed trough IOSF
  31. * sideband. VLV has one such PHY for driving ports B and C, and CHV
  32. * adds another PHY for driving port D. Each PHY responds to specific
  33. * IOSF-SB port.
  34. *
  35. * Each display PHY is made up of one or two channels. Each channel
  36. * houses a common lane part which contains the PLL and other common
  37. * logic. CH0 common lane also contains the IOSF-SB logic for the
  38. * Common Register Interface (CRI) ie. the DPIO registers. CRI clock
  39. * must be running when any DPIO registers are accessed.
  40. *
  41. * In addition to having their own registers, the PHYs are also
  42. * controlled through some dedicated signals from the display
  43. * controller. These include PLL reference clock enable, PLL enable,
  44. * and CRI clock selection, for example.
  45. *
  46. * Eeach channel also has two splines (also called data lanes), and
  47. * each spline is made up of one Physical Access Coding Sub-Layer
  48. * (PCS) block and two TX lanes. So each channel has two PCS blocks
  49. * and four TX lanes. The TX lanes are used as DP lanes or TMDS
  50. * data/clock pairs depending on the output type.
  51. *
  52. * Additionally the PHY also contains an AUX lane with AUX blocks
  53. * for each channel. This is used for DP AUX communication, but
  54. * this fact isn't really relevant for the driver since AUX is
  55. * controlled from the display controller side. No DPIO registers
  56. * need to be accessed during AUX communication,
  57. *
  58. * Generally on VLV/CHV the common lane corresponds to the pipe and
  59. * the spline (PCS/TX) corresponds to the port.
  60. *
  61. * For dual channel PHY (VLV/CHV):
  62. *
  63. * pipe A == CMN/PLL/REF CH0
  64. *
  65. * pipe B == CMN/PLL/REF CH1
  66. *
  67. * port B == PCS/TX CH0
  68. *
  69. * port C == PCS/TX CH1
  70. *
  71. * This is especially important when we cross the streams
  72. * ie. drive port B with pipe B, or port C with pipe A.
  73. *
  74. * For single channel PHY (CHV):
  75. *
  76. * pipe C == CMN/PLL/REF CH0
  77. *
  78. * port D == PCS/TX CH0
  79. *
  80. * On BXT the entire PHY channel corresponds to the port. That means
  81. * the PLL is also now associated with the port rather than the pipe,
  82. * and so the clock needs to be routed to the appropriate transcoder.
  83. * Port A PLL is directly connected to transcoder EDP and port B/C
  84. * PLLs can be routed to any transcoder A/B/C.
  85. *
  86. * Note: DDI0 is digital port B, DD1 is digital port C, and DDI2 is
  87. * digital port D (CHV) or port A (BXT). ::
  88. *
  89. *
  90. * Dual channel PHY (VLV/CHV/BXT)
  91. * ---------------------------------
  92. * | CH0 | CH1 |
  93. * | CMN/PLL/REF | CMN/PLL/REF |
  94. * |---------------|---------------| Display PHY
  95. * | PCS01 | PCS23 | PCS01 | PCS23 |
  96. * |-------|-------|-------|-------|
  97. * |TX0|TX1|TX2|TX3|TX0|TX1|TX2|TX3|
  98. * ---------------------------------
  99. * | DDI0 | DDI1 | DP/HDMI ports
  100. * ---------------------------------
  101. *
  102. * Single channel PHY (CHV/BXT)
  103. * -----------------
  104. * | CH0 |
  105. * | CMN/PLL/REF |
  106. * |---------------| Display PHY
  107. * | PCS01 | PCS23 |
  108. * |-------|-------|
  109. * |TX0|TX1|TX2|TX3|
  110. * -----------------
  111. * | DDI2 | DP/HDMI port
  112. * -----------------
  113. */
  114. /**
  115. * struct bxt_ddi_phy_info - Hold info for a broxton DDI phy
  116. */
  117. struct bxt_ddi_phy_info {
  118. /**
  119. * @dual_channel: true if this phy has a second channel.
  120. */
  121. bool dual_channel;
  122. /**
  123. * @rcomp_phy: If -1, indicates this phy has its own rcomp resistor.
  124. * Otherwise the GRC value will be copied from the phy indicated by
  125. * this field.
  126. */
  127. enum dpio_phy rcomp_phy;
  128. /**
  129. * @reset_delay: delay in us to wait before setting the common reset
  130. * bit in BXT_PHY_CTL_FAMILY, which effectively enables the phy.
  131. */
  132. int reset_delay;
  133. /**
  134. * @pwron_mask: Mask with the appropriate bit set that would cause the
  135. * punit to power this phy if written to BXT_P_CR_GT_DISP_PWRON.
  136. */
  137. u32 pwron_mask;
  138. /**
  139. * @channel: struct containing per channel information.
  140. */
  141. struct {
  142. /**
  143. * @port: which port maps to this channel.
  144. */
  145. enum port port;
  146. } channel[2];
  147. };
  148. static const struct bxt_ddi_phy_info bxt_ddi_phy_info[] = {
  149. [DPIO_PHY0] = {
  150. .dual_channel = true,
  151. .rcomp_phy = DPIO_PHY1,
  152. .pwron_mask = BIT(0),
  153. .channel = {
  154. [DPIO_CH0] = { .port = PORT_B },
  155. [DPIO_CH1] = { .port = PORT_C },
  156. }
  157. },
  158. [DPIO_PHY1] = {
  159. .dual_channel = false,
  160. .rcomp_phy = -1,
  161. .pwron_mask = BIT(1),
  162. .channel = {
  163. [DPIO_CH0] = { .port = PORT_A },
  164. }
  165. },
  166. };
  167. static const struct bxt_ddi_phy_info glk_ddi_phy_info[] = {
  168. [DPIO_PHY0] = {
  169. .dual_channel = false,
  170. .rcomp_phy = DPIO_PHY1,
  171. .pwron_mask = BIT(0),
  172. .reset_delay = 20,
  173. .channel = {
  174. [DPIO_CH0] = { .port = PORT_B },
  175. }
  176. },
  177. [DPIO_PHY1] = {
  178. .dual_channel = false,
  179. .rcomp_phy = -1,
  180. .pwron_mask = BIT(3),
  181. .reset_delay = 20,
  182. .channel = {
  183. [DPIO_CH0] = { .port = PORT_A },
  184. }
  185. },
  186. [DPIO_PHY2] = {
  187. .dual_channel = false,
  188. .rcomp_phy = DPIO_PHY1,
  189. .pwron_mask = BIT(1),
  190. .reset_delay = 20,
  191. .channel = {
  192. [DPIO_CH0] = { .port = PORT_C },
  193. }
  194. },
  195. };
  196. static const struct bxt_ddi_phy_info *
  197. bxt_get_phy_list(struct drm_i915_private *dev_priv, int *count)
  198. {
  199. if (IS_GEMINILAKE(dev_priv)) {
  200. *count = ARRAY_SIZE(glk_ddi_phy_info);
  201. return glk_ddi_phy_info;
  202. } else {
  203. *count = ARRAY_SIZE(bxt_ddi_phy_info);
  204. return bxt_ddi_phy_info;
  205. }
  206. }
  207. static const struct bxt_ddi_phy_info *
  208. bxt_get_phy_info(struct drm_i915_private *dev_priv, enum dpio_phy phy)
  209. {
  210. int count;
  211. const struct bxt_ddi_phy_info *phy_list =
  212. bxt_get_phy_list(dev_priv, &count);
  213. return &phy_list[phy];
  214. }
  215. void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
  216. enum dpio_phy *phy, enum dpio_channel *ch)
  217. {
  218. const struct bxt_ddi_phy_info *phy_info, *phys;
  219. int i, count;
  220. phys = bxt_get_phy_list(dev_priv, &count);
  221. for (i = 0; i < count; i++) {
  222. phy_info = &phys[i];
  223. if (port == phy_info->channel[DPIO_CH0].port) {
  224. *phy = i;
  225. *ch = DPIO_CH0;
  226. return;
  227. }
  228. if (phy_info->dual_channel &&
  229. port == phy_info->channel[DPIO_CH1].port) {
  230. *phy = i;
  231. *ch = DPIO_CH1;
  232. return;
  233. }
  234. }
  235. WARN(1, "PHY not found for PORT %c", port_name(port));
  236. *phy = DPIO_PHY0;
  237. *ch = DPIO_CH0;
  238. }
  239. void bxt_ddi_phy_set_signal_level(struct drm_i915_private *dev_priv,
  240. enum port port, u32 margin, u32 scale,
  241. u32 enable, u32 deemphasis)
  242. {
  243. u32 val;
  244. enum dpio_phy phy;
  245. enum dpio_channel ch;
  246. bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
  247. /*
  248. * While we write to the group register to program all lanes at once we
  249. * can read only lane registers and we pick lanes 0/1 for that.
  250. */
  251. val = I915_READ(BXT_PORT_PCS_DW10_LN01(phy, ch));
  252. val &= ~(TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT);
  253. I915_WRITE(BXT_PORT_PCS_DW10_GRP(phy, ch), val);
  254. val = I915_READ(BXT_PORT_TX_DW2_LN0(phy, ch));
  255. val &= ~(MARGIN_000 | UNIQ_TRANS_SCALE);
  256. val |= margin << MARGIN_000_SHIFT | scale << UNIQ_TRANS_SCALE_SHIFT;
  257. I915_WRITE(BXT_PORT_TX_DW2_GRP(phy, ch), val);
  258. val = I915_READ(BXT_PORT_TX_DW3_LN0(phy, ch));
  259. val &= ~SCALE_DCOMP_METHOD;
  260. if (enable)
  261. val |= SCALE_DCOMP_METHOD;
  262. if ((val & UNIQUE_TRANGE_EN_METHOD) && !(val & SCALE_DCOMP_METHOD))
  263. DRM_ERROR("Disabled scaling while ouniqetrangenmethod was set");
  264. I915_WRITE(BXT_PORT_TX_DW3_GRP(phy, ch), val);
  265. val = I915_READ(BXT_PORT_TX_DW4_LN0(phy, ch));
  266. val &= ~DE_EMPHASIS;
  267. val |= deemphasis << DEEMPH_SHIFT;
  268. I915_WRITE(BXT_PORT_TX_DW4_GRP(phy, ch), val);
  269. val = I915_READ(BXT_PORT_PCS_DW10_LN01(phy, ch));
  270. val |= TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT;
  271. I915_WRITE(BXT_PORT_PCS_DW10_GRP(phy, ch), val);
  272. }
  273. bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv,
  274. enum dpio_phy phy)
  275. {
  276. const struct bxt_ddi_phy_info *phy_info;
  277. phy_info = bxt_get_phy_info(dev_priv, phy);
  278. if (!(I915_READ(BXT_P_CR_GT_DISP_PWRON) & phy_info->pwron_mask))
  279. return false;
  280. if ((I915_READ(BXT_PORT_CL1CM_DW0(phy)) &
  281. (PHY_POWER_GOOD | PHY_RESERVED)) != PHY_POWER_GOOD) {
  282. DRM_DEBUG_DRIVER("DDI PHY %d powered, but power hasn't settled\n",
  283. phy);
  284. return false;
  285. }
  286. if (!(I915_READ(BXT_PHY_CTL_FAMILY(phy)) & COMMON_RESET_DIS)) {
  287. DRM_DEBUG_DRIVER("DDI PHY %d powered, but still in reset\n",
  288. phy);
  289. return false;
  290. }
  291. return true;
  292. }
  293. static u32 bxt_get_grc(struct drm_i915_private *dev_priv, enum dpio_phy phy)
  294. {
  295. u32 val = I915_READ(BXT_PORT_REF_DW6(phy));
  296. return (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT;
  297. }
  298. static void bxt_phy_wait_grc_done(struct drm_i915_private *dev_priv,
  299. enum dpio_phy phy)
  300. {
  301. if (intel_wait_for_register(dev_priv,
  302. BXT_PORT_REF_DW3(phy),
  303. GRC_DONE, GRC_DONE,
  304. 10))
  305. DRM_ERROR("timeout waiting for PHY%d GRC\n", phy);
  306. }
  307. static void _bxt_ddi_phy_init(struct drm_i915_private *dev_priv,
  308. enum dpio_phy phy)
  309. {
  310. const struct bxt_ddi_phy_info *phy_info;
  311. u32 val;
  312. phy_info = bxt_get_phy_info(dev_priv, phy);
  313. if (bxt_ddi_phy_is_enabled(dev_priv, phy)) {
  314. /* Still read out the GRC value for state verification */
  315. if (phy_info->rcomp_phy != -1)
  316. dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv, phy);
  317. if (bxt_ddi_phy_verify_state(dev_priv, phy)) {
  318. DRM_DEBUG_DRIVER("DDI PHY %d already enabled, "
  319. "won't reprogram it\n", phy);
  320. return;
  321. }
  322. DRM_DEBUG_DRIVER("DDI PHY %d enabled with invalid state, "
  323. "force reprogramming it\n", phy);
  324. }
  325. val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
  326. val |= phy_info->pwron_mask;
  327. I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
  328. /*
  329. * The PHY registers start out inaccessible and respond to reads with
  330. * all 1s. Eventually they become accessible as they power up, then
  331. * the reserved bit will give the default 0. Poll on the reserved bit
  332. * becoming 0 to find when the PHY is accessible.
  333. * HW team confirmed that the time to reach phypowergood status is
  334. * anywhere between 50 us and 100us.
  335. */
  336. if (wait_for_us(((I915_READ(BXT_PORT_CL1CM_DW0(phy)) &
  337. (PHY_RESERVED | PHY_POWER_GOOD)) == PHY_POWER_GOOD), 100)) {
  338. DRM_ERROR("timeout during PHY%d power on\n", phy);
  339. }
  340. /* Program PLL Rcomp code offset */
  341. val = I915_READ(BXT_PORT_CL1CM_DW9(phy));
  342. val &= ~IREF0RC_OFFSET_MASK;
  343. val |= 0xE4 << IREF0RC_OFFSET_SHIFT;
  344. I915_WRITE(BXT_PORT_CL1CM_DW9(phy), val);
  345. val = I915_READ(BXT_PORT_CL1CM_DW10(phy));
  346. val &= ~IREF1RC_OFFSET_MASK;
  347. val |= 0xE4 << IREF1RC_OFFSET_SHIFT;
  348. I915_WRITE(BXT_PORT_CL1CM_DW10(phy), val);
  349. /* Program power gating */
  350. val = I915_READ(BXT_PORT_CL1CM_DW28(phy));
  351. val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN |
  352. SUS_CLK_CONFIG;
  353. I915_WRITE(BXT_PORT_CL1CM_DW28(phy), val);
  354. if (phy_info->dual_channel) {
  355. val = I915_READ(BXT_PORT_CL2CM_DW6(phy));
  356. val |= DW6_OLDO_DYN_PWR_DOWN_EN;
  357. I915_WRITE(BXT_PORT_CL2CM_DW6(phy), val);
  358. }
  359. if (phy_info->rcomp_phy != -1) {
  360. uint32_t grc_code;
  361. bxt_phy_wait_grc_done(dev_priv, phy_info->rcomp_phy);
  362. /*
  363. * PHY0 isn't connected to an RCOMP resistor so copy over
  364. * the corresponding calibrated value from PHY1, and disable
  365. * the automatic calibration on PHY0.
  366. */
  367. val = dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv,
  368. phy_info->rcomp_phy);
  369. grc_code = val << GRC_CODE_FAST_SHIFT |
  370. val << GRC_CODE_SLOW_SHIFT |
  371. val;
  372. I915_WRITE(BXT_PORT_REF_DW6(phy), grc_code);
  373. val = I915_READ(BXT_PORT_REF_DW8(phy));
  374. val |= GRC_DIS | GRC_RDY_OVRD;
  375. I915_WRITE(BXT_PORT_REF_DW8(phy), val);
  376. }
  377. if (phy_info->reset_delay)
  378. udelay(phy_info->reset_delay);
  379. val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
  380. val |= COMMON_RESET_DIS;
  381. I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
  382. }
  383. void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy)
  384. {
  385. const struct bxt_ddi_phy_info *phy_info;
  386. uint32_t val;
  387. phy_info = bxt_get_phy_info(dev_priv, phy);
  388. val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
  389. val &= ~COMMON_RESET_DIS;
  390. I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
  391. val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
  392. val &= ~phy_info->pwron_mask;
  393. I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
  394. }
  395. void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy)
  396. {
  397. const struct bxt_ddi_phy_info *phy_info =
  398. bxt_get_phy_info(dev_priv, phy);
  399. enum dpio_phy rcomp_phy = phy_info->rcomp_phy;
  400. bool was_enabled;
  401. lockdep_assert_held(&dev_priv->power_domains.lock);
  402. was_enabled = true;
  403. if (rcomp_phy != -1)
  404. was_enabled = bxt_ddi_phy_is_enabled(dev_priv, rcomp_phy);
  405. /*
  406. * We need to copy the GRC calibration value from rcomp_phy,
  407. * so make sure it's powered up.
  408. */
  409. if (!was_enabled)
  410. _bxt_ddi_phy_init(dev_priv, rcomp_phy);
  411. _bxt_ddi_phy_init(dev_priv, phy);
  412. if (!was_enabled)
  413. bxt_ddi_phy_uninit(dev_priv, rcomp_phy);
  414. }
  415. static bool __printf(6, 7)
  416. __phy_reg_verify_state(struct drm_i915_private *dev_priv, enum dpio_phy phy,
  417. i915_reg_t reg, u32 mask, u32 expected,
  418. const char *reg_fmt, ...)
  419. {
  420. struct va_format vaf;
  421. va_list args;
  422. u32 val;
  423. val = I915_READ(reg);
  424. if ((val & mask) == expected)
  425. return true;
  426. va_start(args, reg_fmt);
  427. vaf.fmt = reg_fmt;
  428. vaf.va = &args;
  429. DRM_DEBUG_DRIVER("DDI PHY %d reg %pV [%08x] state mismatch: "
  430. "current %08x, expected %08x (mask %08x)\n",
  431. phy, &vaf, reg.reg, val, (val & ~mask) | expected,
  432. mask);
  433. va_end(args);
  434. return false;
  435. }
  436. bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv,
  437. enum dpio_phy phy)
  438. {
  439. const struct bxt_ddi_phy_info *phy_info;
  440. uint32_t mask;
  441. bool ok;
  442. phy_info = bxt_get_phy_info(dev_priv, phy);
  443. #define _CHK(reg, mask, exp, fmt, ...) \
  444. __phy_reg_verify_state(dev_priv, phy, reg, mask, exp, fmt, \
  445. ## __VA_ARGS__)
  446. if (!bxt_ddi_phy_is_enabled(dev_priv, phy))
  447. return false;
  448. ok = true;
  449. /* PLL Rcomp code offset */
  450. ok &= _CHK(BXT_PORT_CL1CM_DW9(phy),
  451. IREF0RC_OFFSET_MASK, 0xe4 << IREF0RC_OFFSET_SHIFT,
  452. "BXT_PORT_CL1CM_DW9(%d)", phy);
  453. ok &= _CHK(BXT_PORT_CL1CM_DW10(phy),
  454. IREF1RC_OFFSET_MASK, 0xe4 << IREF1RC_OFFSET_SHIFT,
  455. "BXT_PORT_CL1CM_DW10(%d)", phy);
  456. /* Power gating */
  457. mask = OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | SUS_CLK_CONFIG;
  458. ok &= _CHK(BXT_PORT_CL1CM_DW28(phy), mask, mask,
  459. "BXT_PORT_CL1CM_DW28(%d)", phy);
  460. if (phy_info->dual_channel)
  461. ok &= _CHK(BXT_PORT_CL2CM_DW6(phy),
  462. DW6_OLDO_DYN_PWR_DOWN_EN, DW6_OLDO_DYN_PWR_DOWN_EN,
  463. "BXT_PORT_CL2CM_DW6(%d)", phy);
  464. if (phy_info->rcomp_phy != -1) {
  465. u32 grc_code = dev_priv->bxt_phy_grc;
  466. grc_code = grc_code << GRC_CODE_FAST_SHIFT |
  467. grc_code << GRC_CODE_SLOW_SHIFT |
  468. grc_code;
  469. mask = GRC_CODE_FAST_MASK | GRC_CODE_SLOW_MASK |
  470. GRC_CODE_NOM_MASK;
  471. ok &= _CHK(BXT_PORT_REF_DW6(phy), mask, grc_code,
  472. "BXT_PORT_REF_DW6(%d)", phy);
  473. mask = GRC_DIS | GRC_RDY_OVRD;
  474. ok &= _CHK(BXT_PORT_REF_DW8(phy), mask, mask,
  475. "BXT_PORT_REF_DW8(%d)", phy);
  476. }
  477. return ok;
  478. #undef _CHK
  479. }
  480. uint8_t
  481. bxt_ddi_phy_calc_lane_lat_optim_mask(uint8_t lane_count)
  482. {
  483. switch (lane_count) {
  484. case 1:
  485. return 0;
  486. case 2:
  487. return BIT(2) | BIT(0);
  488. case 4:
  489. return BIT(3) | BIT(2) | BIT(0);
  490. default:
  491. MISSING_CASE(lane_count);
  492. return 0;
  493. }
  494. }
  495. void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder,
  496. uint8_t lane_lat_optim_mask)
  497. {
  498. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  499. enum port port = encoder->port;
  500. enum dpio_phy phy;
  501. enum dpio_channel ch;
  502. int lane;
  503. bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
  504. for (lane = 0; lane < 4; lane++) {
  505. u32 val = I915_READ(BXT_PORT_TX_DW14_LN(phy, ch, lane));
  506. /*
  507. * Note that on CHV this flag is called UPAR, but has
  508. * the same function.
  509. */
  510. val &= ~LATENCY_OPTIM;
  511. if (lane_lat_optim_mask & BIT(lane))
  512. val |= LATENCY_OPTIM;
  513. I915_WRITE(BXT_PORT_TX_DW14_LN(phy, ch, lane), val);
  514. }
  515. }
  516. uint8_t
  517. bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder)
  518. {
  519. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  520. enum port port = encoder->port;
  521. enum dpio_phy phy;
  522. enum dpio_channel ch;
  523. int lane;
  524. uint8_t mask;
  525. bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
  526. mask = 0;
  527. for (lane = 0; lane < 4; lane++) {
  528. u32 val = I915_READ(BXT_PORT_TX_DW14_LN(phy, ch, lane));
  529. if (val & LATENCY_OPTIM)
  530. mask |= BIT(lane);
  531. }
  532. return mask;
  533. }
  534. void chv_set_phy_signal_level(struct intel_encoder *encoder,
  535. u32 deemph_reg_value, u32 margin_reg_value,
  536. bool uniq_trans_scale)
  537. {
  538. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  539. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  540. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  541. enum dpio_channel ch = vlv_dport_to_channel(dport);
  542. enum pipe pipe = intel_crtc->pipe;
  543. u32 val;
  544. int i;
  545. mutex_lock(&dev_priv->sb_lock);
  546. /* Clear calc init */
  547. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
  548. val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
  549. val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
  550. val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
  551. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
  552. if (intel_crtc->config->lane_count > 2) {
  553. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
  554. val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
  555. val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
  556. val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
  557. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
  558. }
  559. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
  560. val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
  561. val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
  562. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
  563. if (intel_crtc->config->lane_count > 2) {
  564. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
  565. val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
  566. val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
  567. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
  568. }
  569. /* Program swing deemph */
  570. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  571. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
  572. val &= ~DPIO_SWING_DEEMPH9P5_MASK;
  573. val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
  574. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
  575. }
  576. /* Program swing margin */
  577. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  578. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
  579. val &= ~DPIO_SWING_MARGIN000_MASK;
  580. val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
  581. /*
  582. * Supposedly this value shouldn't matter when unique transition
  583. * scale is disabled, but in fact it does matter. Let's just
  584. * always program the same value and hope it's OK.
  585. */
  586. val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
  587. val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
  588. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
  589. }
  590. /*
  591. * The document said it needs to set bit 27 for ch0 and bit 26
  592. * for ch1. Might be a typo in the doc.
  593. * For now, for this unique transition scale selection, set bit
  594. * 27 for ch0 and ch1.
  595. */
  596. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  597. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
  598. if (uniq_trans_scale)
  599. val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
  600. else
  601. val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
  602. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
  603. }
  604. /* Start swing calculation */
  605. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
  606. val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
  607. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
  608. if (intel_crtc->config->lane_count > 2) {
  609. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
  610. val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
  611. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
  612. }
  613. mutex_unlock(&dev_priv->sb_lock);
  614. }
  615. void chv_data_lane_soft_reset(struct intel_encoder *encoder,
  616. const struct intel_crtc_state *crtc_state,
  617. bool reset)
  618. {
  619. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  620. enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
  621. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  622. enum pipe pipe = crtc->pipe;
  623. uint32_t val;
  624. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
  625. if (reset)
  626. val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  627. else
  628. val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
  629. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
  630. if (crtc->config->lane_count > 2) {
  631. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
  632. if (reset)
  633. val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  634. else
  635. val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
  636. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
  637. }
  638. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
  639. val |= CHV_PCS_REQ_SOFTRESET_EN;
  640. if (reset)
  641. val &= ~DPIO_PCS_CLK_SOFT_RESET;
  642. else
  643. val |= DPIO_PCS_CLK_SOFT_RESET;
  644. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
  645. if (crtc->config->lane_count > 2) {
  646. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
  647. val |= CHV_PCS_REQ_SOFTRESET_EN;
  648. if (reset)
  649. val &= ~DPIO_PCS_CLK_SOFT_RESET;
  650. else
  651. val |= DPIO_PCS_CLK_SOFT_RESET;
  652. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
  653. }
  654. }
  655. void chv_phy_pre_pll_enable(struct intel_encoder *encoder,
  656. const struct intel_crtc_state *crtc_state)
  657. {
  658. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  659. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  660. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  661. enum dpio_channel ch = vlv_dport_to_channel(dport);
  662. enum pipe pipe = crtc->pipe;
  663. unsigned int lane_mask =
  664. intel_dp_unused_lane_mask(crtc_state->lane_count);
  665. u32 val;
  666. /*
  667. * Must trick the second common lane into life.
  668. * Otherwise we can't even access the PLL.
  669. */
  670. if (ch == DPIO_CH0 && pipe == PIPE_B)
  671. dport->release_cl2_override =
  672. !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
  673. chv_phy_powergate_lanes(encoder, true, lane_mask);
  674. mutex_lock(&dev_priv->sb_lock);
  675. /* Assert data lane reset */
  676. chv_data_lane_soft_reset(encoder, crtc_state, true);
  677. /* program left/right clock distribution */
  678. if (pipe != PIPE_B) {
  679. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  680. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  681. if (ch == DPIO_CH0)
  682. val |= CHV_BUFLEFTENA1_FORCE;
  683. if (ch == DPIO_CH1)
  684. val |= CHV_BUFRIGHTENA1_FORCE;
  685. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  686. } else {
  687. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  688. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  689. if (ch == DPIO_CH0)
  690. val |= CHV_BUFLEFTENA2_FORCE;
  691. if (ch == DPIO_CH1)
  692. val |= CHV_BUFRIGHTENA2_FORCE;
  693. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  694. }
  695. /* program clock channel usage */
  696. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
  697. val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
  698. if (pipe != PIPE_B)
  699. val &= ~CHV_PCS_USEDCLKCHANNEL;
  700. else
  701. val |= CHV_PCS_USEDCLKCHANNEL;
  702. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
  703. if (crtc_state->lane_count > 2) {
  704. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
  705. val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
  706. if (pipe != PIPE_B)
  707. val &= ~CHV_PCS_USEDCLKCHANNEL;
  708. else
  709. val |= CHV_PCS_USEDCLKCHANNEL;
  710. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
  711. }
  712. /*
  713. * This a a bit weird since generally CL
  714. * matches the pipe, but here we need to
  715. * pick the CL based on the port.
  716. */
  717. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
  718. if (pipe != PIPE_B)
  719. val &= ~CHV_CMN_USEDCLKCHANNEL;
  720. else
  721. val |= CHV_CMN_USEDCLKCHANNEL;
  722. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
  723. mutex_unlock(&dev_priv->sb_lock);
  724. }
  725. void chv_phy_pre_encoder_enable(struct intel_encoder *encoder,
  726. const struct intel_crtc_state *crtc_state)
  727. {
  728. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  729. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  730. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  731. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  732. enum dpio_channel ch = vlv_dport_to_channel(dport);
  733. enum pipe pipe = crtc->pipe;
  734. int data, i, stagger;
  735. u32 val;
  736. mutex_lock(&dev_priv->sb_lock);
  737. /* allow hardware to manage TX FIFO reset source */
  738. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
  739. val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
  740. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
  741. if (crtc_state->lane_count > 2) {
  742. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
  743. val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
  744. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
  745. }
  746. /* Program Tx lane latency optimal setting*/
  747. for (i = 0; i < crtc_state->lane_count; i++) {
  748. /* Set the upar bit */
  749. if (crtc_state->lane_count == 1)
  750. data = 0x0;
  751. else
  752. data = (i == 1) ? 0x0 : 0x1;
  753. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
  754. data << DPIO_UPAR_SHIFT);
  755. }
  756. /* Data lane stagger programming */
  757. if (crtc_state->port_clock > 270000)
  758. stagger = 0x18;
  759. else if (crtc_state->port_clock > 135000)
  760. stagger = 0xd;
  761. else if (crtc_state->port_clock > 67500)
  762. stagger = 0x7;
  763. else if (crtc_state->port_clock > 33750)
  764. stagger = 0x4;
  765. else
  766. stagger = 0x2;
  767. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
  768. val |= DPIO_TX2_STAGGER_MASK(0x1f);
  769. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
  770. if (crtc_state->lane_count > 2) {
  771. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
  772. val |= DPIO_TX2_STAGGER_MASK(0x1f);
  773. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
  774. }
  775. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
  776. DPIO_LANESTAGGER_STRAP(stagger) |
  777. DPIO_LANESTAGGER_STRAP_OVRD |
  778. DPIO_TX1_STAGGER_MASK(0x1f) |
  779. DPIO_TX1_STAGGER_MULT(6) |
  780. DPIO_TX2_STAGGER_MULT(0));
  781. if (crtc_state->lane_count > 2) {
  782. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
  783. DPIO_LANESTAGGER_STRAP(stagger) |
  784. DPIO_LANESTAGGER_STRAP_OVRD |
  785. DPIO_TX1_STAGGER_MASK(0x1f) |
  786. DPIO_TX1_STAGGER_MULT(7) |
  787. DPIO_TX2_STAGGER_MULT(5));
  788. }
  789. /* Deassert data lane reset */
  790. chv_data_lane_soft_reset(encoder, crtc_state, false);
  791. mutex_unlock(&dev_priv->sb_lock);
  792. }
  793. void chv_phy_release_cl2_override(struct intel_encoder *encoder)
  794. {
  795. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  796. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  797. if (dport->release_cl2_override) {
  798. chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false);
  799. dport->release_cl2_override = false;
  800. }
  801. }
  802. void chv_phy_post_pll_disable(struct intel_encoder *encoder,
  803. const struct intel_crtc_state *old_crtc_state)
  804. {
  805. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  806. enum pipe pipe = to_intel_crtc(old_crtc_state->base.crtc)->pipe;
  807. u32 val;
  808. mutex_lock(&dev_priv->sb_lock);
  809. /* disable left/right clock distribution */
  810. if (pipe != PIPE_B) {
  811. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  812. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  813. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  814. } else {
  815. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  816. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  817. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  818. }
  819. mutex_unlock(&dev_priv->sb_lock);
  820. /*
  821. * Leave the power down bit cleared for at least one
  822. * lane so that chv_powergate_phy_ch() will power
  823. * on something when the channel is otherwise unused.
  824. * When the port is off and the override is removed
  825. * the lanes power down anyway, so otherwise it doesn't
  826. * really matter what the state of power down bits is
  827. * after this.
  828. */
  829. chv_phy_powergate_lanes(encoder, false, 0x0);
  830. }
  831. void vlv_set_phy_signal_level(struct intel_encoder *encoder,
  832. u32 demph_reg_value, u32 preemph_reg_value,
  833. u32 uniqtranscale_reg_value, u32 tx3_demph)
  834. {
  835. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  836. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  837. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  838. enum dpio_channel port = vlv_dport_to_channel(dport);
  839. enum pipe pipe = intel_crtc->pipe;
  840. mutex_lock(&dev_priv->sb_lock);
  841. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
  842. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
  843. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
  844. uniqtranscale_reg_value);
  845. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
  846. if (tx3_demph)
  847. vlv_dpio_write(dev_priv, pipe, VLV_TX3_DW4(port), tx3_demph);
  848. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
  849. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
  850. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
  851. mutex_unlock(&dev_priv->sb_lock);
  852. }
  853. void vlv_phy_pre_pll_enable(struct intel_encoder *encoder,
  854. const struct intel_crtc_state *crtc_state)
  855. {
  856. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  857. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  858. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  859. enum dpio_channel port = vlv_dport_to_channel(dport);
  860. enum pipe pipe = crtc->pipe;
  861. /* Program Tx lane resets to default */
  862. mutex_lock(&dev_priv->sb_lock);
  863. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
  864. DPIO_PCS_TX_LANE2_RESET |
  865. DPIO_PCS_TX_LANE1_RESET);
  866. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
  867. DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
  868. DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
  869. (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
  870. DPIO_PCS_CLK_SOFT_RESET);
  871. /* Fix up inter-pair skew failure */
  872. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
  873. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
  874. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
  875. mutex_unlock(&dev_priv->sb_lock);
  876. }
  877. void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder,
  878. const struct intel_crtc_state *crtc_state)
  879. {
  880. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  881. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  882. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  883. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  884. enum dpio_channel port = vlv_dport_to_channel(dport);
  885. enum pipe pipe = crtc->pipe;
  886. u32 val;
  887. mutex_lock(&dev_priv->sb_lock);
  888. /* Enable clock channels for this port */
  889. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
  890. val = 0;
  891. if (pipe)
  892. val |= (1<<21);
  893. else
  894. val &= ~(1<<21);
  895. val |= 0x001000c4;
  896. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
  897. /* Program lane clock */
  898. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
  899. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
  900. mutex_unlock(&dev_priv->sb_lock);
  901. }
  902. void vlv_phy_reset_lanes(struct intel_encoder *encoder,
  903. const struct intel_crtc_state *old_crtc_state)
  904. {
  905. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  906. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  907. struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
  908. enum dpio_channel port = vlv_dport_to_channel(dport);
  909. enum pipe pipe = crtc->pipe;
  910. mutex_lock(&dev_priv->sb_lock);
  911. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port), 0x00000000);
  912. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port), 0x00e00060);
  913. mutex_unlock(&dev_priv->sb_lock);
  914. }