18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright © 2009 Intel Corporation 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <linux/delay.h> 78c2ecf20Sopenharmony_ci#include <linux/i2c.h> 88c2ecf20Sopenharmony_ci#include <linux/pm_runtime.h> 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <drm/drm_fourcc.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include "framebuffer.h" 138c2ecf20Sopenharmony_ci#include "gma_display.h" 148c2ecf20Sopenharmony_ci#include "power.h" 158c2ecf20Sopenharmony_ci#include "psb_drv.h" 168c2ecf20Sopenharmony_ci#include "psb_intel_drv.h" 178c2ecf20Sopenharmony_ci#include "psb_intel_reg.h" 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define MRST_LIMIT_LVDS_100L 0 208c2ecf20Sopenharmony_ci#define MRST_LIMIT_LVDS_83 1 218c2ecf20Sopenharmony_ci#define MRST_LIMIT_LVDS_100 2 228c2ecf20Sopenharmony_ci#define MRST_LIMIT_SDVO 3 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define MRST_DOT_MIN 19750 258c2ecf20Sopenharmony_ci#define MRST_DOT_MAX 120000 268c2ecf20Sopenharmony_ci#define MRST_M_MIN_100L 20 278c2ecf20Sopenharmony_ci#define MRST_M_MIN_100 10 288c2ecf20Sopenharmony_ci#define MRST_M_MIN_83 12 298c2ecf20Sopenharmony_ci#define MRST_M_MAX_100L 34 308c2ecf20Sopenharmony_ci#define MRST_M_MAX_100 17 318c2ecf20Sopenharmony_ci#define MRST_M_MAX_83 20 328c2ecf20Sopenharmony_ci#define MRST_P1_MIN 2 338c2ecf20Sopenharmony_ci#define MRST_P1_MAX_0 7 348c2ecf20Sopenharmony_ci#define MRST_P1_MAX_1 8 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistatic bool mrst_lvds_find_best_pll(const struct gma_limit_t *limit, 378c2ecf20Sopenharmony_ci struct drm_crtc *crtc, int target, 388c2ecf20Sopenharmony_ci int refclk, struct gma_clock_t *best_clock); 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistatic bool mrst_sdvo_find_best_pll(const struct gma_limit_t *limit, 418c2ecf20Sopenharmony_ci struct drm_crtc *crtc, int target, 428c2ecf20Sopenharmony_ci int refclk, struct gma_clock_t *best_clock); 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic const struct gma_limit_t mrst_limits[] = { 458c2ecf20Sopenharmony_ci { /* MRST_LIMIT_LVDS_100L */ 468c2ecf20Sopenharmony_ci .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX}, 478c2ecf20Sopenharmony_ci .m = {.min = MRST_M_MIN_100L, .max = MRST_M_MAX_100L}, 488c2ecf20Sopenharmony_ci .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_1}, 498c2ecf20Sopenharmony_ci .find_pll = mrst_lvds_find_best_pll, 508c2ecf20Sopenharmony_ci }, 518c2ecf20Sopenharmony_ci { /* MRST_LIMIT_LVDS_83L */ 528c2ecf20Sopenharmony_ci .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX}, 538c2ecf20Sopenharmony_ci .m = {.min = MRST_M_MIN_83, .max = MRST_M_MAX_83}, 548c2ecf20Sopenharmony_ci .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_0}, 558c2ecf20Sopenharmony_ci .find_pll = mrst_lvds_find_best_pll, 568c2ecf20Sopenharmony_ci }, 578c2ecf20Sopenharmony_ci { /* MRST_LIMIT_LVDS_100 */ 588c2ecf20Sopenharmony_ci .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX}, 598c2ecf20Sopenharmony_ci .m = {.min = MRST_M_MIN_100, .max = MRST_M_MAX_100}, 608c2ecf20Sopenharmony_ci .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_1}, 618c2ecf20Sopenharmony_ci .find_pll = mrst_lvds_find_best_pll, 628c2ecf20Sopenharmony_ci }, 638c2ecf20Sopenharmony_ci { /* MRST_LIMIT_SDVO */ 648c2ecf20Sopenharmony_ci .vco = {.min = 1400000, .max = 2800000}, 658c2ecf20Sopenharmony_ci .n = {.min = 3, .max = 7}, 668c2ecf20Sopenharmony_ci .m = {.min = 80, .max = 137}, 678c2ecf20Sopenharmony_ci .p1 = {.min = 1, .max = 2}, 688c2ecf20Sopenharmony_ci .p2 = {.dot_limit = 200000, .p2_slow = 10, .p2_fast = 10}, 698c2ecf20Sopenharmony_ci .find_pll = mrst_sdvo_find_best_pll, 708c2ecf20Sopenharmony_ci }, 718c2ecf20Sopenharmony_ci}; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#define MRST_M_MIN 10 748c2ecf20Sopenharmony_cistatic const u32 oaktrail_m_converts[] = { 758c2ecf20Sopenharmony_ci 0x2B, 0x15, 0x2A, 0x35, 0x1A, 0x0D, 0x26, 0x33, 0x19, 0x2C, 768c2ecf20Sopenharmony_ci 0x36, 0x3B, 0x1D, 0x2E, 0x37, 0x1B, 0x2D, 0x16, 0x0B, 0x25, 778c2ecf20Sopenharmony_ci 0x12, 0x09, 0x24, 0x32, 0x39, 0x1c, 788c2ecf20Sopenharmony_ci}; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistatic const struct gma_limit_t *mrst_limit(struct drm_crtc *crtc, 818c2ecf20Sopenharmony_ci int refclk) 828c2ecf20Sopenharmony_ci{ 838c2ecf20Sopenharmony_ci const struct gma_limit_t *limit = NULL; 848c2ecf20Sopenharmony_ci struct drm_device *dev = crtc->dev; 858c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci if (gma_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) 888c2ecf20Sopenharmony_ci || gma_pipe_has_type(crtc, INTEL_OUTPUT_MIPI)) { 898c2ecf20Sopenharmony_ci switch (dev_priv->core_freq) { 908c2ecf20Sopenharmony_ci case 100: 918c2ecf20Sopenharmony_ci limit = &mrst_limits[MRST_LIMIT_LVDS_100L]; 928c2ecf20Sopenharmony_ci break; 938c2ecf20Sopenharmony_ci case 166: 948c2ecf20Sopenharmony_ci limit = &mrst_limits[MRST_LIMIT_LVDS_83]; 958c2ecf20Sopenharmony_ci break; 968c2ecf20Sopenharmony_ci case 200: 978c2ecf20Sopenharmony_ci limit = &mrst_limits[MRST_LIMIT_LVDS_100]; 988c2ecf20Sopenharmony_ci break; 998c2ecf20Sopenharmony_ci } 1008c2ecf20Sopenharmony_ci } else if (gma_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) { 1018c2ecf20Sopenharmony_ci limit = &mrst_limits[MRST_LIMIT_SDVO]; 1028c2ecf20Sopenharmony_ci } else { 1038c2ecf20Sopenharmony_ci limit = NULL; 1048c2ecf20Sopenharmony_ci dev_err(dev->dev, "mrst_limit Wrong display type.\n"); 1058c2ecf20Sopenharmony_ci } 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci return limit; 1088c2ecf20Sopenharmony_ci} 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci/** Derive the pixel clock for the given refclk and divisors for 8xx chips. */ 1118c2ecf20Sopenharmony_cistatic void mrst_lvds_clock(int refclk, struct gma_clock_t *clock) 1128c2ecf20Sopenharmony_ci{ 1138c2ecf20Sopenharmony_ci clock->dot = (refclk * clock->m) / (14 * clock->p1); 1148c2ecf20Sopenharmony_ci} 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_cistatic void mrst_print_pll(struct gma_clock_t *clock) 1178c2ecf20Sopenharmony_ci{ 1188c2ecf20Sopenharmony_ci DRM_DEBUG_DRIVER("dotclock=%d, m=%d, m1=%d, m2=%d, n=%d, p1=%d, p2=%d\n", 1198c2ecf20Sopenharmony_ci clock->dot, clock->m, clock->m1, clock->m2, clock->n, 1208c2ecf20Sopenharmony_ci clock->p1, clock->p2); 1218c2ecf20Sopenharmony_ci} 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistatic bool mrst_sdvo_find_best_pll(const struct gma_limit_t *limit, 1248c2ecf20Sopenharmony_ci struct drm_crtc *crtc, int target, 1258c2ecf20Sopenharmony_ci int refclk, struct gma_clock_t *best_clock) 1268c2ecf20Sopenharmony_ci{ 1278c2ecf20Sopenharmony_ci struct gma_clock_t clock; 1288c2ecf20Sopenharmony_ci u32 target_vco, actual_freq; 1298c2ecf20Sopenharmony_ci s32 freq_error, min_error = 100000; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci memset(best_clock, 0, sizeof(*best_clock)); 1328c2ecf20Sopenharmony_ci memset(&clock, 0, sizeof(clock)); 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci for (clock.m = limit->m.min; clock.m <= limit->m.max; clock.m++) { 1358c2ecf20Sopenharmony_ci for (clock.n = limit->n.min; clock.n <= limit->n.max; 1368c2ecf20Sopenharmony_ci clock.n++) { 1378c2ecf20Sopenharmony_ci for (clock.p1 = limit->p1.min; 1388c2ecf20Sopenharmony_ci clock.p1 <= limit->p1.max; clock.p1++) { 1398c2ecf20Sopenharmony_ci /* p2 value always stored in p2_slow on SDVO */ 1408c2ecf20Sopenharmony_ci clock.p = clock.p1 * limit->p2.p2_slow; 1418c2ecf20Sopenharmony_ci target_vco = target * clock.p; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci /* VCO will increase at this point so break */ 1448c2ecf20Sopenharmony_ci if (target_vco > limit->vco.max) 1458c2ecf20Sopenharmony_ci break; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci if (target_vco < limit->vco.min) 1488c2ecf20Sopenharmony_ci continue; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci actual_freq = (refclk * clock.m) / 1518c2ecf20Sopenharmony_ci (clock.n * clock.p); 1528c2ecf20Sopenharmony_ci freq_error = 10000 - 1538c2ecf20Sopenharmony_ci ((target * 10000) / actual_freq); 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci if (freq_error < -min_error) { 1568c2ecf20Sopenharmony_ci /* freq_error will start to decrease at 1578c2ecf20Sopenharmony_ci this point so break */ 1588c2ecf20Sopenharmony_ci break; 1598c2ecf20Sopenharmony_ci } 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci if (freq_error < 0) 1628c2ecf20Sopenharmony_ci freq_error = -freq_error; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci if (freq_error < min_error) { 1658c2ecf20Sopenharmony_ci min_error = freq_error; 1668c2ecf20Sopenharmony_ci *best_clock = clock; 1678c2ecf20Sopenharmony_ci } 1688c2ecf20Sopenharmony_ci } 1698c2ecf20Sopenharmony_ci } 1708c2ecf20Sopenharmony_ci if (min_error == 0) 1718c2ecf20Sopenharmony_ci break; 1728c2ecf20Sopenharmony_ci } 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci return min_error == 0; 1758c2ecf20Sopenharmony_ci} 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci/** 1788c2ecf20Sopenharmony_ci * Returns a set of divisors for the desired target clock with the given refclk, 1798c2ecf20Sopenharmony_ci * or FALSE. Divisor values are the actual divisors for 1808c2ecf20Sopenharmony_ci */ 1818c2ecf20Sopenharmony_cistatic bool mrst_lvds_find_best_pll(const struct gma_limit_t *limit, 1828c2ecf20Sopenharmony_ci struct drm_crtc *crtc, int target, 1838c2ecf20Sopenharmony_ci int refclk, struct gma_clock_t *best_clock) 1848c2ecf20Sopenharmony_ci{ 1858c2ecf20Sopenharmony_ci struct gma_clock_t clock; 1868c2ecf20Sopenharmony_ci int err = target; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci memset(best_clock, 0, sizeof(*best_clock)); 1898c2ecf20Sopenharmony_ci memset(&clock, 0, sizeof(clock)); 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci for (clock.m = limit->m.min; clock.m <= limit->m.max; clock.m++) { 1928c2ecf20Sopenharmony_ci for (clock.p1 = limit->p1.min; clock.p1 <= limit->p1.max; 1938c2ecf20Sopenharmony_ci clock.p1++) { 1948c2ecf20Sopenharmony_ci int this_err; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci mrst_lvds_clock(refclk, &clock); 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci this_err = abs(clock.dot - target); 1998c2ecf20Sopenharmony_ci if (this_err < err) { 2008c2ecf20Sopenharmony_ci *best_clock = clock; 2018c2ecf20Sopenharmony_ci err = this_err; 2028c2ecf20Sopenharmony_ci } 2038c2ecf20Sopenharmony_ci } 2048c2ecf20Sopenharmony_ci } 2058c2ecf20Sopenharmony_ci return err != target; 2068c2ecf20Sopenharmony_ci} 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci/** 2098c2ecf20Sopenharmony_ci * Sets the power management mode of the pipe and plane. 2108c2ecf20Sopenharmony_ci * 2118c2ecf20Sopenharmony_ci * This code should probably grow support for turning the cursor off and back 2128c2ecf20Sopenharmony_ci * on appropriately at the same time as we're turning the pipe off/on. 2138c2ecf20Sopenharmony_ci */ 2148c2ecf20Sopenharmony_cistatic void oaktrail_crtc_dpms(struct drm_crtc *crtc, int mode) 2158c2ecf20Sopenharmony_ci{ 2168c2ecf20Sopenharmony_ci struct drm_device *dev = crtc->dev; 2178c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 2188c2ecf20Sopenharmony_ci struct gma_crtc *gma_crtc = to_gma_crtc(crtc); 2198c2ecf20Sopenharmony_ci int pipe = gma_crtc->pipe; 2208c2ecf20Sopenharmony_ci const struct psb_offset *map = &dev_priv->regmap[pipe]; 2218c2ecf20Sopenharmony_ci u32 temp; 2228c2ecf20Sopenharmony_ci int i; 2238c2ecf20Sopenharmony_ci int need_aux = gma_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ? 1 : 0; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci if (gma_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { 2268c2ecf20Sopenharmony_ci oaktrail_crtc_hdmi_dpms(crtc, mode); 2278c2ecf20Sopenharmony_ci return; 2288c2ecf20Sopenharmony_ci } 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci if (!gma_power_begin(dev, true)) 2318c2ecf20Sopenharmony_ci return; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci /* XXX: When our outputs are all unaware of DPMS modes other than off 2348c2ecf20Sopenharmony_ci * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC. 2358c2ecf20Sopenharmony_ci */ 2368c2ecf20Sopenharmony_ci switch (mode) { 2378c2ecf20Sopenharmony_ci case DRM_MODE_DPMS_ON: 2388c2ecf20Sopenharmony_ci case DRM_MODE_DPMS_STANDBY: 2398c2ecf20Sopenharmony_ci case DRM_MODE_DPMS_SUSPEND: 2408c2ecf20Sopenharmony_ci for (i = 0; i <= need_aux; i++) { 2418c2ecf20Sopenharmony_ci /* Enable the DPLL */ 2428c2ecf20Sopenharmony_ci temp = REG_READ_WITH_AUX(map->dpll, i); 2438c2ecf20Sopenharmony_ci if ((temp & DPLL_VCO_ENABLE) == 0) { 2448c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->dpll, temp, i); 2458c2ecf20Sopenharmony_ci REG_READ_WITH_AUX(map->dpll, i); 2468c2ecf20Sopenharmony_ci /* Wait for the clocks to stabilize. */ 2478c2ecf20Sopenharmony_ci udelay(150); 2488c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->dpll, 2498c2ecf20Sopenharmony_ci temp | DPLL_VCO_ENABLE, i); 2508c2ecf20Sopenharmony_ci REG_READ_WITH_AUX(map->dpll, i); 2518c2ecf20Sopenharmony_ci /* Wait for the clocks to stabilize. */ 2528c2ecf20Sopenharmony_ci udelay(150); 2538c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->dpll, 2548c2ecf20Sopenharmony_ci temp | DPLL_VCO_ENABLE, i); 2558c2ecf20Sopenharmony_ci REG_READ_WITH_AUX(map->dpll, i); 2568c2ecf20Sopenharmony_ci /* Wait for the clocks to stabilize. */ 2578c2ecf20Sopenharmony_ci udelay(150); 2588c2ecf20Sopenharmony_ci } 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci /* Enable the pipe */ 2618c2ecf20Sopenharmony_ci temp = REG_READ_WITH_AUX(map->conf, i); 2628c2ecf20Sopenharmony_ci if ((temp & PIPEACONF_ENABLE) == 0) { 2638c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->conf, 2648c2ecf20Sopenharmony_ci temp | PIPEACONF_ENABLE, i); 2658c2ecf20Sopenharmony_ci } 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci /* Enable the plane */ 2688c2ecf20Sopenharmony_ci temp = REG_READ_WITH_AUX(map->cntr, i); 2698c2ecf20Sopenharmony_ci if ((temp & DISPLAY_PLANE_ENABLE) == 0) { 2708c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->cntr, 2718c2ecf20Sopenharmony_ci temp | DISPLAY_PLANE_ENABLE, 2728c2ecf20Sopenharmony_ci i); 2738c2ecf20Sopenharmony_ci /* Flush the plane changes */ 2748c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->base, 2758c2ecf20Sopenharmony_ci REG_READ_WITH_AUX(map->base, i), i); 2768c2ecf20Sopenharmony_ci } 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci } 2798c2ecf20Sopenharmony_ci gma_crtc_load_lut(crtc); 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci /* Give the overlay scaler a chance to enable 2828c2ecf20Sopenharmony_ci if it's on this pipe */ 2838c2ecf20Sopenharmony_ci /* psb_intel_crtc_dpms_video(crtc, true); TODO */ 2848c2ecf20Sopenharmony_ci break; 2858c2ecf20Sopenharmony_ci case DRM_MODE_DPMS_OFF: 2868c2ecf20Sopenharmony_ci /* Give the overlay scaler a chance to disable 2878c2ecf20Sopenharmony_ci * if it's on this pipe */ 2888c2ecf20Sopenharmony_ci /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */ 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci for (i = 0; i <= need_aux; i++) { 2918c2ecf20Sopenharmony_ci /* Disable the VGA plane that we never use */ 2928c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(VGACNTRL, VGA_DISP_DISABLE, i); 2938c2ecf20Sopenharmony_ci /* Disable display plane */ 2948c2ecf20Sopenharmony_ci temp = REG_READ_WITH_AUX(map->cntr, i); 2958c2ecf20Sopenharmony_ci if ((temp & DISPLAY_PLANE_ENABLE) != 0) { 2968c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->cntr, 2978c2ecf20Sopenharmony_ci temp & ~DISPLAY_PLANE_ENABLE, i); 2988c2ecf20Sopenharmony_ci /* Flush the plane changes */ 2998c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->base, 3008c2ecf20Sopenharmony_ci REG_READ(map->base), i); 3018c2ecf20Sopenharmony_ci REG_READ_WITH_AUX(map->base, i); 3028c2ecf20Sopenharmony_ci } 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci /* Next, disable display pipes */ 3058c2ecf20Sopenharmony_ci temp = REG_READ_WITH_AUX(map->conf, i); 3068c2ecf20Sopenharmony_ci if ((temp & PIPEACONF_ENABLE) != 0) { 3078c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->conf, 3088c2ecf20Sopenharmony_ci temp & ~PIPEACONF_ENABLE, i); 3098c2ecf20Sopenharmony_ci REG_READ_WITH_AUX(map->conf, i); 3108c2ecf20Sopenharmony_ci } 3118c2ecf20Sopenharmony_ci /* Wait for for the pipe disable to take effect. */ 3128c2ecf20Sopenharmony_ci gma_wait_for_vblank(dev); 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci temp = REG_READ_WITH_AUX(map->dpll, i); 3158c2ecf20Sopenharmony_ci if ((temp & DPLL_VCO_ENABLE) != 0) { 3168c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->dpll, 3178c2ecf20Sopenharmony_ci temp & ~DPLL_VCO_ENABLE, i); 3188c2ecf20Sopenharmony_ci REG_READ_WITH_AUX(map->dpll, i); 3198c2ecf20Sopenharmony_ci } 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci /* Wait for the clocks to turn off. */ 3228c2ecf20Sopenharmony_ci udelay(150); 3238c2ecf20Sopenharmony_ci } 3248c2ecf20Sopenharmony_ci break; 3258c2ecf20Sopenharmony_ci } 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci /* Set FIFO Watermarks (values taken from EMGD) */ 3288c2ecf20Sopenharmony_ci REG_WRITE(DSPARB, 0x3f80); 3298c2ecf20Sopenharmony_ci REG_WRITE(DSPFW1, 0x3f8f0404); 3308c2ecf20Sopenharmony_ci REG_WRITE(DSPFW2, 0x04040f04); 3318c2ecf20Sopenharmony_ci REG_WRITE(DSPFW3, 0x0); 3328c2ecf20Sopenharmony_ci REG_WRITE(DSPFW4, 0x04040404); 3338c2ecf20Sopenharmony_ci REG_WRITE(DSPFW5, 0x04040404); 3348c2ecf20Sopenharmony_ci REG_WRITE(DSPFW6, 0x78); 3358c2ecf20Sopenharmony_ci REG_WRITE(DSPCHICKENBIT, REG_READ(DSPCHICKENBIT) | 0xc040); 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci gma_power_end(dev); 3388c2ecf20Sopenharmony_ci} 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci/** 3418c2ecf20Sopenharmony_ci * Return the pipe currently connected to the panel fitter, 3428c2ecf20Sopenharmony_ci * or -1 if the panel fitter is not present or not in use 3438c2ecf20Sopenharmony_ci */ 3448c2ecf20Sopenharmony_cistatic int oaktrail_panel_fitter_pipe(struct drm_device *dev) 3458c2ecf20Sopenharmony_ci{ 3468c2ecf20Sopenharmony_ci u32 pfit_control; 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci pfit_control = REG_READ(PFIT_CONTROL); 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci /* See if the panel fitter is in use */ 3518c2ecf20Sopenharmony_ci if ((pfit_control & PFIT_ENABLE) == 0) 3528c2ecf20Sopenharmony_ci return -1; 3538c2ecf20Sopenharmony_ci return (pfit_control >> 29) & 3; 3548c2ecf20Sopenharmony_ci} 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_cistatic int oaktrail_crtc_mode_set(struct drm_crtc *crtc, 3578c2ecf20Sopenharmony_ci struct drm_display_mode *mode, 3588c2ecf20Sopenharmony_ci struct drm_display_mode *adjusted_mode, 3598c2ecf20Sopenharmony_ci int x, int y, 3608c2ecf20Sopenharmony_ci struct drm_framebuffer *old_fb) 3618c2ecf20Sopenharmony_ci{ 3628c2ecf20Sopenharmony_ci struct drm_device *dev = crtc->dev; 3638c2ecf20Sopenharmony_ci struct gma_crtc *gma_crtc = to_gma_crtc(crtc); 3648c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 3658c2ecf20Sopenharmony_ci int pipe = gma_crtc->pipe; 3668c2ecf20Sopenharmony_ci const struct psb_offset *map = &dev_priv->regmap[pipe]; 3678c2ecf20Sopenharmony_ci int refclk = 0; 3688c2ecf20Sopenharmony_ci struct gma_clock_t clock; 3698c2ecf20Sopenharmony_ci const struct gma_limit_t *limit; 3708c2ecf20Sopenharmony_ci u32 dpll = 0, fp = 0, dspcntr, pipeconf; 3718c2ecf20Sopenharmony_ci bool ok, is_sdvo = false; 3728c2ecf20Sopenharmony_ci bool is_lvds = false; 3738c2ecf20Sopenharmony_ci bool is_mipi = false; 3748c2ecf20Sopenharmony_ci struct drm_mode_config *mode_config = &dev->mode_config; 3758c2ecf20Sopenharmony_ci struct gma_encoder *gma_encoder = NULL; 3768c2ecf20Sopenharmony_ci uint64_t scalingType = DRM_MODE_SCALE_FULLSCREEN; 3778c2ecf20Sopenharmony_ci struct drm_connector *connector; 3788c2ecf20Sopenharmony_ci int i; 3798c2ecf20Sopenharmony_ci int need_aux = gma_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ? 1 : 0; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci if (gma_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) 3828c2ecf20Sopenharmony_ci return oaktrail_crtc_hdmi_mode_set(crtc, mode, adjusted_mode, x, y, old_fb); 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci if (!gma_power_begin(dev, true)) 3858c2ecf20Sopenharmony_ci return 0; 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci memcpy(&gma_crtc->saved_mode, 3888c2ecf20Sopenharmony_ci mode, 3898c2ecf20Sopenharmony_ci sizeof(struct drm_display_mode)); 3908c2ecf20Sopenharmony_ci memcpy(&gma_crtc->saved_adjusted_mode, 3918c2ecf20Sopenharmony_ci adjusted_mode, 3928c2ecf20Sopenharmony_ci sizeof(struct drm_display_mode)); 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci list_for_each_entry(connector, &mode_config->connector_list, head) { 3958c2ecf20Sopenharmony_ci if (!connector->encoder || connector->encoder->crtc != crtc) 3968c2ecf20Sopenharmony_ci continue; 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci gma_encoder = gma_attached_encoder(connector); 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci switch (gma_encoder->type) { 4018c2ecf20Sopenharmony_ci case INTEL_OUTPUT_LVDS: 4028c2ecf20Sopenharmony_ci is_lvds = true; 4038c2ecf20Sopenharmony_ci break; 4048c2ecf20Sopenharmony_ci case INTEL_OUTPUT_SDVO: 4058c2ecf20Sopenharmony_ci is_sdvo = true; 4068c2ecf20Sopenharmony_ci break; 4078c2ecf20Sopenharmony_ci case INTEL_OUTPUT_MIPI: 4088c2ecf20Sopenharmony_ci is_mipi = true; 4098c2ecf20Sopenharmony_ci break; 4108c2ecf20Sopenharmony_ci } 4118c2ecf20Sopenharmony_ci } 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci /* Disable the VGA plane that we never use */ 4148c2ecf20Sopenharmony_ci for (i = 0; i <= need_aux; i++) 4158c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(VGACNTRL, VGA_DISP_DISABLE, i); 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci /* Disable the panel fitter if it was on our pipe */ 4188c2ecf20Sopenharmony_ci if (oaktrail_panel_fitter_pipe(dev) == pipe) 4198c2ecf20Sopenharmony_ci REG_WRITE(PFIT_CONTROL, 0); 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci for (i = 0; i <= need_aux; i++) { 4228c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->src, ((mode->crtc_hdisplay - 1) << 16) | 4238c2ecf20Sopenharmony_ci (mode->crtc_vdisplay - 1), i); 4248c2ecf20Sopenharmony_ci } 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci if (gma_encoder) 4278c2ecf20Sopenharmony_ci drm_object_property_get_value(&connector->base, 4288c2ecf20Sopenharmony_ci dev->mode_config.scaling_mode_property, &scalingType); 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci if (scalingType == DRM_MODE_SCALE_NO_SCALE) { 4318c2ecf20Sopenharmony_ci /* Moorestown doesn't have register support for centering so 4328c2ecf20Sopenharmony_ci * we need to mess with the h/vblank and h/vsync start and 4338c2ecf20Sopenharmony_ci * ends to get centering */ 4348c2ecf20Sopenharmony_ci int offsetX = 0, offsetY = 0; 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci offsetX = (adjusted_mode->crtc_hdisplay - 4378c2ecf20Sopenharmony_ci mode->crtc_hdisplay) / 2; 4388c2ecf20Sopenharmony_ci offsetY = (adjusted_mode->crtc_vdisplay - 4398c2ecf20Sopenharmony_ci mode->crtc_vdisplay) / 2; 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci for (i = 0; i <= need_aux; i++) { 4428c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->htotal, (mode->crtc_hdisplay - 1) | 4438c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_htotal - 1) << 16), i); 4448c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->vtotal, (mode->crtc_vdisplay - 1) | 4458c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_vtotal - 1) << 16), i); 4468c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->hblank, 4478c2ecf20Sopenharmony_ci (adjusted_mode->crtc_hblank_start - offsetX - 1) | 4488c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_hblank_end - offsetX - 1) << 16), i); 4498c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->hsync, 4508c2ecf20Sopenharmony_ci (adjusted_mode->crtc_hsync_start - offsetX - 1) | 4518c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_hsync_end - offsetX - 1) << 16), i); 4528c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->vblank, 4538c2ecf20Sopenharmony_ci (adjusted_mode->crtc_vblank_start - offsetY - 1) | 4548c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_vblank_end - offsetY - 1) << 16), i); 4558c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->vsync, 4568c2ecf20Sopenharmony_ci (adjusted_mode->crtc_vsync_start - offsetY - 1) | 4578c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_vsync_end - offsetY - 1) << 16), i); 4588c2ecf20Sopenharmony_ci } 4598c2ecf20Sopenharmony_ci } else { 4608c2ecf20Sopenharmony_ci for (i = 0; i <= need_aux; i++) { 4618c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->htotal, (adjusted_mode->crtc_hdisplay - 1) | 4628c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_htotal - 1) << 16), i); 4638c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->vtotal, (adjusted_mode->crtc_vdisplay - 1) | 4648c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_vtotal - 1) << 16), i); 4658c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->hblank, (adjusted_mode->crtc_hblank_start - 1) | 4668c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_hblank_end - 1) << 16), i); 4678c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->hsync, (adjusted_mode->crtc_hsync_start - 1) | 4688c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_hsync_end - 1) << 16), i); 4698c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->vblank, (adjusted_mode->crtc_vblank_start - 1) | 4708c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_vblank_end - 1) << 16), i); 4718c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->vsync, (adjusted_mode->crtc_vsync_start - 1) | 4728c2ecf20Sopenharmony_ci ((adjusted_mode->crtc_vsync_end - 1) << 16), i); 4738c2ecf20Sopenharmony_ci } 4748c2ecf20Sopenharmony_ci } 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci /* Flush the plane changes */ 4778c2ecf20Sopenharmony_ci { 4788c2ecf20Sopenharmony_ci const struct drm_crtc_helper_funcs *crtc_funcs = 4798c2ecf20Sopenharmony_ci crtc->helper_private; 4808c2ecf20Sopenharmony_ci crtc_funcs->mode_set_base(crtc, x, y, old_fb); 4818c2ecf20Sopenharmony_ci } 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci /* setup pipeconf */ 4848c2ecf20Sopenharmony_ci pipeconf = REG_READ(map->conf); 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci /* Set up the display plane register */ 4878c2ecf20Sopenharmony_ci dspcntr = REG_READ(map->cntr); 4888c2ecf20Sopenharmony_ci dspcntr |= DISPPLANE_GAMMA_ENABLE; 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci if (pipe == 0) 4918c2ecf20Sopenharmony_ci dspcntr |= DISPPLANE_SEL_PIPE_A; 4928c2ecf20Sopenharmony_ci else 4938c2ecf20Sopenharmony_ci dspcntr |= DISPPLANE_SEL_PIPE_B; 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci if (is_mipi) 4968c2ecf20Sopenharmony_ci goto oaktrail_crtc_mode_set_exit; 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci dpll = 0; /*BIT16 = 0 for 100MHz reference */ 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci refclk = is_sdvo ? 96000 : dev_priv->core_freq * 1000; 5028c2ecf20Sopenharmony_ci limit = mrst_limit(crtc, refclk); 5038c2ecf20Sopenharmony_ci ok = limit->find_pll(limit, crtc, adjusted_mode->clock, 5048c2ecf20Sopenharmony_ci refclk, &clock); 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci if (is_sdvo) { 5078c2ecf20Sopenharmony_ci /* Convert calculated values to register values */ 5088c2ecf20Sopenharmony_ci clock.p1 = (1L << (clock.p1 - 1)); 5098c2ecf20Sopenharmony_ci clock.m -= 2; 5108c2ecf20Sopenharmony_ci clock.n = (1L << (clock.n - 1)); 5118c2ecf20Sopenharmony_ci } 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci if (!ok) 5148c2ecf20Sopenharmony_ci DRM_ERROR("Failed to find proper PLL settings"); 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci mrst_print_pll(&clock); 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci if (is_sdvo) 5198c2ecf20Sopenharmony_ci fp = clock.n << 16 | clock.m; 5208c2ecf20Sopenharmony_ci else 5218c2ecf20Sopenharmony_ci fp = oaktrail_m_converts[(clock.m - MRST_M_MIN)] << 8; 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci dpll |= DPLL_VGA_MODE_DIS; 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci dpll |= DPLL_VCO_ENABLE; 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci if (is_lvds) 5298c2ecf20Sopenharmony_ci dpll |= DPLLA_MODE_LVDS; 5308c2ecf20Sopenharmony_ci else 5318c2ecf20Sopenharmony_ci dpll |= DPLLB_MODE_DAC_SERIAL; 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ci if (is_sdvo) { 5348c2ecf20Sopenharmony_ci int sdvo_pixel_multiply = 5358c2ecf20Sopenharmony_ci adjusted_mode->clock / mode->clock; 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci dpll |= DPLL_DVO_HIGH_SPEED; 5388c2ecf20Sopenharmony_ci dpll |= 5398c2ecf20Sopenharmony_ci (sdvo_pixel_multiply - 5408c2ecf20Sopenharmony_ci 1) << SDVO_MULTIPLIER_SHIFT_HIRES; 5418c2ecf20Sopenharmony_ci } 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci /* compute bitmask from p1 value */ 5458c2ecf20Sopenharmony_ci if (is_sdvo) 5468c2ecf20Sopenharmony_ci dpll |= clock.p1 << 16; // dpll |= (1 << (clock.p1 - 1)) << 16; 5478c2ecf20Sopenharmony_ci else 5488c2ecf20Sopenharmony_ci dpll |= (1 << (clock.p1 - 2)) << 17; 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci dpll |= DPLL_VCO_ENABLE; 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci if (dpll & DPLL_VCO_ENABLE) { 5538c2ecf20Sopenharmony_ci for (i = 0; i <= need_aux; i++) { 5548c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->fp0, fp, i); 5558c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->dpll, dpll & ~DPLL_VCO_ENABLE, i); 5568c2ecf20Sopenharmony_ci REG_READ_WITH_AUX(map->dpll, i); 5578c2ecf20Sopenharmony_ci /* Check the DPLLA lock bit PIPEACONF[29] */ 5588c2ecf20Sopenharmony_ci udelay(150); 5598c2ecf20Sopenharmony_ci } 5608c2ecf20Sopenharmony_ci } 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci for (i = 0; i <= need_aux; i++) { 5638c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->fp0, fp, i); 5648c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->dpll, dpll, i); 5658c2ecf20Sopenharmony_ci REG_READ_WITH_AUX(map->dpll, i); 5668c2ecf20Sopenharmony_ci /* Wait for the clocks to stabilize. */ 5678c2ecf20Sopenharmony_ci udelay(150); 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci /* write it again -- the BIOS does, after all */ 5708c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->dpll, dpll, i); 5718c2ecf20Sopenharmony_ci REG_READ_WITH_AUX(map->dpll, i); 5728c2ecf20Sopenharmony_ci /* Wait for the clocks to stabilize. */ 5738c2ecf20Sopenharmony_ci udelay(150); 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->conf, pipeconf, i); 5768c2ecf20Sopenharmony_ci REG_READ_WITH_AUX(map->conf, i); 5778c2ecf20Sopenharmony_ci gma_wait_for_vblank(dev); 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ci REG_WRITE_WITH_AUX(map->cntr, dspcntr, i); 5808c2ecf20Sopenharmony_ci gma_wait_for_vblank(dev); 5818c2ecf20Sopenharmony_ci } 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_cioaktrail_crtc_mode_set_exit: 5848c2ecf20Sopenharmony_ci gma_power_end(dev); 5858c2ecf20Sopenharmony_ci return 0; 5868c2ecf20Sopenharmony_ci} 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_cistatic int oaktrail_pipe_set_base(struct drm_crtc *crtc, 5898c2ecf20Sopenharmony_ci int x, int y, struct drm_framebuffer *old_fb) 5908c2ecf20Sopenharmony_ci{ 5918c2ecf20Sopenharmony_ci struct drm_device *dev = crtc->dev; 5928c2ecf20Sopenharmony_ci struct drm_psb_private *dev_priv = dev->dev_private; 5938c2ecf20Sopenharmony_ci struct gma_crtc *gma_crtc = to_gma_crtc(crtc); 5948c2ecf20Sopenharmony_ci struct drm_framebuffer *fb = crtc->primary->fb; 5958c2ecf20Sopenharmony_ci int pipe = gma_crtc->pipe; 5968c2ecf20Sopenharmony_ci const struct psb_offset *map = &dev_priv->regmap[pipe]; 5978c2ecf20Sopenharmony_ci unsigned long start, offset; 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci u32 dspcntr; 6008c2ecf20Sopenharmony_ci int ret = 0; 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci /* no fb bound */ 6038c2ecf20Sopenharmony_ci if (!fb) { 6048c2ecf20Sopenharmony_ci dev_dbg(dev->dev, "No FB bound\n"); 6058c2ecf20Sopenharmony_ci return 0; 6068c2ecf20Sopenharmony_ci } 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci if (!gma_power_begin(dev, true)) 6098c2ecf20Sopenharmony_ci return 0; 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci start = to_gtt_range(fb->obj[0])->offset; 6128c2ecf20Sopenharmony_ci offset = y * fb->pitches[0] + x * fb->format->cpp[0]; 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_ci REG_WRITE(map->stride, fb->pitches[0]); 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci dspcntr = REG_READ(map->cntr); 6178c2ecf20Sopenharmony_ci dspcntr &= ~DISPPLANE_PIXFORMAT_MASK; 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci switch (fb->format->cpp[0] * 8) { 6208c2ecf20Sopenharmony_ci case 8: 6218c2ecf20Sopenharmony_ci dspcntr |= DISPPLANE_8BPP; 6228c2ecf20Sopenharmony_ci break; 6238c2ecf20Sopenharmony_ci case 16: 6248c2ecf20Sopenharmony_ci if (fb->format->depth == 15) 6258c2ecf20Sopenharmony_ci dspcntr |= DISPPLANE_15_16BPP; 6268c2ecf20Sopenharmony_ci else 6278c2ecf20Sopenharmony_ci dspcntr |= DISPPLANE_16BPP; 6288c2ecf20Sopenharmony_ci break; 6298c2ecf20Sopenharmony_ci case 24: 6308c2ecf20Sopenharmony_ci case 32: 6318c2ecf20Sopenharmony_ci dspcntr |= DISPPLANE_32BPP_NO_ALPHA; 6328c2ecf20Sopenharmony_ci break; 6338c2ecf20Sopenharmony_ci default: 6348c2ecf20Sopenharmony_ci dev_err(dev->dev, "Unknown color depth\n"); 6358c2ecf20Sopenharmony_ci ret = -EINVAL; 6368c2ecf20Sopenharmony_ci goto pipe_set_base_exit; 6378c2ecf20Sopenharmony_ci } 6388c2ecf20Sopenharmony_ci REG_WRITE(map->cntr, dspcntr); 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci REG_WRITE(map->base, offset); 6418c2ecf20Sopenharmony_ci REG_READ(map->base); 6428c2ecf20Sopenharmony_ci REG_WRITE(map->surf, start); 6438c2ecf20Sopenharmony_ci REG_READ(map->surf); 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_cipipe_set_base_exit: 6468c2ecf20Sopenharmony_ci gma_power_end(dev); 6478c2ecf20Sopenharmony_ci return ret; 6488c2ecf20Sopenharmony_ci} 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ciconst struct drm_crtc_helper_funcs oaktrail_helper_funcs = { 6518c2ecf20Sopenharmony_ci .dpms = oaktrail_crtc_dpms, 6528c2ecf20Sopenharmony_ci .mode_set = oaktrail_crtc_mode_set, 6538c2ecf20Sopenharmony_ci .mode_set_base = oaktrail_pipe_set_base, 6548c2ecf20Sopenharmony_ci .prepare = gma_crtc_prepare, 6558c2ecf20Sopenharmony_ci .commit = gma_crtc_commit, 6568c2ecf20Sopenharmony_ci}; 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci/* Not used yet */ 6598c2ecf20Sopenharmony_ciconst struct gma_clock_funcs mrst_clock_funcs = { 6608c2ecf20Sopenharmony_ci .clock = mrst_lvds_clock, 6618c2ecf20Sopenharmony_ci .limit = mrst_limit, 6628c2ecf20Sopenharmony_ci .pll_is_valid = gma_pll_is_valid, 6638c2ecf20Sopenharmony_ci}; 664