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 419edbd4a0SFrançois Tigeot struct dsi_mnp { 429edbd4a0SFrançois Tigeot u32 dsi_pll_ctrl; 439edbd4a0SFrançois Tigeot u32 dsi_pll_div; 449edbd4a0SFrançois Tigeot }; 459edbd4a0SFrançois Tigeot 469edbd4a0SFrançois Tigeot static const u32 lfsr_converts[] = { 479edbd4a0SFrançois Tigeot 426, 469, 234, 373, 442, 221, 110, 311, 411, /* 62 - 70 */ 489edbd4a0SFrançois Tigeot 461, 486, 243, 377, 188, 350, 175, 343, 427, 213, /* 71 - 80 */ 499edbd4a0SFrançois Tigeot 106, 53, 282, 397, 354, 227, 113, 56, 284, 142, /* 81 - 90 */ 509edbd4a0SFrançois Tigeot 71, 35 /* 91 - 92 */ 519edbd4a0SFrançois Tigeot }; 529edbd4a0SFrançois Tigeot 539edbd4a0SFrançois Tigeot #ifdef DSI_CLK_FROM_RR 549edbd4a0SFrançois Tigeot 559edbd4a0SFrançois Tigeot static u32 dsi_rr_formula(const struct drm_display_mode *mode, 569edbd4a0SFrançois Tigeot int pixel_format, int video_mode_format, 579edbd4a0SFrançois Tigeot int lane_count, bool eotp) 589edbd4a0SFrançois Tigeot { 599edbd4a0SFrançois Tigeot u32 bpp; 609edbd4a0SFrançois Tigeot u32 hactive, vactive, hfp, hsync, hbp, vfp, vsync, vbp; 619edbd4a0SFrançois Tigeot u32 hsync_bytes, hbp_bytes, hactive_bytes, hfp_bytes; 629edbd4a0SFrançois Tigeot u32 bytes_per_line, bytes_per_frame; 639edbd4a0SFrançois Tigeot u32 num_frames; 649edbd4a0SFrançois Tigeot u32 bytes_per_x_frames, bytes_per_x_frames_x_lanes; 659edbd4a0SFrançois Tigeot u32 dsi_bit_clock_hz; 669edbd4a0SFrançois Tigeot u32 dsi_clk; 679edbd4a0SFrançois Tigeot 689edbd4a0SFrançois Tigeot switch (pixel_format) { 699edbd4a0SFrançois Tigeot default: 709edbd4a0SFrançois Tigeot case VID_MODE_FORMAT_RGB888: 719edbd4a0SFrançois Tigeot case VID_MODE_FORMAT_RGB666_LOOSE: 729edbd4a0SFrançois Tigeot bpp = 24; 739edbd4a0SFrançois Tigeot break; 749edbd4a0SFrançois Tigeot case VID_MODE_FORMAT_RGB666: 759edbd4a0SFrançois Tigeot bpp = 18; 769edbd4a0SFrançois Tigeot break; 779edbd4a0SFrançois Tigeot case VID_MODE_FORMAT_RGB565: 789edbd4a0SFrançois Tigeot bpp = 16; 799edbd4a0SFrançois Tigeot break; 809edbd4a0SFrançois Tigeot } 819edbd4a0SFrançois Tigeot 829edbd4a0SFrançois Tigeot hactive = mode->hdisplay; 839edbd4a0SFrançois Tigeot vactive = mode->vdisplay; 849edbd4a0SFrançois Tigeot hfp = mode->hsync_start - mode->hdisplay; 859edbd4a0SFrançois Tigeot hsync = mode->hsync_end - mode->hsync_start; 869edbd4a0SFrançois Tigeot hbp = mode->htotal - mode->hsync_end; 879edbd4a0SFrançois Tigeot 889edbd4a0SFrançois Tigeot vfp = mode->vsync_start - mode->vdisplay; 899edbd4a0SFrançois Tigeot vsync = mode->vsync_end - mode->vsync_start; 909edbd4a0SFrançois Tigeot vbp = mode->vtotal - mode->vsync_end; 919edbd4a0SFrançois Tigeot 929edbd4a0SFrançois Tigeot hsync_bytes = DIV_ROUND_UP(hsync * bpp, 8); 939edbd4a0SFrançois Tigeot hbp_bytes = DIV_ROUND_UP(hbp * bpp, 8); 949edbd4a0SFrançois Tigeot hactive_bytes = DIV_ROUND_UP(hactive * bpp, 8); 959edbd4a0SFrançois Tigeot hfp_bytes = DIV_ROUND_UP(hfp * bpp, 8); 969edbd4a0SFrançois Tigeot 979edbd4a0SFrançois Tigeot bytes_per_line = DSI_HSS_PACKET_SIZE + hsync_bytes + 989edbd4a0SFrançois Tigeot DSI_HSA_PACKET_EXTRA_SIZE + DSI_HSE_PACKET_SIZE + 999edbd4a0SFrançois Tigeot hbp_bytes + DSI_HBP_PACKET_EXTRA_SIZE + 1009edbd4a0SFrançois Tigeot hactive_bytes + DSI_HACTIVE_PACKET_EXTRA_SIZE + 1019edbd4a0SFrançois Tigeot hfp_bytes + DSI_HFP_PACKET_EXTRA_SIZE; 1029edbd4a0SFrançois Tigeot 1039edbd4a0SFrançois Tigeot /* 1049edbd4a0SFrançois Tigeot * XXX: Need to accurately calculate LP to HS transition timeout and add 1059edbd4a0SFrançois Tigeot * it to bytes_per_line/bytes_per_frame. 1069edbd4a0SFrançois Tigeot */ 1079edbd4a0SFrançois Tigeot 1089edbd4a0SFrançois Tigeot if (eotp && video_mode_format == VIDEO_MODE_BURST) 1099edbd4a0SFrançois Tigeot bytes_per_line += DSI_EOTP_PACKET_SIZE; 1109edbd4a0SFrançois Tigeot 1119edbd4a0SFrançois Tigeot bytes_per_frame = vsync * bytes_per_line + vbp * bytes_per_line + 1129edbd4a0SFrançois Tigeot vactive * bytes_per_line + vfp * bytes_per_line; 1139edbd4a0SFrançois Tigeot 1149edbd4a0SFrançois Tigeot if (eotp && 1159edbd4a0SFrançois Tigeot (video_mode_format == VIDEO_MODE_NON_BURST_WITH_SYNC_PULSE || 1169edbd4a0SFrançois Tigeot video_mode_format == VIDEO_MODE_NON_BURST_WITH_SYNC_EVENTS)) 1179edbd4a0SFrançois Tigeot bytes_per_frame += DSI_EOTP_PACKET_SIZE; 1189edbd4a0SFrançois Tigeot 1199edbd4a0SFrançois Tigeot num_frames = drm_mode_vrefresh(mode); 1209edbd4a0SFrançois Tigeot bytes_per_x_frames = num_frames * bytes_per_frame; 1219edbd4a0SFrançois Tigeot 1229edbd4a0SFrançois Tigeot bytes_per_x_frames_x_lanes = bytes_per_x_frames / lane_count; 1239edbd4a0SFrançois Tigeot 1249edbd4a0SFrançois Tigeot /* the dsi clock is divided by 2 in the hardware to get dsi ddr clock */ 1259edbd4a0SFrançois Tigeot dsi_bit_clock_hz = bytes_per_x_frames_x_lanes * 8; 1269edbd4a0SFrançois Tigeot dsi_clk = dsi_bit_clock_hz / 1000; 1279edbd4a0SFrançois Tigeot 1289edbd4a0SFrançois Tigeot if (eotp && video_mode_format == VIDEO_MODE_BURST) 1299edbd4a0SFrançois Tigeot dsi_clk *= 2; 1309edbd4a0SFrançois Tigeot 1319edbd4a0SFrançois Tigeot return dsi_clk; 1329edbd4a0SFrançois Tigeot } 1339edbd4a0SFrançois Tigeot 1349edbd4a0SFrançois Tigeot #else 1359edbd4a0SFrançois Tigeot 1369edbd4a0SFrançois Tigeot /* Get DSI clock from pixel clock */ 137*1b13d190SFrançois Tigeot static u32 dsi_clk_from_pclk(u32 pclk, int pixel_format, int lane_count) 1389edbd4a0SFrançois Tigeot { 1399edbd4a0SFrançois Tigeot u32 dsi_clk_khz; 1409edbd4a0SFrançois Tigeot u32 bpp; 1419edbd4a0SFrançois Tigeot 1429edbd4a0SFrançois Tigeot switch (pixel_format) { 1439edbd4a0SFrançois Tigeot default: 1449edbd4a0SFrançois Tigeot case VID_MODE_FORMAT_RGB888: 1459edbd4a0SFrançois Tigeot case VID_MODE_FORMAT_RGB666_LOOSE: 1469edbd4a0SFrançois Tigeot bpp = 24; 1479edbd4a0SFrançois Tigeot break; 1489edbd4a0SFrançois Tigeot case VID_MODE_FORMAT_RGB666: 1499edbd4a0SFrançois Tigeot bpp = 18; 1509edbd4a0SFrançois Tigeot break; 1519edbd4a0SFrançois Tigeot case VID_MODE_FORMAT_RGB565: 1529edbd4a0SFrançois Tigeot bpp = 16; 1539edbd4a0SFrançois Tigeot break; 1549edbd4a0SFrançois Tigeot } 1559edbd4a0SFrançois Tigeot 1569edbd4a0SFrançois Tigeot /* DSI data rate = pixel clock * bits per pixel / lane count 1579edbd4a0SFrançois Tigeot pixel clock is converted from KHz to Hz */ 158*1b13d190SFrançois Tigeot dsi_clk_khz = DIV_ROUND_CLOSEST(pclk * bpp, lane_count); 1599edbd4a0SFrançois Tigeot 1609edbd4a0SFrançois Tigeot return dsi_clk_khz; 1619edbd4a0SFrançois Tigeot } 1629edbd4a0SFrançois Tigeot 1639edbd4a0SFrançois Tigeot #endif 1649edbd4a0SFrançois Tigeot 1659edbd4a0SFrançois Tigeot static int dsi_calc_mnp(u32 dsi_clk, struct dsi_mnp *dsi_mnp) 1669edbd4a0SFrançois Tigeot { 1679edbd4a0SFrançois Tigeot u32 m, n, p; 1689edbd4a0SFrançois Tigeot u32 ref_clk; 1699edbd4a0SFrançois Tigeot u32 error; 1709edbd4a0SFrançois Tigeot u32 tmp_error; 1719edbd4a0SFrançois Tigeot int target_dsi_clk; 1729edbd4a0SFrançois Tigeot int calc_dsi_clk; 1739edbd4a0SFrançois Tigeot u32 calc_m; 1749edbd4a0SFrançois Tigeot u32 calc_p; 1759edbd4a0SFrançois Tigeot u32 m_seed; 1769edbd4a0SFrançois Tigeot 1779edbd4a0SFrançois Tigeot /* dsi_clk is expected in KHZ */ 1789edbd4a0SFrançois Tigeot if (dsi_clk < 300000 || dsi_clk > 1150000) { 1799edbd4a0SFrançois Tigeot DRM_ERROR("DSI CLK Out of Range\n"); 1809edbd4a0SFrançois Tigeot return -ECHRNG; 1819edbd4a0SFrançois Tigeot } 1829edbd4a0SFrançois Tigeot 1839edbd4a0SFrançois Tigeot ref_clk = 25000; 1849edbd4a0SFrançois Tigeot target_dsi_clk = dsi_clk; 1859edbd4a0SFrançois Tigeot error = 0xFFFFFFFF; 1869edbd4a0SFrançois Tigeot tmp_error = 0xFFFFFFFF; 1879edbd4a0SFrançois Tigeot calc_m = 0; 1889edbd4a0SFrançois Tigeot calc_p = 0; 1899edbd4a0SFrançois Tigeot 1909edbd4a0SFrançois Tigeot for (m = 62; m <= 92; m++) { 1919edbd4a0SFrançois Tigeot for (p = 2; p <= 6; p++) { 1929edbd4a0SFrançois Tigeot /* Find the optimal m and p divisors 1939edbd4a0SFrançois Tigeot with minimal error +/- the required clock */ 1949edbd4a0SFrançois Tigeot calc_dsi_clk = (m * ref_clk) / p; 1959edbd4a0SFrançois Tigeot if (calc_dsi_clk == target_dsi_clk) { 1969edbd4a0SFrançois Tigeot calc_m = m; 1979edbd4a0SFrançois Tigeot calc_p = p; 1989edbd4a0SFrançois Tigeot error = 0; 1999edbd4a0SFrançois Tigeot break; 2009edbd4a0SFrançois Tigeot } else 2019edbd4a0SFrançois Tigeot tmp_error = abs(target_dsi_clk - calc_dsi_clk); 2029edbd4a0SFrançois Tigeot 2039edbd4a0SFrançois Tigeot if (tmp_error < error) { 2049edbd4a0SFrançois Tigeot error = tmp_error; 2059edbd4a0SFrançois Tigeot calc_m = m; 2069edbd4a0SFrançois Tigeot calc_p = p; 2079edbd4a0SFrançois Tigeot } 2089edbd4a0SFrançois Tigeot } 2099edbd4a0SFrançois Tigeot 2109edbd4a0SFrançois Tigeot if (error == 0) 2119edbd4a0SFrançois Tigeot break; 2129edbd4a0SFrançois Tigeot } 2139edbd4a0SFrançois Tigeot 2149edbd4a0SFrançois Tigeot m_seed = lfsr_converts[calc_m - 62]; 2159edbd4a0SFrançois Tigeot n = 1; 2169edbd4a0SFrançois Tigeot dsi_mnp->dsi_pll_ctrl = 1 << (DSI_PLL_P1_POST_DIV_SHIFT + calc_p - 2); 2179edbd4a0SFrançois Tigeot dsi_mnp->dsi_pll_div = (n - 1) << DSI_PLL_N1_DIV_SHIFT | 2189edbd4a0SFrançois Tigeot m_seed << DSI_PLL_M1_DIV_SHIFT; 2199edbd4a0SFrançois Tigeot 2209edbd4a0SFrançois Tigeot return 0; 2219edbd4a0SFrançois Tigeot } 2229edbd4a0SFrançois Tigeot 2239edbd4a0SFrançois Tigeot /* 2249edbd4a0SFrançois Tigeot * XXX: The muxing and gating is hard coded for now. Need to add support for 2259edbd4a0SFrançois Tigeot * sharing PLLs with two DSI outputs. 2269edbd4a0SFrançois Tigeot */ 2279edbd4a0SFrançois Tigeot static void vlv_configure_dsi_pll(struct intel_encoder *encoder) 2289edbd4a0SFrançois Tigeot { 2299edbd4a0SFrançois Tigeot struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; 2309edbd4a0SFrançois Tigeot struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 2319edbd4a0SFrançois Tigeot int ret; 2329edbd4a0SFrançois Tigeot struct dsi_mnp dsi_mnp; 2339edbd4a0SFrançois Tigeot u32 dsi_clk; 2349edbd4a0SFrançois Tigeot 235*1b13d190SFrançois Tigeot dsi_clk = dsi_clk_from_pclk(intel_dsi->pclk, intel_dsi->pixel_format, 2369edbd4a0SFrançois Tigeot intel_dsi->lane_count); 2379edbd4a0SFrançois Tigeot 2389edbd4a0SFrançois Tigeot ret = dsi_calc_mnp(dsi_clk, &dsi_mnp); 2399edbd4a0SFrançois Tigeot if (ret) { 2409edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("dsi_calc_mnp failed\n"); 2419edbd4a0SFrançois Tigeot return; 2429edbd4a0SFrançois Tigeot } 2439edbd4a0SFrançois Tigeot 2449edbd4a0SFrançois Tigeot dsi_mnp.dsi_pll_ctrl |= DSI_PLL_CLK_GATE_DSI0_DSIPLL; 2459edbd4a0SFrançois Tigeot 2469edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("dsi pll div %08x, ctrl %08x\n", 2479edbd4a0SFrançois Tigeot dsi_mnp.dsi_pll_div, dsi_mnp.dsi_pll_ctrl); 2489edbd4a0SFrançois Tigeot 2499edbd4a0SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, 0); 2509edbd4a0SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_DIVIDER, dsi_mnp.dsi_pll_div); 2519edbd4a0SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, dsi_mnp.dsi_pll_ctrl); 2529edbd4a0SFrançois Tigeot } 2539edbd4a0SFrançois Tigeot 2549edbd4a0SFrançois Tigeot void vlv_enable_dsi_pll(struct intel_encoder *encoder) 2559edbd4a0SFrançois Tigeot { 2569edbd4a0SFrançois Tigeot struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; 2579edbd4a0SFrançois Tigeot u32 tmp; 2589edbd4a0SFrançois Tigeot 2599edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("\n"); 2609edbd4a0SFrançois Tigeot 2619edbd4a0SFrançois Tigeot mutex_lock(&dev_priv->dpio_lock); 2629edbd4a0SFrançois Tigeot 2639edbd4a0SFrançois Tigeot vlv_configure_dsi_pll(encoder); 2649edbd4a0SFrançois Tigeot 2659edbd4a0SFrançois Tigeot /* wait at least 0.5 us after ungating before enabling VCO */ 2669edbd4a0SFrançois Tigeot usleep_range(1, 10); 2679edbd4a0SFrançois Tigeot 2689edbd4a0SFrançois Tigeot tmp = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); 2699edbd4a0SFrançois Tigeot tmp |= DSI_PLL_VCO_EN; 2709edbd4a0SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, tmp); 2719edbd4a0SFrançois Tigeot 2729edbd4a0SFrançois Tigeot mutex_unlock(&dev_priv->dpio_lock); 2739edbd4a0SFrançois Tigeot 2749edbd4a0SFrançois Tigeot if (wait_for(I915_READ(PIPECONF(PIPE_A)) & PIPECONF_DSI_PLL_LOCKED, 20)) { 2759edbd4a0SFrançois Tigeot DRM_ERROR("DSI PLL lock failed\n"); 2769edbd4a0SFrançois Tigeot return; 2779edbd4a0SFrançois Tigeot } 2789edbd4a0SFrançois Tigeot 2799edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("DSI PLL locked\n"); 2809edbd4a0SFrançois Tigeot } 2819edbd4a0SFrançois Tigeot 2829edbd4a0SFrançois Tigeot void vlv_disable_dsi_pll(struct intel_encoder *encoder) 2839edbd4a0SFrançois Tigeot { 2849edbd4a0SFrançois Tigeot struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; 2859edbd4a0SFrançois Tigeot u32 tmp; 2869edbd4a0SFrançois Tigeot 2879edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("\n"); 2889edbd4a0SFrançois Tigeot 2899edbd4a0SFrançois Tigeot mutex_lock(&dev_priv->dpio_lock); 2909edbd4a0SFrançois Tigeot 2919edbd4a0SFrançois Tigeot tmp = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); 2929edbd4a0SFrançois Tigeot tmp &= ~DSI_PLL_VCO_EN; 2939edbd4a0SFrançois Tigeot tmp |= DSI_PLL_LDO_GATE; 2949edbd4a0SFrançois Tigeot vlv_cck_write(dev_priv, CCK_REG_DSI_PLL_CONTROL, tmp); 2959edbd4a0SFrançois Tigeot 2969edbd4a0SFrançois Tigeot mutex_unlock(&dev_priv->dpio_lock); 2979edbd4a0SFrançois Tigeot } 29824edb884SFrançois Tigeot 29924edb884SFrançois Tigeot static void assert_bpp_mismatch(int pixel_format, int pipe_bpp) 30024edb884SFrançois Tigeot { 30124edb884SFrançois Tigeot int bpp; 30224edb884SFrançois Tigeot 30324edb884SFrançois Tigeot switch (pixel_format) { 30424edb884SFrançois Tigeot default: 30524edb884SFrançois Tigeot case VID_MODE_FORMAT_RGB888: 30624edb884SFrançois Tigeot case VID_MODE_FORMAT_RGB666_LOOSE: 30724edb884SFrançois Tigeot bpp = 24; 30824edb884SFrançois Tigeot break; 30924edb884SFrançois Tigeot case VID_MODE_FORMAT_RGB666: 31024edb884SFrançois Tigeot bpp = 18; 31124edb884SFrançois Tigeot break; 31224edb884SFrançois Tigeot case VID_MODE_FORMAT_RGB565: 31324edb884SFrançois Tigeot bpp = 16; 31424edb884SFrançois Tigeot break; 31524edb884SFrançois Tigeot } 31624edb884SFrançois Tigeot 31724edb884SFrançois Tigeot WARN(bpp != pipe_bpp, 31824edb884SFrançois Tigeot "bpp match assertion failure (expected %d, current %d)\n", 31924edb884SFrançois Tigeot bpp, pipe_bpp); 32024edb884SFrançois Tigeot } 32124edb884SFrançois Tigeot 32224edb884SFrançois Tigeot u32 vlv_get_dsi_pclk(struct intel_encoder *encoder, int pipe_bpp) 32324edb884SFrançois Tigeot { 32424edb884SFrançois Tigeot struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; 32524edb884SFrançois Tigeot struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base); 32624edb884SFrançois Tigeot u32 dsi_clock, pclk; 32724edb884SFrançois Tigeot u32 pll_ctl, pll_div; 32824edb884SFrançois Tigeot u32 m = 0, p = 0; 32924edb884SFrançois Tigeot int refclk = 25000; 33024edb884SFrançois Tigeot int i; 33124edb884SFrançois Tigeot 33224edb884SFrançois Tigeot DRM_DEBUG_KMS("\n"); 33324edb884SFrançois Tigeot 33424edb884SFrançois Tigeot mutex_lock(&dev_priv->dpio_lock); 33524edb884SFrançois Tigeot pll_ctl = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); 33624edb884SFrançois Tigeot pll_div = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_DIVIDER); 33724edb884SFrançois Tigeot mutex_unlock(&dev_priv->dpio_lock); 33824edb884SFrançois Tigeot 33924edb884SFrançois Tigeot /* mask out other bits and extract the P1 divisor */ 34024edb884SFrançois Tigeot pll_ctl &= DSI_PLL_P1_POST_DIV_MASK; 34124edb884SFrançois Tigeot pll_ctl = pll_ctl >> (DSI_PLL_P1_POST_DIV_SHIFT - 2); 34224edb884SFrançois Tigeot 34324edb884SFrançois Tigeot /* mask out the other bits and extract the M1 divisor */ 34424edb884SFrançois Tigeot pll_div &= DSI_PLL_M1_DIV_MASK; 34524edb884SFrançois Tigeot pll_div = pll_div >> DSI_PLL_M1_DIV_SHIFT; 34624edb884SFrançois Tigeot 34724edb884SFrançois Tigeot while (pll_ctl) { 34824edb884SFrançois Tigeot pll_ctl = pll_ctl >> 1; 34924edb884SFrançois Tigeot p++; 35024edb884SFrançois Tigeot } 35124edb884SFrançois Tigeot p--; 35224edb884SFrançois Tigeot 35324edb884SFrançois Tigeot if (!p) { 35424edb884SFrançois Tigeot DRM_ERROR("wrong P1 divisor\n"); 35524edb884SFrançois Tigeot return 0; 35624edb884SFrançois Tigeot } 35724edb884SFrançois Tigeot 35824edb884SFrançois Tigeot for (i = 0; i < ARRAY_SIZE(lfsr_converts); i++) { 35924edb884SFrançois Tigeot if (lfsr_converts[i] == pll_div) 36024edb884SFrançois Tigeot break; 36124edb884SFrançois Tigeot } 36224edb884SFrançois Tigeot 36324edb884SFrançois Tigeot if (i == ARRAY_SIZE(lfsr_converts)) { 36424edb884SFrançois Tigeot DRM_ERROR("wrong m_seed programmed\n"); 36524edb884SFrançois Tigeot return 0; 36624edb884SFrançois Tigeot } 36724edb884SFrançois Tigeot 36824edb884SFrançois Tigeot m = i + 62; 36924edb884SFrançois Tigeot 37024edb884SFrançois Tigeot dsi_clock = (m * refclk) / p; 37124edb884SFrançois Tigeot 37224edb884SFrançois Tigeot /* pixel_format and pipe_bpp should agree */ 37324edb884SFrançois Tigeot assert_bpp_mismatch(intel_dsi->pixel_format, pipe_bpp); 37424edb884SFrançois Tigeot 37524edb884SFrançois Tigeot pclk = DIV_ROUND_CLOSEST(dsi_clock * intel_dsi->lane_count, pipe_bpp); 37624edb884SFrançois Tigeot 37724edb884SFrançois Tigeot return pclk; 37824edb884SFrançois Tigeot } 379