1926deccbSFrançois Tigeot /* 2926deccbSFrançois Tigeot * Copyright 2007-8 Advanced Micro Devices, Inc. 3926deccbSFrançois Tigeot * Copyright 2008 Red Hat Inc. 4926deccbSFrançois Tigeot * 5926deccbSFrançois Tigeot * Permission is hereby granted, free of charge, to any person obtaining a 6926deccbSFrançois Tigeot * copy of this software and associated documentation files (the "Software"), 7926deccbSFrançois Tigeot * to deal in the Software without restriction, including without limitation 8926deccbSFrançois Tigeot * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9926deccbSFrançois Tigeot * and/or sell copies of the Software, and to permit persons to whom the 10926deccbSFrançois Tigeot * Software is furnished to do so, subject to the following conditions: 11926deccbSFrançois Tigeot * 12926deccbSFrançois Tigeot * The above copyright notice and this permission notice shall be included in 13926deccbSFrançois Tigeot * all copies or substantial portions of the Software. 14926deccbSFrançois Tigeot * 15926deccbSFrançois Tigeot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16926deccbSFrançois Tigeot * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17926deccbSFrançois Tigeot * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18926deccbSFrançois Tigeot * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19926deccbSFrançois Tigeot * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20926deccbSFrançois Tigeot * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21926deccbSFrançois Tigeot * OTHER DEALINGS IN THE SOFTWARE. 22926deccbSFrançois Tigeot * 23926deccbSFrançois Tigeot * Authors: Dave Airlie 24926deccbSFrançois Tigeot * Alex Deucher 25926deccbSFrançois Tigeot */ 26926deccbSFrançois Tigeot #include <drm/drmP.h> 27926deccbSFrançois Tigeot #include <drm/drm_crtc_helper.h> 28c0e85e96SFrançois Tigeot #include <drm/drm_fb_helper.h> 2983b4b9b9SFrançois Tigeot #include <drm/radeon_drm.h> 30926deccbSFrançois Tigeot #include <drm/drm_fixed.h> 31926deccbSFrançois Tigeot #include "radeon.h" 32926deccbSFrançois Tigeot #include "atom.h" 33926deccbSFrançois Tigeot #include "atom-bits.h" 34926deccbSFrançois Tigeot 35926deccbSFrançois Tigeot static void atombios_overscan_setup(struct drm_crtc *crtc, 36926deccbSFrançois Tigeot struct drm_display_mode *mode, 37926deccbSFrançois Tigeot struct drm_display_mode *adjusted_mode) 38926deccbSFrançois Tigeot { 39926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 40926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 41926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 42926deccbSFrançois Tigeot SET_CRTC_OVERSCAN_PS_ALLOCATION args; 43926deccbSFrançois Tigeot int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_OverScan); 44926deccbSFrançois Tigeot int a1, a2; 45926deccbSFrançois Tigeot 46926deccbSFrançois Tigeot memset(&args, 0, sizeof(args)); 47926deccbSFrançois Tigeot 48926deccbSFrançois Tigeot args.ucCRTC = radeon_crtc->crtc_id; 49926deccbSFrançois Tigeot 50926deccbSFrançois Tigeot switch (radeon_crtc->rmx_type) { 51926deccbSFrançois Tigeot case RMX_CENTER: 52926deccbSFrançois Tigeot args.usOverscanTop = cpu_to_le16((adjusted_mode->crtc_vdisplay - mode->crtc_vdisplay) / 2); 53926deccbSFrançois Tigeot args.usOverscanBottom = cpu_to_le16((adjusted_mode->crtc_vdisplay - mode->crtc_vdisplay) / 2); 54926deccbSFrançois Tigeot args.usOverscanLeft = cpu_to_le16((adjusted_mode->crtc_hdisplay - mode->crtc_hdisplay) / 2); 55926deccbSFrançois Tigeot args.usOverscanRight = cpu_to_le16((adjusted_mode->crtc_hdisplay - mode->crtc_hdisplay) / 2); 56926deccbSFrançois Tigeot break; 57926deccbSFrançois Tigeot case RMX_ASPECT: 58926deccbSFrançois Tigeot a1 = mode->crtc_vdisplay * adjusted_mode->crtc_hdisplay; 59926deccbSFrançois Tigeot a2 = adjusted_mode->crtc_vdisplay * mode->crtc_hdisplay; 60926deccbSFrançois Tigeot 61926deccbSFrançois Tigeot if (a1 > a2) { 62926deccbSFrançois Tigeot args.usOverscanLeft = cpu_to_le16((adjusted_mode->crtc_hdisplay - (a2 / mode->crtc_vdisplay)) / 2); 63926deccbSFrançois Tigeot args.usOverscanRight = cpu_to_le16((adjusted_mode->crtc_hdisplay - (a2 / mode->crtc_vdisplay)) / 2); 64926deccbSFrançois Tigeot } else if (a2 > a1) { 65926deccbSFrançois Tigeot args.usOverscanTop = cpu_to_le16((adjusted_mode->crtc_vdisplay - (a1 / mode->crtc_hdisplay)) / 2); 66926deccbSFrançois Tigeot args.usOverscanBottom = cpu_to_le16((adjusted_mode->crtc_vdisplay - (a1 / mode->crtc_hdisplay)) / 2); 67926deccbSFrançois Tigeot } 68926deccbSFrançois Tigeot break; 69926deccbSFrançois Tigeot case RMX_FULL: 70926deccbSFrançois Tigeot default: 71926deccbSFrançois Tigeot args.usOverscanRight = cpu_to_le16(radeon_crtc->h_border); 72926deccbSFrançois Tigeot args.usOverscanLeft = cpu_to_le16(radeon_crtc->h_border); 73926deccbSFrançois Tigeot args.usOverscanBottom = cpu_to_le16(radeon_crtc->v_border); 74926deccbSFrançois Tigeot args.usOverscanTop = cpu_to_le16(radeon_crtc->v_border); 75926deccbSFrançois Tigeot break; 76926deccbSFrançois Tigeot } 77926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 78926deccbSFrançois Tigeot } 79926deccbSFrançois Tigeot 80926deccbSFrançois Tigeot static void atombios_scaler_setup(struct drm_crtc *crtc) 81926deccbSFrançois Tigeot { 82926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 83926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 84926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 85926deccbSFrançois Tigeot ENABLE_SCALER_PS_ALLOCATION args; 86926deccbSFrançois Tigeot int index = GetIndexIntoMasterTable(COMMAND, EnableScaler); 87926deccbSFrançois Tigeot struct radeon_encoder *radeon_encoder = 88926deccbSFrançois Tigeot to_radeon_encoder(radeon_crtc->encoder); 89926deccbSFrançois Tigeot /* fixme - fill in enc_priv for atom dac */ 90926deccbSFrançois Tigeot enum radeon_tv_std tv_std = TV_STD_NTSC; 91926deccbSFrançois Tigeot bool is_tv = false, is_cv = false; 92926deccbSFrançois Tigeot 93926deccbSFrançois Tigeot if (!ASIC_IS_AVIVO(rdev) && radeon_crtc->crtc_id) 94926deccbSFrançois Tigeot return; 95926deccbSFrançois Tigeot 96926deccbSFrançois Tigeot if (radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT) { 97926deccbSFrançois Tigeot struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv; 98926deccbSFrançois Tigeot tv_std = tv_dac->tv_std; 99926deccbSFrançois Tigeot is_tv = true; 100926deccbSFrançois Tigeot } 101926deccbSFrançois Tigeot 102926deccbSFrançois Tigeot memset(&args, 0, sizeof(args)); 103926deccbSFrançois Tigeot 104926deccbSFrançois Tigeot args.ucScaler = radeon_crtc->crtc_id; 105926deccbSFrançois Tigeot 106926deccbSFrançois Tigeot if (is_tv) { 107926deccbSFrançois Tigeot switch (tv_std) { 108926deccbSFrançois Tigeot case TV_STD_NTSC: 109926deccbSFrançois Tigeot default: 110926deccbSFrançois Tigeot args.ucTVStandard = ATOM_TV_NTSC; 111926deccbSFrançois Tigeot break; 112926deccbSFrançois Tigeot case TV_STD_PAL: 113926deccbSFrançois Tigeot args.ucTVStandard = ATOM_TV_PAL; 114926deccbSFrançois Tigeot break; 115926deccbSFrançois Tigeot case TV_STD_PAL_M: 116926deccbSFrançois Tigeot args.ucTVStandard = ATOM_TV_PALM; 117926deccbSFrançois Tigeot break; 118926deccbSFrançois Tigeot case TV_STD_PAL_60: 119926deccbSFrançois Tigeot args.ucTVStandard = ATOM_TV_PAL60; 120926deccbSFrançois Tigeot break; 121926deccbSFrançois Tigeot case TV_STD_NTSC_J: 122926deccbSFrançois Tigeot args.ucTVStandard = ATOM_TV_NTSCJ; 123926deccbSFrançois Tigeot break; 124926deccbSFrançois Tigeot case TV_STD_SCART_PAL: 125926deccbSFrançois Tigeot args.ucTVStandard = ATOM_TV_PAL; /* ??? */ 126926deccbSFrançois Tigeot break; 127926deccbSFrançois Tigeot case TV_STD_SECAM: 128926deccbSFrançois Tigeot args.ucTVStandard = ATOM_TV_SECAM; 129926deccbSFrançois Tigeot break; 130926deccbSFrançois Tigeot case TV_STD_PAL_CN: 131926deccbSFrançois Tigeot args.ucTVStandard = ATOM_TV_PALCN; 132926deccbSFrançois Tigeot break; 133926deccbSFrançois Tigeot } 134926deccbSFrançois Tigeot args.ucEnable = SCALER_ENABLE_MULTITAP_MODE; 135926deccbSFrançois Tigeot } else if (is_cv) { 136926deccbSFrançois Tigeot args.ucTVStandard = ATOM_TV_CV; 137926deccbSFrançois Tigeot args.ucEnable = SCALER_ENABLE_MULTITAP_MODE; 138926deccbSFrançois Tigeot } else { 139926deccbSFrançois Tigeot switch (radeon_crtc->rmx_type) { 140926deccbSFrançois Tigeot case RMX_FULL: 141926deccbSFrançois Tigeot args.ucEnable = ATOM_SCALER_EXPANSION; 142926deccbSFrançois Tigeot break; 143926deccbSFrançois Tigeot case RMX_CENTER: 144926deccbSFrançois Tigeot args.ucEnable = ATOM_SCALER_CENTER; 145926deccbSFrançois Tigeot break; 146926deccbSFrançois Tigeot case RMX_ASPECT: 147926deccbSFrançois Tigeot args.ucEnable = ATOM_SCALER_EXPANSION; 148926deccbSFrançois Tigeot break; 149926deccbSFrançois Tigeot default: 150926deccbSFrançois Tigeot if (ASIC_IS_AVIVO(rdev)) 151926deccbSFrançois Tigeot args.ucEnable = ATOM_SCALER_DISABLE; 152926deccbSFrançois Tigeot else 153926deccbSFrançois Tigeot args.ucEnable = ATOM_SCALER_CENTER; 154926deccbSFrançois Tigeot break; 155926deccbSFrançois Tigeot } 156926deccbSFrançois Tigeot } 157926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 158926deccbSFrançois Tigeot if ((is_tv || is_cv) 159926deccbSFrançois Tigeot && rdev->family >= CHIP_RV515 && rdev->family <= CHIP_R580) { 160926deccbSFrançois Tigeot atom_rv515_force_tv_scaler(rdev, radeon_crtc); 161926deccbSFrançois Tigeot } 162926deccbSFrançois Tigeot } 163926deccbSFrançois Tigeot 164926deccbSFrançois Tigeot static void atombios_lock_crtc(struct drm_crtc *crtc, int lock) 165926deccbSFrançois Tigeot { 166926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 167926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 168926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 169926deccbSFrançois Tigeot int index = 170926deccbSFrançois Tigeot GetIndexIntoMasterTable(COMMAND, UpdateCRTC_DoubleBufferRegisters); 171926deccbSFrançois Tigeot ENABLE_CRTC_PS_ALLOCATION args; 172926deccbSFrançois Tigeot 173926deccbSFrançois Tigeot memset(&args, 0, sizeof(args)); 174926deccbSFrançois Tigeot 175926deccbSFrançois Tigeot args.ucCRTC = radeon_crtc->crtc_id; 176926deccbSFrançois Tigeot args.ucEnable = lock; 177926deccbSFrançois Tigeot 178926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 179926deccbSFrançois Tigeot } 180926deccbSFrançois Tigeot 181926deccbSFrançois Tigeot static void atombios_enable_crtc(struct drm_crtc *crtc, int state) 182926deccbSFrançois Tigeot { 183926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 184926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 185926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 186926deccbSFrançois Tigeot int index = GetIndexIntoMasterTable(COMMAND, EnableCRTC); 187926deccbSFrançois Tigeot ENABLE_CRTC_PS_ALLOCATION args; 188926deccbSFrançois Tigeot 189926deccbSFrançois Tigeot memset(&args, 0, sizeof(args)); 190926deccbSFrançois Tigeot 191926deccbSFrançois Tigeot args.ucCRTC = radeon_crtc->crtc_id; 192926deccbSFrançois Tigeot args.ucEnable = state; 193926deccbSFrançois Tigeot 194926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 195926deccbSFrançois Tigeot } 196926deccbSFrançois Tigeot 197926deccbSFrançois Tigeot static void atombios_enable_crtc_memreq(struct drm_crtc *crtc, int state) 198926deccbSFrançois Tigeot { 199926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 200926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 201926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 202926deccbSFrançois Tigeot int index = GetIndexIntoMasterTable(COMMAND, EnableCRTCMemReq); 203926deccbSFrançois Tigeot ENABLE_CRTC_PS_ALLOCATION args; 204926deccbSFrançois Tigeot 205926deccbSFrançois Tigeot memset(&args, 0, sizeof(args)); 206926deccbSFrançois Tigeot 207926deccbSFrançois Tigeot args.ucCRTC = radeon_crtc->crtc_id; 208926deccbSFrançois Tigeot args.ucEnable = state; 209926deccbSFrançois Tigeot 210926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 211926deccbSFrançois Tigeot } 212926deccbSFrançois Tigeot 213c6f73aabSFrançois Tigeot static const u32 vga_control_regs[6] = 214c6f73aabSFrançois Tigeot { 215c6f73aabSFrançois Tigeot AVIVO_D1VGA_CONTROL, 216c6f73aabSFrançois Tigeot AVIVO_D2VGA_CONTROL, 217c6f73aabSFrançois Tigeot EVERGREEN_D3VGA_CONTROL, 218c6f73aabSFrançois Tigeot EVERGREEN_D4VGA_CONTROL, 219c6f73aabSFrançois Tigeot EVERGREEN_D5VGA_CONTROL, 220c6f73aabSFrançois Tigeot EVERGREEN_D6VGA_CONTROL, 221c6f73aabSFrançois Tigeot }; 222c6f73aabSFrançois Tigeot 223926deccbSFrançois Tigeot static void atombios_blank_crtc(struct drm_crtc *crtc, int state) 224926deccbSFrançois Tigeot { 225926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 226926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 227926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 228926deccbSFrançois Tigeot int index = GetIndexIntoMasterTable(COMMAND, BlankCRTC); 229926deccbSFrançois Tigeot BLANK_CRTC_PS_ALLOCATION args; 230c6f73aabSFrançois Tigeot u32 vga_control = 0; 231926deccbSFrançois Tigeot 232926deccbSFrançois Tigeot memset(&args, 0, sizeof(args)); 233926deccbSFrançois Tigeot 234c6f73aabSFrançois Tigeot if (ASIC_IS_DCE8(rdev)) { 235c6f73aabSFrançois Tigeot vga_control = RREG32(vga_control_regs[radeon_crtc->crtc_id]); 236c6f73aabSFrançois Tigeot WREG32(vga_control_regs[radeon_crtc->crtc_id], vga_control | 1); 237c6f73aabSFrançois Tigeot } 238c6f73aabSFrançois Tigeot 239926deccbSFrançois Tigeot args.ucCRTC = radeon_crtc->crtc_id; 240926deccbSFrançois Tigeot args.ucBlanking = state; 241926deccbSFrançois Tigeot 242926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 243c6f73aabSFrançois Tigeot 244c6f73aabSFrançois Tigeot if (ASIC_IS_DCE8(rdev)) { 245c6f73aabSFrançois Tigeot WREG32(vga_control_regs[radeon_crtc->crtc_id], vga_control); 246c6f73aabSFrançois Tigeot } 247926deccbSFrançois Tigeot } 248926deccbSFrançois Tigeot 249926deccbSFrançois Tigeot static void atombios_powergate_crtc(struct drm_crtc *crtc, int state) 250926deccbSFrançois Tigeot { 251926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 252926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 253926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 254926deccbSFrançois Tigeot int index = GetIndexIntoMasterTable(COMMAND, EnableDispPowerGating); 255926deccbSFrançois Tigeot ENABLE_DISP_POWER_GATING_PARAMETERS_V2_1 args; 256926deccbSFrançois Tigeot 257926deccbSFrançois Tigeot memset(&args, 0, sizeof(args)); 258926deccbSFrançois Tigeot 259926deccbSFrançois Tigeot args.ucDispPipeId = radeon_crtc->crtc_id; 260926deccbSFrançois Tigeot args.ucEnable = state; 261926deccbSFrançois Tigeot 262926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 263926deccbSFrançois Tigeot } 264926deccbSFrançois Tigeot 265926deccbSFrançois Tigeot void atombios_crtc_dpms(struct drm_crtc *crtc, int mode) 266926deccbSFrançois Tigeot { 267926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 268926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 269926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 270926deccbSFrançois Tigeot 271926deccbSFrançois Tigeot switch (mode) { 272926deccbSFrançois Tigeot case DRM_MODE_DPMS_ON: 273926deccbSFrançois Tigeot radeon_crtc->enabled = true; 274926deccbSFrançois Tigeot atombios_enable_crtc(crtc, ATOM_ENABLE); 275926deccbSFrançois Tigeot if (ASIC_IS_DCE3(rdev) && !ASIC_IS_DCE6(rdev)) 276926deccbSFrançois Tigeot atombios_enable_crtc_memreq(crtc, ATOM_ENABLE); 277926deccbSFrançois Tigeot atombios_blank_crtc(crtc, ATOM_DISABLE); 278d78d3a22SFrançois Tigeot if (dev->num_crtcs > radeon_crtc->crtc_id) 2791dedbd3bSFrançois Tigeot drm_crtc_vblank_on(crtc); 280926deccbSFrançois Tigeot radeon_crtc_load_lut(crtc); 281926deccbSFrançois Tigeot break; 282926deccbSFrançois Tigeot case DRM_MODE_DPMS_STANDBY: 283926deccbSFrançois Tigeot case DRM_MODE_DPMS_SUSPEND: 284926deccbSFrançois Tigeot case DRM_MODE_DPMS_OFF: 285d78d3a22SFrançois Tigeot if (dev->num_crtcs > radeon_crtc->crtc_id) 2861dedbd3bSFrançois Tigeot drm_crtc_vblank_off(crtc); 287926deccbSFrançois Tigeot if (radeon_crtc->enabled) 288926deccbSFrançois Tigeot atombios_blank_crtc(crtc, ATOM_ENABLE); 289926deccbSFrançois Tigeot if (ASIC_IS_DCE3(rdev) && !ASIC_IS_DCE6(rdev)) 290926deccbSFrançois Tigeot atombios_enable_crtc_memreq(crtc, ATOM_DISABLE); 291926deccbSFrançois Tigeot atombios_enable_crtc(crtc, ATOM_DISABLE); 292926deccbSFrançois Tigeot radeon_crtc->enabled = false; 293926deccbSFrançois Tigeot break; 294926deccbSFrançois Tigeot } 295c6f73aabSFrançois Tigeot /* adjust pm to dpms */ 296c6f73aabSFrançois Tigeot radeon_pm_compute_clocks(rdev); 297926deccbSFrançois Tigeot } 298926deccbSFrançois Tigeot 299926deccbSFrançois Tigeot static void 300926deccbSFrançois Tigeot atombios_set_crtc_dtd_timing(struct drm_crtc *crtc, 301926deccbSFrançois Tigeot struct drm_display_mode *mode) 302926deccbSFrançois Tigeot { 303926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 304926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 305926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 306926deccbSFrançois Tigeot SET_CRTC_USING_DTD_TIMING_PARAMETERS args; 307926deccbSFrançois Tigeot int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_UsingDTDTiming); 308926deccbSFrançois Tigeot u16 misc = 0; 309926deccbSFrançois Tigeot 310926deccbSFrançois Tigeot memset(&args, 0, sizeof(args)); 311926deccbSFrançois Tigeot args.usH_Size = cpu_to_le16(mode->crtc_hdisplay - (radeon_crtc->h_border * 2)); 312926deccbSFrançois Tigeot args.usH_Blanking_Time = 313926deccbSFrançois Tigeot cpu_to_le16(mode->crtc_hblank_end - mode->crtc_hdisplay + (radeon_crtc->h_border * 2)); 314926deccbSFrançois Tigeot args.usV_Size = cpu_to_le16(mode->crtc_vdisplay - (radeon_crtc->v_border * 2)); 315926deccbSFrançois Tigeot args.usV_Blanking_Time = 316926deccbSFrançois Tigeot cpu_to_le16(mode->crtc_vblank_end - mode->crtc_vdisplay + (radeon_crtc->v_border * 2)); 317926deccbSFrançois Tigeot args.usH_SyncOffset = 318926deccbSFrançois Tigeot cpu_to_le16(mode->crtc_hsync_start - mode->crtc_hdisplay + radeon_crtc->h_border); 319926deccbSFrançois Tigeot args.usH_SyncWidth = 320926deccbSFrançois Tigeot cpu_to_le16(mode->crtc_hsync_end - mode->crtc_hsync_start); 321926deccbSFrançois Tigeot args.usV_SyncOffset = 322926deccbSFrançois Tigeot cpu_to_le16(mode->crtc_vsync_start - mode->crtc_vdisplay + radeon_crtc->v_border); 323926deccbSFrançois Tigeot args.usV_SyncWidth = 324926deccbSFrançois Tigeot cpu_to_le16(mode->crtc_vsync_end - mode->crtc_vsync_start); 325926deccbSFrançois Tigeot args.ucH_Border = radeon_crtc->h_border; 326926deccbSFrançois Tigeot args.ucV_Border = radeon_crtc->v_border; 327926deccbSFrançois Tigeot 328926deccbSFrançois Tigeot if (mode->flags & DRM_MODE_FLAG_NVSYNC) 329926deccbSFrançois Tigeot misc |= ATOM_VSYNC_POLARITY; 330926deccbSFrançois Tigeot if (mode->flags & DRM_MODE_FLAG_NHSYNC) 331926deccbSFrançois Tigeot misc |= ATOM_HSYNC_POLARITY; 332926deccbSFrançois Tigeot if (mode->flags & DRM_MODE_FLAG_CSYNC) 333926deccbSFrançois Tigeot misc |= ATOM_COMPOSITESYNC; 334926deccbSFrançois Tigeot if (mode->flags & DRM_MODE_FLAG_INTERLACE) 335926deccbSFrançois Tigeot misc |= ATOM_INTERLACE; 3367dcf36dcSFrançois Tigeot if (mode->flags & DRM_MODE_FLAG_DBLCLK) 337ee479021SImre Vadász misc |= ATOM_DOUBLE_CLOCK_MODE; 3387dcf36dcSFrançois Tigeot if (mode->flags & DRM_MODE_FLAG_DBLSCAN) 3397dcf36dcSFrançois Tigeot misc |= ATOM_H_REPLICATIONBY2 | ATOM_V_REPLICATIONBY2; 340926deccbSFrançois Tigeot 341926deccbSFrançois Tigeot args.susModeMiscInfo.usAccess = cpu_to_le16(misc); 342926deccbSFrançois Tigeot args.ucCRTC = radeon_crtc->crtc_id; 343926deccbSFrançois Tigeot 344926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 345926deccbSFrançois Tigeot } 346926deccbSFrançois Tigeot 347926deccbSFrançois Tigeot static void atombios_crtc_set_timing(struct drm_crtc *crtc, 348926deccbSFrançois Tigeot struct drm_display_mode *mode) 349926deccbSFrançois Tigeot { 350926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 351926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 352926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 353926deccbSFrançois Tigeot SET_CRTC_TIMING_PARAMETERS_PS_ALLOCATION args; 354926deccbSFrançois Tigeot int index = GetIndexIntoMasterTable(COMMAND, SetCRTC_Timing); 355926deccbSFrançois Tigeot u16 misc = 0; 356926deccbSFrançois Tigeot 357926deccbSFrançois Tigeot memset(&args, 0, sizeof(args)); 358926deccbSFrançois Tigeot args.usH_Total = cpu_to_le16(mode->crtc_htotal); 359926deccbSFrançois Tigeot args.usH_Disp = cpu_to_le16(mode->crtc_hdisplay); 360926deccbSFrançois Tigeot args.usH_SyncStart = cpu_to_le16(mode->crtc_hsync_start); 361926deccbSFrançois Tigeot args.usH_SyncWidth = 362926deccbSFrançois Tigeot cpu_to_le16(mode->crtc_hsync_end - mode->crtc_hsync_start); 363926deccbSFrançois Tigeot args.usV_Total = cpu_to_le16(mode->crtc_vtotal); 364926deccbSFrançois Tigeot args.usV_Disp = cpu_to_le16(mode->crtc_vdisplay); 365926deccbSFrançois Tigeot args.usV_SyncStart = cpu_to_le16(mode->crtc_vsync_start); 366926deccbSFrançois Tigeot args.usV_SyncWidth = 367926deccbSFrançois Tigeot cpu_to_le16(mode->crtc_vsync_end - mode->crtc_vsync_start); 368926deccbSFrançois Tigeot 369926deccbSFrançois Tigeot args.ucOverscanRight = radeon_crtc->h_border; 370926deccbSFrançois Tigeot args.ucOverscanLeft = radeon_crtc->h_border; 371926deccbSFrançois Tigeot args.ucOverscanBottom = radeon_crtc->v_border; 372926deccbSFrançois Tigeot args.ucOverscanTop = radeon_crtc->v_border; 373926deccbSFrançois Tigeot 374926deccbSFrançois Tigeot if (mode->flags & DRM_MODE_FLAG_NVSYNC) 375926deccbSFrançois Tigeot misc |= ATOM_VSYNC_POLARITY; 376926deccbSFrançois Tigeot if (mode->flags & DRM_MODE_FLAG_NHSYNC) 377926deccbSFrançois Tigeot misc |= ATOM_HSYNC_POLARITY; 378926deccbSFrançois Tigeot if (mode->flags & DRM_MODE_FLAG_CSYNC) 379926deccbSFrançois Tigeot misc |= ATOM_COMPOSITESYNC; 380926deccbSFrançois Tigeot if (mode->flags & DRM_MODE_FLAG_INTERLACE) 381926deccbSFrançois Tigeot misc |= ATOM_INTERLACE; 3827dcf36dcSFrançois Tigeot if (mode->flags & DRM_MODE_FLAG_DBLCLK) 383ee479021SImre Vadász misc |= ATOM_DOUBLE_CLOCK_MODE; 3847dcf36dcSFrançois Tigeot if (mode->flags & DRM_MODE_FLAG_DBLSCAN) 3857dcf36dcSFrançois Tigeot misc |= ATOM_H_REPLICATIONBY2 | ATOM_V_REPLICATIONBY2; 386926deccbSFrançois Tigeot 387926deccbSFrançois Tigeot args.susModeMiscInfo.usAccess = cpu_to_le16(misc); 388926deccbSFrançois Tigeot args.ucCRTC = radeon_crtc->crtc_id; 389926deccbSFrançois Tigeot 390926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 391926deccbSFrançois Tigeot } 392926deccbSFrançois Tigeot 393926deccbSFrançois Tigeot static void atombios_disable_ss(struct radeon_device *rdev, int pll_id) 394926deccbSFrançois Tigeot { 395926deccbSFrançois Tigeot u32 ss_cntl; 396926deccbSFrançois Tigeot 397926deccbSFrançois Tigeot if (ASIC_IS_DCE4(rdev)) { 398926deccbSFrançois Tigeot switch (pll_id) { 399926deccbSFrançois Tigeot case ATOM_PPLL1: 400926deccbSFrançois Tigeot ss_cntl = RREG32(EVERGREEN_P1PLL_SS_CNTL); 401926deccbSFrançois Tigeot ss_cntl &= ~EVERGREEN_PxPLL_SS_EN; 402926deccbSFrançois Tigeot WREG32(EVERGREEN_P1PLL_SS_CNTL, ss_cntl); 403926deccbSFrançois Tigeot break; 404926deccbSFrançois Tigeot case ATOM_PPLL2: 405926deccbSFrançois Tigeot ss_cntl = RREG32(EVERGREEN_P2PLL_SS_CNTL); 406926deccbSFrançois Tigeot ss_cntl &= ~EVERGREEN_PxPLL_SS_EN; 407926deccbSFrançois Tigeot WREG32(EVERGREEN_P2PLL_SS_CNTL, ss_cntl); 408926deccbSFrançois Tigeot break; 409926deccbSFrançois Tigeot case ATOM_DCPLL: 410926deccbSFrançois Tigeot case ATOM_PPLL_INVALID: 411926deccbSFrançois Tigeot return; 412926deccbSFrançois Tigeot } 413926deccbSFrançois Tigeot } else if (ASIC_IS_AVIVO(rdev)) { 414926deccbSFrançois Tigeot switch (pll_id) { 415926deccbSFrançois Tigeot case ATOM_PPLL1: 416926deccbSFrançois Tigeot ss_cntl = RREG32(AVIVO_P1PLL_INT_SS_CNTL); 417926deccbSFrançois Tigeot ss_cntl &= ~1; 418926deccbSFrançois Tigeot WREG32(AVIVO_P1PLL_INT_SS_CNTL, ss_cntl); 419926deccbSFrançois Tigeot break; 420926deccbSFrançois Tigeot case ATOM_PPLL2: 421926deccbSFrançois Tigeot ss_cntl = RREG32(AVIVO_P2PLL_INT_SS_CNTL); 422926deccbSFrançois Tigeot ss_cntl &= ~1; 423926deccbSFrançois Tigeot WREG32(AVIVO_P2PLL_INT_SS_CNTL, ss_cntl); 424926deccbSFrançois Tigeot break; 425926deccbSFrançois Tigeot case ATOM_DCPLL: 426926deccbSFrançois Tigeot case ATOM_PPLL_INVALID: 427926deccbSFrançois Tigeot return; 428926deccbSFrançois Tigeot } 429926deccbSFrançois Tigeot } 430926deccbSFrançois Tigeot } 431926deccbSFrançois Tigeot 432926deccbSFrançois Tigeot 433926deccbSFrançois Tigeot union atom_enable_ss { 434926deccbSFrançois Tigeot ENABLE_LVDS_SS_PARAMETERS lvds_ss; 435926deccbSFrançois Tigeot ENABLE_LVDS_SS_PARAMETERS_V2 lvds_ss_2; 436926deccbSFrançois Tigeot ENABLE_SPREAD_SPECTRUM_ON_PPLL_PS_ALLOCATION v1; 437926deccbSFrançois Tigeot ENABLE_SPREAD_SPECTRUM_ON_PPLL_V2 v2; 438926deccbSFrançois Tigeot ENABLE_SPREAD_SPECTRUM_ON_PPLL_V3 v3; 439926deccbSFrançois Tigeot }; 440926deccbSFrançois Tigeot 441926deccbSFrançois Tigeot static void atombios_crtc_program_ss(struct radeon_device *rdev, 442926deccbSFrançois Tigeot int enable, 443926deccbSFrançois Tigeot int pll_id, 444926deccbSFrançois Tigeot int crtc_id, 445926deccbSFrançois Tigeot struct radeon_atom_ss *ss) 446926deccbSFrançois Tigeot { 447926deccbSFrançois Tigeot unsigned i; 448926deccbSFrançois Tigeot int index = GetIndexIntoMasterTable(COMMAND, EnableSpreadSpectrumOnPPLL); 449926deccbSFrançois Tigeot union atom_enable_ss args; 450926deccbSFrançois Tigeot 451c6f73aabSFrançois Tigeot if (enable) { 452c6f73aabSFrançois Tigeot /* Don't mess with SS if percentage is 0 or external ss. 453c6f73aabSFrançois Tigeot * SS is already disabled previously, and disabling it 454c6f73aabSFrançois Tigeot * again can cause display problems if the pll is already 455c6f73aabSFrançois Tigeot * programmed. 456c6f73aabSFrançois Tigeot */ 457c6f73aabSFrançois Tigeot if (ss->percentage == 0) 458c6f73aabSFrançois Tigeot return; 459c6f73aabSFrançois Tigeot if (ss->type & ATOM_EXTERNAL_SS_MASK) 460c6f73aabSFrançois Tigeot return; 461c6f73aabSFrançois Tigeot } else { 462926deccbSFrançois Tigeot for (i = 0; i < rdev->num_crtc; i++) { 463926deccbSFrançois Tigeot if (rdev->mode_info.crtcs[i] && 464926deccbSFrançois Tigeot rdev->mode_info.crtcs[i]->enabled && 465926deccbSFrançois Tigeot i != crtc_id && 466926deccbSFrançois Tigeot pll_id == rdev->mode_info.crtcs[i]->pll_id) { 467926deccbSFrançois Tigeot /* one other crtc is using this pll don't turn 468926deccbSFrançois Tigeot * off spread spectrum as it might turn off 469926deccbSFrançois Tigeot * display on active crtc 470926deccbSFrançois Tigeot */ 471926deccbSFrançois Tigeot return; 472926deccbSFrançois Tigeot } 473926deccbSFrançois Tigeot } 474926deccbSFrançois Tigeot } 475926deccbSFrançois Tigeot 476926deccbSFrançois Tigeot memset(&args, 0, sizeof(args)); 477926deccbSFrançois Tigeot 478926deccbSFrançois Tigeot if (ASIC_IS_DCE5(rdev)) { 479926deccbSFrançois Tigeot args.v3.usSpreadSpectrumAmountFrac = cpu_to_le16(0); 480926deccbSFrançois Tigeot args.v3.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; 481926deccbSFrançois Tigeot switch (pll_id) { 482926deccbSFrançois Tigeot case ATOM_PPLL1: 483926deccbSFrançois Tigeot args.v3.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V3_P1PLL; 484926deccbSFrançois Tigeot break; 485926deccbSFrançois Tigeot case ATOM_PPLL2: 486926deccbSFrançois Tigeot args.v3.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V3_P2PLL; 487926deccbSFrançois Tigeot break; 488926deccbSFrançois Tigeot case ATOM_DCPLL: 489926deccbSFrançois Tigeot args.v3.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V3_DCPLL; 490926deccbSFrançois Tigeot break; 491926deccbSFrançois Tigeot case ATOM_PPLL_INVALID: 492926deccbSFrançois Tigeot return; 493926deccbSFrançois Tigeot } 494926deccbSFrançois Tigeot args.v3.usSpreadSpectrumAmount = cpu_to_le16(ss->amount); 495926deccbSFrançois Tigeot args.v3.usSpreadSpectrumStep = cpu_to_le16(ss->step); 496926deccbSFrançois Tigeot args.v3.ucEnable = enable; 497926deccbSFrançois Tigeot } else if (ASIC_IS_DCE4(rdev)) { 498926deccbSFrançois Tigeot args.v2.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage); 499926deccbSFrançois Tigeot args.v2.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; 500926deccbSFrançois Tigeot switch (pll_id) { 501926deccbSFrançois Tigeot case ATOM_PPLL1: 502926deccbSFrançois Tigeot args.v2.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V2_P1PLL; 503926deccbSFrançois Tigeot break; 504926deccbSFrançois Tigeot case ATOM_PPLL2: 505926deccbSFrançois Tigeot args.v2.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V2_P2PLL; 506926deccbSFrançois Tigeot break; 507926deccbSFrançois Tigeot case ATOM_DCPLL: 508926deccbSFrançois Tigeot args.v2.ucSpreadSpectrumType |= ATOM_PPLL_SS_TYPE_V2_DCPLL; 509926deccbSFrançois Tigeot break; 510926deccbSFrançois Tigeot case ATOM_PPLL_INVALID: 511926deccbSFrançois Tigeot return; 512926deccbSFrançois Tigeot } 513926deccbSFrançois Tigeot args.v2.usSpreadSpectrumAmount = cpu_to_le16(ss->amount); 514926deccbSFrançois Tigeot args.v2.usSpreadSpectrumStep = cpu_to_le16(ss->step); 515926deccbSFrançois Tigeot args.v2.ucEnable = enable; 516926deccbSFrançois Tigeot } else if (ASIC_IS_DCE3(rdev)) { 517926deccbSFrançois Tigeot args.v1.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage); 518926deccbSFrançois Tigeot args.v1.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; 519926deccbSFrançois Tigeot args.v1.ucSpreadSpectrumStep = ss->step; 520926deccbSFrançois Tigeot args.v1.ucSpreadSpectrumDelay = ss->delay; 521926deccbSFrançois Tigeot args.v1.ucSpreadSpectrumRange = ss->range; 522926deccbSFrançois Tigeot args.v1.ucPpll = pll_id; 523926deccbSFrançois Tigeot args.v1.ucEnable = enable; 524926deccbSFrançois Tigeot } else if (ASIC_IS_AVIVO(rdev)) { 525926deccbSFrançois Tigeot if ((enable == ATOM_DISABLE) || (ss->percentage == 0) || 526926deccbSFrançois Tigeot (ss->type & ATOM_EXTERNAL_SS_MASK)) { 527926deccbSFrançois Tigeot atombios_disable_ss(rdev, pll_id); 528926deccbSFrançois Tigeot return; 529926deccbSFrançois Tigeot } 530926deccbSFrançois Tigeot args.lvds_ss_2.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage); 531926deccbSFrançois Tigeot args.lvds_ss_2.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; 532926deccbSFrançois Tigeot args.lvds_ss_2.ucSpreadSpectrumStep = ss->step; 533926deccbSFrançois Tigeot args.lvds_ss_2.ucSpreadSpectrumDelay = ss->delay; 534926deccbSFrançois Tigeot args.lvds_ss_2.ucSpreadSpectrumRange = ss->range; 535926deccbSFrançois Tigeot args.lvds_ss_2.ucEnable = enable; 536926deccbSFrançois Tigeot } else { 537c6f73aabSFrançois Tigeot if (enable == ATOM_DISABLE) { 538926deccbSFrançois Tigeot atombios_disable_ss(rdev, pll_id); 539926deccbSFrançois Tigeot return; 540926deccbSFrançois Tigeot } 541926deccbSFrançois Tigeot args.lvds_ss.usSpreadSpectrumPercentage = cpu_to_le16(ss->percentage); 542926deccbSFrançois Tigeot args.lvds_ss.ucSpreadSpectrumType = ss->type & ATOM_SS_CENTRE_SPREAD_MODE_MASK; 543926deccbSFrançois Tigeot args.lvds_ss.ucSpreadSpectrumStepSize_Delay = (ss->step & 3) << 2; 544926deccbSFrançois Tigeot args.lvds_ss.ucSpreadSpectrumStepSize_Delay |= (ss->delay & 7) << 4; 545926deccbSFrançois Tigeot args.lvds_ss.ucEnable = enable; 546926deccbSFrançois Tigeot } 547926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 548926deccbSFrançois Tigeot } 549926deccbSFrançois Tigeot 550926deccbSFrançois Tigeot union adjust_pixel_clock { 551926deccbSFrançois Tigeot ADJUST_DISPLAY_PLL_PS_ALLOCATION v1; 552926deccbSFrançois Tigeot ADJUST_DISPLAY_PLL_PS_ALLOCATION_V3 v3; 553926deccbSFrançois Tigeot }; 554926deccbSFrançois Tigeot 555926deccbSFrançois Tigeot static u32 atombios_adjust_pll(struct drm_crtc *crtc, 556926deccbSFrançois Tigeot struct drm_display_mode *mode) 557926deccbSFrançois Tigeot { 558926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 559926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 560926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 561926deccbSFrançois Tigeot struct drm_encoder *encoder = radeon_crtc->encoder; 562926deccbSFrançois Tigeot struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 563926deccbSFrançois Tigeot struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); 564926deccbSFrançois Tigeot u32 adjusted_clock = mode->clock; 565926deccbSFrançois Tigeot int encoder_mode = atombios_get_encoder_mode(encoder); 566926deccbSFrançois Tigeot u32 dp_clock = mode->clock; 567c6f73aabSFrançois Tigeot u32 clock = mode->clock; 568c6f73aabSFrançois Tigeot int bpc = radeon_crtc->bpc; 569926deccbSFrançois Tigeot bool is_duallink = radeon_dig_monitor_is_duallink(encoder, mode->clock); 570926deccbSFrançois Tigeot 571926deccbSFrançois Tigeot /* reset the pll flags */ 572926deccbSFrançois Tigeot radeon_crtc->pll_flags = 0; 573926deccbSFrançois Tigeot 574926deccbSFrançois Tigeot if (ASIC_IS_AVIVO(rdev)) { 575926deccbSFrançois Tigeot if ((rdev->family == CHIP_RS600) || 576926deccbSFrançois Tigeot (rdev->family == CHIP_RS690) || 577926deccbSFrançois Tigeot (rdev->family == CHIP_RS740)) 578926deccbSFrançois Tigeot radeon_crtc->pll_flags |= (/*RADEON_PLL_USE_FRAC_FB_DIV |*/ 579926deccbSFrançois Tigeot RADEON_PLL_PREFER_CLOSEST_LOWER); 580926deccbSFrançois Tigeot 581926deccbSFrançois Tigeot if (ASIC_IS_DCE32(rdev) && mode->clock > 200000) /* range limits??? */ 582926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_PREFER_HIGH_FB_DIV; 583926deccbSFrançois Tigeot else 584926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_PREFER_LOW_REF_DIV; 585926deccbSFrançois Tigeot 586926deccbSFrançois Tigeot if (rdev->family < CHIP_RV770) 587926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_PREFER_MINM_OVER_MAXP; 588926deccbSFrançois Tigeot /* use frac fb div on APUs */ 58957e252bfSMichael Neumann if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev) || ASIC_IS_DCE8(rdev)) 590926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV; 591f43cf1b1SMichael Neumann /* use frac fb div on RS780/RS880 */ 592d78d3a22SFrançois Tigeot if (((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880)) 593d78d3a22SFrançois Tigeot && !radeon_crtc->ss_enabled) 594f43cf1b1SMichael Neumann radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV; 595926deccbSFrançois Tigeot if (ASIC_IS_DCE32(rdev) && mode->clock > 165000) 596926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV; 597926deccbSFrançois Tigeot } else { 598926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_LEGACY; 599926deccbSFrançois Tigeot 600926deccbSFrançois Tigeot if (mode->clock > 200000) /* range limits??? */ 601926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_PREFER_HIGH_FB_DIV; 602926deccbSFrançois Tigeot else 603926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_PREFER_LOW_REF_DIV; 604926deccbSFrançois Tigeot } 605926deccbSFrançois Tigeot 606926deccbSFrançois Tigeot if ((radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT | ATOM_DEVICE_DFP_SUPPORT)) || 607926deccbSFrançois Tigeot (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE)) { 608926deccbSFrançois Tigeot if (connector) { 609926deccbSFrançois Tigeot struct radeon_connector *radeon_connector = to_radeon_connector(connector); 610926deccbSFrançois Tigeot struct radeon_connector_atom_dig *dig_connector = 611926deccbSFrançois Tigeot radeon_connector->con_priv; 612926deccbSFrançois Tigeot 613926deccbSFrançois Tigeot dp_clock = dig_connector->dp_clock; 614926deccbSFrançois Tigeot } 615926deccbSFrançois Tigeot } 616926deccbSFrançois Tigeot 617c59a5c48SFrançois Tigeot if (radeon_encoder->is_mst_encoder) { 618c59a5c48SFrançois Tigeot struct radeon_encoder_mst *mst_enc = radeon_encoder->enc_priv; 619c59a5c48SFrançois Tigeot struct radeon_connector_atom_dig *dig_connector = mst_enc->connector->con_priv; 620c59a5c48SFrançois Tigeot 621c59a5c48SFrançois Tigeot dp_clock = dig_connector->dp_clock; 622c59a5c48SFrançois Tigeot } 623c59a5c48SFrançois Tigeot 624926deccbSFrançois Tigeot /* use recommended ref_div for ss */ 625926deccbSFrançois Tigeot if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { 626926deccbSFrançois Tigeot if (radeon_crtc->ss_enabled) { 627926deccbSFrançois Tigeot if (radeon_crtc->ss.refdiv) { 628926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_USE_REF_DIV; 629926deccbSFrançois Tigeot radeon_crtc->pll_reference_div = radeon_crtc->ss.refdiv; 630d78d3a22SFrançois Tigeot if (ASIC_IS_AVIVO(rdev) && 631d78d3a22SFrançois Tigeot rdev->family != CHIP_RS780 && 632d78d3a22SFrançois Tigeot rdev->family != CHIP_RS880) 633926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV; 634926deccbSFrançois Tigeot } 635926deccbSFrançois Tigeot } 636926deccbSFrançois Tigeot } 637926deccbSFrançois Tigeot 638926deccbSFrançois Tigeot if (ASIC_IS_AVIVO(rdev)) { 639926deccbSFrançois Tigeot /* DVO wants 2x pixel clock if the DVO chip is in 12 bit mode */ 640926deccbSFrançois Tigeot if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1) 641926deccbSFrançois Tigeot adjusted_clock = mode->clock * 2; 642926deccbSFrançois Tigeot if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 643926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_PREFER_CLOSEST_LOWER; 644926deccbSFrançois Tigeot if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) 645926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_IS_LCD; 646926deccbSFrançois Tigeot } else { 647926deccbSFrançois Tigeot if (encoder->encoder_type != DRM_MODE_ENCODER_DAC) 648926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_NO_ODD_POST_DIV; 649926deccbSFrançois Tigeot if (encoder->encoder_type == DRM_MODE_ENCODER_LVDS) 650926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_USE_REF_DIV; 651926deccbSFrançois Tigeot } 652926deccbSFrançois Tigeot 653c6f73aabSFrançois Tigeot /* adjust pll for deep color modes */ 654c6f73aabSFrançois Tigeot if (encoder_mode == ATOM_ENCODER_MODE_HDMI) { 655c6f73aabSFrançois Tigeot switch (bpc) { 656c6f73aabSFrançois Tigeot case 8: 657c6f73aabSFrançois Tigeot default: 658c6f73aabSFrançois Tigeot break; 659c6f73aabSFrançois Tigeot case 10: 660c6f73aabSFrançois Tigeot clock = (clock * 5) / 4; 661c6f73aabSFrançois Tigeot break; 662c6f73aabSFrançois Tigeot case 12: 663c6f73aabSFrançois Tigeot clock = (clock * 3) / 2; 664c6f73aabSFrançois Tigeot break; 665c6f73aabSFrançois Tigeot case 16: 666c6f73aabSFrançois Tigeot clock = clock * 2; 667c6f73aabSFrançois Tigeot break; 668c6f73aabSFrançois Tigeot } 669c6f73aabSFrançois Tigeot } 670c6f73aabSFrançois Tigeot 671926deccbSFrançois Tigeot /* DCE3+ has an AdjustDisplayPll that will adjust the pixel clock 672926deccbSFrançois Tigeot * accordingly based on the encoder/transmitter to work around 673926deccbSFrançois Tigeot * special hw requirements. 674926deccbSFrançois Tigeot */ 675926deccbSFrançois Tigeot if (ASIC_IS_DCE3(rdev)) { 676926deccbSFrançois Tigeot union adjust_pixel_clock args; 677926deccbSFrançois Tigeot u8 frev, crev; 678926deccbSFrançois Tigeot int index; 679926deccbSFrançois Tigeot 680926deccbSFrançois Tigeot index = GetIndexIntoMasterTable(COMMAND, AdjustDisplayPll); 681926deccbSFrançois Tigeot if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, 682926deccbSFrançois Tigeot &crev)) 683926deccbSFrançois Tigeot return adjusted_clock; 684926deccbSFrançois Tigeot 685926deccbSFrançois Tigeot memset(&args, 0, sizeof(args)); 686926deccbSFrançois Tigeot 687926deccbSFrançois Tigeot switch (frev) { 688926deccbSFrançois Tigeot case 1: 689926deccbSFrançois Tigeot switch (crev) { 690926deccbSFrançois Tigeot case 1: 691926deccbSFrançois Tigeot case 2: 692c6f73aabSFrançois Tigeot args.v1.usPixelClock = cpu_to_le16(clock / 10); 693926deccbSFrançois Tigeot args.v1.ucTransmitterID = radeon_encoder->encoder_id; 694926deccbSFrançois Tigeot args.v1.ucEncodeMode = encoder_mode; 695926deccbSFrançois Tigeot if (radeon_crtc->ss_enabled && radeon_crtc->ss.percentage) 696926deccbSFrançois Tigeot args.v1.ucConfig |= 697926deccbSFrançois Tigeot ADJUST_DISPLAY_CONFIG_SS_ENABLE; 698926deccbSFrançois Tigeot 699926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, 700926deccbSFrançois Tigeot index, (uint32_t *)&args); 701926deccbSFrançois Tigeot adjusted_clock = le16_to_cpu(args.v1.usPixelClock) * 10; 702926deccbSFrançois Tigeot break; 703926deccbSFrançois Tigeot case 3: 704c6f73aabSFrançois Tigeot args.v3.sInput.usPixelClock = cpu_to_le16(clock / 10); 705926deccbSFrançois Tigeot args.v3.sInput.ucTransmitterID = radeon_encoder->encoder_id; 706926deccbSFrançois Tigeot args.v3.sInput.ucEncodeMode = encoder_mode; 707926deccbSFrançois Tigeot args.v3.sInput.ucDispPllConfig = 0; 708926deccbSFrançois Tigeot if (radeon_crtc->ss_enabled && radeon_crtc->ss.percentage) 709926deccbSFrançois Tigeot args.v3.sInput.ucDispPllConfig |= 710926deccbSFrançois Tigeot DISPPLL_CONFIG_SS_ENABLE; 711926deccbSFrançois Tigeot if (ENCODER_MODE_IS_DP(encoder_mode)) { 712926deccbSFrançois Tigeot args.v3.sInput.ucDispPllConfig |= 713926deccbSFrançois Tigeot DISPPLL_CONFIG_COHERENT_MODE; 714926deccbSFrançois Tigeot /* 16200 or 27000 */ 715926deccbSFrançois Tigeot args.v3.sInput.usPixelClock = cpu_to_le16(dp_clock / 10); 716926deccbSFrançois Tigeot } else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { 717926deccbSFrançois Tigeot struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 718926deccbSFrançois Tigeot if (dig->coherent_mode) 719926deccbSFrançois Tigeot args.v3.sInput.ucDispPllConfig |= 720926deccbSFrançois Tigeot DISPPLL_CONFIG_COHERENT_MODE; 721926deccbSFrançois Tigeot if (is_duallink) 722926deccbSFrançois Tigeot args.v3.sInput.ucDispPllConfig |= 723926deccbSFrançois Tigeot DISPPLL_CONFIG_DUAL_LINK; 724926deccbSFrançois Tigeot } 725926deccbSFrançois Tigeot if (radeon_encoder_get_dp_bridge_encoder_id(encoder) != 726926deccbSFrançois Tigeot ENCODER_OBJECT_ID_NONE) 727926deccbSFrançois Tigeot args.v3.sInput.ucExtTransmitterID = 728926deccbSFrançois Tigeot radeon_encoder_get_dp_bridge_encoder_id(encoder); 729926deccbSFrançois Tigeot else 730926deccbSFrançois Tigeot args.v3.sInput.ucExtTransmitterID = 0; 731926deccbSFrançois Tigeot 732926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, 733926deccbSFrançois Tigeot index, (uint32_t *)&args); 734926deccbSFrançois Tigeot adjusted_clock = le32_to_cpu(args.v3.sOutput.ulDispPllFreq) * 10; 735926deccbSFrançois Tigeot if (args.v3.sOutput.ucRefDiv) { 736926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV; 737926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_USE_REF_DIV; 738926deccbSFrançois Tigeot radeon_crtc->pll_reference_div = args.v3.sOutput.ucRefDiv; 739926deccbSFrançois Tigeot } 740926deccbSFrançois Tigeot if (args.v3.sOutput.ucPostDiv) { 741926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_USE_FRAC_FB_DIV; 742926deccbSFrançois Tigeot radeon_crtc->pll_flags |= RADEON_PLL_USE_POST_DIV; 743926deccbSFrançois Tigeot radeon_crtc->pll_post_div = args.v3.sOutput.ucPostDiv; 744926deccbSFrançois Tigeot } 745926deccbSFrançois Tigeot break; 746926deccbSFrançois Tigeot default: 747926deccbSFrançois Tigeot DRM_ERROR("Unknown table version %d %d\n", frev, crev); 748926deccbSFrançois Tigeot return adjusted_clock; 749926deccbSFrançois Tigeot } 750926deccbSFrançois Tigeot break; 751926deccbSFrançois Tigeot default: 752926deccbSFrançois Tigeot DRM_ERROR("Unknown table version %d %d\n", frev, crev); 753926deccbSFrançois Tigeot return adjusted_clock; 754926deccbSFrançois Tigeot } 755926deccbSFrançois Tigeot } 756926deccbSFrançois Tigeot return adjusted_clock; 757926deccbSFrançois Tigeot } 758926deccbSFrançois Tigeot 759926deccbSFrançois Tigeot union set_pixel_clock { 760926deccbSFrançois Tigeot SET_PIXEL_CLOCK_PS_ALLOCATION base; 761926deccbSFrançois Tigeot PIXEL_CLOCK_PARAMETERS v1; 762926deccbSFrançois Tigeot PIXEL_CLOCK_PARAMETERS_V2 v2; 763926deccbSFrançois Tigeot PIXEL_CLOCK_PARAMETERS_V3 v3; 764926deccbSFrançois Tigeot PIXEL_CLOCK_PARAMETERS_V5 v5; 765926deccbSFrançois Tigeot PIXEL_CLOCK_PARAMETERS_V6 v6; 766926deccbSFrançois Tigeot }; 767926deccbSFrançois Tigeot 768926deccbSFrançois Tigeot /* on DCE5, make sure the voltage is high enough to support the 769926deccbSFrançois Tigeot * required disp clk. 770926deccbSFrançois Tigeot */ 771926deccbSFrançois Tigeot static void atombios_crtc_set_disp_eng_pll(struct radeon_device *rdev, 772926deccbSFrançois Tigeot u32 dispclk) 773926deccbSFrançois Tigeot { 774926deccbSFrançois Tigeot u8 frev, crev; 775926deccbSFrançois Tigeot int index; 776926deccbSFrançois Tigeot union set_pixel_clock args; 777926deccbSFrançois Tigeot 778926deccbSFrançois Tigeot memset(&args, 0, sizeof(args)); 779926deccbSFrançois Tigeot 780926deccbSFrançois Tigeot index = GetIndexIntoMasterTable(COMMAND, SetPixelClock); 781926deccbSFrançois Tigeot if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, 782926deccbSFrançois Tigeot &crev)) 783926deccbSFrançois Tigeot return; 784926deccbSFrançois Tigeot 785926deccbSFrançois Tigeot switch (frev) { 786926deccbSFrançois Tigeot case 1: 787926deccbSFrançois Tigeot switch (crev) { 788926deccbSFrançois Tigeot case 5: 789926deccbSFrançois Tigeot /* if the default dcpll clock is specified, 790926deccbSFrançois Tigeot * SetPixelClock provides the dividers 791926deccbSFrançois Tigeot */ 792926deccbSFrançois Tigeot args.v5.ucCRTC = ATOM_CRTC_INVALID; 793926deccbSFrançois Tigeot args.v5.usPixelClock = cpu_to_le16(dispclk); 794926deccbSFrançois Tigeot args.v5.ucPpll = ATOM_DCPLL; 795926deccbSFrançois Tigeot break; 796926deccbSFrançois Tigeot case 6: 797926deccbSFrançois Tigeot /* if the default dcpll clock is specified, 798926deccbSFrançois Tigeot * SetPixelClock provides the dividers 799926deccbSFrançois Tigeot */ 800926deccbSFrançois Tigeot args.v6.ulDispEngClkFreq = cpu_to_le32(dispclk); 80157e252bfSMichael Neumann if (ASIC_IS_DCE61(rdev) || ASIC_IS_DCE8(rdev)) 802926deccbSFrançois Tigeot args.v6.ucPpll = ATOM_EXT_PLL1; 803926deccbSFrançois Tigeot else if (ASIC_IS_DCE6(rdev)) 804926deccbSFrançois Tigeot args.v6.ucPpll = ATOM_PPLL0; 805926deccbSFrançois Tigeot else 806926deccbSFrançois Tigeot args.v6.ucPpll = ATOM_DCPLL; 807926deccbSFrançois Tigeot break; 808926deccbSFrançois Tigeot default: 809926deccbSFrançois Tigeot DRM_ERROR("Unknown table version %d %d\n", frev, crev); 810926deccbSFrançois Tigeot return; 811926deccbSFrançois Tigeot } 812926deccbSFrançois Tigeot break; 813926deccbSFrançois Tigeot default: 814926deccbSFrançois Tigeot DRM_ERROR("Unknown table version %d %d\n", frev, crev); 815926deccbSFrançois Tigeot return; 816926deccbSFrançois Tigeot } 817926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 818926deccbSFrançois Tigeot } 819926deccbSFrançois Tigeot 820926deccbSFrançois Tigeot static void atombios_crtc_program_pll(struct drm_crtc *crtc, 821926deccbSFrançois Tigeot u32 crtc_id, 822926deccbSFrançois Tigeot int pll_id, 823926deccbSFrançois Tigeot u32 encoder_mode, 824926deccbSFrançois Tigeot u32 encoder_id, 825926deccbSFrançois Tigeot u32 clock, 826926deccbSFrançois Tigeot u32 ref_div, 827926deccbSFrançois Tigeot u32 fb_div, 828926deccbSFrançois Tigeot u32 frac_fb_div, 829926deccbSFrançois Tigeot u32 post_div, 830926deccbSFrançois Tigeot int bpc, 831926deccbSFrançois Tigeot bool ss_enabled, 832926deccbSFrançois Tigeot struct radeon_atom_ss *ss) 833926deccbSFrançois Tigeot { 834926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 835926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 836926deccbSFrançois Tigeot u8 frev, crev; 837926deccbSFrançois Tigeot int index = GetIndexIntoMasterTable(COMMAND, SetPixelClock); 838926deccbSFrançois Tigeot union set_pixel_clock args; 839926deccbSFrançois Tigeot 840926deccbSFrançois Tigeot memset(&args, 0, sizeof(args)); 841926deccbSFrançois Tigeot 842926deccbSFrançois Tigeot if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, 843926deccbSFrançois Tigeot &crev)) 844926deccbSFrançois Tigeot return; 845926deccbSFrançois Tigeot 846926deccbSFrançois Tigeot switch (frev) { 847926deccbSFrançois Tigeot case 1: 848926deccbSFrançois Tigeot switch (crev) { 849926deccbSFrançois Tigeot case 1: 850926deccbSFrançois Tigeot if (clock == ATOM_DISABLE) 851926deccbSFrançois Tigeot return; 852926deccbSFrançois Tigeot args.v1.usPixelClock = cpu_to_le16(clock / 10); 853926deccbSFrançois Tigeot args.v1.usRefDiv = cpu_to_le16(ref_div); 854926deccbSFrançois Tigeot args.v1.usFbDiv = cpu_to_le16(fb_div); 855926deccbSFrançois Tigeot args.v1.ucFracFbDiv = frac_fb_div; 856926deccbSFrançois Tigeot args.v1.ucPostDiv = post_div; 857926deccbSFrançois Tigeot args.v1.ucPpll = pll_id; 858926deccbSFrançois Tigeot args.v1.ucCRTC = crtc_id; 859926deccbSFrançois Tigeot args.v1.ucRefDivSrc = 1; 860926deccbSFrançois Tigeot break; 861926deccbSFrançois Tigeot case 2: 862926deccbSFrançois Tigeot args.v2.usPixelClock = cpu_to_le16(clock / 10); 863926deccbSFrançois Tigeot args.v2.usRefDiv = cpu_to_le16(ref_div); 864926deccbSFrançois Tigeot args.v2.usFbDiv = cpu_to_le16(fb_div); 865926deccbSFrançois Tigeot args.v2.ucFracFbDiv = frac_fb_div; 866926deccbSFrançois Tigeot args.v2.ucPostDiv = post_div; 867926deccbSFrançois Tigeot args.v2.ucPpll = pll_id; 868926deccbSFrançois Tigeot args.v2.ucCRTC = crtc_id; 869926deccbSFrançois Tigeot args.v2.ucRefDivSrc = 1; 870926deccbSFrançois Tigeot break; 871926deccbSFrançois Tigeot case 3: 872926deccbSFrançois Tigeot args.v3.usPixelClock = cpu_to_le16(clock / 10); 873926deccbSFrançois Tigeot args.v3.usRefDiv = cpu_to_le16(ref_div); 874926deccbSFrançois Tigeot args.v3.usFbDiv = cpu_to_le16(fb_div); 875926deccbSFrançois Tigeot args.v3.ucFracFbDiv = frac_fb_div; 876926deccbSFrançois Tigeot args.v3.ucPostDiv = post_div; 877926deccbSFrançois Tigeot args.v3.ucPpll = pll_id; 878926deccbSFrançois Tigeot if (crtc_id == ATOM_CRTC2) 879926deccbSFrançois Tigeot args.v3.ucMiscInfo = PIXEL_CLOCK_MISC_CRTC_SEL_CRTC2; 880926deccbSFrançois Tigeot else 881926deccbSFrançois Tigeot args.v3.ucMiscInfo = PIXEL_CLOCK_MISC_CRTC_SEL_CRTC1; 882926deccbSFrançois Tigeot if (ss_enabled && (ss->type & ATOM_EXTERNAL_SS_MASK)) 883926deccbSFrançois Tigeot args.v3.ucMiscInfo |= PIXEL_CLOCK_MISC_REF_DIV_SRC; 884926deccbSFrançois Tigeot args.v3.ucTransmitterId = encoder_id; 885926deccbSFrançois Tigeot args.v3.ucEncoderMode = encoder_mode; 886926deccbSFrançois Tigeot break; 887926deccbSFrançois Tigeot case 5: 888926deccbSFrançois Tigeot args.v5.ucCRTC = crtc_id; 889926deccbSFrançois Tigeot args.v5.usPixelClock = cpu_to_le16(clock / 10); 890926deccbSFrançois Tigeot args.v5.ucRefDiv = ref_div; 891926deccbSFrançois Tigeot args.v5.usFbDiv = cpu_to_le16(fb_div); 892926deccbSFrançois Tigeot args.v5.ulFbDivDecFrac = cpu_to_le32(frac_fb_div * 100000); 893926deccbSFrançois Tigeot args.v5.ucPostDiv = post_div; 894926deccbSFrançois Tigeot args.v5.ucMiscInfo = 0; /* HDMI depth, etc. */ 895926deccbSFrançois Tigeot if (ss_enabled && (ss->type & ATOM_EXTERNAL_SS_MASK)) 896926deccbSFrançois Tigeot args.v5.ucMiscInfo |= PIXEL_CLOCK_V5_MISC_REF_DIV_SRC; 897c6f73aabSFrançois Tigeot if (encoder_mode == ATOM_ENCODER_MODE_HDMI) { 898926deccbSFrançois Tigeot switch (bpc) { 899926deccbSFrançois Tigeot case 8: 900926deccbSFrançois Tigeot default: 901926deccbSFrançois Tigeot args.v5.ucMiscInfo |= PIXEL_CLOCK_V5_MISC_HDMI_24BPP; 902926deccbSFrançois Tigeot break; 903926deccbSFrançois Tigeot case 10: 904c6f73aabSFrançois Tigeot /* yes this is correct, the atom define is wrong */ 905c6f73aabSFrançois Tigeot args.v5.ucMiscInfo |= PIXEL_CLOCK_V5_MISC_HDMI_32BPP; 906c6f73aabSFrançois Tigeot break; 907c6f73aabSFrançois Tigeot case 12: 908c6f73aabSFrançois Tigeot /* yes this is correct, the atom define is wrong */ 909926deccbSFrançois Tigeot args.v5.ucMiscInfo |= PIXEL_CLOCK_V5_MISC_HDMI_30BPP; 910926deccbSFrançois Tigeot break; 911926deccbSFrançois Tigeot } 912c6f73aabSFrançois Tigeot } 913926deccbSFrançois Tigeot args.v5.ucTransmitterID = encoder_id; 914926deccbSFrançois Tigeot args.v5.ucEncoderMode = encoder_mode; 915926deccbSFrançois Tigeot args.v5.ucPpll = pll_id; 916926deccbSFrançois Tigeot break; 917926deccbSFrançois Tigeot case 6: 918926deccbSFrançois Tigeot args.v6.ulDispEngClkFreq = cpu_to_le32(crtc_id << 24 | clock / 10); 919926deccbSFrançois Tigeot args.v6.ucRefDiv = ref_div; 920926deccbSFrançois Tigeot args.v6.usFbDiv = cpu_to_le16(fb_div); 921926deccbSFrançois Tigeot args.v6.ulFbDivDecFrac = cpu_to_le32(frac_fb_div * 100000); 922926deccbSFrançois Tigeot args.v6.ucPostDiv = post_div; 923926deccbSFrançois Tigeot args.v6.ucMiscInfo = 0; /* HDMI depth, etc. */ 924926deccbSFrançois Tigeot if (ss_enabled && (ss->type & ATOM_EXTERNAL_SS_MASK)) 925926deccbSFrançois Tigeot args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_REF_DIV_SRC; 926c6f73aabSFrançois Tigeot if (encoder_mode == ATOM_ENCODER_MODE_HDMI) { 927926deccbSFrançois Tigeot switch (bpc) { 928926deccbSFrançois Tigeot case 8: 929926deccbSFrançois Tigeot default: 930926deccbSFrançois Tigeot args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_24BPP; 931926deccbSFrançois Tigeot break; 932926deccbSFrançois Tigeot case 10: 933c6f73aabSFrançois Tigeot args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_30BPP_V6; 934926deccbSFrançois Tigeot break; 935926deccbSFrançois Tigeot case 12: 936c6f73aabSFrançois Tigeot args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_36BPP_V6; 937926deccbSFrançois Tigeot break; 938926deccbSFrançois Tigeot case 16: 939926deccbSFrançois Tigeot args.v6.ucMiscInfo |= PIXEL_CLOCK_V6_MISC_HDMI_48BPP; 940926deccbSFrançois Tigeot break; 941926deccbSFrançois Tigeot } 942c6f73aabSFrançois Tigeot } 943926deccbSFrançois Tigeot args.v6.ucTransmitterID = encoder_id; 944926deccbSFrançois Tigeot args.v6.ucEncoderMode = encoder_mode; 945926deccbSFrançois Tigeot args.v6.ucPpll = pll_id; 946926deccbSFrançois Tigeot break; 947926deccbSFrançois Tigeot default: 948926deccbSFrançois Tigeot DRM_ERROR("Unknown table version %d %d\n", frev, crev); 949926deccbSFrançois Tigeot return; 950926deccbSFrançois Tigeot } 951926deccbSFrançois Tigeot break; 952926deccbSFrançois Tigeot default: 953926deccbSFrançois Tigeot DRM_ERROR("Unknown table version %d %d\n", frev, crev); 954926deccbSFrançois Tigeot return; 955926deccbSFrançois Tigeot } 956926deccbSFrançois Tigeot 957926deccbSFrançois Tigeot atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 958926deccbSFrançois Tigeot } 959926deccbSFrançois Tigeot 960926deccbSFrançois Tigeot static bool atombios_crtc_prepare_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) 961926deccbSFrançois Tigeot { 962926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 963926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 964926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 965926deccbSFrançois Tigeot struct radeon_encoder *radeon_encoder = 966926deccbSFrançois Tigeot to_radeon_encoder(radeon_crtc->encoder); 967926deccbSFrançois Tigeot int encoder_mode = atombios_get_encoder_mode(radeon_crtc->encoder); 968926deccbSFrançois Tigeot 969926deccbSFrançois Tigeot radeon_crtc->bpc = 8; 970926deccbSFrançois Tigeot radeon_crtc->ss_enabled = false; 971926deccbSFrançois Tigeot 972c59a5c48SFrançois Tigeot if (radeon_encoder->is_mst_encoder) { 973c59a5c48SFrançois Tigeot radeon_dp_mst_prepare_pll(crtc, mode); 974c59a5c48SFrançois Tigeot } else if ((radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT | ATOM_DEVICE_DFP_SUPPORT)) || 975926deccbSFrançois Tigeot (radeon_encoder_get_dp_bridge_encoder_id(radeon_crtc->encoder) != ENCODER_OBJECT_ID_NONE)) { 976926deccbSFrançois Tigeot struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; 977926deccbSFrançois Tigeot struct drm_connector *connector = 978926deccbSFrançois Tigeot radeon_get_connector_for_encoder(radeon_crtc->encoder); 979926deccbSFrançois Tigeot struct radeon_connector *radeon_connector = 980926deccbSFrançois Tigeot to_radeon_connector(connector); 981926deccbSFrançois Tigeot struct radeon_connector_atom_dig *dig_connector = 982926deccbSFrançois Tigeot radeon_connector->con_priv; 983926deccbSFrançois Tigeot int dp_clock; 984c6f73aabSFrançois Tigeot 985c6f73aabSFrançois Tigeot /* Assign mode clock for hdmi deep color max clock limit check */ 986c6f73aabSFrançois Tigeot radeon_connector->pixelclock_for_modeset = mode->clock; 987926deccbSFrançois Tigeot radeon_crtc->bpc = radeon_get_monitor_bpc(connector); 988926deccbSFrançois Tigeot 989926deccbSFrançois Tigeot switch (encoder_mode) { 990926deccbSFrançois Tigeot case ATOM_ENCODER_MODE_DP_MST: 991926deccbSFrançois Tigeot case ATOM_ENCODER_MODE_DP: 992926deccbSFrançois Tigeot /* DP/eDP */ 993926deccbSFrançois Tigeot dp_clock = dig_connector->dp_clock / 10; 994926deccbSFrançois Tigeot if (ASIC_IS_DCE4(rdev)) 995926deccbSFrançois Tigeot radeon_crtc->ss_enabled = 996926deccbSFrançois Tigeot radeon_atombios_get_asic_ss_info(rdev, &radeon_crtc->ss, 997926deccbSFrançois Tigeot ASIC_INTERNAL_SS_ON_DP, 998926deccbSFrançois Tigeot dp_clock); 999926deccbSFrançois Tigeot else { 1000926deccbSFrançois Tigeot if (dp_clock == 16200) { 1001926deccbSFrançois Tigeot radeon_crtc->ss_enabled = 1002926deccbSFrançois Tigeot radeon_atombios_get_ppll_ss_info(rdev, 1003926deccbSFrançois Tigeot &radeon_crtc->ss, 1004926deccbSFrançois Tigeot ATOM_DP_SS_ID2); 1005926deccbSFrançois Tigeot if (!radeon_crtc->ss_enabled) 1006926deccbSFrançois Tigeot radeon_crtc->ss_enabled = 1007926deccbSFrançois Tigeot radeon_atombios_get_ppll_ss_info(rdev, 1008926deccbSFrançois Tigeot &radeon_crtc->ss, 1009926deccbSFrançois Tigeot ATOM_DP_SS_ID1); 1010c6f73aabSFrançois Tigeot } else { 1011926deccbSFrançois Tigeot radeon_crtc->ss_enabled = 1012926deccbSFrançois Tigeot radeon_atombios_get_ppll_ss_info(rdev, 1013926deccbSFrançois Tigeot &radeon_crtc->ss, 1014926deccbSFrançois Tigeot ATOM_DP_SS_ID1); 1015926deccbSFrançois Tigeot } 1016c6f73aabSFrançois Tigeot /* disable spread spectrum on DCE3 DP */ 1017c6f73aabSFrançois Tigeot radeon_crtc->ss_enabled = false; 1018c6f73aabSFrançois Tigeot } 1019926deccbSFrançois Tigeot break; 1020926deccbSFrançois Tigeot case ATOM_ENCODER_MODE_LVDS: 1021926deccbSFrançois Tigeot if (ASIC_IS_DCE4(rdev)) 1022926deccbSFrançois Tigeot radeon_crtc->ss_enabled = 1023926deccbSFrançois Tigeot radeon_atombios_get_asic_ss_info(rdev, 1024926deccbSFrançois Tigeot &radeon_crtc->ss, 1025926deccbSFrançois Tigeot dig->lcd_ss_id, 1026926deccbSFrançois Tigeot mode->clock / 10); 1027926deccbSFrançois Tigeot else 1028926deccbSFrançois Tigeot radeon_crtc->ss_enabled = 1029926deccbSFrançois Tigeot radeon_atombios_get_ppll_ss_info(rdev, 1030926deccbSFrançois Tigeot &radeon_crtc->ss, 1031926deccbSFrançois Tigeot dig->lcd_ss_id); 1032926deccbSFrançois Tigeot break; 1033926deccbSFrançois Tigeot case ATOM_ENCODER_MODE_DVI: 1034926deccbSFrançois Tigeot if (ASIC_IS_DCE4(rdev)) 1035926deccbSFrançois Tigeot radeon_crtc->ss_enabled = 1036926deccbSFrançois Tigeot radeon_atombios_get_asic_ss_info(rdev, 1037926deccbSFrançois Tigeot &radeon_crtc->ss, 1038926deccbSFrançois Tigeot ASIC_INTERNAL_SS_ON_TMDS, 1039926deccbSFrançois Tigeot mode->clock / 10); 1040926deccbSFrançois Tigeot break; 1041926deccbSFrançois Tigeot case ATOM_ENCODER_MODE_HDMI: 1042926deccbSFrançois Tigeot if (ASIC_IS_DCE4(rdev)) 1043926deccbSFrançois Tigeot radeon_crtc->ss_enabled = 1044926deccbSFrançois Tigeot radeon_atombios_get_asic_ss_info(rdev, 1045926deccbSFrançois Tigeot &radeon_crtc->ss, 1046926deccbSFrançois Tigeot ASIC_INTERNAL_SS_ON_HDMI, 1047926deccbSFrançois Tigeot mode->clock / 10); 1048926deccbSFrançois Tigeot break; 1049926deccbSFrançois Tigeot default: 1050926deccbSFrançois Tigeot break; 1051926deccbSFrançois Tigeot } 1052926deccbSFrançois Tigeot } 1053926deccbSFrançois Tigeot 1054926deccbSFrançois Tigeot /* adjust pixel clock as needed */ 1055926deccbSFrançois Tigeot radeon_crtc->adjusted_clock = atombios_adjust_pll(crtc, mode); 1056926deccbSFrançois Tigeot 1057926deccbSFrançois Tigeot return true; 1058926deccbSFrançois Tigeot } 1059926deccbSFrançois Tigeot 1060926deccbSFrançois Tigeot static void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) 1061926deccbSFrançois Tigeot { 1062926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 1063926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 1064926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 1065926deccbSFrançois Tigeot struct radeon_encoder *radeon_encoder = 1066926deccbSFrançois Tigeot to_radeon_encoder(radeon_crtc->encoder); 1067926deccbSFrançois Tigeot u32 pll_clock = mode->clock; 1068c6f73aabSFrançois Tigeot u32 clock = mode->clock; 1069926deccbSFrançois Tigeot u32 ref_div = 0, fb_div = 0, frac_fb_div = 0, post_div = 0; 1070926deccbSFrançois Tigeot struct radeon_pll *pll; 1071926deccbSFrançois Tigeot int encoder_mode = atombios_get_encoder_mode(radeon_crtc->encoder); 1072926deccbSFrançois Tigeot 1073c6f73aabSFrançois Tigeot /* pass the actual clock to atombios_crtc_program_pll for DCE5,6 for HDMI */ 1074c6f73aabSFrançois Tigeot if (ASIC_IS_DCE5(rdev) && 1075c6f73aabSFrançois Tigeot (encoder_mode == ATOM_ENCODER_MODE_HDMI) && 1076c6f73aabSFrançois Tigeot (radeon_crtc->bpc > 8)) 1077c6f73aabSFrançois Tigeot clock = radeon_crtc->adjusted_clock; 1078c6f73aabSFrançois Tigeot 1079926deccbSFrançois Tigeot switch (radeon_crtc->pll_id) { 1080926deccbSFrançois Tigeot case ATOM_PPLL1: 1081926deccbSFrançois Tigeot pll = &rdev->clock.p1pll; 1082926deccbSFrançois Tigeot break; 1083926deccbSFrançois Tigeot case ATOM_PPLL2: 1084926deccbSFrançois Tigeot pll = &rdev->clock.p2pll; 1085926deccbSFrançois Tigeot break; 1086926deccbSFrançois Tigeot case ATOM_DCPLL: 1087926deccbSFrançois Tigeot case ATOM_PPLL_INVALID: 1088926deccbSFrançois Tigeot default: 1089926deccbSFrançois Tigeot pll = &rdev->clock.dcpll; 1090926deccbSFrançois Tigeot break; 1091926deccbSFrançois Tigeot } 1092926deccbSFrançois Tigeot 1093926deccbSFrançois Tigeot /* update pll params */ 1094926deccbSFrançois Tigeot pll->flags = radeon_crtc->pll_flags; 1095926deccbSFrançois Tigeot pll->reference_div = radeon_crtc->pll_reference_div; 1096926deccbSFrançois Tigeot pll->post_div = radeon_crtc->pll_post_div; 1097926deccbSFrançois Tigeot 1098926deccbSFrançois Tigeot if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) 1099926deccbSFrançois Tigeot /* TV seems to prefer the legacy algo on some boards */ 1100926deccbSFrançois Tigeot radeon_compute_pll_legacy(pll, radeon_crtc->adjusted_clock, &pll_clock, 1101926deccbSFrançois Tigeot &fb_div, &frac_fb_div, &ref_div, &post_div); 1102926deccbSFrançois Tigeot else if (ASIC_IS_AVIVO(rdev)) 1103926deccbSFrançois Tigeot radeon_compute_pll_avivo(pll, radeon_crtc->adjusted_clock, &pll_clock, 1104926deccbSFrançois Tigeot &fb_div, &frac_fb_div, &ref_div, &post_div); 1105926deccbSFrançois Tigeot else 1106926deccbSFrançois Tigeot radeon_compute_pll_legacy(pll, radeon_crtc->adjusted_clock, &pll_clock, 1107926deccbSFrançois Tigeot &fb_div, &frac_fb_div, &ref_div, &post_div); 1108926deccbSFrançois Tigeot 1109926deccbSFrançois Tigeot atombios_crtc_program_ss(rdev, ATOM_DISABLE, radeon_crtc->pll_id, 1110926deccbSFrançois Tigeot radeon_crtc->crtc_id, &radeon_crtc->ss); 1111926deccbSFrançois Tigeot 1112926deccbSFrançois Tigeot atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id, 1113c6f73aabSFrançois Tigeot encoder_mode, radeon_encoder->encoder_id, clock, 1114926deccbSFrançois Tigeot ref_div, fb_div, frac_fb_div, post_div, 1115926deccbSFrançois Tigeot radeon_crtc->bpc, radeon_crtc->ss_enabled, &radeon_crtc->ss); 1116926deccbSFrançois Tigeot 1117926deccbSFrançois Tigeot if (radeon_crtc->ss_enabled) { 1118926deccbSFrançois Tigeot /* calculate ss amount and step size */ 1119926deccbSFrançois Tigeot if (ASIC_IS_DCE4(rdev)) { 1120926deccbSFrançois Tigeot u32 step_size; 1121c6f73aabSFrançois Tigeot u32 amount = (((fb_div * 10) + frac_fb_div) * 1122c6f73aabSFrançois Tigeot (u32)radeon_crtc->ss.percentage) / 1123c6f73aabSFrançois Tigeot (100 * (u32)radeon_crtc->ss.percentage_divider); 1124926deccbSFrançois Tigeot radeon_crtc->ss.amount = (amount / 10) & ATOM_PPLL_SS_AMOUNT_V2_FBDIV_MASK; 1125926deccbSFrançois Tigeot radeon_crtc->ss.amount |= ((amount - (amount / 10)) << ATOM_PPLL_SS_AMOUNT_V2_NFRAC_SHIFT) & 1126926deccbSFrançois Tigeot ATOM_PPLL_SS_AMOUNT_V2_NFRAC_MASK; 1127926deccbSFrançois Tigeot if (radeon_crtc->ss.type & ATOM_PPLL_SS_TYPE_V2_CENTRE_SPREAD) 1128c6f73aabSFrançois Tigeot step_size = (4 * amount * ref_div * ((u32)radeon_crtc->ss.rate * 2048)) / 1129926deccbSFrançois Tigeot (125 * 25 * pll->reference_freq / 100); 1130926deccbSFrançois Tigeot else 1131c6f73aabSFrançois Tigeot step_size = (2 * amount * ref_div * ((u32)radeon_crtc->ss.rate * 2048)) / 1132926deccbSFrançois Tigeot (125 * 25 * pll->reference_freq / 100); 1133926deccbSFrançois Tigeot radeon_crtc->ss.step = step_size; 1134926deccbSFrançois Tigeot } 1135926deccbSFrançois Tigeot 1136926deccbSFrançois Tigeot atombios_crtc_program_ss(rdev, ATOM_ENABLE, radeon_crtc->pll_id, 1137926deccbSFrançois Tigeot radeon_crtc->crtc_id, &radeon_crtc->ss); 1138926deccbSFrançois Tigeot } 1139926deccbSFrançois Tigeot } 1140926deccbSFrançois Tigeot 1141926deccbSFrançois Tigeot static int dce4_crtc_do_set_base(struct drm_crtc *crtc, 1142926deccbSFrançois Tigeot struct drm_framebuffer *fb, 1143926deccbSFrançois Tigeot int x, int y, int atomic) 1144926deccbSFrançois Tigeot { 1145926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 1146926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 1147926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 1148926deccbSFrançois Tigeot struct radeon_framebuffer *radeon_fb; 1149926deccbSFrançois Tigeot struct drm_framebuffer *target_fb; 1150926deccbSFrançois Tigeot struct drm_gem_object *obj; 1151926deccbSFrançois Tigeot struct radeon_bo *rbo; 1152926deccbSFrançois Tigeot uint64_t fb_location; 1153926deccbSFrançois Tigeot uint32_t fb_format, fb_pitch_pixels, tiling_flags; 1154926deccbSFrançois Tigeot unsigned bankw, bankh, mtaspect, tile_split; 1155926deccbSFrançois Tigeot u32 fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_NONE); 1156926deccbSFrançois Tigeot u32 tmp, viewport_w, viewport_h; 1157926deccbSFrançois Tigeot int r; 1158c6f73aabSFrançois Tigeot bool bypass_lut = false; 11594be47400SFrançois Tigeot struct drm_format_name_buf format_name; 1160926deccbSFrançois Tigeot 1161926deccbSFrançois Tigeot /* no fb bound */ 1162ba55f2f5SFrançois Tigeot if (!atomic && !crtc->primary->fb) { 1163926deccbSFrançois Tigeot DRM_DEBUG_KMS("No FB bound\n"); 1164926deccbSFrançois Tigeot return 0; 1165926deccbSFrançois Tigeot } 1166926deccbSFrançois Tigeot 1167926deccbSFrançois Tigeot if (atomic) { 1168926deccbSFrançois Tigeot radeon_fb = to_radeon_framebuffer(fb); 1169926deccbSFrançois Tigeot target_fb = fb; 1170926deccbSFrançois Tigeot } 1171926deccbSFrançois Tigeot else { 1172ba55f2f5SFrançois Tigeot radeon_fb = to_radeon_framebuffer(crtc->primary->fb); 1173ba55f2f5SFrançois Tigeot target_fb = crtc->primary->fb; 1174926deccbSFrançois Tigeot } 1175926deccbSFrançois Tigeot 1176926deccbSFrançois Tigeot /* If atomic, assume fb object is pinned & idle & fenced and 1177926deccbSFrançois Tigeot * just update base pointers 1178926deccbSFrançois Tigeot */ 1179926deccbSFrançois Tigeot obj = radeon_fb->obj; 1180926deccbSFrançois Tigeot rbo = gem_to_radeon_bo(obj); 1181926deccbSFrançois Tigeot r = radeon_bo_reserve(rbo, false); 1182926deccbSFrançois Tigeot if (unlikely(r != 0)) 1183926deccbSFrançois Tigeot return r; 1184926deccbSFrançois Tigeot 1185926deccbSFrançois Tigeot if (atomic) 1186926deccbSFrançois Tigeot fb_location = radeon_bo_gpu_offset(rbo); 1187926deccbSFrançois Tigeot else { 1188f77dbd6cSFrançois Tigeot r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, (u64 *)&fb_location); 1189926deccbSFrançois Tigeot if (unlikely(r != 0)) { 1190926deccbSFrançois Tigeot radeon_bo_unreserve(rbo); 1191926deccbSFrançois Tigeot return -EINVAL; 1192926deccbSFrançois Tigeot } 1193926deccbSFrançois Tigeot } 1194926deccbSFrançois Tigeot 1195926deccbSFrançois Tigeot radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL); 1196926deccbSFrançois Tigeot radeon_bo_unreserve(rbo); 1197926deccbSFrançois Tigeot 1198*a85cb24fSFrançois Tigeot switch (target_fb->format->format) { 1199c6f73aabSFrançois Tigeot case DRM_FORMAT_C8: 1200926deccbSFrançois Tigeot fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_8BPP) | 1201926deccbSFrançois Tigeot EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_INDEXED)); 1202926deccbSFrançois Tigeot break; 1203c6f73aabSFrançois Tigeot case DRM_FORMAT_XRGB4444: 1204c6f73aabSFrançois Tigeot case DRM_FORMAT_ARGB4444: 1205c6f73aabSFrançois Tigeot fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | 1206c6f73aabSFrançois Tigeot EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB4444)); 1207c6f73aabSFrançois Tigeot #ifdef __BIG_ENDIAN 1208c6f73aabSFrançois Tigeot fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_8IN16); 1209c6f73aabSFrançois Tigeot #endif 1210c6f73aabSFrançois Tigeot break; 1211c6f73aabSFrançois Tigeot case DRM_FORMAT_XRGB1555: 1212c6f73aabSFrançois Tigeot case DRM_FORMAT_ARGB1555: 1213926deccbSFrançois Tigeot fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | 1214926deccbSFrançois Tigeot EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB1555)); 1215c6f73aabSFrançois Tigeot #ifdef __BIG_ENDIAN 1216c6f73aabSFrançois Tigeot fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_8IN16); 1217c6f73aabSFrançois Tigeot #endif 1218926deccbSFrançois Tigeot break; 1219c6f73aabSFrançois Tigeot case DRM_FORMAT_BGRX5551: 1220c6f73aabSFrançois Tigeot case DRM_FORMAT_BGRA5551: 1221c6f73aabSFrançois Tigeot fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | 1222c6f73aabSFrançois Tigeot EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_BGRA5551)); 1223c6f73aabSFrançois Tigeot #ifdef __BIG_ENDIAN 1224c6f73aabSFrançois Tigeot fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_8IN16); 1225c6f73aabSFrançois Tigeot #endif 1226c6f73aabSFrançois Tigeot break; 1227c6f73aabSFrançois Tigeot case DRM_FORMAT_RGB565: 1228926deccbSFrançois Tigeot fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | 1229926deccbSFrançois Tigeot EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB565)); 1230926deccbSFrançois Tigeot #ifdef __BIG_ENDIAN 1231926deccbSFrançois Tigeot fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_8IN16); 1232926deccbSFrançois Tigeot #endif 1233926deccbSFrançois Tigeot break; 1234c6f73aabSFrançois Tigeot case DRM_FORMAT_XRGB8888: 1235c6f73aabSFrançois Tigeot case DRM_FORMAT_ARGB8888: 1236926deccbSFrançois Tigeot fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_32BPP) | 1237926deccbSFrançois Tigeot EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB8888)); 1238926deccbSFrançois Tigeot #ifdef __BIG_ENDIAN 1239926deccbSFrançois Tigeot fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_8IN32); 1240926deccbSFrançois Tigeot #endif 1241926deccbSFrançois Tigeot break; 1242c6f73aabSFrançois Tigeot case DRM_FORMAT_XRGB2101010: 1243c6f73aabSFrançois Tigeot case DRM_FORMAT_ARGB2101010: 1244c6f73aabSFrançois Tigeot fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_32BPP) | 1245c6f73aabSFrançois Tigeot EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB2101010)); 1246c6f73aabSFrançois Tigeot #ifdef __BIG_ENDIAN 1247c6f73aabSFrançois Tigeot fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_8IN32); 1248c6f73aabSFrançois Tigeot #endif 1249c6f73aabSFrançois Tigeot /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */ 1250c6f73aabSFrançois Tigeot bypass_lut = true; 1251c6f73aabSFrançois Tigeot break; 1252c6f73aabSFrançois Tigeot case DRM_FORMAT_BGRX1010102: 1253c6f73aabSFrançois Tigeot case DRM_FORMAT_BGRA1010102: 1254c6f73aabSFrançois Tigeot fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_32BPP) | 1255c6f73aabSFrançois Tigeot EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_BGRA1010102)); 1256c6f73aabSFrançois Tigeot #ifdef __BIG_ENDIAN 1257c6f73aabSFrançois Tigeot fb_swap = EVERGREEN_GRPH_ENDIAN_SWAP(EVERGREEN_GRPH_ENDIAN_8IN32); 1258c6f73aabSFrançois Tigeot #endif 1259c6f73aabSFrançois Tigeot /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */ 1260c6f73aabSFrançois Tigeot bypass_lut = true; 1261c6f73aabSFrançois Tigeot break; 1262926deccbSFrançois Tigeot default: 12634be47400SFrançois Tigeot DRM_ERROR("Unsupported screen format %s\n", 1264*a85cb24fSFrançois Tigeot drm_get_format_name(target_fb->format->format, &format_name)); 1265926deccbSFrançois Tigeot return -EINVAL; 1266926deccbSFrançois Tigeot } 1267926deccbSFrançois Tigeot 1268926deccbSFrançois Tigeot if (tiling_flags & RADEON_TILING_MACRO) { 1269c6f73aabSFrançois Tigeot evergreen_tiling_fields(tiling_flags, &bankw, &bankh, &mtaspect, &tile_split); 1270c6f73aabSFrançois Tigeot 1271c6f73aabSFrançois Tigeot /* Set NUM_BANKS. */ 1272c6f73aabSFrançois Tigeot if (rdev->family >= CHIP_TAHITI) { 1273c6f73aabSFrançois Tigeot unsigned index, num_banks; 1274c6f73aabSFrançois Tigeot 1275c6f73aabSFrançois Tigeot if (rdev->family >= CHIP_BONAIRE) { 1276c6f73aabSFrançois Tigeot unsigned tileb, tile_split_bytes; 1277c6f73aabSFrançois Tigeot 1278c6f73aabSFrançois Tigeot /* Calculate the macrotile mode index. */ 1279c6f73aabSFrançois Tigeot tile_split_bytes = 64 << tile_split; 1280*a85cb24fSFrançois Tigeot tileb = 8 * 8 * target_fb->format->cpp[0]; 1281c6f73aabSFrançois Tigeot tileb = min(tile_split_bytes, tileb); 1282c6f73aabSFrançois Tigeot 1283c6f73aabSFrançois Tigeot for (index = 0; tileb > 64; index++) 1284c6f73aabSFrançois Tigeot tileb >>= 1; 1285c6f73aabSFrançois Tigeot 1286c6f73aabSFrançois Tigeot if (index >= 16) { 1287c6f73aabSFrançois Tigeot DRM_ERROR("Wrong screen bpp (%u) or tile split (%u)\n", 1288*a85cb24fSFrançois Tigeot target_fb->format->cpp[0] * 8, 1289*a85cb24fSFrançois Tigeot tile_split); 1290c6f73aabSFrançois Tigeot return -EINVAL; 1291c6f73aabSFrançois Tigeot } 1292c6f73aabSFrançois Tigeot 1293c6f73aabSFrançois Tigeot num_banks = (rdev->config.cik.macrotile_mode_array[index] >> 6) & 0x3; 1294c6f73aabSFrançois Tigeot } else { 1295*a85cb24fSFrançois Tigeot switch (target_fb->format->cpp[0] * 8) { 1296c6f73aabSFrançois Tigeot case 8: 1297c6f73aabSFrançois Tigeot index = 10; 1298c6f73aabSFrançois Tigeot break; 1299c6f73aabSFrançois Tigeot case 16: 1300c6f73aabSFrançois Tigeot index = SI_TILE_MODE_COLOR_2D_SCANOUT_16BPP; 1301c6f73aabSFrançois Tigeot break; 1302c6f73aabSFrançois Tigeot default: 1303c6f73aabSFrançois Tigeot case 32: 1304c6f73aabSFrançois Tigeot index = SI_TILE_MODE_COLOR_2D_SCANOUT_32BPP; 1305c6f73aabSFrançois Tigeot break; 1306c6f73aabSFrançois Tigeot } 1307c6f73aabSFrançois Tigeot 1308c6f73aabSFrançois Tigeot num_banks = (rdev->config.si.tile_mode_array[index] >> 20) & 0x3; 1309c6f73aabSFrançois Tigeot } 1310c6f73aabSFrançois Tigeot 1311c6f73aabSFrançois Tigeot fb_format |= EVERGREEN_GRPH_NUM_BANKS(num_banks); 1312c6f73aabSFrançois Tigeot } else { 1313c6f73aabSFrançois Tigeot /* NI and older. */ 1314c6f73aabSFrançois Tigeot if (rdev->family >= CHIP_CAYMAN) 1315926deccbSFrançois Tigeot tmp = rdev->config.cayman.tile_config; 1316926deccbSFrançois Tigeot else 1317926deccbSFrançois Tigeot tmp = rdev->config.evergreen.tile_config; 1318926deccbSFrançois Tigeot 1319926deccbSFrançois Tigeot switch ((tmp & 0xf0) >> 4) { 1320926deccbSFrançois Tigeot case 0: /* 4 banks */ 1321926deccbSFrançois Tigeot fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_4_BANK); 1322926deccbSFrançois Tigeot break; 1323926deccbSFrançois Tigeot case 1: /* 8 banks */ 1324926deccbSFrançois Tigeot default: 1325926deccbSFrançois Tigeot fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_8_BANK); 1326926deccbSFrançois Tigeot break; 1327926deccbSFrançois Tigeot case 2: /* 16 banks */ 1328926deccbSFrançois Tigeot fb_format |= EVERGREEN_GRPH_NUM_BANKS(EVERGREEN_ADDR_SURF_16_BANK); 1329926deccbSFrançois Tigeot break; 1330926deccbSFrançois Tigeot } 1331c6f73aabSFrançois Tigeot } 1332926deccbSFrançois Tigeot 1333926deccbSFrançois Tigeot fb_format |= EVERGREEN_GRPH_ARRAY_MODE(EVERGREEN_GRPH_ARRAY_2D_TILED_THIN1); 1334926deccbSFrançois Tigeot fb_format |= EVERGREEN_GRPH_TILE_SPLIT(tile_split); 1335926deccbSFrançois Tigeot fb_format |= EVERGREEN_GRPH_BANK_WIDTH(bankw); 1336926deccbSFrançois Tigeot fb_format |= EVERGREEN_GRPH_BANK_HEIGHT(bankh); 1337926deccbSFrançois Tigeot fb_format |= EVERGREEN_GRPH_MACRO_TILE_ASPECT(mtaspect); 133857e252bfSMichael Neumann if (rdev->family >= CHIP_BONAIRE) { 133957e252bfSMichael Neumann /* XXX need to know more about the surface tiling mode */ 134057e252bfSMichael Neumann fb_format |= CIK_GRPH_MICRO_TILE_MODE(CIK_DISPLAY_MICRO_TILING); 134157e252bfSMichael Neumann } 1342926deccbSFrançois Tigeot } else if (tiling_flags & RADEON_TILING_MICRO) 1343926deccbSFrançois Tigeot fb_format |= EVERGREEN_GRPH_ARRAY_MODE(EVERGREEN_GRPH_ARRAY_1D_TILED_THIN1); 1344926deccbSFrançois Tigeot 134557e252bfSMichael Neumann if (rdev->family >= CHIP_BONAIRE) { 1346c6f73aabSFrançois Tigeot /* Read the pipe config from the 2D TILED SCANOUT mode. 1347c6f73aabSFrançois Tigeot * It should be the same for the other modes too, but not all 1348c6f73aabSFrançois Tigeot * modes set the pipe config field. */ 1349c6f73aabSFrançois Tigeot u32 pipe_config = (rdev->config.cik.tile_mode_array[10] >> 6) & 0x1f; 1350c6f73aabSFrançois Tigeot 1351c6f73aabSFrançois Tigeot fb_format |= CIK_GRPH_PIPE_CONFIG(pipe_config); 135257e252bfSMichael Neumann } else if ((rdev->family == CHIP_TAHITI) || 1353926deccbSFrançois Tigeot (rdev->family == CHIP_PITCAIRN)) 1354926deccbSFrançois Tigeot fb_format |= SI_GRPH_PIPE_CONFIG(SI_ADDR_SURF_P8_32x32_8x16); 1355c6f73aabSFrançois Tigeot else if ((rdev->family == CHIP_VERDE) || 1356c6f73aabSFrançois Tigeot (rdev->family == CHIP_OLAND) || 1357c6f73aabSFrançois Tigeot (rdev->family == CHIP_HAINAN)) /* for completeness. HAINAN has no display hw */ 1358926deccbSFrançois Tigeot fb_format |= SI_GRPH_PIPE_CONFIG(SI_ADDR_SURF_P4_8x16); 1359926deccbSFrançois Tigeot 1360926deccbSFrançois Tigeot switch (radeon_crtc->crtc_id) { 1361926deccbSFrançois Tigeot case 0: 1362926deccbSFrançois Tigeot WREG32(AVIVO_D1VGA_CONTROL, 0); 1363926deccbSFrançois Tigeot break; 1364926deccbSFrançois Tigeot case 1: 1365926deccbSFrançois Tigeot WREG32(AVIVO_D2VGA_CONTROL, 0); 1366926deccbSFrançois Tigeot break; 1367926deccbSFrançois Tigeot case 2: 1368926deccbSFrançois Tigeot WREG32(EVERGREEN_D3VGA_CONTROL, 0); 1369926deccbSFrançois Tigeot break; 1370926deccbSFrançois Tigeot case 3: 1371926deccbSFrançois Tigeot WREG32(EVERGREEN_D4VGA_CONTROL, 0); 1372926deccbSFrançois Tigeot break; 1373926deccbSFrançois Tigeot case 4: 1374926deccbSFrançois Tigeot WREG32(EVERGREEN_D5VGA_CONTROL, 0); 1375926deccbSFrançois Tigeot break; 1376926deccbSFrançois Tigeot case 5: 1377926deccbSFrançois Tigeot WREG32(EVERGREEN_D6VGA_CONTROL, 0); 1378926deccbSFrançois Tigeot break; 1379926deccbSFrançois Tigeot default: 1380926deccbSFrançois Tigeot break; 1381926deccbSFrançois Tigeot } 1382926deccbSFrançois Tigeot 1383d78d3a22SFrançois Tigeot /* Make sure surface address is updated at vertical blank rather than 1384d78d3a22SFrançois Tigeot * horizontal blank 1385d78d3a22SFrançois Tigeot */ 1386d78d3a22SFrançois Tigeot WREG32(EVERGREEN_GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset, 0); 1387d78d3a22SFrançois Tigeot 1388926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, 1389926deccbSFrançois Tigeot upper_32_bits(fb_location)); 1390926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, 1391926deccbSFrançois Tigeot upper_32_bits(fb_location)); 1392926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, 1393926deccbSFrançois Tigeot (u32)fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK); 1394926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, 1395926deccbSFrançois Tigeot (u32) fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK); 1396926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_CONTROL + radeon_crtc->crtc_offset, fb_format); 1397926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_SWAP_CONTROL + radeon_crtc->crtc_offset, fb_swap); 1398926deccbSFrançois Tigeot 1399c6f73aabSFrançois Tigeot /* 1400c6f73aabSFrançois Tigeot * The LUT only has 256 slots for indexing by a 8 bpc fb. Bypass the LUT 1401c6f73aabSFrançois Tigeot * for > 8 bpc scanout to avoid truncation of fb indices to 8 msb's, to 1402c6f73aabSFrançois Tigeot * retain the full precision throughout the pipeline. 1403c6f73aabSFrançois Tigeot */ 1404c6f73aabSFrançois Tigeot WREG32_P(EVERGREEN_GRPH_LUT_10BIT_BYPASS_CONTROL + radeon_crtc->crtc_offset, 1405c6f73aabSFrançois Tigeot (bypass_lut ? EVERGREEN_LUT_10BIT_BYPASS_EN : 0), 1406c6f73aabSFrançois Tigeot ~EVERGREEN_LUT_10BIT_BYPASS_EN); 1407c6f73aabSFrançois Tigeot 1408c6f73aabSFrançois Tigeot if (bypass_lut) 1409c6f73aabSFrançois Tigeot DRM_DEBUG_KMS("Bypassing hardware LUT due to 10 bit fb scanout.\n"); 1410c6f73aabSFrançois Tigeot 1411926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_X + radeon_crtc->crtc_offset, 0); 1412926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_Y + radeon_crtc->crtc_offset, 0); 1413926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_X_START + radeon_crtc->crtc_offset, 0); 1414926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_Y_START + radeon_crtc->crtc_offset, 0); 1415926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_X_END + radeon_crtc->crtc_offset, target_fb->width); 1416926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_Y_END + radeon_crtc->crtc_offset, target_fb->height); 1417926deccbSFrançois Tigeot 1418*a85cb24fSFrançois Tigeot fb_pitch_pixels = target_fb->pitches[0] / target_fb->format->cpp[0]; 1419926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_PITCH + radeon_crtc->crtc_offset, fb_pitch_pixels); 1420926deccbSFrançois Tigeot WREG32(EVERGREEN_GRPH_ENABLE + radeon_crtc->crtc_offset, 1); 1421926deccbSFrançois Tigeot 142257e252bfSMichael Neumann if (rdev->family >= CHIP_BONAIRE) 142357e252bfSMichael Neumann WREG32(CIK_LB_DESKTOP_HEIGHT + radeon_crtc->crtc_offset, 142457e252bfSMichael Neumann target_fb->height); 142557e252bfSMichael Neumann else 1426926deccbSFrançois Tigeot WREG32(EVERGREEN_DESKTOP_HEIGHT + radeon_crtc->crtc_offset, 1427926deccbSFrançois Tigeot target_fb->height); 1428926deccbSFrançois Tigeot x &= ~3; 1429926deccbSFrançois Tigeot y &= ~1; 1430926deccbSFrançois Tigeot WREG32(EVERGREEN_VIEWPORT_START + radeon_crtc->crtc_offset, 1431926deccbSFrançois Tigeot (x << 16) | y); 1432926deccbSFrançois Tigeot viewport_w = crtc->mode.hdisplay; 1433926deccbSFrançois Tigeot viewport_h = (crtc->mode.vdisplay + 1) & ~1; 14347dcf36dcSFrançois Tigeot if ((rdev->family >= CHIP_BONAIRE) && 14357dcf36dcSFrançois Tigeot (crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)) 14367dcf36dcSFrançois Tigeot viewport_h *= 2; 1437926deccbSFrançois Tigeot WREG32(EVERGREEN_VIEWPORT_SIZE + radeon_crtc->crtc_offset, 1438926deccbSFrançois Tigeot (viewport_w << 16) | viewport_h); 1439926deccbSFrançois Tigeot 14401dedbd3bSFrançois Tigeot /* set pageflip to happen anywhere in vblank interval */ 14411dedbd3bSFrançois Tigeot WREG32(EVERGREEN_MASTER_UPDATE_MODE + radeon_crtc->crtc_offset, 0); 1442926deccbSFrançois Tigeot 1443ba55f2f5SFrançois Tigeot if (!atomic && fb && fb != crtc->primary->fb) { 1444926deccbSFrançois Tigeot radeon_fb = to_radeon_framebuffer(fb); 1445926deccbSFrançois Tigeot rbo = gem_to_radeon_bo(radeon_fb->obj); 1446926deccbSFrançois Tigeot r = radeon_bo_reserve(rbo, false); 1447926deccbSFrançois Tigeot if (unlikely(r != 0)) 1448926deccbSFrançois Tigeot return r; 1449926deccbSFrançois Tigeot radeon_bo_unpin(rbo); 1450926deccbSFrançois Tigeot radeon_bo_unreserve(rbo); 1451926deccbSFrançois Tigeot } 1452926deccbSFrançois Tigeot 1453926deccbSFrançois Tigeot /* Bytes per pixel may have changed */ 1454926deccbSFrançois Tigeot radeon_bandwidth_update(rdev); 1455926deccbSFrançois Tigeot 1456926deccbSFrançois Tigeot return 0; 1457926deccbSFrançois Tigeot } 1458926deccbSFrançois Tigeot 1459926deccbSFrançois Tigeot static int avivo_crtc_do_set_base(struct drm_crtc *crtc, 1460926deccbSFrançois Tigeot struct drm_framebuffer *fb, 1461926deccbSFrançois Tigeot int x, int y, int atomic) 1462926deccbSFrançois Tigeot { 1463926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 1464926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 1465926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 1466926deccbSFrançois Tigeot struct radeon_framebuffer *radeon_fb; 1467926deccbSFrançois Tigeot struct drm_gem_object *obj; 1468926deccbSFrançois Tigeot struct radeon_bo *rbo; 1469926deccbSFrançois Tigeot struct drm_framebuffer *target_fb; 1470926deccbSFrançois Tigeot uint64_t fb_location; 1471926deccbSFrançois Tigeot uint32_t fb_format, fb_pitch_pixels, tiling_flags; 1472926deccbSFrançois Tigeot u32 fb_swap = R600_D1GRPH_SWAP_ENDIAN_NONE; 1473d78d3a22SFrançois Tigeot u32 viewport_w, viewport_h; 1474926deccbSFrançois Tigeot int r; 1475c6f73aabSFrançois Tigeot bool bypass_lut = false; 14764be47400SFrançois Tigeot struct drm_format_name_buf format_name; 1477926deccbSFrançois Tigeot 1478926deccbSFrançois Tigeot /* no fb bound */ 1479ba55f2f5SFrançois Tigeot if (!atomic && !crtc->primary->fb) { 1480926deccbSFrançois Tigeot DRM_DEBUG_KMS("No FB bound\n"); 1481926deccbSFrançois Tigeot return 0; 1482926deccbSFrançois Tigeot } 1483926deccbSFrançois Tigeot 1484926deccbSFrançois Tigeot if (atomic) { 1485926deccbSFrançois Tigeot radeon_fb = to_radeon_framebuffer(fb); 1486926deccbSFrançois Tigeot target_fb = fb; 1487926deccbSFrançois Tigeot } 1488926deccbSFrançois Tigeot else { 1489ba55f2f5SFrançois Tigeot radeon_fb = to_radeon_framebuffer(crtc->primary->fb); 1490ba55f2f5SFrançois Tigeot target_fb = crtc->primary->fb; 1491926deccbSFrançois Tigeot } 1492926deccbSFrançois Tigeot 1493926deccbSFrançois Tigeot obj = radeon_fb->obj; 1494926deccbSFrançois Tigeot rbo = gem_to_radeon_bo(obj); 1495926deccbSFrançois Tigeot r = radeon_bo_reserve(rbo, false); 1496926deccbSFrançois Tigeot if (unlikely(r != 0)) 1497926deccbSFrançois Tigeot return r; 1498926deccbSFrançois Tigeot 1499926deccbSFrançois Tigeot /* If atomic, assume fb object is pinned & idle & fenced and 1500926deccbSFrançois Tigeot * just update base pointers 1501926deccbSFrançois Tigeot */ 1502926deccbSFrançois Tigeot if (atomic) 1503926deccbSFrançois Tigeot fb_location = radeon_bo_gpu_offset(rbo); 1504926deccbSFrançois Tigeot else { 1505f77dbd6cSFrançois Tigeot r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, (u64 *)&fb_location); 1506926deccbSFrançois Tigeot if (unlikely(r != 0)) { 1507926deccbSFrançois Tigeot radeon_bo_unreserve(rbo); 1508926deccbSFrançois Tigeot return -EINVAL; 1509926deccbSFrançois Tigeot } 1510926deccbSFrançois Tigeot } 1511926deccbSFrançois Tigeot radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL); 1512926deccbSFrançois Tigeot radeon_bo_unreserve(rbo); 1513926deccbSFrançois Tigeot 1514*a85cb24fSFrançois Tigeot switch (target_fb->format->format) { 1515c6f73aabSFrançois Tigeot case DRM_FORMAT_C8: 1516926deccbSFrançois Tigeot fb_format = 1517926deccbSFrançois Tigeot AVIVO_D1GRPH_CONTROL_DEPTH_8BPP | 1518926deccbSFrançois Tigeot AVIVO_D1GRPH_CONTROL_8BPP_INDEXED; 1519926deccbSFrançois Tigeot break; 1520c6f73aabSFrançois Tigeot case DRM_FORMAT_XRGB4444: 1521c6f73aabSFrançois Tigeot case DRM_FORMAT_ARGB4444: 1522c6f73aabSFrançois Tigeot fb_format = 1523c6f73aabSFrançois Tigeot AVIVO_D1GRPH_CONTROL_DEPTH_16BPP | 1524c6f73aabSFrançois Tigeot AVIVO_D1GRPH_CONTROL_16BPP_ARGB4444; 1525c6f73aabSFrançois Tigeot #ifdef __BIG_ENDIAN 1526c6f73aabSFrançois Tigeot fb_swap = R600_D1GRPH_SWAP_ENDIAN_16BIT; 1527c6f73aabSFrançois Tigeot #endif 1528c6f73aabSFrançois Tigeot break; 1529c6f73aabSFrançois Tigeot case DRM_FORMAT_XRGB1555: 1530926deccbSFrançois Tigeot fb_format = 1531926deccbSFrançois Tigeot AVIVO_D1GRPH_CONTROL_DEPTH_16BPP | 1532926deccbSFrançois Tigeot AVIVO_D1GRPH_CONTROL_16BPP_ARGB1555; 1533c6f73aabSFrançois Tigeot #ifdef __BIG_ENDIAN 1534c6f73aabSFrançois Tigeot fb_swap = R600_D1GRPH_SWAP_ENDIAN_16BIT; 1535c6f73aabSFrançois Tigeot #endif 1536926deccbSFrançois Tigeot break; 1537c6f73aabSFrançois Tigeot case DRM_FORMAT_RGB565: 1538926deccbSFrançois Tigeot fb_format = 1539926deccbSFrançois Tigeot AVIVO_D1GRPH_CONTROL_DEPTH_16BPP | 1540926deccbSFrançois Tigeot AVIVO_D1GRPH_CONTROL_16BPP_RGB565; 1541926deccbSFrançois Tigeot #ifdef __BIG_ENDIAN 1542926deccbSFrançois Tigeot fb_swap = R600_D1GRPH_SWAP_ENDIAN_16BIT; 1543926deccbSFrançois Tigeot #endif 1544926deccbSFrançois Tigeot break; 1545c6f73aabSFrançois Tigeot case DRM_FORMAT_XRGB8888: 1546c6f73aabSFrançois Tigeot case DRM_FORMAT_ARGB8888: 1547926deccbSFrançois Tigeot fb_format = 1548926deccbSFrançois Tigeot AVIVO_D1GRPH_CONTROL_DEPTH_32BPP | 1549926deccbSFrançois Tigeot AVIVO_D1GRPH_CONTROL_32BPP_ARGB8888; 1550926deccbSFrançois Tigeot #ifdef __BIG_ENDIAN 1551926deccbSFrançois Tigeot fb_swap = R600_D1GRPH_SWAP_ENDIAN_32BIT; 1552926deccbSFrançois Tigeot #endif 1553926deccbSFrançois Tigeot break; 1554c6f73aabSFrançois Tigeot case DRM_FORMAT_XRGB2101010: 1555c6f73aabSFrançois Tigeot case DRM_FORMAT_ARGB2101010: 1556c6f73aabSFrançois Tigeot fb_format = 1557c6f73aabSFrançois Tigeot AVIVO_D1GRPH_CONTROL_DEPTH_32BPP | 1558c6f73aabSFrançois Tigeot AVIVO_D1GRPH_CONTROL_32BPP_ARGB2101010; 1559c6f73aabSFrançois Tigeot #ifdef __BIG_ENDIAN 1560c6f73aabSFrançois Tigeot fb_swap = R600_D1GRPH_SWAP_ENDIAN_32BIT; 1561c6f73aabSFrançois Tigeot #endif 1562c6f73aabSFrançois Tigeot /* Greater 8 bpc fb needs to bypass hw-lut to retain precision */ 1563c6f73aabSFrançois Tigeot bypass_lut = true; 1564c6f73aabSFrançois Tigeot break; 1565926deccbSFrançois Tigeot default: 15664be47400SFrançois Tigeot DRM_ERROR("Unsupported screen format %s\n", 1567*a85cb24fSFrançois Tigeot drm_get_format_name(target_fb->format->format, &format_name)); 1568926deccbSFrançois Tigeot return -EINVAL; 1569926deccbSFrançois Tigeot } 1570926deccbSFrançois Tigeot 1571926deccbSFrançois Tigeot if (rdev->family >= CHIP_R600) { 1572926deccbSFrançois Tigeot if (tiling_flags & RADEON_TILING_MACRO) 1573926deccbSFrançois Tigeot fb_format |= R600_D1GRPH_ARRAY_MODE_2D_TILED_THIN1; 1574926deccbSFrançois Tigeot else if (tiling_flags & RADEON_TILING_MICRO) 1575926deccbSFrançois Tigeot fb_format |= R600_D1GRPH_ARRAY_MODE_1D_TILED_THIN1; 1576926deccbSFrançois Tigeot } else { 1577926deccbSFrançois Tigeot if (tiling_flags & RADEON_TILING_MACRO) 1578926deccbSFrançois Tigeot fb_format |= AVIVO_D1GRPH_MACRO_ADDRESS_MODE; 1579926deccbSFrançois Tigeot 1580926deccbSFrançois Tigeot if (tiling_flags & RADEON_TILING_MICRO) 1581926deccbSFrançois Tigeot fb_format |= AVIVO_D1GRPH_TILED; 1582926deccbSFrançois Tigeot } 1583926deccbSFrançois Tigeot 1584926deccbSFrançois Tigeot if (radeon_crtc->crtc_id == 0) 1585926deccbSFrançois Tigeot WREG32(AVIVO_D1VGA_CONTROL, 0); 1586926deccbSFrançois Tigeot else 1587926deccbSFrançois Tigeot WREG32(AVIVO_D2VGA_CONTROL, 0); 1588926deccbSFrançois Tigeot 1589d78d3a22SFrançois Tigeot /* Make sure surface address is update at vertical blank rather than 1590d78d3a22SFrançois Tigeot * horizontal blank 1591d78d3a22SFrançois Tigeot */ 1592d78d3a22SFrançois Tigeot WREG32(AVIVO_D1GRPH_FLIP_CONTROL + radeon_crtc->crtc_offset, 0); 1593d78d3a22SFrançois Tigeot 1594926deccbSFrançois Tigeot if (rdev->family >= CHIP_RV770) { 1595926deccbSFrançois Tigeot if (radeon_crtc->crtc_id) { 1596926deccbSFrançois Tigeot WREG32(R700_D2GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location)); 1597926deccbSFrançois Tigeot WREG32(R700_D2GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location)); 1598926deccbSFrançois Tigeot } else { 1599926deccbSFrançois Tigeot WREG32(R700_D1GRPH_PRIMARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location)); 1600926deccbSFrançois Tigeot WREG32(R700_D1GRPH_SECONDARY_SURFACE_ADDRESS_HIGH, upper_32_bits(fb_location)); 1601926deccbSFrançois Tigeot } 1602926deccbSFrançois Tigeot } 1603926deccbSFrançois Tigeot WREG32(AVIVO_D1GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, 1604926deccbSFrançois Tigeot (u32) fb_location); 1605926deccbSFrançois Tigeot WREG32(AVIVO_D1GRPH_SECONDARY_SURFACE_ADDRESS + 1606926deccbSFrançois Tigeot radeon_crtc->crtc_offset, (u32) fb_location); 1607926deccbSFrançois Tigeot WREG32(AVIVO_D1GRPH_CONTROL + radeon_crtc->crtc_offset, fb_format); 1608926deccbSFrançois Tigeot if (rdev->family >= CHIP_R600) 1609926deccbSFrançois Tigeot WREG32(R600_D1GRPH_SWAP_CONTROL + radeon_crtc->crtc_offset, fb_swap); 1610926deccbSFrançois Tigeot 1611c6f73aabSFrançois Tigeot /* LUT only has 256 slots for 8 bpc fb. Bypass for > 8 bpc scanout for precision */ 1612c6f73aabSFrançois Tigeot WREG32_P(AVIVO_D1GRPH_LUT_SEL + radeon_crtc->crtc_offset, 1613c6f73aabSFrançois Tigeot (bypass_lut ? AVIVO_LUT_10BIT_BYPASS_EN : 0), ~AVIVO_LUT_10BIT_BYPASS_EN); 1614c6f73aabSFrançois Tigeot 1615c6f73aabSFrançois Tigeot if (bypass_lut) 1616c6f73aabSFrançois Tigeot DRM_DEBUG_KMS("Bypassing hardware LUT due to 10 bit fb scanout.\n"); 1617c6f73aabSFrançois Tigeot 1618926deccbSFrançois Tigeot WREG32(AVIVO_D1GRPH_SURFACE_OFFSET_X + radeon_crtc->crtc_offset, 0); 1619926deccbSFrançois Tigeot WREG32(AVIVO_D1GRPH_SURFACE_OFFSET_Y + radeon_crtc->crtc_offset, 0); 1620926deccbSFrançois Tigeot WREG32(AVIVO_D1GRPH_X_START + radeon_crtc->crtc_offset, 0); 1621926deccbSFrançois Tigeot WREG32(AVIVO_D1GRPH_Y_START + radeon_crtc->crtc_offset, 0); 1622926deccbSFrançois Tigeot WREG32(AVIVO_D1GRPH_X_END + radeon_crtc->crtc_offset, target_fb->width); 1623926deccbSFrançois Tigeot WREG32(AVIVO_D1GRPH_Y_END + radeon_crtc->crtc_offset, target_fb->height); 1624926deccbSFrançois Tigeot 1625*a85cb24fSFrançois Tigeot fb_pitch_pixels = target_fb->pitches[0] / target_fb->format->cpp[0]; 1626926deccbSFrançois Tigeot WREG32(AVIVO_D1GRPH_PITCH + radeon_crtc->crtc_offset, fb_pitch_pixels); 1627926deccbSFrançois Tigeot WREG32(AVIVO_D1GRPH_ENABLE + radeon_crtc->crtc_offset, 1); 1628926deccbSFrançois Tigeot 1629926deccbSFrançois Tigeot WREG32(AVIVO_D1MODE_DESKTOP_HEIGHT + radeon_crtc->crtc_offset, 1630926deccbSFrançois Tigeot target_fb->height); 1631926deccbSFrançois Tigeot x &= ~3; 1632926deccbSFrançois Tigeot y &= ~1; 1633926deccbSFrançois Tigeot WREG32(AVIVO_D1MODE_VIEWPORT_START + radeon_crtc->crtc_offset, 1634926deccbSFrançois Tigeot (x << 16) | y); 1635926deccbSFrançois Tigeot viewport_w = crtc->mode.hdisplay; 1636926deccbSFrançois Tigeot viewport_h = (crtc->mode.vdisplay + 1) & ~1; 1637926deccbSFrançois Tigeot WREG32(AVIVO_D1MODE_VIEWPORT_SIZE + radeon_crtc->crtc_offset, 1638926deccbSFrançois Tigeot (viewport_w << 16) | viewport_h); 1639926deccbSFrançois Tigeot 1640c6f73aabSFrançois Tigeot /* set pageflip to happen only at start of vblank interval (front porch) */ 1641c6f73aabSFrançois Tigeot WREG32(AVIVO_D1MODE_MASTER_UPDATE_MODE + radeon_crtc->crtc_offset, 3); 1642926deccbSFrançois Tigeot 1643ba55f2f5SFrançois Tigeot if (!atomic && fb && fb != crtc->primary->fb) { 1644926deccbSFrançois Tigeot radeon_fb = to_radeon_framebuffer(fb); 1645926deccbSFrançois Tigeot rbo = gem_to_radeon_bo(radeon_fb->obj); 1646926deccbSFrançois Tigeot r = radeon_bo_reserve(rbo, false); 1647926deccbSFrançois Tigeot if (unlikely(r != 0)) 1648926deccbSFrançois Tigeot return r; 1649926deccbSFrançois Tigeot radeon_bo_unpin(rbo); 1650926deccbSFrançois Tigeot radeon_bo_unreserve(rbo); 1651926deccbSFrançois Tigeot } 1652926deccbSFrançois Tigeot 1653926deccbSFrançois Tigeot /* Bytes per pixel may have changed */ 1654926deccbSFrançois Tigeot radeon_bandwidth_update(rdev); 1655926deccbSFrançois Tigeot 1656926deccbSFrançois Tigeot return 0; 1657926deccbSFrançois Tigeot } 1658926deccbSFrançois Tigeot 1659926deccbSFrançois Tigeot int atombios_crtc_set_base(struct drm_crtc *crtc, int x, int y, 1660926deccbSFrançois Tigeot struct drm_framebuffer *old_fb) 1661926deccbSFrançois Tigeot { 1662926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 1663926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 1664926deccbSFrançois Tigeot 1665926deccbSFrançois Tigeot if (ASIC_IS_DCE4(rdev)) 1666926deccbSFrançois Tigeot return dce4_crtc_do_set_base(crtc, old_fb, x, y, 0); 1667926deccbSFrançois Tigeot else if (ASIC_IS_AVIVO(rdev)) 1668926deccbSFrançois Tigeot return avivo_crtc_do_set_base(crtc, old_fb, x, y, 0); 1669926deccbSFrançois Tigeot else 1670926deccbSFrançois Tigeot return radeon_crtc_do_set_base(crtc, old_fb, x, y, 0); 1671926deccbSFrançois Tigeot } 1672926deccbSFrançois Tigeot 1673926deccbSFrançois Tigeot int atombios_crtc_set_base_atomic(struct drm_crtc *crtc, 1674926deccbSFrançois Tigeot struct drm_framebuffer *fb, 1675926deccbSFrançois Tigeot int x, int y, enum mode_set_atomic state) 1676926deccbSFrançois Tigeot { 1677926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 1678926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 1679926deccbSFrançois Tigeot 1680926deccbSFrançois Tigeot if (ASIC_IS_DCE4(rdev)) 1681926deccbSFrançois Tigeot return dce4_crtc_do_set_base(crtc, fb, x, y, 1); 1682926deccbSFrançois Tigeot else if (ASIC_IS_AVIVO(rdev)) 1683926deccbSFrançois Tigeot return avivo_crtc_do_set_base(crtc, fb, x, y, 1); 1684926deccbSFrançois Tigeot else 1685926deccbSFrançois Tigeot return radeon_crtc_do_set_base(crtc, fb, x, y, 1); 1686926deccbSFrançois Tigeot } 1687926deccbSFrançois Tigeot 1688926deccbSFrançois Tigeot /* properly set additional regs when using atombios */ 1689926deccbSFrançois Tigeot static void radeon_legacy_atom_fixup(struct drm_crtc *crtc) 1690926deccbSFrançois Tigeot { 1691926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 1692926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 1693926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 1694926deccbSFrançois Tigeot u32 disp_merge_cntl; 1695926deccbSFrançois Tigeot 1696926deccbSFrançois Tigeot switch (radeon_crtc->crtc_id) { 1697926deccbSFrançois Tigeot case 0: 1698926deccbSFrançois Tigeot disp_merge_cntl = RREG32(RADEON_DISP_MERGE_CNTL); 1699926deccbSFrançois Tigeot disp_merge_cntl &= ~RADEON_DISP_RGB_OFFSET_EN; 1700926deccbSFrançois Tigeot WREG32(RADEON_DISP_MERGE_CNTL, disp_merge_cntl); 1701926deccbSFrançois Tigeot break; 1702926deccbSFrançois Tigeot case 1: 1703926deccbSFrançois Tigeot disp_merge_cntl = RREG32(RADEON_DISP2_MERGE_CNTL); 1704926deccbSFrançois Tigeot disp_merge_cntl &= ~RADEON_DISP2_RGB_OFFSET_EN; 1705926deccbSFrançois Tigeot WREG32(RADEON_DISP2_MERGE_CNTL, disp_merge_cntl); 1706926deccbSFrançois Tigeot WREG32(RADEON_FP_H2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_H_SYNC_STRT_WID)); 1707926deccbSFrançois Tigeot WREG32(RADEON_FP_V2_SYNC_STRT_WID, RREG32(RADEON_CRTC2_V_SYNC_STRT_WID)); 1708926deccbSFrançois Tigeot break; 1709926deccbSFrançois Tigeot } 1710926deccbSFrançois Tigeot } 1711926deccbSFrançois Tigeot 1712926deccbSFrançois Tigeot /** 1713926deccbSFrançois Tigeot * radeon_get_pll_use_mask - look up a mask of which pplls are in use 1714926deccbSFrançois Tigeot * 1715926deccbSFrançois Tigeot * @crtc: drm crtc 1716926deccbSFrançois Tigeot * 1717926deccbSFrançois Tigeot * Returns the mask of which PPLLs (Pixel PLLs) are in use. 1718926deccbSFrançois Tigeot */ 1719926deccbSFrançois Tigeot static u32 radeon_get_pll_use_mask(struct drm_crtc *crtc) 1720926deccbSFrançois Tigeot { 1721926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 1722926deccbSFrançois Tigeot struct drm_crtc *test_crtc; 1723926deccbSFrançois Tigeot struct radeon_crtc *test_radeon_crtc; 1724926deccbSFrançois Tigeot u32 pll_in_use = 0; 1725926deccbSFrançois Tigeot 1726926deccbSFrançois Tigeot list_for_each_entry(test_crtc, &dev->mode_config.crtc_list, head) { 1727926deccbSFrançois Tigeot if (crtc == test_crtc) 1728926deccbSFrançois Tigeot continue; 1729926deccbSFrançois Tigeot 1730926deccbSFrançois Tigeot test_radeon_crtc = to_radeon_crtc(test_crtc); 1731926deccbSFrançois Tigeot if (test_radeon_crtc->pll_id != ATOM_PPLL_INVALID) 1732926deccbSFrançois Tigeot pll_in_use |= (1 << test_radeon_crtc->pll_id); 1733926deccbSFrançois Tigeot } 1734926deccbSFrançois Tigeot return pll_in_use; 1735926deccbSFrançois Tigeot } 1736926deccbSFrançois Tigeot 1737926deccbSFrançois Tigeot /** 1738926deccbSFrançois Tigeot * radeon_get_shared_dp_ppll - return the PPLL used by another crtc for DP 1739926deccbSFrançois Tigeot * 1740926deccbSFrançois Tigeot * @crtc: drm crtc 1741926deccbSFrançois Tigeot * 1742926deccbSFrançois Tigeot * Returns the PPLL (Pixel PLL) used by another crtc/encoder which is 1743926deccbSFrançois Tigeot * also in DP mode. For DP, a single PPLL can be used for all DP 1744926deccbSFrançois Tigeot * crtcs/encoders. 1745926deccbSFrançois Tigeot */ 1746926deccbSFrançois Tigeot static int radeon_get_shared_dp_ppll(struct drm_crtc *crtc) 1747926deccbSFrançois Tigeot { 1748926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 1749c59a5c48SFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 1750926deccbSFrançois Tigeot struct drm_crtc *test_crtc; 1751926deccbSFrançois Tigeot struct radeon_crtc *test_radeon_crtc; 1752926deccbSFrançois Tigeot 1753926deccbSFrançois Tigeot list_for_each_entry(test_crtc, &dev->mode_config.crtc_list, head) { 1754926deccbSFrançois Tigeot if (crtc == test_crtc) 1755926deccbSFrançois Tigeot continue; 1756926deccbSFrançois Tigeot test_radeon_crtc = to_radeon_crtc(test_crtc); 1757926deccbSFrançois Tigeot if (test_radeon_crtc->encoder && 1758926deccbSFrançois Tigeot ENCODER_MODE_IS_DP(atombios_get_encoder_mode(test_radeon_crtc->encoder))) { 1759c59a5c48SFrançois Tigeot /* PPLL2 is exclusive to UNIPHYA on DCE61 */ 1760c59a5c48SFrançois Tigeot if (ASIC_IS_DCE61(rdev) && !ASIC_IS_DCE8(rdev) && 1761c59a5c48SFrançois Tigeot test_radeon_crtc->pll_id == ATOM_PPLL2) 1762c59a5c48SFrançois Tigeot continue; 1763926deccbSFrançois Tigeot /* for DP use the same PLL for all */ 1764926deccbSFrançois Tigeot if (test_radeon_crtc->pll_id != ATOM_PPLL_INVALID) 1765926deccbSFrançois Tigeot return test_radeon_crtc->pll_id; 1766926deccbSFrançois Tigeot } 1767926deccbSFrançois Tigeot } 1768926deccbSFrançois Tigeot return ATOM_PPLL_INVALID; 1769926deccbSFrançois Tigeot } 1770926deccbSFrançois Tigeot 1771926deccbSFrançois Tigeot /** 1772926deccbSFrançois Tigeot * radeon_get_shared_nondp_ppll - return the PPLL used by another non-DP crtc 1773926deccbSFrançois Tigeot * 1774926deccbSFrançois Tigeot * @crtc: drm crtc 1775926deccbSFrançois Tigeot * @encoder: drm encoder 1776926deccbSFrançois Tigeot * 1777926deccbSFrançois Tigeot * Returns the PPLL (Pixel PLL) used by another non-DP crtc/encoder which can 1778926deccbSFrançois Tigeot * be shared (i.e., same clock). 1779926deccbSFrançois Tigeot */ 1780926deccbSFrançois Tigeot static int radeon_get_shared_nondp_ppll(struct drm_crtc *crtc) 1781926deccbSFrançois Tigeot { 1782926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 1783926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 1784c59a5c48SFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 1785926deccbSFrançois Tigeot struct drm_crtc *test_crtc; 1786926deccbSFrançois Tigeot struct radeon_crtc *test_radeon_crtc; 1787926deccbSFrançois Tigeot u32 adjusted_clock, test_adjusted_clock; 1788926deccbSFrançois Tigeot 1789926deccbSFrançois Tigeot adjusted_clock = radeon_crtc->adjusted_clock; 1790926deccbSFrançois Tigeot 1791926deccbSFrançois Tigeot if (adjusted_clock == 0) 1792926deccbSFrançois Tigeot return ATOM_PPLL_INVALID; 1793926deccbSFrançois Tigeot 1794926deccbSFrançois Tigeot list_for_each_entry(test_crtc, &dev->mode_config.crtc_list, head) { 1795926deccbSFrançois Tigeot if (crtc == test_crtc) 1796926deccbSFrançois Tigeot continue; 1797926deccbSFrançois Tigeot test_radeon_crtc = to_radeon_crtc(test_crtc); 1798926deccbSFrançois Tigeot if (test_radeon_crtc->encoder && 1799926deccbSFrançois Tigeot !ENCODER_MODE_IS_DP(atombios_get_encoder_mode(test_radeon_crtc->encoder))) { 1800c59a5c48SFrançois Tigeot /* PPLL2 is exclusive to UNIPHYA on DCE61 */ 1801c59a5c48SFrançois Tigeot if (ASIC_IS_DCE61(rdev) && !ASIC_IS_DCE8(rdev) && 1802c59a5c48SFrançois Tigeot test_radeon_crtc->pll_id == ATOM_PPLL2) 1803c59a5c48SFrançois Tigeot continue; 1804926deccbSFrançois Tigeot /* check if we are already driving this connector with another crtc */ 1805926deccbSFrançois Tigeot if (test_radeon_crtc->connector == radeon_crtc->connector) { 1806926deccbSFrançois Tigeot /* if we are, return that pll */ 1807926deccbSFrançois Tigeot if (test_radeon_crtc->pll_id != ATOM_PPLL_INVALID) 1808926deccbSFrançois Tigeot return test_radeon_crtc->pll_id; 1809926deccbSFrançois Tigeot } 1810926deccbSFrançois Tigeot /* for non-DP check the clock */ 1811926deccbSFrançois Tigeot test_adjusted_clock = test_radeon_crtc->adjusted_clock; 1812926deccbSFrançois Tigeot if ((crtc->mode.clock == test_crtc->mode.clock) && 1813926deccbSFrançois Tigeot (adjusted_clock == test_adjusted_clock) && 1814926deccbSFrançois Tigeot (radeon_crtc->ss_enabled == test_radeon_crtc->ss_enabled) && 1815926deccbSFrançois Tigeot (test_radeon_crtc->pll_id != ATOM_PPLL_INVALID)) 1816926deccbSFrançois Tigeot return test_radeon_crtc->pll_id; 1817926deccbSFrançois Tigeot } 1818926deccbSFrançois Tigeot } 1819926deccbSFrançois Tigeot return ATOM_PPLL_INVALID; 1820926deccbSFrançois Tigeot } 1821926deccbSFrançois Tigeot 1822926deccbSFrançois Tigeot /** 1823926deccbSFrançois Tigeot * radeon_atom_pick_pll - Allocate a PPLL for use by the crtc. 1824926deccbSFrançois Tigeot * 1825926deccbSFrançois Tigeot * @crtc: drm crtc 1826926deccbSFrançois Tigeot * 1827926deccbSFrançois Tigeot * Returns the PPLL (Pixel PLL) to be used by the crtc. For DP monitors 1828926deccbSFrançois Tigeot * a single PPLL can be used for all DP crtcs/encoders. For non-DP 1829926deccbSFrançois Tigeot * monitors a dedicated PPLL must be used. If a particular board has 1830926deccbSFrançois Tigeot * an external DP PLL, return ATOM_PPLL_INVALID to skip PLL programming 1831926deccbSFrançois Tigeot * as there is no need to program the PLL itself. If we are not able to 1832926deccbSFrançois Tigeot * allocate a PLL, return ATOM_PPLL_INVALID to skip PLL programming to 1833926deccbSFrançois Tigeot * avoid messing up an existing monitor. 1834926deccbSFrançois Tigeot * 1835926deccbSFrançois Tigeot * Asic specific PLL information 1836926deccbSFrançois Tigeot * 183757e252bfSMichael Neumann * DCE 8.x 183857e252bfSMichael Neumann * KB/KV 183957e252bfSMichael Neumann * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) 184057e252bfSMichael Neumann * CI 184157e252bfSMichael Neumann * - PPLL0, PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC 184257e252bfSMichael Neumann * 1843926deccbSFrançois Tigeot * DCE 6.1 1844926deccbSFrançois Tigeot * - PPLL2 is only available to UNIPHYA (both DP and non-DP) 1845926deccbSFrançois Tigeot * - PPLL0, PPLL1 are available for UNIPHYB/C/D/E/F (both DP and non-DP) 1846926deccbSFrançois Tigeot * 1847926deccbSFrançois Tigeot * DCE 6.0 1848926deccbSFrançois Tigeot * - PPLL0 is available to all UNIPHY (DP only) 1849926deccbSFrançois Tigeot * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC 1850926deccbSFrançois Tigeot * 1851926deccbSFrançois Tigeot * DCE 5.0 1852926deccbSFrançois Tigeot * - DCPLL is available to all UNIPHY (DP only) 1853926deccbSFrançois Tigeot * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC 1854926deccbSFrançois Tigeot * 1855926deccbSFrançois Tigeot * DCE 3.0/4.0/4.1 1856926deccbSFrançois Tigeot * - PPLL1, PPLL2 are available for all UNIPHY (both DP and non-DP) and DAC 1857926deccbSFrançois Tigeot * 1858926deccbSFrançois Tigeot */ 1859926deccbSFrançois Tigeot static int radeon_atom_pick_pll(struct drm_crtc *crtc) 1860926deccbSFrançois Tigeot { 1861926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 1862926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 1863926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 1864926deccbSFrançois Tigeot struct radeon_encoder *radeon_encoder = 1865926deccbSFrançois Tigeot to_radeon_encoder(radeon_crtc->encoder); 1866926deccbSFrançois Tigeot u32 pll_in_use; 1867926deccbSFrançois Tigeot int pll; 1868926deccbSFrançois Tigeot 186957e252bfSMichael Neumann if (ASIC_IS_DCE8(rdev)) { 187057e252bfSMichael Neumann if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(radeon_crtc->encoder))) { 187157e252bfSMichael Neumann if (rdev->clock.dp_extclk) 187257e252bfSMichael Neumann /* skip PPLL programming if using ext clock */ 187357e252bfSMichael Neumann return ATOM_PPLL_INVALID; 187457e252bfSMichael Neumann else { 187557e252bfSMichael Neumann /* use the same PPLL for all DP monitors */ 187657e252bfSMichael Neumann pll = radeon_get_shared_dp_ppll(crtc); 187757e252bfSMichael Neumann if (pll != ATOM_PPLL_INVALID) 187857e252bfSMichael Neumann return pll; 187957e252bfSMichael Neumann } 188057e252bfSMichael Neumann } else { 188157e252bfSMichael Neumann /* use the same PPLL for all monitors with the same clock */ 188257e252bfSMichael Neumann pll = radeon_get_shared_nondp_ppll(crtc); 188357e252bfSMichael Neumann if (pll != ATOM_PPLL_INVALID) 188457e252bfSMichael Neumann return pll; 188557e252bfSMichael Neumann } 188657e252bfSMichael Neumann /* otherwise, pick one of the plls */ 18877dcf36dcSFrançois Tigeot if ((rdev->family == CHIP_KABINI) || 1888c6f73aabSFrançois Tigeot (rdev->family == CHIP_MULLINS)) { 18897dcf36dcSFrançois Tigeot /* KB/ML has PPLL1 and PPLL2 */ 189057e252bfSMichael Neumann pll_in_use = radeon_get_pll_use_mask(crtc); 189157e252bfSMichael Neumann if (!(pll_in_use & (1 << ATOM_PPLL2))) 189257e252bfSMichael Neumann return ATOM_PPLL2; 189357e252bfSMichael Neumann if (!(pll_in_use & (1 << ATOM_PPLL1))) 189457e252bfSMichael Neumann return ATOM_PPLL1; 189557e252bfSMichael Neumann DRM_ERROR("unable to allocate a PPLL\n"); 189657e252bfSMichael Neumann return ATOM_PPLL_INVALID; 189757e252bfSMichael Neumann } else { 18987dcf36dcSFrançois Tigeot /* CI/KV has PPLL0, PPLL1, and PPLL2 */ 189957e252bfSMichael Neumann pll_in_use = radeon_get_pll_use_mask(crtc); 190057e252bfSMichael Neumann if (!(pll_in_use & (1 << ATOM_PPLL2))) 190157e252bfSMichael Neumann return ATOM_PPLL2; 190257e252bfSMichael Neumann if (!(pll_in_use & (1 << ATOM_PPLL1))) 190357e252bfSMichael Neumann return ATOM_PPLL1; 190457e252bfSMichael Neumann if (!(pll_in_use & (1 << ATOM_PPLL0))) 190557e252bfSMichael Neumann return ATOM_PPLL0; 190657e252bfSMichael Neumann DRM_ERROR("unable to allocate a PPLL\n"); 190757e252bfSMichael Neumann return ATOM_PPLL_INVALID; 190857e252bfSMichael Neumann } 190957e252bfSMichael Neumann } else if (ASIC_IS_DCE61(rdev)) { 1910926deccbSFrançois Tigeot struct radeon_encoder_atom_dig *dig = 1911926deccbSFrançois Tigeot radeon_encoder->enc_priv; 1912926deccbSFrançois Tigeot 1913926deccbSFrançois Tigeot if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_UNIPHY) && 1914926deccbSFrançois Tigeot (dig->linkb == false)) 1915926deccbSFrançois Tigeot /* UNIPHY A uses PPLL2 */ 1916926deccbSFrançois Tigeot return ATOM_PPLL2; 1917926deccbSFrançois Tigeot else if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(radeon_crtc->encoder))) { 1918926deccbSFrançois Tigeot /* UNIPHY B/C/D/E/F */ 1919926deccbSFrançois Tigeot if (rdev->clock.dp_extclk) 1920926deccbSFrançois Tigeot /* skip PPLL programming if using ext clock */ 1921926deccbSFrançois Tigeot return ATOM_PPLL_INVALID; 1922926deccbSFrançois Tigeot else { 1923926deccbSFrançois Tigeot /* use the same PPLL for all DP monitors */ 1924926deccbSFrançois Tigeot pll = radeon_get_shared_dp_ppll(crtc); 1925926deccbSFrançois Tigeot if (pll != ATOM_PPLL_INVALID) 1926926deccbSFrançois Tigeot return pll; 1927926deccbSFrançois Tigeot } 1928926deccbSFrançois Tigeot } else { 1929926deccbSFrançois Tigeot /* use the same PPLL for all monitors with the same clock */ 1930926deccbSFrançois Tigeot pll = radeon_get_shared_nondp_ppll(crtc); 1931926deccbSFrançois Tigeot if (pll != ATOM_PPLL_INVALID) 1932926deccbSFrançois Tigeot return pll; 1933926deccbSFrançois Tigeot } 1934926deccbSFrançois Tigeot /* UNIPHY B/C/D/E/F */ 1935926deccbSFrançois Tigeot pll_in_use = radeon_get_pll_use_mask(crtc); 1936926deccbSFrançois Tigeot if (!(pll_in_use & (1 << ATOM_PPLL0))) 1937926deccbSFrançois Tigeot return ATOM_PPLL0; 1938926deccbSFrançois Tigeot if (!(pll_in_use & (1 << ATOM_PPLL1))) 1939926deccbSFrançois Tigeot return ATOM_PPLL1; 1940926deccbSFrançois Tigeot DRM_ERROR("unable to allocate a PPLL\n"); 1941926deccbSFrançois Tigeot return ATOM_PPLL_INVALID; 1942c6f73aabSFrançois Tigeot } else if (ASIC_IS_DCE41(rdev)) { 1943c6f73aabSFrançois Tigeot /* Don't share PLLs on DCE4.1 chips */ 1944c6f73aabSFrançois Tigeot if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(radeon_crtc->encoder))) { 1945c6f73aabSFrançois Tigeot if (rdev->clock.dp_extclk) 1946c6f73aabSFrançois Tigeot /* skip PPLL programming if using ext clock */ 1947c6f73aabSFrançois Tigeot return ATOM_PPLL_INVALID; 1948c6f73aabSFrançois Tigeot } 1949c6f73aabSFrançois Tigeot pll_in_use = radeon_get_pll_use_mask(crtc); 1950c6f73aabSFrançois Tigeot if (!(pll_in_use & (1 << ATOM_PPLL1))) 1951c6f73aabSFrançois Tigeot return ATOM_PPLL1; 1952c6f73aabSFrançois Tigeot if (!(pll_in_use & (1 << ATOM_PPLL2))) 1953c6f73aabSFrançois Tigeot return ATOM_PPLL2; 1954c6f73aabSFrançois Tigeot DRM_ERROR("unable to allocate a PPLL\n"); 1955c6f73aabSFrançois Tigeot return ATOM_PPLL_INVALID; 1956926deccbSFrançois Tigeot } else if (ASIC_IS_DCE4(rdev)) { 1957926deccbSFrançois Tigeot /* in DP mode, the DP ref clock can come from PPLL, DCPLL, or ext clock, 1958926deccbSFrançois Tigeot * depending on the asic: 1959926deccbSFrançois Tigeot * DCE4: PPLL or ext clock 1960926deccbSFrançois Tigeot * DCE5: PPLL, DCPLL, or ext clock 1961926deccbSFrançois Tigeot * DCE6: PPLL, PPLL0, or ext clock 1962926deccbSFrançois Tigeot * 1963926deccbSFrançois Tigeot * Setting ATOM_PPLL_INVALID will cause SetPixelClock to skip 1964926deccbSFrançois Tigeot * PPLL/DCPLL programming and only program the DP DTO for the 1965926deccbSFrançois Tigeot * crtc virtual pixel clock. 1966926deccbSFrançois Tigeot */ 1967926deccbSFrançois Tigeot if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(radeon_crtc->encoder))) { 1968926deccbSFrançois Tigeot if (rdev->clock.dp_extclk) 1969926deccbSFrançois Tigeot /* skip PPLL programming if using ext clock */ 1970926deccbSFrançois Tigeot return ATOM_PPLL_INVALID; 1971926deccbSFrançois Tigeot else if (ASIC_IS_DCE6(rdev)) 1972926deccbSFrançois Tigeot /* use PPLL0 for all DP */ 1973926deccbSFrançois Tigeot return ATOM_PPLL0; 1974926deccbSFrançois Tigeot else if (ASIC_IS_DCE5(rdev)) 1975926deccbSFrançois Tigeot /* use DCPLL for all DP */ 1976926deccbSFrançois Tigeot return ATOM_DCPLL; 1977926deccbSFrançois Tigeot else { 1978926deccbSFrançois Tigeot /* use the same PPLL for all DP monitors */ 1979926deccbSFrançois Tigeot pll = radeon_get_shared_dp_ppll(crtc); 1980926deccbSFrançois Tigeot if (pll != ATOM_PPLL_INVALID) 1981926deccbSFrançois Tigeot return pll; 1982926deccbSFrançois Tigeot } 1983926deccbSFrançois Tigeot } else { 1984926deccbSFrançois Tigeot /* use the same PPLL for all monitors with the same clock */ 1985926deccbSFrançois Tigeot pll = radeon_get_shared_nondp_ppll(crtc); 1986926deccbSFrançois Tigeot if (pll != ATOM_PPLL_INVALID) 1987926deccbSFrançois Tigeot return pll; 1988926deccbSFrançois Tigeot } 1989926deccbSFrançois Tigeot /* all other cases */ 1990926deccbSFrançois Tigeot pll_in_use = radeon_get_pll_use_mask(crtc); 1991926deccbSFrançois Tigeot if (!(pll_in_use & (1 << ATOM_PPLL1))) 1992926deccbSFrançois Tigeot return ATOM_PPLL1; 1993926deccbSFrançois Tigeot if (!(pll_in_use & (1 << ATOM_PPLL2))) 1994926deccbSFrançois Tigeot return ATOM_PPLL2; 1995926deccbSFrançois Tigeot DRM_ERROR("unable to allocate a PPLL\n"); 1996926deccbSFrançois Tigeot return ATOM_PPLL_INVALID; 1997926deccbSFrançois Tigeot } else { 1998926deccbSFrançois Tigeot /* on pre-R5xx asics, the crtc to pll mapping is hardcoded */ 1999926deccbSFrançois Tigeot /* some atombios (observed in some DCE2/DCE3) code have a bug, 2000926deccbSFrançois Tigeot * the matching btw pll and crtc is done through 2001926deccbSFrançois Tigeot * PCLK_CRTC[1|2]_CNTL (0x480/0x484) but atombios code use the 2002926deccbSFrançois Tigeot * pll (1 or 2) to select which register to write. ie if using 2003926deccbSFrançois Tigeot * pll1 it will use PCLK_CRTC1_CNTL (0x480) and if using pll2 2004926deccbSFrançois Tigeot * it will use PCLK_CRTC2_CNTL (0x484), it then use crtc id to 2005926deccbSFrançois Tigeot * choose which value to write. Which is reverse order from 2006926deccbSFrançois Tigeot * register logic. So only case that works is when pllid is 2007926deccbSFrançois Tigeot * same as crtcid or when both pll and crtc are enabled and 2008926deccbSFrançois Tigeot * both use same clock. 2009926deccbSFrançois Tigeot * 2010926deccbSFrançois Tigeot * So just return crtc id as if crtc and pll were hard linked 2011926deccbSFrançois Tigeot * together even if they aren't 2012926deccbSFrançois Tigeot */ 2013926deccbSFrançois Tigeot return radeon_crtc->crtc_id; 2014926deccbSFrançois Tigeot } 2015926deccbSFrançois Tigeot } 2016926deccbSFrançois Tigeot 2017926deccbSFrançois Tigeot void radeon_atom_disp_eng_pll_init(struct radeon_device *rdev) 2018926deccbSFrançois Tigeot { 2019926deccbSFrançois Tigeot /* always set DCPLL */ 2020926deccbSFrançois Tigeot if (ASIC_IS_DCE6(rdev)) 2021926deccbSFrançois Tigeot atombios_crtc_set_disp_eng_pll(rdev, rdev->clock.default_dispclk); 2022926deccbSFrançois Tigeot else if (ASIC_IS_DCE4(rdev)) { 2023926deccbSFrançois Tigeot struct radeon_atom_ss ss; 2024926deccbSFrançois Tigeot bool ss_enabled = radeon_atombios_get_asic_ss_info(rdev, &ss, 2025926deccbSFrançois Tigeot ASIC_INTERNAL_SS_ON_DCPLL, 2026926deccbSFrançois Tigeot rdev->clock.default_dispclk); 2027926deccbSFrançois Tigeot if (ss_enabled) 2028926deccbSFrançois Tigeot atombios_crtc_program_ss(rdev, ATOM_DISABLE, ATOM_DCPLL, -1, &ss); 2029926deccbSFrançois Tigeot /* XXX: DCE5, make sure voltage, dispclk is high enough */ 2030926deccbSFrançois Tigeot atombios_crtc_set_disp_eng_pll(rdev, rdev->clock.default_dispclk); 2031926deccbSFrançois Tigeot if (ss_enabled) 2032926deccbSFrançois Tigeot atombios_crtc_program_ss(rdev, ATOM_ENABLE, ATOM_DCPLL, -1, &ss); 2033926deccbSFrançois Tigeot } 2034926deccbSFrançois Tigeot 2035926deccbSFrançois Tigeot } 2036926deccbSFrançois Tigeot 2037926deccbSFrançois Tigeot int atombios_crtc_mode_set(struct drm_crtc *crtc, 2038926deccbSFrançois Tigeot struct drm_display_mode *mode, 2039926deccbSFrançois Tigeot struct drm_display_mode *adjusted_mode, 2040926deccbSFrançois Tigeot int x, int y, struct drm_framebuffer *old_fb) 2041926deccbSFrançois Tigeot { 2042926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 2043926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 2044926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 2045926deccbSFrançois Tigeot struct radeon_encoder *radeon_encoder = 2046926deccbSFrançois Tigeot to_radeon_encoder(radeon_crtc->encoder); 2047926deccbSFrançois Tigeot bool is_tvcv = false; 2048926deccbSFrançois Tigeot 2049926deccbSFrançois Tigeot if (radeon_encoder->active_device & 2050926deccbSFrançois Tigeot (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) 2051926deccbSFrançois Tigeot is_tvcv = true; 2052926deccbSFrançois Tigeot 2053c6f73aabSFrançois Tigeot if (!radeon_crtc->adjusted_clock) 2054c6f73aabSFrançois Tigeot return -EINVAL; 2055c6f73aabSFrançois Tigeot 2056926deccbSFrançois Tigeot atombios_crtc_set_pll(crtc, adjusted_mode); 2057926deccbSFrançois Tigeot 2058926deccbSFrançois Tigeot if (ASIC_IS_DCE4(rdev)) 2059926deccbSFrançois Tigeot atombios_set_crtc_dtd_timing(crtc, adjusted_mode); 2060926deccbSFrançois Tigeot else if (ASIC_IS_AVIVO(rdev)) { 2061926deccbSFrançois Tigeot if (is_tvcv) 2062926deccbSFrançois Tigeot atombios_crtc_set_timing(crtc, adjusted_mode); 2063926deccbSFrançois Tigeot else 2064926deccbSFrançois Tigeot atombios_set_crtc_dtd_timing(crtc, adjusted_mode); 2065926deccbSFrançois Tigeot } else { 2066926deccbSFrançois Tigeot atombios_crtc_set_timing(crtc, adjusted_mode); 2067926deccbSFrançois Tigeot if (radeon_crtc->crtc_id == 0) 2068926deccbSFrançois Tigeot atombios_set_crtc_dtd_timing(crtc, adjusted_mode); 2069926deccbSFrançois Tigeot radeon_legacy_atom_fixup(crtc); 2070926deccbSFrançois Tigeot } 2071926deccbSFrançois Tigeot atombios_crtc_set_base(crtc, x, y, old_fb); 2072926deccbSFrançois Tigeot atombios_overscan_setup(crtc, mode, adjusted_mode); 2073926deccbSFrançois Tigeot atombios_scaler_setup(crtc); 20747dcf36dcSFrançois Tigeot radeon_cursor_reset(crtc); 207557e252bfSMichael Neumann /* update the hw version fpr dpm */ 207657e252bfSMichael Neumann radeon_crtc->hw_mode = *adjusted_mode; 207757e252bfSMichael Neumann 2078926deccbSFrançois Tigeot return 0; 2079926deccbSFrançois Tigeot } 2080926deccbSFrançois Tigeot 2081926deccbSFrançois Tigeot static bool atombios_crtc_mode_fixup(struct drm_crtc *crtc, 2082926deccbSFrançois Tigeot const struct drm_display_mode *mode, 2083926deccbSFrançois Tigeot struct drm_display_mode *adjusted_mode) 2084926deccbSFrançois Tigeot { 2085926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 2086926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 2087926deccbSFrançois Tigeot struct drm_encoder *encoder; 2088926deccbSFrançois Tigeot 2089926deccbSFrançois Tigeot /* assign the encoder to the radeon crtc to avoid repeated lookups later */ 2090926deccbSFrançois Tigeot list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 2091926deccbSFrançois Tigeot if (encoder->crtc == crtc) { 2092926deccbSFrançois Tigeot radeon_crtc->encoder = encoder; 2093926deccbSFrançois Tigeot radeon_crtc->connector = radeon_get_connector_for_encoder(encoder); 2094926deccbSFrançois Tigeot break; 2095926deccbSFrançois Tigeot } 2096926deccbSFrançois Tigeot } 2097926deccbSFrançois Tigeot if ((radeon_crtc->encoder == NULL) || (radeon_crtc->connector == NULL)) { 2098926deccbSFrançois Tigeot radeon_crtc->encoder = NULL; 2099926deccbSFrançois Tigeot radeon_crtc->connector = NULL; 2100926deccbSFrançois Tigeot return false; 2101926deccbSFrançois Tigeot } 2102c59a5c48SFrançois Tigeot if (radeon_crtc->encoder) { 2103c59a5c48SFrançois Tigeot struct radeon_encoder *radeon_encoder = 2104c59a5c48SFrançois Tigeot to_radeon_encoder(radeon_crtc->encoder); 2105c59a5c48SFrançois Tigeot 2106c59a5c48SFrançois Tigeot radeon_crtc->output_csc = radeon_encoder->output_csc; 2107c59a5c48SFrançois Tigeot } 2108926deccbSFrançois Tigeot if (!radeon_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode)) 2109926deccbSFrançois Tigeot return false; 2110926deccbSFrançois Tigeot if (!atombios_crtc_prepare_pll(crtc, adjusted_mode)) 2111926deccbSFrançois Tigeot return false; 2112926deccbSFrançois Tigeot /* pick pll */ 2113926deccbSFrançois Tigeot radeon_crtc->pll_id = radeon_atom_pick_pll(crtc); 2114926deccbSFrançois Tigeot /* if we can't get a PPLL for a non-DP encoder, fail */ 2115926deccbSFrançois Tigeot if ((radeon_crtc->pll_id == ATOM_PPLL_INVALID) && 2116926deccbSFrançois Tigeot !ENCODER_MODE_IS_DP(atombios_get_encoder_mode(radeon_crtc->encoder))) 2117926deccbSFrançois Tigeot return false; 2118926deccbSFrançois Tigeot 2119926deccbSFrançois Tigeot return true; 2120926deccbSFrançois Tigeot } 2121926deccbSFrançois Tigeot 2122926deccbSFrançois Tigeot static void atombios_crtc_prepare(struct drm_crtc *crtc) 2123926deccbSFrançois Tigeot { 2124926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 2125926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 2126926deccbSFrançois Tigeot 2127926deccbSFrançois Tigeot /* disable crtc pair power gating before programming */ 2128926deccbSFrançois Tigeot if (ASIC_IS_DCE6(rdev)) 2129926deccbSFrançois Tigeot atombios_powergate_crtc(crtc, ATOM_DISABLE); 2130926deccbSFrançois Tigeot 2131926deccbSFrançois Tigeot atombios_lock_crtc(crtc, ATOM_ENABLE); 2132926deccbSFrançois Tigeot atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); 2133926deccbSFrançois Tigeot } 2134926deccbSFrançois Tigeot 2135926deccbSFrançois Tigeot static void atombios_crtc_commit(struct drm_crtc *crtc) 2136926deccbSFrançois Tigeot { 2137926deccbSFrançois Tigeot atombios_crtc_dpms(crtc, DRM_MODE_DPMS_ON); 2138926deccbSFrançois Tigeot atombios_lock_crtc(crtc, ATOM_DISABLE); 2139926deccbSFrançois Tigeot } 2140926deccbSFrançois Tigeot 2141926deccbSFrançois Tigeot static void atombios_crtc_disable(struct drm_crtc *crtc) 2142926deccbSFrançois Tigeot { 2143926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 2144926deccbSFrançois Tigeot struct drm_device *dev = crtc->dev; 2145926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 2146926deccbSFrançois Tigeot struct radeon_atom_ss ss; 2147926deccbSFrançois Tigeot int i; 2148926deccbSFrançois Tigeot 2149926deccbSFrançois Tigeot atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); 2150c6f73aabSFrançois Tigeot if (crtc->primary->fb) { 2151c6f73aabSFrançois Tigeot int r; 2152c6f73aabSFrançois Tigeot struct radeon_framebuffer *radeon_fb; 2153c6f73aabSFrançois Tigeot struct radeon_bo *rbo; 2154c6f73aabSFrançois Tigeot 2155c6f73aabSFrançois Tigeot radeon_fb = to_radeon_framebuffer(crtc->primary->fb); 2156c6f73aabSFrançois Tigeot rbo = gem_to_radeon_bo(radeon_fb->obj); 2157c6f73aabSFrançois Tigeot r = radeon_bo_reserve(rbo, false); 2158c6f73aabSFrançois Tigeot if (unlikely(r)) 2159c6f73aabSFrançois Tigeot DRM_ERROR("failed to reserve rbo before unpin\n"); 2160c6f73aabSFrançois Tigeot else { 2161c6f73aabSFrançois Tigeot radeon_bo_unpin(rbo); 2162c6f73aabSFrançois Tigeot radeon_bo_unreserve(rbo); 2163c6f73aabSFrançois Tigeot } 2164c6f73aabSFrançois Tigeot } 21654cd92098Szrj /* disable the GRPH */ 21664cd92098Szrj if (ASIC_IS_DCE4(rdev)) 21674cd92098Szrj WREG32(EVERGREEN_GRPH_ENABLE + radeon_crtc->crtc_offset, 0); 21684cd92098Szrj else if (ASIC_IS_AVIVO(rdev)) 21694cd92098Szrj WREG32(AVIVO_D1GRPH_ENABLE + radeon_crtc->crtc_offset, 0); 21704cd92098Szrj 2171b403bed8SMichael Neumann if (ASIC_IS_DCE6(rdev)) 2172b403bed8SMichael Neumann atombios_powergate_crtc(crtc, ATOM_ENABLE); 2173926deccbSFrançois Tigeot 2174926deccbSFrançois Tigeot for (i = 0; i < rdev->num_crtc; i++) { 2175926deccbSFrançois Tigeot if (rdev->mode_info.crtcs[i] && 2176926deccbSFrançois Tigeot rdev->mode_info.crtcs[i]->enabled && 2177926deccbSFrançois Tigeot i != radeon_crtc->crtc_id && 2178926deccbSFrançois Tigeot radeon_crtc->pll_id == rdev->mode_info.crtcs[i]->pll_id) { 2179926deccbSFrançois Tigeot /* one other crtc is using this pll don't turn 2180926deccbSFrançois Tigeot * off the pll 2181926deccbSFrançois Tigeot */ 2182926deccbSFrançois Tigeot goto done; 2183926deccbSFrançois Tigeot } 2184926deccbSFrançois Tigeot } 2185926deccbSFrançois Tigeot 2186926deccbSFrançois Tigeot switch (radeon_crtc->pll_id) { 2187926deccbSFrançois Tigeot case ATOM_PPLL1: 2188926deccbSFrançois Tigeot case ATOM_PPLL2: 2189926deccbSFrançois Tigeot /* disable the ppll */ 2190926deccbSFrançois Tigeot atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id, 2191926deccbSFrançois Tigeot 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss); 2192926deccbSFrançois Tigeot break; 2193926deccbSFrançois Tigeot case ATOM_PPLL0: 2194926deccbSFrançois Tigeot /* disable the ppll */ 2195c6f73aabSFrançois Tigeot if ((rdev->family == CHIP_ARUBA) || 21967dcf36dcSFrançois Tigeot (rdev->family == CHIP_KAVERI) || 2197c6f73aabSFrançois Tigeot (rdev->family == CHIP_BONAIRE) || 2198c6f73aabSFrançois Tigeot (rdev->family == CHIP_HAWAII)) 2199926deccbSFrançois Tigeot atombios_crtc_program_pll(crtc, radeon_crtc->crtc_id, radeon_crtc->pll_id, 2200926deccbSFrançois Tigeot 0, 0, ATOM_DISABLE, 0, 0, 0, 0, 0, false, &ss); 2201926deccbSFrançois Tigeot break; 2202926deccbSFrançois Tigeot default: 2203926deccbSFrançois Tigeot break; 2204926deccbSFrançois Tigeot } 2205926deccbSFrançois Tigeot done: 2206926deccbSFrançois Tigeot radeon_crtc->pll_id = ATOM_PPLL_INVALID; 2207926deccbSFrançois Tigeot radeon_crtc->adjusted_clock = 0; 2208926deccbSFrançois Tigeot radeon_crtc->encoder = NULL; 2209926deccbSFrançois Tigeot radeon_crtc->connector = NULL; 2210926deccbSFrançois Tigeot } 2211926deccbSFrançois Tigeot 2212926deccbSFrançois Tigeot static const struct drm_crtc_helper_funcs atombios_helper_funcs = { 2213926deccbSFrançois Tigeot .dpms = atombios_crtc_dpms, 2214926deccbSFrançois Tigeot .mode_fixup = atombios_crtc_mode_fixup, 2215926deccbSFrançois Tigeot .mode_set = atombios_crtc_mode_set, 2216926deccbSFrançois Tigeot .mode_set_base = atombios_crtc_set_base, 2217926deccbSFrançois Tigeot .mode_set_base_atomic = atombios_crtc_set_base_atomic, 2218926deccbSFrançois Tigeot .prepare = atombios_crtc_prepare, 2219926deccbSFrançois Tigeot .commit = atombios_crtc_commit, 2220926deccbSFrançois Tigeot .load_lut = radeon_crtc_load_lut, 2221926deccbSFrançois Tigeot .disable = atombios_crtc_disable, 2222926deccbSFrançois Tigeot }; 2223926deccbSFrançois Tigeot 2224926deccbSFrançois Tigeot void radeon_atombios_init_crtc(struct drm_device *dev, 2225926deccbSFrançois Tigeot struct radeon_crtc *radeon_crtc) 2226926deccbSFrançois Tigeot { 2227926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 2228926deccbSFrançois Tigeot 2229926deccbSFrançois Tigeot if (ASIC_IS_DCE4(rdev)) { 2230926deccbSFrançois Tigeot switch (radeon_crtc->crtc_id) { 2231926deccbSFrançois Tigeot case 0: 2232926deccbSFrançois Tigeot default: 2233926deccbSFrançois Tigeot radeon_crtc->crtc_offset = EVERGREEN_CRTC0_REGISTER_OFFSET; 2234926deccbSFrançois Tigeot break; 2235926deccbSFrançois Tigeot case 1: 2236926deccbSFrançois Tigeot radeon_crtc->crtc_offset = EVERGREEN_CRTC1_REGISTER_OFFSET; 2237926deccbSFrançois Tigeot break; 2238926deccbSFrançois Tigeot case 2: 2239926deccbSFrançois Tigeot radeon_crtc->crtc_offset = EVERGREEN_CRTC2_REGISTER_OFFSET; 2240926deccbSFrançois Tigeot break; 2241926deccbSFrançois Tigeot case 3: 2242926deccbSFrançois Tigeot radeon_crtc->crtc_offset = EVERGREEN_CRTC3_REGISTER_OFFSET; 2243926deccbSFrançois Tigeot break; 2244926deccbSFrançois Tigeot case 4: 2245926deccbSFrançois Tigeot radeon_crtc->crtc_offset = EVERGREEN_CRTC4_REGISTER_OFFSET; 2246926deccbSFrançois Tigeot break; 2247926deccbSFrançois Tigeot case 5: 2248926deccbSFrançois Tigeot radeon_crtc->crtc_offset = EVERGREEN_CRTC5_REGISTER_OFFSET; 2249926deccbSFrançois Tigeot break; 2250926deccbSFrançois Tigeot } 2251926deccbSFrançois Tigeot } else { 2252926deccbSFrançois Tigeot if (radeon_crtc->crtc_id == 1) 2253926deccbSFrançois Tigeot radeon_crtc->crtc_offset = 2254926deccbSFrançois Tigeot AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL; 2255926deccbSFrançois Tigeot else 2256926deccbSFrançois Tigeot radeon_crtc->crtc_offset = 0; 2257926deccbSFrançois Tigeot } 2258926deccbSFrançois Tigeot radeon_crtc->pll_id = ATOM_PPLL_INVALID; 2259926deccbSFrançois Tigeot radeon_crtc->adjusted_clock = 0; 2260926deccbSFrançois Tigeot radeon_crtc->encoder = NULL; 2261926deccbSFrançois Tigeot radeon_crtc->connector = NULL; 2262926deccbSFrançois Tigeot drm_crtc_helper_add(&radeon_crtc->base, &atombios_helper_funcs); 2263926deccbSFrançois Tigeot } 2264