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