19edbd4a0SFrançois Tigeot /*
29edbd4a0SFrançois Tigeot * Copyright © 2013 Intel Corporation
39edbd4a0SFrançois Tigeot *
49edbd4a0SFrançois Tigeot * Permission is hereby granted, free of charge, to any person obtaining a
59edbd4a0SFrançois Tigeot * copy of this software and associated documentation files (the "Software"),
69edbd4a0SFrançois Tigeot * to deal in the Software without restriction, including without limitation
79edbd4a0SFrançois Tigeot * the rights to use, copy, modify, merge, publish, distribute, sublicense,
89edbd4a0SFrançois Tigeot * and/or sell copies of the Software, and to permit persons to whom the
99edbd4a0SFrançois Tigeot * Software is furnished to do so, subject to the following conditions:
109edbd4a0SFrançois Tigeot *
119edbd4a0SFrançois Tigeot * The above copyright notice and this permission notice (including the next
129edbd4a0SFrançois Tigeot * paragraph) shall be included in all copies or substantial portions of the
139edbd4a0SFrançois Tigeot * Software.
149edbd4a0SFrançois Tigeot *
159edbd4a0SFrançois Tigeot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
169edbd4a0SFrançois Tigeot * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
179edbd4a0SFrançois Tigeot * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
189edbd4a0SFrançois Tigeot * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
199edbd4a0SFrançois Tigeot * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
209edbd4a0SFrançois Tigeot * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
219edbd4a0SFrançois Tigeot * DEALINGS IN THE SOFTWARE.
229edbd4a0SFrançois Tigeot *
239edbd4a0SFrançois Tigeot * Authors:
249edbd4a0SFrançois Tigeot * Shobhit Kumar <shobhit.kumar@intel.com>
259edbd4a0SFrançois Tigeot * Yogesh Mohan Marimuthu <yogesh.mohan.marimuthu@intel.com>
269edbd4a0SFrançois Tigeot */
279edbd4a0SFrançois Tigeot
289edbd4a0SFrançois Tigeot #include <linux/kernel.h>
299edbd4a0SFrançois Tigeot #include "intel_drv.h"
309edbd4a0SFrançois Tigeot #include "i915_drv.h"
319edbd4a0SFrançois Tigeot #include "intel_dsi.h"
329edbd4a0SFrançois Tigeot
338621f407SFrançois Tigeot static const u16 lfsr_converts[] = {
349edbd4a0SFrançois Tigeot 426, 469, 234, 373, 442, 221, 110, 311, 411, /* 62 - 70 */
359edbd4a0SFrançois Tigeot 461, 486, 243, 377, 188, 350, 175, 343, 427, 213, /* 71 - 80 */
36a05eeebfSFrançois Tigeot 106, 53, 282, 397, 454, 227, 113, 56, 284, 142, /* 81 - 90 */
37a05eeebfSFrançois Tigeot 71, 35, 273, 136, 324, 418, 465, 488, 500, 506 /* 91 - 100 */
389edbd4a0SFrançois Tigeot };
399edbd4a0SFrançois Tigeot
409edbd4a0SFrançois Tigeot /* Get DSI clock from pixel clock */
dsi_clk_from_pclk(u32 pclk,enum mipi_dsi_pixel_format fmt,int lane_count)418621f407SFrançois Tigeot static u32 dsi_clk_from_pclk(u32 pclk, enum mipi_dsi_pixel_format fmt,
428621f407SFrançois Tigeot int lane_count)
439edbd4a0SFrançois Tigeot {
449edbd4a0SFrançois Tigeot u32 dsi_clk_khz;
458621f407SFrançois Tigeot u32 bpp = mipi_dsi_pixel_format_to_bpp(fmt);
469edbd4a0SFrançois Tigeot
479edbd4a0SFrançois Tigeot /* DSI data rate = pixel clock * bits per pixel / lane count
489edbd4a0SFrançois Tigeot pixel clock is converted from KHz to Hz */
491b13d190SFrançois Tigeot dsi_clk_khz = DIV_ROUND_CLOSEST(pclk * bpp, lane_count);
509edbd4a0SFrançois Tigeot
519edbd4a0SFrançois Tigeot return dsi_clk_khz;
529edbd4a0SFrançois Tigeot }
539edbd4a0SFrançois Tigeot
dsi_calc_mnp(struct drm_i915_private * dev_priv,struct intel_crtc_state * config,int target_dsi_clk)54a05eeebfSFrançois Tigeot static int dsi_calc_mnp(struct drm_i915_private *dev_priv,
558621f407SFrançois Tigeot struct intel_crtc_state *config,
568621f407SFrançois Tigeot int target_dsi_clk)
579edbd4a0SFrançois Tigeot {
58a05eeebfSFrançois Tigeot unsigned int m_min, m_max, p_min = 2, p_max = 6;
59a05eeebfSFrançois Tigeot unsigned int m, n, p;
60303bf270SFrançois Tigeot unsigned int calc_m, calc_p;
61303bf270SFrançois Tigeot int delta, ref_clk;
629edbd4a0SFrançois Tigeot
6319c468b4SFrançois Tigeot /* target_dsi_clk is expected in kHz */
6419c468b4SFrançois Tigeot if (target_dsi_clk < 300000 || target_dsi_clk > 1150000) {
659edbd4a0SFrançois Tigeot DRM_ERROR("DSI CLK Out of Range\n");
669edbd4a0SFrançois Tigeot return -ECHRNG;
679edbd4a0SFrançois Tigeot }
689edbd4a0SFrançois Tigeot
69a05eeebfSFrançois Tigeot if (IS_CHERRYVIEW(dev_priv)) {
70a05eeebfSFrançois Tigeot ref_clk = 100000;
71a05eeebfSFrançois Tigeot n = 4;
72a05eeebfSFrançois Tigeot m_min = 70;
73a05eeebfSFrançois Tigeot m_max = 96;
74a05eeebfSFrançois Tigeot } else {
75a05eeebfSFrançois Tigeot ref_clk = 25000;
76a05eeebfSFrançois Tigeot n = 1;
77a05eeebfSFrançois Tigeot m_min = 62;
78a05eeebfSFrançois Tigeot m_max = 92;
79a05eeebfSFrançois Tigeot }
80a05eeebfSFrançois Tigeot
81303bf270SFrançois Tigeot calc_p = p_min;
82303bf270SFrançois Tigeot calc_m = m_min;
83303bf270SFrançois Tigeot delta = abs(target_dsi_clk - (m_min * ref_clk) / (p_min * n));
84303bf270SFrançois Tigeot
85a05eeebfSFrançois Tigeot for (m = m_min; m <= m_max && delta; m++) {
86a05eeebfSFrançois Tigeot for (p = p_min; p <= p_max && delta; p++) {
8719c468b4SFrançois Tigeot /*
8819c468b4SFrançois Tigeot * Find the optimal m and p divisors with minimal delta
8919c468b4SFrançois Tigeot * +/- the required clock
9019c468b4SFrançois Tigeot */
9119c468b4SFrançois Tigeot int calc_dsi_clk = (m * ref_clk) / (p * n);
9219c468b4SFrançois Tigeot int d = abs(target_dsi_clk - calc_dsi_clk);
9319c468b4SFrançois Tigeot if (d < delta) {
9419c468b4SFrançois Tigeot delta = d;
959edbd4a0SFrançois Tigeot calc_m = m;
969edbd4a0SFrançois Tigeot calc_p = p;
979edbd4a0SFrançois Tigeot }
989edbd4a0SFrançois Tigeot }
999edbd4a0SFrançois Tigeot }
1009edbd4a0SFrançois Tigeot
10119c468b4SFrançois Tigeot /* register has log2(N1), this works fine for powers of two */
1028621f407SFrançois Tigeot config->dsi_pll.ctrl = 1 << (DSI_PLL_P1_POST_DIV_SHIFT + calc_p - 2);
103303bf270SFrançois Tigeot config->dsi_pll.div =
104303bf270SFrançois Tigeot (ffs(n) - 1) << DSI_PLL_N1_DIV_SHIFT |
105303bf270SFrançois Tigeot (u32)lfsr_converts[calc_m - 62] << DSI_PLL_M1_DIV_SHIFT;
1069edbd4a0SFrançois Tigeot
1079edbd4a0SFrançois Tigeot return 0;
1089edbd4a0SFrançois Tigeot }
1099edbd4a0SFrançois Tigeot
1109edbd4a0SFrançois Tigeot /*
1119edbd4a0SFrançois Tigeot * XXX: The muxing and gating is hard coded for now. Need to add support for
1129edbd4a0SFrançois Tigeot * sharing PLLs with two DSI outputs.
1139edbd4a0SFrançois Tigeot */
vlv_compute_dsi_pll(struct intel_encoder * encoder,struct intel_crtc_state * config)1148621f407SFrançois Tigeot static int vlv_compute_dsi_pll(struct intel_encoder *encoder,
1158621f407SFrançois Tigeot struct intel_crtc_state *config)
1169edbd4a0SFrançois Tigeot {
117303bf270SFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1189edbd4a0SFrançois Tigeot struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
1199edbd4a0SFrançois Tigeot int ret;
1209edbd4a0SFrançois Tigeot u32 dsi_clk;
1219edbd4a0SFrançois Tigeot
1221b13d190SFrançois Tigeot dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format,
1239edbd4a0SFrançois Tigeot intel_dsi->lane_count);
1249edbd4a0SFrançois Tigeot
1258621f407SFrançois Tigeot ret = dsi_calc_mnp(dev_priv, config, dsi_clk);
1269edbd4a0SFrançois Tigeot if (ret) {
1279edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("dsi_calc_mnp failed\n");
1288621f407SFrançois Tigeot return ret;
1299edbd4a0SFrançois Tigeot }
1309edbd4a0SFrançois Tigeot
1312c9916cdSFrançois Tigeot if (intel_dsi->ports & (1 << PORT_A))
1328621f407SFrançois Tigeot config->dsi_pll.ctrl |= DSI_PLL_CLK_GATE_DSI0_DSIPLL;
1339edbd4a0SFrançois Tigeot
1342c9916cdSFrançois Tigeot if (intel_dsi->ports & (1 << PORT_C))
1358621f407SFrançois Tigeot config->dsi_pll.ctrl |= DSI_PLL_CLK_GATE_DSI1_DSIPLL;
1368621f407SFrançois Tigeot
1378621f407SFrançois Tigeot config->dsi_pll.ctrl |= DSI_PLL_VCO_EN;
1382c9916cdSFrançois Tigeot
1399edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("dsi pll div %08x, ctrl %08x\n",
1408621f407SFrançois Tigeot config->dsi_pll.div, config->dsi_pll.ctrl);
1419edbd4a0SFrançois Tigeot
1428621f407SFrançois Tigeot return 0;
1439edbd4a0SFrançois Tigeot }
1449edbd4a0SFrançois Tigeot
vlv_enable_dsi_pll(struct intel_encoder * encoder,const struct intel_crtc_state * config)1458621f407SFrançois Tigeot static void vlv_enable_dsi_pll(struct intel_encoder *encoder,
1468621f407SFrançois Tigeot const struct intel_crtc_state *config)
1479edbd4a0SFrançois Tigeot {
1488621f407SFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1499edbd4a0SFrançois Tigeot
1509edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("\n");
1519edbd4a0SFrançois Tigeot
15219c468b4SFrançois Tigeot mutex_lock(&dev_priv->sb_lock);
1539edbd4a0SFrançois Tigeot
1548621f407SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, 0);
1558621f407SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_DIVIDER, config->dsi_pll.div);
1568621f407SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL,
1578621f407SFrançois Tigeot config->dsi_pll.ctrl & ~DSI_PLL_VCO_EN);
1589edbd4a0SFrançois Tigeot
159*a85cb24fSFrançois Tigeot /* wait at least 0.5 us after ungating before enabling VCO,
160*a85cb24fSFrançois Tigeot * allow hrtimer subsystem optimization by relaxing timing
161*a85cb24fSFrançois Tigeot */
162*a85cb24fSFrançois Tigeot usleep_range(10, 50);
1639edbd4a0SFrançois Tigeot
1648621f407SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, config->dsi_pll.ctrl);
1659edbd4a0SFrançois Tigeot
1662c9916cdSFrançois Tigeot if (wait_for(vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL) &
1672c9916cdSFrançois Tigeot DSI_PLL_LOCK, 20)) {
1689edbd4a0SFrançois Tigeot
16919c468b4SFrançois Tigeot mutex_unlock(&dev_priv->sb_lock);
1709edbd4a0SFrançois Tigeot DRM_ERROR("DSI PLL lock failed\n");
1719edbd4a0SFrançois Tigeot return;
1729edbd4a0SFrançois Tigeot }
17319c468b4SFrançois Tigeot mutex_unlock(&dev_priv->sb_lock);
1749edbd4a0SFrançois Tigeot
1759edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("DSI PLL locked\n");
1769edbd4a0SFrançois Tigeot }
1779edbd4a0SFrançois Tigeot
vlv_disable_dsi_pll(struct intel_encoder * encoder)178352ff8bdSFrançois Tigeot static void vlv_disable_dsi_pll(struct intel_encoder *encoder)
1799edbd4a0SFrançois Tigeot {
1808621f407SFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
1819edbd4a0SFrançois Tigeot u32 tmp;
1829edbd4a0SFrançois Tigeot
1839edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("\n");
1849edbd4a0SFrançois Tigeot
18519c468b4SFrançois Tigeot mutex_lock(&dev_priv->sb_lock);
1869edbd4a0SFrançois Tigeot
1879edbd4a0SFrançois Tigeot tmp = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
1889edbd4a0SFrançois Tigeot tmp &= ~DSI_PLL_VCO_EN;
1899edbd4a0SFrançois Tigeot tmp |= DSI_PLL_LDO_GATE;
1909edbd4a0SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, tmp);
1919edbd4a0SFrançois Tigeot
19219c468b4SFrançois Tigeot mutex_unlock(&dev_priv->sb_lock);
1939edbd4a0SFrançois Tigeot }
19424edb884SFrançois Tigeot
bxt_dsi_pll_is_enabled(struct drm_i915_private * dev_priv)1958621f407SFrançois Tigeot static bool bxt_dsi_pll_is_enabled(struct drm_i915_private *dev_priv)
1968621f407SFrançois Tigeot {
1978621f407SFrançois Tigeot bool enabled;
1988621f407SFrançois Tigeot u32 val;
1998621f407SFrançois Tigeot u32 mask;
2008621f407SFrançois Tigeot
2018621f407SFrançois Tigeot mask = BXT_DSI_PLL_DO_ENABLE | BXT_DSI_PLL_LOCKED;
2028621f407SFrançois Tigeot val = I915_READ(BXT_DSI_PLL_ENABLE);
2038621f407SFrançois Tigeot enabled = (val & mask) == mask;
2048621f407SFrançois Tigeot
2058621f407SFrançois Tigeot if (!enabled)
2068621f407SFrançois Tigeot return false;
2078621f407SFrançois Tigeot
2088621f407SFrançois Tigeot /*
209*a85cb24fSFrançois Tigeot * Dividers must be programmed with valid values. As per BSEPC, for
210*a85cb24fSFrançois Tigeot * GEMINLAKE only PORT A divider values are checked while for BXT
211*a85cb24fSFrançois Tigeot * both divider values are validated. Check this here for
2128621f407SFrançois Tigeot * paranoia, since BIOS is known to misconfigure PLLs in this way at
2138621f407SFrançois Tigeot * times, and since accessing DSI registers with invalid dividers
2148621f407SFrançois Tigeot * causes a system hang.
2158621f407SFrançois Tigeot */
2168621f407SFrançois Tigeot val = I915_READ(BXT_DSI_PLL_CTL);
217*a85cb24fSFrançois Tigeot if (IS_GEMINILAKE(dev_priv)) {
218*a85cb24fSFrançois Tigeot if (!(val & BXT_DSIA_16X_MASK)) {
219*a85cb24fSFrançois Tigeot DRM_DEBUG_DRIVER("Invalid PLL divider (%08x)\n", val);
2208621f407SFrançois Tigeot enabled = false;
2218621f407SFrançois Tigeot }
222*a85cb24fSFrançois Tigeot } else {
223*a85cb24fSFrançois Tigeot if (!(val & BXT_DSIA_16X_MASK) || !(val & BXT_DSIC_16X_MASK)) {
224*a85cb24fSFrançois Tigeot DRM_DEBUG_DRIVER("Invalid PLL divider (%08x)\n", val);
225*a85cb24fSFrançois Tigeot enabled = false;
226*a85cb24fSFrançois Tigeot }
227*a85cb24fSFrançois Tigeot }
2288621f407SFrançois Tigeot
2298621f407SFrançois Tigeot return enabled;
2308621f407SFrançois Tigeot }
2318621f407SFrançois Tigeot
bxt_disable_dsi_pll(struct intel_encoder * encoder)232352ff8bdSFrançois Tigeot static void bxt_disable_dsi_pll(struct intel_encoder *encoder)
233352ff8bdSFrançois Tigeot {
2348621f407SFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
235352ff8bdSFrançois Tigeot u32 val;
236352ff8bdSFrançois Tigeot
237352ff8bdSFrançois Tigeot DRM_DEBUG_KMS("\n");
238352ff8bdSFrançois Tigeot
239352ff8bdSFrançois Tigeot val = I915_READ(BXT_DSI_PLL_ENABLE);
240352ff8bdSFrançois Tigeot val &= ~BXT_DSI_PLL_DO_ENABLE;
241352ff8bdSFrançois Tigeot I915_WRITE(BXT_DSI_PLL_ENABLE, val);
242352ff8bdSFrançois Tigeot
243352ff8bdSFrançois Tigeot /*
244352ff8bdSFrançois Tigeot * PLL lock should deassert within 200us.
245352ff8bdSFrançois Tigeot * Wait up to 1ms before timing out.
246352ff8bdSFrançois Tigeot */
2471487f786SFrançois Tigeot if (intel_wait_for_register(dev_priv,
2481487f786SFrançois Tigeot BXT_DSI_PLL_ENABLE,
2491487f786SFrançois Tigeot BXT_DSI_PLL_LOCKED,
2501487f786SFrançois Tigeot 0,
2511487f786SFrançois Tigeot 1))
252352ff8bdSFrançois Tigeot DRM_ERROR("Timeout waiting for PLL lock deassertion\n");
253352ff8bdSFrançois Tigeot }
254352ff8bdSFrançois Tigeot
assert_bpp_mismatch(enum mipi_dsi_pixel_format fmt,int pipe_bpp)2558621f407SFrançois Tigeot static void assert_bpp_mismatch(enum mipi_dsi_pixel_format fmt, int pipe_bpp)
25624edb884SFrançois Tigeot {
2578621f407SFrançois Tigeot int bpp = mipi_dsi_pixel_format_to_bpp(fmt);
25824edb884SFrançois Tigeot
25924edb884SFrançois Tigeot WARN(bpp != pipe_bpp,
26024edb884SFrançois Tigeot "bpp match assertion failure (expected %d, current %d)\n",
26124edb884SFrançois Tigeot bpp, pipe_bpp);
26224edb884SFrançois Tigeot }
26324edb884SFrançois Tigeot
vlv_dsi_get_pclk(struct intel_encoder * encoder,int pipe_bpp,struct intel_crtc_state * config)2648621f407SFrançois Tigeot static u32 vlv_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp,
2658621f407SFrançois Tigeot struct intel_crtc_state *config)
26624edb884SFrançois Tigeot {
2678621f407SFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
26824edb884SFrançois Tigeot struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
26924edb884SFrançois Tigeot u32 dsi_clock, pclk;
27024edb884SFrançois Tigeot u32 pll_ctl, pll_div;
27119c468b4SFrançois Tigeot u32 m = 0, p = 0, n;
2728621f407SFrançois Tigeot int refclk = IS_CHERRYVIEW(dev_priv) ? 100000 : 25000;
27324edb884SFrançois Tigeot int i;
27424edb884SFrançois Tigeot
27524edb884SFrançois Tigeot DRM_DEBUG_KMS("\n");
27624edb884SFrançois Tigeot
27719c468b4SFrançois Tigeot mutex_lock(&dev_priv->sb_lock);
27824edb884SFrançois Tigeot pll_ctl = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
27924edb884SFrançois Tigeot pll_div = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_DIVIDER);
28019c468b4SFrançois Tigeot mutex_unlock(&dev_priv->sb_lock);
28124edb884SFrançois Tigeot
2828621f407SFrançois Tigeot config->dsi_pll.ctrl = pll_ctl & ~DSI_PLL_LOCK;
2838621f407SFrançois Tigeot config->dsi_pll.div = pll_div;
2848621f407SFrançois Tigeot
28524edb884SFrançois Tigeot /* mask out other bits and extract the P1 divisor */
28624edb884SFrançois Tigeot pll_ctl &= DSI_PLL_P1_POST_DIV_MASK;
28724edb884SFrançois Tigeot pll_ctl = pll_ctl >> (DSI_PLL_P1_POST_DIV_SHIFT - 2);
28824edb884SFrançois Tigeot
28919c468b4SFrançois Tigeot /* N1 divisor */
29019c468b4SFrançois Tigeot n = (pll_div & DSI_PLL_N1_DIV_MASK) >> DSI_PLL_N1_DIV_SHIFT;
29119c468b4SFrançois Tigeot n = 1 << n; /* register has log2(N1) */
29219c468b4SFrançois Tigeot
29324edb884SFrançois Tigeot /* mask out the other bits and extract the M1 divisor */
29424edb884SFrançois Tigeot pll_div &= DSI_PLL_M1_DIV_MASK;
29524edb884SFrançois Tigeot pll_div = pll_div >> DSI_PLL_M1_DIV_SHIFT;
29624edb884SFrançois Tigeot
29724edb884SFrançois Tigeot while (pll_ctl) {
29824edb884SFrançois Tigeot pll_ctl = pll_ctl >> 1;
29924edb884SFrançois Tigeot p++;
30024edb884SFrançois Tigeot }
30124edb884SFrançois Tigeot p--;
30224edb884SFrançois Tigeot
30324edb884SFrançois Tigeot if (!p) {
30424edb884SFrançois Tigeot DRM_ERROR("wrong P1 divisor\n");
30524edb884SFrançois Tigeot return 0;
30624edb884SFrançois Tigeot }
30724edb884SFrançois Tigeot
30824edb884SFrançois Tigeot for (i = 0; i < ARRAY_SIZE(lfsr_converts); i++) {
30924edb884SFrançois Tigeot if (lfsr_converts[i] == pll_div)
31024edb884SFrançois Tigeot break;
31124edb884SFrançois Tigeot }
31224edb884SFrançois Tigeot
31324edb884SFrançois Tigeot if (i == ARRAY_SIZE(lfsr_converts)) {
31424edb884SFrançois Tigeot DRM_ERROR("wrong m_seed programmed\n");
31524edb884SFrançois Tigeot return 0;
31624edb884SFrançois Tigeot }
31724edb884SFrançois Tigeot
31824edb884SFrançois Tigeot m = i + 62;
31924edb884SFrançois Tigeot
32019c468b4SFrançois Tigeot dsi_clock = (m * refclk) / (p * n);
32124edb884SFrançois Tigeot
32224edb884SFrançois Tigeot /* pixel_format and pipe_bpp should agree */
32324edb884SFrançois Tigeot assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp);
32424edb884SFrançois Tigeot
32524edb884SFrançois Tigeot pclk = DIV_ROUND_CLOSEST(dsi_clock * intel_dsi->lane_count, pipe_bpp);
32624edb884SFrançois Tigeot
32724edb884SFrançois Tigeot return pclk;
32824edb884SFrançois Tigeot }
329352ff8bdSFrançois Tigeot
bxt_dsi_get_pclk(struct intel_encoder * encoder,int pipe_bpp,struct intel_crtc_state * config)3308621f407SFrançois Tigeot static u32 bxt_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp,
3318621f407SFrançois Tigeot struct intel_crtc_state *config)
332352ff8bdSFrançois Tigeot {
333352ff8bdSFrançois Tigeot u32 pclk;
334352ff8bdSFrançois Tigeot u32 dsi_clk;
335352ff8bdSFrançois Tigeot u32 dsi_ratio;
336352ff8bdSFrançois Tigeot struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
337303bf270SFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
338352ff8bdSFrançois Tigeot
339352ff8bdSFrançois Tigeot /* Divide by zero */
340352ff8bdSFrançois Tigeot if (!pipe_bpp) {
341352ff8bdSFrançois Tigeot DRM_ERROR("Invalid BPP(0)\n");
342352ff8bdSFrançois Tigeot return 0;
343352ff8bdSFrançois Tigeot }
344352ff8bdSFrançois Tigeot
3458621f407SFrançois Tigeot config->dsi_pll.ctrl = I915_READ(BXT_DSI_PLL_CTL);
346352ff8bdSFrançois Tigeot
3478621f407SFrançois Tigeot dsi_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
348352ff8bdSFrançois Tigeot
349352ff8bdSFrançois Tigeot dsi_clk = (dsi_ratio * BXT_REF_CLOCK_KHZ) / 2;
350352ff8bdSFrançois Tigeot
351352ff8bdSFrançois Tigeot /* pixel_format and pipe_bpp should agree */
352352ff8bdSFrançois Tigeot assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp);
353352ff8bdSFrançois Tigeot
354352ff8bdSFrançois Tigeot pclk = DIV_ROUND_CLOSEST(dsi_clk * intel_dsi->lane_count, pipe_bpp);
355352ff8bdSFrançois Tigeot
356352ff8bdSFrançois Tigeot DRM_DEBUG_DRIVER("Calculated pclk=%u\n", pclk);
357352ff8bdSFrançois Tigeot return pclk;
358352ff8bdSFrançois Tigeot }
359352ff8bdSFrançois Tigeot
intel_dsi_get_pclk(struct intel_encoder * encoder,int pipe_bpp,struct intel_crtc_state * config)3608621f407SFrançois Tigeot u32 intel_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp,
3618621f407SFrançois Tigeot struct intel_crtc_state *config)
362c0e85e96SFrançois Tigeot {
363*a85cb24fSFrançois Tigeot if (IS_GEN9_LP(to_i915(encoder->base.dev)))
3648621f407SFrançois Tigeot return bxt_dsi_get_pclk(encoder, pipe_bpp, config);
365c0e85e96SFrançois Tigeot else
3668621f407SFrançois Tigeot return vlv_dsi_get_pclk(encoder, pipe_bpp, config);
367c0e85e96SFrançois Tigeot }
368c0e85e96SFrançois Tigeot
vlv_dsi_reset_clocks(struct intel_encoder * encoder,enum port port)369352ff8bdSFrançois Tigeot static void vlv_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
370352ff8bdSFrançois Tigeot {
371352ff8bdSFrançois Tigeot u32 temp;
372303bf270SFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
373352ff8bdSFrançois Tigeot struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
374352ff8bdSFrançois Tigeot
375352ff8bdSFrançois Tigeot temp = I915_READ(MIPI_CTRL(port));
376352ff8bdSFrançois Tigeot temp &= ~ESCAPE_CLOCK_DIVIDER_MASK;
377352ff8bdSFrançois Tigeot I915_WRITE(MIPI_CTRL(port), temp |
378352ff8bdSFrançois Tigeot intel_dsi->escape_clk_div <<
379352ff8bdSFrançois Tigeot ESCAPE_CLOCK_DIVIDER_SHIFT);
380352ff8bdSFrançois Tigeot }
381352ff8bdSFrançois Tigeot
glk_dsi_program_esc_clock(struct drm_device * dev,const struct intel_crtc_state * config)382*a85cb24fSFrançois Tigeot static void glk_dsi_program_esc_clock(struct drm_device *dev,
383*a85cb24fSFrançois Tigeot const struct intel_crtc_state *config)
384*a85cb24fSFrançois Tigeot {
385*a85cb24fSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(dev);
386*a85cb24fSFrançois Tigeot u32 dsi_rate = 0;
387*a85cb24fSFrançois Tigeot u32 pll_ratio = 0;
388*a85cb24fSFrançois Tigeot u32 ddr_clk = 0;
389*a85cb24fSFrançois Tigeot u32 div1_value = 0;
390*a85cb24fSFrançois Tigeot u32 div2_value = 0;
391*a85cb24fSFrançois Tigeot u32 txesc1_div = 0;
392*a85cb24fSFrançois Tigeot u32 txesc2_div = 0;
393*a85cb24fSFrançois Tigeot
394*a85cb24fSFrançois Tigeot pll_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
395*a85cb24fSFrançois Tigeot
396*a85cb24fSFrançois Tigeot dsi_rate = (BXT_REF_CLOCK_KHZ * pll_ratio) / 2;
397*a85cb24fSFrançois Tigeot
398*a85cb24fSFrançois Tigeot ddr_clk = dsi_rate / 2;
399*a85cb24fSFrançois Tigeot
400*a85cb24fSFrançois Tigeot /* Variable divider value */
401*a85cb24fSFrançois Tigeot div1_value = DIV_ROUND_CLOSEST(ddr_clk, 20000);
402*a85cb24fSFrançois Tigeot
403*a85cb24fSFrançois Tigeot /* Calculate TXESC1 divider */
404*a85cb24fSFrançois Tigeot if (div1_value <= 10)
405*a85cb24fSFrançois Tigeot txesc1_div = div1_value;
406*a85cb24fSFrançois Tigeot else if ((div1_value > 10) && (div1_value <= 20))
407*a85cb24fSFrançois Tigeot txesc1_div = DIV_ROUND_UP(div1_value, 2);
408*a85cb24fSFrançois Tigeot else if ((div1_value > 20) && (div1_value <= 30))
409*a85cb24fSFrançois Tigeot txesc1_div = DIV_ROUND_UP(div1_value, 4);
410*a85cb24fSFrançois Tigeot else if ((div1_value > 30) && (div1_value <= 40))
411*a85cb24fSFrançois Tigeot txesc1_div = DIV_ROUND_UP(div1_value, 6);
412*a85cb24fSFrançois Tigeot else if ((div1_value > 40) && (div1_value <= 50))
413*a85cb24fSFrançois Tigeot txesc1_div = DIV_ROUND_UP(div1_value, 8);
414*a85cb24fSFrançois Tigeot else
415*a85cb24fSFrançois Tigeot txesc1_div = 10;
416*a85cb24fSFrançois Tigeot
417*a85cb24fSFrançois Tigeot /* Calculate TXESC2 divider */
418*a85cb24fSFrançois Tigeot div2_value = DIV_ROUND_UP(div1_value, txesc1_div);
419*a85cb24fSFrançois Tigeot
420*a85cb24fSFrançois Tigeot if (div2_value < 10)
421*a85cb24fSFrançois Tigeot txesc2_div = div2_value;
422*a85cb24fSFrançois Tigeot else
423*a85cb24fSFrançois Tigeot txesc2_div = 10;
424*a85cb24fSFrançois Tigeot
425*a85cb24fSFrançois Tigeot I915_WRITE(MIPIO_TXESC_CLK_DIV1, txesc1_div & GLK_TX_ESC_CLK_DIV1_MASK);
426*a85cb24fSFrançois Tigeot I915_WRITE(MIPIO_TXESC_CLK_DIV2, txesc2_div & GLK_TX_ESC_CLK_DIV2_MASK);
427*a85cb24fSFrançois Tigeot }
428*a85cb24fSFrançois Tigeot
429352ff8bdSFrançois Tigeot /* Program BXT Mipi clocks and dividers */
bxt_dsi_program_clocks(struct drm_device * dev,enum port port,const struct intel_crtc_state * config)4308621f407SFrançois Tigeot static void bxt_dsi_program_clocks(struct drm_device *dev, enum port port,
4318621f407SFrançois Tigeot const struct intel_crtc_state *config)
432352ff8bdSFrançois Tigeot {
433303bf270SFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(dev);
4348621f407SFrançois Tigeot u32 tmp;
4358621f407SFrançois Tigeot u32 dsi_rate = 0;
4368621f407SFrançois Tigeot u32 pll_ratio = 0;
4378621f407SFrançois Tigeot u32 rx_div;
4388621f407SFrançois Tigeot u32 tx_div;
4398621f407SFrançois Tigeot u32 rx_div_upper;
4408621f407SFrançois Tigeot u32 rx_div_lower;
4418621f407SFrançois Tigeot u32 mipi_8by3_divider;
442352ff8bdSFrançois Tigeot
443352ff8bdSFrançois Tigeot /* Clear old configurations */
444352ff8bdSFrançois Tigeot tmp = I915_READ(BXT_MIPI_CLOCK_CTL);
445352ff8bdSFrançois Tigeot tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port));
4468621f407SFrançois Tigeot tmp &= ~(BXT_MIPI_RX_ESCLK_UPPER_FIXDIV_MASK(port));
4478621f407SFrançois Tigeot tmp &= ~(BXT_MIPI_8X_BY3_DIVIDER_MASK(port));
4488621f407SFrançois Tigeot tmp &= ~(BXT_MIPI_RX_ESCLK_LOWER_FIXDIV_MASK(port));
449352ff8bdSFrançois Tigeot
450352ff8bdSFrançois Tigeot /* Get the current DSI rate(actual) */
4518621f407SFrançois Tigeot pll_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK;
452352ff8bdSFrançois Tigeot dsi_rate = (BXT_REF_CLOCK_KHZ * pll_ratio) / 2;
453352ff8bdSFrançois Tigeot
4548621f407SFrançois Tigeot /*
4558621f407SFrançois Tigeot * tx clock should be <= 20MHz and the div value must be
4568621f407SFrançois Tigeot * subtracted by 1 as per bspec
4578621f407SFrançois Tigeot */
4588621f407SFrançois Tigeot tx_div = DIV_ROUND_UP(dsi_rate, 20000) - 1;
4598621f407SFrançois Tigeot /*
4608621f407SFrançois Tigeot * rx clock should be <= 150MHz and the div value must be
4618621f407SFrançois Tigeot * subtracted by 1 as per bspec
4628621f407SFrançois Tigeot */
4638621f407SFrançois Tigeot rx_div = DIV_ROUND_UP(dsi_rate, 150000) - 1;
464352ff8bdSFrançois Tigeot
465352ff8bdSFrançois Tigeot /*
4668621f407SFrançois Tigeot * rx divider value needs to be updated in the
4678621f407SFrançois Tigeot * two differnt bit fields in the register hence splitting the
4688621f407SFrançois Tigeot * rx divider value accordingly
469352ff8bdSFrançois Tigeot */
4708621f407SFrançois Tigeot rx_div_lower = rx_div & RX_DIVIDER_BIT_1_2;
4718621f407SFrançois Tigeot rx_div_upper = (rx_div & RX_DIVIDER_BIT_3_4) >> 2;
472352ff8bdSFrançois Tigeot
4738621f407SFrançois Tigeot mipi_8by3_divider = 0x2;
4748621f407SFrançois Tigeot
4758621f407SFrançois Tigeot tmp |= BXT_MIPI_8X_BY3_DIVIDER(port, mipi_8by3_divider);
4768621f407SFrançois Tigeot tmp |= BXT_MIPI_TX_ESCLK_DIVIDER(port, tx_div);
4778621f407SFrançois Tigeot tmp |= BXT_MIPI_RX_ESCLK_LOWER_DIVIDER(port, rx_div_lower);
4788621f407SFrançois Tigeot tmp |= BXT_MIPI_RX_ESCLK_UPPER_DIVIDER(port, rx_div_upper);
479352ff8bdSFrançois Tigeot
480352ff8bdSFrançois Tigeot I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp);
481352ff8bdSFrançois Tigeot }
482352ff8bdSFrançois Tigeot
gen9lp_compute_dsi_pll(struct intel_encoder * encoder,struct intel_crtc_state * config)483*a85cb24fSFrançois Tigeot static int gen9lp_compute_dsi_pll(struct intel_encoder *encoder,
4848621f407SFrançois Tigeot struct intel_crtc_state *config)
485352ff8bdSFrançois Tigeot {
486*a85cb24fSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
487352ff8bdSFrançois Tigeot struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
488*a85cb24fSFrançois Tigeot u8 dsi_ratio, dsi_ratio_min, dsi_ratio_max;
489352ff8bdSFrançois Tigeot u32 dsi_clk;
490352ff8bdSFrançois Tigeot
491352ff8bdSFrançois Tigeot dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format,
492352ff8bdSFrançois Tigeot intel_dsi->lane_count);
493352ff8bdSFrançois Tigeot
494352ff8bdSFrançois Tigeot /*
495352ff8bdSFrançois Tigeot * From clock diagram, to get PLL ratio divider, divide double of DSI
496352ff8bdSFrançois Tigeot * link rate (i.e., 2*8x=16x frequency value) by ref clock. Make sure to
497352ff8bdSFrançois Tigeot * round 'up' the result
498352ff8bdSFrançois Tigeot */
499352ff8bdSFrançois Tigeot dsi_ratio = DIV_ROUND_UP(dsi_clk * 2, BXT_REF_CLOCK_KHZ);
500*a85cb24fSFrançois Tigeot
501*a85cb24fSFrançois Tigeot if (IS_BROXTON(dev_priv)) {
502*a85cb24fSFrançois Tigeot dsi_ratio_min = BXT_DSI_PLL_RATIO_MIN;
503*a85cb24fSFrançois Tigeot dsi_ratio_max = BXT_DSI_PLL_RATIO_MAX;
504*a85cb24fSFrançois Tigeot } else {
505*a85cb24fSFrançois Tigeot dsi_ratio_min = GLK_DSI_PLL_RATIO_MIN;
506*a85cb24fSFrançois Tigeot dsi_ratio_max = GLK_DSI_PLL_RATIO_MAX;
507*a85cb24fSFrançois Tigeot }
508*a85cb24fSFrançois Tigeot
509*a85cb24fSFrançois Tigeot if (dsi_ratio < dsi_ratio_min || dsi_ratio > dsi_ratio_max) {
510352ff8bdSFrançois Tigeot DRM_ERROR("Cant get a suitable ratio from DSI PLL ratios\n");
5118621f407SFrançois Tigeot return -ECHRNG;
512*a85cb24fSFrançois Tigeot } else
513*a85cb24fSFrançois Tigeot DRM_DEBUG_KMS("DSI PLL calculation is Done!!\n");
514352ff8bdSFrançois Tigeot
515352ff8bdSFrançois Tigeot /*
516352ff8bdSFrançois Tigeot * Program DSI ratio and Select MIPIC and MIPIA PLL output as 8x
517352ff8bdSFrançois Tigeot * Spec says both have to be programmed, even if one is not getting
518352ff8bdSFrançois Tigeot * used. Configure MIPI_CLOCK_CTL dividers in modeset
519352ff8bdSFrançois Tigeot */
5208621f407SFrançois Tigeot config->dsi_pll.ctrl = dsi_ratio | BXT_DSIA_16X_BY2 | BXT_DSIC_16X_BY2;
521352ff8bdSFrançois Tigeot
522352ff8bdSFrançois Tigeot /* As per recommendation from hardware team,
523352ff8bdSFrançois Tigeot * Prog PVD ratio =1 if dsi ratio <= 50
524352ff8bdSFrançois Tigeot */
525*a85cb24fSFrançois Tigeot if (IS_BROXTON(dev_priv) && dsi_ratio <= 50)
5268621f407SFrançois Tigeot config->dsi_pll.ctrl |= BXT_DSI_PLL_PVD_RATIO_1;
5278621f407SFrançois Tigeot
5288621f407SFrançois Tigeot return 0;
529352ff8bdSFrançois Tigeot }
530352ff8bdSFrançois Tigeot
gen9lp_enable_dsi_pll(struct intel_encoder * encoder,const struct intel_crtc_state * config)531*a85cb24fSFrançois Tigeot static void gen9lp_enable_dsi_pll(struct intel_encoder *encoder,
5328621f407SFrançois Tigeot const struct intel_crtc_state *config)
533352ff8bdSFrançois Tigeot {
534303bf270SFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
535352ff8bdSFrançois Tigeot struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
536352ff8bdSFrançois Tigeot enum port port;
537352ff8bdSFrançois Tigeot u32 val;
538352ff8bdSFrançois Tigeot
539352ff8bdSFrançois Tigeot DRM_DEBUG_KMS("\n");
540352ff8bdSFrançois Tigeot
541352ff8bdSFrançois Tigeot /* Configure PLL vales */
5428621f407SFrançois Tigeot I915_WRITE(BXT_DSI_PLL_CTL, config->dsi_pll.ctrl);
5438621f407SFrançois Tigeot POSTING_READ(BXT_DSI_PLL_CTL);
544352ff8bdSFrançois Tigeot
545352ff8bdSFrançois Tigeot /* Program TX, RX, Dphy clocks */
546*a85cb24fSFrançois Tigeot if (IS_BROXTON(dev_priv)) {
547352ff8bdSFrançois Tigeot for_each_dsi_port(port, intel_dsi->ports)
5488621f407SFrançois Tigeot bxt_dsi_program_clocks(encoder->base.dev, port, config);
549*a85cb24fSFrançois Tigeot } else {
550*a85cb24fSFrançois Tigeot glk_dsi_program_esc_clock(encoder->base.dev, config);
551*a85cb24fSFrançois Tigeot }
552352ff8bdSFrançois Tigeot
553352ff8bdSFrançois Tigeot /* Enable DSI PLL */
554352ff8bdSFrançois Tigeot val = I915_READ(BXT_DSI_PLL_ENABLE);
555352ff8bdSFrançois Tigeot val |= BXT_DSI_PLL_DO_ENABLE;
556352ff8bdSFrançois Tigeot I915_WRITE(BXT_DSI_PLL_ENABLE, val);
557352ff8bdSFrançois Tigeot
558352ff8bdSFrançois Tigeot /* Timeout and fail if PLL not locked */
5591487f786SFrançois Tigeot if (intel_wait_for_register(dev_priv,
5601487f786SFrançois Tigeot BXT_DSI_PLL_ENABLE,
5611487f786SFrançois Tigeot BXT_DSI_PLL_LOCKED,
5621487f786SFrançois Tigeot BXT_DSI_PLL_LOCKED,
5631487f786SFrançois Tigeot 1)) {
564352ff8bdSFrançois Tigeot DRM_ERROR("Timed out waiting for DSI PLL to lock\n");
565352ff8bdSFrançois Tigeot return;
566352ff8bdSFrançois Tigeot }
567352ff8bdSFrançois Tigeot
568352ff8bdSFrançois Tigeot DRM_DEBUG_KMS("DSI PLL locked\n");
569352ff8bdSFrançois Tigeot }
570352ff8bdSFrançois Tigeot
intel_dsi_pll_is_enabled(struct drm_i915_private * dev_priv)5718621f407SFrançois Tigeot bool intel_dsi_pll_is_enabled(struct drm_i915_private *dev_priv)
5728621f407SFrançois Tigeot {
573*a85cb24fSFrançois Tigeot if (IS_GEN9_LP(dev_priv))
5748621f407SFrançois Tigeot return bxt_dsi_pll_is_enabled(dev_priv);
5758621f407SFrançois Tigeot
5768621f407SFrançois Tigeot MISSING_CASE(INTEL_DEVID(dev_priv));
5778621f407SFrançois Tigeot
5788621f407SFrançois Tigeot return false;
5798621f407SFrançois Tigeot }
5808621f407SFrançois Tigeot
intel_compute_dsi_pll(struct intel_encoder * encoder,struct intel_crtc_state * config)5818621f407SFrançois Tigeot int intel_compute_dsi_pll(struct intel_encoder *encoder,
5828621f407SFrançois Tigeot struct intel_crtc_state *config)
583352ff8bdSFrançois Tigeot {
5841e12ee3bSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
585352ff8bdSFrançois Tigeot
5861e12ee3bSFrançois Tigeot if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5878621f407SFrançois Tigeot return vlv_compute_dsi_pll(encoder, config);
588*a85cb24fSFrançois Tigeot else if (IS_GEN9_LP(dev_priv))
589*a85cb24fSFrançois Tigeot return gen9lp_compute_dsi_pll(encoder, config);
5908621f407SFrançois Tigeot
5918621f407SFrançois Tigeot return -ENODEV;
5928621f407SFrançois Tigeot }
5938621f407SFrançois Tigeot
intel_enable_dsi_pll(struct intel_encoder * encoder,const struct intel_crtc_state * config)5948621f407SFrançois Tigeot void intel_enable_dsi_pll(struct intel_encoder *encoder,
5958621f407SFrançois Tigeot const struct intel_crtc_state *config)
5968621f407SFrançois Tigeot {
5971e12ee3bSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
5988621f407SFrançois Tigeot
5991e12ee3bSFrançois Tigeot if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
6008621f407SFrançois Tigeot vlv_enable_dsi_pll(encoder, config);
601*a85cb24fSFrançois Tigeot else if (IS_GEN9_LP(dev_priv))
602*a85cb24fSFrançois Tigeot gen9lp_enable_dsi_pll(encoder, config);
603352ff8bdSFrançois Tigeot }
604352ff8bdSFrançois Tigeot
intel_disable_dsi_pll(struct intel_encoder * encoder)605352ff8bdSFrançois Tigeot void intel_disable_dsi_pll(struct intel_encoder *encoder)
606352ff8bdSFrançois Tigeot {
6071e12ee3bSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
608352ff8bdSFrançois Tigeot
6091e12ee3bSFrançois Tigeot if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
610352ff8bdSFrançois Tigeot vlv_disable_dsi_pll(encoder);
611*a85cb24fSFrançois Tigeot else if (IS_GEN9_LP(dev_priv))
612352ff8bdSFrançois Tigeot bxt_disable_dsi_pll(encoder);
613352ff8bdSFrançois Tigeot }
614352ff8bdSFrançois Tigeot
gen9lp_dsi_reset_clocks(struct intel_encoder * encoder,enum port port)615*a85cb24fSFrançois Tigeot static void gen9lp_dsi_reset_clocks(struct intel_encoder *encoder,
616*a85cb24fSFrançois Tigeot enum port port)
617352ff8bdSFrançois Tigeot {
618352ff8bdSFrançois Tigeot u32 tmp;
619352ff8bdSFrançois Tigeot struct drm_device *dev = encoder->base.dev;
620303bf270SFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(dev);
621352ff8bdSFrançois Tigeot
622352ff8bdSFrançois Tigeot /* Clear old configurations */
623*a85cb24fSFrançois Tigeot if (IS_BROXTON(dev_priv)) {
624352ff8bdSFrançois Tigeot tmp = I915_READ(BXT_MIPI_CLOCK_CTL);
625352ff8bdSFrançois Tigeot tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port));
6268621f407SFrançois Tigeot tmp &= ~(BXT_MIPI_RX_ESCLK_UPPER_FIXDIV_MASK(port));
6278621f407SFrançois Tigeot tmp &= ~(BXT_MIPI_8X_BY3_DIVIDER_MASK(port));
6288621f407SFrançois Tigeot tmp &= ~(BXT_MIPI_RX_ESCLK_LOWER_FIXDIV_MASK(port));
629352ff8bdSFrançois Tigeot I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp);
630*a85cb24fSFrançois Tigeot } else {
631*a85cb24fSFrançois Tigeot tmp = I915_READ(MIPIO_TXESC_CLK_DIV1);
632*a85cb24fSFrançois Tigeot tmp &= ~GLK_TX_ESC_CLK_DIV1_MASK;
633*a85cb24fSFrançois Tigeot I915_WRITE(MIPIO_TXESC_CLK_DIV1, tmp);
634*a85cb24fSFrançois Tigeot
635*a85cb24fSFrançois Tigeot tmp = I915_READ(MIPIO_TXESC_CLK_DIV2);
636*a85cb24fSFrançois Tigeot tmp &= ~GLK_TX_ESC_CLK_DIV2_MASK;
637*a85cb24fSFrançois Tigeot I915_WRITE(MIPIO_TXESC_CLK_DIV2, tmp);
638*a85cb24fSFrançois Tigeot }
639352ff8bdSFrançois Tigeot I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP);
640352ff8bdSFrançois Tigeot }
641352ff8bdSFrançois Tigeot
intel_dsi_reset_clocks(struct intel_encoder * encoder,enum port port)642352ff8bdSFrançois Tigeot void intel_dsi_reset_clocks(struct intel_encoder *encoder, enum port port)
643352ff8bdSFrançois Tigeot {
6441e12ee3bSFrançois Tigeot struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
645352ff8bdSFrançois Tigeot
646*a85cb24fSFrançois Tigeot if (IS_GEN9_LP(dev_priv))
647*a85cb24fSFrançois Tigeot gen9lp_dsi_reset_clocks(encoder, port);
6481e12ee3bSFrançois Tigeot else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
649352ff8bdSFrançois Tigeot vlv_dsi_reset_clocks(encoder, port);
650352ff8bdSFrançois Tigeot }
651