intel_dsi_pll.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. static int vlv_compute_dsi_pll(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. static void vlv_enable_dsi_pll(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. static void vlv_disable_dsi_pll(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. static 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. static void bxt_disable_dsi_pll(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. static 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. static 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. u32 intel_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp,
  291. struct intel_crtc_state *config)
  292. {
  293. if (IS_GEN9_LP(to_i915(encoder->base.dev)))
  294. return bxt_dsi_get_pclk(encoder, pipe_bpp, config);
  295. else
  296. return vlv_dsi_get_pclk(encoder, pipe_bpp, config);
  297. }
  298. static void vlv_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
  299. {
  300. u32 temp;
  301. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  302. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  303. temp = I915_READ(MIPI_CTRL(port));
  304. temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  305. I915_WRITE(MIPI_CTRL(port), temp |
  306. intel_dsi->escape_clk_div <<
  307. ESCAPE_CLOCK_DIVIDER_SHIFT);
  308. }
  309. static void glk_dsi_program_esc_clock(struct drm_device *dev,
  310. const struct intel_crtc_state *config)
  311. {
  312. struct drm_i915_private *dev_priv = to_i915(dev);
  313. u32 dsi_rate = 0;
  314. u32 pll_ratio = 0;
  315. u32 ddr_clk = 0;
  316. u32 div1_value = 0;
  317. u32 div2_value = 0;
  318. u32 txesc1_div = 0;
  319. u32 txesc2_div = 0;
  320. pll_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
  321. dsi_rate = (BXT_REF_CLOCK_KHZ * pll_ratio) / 2;
  322. ddr_clk = dsi_rate / 2;
  323. /* Variable divider value */
  324. div1_value = DIV_ROUND_CLOSEST(ddr_clk, 20000);
  325. /* Calculate TXESC1 divider */
  326. if (div1_value <= 10)
  327. txesc1_div = div1_value;
  328. else if ((div1_value > 10) && (div1_value <= 20))
  329. txesc1_div = DIV_ROUND_UP(div1_value, 2);
  330. else if ((div1_value > 20) && (div1_value <= 30))
  331. txesc1_div = DIV_ROUND_UP(div1_value, 4);
  332. else if ((div1_value > 30) && (div1_value <= 40))
  333. txesc1_div = DIV_ROUND_UP(div1_value, 6);
  334. else if ((div1_value > 40) && (div1_value <= 50))
  335. txesc1_div = DIV_ROUND_UP(div1_value, 8);
  336. else
  337. txesc1_div = 10;
  338. /* Calculate TXESC2 divider */
  339. div2_value = DIV_ROUND_UP(div1_value, txesc1_div);
  340. if (div2_value < 10)
  341. txesc2_div = div2_value;
  342. else
  343. txesc2_div = 10;
  344. I915_WRITE(MIPIO_TXESC_CLK_DIV1, txesc1_div & GLK_TX_ESC_CLK_DIV1_MASK);
  345. I915_WRITE(MIPIO_TXESC_CLK_DIV2, txesc2_div & GLK_TX_ESC_CLK_DIV2_MASK);
  346. }
  347. /* Program BXT Mipi clocks and dividers */
  348. static void bxt_dsi_program_clocks(struct drm_device *dev, enum port port,
  349. const struct intel_crtc_state *config)
  350. {
  351. struct drm_i915_private *dev_priv = to_i915(dev);
  352. u32 tmp;
  353. u32 dsi_rate = 0;
  354. u32 pll_ratio = 0;
  355. u32 rx_div;
  356. u32 tx_div;
  357. u32 rx_div_upper;
  358. u32 rx_div_lower;
  359. u32 mipi_8by3_divider;
  360. /* Clear old configurations */
  361. tmp = I915_READ(BXT_MIPI_CLOCK_CTL);
  362. tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port));
  363. tmp &= ~(BXT_MIPI_RX_ESCLK_UPPER_FIXDIV_MASK(port));
  364. tmp &= ~(BXT_MIPI_8X_BY3_DIVIDER_MASK(port));
  365. tmp &= ~(BXT_MIPI_RX_ESCLK_LOWER_FIXDIV_MASK(port));
  366. /* Get the current DSI rate(actual) */
  367. pll_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
  368. dsi_rate = (BXT_REF_CLOCK_KHZ * pll_ratio) / 2;
  369. /*
  370. * tx clock should be <= 20MHz and the div value must be
  371. * subtracted by 1 as per bspec
  372. */
  373. tx_div = DIV_ROUND_UP(dsi_rate, 20000) - 1;
  374. /*
  375. * rx clock should be <= 150MHz and the div value must be
  376. * subtracted by 1 as per bspec
  377. */
  378. rx_div = DIV_ROUND_UP(dsi_rate, 150000) - 1;
  379. /*
  380. * rx divider value needs to be updated in the
  381. * two differnt bit fields in the register hence splitting the
  382. * rx divider value accordingly
  383. */
  384. rx_div_lower = rx_div & RX_DIVIDER_BIT_1_2;
  385. rx_div_upper = (rx_div & RX_DIVIDER_BIT_3_4) >> 2;
  386. mipi_8by3_divider = 0x2;
  387. tmp |= BXT_MIPI_8X_BY3_DIVIDER(port, mipi_8by3_divider);
  388. tmp |= BXT_MIPI_TX_ESCLK_DIVIDER(port, tx_div);
  389. tmp |= BXT_MIPI_RX_ESCLK_LOWER_DIVIDER(port, rx_div_lower);
  390. tmp |= BXT_MIPI_RX_ESCLK_UPPER_DIVIDER(port, rx_div_upper);
  391. I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp);
  392. }
  393. static int gen9lp_compute_dsi_pll(struct intel_encoder *encoder,
  394. struct intel_crtc_state *config)
  395. {
  396. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  397. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  398. u8 dsi_ratio, dsi_ratio_min, dsi_ratio_max;
  399. u32 dsi_clk;
  400. dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format,
  401. intel_dsi->lane_count);
  402. /*
  403. * From clock diagram, to get PLL ratio divider, divide double of DSI
  404. * link rate (i.e., 2*8x=16x frequency value) by ref clock. Make sure to
  405. * round 'up' the result
  406. */
  407. dsi_ratio = DIV_ROUND_UP(dsi_clk * 2, BXT_REF_CLOCK_KHZ);
  408. if (IS_BROXTON(dev_priv)) {
  409. dsi_ratio_min = BXT_DSI_PLL_RATIO_MIN;
  410. dsi_ratio_max = BXT_DSI_PLL_RATIO_MAX;
  411. } else {
  412. dsi_ratio_min = GLK_DSI_PLL_RATIO_MIN;
  413. dsi_ratio_max = GLK_DSI_PLL_RATIO_MAX;
  414. }
  415. if (dsi_ratio < dsi_ratio_min || dsi_ratio > dsi_ratio_max) {
  416. DRM_ERROR("Cant get a suitable ratio from DSI PLL ratios\n");
  417. return -ECHRNG;
  418. } else
  419. DRM_DEBUG_KMS("DSI PLL calculation is Done!!\n");
  420. /*
  421. * Program DSI ratio and Select MIPIC and MIPIA PLL output as 8x
  422. * Spec says both have to be programmed, even if one is not getting
  423. * used. Configure MIPI_CLOCK_CTL dividers in modeset
  424. */
  425. config->dsi_pll.ctrl = dsi_ratio | BXT_DSIA_16X_BY2 | BXT_DSIC_16X_BY2;
  426. /* As per recommendation from hardware team,
  427. * Prog PVD ratio =1 if dsi ratio <= 50
  428. */
  429. if (IS_BROXTON(dev_priv) && dsi_ratio <= 50)
  430. config->dsi_pll.ctrl |= BXT_DSI_PLL_PVD_RATIO_1;
  431. return 0;
  432. }
  433. static void gen9lp_enable_dsi_pll(struct intel_encoder *encoder,
  434. const struct intel_crtc_state *config)
  435. {
  436. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  437. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  438. enum port port;
  439. u32 val;
  440. DRM_DEBUG_KMS("\n");
  441. /* Configure PLL vales */
  442. I915_WRITE(BXT_DSI_PLL_CTL, config->dsi_pll.ctrl);
  443. POSTING_READ(BXT_DSI_PLL_CTL);
  444. /* Program TX, RX, Dphy clocks */
  445. if (IS_BROXTON(dev_priv)) {
  446. for_each_dsi_port(port, intel_dsi->ports)
  447. bxt_dsi_program_clocks(encoder->base.dev, port, config);
  448. } else {
  449. glk_dsi_program_esc_clock(encoder->base.dev, config);
  450. }
  451. /* Enable DSI PLL */
  452. val = I915_READ(BXT_DSI_PLL_ENABLE);
  453. val |= BXT_DSI_PLL_DO_ENABLE;
  454. I915_WRITE(BXT_DSI_PLL_ENABLE, val);
  455. /* Timeout and fail if PLL not locked */
  456. if (intel_wait_for_register(dev_priv,
  457. BXT_DSI_PLL_ENABLE,
  458. BXT_DSI_PLL_LOCKED,
  459. BXT_DSI_PLL_LOCKED,
  460. 1)) {
  461. DRM_ERROR("Timed out waiting for DSI PLL to lock\n");
  462. return;
  463. }
  464. DRM_DEBUG_KMS("DSI PLL locked\n");
  465. }
  466. bool intel_dsi_pll_is_enabled(struct drm_i915_private *dev_priv)
  467. {
  468. if (IS_GEN9_LP(dev_priv))
  469. return bxt_dsi_pll_is_enabled(dev_priv);
  470. MISSING_CASE(INTEL_DEVID(dev_priv));
  471. return false;
  472. }
  473. int intel_compute_dsi_pll(struct intel_encoder *encoder,
  474. struct intel_crtc_state *config)
  475. {
  476. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  477. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  478. return vlv_compute_dsi_pll(encoder, config);
  479. else if (IS_GEN9_LP(dev_priv))
  480. return gen9lp_compute_dsi_pll(encoder, config);
  481. return -ENODEV;
  482. }
  483. void intel_enable_dsi_pll(struct intel_encoder *encoder,
  484. const struct intel_crtc_state *config)
  485. {
  486. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  487. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  488. vlv_enable_dsi_pll(encoder, config);
  489. else if (IS_GEN9_LP(dev_priv))
  490. gen9lp_enable_dsi_pll(encoder, config);
  491. }
  492. void intel_disable_dsi_pll(struct intel_encoder *encoder)
  493. {
  494. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  495. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  496. vlv_disable_dsi_pll(encoder);
  497. else if (IS_GEN9_LP(dev_priv))
  498. bxt_disable_dsi_pll(encoder);
  499. }
  500. static void gen9lp_dsi_reset_clocks(struct intel_encoder *encoder,
  501. enum port port)
  502. {
  503. u32 tmp;
  504. struct drm_device *dev = encoder->base.dev;
  505. struct drm_i915_private *dev_priv = to_i915(dev);
  506. /* Clear old configurations */
  507. if (IS_BROXTON(dev_priv)) {
  508. tmp = I915_READ(BXT_MIPI_CLOCK_CTL);
  509. tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port));
  510. tmp &= ~(BXT_MIPI_RX_ESCLK_UPPER_FIXDIV_MASK(port));
  511. tmp &= ~(BXT_MIPI_8X_BY3_DIVIDER_MASK(port));
  512. tmp &= ~(BXT_MIPI_RX_ESCLK_LOWER_FIXDIV_MASK(port));
  513. I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp);
  514. } else {
  515. tmp = I915_READ(MIPIO_TXESC_CLK_DIV1);
  516. tmp &= ~GLK_TX_ESC_CLK_DIV1_MASK;
  517. I915_WRITE(MIPIO_TXESC_CLK_DIV1, tmp);
  518. tmp = I915_READ(MIPIO_TXESC_CLK_DIV2);
  519. tmp &= ~GLK_TX_ESC_CLK_DIV2_MASK;
  520. I915_WRITE(MIPIO_TXESC_CLK_DIV2, tmp);
  521. }
  522. I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
  523. }
  524. void intel_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
  525. {
  526. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  527. if (IS_GEN9_LP(dev_priv))
  528. gen9lp_dsi_reset_clocks(encoder, port);
  529. else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  530. vlv_dsi_reset_clocks(encoder, port);
  531. }