intel_dpio_phy.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  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. if (rcomp_phy != -1) {
  403. was_enabled = bxt_ddi_phy_is_enabled(dev_priv, rcomp_phy);
  404. /*
  405. * We need to copy the GRC calibration value from rcomp_phy,
  406. * so make sure it's powered up.
  407. */
  408. if (!was_enabled)
  409. _bxt_ddi_phy_init(dev_priv, rcomp_phy);
  410. }
  411. _bxt_ddi_phy_init(dev_priv, phy);
  412. if (rcomp_phy != -1 && !was_enabled)
  413. bxt_ddi_phy_uninit(dev_priv, phy_info->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(struct intel_encoder *encoder,
  482. 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 intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  500. struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
  501. enum port port = dport->port;
  502. enum dpio_phy phy;
  503. enum dpio_channel ch;
  504. int lane;
  505. bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
  506. for (lane = 0; lane < 4; lane++) {
  507. u32 val = I915_READ(BXT_PORT_TX_DW14_LN(phy, ch, lane));
  508. /*
  509. * Note that on CHV this flag is called UPAR, but has
  510. * the same function.
  511. */
  512. val &= ~LATENCY_OPTIM;
  513. if (lane_lat_optim_mask & BIT(lane))
  514. val |= LATENCY_OPTIM;
  515. I915_WRITE(BXT_PORT_TX_DW14_LN(phy, ch, lane), val);
  516. }
  517. }
  518. uint8_t
  519. bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder)
  520. {
  521. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  522. struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
  523. enum port port = dport->port;
  524. enum dpio_phy phy;
  525. enum dpio_channel ch;
  526. int lane;
  527. uint8_t mask;
  528. bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
  529. mask = 0;
  530. for (lane = 0; lane < 4; lane++) {
  531. u32 val = I915_READ(BXT_PORT_TX_DW14_LN(phy, ch, lane));
  532. if (val & LATENCY_OPTIM)
  533. mask |= BIT(lane);
  534. }
  535. return mask;
  536. }
  537. void chv_set_phy_signal_level(struct intel_encoder *encoder,
  538. u32 deemph_reg_value, u32 margin_reg_value,
  539. bool uniq_trans_scale)
  540. {
  541. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  542. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  543. struct intel_crtc *intel_crtc = to_intel_crtc(dport->base.base.crtc);
  544. enum dpio_channel ch = vlv_dport_to_channel(dport);
  545. enum pipe pipe = intel_crtc->pipe;
  546. u32 val;
  547. int i;
  548. mutex_lock(&dev_priv->sb_lock);
  549. /* Clear calc init */
  550. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
  551. val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
  552. val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
  553. val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
  554. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
  555. if (intel_crtc->config->lane_count > 2) {
  556. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
  557. val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
  558. val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
  559. val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
  560. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
  561. }
  562. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
  563. val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
  564. val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
  565. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
  566. if (intel_crtc->config->lane_count > 2) {
  567. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
  568. val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
  569. val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
  570. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
  571. }
  572. /* Program swing deemph */
  573. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  574. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
  575. val &= ~DPIO_SWING_DEEMPH9P5_MASK;
  576. val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
  577. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
  578. }
  579. /* Program swing margin */
  580. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  581. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
  582. val &= ~DPIO_SWING_MARGIN000_MASK;
  583. val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
  584. /*
  585. * Supposedly this value shouldn't matter when unique transition
  586. * scale is disabled, but in fact it does matter. Let's just
  587. * always program the same value and hope it's OK.
  588. */
  589. val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
  590. val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
  591. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
  592. }
  593. /*
  594. * The document said it needs to set bit 27 for ch0 and bit 26
  595. * for ch1. Might be a typo in the doc.
  596. * For now, for this unique transition scale selection, set bit
  597. * 27 for ch0 and ch1.
  598. */
  599. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  600. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
  601. if (uniq_trans_scale)
  602. val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
  603. else
  604. val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
  605. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
  606. }
  607. /* Start swing calculation */
  608. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
  609. val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
  610. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
  611. if (intel_crtc->config->lane_count > 2) {
  612. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
  613. val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
  614. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
  615. }
  616. mutex_unlock(&dev_priv->sb_lock);
  617. }
  618. void chv_data_lane_soft_reset(struct intel_encoder *encoder,
  619. bool reset)
  620. {
  621. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  622. enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
  623. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  624. enum pipe pipe = crtc->pipe;
  625. uint32_t val;
  626. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
  627. if (reset)
  628. val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  629. else
  630. val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
  631. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
  632. if (crtc->config->lane_count > 2) {
  633. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
  634. if (reset)
  635. val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  636. else
  637. val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
  638. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
  639. }
  640. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
  641. val |= CHV_PCS_REQ_SOFTRESET_EN;
  642. if (reset)
  643. val &= ~DPIO_PCS_CLK_SOFT_RESET;
  644. else
  645. val |= DPIO_PCS_CLK_SOFT_RESET;
  646. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
  647. if (crtc->config->lane_count > 2) {
  648. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
  649. val |= CHV_PCS_REQ_SOFTRESET_EN;
  650. if (reset)
  651. val &= ~DPIO_PCS_CLK_SOFT_RESET;
  652. else
  653. val |= DPIO_PCS_CLK_SOFT_RESET;
  654. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
  655. }
  656. }
  657. void chv_phy_pre_pll_enable(struct intel_encoder *encoder)
  658. {
  659. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  660. struct drm_device *dev = encoder->base.dev;
  661. struct drm_i915_private *dev_priv = to_i915(dev);
  662. struct intel_crtc *intel_crtc =
  663. to_intel_crtc(encoder->base.crtc);
  664. enum dpio_channel ch = vlv_dport_to_channel(dport);
  665. enum pipe pipe = intel_crtc->pipe;
  666. unsigned int lane_mask =
  667. intel_dp_unused_lane_mask(intel_crtc->config->lane_count);
  668. u32 val;
  669. /*
  670. * Must trick the second common lane into life.
  671. * Otherwise we can't even access the PLL.
  672. */
  673. if (ch == DPIO_CH0 && pipe == PIPE_B)
  674. dport->release_cl2_override =
  675. !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
  676. chv_phy_powergate_lanes(encoder, true, lane_mask);
  677. mutex_lock(&dev_priv->sb_lock);
  678. /* Assert data lane reset */
  679. chv_data_lane_soft_reset(encoder, true);
  680. /* program left/right clock distribution */
  681. if (pipe != PIPE_B) {
  682. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  683. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  684. if (ch == DPIO_CH0)
  685. val |= CHV_BUFLEFTENA1_FORCE;
  686. if (ch == DPIO_CH1)
  687. val |= CHV_BUFRIGHTENA1_FORCE;
  688. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  689. } else {
  690. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  691. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  692. if (ch == DPIO_CH0)
  693. val |= CHV_BUFLEFTENA2_FORCE;
  694. if (ch == DPIO_CH1)
  695. val |= CHV_BUFRIGHTENA2_FORCE;
  696. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  697. }
  698. /* program clock channel usage */
  699. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
  700. val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
  701. if (pipe != PIPE_B)
  702. val &= ~CHV_PCS_USEDCLKCHANNEL;
  703. else
  704. val |= CHV_PCS_USEDCLKCHANNEL;
  705. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
  706. if (intel_crtc->config->lane_count > 2) {
  707. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
  708. val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
  709. if (pipe != PIPE_B)
  710. val &= ~CHV_PCS_USEDCLKCHANNEL;
  711. else
  712. val |= CHV_PCS_USEDCLKCHANNEL;
  713. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
  714. }
  715. /*
  716. * This a a bit weird since generally CL
  717. * matches the pipe, but here we need to
  718. * pick the CL based on the port.
  719. */
  720. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
  721. if (pipe != PIPE_B)
  722. val &= ~CHV_CMN_USEDCLKCHANNEL;
  723. else
  724. val |= CHV_CMN_USEDCLKCHANNEL;
  725. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
  726. mutex_unlock(&dev_priv->sb_lock);
  727. }
  728. void chv_phy_pre_encoder_enable(struct intel_encoder *encoder)
  729. {
  730. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  731. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  732. struct drm_device *dev = encoder->base.dev;
  733. struct drm_i915_private *dev_priv = to_i915(dev);
  734. struct intel_crtc *intel_crtc =
  735. to_intel_crtc(encoder->base.crtc);
  736. enum dpio_channel ch = vlv_dport_to_channel(dport);
  737. int pipe = intel_crtc->pipe;
  738. int data, i, stagger;
  739. u32 val;
  740. mutex_lock(&dev_priv->sb_lock);
  741. /* allow hardware to manage TX FIFO reset source */
  742. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
  743. val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
  744. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
  745. if (intel_crtc->config->lane_count > 2) {
  746. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
  747. val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
  748. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
  749. }
  750. /* Program Tx lane latency optimal setting*/
  751. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  752. /* Set the upar bit */
  753. if (intel_crtc->config->lane_count == 1)
  754. data = 0x0;
  755. else
  756. data = (i == 1) ? 0x0 : 0x1;
  757. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
  758. data << DPIO_UPAR_SHIFT);
  759. }
  760. /* Data lane stagger programming */
  761. if (intel_crtc->config->port_clock > 270000)
  762. stagger = 0x18;
  763. else if (intel_crtc->config->port_clock > 135000)
  764. stagger = 0xd;
  765. else if (intel_crtc->config->port_clock > 67500)
  766. stagger = 0x7;
  767. else if (intel_crtc->config->port_clock > 33750)
  768. stagger = 0x4;
  769. else
  770. stagger = 0x2;
  771. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
  772. val |= DPIO_TX2_STAGGER_MASK(0x1f);
  773. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
  774. if (intel_crtc->config->lane_count > 2) {
  775. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
  776. val |= DPIO_TX2_STAGGER_MASK(0x1f);
  777. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
  778. }
  779. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
  780. DPIO_LANESTAGGER_STRAP(stagger) |
  781. DPIO_LANESTAGGER_STRAP_OVRD |
  782. DPIO_TX1_STAGGER_MASK(0x1f) |
  783. DPIO_TX1_STAGGER_MULT(6) |
  784. DPIO_TX2_STAGGER_MULT(0));
  785. if (intel_crtc->config->lane_count > 2) {
  786. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
  787. DPIO_LANESTAGGER_STRAP(stagger) |
  788. DPIO_LANESTAGGER_STRAP_OVRD |
  789. DPIO_TX1_STAGGER_MASK(0x1f) |
  790. DPIO_TX1_STAGGER_MULT(7) |
  791. DPIO_TX2_STAGGER_MULT(5));
  792. }
  793. /* Deassert data lane reset */
  794. chv_data_lane_soft_reset(encoder, false);
  795. mutex_unlock(&dev_priv->sb_lock);
  796. }
  797. void chv_phy_release_cl2_override(struct intel_encoder *encoder)
  798. {
  799. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  800. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  801. if (dport->release_cl2_override) {
  802. chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false);
  803. dport->release_cl2_override = false;
  804. }
  805. }
  806. void chv_phy_post_pll_disable(struct intel_encoder *encoder)
  807. {
  808. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  809. enum pipe pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  810. u32 val;
  811. mutex_lock(&dev_priv->sb_lock);
  812. /* disable left/right clock distribution */
  813. if (pipe != PIPE_B) {
  814. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  815. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  816. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  817. } else {
  818. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  819. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  820. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  821. }
  822. mutex_unlock(&dev_priv->sb_lock);
  823. /*
  824. * Leave the power down bit cleared for at least one
  825. * lane so that chv_powergate_phy_ch() will power
  826. * on something when the channel is otherwise unused.
  827. * When the port is off and the override is removed
  828. * the lanes power down anyway, so otherwise it doesn't
  829. * really matter what the state of power down bits is
  830. * after this.
  831. */
  832. chv_phy_powergate_lanes(encoder, false, 0x0);
  833. }
  834. void vlv_set_phy_signal_level(struct intel_encoder *encoder,
  835. u32 demph_reg_value, u32 preemph_reg_value,
  836. u32 uniqtranscale_reg_value, u32 tx3_demph)
  837. {
  838. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  839. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  840. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  841. enum dpio_channel port = vlv_dport_to_channel(dport);
  842. int pipe = intel_crtc->pipe;
  843. mutex_lock(&dev_priv->sb_lock);
  844. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
  845. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
  846. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
  847. uniqtranscale_reg_value);
  848. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
  849. if (tx3_demph)
  850. vlv_dpio_write(dev_priv, pipe, VLV_TX3_DW4(port), tx3_demph);
  851. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
  852. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
  853. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
  854. mutex_unlock(&dev_priv->sb_lock);
  855. }
  856. void vlv_phy_pre_pll_enable(struct intel_encoder *encoder)
  857. {
  858. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  859. struct drm_device *dev = encoder->base.dev;
  860. struct drm_i915_private *dev_priv = to_i915(dev);
  861. struct intel_crtc *intel_crtc =
  862. to_intel_crtc(encoder->base.crtc);
  863. enum dpio_channel port = vlv_dport_to_channel(dport);
  864. int pipe = intel_crtc->pipe;
  865. /* Program Tx lane resets to default */
  866. mutex_lock(&dev_priv->sb_lock);
  867. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
  868. DPIO_PCS_TX_LANE2_RESET |
  869. DPIO_PCS_TX_LANE1_RESET);
  870. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
  871. DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
  872. DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
  873. (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
  874. DPIO_PCS_CLK_SOFT_RESET);
  875. /* Fix up inter-pair skew failure */
  876. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
  877. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
  878. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
  879. mutex_unlock(&dev_priv->sb_lock);
  880. }
  881. void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder)
  882. {
  883. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  884. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  885. struct drm_device *dev = encoder->base.dev;
  886. struct drm_i915_private *dev_priv = to_i915(dev);
  887. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  888. enum dpio_channel port = vlv_dport_to_channel(dport);
  889. int pipe = intel_crtc->pipe;
  890. u32 val;
  891. mutex_lock(&dev_priv->sb_lock);
  892. /* Enable clock channels for this port */
  893. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
  894. val = 0;
  895. if (pipe)
  896. val |= (1<<21);
  897. else
  898. val &= ~(1<<21);
  899. val |= 0x001000c4;
  900. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
  901. /* Program lane clock */
  902. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
  903. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
  904. mutex_unlock(&dev_priv->sb_lock);
  905. }
  906. void vlv_phy_reset_lanes(struct intel_encoder *encoder)
  907. {
  908. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  909. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  910. struct intel_crtc *intel_crtc =
  911. to_intel_crtc(encoder->base.crtc);
  912. enum dpio_channel port = vlv_dport_to_channel(dport);
  913. int pipe = intel_crtc->pipe;
  914. mutex_lock(&dev_priv->sb_lock);
  915. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port), 0x00000000);
  916. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port), 0x00e00060);
  917. mutex_unlock(&dev_priv->sb_lock);
  918. }