intel_dpio_phy.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  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. void bxt_ddi_phy_set_signal_level(struct drm_i915_private *dev_priv,
  115. enum port port, u32 margin, u32 scale,
  116. u32 enable, u32 deemphasis)
  117. {
  118. u32 val;
  119. /*
  120. * While we write to the group register to program all lanes at once we
  121. * can read only lane registers and we pick lanes 0/1 for that.
  122. */
  123. val = I915_READ(BXT_PORT_PCS_DW10_LN01(port));
  124. val &= ~(TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT);
  125. I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val);
  126. val = I915_READ(BXT_PORT_TX_DW2_LN0(port));
  127. val &= ~(MARGIN_000 | UNIQ_TRANS_SCALE);
  128. val |= margin << MARGIN_000_SHIFT | scale << UNIQ_TRANS_SCALE_SHIFT;
  129. I915_WRITE(BXT_PORT_TX_DW2_GRP(port), val);
  130. val = I915_READ(BXT_PORT_TX_DW3_LN0(port));
  131. val &= ~SCALE_DCOMP_METHOD;
  132. if (enable)
  133. val |= SCALE_DCOMP_METHOD;
  134. if ((val & UNIQUE_TRANGE_EN_METHOD) && !(val & SCALE_DCOMP_METHOD))
  135. DRM_ERROR("Disabled scaling while ouniqetrangenmethod was set");
  136. I915_WRITE(BXT_PORT_TX_DW3_GRP(port), val);
  137. val = I915_READ(BXT_PORT_TX_DW4_LN0(port));
  138. val &= ~DE_EMPHASIS;
  139. val |= deemphasis << DEEMPH_SHIFT;
  140. I915_WRITE(BXT_PORT_TX_DW4_GRP(port), val);
  141. val = I915_READ(BXT_PORT_PCS_DW10_LN01(port));
  142. val |= TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT;
  143. I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val);
  144. }
  145. bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv,
  146. enum dpio_phy phy)
  147. {
  148. enum port port;
  149. if (!(I915_READ(BXT_P_CR_GT_DISP_PWRON) & GT_DISPLAY_POWER_ON(phy)))
  150. return false;
  151. if ((I915_READ(BXT_PORT_CL1CM_DW0(phy)) &
  152. (PHY_POWER_GOOD | PHY_RESERVED)) != PHY_POWER_GOOD) {
  153. DRM_DEBUG_DRIVER("DDI PHY %d powered, but power hasn't settled\n",
  154. phy);
  155. return false;
  156. }
  157. if (phy == DPIO_PHY1 &&
  158. !(I915_READ(BXT_PORT_REF_DW3(DPIO_PHY1)) & GRC_DONE)) {
  159. DRM_DEBUG_DRIVER("DDI PHY 1 powered, but GRC isn't done\n");
  160. return false;
  161. }
  162. if (!(I915_READ(BXT_PHY_CTL_FAMILY(phy)) & COMMON_RESET_DIS)) {
  163. DRM_DEBUG_DRIVER("DDI PHY %d powered, but still in reset\n",
  164. phy);
  165. return false;
  166. }
  167. for_each_port_masked(port,
  168. phy == DPIO_PHY0 ? BIT(PORT_B) | BIT(PORT_C) :
  169. BIT(PORT_A)) {
  170. u32 tmp = I915_READ(BXT_PHY_CTL(port));
  171. if (tmp & BXT_PHY_CMNLANE_POWERDOWN_ACK) {
  172. DRM_DEBUG_DRIVER("DDI PHY %d powered, but common lane "
  173. "for port %c powered down "
  174. "(PHY_CTL %08x)\n",
  175. phy, port_name(port), tmp);
  176. return false;
  177. }
  178. }
  179. return true;
  180. }
  181. static u32 bxt_get_grc(struct drm_i915_private *dev_priv, enum dpio_phy phy)
  182. {
  183. u32 val = I915_READ(BXT_PORT_REF_DW6(phy));
  184. return (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT;
  185. }
  186. static void bxt_phy_wait_grc_done(struct drm_i915_private *dev_priv,
  187. enum dpio_phy phy)
  188. {
  189. if (intel_wait_for_register(dev_priv,
  190. BXT_PORT_REF_DW3(phy),
  191. GRC_DONE, GRC_DONE,
  192. 10))
  193. DRM_ERROR("timeout waiting for PHY%d GRC\n", phy);
  194. }
  195. void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy)
  196. {
  197. u32 val;
  198. if (bxt_ddi_phy_is_enabled(dev_priv, phy)) {
  199. /* Still read out the GRC value for state verification */
  200. if (phy == DPIO_PHY0)
  201. dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv, phy);
  202. if (bxt_ddi_phy_verify_state(dev_priv, phy)) {
  203. DRM_DEBUG_DRIVER("DDI PHY %d already enabled, "
  204. "won't reprogram it\n", phy);
  205. return;
  206. }
  207. DRM_DEBUG_DRIVER("DDI PHY %d enabled with invalid state, "
  208. "force reprogramming it\n", phy);
  209. }
  210. val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
  211. val |= GT_DISPLAY_POWER_ON(phy);
  212. I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
  213. /*
  214. * The PHY registers start out inaccessible and respond to reads with
  215. * all 1s. Eventually they become accessible as they power up, then
  216. * the reserved bit will give the default 0. Poll on the reserved bit
  217. * becoming 0 to find when the PHY is accessible.
  218. * HW team confirmed that the time to reach phypowergood status is
  219. * anywhere between 50 us and 100us.
  220. */
  221. if (wait_for_us(((I915_READ(BXT_PORT_CL1CM_DW0(phy)) &
  222. (PHY_RESERVED | PHY_POWER_GOOD)) == PHY_POWER_GOOD), 100)) {
  223. DRM_ERROR("timeout during PHY%d power on\n", phy);
  224. }
  225. /* Program PLL Rcomp code offset */
  226. val = I915_READ(BXT_PORT_CL1CM_DW9(phy));
  227. val &= ~IREF0RC_OFFSET_MASK;
  228. val |= 0xE4 << IREF0RC_OFFSET_SHIFT;
  229. I915_WRITE(BXT_PORT_CL1CM_DW9(phy), val);
  230. val = I915_READ(BXT_PORT_CL1CM_DW10(phy));
  231. val &= ~IREF1RC_OFFSET_MASK;
  232. val |= 0xE4 << IREF1RC_OFFSET_SHIFT;
  233. I915_WRITE(BXT_PORT_CL1CM_DW10(phy), val);
  234. /* Program power gating */
  235. val = I915_READ(BXT_PORT_CL1CM_DW28(phy));
  236. val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN |
  237. SUS_CLK_CONFIG;
  238. I915_WRITE(BXT_PORT_CL1CM_DW28(phy), val);
  239. if (phy == DPIO_PHY0) {
  240. val = I915_READ(BXT_PORT_CL2CM_DW6_BC);
  241. val |= DW6_OLDO_DYN_PWR_DOWN_EN;
  242. I915_WRITE(BXT_PORT_CL2CM_DW6_BC, val);
  243. }
  244. val = I915_READ(BXT_PORT_CL1CM_DW30(phy));
  245. val &= ~OCL2_LDOFUSE_PWR_DIS;
  246. /*
  247. * On PHY1 disable power on the second channel, since no port is
  248. * connected there. On PHY0 both channels have a port, so leave it
  249. * enabled.
  250. * TODO: port C is only connected on BXT-P, so on BXT0/1 we should
  251. * power down the second channel on PHY0 as well.
  252. *
  253. * FIXME: Clarify programming of the following, the register is
  254. * read-only with bit 6 fixed at 0 at least in stepping A.
  255. */
  256. if (phy == DPIO_PHY1)
  257. val |= OCL2_LDOFUSE_PWR_DIS;
  258. I915_WRITE(BXT_PORT_CL1CM_DW30(phy), val);
  259. if (phy == DPIO_PHY0) {
  260. uint32_t grc_code;
  261. /*
  262. * PHY0 isn't connected to an RCOMP resistor so copy over
  263. * the corresponding calibrated value from PHY1, and disable
  264. * the automatic calibration on PHY0.
  265. */
  266. val = dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv, DPIO_PHY1);
  267. grc_code = val << GRC_CODE_FAST_SHIFT |
  268. val << GRC_CODE_SLOW_SHIFT |
  269. val;
  270. I915_WRITE(BXT_PORT_REF_DW6(DPIO_PHY0), grc_code);
  271. val = I915_READ(BXT_PORT_REF_DW8(DPIO_PHY0));
  272. val |= GRC_DIS | GRC_RDY_OVRD;
  273. I915_WRITE(BXT_PORT_REF_DW8(DPIO_PHY0), val);
  274. }
  275. val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
  276. val |= COMMON_RESET_DIS;
  277. I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
  278. if (phy == DPIO_PHY1)
  279. bxt_phy_wait_grc_done(dev_priv, DPIO_PHY1);
  280. }
  281. void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy)
  282. {
  283. uint32_t val;
  284. val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
  285. val &= ~COMMON_RESET_DIS;
  286. I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
  287. val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
  288. val &= ~GT_DISPLAY_POWER_ON(phy);
  289. I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
  290. }
  291. static bool __printf(6, 7)
  292. __phy_reg_verify_state(struct drm_i915_private *dev_priv, enum dpio_phy phy,
  293. i915_reg_t reg, u32 mask, u32 expected,
  294. const char *reg_fmt, ...)
  295. {
  296. struct va_format vaf;
  297. va_list args;
  298. u32 val;
  299. val = I915_READ(reg);
  300. if ((val & mask) == expected)
  301. return true;
  302. va_start(args, reg_fmt);
  303. vaf.fmt = reg_fmt;
  304. vaf.va = &args;
  305. DRM_DEBUG_DRIVER("DDI PHY %d reg %pV [%08x] state mismatch: "
  306. "current %08x, expected %08x (mask %08x)\n",
  307. phy, &vaf, reg.reg, val, (val & ~mask) | expected,
  308. mask);
  309. va_end(args);
  310. return false;
  311. }
  312. bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv,
  313. enum dpio_phy phy)
  314. {
  315. uint32_t mask;
  316. bool ok;
  317. #define _CHK(reg, mask, exp, fmt, ...) \
  318. __phy_reg_verify_state(dev_priv, phy, reg, mask, exp, fmt, \
  319. ## __VA_ARGS__)
  320. if (!bxt_ddi_phy_is_enabled(dev_priv, phy))
  321. return false;
  322. ok = true;
  323. /* PLL Rcomp code offset */
  324. ok &= _CHK(BXT_PORT_CL1CM_DW9(phy),
  325. IREF0RC_OFFSET_MASK, 0xe4 << IREF0RC_OFFSET_SHIFT,
  326. "BXT_PORT_CL1CM_DW9(%d)", phy);
  327. ok &= _CHK(BXT_PORT_CL1CM_DW10(phy),
  328. IREF1RC_OFFSET_MASK, 0xe4 << IREF1RC_OFFSET_SHIFT,
  329. "BXT_PORT_CL1CM_DW10(%d)", phy);
  330. /* Power gating */
  331. mask = OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | SUS_CLK_CONFIG;
  332. ok &= _CHK(BXT_PORT_CL1CM_DW28(phy), mask, mask,
  333. "BXT_PORT_CL1CM_DW28(%d)", phy);
  334. if (phy == DPIO_PHY0)
  335. ok &= _CHK(BXT_PORT_CL2CM_DW6_BC,
  336. DW6_OLDO_DYN_PWR_DOWN_EN, DW6_OLDO_DYN_PWR_DOWN_EN,
  337. "BXT_PORT_CL2CM_DW6_BC");
  338. /*
  339. * TODO: Verify BXT_PORT_CL1CM_DW30 bit OCL2_LDOFUSE_PWR_DIS,
  340. * at least on stepping A this bit is read-only and fixed at 0.
  341. */
  342. if (phy == DPIO_PHY0) {
  343. u32 grc_code = dev_priv->bxt_phy_grc;
  344. grc_code = grc_code << GRC_CODE_FAST_SHIFT |
  345. grc_code << GRC_CODE_SLOW_SHIFT |
  346. grc_code;
  347. mask = GRC_CODE_FAST_MASK | GRC_CODE_SLOW_MASK |
  348. GRC_CODE_NOM_MASK;
  349. ok &= _CHK(BXT_PORT_REF_DW6(DPIO_PHY0), mask, grc_code,
  350. "BXT_PORT_REF_DW6(%d)", DPIO_PHY0);
  351. mask = GRC_DIS | GRC_RDY_OVRD;
  352. ok &= _CHK(BXT_PORT_REF_DW8(DPIO_PHY0), mask, mask,
  353. "BXT_PORT_REF_DW8(%d)", DPIO_PHY0);
  354. }
  355. return ok;
  356. #undef _CHK
  357. }
  358. uint8_t
  359. bxt_ddi_phy_calc_lane_lat_optim_mask(struct intel_encoder *encoder,
  360. uint8_t lane_count)
  361. {
  362. switch (lane_count) {
  363. case 1:
  364. return 0;
  365. case 2:
  366. return BIT(2) | BIT(0);
  367. case 4:
  368. return BIT(3) | BIT(2) | BIT(0);
  369. default:
  370. MISSING_CASE(lane_count);
  371. return 0;
  372. }
  373. }
  374. void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder,
  375. uint8_t lane_lat_optim_mask)
  376. {
  377. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  378. struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
  379. enum port port = dport->port;
  380. int lane;
  381. for (lane = 0; lane < 4; lane++) {
  382. u32 val = I915_READ(BXT_PORT_TX_DW14_LN(port, lane));
  383. /*
  384. * Note that on CHV this flag is called UPAR, but has
  385. * the same function.
  386. */
  387. val &= ~LATENCY_OPTIM;
  388. if (lane_lat_optim_mask & BIT(lane))
  389. val |= LATENCY_OPTIM;
  390. I915_WRITE(BXT_PORT_TX_DW14_LN(port, lane), val);
  391. }
  392. }
  393. uint8_t
  394. bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder)
  395. {
  396. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  397. struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
  398. enum port port = dport->port;
  399. int lane;
  400. uint8_t mask;
  401. mask = 0;
  402. for (lane = 0; lane < 4; lane++) {
  403. u32 val = I915_READ(BXT_PORT_TX_DW14_LN(port, lane));
  404. if (val & LATENCY_OPTIM)
  405. mask |= BIT(lane);
  406. }
  407. return mask;
  408. }
  409. void chv_set_phy_signal_level(struct intel_encoder *encoder,
  410. u32 deemph_reg_value, u32 margin_reg_value,
  411. bool uniq_trans_scale)
  412. {
  413. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  414. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  415. struct intel_crtc *intel_crtc = to_intel_crtc(dport->base.base.crtc);
  416. enum dpio_channel ch = vlv_dport_to_channel(dport);
  417. enum pipe pipe = intel_crtc->pipe;
  418. u32 val;
  419. int i;
  420. mutex_lock(&dev_priv->sb_lock);
  421. /* Clear calc init */
  422. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
  423. val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
  424. val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
  425. val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
  426. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
  427. if (intel_crtc->config->lane_count > 2) {
  428. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
  429. val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
  430. val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
  431. val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
  432. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
  433. }
  434. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
  435. val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
  436. val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
  437. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
  438. if (intel_crtc->config->lane_count > 2) {
  439. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
  440. val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
  441. val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
  442. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
  443. }
  444. /* Program swing deemph */
  445. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  446. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
  447. val &= ~DPIO_SWING_DEEMPH9P5_MASK;
  448. val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
  449. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
  450. }
  451. /* Program swing margin */
  452. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  453. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
  454. val &= ~DPIO_SWING_MARGIN000_MASK;
  455. val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
  456. /*
  457. * Supposedly this value shouldn't matter when unique transition
  458. * scale is disabled, but in fact it does matter. Let's just
  459. * always program the same value and hope it's OK.
  460. */
  461. val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
  462. val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
  463. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
  464. }
  465. /*
  466. * The document said it needs to set bit 27 for ch0 and bit 26
  467. * for ch1. Might be a typo in the doc.
  468. * For now, for this unique transition scale selection, set bit
  469. * 27 for ch0 and ch1.
  470. */
  471. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  472. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
  473. if (uniq_trans_scale)
  474. val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
  475. else
  476. val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
  477. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
  478. }
  479. /* Start swing calculation */
  480. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
  481. val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
  482. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
  483. if (intel_crtc->config->lane_count > 2) {
  484. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
  485. val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
  486. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
  487. }
  488. mutex_unlock(&dev_priv->sb_lock);
  489. }
  490. void chv_data_lane_soft_reset(struct intel_encoder *encoder,
  491. bool reset)
  492. {
  493. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  494. enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
  495. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  496. enum pipe pipe = crtc->pipe;
  497. uint32_t val;
  498. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
  499. if (reset)
  500. val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  501. else
  502. val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
  503. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
  504. if (crtc->config->lane_count > 2) {
  505. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
  506. if (reset)
  507. val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  508. else
  509. val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
  510. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
  511. }
  512. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
  513. val |= CHV_PCS_REQ_SOFTRESET_EN;
  514. if (reset)
  515. val &= ~DPIO_PCS_CLK_SOFT_RESET;
  516. else
  517. val |= DPIO_PCS_CLK_SOFT_RESET;
  518. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
  519. if (crtc->config->lane_count > 2) {
  520. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
  521. val |= CHV_PCS_REQ_SOFTRESET_EN;
  522. if (reset)
  523. val &= ~DPIO_PCS_CLK_SOFT_RESET;
  524. else
  525. val |= DPIO_PCS_CLK_SOFT_RESET;
  526. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
  527. }
  528. }
  529. void chv_phy_pre_pll_enable(struct intel_encoder *encoder)
  530. {
  531. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  532. struct drm_device *dev = encoder->base.dev;
  533. struct drm_i915_private *dev_priv = to_i915(dev);
  534. struct intel_crtc *intel_crtc =
  535. to_intel_crtc(encoder->base.crtc);
  536. enum dpio_channel ch = vlv_dport_to_channel(dport);
  537. enum pipe pipe = intel_crtc->pipe;
  538. unsigned int lane_mask =
  539. intel_dp_unused_lane_mask(intel_crtc->config->lane_count);
  540. u32 val;
  541. /*
  542. * Must trick the second common lane into life.
  543. * Otherwise we can't even access the PLL.
  544. */
  545. if (ch == DPIO_CH0 && pipe == PIPE_B)
  546. dport->release_cl2_override =
  547. !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
  548. chv_phy_powergate_lanes(encoder, true, lane_mask);
  549. mutex_lock(&dev_priv->sb_lock);
  550. /* Assert data lane reset */
  551. chv_data_lane_soft_reset(encoder, true);
  552. /* program left/right clock distribution */
  553. if (pipe != PIPE_B) {
  554. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  555. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  556. if (ch == DPIO_CH0)
  557. val |= CHV_BUFLEFTENA1_FORCE;
  558. if (ch == DPIO_CH1)
  559. val |= CHV_BUFRIGHTENA1_FORCE;
  560. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  561. } else {
  562. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  563. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  564. if (ch == DPIO_CH0)
  565. val |= CHV_BUFLEFTENA2_FORCE;
  566. if (ch == DPIO_CH1)
  567. val |= CHV_BUFRIGHTENA2_FORCE;
  568. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  569. }
  570. /* program clock channel usage */
  571. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
  572. val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
  573. if (pipe != PIPE_B)
  574. val &= ~CHV_PCS_USEDCLKCHANNEL;
  575. else
  576. val |= CHV_PCS_USEDCLKCHANNEL;
  577. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
  578. if (intel_crtc->config->lane_count > 2) {
  579. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
  580. val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
  581. if (pipe != PIPE_B)
  582. val &= ~CHV_PCS_USEDCLKCHANNEL;
  583. else
  584. val |= CHV_PCS_USEDCLKCHANNEL;
  585. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
  586. }
  587. /*
  588. * This a a bit weird since generally CL
  589. * matches the pipe, but here we need to
  590. * pick the CL based on the port.
  591. */
  592. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
  593. if (pipe != PIPE_B)
  594. val &= ~CHV_CMN_USEDCLKCHANNEL;
  595. else
  596. val |= CHV_CMN_USEDCLKCHANNEL;
  597. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
  598. mutex_unlock(&dev_priv->sb_lock);
  599. }
  600. void chv_phy_pre_encoder_enable(struct intel_encoder *encoder)
  601. {
  602. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  603. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  604. struct drm_device *dev = encoder->base.dev;
  605. struct drm_i915_private *dev_priv = to_i915(dev);
  606. struct intel_crtc *intel_crtc =
  607. to_intel_crtc(encoder->base.crtc);
  608. enum dpio_channel ch = vlv_dport_to_channel(dport);
  609. int pipe = intel_crtc->pipe;
  610. int data, i, stagger;
  611. u32 val;
  612. mutex_lock(&dev_priv->sb_lock);
  613. /* allow hardware to manage TX FIFO reset source */
  614. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
  615. val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
  616. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
  617. if (intel_crtc->config->lane_count > 2) {
  618. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
  619. val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
  620. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
  621. }
  622. /* Program Tx lane latency optimal setting*/
  623. for (i = 0; i < intel_crtc->config->lane_count; i++) {
  624. /* Set the upar bit */
  625. if (intel_crtc->config->lane_count == 1)
  626. data = 0x0;
  627. else
  628. data = (i == 1) ? 0x0 : 0x1;
  629. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
  630. data << DPIO_UPAR_SHIFT);
  631. }
  632. /* Data lane stagger programming */
  633. if (intel_crtc->config->port_clock > 270000)
  634. stagger = 0x18;
  635. else if (intel_crtc->config->port_clock > 135000)
  636. stagger = 0xd;
  637. else if (intel_crtc->config->port_clock > 67500)
  638. stagger = 0x7;
  639. else if (intel_crtc->config->port_clock > 33750)
  640. stagger = 0x4;
  641. else
  642. stagger = 0x2;
  643. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
  644. val |= DPIO_TX2_STAGGER_MASK(0x1f);
  645. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
  646. if (intel_crtc->config->lane_count > 2) {
  647. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
  648. val |= DPIO_TX2_STAGGER_MASK(0x1f);
  649. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
  650. }
  651. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
  652. DPIO_LANESTAGGER_STRAP(stagger) |
  653. DPIO_LANESTAGGER_STRAP_OVRD |
  654. DPIO_TX1_STAGGER_MASK(0x1f) |
  655. DPIO_TX1_STAGGER_MULT(6) |
  656. DPIO_TX2_STAGGER_MULT(0));
  657. if (intel_crtc->config->lane_count > 2) {
  658. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
  659. DPIO_LANESTAGGER_STRAP(stagger) |
  660. DPIO_LANESTAGGER_STRAP_OVRD |
  661. DPIO_TX1_STAGGER_MASK(0x1f) |
  662. DPIO_TX1_STAGGER_MULT(7) |
  663. DPIO_TX2_STAGGER_MULT(5));
  664. }
  665. /* Deassert data lane reset */
  666. chv_data_lane_soft_reset(encoder, false);
  667. mutex_unlock(&dev_priv->sb_lock);
  668. }
  669. void chv_phy_release_cl2_override(struct intel_encoder *encoder)
  670. {
  671. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  672. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  673. if (dport->release_cl2_override) {
  674. chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false);
  675. dport->release_cl2_override = false;
  676. }
  677. }
  678. void chv_phy_post_pll_disable(struct intel_encoder *encoder)
  679. {
  680. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  681. enum pipe pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  682. u32 val;
  683. mutex_lock(&dev_priv->sb_lock);
  684. /* disable left/right clock distribution */
  685. if (pipe != PIPE_B) {
  686. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  687. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  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. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  693. }
  694. mutex_unlock(&dev_priv->sb_lock);
  695. /*
  696. * Leave the power down bit cleared for at least one
  697. * lane so that chv_powergate_phy_ch() will power
  698. * on something when the channel is otherwise unused.
  699. * When the port is off and the override is removed
  700. * the lanes power down anyway, so otherwise it doesn't
  701. * really matter what the state of power down bits is
  702. * after this.
  703. */
  704. chv_phy_powergate_lanes(encoder, false, 0x0);
  705. }
  706. void vlv_set_phy_signal_level(struct intel_encoder *encoder,
  707. u32 demph_reg_value, u32 preemph_reg_value,
  708. u32 uniqtranscale_reg_value, u32 tx3_demph)
  709. {
  710. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  711. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  712. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  713. enum dpio_channel port = vlv_dport_to_channel(dport);
  714. int pipe = intel_crtc->pipe;
  715. mutex_lock(&dev_priv->sb_lock);
  716. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
  717. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
  718. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
  719. uniqtranscale_reg_value);
  720. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
  721. if (tx3_demph)
  722. vlv_dpio_write(dev_priv, pipe, VLV_TX3_DW4(port), tx3_demph);
  723. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
  724. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
  725. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
  726. mutex_unlock(&dev_priv->sb_lock);
  727. }
  728. void vlv_phy_pre_pll_enable(struct intel_encoder *encoder)
  729. {
  730. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  731. struct drm_device *dev = encoder->base.dev;
  732. struct drm_i915_private *dev_priv = to_i915(dev);
  733. struct intel_crtc *intel_crtc =
  734. to_intel_crtc(encoder->base.crtc);
  735. enum dpio_channel port = vlv_dport_to_channel(dport);
  736. int pipe = intel_crtc->pipe;
  737. /* Program Tx lane resets to default */
  738. mutex_lock(&dev_priv->sb_lock);
  739. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
  740. DPIO_PCS_TX_LANE2_RESET |
  741. DPIO_PCS_TX_LANE1_RESET);
  742. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
  743. DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
  744. DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
  745. (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
  746. DPIO_PCS_CLK_SOFT_RESET);
  747. /* Fix up inter-pair skew failure */
  748. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
  749. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
  750. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
  751. mutex_unlock(&dev_priv->sb_lock);
  752. }
  753. void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder)
  754. {
  755. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  756. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  757. struct drm_device *dev = encoder->base.dev;
  758. struct drm_i915_private *dev_priv = to_i915(dev);
  759. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  760. enum dpio_channel port = vlv_dport_to_channel(dport);
  761. int pipe = intel_crtc->pipe;
  762. u32 val;
  763. mutex_lock(&dev_priv->sb_lock);
  764. /* Enable clock channels for this port */
  765. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
  766. val = 0;
  767. if (pipe)
  768. val |= (1<<21);
  769. else
  770. val &= ~(1<<21);
  771. val |= 0x001000c4;
  772. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
  773. /* Program lane clock */
  774. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
  775. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
  776. mutex_unlock(&dev_priv->sb_lock);
  777. }
  778. void vlv_phy_reset_lanes(struct intel_encoder *encoder)
  779. {
  780. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  781. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  782. struct intel_crtc *intel_crtc =
  783. to_intel_crtc(encoder->base.crtc);
  784. enum dpio_channel port = vlv_dport_to_channel(dport);
  785. int pipe = intel_crtc->pipe;
  786. mutex_lock(&dev_priv->sb_lock);
  787. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port), 0x00000000);
  788. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port), 0x00e00060);
  789. mutex_unlock(&dev_priv->sb_lock);
  790. }