ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 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 | |
| 28 | #include <linux/kernel.h> |
| 29 | #include "intel_drv.h" |
| 30 | #include "i915_drv.h" |
| 31 | #include "intel_dsi.h" |
| 32 | |
Ville Syrjälä | 50dd63a | 2016-03-15 16:40:02 +0200 | [diff] [blame] | 33 | static const u16 lfsr_converts[] = { |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 34 | 426, 469, 234, 373, 442, 221, 110, 311, 411, /* 62 - 70 */ |
| 35 | 461, 486, 243, 377, 188, 350, 175, 343, 427, 213, /* 71 - 80 */ |
Gaurav K Singh | 3c5c6d8 | 2015-07-01 15:58:51 +0300 | [diff] [blame] | 36 | 106, 53, 282, 397, 454, 227, 113, 56, 284, 142, /* 81 - 90 */ |
| 37 | 71, 35, 273, 136, 324, 418, 465, 488, 500, 506 /* 91 - 100 */ |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 38 | }; |
| 39 | |
Shobhit Kumar | 44d4c6e | 2013-12-10 12:14:56 +0530 | [diff] [blame] | 40 | /* Get DSI clock from pixel clock */ |
Jani Nikula | 1e78aa0 | 2016-03-16 12:21:40 +0200 | [diff] [blame] | 41 | static u32 dsi_clk_from_pclk(u32 pclk, enum mipi_dsi_pixel_format fmt, |
| 42 | int lane_count) |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 43 | { |
Shobhit Kumar | 44d4c6e | 2013-12-10 12:14:56 +0530 | [diff] [blame] | 44 | u32 dsi_clk_khz; |
Jani Nikula | 1e78aa0 | 2016-03-16 12:21:40 +0200 | [diff] [blame] | 45 | u32 bpp = mipi_dsi_pixel_format_to_bpp(fmt); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 46 | |
Shobhit Kumar | 44d4c6e | 2013-12-10 12:14:56 +0530 | [diff] [blame] | 47 | /* DSI data rate = pixel clock * bits per pixel / lane count |
| 48 | pixel clock is converted from KHz to Hz */ |
Shobhit Kumar | 7f0c860 | 2014-07-30 20:34:57 +0530 | [diff] [blame] | 49 | dsi_clk_khz = DIV_ROUND_CLOSEST(pclk * bpp, lane_count); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 50 | |
Shobhit Kumar | 44d4c6e | 2013-12-10 12:14:56 +0530 | [diff] [blame] | 51 | return dsi_clk_khz; |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 52 | } |
| 53 | |
Gaurav K Singh | 20dbe1a | 2015-07-01 15:58:52 +0300 | [diff] [blame] | 54 | static int dsi_calc_mnp(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 55 | struct intel_crtc_state *config, |
| 56 | int target_dsi_clk) |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 57 | { |
Gaurav K Singh | 20dbe1a | 2015-07-01 15:58:52 +0300 | [diff] [blame] | 58 | unsigned int m_min, m_max, p_min = 2, p_max = 6; |
| 59 | unsigned int m, n, p; |
Chris Wilson | 1bbea16 | 2016-07-02 15:36:04 +0100 | [diff] [blame] | 60 | unsigned int calc_m, calc_p; |
| 61 | int delta, ref_clk; |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 62 | |
Jani Nikula | 7471bf4 | 2015-05-12 15:23:09 +0300 | [diff] [blame] | 63 | /* target_dsi_clk is expected in kHz */ |
| 64 | if (target_dsi_clk < 300000 || target_dsi_clk > 1150000) { |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 65 | DRM_ERROR("DSI CLK Out of Range\n"); |
| 66 | return -ECHRNG; |
| 67 | } |
| 68 | |
Gaurav K Singh | 20dbe1a | 2015-07-01 15:58:52 +0300 | [diff] [blame] | 69 | if (IS_CHERRYVIEW(dev_priv)) { |
| 70 | ref_clk = 100000; |
| 71 | n = 4; |
| 72 | m_min = 70; |
| 73 | m_max = 96; |
| 74 | } else { |
| 75 | ref_clk = 25000; |
| 76 | n = 1; |
| 77 | m_min = 62; |
| 78 | m_max = 92; |
| 79 | } |
| 80 | |
Chris Wilson | 1bbea16 | 2016-07-02 15:36:04 +0100 | [diff] [blame] | 81 | calc_p = p_min; |
| 82 | calc_m = m_min; |
| 83 | delta = abs(target_dsi_clk - (m_min * ref_clk) / (p_min * n)); |
| 84 | |
Gaurav K Singh | 20dbe1a | 2015-07-01 15:58:52 +0300 | [diff] [blame] | 85 | for (m = m_min; m <= m_max && delta; m++) { |
| 86 | for (p = p_min; p <= p_max && delta; p++) { |
Jani Nikula | 7471bf4 | 2015-05-12 15:23:09 +0300 | [diff] [blame] | 87 | /* |
| 88 | * Find the optimal m and p divisors with minimal delta |
| 89 | * +/- the required clock |
| 90 | */ |
Jani Nikula | a856c5b | 2015-05-13 10:35:25 +0300 | [diff] [blame] | 91 | int calc_dsi_clk = (m * ref_clk) / (p * n); |
Jani Nikula | 7471bf4 | 2015-05-12 15:23:09 +0300 | [diff] [blame] | 92 | int d = abs(target_dsi_clk - calc_dsi_clk); |
| 93 | if (d < delta) { |
| 94 | delta = d; |
Shobhit Kumar | 8e1eed5 | 2013-12-10 12:14:57 +0530 | [diff] [blame] | 95 | calc_m = m; |
| 96 | calc_p = p; |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
Jani Nikula | a856c5b | 2015-05-13 10:35:25 +0300 | [diff] [blame] | 101 | /* register has log2(N1), this works fine for powers of two */ |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 102 | config->dsi_pll.ctrl = 1 << (DSI_PLL_P1_POST_DIV_SHIFT + calc_p - 2); |
Chris Wilson | 1bbea16 | 2016-07-02 15:36:04 +0100 | [diff] [blame] | 103 | config->dsi_pll.div = |
| 104 | (ffs(n) - 1) << DSI_PLL_N1_DIV_SHIFT | |
| 105 | (u32)lfsr_converts[calc_m - 62] << DSI_PLL_M1_DIV_SHIFT; |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 110 | /* |
| 111 | * XXX: The muxing and gating is hard coded for now. Need to add support for |
| 112 | * sharing PLLs with two DSI outputs. |
| 113 | */ |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 114 | static int vlv_compute_dsi_pll(struct intel_encoder *encoder, |
| 115 | struct intel_crtc_state *config) |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 116 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 117 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 118 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 119 | int ret; |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 120 | u32 dsi_clk; |
| 121 | |
Shobhit Kumar | 7f0c860 | 2014-07-30 20:34:57 +0530 | [diff] [blame] | 122 | dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format, |
Daniel Vetter | 7f3de83 | 2014-07-30 22:34:27 +0200 | [diff] [blame] | 123 | intel_dsi->lane_count); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 124 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 125 | ret = dsi_calc_mnp(dev_priv, config, dsi_clk); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 126 | if (ret) { |
| 127 | DRM_DEBUG_KMS("dsi_calc_mnp failed\n"); |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 128 | return ret; |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 129 | } |
| 130 | |
Gaurav K Singh | 3c860ab | 2014-12-09 10:57:00 +0530 | [diff] [blame] | 131 | if (intel_dsi->ports & (1 << PORT_A)) |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 132 | config->dsi_pll.ctrl |= DSI_PLL_CLK_GATE_DSI0_DSIPLL; |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 133 | |
Gaurav K Singh | 3c860ab | 2014-12-09 10:57:00 +0530 | [diff] [blame] | 134 | if (intel_dsi->ports & (1 << PORT_C)) |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 135 | config->dsi_pll.ctrl |= DSI_PLL_CLK_GATE_DSI1_DSIPLL; |
| 136 | |
| 137 | config->dsi_pll.ctrl |= DSI_PLL_VCO_EN; |
Gaurav K Singh | 58cf888 | 2014-12-04 10:58:52 +0530 | [diff] [blame] | 138 | |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 139 | DRM_DEBUG_KMS("dsi pll div %08x, ctrl %08x\n", |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 140 | config->dsi_pll.div, config->dsi_pll.ctrl); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 141 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 142 | return 0; |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 143 | } |
| 144 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 145 | static void vlv_enable_dsi_pll(struct intel_encoder *encoder, |
| 146 | const struct intel_crtc_state *config) |
| 147 | { |
| 148 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 149 | |
| 150 | DRM_DEBUG_KMS("\n"); |
| 151 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 152 | mutex_lock(&dev_priv->sb_lock); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 153 | |
Ville Syrjälä | 062efa5 | 2016-04-12 22:14:36 +0300 | [diff] [blame] | 154 | vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, 0); |
| 155 | vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_DIVIDER, config->dsi_pll.div); |
| 156 | vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, |
| 157 | config->dsi_pll.ctrl & ~DSI_PLL_VCO_EN); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 158 | |
| 159 | /* wait at least 0.5 us after ungating before enabling VCO */ |
| 160 | usleep_range(1, 10); |
| 161 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 162 | vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, config->dsi_pll.ctrl); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 163 | |
Gaurav K Singh | 3770f0e | 2014-12-05 14:16:58 +0530 | [diff] [blame] | 164 | if (wait_for(vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL) & |
| 165 | DSI_PLL_LOCK, 20)) { |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 166 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 167 | mutex_unlock(&dev_priv->sb_lock); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 168 | DRM_ERROR("DSI PLL lock failed\n"); |
| 169 | return; |
| 170 | } |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 171 | mutex_unlock(&dev_priv->sb_lock); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 172 | |
| 173 | DRM_DEBUG_KMS("DSI PLL locked\n"); |
| 174 | } |
| 175 | |
Shashank Sharma | fe88fc6 | 2015-09-01 19:41:39 +0530 | [diff] [blame] | 176 | static void vlv_disable_dsi_pll(struct intel_encoder *encoder) |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 177 | { |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 178 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 179 | u32 tmp; |
| 180 | |
| 181 | DRM_DEBUG_KMS("\n"); |
| 182 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 183 | mutex_lock(&dev_priv->sb_lock); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 184 | |
| 185 | tmp = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
| 186 | tmp &= ~DSI_PLL_VCO_EN; |
| 187 | tmp |= DSI_PLL_LDO_GATE; |
| 188 | vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, tmp); |
| 189 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 190 | mutex_unlock(&dev_priv->sb_lock); |
ymohanma | be4fc04 | 2013-08-27 23:40:56 +0300 | [diff] [blame] | 191 | } |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 192 | |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 193 | static bool bxt_dsi_pll_is_enabled(struct drm_i915_private *dev_priv) |
| 194 | { |
| 195 | bool enabled; |
| 196 | u32 val; |
| 197 | u32 mask; |
| 198 | |
| 199 | mask = BXT_DSI_PLL_DO_ENABLE | BXT_DSI_PLL_LOCKED; |
| 200 | val = I915_READ(BXT_DSI_PLL_ENABLE); |
| 201 | enabled = (val & mask) == mask; |
| 202 | |
| 203 | if (!enabled) |
| 204 | return false; |
| 205 | |
| 206 | /* |
| 207 | * Both dividers must be programmed with valid values even if only one |
| 208 | * of the PLL is used, see BSpec/Broxton Clocks. Check this here for |
| 209 | * paranoia, since BIOS is known to misconfigure PLLs in this way at |
| 210 | * times, and since accessing DSI registers with invalid dividers |
| 211 | * causes a system hang. |
| 212 | */ |
| 213 | val = I915_READ(BXT_DSI_PLL_CTL); |
| 214 | if (!(val & BXT_DSIA_16X_MASK) || !(val & BXT_DSIC_16X_MASK)) { |
| 215 | DRM_DEBUG_DRIVER("PLL is enabled with invalid divider settings (%08x)\n", |
| 216 | val); |
| 217 | enabled = false; |
| 218 | } |
| 219 | |
| 220 | return enabled; |
| 221 | } |
| 222 | |
Shashank Sharma | fe88fc6 | 2015-09-01 19:41:39 +0530 | [diff] [blame] | 223 | static void bxt_disable_dsi_pll(struct intel_encoder *encoder) |
| 224 | { |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 225 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Shashank Sharma | fe88fc6 | 2015-09-01 19:41:39 +0530 | [diff] [blame] | 226 | u32 val; |
| 227 | |
| 228 | DRM_DEBUG_KMS("\n"); |
| 229 | |
| 230 | val = I915_READ(BXT_DSI_PLL_ENABLE); |
| 231 | val &= ~BXT_DSI_PLL_DO_ENABLE; |
| 232 | I915_WRITE(BXT_DSI_PLL_ENABLE, val); |
| 233 | |
| 234 | /* |
| 235 | * PLL lock should deassert within 200us. |
| 236 | * Wait up to 1ms before timing out. |
| 237 | */ |
Chris Wilson | 90a392c | 2016-06-30 15:33:19 +0100 | [diff] [blame] | 238 | if (intel_wait_for_register(dev_priv, |
| 239 | BXT_DSI_PLL_ENABLE, |
| 240 | BXT_DSI_PLL_LOCKED, |
| 241 | 0, |
| 242 | 1)) |
Shashank Sharma | fe88fc6 | 2015-09-01 19:41:39 +0530 | [diff] [blame] | 243 | DRM_ERROR("Timeout waiting for PLL lock deassertion\n"); |
| 244 | } |
| 245 | |
Jani Nikula | 1e78aa0 | 2016-03-16 12:21:40 +0200 | [diff] [blame] | 246 | static void assert_bpp_mismatch(enum mipi_dsi_pixel_format fmt, int pipe_bpp) |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 247 | { |
Jani Nikula | 1e78aa0 | 2016-03-16 12:21:40 +0200 | [diff] [blame] | 248 | int bpp = mipi_dsi_pixel_format_to_bpp(fmt); |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 249 | |
| 250 | WARN(bpp != pipe_bpp, |
Daniel Vetter | 7f3de83 | 2014-07-30 22:34:27 +0200 | [diff] [blame] | 251 | "bpp match assertion failure (expected %d, current %d)\n", |
| 252 | bpp, pipe_bpp); |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 253 | } |
| 254 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 255 | static u32 vlv_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp, |
| 256 | struct intel_crtc_state *config) |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 257 | { |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 258 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 259 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 260 | u32 dsi_clock, pclk; |
| 261 | u32 pll_ctl, pll_div; |
Jani Nikula | a856c5b | 2015-05-13 10:35:25 +0300 | [diff] [blame] | 262 | u32 m = 0, p = 0, n; |
Ville Syrjälä | ae9ec62 | 2016-03-15 16:40:05 +0200 | [diff] [blame] | 263 | int refclk = IS_CHERRYVIEW(dev_priv) ? 100000 : 25000; |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 264 | int i; |
| 265 | |
| 266 | DRM_DEBUG_KMS("\n"); |
| 267 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 268 | mutex_lock(&dev_priv->sb_lock); |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 269 | pll_ctl = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
| 270 | pll_div = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_DIVIDER); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 271 | mutex_unlock(&dev_priv->sb_lock); |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 272 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 273 | config->dsi_pll.ctrl = pll_ctl & ~DSI_PLL_LOCK; |
| 274 | config->dsi_pll.div = pll_div; |
| 275 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 276 | /* mask out other bits and extract the P1 divisor */ |
| 277 | pll_ctl &= DSI_PLL_P1_POST_DIV_MASK; |
| 278 | pll_ctl = pll_ctl >> (DSI_PLL_P1_POST_DIV_SHIFT - 2); |
| 279 | |
Jani Nikula | a856c5b | 2015-05-13 10:35:25 +0300 | [diff] [blame] | 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 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 284 | /* mask out the other bits and extract the M1 divisor */ |
| 285 | pll_div &= DSI_PLL_M1_DIV_MASK; |
| 286 | pll_div = pll_div >> DSI_PLL_M1_DIV_SHIFT; |
| 287 | |
| 288 | while (pll_ctl) { |
| 289 | pll_ctl = pll_ctl >> 1; |
| 290 | p++; |
| 291 | } |
| 292 | p--; |
| 293 | |
| 294 | if (!p) { |
| 295 | DRM_ERROR("wrong P1 divisor\n"); |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | for (i = 0; i < ARRAY_SIZE(lfsr_converts); i++) { |
| 300 | if (lfsr_converts[i] == pll_div) |
| 301 | break; |
| 302 | } |
| 303 | |
| 304 | if (i == ARRAY_SIZE(lfsr_converts)) { |
| 305 | DRM_ERROR("wrong m_seed programmed\n"); |
| 306 | return 0; |
| 307 | } |
| 308 | |
| 309 | m = i + 62; |
| 310 | |
Jani Nikula | a856c5b | 2015-05-13 10:35:25 +0300 | [diff] [blame] | 311 | dsi_clock = (m * refclk) / (p * n); |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 312 | |
| 313 | /* pixel_format and pipe_bpp should agree */ |
| 314 | assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp); |
| 315 | |
| 316 | pclk = DIV_ROUND_CLOSEST(dsi_clock * intel_dsi->lane_count, pipe_bpp); |
| 317 | |
| 318 | return pclk; |
| 319 | } |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 320 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 321 | static u32 bxt_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp, |
| 322 | struct intel_crtc_state *config) |
Shashank Sharma | ce0c982 | 2015-09-01 19:41:46 +0530 | [diff] [blame] | 323 | { |
| 324 | u32 pclk; |
| 325 | u32 dsi_clk; |
| 326 | u32 dsi_ratio; |
| 327 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 328 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Shashank Sharma | ce0c982 | 2015-09-01 19:41:46 +0530 | [diff] [blame] | 329 | |
| 330 | /* Divide by zero */ |
| 331 | if (!pipe_bpp) { |
| 332 | DRM_ERROR("Invalid BPP(0)\n"); |
| 333 | return 0; |
| 334 | } |
| 335 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 336 | config->dsi_pll.ctrl = I915_READ(BXT_DSI_PLL_CTL); |
Shashank Sharma | ce0c982 | 2015-09-01 19:41:46 +0530 | [diff] [blame] | 337 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 338 | dsi_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK; |
Shashank Sharma | ce0c982 | 2015-09-01 19:41:46 +0530 | [diff] [blame] | 339 | |
| 340 | dsi_clk = (dsi_ratio * BXT_REF_CLOCK_KHZ) / 2; |
| 341 | |
| 342 | /* pixel_format and pipe_bpp should agree */ |
| 343 | assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp); |
| 344 | |
| 345 | pclk = DIV_ROUND_CLOSEST(dsi_clk * intel_dsi->lane_count, pipe_bpp); |
| 346 | |
| 347 | DRM_DEBUG_DRIVER("Calculated pclk=%u\n", pclk); |
| 348 | return pclk; |
| 349 | } |
| 350 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 351 | u32 intel_dsi_get_pclk(struct intel_encoder *encoder, int pipe_bpp, |
| 352 | struct intel_crtc_state *config) |
Jani Nikula | d7d85d8 | 2016-01-08 12:45:39 +0200 | [diff] [blame] | 353 | { |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame^] | 354 | if (IS_BROXTON(to_i915(encoder->base.dev))) |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 355 | return bxt_dsi_get_pclk(encoder, pipe_bpp, config); |
Jani Nikula | d7d85d8 | 2016-01-08 12:45:39 +0200 | [diff] [blame] | 356 | else |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 357 | return vlv_dsi_get_pclk(encoder, pipe_bpp, config); |
Jani Nikula | d7d85d8 | 2016-01-08 12:45:39 +0200 | [diff] [blame] | 358 | } |
| 359 | |
kbuild test robot | b248e65 | 2015-10-05 16:21:11 +0800 | [diff] [blame] | 360 | static void vlv_dsi_reset_clocks(struct intel_encoder *encoder, enum port port) |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame] | 361 | { |
| 362 | u32 temp; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 363 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame] | 364 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 365 | |
| 366 | temp = I915_READ(MIPI_CTRL(port)); |
| 367 | temp &= ~ESCAPE_CLOCK_DIVIDER_MASK; |
| 368 | I915_WRITE(MIPI_CTRL(port), temp | |
| 369 | intel_dsi->escape_clk_div << |
| 370 | ESCAPE_CLOCK_DIVIDER_SHIFT); |
| 371 | } |
| 372 | |
Shashank Sharma | 11b8e4f | 2015-09-23 23:27:17 +0530 | [diff] [blame] | 373 | /* Program BXT Mipi clocks and dividers */ |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 374 | static void bxt_dsi_program_clocks(struct drm_device *dev, enum port port, |
| 375 | const struct intel_crtc_state *config) |
Shashank Sharma | 11b8e4f | 2015-09-23 23:27:17 +0530 | [diff] [blame] | 376 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 377 | struct drm_i915_private *dev_priv = to_i915(dev); |
Deepak M | 782d25c | 2016-02-15 22:43:57 +0530 | [diff] [blame] | 378 | u32 tmp; |
| 379 | u32 dsi_rate = 0; |
| 380 | u32 pll_ratio = 0; |
| 381 | u32 rx_div; |
| 382 | u32 tx_div; |
| 383 | u32 rx_div_upper; |
| 384 | u32 rx_div_lower; |
| 385 | u32 mipi_8by3_divider; |
Shashank Sharma | 11b8e4f | 2015-09-23 23:27:17 +0530 | [diff] [blame] | 386 | |
| 387 | /* Clear old configurations */ |
| 388 | tmp = I915_READ(BXT_MIPI_CLOCK_CTL); |
| 389 | tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port)); |
Deepak M | 782d25c | 2016-02-15 22:43:57 +0530 | [diff] [blame] | 390 | tmp &= ~(BXT_MIPI_RX_ESCLK_UPPER_FIXDIV_MASK(port)); |
| 391 | tmp &= ~(BXT_MIPI_8X_BY3_DIVIDER_MASK(port)); |
| 392 | tmp &= ~(BXT_MIPI_RX_ESCLK_LOWER_FIXDIV_MASK(port)); |
Shashank Sharma | 11b8e4f | 2015-09-23 23:27:17 +0530 | [diff] [blame] | 393 | |
| 394 | /* Get the current DSI rate(actual) */ |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 395 | pll_ratio = config->dsi_pll.ctrl & BXT_DSI_PLL_RATIO_MASK; |
Shashank Sharma | 11b8e4f | 2015-09-23 23:27:17 +0530 | [diff] [blame] | 396 | dsi_rate = (BXT_REF_CLOCK_KHZ * pll_ratio) / 2; |
| 397 | |
Deepak M | 782d25c | 2016-02-15 22:43:57 +0530 | [diff] [blame] | 398 | /* |
| 399 | * tx clock should be <= 20MHz and the div value must be |
| 400 | * subtracted by 1 as per bspec |
| 401 | */ |
| 402 | tx_div = DIV_ROUND_UP(dsi_rate, 20000) - 1; |
| 403 | /* |
| 404 | * rx clock should be <= 150MHz and the div value must be |
| 405 | * subtracted by 1 as per bspec |
| 406 | */ |
| 407 | rx_div = DIV_ROUND_UP(dsi_rate, 150000) - 1; |
Shashank Sharma | 11b8e4f | 2015-09-23 23:27:17 +0530 | [diff] [blame] | 408 | |
| 409 | /* |
Deepak M | 782d25c | 2016-02-15 22:43:57 +0530 | [diff] [blame] | 410 | * rx divider value needs to be updated in the |
| 411 | * two differnt bit fields in the register hence splitting the |
| 412 | * rx divider value accordingly |
Shashank Sharma | 11b8e4f | 2015-09-23 23:27:17 +0530 | [diff] [blame] | 413 | */ |
Deepak M | 782d25c | 2016-02-15 22:43:57 +0530 | [diff] [blame] | 414 | rx_div_lower = rx_div & RX_DIVIDER_BIT_1_2; |
| 415 | rx_div_upper = (rx_div & RX_DIVIDER_BIT_3_4) >> 2; |
Shashank Sharma | 11b8e4f | 2015-09-23 23:27:17 +0530 | [diff] [blame] | 416 | |
Deepak M | 782d25c | 2016-02-15 22:43:57 +0530 | [diff] [blame] | 417 | /* As per bpsec program the 8/3X clock divider to the below value */ |
| 418 | if (dev_priv->vbt.dsi.config->is_cmd_mode) |
| 419 | mipi_8by3_divider = 0x2; |
| 420 | else |
| 421 | mipi_8by3_divider = 0x3; |
| 422 | |
| 423 | tmp |= BXT_MIPI_8X_BY3_DIVIDER(port, mipi_8by3_divider); |
| 424 | tmp |= BXT_MIPI_TX_ESCLK_DIVIDER(port, tx_div); |
| 425 | tmp |= BXT_MIPI_RX_ESCLK_LOWER_DIVIDER(port, rx_div_lower); |
| 426 | tmp |= BXT_MIPI_RX_ESCLK_UPPER_DIVIDER(port, rx_div_upper); |
Shashank Sharma | 11b8e4f | 2015-09-23 23:27:17 +0530 | [diff] [blame] | 427 | |
| 428 | I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp); |
| 429 | } |
| 430 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 431 | static int bxt_compute_dsi_pll(struct intel_encoder *encoder, |
| 432 | struct intel_crtc_state *config) |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 433 | { |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 434 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 435 | u8 dsi_ratio; |
| 436 | u32 dsi_clk; |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 437 | |
| 438 | dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format, |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 439 | intel_dsi->lane_count); |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 440 | |
| 441 | /* |
| 442 | * From clock diagram, to get PLL ratio divider, divide double of DSI |
| 443 | * link rate (i.e., 2*8x=16x frequency value) by ref clock. Make sure to |
| 444 | * round 'up' the result |
| 445 | */ |
| 446 | dsi_ratio = DIV_ROUND_UP(dsi_clk * 2, BXT_REF_CLOCK_KHZ); |
| 447 | if (dsi_ratio < BXT_DSI_PLL_RATIO_MIN || |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 448 | dsi_ratio > BXT_DSI_PLL_RATIO_MAX) { |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 449 | DRM_ERROR("Cant get a suitable ratio from DSI PLL ratios\n"); |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 450 | return -ECHRNG; |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /* |
| 454 | * Program DSI ratio and Select MIPIC and MIPIA PLL output as 8x |
| 455 | * Spec says both have to be programmed, even if one is not getting |
| 456 | * used. Configure MIPI_CLOCK_CTL dividers in modeset |
| 457 | */ |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 458 | config->dsi_pll.ctrl = dsi_ratio | BXT_DSIA_16X_BY2 | BXT_DSIC_16X_BY2; |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 459 | |
| 460 | /* As per recommendation from hardware team, |
| 461 | * Prog PVD ratio =1 if dsi ratio <= 50 |
| 462 | */ |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 463 | if (dsi_ratio <= 50) |
| 464 | config->dsi_pll.ctrl |= BXT_DSI_PLL_PVD_RATIO_1; |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 465 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 466 | return 0; |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 467 | } |
| 468 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 469 | static void bxt_enable_dsi_pll(struct intel_encoder *encoder, |
| 470 | const struct intel_crtc_state *config) |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 471 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 472 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Shashank Sharma | 11b8e4f | 2015-09-23 23:27:17 +0530 | [diff] [blame] | 473 | struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); |
| 474 | enum port port; |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 475 | u32 val; |
| 476 | |
| 477 | DRM_DEBUG_KMS("\n"); |
| 478 | |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 479 | /* Configure PLL vales */ |
Ville Syrjälä | 062efa5 | 2016-04-12 22:14:36 +0300 | [diff] [blame] | 480 | I915_WRITE(BXT_DSI_PLL_CTL, config->dsi_pll.ctrl); |
| 481 | POSTING_READ(BXT_DSI_PLL_CTL); |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 482 | |
Shashank Sharma | 11b8e4f | 2015-09-23 23:27:17 +0530 | [diff] [blame] | 483 | /* Program TX, RX, Dphy clocks */ |
| 484 | for_each_dsi_port(port, intel_dsi->ports) |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 485 | bxt_dsi_program_clocks(encoder->base.dev, port, config); |
Shashank Sharma | 11b8e4f | 2015-09-23 23:27:17 +0530 | [diff] [blame] | 486 | |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 487 | /* Enable DSI PLL */ |
| 488 | val = I915_READ(BXT_DSI_PLL_ENABLE); |
| 489 | val |= BXT_DSI_PLL_DO_ENABLE; |
| 490 | I915_WRITE(BXT_DSI_PLL_ENABLE, val); |
| 491 | |
| 492 | /* Timeout and fail if PLL not locked */ |
Chris Wilson | 186f1c5 | 2016-06-30 15:33:20 +0100 | [diff] [blame] | 493 | if (intel_wait_for_register(dev_priv, |
| 494 | BXT_DSI_PLL_ENABLE, |
| 495 | BXT_DSI_PLL_LOCKED, |
| 496 | BXT_DSI_PLL_LOCKED, |
| 497 | 1)) { |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 498 | DRM_ERROR("Timed out waiting for DSI PLL to lock\n"); |
| 499 | return; |
| 500 | } |
| 501 | |
| 502 | DRM_DEBUG_KMS("DSI PLL locked\n"); |
| 503 | } |
| 504 | |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 505 | bool intel_dsi_pll_is_enabled(struct drm_i915_private *dev_priv) |
| 506 | { |
| 507 | if (IS_BROXTON(dev_priv)) |
| 508 | return bxt_dsi_pll_is_enabled(dev_priv); |
| 509 | |
| 510 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
| 511 | |
| 512 | return false; |
| 513 | } |
| 514 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 515 | int intel_compute_dsi_pll(struct intel_encoder *encoder, |
| 516 | struct intel_crtc_state *config) |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 517 | { |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame^] | 518 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 519 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame^] | 520 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 521 | return vlv_compute_dsi_pll(encoder, config); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame^] | 522 | else if (IS_BROXTON(dev_priv)) |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 523 | return bxt_compute_dsi_pll(encoder, config); |
| 524 | |
| 525 | return -ENODEV; |
| 526 | } |
| 527 | |
| 528 | void intel_enable_dsi_pll(struct intel_encoder *encoder, |
| 529 | const struct intel_crtc_state *config) |
| 530 | { |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame^] | 531 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 532 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame^] | 533 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 534 | vlv_enable_dsi_pll(encoder, config); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame^] | 535 | else if (IS_BROXTON(dev_priv)) |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 536 | bxt_enable_dsi_pll(encoder, config); |
Shashank Sharma | cfe01a5 | 2015-09-01 19:41:38 +0530 | [diff] [blame] | 537 | } |
Shashank Sharma | fe88fc6 | 2015-09-01 19:41:39 +0530 | [diff] [blame] | 538 | |
| 539 | void intel_disable_dsi_pll(struct intel_encoder *encoder) |
| 540 | { |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame^] | 541 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Shashank Sharma | fe88fc6 | 2015-09-01 19:41:39 +0530 | [diff] [blame] | 542 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame^] | 543 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Shashank Sharma | fe88fc6 | 2015-09-01 19:41:39 +0530 | [diff] [blame] | 544 | vlv_disable_dsi_pll(encoder); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame^] | 545 | else if (IS_BROXTON(dev_priv)) |
Shashank Sharma | fe88fc6 | 2015-09-01 19:41:39 +0530 | [diff] [blame] | 546 | bxt_disable_dsi_pll(encoder); |
| 547 | } |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame] | 548 | |
kbuild test robot | b248e65 | 2015-10-05 16:21:11 +0800 | [diff] [blame] | 549 | static void bxt_dsi_reset_clocks(struct intel_encoder *encoder, enum port port) |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame] | 550 | { |
| 551 | u32 tmp; |
| 552 | struct drm_device *dev = encoder->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 553 | struct drm_i915_private *dev_priv = to_i915(dev); |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame] | 554 | |
| 555 | /* Clear old configurations */ |
| 556 | tmp = I915_READ(BXT_MIPI_CLOCK_CTL); |
| 557 | tmp &= ~(BXT_MIPI_TX_ESCLK_FIXDIV_MASK(port)); |
Deepak M | 782d25c | 2016-02-15 22:43:57 +0530 | [diff] [blame] | 558 | tmp &= ~(BXT_MIPI_RX_ESCLK_UPPER_FIXDIV_MASK(port)); |
| 559 | tmp &= ~(BXT_MIPI_8X_BY3_DIVIDER_MASK(port)); |
| 560 | tmp &= ~(BXT_MIPI_RX_ESCLK_LOWER_FIXDIV_MASK(port)); |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame] | 561 | I915_WRITE(BXT_MIPI_CLOCK_CTL, tmp); |
| 562 | I915_WRITE(MIPI_EOT_DISABLE(port), CLOCKSTOP); |
| 563 | } |
| 564 | |
| 565 | void intel_dsi_reset_clocks(struct intel_encoder *encoder, enum port port) |
| 566 | { |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame^] | 567 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame] | 568 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame^] | 569 | if (IS_BROXTON(dev_priv)) |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame] | 570 | bxt_dsi_reset_clocks(encoder, port); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame^] | 571 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Shashank Sharma | b389a45 | 2015-09-01 19:41:44 +0530 | [diff] [blame] | 572 | vlv_dsi_reset_clocks(encoder, port); |
| 573 | } |