intel_dsi_pll.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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. #define DSI_HSS_PACKET_SIZE 4
  32. #define DSI_HSE_PACKET_SIZE 4
  33. #define DSI_HSA_PACKET_EXTRA_SIZE 6
  34. #define DSI_HBP_PACKET_EXTRA_SIZE 6
  35. #define DSI_HACTIVE_PACKET_EXTRA_SIZE 6
  36. #define DSI_HFP_PACKET_EXTRA_SIZE 6
  37. #define DSI_EOTP_PACKET_SIZE 4
  38. static int dsi_pixel_format_bpp(int pixel_format)
  39. {
  40. int bpp;
  41. switch (pixel_format) {
  42. default:
  43. case VID_MODE_FORMAT_RGB888:
  44. case VID_MODE_FORMAT_RGB666_LOOSE:
  45. bpp = 24;
  46. break;
  47. case VID_MODE_FORMAT_RGB666:
  48. bpp = 18;
  49. break;
  50. case VID_MODE_FORMAT_RGB565:
  51. bpp = 16;
  52. break;
  53. }
  54. return bpp;
  55. }
  56. struct dsi_mnp {
  57. u32 dsi_pll_ctrl;
  58. u32 dsi_pll_div;
  59. };
  60. static const u32 lfsr_converts[] = {
  61. 426, 469, 234, 373, 442, 221, 110, 311, 411, /* 62 - 70 */
  62. 461, 486, 243, 377, 188, 350, 175, 343, 427, 213, /* 71 - 80 */
  63. 106, 53, 282, 397, 454, 227, 113, 56, 284, 142, /* 81 - 90 */
  64. 71, 35, 273, 136, 324, 418, 465, 488, 500, 506 /* 91 - 100 */
  65. };
  66. #ifdef DSI_CLK_FROM_RR
  67. static u32 dsi_rr_formula(const struct drm_display_mode *mode,
  68. int pixel_format, int video_mode_format,
  69. int lane_count, bool eotp)
  70. {
  71. u32 bpp;
  72. u32 hactive, vactive, hfp, hsync, hbp, vfp, vsync, vbp;
  73. u32 hsync_bytes, hbp_bytes, hactive_bytes, hfp_bytes;
  74. u32 bytes_per_line, bytes_per_frame;
  75. u32 num_frames;
  76. u32 bytes_per_x_frames, bytes_per_x_frames_x_lanes;
  77. u32 dsi_bit_clock_hz;
  78. u32 dsi_clk;
  79. bpp = dsi_pixel_format_bpp(pixel_format);
  80. hactive = mode->hdisplay;
  81. vactive = mode->vdisplay;
  82. hfp = mode->hsync_start - mode->hdisplay;
  83. hsync = mode->hsync_end - mode->hsync_start;
  84. hbp = mode->htotal - mode->hsync_end;
  85. vfp = mode->vsync_start - mode->vdisplay;
  86. vsync = mode->vsync_end - mode->vsync_start;
  87. vbp = mode->vtotal - mode->vsync_end;
  88. hsync_bytes = DIV_ROUND_UP(hsync * bpp, 8);
  89. hbp_bytes = DIV_ROUND_UP(hbp * bpp, 8);
  90. hactive_bytes = DIV_ROUND_UP(hactive * bpp, 8);
  91. hfp_bytes = DIV_ROUND_UP(hfp * bpp, 8);
  92. bytes_per_line = DSI_HSS_PACKET_SIZE + hsync_bytes +
  93. DSI_HSA_PACKET_EXTRA_SIZE + DSI_HSE_PACKET_SIZE +
  94. hbp_bytes + DSI_HBP_PACKET_EXTRA_SIZE +
  95. hactive_bytes + DSI_HACTIVE_PACKET_EXTRA_SIZE +
  96. hfp_bytes + DSI_HFP_PACKET_EXTRA_SIZE;
  97. /*
  98. * XXX: Need to accurately calculate LP to HS transition timeout and add
  99. * it to bytes_per_line/bytes_per_frame.
  100. */
  101. if (eotp && video_mode_format == VIDEO_MODE_BURST)
  102. bytes_per_line += DSI_EOTP_PACKET_SIZE;
  103. bytes_per_frame = vsync * bytes_per_line + vbp * bytes_per_line +
  104. vactive * bytes_per_line + vfp * bytes_per_line;
  105. if (eotp &&
  106. (video_mode_format == VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE ||
  107. video_mode_format == VIDEO_MODE_NON_BURST_WITH_SYNC_EVENTS))
  108. bytes_per_frame += DSI_EOTP_PACKET_SIZE;
  109. num_frames = drm_mode_vrefresh(mode);
  110. bytes_per_x_frames = num_frames * bytes_per_frame;
  111. bytes_per_x_frames_x_lanes = bytes_per_x_frames / lane_count;
  112. /* the dsi clock is divided by 2 in the hardware to get dsi ddr clock */
  113. dsi_bit_clock_hz = bytes_per_x_frames_x_lanes * 8;
  114. dsi_clk = dsi_bit_clock_hz / 1000;
  115. if (eotp && video_mode_format == VIDEO_MODE_BURST)
  116. dsi_clk *= 2;
  117. return dsi_clk;
  118. }
  119. #else
  120. /* Get DSI clock from pixel clock */
  121. static u32 dsi_clk_from_pclk(u32 pclk, int pixel_format, int lane_count)
  122. {
  123. u32 dsi_clk_khz;
  124. u32 bpp = dsi_pixel_format_bpp(pixel_format);
  125. /* DSI data rate = pixel clock * bits per pixel / lane count
  126. pixel clock is converted from KHz to Hz */
  127. dsi_clk_khz = DIV_ROUND_CLOSEST(pclk * bpp, lane_count);
  128. return dsi_clk_khz;
  129. }
  130. #endif
  131. static int dsi_calc_mnp(struct drm_i915_private *dev_priv,
  132. struct dsi_mnp *dsi_mnp, int target_dsi_clk)
  133. {
  134. unsigned int calc_m = 0, calc_p = 0;
  135. unsigned int m_min, m_max, p_min = 2, p_max = 6;
  136. unsigned int m, n, p;
  137. int ref_clk;
  138. int delta = target_dsi_clk;
  139. u32 m_seed;
  140. /* target_dsi_clk is expected in kHz */
  141. if (target_dsi_clk < 300000 || target_dsi_clk > 1150000) {
  142. DRM_ERROR("DSI CLK Out of Range\n");
  143. return -ECHRNG;
  144. }
  145. if (IS_CHERRYVIEW(dev_priv)) {
  146. ref_clk = 100000;
  147. n = 4;
  148. m_min = 70;
  149. m_max = 96;
  150. } else {
  151. ref_clk = 25000;
  152. n = 1;
  153. m_min = 62;
  154. m_max = 92;
  155. }
  156. for (m = m_min; m <= m_max && delta; m++) {
  157. for (p = p_min; p <= p_max && delta; p++) {
  158. /*
  159. * Find the optimal m and p divisors with minimal delta
  160. * +/- the required clock
  161. */
  162. int calc_dsi_clk = (m * ref_clk) / (p * n);
  163. int d = abs(target_dsi_clk - calc_dsi_clk);
  164. if (d < delta) {
  165. delta = d;
  166. calc_m = m;
  167. calc_p = p;
  168. }
  169. }
  170. }
  171. /* register has log2(N1), this works fine for powers of two */
  172. n = ffs(n) - 1;
  173. m_seed = lfsr_converts[calc_m - 62];
  174. dsi_mnp->dsi_pll_ctrl = 1 << (DSI_PLL_P1_POST_DIV_SHIFT + calc_p - 2);
  175. dsi_mnp->dsi_pll_div = n << DSI_PLL_N1_DIV_SHIFT |
  176. m_seed << DSI_PLL_M1_DIV_SHIFT;
  177. return 0;
  178. }
  179. /*
  180. * XXX: The muxing and gating is hard coded for now. Need to add support for
  181. * sharing PLLs with two DSI outputs.
  182. */
  183. static void vlv_configure_dsi_pll(struct intel_encoder *encoder)
  184. {
  185. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  186. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  187. int ret;
  188. struct dsi_mnp dsi_mnp;
  189. u32 dsi_clk;
  190. dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format,
  191. intel_dsi->lane_count);
  192. ret = dsi_calc_mnp(dev_priv, &dsi_mnp, dsi_clk);
  193. if (ret) {
  194. DRM_DEBUG_KMS("dsi_calc_mnp failed\n");
  195. return;
  196. }
  197. if (intel_dsi->ports & (1 << PORT_A))
  198. dsi_mnp.dsi_pll_ctrl |= DSI_PLL_CLK_GATE_DSI0_DSIPLL;
  199. if (intel_dsi->ports & (1 << PORT_C))
  200. dsi_mnp.dsi_pll_ctrl |= DSI_PLL_CLK_GATE_DSI1_DSIPLL;
  201. DRM_DEBUG_KMS("dsi pll div %08x, ctrl %08x\n",
  202. dsi_mnp.dsi_pll_div, dsi_mnp.dsi_pll_ctrl);
  203. vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, 0);
  204. vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_DIVIDER, dsi_mnp.dsi_pll_div);
  205. vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, dsi_mnp.dsi_pll_ctrl);
  206. }
  207. static void vlv_enable_dsi_pll(struct intel_encoder *encoder)
  208. {
  209. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  210. u32 tmp;
  211. DRM_DEBUG_KMS("\n");
  212. mutex_lock(&dev_priv->sb_lock);
  213. vlv_configure_dsi_pll(encoder);
  214. /* wait at least 0.5 us after ungating before enabling VCO */
  215. usleep_range(1, 10);
  216. tmp = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  217. tmp |= DSI_PLL_VCO_EN;
  218. vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, tmp);
  219. if (wait_for(vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL) &
  220. DSI_PLL_LOCK, 20)) {
  221. mutex_unlock(&dev_priv->sb_lock);
  222. DRM_ERROR("DSI PLL lock failed\n");
  223. return;
  224. }
  225. mutex_unlock(&dev_priv->sb_lock);
  226. DRM_DEBUG_KMS("DSI PLL locked\n");
  227. }
  228. static void vlv_disable_dsi_pll(struct intel_encoder *encoder)
  229. {
  230. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  231. u32 tmp;
  232. DRM_DEBUG_KMS("\n");
  233. mutex_lock(&dev_priv->sb_lock);
  234. tmp = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  235. tmp &= ~DSI_PLL_VCO_EN;
  236. tmp |= DSI_PLL_LDO_GATE;
  237. vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, tmp);
  238. mutex_unlock(&dev_priv->sb_lock);
  239. }
  240. static void bxt_disable_dsi_pll(struct intel_encoder *encoder)
  241. {
  242. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  243. u32 val;
  244. DRM_DEBUG_KMS("\n");
  245. val = I915_READ(BXT_DSI_PLL_ENABLE);
  246. val &= ~BXT_DSI_PLL_DO_ENABLE;
  247. I915_WRITE(BXT_DSI_PLL_ENABLE, val);
  248. /*
  249. * PLL lock should deassert within 200us.
  250. * Wait up to 1ms before timing out.
  251. */
  252. if (wait_for((I915_READ(BXT_DSI_PLL_ENABLE)
  253. & BXT_DSI_PLL_LOCKED) == 0, 1))
  254. DRM_ERROR("Timeout waiting for PLL lock deassertion\n");
  255. }
  256. static void assert_bpp_mismatch(int pixel_format, int pipe_bpp)
  257. {
  258. int bpp = dsi_pixel_format_bpp(pixel_format);
  259. WARN(bpp != pipe_bpp,
  260. "bpp match assertion failure (expected %d, current %d)\n",
  261. bpp, pipe_bpp);
  262. }
  263. u32 vlv_get_dsi_pclk(struct intel_encoder *encoder, int pipe_bpp)
  264. {
  265. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  266. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  267. u32 dsi_clock, pclk;
  268. u32 pll_ctl, pll_div;
  269. u32 m = 0, p = 0, n;
  270. int refclk = 25000;
  271. int i;
  272. DRM_DEBUG_KMS("\n");
  273. mutex_lock(&dev_priv->sb_lock);
  274. pll_ctl = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  275. pll_div = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_DIVIDER);
  276. mutex_unlock(&dev_priv->sb_lock);
  277. /* mask out other bits and extract the P1 divisor */
  278. pll_ctl &= DSI_PLL_P1_POST_DIV_MASK;
  279. pll_ctl = pll_ctl >> (DSI_PLL_P1_POST_DIV_SHIFT - 2);
  280. /* N1 divisor */
  281. n = (pll_div & DSI_PLL_N1_DIV_MASK) >> DSI_PLL_N1_DIV_SHIFT;
  282. n = 1 << n; /* register has log2(N1) */
  283. /* mask out the other bits and extract the M1 divisor */
  284. pll_div &= DSI_PLL_M1_DIV_MASK;
  285. pll_div = pll_div >> DSI_PLL_M1_DIV_SHIFT;
  286. while (pll_ctl) {
  287. pll_ctl = pll_ctl >> 1;
  288. p++;
  289. }
  290. p--;
  291. if (!p) {
  292. DRM_ERROR("wrong P1 divisor\n");
  293. return 0;
  294. }
  295. for (i = 0; i < ARRAY_SIZE(lfsr_converts); i++) {
  296. if (lfsr_converts[i] == pll_div)
  297. break;
  298. }
  299. if (i == ARRAY_SIZE(lfsr_converts)) {
  300. DRM_ERROR("wrong m_seed programmed\n");
  301. return 0;
  302. }
  303. m = i + 62;
  304. dsi_clock = (m * refclk) / (p * n);
  305. /* pixel_format and pipe_bpp should agree */
  306. assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp);
  307. pclk = DIV_ROUND_CLOSEST(dsi_clock * intel_dsi->lane_count, pipe_bpp);
  308. return pclk;
  309. }
  310. u32 bxt_get_dsi_pclk(struct intel_encoder *encoder, int pipe_bpp)
  311. {
  312. u32 pclk;
  313. u32 dsi_clk;
  314. u32 dsi_ratio;
  315. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  316. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  317. /* Divide by zero */
  318. if (!pipe_bpp) {
  319. DRM_ERROR("Invalid BPP(0)\n");
  320. return 0;
  321. }
  322. dsi_ratio = I915_READ(BXT_DSI_PLL_CTL) &
  323. BXT_DSI_PLL_RATIO_MASK;
  324. /* Invalid DSI ratio ? */
  325. if (dsi_ratio < BXT_DSI_PLL_RATIO_MIN ||
  326. dsi_ratio > BXT_DSI_PLL_RATIO_MAX) {
  327. DRM_ERROR("Invalid DSI pll ratio(%u) programmed\n", dsi_ratio);
  328. return 0;
  329. }
  330. dsi_clk = (dsi_ratio * BXT_REF_CLOCK_KHZ) / 2;
  331. /* pixel_format and pipe_bpp should agree */
  332. assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp);
  333. pclk = DIV_ROUND_CLOSEST(dsi_clk * intel_dsi->lane_count, pipe_bpp);
  334. DRM_DEBUG_DRIVER("Calculated pclk=%u\n", pclk);
  335. return pclk;
  336. }
  337. static void vlv_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
  338. {
  339. u32 temp;
  340. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  341. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  342. temp = I915_READ(MIPI_CTRL(port));
  343. temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
  344. I915_WRITE(MIPI_CTRL(port), temp |
  345. intel_dsi->escape_clk_div <<
  346. ESCAPE_CLOCK_DIVIDER_SHIFT);
  347. }
  348. /* Program BXT Mipi clocks and dividers */
  349. static void bxt_dsi_program_clocks(struct drm_device *dev, enum port port)
  350. {
  351. u32 tmp;
  352. u32 divider;
  353. u32 dsi_rate;
  354. u32 pll_ratio;
  355. struct drm_i915_private *dev_priv = dev->dev_private;
  356. /* Clear old configurations */
  357. tmp = I915_READ(BXT_MIPI_CLOCK_CTL);
  358. tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port));
  359. tmp &= ~(BXT_MIPI_RX_ESCLK_FIXDIV_MASK(port));
  360. tmp &= ~(BXT_MIPI_ESCLK_VAR_DIV_MASK(port));
  361. tmp &= ~(BXT_MIPI_DPHY_DIVIDER_MASK(port));
  362. /* Get the current DSI rate(actual) */
  363. pll_ratio = I915_READ(BXT_DSI_PLL_CTL) &
  364. BXT_DSI_PLL_RATIO_MASK;
  365. dsi_rate = (BXT_REF_CLOCK_KHZ * pll_ratio) / 2;
  366. /* Max possible output of clock is 39.5 MHz, program value -1 */
  367. divider = (dsi_rate / BXT_MAX_VAR_OUTPUT_KHZ) - 1;
  368. tmp |= BXT_MIPI_ESCLK_VAR_DIV(port, divider);
  369. /*
  370. * Tx escape clock must be as close to 20MHz possible, but should
  371. * not exceed it. Hence select divide by 2
  372. */
  373. tmp |= BXT_MIPI_TX_ESCLK_8XDIV_BY2(port);
  374. tmp |= BXT_MIPI_RX_ESCLK_8X_BY3(port);
  375. I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp);
  376. }
  377. static bool bxt_configure_dsi_pll(struct intel_encoder *encoder)
  378. {
  379. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  380. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  381. u8 dsi_ratio;
  382. u32 dsi_clk;
  383. u32 val;
  384. dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format,
  385. intel_dsi->lane_count);
  386. /*
  387. * From clock diagram, to get PLL ratio divider, divide double of DSI
  388. * link rate (i.e., 2*8x=16x frequency value) by ref clock. Make sure to
  389. * round 'up' the result
  390. */
  391. dsi_ratio = DIV_ROUND_UP(dsi_clk * 2, BXT_REF_CLOCK_KHZ);
  392. if (dsi_ratio < BXT_DSI_PLL_RATIO_MIN ||
  393. dsi_ratio > BXT_DSI_PLL_RATIO_MAX) {
  394. DRM_ERROR("Cant get a suitable ratio from DSI PLL ratios\n");
  395. return false;
  396. }
  397. /*
  398. * Program DSI ratio and Select MIPIC and MIPIA PLL output as 8x
  399. * Spec says both have to be programmed, even if one is not getting
  400. * used. Configure MIPI_CLOCK_CTL dividers in modeset
  401. */
  402. val = I915_READ(BXT_DSI_PLL_CTL);
  403. val &= ~BXT_DSI_PLL_PVD_RATIO_MASK;
  404. val &= ~BXT_DSI_FREQ_SEL_MASK;
  405. val &= ~BXT_DSI_PLL_RATIO_MASK;
  406. val |= (dsi_ratio | BXT_DSIA_16X_BY2 | BXT_DSIC_16X_BY2);
  407. /* As per recommendation from hardware team,
  408. * Prog PVD ratio =1 if dsi ratio <= 50
  409. */
  410. if (dsi_ratio <= 50) {
  411. val &= ~BXT_DSI_PLL_PVD_RATIO_MASK;
  412. val |= BXT_DSI_PLL_PVD_RATIO_1;
  413. }
  414. I915_WRITE(BXT_DSI_PLL_CTL, val);
  415. POSTING_READ(BXT_DSI_PLL_CTL);
  416. return true;
  417. }
  418. static void bxt_enable_dsi_pll(struct intel_encoder *encoder)
  419. {
  420. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  421. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  422. enum port port;
  423. u32 val;
  424. DRM_DEBUG_KMS("\n");
  425. val = I915_READ(BXT_DSI_PLL_ENABLE);
  426. if (val & BXT_DSI_PLL_DO_ENABLE) {
  427. WARN(1, "DSI PLL already enabled. Disabling it.\n");
  428. val &= ~BXT_DSI_PLL_DO_ENABLE;
  429. I915_WRITE(BXT_DSI_PLL_ENABLE, val);
  430. }
  431. /* Configure PLL vales */
  432. if (!bxt_configure_dsi_pll(encoder)) {
  433. DRM_ERROR("Configure DSI PLL failed, abort PLL enable\n");
  434. return;
  435. }
  436. /* Program TX, RX, Dphy clocks */
  437. for_each_dsi_port(port, intel_dsi->ports)
  438. bxt_dsi_program_clocks(encoder->base.dev, port);
  439. /* Enable DSI PLL */
  440. val = I915_READ(BXT_DSI_PLL_ENABLE);
  441. val |= BXT_DSI_PLL_DO_ENABLE;
  442. I915_WRITE(BXT_DSI_PLL_ENABLE, val);
  443. /* Timeout and fail if PLL not locked */
  444. if (wait_for(I915_READ(BXT_DSI_PLL_ENABLE) & BXT_DSI_PLL_LOCKED, 1)) {
  445. DRM_ERROR("Timed out waiting for DSI PLL to lock\n");
  446. return;
  447. }
  448. DRM_DEBUG_KMS("DSI PLL locked\n");
  449. }
  450. void intel_enable_dsi_pll(struct intel_encoder *encoder)
  451. {
  452. struct drm_device *dev = encoder->base.dev;
  453. if (IS_VALLEYVIEW(dev))
  454. vlv_enable_dsi_pll(encoder);
  455. else if (IS_BROXTON(dev))
  456. bxt_enable_dsi_pll(encoder);
  457. }
  458. void intel_disable_dsi_pll(struct intel_encoder *encoder)
  459. {
  460. struct drm_device *dev = encoder->base.dev;
  461. if (IS_VALLEYVIEW(dev))
  462. vlv_disable_dsi_pll(encoder);
  463. else if (IS_BROXTON(dev))
  464. bxt_disable_dsi_pll(encoder);
  465. }
  466. static void bxt_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
  467. {
  468. u32 tmp;
  469. struct drm_device *dev = encoder->base.dev;
  470. struct drm_i915_private *dev_priv = dev->dev_private;
  471. /* Clear old configurations */
  472. tmp = I915_READ(BXT_MIPI_CLOCK_CTL);
  473. tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port));
  474. tmp &= ~(BXT_MIPI_RX_ESCLK_FIXDIV_MASK(port));
  475. tmp &= ~(BXT_MIPI_ESCLK_VAR_DIV_MASK(port));
  476. tmp &= ~(BXT_MIPI_DPHY_DIVIDER_MASK(port));
  477. I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp);
  478. I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
  479. }
  480. void intel_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
  481. {
  482. struct drm_device *dev = encoder->base.dev;
  483. if (IS_BROXTON(dev))
  484. bxt_dsi_reset_clocks(encoder, port);
  485. else if (IS_VALLEYVIEW(dev))
  486. vlv_dsi_reset_clocks(encoder, port);
  487. }