18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright © 2006-2011 Intel Corporation 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Authors: 68c2ecf20Sopenharmony_ci * Eric Anholt <eric@anholt.net> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/delay.h> 108c2ecf20Sopenharmony_ci#include <linux/i2c.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <drm/drm_crtc.h> 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include "cdv_device.h" 158c2ecf20Sopenharmony_ci#include "framebuffer.h" 168c2ecf20Sopenharmony_ci#include "gma_display.h" 178c2ecf20Sopenharmony_ci#include "power.h" 188c2ecf20Sopenharmony_ci#include "psb_drv.h" 198c2ecf20Sopenharmony_ci#include "psb_intel_drv.h" 208c2ecf20Sopenharmony_ci#include "psb_intel_reg.h" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistatic bool cdv_intel_find_dp_pll(const struct gma_limit_t *limit, 238c2ecf20Sopenharmony_ci struct drm_crtc *crtc, int target, 248c2ecf20Sopenharmony_ci int refclk, struct gma_clock_t *best_clock); 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define CDV_LIMIT_SINGLE_LVDS_96 0 288c2ecf20Sopenharmony_ci#define CDV_LIMIT_SINGLE_LVDS_100 1 298c2ecf20Sopenharmony_ci#define CDV_LIMIT_DAC_HDMI_27 2 308c2ecf20Sopenharmony_ci#define CDV_LIMIT_DAC_HDMI_96 3 318c2ecf20Sopenharmony_ci#define CDV_LIMIT_DP_27 4 328c2ecf20Sopenharmony_ci#define CDV_LIMIT_DP_100 5 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic const struct gma_limit_t cdv_intel_limits[] = { 358c2ecf20Sopenharmony_ci { /* CDV_SINGLE_LVDS_96MHz */ 368c2ecf20Sopenharmony_ci .dot = {.min = 20000, .max = 115500}, 378c2ecf20Sopenharmony_ci .vco = {.min = 1800000, .max = 3600000}, 388c2ecf20Sopenharmony_ci .n = {.min = 2, .max = 6}, 398c2ecf20Sopenharmony_ci .m = {.min = 60, .max = 160}, 408c2ecf20Sopenharmony_ci .m1 = {.min = 0, .max = 0}, 418c2ecf20Sopenharmony_ci .m2 = {.min = 58, .max = 158}, 428c2ecf20Sopenharmony_ci .p = {.min = 28, .max = 140}, 438c2ecf20Sopenharmony_ci .p1 = {.min = 2, .max = 10}, 448c2ecf20Sopenharmony_ci .p2 = {.dot_limit = 200000, .p2_slow = 14, .p2_fast = 14}, 458c2ecf20Sopenharmony_ci .find_pll = gma_find_best_pll, 468c2ecf20Sopenharmony_ci }, 478c2ecf20Sopenharmony_ci { /* CDV_SINGLE_LVDS_100MHz */ 488c2ecf20Sopenharmony_ci .dot = {.min = 20000, .max = 115500}, 498c2ecf20Sopenharmony_ci .vco = {.min = 1800000, .max = 3600000}, 508c2ecf20Sopenharmony_ci .n = {.min = 2, .max = 6}, 518c2ecf20Sopenharmony_ci .m = {.min = 60, .max = 160}, 528c2ecf20Sopenharmony_ci .m1 = {.min = 0, .max = 0}, 538c2ecf20Sopenharmony_ci .m2 = {.min = 58, .max = 158}, 548c2ecf20Sopenharmony_ci .p = {.min = 28, .max = 140}, 558c2ecf20Sopenharmony_ci .p1 = {.min = 2, .max = 10}, 568c2ecf20Sopenharmony_ci /* The single-channel range is 25-112Mhz, and dual-channel 578c2ecf20Sopenharmony_ci * is 80-224Mhz. Prefer single channel as much as possible. 588c2ecf20Sopenharmony_ci */ 598c2ecf20Sopenharmony_ci .p2 = {.dot_limit = 200000, .p2_slow = 14, .p2_fast = 14}, 608c2ecf20Sopenharmony_ci .find_pll = gma_find_best_pll, 618c2ecf20Sopenharmony_ci }, 628c2ecf20Sopenharmony_ci { /* CDV_DAC_HDMI_27MHz */ 638c2ecf20Sopenharmony_ci .dot = {.min = 20000, .max = 400000}, 648c2ecf20Sopenharmony_ci .vco = {.min = 1809000, .max = 3564000}, 658c2ecf20Sopenharmony_ci .n = {.min = 1, .max = 1}, 668c2ecf20Sopenharmony_ci .m = {.min = 67, .max = 132}, 678c2ecf20Sopenharmony_ci .m1 = {.min = 0, .max = 0}, 688c2ecf20Sopenharmony_ci .m2 = {.min = 65, .max = 130}, 698c2ecf20Sopenharmony_ci .p = {.min = 5, .max = 90}, 708c2ecf20Sopenharmony_ci .p1 = {.min = 1, .max = 9}, 718c2ecf20Sopenharmony_ci .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 5}, 728c2ecf20Sopenharmony_ci .find_pll = gma_find_best_pll, 738c2ecf20Sopenharmony_ci }, 748c2ecf20Sopenharmony_ci { /* CDV_DAC_HDMI_96MHz */ 758c2ecf20Sopenharmony_ci .dot = {.min = 20000, .max = 400000}, 768c2ecf20Sopenharmony_ci .vco = {.min = 1800000, .max = 3600000}, 778c2ecf20Sopenharmony_ci .n = {.min = 2, .max = 6}, 788c2ecf20Sopenharmony_ci .m = {.min = 60, .max = 160}, 798c2ecf20Sopenharmony_ci .m1 = {.min = 0, .max = 0}, 808c2ecf20Sopenharmony_ci .m2 = {.min = 58, .max = 158}, 818c2ecf20Sopenharmony_ci .p = {.min = 5, .max = 100}, 828c2ecf20Sopenharmony_ci .p1 = {.min = 1, .max = 10}, 838c2ecf20Sopenharmony_ci .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 5}, 848c2ecf20Sopenharmony_ci .find_pll = gma_find_best_pll, 858c2ecf20Sopenharmony_ci }, 868c2ecf20Sopenharmony_ci { /* CDV_DP_27MHz */ 878c2ecf20Sopenharmony_ci .dot = {.min = 160000, .max = 272000}, 888c2ecf20Sopenharmony_ci .vco = {.min = 1809000, .max = 3564000}, 898c2ecf20Sopenharmony_ci .n = {.min = 1, .max = 1}, 908c2ecf20Sopenharmony_ci .m = {.min = 67, .max = 132}, 918c2ecf20Sopenharmony_ci .m1 = {.min = 0, .max = 0}, 928c2ecf20Sopenharmony_ci .m2 = {.min = 65, .max = 130}, 938c2ecf20Sopenharmony_ci .p = {.min = 5, .max = 90}, 948c2ecf20Sopenharmony_ci .p1 = {.min = 1, .max = 9}, 958c2ecf20Sopenharmony_ci .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 10}, 968c2ecf20Sopenharmony_ci .find_pll = cdv_intel_find_dp_pll, 978c2ecf20Sopenharmony_ci }, 988c2ecf20Sopenharmony_ci { /* CDV_DP_100MHz */ 998c2ecf20Sopenharmony_ci .dot = {.min = 160000, .max = 272000}, 1008c2ecf20Sopenharmony_ci .vco = {.min = 1800000, .max = 3600000}, 1018c2ecf20Sopenharmony_ci .n = {.min = 2, .max = 6}, 1028c2ecf20Sopenharmony_ci .m = {.min = 60, .max = 164}, 1038c2ecf20Sopenharmony_ci .m1 = {.min = 0, .max = 0}, 1048c2ecf20Sopenharmony_ci .m2 = {.min = 58, .max = 162}, 1058c2ecf20Sopenharmony_ci .p = {.min = 5, .max = 100}, 1068c2ecf20Sopenharmony_ci .p1 = {.min = 1, .max = 10}, 1078c2ecf20Sopenharmony_ci .p2 = {.dot_limit = 225000, .p2_slow = 10, .p2_fast = 10}, 1088c2ecf20Sopenharmony_ci .find_pll = cdv_intel_find_dp_pll, 1098c2ecf20Sopenharmony_ci } 1108c2ecf20Sopenharmony_ci}; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci#define _wait_for(COND, MS, W) ({ \ 1138c2ecf20Sopenharmony_ci unsigned long timeout__ = jiffies + msecs_to_jiffies(MS); \ 1148c2ecf20Sopenharmony_ci int ret__ = 0; \ 1158c2ecf20Sopenharmony_ci while (!(COND)) { \ 1168c2ecf20Sopenharmony_ci if (time_after(jiffies, timeout__)) { \ 1178c2ecf20Sopenharmony_ci ret__ = -ETIMEDOUT; \ 1188c2ecf20Sopenharmony_ci break; \ 1198c2ecf20Sopenharmony_ci } \ 1208c2ecf20Sopenharmony_ci if (W && !in_dbg_master()) \ 1218c2ecf20Sopenharmony_ci msleep(W); \ 1228c2ecf20Sopenharmony_ci } \ 1238c2ecf20Sopenharmony_ci ret__; \ 1248c2ecf20Sopenharmony_ci}) 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci#define wait_for(COND, MS) _wait_for(COND, MS, 1) 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ciint cdv_sb_read(struct drm_device *dev, u32 reg, u32 *val) 1308c2ecf20Sopenharmony_ci{ 1318c2ecf20Sopenharmony_ci int ret; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci ret = wait_for((REG_READ(SB_PCKT) & SB_BUSY) == 0, 1000); 1348c2ecf20Sopenharmony_ci if (ret) { 1358c2ecf20Sopenharmony_ci DRM_ERROR("timeout waiting for SB to idle before read\n"); 1368c2ecf20Sopenharmony_ci return ret; 1378c2ecf20Sopenharmony_ci } 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci REG_WRITE(SB_ADDR, reg); 1408c2ecf20Sopenharmony_ci REG_WRITE(SB_PCKT, 1418c2ecf20Sopenharmony_ci SET_FIELD(SB_OPCODE_READ, SB_OPCODE) | 1428c2ecf20Sopenharmony_ci SET_FIELD(SB_DEST_DPLL, SB_DEST) | 1438c2ecf20Sopenharmony_ci SET_FIELD(0xf, SB_BYTE_ENABLE)); 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci ret = wait_for((REG_READ(SB_PCKT) & SB_BUSY) == 0, 1000); 1468c2ecf20Sopenharmony_ci if (ret) { 1478c2ecf20Sopenharmony_ci DRM_ERROR("timeout waiting for SB to idle after read\n"); 1488c2ecf20Sopenharmony_ci return ret; 1498c2ecf20Sopenharmony_ci } 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci *val = REG_READ(SB_DATA); 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci return 0; 1548c2ecf20Sopenharmony_ci} 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ciint cdv_sb_write(struct drm_device *dev, u32 reg, u32 val) 1578c2ecf20Sopenharmony_ci{ 1588c2ecf20Sopenharmony_ci int ret; 1598c2ecf20Sopenharmony_ci static bool dpio_debug = true; 1608c2ecf20Sopenharmony_ci u32 temp; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci if (dpio_debug) { 1638c2ecf20Sopenharmony_ci if (cdv_sb_read(dev, reg, &temp) == 0) 1648c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("0x%08x: 0x%08x (before)\n", reg, temp); 1658c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("0x%08x: 0x%08x\n", reg, val); 1668c2ecf20Sopenharmony_ci } 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci ret = wait_for((REG_READ(SB_PCKT) & SB_BUSY) == 0, 1000); 1698c2ecf20Sopenharmony_ci if (ret) { 1708c2ecf20Sopenharmony_ci DRM_ERROR("timeout waiting for SB to idle before write\n"); 1718c2ecf20Sopenharmony_ci return ret; 1728c2ecf20Sopenharmony_ci } 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci REG_WRITE(SB_ADDR, reg); 1758c2ecf20Sopenharmony_ci REG_WRITE(SB_DATA, val); 1768c2ecf20Sopenharmony_ci REG_WRITE(SB_PCKT, 1778c2ecf20Sopenharmony_ci SET_FIELD(SB_OPCODE_WRITE, SB_OPCODE) | 1788c2ecf20Sopenharmony_ci SET_FIELD(SB_DEST_DPLL, SB_DEST) | 1798c2ecf20Sopenharmony_ci SET_FIELD(0xf, SB_BYTE_ENABLE)); 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci ret = wait_for((REG_READ(SB_PCKT) & SB_BUSY) == 0, 1000); 1828c2ecf20Sopenharmony_ci if (ret) { 1838c2ecf20Sopenharmony_ci DRM_ERROR("timeout waiting for SB to idle after write\n"); 1848c2ecf20Sopenharmony_ci return ret; 1858c2ecf20Sopenharmony_ci } 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci if (dpio_debug) { 1888c2ecf20Sopenharmony_ci if (cdv_sb_read(dev, reg, &temp) == 0) 1898c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("0x%08x: 0x%08x (after)\n", reg, temp); 1908c2ecf20Sopenharmony_ci } 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci return 0; 1938c2ecf20Sopenharmony_ci} 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci/* Reset the DPIO configuration register. The BIOS does this at every 1968c2ecf20Sopenharmony_ci * mode set. 1978c2ecf20Sopenharmony_ci */ 1988c2ecf20Sopenharmony_civoid cdv_sb_reset(struct drm_device *dev) 1998c2ecf20Sopenharmony_ci{ 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci REG_WRITE(DPIO_CFG, 0); 2028c2ecf20Sopenharmony_ci REG_READ(DPIO_CFG); 2038c2ecf20Sopenharmony_ci REG_WRITE(DPIO_CFG, DPIO_MODE_SELECT_0 | DPIO_CMN_RESET_N); 2048c2ecf20Sopenharmony_ci} 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci/* Unlike most Intel display engines, on Cedarview the DPLL registers 2078c2ecf20Sopenharmony_ci * are behind this sideband bus. They must be programmed while the 2088c2ecf20Sopenharmony_ci * DPLL reference clock is on in the DPLL control register, but before 2098c2ecf20Sopenharmony_ci * the DPLL is enabled in the DPLL control register. 2108c2ecf20Sopenharmony_ci */ 2118c2ecf20Sopenharmony_cistatic int 2128c2ecf20Sopenharmony_cicdv_dpll_set_clock_cdv(struct drm_device *dev, struct drm_crtc *crtc, 2138c2ecf20Sopenharmony_ci struct gma_clock_t *clock, bool is_lvds, u32 ddi_select) 2148c2ecf20Sopenharmony_ci{ 2158c2ecf20Sopenharmony_ci struct gma_crtc *gma_crtc = to_gma_crtc(crtc); 2168c2ecf20Sopenharmony_ci int pipe = gma_crtc->pipe; 2178c2ecf20Sopenharmony_ci u32 m, n_vco, p; 2188c2ecf20Sopenharmony_ci int ret = 0; 2198c2ecf20Sopenharmony_ci int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; 2208c2ecf20Sopenharmony_ci int ref_sfr = (pipe == 0) ? SB_REF_DPLLA : SB_REF_DPLLB; 2218c2ecf20Sopenharmony_ci u32 ref_value; 2228c2ecf20Sopenharmony_ci u32 lane_reg, lane_value; 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci cdv_sb_reset(dev); 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci REG_WRITE(dpll_reg, DPLL_SYNCLOCK_ENABLE | DPLL_VGA_MODE_DIS); 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci udelay(100); 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci /* Follow the BIOS and write the REF/SFR Register. Hardcoded value */ 2318c2ecf20Sopenharmony_ci ref_value = 0x68A701; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci cdv_sb_write(dev, SB_REF_SFR(pipe), ref_value); 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci /* We don't know what the other fields of these regs are, so 2368c2ecf20Sopenharmony_ci * leave them in place. 2378c2ecf20Sopenharmony_ci */ 2388c2ecf20Sopenharmony_ci /* 2398c2ecf20Sopenharmony_ci * The BIT 14:13 of 0x8010/0x8030 is used to select the ref clk 2408c2ecf20Sopenharmony_ci * for the pipe A/B. Display spec 1.06 has wrong definition. 2418c2ecf20Sopenharmony_ci * Correct definition is like below: 2428c2ecf20Sopenharmony_ci * 2438c2ecf20Sopenharmony_ci * refclka mean use clock from same PLL 2448c2ecf20Sopenharmony_ci * 2458c2ecf20Sopenharmony_ci * if DPLLA sets 01 and DPLLB sets 01, they use clock from their pll 2468c2ecf20Sopenharmony_ci * 2478c2ecf20Sopenharmony_ci * if DPLLA sets 01 and DPLLB sets 02, both use clk from DPLLA 2488c2ecf20Sopenharmony_ci * 2498c2ecf20Sopenharmony_ci */ 2508c2ecf20Sopenharmony_ci ret = cdv_sb_read(dev, ref_sfr, &ref_value); 2518c2ecf20Sopenharmony_ci if (ret) 2528c2ecf20Sopenharmony_ci return ret; 2538c2ecf20Sopenharmony_ci ref_value &= ~(REF_CLK_MASK); 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci /* use DPLL_A for pipeB on CRT/HDMI */ 2568c2ecf20Sopenharmony_ci if (pipe == 1 && !is_lvds && !(ddi_select & DP_MASK)) { 2578c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("use DPLLA for pipe B\n"); 2588c2ecf20Sopenharmony_ci ref_value |= REF_CLK_DPLLA; 2598c2ecf20Sopenharmony_ci } else { 2608c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("use their DPLL for pipe A/B\n"); 2618c2ecf20Sopenharmony_ci ref_value |= REF_CLK_DPLL; 2628c2ecf20Sopenharmony_ci } 2638c2ecf20Sopenharmony_ci ret = cdv_sb_write(dev, ref_sfr, ref_value); 2648c2ecf20Sopenharmony_ci if (ret) 2658c2ecf20Sopenharmony_ci return ret; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci ret = cdv_sb_read(dev, SB_M(pipe), &m); 2688c2ecf20Sopenharmony_ci if (ret) 2698c2ecf20Sopenharmony_ci return ret; 2708c2ecf20Sopenharmony_ci m &= ~SB_M_DIVIDER_MASK; 2718c2ecf20Sopenharmony_ci m |= ((clock->m2) << SB_M_DIVIDER_SHIFT); 2728c2ecf20Sopenharmony_ci ret = cdv_sb_write(dev, SB_M(pipe), m); 2738c2ecf20Sopenharmony_ci if (ret) 2748c2ecf20Sopenharmony_ci return ret; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci ret = cdv_sb_read(dev, SB_N_VCO(pipe), &n_vco); 2778c2ecf20Sopenharmony_ci if (ret) 2788c2ecf20Sopenharmony_ci return ret; 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci /* Follow the BIOS to program the N_DIVIDER REG */ 2818c2ecf20Sopenharmony_ci n_vco &= 0xFFFF; 2828c2ecf20Sopenharmony_ci n_vco |= 0x107; 2838c2ecf20Sopenharmony_ci n_vco &= ~(SB_N_VCO_SEL_MASK | 2848c2ecf20Sopenharmony_ci SB_N_DIVIDER_MASK | 2858c2ecf20Sopenharmony_ci SB_N_CB_TUNE_MASK); 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci n_vco |= ((clock->n) << SB_N_DIVIDER_SHIFT); 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci if (clock->vco < 2250000) { 2908c2ecf20Sopenharmony_ci n_vco |= (2 << SB_N_CB_TUNE_SHIFT); 2918c2ecf20Sopenharmony_ci n_vco |= (0 << SB_N_VCO_SEL_SHIFT); 2928c2ecf20Sopenharmony_ci } else if (clock->vco < 2750000) { 2938c2ecf20Sopenharmony_ci n_vco |= (1 << SB_N_CB_TUNE_SHIFT); 2948c2ecf20Sopenharmony_ci n_vco |= (1 << SB_N_VCO_SEL_SHIFT); 2958c2ecf20Sopenharmony_ci } else if (clock->vco < 3300000) { 2968c2ecf20Sopenharmony_ci n_vco |= (0 << SB_N_CB_TUNE_SHIFT); 2978c2ecf20Sopenharmony_ci n_vco |= (2 << SB_N_VCO_SEL_SHIFT); 2988c2ecf20Sopenharmony_ci } else { 2998c2ecf20Sopenharmony_ci n_vco |= (0 << SB_N_CB_TUNE_SHIFT); 3008c2ecf20Sopenharmony_ci n_vco |= (3 << SB_N_VCO_SEL_SHIFT); 3018c2ecf20Sopenharmony_ci } 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci ret = cdv_sb_write(dev, SB_N_VCO(pipe), n_vco); 3048c2ecf20Sopenharmony_ci if (ret) 3058c2ecf20Sopenharmony_ci return ret; 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci ret = cdv_sb_read(dev, SB_P(pipe), &p); 3088c2ecf20Sopenharmony_ci if (ret) 3098c2ecf20Sopenharmony_ci return ret; 3108c2ecf20Sopenharmony_ci p &= ~(SB_P2_DIVIDER_MASK | SB_P1_DIVIDER_MASK); 3118c2ecf20Sopenharmony_ci p |= SET_FIELD(clock->p1, SB_P1_DIVIDER); 3128c2ecf20Sopenharmony_ci switch (clock->p2) { 3138c2ecf20Sopenharmony_ci case 5: 3148c2ecf20Sopenharmony_ci p |= SET_FIELD(SB_P2_5, SB_P2_DIVIDER); 3158c2ecf20Sopenharmony_ci break; 3168c2ecf20Sopenharmony_ci case 10: 3178c2ecf20Sopenharmony_ci p |= SET_FIELD(SB_P2_10, SB_P2_DIVIDER); 3188c2ecf20Sopenharmony_ci break; 3198c2ecf20Sopenharmony_ci case 14: 3208c2ecf20Sopenharmony_ci p |= SET_FIELD(SB_P2_14, SB_P2_DIVIDER); 3218c2ecf20Sopenharmony_ci break; 3228c2ecf20Sopenharmony_ci case 7: 3238c2ecf20Sopenharmony_ci p |= SET_FIELD(SB_P2_7, SB_P2_DIVIDER); 3248c2ecf20Sopenharmony_ci break; 3258c2ecf20Sopenharmony_ci default: 3268c2ecf20Sopenharmony_ci DRM_ERROR("Bad P2 clock: %d\n", clock->p2); 3278c2ecf20Sopenharmony_ci return -EINVAL; 3288c2ecf20Sopenharmony_ci } 3298c2ecf20Sopenharmony_ci ret = cdv_sb_write(dev, SB_P(pipe), p); 3308c2ecf20Sopenharmony_ci if (ret) 3318c2ecf20Sopenharmony_ci return ret; 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci if (ddi_select) { 3348c2ecf20Sopenharmony_ci if ((ddi_select & DDI_MASK) == DDI0_SELECT) { 3358c2ecf20Sopenharmony_ci lane_reg = PSB_LANE0; 3368c2ecf20Sopenharmony_ci cdv_sb_read(dev, lane_reg, &lane_value); 3378c2ecf20Sopenharmony_ci lane_value &= ~(LANE_PLL_MASK); 3388c2ecf20Sopenharmony_ci lane_value |= LANE_PLL_ENABLE | LANE_PLL_PIPE(pipe); 3398c2ecf20Sopenharmony_ci cdv_sb_write(dev, lane_reg, lane_value); 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci lane_reg = PSB_LANE1; 3428c2ecf20Sopenharmony_ci cdv_sb_read(dev, lane_reg, &lane_value); 3438c2ecf20Sopenharmony_ci lane_value &= ~(LANE_PLL_MASK); 3448c2ecf20Sopenharmony_ci lane_value |= LANE_PLL_ENABLE | LANE_PLL_PIPE(pipe); 3458c2ecf20Sopenharmony_ci cdv_sb_write(dev, lane_reg, lane_value); 3468c2ecf20Sopenharmony_ci } else { 3478c2ecf20Sopenharmony_ci lane_reg = PSB_LANE2; 3488c2ecf20Sopenharmony_ci cdv_sb_read(dev, lane_reg, &lane_value); 3498c2ecf20Sopenharmony_ci lane_value &= ~(LANE_PLL_MASK); 3508c2ecf20Sopenharmony_ci lane_value |= LANE_PLL_ENABLE | LANE_PLL_PIPE(pipe); 3518c2ecf20Sopenharmony_ci cdv_sb_write(dev, lane_reg, lane_value); 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci lane_reg = PSB_LANE3; 3548c2ecf20Sopenharmony_ci cdv_sb_read(dev, lane_reg, &lane_value); 3558c2ecf20Sopenharmony_ci lane_value &= ~(LANE_PLL_MASK); 3568c2ecf20Sopenharmony_ci lane_value |= LANE_PLL_ENABLE | LANE_PLL_PIPE(pipe); 3578c2ecf20Sopenharmony_ci cdv_sb_write(dev, lane_reg, lane_value); 3588c2ecf20Sopenharmony_ci } 3598c2ecf20Sopenharmony_ci } 3608c2ecf20Sopenharmony_ci return 0; 3618c2ecf20Sopenharmony_ci} 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_cistatic const struct gma_limit_t *cdv_intel_limit(struct drm_crtc *crtc, 3648c2ecf20Sopenharmony_ci int refclk) 3658c2ecf20Sopenharmony_ci{ 3668c2ecf20Sopenharmony_ci const struct gma_limit_t *limit; 3678c2ecf20Sopenharmony_ci if (gma_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { 3688c2ecf20Sopenharmony_ci /* 3698c2ecf20Sopenharmony_ci * Now only single-channel LVDS is supported on CDV. If it is 3708c2ecf20Sopenharmony_ci * incorrect, please add the dual-channel LVDS. 3718c2ecf20Sopenharmony_ci */ 3728c2ecf20Sopenharmony_ci if (refclk == 96000) 3738c2ecf20Sopenharmony_ci limit = &cdv_intel_limits[CDV_LIMIT_SINGLE_LVDS_96]; 3748c2ecf20Sopenharmony_ci else 3758c2ecf20Sopenharmony_ci limit = &cdv_intel_limits[CDV_LIMIT_SINGLE_LVDS_100]; 3768c2ecf20Sopenharmony_ci } else if (gma_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || 3778c2ecf20Sopenharmony_ci gma_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) { 3788c2ecf20Sopenharmony_ci if (refclk == 27000) 3798c2ecf20Sopenharmony_ci limit = &cdv_intel_limits[CDV_LIMIT_DP_27]; 3808c2ecf20Sopenharmony_ci else 3818c2ecf20Sopenharmony_ci limit = &cdv_intel_limits[CDV_LIMIT_DP_100]; 3828c2ecf20Sopenharmony_ci } else { 3838c2ecf20Sopenharmony_ci if (refclk == 27000) 3848c2ecf20Sopenharmony_ci limit = &cdv_intel_limits[CDV_LIMIT_DAC_HDMI_27]; 3858c2ecf20Sopenharmony_ci else 3868c2ecf20Sopenharmony_ci limit = &cdv_intel_limits[CDV_LIMIT_DAC_HDMI_96]; 3878c2ecf20Sopenharmony_ci } 3888c2ecf20Sopenharmony_ci return limit; 3898c2ecf20Sopenharmony_ci} 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci/* m1 is reserved as 0 in CDV, n is a ring counter */ 3928c2ecf20Sopenharmony_cistatic void cdv_intel_clock(int refclk, struct gma_clock_t *clock) 3938c2ecf20Sopenharmony_ci{ 3948c2ecf20Sopenharmony_ci clock->m = clock->m2 + 2; 3958c2ecf20Sopenharmony_ci clock->p = clock->p1 * clock->p2; 3968c2ecf20Sopenharmony_ci clock->vco = (refclk * clock->m) / clock->n; 3978c2ecf20Sopenharmony_ci clock->dot = clock->vco / clock->p; 3988c2ecf20Sopenharmony_ci} 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_cistatic bool cdv_intel_find_dp_pll(const struct gma_limit_t *limit, 4018c2ecf20Sopenharmony_ci struct drm_crtc *crtc, int target, 4028c2ecf20Sopenharmony_ci int refclk, 4038c2ecf20Sopenharmony_ci struct gma_clock_t *best_clock) 4048c2ecf20Sopenharmony_ci{ 4058c2ecf20Sopenharmony_ci struct gma_crtc *gma_crtc = to_gma_crtc(crtc); 4068c2ecf20Sopenharmony_ci struct gma_clock_t clock; 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci memset(&clock, 0, sizeof(clock)); 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci switch (refclk) { 4118c2ecf20Sopenharmony_ci case 27000: 4128c2ecf20Sopenharmony_ci if (target < 200000) { 4138c2ecf20Sopenharmony_ci clock.p1 = 2; 4148c2ecf20Sopenharmony_ci clock.p2 = 10; 4158c2ecf20Sopenharmony_ci clock.n = 1; 4168c2ecf20Sopenharmony_ci clock.m1 = 0; 4178c2ecf20Sopenharmony_ci clock.m2 = 118; 4188c2ecf20Sopenharmony_ci } else { 4198c2ecf20Sopenharmony_ci clock.p1 = 1; 4208c2ecf20Sopenharmony_ci clock.p2 = 10; 4218c2ecf20Sopenharmony_ci clock.n = 1; 4228c2ecf20Sopenharmony_ci clock.m1 = 0; 4238c2ecf20Sopenharmony_ci clock.m2 = 98; 4248c2ecf20Sopenharmony_ci } 4258c2ecf20Sopenharmony_ci break; 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci case 100000: 4288c2ecf20Sopenharmony_ci if (target < 200000) { 4298c2ecf20Sopenharmony_ci clock.p1 = 2; 4308c2ecf20Sopenharmony_ci clock.p2 = 10; 4318c2ecf20Sopenharmony_ci clock.n = 5; 4328c2ecf20Sopenharmony_ci clock.m1 = 0; 4338c2ecf20Sopenharmony_ci clock.m2 = 160; 4348c2ecf20Sopenharmony_ci } else { 4358c2ecf20Sopenharmony_ci clock.p1 = 1; 4368c2ecf20Sopenharmony_ci clock.p2 = 10; 4378c2ecf20Sopenharmony_ci clock.n = 5; 4388c2ecf20Sopenharmony_ci clock.m1 = 0; 4398c2ecf20Sopenharmony_ci clock.m2 = 133; 4408c2ecf20Sopenharmony_ci } 4418c2ecf20Sopenharmony_ci break; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci default: 4448c2ecf20Sopenharmony_ci return false; 4458c2ecf20Sopenharmony_ci } 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci gma_crtc->clock_funcs->clock(refclk, &clock); 4488c2ecf20Sopenharmony_ci memcpy(best_clock, &clock, sizeof(struct gma_clock_t)); 4498c2ecf20Sopenharmony_ci return true; 4508c2ecf20Sopenharmony_ci} 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci#define FIFO_PIPEA (1 << 0) 4538c2ecf20Sopenharmony_ci#define FIFO_PIPEB (1 << 1) 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_cistatic bool cdv_intel_pipe_enabled(struct drm_device *dev, int pipe) 4568c2ecf20Sopenharmony_ci{ 4578c2ecf20Sopenharmony_ci struct drm_crtc *crtc; 4588c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 4598c2ecf20Sopenharmony_ci struct gma_crtc *gma_crtc = NULL; 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci crtc = dev_priv->pipe_to_crtc_mapping[pipe]; 4628c2ecf20Sopenharmony_ci gma_crtc = to_gma_crtc(crtc); 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci if (crtc->primary->fb == NULL || !gma_crtc->active) 4658c2ecf20Sopenharmony_ci return false; 4668c2ecf20Sopenharmony_ci return true; 4678c2ecf20Sopenharmony_ci} 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_civoid cdv_disable_sr(struct drm_device *dev) 4708c2ecf20Sopenharmony_ci{ 4718c2ecf20Sopenharmony_ci if (REG_READ(FW_BLC_SELF) & FW_BLC_SELF_EN) { 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_ci /* Disable self-refresh before adjust WM */ 4748c2ecf20Sopenharmony_ci REG_WRITE(FW_BLC_SELF, (REG_READ(FW_BLC_SELF) & ~FW_BLC_SELF_EN)); 4758c2ecf20Sopenharmony_ci REG_READ(FW_BLC_SELF); 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci gma_wait_for_vblank(dev); 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci /* Cedarview workaround to write ovelay plane, which force to leave 4808c2ecf20Sopenharmony_ci * MAX_FIFO state. 4818c2ecf20Sopenharmony_ci */ 4828c2ecf20Sopenharmony_ci REG_WRITE(OV_OVADD, 0/*dev_priv->ovl_offset*/); 4838c2ecf20Sopenharmony_ci REG_READ(OV_OVADD); 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci gma_wait_for_vblank(dev); 4868c2ecf20Sopenharmony_ci } 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci} 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_civoid cdv_update_wm(struct drm_device *dev, struct drm_crtc *crtc) 4918c2ecf20Sopenharmony_ci{ 4928c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 4938c2ecf20Sopenharmony_ci struct gma_crtc *gma_crtc = to_gma_crtc(crtc); 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci /* Is only one pipe enabled? */ 4968c2ecf20Sopenharmony_ci if (cdv_intel_pipe_enabled(dev, 0) ^ cdv_intel_pipe_enabled(dev, 1)) { 4978c2ecf20Sopenharmony_ci u32 fw; 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci fw = REG_READ(DSPFW1); 5008c2ecf20Sopenharmony_ci fw &= ~DSP_FIFO_SR_WM_MASK; 5018c2ecf20Sopenharmony_ci fw |= (0x7e << DSP_FIFO_SR_WM_SHIFT); 5028c2ecf20Sopenharmony_ci fw &= ~CURSOR_B_FIFO_WM_MASK; 5038c2ecf20Sopenharmony_ci fw |= (0x4 << CURSOR_B_FIFO_WM_SHIFT); 5048c2ecf20Sopenharmony_ci REG_WRITE(DSPFW1, fw); 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci fw = REG_READ(DSPFW2); 5078c2ecf20Sopenharmony_ci fw &= ~CURSOR_A_FIFO_WM_MASK; 5088c2ecf20Sopenharmony_ci fw |= (0x6 << CURSOR_A_FIFO_WM_SHIFT); 5098c2ecf20Sopenharmony_ci fw &= ~DSP_PLANE_C_FIFO_WM_MASK; 5108c2ecf20Sopenharmony_ci fw |= (0x8 << DSP_PLANE_C_FIFO_WM_SHIFT); 5118c2ecf20Sopenharmony_ci REG_WRITE(DSPFW2, fw); 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci REG_WRITE(DSPFW3, 0x36000000); 5148c2ecf20Sopenharmony_ci 5158c2ecf20Sopenharmony_ci /* ignore FW4 */ 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci /* Is pipe b lvds ? */ 5188c2ecf20Sopenharmony_ci if (gma_crtc->pipe == 1 && 5198c2ecf20Sopenharmony_ci gma_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { 5208c2ecf20Sopenharmony_ci REG_WRITE(DSPFW5, 0x00040330); 5218c2ecf20Sopenharmony_ci } else { 5228c2ecf20Sopenharmony_ci fw = (3 << DSP_PLANE_B_FIFO_WM1_SHIFT) | 5238c2ecf20Sopenharmony_ci (4 << DSP_PLANE_A_FIFO_WM1_SHIFT) | 5248c2ecf20Sopenharmony_ci (3 << CURSOR_B_FIFO_WM1_SHIFT) | 5258c2ecf20Sopenharmony_ci (4 << CURSOR_FIFO_SR_WM1_SHIFT); 5268c2ecf20Sopenharmony_ci REG_WRITE(DSPFW5, fw); 5278c2ecf20Sopenharmony_ci } 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci REG_WRITE(DSPFW6, 0x10); 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci gma_wait_for_vblank(dev); 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ci /* enable self-refresh for single pipe active */ 5348c2ecf20Sopenharmony_ci REG_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN); 5358c2ecf20Sopenharmony_ci REG_READ(FW_BLC_SELF); 5368c2ecf20Sopenharmony_ci gma_wait_for_vblank(dev); 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci } else { 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci /* HW team suggested values... */ 5418c2ecf20Sopenharmony_ci REG_WRITE(DSPFW1, 0x3f880808); 5428c2ecf20Sopenharmony_ci REG_WRITE(DSPFW2, 0x0b020202); 5438c2ecf20Sopenharmony_ci REG_WRITE(DSPFW3, 0x24000000); 5448c2ecf20Sopenharmony_ci REG_WRITE(DSPFW4, 0x08030202); 5458c2ecf20Sopenharmony_ci REG_WRITE(DSPFW5, 0x01010101); 5468c2ecf20Sopenharmony_ci REG_WRITE(DSPFW6, 0x1d0); 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_ci gma_wait_for_vblank(dev); 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci dev_priv->ops->disable_sr(dev); 5518c2ecf20Sopenharmony_ci } 5528c2ecf20Sopenharmony_ci} 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci/** 5558c2ecf20Sopenharmony_ci * Return the pipe currently connected to the panel fitter, 5568c2ecf20Sopenharmony_ci * or -1 if the panel fitter is not present or not in use 5578c2ecf20Sopenharmony_ci */ 5588c2ecf20Sopenharmony_cistatic int cdv_intel_panel_fitter_pipe(struct drm_device *dev) 5598c2ecf20Sopenharmony_ci{ 5608c2ecf20Sopenharmony_ci u32 pfit_control; 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci pfit_control = REG_READ(PFIT_CONTROL); 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci /* See if the panel fitter is in use */ 5658c2ecf20Sopenharmony_ci if ((pfit_control & PFIT_ENABLE) == 0) 5668c2ecf20Sopenharmony_ci return -1; 5678c2ecf20Sopenharmony_ci return (pfit_control >> 29) & 0x3; 5688c2ecf20Sopenharmony_ci} 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_cistatic int cdv_intel_crtc_mode_set(struct drm_crtc *crtc, 5718c2ecf20Sopenharmony_ci struct drm_display_mode *mode, 5728c2ecf20Sopenharmony_ci struct drm_display_mode *adjusted_mode, 5738c2ecf20Sopenharmony_ci int x, int y, 5748c2ecf20Sopenharmony_ci struct drm_framebuffer *old_fb) 5758c2ecf20Sopenharmony_ci{ 5768c2ecf20Sopenharmony_ci struct drm_device *dev = crtc->dev; 5778c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 5788c2ecf20Sopenharmony_ci struct gma_crtc *gma_crtc = to_gma_crtc(crtc); 5798c2ecf20Sopenharmony_ci int pipe = gma_crtc->pipe; 5808c2ecf20Sopenharmony_ci const struct psb_offset *map = &dev_priv->regmap[pipe]; 5818c2ecf20Sopenharmony_ci int refclk; 5828c2ecf20Sopenharmony_ci struct gma_clock_t clock; 5838c2ecf20Sopenharmony_ci u32 dpll = 0, dspcntr, pipeconf; 5848c2ecf20Sopenharmony_ci bool ok; 5858c2ecf20Sopenharmony_ci bool is_lvds = false, is_tv = false; 5868c2ecf20Sopenharmony_ci bool is_dp = false; 5878c2ecf20Sopenharmony_ci struct drm_mode_config *mode_config = &dev->mode_config; 5888c2ecf20Sopenharmony_ci struct drm_connector *connector; 5898c2ecf20Sopenharmony_ci const struct gma_limit_t *limit; 5908c2ecf20Sopenharmony_ci u32 ddi_select = 0; 5918c2ecf20Sopenharmony_ci bool is_edp = false; 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci list_for_each_entry(connector, &mode_config->connector_list, head) { 5948c2ecf20Sopenharmony_ci struct gma_encoder *gma_encoder = 5958c2ecf20Sopenharmony_ci gma_attached_encoder(connector); 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ci if (!connector->encoder 5988c2ecf20Sopenharmony_ci || connector->encoder->crtc != crtc) 5998c2ecf20Sopenharmony_ci continue; 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci ddi_select = gma_encoder->ddi_select; 6028c2ecf20Sopenharmony_ci switch (gma_encoder->type) { 6038c2ecf20Sopenharmony_ci case INTEL_OUTPUT_LVDS: 6048c2ecf20Sopenharmony_ci is_lvds = true; 6058c2ecf20Sopenharmony_ci break; 6068c2ecf20Sopenharmony_ci case INTEL_OUTPUT_TVOUT: 6078c2ecf20Sopenharmony_ci is_tv = true; 6088c2ecf20Sopenharmony_ci break; 6098c2ecf20Sopenharmony_ci case INTEL_OUTPUT_ANALOG: 6108c2ecf20Sopenharmony_ci case INTEL_OUTPUT_HDMI: 6118c2ecf20Sopenharmony_ci break; 6128c2ecf20Sopenharmony_ci case INTEL_OUTPUT_DISPLAYPORT: 6138c2ecf20Sopenharmony_ci is_dp = true; 6148c2ecf20Sopenharmony_ci break; 6158c2ecf20Sopenharmony_ci case INTEL_OUTPUT_EDP: 6168c2ecf20Sopenharmony_ci is_edp = true; 6178c2ecf20Sopenharmony_ci break; 6188c2ecf20Sopenharmony_ci default: 6198c2ecf20Sopenharmony_ci DRM_ERROR("invalid output type.\n"); 6208c2ecf20Sopenharmony_ci return 0; 6218c2ecf20Sopenharmony_ci } 6228c2ecf20Sopenharmony_ci } 6238c2ecf20Sopenharmony_ci 6248c2ecf20Sopenharmony_ci if (dev_priv->dplla_96mhz) 6258c2ecf20Sopenharmony_ci /* low-end sku, 96/100 mhz */ 6268c2ecf20Sopenharmony_ci refclk = 96000; 6278c2ecf20Sopenharmony_ci else 6288c2ecf20Sopenharmony_ci /* high-end sku, 27/100 mhz */ 6298c2ecf20Sopenharmony_ci refclk = 27000; 6308c2ecf20Sopenharmony_ci if (is_dp || is_edp) { 6318c2ecf20Sopenharmony_ci /* 6328c2ecf20Sopenharmony_ci * Based on the spec the low-end SKU has only CRT/LVDS. So it is 6338c2ecf20Sopenharmony_ci * unnecessary to consider it for DP/eDP. 6348c2ecf20Sopenharmony_ci * On the high-end SKU, it will use the 27/100M reference clk 6358c2ecf20Sopenharmony_ci * for DP/eDP. When using SSC clock, the ref clk is 100MHz.Otherwise 6368c2ecf20Sopenharmony_ci * it will be 27MHz. From the VBIOS code it seems that the pipe A choose 6378c2ecf20Sopenharmony_ci * 27MHz for DP/eDP while the Pipe B chooses the 100MHz. 6388c2ecf20Sopenharmony_ci */ 6398c2ecf20Sopenharmony_ci if (pipe == 0) 6408c2ecf20Sopenharmony_ci refclk = 27000; 6418c2ecf20Sopenharmony_ci else 6428c2ecf20Sopenharmony_ci refclk = 100000; 6438c2ecf20Sopenharmony_ci } 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ci if (is_lvds && dev_priv->lvds_use_ssc) { 6468c2ecf20Sopenharmony_ci refclk = dev_priv->lvds_ssc_freq * 1000; 6478c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("Use SSC reference clock %d Mhz\n", dev_priv->lvds_ssc_freq); 6488c2ecf20Sopenharmony_ci } 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci drm_mode_debug_printmodeline(adjusted_mode); 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_ci limit = gma_crtc->clock_funcs->limit(crtc, refclk); 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, 6558c2ecf20Sopenharmony_ci &clock); 6568c2ecf20Sopenharmony_ci if (!ok) { 6578c2ecf20Sopenharmony_ci DRM_ERROR("Couldn't find PLL settings for mode! target: %d, actual: %d", 6588c2ecf20Sopenharmony_ci adjusted_mode->clock, clock.dot); 6598c2ecf20Sopenharmony_ci return 0; 6608c2ecf20Sopenharmony_ci } 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_ci dpll = DPLL_VGA_MODE_DIS; 6638c2ecf20Sopenharmony_ci if (is_tv) { 6648c2ecf20Sopenharmony_ci /* XXX: just matching BIOS for now */ 6658c2ecf20Sopenharmony_ci/* dpll |= PLL_REF_INPUT_TVCLKINBC; */ 6668c2ecf20Sopenharmony_ci dpll |= 3; 6678c2ecf20Sopenharmony_ci } 6688c2ecf20Sopenharmony_ci/* dpll |= PLL_REF_INPUT_DREFCLK; */ 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci if (is_dp || is_edp) { 6718c2ecf20Sopenharmony_ci cdv_intel_dp_set_m_n(crtc, mode, adjusted_mode); 6728c2ecf20Sopenharmony_ci } else { 6738c2ecf20Sopenharmony_ci REG_WRITE(PIPE_GMCH_DATA_M(pipe), 0); 6748c2ecf20Sopenharmony_ci REG_WRITE(PIPE_GMCH_DATA_N(pipe), 0); 6758c2ecf20Sopenharmony_ci REG_WRITE(PIPE_DP_LINK_M(pipe), 0); 6768c2ecf20Sopenharmony_ci REG_WRITE(PIPE_DP_LINK_N(pipe), 0); 6778c2ecf20Sopenharmony_ci } 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_ci dpll |= DPLL_SYNCLOCK_ENABLE; 6808c2ecf20Sopenharmony_ci/* if (is_lvds) 6818c2ecf20Sopenharmony_ci dpll |= DPLLB_MODE_LVDS; 6828c2ecf20Sopenharmony_ci else 6838c2ecf20Sopenharmony_ci dpll |= DPLLB_MODE_DAC_SERIAL; */ 6848c2ecf20Sopenharmony_ci /* dpll |= (2 << 11); */ 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ci /* setup pipeconf */ 6878c2ecf20Sopenharmony_ci pipeconf = REG_READ(map->conf); 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ci pipeconf &= ~(PIPE_BPC_MASK); 6908c2ecf20Sopenharmony_ci if (is_edp) { 6918c2ecf20Sopenharmony_ci switch (dev_priv->edp.bpp) { 6928c2ecf20Sopenharmony_ci case 24: 6938c2ecf20Sopenharmony_ci pipeconf |= PIPE_8BPC; 6948c2ecf20Sopenharmony_ci break; 6958c2ecf20Sopenharmony_ci case 18: 6968c2ecf20Sopenharmony_ci pipeconf |= PIPE_6BPC; 6978c2ecf20Sopenharmony_ci break; 6988c2ecf20Sopenharmony_ci case 30: 6998c2ecf20Sopenharmony_ci pipeconf |= PIPE_10BPC; 7008c2ecf20Sopenharmony_ci break; 7018c2ecf20Sopenharmony_ci default: 7028c2ecf20Sopenharmony_ci pipeconf |= PIPE_8BPC; 7038c2ecf20Sopenharmony_ci break; 7048c2ecf20Sopenharmony_ci } 7058c2ecf20Sopenharmony_ci } else if (is_lvds) { 7068c2ecf20Sopenharmony_ci /* the BPC will be 6 if it is 18-bit LVDS panel */ 7078c2ecf20Sopenharmony_ci if ((REG_READ(LVDS) & LVDS_A3_POWER_MASK) == LVDS_A3_POWER_UP) 7088c2ecf20Sopenharmony_ci pipeconf |= PIPE_8BPC; 7098c2ecf20Sopenharmony_ci else 7108c2ecf20Sopenharmony_ci pipeconf |= PIPE_6BPC; 7118c2ecf20Sopenharmony_ci } else 7128c2ecf20Sopenharmony_ci pipeconf |= PIPE_8BPC; 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci /* Set up the display plane register */ 7158c2ecf20Sopenharmony_ci dspcntr = DISPPLANE_GAMMA_ENABLE; 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci if (pipe == 0) 7188c2ecf20Sopenharmony_ci dspcntr |= DISPPLANE_SEL_PIPE_A; 7198c2ecf20Sopenharmony_ci else 7208c2ecf20Sopenharmony_ci dspcntr |= DISPPLANE_SEL_PIPE_B; 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ci dspcntr |= DISPLAY_PLANE_ENABLE; 7238c2ecf20Sopenharmony_ci pipeconf |= PIPEACONF_ENABLE; 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_ci REG_WRITE(map->dpll, dpll | DPLL_VGA_MODE_DIS | DPLL_SYNCLOCK_ENABLE); 7268c2ecf20Sopenharmony_ci REG_READ(map->dpll); 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_ci cdv_dpll_set_clock_cdv(dev, crtc, &clock, is_lvds, ddi_select); 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_ci udelay(150); 7318c2ecf20Sopenharmony_ci 7328c2ecf20Sopenharmony_ci 7338c2ecf20Sopenharmony_ci /* The LVDS pin pair needs to be on before the DPLLs are enabled. 7348c2ecf20Sopenharmony_ci * This is an exception to the general rule that mode_set doesn't turn 7358c2ecf20Sopenharmony_ci * things on. 7368c2ecf20Sopenharmony_ci */ 7378c2ecf20Sopenharmony_ci if (is_lvds) { 7388c2ecf20Sopenharmony_ci u32 lvds = REG_READ(LVDS); 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ci lvds |= 7418c2ecf20Sopenharmony_ci LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP | 7428c2ecf20Sopenharmony_ci LVDS_PIPEB_SELECT; 7438c2ecf20Sopenharmony_ci /* Set the B0-B3 data pairs corresponding to 7448c2ecf20Sopenharmony_ci * whether we're going to 7458c2ecf20Sopenharmony_ci * set the DPLLs for dual-channel mode or not. 7468c2ecf20Sopenharmony_ci */ 7478c2ecf20Sopenharmony_ci if (clock.p2 == 7) 7488c2ecf20Sopenharmony_ci lvds |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP; 7498c2ecf20Sopenharmony_ci else 7508c2ecf20Sopenharmony_ci lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP); 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP) 7538c2ecf20Sopenharmony_ci * appropriately here, but we need to look more 7548c2ecf20Sopenharmony_ci * thoroughly into how panels behave in the two modes. 7558c2ecf20Sopenharmony_ci */ 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_ci REG_WRITE(LVDS, lvds); 7588c2ecf20Sopenharmony_ci REG_READ(LVDS); 7598c2ecf20Sopenharmony_ci } 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_ci dpll |= DPLL_VCO_ENABLE; 7628c2ecf20Sopenharmony_ci 7638c2ecf20Sopenharmony_ci /* Disable the panel fitter if it was on our pipe */ 7648c2ecf20Sopenharmony_ci if (cdv_intel_panel_fitter_pipe(dev) == pipe) 7658c2ecf20Sopenharmony_ci REG_WRITE(PFIT_CONTROL, 0); 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B'); 7688c2ecf20Sopenharmony_ci drm_mode_debug_printmodeline(mode); 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_ci REG_WRITE(map->dpll, 7718c2ecf20Sopenharmony_ci (REG_READ(map->dpll) & ~DPLL_LOCK) | DPLL_VCO_ENABLE); 7728c2ecf20Sopenharmony_ci REG_READ(map->dpll); 7738c2ecf20Sopenharmony_ci /* Wait for the clocks to stabilize. */ 7748c2ecf20Sopenharmony_ci udelay(150); /* 42 usec w/o calibration, 110 with. rounded up. */ 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_ci if (!(REG_READ(map->dpll) & DPLL_LOCK)) { 7778c2ecf20Sopenharmony_ci dev_err(dev->dev, "Failed to get DPLL lock\n"); 7788c2ecf20Sopenharmony_ci return -EBUSY; 7798c2ecf20Sopenharmony_ci } 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_ci { 7828c2ecf20Sopenharmony_ci int sdvo_pixel_multiply = adjusted_mode->clock / mode->clock; 7838c2ecf20Sopenharmony_ci REG_WRITE(map->dpll_md, (0 << DPLL_MD_UDI_DIVIDER_SHIFT) | ((sdvo_pixel_multiply - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT)); 7848c2ecf20Sopenharmony_ci } 7858c2ecf20Sopenharmony_ci 7868c2ecf20Sopenharmony_ci REG_WRITE(map->htotal, (adjusted_mode->crtc_hdisplay - 1) | 7878c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_htotal - 1) << 16)); 7888c2ecf20Sopenharmony_ci REG_WRITE(map->hblank, (adjusted_mode->crtc_hblank_start - 1) | 7898c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_hblank_end - 1) << 16)); 7908c2ecf20Sopenharmony_ci REG_WRITE(map->hsync, (adjusted_mode->crtc_hsync_start - 1) | 7918c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_hsync_end - 1) << 16)); 7928c2ecf20Sopenharmony_ci REG_WRITE(map->vtotal, (adjusted_mode->crtc_vdisplay - 1) | 7938c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_vtotal - 1) << 16)); 7948c2ecf20Sopenharmony_ci REG_WRITE(map->vblank, (adjusted_mode->crtc_vblank_start - 1) | 7958c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_vblank_end - 1) << 16)); 7968c2ecf20Sopenharmony_ci REG_WRITE(map->vsync, (adjusted_mode->crtc_vsync_start - 1) | 7978c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_vsync_end - 1) << 16)); 7988c2ecf20Sopenharmony_ci /* pipesrc and dspsize control the size that is scaled from, 7998c2ecf20Sopenharmony_ci * which should always be the user's requested size. 8008c2ecf20Sopenharmony_ci */ 8018c2ecf20Sopenharmony_ci REG_WRITE(map->size, 8028c2ecf20Sopenharmony_ci ((mode->vdisplay - 1) << 16) | (mode->hdisplay - 1)); 8038c2ecf20Sopenharmony_ci REG_WRITE(map->pos, 0); 8048c2ecf20Sopenharmony_ci REG_WRITE(map->src, 8058c2ecf20Sopenharmony_ci ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1)); 8068c2ecf20Sopenharmony_ci REG_WRITE(map->conf, pipeconf); 8078c2ecf20Sopenharmony_ci REG_READ(map->conf); 8088c2ecf20Sopenharmony_ci 8098c2ecf20Sopenharmony_ci gma_wait_for_vblank(dev); 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci REG_WRITE(map->cntr, dspcntr); 8128c2ecf20Sopenharmony_ci 8138c2ecf20Sopenharmony_ci /* Flush the plane changes */ 8148c2ecf20Sopenharmony_ci { 8158c2ecf20Sopenharmony_ci const struct drm_crtc_helper_funcs *crtc_funcs = 8168c2ecf20Sopenharmony_ci crtc->helper_private; 8178c2ecf20Sopenharmony_ci crtc_funcs->mode_set_base(crtc, x, y, old_fb); 8188c2ecf20Sopenharmony_ci } 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_ci gma_wait_for_vblank(dev); 8218c2ecf20Sopenharmony_ci 8228c2ecf20Sopenharmony_ci return 0; 8238c2ecf20Sopenharmony_ci} 8248c2ecf20Sopenharmony_ci 8258c2ecf20Sopenharmony_ci/** Derive the pixel clock for the given refclk and divisors for 8xx chips. */ 8268c2ecf20Sopenharmony_ci 8278c2ecf20Sopenharmony_ci/* FIXME: why are we using this, should it be cdv_ in this tree ? */ 8288c2ecf20Sopenharmony_ci 8298c2ecf20Sopenharmony_cistatic void i8xx_clock(int refclk, struct gma_clock_t *clock) 8308c2ecf20Sopenharmony_ci{ 8318c2ecf20Sopenharmony_ci clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2); 8328c2ecf20Sopenharmony_ci clock->p = clock->p1 * clock->p2; 8338c2ecf20Sopenharmony_ci clock->vco = refclk * clock->m / (clock->n + 2); 8348c2ecf20Sopenharmony_ci clock->dot = clock->vco / clock->p; 8358c2ecf20Sopenharmony_ci} 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci/* Returns the clock of the currently programmed mode of the given pipe. */ 8388c2ecf20Sopenharmony_cistatic int cdv_intel_crtc_clock_get(struct drm_device *dev, 8398c2ecf20Sopenharmony_ci struct drm_crtc *crtc) 8408c2ecf20Sopenharmony_ci{ 8418c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 8428c2ecf20Sopenharmony_ci struct gma_crtc *gma_crtc = to_gma_crtc(crtc); 8438c2ecf20Sopenharmony_ci int pipe = gma_crtc->pipe; 8448c2ecf20Sopenharmony_ci const struct psb_offset *map = &dev_priv->regmap[pipe]; 8458c2ecf20Sopenharmony_ci u32 dpll; 8468c2ecf20Sopenharmony_ci u32 fp; 8478c2ecf20Sopenharmony_ci struct gma_clock_t clock; 8488c2ecf20Sopenharmony_ci bool is_lvds; 8498c2ecf20Sopenharmony_ci struct psb_pipe *p = &dev_priv->regs.pipe[pipe]; 8508c2ecf20Sopenharmony_ci 8518c2ecf20Sopenharmony_ci if (gma_power_begin(dev, false)) { 8528c2ecf20Sopenharmony_ci dpll = REG_READ(map->dpll); 8538c2ecf20Sopenharmony_ci if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) 8548c2ecf20Sopenharmony_ci fp = REG_READ(map->fp0); 8558c2ecf20Sopenharmony_ci else 8568c2ecf20Sopenharmony_ci fp = REG_READ(map->fp1); 8578c2ecf20Sopenharmony_ci is_lvds = (pipe == 1) && (REG_READ(LVDS) & LVDS_PORT_EN); 8588c2ecf20Sopenharmony_ci gma_power_end(dev); 8598c2ecf20Sopenharmony_ci } else { 8608c2ecf20Sopenharmony_ci dpll = p->dpll; 8618c2ecf20Sopenharmony_ci if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) 8628c2ecf20Sopenharmony_ci fp = p->fp0; 8638c2ecf20Sopenharmony_ci else 8648c2ecf20Sopenharmony_ci fp = p->fp1; 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_ci is_lvds = (pipe == 1) && 8678c2ecf20Sopenharmony_ci (dev_priv->regs.psb.saveLVDS & LVDS_PORT_EN); 8688c2ecf20Sopenharmony_ci } 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; 8718c2ecf20Sopenharmony_ci clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; 8728c2ecf20Sopenharmony_ci clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci if (is_lvds) { 8758c2ecf20Sopenharmony_ci clock.p1 = 8768c2ecf20Sopenharmony_ci ffs((dpll & 8778c2ecf20Sopenharmony_ci DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> 8788c2ecf20Sopenharmony_ci DPLL_FPA01_P1_POST_DIV_SHIFT); 8798c2ecf20Sopenharmony_ci if (clock.p1 == 0) { 8808c2ecf20Sopenharmony_ci clock.p1 = 4; 8818c2ecf20Sopenharmony_ci dev_err(dev->dev, "PLL %d\n", dpll); 8828c2ecf20Sopenharmony_ci } 8838c2ecf20Sopenharmony_ci clock.p2 = 14; 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ci if ((dpll & PLL_REF_INPUT_MASK) == 8868c2ecf20Sopenharmony_ci PLLB_REF_INPUT_SPREADSPECTRUMIN) { 8878c2ecf20Sopenharmony_ci /* XXX: might not be 66MHz */ 8888c2ecf20Sopenharmony_ci i8xx_clock(66000, &clock); 8898c2ecf20Sopenharmony_ci } else 8908c2ecf20Sopenharmony_ci i8xx_clock(48000, &clock); 8918c2ecf20Sopenharmony_ci } else { 8928c2ecf20Sopenharmony_ci if (dpll & PLL_P1_DIVIDE_BY_TWO) 8938c2ecf20Sopenharmony_ci clock.p1 = 2; 8948c2ecf20Sopenharmony_ci else { 8958c2ecf20Sopenharmony_ci clock.p1 = 8968c2ecf20Sopenharmony_ci ((dpll & 8978c2ecf20Sopenharmony_ci DPLL_FPA01_P1_POST_DIV_MASK_I830) >> 8988c2ecf20Sopenharmony_ci DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; 8998c2ecf20Sopenharmony_ci } 9008c2ecf20Sopenharmony_ci if (dpll & PLL_P2_DIVIDE_BY_4) 9018c2ecf20Sopenharmony_ci clock.p2 = 4; 9028c2ecf20Sopenharmony_ci else 9038c2ecf20Sopenharmony_ci clock.p2 = 2; 9048c2ecf20Sopenharmony_ci 9058c2ecf20Sopenharmony_ci i8xx_clock(48000, &clock); 9068c2ecf20Sopenharmony_ci } 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_ci /* XXX: It would be nice to validate the clocks, but we can't reuse 9098c2ecf20Sopenharmony_ci * i830PllIsValid() because it relies on the xf86_config connector 9108c2ecf20Sopenharmony_ci * configuration being accurate, which it isn't necessarily. 9118c2ecf20Sopenharmony_ci */ 9128c2ecf20Sopenharmony_ci 9138c2ecf20Sopenharmony_ci return clock.dot; 9148c2ecf20Sopenharmony_ci} 9158c2ecf20Sopenharmony_ci 9168c2ecf20Sopenharmony_ci/** Returns the currently programmed mode of the given pipe. */ 9178c2ecf20Sopenharmony_cistruct drm_display_mode *cdv_intel_crtc_mode_get(struct drm_device *dev, 9188c2ecf20Sopenharmony_ci struct drm_crtc *crtc) 9198c2ecf20Sopenharmony_ci{ 9208c2ecf20Sopenharmony_ci struct gma_crtc *gma_crtc = to_gma_crtc(crtc); 9218c2ecf20Sopenharmony_ci int pipe = gma_crtc->pipe; 9228c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 9238c2ecf20Sopenharmony_ci struct psb_pipe *p = &dev_priv->regs.pipe[pipe]; 9248c2ecf20Sopenharmony_ci const struct psb_offset *map = &dev_priv->regmap[pipe]; 9258c2ecf20Sopenharmony_ci struct drm_display_mode *mode; 9268c2ecf20Sopenharmony_ci int htot; 9278c2ecf20Sopenharmony_ci int hsync; 9288c2ecf20Sopenharmony_ci int vtot; 9298c2ecf20Sopenharmony_ci int vsync; 9308c2ecf20Sopenharmony_ci 9318c2ecf20Sopenharmony_ci if (gma_power_begin(dev, false)) { 9328c2ecf20Sopenharmony_ci htot = REG_READ(map->htotal); 9338c2ecf20Sopenharmony_ci hsync = REG_READ(map->hsync); 9348c2ecf20Sopenharmony_ci vtot = REG_READ(map->vtotal); 9358c2ecf20Sopenharmony_ci vsync = REG_READ(map->vsync); 9368c2ecf20Sopenharmony_ci gma_power_end(dev); 9378c2ecf20Sopenharmony_ci } else { 9388c2ecf20Sopenharmony_ci htot = p->htotal; 9398c2ecf20Sopenharmony_ci hsync = p->hsync; 9408c2ecf20Sopenharmony_ci vtot = p->vtotal; 9418c2ecf20Sopenharmony_ci vsync = p->vsync; 9428c2ecf20Sopenharmony_ci } 9438c2ecf20Sopenharmony_ci 9448c2ecf20Sopenharmony_ci mode = kzalloc(sizeof(*mode), GFP_KERNEL); 9458c2ecf20Sopenharmony_ci if (!mode) 9468c2ecf20Sopenharmony_ci return NULL; 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_ci mode->clock = cdv_intel_crtc_clock_get(dev, crtc); 9498c2ecf20Sopenharmony_ci mode->hdisplay = (htot & 0xffff) + 1; 9508c2ecf20Sopenharmony_ci mode->htotal = ((htot & 0xffff0000) >> 16) + 1; 9518c2ecf20Sopenharmony_ci mode->hsync_start = (hsync & 0xffff) + 1; 9528c2ecf20Sopenharmony_ci mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; 9538c2ecf20Sopenharmony_ci mode->vdisplay = (vtot & 0xffff) + 1; 9548c2ecf20Sopenharmony_ci mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; 9558c2ecf20Sopenharmony_ci mode->vsync_start = (vsync & 0xffff) + 1; 9568c2ecf20Sopenharmony_ci mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; 9578c2ecf20Sopenharmony_ci 9588c2ecf20Sopenharmony_ci drm_mode_set_name(mode); 9598c2ecf20Sopenharmony_ci drm_mode_set_crtcinfo(mode, 0); 9608c2ecf20Sopenharmony_ci 9618c2ecf20Sopenharmony_ci return mode; 9628c2ecf20Sopenharmony_ci} 9638c2ecf20Sopenharmony_ci 9648c2ecf20Sopenharmony_ciconst struct drm_crtc_helper_funcs cdv_intel_helper_funcs = { 9658c2ecf20Sopenharmony_ci .dpms = gma_crtc_dpms, 9668c2ecf20Sopenharmony_ci .mode_set = cdv_intel_crtc_mode_set, 9678c2ecf20Sopenharmony_ci .mode_set_base = gma_pipe_set_base, 9688c2ecf20Sopenharmony_ci .prepare = gma_crtc_prepare, 9698c2ecf20Sopenharmony_ci .commit = gma_crtc_commit, 9708c2ecf20Sopenharmony_ci .disable = gma_crtc_disable, 9718c2ecf20Sopenharmony_ci}; 9728c2ecf20Sopenharmony_ci 9738c2ecf20Sopenharmony_ciconst struct drm_crtc_funcs cdv_intel_crtc_funcs = { 9748c2ecf20Sopenharmony_ci .cursor_set = gma_crtc_cursor_set, 9758c2ecf20Sopenharmony_ci .cursor_move = gma_crtc_cursor_move, 9768c2ecf20Sopenharmony_ci .gamma_set = gma_crtc_gamma_set, 9778c2ecf20Sopenharmony_ci .set_config = gma_crtc_set_config, 9788c2ecf20Sopenharmony_ci .destroy = gma_crtc_destroy, 9798c2ecf20Sopenharmony_ci .page_flip = gma_crtc_page_flip, 9808c2ecf20Sopenharmony_ci .enable_vblank = psb_enable_vblank, 9818c2ecf20Sopenharmony_ci .disable_vblank = psb_disable_vblank, 9828c2ecf20Sopenharmony_ci .get_vblank_counter = psb_get_vblank_counter, 9838c2ecf20Sopenharmony_ci}; 9848c2ecf20Sopenharmony_ci 9858c2ecf20Sopenharmony_ciconst struct gma_clock_funcs cdv_clock_funcs = { 9868c2ecf20Sopenharmony_ci .clock = cdv_intel_clock, 9878c2ecf20Sopenharmony_ci .limit = cdv_intel_limit, 9888c2ecf20Sopenharmony_ci .pll_is_valid = gma_pll_is_valid, 9898c2ecf20Sopenharmony_ci}; 990