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 339edbd4a0SFrançois Tigeot #define DSI_HSS_PACKET_SIZE 4 349edbd4a0SFrançois Tigeot #define DSI_HSE_PACKET_SIZE 4 359edbd4a0SFrançois Tigeot #define DSI_HSA_PACKET_EXTRA_SIZE 6 369edbd4a0SFrançois Tigeot #define DSI_HBP_PACKET_EXTRA_SIZE 6 379edbd4a0SFrançois Tigeot #define DSI_HACTIVE_PACKET_EXTRA_SIZE 6 389edbd4a0SFrançois Tigeot #define DSI_HFP_PACKET_EXTRA_SIZE 6 399edbd4a0SFrançois Tigeot #define DSI_EOTP_PACKET_SIZE 4 409edbd4a0SFrançois Tigeot 41*a05eeebfSFrançois Tigeot static int dsi_pixel_format_bpp(int pixel_format) 42*a05eeebfSFrançois Tigeot { 43*a05eeebfSFrançois Tigeot int bpp; 44*a05eeebfSFrançois Tigeot 45*a05eeebfSFrançois Tigeot switch (pixel_format) { 46*a05eeebfSFrançois Tigeot default: 47*a05eeebfSFrançois Tigeot case VID_MODE_FORMAT_RGB888: 48*a05eeebfSFrançois Tigeot case VID_MODE_FORMAT_RGB666_LOOSE: 49*a05eeebfSFrançois Tigeot bpp = 24; 50*a05eeebfSFrançois Tigeot break; 51*a05eeebfSFrançois Tigeot case VID_MODE_FORMAT_RGB666: 52*a05eeebfSFrançois Tigeot bpp = 18; 53*a05eeebfSFrançois Tigeot break; 54*a05eeebfSFrançois Tigeot case VID_MODE_FORMAT_RGB565: 55*a05eeebfSFrançois Tigeot bpp = 16; 56*a05eeebfSFrançois Tigeot break; 57*a05eeebfSFrançois Tigeot } 58*a05eeebfSFrançois Tigeot 59*a05eeebfSFrançois Tigeot return bpp; 60*a05eeebfSFrançois Tigeot } 61*a05eeebfSFrançois Tigeot 629edbd4a0SFrançois Tigeot struct dsi_mnp { 639edbd4a0SFrançois Tigeot u32 dsi_pll_ctrl; 649edbd4a0SFrançois Tigeot u32 dsi_pll_div; 659edbd4a0SFrançois Tigeot }; 669edbd4a0SFrançois Tigeot 679edbd4a0SFrançois Tigeot static const u32 lfsr_converts[] = { 689edbd4a0SFrançois Tigeot 426, 469, 234, 373, 442, 221, 110, 311, 411, /* 62 - 70 */ 699edbd4a0SFrançois Tigeot 461, 486, 243, 377, 188, 350, 175, 343, 427, 213, /* 71 - 80 */ 70*a05eeebfSFrançois Tigeot 106, 53, 282, 397, 454, 227, 113, 56, 284, 142, /* 81 - 90 */ 71*a05eeebfSFrançois Tigeot 71, 35, 273, 136, 324, 418, 465, 488, 500, 506 /* 91 - 100 */ 729edbd4a0SFrançois Tigeot }; 739edbd4a0SFrançois Tigeot 749edbd4a0SFrançois Tigeot #ifdef DSI_CLK_FROM_RR 759edbd4a0SFrançois Tigeot 769edbd4a0SFrançois Tigeot static u32 dsi_rr_formula(const struct drm_display_mode *mode, 779edbd4a0SFrançois Tigeot int pixel_format, int video_mode_format, 789edbd4a0SFrançois Tigeot int lane_count, bool eotp) 799edbd4a0SFrançois Tigeot { 809edbd4a0SFrançois Tigeot u32 bpp; 819edbd4a0SFrançois Tigeot u32 hactive, vactive, hfp, hsync, hbp, vfp, vsync, vbp; 829edbd4a0SFrançois Tigeot u32 hsync_bytes, hbp_bytes, hactive_bytes, hfp_bytes; 839edbd4a0SFrançois Tigeot u32 bytes_per_line, bytes_per_frame; 849edbd4a0SFrançois Tigeot u32 num_frames; 859edbd4a0SFrançois Tigeot u32 bytes_per_x_frames, bytes_per_x_frames_x_lanes; 869edbd4a0SFrançois Tigeot u32 dsi_bit_clock_hz; 879edbd4a0SFrançois Tigeot u32 dsi_clk; 889edbd4a0SFrançois Tigeot 89*a05eeebfSFrançois Tigeot bpp = dsi_pixel_format_bpp(pixel_format); 909edbd4a0SFrançois Tigeot 919edbd4a0SFrançois Tigeot hactive = mode->hdisplay; 929edbd4a0SFrançois Tigeot vactive = mode->vdisplay; 939edbd4a0SFrançois Tigeot hfp = mode->hsync_start - mode->hdisplay; 949edbd4a0SFrançois Tigeot hsync = mode->hsync_end - mode->hsync_start; 959edbd4a0SFrançois Tigeot hbp = mode->htotal - mode->hsync_end; 969edbd4a0SFrançois Tigeot 979edbd4a0SFrançois Tigeot vfp = mode->vsync_start - mode->vdisplay; 989edbd4a0SFrançois Tigeot vsync = mode->vsync_end - mode->vsync_start; 999edbd4a0SFrançois Tigeot vbp = mode->vtotal - mode->vsync_end; 1009edbd4a0SFrançois Tigeot 1019edbd4a0SFrançois Tigeot hsync_bytes = DIV_ROUND_UP(hsync * bpp, 8); 1029edbd4a0SFrançois Tigeot hbp_bytes = DIV_ROUND_UP(hbp * bpp, 8); 1039edbd4a0SFrançois Tigeot hactive_bytes = DIV_ROUND_UP(hactive * bpp, 8); 1049edbd4a0SFrançois Tigeot hfp_bytes = DIV_ROUND_UP(hfp * bpp, 8); 1059edbd4a0SFrançois Tigeot 1069edbd4a0SFrançois Tigeot bytes_per_line = DSI_HSS_PACKET_SIZE + hsync_bytes + 1079edbd4a0SFrançois Tigeot DSI_HSA_PACKET_EXTRA_SIZE + DSI_HSE_PACKET_SIZE + 1089edbd4a0SFrançois Tigeot hbp_bytes + DSI_HBP_PACKET_EXTRA_SIZE + 1099edbd4a0SFrançois Tigeot hactive_bytes + DSI_HACTIVE_PACKET_EXTRA_SIZE + 1109edbd4a0SFrançois Tigeot hfp_bytes + DSI_HFP_PACKET_EXTRA_SIZE; 1119edbd4a0SFrançois Tigeot 1129edbd4a0SFrançois Tigeot /* 1139edbd4a0SFrançois Tigeot * XXX: Need to accurately calculate LP to HS transition timeout and add 1149edbd4a0SFrançois Tigeot * it to bytes_per_line/bytes_per_frame. 1159edbd4a0SFrançois Tigeot */ 1169edbd4a0SFrançois Tigeot 1179edbd4a0SFrançois Tigeot if (eotp && video_mode_format == VIDEO_MODE_BURST) 1189edbd4a0SFrançois Tigeot bytes_per_line += DSI_EOTP_PACKET_SIZE; 1199edbd4a0SFrançois Tigeot 1209edbd4a0SFrançois Tigeot bytes_per_frame = vsync * bytes_per_line + vbp * bytes_per_line + 1219edbd4a0SFrançois Tigeot vactive * bytes_per_line + vfp * bytes_per_line; 1229edbd4a0SFrançois Tigeot 1239edbd4a0SFrançois Tigeot if (eotp && 1249edbd4a0SFrançois Tigeot (video_mode_format == VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE || 1259edbd4a0SFrançois Tigeot video_mode_format == VIDEO_MODE_NON_BURST_WITH_SYNC_EVENTS)) 1269edbd4a0SFrançois Tigeot bytes_per_frame += DSI_EOTP_PACKET_SIZE; 1279edbd4a0SFrançois Tigeot 1289edbd4a0SFrançois Tigeot num_frames = drm_mode_vrefresh(mode); 1299edbd4a0SFrançois Tigeot bytes_per_x_frames = num_frames * bytes_per_frame; 1309edbd4a0SFrançois Tigeot 1319edbd4a0SFrançois Tigeot bytes_per_x_frames_x_lanes = bytes_per_x_frames / lane_count; 1329edbd4a0SFrançois Tigeot 1339edbd4a0SFrançois Tigeot /* the dsi clock is divided by 2 in the hardware to get dsi ddr clock */ 1349edbd4a0SFrançois Tigeot dsi_bit_clock_hz = bytes_per_x_frames_x_lanes * 8; 1359edbd4a0SFrançois Tigeot dsi_clk = dsi_bit_clock_hz / 1000; 1369edbd4a0SFrançois Tigeot 1379edbd4a0SFrançois Tigeot if (eotp && video_mode_format == VIDEO_MODE_BURST) 1389edbd4a0SFrançois Tigeot dsi_clk *= 2; 1399edbd4a0SFrançois Tigeot 1409edbd4a0SFrançois Tigeot return dsi_clk; 1419edbd4a0SFrançois Tigeot } 1429edbd4a0SFrançois Tigeot 1439edbd4a0SFrançois Tigeot #else 1449edbd4a0SFrançois Tigeot 1459edbd4a0SFrançois Tigeot /* Get DSI clock from pixel clock */ 1461b13d190SFrançois Tigeot static u32 dsi_clk_from_pclk(u32 pclk, int pixel_format, int lane_count) 1479edbd4a0SFrançois Tigeot { 1489edbd4a0SFrançois Tigeot u32 dsi_clk_khz; 149*a05eeebfSFrançois Tigeot u32 bpp = dsi_pixel_format_bpp(pixel_format); 1509edbd4a0SFrançois Tigeot 1519edbd4a0SFrançois Tigeot /* DSI data rate = pixel clock * bits per pixel / lane count 1529edbd4a0SFrançois Tigeot pixel clock is converted from KHz to Hz */ 1531b13d190SFrançois Tigeot dsi_clk_khz = DIV_ROUND_CLOSEST(pclk * bpp, lane_count); 1549edbd4a0SFrançois Tigeot 1559edbd4a0SFrançois Tigeot return dsi_clk_khz; 1569edbd4a0SFrançois Tigeot } 1579edbd4a0SFrançois Tigeot 1589edbd4a0SFrançois Tigeot #endif 1599edbd4a0SFrançois Tigeot 160*a05eeebfSFrançois Tigeot static int dsi_calc_mnp(struct drm_i915_private *dev_priv, 161*a05eeebfSFrançois Tigeot struct dsi_mnp *dsi_mnp, int target_dsi_clk) 1629edbd4a0SFrançois Tigeot { 16319c468b4SFrançois Tigeot unsigned int calc_m = 0, calc_p = 0; 164*a05eeebfSFrançois Tigeot unsigned int m_min, m_max, p_min = 2, p_max = 6; 165*a05eeebfSFrançois Tigeot unsigned int m, n, p; 166*a05eeebfSFrançois Tigeot int ref_clk; 16719c468b4SFrançois Tigeot int delta = target_dsi_clk; 1689edbd4a0SFrançois Tigeot u32 m_seed; 1699edbd4a0SFrançois Tigeot 17019c468b4SFrançois Tigeot /* target_dsi_clk is expected in kHz */ 17119c468b4SFrançois Tigeot if (target_dsi_clk < 300000 || target_dsi_clk > 1150000) { 1729edbd4a0SFrançois Tigeot DRM_ERROR("DSI CLK Out of Range\n"); 1739edbd4a0SFrançois Tigeot return -ECHRNG; 1749edbd4a0SFrançois Tigeot } 1759edbd4a0SFrançois Tigeot 176*a05eeebfSFrançois Tigeot if (IS_CHERRYVIEW(dev_priv)) { 177*a05eeebfSFrançois Tigeot ref_clk = 100000; 178*a05eeebfSFrançois Tigeot n = 4; 179*a05eeebfSFrançois Tigeot m_min = 70; 180*a05eeebfSFrançois Tigeot m_max = 96; 181*a05eeebfSFrançois Tigeot } else { 182*a05eeebfSFrançois Tigeot ref_clk = 25000; 183*a05eeebfSFrançois Tigeot n = 1; 184*a05eeebfSFrançois Tigeot m_min = 62; 185*a05eeebfSFrançois Tigeot m_max = 92; 186*a05eeebfSFrançois Tigeot } 187*a05eeebfSFrançois Tigeot 188*a05eeebfSFrançois Tigeot for (m = m_min; m <= m_max && delta; m++) { 189*a05eeebfSFrançois Tigeot for (p = p_min; p <= p_max && delta; p++) { 19019c468b4SFrançois Tigeot /* 19119c468b4SFrançois Tigeot * Find the optimal m and p divisors with minimal delta 19219c468b4SFrançois Tigeot * +/- the required clock 19319c468b4SFrançois Tigeot */ 19419c468b4SFrançois Tigeot int calc_dsi_clk = (m * ref_clk) / (p * n); 19519c468b4SFrançois Tigeot int d = abs(target_dsi_clk - calc_dsi_clk); 19619c468b4SFrançois Tigeot if (d < delta) { 19719c468b4SFrançois Tigeot delta = d; 1989edbd4a0SFrançois Tigeot calc_m = m; 1999edbd4a0SFrançois Tigeot calc_p = p; 2009edbd4a0SFrançois Tigeot } 2019edbd4a0SFrançois Tigeot } 2029edbd4a0SFrançois Tigeot } 2039edbd4a0SFrançois Tigeot 20419c468b4SFrançois Tigeot /* register has log2(N1), this works fine for powers of two */ 20519c468b4SFrançois Tigeot n = ffs(n) - 1; 2069edbd4a0SFrançois Tigeot m_seed = lfsr_converts[calc_m - 62]; 2079edbd4a0SFrançois Tigeot dsi_mnp->dsi_pll_ctrl = 1 << (DSI_PLL_P1_POST_DIV_SHIFT + calc_p - 2); 20819c468b4SFrançois Tigeot dsi_mnp->dsi_pll_div = n << DSI_PLL_N1_DIV_SHIFT | 2099edbd4a0SFrançois Tigeot m_seed << DSI_PLL_M1_DIV_SHIFT; 2109edbd4a0SFrançois Tigeot 2119edbd4a0SFrançois Tigeot return 0; 2129edbd4a0SFrançois Tigeot } 2139edbd4a0SFrançois Tigeot 2149edbd4a0SFrançois Tigeot /* 2159edbd4a0SFrançois Tigeot * XXX: The muxing and gating is hard coded for now. Need to add support for 2169edbd4a0SFrançois Tigeot * sharing PLLs with two DSI outputs. 2179edbd4a0SFrançois Tigeot */ 2189edbd4a0SFrançois Tigeot static void vlv_configure_dsi_pll(struct intel_encoder *encoder) 2199edbd4a0SFrançois Tigeot { 2209edbd4a0SFrançois Tigeot struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; 2219edbd4a0SFrançois Tigeot struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 2229edbd4a0SFrançois Tigeot int ret; 2239edbd4a0SFrançois Tigeot struct dsi_mnp dsi_mnp; 2249edbd4a0SFrançois Tigeot u32 dsi_clk; 2259edbd4a0SFrançois Tigeot 2261b13d190SFrançois Tigeot dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format, 2279edbd4a0SFrançois Tigeot intel_dsi->lane_count); 2289edbd4a0SFrançois Tigeot 229*a05eeebfSFrançois Tigeot ret = dsi_calc_mnp(dev_priv, &dsi_mnp, dsi_clk); 2309edbd4a0SFrançois Tigeot if (ret) { 2319edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("dsi_calc_mnp failed\n"); 2329edbd4a0SFrançois Tigeot return; 2339edbd4a0SFrançois Tigeot } 2349edbd4a0SFrançois Tigeot 2352c9916cdSFrançois Tigeot if (intel_dsi->ports & (1 << PORT_A)) 2369edbd4a0SFrançois Tigeot dsi_mnp.dsi_pll_ctrl |= DSI_PLL_CLK_GATE_DSI0_DSIPLL; 2379edbd4a0SFrançois Tigeot 2382c9916cdSFrançois Tigeot if (intel_dsi->ports & (1 << PORT_C)) 2392c9916cdSFrançois Tigeot dsi_mnp.dsi_pll_ctrl |= DSI_PLL_CLK_GATE_DSI1_DSIPLL; 2402c9916cdSFrançois Tigeot 2419edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("dsi pll div %08x, ctrl %08x\n", 2429edbd4a0SFrançois Tigeot dsi_mnp.dsi_pll_div, dsi_mnp.dsi_pll_ctrl); 2439edbd4a0SFrançois Tigeot 2449edbd4a0SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, 0); 2459edbd4a0SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_DIVIDER, dsi_mnp.dsi_pll_div); 2469edbd4a0SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, dsi_mnp.dsi_pll_ctrl); 2479edbd4a0SFrançois Tigeot } 2489edbd4a0SFrançois Tigeot 2499edbd4a0SFrançois Tigeot void vlv_enable_dsi_pll(struct intel_encoder *encoder) 2509edbd4a0SFrançois Tigeot { 2519edbd4a0SFrançois Tigeot struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; 2529edbd4a0SFrançois Tigeot u32 tmp; 2539edbd4a0SFrançois Tigeot 2549edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("\n"); 2559edbd4a0SFrançois Tigeot 25619c468b4SFrançois Tigeot mutex_lock(&dev_priv->sb_lock); 2579edbd4a0SFrançois Tigeot 2589edbd4a0SFrançois Tigeot vlv_configure_dsi_pll(encoder); 2599edbd4a0SFrançois Tigeot 2609edbd4a0SFrançois Tigeot /* wait at least 0.5 us after ungating before enabling VCO */ 2619edbd4a0SFrançois Tigeot usleep_range(1, 10); 2629edbd4a0SFrançois Tigeot 2639edbd4a0SFrançois Tigeot tmp = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); 2649edbd4a0SFrançois Tigeot tmp |= DSI_PLL_VCO_EN; 2659edbd4a0SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, tmp); 2669edbd4a0SFrançois Tigeot 2672c9916cdSFrançois Tigeot if (wait_for(vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL) & 2682c9916cdSFrançois Tigeot DSI_PLL_LOCK, 20)) { 2699edbd4a0SFrançois Tigeot 27019c468b4SFrançois Tigeot mutex_unlock(&dev_priv->sb_lock); 2719edbd4a0SFrançois Tigeot DRM_ERROR("DSI PLL lock failed\n"); 2729edbd4a0SFrançois Tigeot return; 2739edbd4a0SFrançois Tigeot } 27419c468b4SFrançois Tigeot mutex_unlock(&dev_priv->sb_lock); 2759edbd4a0SFrançois Tigeot 2769edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("DSI PLL locked\n"); 2779edbd4a0SFrançois Tigeot } 2789edbd4a0SFrançois Tigeot 2799edbd4a0SFrançois Tigeot void vlv_disable_dsi_pll(struct intel_encoder *encoder) 2809edbd4a0SFrançois Tigeot { 2819edbd4a0SFrançois Tigeot struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; 2829edbd4a0SFrançois Tigeot u32 tmp; 2839edbd4a0SFrançois Tigeot 2849edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("\n"); 2859edbd4a0SFrançois Tigeot 28619c468b4SFrançois Tigeot mutex_lock(&dev_priv->sb_lock); 2879edbd4a0SFrançois Tigeot 2889edbd4a0SFrançois Tigeot tmp = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); 2899edbd4a0SFrançois Tigeot tmp &= ~DSI_PLL_VCO_EN; 2909edbd4a0SFrançois Tigeot tmp |= DSI_PLL_LDO_GATE; 2919edbd4a0SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, tmp); 2929edbd4a0SFrançois Tigeot 29319c468b4SFrançois Tigeot mutex_unlock(&dev_priv->sb_lock); 2949edbd4a0SFrançois Tigeot } 29524edb884SFrançois Tigeot 29624edb884SFrançois Tigeot static void assert_bpp_mismatch(int pixel_format, int pipe_bpp) 29724edb884SFrançois Tigeot { 298*a05eeebfSFrançois Tigeot int bpp = dsi_pixel_format_bpp(pixel_format); 29924edb884SFrançois Tigeot 30024edb884SFrançois Tigeot WARN(bpp != pipe_bpp, 30124edb884SFrançois Tigeot "bpp match assertion failure (expected %d, current %d)\n", 30224edb884SFrançois Tigeot bpp, pipe_bpp); 30324edb884SFrançois Tigeot } 30424edb884SFrançois Tigeot 30524edb884SFrançois Tigeot u32 vlv_get_dsi_pclk(struct intel_encoder *encoder, int pipe_bpp) 30624edb884SFrançois Tigeot { 30724edb884SFrançois Tigeot struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; 30824edb884SFrançois Tigeot struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 30924edb884SFrançois Tigeot u32 dsi_clock, pclk; 31024edb884SFrançois Tigeot u32 pll_ctl, pll_div; 31119c468b4SFrançois Tigeot u32 m = 0, p = 0, n; 31224edb884SFrançois Tigeot int refclk = 25000; 31324edb884SFrançois Tigeot int i; 31424edb884SFrançois Tigeot 31524edb884SFrançois Tigeot DRM_DEBUG_KMS("\n"); 31624edb884SFrançois Tigeot 31719c468b4SFrançois Tigeot mutex_lock(&dev_priv->sb_lock); 31824edb884SFrançois Tigeot pll_ctl = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); 31924edb884SFrançois Tigeot pll_div = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_DIVIDER); 32019c468b4SFrançois Tigeot mutex_unlock(&dev_priv->sb_lock); 32124edb884SFrançois Tigeot 32224edb884SFrançois Tigeot /* mask out other bits and extract the P1 divisor */ 32324edb884SFrançois Tigeot pll_ctl &= DSI_PLL_P1_POST_DIV_MASK; 32424edb884SFrançois Tigeot pll_ctl = pll_ctl >> (DSI_PLL_P1_POST_DIV_SHIFT - 2); 32524edb884SFrançois Tigeot 32619c468b4SFrançois Tigeot /* N1 divisor */ 32719c468b4SFrançois Tigeot n = (pll_div & DSI_PLL_N1_DIV_MASK) >> DSI_PLL_N1_DIV_SHIFT; 32819c468b4SFrançois Tigeot n = 1 << n; /* register has log2(N1) */ 32919c468b4SFrançois Tigeot 33024edb884SFrançois Tigeot /* mask out the other bits and extract the M1 divisor */ 33124edb884SFrançois Tigeot pll_div &= DSI_PLL_M1_DIV_MASK; 33224edb884SFrançois Tigeot pll_div = pll_div >> DSI_PLL_M1_DIV_SHIFT; 33324edb884SFrançois Tigeot 33424edb884SFrançois Tigeot while (pll_ctl) { 33524edb884SFrançois Tigeot pll_ctl = pll_ctl >> 1; 33624edb884SFrançois Tigeot p++; 33724edb884SFrançois Tigeot } 33824edb884SFrançois Tigeot p--; 33924edb884SFrançois Tigeot 34024edb884SFrançois Tigeot if (!p) { 34124edb884SFrançois Tigeot DRM_ERROR("wrong P1 divisor\n"); 34224edb884SFrançois Tigeot return 0; 34324edb884SFrançois Tigeot } 34424edb884SFrançois Tigeot 34524edb884SFrançois Tigeot for (i = 0; i < ARRAY_SIZE(lfsr_converts); i++) { 34624edb884SFrançois Tigeot if (lfsr_converts[i] == pll_div) 34724edb884SFrançois Tigeot break; 34824edb884SFrançois Tigeot } 34924edb884SFrançois Tigeot 35024edb884SFrançois Tigeot if (i == ARRAY_SIZE(lfsr_converts)) { 35124edb884SFrançois Tigeot DRM_ERROR("wrong m_seed programmed\n"); 35224edb884SFrançois Tigeot return 0; 35324edb884SFrançois Tigeot } 35424edb884SFrançois Tigeot 35524edb884SFrançois Tigeot m = i + 62; 35624edb884SFrançois Tigeot 35719c468b4SFrançois Tigeot dsi_clock = (m * refclk) / (p * n); 35824edb884SFrançois Tigeot 35924edb884SFrançois Tigeot /* pixel_format and pipe_bpp should agree */ 36024edb884SFrançois Tigeot assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp); 36124edb884SFrançois Tigeot 36224edb884SFrançois Tigeot pclk = DIV_ROUND_CLOSEST(dsi_clock * intel_dsi->lane_count, pipe_bpp); 36324edb884SFrançois Tigeot 36424edb884SFrançois Tigeot return pclk; 36524edb884SFrançois Tigeot } 366