1 1.3 riastrad /* $NetBSD: radeon_legacy_encoders.c,v 1.4 2021/12/18 23:45:43 riastradh Exp $ */ 2 1.3 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2007-8 Advanced Micro Devices, Inc. 5 1.1 riastrad * Copyright 2008 Red Hat Inc. 6 1.1 riastrad * 7 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 8 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 9 1.1 riastrad * to deal in the Software without restriction, including without limitation 10 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 12 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 13 1.1 riastrad * 14 1.1 riastrad * The above copyright notice and this permission notice shall be included in 15 1.1 riastrad * all copies or substantial portions of the Software. 16 1.1 riastrad * 17 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 1.1 riastrad * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 24 1.1 riastrad * 25 1.1 riastrad * Authors: Dave Airlie 26 1.1 riastrad * Alex Deucher 27 1.1 riastrad */ 28 1.4 riastrad 29 1.3 riastrad #include <sys/cdefs.h> 30 1.3 riastrad __KERNEL_RCSID(0, "$NetBSD: radeon_legacy_encoders.c,v 1.4 2021/12/18 23:45:43 riastradh Exp $"); 31 1.3 riastrad 32 1.4 riastrad #include <linux/backlight.h> 33 1.4 riastrad #include <linux/pci.h> 34 1.4 riastrad 35 1.1 riastrad #include <drm/drm_crtc_helper.h> 36 1.4 riastrad #include <drm/drm_device.h> 37 1.4 riastrad #include <drm/drm_file.h> 38 1.4 riastrad #include <drm/drm_util.h> 39 1.1 riastrad #include <drm/radeon_drm.h> 40 1.4 riastrad 41 1.1 riastrad #include "radeon.h" 42 1.4 riastrad #include "radeon_asic.h" 43 1.1 riastrad #include "atom.h" 44 1.1 riastrad #ifdef CONFIG_PMAC_BACKLIGHT 45 1.1 riastrad #include <asm/backlight.h> 46 1.1 riastrad #endif 47 1.1 riastrad 48 1.1 riastrad static void radeon_legacy_encoder_disable(struct drm_encoder *encoder) 49 1.1 riastrad { 50 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 51 1.3 riastrad const struct drm_encoder_helper_funcs *encoder_funcs; 52 1.1 riastrad 53 1.1 riastrad encoder_funcs = encoder->helper_private; 54 1.1 riastrad encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF); 55 1.1 riastrad radeon_encoder->active_device = 0; 56 1.1 riastrad } 57 1.1 riastrad 58 1.1 riastrad static void radeon_legacy_lvds_update(struct drm_encoder *encoder, int mode) 59 1.1 riastrad { 60 1.1 riastrad struct drm_device *dev = encoder->dev; 61 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 62 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 63 1.1 riastrad uint32_t lvds_gen_cntl, lvds_pll_cntl, pixclks_cntl, disp_pwr_man; 64 1.1 riastrad int panel_pwr_delay = 2000; 65 1.1 riastrad bool is_mac = false; 66 1.1 riastrad uint8_t backlight_level; 67 1.1 riastrad DRM_DEBUG_KMS("\n"); 68 1.1 riastrad 69 1.1 riastrad lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL); 70 1.1 riastrad backlight_level = (lvds_gen_cntl >> RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff; 71 1.1 riastrad 72 1.1 riastrad if (radeon_encoder->enc_priv) { 73 1.1 riastrad if (rdev->is_atom_bios) { 74 1.1 riastrad struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv; 75 1.1 riastrad panel_pwr_delay = lvds->panel_pwr_delay; 76 1.1 riastrad if (lvds->bl_dev) 77 1.1 riastrad backlight_level = lvds->backlight_level; 78 1.1 riastrad } else { 79 1.1 riastrad struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv; 80 1.1 riastrad panel_pwr_delay = lvds->panel_pwr_delay; 81 1.1 riastrad if (lvds->bl_dev) 82 1.1 riastrad backlight_level = lvds->backlight_level; 83 1.1 riastrad } 84 1.1 riastrad } 85 1.1 riastrad 86 1.1 riastrad /* macs (and possibly some x86 oem systems?) wire up LVDS strangely 87 1.1 riastrad * Taken from radeonfb. 88 1.1 riastrad */ 89 1.1 riastrad if ((rdev->mode_info.connector_table == CT_IBOOK) || 90 1.1 riastrad (rdev->mode_info.connector_table == CT_POWERBOOK_EXTERNAL) || 91 1.1 riastrad (rdev->mode_info.connector_table == CT_POWERBOOK_INTERNAL) || 92 1.1 riastrad (rdev->mode_info.connector_table == CT_POWERBOOK_VGA)) 93 1.1 riastrad is_mac = true; 94 1.1 riastrad 95 1.1 riastrad switch (mode) { 96 1.1 riastrad case DRM_MODE_DPMS_ON: 97 1.1 riastrad disp_pwr_man = RREG32(RADEON_DISP_PWR_MAN); 98 1.1 riastrad disp_pwr_man |= RADEON_AUTO_PWRUP_EN; 99 1.1 riastrad WREG32(RADEON_DISP_PWR_MAN, disp_pwr_man); 100 1.1 riastrad lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL); 101 1.1 riastrad lvds_pll_cntl |= RADEON_LVDS_PLL_EN; 102 1.1 riastrad WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl); 103 1.1 riastrad mdelay(1); 104 1.1 riastrad 105 1.1 riastrad lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL); 106 1.1 riastrad lvds_pll_cntl &= ~RADEON_LVDS_PLL_RESET; 107 1.1 riastrad WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl); 108 1.1 riastrad 109 1.1 riastrad lvds_gen_cntl &= ~(RADEON_LVDS_DISPLAY_DIS | 110 1.1 riastrad RADEON_LVDS_BL_MOD_LEVEL_MASK); 111 1.1 riastrad lvds_gen_cntl |= (RADEON_LVDS_ON | RADEON_LVDS_EN | 112 1.1 riastrad RADEON_LVDS_DIGON | RADEON_LVDS_BLON | 113 1.1 riastrad (backlight_level << RADEON_LVDS_BL_MOD_LEVEL_SHIFT)); 114 1.1 riastrad if (is_mac) 115 1.1 riastrad lvds_gen_cntl |= RADEON_LVDS_BL_MOD_EN; 116 1.1 riastrad mdelay(panel_pwr_delay); 117 1.1 riastrad WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl); 118 1.1 riastrad break; 119 1.1 riastrad case DRM_MODE_DPMS_STANDBY: 120 1.1 riastrad case DRM_MODE_DPMS_SUSPEND: 121 1.1 riastrad case DRM_MODE_DPMS_OFF: 122 1.1 riastrad pixclks_cntl = RREG32_PLL(RADEON_PIXCLKS_CNTL); 123 1.1 riastrad WREG32_PLL_P(RADEON_PIXCLKS_CNTL, 0, ~RADEON_PIXCLK_LVDS_ALWAYS_ONb); 124 1.1 riastrad lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS; 125 1.1 riastrad if (is_mac) { 126 1.1 riastrad lvds_gen_cntl &= ~RADEON_LVDS_BL_MOD_EN; 127 1.1 riastrad WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl); 128 1.1 riastrad lvds_gen_cntl &= ~(RADEON_LVDS_ON | RADEON_LVDS_EN); 129 1.1 riastrad } else { 130 1.1 riastrad WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl); 131 1.1 riastrad lvds_gen_cntl &= ~(RADEON_LVDS_ON | RADEON_LVDS_BLON | RADEON_LVDS_EN | RADEON_LVDS_DIGON); 132 1.1 riastrad } 133 1.1 riastrad mdelay(panel_pwr_delay); 134 1.1 riastrad WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl); 135 1.1 riastrad WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl); 136 1.1 riastrad mdelay(panel_pwr_delay); 137 1.1 riastrad break; 138 1.1 riastrad } 139 1.1 riastrad 140 1.1 riastrad if (rdev->is_atom_bios) 141 1.1 riastrad radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 142 1.1 riastrad else 143 1.1 riastrad radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 144 1.1 riastrad 145 1.1 riastrad } 146 1.1 riastrad 147 1.1 riastrad static void radeon_legacy_lvds_dpms(struct drm_encoder *encoder, int mode) 148 1.1 riastrad { 149 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 150 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 151 1.1 riastrad DRM_DEBUG("\n"); 152 1.1 riastrad 153 1.1 riastrad if (radeon_encoder->enc_priv) { 154 1.1 riastrad if (rdev->is_atom_bios) { 155 1.1 riastrad struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv; 156 1.1 riastrad lvds->dpms_mode = mode; 157 1.1 riastrad } else { 158 1.1 riastrad struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv; 159 1.1 riastrad lvds->dpms_mode = mode; 160 1.1 riastrad } 161 1.1 riastrad } 162 1.1 riastrad 163 1.1 riastrad radeon_legacy_lvds_update(encoder, mode); 164 1.1 riastrad } 165 1.1 riastrad 166 1.1 riastrad static void radeon_legacy_lvds_prepare(struct drm_encoder *encoder) 167 1.1 riastrad { 168 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 169 1.1 riastrad 170 1.1 riastrad if (rdev->is_atom_bios) 171 1.1 riastrad radeon_atom_output_lock(encoder, true); 172 1.1 riastrad else 173 1.1 riastrad radeon_combios_output_lock(encoder, true); 174 1.1 riastrad radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_OFF); 175 1.1 riastrad } 176 1.1 riastrad 177 1.1 riastrad static void radeon_legacy_lvds_commit(struct drm_encoder *encoder) 178 1.1 riastrad { 179 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 180 1.1 riastrad 181 1.1 riastrad radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_ON); 182 1.1 riastrad if (rdev->is_atom_bios) 183 1.1 riastrad radeon_atom_output_lock(encoder, false); 184 1.1 riastrad else 185 1.1 riastrad radeon_combios_output_lock(encoder, false); 186 1.1 riastrad } 187 1.1 riastrad 188 1.1 riastrad static void radeon_legacy_lvds_mode_set(struct drm_encoder *encoder, 189 1.1 riastrad struct drm_display_mode *mode, 190 1.1 riastrad struct drm_display_mode *adjusted_mode) 191 1.1 riastrad { 192 1.1 riastrad struct drm_device *dev = encoder->dev; 193 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 194 1.1 riastrad struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 195 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 196 1.1 riastrad uint32_t lvds_pll_cntl, lvds_gen_cntl, lvds_ss_gen_cntl; 197 1.1 riastrad 198 1.1 riastrad DRM_DEBUG_KMS("\n"); 199 1.1 riastrad 200 1.1 riastrad lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL); 201 1.1 riastrad lvds_pll_cntl &= ~RADEON_LVDS_PLL_EN; 202 1.1 riastrad 203 1.1 riastrad lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL); 204 1.1 riastrad if (rdev->is_atom_bios) { 205 1.1 riastrad /* LVDS_GEN_CNTL parameters are computed in LVDSEncoderControl 206 1.1 riastrad * need to call that on resume to set up the reg properly. 207 1.1 riastrad */ 208 1.1 riastrad radeon_encoder->pixel_clock = adjusted_mode->clock; 209 1.1 riastrad atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_ENABLE); 210 1.1 riastrad lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL); 211 1.1 riastrad } else { 212 1.1 riastrad struct radeon_encoder_lvds *lvds = (struct radeon_encoder_lvds *)radeon_encoder->enc_priv; 213 1.1 riastrad if (lvds) { 214 1.1 riastrad DRM_DEBUG_KMS("bios LVDS_GEN_CNTL: 0x%x\n", lvds->lvds_gen_cntl); 215 1.1 riastrad lvds_gen_cntl = lvds->lvds_gen_cntl; 216 1.1 riastrad lvds_ss_gen_cntl &= ~((0xf << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) | 217 1.1 riastrad (0xf << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT)); 218 1.1 riastrad lvds_ss_gen_cntl |= ((lvds->panel_digon_delay << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) | 219 1.1 riastrad (lvds->panel_blon_delay << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT)); 220 1.1 riastrad } else 221 1.1 riastrad lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL); 222 1.1 riastrad } 223 1.1 riastrad lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS; 224 1.1 riastrad lvds_gen_cntl &= ~(RADEON_LVDS_ON | 225 1.1 riastrad RADEON_LVDS_BLON | 226 1.1 riastrad RADEON_LVDS_EN | 227 1.1 riastrad RADEON_LVDS_RST_FM); 228 1.1 riastrad 229 1.1 riastrad if (ASIC_IS_R300(rdev)) 230 1.1 riastrad lvds_pll_cntl &= ~(R300_LVDS_SRC_SEL_MASK); 231 1.1 riastrad 232 1.1 riastrad if (radeon_crtc->crtc_id == 0) { 233 1.1 riastrad if (ASIC_IS_R300(rdev)) { 234 1.1 riastrad if (radeon_encoder->rmx_type != RMX_OFF) 235 1.1 riastrad lvds_pll_cntl |= R300_LVDS_SRC_SEL_RMX; 236 1.1 riastrad } else 237 1.1 riastrad lvds_gen_cntl &= ~RADEON_LVDS_SEL_CRTC2; 238 1.1 riastrad } else { 239 1.1 riastrad if (ASIC_IS_R300(rdev)) 240 1.1 riastrad lvds_pll_cntl |= R300_LVDS_SRC_SEL_CRTC2; 241 1.1 riastrad else 242 1.1 riastrad lvds_gen_cntl |= RADEON_LVDS_SEL_CRTC2; 243 1.1 riastrad } 244 1.1 riastrad 245 1.1 riastrad WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl); 246 1.1 riastrad WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl); 247 1.1 riastrad WREG32(RADEON_LVDS_SS_GEN_CNTL, lvds_ss_gen_cntl); 248 1.1 riastrad 249 1.1 riastrad if (rdev->family == CHIP_RV410) 250 1.1 riastrad WREG32(RADEON_CLOCK_CNTL_INDEX, 0); 251 1.1 riastrad 252 1.1 riastrad if (rdev->is_atom_bios) 253 1.1 riastrad radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); 254 1.1 riastrad else 255 1.1 riastrad radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); 256 1.1 riastrad } 257 1.1 riastrad 258 1.1 riastrad static bool radeon_legacy_mode_fixup(struct drm_encoder *encoder, 259 1.1 riastrad const struct drm_display_mode *mode, 260 1.1 riastrad struct drm_display_mode *adjusted_mode) 261 1.1 riastrad { 262 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 263 1.1 riastrad 264 1.1 riastrad /* set the active encoder to connector routing */ 265 1.1 riastrad radeon_encoder_set_active_device(encoder); 266 1.1 riastrad drm_mode_set_crtcinfo(adjusted_mode, 0); 267 1.1 riastrad 268 1.1 riastrad /* get the native mode for LVDS */ 269 1.1 riastrad if (radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT)) 270 1.1 riastrad radeon_panel_mode_fixup(encoder, adjusted_mode); 271 1.1 riastrad 272 1.1 riastrad return true; 273 1.1 riastrad } 274 1.1 riastrad 275 1.1 riastrad static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs = { 276 1.1 riastrad .dpms = radeon_legacy_lvds_dpms, 277 1.1 riastrad .mode_fixup = radeon_legacy_mode_fixup, 278 1.1 riastrad .prepare = radeon_legacy_lvds_prepare, 279 1.1 riastrad .mode_set = radeon_legacy_lvds_mode_set, 280 1.1 riastrad .commit = radeon_legacy_lvds_commit, 281 1.1 riastrad .disable = radeon_legacy_encoder_disable, 282 1.1 riastrad }; 283 1.1 riastrad 284 1.1 riastrad u8 285 1.1 riastrad radeon_legacy_get_backlight_level(struct radeon_encoder *radeon_encoder) 286 1.1 riastrad { 287 1.1 riastrad struct drm_device *dev = radeon_encoder->base.dev; 288 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 289 1.1 riastrad u8 backlight_level; 290 1.1 riastrad 291 1.1 riastrad backlight_level = (RREG32(RADEON_LVDS_GEN_CNTL) >> 292 1.1 riastrad RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff; 293 1.1 riastrad 294 1.1 riastrad return backlight_level; 295 1.1 riastrad } 296 1.1 riastrad 297 1.1 riastrad void 298 1.1 riastrad radeon_legacy_set_backlight_level(struct radeon_encoder *radeon_encoder, u8 level) 299 1.1 riastrad { 300 1.1 riastrad struct drm_device *dev = radeon_encoder->base.dev; 301 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 302 1.1 riastrad int dpms_mode = DRM_MODE_DPMS_ON; 303 1.1 riastrad 304 1.1 riastrad if (radeon_encoder->enc_priv) { 305 1.1 riastrad if (rdev->is_atom_bios) { 306 1.1 riastrad struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv; 307 1.1 riastrad if (lvds->backlight_level > 0) 308 1.1 riastrad dpms_mode = lvds->dpms_mode; 309 1.1 riastrad else 310 1.1 riastrad dpms_mode = DRM_MODE_DPMS_OFF; 311 1.1 riastrad lvds->backlight_level = level; 312 1.1 riastrad } else { 313 1.1 riastrad struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv; 314 1.1 riastrad if (lvds->backlight_level > 0) 315 1.1 riastrad dpms_mode = lvds->dpms_mode; 316 1.1 riastrad else 317 1.1 riastrad dpms_mode = DRM_MODE_DPMS_OFF; 318 1.1 riastrad lvds->backlight_level = level; 319 1.1 riastrad } 320 1.1 riastrad } 321 1.1 riastrad 322 1.1 riastrad radeon_legacy_lvds_update(&radeon_encoder->base, dpms_mode); 323 1.1 riastrad } 324 1.1 riastrad 325 1.2 skrll #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) || IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE) 326 1.1 riastrad 327 1.1 riastrad static uint8_t radeon_legacy_lvds_level(struct backlight_device *bd) 328 1.1 riastrad { 329 1.1 riastrad struct radeon_backlight_privdata *pdata = bl_get_data(bd); 330 1.1 riastrad uint8_t level; 331 1.1 riastrad 332 1.1 riastrad /* Convert brightness to hardware level */ 333 1.1 riastrad if (bd->props.brightness < 0) 334 1.1 riastrad level = 0; 335 1.1 riastrad else if (bd->props.brightness > RADEON_MAX_BL_LEVEL) 336 1.1 riastrad level = RADEON_MAX_BL_LEVEL; 337 1.1 riastrad else 338 1.1 riastrad level = bd->props.brightness; 339 1.1 riastrad 340 1.1 riastrad if (pdata->negative) 341 1.1 riastrad level = RADEON_MAX_BL_LEVEL - level; 342 1.1 riastrad 343 1.1 riastrad return level; 344 1.1 riastrad } 345 1.1 riastrad 346 1.1 riastrad static int radeon_legacy_backlight_update_status(struct backlight_device *bd) 347 1.1 riastrad { 348 1.1 riastrad struct radeon_backlight_privdata *pdata = bl_get_data(bd); 349 1.1 riastrad struct radeon_encoder *radeon_encoder = pdata->encoder; 350 1.1 riastrad 351 1.1 riastrad radeon_legacy_set_backlight_level(radeon_encoder, 352 1.1 riastrad radeon_legacy_lvds_level(bd)); 353 1.1 riastrad 354 1.1 riastrad return 0; 355 1.1 riastrad } 356 1.1 riastrad 357 1.1 riastrad static int radeon_legacy_backlight_get_brightness(struct backlight_device *bd) 358 1.1 riastrad { 359 1.1 riastrad struct radeon_backlight_privdata *pdata = bl_get_data(bd); 360 1.1 riastrad struct radeon_encoder *radeon_encoder = pdata->encoder; 361 1.1 riastrad struct drm_device *dev = radeon_encoder->base.dev; 362 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 363 1.1 riastrad uint8_t backlight_level; 364 1.1 riastrad 365 1.1 riastrad backlight_level = (RREG32(RADEON_LVDS_GEN_CNTL) >> 366 1.1 riastrad RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff; 367 1.1 riastrad 368 1.1 riastrad return pdata->negative ? RADEON_MAX_BL_LEVEL - backlight_level : backlight_level; 369 1.1 riastrad } 370 1.1 riastrad 371 1.1 riastrad static const struct backlight_ops radeon_backlight_ops = { 372 1.1 riastrad .get_brightness = radeon_legacy_backlight_get_brightness, 373 1.1 riastrad .update_status = radeon_legacy_backlight_update_status, 374 1.1 riastrad }; 375 1.1 riastrad 376 1.1 riastrad void radeon_legacy_backlight_init(struct radeon_encoder *radeon_encoder, 377 1.1 riastrad struct drm_connector *drm_connector) 378 1.1 riastrad { 379 1.1 riastrad struct drm_device *dev = radeon_encoder->base.dev; 380 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 381 1.1 riastrad struct backlight_device *bd; 382 1.1 riastrad struct backlight_properties props; 383 1.1 riastrad struct radeon_backlight_privdata *pdata; 384 1.1 riastrad uint8_t backlight_level; 385 1.1 riastrad char bl_name[16]; 386 1.1 riastrad 387 1.1 riastrad if (!radeon_encoder->enc_priv) 388 1.1 riastrad return; 389 1.1 riastrad 390 1.1 riastrad #ifdef CONFIG_PMAC_BACKLIGHT 391 1.1 riastrad if (!pmac_has_backlight_type("ati") && 392 1.1 riastrad !pmac_has_backlight_type("mnca")) 393 1.1 riastrad return; 394 1.1 riastrad #endif 395 1.1 riastrad 396 1.1 riastrad pdata = kmalloc(sizeof(struct radeon_backlight_privdata), GFP_KERNEL); 397 1.1 riastrad if (!pdata) { 398 1.1 riastrad DRM_ERROR("Memory allocation failed\n"); 399 1.1 riastrad goto error; 400 1.1 riastrad } 401 1.1 riastrad 402 1.1 riastrad memset(&props, 0, sizeof(props)); 403 1.1 riastrad props.max_brightness = RADEON_MAX_BL_LEVEL; 404 1.1 riastrad props.type = BACKLIGHT_RAW; 405 1.1 riastrad snprintf(bl_name, sizeof(bl_name), 406 1.1 riastrad "radeon_bl%d", dev->primary->index); 407 1.1 riastrad bd = backlight_device_register(bl_name, drm_connector->kdev, 408 1.1 riastrad pdata, &radeon_backlight_ops, &props); 409 1.1 riastrad if (IS_ERR(bd)) { 410 1.1 riastrad DRM_ERROR("Backlight registration failed\n"); 411 1.1 riastrad goto error; 412 1.1 riastrad } 413 1.1 riastrad 414 1.1 riastrad pdata->encoder = radeon_encoder; 415 1.1 riastrad 416 1.1 riastrad backlight_level = (RREG32(RADEON_LVDS_GEN_CNTL) >> 417 1.1 riastrad RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff; 418 1.1 riastrad 419 1.1 riastrad /* First, try to detect backlight level sense based on the assumption 420 1.1 riastrad * that firmware set it up at full brightness 421 1.1 riastrad */ 422 1.1 riastrad if (backlight_level == 0) 423 1.1 riastrad pdata->negative = true; 424 1.1 riastrad else if (backlight_level == 0xff) 425 1.1 riastrad pdata->negative = false; 426 1.1 riastrad else { 427 1.1 riastrad /* XXX hack... maybe some day we can figure out in what direction 428 1.1 riastrad * backlight should work on a given panel? 429 1.1 riastrad */ 430 1.1 riastrad pdata->negative = (rdev->family != CHIP_RV200 && 431 1.1 riastrad rdev->family != CHIP_RV250 && 432 1.1 riastrad rdev->family != CHIP_RV280 && 433 1.1 riastrad rdev->family != CHIP_RV350); 434 1.1 riastrad 435 1.1 riastrad #ifdef CONFIG_PMAC_BACKLIGHT 436 1.1 riastrad pdata->negative = (pdata->negative || 437 1.1 riastrad of_machine_is_compatible("PowerBook4,3") || 438 1.1 riastrad of_machine_is_compatible("PowerBook6,3") || 439 1.1 riastrad of_machine_is_compatible("PowerBook6,5")); 440 1.1 riastrad #endif 441 1.1 riastrad } 442 1.1 riastrad 443 1.1 riastrad if (rdev->is_atom_bios) { 444 1.1 riastrad struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv; 445 1.1 riastrad lvds->bl_dev = bd; 446 1.1 riastrad } else { 447 1.1 riastrad struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv; 448 1.1 riastrad lvds->bl_dev = bd; 449 1.1 riastrad } 450 1.1 riastrad 451 1.1 riastrad bd->props.brightness = radeon_legacy_backlight_get_brightness(bd); 452 1.1 riastrad bd->props.power = FB_BLANK_UNBLANK; 453 1.1 riastrad backlight_update_status(bd); 454 1.1 riastrad 455 1.1 riastrad DRM_INFO("radeon legacy LVDS backlight initialized\n"); 456 1.3 riastrad rdev->mode_info.bl_encoder = radeon_encoder; 457 1.1 riastrad 458 1.1 riastrad return; 459 1.1 riastrad 460 1.1 riastrad error: 461 1.1 riastrad kfree(pdata); 462 1.1 riastrad return; 463 1.1 riastrad } 464 1.1 riastrad 465 1.1 riastrad static void radeon_legacy_backlight_exit(struct radeon_encoder *radeon_encoder) 466 1.1 riastrad { 467 1.1 riastrad struct drm_device *dev = radeon_encoder->base.dev; 468 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 469 1.1 riastrad struct backlight_device *bd = NULL; 470 1.1 riastrad 471 1.1 riastrad if (!radeon_encoder->enc_priv) 472 1.1 riastrad return; 473 1.1 riastrad 474 1.1 riastrad if (rdev->is_atom_bios) { 475 1.1 riastrad struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv; 476 1.1 riastrad bd = lvds->bl_dev; 477 1.1 riastrad lvds->bl_dev = NULL; 478 1.1 riastrad } else { 479 1.1 riastrad struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv; 480 1.1 riastrad bd = lvds->bl_dev; 481 1.1 riastrad lvds->bl_dev = NULL; 482 1.1 riastrad } 483 1.1 riastrad 484 1.1 riastrad if (bd) { 485 1.1 riastrad struct radeon_backlight_privdata *pdata; 486 1.1 riastrad 487 1.1 riastrad pdata = bl_get_data(bd); 488 1.1 riastrad backlight_device_unregister(bd); 489 1.1 riastrad kfree(pdata); 490 1.1 riastrad 491 1.1 riastrad DRM_INFO("radeon legacy LVDS backlight unloaded\n"); 492 1.1 riastrad } 493 1.1 riastrad } 494 1.1 riastrad 495 1.1 riastrad #else /* !CONFIG_BACKLIGHT_CLASS_DEVICE */ 496 1.1 riastrad 497 1.1 riastrad void radeon_legacy_backlight_init(struct radeon_encoder *encoder) 498 1.1 riastrad { 499 1.1 riastrad } 500 1.1 riastrad 501 1.1 riastrad static void radeon_legacy_backlight_exit(struct radeon_encoder *encoder) 502 1.1 riastrad { 503 1.1 riastrad } 504 1.1 riastrad 505 1.1 riastrad #endif 506 1.1 riastrad 507 1.1 riastrad 508 1.1 riastrad static void radeon_lvds_enc_destroy(struct drm_encoder *encoder) 509 1.1 riastrad { 510 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 511 1.1 riastrad 512 1.1 riastrad if (radeon_encoder->enc_priv) { 513 1.1 riastrad radeon_legacy_backlight_exit(radeon_encoder); 514 1.1 riastrad kfree(radeon_encoder->enc_priv); 515 1.1 riastrad } 516 1.1 riastrad drm_encoder_cleanup(encoder); 517 1.1 riastrad kfree(radeon_encoder); 518 1.1 riastrad } 519 1.1 riastrad 520 1.1 riastrad static const struct drm_encoder_funcs radeon_legacy_lvds_enc_funcs = { 521 1.1 riastrad .destroy = radeon_lvds_enc_destroy, 522 1.1 riastrad }; 523 1.1 riastrad 524 1.1 riastrad static void radeon_legacy_primary_dac_dpms(struct drm_encoder *encoder, int mode) 525 1.1 riastrad { 526 1.1 riastrad struct drm_device *dev = encoder->dev; 527 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 528 1.1 riastrad uint32_t crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL); 529 1.1 riastrad uint32_t dac_cntl = RREG32(RADEON_DAC_CNTL); 530 1.1 riastrad uint32_t dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL); 531 1.1 riastrad 532 1.1 riastrad DRM_DEBUG_KMS("\n"); 533 1.1 riastrad 534 1.1 riastrad switch (mode) { 535 1.1 riastrad case DRM_MODE_DPMS_ON: 536 1.1 riastrad crtc_ext_cntl |= RADEON_CRTC_CRT_ON; 537 1.1 riastrad dac_cntl &= ~RADEON_DAC_PDWN; 538 1.1 riastrad dac_macro_cntl &= ~(RADEON_DAC_PDWN_R | 539 1.1 riastrad RADEON_DAC_PDWN_G | 540 1.1 riastrad RADEON_DAC_PDWN_B); 541 1.1 riastrad break; 542 1.1 riastrad case DRM_MODE_DPMS_STANDBY: 543 1.1 riastrad case DRM_MODE_DPMS_SUSPEND: 544 1.1 riastrad case DRM_MODE_DPMS_OFF: 545 1.1 riastrad crtc_ext_cntl &= ~RADEON_CRTC_CRT_ON; 546 1.1 riastrad dac_cntl |= RADEON_DAC_PDWN; 547 1.1 riastrad dac_macro_cntl |= (RADEON_DAC_PDWN_R | 548 1.1 riastrad RADEON_DAC_PDWN_G | 549 1.1 riastrad RADEON_DAC_PDWN_B); 550 1.1 riastrad break; 551 1.1 riastrad } 552 1.1 riastrad 553 1.1 riastrad /* handled in radeon_crtc_dpms() */ 554 1.1 riastrad if (!(rdev->flags & RADEON_SINGLE_CRTC)) 555 1.1 riastrad WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl); 556 1.1 riastrad WREG32(RADEON_DAC_CNTL, dac_cntl); 557 1.1 riastrad WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl); 558 1.1 riastrad 559 1.1 riastrad if (rdev->is_atom_bios) 560 1.1 riastrad radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 561 1.1 riastrad else 562 1.1 riastrad radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 563 1.1 riastrad 564 1.1 riastrad } 565 1.1 riastrad 566 1.1 riastrad static void radeon_legacy_primary_dac_prepare(struct drm_encoder *encoder) 567 1.1 riastrad { 568 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 569 1.1 riastrad 570 1.1 riastrad if (rdev->is_atom_bios) 571 1.1 riastrad radeon_atom_output_lock(encoder, true); 572 1.1 riastrad else 573 1.1 riastrad radeon_combios_output_lock(encoder, true); 574 1.1 riastrad radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_OFF); 575 1.1 riastrad } 576 1.1 riastrad 577 1.1 riastrad static void radeon_legacy_primary_dac_commit(struct drm_encoder *encoder) 578 1.1 riastrad { 579 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 580 1.1 riastrad 581 1.1 riastrad radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_ON); 582 1.1 riastrad 583 1.1 riastrad if (rdev->is_atom_bios) 584 1.1 riastrad radeon_atom_output_lock(encoder, false); 585 1.1 riastrad else 586 1.1 riastrad radeon_combios_output_lock(encoder, false); 587 1.1 riastrad } 588 1.1 riastrad 589 1.1 riastrad static void radeon_legacy_primary_dac_mode_set(struct drm_encoder *encoder, 590 1.1 riastrad struct drm_display_mode *mode, 591 1.1 riastrad struct drm_display_mode *adjusted_mode) 592 1.1 riastrad { 593 1.1 riastrad struct drm_device *dev = encoder->dev; 594 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 595 1.1 riastrad struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 596 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 597 1.1 riastrad uint32_t disp_output_cntl, dac_cntl, dac2_cntl, dac_macro_cntl; 598 1.1 riastrad 599 1.1 riastrad DRM_DEBUG_KMS("\n"); 600 1.1 riastrad 601 1.1 riastrad if (radeon_crtc->crtc_id == 0) { 602 1.1 riastrad if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev)) { 603 1.1 riastrad disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL) & 604 1.1 riastrad ~(RADEON_DISP_DAC_SOURCE_MASK); 605 1.1 riastrad WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl); 606 1.1 riastrad } else { 607 1.1 riastrad dac2_cntl = RREG32(RADEON_DAC_CNTL2) & ~(RADEON_DAC2_DAC_CLK_SEL); 608 1.1 riastrad WREG32(RADEON_DAC_CNTL2, dac2_cntl); 609 1.1 riastrad } 610 1.1 riastrad } else { 611 1.1 riastrad if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev)) { 612 1.1 riastrad disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL) & 613 1.1 riastrad ~(RADEON_DISP_DAC_SOURCE_MASK); 614 1.1 riastrad disp_output_cntl |= RADEON_DISP_DAC_SOURCE_CRTC2; 615 1.1 riastrad WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl); 616 1.1 riastrad } else { 617 1.1 riastrad dac2_cntl = RREG32(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC_CLK_SEL; 618 1.1 riastrad WREG32(RADEON_DAC_CNTL2, dac2_cntl); 619 1.1 riastrad } 620 1.1 riastrad } 621 1.1 riastrad 622 1.1 riastrad dac_cntl = (RADEON_DAC_MASK_ALL | 623 1.1 riastrad RADEON_DAC_VGA_ADR_EN | 624 1.1 riastrad /* TODO 6-bits */ 625 1.1 riastrad RADEON_DAC_8BIT_EN); 626 1.1 riastrad 627 1.1 riastrad WREG32_P(RADEON_DAC_CNTL, 628 1.1 riastrad dac_cntl, 629 1.1 riastrad RADEON_DAC_RANGE_CNTL | 630 1.1 riastrad RADEON_DAC_BLANKING); 631 1.1 riastrad 632 1.1 riastrad if (radeon_encoder->enc_priv) { 633 1.1 riastrad struct radeon_encoder_primary_dac *p_dac = (struct radeon_encoder_primary_dac *)radeon_encoder->enc_priv; 634 1.1 riastrad dac_macro_cntl = p_dac->ps2_pdac_adj; 635 1.1 riastrad } else 636 1.1 riastrad dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL); 637 1.1 riastrad dac_macro_cntl |= RADEON_DAC_PDWN_R | RADEON_DAC_PDWN_G | RADEON_DAC_PDWN_B; 638 1.1 riastrad WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl); 639 1.1 riastrad 640 1.1 riastrad if (rdev->is_atom_bios) 641 1.1 riastrad radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); 642 1.1 riastrad else 643 1.1 riastrad radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); 644 1.1 riastrad } 645 1.1 riastrad 646 1.1 riastrad static enum drm_connector_status radeon_legacy_primary_dac_detect(struct drm_encoder *encoder, 647 1.1 riastrad struct drm_connector *connector) 648 1.1 riastrad { 649 1.1 riastrad struct drm_device *dev = encoder->dev; 650 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 651 1.1 riastrad uint32_t vclk_ecp_cntl, crtc_ext_cntl; 652 1.1 riastrad uint32_t dac_ext_cntl, dac_cntl, dac_macro_cntl, tmp; 653 1.1 riastrad enum drm_connector_status found = connector_status_disconnected; 654 1.1 riastrad bool color = true; 655 1.1 riastrad 656 1.1 riastrad /* just don't bother on RN50 those chip are often connected to remoting 657 1.1 riastrad * console hw and often we get failure to load detect those. So to make 658 1.1 riastrad * everyone happy report the encoder as always connected. 659 1.1 riastrad */ 660 1.1 riastrad if (ASIC_IS_RN50(rdev)) { 661 1.1 riastrad return connector_status_connected; 662 1.1 riastrad } 663 1.1 riastrad 664 1.1 riastrad /* save the regs we need */ 665 1.1 riastrad vclk_ecp_cntl = RREG32_PLL(RADEON_VCLK_ECP_CNTL); 666 1.1 riastrad crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL); 667 1.1 riastrad dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL); 668 1.1 riastrad dac_cntl = RREG32(RADEON_DAC_CNTL); 669 1.1 riastrad dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL); 670 1.1 riastrad 671 1.1 riastrad tmp = vclk_ecp_cntl & 672 1.1 riastrad ~(RADEON_PIXCLK_ALWAYS_ONb | RADEON_PIXCLK_DAC_ALWAYS_ONb); 673 1.1 riastrad WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp); 674 1.1 riastrad 675 1.1 riastrad tmp = crtc_ext_cntl | RADEON_CRTC_CRT_ON; 676 1.1 riastrad WREG32(RADEON_CRTC_EXT_CNTL, tmp); 677 1.1 riastrad 678 1.1 riastrad tmp = RADEON_DAC_FORCE_BLANK_OFF_EN | 679 1.1 riastrad RADEON_DAC_FORCE_DATA_EN; 680 1.1 riastrad 681 1.1 riastrad if (color) 682 1.1 riastrad tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB; 683 1.1 riastrad else 684 1.1 riastrad tmp |= RADEON_DAC_FORCE_DATA_SEL_G; 685 1.1 riastrad 686 1.1 riastrad if (ASIC_IS_R300(rdev)) 687 1.1 riastrad tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT); 688 1.1 riastrad else if (ASIC_IS_RV100(rdev)) 689 1.1 riastrad tmp |= (0x1ac << RADEON_DAC_FORCE_DATA_SHIFT); 690 1.1 riastrad else 691 1.1 riastrad tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT); 692 1.1 riastrad 693 1.1 riastrad WREG32(RADEON_DAC_EXT_CNTL, tmp); 694 1.1 riastrad 695 1.1 riastrad tmp = dac_cntl & ~(RADEON_DAC_RANGE_CNTL_MASK | RADEON_DAC_PDWN); 696 1.1 riastrad tmp |= RADEON_DAC_RANGE_CNTL_PS2 | RADEON_DAC_CMP_EN; 697 1.1 riastrad WREG32(RADEON_DAC_CNTL, tmp); 698 1.1 riastrad 699 1.1 riastrad tmp = dac_macro_cntl; 700 1.1 riastrad tmp &= ~(RADEON_DAC_PDWN_R | 701 1.1 riastrad RADEON_DAC_PDWN_G | 702 1.1 riastrad RADEON_DAC_PDWN_B); 703 1.1 riastrad 704 1.1 riastrad WREG32(RADEON_DAC_MACRO_CNTL, tmp); 705 1.1 riastrad 706 1.1 riastrad mdelay(2); 707 1.1 riastrad 708 1.1 riastrad if (RREG32(RADEON_DAC_CNTL) & RADEON_DAC_CMP_OUTPUT) 709 1.1 riastrad found = connector_status_connected; 710 1.1 riastrad 711 1.1 riastrad /* restore the regs we used */ 712 1.1 riastrad WREG32(RADEON_DAC_CNTL, dac_cntl); 713 1.1 riastrad WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl); 714 1.1 riastrad WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl); 715 1.1 riastrad WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl); 716 1.1 riastrad WREG32_PLL(RADEON_VCLK_ECP_CNTL, vclk_ecp_cntl); 717 1.1 riastrad 718 1.1 riastrad return found; 719 1.1 riastrad } 720 1.1 riastrad 721 1.1 riastrad static const struct drm_encoder_helper_funcs radeon_legacy_primary_dac_helper_funcs = { 722 1.1 riastrad .dpms = radeon_legacy_primary_dac_dpms, 723 1.1 riastrad .mode_fixup = radeon_legacy_mode_fixup, 724 1.1 riastrad .prepare = radeon_legacy_primary_dac_prepare, 725 1.1 riastrad .mode_set = radeon_legacy_primary_dac_mode_set, 726 1.1 riastrad .commit = radeon_legacy_primary_dac_commit, 727 1.1 riastrad .detect = radeon_legacy_primary_dac_detect, 728 1.1 riastrad .disable = radeon_legacy_encoder_disable, 729 1.1 riastrad }; 730 1.1 riastrad 731 1.1 riastrad 732 1.1 riastrad static const struct drm_encoder_funcs radeon_legacy_primary_dac_enc_funcs = { 733 1.1 riastrad .destroy = radeon_enc_destroy, 734 1.1 riastrad }; 735 1.1 riastrad 736 1.1 riastrad static void radeon_legacy_tmds_int_dpms(struct drm_encoder *encoder, int mode) 737 1.1 riastrad { 738 1.1 riastrad struct drm_device *dev = encoder->dev; 739 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 740 1.1 riastrad uint32_t fp_gen_cntl = RREG32(RADEON_FP_GEN_CNTL); 741 1.1 riastrad DRM_DEBUG_KMS("\n"); 742 1.1 riastrad 743 1.1 riastrad switch (mode) { 744 1.1 riastrad case DRM_MODE_DPMS_ON: 745 1.1 riastrad fp_gen_cntl |= (RADEON_FP_FPON | RADEON_FP_TMDS_EN); 746 1.1 riastrad break; 747 1.1 riastrad case DRM_MODE_DPMS_STANDBY: 748 1.1 riastrad case DRM_MODE_DPMS_SUSPEND: 749 1.1 riastrad case DRM_MODE_DPMS_OFF: 750 1.1 riastrad fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN); 751 1.1 riastrad break; 752 1.1 riastrad } 753 1.1 riastrad 754 1.1 riastrad WREG32(RADEON_FP_GEN_CNTL, fp_gen_cntl); 755 1.1 riastrad 756 1.1 riastrad if (rdev->is_atom_bios) 757 1.1 riastrad radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 758 1.1 riastrad else 759 1.1 riastrad radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 760 1.1 riastrad 761 1.1 riastrad } 762 1.1 riastrad 763 1.1 riastrad static void radeon_legacy_tmds_int_prepare(struct drm_encoder *encoder) 764 1.1 riastrad { 765 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 766 1.1 riastrad 767 1.1 riastrad if (rdev->is_atom_bios) 768 1.1 riastrad radeon_atom_output_lock(encoder, true); 769 1.1 riastrad else 770 1.1 riastrad radeon_combios_output_lock(encoder, true); 771 1.1 riastrad radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_OFF); 772 1.1 riastrad } 773 1.1 riastrad 774 1.1 riastrad static void radeon_legacy_tmds_int_commit(struct drm_encoder *encoder) 775 1.1 riastrad { 776 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 777 1.1 riastrad 778 1.1 riastrad radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_ON); 779 1.1 riastrad 780 1.1 riastrad if (rdev->is_atom_bios) 781 1.1 riastrad radeon_atom_output_lock(encoder, true); 782 1.1 riastrad else 783 1.1 riastrad radeon_combios_output_lock(encoder, true); 784 1.1 riastrad } 785 1.1 riastrad 786 1.1 riastrad static void radeon_legacy_tmds_int_mode_set(struct drm_encoder *encoder, 787 1.1 riastrad struct drm_display_mode *mode, 788 1.1 riastrad struct drm_display_mode *adjusted_mode) 789 1.1 riastrad { 790 1.1 riastrad struct drm_device *dev = encoder->dev; 791 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 792 1.1 riastrad struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 793 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 794 1.1 riastrad uint32_t tmp, tmds_pll_cntl, tmds_transmitter_cntl, fp_gen_cntl; 795 1.1 riastrad int i; 796 1.1 riastrad 797 1.1 riastrad DRM_DEBUG_KMS("\n"); 798 1.1 riastrad 799 1.1 riastrad tmp = tmds_pll_cntl = RREG32(RADEON_TMDS_PLL_CNTL); 800 1.1 riastrad tmp &= 0xfffff; 801 1.1 riastrad if (rdev->family == CHIP_RV280) { 802 1.1 riastrad /* bit 22 of TMDS_PLL_CNTL is read-back inverted */ 803 1.1 riastrad tmp ^= (1 << 22); 804 1.1 riastrad tmds_pll_cntl ^= (1 << 22); 805 1.1 riastrad } 806 1.1 riastrad 807 1.1 riastrad if (radeon_encoder->enc_priv) { 808 1.1 riastrad struct radeon_encoder_int_tmds *tmds = (struct radeon_encoder_int_tmds *)radeon_encoder->enc_priv; 809 1.1 riastrad 810 1.1 riastrad for (i = 0; i < 4; i++) { 811 1.1 riastrad if (tmds->tmds_pll[i].freq == 0) 812 1.1 riastrad break; 813 1.1 riastrad if ((uint32_t)(mode->clock / 10) < tmds->tmds_pll[i].freq) { 814 1.1 riastrad tmp = tmds->tmds_pll[i].value ; 815 1.1 riastrad break; 816 1.1 riastrad } 817 1.1 riastrad } 818 1.1 riastrad } 819 1.1 riastrad 820 1.1 riastrad if (ASIC_IS_R300(rdev) || (rdev->family == CHIP_RV280)) { 821 1.1 riastrad if (tmp & 0xfff00000) 822 1.1 riastrad tmds_pll_cntl = tmp; 823 1.1 riastrad else { 824 1.1 riastrad tmds_pll_cntl &= 0xfff00000; 825 1.1 riastrad tmds_pll_cntl |= tmp; 826 1.1 riastrad } 827 1.1 riastrad } else 828 1.1 riastrad tmds_pll_cntl = tmp; 829 1.1 riastrad 830 1.1 riastrad tmds_transmitter_cntl = RREG32(RADEON_TMDS_TRANSMITTER_CNTL) & 831 1.1 riastrad ~(RADEON_TMDS_TRANSMITTER_PLLRST); 832 1.1 riastrad 833 1.4 riastrad if (rdev->family == CHIP_R200 || 834 1.4 riastrad rdev->family == CHIP_R100 || 835 1.4 riastrad ASIC_IS_R300(rdev)) 836 1.4 riastrad tmds_transmitter_cntl &= ~(RADEON_TMDS_TRANSMITTER_PLLEN); 837 1.4 riastrad else /* RV chips got this bit reversed */ 838 1.4 riastrad tmds_transmitter_cntl |= RADEON_TMDS_TRANSMITTER_PLLEN; 839 1.4 riastrad 840 1.4 riastrad fp_gen_cntl = (RREG32(RADEON_FP_GEN_CNTL) | 841 1.4 riastrad (RADEON_FP_CRTC_DONT_SHADOW_VPAR | 842 1.4 riastrad RADEON_FP_CRTC_DONT_SHADOW_HEND)); 843 1.4 riastrad 844 1.4 riastrad fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN); 845 1.4 riastrad 846 1.4 riastrad fp_gen_cntl &= ~(RADEON_FP_RMX_HVSYNC_CONTROL_EN | 847 1.4 riastrad RADEON_FP_DFP_SYNC_SEL | 848 1.4 riastrad RADEON_FP_CRT_SYNC_SEL | 849 1.4 riastrad RADEON_FP_CRTC_LOCK_8DOT | 850 1.4 riastrad RADEON_FP_USE_SHADOW_EN | 851 1.4 riastrad RADEON_FP_CRTC_USE_SHADOW_VEND | 852 1.4 riastrad RADEON_FP_CRT_SYNC_ALT); 853 1.4 riastrad 854 1.4 riastrad if (1) /* FIXME rgbBits == 8 */ 855 1.4 riastrad fp_gen_cntl |= RADEON_FP_PANEL_FORMAT; /* 24 bit format */ 856 1.4 riastrad else 857 1.4 riastrad fp_gen_cntl &= ~RADEON_FP_PANEL_FORMAT;/* 18 bit format */ 858 1.4 riastrad 859 1.4 riastrad if (radeon_crtc->crtc_id == 0) { 860 1.4 riastrad if (ASIC_IS_R300(rdev) || rdev->family == CHIP_R200) { 861 1.4 riastrad fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK; 862 1.4 riastrad if (radeon_encoder->rmx_type != RMX_OFF) 863 1.4 riastrad fp_gen_cntl |= R200_FP_SOURCE_SEL_RMX; 864 1.4 riastrad else 865 1.4 riastrad fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC1; 866 1.4 riastrad } else 867 1.4 riastrad fp_gen_cntl &= ~RADEON_FP_SEL_CRTC2; 868 1.4 riastrad } else { 869 1.4 riastrad if (ASIC_IS_R300(rdev) || rdev->family == CHIP_R200) { 870 1.4 riastrad fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK; 871 1.4 riastrad fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC2; 872 1.4 riastrad } else 873 1.4 riastrad fp_gen_cntl |= RADEON_FP_SEL_CRTC2; 874 1.4 riastrad } 875 1.4 riastrad 876 1.4 riastrad WREG32(RADEON_TMDS_PLL_CNTL, tmds_pll_cntl); 877 1.4 riastrad WREG32(RADEON_TMDS_TRANSMITTER_CNTL, tmds_transmitter_cntl); 878 1.4 riastrad WREG32(RADEON_FP_GEN_CNTL, fp_gen_cntl); 879 1.1 riastrad 880 1.1 riastrad if (rdev->is_atom_bios) 881 1.1 riastrad radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); 882 1.1 riastrad else 883 1.1 riastrad radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); 884 1.1 riastrad } 885 1.1 riastrad 886 1.1 riastrad static const struct drm_encoder_helper_funcs radeon_legacy_tmds_int_helper_funcs = { 887 1.1 riastrad .dpms = radeon_legacy_tmds_int_dpms, 888 1.1 riastrad .mode_fixup = radeon_legacy_mode_fixup, 889 1.1 riastrad .prepare = radeon_legacy_tmds_int_prepare, 890 1.1 riastrad .mode_set = radeon_legacy_tmds_int_mode_set, 891 1.1 riastrad .commit = radeon_legacy_tmds_int_commit, 892 1.1 riastrad .disable = radeon_legacy_encoder_disable, 893 1.1 riastrad }; 894 1.1 riastrad 895 1.1 riastrad 896 1.1 riastrad static const struct drm_encoder_funcs radeon_legacy_tmds_int_enc_funcs = { 897 1.1 riastrad .destroy = radeon_enc_destroy, 898 1.1 riastrad }; 899 1.1 riastrad 900 1.1 riastrad static void radeon_legacy_tmds_ext_dpms(struct drm_encoder *encoder, int mode) 901 1.1 riastrad { 902 1.1 riastrad struct drm_device *dev = encoder->dev; 903 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 904 1.1 riastrad uint32_t fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL); 905 1.1 riastrad DRM_DEBUG_KMS("\n"); 906 1.1 riastrad 907 1.1 riastrad switch (mode) { 908 1.1 riastrad case DRM_MODE_DPMS_ON: 909 1.1 riastrad fp2_gen_cntl &= ~RADEON_FP2_BLANK_EN; 910 1.1 riastrad fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN); 911 1.1 riastrad break; 912 1.1 riastrad case DRM_MODE_DPMS_STANDBY: 913 1.1 riastrad case DRM_MODE_DPMS_SUSPEND: 914 1.1 riastrad case DRM_MODE_DPMS_OFF: 915 1.1 riastrad fp2_gen_cntl |= RADEON_FP2_BLANK_EN; 916 1.1 riastrad fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN); 917 1.1 riastrad break; 918 1.1 riastrad } 919 1.1 riastrad 920 1.1 riastrad WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl); 921 1.1 riastrad 922 1.1 riastrad if (rdev->is_atom_bios) 923 1.1 riastrad radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 924 1.1 riastrad else 925 1.1 riastrad radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 926 1.1 riastrad 927 1.1 riastrad } 928 1.1 riastrad 929 1.1 riastrad static void radeon_legacy_tmds_ext_prepare(struct drm_encoder *encoder) 930 1.1 riastrad { 931 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 932 1.1 riastrad 933 1.1 riastrad if (rdev->is_atom_bios) 934 1.1 riastrad radeon_atom_output_lock(encoder, true); 935 1.1 riastrad else 936 1.1 riastrad radeon_combios_output_lock(encoder, true); 937 1.1 riastrad radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_OFF); 938 1.1 riastrad } 939 1.1 riastrad 940 1.1 riastrad static void radeon_legacy_tmds_ext_commit(struct drm_encoder *encoder) 941 1.1 riastrad { 942 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 943 1.1 riastrad radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_ON); 944 1.1 riastrad 945 1.1 riastrad if (rdev->is_atom_bios) 946 1.1 riastrad radeon_atom_output_lock(encoder, false); 947 1.1 riastrad else 948 1.1 riastrad radeon_combios_output_lock(encoder, false); 949 1.1 riastrad } 950 1.1 riastrad 951 1.1 riastrad static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder *encoder, 952 1.1 riastrad struct drm_display_mode *mode, 953 1.1 riastrad struct drm_display_mode *adjusted_mode) 954 1.1 riastrad { 955 1.1 riastrad struct drm_device *dev = encoder->dev; 956 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 957 1.1 riastrad struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 958 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 959 1.1 riastrad uint32_t fp2_gen_cntl; 960 1.1 riastrad 961 1.1 riastrad DRM_DEBUG_KMS("\n"); 962 1.1 riastrad 963 1.1 riastrad if (rdev->is_atom_bios) { 964 1.1 riastrad radeon_encoder->pixel_clock = adjusted_mode->clock; 965 1.1 riastrad atombios_dvo_setup(encoder, ATOM_ENABLE); 966 1.1 riastrad fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL); 967 1.1 riastrad } else { 968 1.1 riastrad fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL); 969 1.1 riastrad 970 1.1 riastrad if (1) /* FIXME rgbBits == 8 */ 971 1.1 riastrad fp2_gen_cntl |= RADEON_FP2_PANEL_FORMAT; /* 24 bit format, */ 972 1.1 riastrad else 973 1.1 riastrad fp2_gen_cntl &= ~RADEON_FP2_PANEL_FORMAT;/* 18 bit format, */ 974 1.1 riastrad 975 1.1 riastrad fp2_gen_cntl &= ~(RADEON_FP2_ON | 976 1.1 riastrad RADEON_FP2_DVO_EN | 977 1.1 riastrad RADEON_FP2_DVO_RATE_SEL_SDR); 978 1.1 riastrad 979 1.1 riastrad /* XXX: these are oem specific */ 980 1.1 riastrad if (ASIC_IS_R300(rdev)) { 981 1.1 riastrad if ((dev->pdev->device == 0x4850) && 982 1.1 riastrad (dev->pdev->subsystem_vendor == 0x1028) && 983 1.1 riastrad (dev->pdev->subsystem_device == 0x2001)) /* Dell Inspiron 8600 */ 984 1.1 riastrad fp2_gen_cntl |= R300_FP2_DVO_CLOCK_MODE_SINGLE; 985 1.1 riastrad else 986 1.1 riastrad fp2_gen_cntl |= RADEON_FP2_PAD_FLOP_EN | R300_FP2_DVO_CLOCK_MODE_SINGLE; 987 1.1 riastrad 988 1.1 riastrad /*if (mode->clock > 165000) 989 1.1 riastrad fp2_gen_cntl |= R300_FP2_DVO_DUAL_CHANNEL_EN;*/ 990 1.1 riastrad } 991 1.1 riastrad if (!radeon_combios_external_tmds_setup(encoder)) 992 1.1 riastrad radeon_external_tmds_setup(encoder); 993 1.1 riastrad } 994 1.1 riastrad 995 1.1 riastrad if (radeon_crtc->crtc_id == 0) { 996 1.1 riastrad if ((rdev->family == CHIP_R200) || ASIC_IS_R300(rdev)) { 997 1.1 riastrad fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK; 998 1.1 riastrad if (radeon_encoder->rmx_type != RMX_OFF) 999 1.1 riastrad fp2_gen_cntl |= R200_FP2_SOURCE_SEL_RMX; 1000 1.1 riastrad else 1001 1.1 riastrad fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC1; 1002 1.1 riastrad } else 1003 1.1 riastrad fp2_gen_cntl &= ~RADEON_FP2_SRC_SEL_CRTC2; 1004 1.1 riastrad } else { 1005 1.1 riastrad if ((rdev->family == CHIP_R200) || ASIC_IS_R300(rdev)) { 1006 1.1 riastrad fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK; 1007 1.1 riastrad fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2; 1008 1.1 riastrad } else 1009 1.1 riastrad fp2_gen_cntl |= RADEON_FP2_SRC_SEL_CRTC2; 1010 1.1 riastrad } 1011 1.1 riastrad 1012 1.1 riastrad WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl); 1013 1.1 riastrad 1014 1.1 riastrad if (rdev->is_atom_bios) 1015 1.1 riastrad radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); 1016 1.1 riastrad else 1017 1.1 riastrad radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); 1018 1.1 riastrad } 1019 1.1 riastrad 1020 1.1 riastrad static void radeon_ext_tmds_enc_destroy(struct drm_encoder *encoder) 1021 1.1 riastrad { 1022 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1023 1.1 riastrad /* don't destroy the i2c bus record here, this will be done in radeon_i2c_fini */ 1024 1.1 riastrad kfree(radeon_encoder->enc_priv); 1025 1.1 riastrad drm_encoder_cleanup(encoder); 1026 1.1 riastrad kfree(radeon_encoder); 1027 1.1 riastrad } 1028 1.1 riastrad 1029 1.1 riastrad static const struct drm_encoder_helper_funcs radeon_legacy_tmds_ext_helper_funcs = { 1030 1.1 riastrad .dpms = radeon_legacy_tmds_ext_dpms, 1031 1.1 riastrad .mode_fixup = radeon_legacy_mode_fixup, 1032 1.1 riastrad .prepare = radeon_legacy_tmds_ext_prepare, 1033 1.1 riastrad .mode_set = radeon_legacy_tmds_ext_mode_set, 1034 1.1 riastrad .commit = radeon_legacy_tmds_ext_commit, 1035 1.1 riastrad .disable = radeon_legacy_encoder_disable, 1036 1.1 riastrad }; 1037 1.1 riastrad 1038 1.1 riastrad 1039 1.1 riastrad static const struct drm_encoder_funcs radeon_legacy_tmds_ext_enc_funcs = { 1040 1.1 riastrad .destroy = radeon_ext_tmds_enc_destroy, 1041 1.1 riastrad }; 1042 1.1 riastrad 1043 1.1 riastrad static void radeon_legacy_tv_dac_dpms(struct drm_encoder *encoder, int mode) 1044 1.1 riastrad { 1045 1.1 riastrad struct drm_device *dev = encoder->dev; 1046 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 1047 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1048 1.1 riastrad uint32_t fp2_gen_cntl = 0, crtc2_gen_cntl = 0, tv_dac_cntl = 0; 1049 1.1 riastrad uint32_t tv_master_cntl = 0; 1050 1.1 riastrad bool is_tv; 1051 1.1 riastrad DRM_DEBUG_KMS("\n"); 1052 1.1 riastrad 1053 1.1 riastrad is_tv = radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT ? true : false; 1054 1.1 riastrad 1055 1.1 riastrad if (rdev->family == CHIP_R200) 1056 1.1 riastrad fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL); 1057 1.1 riastrad else { 1058 1.1 riastrad if (is_tv) 1059 1.1 riastrad tv_master_cntl = RREG32(RADEON_TV_MASTER_CNTL); 1060 1.1 riastrad else 1061 1.1 riastrad crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL); 1062 1.1 riastrad tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL); 1063 1.1 riastrad } 1064 1.1 riastrad 1065 1.1 riastrad switch (mode) { 1066 1.1 riastrad case DRM_MODE_DPMS_ON: 1067 1.1 riastrad if (rdev->family == CHIP_R200) { 1068 1.1 riastrad fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN); 1069 1.1 riastrad } else { 1070 1.1 riastrad if (is_tv) 1071 1.1 riastrad tv_master_cntl |= RADEON_TV_ON; 1072 1.1 riastrad else 1073 1.1 riastrad crtc2_gen_cntl |= RADEON_CRTC2_CRT2_ON; 1074 1.1 riastrad 1075 1.1 riastrad if (rdev->family == CHIP_R420 || 1076 1.1 riastrad rdev->family == CHIP_R423 || 1077 1.1 riastrad rdev->family == CHIP_RV410) 1078 1.1 riastrad tv_dac_cntl &= ~(R420_TV_DAC_RDACPD | 1079 1.1 riastrad R420_TV_DAC_GDACPD | 1080 1.1 riastrad R420_TV_DAC_BDACPD | 1081 1.1 riastrad RADEON_TV_DAC_BGSLEEP); 1082 1.1 riastrad else 1083 1.1 riastrad tv_dac_cntl &= ~(RADEON_TV_DAC_RDACPD | 1084 1.1 riastrad RADEON_TV_DAC_GDACPD | 1085 1.1 riastrad RADEON_TV_DAC_BDACPD | 1086 1.1 riastrad RADEON_TV_DAC_BGSLEEP); 1087 1.1 riastrad } 1088 1.1 riastrad break; 1089 1.1 riastrad case DRM_MODE_DPMS_STANDBY: 1090 1.1 riastrad case DRM_MODE_DPMS_SUSPEND: 1091 1.1 riastrad case DRM_MODE_DPMS_OFF: 1092 1.1 riastrad if (rdev->family == CHIP_R200) 1093 1.1 riastrad fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN); 1094 1.1 riastrad else { 1095 1.1 riastrad if (is_tv) 1096 1.1 riastrad tv_master_cntl &= ~RADEON_TV_ON; 1097 1.1 riastrad else 1098 1.1 riastrad crtc2_gen_cntl &= ~RADEON_CRTC2_CRT2_ON; 1099 1.1 riastrad 1100 1.1 riastrad if (rdev->family == CHIP_R420 || 1101 1.1 riastrad rdev->family == CHIP_R423 || 1102 1.1 riastrad rdev->family == CHIP_RV410) 1103 1.1 riastrad tv_dac_cntl |= (R420_TV_DAC_RDACPD | 1104 1.1 riastrad R420_TV_DAC_GDACPD | 1105 1.1 riastrad R420_TV_DAC_BDACPD | 1106 1.1 riastrad RADEON_TV_DAC_BGSLEEP); 1107 1.1 riastrad else 1108 1.1 riastrad tv_dac_cntl |= (RADEON_TV_DAC_RDACPD | 1109 1.1 riastrad RADEON_TV_DAC_GDACPD | 1110 1.1 riastrad RADEON_TV_DAC_BDACPD | 1111 1.1 riastrad RADEON_TV_DAC_BGSLEEP); 1112 1.1 riastrad } 1113 1.1 riastrad break; 1114 1.1 riastrad } 1115 1.1 riastrad 1116 1.1 riastrad if (rdev->family == CHIP_R200) { 1117 1.1 riastrad WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl); 1118 1.1 riastrad } else { 1119 1.1 riastrad if (is_tv) 1120 1.1 riastrad WREG32(RADEON_TV_MASTER_CNTL, tv_master_cntl); 1121 1.1 riastrad /* handled in radeon_crtc_dpms() */ 1122 1.1 riastrad else if (!(rdev->flags & RADEON_SINGLE_CRTC)) 1123 1.1 riastrad WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl); 1124 1.1 riastrad WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl); 1125 1.1 riastrad } 1126 1.1 riastrad 1127 1.1 riastrad if (rdev->is_atom_bios) 1128 1.1 riastrad radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 1129 1.1 riastrad else 1130 1.1 riastrad radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); 1131 1.1 riastrad 1132 1.1 riastrad } 1133 1.1 riastrad 1134 1.1 riastrad static void radeon_legacy_tv_dac_prepare(struct drm_encoder *encoder) 1135 1.1 riastrad { 1136 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 1137 1.1 riastrad 1138 1.1 riastrad if (rdev->is_atom_bios) 1139 1.1 riastrad radeon_atom_output_lock(encoder, true); 1140 1.1 riastrad else 1141 1.1 riastrad radeon_combios_output_lock(encoder, true); 1142 1.1 riastrad radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_OFF); 1143 1.1 riastrad } 1144 1.1 riastrad 1145 1.1 riastrad static void radeon_legacy_tv_dac_commit(struct drm_encoder *encoder) 1146 1.1 riastrad { 1147 1.1 riastrad struct radeon_device *rdev = encoder->dev->dev_private; 1148 1.1 riastrad 1149 1.1 riastrad radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_ON); 1150 1.1 riastrad 1151 1.1 riastrad if (rdev->is_atom_bios) 1152 1.1 riastrad radeon_atom_output_lock(encoder, true); 1153 1.1 riastrad else 1154 1.1 riastrad radeon_combios_output_lock(encoder, true); 1155 1.1 riastrad } 1156 1.1 riastrad 1157 1.1 riastrad static void radeon_legacy_tv_dac_mode_set(struct drm_encoder *encoder, 1158 1.1 riastrad struct drm_display_mode *mode, 1159 1.1 riastrad struct drm_display_mode *adjusted_mode) 1160 1.1 riastrad { 1161 1.1 riastrad struct drm_device *dev = encoder->dev; 1162 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 1163 1.1 riastrad struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); 1164 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1165 1.1 riastrad struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv; 1166 1.1 riastrad uint32_t tv_dac_cntl, gpiopad_a = 0, dac2_cntl, disp_output_cntl = 0; 1167 1.1 riastrad uint32_t disp_hw_debug = 0, fp2_gen_cntl = 0, disp_tv_out_cntl = 0; 1168 1.1 riastrad bool is_tv = false; 1169 1.1 riastrad 1170 1.1 riastrad DRM_DEBUG_KMS("\n"); 1171 1.1 riastrad 1172 1.1 riastrad is_tv = radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT ? true : false; 1173 1.1 riastrad 1174 1.1 riastrad if (rdev->family != CHIP_R200) { 1175 1.1 riastrad tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL); 1176 1.1 riastrad if (rdev->family == CHIP_R420 || 1177 1.1 riastrad rdev->family == CHIP_R423 || 1178 1.1 riastrad rdev->family == CHIP_RV410) { 1179 1.1 riastrad tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK | 1180 1.1 riastrad RADEON_TV_DAC_BGADJ_MASK | 1181 1.1 riastrad R420_TV_DAC_DACADJ_MASK | 1182 1.1 riastrad R420_TV_DAC_RDACPD | 1183 1.1 riastrad R420_TV_DAC_GDACPD | 1184 1.1 riastrad R420_TV_DAC_BDACPD | 1185 1.1 riastrad R420_TV_DAC_TVENABLE); 1186 1.1 riastrad } else { 1187 1.1 riastrad tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK | 1188 1.1 riastrad RADEON_TV_DAC_BGADJ_MASK | 1189 1.1 riastrad RADEON_TV_DAC_DACADJ_MASK | 1190 1.1 riastrad RADEON_TV_DAC_RDACPD | 1191 1.1 riastrad RADEON_TV_DAC_GDACPD | 1192 1.1 riastrad RADEON_TV_DAC_BDACPD); 1193 1.1 riastrad } 1194 1.1 riastrad 1195 1.1 riastrad tv_dac_cntl |= RADEON_TV_DAC_NBLANK | RADEON_TV_DAC_NHOLD; 1196 1.1 riastrad 1197 1.1 riastrad if (is_tv) { 1198 1.1 riastrad if (tv_dac->tv_std == TV_STD_NTSC || 1199 1.1 riastrad tv_dac->tv_std == TV_STD_NTSC_J || 1200 1.1 riastrad tv_dac->tv_std == TV_STD_PAL_M || 1201 1.1 riastrad tv_dac->tv_std == TV_STD_PAL_60) 1202 1.1 riastrad tv_dac_cntl |= tv_dac->ntsc_tvdac_adj; 1203 1.1 riastrad else 1204 1.1 riastrad tv_dac_cntl |= tv_dac->pal_tvdac_adj; 1205 1.1 riastrad 1206 1.1 riastrad if (tv_dac->tv_std == TV_STD_NTSC || 1207 1.1 riastrad tv_dac->tv_std == TV_STD_NTSC_J) 1208 1.1 riastrad tv_dac_cntl |= RADEON_TV_DAC_STD_NTSC; 1209 1.1 riastrad else 1210 1.1 riastrad tv_dac_cntl |= RADEON_TV_DAC_STD_PAL; 1211 1.1 riastrad } else 1212 1.1 riastrad tv_dac_cntl |= (RADEON_TV_DAC_STD_PS2 | 1213 1.1 riastrad tv_dac->ps2_tvdac_adj); 1214 1.1 riastrad 1215 1.1 riastrad WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl); 1216 1.1 riastrad } 1217 1.1 riastrad 1218 1.1 riastrad if (ASIC_IS_R300(rdev)) { 1219 1.1 riastrad gpiopad_a = RREG32(RADEON_GPIOPAD_A) | 1; 1220 1.1 riastrad disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL); 1221 1.1 riastrad } else if (rdev->family != CHIP_R200) 1222 1.1 riastrad disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG); 1223 1.1 riastrad else if (rdev->family == CHIP_R200) 1224 1.1 riastrad fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL); 1225 1.1 riastrad 1226 1.1 riastrad if (rdev->family >= CHIP_R200) 1227 1.1 riastrad disp_tv_out_cntl = RREG32(RADEON_DISP_TV_OUT_CNTL); 1228 1.1 riastrad 1229 1.1 riastrad if (is_tv) { 1230 1.1 riastrad uint32_t dac_cntl; 1231 1.1 riastrad 1232 1.1 riastrad dac_cntl = RREG32(RADEON_DAC_CNTL); 1233 1.1 riastrad dac_cntl &= ~RADEON_DAC_TVO_EN; 1234 1.1 riastrad WREG32(RADEON_DAC_CNTL, dac_cntl); 1235 1.1 riastrad 1236 1.1 riastrad if (ASIC_IS_R300(rdev)) 1237 1.1 riastrad gpiopad_a = RREG32(RADEON_GPIOPAD_A) & ~1; 1238 1.1 riastrad 1239 1.1 riastrad dac2_cntl = RREG32(RADEON_DAC_CNTL2) & ~RADEON_DAC2_DAC2_CLK_SEL; 1240 1.1 riastrad if (radeon_crtc->crtc_id == 0) { 1241 1.1 riastrad if (ASIC_IS_R300(rdev)) { 1242 1.1 riastrad disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK; 1243 1.1 riastrad disp_output_cntl |= (RADEON_DISP_TVDAC_SOURCE_CRTC | 1244 1.1 riastrad RADEON_DISP_TV_SOURCE_CRTC); 1245 1.1 riastrad } 1246 1.1 riastrad if (rdev->family >= CHIP_R200) { 1247 1.1 riastrad disp_tv_out_cntl &= ~RADEON_DISP_TV_PATH_SRC_CRTC2; 1248 1.1 riastrad } else { 1249 1.1 riastrad disp_hw_debug |= RADEON_CRT2_DISP1_SEL; 1250 1.1 riastrad } 1251 1.1 riastrad } else { 1252 1.1 riastrad if (ASIC_IS_R300(rdev)) { 1253 1.1 riastrad disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK; 1254 1.1 riastrad disp_output_cntl |= RADEON_DISP_TV_SOURCE_CRTC; 1255 1.1 riastrad } 1256 1.1 riastrad if (rdev->family >= CHIP_R200) { 1257 1.1 riastrad disp_tv_out_cntl |= RADEON_DISP_TV_PATH_SRC_CRTC2; 1258 1.1 riastrad } else { 1259 1.1 riastrad disp_hw_debug &= ~RADEON_CRT2_DISP1_SEL; 1260 1.1 riastrad } 1261 1.1 riastrad } 1262 1.1 riastrad WREG32(RADEON_DAC_CNTL2, dac2_cntl); 1263 1.1 riastrad } else { 1264 1.1 riastrad 1265 1.1 riastrad dac2_cntl = RREG32(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC2_CLK_SEL; 1266 1.1 riastrad 1267 1.1 riastrad if (radeon_crtc->crtc_id == 0) { 1268 1.1 riastrad if (ASIC_IS_R300(rdev)) { 1269 1.1 riastrad disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK; 1270 1.1 riastrad disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC; 1271 1.1 riastrad } else if (rdev->family == CHIP_R200) { 1272 1.1 riastrad fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK | 1273 1.1 riastrad RADEON_FP2_DVO_RATE_SEL_SDR); 1274 1.1 riastrad } else 1275 1.1 riastrad disp_hw_debug |= RADEON_CRT2_DISP1_SEL; 1276 1.1 riastrad } else { 1277 1.1 riastrad if (ASIC_IS_R300(rdev)) { 1278 1.1 riastrad disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK; 1279 1.1 riastrad disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC2; 1280 1.1 riastrad } else if (rdev->family == CHIP_R200) { 1281 1.1 riastrad fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK | 1282 1.1 riastrad RADEON_FP2_DVO_RATE_SEL_SDR); 1283 1.1 riastrad fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2; 1284 1.1 riastrad } else 1285 1.1 riastrad disp_hw_debug &= ~RADEON_CRT2_DISP1_SEL; 1286 1.1 riastrad } 1287 1.1 riastrad WREG32(RADEON_DAC_CNTL2, dac2_cntl); 1288 1.1 riastrad } 1289 1.1 riastrad 1290 1.1 riastrad if (ASIC_IS_R300(rdev)) { 1291 1.1 riastrad WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1); 1292 1.1 riastrad WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl); 1293 1.1 riastrad } else if (rdev->family != CHIP_R200) 1294 1.1 riastrad WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug); 1295 1.1 riastrad else if (rdev->family == CHIP_R200) 1296 1.1 riastrad WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl); 1297 1.1 riastrad 1298 1.1 riastrad if (rdev->family >= CHIP_R200) 1299 1.1 riastrad WREG32(RADEON_DISP_TV_OUT_CNTL, disp_tv_out_cntl); 1300 1.1 riastrad 1301 1.1 riastrad if (is_tv) 1302 1.1 riastrad radeon_legacy_tv_mode_set(encoder, mode, adjusted_mode); 1303 1.1 riastrad 1304 1.1 riastrad if (rdev->is_atom_bios) 1305 1.1 riastrad radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); 1306 1.1 riastrad else 1307 1.1 riastrad radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); 1308 1.1 riastrad 1309 1.1 riastrad } 1310 1.1 riastrad 1311 1.1 riastrad static bool r300_legacy_tv_detect(struct drm_encoder *encoder, 1312 1.1 riastrad struct drm_connector *connector) 1313 1.1 riastrad { 1314 1.1 riastrad struct drm_device *dev = encoder->dev; 1315 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 1316 1.1 riastrad uint32_t crtc2_gen_cntl, tv_dac_cntl, dac_cntl2, dac_ext_cntl; 1317 1.1 riastrad uint32_t disp_output_cntl, gpiopad_a, tmp; 1318 1.1 riastrad bool found = false; 1319 1.1 riastrad 1320 1.1 riastrad /* save regs needed */ 1321 1.1 riastrad gpiopad_a = RREG32(RADEON_GPIOPAD_A); 1322 1.1 riastrad dac_cntl2 = RREG32(RADEON_DAC_CNTL2); 1323 1.1 riastrad crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL); 1324 1.1 riastrad dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL); 1325 1.1 riastrad tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL); 1326 1.1 riastrad disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL); 1327 1.1 riastrad 1328 1.1 riastrad WREG32_P(RADEON_GPIOPAD_A, 0, ~1); 1329 1.1 riastrad 1330 1.1 riastrad WREG32(RADEON_DAC_CNTL2, RADEON_DAC2_DAC2_CLK_SEL); 1331 1.1 riastrad 1332 1.1 riastrad WREG32(RADEON_CRTC2_GEN_CNTL, 1333 1.1 riastrad RADEON_CRTC2_CRT2_ON | RADEON_CRTC2_VSYNC_TRISTAT); 1334 1.1 riastrad 1335 1.1 riastrad tmp = disp_output_cntl & ~RADEON_DISP_TVDAC_SOURCE_MASK; 1336 1.1 riastrad tmp |= RADEON_DISP_TVDAC_SOURCE_CRTC2; 1337 1.1 riastrad WREG32(RADEON_DISP_OUTPUT_CNTL, tmp); 1338 1.1 riastrad 1339 1.1 riastrad WREG32(RADEON_DAC_EXT_CNTL, 1340 1.1 riastrad RADEON_DAC2_FORCE_BLANK_OFF_EN | 1341 1.1 riastrad RADEON_DAC2_FORCE_DATA_EN | 1342 1.1 riastrad RADEON_DAC_FORCE_DATA_SEL_RGB | 1343 1.1 riastrad (0xec << RADEON_DAC_FORCE_DATA_SHIFT)); 1344 1.1 riastrad 1345 1.1 riastrad WREG32(RADEON_TV_DAC_CNTL, 1346 1.1 riastrad RADEON_TV_DAC_STD_NTSC | 1347 1.1 riastrad (8 << RADEON_TV_DAC_BGADJ_SHIFT) | 1348 1.1 riastrad (6 << RADEON_TV_DAC_DACADJ_SHIFT)); 1349 1.1 riastrad 1350 1.1 riastrad RREG32(RADEON_TV_DAC_CNTL); 1351 1.1 riastrad mdelay(4); 1352 1.1 riastrad 1353 1.1 riastrad WREG32(RADEON_TV_DAC_CNTL, 1354 1.1 riastrad RADEON_TV_DAC_NBLANK | 1355 1.1 riastrad RADEON_TV_DAC_NHOLD | 1356 1.1 riastrad RADEON_TV_MONITOR_DETECT_EN | 1357 1.1 riastrad RADEON_TV_DAC_STD_NTSC | 1358 1.1 riastrad (8 << RADEON_TV_DAC_BGADJ_SHIFT) | 1359 1.1 riastrad (6 << RADEON_TV_DAC_DACADJ_SHIFT)); 1360 1.1 riastrad 1361 1.1 riastrad RREG32(RADEON_TV_DAC_CNTL); 1362 1.1 riastrad mdelay(6); 1363 1.1 riastrad 1364 1.1 riastrad tmp = RREG32(RADEON_TV_DAC_CNTL); 1365 1.1 riastrad if ((tmp & RADEON_TV_DAC_GDACDET) != 0) { 1366 1.1 riastrad found = true; 1367 1.1 riastrad DRM_DEBUG_KMS("S-video TV connection detected\n"); 1368 1.1 riastrad } else if ((tmp & RADEON_TV_DAC_BDACDET) != 0) { 1369 1.1 riastrad found = true; 1370 1.1 riastrad DRM_DEBUG_KMS("Composite TV connection detected\n"); 1371 1.1 riastrad } 1372 1.1 riastrad 1373 1.1 riastrad WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl); 1374 1.1 riastrad WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl); 1375 1.1 riastrad WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl); 1376 1.1 riastrad WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl); 1377 1.1 riastrad WREG32(RADEON_DAC_CNTL2, dac_cntl2); 1378 1.1 riastrad WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1); 1379 1.1 riastrad return found; 1380 1.1 riastrad } 1381 1.1 riastrad 1382 1.1 riastrad static bool radeon_legacy_tv_detect(struct drm_encoder *encoder, 1383 1.1 riastrad struct drm_connector *connector) 1384 1.1 riastrad { 1385 1.1 riastrad struct drm_device *dev = encoder->dev; 1386 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 1387 1.1 riastrad uint32_t tv_dac_cntl, dac_cntl2; 1388 1.1 riastrad uint32_t config_cntl, tv_pre_dac_mux_cntl, tv_master_cntl, tmp; 1389 1.1 riastrad bool found = false; 1390 1.1 riastrad 1391 1.1 riastrad if (ASIC_IS_R300(rdev)) 1392 1.1 riastrad return r300_legacy_tv_detect(encoder, connector); 1393 1.1 riastrad 1394 1.1 riastrad dac_cntl2 = RREG32(RADEON_DAC_CNTL2); 1395 1.1 riastrad tv_master_cntl = RREG32(RADEON_TV_MASTER_CNTL); 1396 1.1 riastrad tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL); 1397 1.1 riastrad config_cntl = RREG32(RADEON_CONFIG_CNTL); 1398 1.1 riastrad tv_pre_dac_mux_cntl = RREG32(RADEON_TV_PRE_DAC_MUX_CNTL); 1399 1.1 riastrad 1400 1.1 riastrad tmp = dac_cntl2 & ~RADEON_DAC2_DAC2_CLK_SEL; 1401 1.1 riastrad WREG32(RADEON_DAC_CNTL2, tmp); 1402 1.1 riastrad 1403 1.1 riastrad tmp = tv_master_cntl | RADEON_TV_ON; 1404 1.1 riastrad tmp &= ~(RADEON_TV_ASYNC_RST | 1405 1.1 riastrad RADEON_RESTART_PHASE_FIX | 1406 1.1 riastrad RADEON_CRT_FIFO_CE_EN | 1407 1.1 riastrad RADEON_TV_FIFO_CE_EN | 1408 1.1 riastrad RADEON_RE_SYNC_NOW_SEL_MASK); 1409 1.1 riastrad tmp |= RADEON_TV_FIFO_ASYNC_RST | RADEON_CRT_ASYNC_RST; 1410 1.1 riastrad WREG32(RADEON_TV_MASTER_CNTL, tmp); 1411 1.1 riastrad 1412 1.1 riastrad tmp = RADEON_TV_DAC_NBLANK | RADEON_TV_DAC_NHOLD | 1413 1.1 riastrad RADEON_TV_MONITOR_DETECT_EN | RADEON_TV_DAC_STD_NTSC | 1414 1.1 riastrad (8 << RADEON_TV_DAC_BGADJ_SHIFT); 1415 1.1 riastrad 1416 1.1 riastrad if (config_cntl & RADEON_CFG_ATI_REV_ID_MASK) 1417 1.1 riastrad tmp |= (4 << RADEON_TV_DAC_DACADJ_SHIFT); 1418 1.1 riastrad else 1419 1.1 riastrad tmp |= (8 << RADEON_TV_DAC_DACADJ_SHIFT); 1420 1.1 riastrad WREG32(RADEON_TV_DAC_CNTL, tmp); 1421 1.1 riastrad 1422 1.1 riastrad tmp = RADEON_C_GRN_EN | RADEON_CMP_BLU_EN | 1423 1.1 riastrad RADEON_RED_MX_FORCE_DAC_DATA | 1424 1.1 riastrad RADEON_GRN_MX_FORCE_DAC_DATA | 1425 1.1 riastrad RADEON_BLU_MX_FORCE_DAC_DATA | 1426 1.1 riastrad (0x109 << RADEON_TV_FORCE_DAC_DATA_SHIFT); 1427 1.1 riastrad WREG32(RADEON_TV_PRE_DAC_MUX_CNTL, tmp); 1428 1.1 riastrad 1429 1.1 riastrad mdelay(3); 1430 1.1 riastrad tmp = RREG32(RADEON_TV_DAC_CNTL); 1431 1.1 riastrad if (tmp & RADEON_TV_DAC_GDACDET) { 1432 1.1 riastrad found = true; 1433 1.1 riastrad DRM_DEBUG_KMS("S-video TV connection detected\n"); 1434 1.1 riastrad } else if ((tmp & RADEON_TV_DAC_BDACDET) != 0) { 1435 1.1 riastrad found = true; 1436 1.1 riastrad DRM_DEBUG_KMS("Composite TV connection detected\n"); 1437 1.1 riastrad } 1438 1.1 riastrad 1439 1.1 riastrad WREG32(RADEON_TV_PRE_DAC_MUX_CNTL, tv_pre_dac_mux_cntl); 1440 1.1 riastrad WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl); 1441 1.1 riastrad WREG32(RADEON_TV_MASTER_CNTL, tv_master_cntl); 1442 1.1 riastrad WREG32(RADEON_DAC_CNTL2, dac_cntl2); 1443 1.1 riastrad return found; 1444 1.1 riastrad } 1445 1.1 riastrad 1446 1.1 riastrad static bool radeon_legacy_ext_dac_detect(struct drm_encoder *encoder, 1447 1.1 riastrad struct drm_connector *connector) 1448 1.1 riastrad { 1449 1.1 riastrad struct drm_device *dev = encoder->dev; 1450 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 1451 1.1 riastrad uint32_t gpio_monid, fp2_gen_cntl, disp_output_cntl, crtc2_gen_cntl; 1452 1.1 riastrad uint32_t disp_lin_trans_grph_a, disp_lin_trans_grph_b, disp_lin_trans_grph_c; 1453 1.1 riastrad uint32_t disp_lin_trans_grph_d, disp_lin_trans_grph_e, disp_lin_trans_grph_f; 1454 1.1 riastrad uint32_t tmp, crtc2_h_total_disp, crtc2_v_total_disp; 1455 1.1 riastrad uint32_t crtc2_h_sync_strt_wid, crtc2_v_sync_strt_wid; 1456 1.1 riastrad bool found = false; 1457 1.1 riastrad int i; 1458 1.1 riastrad 1459 1.1 riastrad /* save the regs we need */ 1460 1.1 riastrad gpio_monid = RREG32(RADEON_GPIO_MONID); 1461 1.1 riastrad fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL); 1462 1.1 riastrad disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL); 1463 1.1 riastrad crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL); 1464 1.1 riastrad disp_lin_trans_grph_a = RREG32(RADEON_DISP_LIN_TRANS_GRPH_A); 1465 1.1 riastrad disp_lin_trans_grph_b = RREG32(RADEON_DISP_LIN_TRANS_GRPH_B); 1466 1.1 riastrad disp_lin_trans_grph_c = RREG32(RADEON_DISP_LIN_TRANS_GRPH_C); 1467 1.1 riastrad disp_lin_trans_grph_d = RREG32(RADEON_DISP_LIN_TRANS_GRPH_D); 1468 1.1 riastrad disp_lin_trans_grph_e = RREG32(RADEON_DISP_LIN_TRANS_GRPH_E); 1469 1.1 riastrad disp_lin_trans_grph_f = RREG32(RADEON_DISP_LIN_TRANS_GRPH_F); 1470 1.1 riastrad crtc2_h_total_disp = RREG32(RADEON_CRTC2_H_TOTAL_DISP); 1471 1.1 riastrad crtc2_v_total_disp = RREG32(RADEON_CRTC2_V_TOTAL_DISP); 1472 1.1 riastrad crtc2_h_sync_strt_wid = RREG32(RADEON_CRTC2_H_SYNC_STRT_WID); 1473 1.1 riastrad crtc2_v_sync_strt_wid = RREG32(RADEON_CRTC2_V_SYNC_STRT_WID); 1474 1.1 riastrad 1475 1.1 riastrad tmp = RREG32(RADEON_GPIO_MONID); 1476 1.1 riastrad tmp &= ~RADEON_GPIO_A_0; 1477 1.1 riastrad WREG32(RADEON_GPIO_MONID, tmp); 1478 1.1 riastrad 1479 1.1 riastrad WREG32(RADEON_FP2_GEN_CNTL, (RADEON_FP2_ON | 1480 1.1 riastrad RADEON_FP2_PANEL_FORMAT | 1481 1.1 riastrad R200_FP2_SOURCE_SEL_TRANS_UNIT | 1482 1.1 riastrad RADEON_FP2_DVO_EN | 1483 1.1 riastrad R200_FP2_DVO_RATE_SEL_SDR)); 1484 1.1 riastrad 1485 1.1 riastrad WREG32(RADEON_DISP_OUTPUT_CNTL, (RADEON_DISP_DAC_SOURCE_RMX | 1486 1.1 riastrad RADEON_DISP_TRANS_MATRIX_GRAPHICS)); 1487 1.1 riastrad 1488 1.1 riastrad WREG32(RADEON_CRTC2_GEN_CNTL, (RADEON_CRTC2_EN | 1489 1.1 riastrad RADEON_CRTC2_DISP_REQ_EN_B)); 1490 1.1 riastrad 1491 1.1 riastrad WREG32(RADEON_DISP_LIN_TRANS_GRPH_A, 0x00000000); 1492 1.1 riastrad WREG32(RADEON_DISP_LIN_TRANS_GRPH_B, 0x000003f0); 1493 1.1 riastrad WREG32(RADEON_DISP_LIN_TRANS_GRPH_C, 0x00000000); 1494 1.1 riastrad WREG32(RADEON_DISP_LIN_TRANS_GRPH_D, 0x000003f0); 1495 1.1 riastrad WREG32(RADEON_DISP_LIN_TRANS_GRPH_E, 0x00000000); 1496 1.1 riastrad WREG32(RADEON_DISP_LIN_TRANS_GRPH_F, 0x000003f0); 1497 1.1 riastrad 1498 1.1 riastrad WREG32(RADEON_CRTC2_H_TOTAL_DISP, 0x01000008); 1499 1.1 riastrad WREG32(RADEON_CRTC2_H_SYNC_STRT_WID, 0x00000800); 1500 1.1 riastrad WREG32(RADEON_CRTC2_V_TOTAL_DISP, 0x00080001); 1501 1.1 riastrad WREG32(RADEON_CRTC2_V_SYNC_STRT_WID, 0x00000080); 1502 1.1 riastrad 1503 1.1 riastrad for (i = 0; i < 200; i++) { 1504 1.1 riastrad tmp = RREG32(RADEON_GPIO_MONID); 1505 1.1 riastrad if (tmp & RADEON_GPIO_Y_0) 1506 1.1 riastrad found = true; 1507 1.1 riastrad 1508 1.1 riastrad if (found) 1509 1.1 riastrad break; 1510 1.1 riastrad 1511 1.1 riastrad if (!drm_can_sleep()) 1512 1.1 riastrad mdelay(1); 1513 1.1 riastrad else 1514 1.1 riastrad msleep(1); 1515 1.1 riastrad } 1516 1.1 riastrad 1517 1.1 riastrad /* restore the regs we used */ 1518 1.1 riastrad WREG32(RADEON_DISP_LIN_TRANS_GRPH_A, disp_lin_trans_grph_a); 1519 1.1 riastrad WREG32(RADEON_DISP_LIN_TRANS_GRPH_B, disp_lin_trans_grph_b); 1520 1.1 riastrad WREG32(RADEON_DISP_LIN_TRANS_GRPH_C, disp_lin_trans_grph_c); 1521 1.1 riastrad WREG32(RADEON_DISP_LIN_TRANS_GRPH_D, disp_lin_trans_grph_d); 1522 1.1 riastrad WREG32(RADEON_DISP_LIN_TRANS_GRPH_E, disp_lin_trans_grph_e); 1523 1.1 riastrad WREG32(RADEON_DISP_LIN_TRANS_GRPH_F, disp_lin_trans_grph_f); 1524 1.1 riastrad WREG32(RADEON_CRTC2_H_TOTAL_DISP, crtc2_h_total_disp); 1525 1.1 riastrad WREG32(RADEON_CRTC2_V_TOTAL_DISP, crtc2_v_total_disp); 1526 1.1 riastrad WREG32(RADEON_CRTC2_H_SYNC_STRT_WID, crtc2_h_sync_strt_wid); 1527 1.1 riastrad WREG32(RADEON_CRTC2_V_SYNC_STRT_WID, crtc2_v_sync_strt_wid); 1528 1.1 riastrad WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl); 1529 1.1 riastrad WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl); 1530 1.1 riastrad WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl); 1531 1.1 riastrad WREG32(RADEON_GPIO_MONID, gpio_monid); 1532 1.1 riastrad 1533 1.1 riastrad return found; 1534 1.1 riastrad } 1535 1.1 riastrad 1536 1.1 riastrad static enum drm_connector_status radeon_legacy_tv_dac_detect(struct drm_encoder *encoder, 1537 1.1 riastrad struct drm_connector *connector) 1538 1.1 riastrad { 1539 1.1 riastrad struct drm_device *dev = encoder->dev; 1540 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 1541 1.1 riastrad uint32_t crtc2_gen_cntl = 0, tv_dac_cntl, dac_cntl2, dac_ext_cntl; 1542 1.1 riastrad uint32_t gpiopad_a = 0, pixclks_cntl, tmp; 1543 1.1 riastrad uint32_t disp_output_cntl = 0, disp_hw_debug = 0, crtc_ext_cntl = 0; 1544 1.1 riastrad enum drm_connector_status found = connector_status_disconnected; 1545 1.1 riastrad struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); 1546 1.1 riastrad struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv; 1547 1.1 riastrad bool color = true; 1548 1.1 riastrad struct drm_crtc *crtc; 1549 1.1 riastrad 1550 1.1 riastrad /* find out if crtc2 is in use or if this encoder is using it */ 1551 1.1 riastrad list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 1552 1.1 riastrad struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 1553 1.1 riastrad if ((radeon_crtc->crtc_id == 1) && crtc->enabled) { 1554 1.1 riastrad if (encoder->crtc != crtc) { 1555 1.1 riastrad return connector_status_disconnected; 1556 1.1 riastrad } 1557 1.1 riastrad } 1558 1.1 riastrad } 1559 1.1 riastrad 1560 1.1 riastrad if (connector->connector_type == DRM_MODE_CONNECTOR_SVIDEO || 1561 1.1 riastrad connector->connector_type == DRM_MODE_CONNECTOR_Composite || 1562 1.1 riastrad connector->connector_type == DRM_MODE_CONNECTOR_9PinDIN) { 1563 1.1 riastrad bool tv_detect; 1564 1.1 riastrad 1565 1.1 riastrad if (radeon_encoder->active_device && !(radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT)) 1566 1.1 riastrad return connector_status_disconnected; 1567 1.1 riastrad 1568 1.1 riastrad tv_detect = radeon_legacy_tv_detect(encoder, connector); 1569 1.1 riastrad if (tv_detect && tv_dac) 1570 1.1 riastrad found = connector_status_connected; 1571 1.1 riastrad return found; 1572 1.1 riastrad } 1573 1.1 riastrad 1574 1.1 riastrad /* don't probe if the encoder is being used for something else not CRT related */ 1575 1.1 riastrad if (radeon_encoder->active_device && !(radeon_encoder->active_device & ATOM_DEVICE_CRT_SUPPORT)) { 1576 1.1 riastrad DRM_INFO("not detecting due to %08x\n", radeon_encoder->active_device); 1577 1.1 riastrad return connector_status_disconnected; 1578 1.1 riastrad } 1579 1.1 riastrad 1580 1.1 riastrad /* R200 uses an external DAC for secondary DAC */ 1581 1.1 riastrad if (rdev->family == CHIP_R200) { 1582 1.1 riastrad if (radeon_legacy_ext_dac_detect(encoder, connector)) 1583 1.1 riastrad found = connector_status_connected; 1584 1.1 riastrad return found; 1585 1.1 riastrad } 1586 1.1 riastrad 1587 1.1 riastrad /* save the regs we need */ 1588 1.1 riastrad pixclks_cntl = RREG32_PLL(RADEON_PIXCLKS_CNTL); 1589 1.1 riastrad 1590 1.1 riastrad if (rdev->flags & RADEON_SINGLE_CRTC) { 1591 1.1 riastrad crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL); 1592 1.1 riastrad } else { 1593 1.1 riastrad if (ASIC_IS_R300(rdev)) { 1594 1.1 riastrad gpiopad_a = RREG32(RADEON_GPIOPAD_A); 1595 1.1 riastrad disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL); 1596 1.1 riastrad } else { 1597 1.1 riastrad disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG); 1598 1.1 riastrad } 1599 1.1 riastrad crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL); 1600 1.1 riastrad } 1601 1.1 riastrad tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL); 1602 1.1 riastrad dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL); 1603 1.1 riastrad dac_cntl2 = RREG32(RADEON_DAC_CNTL2); 1604 1.1 riastrad 1605 1.1 riastrad tmp = pixclks_cntl & ~(RADEON_PIX2CLK_ALWAYS_ONb 1606 1.1 riastrad | RADEON_PIX2CLK_DAC_ALWAYS_ONb); 1607 1.1 riastrad WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp); 1608 1.1 riastrad 1609 1.1 riastrad if (rdev->flags & RADEON_SINGLE_CRTC) { 1610 1.1 riastrad tmp = crtc_ext_cntl | RADEON_CRTC_CRT_ON; 1611 1.1 riastrad WREG32(RADEON_CRTC_EXT_CNTL, tmp); 1612 1.1 riastrad } else { 1613 1.1 riastrad tmp = crtc2_gen_cntl & ~RADEON_CRTC2_PIX_WIDTH_MASK; 1614 1.1 riastrad tmp |= RADEON_CRTC2_CRT2_ON | 1615 1.1 riastrad (2 << RADEON_CRTC2_PIX_WIDTH_SHIFT); 1616 1.1 riastrad WREG32(RADEON_CRTC2_GEN_CNTL, tmp); 1617 1.1 riastrad 1618 1.1 riastrad if (ASIC_IS_R300(rdev)) { 1619 1.1 riastrad WREG32_P(RADEON_GPIOPAD_A, 1, ~1); 1620 1.1 riastrad tmp = disp_output_cntl & ~RADEON_DISP_TVDAC_SOURCE_MASK; 1621 1.1 riastrad tmp |= RADEON_DISP_TVDAC_SOURCE_CRTC2; 1622 1.1 riastrad WREG32(RADEON_DISP_OUTPUT_CNTL, tmp); 1623 1.1 riastrad } else { 1624 1.1 riastrad tmp = disp_hw_debug & ~RADEON_CRT2_DISP1_SEL; 1625 1.1 riastrad WREG32(RADEON_DISP_HW_DEBUG, tmp); 1626 1.1 riastrad } 1627 1.1 riastrad } 1628 1.1 riastrad 1629 1.1 riastrad tmp = RADEON_TV_DAC_NBLANK | 1630 1.1 riastrad RADEON_TV_DAC_NHOLD | 1631 1.1 riastrad RADEON_TV_MONITOR_DETECT_EN | 1632 1.1 riastrad RADEON_TV_DAC_STD_PS2; 1633 1.1 riastrad 1634 1.1 riastrad WREG32(RADEON_TV_DAC_CNTL, tmp); 1635 1.1 riastrad 1636 1.1 riastrad tmp = RADEON_DAC2_FORCE_BLANK_OFF_EN | 1637 1.1 riastrad RADEON_DAC2_FORCE_DATA_EN; 1638 1.1 riastrad 1639 1.1 riastrad if (color) 1640 1.1 riastrad tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB; 1641 1.1 riastrad else 1642 1.1 riastrad tmp |= RADEON_DAC_FORCE_DATA_SEL_G; 1643 1.1 riastrad 1644 1.1 riastrad if (ASIC_IS_R300(rdev)) 1645 1.1 riastrad tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT); 1646 1.1 riastrad else 1647 1.1 riastrad tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT); 1648 1.1 riastrad 1649 1.1 riastrad WREG32(RADEON_DAC_EXT_CNTL, tmp); 1650 1.1 riastrad 1651 1.1 riastrad tmp = dac_cntl2 | RADEON_DAC2_DAC2_CLK_SEL | RADEON_DAC2_CMP_EN; 1652 1.1 riastrad WREG32(RADEON_DAC_CNTL2, tmp); 1653 1.1 riastrad 1654 1.1 riastrad mdelay(10); 1655 1.1 riastrad 1656 1.1 riastrad if (ASIC_IS_R300(rdev)) { 1657 1.1 riastrad if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUT_B) 1658 1.1 riastrad found = connector_status_connected; 1659 1.1 riastrad } else { 1660 1.1 riastrad if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUTPUT) 1661 1.1 riastrad found = connector_status_connected; 1662 1.1 riastrad } 1663 1.1 riastrad 1664 1.1 riastrad /* restore regs we used */ 1665 1.1 riastrad WREG32(RADEON_DAC_CNTL2, dac_cntl2); 1666 1.1 riastrad WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl); 1667 1.1 riastrad WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl); 1668 1.1 riastrad 1669 1.1 riastrad if (rdev->flags & RADEON_SINGLE_CRTC) { 1670 1.1 riastrad WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl); 1671 1.1 riastrad } else { 1672 1.1 riastrad WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl); 1673 1.1 riastrad if (ASIC_IS_R300(rdev)) { 1674 1.1 riastrad WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl); 1675 1.1 riastrad WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1); 1676 1.1 riastrad } else { 1677 1.1 riastrad WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug); 1678 1.1 riastrad } 1679 1.1 riastrad } 1680 1.1 riastrad 1681 1.1 riastrad WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl); 1682 1.1 riastrad 1683 1.1 riastrad return found; 1684 1.1 riastrad 1685 1.1 riastrad } 1686 1.1 riastrad 1687 1.1 riastrad static const struct drm_encoder_helper_funcs radeon_legacy_tv_dac_helper_funcs = { 1688 1.1 riastrad .dpms = radeon_legacy_tv_dac_dpms, 1689 1.1 riastrad .mode_fixup = radeon_legacy_mode_fixup, 1690 1.1 riastrad .prepare = radeon_legacy_tv_dac_prepare, 1691 1.1 riastrad .mode_set = radeon_legacy_tv_dac_mode_set, 1692 1.1 riastrad .commit = radeon_legacy_tv_dac_commit, 1693 1.1 riastrad .detect = radeon_legacy_tv_dac_detect, 1694 1.1 riastrad .disable = radeon_legacy_encoder_disable, 1695 1.1 riastrad }; 1696 1.1 riastrad 1697 1.1 riastrad 1698 1.1 riastrad static const struct drm_encoder_funcs radeon_legacy_tv_dac_enc_funcs = { 1699 1.1 riastrad .destroy = radeon_enc_destroy, 1700 1.1 riastrad }; 1701 1.1 riastrad 1702 1.1 riastrad 1703 1.1 riastrad static struct radeon_encoder_int_tmds *radeon_legacy_get_tmds_info(struct radeon_encoder *encoder) 1704 1.1 riastrad { 1705 1.1 riastrad struct drm_device *dev = encoder->base.dev; 1706 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 1707 1.1 riastrad struct radeon_encoder_int_tmds *tmds = NULL; 1708 1.1 riastrad bool ret; 1709 1.1 riastrad 1710 1.1 riastrad tmds = kzalloc(sizeof(struct radeon_encoder_int_tmds), GFP_KERNEL); 1711 1.1 riastrad 1712 1.1 riastrad if (!tmds) 1713 1.1 riastrad return NULL; 1714 1.1 riastrad 1715 1.1 riastrad if (rdev->is_atom_bios) 1716 1.1 riastrad ret = radeon_atombios_get_tmds_info(encoder, tmds); 1717 1.1 riastrad else 1718 1.1 riastrad ret = radeon_legacy_get_tmds_info_from_combios(encoder, tmds); 1719 1.1 riastrad 1720 1.4 riastrad if (!ret) 1721 1.1 riastrad radeon_legacy_get_tmds_info_from_table(encoder, tmds); 1722 1.1 riastrad 1723 1.1 riastrad return tmds; 1724 1.1 riastrad } 1725 1.1 riastrad 1726 1.1 riastrad static struct radeon_encoder_ext_tmds *radeon_legacy_get_ext_tmds_info(struct radeon_encoder *encoder) 1727 1.1 riastrad { 1728 1.1 riastrad struct drm_device *dev = encoder->base.dev; 1729 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 1730 1.1 riastrad struct radeon_encoder_ext_tmds *tmds = NULL; 1731 1.1 riastrad bool ret; 1732 1.1 riastrad 1733 1.1 riastrad if (rdev->is_atom_bios) 1734 1.1 riastrad return NULL; 1735 1.1 riastrad 1736 1.1 riastrad tmds = kzalloc(sizeof(struct radeon_encoder_ext_tmds), GFP_KERNEL); 1737 1.1 riastrad 1738 1.1 riastrad if (!tmds) 1739 1.1 riastrad return NULL; 1740 1.1 riastrad 1741 1.1 riastrad ret = radeon_legacy_get_ext_tmds_info_from_combios(encoder, tmds); 1742 1.1 riastrad 1743 1.4 riastrad if (!ret) 1744 1.1 riastrad radeon_legacy_get_ext_tmds_info_from_table(encoder, tmds); 1745 1.1 riastrad 1746 1.1 riastrad return tmds; 1747 1.1 riastrad } 1748 1.1 riastrad 1749 1.1 riastrad void 1750 1.1 riastrad radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum, uint32_t supported_device) 1751 1.1 riastrad { 1752 1.1 riastrad struct radeon_device *rdev = dev->dev_private; 1753 1.1 riastrad struct drm_encoder *encoder; 1754 1.1 riastrad struct radeon_encoder *radeon_encoder; 1755 1.1 riastrad 1756 1.1 riastrad /* see if we already added it */ 1757 1.1 riastrad list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { 1758 1.1 riastrad radeon_encoder = to_radeon_encoder(encoder); 1759 1.1 riastrad if (radeon_encoder->encoder_enum == encoder_enum) { 1760 1.1 riastrad radeon_encoder->devices |= supported_device; 1761 1.1 riastrad return; 1762 1.1 riastrad } 1763 1.1 riastrad 1764 1.1 riastrad } 1765 1.1 riastrad 1766 1.1 riastrad /* add a new one */ 1767 1.1 riastrad radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL); 1768 1.1 riastrad if (!radeon_encoder) 1769 1.1 riastrad return; 1770 1.1 riastrad 1771 1.1 riastrad encoder = &radeon_encoder->base; 1772 1.1 riastrad if (rdev->flags & RADEON_SINGLE_CRTC) 1773 1.1 riastrad encoder->possible_crtcs = 0x1; 1774 1.1 riastrad else 1775 1.1 riastrad encoder->possible_crtcs = 0x3; 1776 1.1 riastrad 1777 1.1 riastrad radeon_encoder->enc_priv = NULL; 1778 1.1 riastrad 1779 1.1 riastrad radeon_encoder->encoder_enum = encoder_enum; 1780 1.1 riastrad radeon_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT; 1781 1.1 riastrad radeon_encoder->devices = supported_device; 1782 1.1 riastrad radeon_encoder->rmx_type = RMX_OFF; 1783 1.1 riastrad 1784 1.1 riastrad switch (radeon_encoder->encoder_id) { 1785 1.1 riastrad case ENCODER_OBJECT_ID_INTERNAL_LVDS: 1786 1.1 riastrad encoder->possible_crtcs = 0x1; 1787 1.4 riastrad drm_encoder_init(dev, encoder, &radeon_legacy_lvds_enc_funcs, 1788 1.4 riastrad DRM_MODE_ENCODER_LVDS, NULL); 1789 1.1 riastrad drm_encoder_helper_add(encoder, &radeon_legacy_lvds_helper_funcs); 1790 1.1 riastrad if (rdev->is_atom_bios) 1791 1.1 riastrad radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder); 1792 1.1 riastrad else 1793 1.1 riastrad radeon_encoder->enc_priv = radeon_combios_get_lvds_info(radeon_encoder); 1794 1.1 riastrad radeon_encoder->rmx_type = RMX_FULL; 1795 1.1 riastrad break; 1796 1.1 riastrad case ENCODER_OBJECT_ID_INTERNAL_TMDS1: 1797 1.4 riastrad drm_encoder_init(dev, encoder, &radeon_legacy_tmds_int_enc_funcs, 1798 1.4 riastrad DRM_MODE_ENCODER_TMDS, NULL); 1799 1.1 riastrad drm_encoder_helper_add(encoder, &radeon_legacy_tmds_int_helper_funcs); 1800 1.1 riastrad radeon_encoder->enc_priv = radeon_legacy_get_tmds_info(radeon_encoder); 1801 1.1 riastrad break; 1802 1.1 riastrad case ENCODER_OBJECT_ID_INTERNAL_DAC1: 1803 1.4 riastrad drm_encoder_init(dev, encoder, &radeon_legacy_primary_dac_enc_funcs, 1804 1.4 riastrad DRM_MODE_ENCODER_DAC, NULL); 1805 1.1 riastrad drm_encoder_helper_add(encoder, &radeon_legacy_primary_dac_helper_funcs); 1806 1.1 riastrad if (rdev->is_atom_bios) 1807 1.1 riastrad radeon_encoder->enc_priv = radeon_atombios_get_primary_dac_info(radeon_encoder); 1808 1.1 riastrad else 1809 1.1 riastrad radeon_encoder->enc_priv = radeon_combios_get_primary_dac_info(radeon_encoder); 1810 1.1 riastrad break; 1811 1.1 riastrad case ENCODER_OBJECT_ID_INTERNAL_DAC2: 1812 1.4 riastrad drm_encoder_init(dev, encoder, &radeon_legacy_tv_dac_enc_funcs, 1813 1.4 riastrad DRM_MODE_ENCODER_TVDAC, NULL); 1814 1.1 riastrad drm_encoder_helper_add(encoder, &radeon_legacy_tv_dac_helper_funcs); 1815 1.1 riastrad if (rdev->is_atom_bios) 1816 1.1 riastrad radeon_encoder->enc_priv = radeon_atombios_get_tv_dac_info(radeon_encoder); 1817 1.1 riastrad else 1818 1.1 riastrad radeon_encoder->enc_priv = radeon_combios_get_tv_dac_info(radeon_encoder); 1819 1.1 riastrad break; 1820 1.1 riastrad case ENCODER_OBJECT_ID_INTERNAL_DVO1: 1821 1.4 riastrad drm_encoder_init(dev, encoder, &radeon_legacy_tmds_ext_enc_funcs, 1822 1.4 riastrad DRM_MODE_ENCODER_TMDS, NULL); 1823 1.1 riastrad drm_encoder_helper_add(encoder, &radeon_legacy_tmds_ext_helper_funcs); 1824 1.1 riastrad if (!rdev->is_atom_bios) 1825 1.1 riastrad radeon_encoder->enc_priv = radeon_legacy_get_ext_tmds_info(radeon_encoder); 1826 1.1 riastrad break; 1827 1.1 riastrad } 1828 1.1 riastrad } 1829