intel_dsi_pll.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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. * Both dividers must be programmed with valid values even if only one
  172. * of the PLL is used, see BSpec/Broxton Clocks. Check this here for
  173. * paranoia, since BIOS is known to misconfigure PLLs in this way at
  174. * times, and since accessing DSI registers with invalid dividers
  175. * causes a system hang.
  176. */
  177. val = I915_READ(BXT_DSI_PLL_CTL);
  178. if (!(val & BXT_DSIA_16X_MASK) || !(val & BXT_DSIC_16X_MASK)) {
  179. DRM_DEBUG_DRIVER("PLL is enabled with invalid divider settings (%08x)\n",
  180. val);
  181. enabled = false;
  182. }
  183. return enabled;
  184. }
  185. static void bxt_disable_dsi_pll(struct intel_encoder *encoder)
  186. {
  187. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  188. u32 val;
  189. DRM_DEBUG_KMS("\n");
  190. val = I915_READ(BXT_DSI_PLL_ENABLE);
  191. val &= ~BXT_DSI_PLL_DO_ENABLE;
  192. I915_WRITE(BXT_DSI_PLL_ENABLE, val);
  193. /*
  194. * PLL lock should deassert within 200us.
  195. * Wait up to 1ms before timing out.
  196. */
  197. if (intel_wait_for_register(dev_priv,
  198. BXT_DSI_PLL_ENABLE,
  199. BXT_DSI_PLL_LOCKED,
  200. 0,
  201. 1))
  202. DRM_ERROR("Timeout waiting for PLL lock deassertion\n");
  203. }
  204. static void assert_bpp_mismatch(enum mipi_dsi_pixel_format fmt, int pipe_bpp)
  205. {
  206. int bpp = mipi_dsi_pixel_format_to_bpp(fmt);
  207. WARN(bpp != pipe_bpp,
  208. "bpp match assertion failure (expected %d, current %d)\n",
  209. bpp, pipe_bpp);
  210. }
  211. static u32 vlv_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp,
  212. struct intel_crtc_state *config)
  213. {
  214. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  215. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  216. u32 dsi_clock, pclk;
  217. u32 pll_ctl, pll_div;
  218. u32 m = 0, p = 0, n;
  219. int refclk = IS_CHERRYVIEW(dev_priv) ? 100000 : 25000;
  220. int i;
  221. DRM_DEBUG_KMS("\n");
  222. mutex_lock(&dev_priv->sb_lock);
  223. pll_ctl = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  224. pll_div = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_DIVIDER);
  225. mutex_unlock(&dev_priv->sb_lock);
  226. config->dsi_pll.ctrl = pll_ctl & ~DSI_PLL_LOCK;
  227. config->dsi_pll.div = pll_div;
  228. /* mask out other bits and extract the P1 divisor */
  229. pll_ctl &= DSI_PLL_P1_POST_DIV_MASK;
  230. pll_ctl = pll_ctl >> (DSI_PLL_P1_POST_DIV_SHIFT - 2);
  231. /* N1 divisor */
  232. n = (pll_div & DSI_PLL_N1_DIV_MASK) >> DSI_PLL_N1_DIV_SHIFT;
  233. n = 1 << n; /* register has log2(N1) */
  234. /* mask out the other bits and extract the M1 divisor */
  235. pll_div &= DSI_PLL_M1_DIV_MASK;
  236. pll_div = pll_div >> DSI_PLL_M1_DIV_SHIFT;
  237. while (pll_ctl) {
  238. pll_ctl = pll_ctl >> 1;
  239. p++;
  240. }
  241. p--;
  242. if (!p) {
  243. DRM_ERROR("wrong P1 divisor\n");
  244. return 0;
  245. }
  246. for (i = 0; i < ARRAY_SIZE(lfsr_converts); i++) {
  247. if (lfsr_converts[i] == pll_div)
  248. break;
  249. }
  250. if (i == ARRAY_SIZE(lfsr_converts)) {
  251. DRM_ERROR("wrong m_seed programmed\n");
  252. return 0;
  253. }
  254. m = i + 62;
  255. dsi_clock = (m * refclk) / (p * n);
  256. /* pixel_format and pipe_bpp should agree */
  257. assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp);
  258. pclk = DIV_ROUND_CLOSEST(dsi_clock * intel_dsi->lane_count, pipe_bpp);
  259. return pclk;
  260. }
  261. static u32 bxt_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp,
  262. struct intel_crtc_state *config)
  263. {
  264. u32 pclk;
  265. u32 dsi_clk;
  266. u32 dsi_ratio;
  267. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  268. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  269. /* Divide by zero */
  270. if (!pipe_bpp) {
  271. DRM_ERROR("Invalid BPP(0)\n");
  272. return 0;
  273. }
  274. config->dsi_pll.ctrl = I915_READ(BXT_DSI_PLL_CTL);
  275. dsi_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
  276. dsi_clk = (dsi_ratio * BXT_REF_CLOCK_KHZ) / 2;
  277. /* pixel_format and pipe_bpp should agree */
  278. assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp);
  279. pclk = DIV_ROUND_CLOSEST(dsi_clk * intel_dsi->lane_count, pipe_bpp);
  280. DRM_DEBUG_DRIVER("Calculated pclk=%u\n", pclk);
  281. return pclk;
  282. }
  283. u32 intel_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp,
  284. struct intel_crtc_state *config)
  285. {
  286. if (IS_GEN9_LP(to_i915(encoder->base.dev)))
  287. return bxt_dsi_get_pclk(encoder, pipe_bpp, config);
  288. else
  289. return vlv_dsi_get_pclk(encoder, pipe_bpp, config);
  290. }
  291. static void vlv_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
  292. {
  293. u32 temp;
  294. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  295. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  296. temp = I915_READ(MIPI_CTRL(port));
  297. temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  298. I915_WRITE(MIPI_CTRL(port), temp |
  299. intel_dsi->escape_clk_div <<
  300. ESCAPE_CLOCK_DIVIDER_SHIFT);
  301. }
  302. /* Program BXT Mipi clocks and dividers */
  303. static void bxt_dsi_program_clocks(struct drm_device *dev, enum port port,
  304. const struct intel_crtc_state *config)
  305. {
  306. struct drm_i915_private *dev_priv = to_i915(dev);
  307. u32 tmp;
  308. u32 dsi_rate = 0;
  309. u32 pll_ratio = 0;
  310. u32 rx_div;
  311. u32 tx_div;
  312. u32 rx_div_upper;
  313. u32 rx_div_lower;
  314. u32 mipi_8by3_divider;
  315. /* Clear old configurations */
  316. tmp = I915_READ(BXT_MIPI_CLOCK_CTL);
  317. tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port));
  318. tmp &= ~(BXT_MIPI_RX_ESCLK_UPPER_FIXDIV_MASK(port));
  319. tmp &= ~(BXT_MIPI_8X_BY3_DIVIDER_MASK(port));
  320. tmp &= ~(BXT_MIPI_RX_ESCLK_LOWER_FIXDIV_MASK(port));
  321. /* Get the current DSI rate(actual) */
  322. pll_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
  323. dsi_rate = (BXT_REF_CLOCK_KHZ * pll_ratio) / 2;
  324. /*
  325. * tx clock should be <= 20MHz and the div value must be
  326. * subtracted by 1 as per bspec
  327. */
  328. tx_div = DIV_ROUND_UP(dsi_rate, 20000) - 1;
  329. /*
  330. * rx clock should be <= 150MHz and the div value must be
  331. * subtracted by 1 as per bspec
  332. */
  333. rx_div = DIV_ROUND_UP(dsi_rate, 150000) - 1;
  334. /*
  335. * rx divider value needs to be updated in the
  336. * two differnt bit fields in the register hence splitting the
  337. * rx divider value accordingly
  338. */
  339. rx_div_lower = rx_div & RX_DIVIDER_BIT_1_2;
  340. rx_div_upper = (rx_div & RX_DIVIDER_BIT_3_4) >> 2;
  341. /* As per bpsec program the 8/3X clock divider to the below value */
  342. if (dev_priv->vbt.dsi.config->is_cmd_mode)
  343. mipi_8by3_divider = 0x2;
  344. else
  345. mipi_8by3_divider = 0x3;
  346. tmp |= BXT_MIPI_8X_BY3_DIVIDER(port, mipi_8by3_divider);
  347. tmp |= BXT_MIPI_TX_ESCLK_DIVIDER(port, tx_div);
  348. tmp |= BXT_MIPI_RX_ESCLK_LOWER_DIVIDER(port, rx_div_lower);
  349. tmp |= BXT_MIPI_RX_ESCLK_UPPER_DIVIDER(port, rx_div_upper);
  350. I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp);
  351. }
  352. static int bxt_compute_dsi_pll(struct intel_encoder *encoder,
  353. struct intel_crtc_state *config)
  354. {
  355. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  356. u8 dsi_ratio;
  357. u32 dsi_clk;
  358. dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format,
  359. intel_dsi->lane_count);
  360. /*
  361. * From clock diagram, to get PLL ratio divider, divide double of DSI
  362. * link rate (i.e., 2*8x=16x frequency value) by ref clock. Make sure to
  363. * round 'up' the result
  364. */
  365. dsi_ratio = DIV_ROUND_UP(dsi_clk * 2, BXT_REF_CLOCK_KHZ);
  366. if (dsi_ratio < BXT_DSI_PLL_RATIO_MIN ||
  367. dsi_ratio > BXT_DSI_PLL_RATIO_MAX) {
  368. DRM_ERROR("Cant get a suitable ratio from DSI PLL ratios\n");
  369. return -ECHRNG;
  370. }
  371. /*
  372. * Program DSI ratio and Select MIPIC and MIPIA PLL output as 8x
  373. * Spec says both have to be programmed, even if one is not getting
  374. * used. Configure MIPI_CLOCK_CTL dividers in modeset
  375. */
  376. config->dsi_pll.ctrl = dsi_ratio | BXT_DSIA_16X_BY2 | BXT_DSIC_16X_BY2;
  377. /* As per recommendation from hardware team,
  378. * Prog PVD ratio =1 if dsi ratio <= 50
  379. */
  380. if (dsi_ratio <= 50)
  381. config->dsi_pll.ctrl |= BXT_DSI_PLL_PVD_RATIO_1;
  382. return 0;
  383. }
  384. static void bxt_enable_dsi_pll(struct intel_encoder *encoder,
  385. const struct intel_crtc_state *config)
  386. {
  387. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  388. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  389. enum port port;
  390. u32 val;
  391. DRM_DEBUG_KMS("\n");
  392. /* Configure PLL vales */
  393. I915_WRITE(BXT_DSI_PLL_CTL, config->dsi_pll.ctrl);
  394. POSTING_READ(BXT_DSI_PLL_CTL);
  395. /* Program TX, RX, Dphy clocks */
  396. for_each_dsi_port(port, intel_dsi->ports)
  397. bxt_dsi_program_clocks(encoder->base.dev, port, config);
  398. /* Enable DSI PLL */
  399. val = I915_READ(BXT_DSI_PLL_ENABLE);
  400. val |= BXT_DSI_PLL_DO_ENABLE;
  401. I915_WRITE(BXT_DSI_PLL_ENABLE, val);
  402. /* Timeout and fail if PLL not locked */
  403. if (intel_wait_for_register(dev_priv,
  404. BXT_DSI_PLL_ENABLE,
  405. BXT_DSI_PLL_LOCKED,
  406. BXT_DSI_PLL_LOCKED,
  407. 1)) {
  408. DRM_ERROR("Timed out waiting for DSI PLL to lock\n");
  409. return;
  410. }
  411. DRM_DEBUG_KMS("DSI PLL locked\n");
  412. }
  413. bool intel_dsi_pll_is_enabled(struct drm_i915_private *dev_priv)
  414. {
  415. if (IS_GEN9_LP(dev_priv))
  416. return bxt_dsi_pll_is_enabled(dev_priv);
  417. MISSING_CASE(INTEL_DEVID(dev_priv));
  418. return false;
  419. }
  420. int intel_compute_dsi_pll(struct intel_encoder *encoder,
  421. struct intel_crtc_state *config)
  422. {
  423. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  424. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  425. return vlv_compute_dsi_pll(encoder, config);
  426. else if (IS_GEN9_LP(dev_priv))
  427. return bxt_compute_dsi_pll(encoder, config);
  428. return -ENODEV;
  429. }
  430. void intel_enable_dsi_pll(struct intel_encoder *encoder,
  431. const struct intel_crtc_state *config)
  432. {
  433. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  434. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  435. vlv_enable_dsi_pll(encoder, config);
  436. else if (IS_GEN9_LP(dev_priv))
  437. bxt_enable_dsi_pll(encoder, config);
  438. }
  439. void intel_disable_dsi_pll(struct intel_encoder *encoder)
  440. {
  441. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  442. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  443. vlv_disable_dsi_pll(encoder);
  444. else if (IS_GEN9_LP(dev_priv))
  445. bxt_disable_dsi_pll(encoder);
  446. }
  447. static void bxt_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
  448. {
  449. u32 tmp;
  450. struct drm_device *dev = encoder->base.dev;
  451. struct drm_i915_private *dev_priv = to_i915(dev);
  452. /* Clear old configurations */
  453. tmp = I915_READ(BXT_MIPI_CLOCK_CTL);
  454. tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port));
  455. tmp &= ~(BXT_MIPI_RX_ESCLK_UPPER_FIXDIV_MASK(port));
  456. tmp &= ~(BXT_MIPI_8X_BY3_DIVIDER_MASK(port));
  457. tmp &= ~(BXT_MIPI_RX_ESCLK_LOWER_FIXDIV_MASK(port));
  458. I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp);
  459. I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
  460. }
  461. void intel_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
  462. {
  463. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  464. if (IS_GEN9_LP(dev_priv))
  465. bxt_dsi_reset_clocks(encoder, port);
  466. else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  467. vlv_dsi_reset_clocks(encoder, port);
  468. }