vlv_dsi_pll.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /*
  2. * Copyright © 2013 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. * Authors:
  24. * Shobhit Kumar <shobhit.kumar@intel.com>
  25. * Yogesh Mohan Marimuthu <yogesh.mohan.marimuthu@intel.com>
  26. */
  27. #include <linux/kernel.h>
  28. #include "intel_drv.h"
  29. #include "i915_drv.h"
  30. #include "intel_dsi.h"
  31. static const u16 lfsr_converts[] = {
  32. 426, 469, 234, 373, 442, 221, 110, 311, 411, /* 62 - 70 */
  33. 461, 486, 243, 377, 188, 350, 175, 343, 427, 213, /* 71 - 80 */
  34. 106, 53, 282, 397, 454, 227, 113, 56, 284, 142, /* 81 - 90 */
  35. 71, 35, 273, 136, 324, 418, 465, 488, 500, 506 /* 91 - 100 */
  36. };
  37. /* Get DSI clock from pixel clock */
  38. static u32 dsi_clk_from_pclk(u32 pclk, enum mipi_dsi_pixel_format fmt,
  39. int lane_count)
  40. {
  41. u32 dsi_clk_khz;
  42. u32 bpp = mipi_dsi_pixel_format_to_bpp(fmt);
  43. /* DSI data rate = pixel clock * bits per pixel / lane count
  44. pixel clock is converted from KHz to Hz */
  45. dsi_clk_khz = DIV_ROUND_CLOSEST(pclk * bpp, lane_count);
  46. return dsi_clk_khz;
  47. }
  48. static int dsi_calc_mnp(struct drm_i915_private *dev_priv,
  49. struct intel_crtc_state *config,
  50. int target_dsi_clk)
  51. {
  52. unsigned int m_min, m_max, p_min = 2, p_max = 6;
  53. unsigned int m, n, p;
  54. unsigned int calc_m, calc_p;
  55. int delta, ref_clk;
  56. /* target_dsi_clk is expected in kHz */
  57. if (target_dsi_clk < 300000 || target_dsi_clk > 1150000) {
  58. DRM_ERROR("DSI CLK Out of Range\n");
  59. return -ECHRNG;
  60. }
  61. if (IS_CHERRYVIEW(dev_priv)) {
  62. ref_clk = 100000;
  63. n = 4;
  64. m_min = 70;
  65. m_max = 96;
  66. } else {
  67. ref_clk = 25000;
  68. n = 1;
  69. m_min = 62;
  70. m_max = 92;
  71. }
  72. calc_p = p_min;
  73. calc_m = m_min;
  74. delta = abs(target_dsi_clk - (m_min * ref_clk) / (p_min * n));
  75. for (m = m_min; m <= m_max && delta; m++) {
  76. for (p = p_min; p <= p_max && delta; p++) {
  77. /*
  78. * Find the optimal m and p divisors with minimal delta
  79. * +/- the required clock
  80. */
  81. int calc_dsi_clk = (m * ref_clk) / (p * n);
  82. int d = abs(target_dsi_clk - calc_dsi_clk);
  83. if (d < delta) {
  84. delta = d;
  85. calc_m = m;
  86. calc_p = p;
  87. }
  88. }
  89. }
  90. /* register has log2(N1), this works fine for powers of two */
  91. config->dsi_pll.ctrl = 1 << (DSI_PLL_P1_POST_DIV_SHIFT + calc_p - 2);
  92. config->dsi_pll.div =
  93. (ffs(n) - 1) << DSI_PLL_N1_DIV_SHIFT |
  94. (u32)lfsr_converts[calc_m - 62] << DSI_PLL_M1_DIV_SHIFT;
  95. return 0;
  96. }
  97. /*
  98. * XXX: The muxing and gating is hard coded for now. Need to add support for
  99. * sharing PLLs with two DSI outputs.
  100. */
  101. int vlv_dsi_pll_compute(struct intel_encoder *encoder,
  102. struct intel_crtc_state *config)
  103. {
  104. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  105. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  106. int ret;
  107. u32 dsi_clk;
  108. dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format,
  109. intel_dsi->lane_count);
  110. ret = dsi_calc_mnp(dev_priv, config, dsi_clk);
  111. if (ret) {
  112. DRM_DEBUG_KMS("dsi_calc_mnp failed\n");
  113. return ret;
  114. }
  115. if (intel_dsi->ports & (1 << PORT_A))
  116. config->dsi_pll.ctrl |= DSI_PLL_CLK_GATE_DSI0_DSIPLL;
  117. if (intel_dsi->ports & (1 << PORT_C))
  118. config->dsi_pll.ctrl |= DSI_PLL_CLK_GATE_DSI1_DSIPLL;
  119. config->dsi_pll.ctrl |= DSI_PLL_VCO_EN;
  120. DRM_DEBUG_KMS("dsi pll div %08x, ctrl %08x\n",
  121. config->dsi_pll.div, config->dsi_pll.ctrl);
  122. return 0;
  123. }
  124. void vlv_dsi_pll_enable(struct intel_encoder *encoder,
  125. const struct intel_crtc_state *config)
  126. {
  127. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  128. DRM_DEBUG_KMS("\n");
  129. mutex_lock(&dev_priv->sb_lock);
  130. vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, 0);
  131. vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_DIVIDER, config->dsi_pll.div);
  132. vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL,
  133. config->dsi_pll.ctrl & ~DSI_PLL_VCO_EN);
  134. /* wait at least 0.5 us after ungating before enabling VCO,
  135. * allow hrtimer subsystem optimization by relaxing timing
  136. */
  137. usleep_range(10, 50);
  138. vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, config->dsi_pll.ctrl);
  139. if (wait_for(vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL) &
  140. DSI_PLL_LOCK, 20)) {
  141. mutex_unlock(&dev_priv->sb_lock);
  142. DRM_ERROR("DSI PLL lock failed\n");
  143. return;
  144. }
  145. mutex_unlock(&dev_priv->sb_lock);
  146. DRM_DEBUG_KMS("DSI PLL locked\n");
  147. }
  148. void vlv_dsi_pll_disable(struct intel_encoder *encoder)
  149. {
  150. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  151. u32 tmp;
  152. DRM_DEBUG_KMS("\n");
  153. mutex_lock(&dev_priv->sb_lock);
  154. tmp = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  155. tmp &= ~DSI_PLL_VCO_EN;
  156. tmp |= DSI_PLL_LDO_GATE;
  157. vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, tmp);
  158. mutex_unlock(&dev_priv->sb_lock);
  159. }
  160. bool bxt_dsi_pll_is_enabled(struct drm_i915_private *dev_priv)
  161. {
  162. bool enabled;
  163. u32 val;
  164. u32 mask;
  165. mask = BXT_DSI_PLL_DO_ENABLE | BXT_DSI_PLL_LOCKED;
  166. val = I915_READ(BXT_DSI_PLL_ENABLE);
  167. enabled = (val & mask) == mask;
  168. if (!enabled)
  169. return false;
  170. /*
  171. * Dividers must be programmed with valid values. As per BSEPC, for
  172. * GEMINLAKE only PORT A divider values are checked while for BXT
  173. * both divider values are validated. Check this here for
  174. * paranoia, since BIOS is known to misconfigure PLLs in this way at
  175. * times, and since accessing DSI registers with invalid dividers
  176. * causes a system hang.
  177. */
  178. val = I915_READ(BXT_DSI_PLL_CTL);
  179. if (IS_GEMINILAKE(dev_priv)) {
  180. if (!(val & BXT_DSIA_16X_MASK)) {
  181. DRM_DEBUG_DRIVER("Invalid PLL divider (%08x)\n", val);
  182. enabled = false;
  183. }
  184. } else {
  185. if (!(val & BXT_DSIA_16X_MASK) || !(val & BXT_DSIC_16X_MASK)) {
  186. DRM_DEBUG_DRIVER("Invalid PLL divider (%08x)\n", val);
  187. enabled = false;
  188. }
  189. }
  190. return enabled;
  191. }
  192. void bxt_dsi_pll_disable(struct intel_encoder *encoder)
  193. {
  194. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  195. u32 val;
  196. DRM_DEBUG_KMS("\n");
  197. val = I915_READ(BXT_DSI_PLL_ENABLE);
  198. val &= ~BXT_DSI_PLL_DO_ENABLE;
  199. I915_WRITE(BXT_DSI_PLL_ENABLE, val);
  200. /*
  201. * PLL lock should deassert within 200us.
  202. * Wait up to 1ms before timing out.
  203. */
  204. if (intel_wait_for_register(dev_priv,
  205. BXT_DSI_PLL_ENABLE,
  206. BXT_DSI_PLL_LOCKED,
  207. 0,
  208. 1))
  209. DRM_ERROR("Timeout waiting for PLL lock deassertion\n");
  210. }
  211. static void assert_bpp_mismatch(enum mipi_dsi_pixel_format fmt, int pipe_bpp)
  212. {
  213. int bpp = mipi_dsi_pixel_format_to_bpp(fmt);
  214. WARN(bpp != pipe_bpp,
  215. "bpp match assertion failure (expected %d, current %d)\n",
  216. bpp, pipe_bpp);
  217. }
  218. u32 vlv_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp,
  219. struct intel_crtc_state *config)
  220. {
  221. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  222. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  223. u32 dsi_clock, pclk;
  224. u32 pll_ctl, pll_div;
  225. u32 m = 0, p = 0, n;
  226. int refclk = IS_CHERRYVIEW(dev_priv) ? 100000 : 25000;
  227. int i;
  228. DRM_DEBUG_KMS("\n");
  229. mutex_lock(&dev_priv->sb_lock);
  230. pll_ctl = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  231. pll_div = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_DIVIDER);
  232. mutex_unlock(&dev_priv->sb_lock);
  233. config->dsi_pll.ctrl = pll_ctl & ~DSI_PLL_LOCK;
  234. config->dsi_pll.div = pll_div;
  235. /* mask out other bits and extract the P1 divisor */
  236. pll_ctl &= DSI_PLL_P1_POST_DIV_MASK;
  237. pll_ctl = pll_ctl >> (DSI_PLL_P1_POST_DIV_SHIFT - 2);
  238. /* N1 divisor */
  239. n = (pll_div & DSI_PLL_N1_DIV_MASK) >> DSI_PLL_N1_DIV_SHIFT;
  240. n = 1 << n; /* register has log2(N1) */
  241. /* mask out the other bits and extract the M1 divisor */
  242. pll_div &= DSI_PLL_M1_DIV_MASK;
  243. pll_div = pll_div >> DSI_PLL_M1_DIV_SHIFT;
  244. while (pll_ctl) {
  245. pll_ctl = pll_ctl >> 1;
  246. p++;
  247. }
  248. p--;
  249. if (!p) {
  250. DRM_ERROR("wrong P1 divisor\n");
  251. return 0;
  252. }
  253. for (i = 0; i < ARRAY_SIZE(lfsr_converts); i++) {
  254. if (lfsr_converts[i] == pll_div)
  255. break;
  256. }
  257. if (i == ARRAY_SIZE(lfsr_converts)) {
  258. DRM_ERROR("wrong m_seed programmed\n");
  259. return 0;
  260. }
  261. m = i + 62;
  262. dsi_clock = (m * refclk) / (p * n);
  263. /* pixel_format and pipe_bpp should agree */
  264. assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp);
  265. pclk = DIV_ROUND_CLOSEST(dsi_clock * intel_dsi->lane_count, pipe_bpp);
  266. return pclk;
  267. }
  268. u32 bxt_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp,
  269. struct intel_crtc_state *config)
  270. {
  271. u32 pclk;
  272. u32 dsi_clk;
  273. u32 dsi_ratio;
  274. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  275. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  276. /* Divide by zero */
  277. if (!pipe_bpp) {
  278. DRM_ERROR("Invalid BPP(0)\n");
  279. return 0;
  280. }
  281. config->dsi_pll.ctrl = I915_READ(BXT_DSI_PLL_CTL);
  282. dsi_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
  283. dsi_clk = (dsi_ratio * BXT_REF_CLOCK_KHZ) / 2;
  284. /* pixel_format and pipe_bpp should agree */
  285. assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp);
  286. pclk = DIV_ROUND_CLOSEST(dsi_clk * intel_dsi->lane_count, pipe_bpp);
  287. DRM_DEBUG_DRIVER("Calculated pclk=%u\n", pclk);
  288. return pclk;
  289. }
  290. void vlv_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
  291. {
  292. u32 temp;
  293. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  294. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  295. temp = I915_READ(MIPI_CTRL(port));
  296. temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  297. I915_WRITE(MIPI_CTRL(port), temp |
  298. intel_dsi->escape_clk_div <<
  299. ESCAPE_CLOCK_DIVIDER_SHIFT);
  300. }
  301. static void glk_dsi_program_esc_clock(struct drm_device *dev,
  302. const struct intel_crtc_state *config)
  303. {
  304. struct drm_i915_private *dev_priv = to_i915(dev);
  305. u32 dsi_rate = 0;
  306. u32 pll_ratio = 0;
  307. u32 ddr_clk = 0;
  308. u32 div1_value = 0;
  309. u32 div2_value = 0;
  310. u32 txesc1_div = 0;
  311. u32 txesc2_div = 0;
  312. pll_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
  313. dsi_rate = (BXT_REF_CLOCK_KHZ * pll_ratio) / 2;
  314. ddr_clk = dsi_rate / 2;
  315. /* Variable divider value */
  316. div1_value = DIV_ROUND_CLOSEST(ddr_clk, 20000);
  317. /* Calculate TXESC1 divider */
  318. if (div1_value <= 10)
  319. txesc1_div = div1_value;
  320. else if ((div1_value > 10) && (div1_value <= 20))
  321. txesc1_div = DIV_ROUND_UP(div1_value, 2);
  322. else if ((div1_value > 20) && (div1_value <= 30))
  323. txesc1_div = DIV_ROUND_UP(div1_value, 4);
  324. else if ((div1_value > 30) && (div1_value <= 40))
  325. txesc1_div = DIV_ROUND_UP(div1_value, 6);
  326. else if ((div1_value > 40) && (div1_value <= 50))
  327. txesc1_div = DIV_ROUND_UP(div1_value, 8);
  328. else
  329. txesc1_div = 10;
  330. /* Calculate TXESC2 divider */
  331. div2_value = DIV_ROUND_UP(div1_value, txesc1_div);
  332. if (div2_value < 10)
  333. txesc2_div = div2_value;
  334. else
  335. txesc2_div = 10;
  336. I915_WRITE(MIPIO_TXESC_CLK_DIV1, (1 << (txesc1_div - 1)) & GLK_TX_ESC_CLK_DIV1_MASK);
  337. I915_WRITE(MIPIO_TXESC_CLK_DIV2, (1 << (txesc2_div - 1)) & GLK_TX_ESC_CLK_DIV2_MASK);
  338. }
  339. /* Program BXT Mipi clocks and dividers */
  340. static void bxt_dsi_program_clocks(struct drm_device *dev, enum port port,
  341. const struct intel_crtc_state *config)
  342. {
  343. struct drm_i915_private *dev_priv = to_i915(dev);
  344. u32 tmp;
  345. u32 dsi_rate = 0;
  346. u32 pll_ratio = 0;
  347. u32 rx_div;
  348. u32 tx_div;
  349. u32 rx_div_upper;
  350. u32 rx_div_lower;
  351. u32 mipi_8by3_divider;
  352. /* Clear old configurations */
  353. tmp = I915_READ(BXT_MIPI_CLOCK_CTL);
  354. tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port));
  355. tmp &= ~(BXT_MIPI_RX_ESCLK_UPPER_FIXDIV_MASK(port));
  356. tmp &= ~(BXT_MIPI_8X_BY3_DIVIDER_MASK(port));
  357. tmp &= ~(BXT_MIPI_RX_ESCLK_LOWER_FIXDIV_MASK(port));
  358. /* Get the current DSI rate(actual) */
  359. pll_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
  360. dsi_rate = (BXT_REF_CLOCK_KHZ * pll_ratio) / 2;
  361. /*
  362. * tx clock should be <= 20MHz and the div value must be
  363. * subtracted by 1 as per bspec
  364. */
  365. tx_div = DIV_ROUND_UP(dsi_rate, 20000) - 1;
  366. /*
  367. * rx clock should be <= 150MHz and the div value must be
  368. * subtracted by 1 as per bspec
  369. */
  370. rx_div = DIV_ROUND_UP(dsi_rate, 150000) - 1;
  371. /*
  372. * rx divider value needs to be updated in the
  373. * two differnt bit fields in the register hence splitting the
  374. * rx divider value accordingly
  375. */
  376. rx_div_lower = rx_div & RX_DIVIDER_BIT_1_2;
  377. rx_div_upper = (rx_div & RX_DIVIDER_BIT_3_4) >> 2;
  378. mipi_8by3_divider = 0x2;
  379. tmp |= BXT_MIPI_8X_BY3_DIVIDER(port, mipi_8by3_divider);
  380. tmp |= BXT_MIPI_TX_ESCLK_DIVIDER(port, tx_div);
  381. tmp |= BXT_MIPI_RX_ESCLK_LOWER_DIVIDER(port, rx_div_lower);
  382. tmp |= BXT_MIPI_RX_ESCLK_UPPER_DIVIDER(port, rx_div_upper);
  383. I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp);
  384. }
  385. int bxt_dsi_pll_compute(struct intel_encoder *encoder,
  386. struct intel_crtc_state *config)
  387. {
  388. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  389. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  390. u8 dsi_ratio, dsi_ratio_min, dsi_ratio_max;
  391. u32 dsi_clk;
  392. dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format,
  393. intel_dsi->lane_count);
  394. /*
  395. * From clock diagram, to get PLL ratio divider, divide double of DSI
  396. * link rate (i.e., 2*8x=16x frequency value) by ref clock. Make sure to
  397. * round 'up' the result
  398. */
  399. dsi_ratio = DIV_ROUND_UP(dsi_clk * 2, BXT_REF_CLOCK_KHZ);
  400. if (IS_BROXTON(dev_priv)) {
  401. dsi_ratio_min = BXT_DSI_PLL_RATIO_MIN;
  402. dsi_ratio_max = BXT_DSI_PLL_RATIO_MAX;
  403. } else {
  404. dsi_ratio_min = GLK_DSI_PLL_RATIO_MIN;
  405. dsi_ratio_max = GLK_DSI_PLL_RATIO_MAX;
  406. }
  407. if (dsi_ratio < dsi_ratio_min || dsi_ratio > dsi_ratio_max) {
  408. DRM_ERROR("Cant get a suitable ratio from DSI PLL ratios\n");
  409. return -ECHRNG;
  410. } else
  411. DRM_DEBUG_KMS("DSI PLL calculation is Done!!\n");
  412. /*
  413. * Program DSI ratio and Select MIPIC and MIPIA PLL output as 8x
  414. * Spec says both have to be programmed, even if one is not getting
  415. * used. Configure MIPI_CLOCK_CTL dividers in modeset
  416. */
  417. config->dsi_pll.ctrl = dsi_ratio | BXT_DSIA_16X_BY2 | BXT_DSIC_16X_BY2;
  418. /* As per recommendation from hardware team,
  419. * Prog PVD ratio =1 if dsi ratio <= 50
  420. */
  421. if (IS_BROXTON(dev_priv) && dsi_ratio <= 50)
  422. config->dsi_pll.ctrl |= BXT_DSI_PLL_PVD_RATIO_1;
  423. return 0;
  424. }
  425. void bxt_dsi_pll_enable(struct intel_encoder *encoder,
  426. const struct intel_crtc_state *config)
  427. {
  428. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  429. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  430. enum port port;
  431. u32 val;
  432. DRM_DEBUG_KMS("\n");
  433. /* Configure PLL vales */
  434. I915_WRITE(BXT_DSI_PLL_CTL, config->dsi_pll.ctrl);
  435. POSTING_READ(BXT_DSI_PLL_CTL);
  436. /* Program TX, RX, Dphy clocks */
  437. if (IS_BROXTON(dev_priv)) {
  438. for_each_dsi_port(port, intel_dsi->ports)
  439. bxt_dsi_program_clocks(encoder->base.dev, port, config);
  440. } else {
  441. glk_dsi_program_esc_clock(encoder->base.dev, config);
  442. }
  443. /* Enable DSI PLL */
  444. val = I915_READ(BXT_DSI_PLL_ENABLE);
  445. val |= BXT_DSI_PLL_DO_ENABLE;
  446. I915_WRITE(BXT_DSI_PLL_ENABLE, val);
  447. /* Timeout and fail if PLL not locked */
  448. if (intel_wait_for_register(dev_priv,
  449. BXT_DSI_PLL_ENABLE,
  450. BXT_DSI_PLL_LOCKED,
  451. BXT_DSI_PLL_LOCKED,
  452. 1)) {
  453. DRM_ERROR("Timed out waiting for DSI PLL to lock\n");
  454. return;
  455. }
  456. DRM_DEBUG_KMS("DSI PLL locked\n");
  457. }
  458. void bxt_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
  459. {
  460. u32 tmp;
  461. struct drm_device *dev = encoder->base.dev;
  462. struct drm_i915_private *dev_priv = to_i915(dev);
  463. /* Clear old configurations */
  464. if (IS_BROXTON(dev_priv)) {
  465. tmp = I915_READ(BXT_MIPI_CLOCK_CTL);
  466. tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port));
  467. tmp &= ~(BXT_MIPI_RX_ESCLK_UPPER_FIXDIV_MASK(port));
  468. tmp &= ~(BXT_MIPI_8X_BY3_DIVIDER_MASK(port));
  469. tmp &= ~(BXT_MIPI_RX_ESCLK_LOWER_FIXDIV_MASK(port));
  470. I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp);
  471. } else {
  472. tmp = I915_READ(MIPIO_TXESC_CLK_DIV1);
  473. tmp &= ~GLK_TX_ESC_CLK_DIV1_MASK;
  474. I915_WRITE(MIPIO_TXESC_CLK_DIV1, tmp);
  475. tmp = I915_READ(MIPIO_TXESC_CLK_DIV2);
  476. tmp &= ~GLK_TX_ESC_CLK_DIV2_MASK;
  477. I915_WRITE(MIPIO_TXESC_CLK_DIV2, tmp);
  478. }
  479. I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
  480. }