intel_dpio_phy.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  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. * @channel.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. * The flag should get set in 100us according to the HW team, but
  334. * use 1ms due to occasional timeouts observed with that.
  335. */
  336. if (intel_wait_for_register_fw(dev_priv, BXT_PORT_CL1CM_DW0(phy),
  337. PHY_RESERVED | PHY_POWER_GOOD,
  338. PHY_POWER_GOOD,
  339. 1))
  340. DRM_ERROR("timeout during PHY%d power on\n", phy);
  341. /* Program PLL Rcomp code offset */
  342. val = I915_READ(BXT_PORT_CL1CM_DW9(phy));
  343. val &= ~IREF0RC_OFFSET_MASK;
  344. val |= 0xE4 << IREF0RC_OFFSET_SHIFT;
  345. I915_WRITE(BXT_PORT_CL1CM_DW9(phy), val);
  346. val = I915_READ(BXT_PORT_CL1CM_DW10(phy));
  347. val &= ~IREF1RC_OFFSET_MASK;
  348. val |= 0xE4 << IREF1RC_OFFSET_SHIFT;
  349. I915_WRITE(BXT_PORT_CL1CM_DW10(phy), val);
  350. /* Program power gating */
  351. val = I915_READ(BXT_PORT_CL1CM_DW28(phy));
  352. val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN |
  353. SUS_CLK_CONFIG;
  354. I915_WRITE(BXT_PORT_CL1CM_DW28(phy), val);
  355. if (phy_info->dual_channel) {
  356. val = I915_READ(BXT_PORT_CL2CM_DW6(phy));
  357. val |= DW6_OLDO_DYN_PWR_DOWN_EN;
  358. I915_WRITE(BXT_PORT_CL2CM_DW6(phy), val);
  359. }
  360. if (phy_info->rcomp_phy != -1) {
  361. uint32_t grc_code;
  362. bxt_phy_wait_grc_done(dev_priv, phy_info->rcomp_phy);
  363. /*
  364. * PHY0 isn't connected to an RCOMP resistor so copy over
  365. * the corresponding calibrated value from PHY1, and disable
  366. * the automatic calibration on PHY0.
  367. */
  368. val = dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv,
  369. phy_info->rcomp_phy);
  370. grc_code = val << GRC_CODE_FAST_SHIFT |
  371. val << GRC_CODE_SLOW_SHIFT |
  372. val;
  373. I915_WRITE(BXT_PORT_REF_DW6(phy), grc_code);
  374. val = I915_READ(BXT_PORT_REF_DW8(phy));
  375. val |= GRC_DIS | GRC_RDY_OVRD;
  376. I915_WRITE(BXT_PORT_REF_DW8(phy), val);
  377. }
  378. if (phy_info->reset_delay)
  379. udelay(phy_info->reset_delay);
  380. val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
  381. val |= COMMON_RESET_DIS;
  382. I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
  383. }
  384. void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy)
  385. {
  386. const struct bxt_ddi_phy_info *phy_info;
  387. uint32_t val;
  388. phy_info = bxt_get_phy_info(dev_priv, phy);
  389. val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
  390. val &= ~COMMON_RESET_DIS;
  391. I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
  392. val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
  393. val &= ~phy_info->pwron_mask;
  394. I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
  395. }
  396. void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy)
  397. {
  398. const struct bxt_ddi_phy_info *phy_info =
  399. bxt_get_phy_info(dev_priv, phy);
  400. enum dpio_phy rcomp_phy = phy_info->rcomp_phy;
  401. bool was_enabled;
  402. lockdep_assert_held(&dev_priv->power_domains.lock);
  403. was_enabled = true;
  404. if (rcomp_phy != -1)
  405. was_enabled = bxt_ddi_phy_is_enabled(dev_priv, rcomp_phy);
  406. /*
  407. * We need to copy the GRC calibration value from rcomp_phy,
  408. * so make sure it's powered up.
  409. */
  410. if (!was_enabled)
  411. _bxt_ddi_phy_init(dev_priv, rcomp_phy);
  412. _bxt_ddi_phy_init(dev_priv, phy);
  413. if (!was_enabled)
  414. bxt_ddi_phy_uninit(dev_priv, rcomp_phy);
  415. }
  416. static bool __printf(6, 7)
  417. __phy_reg_verify_state(struct drm_i915_private *dev_priv, enum dpio_phy phy,
  418. i915_reg_t reg, u32 mask, u32 expected,
  419. const char *reg_fmt, ...)
  420. {
  421. struct va_format vaf;
  422. va_list args;
  423. u32 val;
  424. val = I915_READ(reg);
  425. if ((val & mask) == expected)
  426. return true;
  427. va_start(args, reg_fmt);
  428. vaf.fmt = reg_fmt;
  429. vaf.va = &args;
  430. DRM_DEBUG_DRIVER("DDI PHY %d reg %pV [%08x] state mismatch: "
  431. "current %08x, expected %08x (mask %08x)\n",
  432. phy, &vaf, reg.reg, val, (val & ~mask) | expected,
  433. mask);
  434. va_end(args);
  435. return false;
  436. }
  437. bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv,
  438. enum dpio_phy phy)
  439. {
  440. const struct bxt_ddi_phy_info *phy_info;
  441. uint32_t mask;
  442. bool ok;
  443. phy_info = bxt_get_phy_info(dev_priv, phy);
  444. #define _CHK(reg, mask, exp, fmt, ...) \
  445. __phy_reg_verify_state(dev_priv, phy, reg, mask, exp, fmt, \
  446. ## __VA_ARGS__)
  447. if (!bxt_ddi_phy_is_enabled(dev_priv, phy))
  448. return false;
  449. ok = true;
  450. /* PLL Rcomp code offset */
  451. ok &= _CHK(BXT_PORT_CL1CM_DW9(phy),
  452. IREF0RC_OFFSET_MASK, 0xe4 << IREF0RC_OFFSET_SHIFT,
  453. "BXT_PORT_CL1CM_DW9(%d)", phy);
  454. ok &= _CHK(BXT_PORT_CL1CM_DW10(phy),
  455. IREF1RC_OFFSET_MASK, 0xe4 << IREF1RC_OFFSET_SHIFT,
  456. "BXT_PORT_CL1CM_DW10(%d)", phy);
  457. /* Power gating */
  458. mask = OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | SUS_CLK_CONFIG;
  459. ok &= _CHK(BXT_PORT_CL1CM_DW28(phy), mask, mask,
  460. "BXT_PORT_CL1CM_DW28(%d)", phy);
  461. if (phy_info->dual_channel)
  462. ok &= _CHK(BXT_PORT_CL2CM_DW6(phy),
  463. DW6_OLDO_DYN_PWR_DOWN_EN, DW6_OLDO_DYN_PWR_DOWN_EN,
  464. "BXT_PORT_CL2CM_DW6(%d)", phy);
  465. if (phy_info->rcomp_phy != -1) {
  466. u32 grc_code = dev_priv->bxt_phy_grc;
  467. grc_code = grc_code << GRC_CODE_FAST_SHIFT |
  468. grc_code << GRC_CODE_SLOW_SHIFT |
  469. grc_code;
  470. mask = GRC_CODE_FAST_MASK | GRC_CODE_SLOW_MASK |
  471. GRC_CODE_NOM_MASK;
  472. ok &= _CHK(BXT_PORT_REF_DW6(phy), mask, grc_code,
  473. "BXT_PORT_REF_DW6(%d)", phy);
  474. mask = GRC_DIS | GRC_RDY_OVRD;
  475. ok &= _CHK(BXT_PORT_REF_DW8(phy), mask, mask,
  476. "BXT_PORT_REF_DW8(%d)", phy);
  477. }
  478. return ok;
  479. #undef _CHK
  480. }
  481. uint8_t
  482. bxt_ddi_phy_calc_lane_lat_optim_mask(uint8_t lane_count)
  483. {
  484. switch (lane_count) {
  485. case 1:
  486. return 0;
  487. case 2:
  488. return BIT(2) | BIT(0);
  489. case 4:
  490. return BIT(3) | BIT(2) | BIT(0);
  491. default:
  492. MISSING_CASE(lane_count);
  493. return 0;
  494. }
  495. }
  496. void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder,
  497. uint8_t lane_lat_optim_mask)
  498. {
  499. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  500. enum port port = encoder->port;
  501. enum dpio_phy phy;
  502. enum dpio_channel ch;
  503. int lane;
  504. bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
  505. for (lane = 0; lane < 4; lane++) {
  506. u32 val = I915_READ(BXT_PORT_TX_DW14_LN(phy, ch, lane));
  507. /*
  508. * Note that on CHV this flag is called UPAR, but has
  509. * the same function.
  510. */
  511. val &= ~LATENCY_OPTIM;
  512. if (lane_lat_optim_mask & BIT(lane))
  513. val |= LATENCY_OPTIM;
  514. I915_WRITE(BXT_PORT_TX_DW14_LN(phy, ch, lane), val);
  515. }
  516. }
  517. uint8_t
  518. bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder)
  519. {
  520. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  521. enum port port = encoder->port;
  522. enum dpio_phy phy;
  523. enum dpio_channel ch;
  524. int lane;
  525. uint8_t mask;
  526. bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
  527. mask = 0;
  528. for (lane = 0; lane < 4; lane++) {
  529. u32 val = I915_READ(BXT_PORT_TX_DW14_LN(phy, ch, lane));
  530. if (val & LATENCY_OPTIM)
  531. mask |= BIT(lane);
  532. }
  533. return mask;
  534. }
  535. void chv_set_phy_signal_level(struct intel_encoder *encoder,
  536. u32 deemph_reg_value, u32 margin_reg_value,
  537. bool uniq_trans_scale)
  538. {
  539. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  540. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  541. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  542. enum dpio_channel ch = vlv_dport_to_channel(dport);
  543. enum pipe pipe = intel_crtc->pipe;
  544. u32 val;
  545. int i;
  546. mutex_lock(&dev_priv->sb_lock);
  547. /* Clear calc init */
  548. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
  549. val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
  550. val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
  551. val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
  552. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
  553. if (intel_crtc->config->lane_count > 2) {
  554. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
  555. val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
  556. val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
  557. val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
  558. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
  559. }
  560. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
  561. val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
  562. val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
  563. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
  564. if (intel_crtc->config->lane_count > 2) {
  565. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
  566. val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
  567. val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
  568. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
  569. }
  570. /* Program swing deemph */
  571. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  572. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
  573. val &= ~DPIO_SWING_DEEMPH9P5_MASK;
  574. val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
  575. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
  576. }
  577. /* Program swing margin */
  578. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  579. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
  580. val &= ~DPIO_SWING_MARGIN000_MASK;
  581. val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
  582. /*
  583. * Supposedly this value shouldn't matter when unique transition
  584. * scale is disabled, but in fact it does matter. Let's just
  585. * always program the same value and hope it's OK.
  586. */
  587. val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
  588. val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
  589. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
  590. }
  591. /*
  592. * The document said it needs to set bit 27 for ch0 and bit 26
  593. * for ch1. Might be a typo in the doc.
  594. * For now, for this unique transition scale selection, set bit
  595. * 27 for ch0 and ch1.
  596. */
  597. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  598. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
  599. if (uniq_trans_scale)
  600. val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
  601. else
  602. val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
  603. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
  604. }
  605. /* Start swing calculation */
  606. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
  607. val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
  608. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
  609. if (intel_crtc->config->lane_count > 2) {
  610. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
  611. val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
  612. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
  613. }
  614. mutex_unlock(&dev_priv->sb_lock);
  615. }
  616. void chv_data_lane_soft_reset(struct intel_encoder *encoder,
  617. const struct intel_crtc_state *crtc_state,
  618. bool reset)
  619. {
  620. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  621. enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
  622. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  623. enum pipe pipe = crtc->pipe;
  624. uint32_t val;
  625. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
  626. if (reset)
  627. val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  628. else
  629. val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
  630. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
  631. if (crtc->config->lane_count > 2) {
  632. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
  633. if (reset)
  634. val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  635. else
  636. val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
  637. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
  638. }
  639. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
  640. val |= CHV_PCS_REQ_SOFTRESET_EN;
  641. if (reset)
  642. val &= ~DPIO_PCS_CLK_SOFT_RESET;
  643. else
  644. val |= DPIO_PCS_CLK_SOFT_RESET;
  645. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
  646. if (crtc->config->lane_count > 2) {
  647. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
  648. val |= CHV_PCS_REQ_SOFTRESET_EN;
  649. if (reset)
  650. val &= ~DPIO_PCS_CLK_SOFT_RESET;
  651. else
  652. val |= DPIO_PCS_CLK_SOFT_RESET;
  653. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
  654. }
  655. }
  656. void chv_phy_pre_pll_enable(struct intel_encoder *encoder,
  657. const struct intel_crtc_state *crtc_state)
  658. {
  659. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  660. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  661. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  662. enum dpio_channel ch = vlv_dport_to_channel(dport);
  663. enum pipe pipe = crtc->pipe;
  664. unsigned int lane_mask =
  665. intel_dp_unused_lane_mask(crtc_state->lane_count);
  666. u32 val;
  667. /*
  668. * Must trick the second common lane into life.
  669. * Otherwise we can't even access the PLL.
  670. */
  671. if (ch == DPIO_CH0 && pipe == PIPE_B)
  672. dport->release_cl2_override =
  673. !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
  674. chv_phy_powergate_lanes(encoder, true, lane_mask);
  675. mutex_lock(&dev_priv->sb_lock);
  676. /* Assert data lane reset */
  677. chv_data_lane_soft_reset(encoder, crtc_state, true);
  678. /* program left/right clock distribution */
  679. if (pipe != PIPE_B) {
  680. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  681. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  682. if (ch == DPIO_CH0)
  683. val |= CHV_BUFLEFTENA1_FORCE;
  684. if (ch == DPIO_CH1)
  685. val |= CHV_BUFRIGHTENA1_FORCE;
  686. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  687. } else {
  688. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  689. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  690. if (ch == DPIO_CH0)
  691. val |= CHV_BUFLEFTENA2_FORCE;
  692. if (ch == DPIO_CH1)
  693. val |= CHV_BUFRIGHTENA2_FORCE;
  694. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  695. }
  696. /* program clock channel usage */
  697. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
  698. val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
  699. if (pipe != PIPE_B)
  700. val &= ~CHV_PCS_USEDCLKCHANNEL;
  701. else
  702. val |= CHV_PCS_USEDCLKCHANNEL;
  703. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
  704. if (crtc_state->lane_count > 2) {
  705. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
  706. val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
  707. if (pipe != PIPE_B)
  708. val &= ~CHV_PCS_USEDCLKCHANNEL;
  709. else
  710. val |= CHV_PCS_USEDCLKCHANNEL;
  711. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
  712. }
  713. /*
  714. * This a a bit weird since generally CL
  715. * matches the pipe, but here we need to
  716. * pick the CL based on the port.
  717. */
  718. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
  719. if (pipe != PIPE_B)
  720. val &= ~CHV_CMN_USEDCLKCHANNEL;
  721. else
  722. val |= CHV_CMN_USEDCLKCHANNEL;
  723. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
  724. mutex_unlock(&dev_priv->sb_lock);
  725. }
  726. void chv_phy_pre_encoder_enable(struct intel_encoder *encoder,
  727. const struct intel_crtc_state *crtc_state)
  728. {
  729. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  730. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  731. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  732. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  733. enum dpio_channel ch = vlv_dport_to_channel(dport);
  734. enum pipe pipe = crtc->pipe;
  735. int data, i, stagger;
  736. u32 val;
  737. mutex_lock(&dev_priv->sb_lock);
  738. /* allow hardware to manage TX FIFO reset source */
  739. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
  740. val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
  741. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
  742. if (crtc_state->lane_count > 2) {
  743. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
  744. val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
  745. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
  746. }
  747. /* Program Tx lane latency optimal setting*/
  748. for (i = 0; i < crtc_state->lane_count; i++) {
  749. /* Set the upar bit */
  750. if (crtc_state->lane_count == 1)
  751. data = 0x0;
  752. else
  753. data = (i == 1) ? 0x0 : 0x1;
  754. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
  755. data << DPIO_UPAR_SHIFT);
  756. }
  757. /* Data lane stagger programming */
  758. if (crtc_state->port_clock > 270000)
  759. stagger = 0x18;
  760. else if (crtc_state->port_clock > 135000)
  761. stagger = 0xd;
  762. else if (crtc_state->port_clock > 67500)
  763. stagger = 0x7;
  764. else if (crtc_state->port_clock > 33750)
  765. stagger = 0x4;
  766. else
  767. stagger = 0x2;
  768. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
  769. val |= DPIO_TX2_STAGGER_MASK(0x1f);
  770. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
  771. if (crtc_state->lane_count > 2) {
  772. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
  773. val |= DPIO_TX2_STAGGER_MASK(0x1f);
  774. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
  775. }
  776. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
  777. DPIO_LANESTAGGER_STRAP(stagger) |
  778. DPIO_LANESTAGGER_STRAP_OVRD |
  779. DPIO_TX1_STAGGER_MASK(0x1f) |
  780. DPIO_TX1_STAGGER_MULT(6) |
  781. DPIO_TX2_STAGGER_MULT(0));
  782. if (crtc_state->lane_count > 2) {
  783. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
  784. DPIO_LANESTAGGER_STRAP(stagger) |
  785. DPIO_LANESTAGGER_STRAP_OVRD |
  786. DPIO_TX1_STAGGER_MASK(0x1f) |
  787. DPIO_TX1_STAGGER_MULT(7) |
  788. DPIO_TX2_STAGGER_MULT(5));
  789. }
  790. /* Deassert data lane reset */
  791. chv_data_lane_soft_reset(encoder, crtc_state, false);
  792. mutex_unlock(&dev_priv->sb_lock);
  793. }
  794. void chv_phy_release_cl2_override(struct intel_encoder *encoder)
  795. {
  796. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  797. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  798. if (dport->release_cl2_override) {
  799. chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false);
  800. dport->release_cl2_override = false;
  801. }
  802. }
  803. void chv_phy_post_pll_disable(struct intel_encoder *encoder,
  804. const struct intel_crtc_state *old_crtc_state)
  805. {
  806. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  807. enum pipe pipe = to_intel_crtc(old_crtc_state->base.crtc)->pipe;
  808. u32 val;
  809. mutex_lock(&dev_priv->sb_lock);
  810. /* disable left/right clock distribution */
  811. if (pipe != PIPE_B) {
  812. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  813. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  814. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  815. } else {
  816. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  817. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  818. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  819. }
  820. mutex_unlock(&dev_priv->sb_lock);
  821. /*
  822. * Leave the power down bit cleared for at least one
  823. * lane so that chv_powergate_phy_ch() will power
  824. * on something when the channel is otherwise unused.
  825. * When the port is off and the override is removed
  826. * the lanes power down anyway, so otherwise it doesn't
  827. * really matter what the state of power down bits is
  828. * after this.
  829. */
  830. chv_phy_powergate_lanes(encoder, false, 0x0);
  831. }
  832. void vlv_set_phy_signal_level(struct intel_encoder *encoder,
  833. u32 demph_reg_value, u32 preemph_reg_value,
  834. u32 uniqtranscale_reg_value, u32 tx3_demph)
  835. {
  836. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  837. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  838. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  839. enum dpio_channel port = vlv_dport_to_channel(dport);
  840. enum pipe pipe = intel_crtc->pipe;
  841. mutex_lock(&dev_priv->sb_lock);
  842. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
  843. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
  844. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
  845. uniqtranscale_reg_value);
  846. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
  847. if (tx3_demph)
  848. vlv_dpio_write(dev_priv, pipe, VLV_TX3_DW4(port), tx3_demph);
  849. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
  850. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
  851. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
  852. mutex_unlock(&dev_priv->sb_lock);
  853. }
  854. void vlv_phy_pre_pll_enable(struct intel_encoder *encoder,
  855. const struct intel_crtc_state *crtc_state)
  856. {
  857. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  858. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  859. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  860. enum dpio_channel port = vlv_dport_to_channel(dport);
  861. enum pipe pipe = crtc->pipe;
  862. /* Program Tx lane resets to default */
  863. mutex_lock(&dev_priv->sb_lock);
  864. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
  865. DPIO_PCS_TX_LANE2_RESET |
  866. DPIO_PCS_TX_LANE1_RESET);
  867. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
  868. DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
  869. DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
  870. (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
  871. DPIO_PCS_CLK_SOFT_RESET);
  872. /* Fix up inter-pair skew failure */
  873. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
  874. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
  875. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
  876. mutex_unlock(&dev_priv->sb_lock);
  877. }
  878. void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder,
  879. const struct intel_crtc_state *crtc_state)
  880. {
  881. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  882. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  883. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  884. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  885. enum dpio_channel port = vlv_dport_to_channel(dport);
  886. enum pipe pipe = crtc->pipe;
  887. u32 val;
  888. mutex_lock(&dev_priv->sb_lock);
  889. /* Enable clock channels for this port */
  890. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
  891. val = 0;
  892. if (pipe)
  893. val |= (1<<21);
  894. else
  895. val &= ~(1<<21);
  896. val |= 0x001000c4;
  897. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
  898. /* Program lane clock */
  899. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
  900. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
  901. mutex_unlock(&dev_priv->sb_lock);
  902. }
  903. void vlv_phy_reset_lanes(struct intel_encoder *encoder,
  904. const struct intel_crtc_state *old_crtc_state)
  905. {
  906. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  907. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  908. struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
  909. enum dpio_channel port = vlv_dport_to_channel(dport);
  910. enum pipe pipe = crtc->pipe;
  911. mutex_lock(&dev_priv->sb_lock);
  912. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port), 0x00000000);
  913. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port), 0x00e00060);
  914. mutex_unlock(&dev_priv->sb_lock);
  915. }